Prechádzať zdrojové kódy

对接修改消息模板解析

车车 9 mesiacov pred
rodič
commit
2ad3039c8d

+ 2 - 1
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/controller/admin/notifyconfig/NotifyConfigController.java

@@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.iscs.controller.admin.notifyconfig.vo.NotifyConfi
 import cn.iocoder.yudao.module.iscs.controller.admin.notifyconfig.vo.NotifyConfigRespVO;
 import cn.iocoder.yudao.module.iscs.controller.admin.notifyconfig.vo.NotifyConfigSaveReqVO;
 import cn.iocoder.yudao.module.iscs.service.notifyconfig.NotifyConfigService;
+import com.fasterxml.jackson.core.JsonProcessingException;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -72,7 +73,7 @@ public class NotifyConfigController {
 
     @PostMapping("/insertMessByRule")
     @Operation(summary = "根据规则创建消息的发送机制")
-    public CommonResult<Boolean> insertMessByRule(@Valid @RequestBody MessSaveVO vo) {
+    public CommonResult<Boolean> insertMessByRule(@Valid @RequestBody MessSaveVO vo) throws JsonProcessingException {
         return success(notifyConfigService.insertMessByRule(vo));
     }
 

+ 30 - 6
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/job/SopExecutionPlanJob.java

@@ -4,20 +4,22 @@ import cn.hutool.core.date.DateUtil;
 import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
 import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
 import cn.iocoder.yudao.module.iscs.controller.admin.jobticket.vo.JobTicketSaveReqVO;
+import cn.iocoder.yudao.module.iscs.controller.admin.notifyconfig.vo.MessSaveVO;
 import cn.iocoder.yudao.module.iscs.controller.admin.sop.vo.SopExecutionPlanRespVO;
 import cn.iocoder.yudao.module.iscs.dal.dataobject.jobticket.JobTicketDO;
 import cn.iocoder.yudao.module.iscs.service.jobticket.JobTicketService;
+import cn.iocoder.yudao.module.iscs.service.notifyconfig.NotifyConfigService;
 import cn.iocoder.yudao.module.iscs.service.sop.SopExecutionPlanService;
-import cn.iocoder.yudao.module.system.service.user.AdminUserService;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.fasterxml.jackson.core.JsonProcessingException;
 import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Component;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
 
 /**
  * SOP执行计划任务
@@ -33,7 +35,7 @@ public class SopExecutionPlanJob implements JobHandler {
     @Resource
     private JobTicketService jobTicketService;
     @Resource
-    private AdminUserService adminUserService;
+    private NotifyConfigService notifyConfigService;
 
     /**
      * 查找需要执行的数据,生成作业
@@ -44,7 +46,7 @@ public class SopExecutionPlanJob implements JobHandler {
     // @TenantIgnore
     @Override
     @TenantJob
-    public String execute(String param) {
+    public String execute(String param) throws JsonProcessingException {
         /*TenantUtils.execute(1L, () -> {
             AdminUserRespDTO user = new AdminUserRespDTO();
             user.setId(0L);
@@ -77,6 +79,28 @@ public class SopExecutionPlanJob implements JobHandler {
                 Long l = jobTicketService.insertJobTicketBySop(jobTicketSaveReqVO);
                 sopIds.add(executionPlanRespVO.getSopId());
                 ticketIds.add(l);
+
+                // 发送消息
+                // 定义匹配输入格式的解析器
+                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+                Map<String, Object> stringObjectHashMap = new HashMap<>();
+                stringObjectHashMap.put("workstationName", "R&R");
+                stringObjectHashMap.put("sopName", "SOP名称");
+                stringObjectHashMap.put("jobTicketName", "作业名称");
+                stringObjectHashMap.put("sendUser", "发信人名字");
+                stringObjectHashMap.put("receiveUser", "收信人名字");
+                stringObjectHashMap.put("ticketStartTime", "作业开始时间");
+                stringObjectHashMap.put("ticketEndTime", "作业预计结束时间");
+                stringObjectHashMap.put("machineryName", "工艺/设备名称");
+                stringObjectHashMap.put("sopTypeName", "SOP类型");
+                MessSaveVO messSaveVO = new MessSaveVO();
+                messSaveVO.setSopId(executionPlanRespVO.getSopId());
+                messSaveVO.setType(0);
+                messSaveVO.setRule("0");
+                messSaveVO.setTicketId(l);
+                messSaveVO.setShouldSendTime(LocalDateTime.parse(planStartTime, formatter));
+                messSaveVO.setTemplateParams(stringObjectHashMap);
+                notifyConfigService.insertMessByRule(messSaveVO);
             }
         }
         return String.format("定时执行sop生成作业,sopIds = " + sopIds + ",ticketIds = " + ticketIds);

+ 2 - 1
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/service/notifyconfig/NotifyConfigService.java

@@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.iscs.controller.admin.notifyconfig.vo.NotifyConfi
 import cn.iocoder.yudao.module.iscs.controller.admin.notifyconfig.vo.NotifyConfigSaveReqVO;
 import cn.iocoder.yudao.module.iscs.dal.dataobject.notifyconfig.NotifyConfigDO;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.fasterxml.jackson.core.JsonProcessingException;
 import jakarta.validation.Valid;
 
 import java.util.List;
@@ -56,6 +57,6 @@ public interface NotifyConfigService extends IService<NotifyConfigDO> {
      */
     PageResult<NotifyConfigRespVO> getNotifyConfigPage(NotifyConfigPageReqVO pageReqVO);
 
-    Boolean insertMessByRule(MessSaveVO vo);
+    Boolean insertMessByRule(MessSaveVO vo) throws JsonProcessingException;
 
 }

+ 14 - 10
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/service/notifyconfig/NotifyConfigServiceImpl.java

@@ -1,6 +1,5 @@
 package cn.iocoder.yudao.module.iscs.service.notifyconfig;
 
-import cn.hutool.json.JSONArray;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.module.iscs.controller.admin.jobticket.vo.JobTicketUserRespVO;
@@ -22,6 +21,8 @@ import cn.iocoder.yudao.module.system.service.user.AdminUserService;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import jakarta.annotation.Resource;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
@@ -125,7 +126,7 @@ public class NotifyConfigServiceImpl extends ServiceImpl<NotifyConfigMapper, Not
     }
 
     @Override
