Sfoglia il codice sorgente

流程发送消息

wangliang 1 anno fa
parent
commit
ba10f25b72

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

@@ -1,17 +1,13 @@
 package com.qmth.sop.business.activiti.listener;
 
+import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qmth.sop.business.bean.dto.FlowRejectSequenceDto;
-import com.qmth.sop.business.bean.result.FlowFormWidgetResult;
-import com.qmth.sop.business.bean.result.FlowResult;
-import com.qmth.sop.business.bean.result.FlowTablePropResult;
-import com.qmth.sop.business.bean.result.FlowTaskResult;
+import com.qmth.sop.business.bean.result.*;
 import com.qmth.sop.business.entity.*;
-import com.qmth.sop.business.service.SysUserService;
-import com.qmth.sop.business.service.TFCustomFlowService;
-import com.qmth.sop.business.service.TSJobRemindService;
+import com.qmth.sop.business.service.*;
 import com.qmth.sop.business.util.SmsSendUtil;
 import com.qmth.sop.common.contant.SpringContextHolder;
 import com.qmth.sop.common.contant.SystemConstant;
@@ -64,6 +60,7 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
                     TFCustomFlow tfCustomFlow = null;
                     TFCustomFlowEntity tfCustomFlowEntity = null;
                     TFFlowApprove tfFlowApprove = null;
+                    TFFlowLog tfFlowLog = null;
                     for (HistoricVariableInstance h : historicVariableInstanceList) {
                         if (Objects.equals(h.getVariableName(), SystemConstant.FLOW_CUSTOM)) {
                             tfCustomFlow = (TFCustomFlow) h.getValue();
@@ -77,8 +74,12 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
                             tfFlowApprove = (TFFlowApprove) h.getValue();
                             Optional.ofNullable(tfFlowApprove).orElseThrow(() -> ExceptionResultEnum.FLOW_APPROVE_NO_DATA.exception());
                         }
+                        if (Objects.equals(h.getVariableName(), SystemConstant.FLOW_APPROVE_LOG)) {
+                            tfFlowApprove = (TFFlowApprove) h.getValue();
+                            Optional.ofNullable(tfFlowApprove).orElseThrow(() -> ExceptionResultEnum.FLOW_APPROVE_NO_DATA.exception());
+                        }
                     }
-                    this.sendFlowFinishSms(tfCustomFlow.getType(), tfFlowApprove.getStatus(), tfCustomFlowEntity.getCreateId());
+                    this.sendFlowFinishSms(tfCustomFlow.getType(), tfCustomFlowEntity, tfFlowApprove.getStatus(), tfFlowLog);
                 }
                 break;
             case TASK_CREATED:
@@ -306,9 +307,6 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
                 flowResult.setVersion(tfCustomFlow.getVersion());
                 tfCustomFlow.setUpdateTime(System.currentTimeMillis());
             }
