Procházet zdrojové kódy

pms 瑞鹰日报 审批 代码初始化

zhangcl před 1 týdnem
rodič
revize
d69a565593

+ 8 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotrydailyreport/IotRyDailyReportController.java

@@ -74,6 +74,14 @@ public class IotRyDailyReportController {
         return success(true);
     }
 
+    @PutMapping("/approval")
+    @Operation(summary = "审批日报")
+    @PreAuthorize("@ss.hasPermission('pms:iot-ry-daily-report:update')")
+    public CommonResult<Boolean> approvalRhDailyReport(@Valid @RequestBody IotRyDailyReportSaveReqVO updateReqVO) {
+        iotRyDailyReportService.approvalRyDailyReport(updateReqVO);
+        return success(true);
+    }
+
     @DeleteMapping("/delete")
     @Operation(summary = "删除瑞鹰日报")
     @Parameter(name = "id", description = "编号", required = true)

+ 3 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotrydailyreport/vo/IotRyDailyReportRespVO.java

@@ -210,6 +210,9 @@ public class IotRyDailyReportRespVO {
     @ExcelProperty("审批状态 未提交、审批中、审批通过、审批不通过、已取消")
     private Integer auditStatus;
 
+    @Schema(description = "审批意见", example = "同意")
+    private String opinion;
+
     @Schema(description = "创建时间")
     @ExcelProperty("创建时间")
     private LocalDateTime createTime;

+ 3 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotrydailyreport/vo/IotRyDailyReportSaveReqVO.java

@@ -156,6 +156,9 @@ public class IotRyDailyReportSaveReqVO {
     @Schema(description = "审批状态 未提交、审批中、审批通过、审批不通过、已取消", example = "2")
     private Integer auditStatus;
 
+    @Schema(description = "审批意见", example = "同意")
+    private String opinion;
+
     /**
      * 扩展字段
      */

+ 4 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/iotrydailyreport/IotRyDailyReportDO.java

@@ -231,5 +231,9 @@ public class IotRyDailyReportDO extends BaseDO {
      * 审批状态 未提交、审批中、审批通过、审批不通过、已取消
      */
     private Integer auditStatus;
+    /**
+     * 审批意见
+     */
+    private String opinion;
 
 }

+ 7 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotrydailyreport/IotRyDailyReportService.java

@@ -142,4 +142,11 @@ public interface IotRyDailyReportService {
      * @return
      */
     List<IotRyDailyReportPolylineVO> polylineStatistics(IotRyDailyReportPageReqVO pageReqVO);
+
+    /**
+     * 审批瑞鹰日报
+     *
+     * @param updateReqVO 更新信息
+     */
+    void approvalRyDailyReport(IotRyDailyReportSaveReqVO updateReqVO);
 }

+ 119 - 3
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotrydailyreport/IotRyDailyReportServiceImpl.java

@@ -22,13 +22,24 @@ import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.depttype.IotDeptTypeMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotprojecttask.IotProjectTaskMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotrydailyreport.IotRyDailyReportMapper;
+import cn.iocoder.yudao.module.pms.message.PmsMessage;
+import cn.iocoder.yudao.module.supplier.enums.common.SupplierAuditStatusEnum;
+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.controller.admin.dept.vo.dept.DeptListReqVO;
 import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
 import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO;
+import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
+import cn.iocoder.yudao.module.system.dal.dataobject.permission.UserRoleDO;
+import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
+import cn.iocoder.yudao.module.system.dal.mysql.permission.UserRoleMapper;
 import cn.iocoder.yudao.module.system.service.dept.DeptService;
 import cn.iocoder.yudao.module.system.service.dict.DictTypeService;
+import cn.iocoder.yudao.module.system.service.permission.RoleService;
+import cn.iocoder.yudao.module.system.service.user.AdminUserService;
 import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
@@ -41,12 +52,14 @@ import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoUnit;
 import java.util.*;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
 import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.*;
+import static cn.iocoder.yudao.module.pms.framework.config.MultiThreadConfiguration.PMS_THREAD_POOL_TASK_EXECUTOR;
 
 
 /**
@@ -70,6 +83,18 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
     private DeptService deptService;
     @Resource
     private IotDeptTypeMapper iotDeptTypeMapper;
+    @Resource
+    private AdminUserService adminUserService;
+    @Resource
+    private RoleService roleService;
+    @Resource
+    private UserRoleMapper userRoleMapper;
+    @Resource
+    private AdminUserApi adminUserApi;
+    @Resource(name = PMS_THREAD_POOL_TASK_EXECUTOR)
+    private ThreadPoolTaskExecutor pmsThreadPoolTaskExecutor;
+    @Resource
+    private PmsMessage pmsMessage;
 
     @Override
     public Long createIotRyDailyReport(IotRyDailyReportSaveReqVO createReqVO) {
@@ -87,7 +112,10 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
             // 钻井类型日报必须 填写当前井深
             throw exception(IOT_RY_DAILY_REPORT_CURRENT_DEPTH_NOT_EXISTS);
         }
-
+        // 设置 日报填写状态 审核状态
+        iotRyDailyReport.setStatus(1);
+        // 设置 日报审批状态为 审批中 auditStatus = 10
+        iotRyDailyReport.setAuditStatus(10);
         // 根据日报的 施工队伍 deptId 查询队伍所在的 项目 任务
         // 根据日报的施工状态 更新 对应任务的 状态
         Long taskId = Long.MIN_VALUE;
@@ -96,8 +124,11 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         reqVO.setDeptId(createReqVO.getDeptId());
         // 查询包含当前日报施工队伍的任务
         List<IotProjectTaskDO> tasks = iotProjectTaskMapper.selectList(reqVO);
+        // 井号
+        String wellName = StrUtil.EMPTY;
         if (CollUtil.isNotEmpty(tasks)) {
             IotProjectTaskDO task = tasks.get(0);
+            wellName = task.getWellName();
             // 暂时只考虑1个施工队伍只属于1个任务
             iotRyDailyReport.setProjectId(task.getProjectId());
             iotRyDailyReport.setTaskId(task.getId());
@@ -180,6 +211,72 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
             iotRyDailyReport.setId(existReport.getId());
             iotRyDailyReportMapper.updateById(iotRyDailyReport);
         }
+        // 生成消息提醒 到 项目部审批人员 站内信 钉钉
+        Long deptId = createReqVO.getDeptId();
+        DeptDO dept = deptService.getDept(deptId);
+        Long parentId = dept.getParentId();
+        if (ObjUtil.isNotEmpty(parentId)) {
+            DeptDO projectDept = deptService.getDept(parentId);
+            // 查找队伍上级项目部 拥有‘项目部日报审批RY’角色 的审批人 如果查找不到 则使用 瑞鹰国际 下拥有‘项目部日报审批RY’角色的审批人
+            if (ObjUtil.isNotEmpty(projectDept) && "2".equals(projectDept.getType())) {
+                // 查询项目部下具有 项目部日报审批RH 角色的人员 如果查找不到 查询 瑞鹰国际下 拥有‘项目部日报审批RH’角色的审批人
+                // 瑞鹰国际 158
+                Set<Long> projectIds = new HashSet<>();
+                projectIds.add(projectDept.getId());
+                projectIds.add(158l);
+                List<AdminUserDO> receivedMsgUsers = adminUserService.getUserListByDeptIds(projectIds);
+                if (CollUtil.isNotEmpty(receivedMsgUsers)) {
+                    Set<Long> userIds = new HashSet<>();
+                    receivedMsgUsers.forEach(user -> {
+                        userIds.add(user.getId());
+                    });
+                    RoleDO role = roleService.getRoleByCode("项目部日报审批RY");
+                    if (ObjUtil.isNotEmpty(role)) {
+                        Set<Long> roleIds = new HashSet<>();
+                        roleIds.add(role.getId());
+                        List<UserRoleDO> userRoles = userRoleMapper.selectListByRoleIds(roleIds);
+                        if (CollUtil.isNotEmpty(userRoles)) {
+                            // 提取有审批角色的所有用户ID(去重+空值过滤)
+                            Set<Long> roleUserIds = userRoles.stream()
+                                    .map(UserRoleDO::getUserId)
+                                    .filter(Objects::nonNull) // 过滤空userId
+                                    .collect(Collectors.toSet());
+                            // 计算两个集合的交集,得到最终目标用户ID
+                            Set<Long> targetUserIds = userIds.stream()
+                                    .filter(roleUserIds::contains)
+                                    .collect(Collectors.toSet());
+                            // 异步发送 站内信 钉钉消息
+                            if (CollUtil.isNotEmpty(targetUserIds)) {
+                                Map<Long, AdminUserRespDTO> users = adminUserApi.getUserMap(targetUserIds);
+                                // 给多个用户发送 相同 的 提醒消息
+                                if (CollUtil.isNotEmpty(users)) {
+                                    // 生成消息提醒标题 部门名称-井号
+                                    String msgTitle = dept.getName();
+                                    if (StrUtil.isNotBlank(wellName)) {
+                                        msgTitle = StrUtil.join("-", msgTitle, wellName);
+                                    }
+                                    CountDownLatch latch = new CountDownLatch(users.size());
+                                    String finalMsgTitle = msgTitle;
+                                    users.forEach((userId, user) -> {
+                                        pmsThreadPoolTaskExecutor.execute(() -> {
+                                            try {
+                                                String mobile = user.getMobile();
+                                                if (StrUtil.isNotBlank(mobile) && StrUtil.isNotBlank(finalMsgTitle)) {
+                                                    /* pmsMessage.sendMessage(iotRyDailyReport.getId(), finalMsgTitle, PmsConstants.RY_DAILY_REPORT_APPROVAL,
+                                                            userId, mobile); */
+                                                }
+                                            } finally {
+                                                latch.countDown();
+                                            }
+                                        });
+                                    });
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
         // 返回
         return iotRyDailyReport.getId();
     }
