Zimo 1 сар өмнө
parent
commit
a68703afd5

+ 60 - 3
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/expression/BpmTaskPostExpression.java

@@ -39,12 +39,15 @@ public class BpmTaskPostExpression {
     @Autowired
     private PostApi postApi;
 
-
-    public Set<Long> calculateUsers(DelegateExecution execution, int level) {
+    public Set<Long> calculateUsers(DelegateExecution execution, int level,String type) {
         Assert.isTrue(level>0, "leve必须大于0");
         ProcessInstance processInstance = processInstanceService.getProcessInstance(execution.getProcessInstanceId());
         Long startId = NumberUtils.parseLong(processInstance.getStartUserId());
         DeptRespDTO dept = null;
+        String companyCode = getCompanyCode(startId);
+        if ("qhse-bz".equals(type)&&"rh".equals(companyCode)) {
+            level = level+1;
+        }
         for (int i = 0; i < level; i++) {
             // 获得 level 对应的部门
             if (dept == null) {
@@ -60,11 +63,16 @@ public class BpmTaskPostExpression {
                 dept = parentDept;
             }
         }
+        if (dept == null) {
+            DeptRespDTO parentDept = deptApi.getDept(dept.getParentId());
+            // 找不到父级部门,所以只好结束寻找。原因是:例如说,级别比较高的人,所在部门层级比较少
+            dept = parentDept;
+        }
         if (dept == null) {
             throw new ServiceException(new ErrorCode(12,"部门不存在"));
         }
         Long deptId = dept.getId();
-        List<DictDataRespDTO> dictDataList = dictDataApi.getDictDataList("failure_report_post");
+        List<DictDataRespDTO> dictDataList = dictDataApi.getDictDataList(type);
         if (CollUtil.isEmpty(dictDataList)) {
             throw new ServiceException();
         }
@@ -93,4 +101,53 @@ public class BpmTaskPostExpression {
         }
         return deptApi.getDept(startUser.getDeptId());
     }
+
+    private String getCompanyCode(Long deptId) {
+        DeptRespDTO dept = deptApi.getDeptNoPermission(deptId);
+        String name = dept.getName();
+        String companyCode = "";
+        if (name.contains("瑞恒")) {
+            companyCode = "rh";
+        } else if (name.contains("瑞都")) {
+            companyCode = "rd";
+        } else if (name.contains("瑞鹰")) {
+            companyCode = "ry";
+        } else if (name.contains("科瑞石油技术")) {
+            companyCode = "jt";
+        } else {
+            Long parentId = dept.getParentId();
+            DeptRespDTO dept1 = deptApi.getDeptNoPermission(parentId);
+            String name1 = dept1.getName();
+            if (name1.contains("瑞恒")) {
+                companyCode = "rh";
+            } else if (name1.contains("瑞都")) {
+                companyCode = "rd";
+            } else if (name1.contains("瑞鹰")) {
+                companyCode = "ry";
+            } else if (name1.contains("科瑞石油技术")) {
+                companyCode = "jt";
+            } else {
+                DeptRespDTO dept2 = deptApi.getDeptNoPermission(dept1.getParentId());
+                String name2 = dept2.getName();
+                if (name2.contains("瑞恒")) {
+                    companyCode = "rh";
+                } else if (name2.contains("瑞都")) {
+                    companyCode = "rd";
+                } else if (name2.contains("瑞鹰")) {
+                    companyCode = "ry";
+                } else {
+                    DeptRespDTO dept3= deptApi.getDeptNoPermission(dept2.getParentId());
+                    String name3 = dept3.getName();
+                    if (name3.contains("瑞恒")) {
+                        companyCode = "rh";
+                    } else if (name3.contains("瑞都")) {
+                        companyCode = "rd";
+                    } else if (name3.contains("瑞鹰")) {
+                        companyCode = "ry";
+                    }
+                }
+            }
+        }
+        return companyCode;
+    }
 }

+ 8 - 0
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/message/BpmMessageServiceImpl.java

@@ -104,6 +104,14 @@ public class BpmMessageServiceImpl implements BpmMessageService {
                     .setUserId(reqDTO.getAssigneeUserId()).setTemplateCode(templateCode).setTemplateParams(templateParams));
             msg = "您有新的委外维修流程,请审批。"+"["+ DateUtil.format(new Date(),"yyyy-MM-dd hh:mm:ss")+"]";
             url=systemUrl + "dingding?id="+reqDTO.getProcessInstanceId()+"&type=maintainOut&userId="+reqDTO.getAssigneeUserId();
+        } else if ("QHSE事故上报".equals(reqDTO.getProcessInstanceName())){
+            String templateCode = "qhse-accident";
+            templateParams.put("businessType", "qhseAccident");
+            templateParams.put("businessId", reqDTO.getProcessInstanceId());
+            templateParams.put("processcode", reqDTO.getProcessInstanceId());
+            notifyMessageSendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
+                    .setUserId(reqDTO.getAssigneeUserId()).setTemplateCode(templateCode).setTemplateParams(templateParams));
+            url=systemUrl + "dingding?id="+reqDTO.getProcessInstanceId()+"&type=qhseAccident&userId="+reqDTO.getAssigneeUserId();
         }
         dingtalkSendApi.send(user.getMobile(), msg,"link",url);
     }

