Просмотр исходного кода

新增sop编辑log,延期预警跨节点和流程结束不预警

wangliang 1 год назад
Родитель
Сommit
b3c54fbc5d

+ 0 - 19
sop-business/src/main/java/com/qmth/sop/business/entity/TBSopLog.java

@@ -9,7 +9,6 @@ import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
 import java.io.Serializable;
-import java.util.Objects;
 
 /**
  * <p>
@@ -71,24 +70,6 @@ public class TBSopLog implements Serializable {
         this.createTime = System.currentTimeMillis();
     }
 
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) {
-            return true;
-        }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-        TBSopLog tbSopLog = (TBSopLog) o;
-        return sopId.equals(tbSopLog.sopId) && updateBeforeObj.equals(tbSopLog.updateBeforeObj)
-                && updateAfterObj.equals(tbSopLog.updateAfterObj);
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(sopId, updateBeforeObj, updateAfterObj);
-    }
-
     public Long getId() {
         return id;
     }

+ 27 - 28
sop-business/src/main/java/com/qmth/sop/business/entity/TSJobRemind.java

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.FlowApproveOperationEnum;
+import com.qmth.sop.common.enums.FlowStatusEnum;
 import com.qmth.sop.common.enums.JobQuartzTypeEnum;
 import com.qmth.sop.common.enums.JobTypeEnum;
 import io.swagger.annotations.ApiModel;
@@ -34,6 +35,12 @@ public class TSJobRemind implements Serializable {
     @ApiModelProperty(value = "编码")
     private String code;
 
+    @ApiModelProperty(value = "流程步骤")
+    private Integer setup;
+
+    @ApiModelProperty(value = "状态,START:已开始,AUDITING:审核中,REJECT:已驳回,END:已终止,FINISH:已结束")
+    private FlowStatusEnum status;
+
     @ApiModelProperty(value = "实体id")
     @JsonSerialize(using = ToStringSerializer.class)
     private Long objId;
@@ -74,19 +81,9 @@ public class TSJobRemind implements Serializable {
 
     }
 
-    public TSJobRemind(JobQuartzTypeEnum type, Long objId, String objName, JobTypeEnum remindType, Long userId, String crmNo) {
-        this.id = SystemConstant.getDbUuid();
-        this.type = type;
-        this.objId = objId;
-        this.objName = objName;
-        this.remindType = remindType;
-        this.createId = userId;
-        this.createTime = System.currentTimeMillis();
-        this.enable = true;
-        this.crmNo = crmNo;
-    }
-
-    public TSJobRemind(JobQuartzTypeEnum type, String code, Long objId, String objName, JobTypeEnum remindType, Long receiveUserId, FlowApproveOperationEnum approveOperation, Long userId, String crmNo) {
+    public TSJobRemind(JobQuartzTypeEnum type, String code, Long objId, String objName, JobTypeEnum remindType,
+            Long receiveUserId, FlowApproveOperationEnum approveOperation, Long createTime, String execField,
+            Long userId, String crmNo, Integer setup, FlowStatusEnum status) {
         this.id = SystemConstant.getDbUuid();
         this.type = type;
         this.code = code;
@@ -96,26 +93,28 @@ public class TSJobRemind implements Serializable {
         this.receiveUserId = receiveUserId;
         this.approveOperation = approveOperation;
         this.createId = userId;
-        this.createTime = System.currentTimeMillis();
+        this.createTime = createTime;
+        this.execField = execField;
         this.enable = true;
         this.crmNo = crmNo;
+        this.setup = setup;
+        this.status = status;
     }
 
+    public Integer getSetup() {
+        return setup;
+    }
 
-    public TSJobRemind(JobQuartzTypeEnum type, String code, Long objId, String objName, JobTypeEnum remindType, Long receiveUserId, FlowApproveOperationEnum approveOperation, Long createTime, String execField, Long userId, String crmNo) {
-        this.id = SystemConstant.getDbUuid();
-        this.type = type;
-        this.code = code;
-        this.objId = objId;
-        this.objName = objName;
-        this.remindType = remindType;
-        this.receiveUserId = receiveUserId;
-        this.approveOperation = approveOperation;
-        this.createId = userId;
-        this.createTime = createTime;
-        this.execField = execField;
-        this.enable = true;
-        this.crmNo = crmNo;
+    public void setSetup(Integer setup) {
+        this.setup = setup;
+    }
+
+    public FlowStatusEnum getStatus() {
+        return status;
+    }
+
+    public void setStatus(FlowStatusEnum status) {
+        this.status = status;
     }
 
     public String getCrmNo() {

+ 8 - 0
sop-business/src/main/java/com/qmth/sop/business/mapper/TSJobRemindMapper.java

@@ -35,4 +35,12 @@ public interface TSJobRemindMapper extends BaseMapper<TSJobRemind> {
      * @return
      */
     List<WorkTaskResult> getJobRemindProcessHour(@Param("userId") Long userId, @Param("sopNoSet") Set<String> sopNoSet);
+
+    /**
+     * 根据enable查询
+     *
+     * @param enable
+     * @return
+     */
+    List<TSJobRemind> getJobRemindEnable(@Param("enable") Boolean enable);
 }

+ 7 - 0
sop-business/src/main/java/com/qmth/sop/business/service/TSJobRemindService.java

