Browse Source

处理时限加入禁用

wangliang 1 year ago
parent
commit
6ede414c8a

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

@@ -117,13 +117,13 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
 //                        Map<String, Object> map = (Map) taskService.getVariable(task.getId(), SystemConstant.APPROVE_MAP_VAR);
 
                         //此处统一流程节点保存延期预警任务
-                        if ((tfCustomFlow.getType() != TFCustomTypeEnum.OFFICE_SOP_FLOW && tfCustomFlow.getType() != TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW)
+                        if ((tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW || tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW)
                                 && tfFlowLog.getApproveOperation() != FlowApproveOperationEnum.DRAFT
                                 && tfFlowLog.getApproveOperation() != FlowApproveOperationEnum.END
                                 && tfFlowLog.getApproveOperation() != FlowApproveOperationEnum.FINISH) {
                             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()));
+                                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(), tfCustomFlowEntity.getCrmNo()));
 //                                if (CollectionUtils.isEmpty(map)) {//系统自动提交的不发待办短信
                                 this.sendSopFlowDoneSms(tfCustomFlow.getType(), tfCustomFlowEntity, task.getName(), Long.parseLong(task.getAssignee()));
 //                                    jobRemindService.saveJobRemind(tsJobRemindArrayList);
@@ -132,7 +132,7 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
                                 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()));
+                                        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(), tfCustomFlowEntity.getCrmNo()));
 //                                        if (CollectionUtils.isEmpty(map)) {//系统自动提交的不发待办短信
                                         this.sendSopFlowDoneSms(tfCustomFlow.getType(), tfCustomFlowEntity, task.getName(), Long.parseLong(i.getUserId()));
 //                                            jobRemindService.saveJobRemind(tsJobRemindArrayList);
@@ -160,7 +160,7 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
                         TFFlowLog tfFlowLog = (TFFlowLog) taskService.getVariable(task.getId(), SystemConstant.FLOW_APPROVE_LOG);
                         Optional.ofNullable(tfFlowLog).orElseThrow(() -> ExceptionResultEnum.FLOW_APPROVE_LOG_NO_DATA.exception());
 
-                        if ((tfCustomFlow.getType() != TFCustomTypeEnum.OFFICE_SOP_FLOW && tfCustomFlow.getType() != TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW)
+                        if ((tfCustomFlow.getType() == TFCustomTypeEnum.OFFICE_SOP_FLOW || tfCustomFlow.getType() == TFCustomTypeEnum.CLOUD_MARK_SOP_FLOW)
                                 && tfFlowLog.getApproveSetup().intValue() > 1) {//流程提交不需要提醒
                             //任务完成后统一设置延期预警任务enable为false
                             jobRemindService.updateJobRemind(Long.parseLong(task.getId()));

+ 1 - 0
sop-business/src/main/java/com/qmth/sop/business/activiti/service/impl/ActivitiServiceImpl.java

@@ -737,6 +737,7 @@ public class ActivitiServiceImpl implements ActivitiService {
                 activitiService.flowEnd(l);
             }
         }
+        tsJobRemindService.updateJobRemind(crmNo);
         return true;
     }
 

+ 17 - 3
sop-business/src/main/java/com/qmth/sop/business/entity/TSJobRemind.java