@@ -201,10 +298,12 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         iotRyDailyReportMapper.deleteById(id);
     }
 
-    private void validateIotRyDailyReportExists(Long id) {
-        if (iotRyDailyReportMapper.selectById(id) == null) {
+    private IotRyDailyReportDO validateIotRyDailyReportExists(Long id) {
+        IotRyDailyReportDO dailyReport = iotRyDailyReportMapper.selectById(id);
+        if (ObjUtil.isEmpty(dailyReport)) {
             throw exception(IOT_RY_DAILY_REPORT_NOT_EXISTS);
         }
+        return dailyReport;
     }
 
     @Override
@@ -635,6 +734,23 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         return result;
     }
 
+    @Override
+    public void approvalRyDailyReport(IotRyDailyReportSaveReqVO updateReqVO) {
+        // 审核瑞恒日报
+        // 如果审批拒绝 修改日报 填报状态 status = 0 填写中  审批状态 auditStatus = 30
+        // 审批通过 设置 日报审批状态 auditStatus = 20
+        IotRyDailyReportDO dailyReport = validateIotRyDailyReportExists(updateReqVO.getId());
+        dailyReport.setAuditStatus(updateReqVO.getAuditStatus());
+        dailyReport.setOpinion(updateReqVO.getOpinion());
+        if (SupplierAuditStatusEnum.REJECT.getStatus().equals(updateReqVO.getAuditStatus())) {
+            dailyReport.setStatus(0);
+        } else {
+
+        }
+        // 更新瑞恒日报审核状态
+        iotRyDailyReportMapper.updateById(dailyReport);
+    }
+
     private List<IotDeviceDO> devices() {
         // 查询 瑞鹰158l 所有存在设备的队伍
         // 查询 瑞鹰 下所有部门