-//            if (!CollectionUtils.isEmpty(approveRejectMap)) {
-//                flowResult.setApproveRejectMap(approveRejectMap);
-//            }
             tfCustomFlow.setFlowProcessVar(JacksonUtil.parseJson(flowResult));
             tfCustomFlowService.saveOrUpdate(tfCustomFlow);
         } catch (DocumentException e) {
@@ -339,22 +337,61 @@ public class ProcessEventListener implements ActivitiEventListener, Serializable
      * 发送流程结束短信
      *
      * @param type
+     * @param tfCustomFlowEntity
      * @param status
-     * @param userId
+     * @param tfFlowLog
      */
-    protected void sendFlowFinishSms(TFCustomTypeEnum type, FlowStatusEnum status, Long userId) {
-        SysUserService sysUserService = SpringContextHolder.getBean(SysUserService.class);
+    protected void sendFlowFinishSms(TFCustomTypeEnum type, TFCustomFlowEntity tfCustomFlowEntity, FlowStatusEnum status, TFFlowLog tfFlowLog) {
         SmsSendUtil smsSendUtil = SpringContextHolder.getBean(SmsSendUtil.class);
+        SysMessageService sysMessageService = SpringContextHolder.getBean(SysMessageService.class);
+        TFCustomFlowEntityService tfCustomFlowEntityService = SpringContextHolder.getBean(TFCustomFlowEntityService.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());
+            FlowTaskMsgResult flowTaskMsgResult = tfCustomFlowEntityService.getFlowTaskRemindMsgInfo(tfCustomFlowEntity.getId(), tfCustomFlowEntity.getCreateId());
+            Optional.ofNullable(flowTaskMsgResult).orElseThrow(() -> ExceptionResultEnum.USER_NO_EXISTS.exception());
 
+            SysMessage sysMessage = null;
+            String configKey = null, content = null;
             Map<String, Object> templateParam = new HashMap<>();
-            templateParam.put("code", "test");
-            smsSendUtil.sendSms(sysUser.getMobileNumber(), SystemConstant.SMS_TPL_CODE, templateParam);
+            templateParam.put("userName", flowTaskMsgResult.getRealName());
+            if (type == TFCustomTypeEnum.DING_EXCEPTION_FLOW) {//考勤异常
+                content = MessageEnum.NOTICE_OF_DING_EXCEPTION.getTemplate();
+                content = content.replaceAll("\\$\\{userName\\}", flowTaskMsgResult.getRealName());
+                content = content.replaceAll("\\$\\{dingDate\\}", DateUtil.format(new Date(flowTaskMsgResult.getApplyTime()), SystemConstant.DEFAULT_DATE_PATTERN));
+                content = content.replaceAll("\\$\\{approveRemark\\}", tfFlowLog.getApproveRemark());
+
+                configKey = SystemConstant.SMS_TPL_CODE;
+                templateParam.put("dingDate", DateUtil.format(new Date(flowTaskMsgResult.getApplyTime()), SystemConstant.DEFAULT_DATE_PATTERN));
+                templateParam.put("approveRemark", tfFlowLog.getApproveRemark());
+
+                sysMessage = new SysMessage(tfCustomFlowEntity.getCrmNo(), tfCustomFlowEntity.getCode(),
+                        MessageTypeEnum.EXCEPTION_APPROVE,
+                        type.name(), flowTaskMsgResult.getServiceId(), tfCustomFlowEntity.getCreateId(), content);
+
+                configKey = SystemConstant.SMS_TPL_CODE;
+            } else if (type == TFCustomTypeEnum.PROJECT_EXCHANGE_FLOW) {//项目计划变更
+                content = MessageEnum.NOTICE_OF_PROJECT_EXCHANGE.getTemplate();
+                content = content.replaceAll("\\$\\{userName\\}", flowTaskMsgResult.getRealName());
+                content = content.replaceAll("\\$\\{serviceName\\}", flowTaskMsgResult.getServiceName());
+                content = content.replaceAll("\\$\\{customName\\}", flowTaskMsgResult.getCustomName());
+                content = content.replaceAll("\\$\\{exchangeType\\}", flowTaskMsgResult.getExchangeType().getTitle());
+
+                configKey = SystemConstant.SMS_TPL_CODE;
+                templateParam.put("serviceName", flowTaskMsgResult.getServiceName());
+                templateParam.put("customName", flowTaskMsgResult.getCustomName());
+                templateParam.put("exchangeType", flowTaskMsgResult.getExchangeType().getTitle());
+
+                sysMessage = new SysMessage(tfCustomFlowEntity.getCrmNo(), tfCustomFlowEntity.getCode(),
+                        MessageTypeEnum.SYSTEM_PLAN_CHANGE,
+                        type.name(), flowTaskMsgResult.getServiceId(), tfCustomFlowEntity.getCreateId(), content);
+            }
+            //发送消息
+            sysMessageService.saveSysMessage(Arrays.asList(sysMessage));
+
+            //发送短信
+            smsSendUtil.sendSms(flowTaskMsgResult.getMobileNumber(), configKey, templateParam);
         }
     }
 }

+ 96 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/FlowTaskMsgResult.java

