Browse Source

流程待办和结束发送短信

wangliang 1 năm trước cách đây
mục cha
commit
2640d32f4e

+ 45 - 14
sop-business/src/main/java/com/qmth/sop/business/activiti/listener/ProcessEventListener.java

@@ -58,8 +58,6 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
                 // 流程结束
                 log.info("流程结束_PROCESS_COMPLETED:ProcessInstanceId:{},ExecutionId:{},ProcessDefinitionId:{}", event.getProcessInstanceId(), event.getExecutionId(), event.getProcessDefinitionId());
                 HistoryService historyService = SpringContextHolder.getBean(HistoryService.class);
-                SmsSendUtil smsSendUtil = SpringContextHolder.getBean(SmsSendUtil.class);
-                SysUserService sysUserService = SpringContextHolder.getBean(SysUserService.class);
 
                 List<HistoricVariableInstance> historicVariableInstanceList = historyService.createHistoricVariableInstanceQuery().processInstanceId(event.getProcessInstanceId()).list();
                 if (!CollectionUtils.isEmpty(historicVariableInstanceList)) {
@@ -80,23 +78,13 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
                             Optional.ofNullable(tfFlowApprove).orElseThrow(() -> ExceptionResultEnum.FLOW_APPROVE_NO_DATA.exception());
                         }
                     }
-                    if ((tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW
-                            || tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW
-                            || tfCustomFlow.getType() == TFCustomTypeEnum.DING_EXCEPTION_FLOW
-                            || tfCustomFlow.getType() == TFCustomTypeEnum.PROJECT_EXCHANGE_FLOW) &&
-                            tfFlowApprove.getStatus() == FlowStatusEnum.FINISH) {
-                        SysUser sysUser = sysUserService.getById(tfCustomFlowEntity.getCreateId());
-                        Optional.ofNullable(sysUser).orElseThrow(() -> ExceptionResultEnum.USER_NO_EXISTS.exception());
-
-                        Map<String, Object> templateParam = new HashMap<>();
-                        templateParam.put("code", "test");
-                        smsSendUtil.sendSms(sysUser.getMobileNumber(), SystemConstant.SMS_TPL_CODE, templateParam);
-                    }
+                    this.sendFlowFinishSms(tfCustomFlow.getType(), tfFlowApprove.getStatus(), tfCustomFlowEntity.getCreateId());
                 }
                 break;
             case TASK_CREATED:
                 log.info("流程任务创建_TASK_CREATED:ProcessInstanceId:{},ExecutionId:{},ProcessDefinitionId:{}", event.getProcessInstanceId(), event.getExecutionId(), event.getProcessDefinitionId());
                 TaskService taskService = SpringContextHolder.getBean(TaskService.class);
+
                 TSJobRemindService jobRemindService = SpringContextHolder.getBean(TSJobRemindService.class);
                 ActivitiEntityEvent activitiEntityEvent = (ActivitiEntityEvent) event;
                 if (activitiEntityEvent.getEntity() instanceof Task) {
@@ -124,11 +112,13 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
                             List<TSJobRemind> tsJobRemindArrayList = new ArrayList<>();
                             if (Objects.nonNull(task.getAssignee())) {
                                 tsJobRemindArrayList.add(new TSJobRemind(JobQuartzTypeEnum.FLOW, tfCustomFlowEntity.getCode(), Long.parseLong(task.getId()), tfCustomFlow.getType().getTitle() + ";" + task.getName(), JobTypeEnum.AFTER, Long.parseLong(task.getAssignee()), tfFlowLog.getApproveOperation(), sysUser.getId()));
+                                this.sendSopFlowDoneSms(tfCustomFlow.getType(), Long.parseLong(task.getAssignee()));
                             } else {
                                 List<IdentityLink> identityLinkList = taskService.getIdentityLinksForTask(task.getId());
                                 if (!CollectionUtils.isEmpty(identityLinkList)) {
                                     for (IdentityLink i : identityLinkList) {
                                         tsJobRemindArrayList.add(new TSJobRemind(JobQuartzTypeEnum.FLOW, tfCustomFlowEntity.getCode(), Long.parseLong(i.getTaskId()), tfCustomFlow.getType().getTitle() + ";" + task.getName(), JobTypeEnum.AFTER, Long.parseLong(i.getUserId()), tfFlowLog.getApproveOperation(), sysUser.getId()));
+                                        this.sendSopFlowDoneSms(tfCustomFlow.getType(), Long.parseLong(i.getUserId()));
                                     }
                                 }
                             }
@@ -326,4 +316,45 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
         }
         SystemConstant.FLOW_MAP.add(resourceEntity.getDeploymentId() + SystemConstant.BPMN_PREFIX, xml);
     }
+
+    /**
+     * 发送流程待办短信
+     *
+     * @param type
+     * @param userId
+     */
+    protected void sendSopFlowDoneSms(TFCustomTypeEnum type, Long userId) {
+        SysUserService sysUserService = SpringContextHolder.getBean(SysUserService.class);
+        SmsSendUtil smsSendUtil = SpringContextHolder.getBean(SmsSendUtil.class);
+        if (type == TFCustomTypeEnum.OFFICE_SOP_FLOW || type == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW) {//发送待审批短信
+            Map<String, Object> templateParam = new HashMap<>();
+            templateParam.put("code", "test");
+            SysUser sysUser = sysUserService.getById(userId);
+            Optional.ofNullable(sysUser).orElseThrow(() -> ExceptionResultEnum.USER_NO_EXISTS.exception());
+            smsSendUtil.sendSms(sysUser.getMobileNumber(), SystemConstant.SMS_TPL_CODE, templateParam);
+        }
+    }
+
+    /**
+     * 发送流程结束短信
+     *
+     * @param type
+     * @param status
+     * @param userId
+     */
+    protected void sendFlowFinishSms(TFCustomTypeEnum type, FlowStatusEnum status, Long userId) {
+        SysUserService sysUserService = SpringContextHolder.getBean(SysUserService.class);
+        SmsSendUtil smsSendUtil = SpringContextHolder.getBean(SmsSendUtil.class);
+
+        if ((type == TFCustomTypeEnum.DING_EXCEPTION_FLOW
+                || type == TFCustomTypeEnum.PROJECT_EXCHANGE_FLOW) &&
+                status == FlowStatusEnum.FINISH) {//流程结束发送短信
+            SysUser sysUser = sysUserService.getById(userId);
+            Optional.ofNullable(sysUser).orElseThrow(() -> ExceptionResultEnum.USER_NO_EXISTS.exception());
+
+            Map<String, Object> templateParam = new HashMap<>();
+            templateParam.put("code", "test");
+            smsSendUtil.sendSms(sysUser.getMobileNumber(), SystemConstant.SMS_TPL_CODE, templateParam);
+        }
+    }
 }