+ 7 - 1
yudao-module-pms/yudao-module-pms-biz/pom.xml

@@ -140,7 +140,13 @@
             <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
             <version>1.2.5</version>
         </dependency>
-<!--        <dependency>-->
+        <dependency>
+            <groupId>org.flowable</groupId>
+            <artifactId>flowable-engine</artifactId>
+            <version>6.8.0</version>
+            <scope>compile</scope>
+        </dependency>
+        <!--        <dependency>-->
 <!--            <groupId>javax.sip</groupId>-->
 <!--            <artifactId>jain-sip-ri</artifactId>-->
 <!--            <version>1.3.0-91</version>-->

+ 1 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/qhse/accident/vo/IotAccidentReportRespVO.java

@@ -82,5 +82,5 @@ public class IotAccidentReportRespVO {
     @Schema(description = "备注", example = "随便")
     @ExcelProperty("备注")
     private String remark;
-
+    private String processInstanceId;
 }

+ 4 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/qhse/accident/IotAccidentReportDO.java

@@ -92,5 +92,8 @@ public class IotAccidentReportDO extends BaseDO {
      * 备注
      */
     private String remark;
-
+    /**
+     * 流程实例id
+     */
+    private String processInstanceId;
 }

+ 23 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/listener/AccidentBpmStatusListener.java

@@ -0,0 +1,23 @@
+package cn.iocoder.yudao.module.pms.listener;
+
+import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceStatusEvent;
+import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceStatusEventListener;
+import cn.iocoder.yudao.module.pms.service.qhse.accident.IotAccidentReportServiceImpl;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+
+@Component
+public class AccidentBpmStatusListener extends BpmProcessInstanceStatusEventListener {
+    @Resource
+    private IotAccidentReportServiceImpl iotAccidentReportService;
+    @Override
+    protected String getProcessDefinitionKey() {
+        return "qhse-accident";
+    }
+
+    @Override
+    protected void onEvent(BpmProcessInstanceStatusEvent event) {
+        iotAccidentReportService.approvalAccidentFlow(Long.parseLong(event.getBusinessKey()), event.getStatus());
+    }
+}

+ 31 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/listener/AccidentSpringExpressionExecutionListener.java

@@ -0,0 +1,31 @@
+package cn.iocoder.yudao.module.pms.listener;
+
+import cn.iocoder.yudao.framework.common.exception.ErrorCode;
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
+import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.accident.IotAccidentReportDO;
+import cn.iocoder.yudao.module.pms.dal.mysql.qhse.accident.IotAccidentReportMapper;
+import lombok.extern.slf4j.Slf4j;
+import org.flowable.engine.delegate.DelegateExecution;
+import org.springframework.stereotype.Component;
+
+@Component
+@Slf4j
+public class AccidentSpringExpressionExecutionListener {
+
+    private final IotAccidentReportMapper iotAccidentReportMapper;
+
+    public AccidentSpringExpressionExecutionListener(IotAccidentReportMapper iotAccidentReportMapper) {
+        this.iotAccidentReportMapper = iotAccidentReportMapper;
+    }
+
+    public void execute(DelegateExecution execution) {
+        //最后一步执行完成之后处理更新状态
+        String processInstanceBusinessKey = execution.getProcessInstanceBusinessKey();
+
+        IotAccidentReportDO iotAccidentReportDO = iotAccidentReportMapper.selectById(processInstanceBusinessKey);
+        if (iotAccidentReportDO == null) {throw new ServiceException(new ErrorCode(22,"不存在事故上报信息"));}
+        iotAccidentReportDO.setStatus("finished");
+        iotAccidentReportMapper.updateById(iotAccidentReportDO);
+    }
+
+}

+ 1 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/qhse/accident/IotAccidentReportService.java