@@ -67,11 +67,14 @@ public class TSJobRemind implements Serializable {
     @ApiModelProperty(value = "创建时间")
     private Long createTime;
 
+    @ApiModelProperty(value = "crm单号")
+    private String crmNo;
+
     public TSJobRemind() {
 
     }
 
-    public TSJobRemind(JobQuartzTypeEnum type, Long objId, String objName, JobTypeEnum remindType, Long userId) {
+    public TSJobRemind(JobQuartzTypeEnum type, Long objId, String objName, JobTypeEnum remindType, Long userId, String crmNo) {
         this.id = SystemConstant.getDbUuid();
         this.type = type;
         this.objId = objId;
@@ -80,9 +83,10 @@ public class TSJobRemind implements Serializable {
         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) {
+    public TSJobRemind(JobQuartzTypeEnum type, String code, Long objId, String objName, JobTypeEnum remindType, Long receiveUserId, FlowApproveOperationEnum approveOperation, Long userId, String crmNo) {
         this.id = SystemConstant.getDbUuid();
         this.type = type;
         this.code = code;
@@ -94,10 +98,11 @@ public class TSJobRemind implements Serializable {
         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 createTime, String execField, Long userId) {
+    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;
@@ -110,6 +115,15 @@ public class TSJobRemind implements Serializable {
         this.createTime = createTime;
         this.execField = execField;
         this.enable = true;
+        this.crmNo = crmNo;
+    }
+
+    public String getCrmNo() {
+        return crmNo;
+    }
+
+    public void setCrmNo(String crmNo) {
+        this.crmNo = crmNo;
     }
 
     public JobQuartzTypeEnum getType() {

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

@@ -34,6 +34,14 @@ public interface TSJobRemindService extends IService<TSJobRemind> {
      */
     Boolean updateJobRemind(Long taskId);
 
+    /**
+     * 根据crmNo更新任务提醒
+     *
+     * @param crmNo
+     * @return
+     */
+    Boolean updateJobRemind(String crmNo);
+
     /**
      * 获取流程任务发送短信内容
      *

+ 4 - 5
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBSopInfoServiceImpl.java

@@ -86,7 +86,6 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
     @Resource
     TFFlowLogService tfFlowLogService;
 
-
     /**
      * 查询动态sop表名是否存在
      *
@@ -758,14 +757,14 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
                     tsJobRemindService.updateJobRemind(Long.parseLong(task.getId()));
                     List<TSJobRemind> tsJobRemindList = new ArrayList<>();
                     if (Objects.nonNull(task.getAssignee())) {
-                        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()));
-                        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()));
+                        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()));
+                        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()));
                     } else {
                         List<IdentityLink> identityLinkList = taskService.getIdentityLinksForTask(task.getId());
                         if (!CollectionUtils.isEmpty(identityLinkList)) {
                             for (IdentityLink i : identityLinkList) {
-                                tsJobRemindList.add(new TSJobRemind(JobQuartzTypeEnum.FLOW, tfCustomFlowEntity.getCode(), Long.parseLong(i.getTaskId()), tfCustomFlow.getType().getTitle() + ";" + task.getName(), JobTypeEnum.BEFORE, Long.parseLong(i.getUserId()), tfFlowLog.getApproveOperation(), processLimitedTime, execField, sysUser.getId()));
-                                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()));
+                                tsJobRemindList.add(new TSJobRemind(JobQuartzTypeEnum.FLOW, tfCustomFlowEntity.getCode(), Long.parseLong(i.getTaskId()), tfCustomFlow.getType().getTitle() + ";" + task.getName(), JobTypeEnum.BEFORE, Long.parseLong(i.getUserId()), tfFlowLog.getApproveOperation(), processLimitedTime, execField, sysUser.getId(), tfCustomFlowEntity.getCrmNo()));
+                                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()));
                             }
                         }
                     }

+ 15 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/TSJobRemindServiceImpl.java

@@ -7,6 +7,7 @@ import com.qmth.sop.business.bean.result.WorkTaskResult;
 import com.qmth.sop.business.entity.TSJobRemind;
 import com.qmth.sop.business.mapper.TSJobRemindMapper;
 import com.qmth.sop.business.service.TSJobRemindService;
+import com.qmth.sop.common.enums.JobQuartzTypeEnum;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
@@ -51,6 +52,20 @@ public class TSJobRemindServiceImpl extends ServiceImpl<TSJobRemindMapper, TSJob
                 .set(TSJobRemind::getEnable, false));
     }
 
+    /**
+     * 根据crmNo更新任务提醒
+     *
+     * @param crmNo
+     * @return
+     */
+    @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));
+    }
+
     /**
      * 获取流程任务发送短信内容
      *

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

@@ -1896,4 +1896,7 @@ SET name='考勤异常审核接口', url='/api/admin/ding/exception/apply/flow/a
 WHERE id=3021;
 UPDATE sys_privilege
 SET name='考勤异常批量审核接口', url='/api/admin/ding/exception/apply/flow/batch/approve', `type`='URL', parent_id=27, `sequence`=5, property='AUTH', related=NULL, enable=1, default_auth=1, front_display=0
-WHERE id=3022;
+WHERE id=3022;
+
+ALTER TABLE t_s_job_remind ADD crm_no varchar(100) NULL COMMENT 'crm单号';
+ALTER TABLE t_s_job_remind CHANGE crm_no crm_no varchar(100) NULL COMMENT 'crm单号' AFTER `type`;

+ 12 - 7
sop-task/src/main/java/com/qmth/sop/task/job/service/impl/JobServiceImpl.java

@@ -59,7 +59,6 @@ public class JobServiceImpl implements JobService {
         List<TSJobRemind> tsJobRemindList = tsJobRemindService.list(new QueryWrapper<TSJobRemind>().lambda().isNull(TSJobRemind::getExecTime).last(" " + sysConfig.getConfigValue() + " "));
         if (!CollectionUtils.isEmpty(tsJobRemindList)) {
             List<TSJobRemind> tsJobRemindUpdateList = new ArrayList<>(tsJobRemindList.size());
-            List<Long> tsJobRemindIdList = new ArrayList<>(tsJobRemindList.size());
             for (TSJobRemind t : tsJobRemindList) {
                 if (Objects.nonNull(t.getEnable()) && t.getEnable()) {//新建定时任务
                     if (t.getType() == JobQuartzTypeEnum.FLOW) {//流程
@@ -103,17 +102,23 @@ public class JobServiceImpl implements JobService {
                                 break;
                         }
                     }
-                } else if (Objects.nonNull(t.getEnable()) && !t.getEnable()) {
-                    //禁用需删除定时任务
-                    quartzService.deleteJob(t.getObjId().toString(), JobEnum.REMIND_QUARTZ_JOB_GROUP.name());
-                    tsJobRemindIdList.add(t.getId());
                 }
             }
             if (!CollectionUtils.isEmpty(tsJobRemindUpdateList)) {
                 tsJobRemindService.saveOrUpdateBatch(tsJobRemindUpdateList);
             }
-            if (!CollectionUtils.isEmpty(tsJobRemindIdList)) {
-                tsJobRemindService.removeByIds(tsJobRemindIdList);
+        }
+
+        List<TSJobRemind> tsJobRemindFalseList = tsJobRemindService.list(new QueryWrapper<TSJobRemind>().lambda().eq(TSJobRemind::getEnable, false).last(" " + sysConfig.getConfigValue() + " "));
+        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());
+                tsJobRemindFalseIdList.add(t.getId());
+            }
+            if (!CollectionUtils.isEmpty(tsJobRemindFalseIdList)) {
+                tsJobRemindService.removeByIds(tsJobRemindFalseIdList);
             }
         }
     }

+ 4 - 0
sop-task/src/main/java/com/qmth/sop/task/listener/MyJobListener.java

@@ -52,6 +52,10 @@ public class MyJobListener implements JobListener {
                 try {
                     JobDataMap map = context.getJobDetail().getJobDataMap();
                     TSJobRemind tsJobRemind = (TSJobRemind) map.get(SystemConstant.JOB_DATA);
+                    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);