-    public Boolean insertMessByRule(MessSaveVO vo) {
+    public Boolean insertMessByRule(MessSaveVO vo) throws JsonProcessingException {
         // 1.先查询当前操作在isc_notify_config中有没有值
         NotifyConfigDO notifyConfigDO = getOne(Wrappers.<NotifyConfigDO>lambdaQuery()
                 .eq(NotifyConfigDO::getSopId, vo.getSopId())
@@ -139,11 +140,11 @@ public class NotifyConfigServiceImpl extends ServiceImpl<NotifyConfigMapper, Not
                 // 3.1提前
                 beforeSend(notifyConfigDO.getId(), vo.getTicketId(), vo.getShouldSendTime(), notifyConfigDO.getNotifyTime(), vo.getTemplateParams());
             }
-            if (notifyConfigDO.getNotifyTimeType().equals(0)) {
+            if (notifyConfigDO.getNotifyTimeType().equals(1)) {
                 // 3.2立即
                 immediatelySend(notifyConfigDO.getId(), vo.getTicketId(), vo.getTemplateParams());
             }
-            if (notifyConfigDO.getNotifyTimeType().equals(0)) {
+            if (notifyConfigDO.getNotifyTimeType().equals(2)) {
                 // 3.3延后
                 delaySend(notifyConfigDO.getId(), vo.getTicketId(), vo.getShouldSendTime(), notifyConfigDO.getNotifyTime(), vo.getTemplateParams());
             }
@@ -151,6 +152,8 @@ public class NotifyConfigServiceImpl extends ServiceImpl<NotifyConfigMapper, Not
         return true;
     }
 
+    ObjectMapper objectMapper = new ObjectMapper();
+
     /**
      * 提前发送的消息
      *
@@ -161,7 +164,8 @@ public class NotifyConfigServiceImpl extends ServiceImpl<NotifyConfigMapper, Not
      * @param templateParams    参数模板
      * @return
      */
-    private Boolean beforeSend(Long notifyConfigId, Long ticketId, LocalDateTime shouldSendTime, Integer secondsToSubtract, Map<String, Object> templateParams) {
+    private Boolean beforeSend(Long notifyConfigId, Long ticketId, LocalDateTime shouldSendTime, Integer secondsToSubtract, Map<String, Object> templateParams) throws JsonProcessingException {
+
         // 查询规则详情-启用的
         List<NotifyConfigDetailDO> notifyConfigDetailDOS = notifyConfigDetailService.list(Wrappers.<NotifyConfigDetailDO>lambdaQuery()
                 .eq(NotifyConfigDetailDO::getConfigId, notifyConfigId)
@@ -197,7 +201,7 @@ public class NotifyConfigServiceImpl extends ServiceImpl<NotifyConfigMapper, Not
                         notifyMessagePlanDO.setTemplateNickname(notifyTemplateByCodeFromCache.getNickname());
                         notifyMessagePlanDO.setTemplateContent(notifyTemplateService.formatNotifyTemplateContent(notifyTemplateByCodeFromCache.getContent(), templateParams));
                         notifyMessagePlanDO.setTemplateType(notifyTemplateByCodeFromCache.getType());
-                        notifyMessagePlanDO.setTemplateParams(new JSONArray(notifyTemplateByCodeFromCache.getParams()).toString());
+                        notifyMessagePlanDO.setTemplateParams(objectMapper.writeValueAsString(templateParams));
                         notifyMessagePlanDO.setPlanSendTime(shouldSendTime.minusSeconds(secondsToSubtract));
                         notifyMessagePlanDO.setSendStatus(0);
                         notifyMessagePlanService.save(notifyMessagePlanDO);
@@ -218,7 +222,7 @@ public class NotifyConfigServiceImpl extends ServiceImpl<NotifyConfigMapper, Not
                         notifyMessagePlanDO.setTemplateNickname(notifyTemplateByCodeFromCache.getNickname());
                         notifyMessagePlanDO.setTemplateContent(notifyTemplateService.formatNotifyTemplateContent(notifyTemplateByCodeFromCache.getContent(), templateParams));
                         notifyMessagePlanDO.setTemplateType(notifyTemplateByCodeFromCache.getType());
-                        notifyMessagePlanDO.setTemplateParams(new JSONArray(notifyTemplateByCodeFromCache.getParams()).toString());
+                        notifyMessagePlanDO.setTemplateParams(objectMapper.writeValueAsString(templateParams));
                         notifyMessagePlanDO.setPlanSendTime(shouldSendTime.minusSeconds(secondsToSubtract));
                         notifyMessagePlanDO.setSendStatus(0);
                         notifyMessagePlanService.save(notifyMessagePlanDO);
@@ -301,7 +305,7 @@ public class NotifyConfigServiceImpl extends ServiceImpl<NotifyConfigMapper, Not
      * @param templateParams    参数模板
      * @return
      */
-    private Boolean delaySend(Long notifyConfigId, Long ticketId, LocalDateTime shouldSendTime, Integer secondsToSubtract, Map<String, Object> templateParams) {
+    private Boolean delaySend(Long notifyConfigId, Long ticketId, LocalDateTime shouldSendTime, Integer secondsToSubtract, Map<String, Object> templateParams) throws JsonProcessingException {
         // 查询规则详情-启用的
         List<NotifyConfigDetailDO> notifyConfigDetailDOS = notifyConfigDetailService.list(Wrappers.<NotifyConfigDetailDO>lambdaQuery()
                 .eq(NotifyConfigDetailDO::getConfigId, notifyConfigId)
@@ -337,7 +341,7 @@ public class NotifyConfigServiceImpl extends ServiceImpl<NotifyConfigMapper, Not
                         notifyMessagePlanDO.setTemplateNickname(notifyTemplateByCodeFromCache.getNickname());
                         notifyMessagePlanDO.setTemplateContent(notifyTemplateService.formatNotifyTemplateContent(notifyTemplateByCodeFromCache.getContent(), templateParams));
                         notifyMessagePlanDO.setTemplateType(notifyTemplateByCodeFromCache.getType());
-                        notifyMessagePlanDO.setTemplateParams(new JSONArray(notifyTemplateByCodeFromCache.getParams()).toString());
+                        notifyMessagePlanDO.setTemplateParams(objectMapper.writeValueAsString(templateParams));
                         notifyMessagePlanDO.setPlanSendTime(shouldSendTime.plusSeconds(secondsToSubtract));
                         notifyMessagePlanDO.setSendStatus(0);
                         notifyMessagePlanService.save(notifyMessagePlanDO);
@@ -358,7 +362,7 @@ public class NotifyConfigServiceImpl extends ServiceImpl<NotifyConfigMapper, Not
                         notifyMessagePlanDO.setTemplateNickname(notifyTemplateByCodeFromCache.getNickname());
                         notifyMessagePlanDO.setTemplateContent(notifyTemplateService.formatNotifyTemplateContent(notifyTemplateByCodeFromCache.getContent(), templateParams));
                         notifyMessagePlanDO.setTemplateType(notifyTemplateByCodeFromCache.getType());
-                        notifyMessagePlanDO.setTemplateParams(new JSONArray(notifyTemplateByCodeFromCache.getParams()).toString());
+                        notifyMessagePlanDO.setTemplateParams(objectMapper.writeValueAsString(templateParams));
                         notifyMessagePlanDO.setPlanSendTime(shouldSendTime.minusSeconds(secondsToSubtract));
                         notifyMessagePlanDO.setSendStatus(0);
                         notifyMessagePlanService.save(notifyMessagePlanDO);

+ 1 - 1
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/utils/SuperDateUtils.java

@@ -8,12 +8,12 @@ import java.time.YearMonth;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.TemporalAdjusters;
 import java.util.*;
-import java.util.stream.Collectors;
 
 public class SuperDateUtils {
 
     private static final DateTimeFormatter YYYYMM = DateTimeFormatter.ofPattern("yyyy-MM");
     private static final DateTimeFormatter YYYYMMDD = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+    private static final DateTimeFormatter YYYYMMDDHHMMSS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
 
     private static final Map<String, DayOfWeek> WEEKDAY_MAP = new HashMap<>();
 

+ 2 - 2
yudao-module-iscs/src/main/resources/mapper/NotifyConfigMapper.xml

@@ -20,8 +20,8 @@
         LEFT JOIN isc_workstation w ON w.id = n.workstation_id
         LEFT JOIN isc_sop_workflow_step ws ON ws.id = n.rule and n.type = 3
         <where>
-            <if test="vo.sopId != null and vo.sopId.trim != ''">
-                n.sop_id #{vo.sopId}
+            <if test="vo.sopId != null">
+                n.sop_id = #{vo.sopId}
             </if>
         </where>
     </select>