@@ -58,4 +58,11 @@ public interface TSJobRemindService extends IService<TSJobRemind> {
      * @return
      */
     List<WorkTaskResult> getJobRemindProcessHour(Long userId, Set<String> sopNoSet);
+
+    /**
+     * 根据enable查询
+     *
+     * @return
+     */
+    List<TSJobRemind> getJobRemindEnable(Boolean enable);
 }

+ 18 - 19
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBSopInfoServiceImpl.java

@@ -378,18 +378,13 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
             tbSopInfoService.saveJobRemind(map);
 
             //新增sop日志
-            if (tbSopInfo.getStatus() == SopStatusEnum.START) {
-                TFFlowApprove tfFlowApprove = (TFFlowApprove) map.get(SystemConstant.FLOW_APPROVE);
-                Optional.ofNullable(tfFlowApprove)
-                        .orElseThrow(() -> ExceptionResultEnum.FLOW_APPROVE_NO_DATA.exception());
+            TFFlowApprove tfFlowApprove = (TFFlowApprove) map.get(SystemConstant.FLOW_APPROVE);
+            Optional.ofNullable(tfFlowApprove).orElseThrow(() -> ExceptionResultEnum.FLOW_APPROVE_NO_DATA.exception());
 
-                TBSopLog tbSopLog = new TBSopLog(tbSopInfo.getId(), SopLogTypeEnum.APPROVE, tfFlowApprove.getStatus(),
-                        tfFlowApprove.getSetup(), oldFlowProcessVar, tfCustomFlowEntity.getFlowProcessVar(),
-                        sysUser.getId());
-                if (tbSopLog.equals(tbSopLog)) {
-                    tbSopLogService.save(tbSopLog);
-                }
-            }
+            TBSopLog tbSopLog = new TBSopLog(tbSopInfo.getId(), SopLogTypeEnum.APPROVE, tfFlowApprove.getStatus(),
+                    tfFlowApprove.getSetup(), oldFlowProcessVar, tfCustomFlowEntity.getFlowProcessVar(),
+                    sysUser.getId());
+            tbSopLogService.save(tbSopLog);
         }
         TFFlowApprove tfFlowApprove = (TFFlowApprove) map.get(SystemConstant.FLOW_APPROVE);
         tbSopInfo.setStatus(
@@ -1108,11 +1103,13 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
                         tsJobRemindList.add(new TSJobRemind(JobQuartzTypeEnum.FLOW, tfCustomFlowEntity.getCode(),
                                 Long.parseLong(task.getId()), tfCustomFlow.getType().getTitle() + ";" + task.getName(),
                                 JobTypeEnum.BEFORE, Long.parseLong(task.getAssignee()), tfFlowLog.getApproveOperation(),
-                                processLimitedTime, execField, sysUser.getId(), tfCustomFlowEntity.getCrmNo()));
+                                processLimitedTime, execField, sysUser.getId(), tfCustomFlowEntity.getCrmNo(),
+                                tfFlowApprove.getSetup(), tfFlowApprove.getStatus()));
                         tsJobRemindList.add(new TSJobRemind(JobQuartzTypeEnum.FLOW, tfCustomFlowEntity.getCode(),
                                 Long.parseLong(task.getId()), tfCustomFlow.getType().getTitle() + ";" + task.getName(),
                                 JobTypeEnum.AFTER, Long.parseLong(task.getAssignee()), tfFlowLog.getApproveOperation(),
-                                processLimitedTime, execField, sysUser.getId(), tfCustomFlowEntity.getCrmNo()));
+                                processLimitedTime, execField, sysUser.getId(), tfCustomFlowEntity.getCrmNo(),
+                                tfFlowApprove.getSetup(), tfFlowApprove.getStatus()));
                     } else {
                         List<IdentityLink> identityLinkList = taskService.getIdentityLinksForTask(task.getId());
                         if (!CollectionUtils.isEmpty(identityLinkList)) {
@@ -1123,14 +1120,16 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
                                                 tfCustomFlow.getType().getTitle() + ";" + task.getName(),
                                                 JobTypeEnum.BEFORE, Long.parseLong(i.getUserId()),
                                                 tfFlowLog.getApproveOperation(), processLimitedTime, execField,
-                                                sysUser.getId(), tfCustomFlowEntity.getCrmNo()));
+                                                sysUser.getId(), tfCustomFlowEntity.getCrmNo(),
+                                                tfFlowApprove.getSetup(), tfFlowApprove.getStatus()));
                                 tsJobRemindList.add(
                                         new TSJobRemind(JobQuartzTypeEnum.FLOW, tfCustomFlowEntity.getCode(),
                                                 Long.parseLong(i.getTaskId()),
                                                 tfCustomFlow.getType().getTitle() + ";" + task.getName(),
                                                 JobTypeEnum.AFTER, Long.parseLong(i.getUserId()),
                                                 tfFlowLog.getApproveOperation(), processLimitedTime, execField,
-                                                sysUser.getId(), tfCustomFlowEntity.getCrmNo()));
+                                                sysUser.getId(), tfCustomFlowEntity.getCrmNo(),
+                                                tfFlowApprove.getSetup(), tfFlowApprove.getStatus()));
                             }
                         }
                     }
@@ -1332,10 +1331,10 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
                     sysUser.getId());
 
             //新增sop日志