@@ -0,0 +1,96 @@
+package com.qmth.sop.business.bean.result;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.sop.common.enums.DelayWarnTypeEnum;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * @Description: 流程消息提醒 result
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2023/2/17
+ */
+public class FlowTaskMsgResult implements Serializable {
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "服务单元id")
+    Long serviceId;
+
+    @ApiModelProperty(value = "服务单元名称")
+    String serviceName;
+
+    @ApiModelProperty(value = "客户名称")
+    String customName;
+
+    @ApiModelProperty(value = "用户真实姓名")
+    String realName;
+
+    @ApiModelProperty(value = "用户手机号码")
+    String mobileNumber;
+
+    @ApiModelProperty(value = "考勤异常申请时间")
+    Long applyTime;
+
+    @ApiModelProperty(value = "项目计划变更类型")
+    DelayWarnTypeEnum exchangeType;
+
+    public Long getApplyTime() {
+        return applyTime;
+    }
+
+    public void setApplyTime(Long applyTime) {
+        this.applyTime = applyTime;
+    }
+
+    public DelayWarnTypeEnum getExchangeType() {
+        return exchangeType;
+    }
+
+    public void setExchangeType(DelayWarnTypeEnum exchangeType) {
+        this.exchangeType = exchangeType;
+    }
+
+    public Long getServiceId() {
+        return serviceId;
+    }
+
+    public void setServiceId(Long serviceId) {
+        this.serviceId = serviceId;
+    }
+
+    public String getServiceName() {
+        return serviceName;
+    }
+
+    public void setServiceName(String serviceName) {
+        this.serviceName = serviceName;
+    }
+
+    public String getCustomName() {
+        return customName;
+    }
+
+    public void setCustomName(String customName) {
+        this.customName = customName;
+    }
+
+    public String getRealName() {
+        return realName;
+    }
+
+    public void setRealName(String realName) {
+        this.realName = realName;
+    }
+
+    public String getMobileNumber() {
+        return mobileNumber;
+    }
+
+    public void setMobileNumber(String mobileNumber) {
+        this.mobileNumber = mobileNumber;
+    }
+}

+ 19 - 1
sop-business/src/main/java/com/qmth/sop/business/entity/SysMessage.java

@@ -2,6 +2,7 @@ package com.qmth.sop.business.entity;
 
 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.MessageTypeEnum;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -16,7 +17,7 @@ import java.io.Serializable;
  * @author wangliang
  * @since 2023-08-01
  */
