Selaa lähdekoodia

qhse月报功能

Zimo 2 päivää sitten
vanhempi
commit
9ad9b4e6b5

+ 24 - 1
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java

@@ -6,7 +6,6 @@ import com.google.common.collect.ImmutableMap;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.sql.Timestamp;
-import java.text.SimpleDateFormat;
 import java.time.*;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoUnit;
@@ -26,6 +25,8 @@ public class DateUtils {
      * 时区 - 默认
      */
     public static final String TIME_ZONE_DEFAULT = "GMT+8";
+    private static final ZoneId ZONE_ID = ZoneId.systemDefault();
+
 
     /**
      * 秒转换成毫秒
@@ -172,7 +173,29 @@ public class DateUtils {
 
         return ImmutableMap.of("start", weekStart, "end", weekEnd);
     }
+    /**
+     * 获取上个月第一天 00:00:00
+     */
+    public static LocalDateTime getFirstDayOfLastMonth() {
+        LocalDate now = LocalDate.now(ZONE_ID);
+        // 上个月
+        LocalDate lastMonth = now.minusMonths(1);
+        // 上个月第一天
+        LocalDate firstDay = lastMonth.withDayOfMonth(1);
+        return firstDay.atStartOfDay();
+    }
 
+    /**
+     * 获取上个月最后一天 23:59:59
+     */
+    public static LocalDateTime getLastDayOfLastMonth() {
+        LocalDate now = LocalDate.now(ZONE_ID);
+        // 上个月
+        LocalDate lastMonth = now.minusMonths(1);
+        // 上个月最后一天
+        LocalDate lastDay = lastMonth.plusMonths(1).withDayOfMonth(1).minusDays(1);
+        return lastDay.atTime(23, 59, 59);
+    }
     public static ImmutableMap<String, LocalDateTime> getBeginEndMonth() {
         // 近一月开始时间(如今天是2025-05-09,此值为2025-04-10 00:00)
         LocalDateTime monthStart = LocalDate.now().minusDays(29).atStartOfDay();

+ 1 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/constant/PmsConstants.java

@@ -5,6 +5,7 @@ public interface PmsConstants {
     String QHSE_ACCIDENT = "qhse-accident";
     String GENERATE_MAINTAIN = "generateMaintain";
     String GENERATE_QHSE_CERT = "generateQhseCert";
+    String QHSE_MONTH_REPORT = "qhsemonthReport";
     String FAILURE_NO_PASS = "failureNoPass";
     String ALARM_MESSAGE = "alarmMessage";
     String WEEK_ALARM_MESSAGE = "weekAlarmMessage";

+ 9 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/qhse/report/vo/QhseMonthReportPageReqVO.java

@@ -16,7 +16,12 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
 @EqualsAndHashCode(callSuper = true)
 @ToString(callSuper = true)
 public class QhseMonthReportPageReqVO extends PageParam {
-
+    @Schema(description = "月报名称")
+    private String title;
+    @Schema(description = "部门id")
+    private Long deptId;
+    @Schema(description = "年月")
+    private String yearMonth;
     @Schema(description = "员工人数")
     private String employee;
 
@@ -110,6 +115,9 @@ public class QhseMonthReportPageReqVO extends PageParam {
     @Schema(description = "备注", example = "你说的对")
     private String remark;
 
+    @Schema(description = "工单填报人")
+    private Long dutyPerson;
+
     @Schema(description = "创建时间")
     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
     private LocalDateTime[] createTime;

+ 11 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/qhse/report/vo/QhseMonthReportRespVO.java

@@ -15,6 +15,14 @@ public class QhseMonthReportRespVO {
     @Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "28182")
     @ExcelProperty("主键id")
     private Long id;
+    @Schema(description = "月报名称")
+    private String title;
+
+    @Schema(description = "年月")
+    private String yearMonth;
+
+    @Schema(description = "部门id")
+    private Long deptId;
 
     @Schema(description = "员工人数", requiredMode = Schema.RequiredMode.REQUIRED)
     @ExcelProperty("员工人数")
@@ -140,6 +148,9 @@ public class QhseMonthReportRespVO {
     @ExcelProperty("备注")
     private String remark;
 
+    @Schema(description = "工单填报人")
+    private Long dutyPerson;
+
     @Schema(description = "创建时间")
     @ExcelProperty("创建时间")
     private LocalDateTime createTime;

+ 11 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/qhse/report/vo/QhseMonthReportSaveReqVO.java

@@ -12,6 +12,15 @@ public class QhseMonthReportSaveReqVO {
     @Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "28182")
     private Long id;
 
+    @Schema(description = "月报名称")
+    private String title;
+
+    @Schema(description = "部门id")
+    private Long deptId;
+
+    @Schema(description = "年月")
+    private String yearMonth;
+
     @Schema(description = "员工人数", requiredMode = Schema.RequiredMode.REQUIRED)
     @NotEmpty(message = "员工人数不能为空")
     private String employee;
@@ -132,6 +141,8 @@ public class QhseMonthReportSaveReqVO {
     @NotEmpty(message = "天然气消耗量(立方米)不能为空")
     private String naturalGasConsumption;
 
+    @Schema(description = "工单填报人")
+    private Long dutyPerson;
     @Schema(description = "备注", example = "你说的对")
     private String remark;
 

+ 13 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/qhse/report/QhseMonthReportDO.java

@@ -26,6 +26,15 @@ public class QhseMonthReportDO extends BaseDO {
      */
     @TableId
     private Long id;
+    /**
+     * 月报名称
+     */
+    private String title;
+    private String yearMonth;
+    /**
+     * 部门id
+     */
+    private Long deptId;
     /**
      * 员工人数
      */
@@ -146,6 +155,10 @@ public class QhseMonthReportDO extends BaseDO {
      * 天然气消耗量(立方米)
      */
     private String naturalGasConsumption;
+    /**
+     * 工单填报人
+     */
+    private Long dutyPerson;
     /**
      * 备注
      */

+ 6 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/qhse/jsa/QhseJsaMapper.java

@@ -33,4 +33,10 @@ public interface QhseJsaMapper extends BaseMapperX<QhseJsaDO> {
                 .orderByDesc(QhseJsaDO::getId));
     }
 
+    default Long selectCountByDeptAndTime(QhseJsaPageReqVO reqVO, Set<Long> ids) {
+        return selectCount(new LambdaQueryWrapperX<QhseJsaDO>()
+                .inIfPresent(QhseJsaDO::getDeptId, ids)
+                .betweenIfPresent(QhseJsaDO::getJsaTime, reqVO.getJsaTime()));
+    }
+
 }

+ 6 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/qhse/ptw/QhsePtwMapper.java

@@ -45,4 +45,10 @@ public interface QhsePtwMapper extends BaseMapperX<QhsePtwDO> {
                 .betweenIfPresent(QhsePtwDO::getCreateTime, reqVO.getCreateTime())
                 .inIfPresent(QhsePtwDO::getDeptId, ids));
     }
+
+    default Long selectCountByDeptAndTime(QhsePtwPageReqVO reqVO, Set<Long> ids) {
+        return selectCount(new LambdaQueryWrapperX<QhsePtwDO>()
+                .inIfPresent(QhsePtwDO::getDeptId, ids)
+                .betweenIfPresent(QhsePtwDO::getPtwTime, reqVO.getPtwTime()));
+    }
 }

+ 102 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/qhse/MonthReportJob.java

@@ -0,0 +1,102 @@
+package cn.iocoder.yudao.module.pms.job.qhse;
+
+import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
+import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
+import cn.iocoder.yudao.module.pms.constant.PmsConstants;
+import cn.iocoder.yudao.module.pms.controller.admin.qhse.jsa.vo.QhseJsaPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.qhse.ptw.vo.QhsePtwPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.qhse.soc.vo.IotSocSummaryPageReqVO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.report.QhseMonthReportDO;
+import cn.iocoder.yudao.module.pms.dal.mysql.qhse.jsa.QhseJsaMapper;
+import cn.iocoder.yudao.module.pms.dal.mysql.qhse.ptw.QhsePtwMapper;
+import cn.iocoder.yudao.module.pms.dal.mysql.qhse.report.QhseMonthReportMapper;
+import cn.iocoder.yudao.module.pms.dal.mysql.qhse.soc.IotSocSummaryMapper;
+import cn.iocoder.yudao.module.pms.message.PmsMessage;
+import cn.iocoder.yudao.module.system.api.dept.DeptApi;
+import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
+import cn.iocoder.yudao.module.system.api.permission.RoleApi;
+import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
+import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
+import cn.iocoder.yudao.module.system.service.dept.DeptService;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.getFirstDayOfLastMonth;
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.getLastDayOfLastMonth;
+
+@Component
+public class MonthReportJob implements JobHandler {
+    private final RoleApi roleApi;
+    private final IotSocSummaryMapper iotSocSummaryMapper;
+    private final AdminUserApi adminUserApi;
+    private final DeptService deptService;
+    private final QhseJsaMapper qhseJsaMapper;
+    private final QhsePtwMapper qhsePtwMapper;
+    private final DeptApi deptApi;
+    private final QhseMonthReportMapper qhseMonthReportMapper;
+    private final PmsMessage pmsMessage;
+
+    public MonthReportJob(RoleApi roleApi, IotSocSummaryMapper iotSocSummaryMapper, AdminUserApi adminUserApi, DeptService deptService, QhseJsaMapper qhseJsaMapper, QhsePtwMapper qhsePtwMapper, DeptApi deptApi, QhseMonthReportMapper qhseMonthReportMapper, PmsMessage pmsMessage) {
+        this.roleApi = roleApi;
+        this.iotSocSummaryMapper = iotSocSummaryMapper;
+        this.adminUserApi = adminUserApi;
+        this.deptService = deptService;
+        this.qhseJsaMapper = qhseJsaMapper;
+        this.qhsePtwMapper = qhsePtwMapper;
+        this.deptApi = deptApi;
+        this.qhseMonthReportMapper = qhseMonthReportMapper;
+        this.pmsMessage = pmsMessage;
+    }
+
+    @Override
+    @TenantIgnore
+    public String execute(String param) throws Exception {
+        LocalDateTime firstDayOfLastMonth = getFirstDayOfLastMonth();
+        // 上个月结束:yyyy-MM-最后一天 23:59:59
+        LocalDateTime lastDayOfLastMonth = getLastDayOfLastMonth();
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
+        String yearMonth = firstDayOfLastMonth.format(formatter);
+        List<Long> userIds = roleApi.getRoleUserIds("QHSE月报");
+        userIds.forEach(e ->{
+            Set<Long> ids = new HashSet<>();
+            AdminUserRespDTO user = adminUserApi.getUser(e);
+            if (Objects.nonNull(user.getDeptId())) {
+                ids = deptService.getChildDeptIdListFromCache(user.getDeptId());
+                ids.add(user.getDeptId());
+            }
+            IotSocSummaryPageReqVO pageReqVO = new IotSocSummaryPageReqVO();
+            pageReqVO.setObservationDate(new LocalDateTime[]{firstDayOfLastMonth, lastDayOfLastMonth});
+            Long socCount = iotSocSummaryMapper.selectCountBySocClassAndTime(pageReqVO, ids);
+            QhseJsaPageReqVO qhseJsaPageReqVO = new QhseJsaPageReqVO();
+            qhseJsaPageReqVO.setJsaTime(new LocalDateTime[]{firstDayOfLastMonth, lastDayOfLastMonth});
+            Long jsaCount = qhseJsaMapper.selectCountByDeptAndTime(qhseJsaPageReqVO, ids);
+            QhsePtwPageReqVO qhsePtwPageReqVO = new QhsePtwPageReqVO();
+            qhsePtwPageReqVO.setPtwTime(new LocalDateTime[]{firstDayOfLastMonth, lastDayOfLastMonth});
+            Long ptwCount = qhsePtwMapper.selectCountByDeptAndTime(qhsePtwPageReqVO, ids);
+            QhseMonthReportDO qhseMonthReportDO = new QhseMonthReportDO();
+            DeptRespDTO dept = deptApi.getDept(user.getDeptId());
+
+            qhseMonthReportDO.setTitle(dept.getName()+yearMonth+"QHSE月报");
+            qhseMonthReportDO.setYearMonth(yearMonth);
+            qhseMonthReportDO.setDeleted(false);
+            qhseMonthReportDO.setSocCards(String.valueOf(socCount));
+            qhseMonthReportDO.setJsa(String.valueOf(jsaCount));
+            qhseMonthReportDO.setPtwAudit(String.valueOf(ptwCount));
+            qhseMonthReportDO.setDutyPerson(e);
+            qhseMonthReportDO.setDeptId(dept.getId());
+            qhseMonthReportMapper.insert(qhseMonthReportDO);
+            //异步线程发送消息
+            CompletableFuture.runAsync(() -> {
+                pmsMessage.sendMessage(qhseMonthReportDO.getId(), dept.getName() + yearMonth + "QHSE月报已生成,请前往QHSE系统月报模块进行填报。", PmsConstants.QHSE_MONTH_REPORT, user.getId(), user.getMobile());
+            });
+        });
+        return "";
+    }
+}