-            TBSopLog tbSopLog = new TBSopLog(tbSopInfo.getId(), SopLogTypeEnum.EDIT, tfFlowApprove.getStatus(),
-                    tfFlowApprove.getSetup(), oldFlowProcessVar, tfCustomFlowEntity.getFlowProcessVar(),
-                    sysUser.getId());
-            if (tbSopLog.equals(tbSopLog)) {
+            if (!Objects.equals(oldFlowProcessVar, tfCustomFlowEntity.getFlowProcessVar())) {
+                TBSopLog tbSopLog = new TBSopLog(tbSopInfo.getId(), SopLogTypeEnum.EDIT, tfFlowApprove.getStatus(),
+                        tfFlowApprove.getSetup(), oldFlowProcessVar, tfCustomFlowEntity.getFlowProcessVar(),
+                        sysUser.getId());
                 tbSopLogService.save(tbSopLog);
             }
         }

+ 14 - 5
sop-business/src/main/java/com/qmth/sop/business/service/impl/TSJobRemindServiceImpl.java

@@ -47,8 +47,7 @@ public class TSJobRemindServiceImpl extends ServiceImpl<TSJobRemindMapper, TSJob
     @Override
     @Transactional(propagation = Propagation.REQUIRES_NEW)
     public Boolean updateJobRemind(Long taskId) {
-        return this.update(new UpdateWrapper<TSJobRemind>().lambda()
-                .eq(TSJobRemind::getObjId, taskId)
+        return this.update(new UpdateWrapper<TSJobRemind>().lambda().eq(TSJobRemind::getObjId, taskId)
                 .set(TSJobRemind::getEnable, false));
     }
 
@@ -61,9 +60,8 @@ public class TSJobRemindServiceImpl extends ServiceImpl<TSJobRemindMapper, TSJob
     @Override
     @Transactional(propagation = Propagation.REQUIRES_NEW)
     public Boolean updateJobRemind(String crmNo) {
-        return this.update(new UpdateWrapper<TSJobRemind>().lambda()
-                .eq(TSJobRemind::getCrmNo, crmNo).eq(TSJobRemind::getType, JobQuartzTypeEnum.FLOW)
-                .set(TSJobRemind::getEnable, false));
+        return this.update(new UpdateWrapper<TSJobRemind>().lambda().eq(TSJobRemind::getCrmNo, crmNo)
+                .eq(TSJobRemind::getType, JobQuartzTypeEnum.FLOW).set(TSJobRemind::getEnable, false));
     }
 
     /**
@@ -88,4 +86,15 @@ public class TSJobRemindServiceImpl extends ServiceImpl<TSJobRemindMapper, TSJob
     public List<WorkTaskResult> getJobRemindProcessHour(Long userId, Set<String> sopNoSet) {
         return this.baseMapper.getJobRemindProcessHour(userId, sopNoSet);
     }
+
+    /**
+     * 根据enable查询
+     *
+     * @param enable
+     * @return
+     */
+    @Override
+    public List<TSJobRemind> getJobRemindEnable(Boolean enable) {
+        return this.baseMapper.getJobRemindEnable(enable);
+    }
 }

+ 4 - 0
sop-business/src/main/resources/db/log/wangliang_update_log.sql