@@ -14,6 +14,7 @@ import java.util.Set;
  * @author 超级管理员
  */
 public interface IotAccidentReportService {
+    void approvalAccidentFlow(Long id, Integer bpmResult);
     Set<Long> getDeptIdCompany(Long deviceDept);
     void approvalAccident(Long id, String suggestion);
     /**

+ 43 - 23
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/qhse/accident/IotAccidentReportServiceImpl.java

@@ -6,6 +6,8 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
+import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
+import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
 import cn.iocoder.yudao.module.pms.controller.admin.qhse.accident.vo.IotAccidentReportPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.qhse.accident.vo.IotAccidentReportSaveReqVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.accident.IotAccidentReportDO;
@@ -27,12 +29,10 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
-import java.time.LocalDateTime;
 import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 import java.util.Set;
-import java.util.stream.Collectors;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 
@@ -59,6 +59,8 @@ public class IotAccidentReportServiceImpl implements IotAccidentReportService {
     private PostApi postApi;
     @Autowired
     private IotAccidentReportProcessMapper iotAccidentReportProcessMapper;
+    @Resource
+    private BpmProcessInstanceApi processInstanceApi;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -114,10 +116,23 @@ public class IotAccidentReportServiceImpl implements IotAccidentReportService {
             });
         }
         iotAccidentReportProcessMapper.insert(processDO);
+
         iotAccidentReportMapper.updateById(iotAccidentReportDO);
 
     }
 
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void approvalAccidentFlow(Long id, Integer bpmResult) {
+//        IotAccidentReportDO iotAccidentReportDO = iotAccidentReportMapper.selectById(id);
+//        if (iotAccidentReportDO == null) {throw new ServiceException(new ErrorCode(111,"不存在事故上报信息"));}
+//        if(bpmResult ==2 ){
+//            iotAccidentReportDO.setStatus("finished");
+//            iotAccidentReportMapper.updateById(iotAccidentReportDO);
+//        }
+    }
+
     public Set<Long> getDeptIdCompany(Long deviceDept) {
         List<DeptRespDTO> rhdept = deptApi.getDeptByNamePermission("瑞恒兴域");
         Set<Long> rhDeptIds = Collections.emptySet();
@@ -168,28 +183,33 @@ public class IotAccidentReportServiceImpl implements IotAccidentReportService {
         iotAccidentReport.setDeleted(false);
         iotAccidentReport.setFlowStatus("2");
         //获取当前部门的上一级部门也就是项目部的项目经理
-        Long parentId = dept.getParentId();
-        List<AdminUserRespDTO> parentDeptUsers = adminUserApi.getUserListByDeptIdsNew(Collections.singleton(parentId));
-        List<Long> projectUserIds = roleApi.getRoleUserIds("项目经理");
-        Set<Long> currentUserIds = parentDeptUsers.stream().map(AdminUserRespDTO::getId)
-                .filter(projectUserIds::contains)
-                .collect(Collectors.toSet());
-        if (CollUtil.isEmpty(currentUserIds)){
-            throw new ServiceException(new ErrorCode(22,"未找到项目经理,无法完成事故上报"));
-        }
-        iotAccidentReport.setCurrentPerson(Collections.singleton(currentUserIds.stream().findFirst().get()));
+//        Long parentId = dept.getParentId();
+//        List<AdminUserRespDTO> parentDeptUsers = adminUserApi.getUserListByDeptIdsNew(Collections.singleton(parentId));
+//        List<Long> projectUserIds = roleApi.getRoleUserIds("项目经理");
+//        Set<Long> currentUserIds = parentDeptUsers.stream().map(AdminUserRespDTO::getId)
+//                .filter(projectUserIds::contains)
+//                .collect(Collectors.toSet());
+//        if (CollUtil.isEmpty(currentUserIds)){
+//            throw new ServiceException(new ErrorCode(22,"未找到项目经理,无法完成事故上报"));
+//        }
+//        iotAccidentReport.setCurrentPerson(Collections.singleton(currentUserIds.stream().findFirst().get()));
         iotAccidentReportMapper.insert(iotAccidentReport);
-        //插入流程明细表
-        IotAccidentReportProcessDO processDO = new IotAccidentReportProcessDO();
-        processDO.setAccidentId(iotAccidentReport.getId());
-        String loginUserNickname = SecurityFrameworkUtils.getLoginUserNickname();
-        processDO.setOperator(loginUserNickname);
-        processDO.setDescription("发起事故事件上报");
-        processDO.setNodeName("发起人");
-        processDO.setDeleted(false);
-        processDO.setCreateTime(LocalDateTime.now());
-        processDO.setStatus("提交上报");
-        iotAccidentReportProcessMapper.insert(processDO);
+//        //插入流程明细表
+//        IotAccidentReportProcessDO processDO = new IotAccidentReportProcessDO();
+//        processDO.setAccidentId(iotAccidentReport.getId());
+//        String loginUserNickname = SecurityFrameworkUtils.getLoginUserNickname();
+//        processDO.setOperator(loginUserNickname);
+//        processDO.setDescription("发起事故事件上报");
+//        processDO.setNodeName("发起人");
+//        processDO.setDeleted(false);
+//        processDO.setCreateTime(LocalDateTime.now());
+//        processDO.setStatus("提交上报");
+//        iotAccidentReportProcessMapper.insert(processDO);
+        String processInstanceId;
+        processInstanceId = processInstanceApi.createProcessInstance(SecurityFrameworkUtils.getLoginUserId(),
+                new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey("qhse-accident").setBusinessKey(String.valueOf(iotAccidentReport.getId())));
+
+        iotAccidentReportMapper.updateById(new IotAccidentReportDO().setId(iotAccidentReport.getId()).setProcessInstanceId(processInstanceId));
         // 返回
         return iotAccidentReport.getId();
     }