-@ApiModel(value="SysMessage对象", description="系统消息")
+@ApiModel(value = "SysMessage对象", description = "系统消息")
 public class SysMessage implements Serializable {
 
     private static final long serialVersionUID = 1L;
@@ -69,6 +70,23 @@ public class SysMessage implements Serializable {
     @ApiModelProperty(value = "是否已阅,0:未阅,1:已阅")
     private Boolean status;
 
+    public SysMessage() {
+
+    }
+
+    public SysMessage(String crmNo, String code, MessageTypeEnum type, String objType, Long serviceId, Long receiveUserId, String content) {
+        this.id = SystemConstant.getDbUuid();
+        this.crmNo = crmNo;
+        this.code = code;
+        this.type = type;
+        this.objType = objType;
+        this.serviceId = serviceId;
+        this.receiveUserId = receiveUserId;
+        this.content = content;
+        this.sendTime = System.currentTimeMillis();
+        this.status = false;
+    }
+
     public String getCode() {
         return code;
     }

+ 11 - 0
sop-business/src/main/java/com/qmth/sop/business/entity/TBProjectExchange.java

@@ -31,6 +31,9 @@ public class TBProjectExchange implements Serializable {
     @ApiModelProperty(value = "crm单号")
     private String crmNo;
 
+    @ApiModelProperty(value = "变更编号")
+    private String exchangeNo;
+
     @ApiModelProperty(value = "服务单元id")
     @JsonSerialize(using = ToStringSerializer.class)
     private Long serviceId;
@@ -54,6 +57,14 @@ public class TBProjectExchange implements Serializable {
     @ApiModelProperty(value = "创建时间")
     private Long createTime;
 
+    public String getExchangeNo() {
+        return exchangeNo;
+    }
+
+    public void setExchangeNo(String exchangeNo) {
+        this.exchangeNo = exchangeNo;
+    }
+
     public Long getId() {
         return id;
     }

+ 10 - 0
sop-business/src/main/java/com/qmth/sop/business/mapper/TFCustomFlowEntityMapper.java

@@ -1,7 +1,9 @@
 package com.qmth.sop.business.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qmth.sop.business.bean.result.FlowTaskMsgResult;
 import com.qmth.sop.business.entity.TFCustomFlowEntity;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * <p>
@@ -13,4 +15,12 @@ import com.qmth.sop.business.entity.TFCustomFlowEntity;
  */
 public interface TFCustomFlowEntityMapper extends BaseMapper<TFCustomFlowEntity> {
 
+    /**
+     * 根据id和用户id获取流程消息信息
+     *
+     * @param id
+     * @param userId
+     * @return
+     */
+    FlowTaskMsgResult getFlowTaskRemindMsgInfo(@Param("id") Long id, @Param("userId") Long userId);
 }

+ 14 - 7
sop-business/src/main/java/com/qmth/sop/business/service/SysMessageService.java

@@ -22,20 +22,19 @@ import java.util.Map;
  * @email: shudonghui@qmth.com.cn
  * @Company: www.qmth.com.cn
  */
-public interface SysMessageService extends IService<SysMessage>{
+public interface SysMessageService extends IService<SysMessage> {
 
     /**
-    * 查询列表
-    *
-    * @param iPage
-    * @return
-    */
+     * 查询列表
+     *
+     * @param iPage
+     * @return
+     */
     IPage<SysMessageResult> query(IPage<Map> iPage, Long noticeId, String city, Long supplierId, Boolean status);
 
     List<SysMessageResult> query(Long noticeId, String city, Long supplierId, Boolean status);
 
 
-
     SysMessageCountResult count(long noticeId);
 
     void deleteByNoticeId(long id);
@@ -44,10 +43,18 @@ public interface SysMessageService extends IService<SysMessage>{
 
     /**
      * 保存任务提醒
+     *
      * @param tsJobRemind
      */
     void publishByTSJobRemind(TSJobRemind tsJobRemind);
 
+    /**
+     * 保存消息
+     *
+     * @param sysMessageList
+     */
+    void saveSysMessage(List<SysMessage> sysMessageList);
+
     boolean read(long id);
 
 

+ 9 - 0
sop-business/src/main/java/com/qmth/sop/business/service/TFCustomFlowEntityService.java

@@ -1,6 +1,7 @@
 package com.qmth.sop.business.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.sop.business.bean.result.FlowTaskMsgResult;
 import com.qmth.sop.business.entity.TFCustomFlowEntity;
 
 /**
@@ -13,4 +14,12 @@ import com.qmth.sop.business.entity.TFCustomFlowEntity;
  */
 public interface TFCustomFlowEntityService extends IService<TFCustomFlowEntity> {
 
+    /**
+     * 根据id和用户id获取流程消息信息
+     *
+     * @param id
+     * @param userId
+     * @return
+     */
+    FlowTaskMsgResult getFlowTaskRemindMsgInfo(Long id, Long userId);
 }

+ 12 - 5
sop-business/src/main/java/com/qmth/sop/business/service/impl/SysMessageServiceImpl.java

@@ -36,18 +36,15 @@ import java.util.Map;
 @Service
 public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMessage> implements SysMessageService {
 
-
     @Resource
     SysUserService sysUserService;
 
-
     @Resource
     TBUserArchivesSupplierService tbUserArchivesSupplierService;
 
     @Resource
     TBServiceService tbServiceService;
 
-
     @Override
     public IPage<SysMessageResult> query(IPage<Map> iPage, Long noticeId, String city, Long supplierId, Boolean status) {
         return this.baseMapper.query(iPage, noticeId, city, supplierId, status);
@@ -82,7 +79,6 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
             List<TBService> tbServices = tbServiceService.listEnable(sysNotice.getServiceId());
             tbServices.forEach(s -> insertMessage(sysNotice, s.getServiceLeadId()));
         }
-
     }
 
     @Override
@@ -96,6 +92,17 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
         }
     }
 
+    /**
+     * 保存消息
+     *
+     * @param sysMessageList
+     */
+    @Override
+    @Transactional
+    public void saveSysMessage(List<SysMessage> sysMessageList) {
+        this.saveBatch(sysMessageList);
+    }
+
     private void insertMessage(SysNotice sysNotice, Long s) {
         SysMessage sysMessage = new SysMessage();
         sysMessage.setContent(sysNotice.getContent());
@@ -120,7 +127,7 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
         sysMessage.setSendTime(System.currentTimeMillis());
         sysMessage.setStatus(false);
         sysMessage.setContent(tsJobRemind.getObjName());
-        sysMessage.setType(tsJobRemind.getRemindType().equals(JobTypeEnum.AFTER)?MessageTypeEnum.AFTER:MessageTypeEnum.BEFORE);
+        sysMessage.setType(tsJobRemind.getRemindType().equals(JobTypeEnum.AFTER) ? MessageTypeEnum.AFTER : MessageTypeEnum.BEFORE);
         sysMessage.setCode(tsJobRemind.getCode());
         this.save(sysMessage);
     }

+ 12 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/TFCustomFlowEntityServiceImpl.java

@@ -1,6 +1,7 @@
 package com.qmth.sop.business.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.sop.business.bean.result.FlowTaskMsgResult;
 import com.qmth.sop.business.entity.TFCustomFlowEntity;
 import com.qmth.sop.business.mapper.TFCustomFlowEntityMapper;
 import com.qmth.sop.business.service.TFCustomFlowEntityService;
@@ -17,4 +18,15 @@ import org.springframework.stereotype.Service;
 @Service
 public class TFCustomFlowEntityServiceImpl extends ServiceImpl<TFCustomFlowEntityMapper, TFCustomFlowEntity> implements TFCustomFlowEntityService {
 
+    /**
+     * 根据id和用户id获取流程消息信息
+     *
+     * @param id
+     * @param userId
+     * @return
+     */
+    @Override
+    public FlowTaskMsgResult getFlowTaskRemindMsgInfo(Long id, Long userId) {
+        return this.baseMapper.getFlowTaskRemindMsgInfo(id, userId);
+    }
 }

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

@@ -657,4 +657,7 @@ ALTER TABLE t_s_job_remind CHANGE COLUMN approve_operation approve_operation VAR
     COMMENT '审批操作,START:提交,DRAFT:草稿,APPROVE:审批,REJECT:驳回,END:终止,CANCEL:撤销,EXCHANGE:转他人审批,FINISH:结束' NULL;
 
 ALTER TABLE t_s_job_remind CHANGE COLUMN receive_user_id receive_user_id BIGINT
-    COMMENT '接收人id' NULL;
+    COMMENT '接收人id' NULL;
+
+ALTER TABLE t_b_project_exchange ADD exchange_no VARCHAR(100)
+    COMMENT '变更编号' NULL after crm_no;

+ 19 - 0
sop-business/src/main/resources/mapper/TFCustomFlowEntityMapper.xml

@@ -2,4 +2,23 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.qmth.sop.business.mapper.TFCustomFlowEntityMapper">
 
+    <select id="getFlowTaskRemindMsgInfo" resultType="com.qmth.sop.business.bean.result.FlowTaskMsgResult">
+        select
+            tbc.id as serviceId,
+            tbc.name as serviceName,
+            sc.name as customName,
+            su.real_name as realName,
+            su.mobile_number as mobileNumber,
+            tbda.apply_time as applyTime,
+            tbpe.type as exchangeType
+        from
+            t_f_custom_flow_entity tfcfe
+            left join t_b_crm tbc on tbc.crm_no = tfcfe.crm_no
+            left join sys_custom sc on sc.id = tbc.custom_id
+            left join t_b_ding_apply tbda on tbda.ding_exception_no = tfcfe.code
+            left join t_b_project_exchange tbpe on tbpe.exchange_no = tfcfe.code
+            left join sys_user su on su.id = #{userId}
+        where
+            tfcfe.id = #{id}
+    </select>
 </mapper>

+ 9 - 0
sop-common/src/main/java/com/qmth/sop/common/enums/MessageEnum.java

@@ -29,5 +29,14 @@ public enum MessageEnum {
     }
 
     private final String name;
+
     private final String template;
+
+    public String getName() {
+        return name;
+    }
+
+    public String getTemplate() {
+        return template;
+    }
 }