@@ -2480,3 +2480,7 @@ CREATE INDEX t_f_flow_approve_flow_id_IDX USING BTREE ON t_f_flow_approve (flow_
 ALTER TABLE t_f_custom_flow_entity DROP INDEX t_f_custom_flow_entity_UN_code;
 CREATE INDEX t_f_custom_flow_entity_code_IDX USING BTREE ON t_f_custom_flow_entity (code);
 
+ALTER TABLE t_s_job_remind ADD setup INT NOT NULL COMMENT '计划步骤';
+ALTER TABLE t_s_job_remind CHANGE setup setup INT NOT NULL COMMENT '计划步骤' AFTER code;
+ALTER TABLE t_s_job_remind ADD status varchar(50) NULL COMMENT '状态,START:已开始,AUDITING:审核中,REJECT:已驳回,END:已终止,FINISH:已结束';
+ALTER TABLE t_s_job_remind CHANGE status status varchar(50) NULL COMMENT '状态,START:已开始,AUDITING:审核中,REJECT:已驳回,END:已终止,FINISH:已结束' AFTER setup;

+ 4 - 0
sop-business/src/main/resources/mapper/TSJobRemindMapper.xml

@@ -50,4 +50,8 @@
             tsjr.code,
             tsjr.exec_time
     </select>
+
+    <select id="getJobRemindEnable" resultType="com.qmth.sop.business.entity.TSJobRemind">
+        select jsjr.* from t_s_job_remind jsjr left join t_s_job_log tsjl on jsjr.id  = tsjl.job_remind_id where jsjr.enable = #{enable}
+    </select>
 </mapper>

+ 80 - 50
sop-task/src/main/java/com/qmth/sop/task/job/RemindTaskJob.java

@@ -2,12 +2,8 @@ package com.qmth.sop.task.job;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qmth.sop.business.bean.result.FlowTaskSmsResult;
-import com.qmth.sop.business.entity.SysMessage;
-import com.qmth.sop.business.entity.SysUser;
-import com.qmth.sop.business.entity.TSJobRemind;
-import com.qmth.sop.business.service.SysMessageService;
-import com.qmth.sop.business.service.SysUserService;
-import com.qmth.sop.business.service.TSJobRemindService;
+import com.qmth.sop.business.entity.*;
+import com.qmth.sop.business.service.*;
 import com.qmth.sop.business.util.SmsSendUtil;
 import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.*;
@@ -30,6 +26,7 @@ import java.util.*;
  * @Date: 2021/7/9
  */
 public class RemindTaskJob extends QuartzJobBean {
+
     private final static Logger log = LoggerFactory.getLogger(RemindTaskJob.class);
 
     @Resource
@@ -44,6 +41,12 @@ public class RemindTaskJob extends QuartzJobBean {
     @Resource
     SysMessageService sysMessageService;
 
+    @Resource
+    TFCustomFlowEntityService tfCustomFlowEntityService;
+
+    @Resource
+    TFFlowApproveService tfFlowApproveService;
+
     @Override
     @Transactional
     public void executeInternal(JobExecutionContext context) throws JobExecutionException {
@@ -55,54 +58,81 @@ public class RemindTaskJob extends QuartzJobBean {
                 TSJobRemind tsJobRemind = tsJobRemindService.getById(tsJobRemindTask.getId());
                 if (Objects.nonNull(tsJobRemind)) {//数据还在则说明要发送提醒短信
                     if (tsJobRemind.getType() == JobQuartzTypeEnum.FLOW) {//流程发送短信
-                        FlowTaskSmsResult flowTaskSmsResult = tsJobRemindService.getFlowTaskRemindSmsInfo(tsJobRemind.getId());
-                        Optional.ofNullable(flowTaskSmsResult).orElseThrow(() -> ExceptionResultEnum.USER_NO_EXISTS.exception());
-
-                        Map<String, Object> templateParam = new HashMap<>();
-                        templateParam.put("userName", flowTaskSmsResult.getRealName());
-
-                        SysMessage sysMessage = null;
-                        String configKey = null, content = null;
-                        if (Objects.nonNull(flowTaskSmsResult)) {
-                            String[] strs = tsJobRemind.getObjName().split(";");
-                            if (tsJobRemind.getRemindType() == JobTypeEnum.BEFORE) {//教务处SOP和研究生SOP
-                                content = MessageEnum.NOTICE_OF_SOP_DONE_REMIND.getTemplate();
-                                content = content.replaceAll("\\$\\{userName\\}", flowTaskSmsResult.getRealName());
-                                content = content.replaceAll("\\$\\{serviceName\\}", flowTaskSmsResult.getServiceName());
-                                content = content.replaceAll("\\$\\{customName\\}", flowTaskSmsResult.getCustomName());
-                                content = content.replaceAll("\\$\\{flowName\\}", strs[0] + "【" + strs[1] + "】");
-
-                                configKey = SystemConstant.SMS_SOP_BEFORE_REMIND_CODE;
-                                templateParam.put("serviceName", flowTaskSmsResult.getServiceName());
-                                templateParam.put("customName", flowTaskSmsResult.getCustomName());
-                                templateParam.put("flowName", strs[0] + "【" + strs[1] + "】");
-
-                                sysMessage = new SysMessage(flowTaskSmsResult.getCrmNo(), tsJobRemind.getCode(),
-                                        MessageTypeEnum.BEFORE, flowTaskSmsResult.getType().name(), flowTaskSmsResult.getServiceId(), flowTaskSmsResult.getUserId(), content,tsJobRemind.getCreateId());
-                            } else if (tsJobRemind.getRemindType() == JobTypeEnum.AFTER) {
-                                content = MessageEnum.NOTICE_OF_DELAY_REMIND.getTemplate();
-                                content = content.replaceAll("\\$\\{userName\\}", flowTaskSmsResult.getRealName());
-                                content = content.replaceAll("\\$\\{serviceName\\}", flowTaskSmsResult.getServiceName());
-                                content = content.replaceAll("\\$\\{customName\\}", flowTaskSmsResult.getCustomName());
-                                content = content.replaceAll("\\$\\{flowName\\}", strs[0] + "【" + strs[1] + "】");
-
-                                configKey = SystemConstant.SMS_SOP_AFTER_REMIND_CODE;
-                                templateParam.put("serviceName", flowTaskSmsResult.getServiceName());
-                                templateParam.put("customName", flowTaskSmsResult.getCustomName());
-                                templateParam.put("flowName", strs[0] + "【" + strs[1] + "】");
-
-                                sysMessage = new SysMessage(flowTaskSmsResult.getCrmNo(), tsJobRemind.getCode(),
-                                        MessageTypeEnum.AFTER, flowTaskSmsResult.getType().name(), flowTaskSmsResult.getServiceId(), flowTaskSmsResult.getUserId(), content,tsJobRemind.getCreateId());
-                            }
-                            //发送消息
-                            sysMessageService.saveSysMessage(Arrays.asList(sysMessage));
+                        TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(
+                                new QueryWrapper<TFCustomFlowEntity>().lambda()
+                                        .eq(TFCustomFlowEntity::getCode, tsJobRemind.getCode()));
+                        Optional.ofNullable(tfCustomFlowEntity)
+                                .orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
+
+                        TFFlowApprove tfFlowApprove = tfFlowApproveService.getOne(
+                                new QueryWrapper<TFFlowApprove>().lambda()
+                                        .eq(TFFlowApprove::getFlowId, tfCustomFlowEntity.getFlowId()));
+                        Optional.ofNullable(tfFlowApprove)
+                                .orElseThrow(() -> ExceptionResultEnum.FLOW_APPROVE_NO_DATA.exception());
+
+                        if (tfFlowApprove.getSetup().intValue() > 0 && Objects.nonNull(tsJobRemind.getSetup())
+                                && tsJobRemind.getSetup().intValue() == tfFlowApprove.getSetup().intValue()) {
+                            FlowTaskSmsResult flowTaskSmsResult = tsJobRemindService.getFlowTaskRemindSmsInfo(
+                                    tsJobRemind.getId());
+                            Optional.ofNullable(flowTaskSmsResult)
+                                    .orElseThrow(() -> ExceptionResultEnum.USER_NO_EXISTS.exception());
 
-                            //发送短信
-                            smsSendUtil.sendSms(flowTaskSmsResult.getMobileNumber(), configKey, templateParam);
+                            Map<String, Object> templateParam = new HashMap<>();
+                            templateParam.put("userName", flowTaskSmsResult.getRealName());
+
+                            SysMessage sysMessage = null;
+                            String configKey = null, content = null;
+                            if (Objects.nonNull(flowTaskSmsResult)) {
+                                String[] strs = tsJobRemind.getObjName().split(";");
+                                if (tsJobRemind.getRemindType() == JobTypeEnum.BEFORE) {//教务处SOP和研究生SOP
+                                    content = MessageEnum.NOTICE_OF_SOP_DONE_REMIND.getTemplate();
+                                    content = content.replaceAll("\\$\\{userName\\}", flowTaskSmsResult.getRealName());
+                                    content = content.replaceAll("\\$\\{serviceName\\}",
+                                            flowTaskSmsResult.getServiceName());
+                                    content = content.replaceAll("\\$\\{customName\\}",
+                                            flowTaskSmsResult.getCustomName());
+                                    content = content.replaceAll("\\$\\{flowName\\}", strs[0] + "【" + strs[1] + "】");
+
+                                    configKey = SystemConstant.SMS_SOP_BEFORE_REMIND_CODE;
+                                    templateParam.put("serviceName", flowTaskSmsResult.getServiceName());
+                                    templateParam.put("customName", flowTaskSmsResult.getCustomName());
+                                    templateParam.put("flowName", strs[0] + "【" + strs[1] + "】");
+
+                                    sysMessage = new SysMessage(flowTaskSmsResult.getCrmNo(), tsJobRemind.getCode(),
+                                            MessageTypeEnum.BEFORE, flowTaskSmsResult.getType().name(),
+                                            flowTaskSmsResult.getServiceId(), flowTaskSmsResult.getUserId(), content,
+                                            tsJobRemind.getCreateId());
+                                } else if (tsJobRemind.getRemindType() == JobTypeEnum.AFTER) {
+                                    content = MessageEnum.NOTICE_OF_DELAY_REMIND.getTemplate();
+                                    content = content.replaceAll("\\$\\{userName\\}", flowTaskSmsResult.getRealName());
+                                    content = content.replaceAll("\\$\\{serviceName\\}",
+                                            flowTaskSmsResult.getServiceName());
+                                    content = content.replaceAll("\\$\\{customName\\}",
+                                            flowTaskSmsResult.getCustomName());
+                                    content = content.replaceAll("\\$\\{flowName\\}", strs[0] + "【" + strs[1] + "】");
+
+                                    configKey = SystemConstant.SMS_SOP_AFTER_REMIND_CODE;
+                                    templateParam.put("serviceName", flowTaskSmsResult.getServiceName());
+                                    templateParam.put("customName", flowTaskSmsResult.getCustomName());
+                                    templateParam.put("flowName", strs[0] + "【" + strs[1] + "】");
+
+                                    sysMessage = new SysMessage(flowTaskSmsResult.getCrmNo(), tsJobRemind.getCode(),
+                                            MessageTypeEnum.AFTER, flowTaskSmsResult.getType().name(),
+                                            flowTaskSmsResult.getServiceId(), flowTaskSmsResult.getUserId(), content,
+                                            tsJobRemind.getCreateId());
+                                }
+                                //发送消息
+                                sysMessageService.saveSysMessage(Arrays.asList(sysMessage));
+
+                                //发送短信
+                                smsSendUtil.sendSms(flowTaskSmsResult.getMobileNumber(), configKey, templateParam);
+                            }
                         }
                     } else if (tsJobRemind.getType() == JobQuartzTypeEnum.NOTICE) {//公告发送短信
                         if (tsJobRemind.getRemindType() == JobTypeEnum.AFTER) {
-                            List<SysUser> sysUserList = sysUserService.list(new QueryWrapper<SysUser>().lambda().isNotNull(SysUser::getMobileNumber).eq(SysUser::getEnable, true));
+                            List<SysUser> sysUserList = sysUserService.list(
+                                    new QueryWrapper<SysUser>().lambda().isNotNull(SysUser::getMobileNumber)
+                                            .eq(SysUser::getEnable, true));
                             for (SysUser s : sysUserList) {
                                 Map<String, Object> templateParam = new HashMap<>();
                                 templateParam.put("userName", s.getRealName());

+ 44 - 19
sop-task/src/main/java/com/qmth/sop/task/job/service/impl/JobServiceImpl.java

@@ -78,31 +78,45 @@ public class JobServiceImpl implements JobService {
         SysConfig sysConfig = commonCacheService.addSysConfigCache(SystemConstant.REMIND_JOB_DB_LIMIT);
         Optional.ofNullable(sysConfig).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("任务提醒查询条数未设置"));
         List<TSJobRemind> tsJobRemindList = tsJobRemindService.list(
-                new QueryWrapper<TSJobRemind>().lambda().isNull(TSJobRemind::getExecTime).last(" " + sysConfig.getConfigValue() + " "));
+                new QueryWrapper<TSJobRemind>().lambda().isNull(TSJobRemind::getExecTime)
+                        .last(" " + sysConfig.getConfigValue() + " "));
         if (!CollectionUtils.isEmpty(tsJobRemindList)) {
             List<TSJobRemind> tsJobRemindUpdateList = new ArrayList<>(tsJobRemindList.size());
+            List<Long> tsJobRemindDeleteList = new ArrayList<>(tsJobRemindList.size());
             for (TSJobRemind t : tsJobRemindList) {
                 if (Objects.nonNull(t.getEnable()) && t.getEnable()) {//新建定时任务
                     if (t.getType() == JobQuartzTypeEnum.FLOW) {//流程
                         switch (t.getRemindType()) {
                         case BEFORE://提前提醒
-                            SysConfig sysConfigBefore = commonCacheService.addSysConfigCache(SystemConstant.FLOW_JOB_BEFORE_TIME);
-                            Optional.ofNullable(sysConfigBefore).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("流程提前提醒任务时间未设置"));
-                            Long execTime = SystemConstant.processMiniuteMinus(t.getCreateTime(), Duration.ofMinutes(Long.parseLong(sysConfigBefore.getConfigValue())));
+                            SysConfig sysConfigBefore = commonCacheService.addSysConfigCache(
+                                    SystemConstant.FLOW_JOB_BEFORE_TIME);
+                            Optional.ofNullable(sysConfigBefore)
+                                    .orElseThrow(() -> ExceptionResultEnum.ERROR.exception("流程提前提醒任务时间未设置"));
+                            Long execTime = SystemConstant.processMiniuteMinus(t.getCreateTime(),
+                                    Duration.ofMinutes(Long.parseLong(sysConfigBefore.getConfigValue())));
                             if (Objects.nonNull(execTime) && execTime.longValue() > System.currentTimeMillis()) {
                                 t.setExecTime(execTime);
-                                this.setJobTime(execTime, t.getId().toString(), t, RemindTaskJob.class, JobEnum.REMIND_QUARTZ_JOB_GROUP);
+                                this.setJobTime(execTime, t.getId().toString(), t, RemindTaskJob.class,
+                                        JobEnum.REMIND_QUARTZ_JOB_GROUP);
                                 tsJobRemindUpdateList.add(t);
+                            } else {
+                                tsJobRemindDeleteList.add(t.getId());
                             }
                             break;
                         case AFTER://超时提醒
-                            SysConfig sysConfigAfter = commonCacheService.addSysConfigCache(SystemConstant.FLOW_JOB_AFTER_TIME);
-                            Optional.ofNullable(sysConfigAfter).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("流程超时提醒任务时间未设置"));
-                            execTime = SystemConstant.processMiniutePlus(t.getCreateTime(), Duration.ofMinutes(Long.parseLong(sysConfigAfter.getConfigValue())));
+                            SysConfig sysConfigAfter = commonCacheService.addSysConfigCache(
+                                    SystemConstant.FLOW_JOB_AFTER_TIME);
+                            Optional.ofNullable(sysConfigAfter)
+                                    .orElseThrow(() -> ExceptionResultEnum.ERROR.exception("流程超时提醒任务时间未设置"));
+                            execTime = SystemConstant.processMiniutePlus(t.getCreateTime(),
+                                    Duration.ofMinutes(Long.parseLong(sysConfigAfter.getConfigValue())));
                             if (Objects.nonNull(execTime) && execTime.longValue() > System.currentTimeMillis()) {
                                 t.setExecTime(execTime);
-                                this.setJobTime(execTime, t.getId().toString(), t, RemindTaskJob.class, JobEnum.REMIND_QUARTZ_JOB_GROUP);
+                                this.setJobTime(execTime, t.getId().toString(), t, RemindTaskJob.class,
+                                        JobEnum.REMIND_QUARTZ_JOB_GROUP);
                                 tsJobRemindUpdateList.add(t);
+                            } else {
+                                tsJobRemindDeleteList.add(t.getId());
                             }
                             break;
                         default:
@@ -111,13 +125,19 @@ public class JobServiceImpl implements JobService {
                     } else if (t.getType() == JobQuartzTypeEnum.FLOW) {//通告
                         switch (t.getRemindType()) {
                         case AFTER://超时提醒
-                            SysConfig sysConfigAfter = commonCacheService.addSysConfigCache(SystemConstant.NOTICE_JOB_AFTER_TIME);
-                            Optional.ofNullable(sysConfigAfter).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("公告超时提醒任务时间未设置"));
-                            Long execTime = SystemConstant.processMiniutePlus(t.getCreateTime(), Duration.ofMinutes(Long.parseLong(sysConfigAfter.getConfigValue())));
+                            SysConfig sysConfigAfter = commonCacheService.addSysConfigCache(
+                                    SystemConstant.NOTICE_JOB_AFTER_TIME);
+                            Optional.ofNullable(sysConfigAfter)
+                                    .orElseThrow(() -> ExceptionResultEnum.ERROR.exception("公告超时提醒任务时间未设置"));
+                            Long execTime = SystemConstant.processMiniutePlus(t.getCreateTime(),
+                                    Duration.ofMinutes(Long.parseLong(sysConfigAfter.getConfigValue())));
                             if (Objects.nonNull(execTime) && execTime.longValue() > System.currentTimeMillis()) {
                                 t.setExecTime(execTime);
-                                this.setJobTime(execTime, t.getId().toString(), t, RemindTaskJob.class, JobEnum.REMIND_QUARTZ_JOB_GROUP);
+                                this.setJobTime(execTime, t.getId().toString(), t, RemindTaskJob.class,
+                                        JobEnum.REMIND_QUARTZ_JOB_GROUP);
                                 tsJobRemindUpdateList.add(t);
+                            } else {
+                                tsJobRemindDeleteList.add(t.getId());
                             }
                             break;
                         default:
@@ -129,15 +149,17 @@ public class JobServiceImpl implements JobService {
             if (!CollectionUtils.isEmpty(tsJobRemindUpdateList)) {
                 tsJobRemindService.saveOrUpdateBatch(tsJobRemindUpdateList);
             }
+            if (!CollectionUtils.isEmpty(tsJobRemindDeleteList)) {
+                tsJobRemindService.removeByIds(tsJobRemindDeleteList);
+            }
         }
 
-        List<TSJobRemind> tsJobRemindFalseList = tsJobRemindService.list(
-                new QueryWrapper<TSJobRemind>().lambda().eq(TSJobRemind::getEnable, false).last(" " + sysConfig.getConfigValue() + " "));
+        List<TSJobRemind> tsJobRemindFalseList = tsJobRemindService.getJobRemindEnable(false);
         if (!CollectionUtils.isEmpty(tsJobRemindFalseList)) {
             List<Long> tsJobRemindFalseIdList = new ArrayList<>(tsJobRemindFalseList.size());
             for (TSJobRemind t : tsJobRemindFalseList) {
                 //禁用需删除定时任务
-                quartzService.deleteJob(t.getObjId().toString(), JobEnum.REMIND_QUARTZ_JOB_GROUP.name());
+                quartzService.deleteJob(t.getId().toString(), JobEnum.REMIND_QUARTZ_JOB_GROUP.name());
                 tsJobRemindFalseIdList.add(t.getId());
             }
             if (!CollectionUtils.isEmpty(tsJobRemindFalseIdList)) {
@@ -195,7 +217,8 @@ public class JobServiceImpl implements JobService {
         TBTask tbTask;
         if (!CollectionUtils.isEmpty(tbTaskList)) {
             if (tbTaskList.size() > 1) {
-                throw ExceptionResultEnum.ERROR.exception(String.format("存在多条类型为[%s]的任务", TaskTypeEnum.CRM_SYNC.getTitle()));
+                throw ExceptionResultEnum.ERROR.exception(
+                        String.format("存在多条类型为[%s]的任务", TaskTypeEnum.CRM_SYNC.getTitle()));
             }
             tbTask = tbTaskList.get(0);
             tbTask.setStatus(TaskStatusEnum.RUNNING);
@@ -222,7 +245,8 @@ public class JobServiceImpl implements JobService {
         TBTask tbTask;
         if (!CollectionUtils.isEmpty(tbTaskList)) {
             if (tbTaskList.size() > 1) {
-                throw ExceptionResultEnum.ERROR.exception(String.format("存在多条类型为[%s]的任务", TaskTypeEnum.RTZF_USER_PUSH_SYNC.getTitle()));
+                throw ExceptionResultEnum.ERROR.exception(
+                        String.format("存在多条类型为[%s]的任务", TaskTypeEnum.RTZF_USER_PUSH_SYNC.getTitle()));
             }
             tbTask = tbTaskList.get(0);
             tbTask.setStatus(TaskStatusEnum.RUNNING);
@@ -249,7 +273,8 @@ public class JobServiceImpl implements JobService {
         TBTask tbTask;
         if (!CollectionUtils.isEmpty(tbTaskList)) {
             if (tbTaskList.size() > 1) {
-                throw ExceptionResultEnum.ERROR.exception(String.format("存在多条类型为[%s]的任务", TaskTypeEnum.RTZF_USER_UPDATE_SYNC.getTitle()));
+                throw ExceptionResultEnum.ERROR.exception(
+                        String.format("存在多条类型为[%s]的任务", TaskTypeEnum.RTZF_USER_UPDATE_SYNC.getTitle()));
             }
             tbTask = tbTaskList.get(0);
             tbTask.setStatus(TaskStatusEnum.RUNNING);

+ 38 - 24
sop-task/src/main/java/com/qmth/sop/task/listener/MyJobListener.java

@@ -16,6 +16,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Objects;
 import java.util.Optional;
 
 /**
@@ -26,6 +27,7 @@ import java.util.Optional;
  * @Date: 2022/9/22
  */
 public class MyJobListener implements JobListener {
+
     private final static Logger log = LoggerFactory.getLogger(MyJobListener.class);
 
     @Override
@@ -48,47 +50,59 @@ public class MyJobListener implements JobListener {
     public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
         JobEnum jobEnum = JobEnum.valueOf(context.getTrigger().getJobKey().getGroup());
         switch (jobEnum) {
-            case REMIND_QUARTZ_JOB_GROUP:
-                try {
-                    JobDataMap map = context.getJobDetail().getJobDataMap();
-                    TSJobRemind tsJobRemind = (TSJobRemind) map.get(SystemConstant.JOB_DATA);
+        case REMIND_QUARTZ_JOB_GROUP:
+            try {
+                JobDataMap map = context.getJobDetail().getJobDataMap();
+                TSJobRemindService tsJobRemindService = SpringContextHolder.getBean(TSJobRemindService.class);
+                TSJobRemind tsJobRemind = (TSJobRemind) map.get(SystemConstant.JOB_DATA);
+                tsJobRemind = tsJobRemindService.getById(tsJobRemind.getId());
+                if (Objects.nonNull(tsJobRemind)) {
                     tsJobRemind.setEnable(false);
-
-                    TSJobRemindService tsJobRemindService = SpringContextHolder.getBean(TSJobRemindService.class);
                     tsJobRemindService.updateById(tsJobRemind);
                     TSJobLogService tsJobLogService = SpringContextHolder.getBean(TSJobLogService.class);
                     TSJobLog tsJobLog = new TSJobLog(tsJobRemind);
                     tsJobLogService.save(tsJobLog);
 
                     //往延期预警表插数据
-                    if (tsJobRemind.getType() == JobQuartzTypeEnum.FLOW && tsJobRemind.getRemindType() == JobTypeEnum.AFTER) {
-                        TFCustomFlowEntityService tfCustomFlowEntityService = SpringContextHolder.getBean(TFCustomFlowEntityService.class);
-                        TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getCode, tsJobRemind.getCode()));
-                        Optional.ofNullable(tfCustomFlowEntity).orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
+                    if (tsJobRemind.getType() == JobQuartzTypeEnum.FLOW
+                            && tsJobRemind.getRemindType() == JobTypeEnum.AFTER) {
+                        TFCustomFlowEntityService tfCustomFlowEntityService = SpringContextHolder.getBean(
+                                TFCustomFlowEntityService.class);
+                        TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(
+                                new QueryWrapper<TFCustomFlowEntity>().lambda()
+                                        .eq(TFCustomFlowEntity::getCode, tsJobRemind.getCode()));
+                        Optional.ofNullable(tfCustomFlowEntity)
+                                .orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
 
                         if (tsJobRemind.getCode().contains(SystemConstant.SOP)) {
-                            TBDelayWarnService tbDelayWarnService = SpringContextHolder.getBean(TBDelayWarnService.class);
+                            TBDelayWarnService tbDelayWarnService = SpringContextHolder.getBean(
+                                    TBDelayWarnService.class);
                             SequenceService sequenceService = SpringContextHolder.getBean(SequenceService.class);
 
                             TBSopInfoService tbSopInfoService = SpringContextHolder.getBean(TBSopInfoService.class);
                             TBSopInfo tbSopInfo = tbSopInfoService.getById(tfCustomFlowEntity.getObjId());
-                            Optional.ofNullable(tbSopInfo).orElseThrow(() -> ExceptionResultEnum.SOP_INFO_NO_DATA.exception());
+                            Optional.ofNullable(tbSopInfo)
+                                    .orElseThrow(() -> ExceptionResultEnum.SOP_INFO_NO_DATA.exception());
 
-                            String code = DelayWarnSeqTypeEnum.DELAY_WARN.getMark() + sequenceService.createCode(DelayWarnSeqTypeEnum.DELAY_WARN.getCode());
-                            tbDelayWarnService.save(new TBDelayWarn(tbSopInfo.getCrmNo(), tbSopInfo.getSopNo(), tbSopInfo.getServiceId(), code, tsJobLog.getCreateTime(), tsJobRemind.getReceiveUserId(), tsJobRemind.getExecField()));
+                            String code = DelayWarnSeqTypeEnum.DELAY_WARN.getMark() + sequenceService.createCode(
+                                    DelayWarnSeqTypeEnum.DELAY_WARN.getCode());
+                            tbDelayWarnService.save(new TBDelayWarn(tbSopInfo.getCrmNo(), tbSopInfo.getSopNo(),
+                                    tbSopInfo.getServiceId(), code, tsJobLog.getCreateTime(),
+                                    tsJobRemind.getReceiveUserId(), tsJobRemind.getExecField()));
                         }
                     }
-                } catch (Exception e) {
-                    log.error(SystemConstant.LOG_ERROR, e);
-                    if (e instanceof ApiException) {
-                        ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
-                    } else {
-                        ResultUtil.error(e.getMessage());
-                    }
                 }
-                break;
-            default:
-                break;
+            } catch (Exception e) {
+                log.error(SystemConstant.LOG_ERROR, e);
+                if (e instanceof ApiException) {
+                    ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
+                } else {
+                    ResultUtil.error(e.getMessage());
+                }
+            }
+            break;
+        default:
+            break;
         }
         log.info("定时任务:{}-执行结束", context.getTrigger().getJobKey());
     }