diff --git a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/AbnormalBillService.java b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/AbnormalBillService.java index 91bab651..f3a377b4 100644 --- a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/AbnormalBillService.java +++ b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/AbnormalBillService.java @@ -155,7 +155,7 @@ public interface AbnormalBillService extends IService { void batchRepair(SfcDto sfcDto); /** - * 根据异常单的状态和对应的用户组找到对应的消息类型 + * 根据异常单的状态和对应的用户组(status对应不同的用户组)找到对应的消息类型 * @param message * @param abnormalBill * @param abnormalBillDispose diff --git a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AbnormalBillServiceImpl.java b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AbnormalBillServiceImpl.java index 9fb5d1c6..fdc0d4cf 100644 --- a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AbnormalBillServiceImpl.java +++ b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AbnormalBillServiceImpl.java @@ -1176,7 +1176,7 @@ public class AbnormalBillServiceImpl extends ServiceImpl customFieldByUserId = usrMapper.findCustomFieldByUserId(site, nwaUsers); if(customFieldByUserId != null && customFieldByUserId.size() <= 0){ - throw new BaseException("消息发送失败,发送的用户组下面的自定义数据没有维护"); + throw new BaseException("消息发送失败,发送的用户组下面的用户的自定义数据没有维护"); } StringBuilder sendUsers = new StringBuilder(); for (int i = 0; i < Objects.requireNonNull(customFieldByUserId).size(); i++) { diff --git a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AbnormalPlanServiceImpl.java b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AbnormalPlanServiceImpl.java index 5ec69833..c47ed487 100644 --- a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AbnormalPlanServiceImpl.java +++ b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AbnormalPlanServiceImpl.java @@ -20,7 +20,10 @@ import com.foreverwin.mesnac.common.model.Message; import com.foreverwin.mesnac.common.service.MessageService; import com.foreverwin.mesnac.common.util.ActiveMQUtil; import com.foreverwin.mesnac.common.util.StringUtil; +import com.foreverwin.mesnac.listener.mapper.UsrMapper; +import com.foreverwin.mesnac.meapi.mapper.MessageTypeMapper; import com.foreverwin.mesnac.meapi.mapper.UserGroupMapper; +import com.foreverwin.mesnac.meapi.model.MessageType; import com.foreverwin.mesnac.meapi.model.NwaUser; import com.foreverwin.mesnac.meapi.model.UserGroup; import com.foreverwin.mesnac.meapi.service.NwaUserService; @@ -78,6 +81,12 @@ public class AbnormalPlanServiceImpl extends ServiceImpl selectPage(FrontPage frontPage, AbnormalPlan abnormalPlan) { @@ -191,18 +200,22 @@ public class AbnormalPlanServiceImpl extends ServiceImpl customFieldByUserId = usrMapper.findCustomFieldByUserId(site, nwaUsers); + if(customFieldByUserId != null && customFieldByUserId.size() <= 0){ + throw new BaseException("消息发送失败,发送的用户组下面的自定义数据没有维护"); + } StringBuilder sendUsers = new StringBuilder(); - for (int i = 0; i < Objects.requireNonNull(nwaUsers).size(); i++) { - if(i == (nwaUsers.size() - 1)){ - sendUsers.append(nwaUsers.get(i).getUserName()); + for (int i = 0; i < Objects.requireNonNull(customFieldByUserId).size(); i++) { + if(i == (customFieldByUserId.size() - 1)){ + sendUsers.append(customFieldByUserId.get(i)); }else{ - sendUsers.append(nwaUsers.get(i).getUserName()).append("|"); + sendUsers.append(customFieldByUserId.get(i)).append("|"); } } activeMQUtil.wechatSendMessage(sendUsers.toString(),message.getContent()); diff --git a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AnomalyJobServiceImpl.java b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AnomalyJobServiceImpl.java index 9b5b2c58..a26bc9a5 100644 --- a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AnomalyJobServiceImpl.java +++ b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AnomalyJobServiceImpl.java @@ -127,14 +127,22 @@ public class AnomalyJobServiceImpl implements AnomalyJobService { abnormalMessage.setModifiedUser(user); abnormalMessage.setModifiedDateTime(now); + List nwaUsers = null; //发送消息 - List nwaUsers = nwaUserService.checkUserGroup(site,abnormalMessage.getSendUserGroup()); + try{ + nwaUsers = nwaUserService.checkUserGroup(site,abnormalMessage.getSendUserGroup()); + if(nwaUsers == null){ + logger.info("异常单:"+abnormalBill.getAbnormalNo()+"消息发送失败,错误信息:找不到发送的用户组\n"); + } + }catch(Exception e){ + logger.info("异常单:"+abnormalBill.getAbnormalNo()+"消息发送失败,错误信息:找不到发送的用户组\n"); + } if(nwaUsers != null && nwaUsers.size() <= 0){ - logger.info("消息发送失败,发送的用户组下面没有用户") ; + logger.info("异常单:"+abnormalBill.getAbnormalNo()+"消息发送失败,错误信息:发送的用户组下面没有用户\n") ; }else{ List customFieldByUserId = usrMapper.findCustomFieldByUserId(site, nwaUsers); if(customFieldByUserId != null && customFieldByUserId.size() <= 0){ - logger.info("消息发送失败,发送的用户组下面的用户的自定义数据没有维护"); + logger.info("异常单:"+abnormalBill.getAbnormalNo()+"消息发送失败,错误信息:发送的用户组下面的用户的自定义数据没有维护\n"); }else { StringBuilder sendUsers = new StringBuilder(); for (int i = 0; i < Objects.requireNonNull(customFieldByUserId).size(); i++) { @@ -164,7 +172,8 @@ public class AnomalyJobServiceImpl implements AnomalyJobService { messageTypeQueryWrapper.setEntity(messageTypeEntity); MessageType sendMessageType = messageTypeMapper.selectOne(messageTypeQueryWrapper); if(sendMessageType == null){ - return "消息类型:"+message.getMessageType()+"找不到,异常单为:"+abnormalBill.getAbnormalNo()+",状态为:"+abnormalBill.getStatus(); + // return "消息类型:"+message.getMessageType()+"找不到,异常单为:"+abnormalBill.getAbnormalNo()+",状态为:"+abnormalBill.getStatus(); + return "找不到消息类型!!!"; } //找到要替换的消息 Map replaceMessage = abnormalBillMapper.findReplaceMessageByAbnormal(abnormalBill); diff --git a/anomaly/src/main/resources/mapper/AbnormalBillMapper.xml b/anomaly/src/main/resources/mapper/AbnormalBillMapper.xml index 54dda5e8..6f39e4eb 100644 --- a/anomaly/src/main/resources/mapper/AbnormalBillMapper.xml +++ b/anomaly/src/main/resources/mapper/AbnormalBillMapper.xml @@ -1281,7 +1281,8 @@ WHEN zabd.ABNORMAL_METHOD = 'FB' THEN '返修(不返回原工艺)' ELSE '' END METHOD, - zab.ABNORMAL_NO ABNORMAL_NO + zab.ABNORMAL_NO, + zab.CANCEL_REASON CANCEL_REASON FROM Z_ABNORMAL_BILL zab INNER JOIN ITEM i ON i.HANDLE = zab.ITEM_BO LEFT JOIN RESRCE r ON r.RESRCE = zab.RESRCE AND r.SITE = zab.SITE @@ -1307,7 +1308,9 @@ GROUP BY wct.DESCRIPTION ,so.SHOP_ORDER ,it.DESCRIPTION,r.DESCRIPTION,r2.DESCRIPTION, - zab.WORK_ORDER,zab.ITEM_NUMBER,zabd.ABNORMAL_METHOD,zab.ABNORMAL_NO,item.VALUE,workOrder.VALUE + zab.WORK_ORDER,zab.ITEM_NUMBER,zabd.ABNORMAL_METHOD,zab.ABNORMAL_NO,item.VALUE,workOrder.VALUE, + zab.CANCEL_REASON + diff --git a/equip/pom.xml b/equip/pom.xml index 120e07e8..618f0618 100644 --- a/equip/pom.xml +++ b/equip/pom.xml @@ -78,5 +78,9 @@ com.google.guava guava + + com.foreverwin.mesnac + listener + \ No newline at end of file diff --git a/equip/src/main/java/com/foreverwin/mesnac/equip/mapper/ResourceRepairTaskMapper.java b/equip/src/main/java/com/foreverwin/mesnac/equip/mapper/ResourceRepairTaskMapper.java index f4e139a5..763cbf1c 100644 --- a/equip/src/main/java/com/foreverwin/mesnac/equip/mapper/ResourceRepairTaskMapper.java +++ b/equip/src/main/java/com/foreverwin/mesnac/equip/mapper/ResourceRepairTaskMapper.java @@ -1,11 +1,12 @@ package com.foreverwin.mesnac.equip.mapper; -import com.foreverwin.mesnac.equip.model.ResourceRepairTask; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.foreverwin.mesnac.equip.model.ResourceRepairTask; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Map; /** *

@@ -46,4 +47,7 @@ public interface ResourceRepairTaskMapper extends BaseMapper */ void insertRepairTaskLog(ResourceRepairTask resourceRepairTask); + + Map findReplaceMessageByResourceRepairTask(ResourceRepairTask resourceRepairTask); + } \ No newline at end of file diff --git a/equip/src/main/java/com/foreverwin/mesnac/equip/service/ResourceRepairTaskService.java b/equip/src/main/java/com/foreverwin/mesnac/equip/service/ResourceRepairTaskService.java index b86159de..f0709c0f 100644 --- a/equip/src/main/java/com/foreverwin/mesnac/equip/service/ResourceRepairTaskService.java +++ b/equip/src/main/java/com/foreverwin/mesnac/equip/service/ResourceRepairTaskService.java @@ -76,4 +76,25 @@ public interface ResourceRepairTaskService extends IService */ Boolean updateResourceRepairTaskInfoByHandle(ResourceRepairTask resourceRepairTask); + /** + * 发送消息 + * 消息内容 以下为可在消息内容中替换的字段 + * #WORKCENTER# 车间 + * #RESRCE# 设备 + * #DESCRIPTION# 设备描述 + * #NCCODE# 故障代码(描述) + * #NCDESCRIPTION 不良补充描述 + * @param resourceRepairTask 根据它的handle找到要替换的字段 + */ + void createAndSendMessage(ResourceRepairTask resourceRepairTask); + + /** + * 格式化消息内容 + * @param resourceRepairTask 从这个实体类中找到要替换的消息内容 + * @param messageType 消息类型,根据它找到对应的消息内容 + * @param site 站点 + * @return + */ + String formatMessage(ResourceRepairTask resourceRepairTask,String messageType,String site); + } \ No newline at end of file diff --git a/equip/src/main/java/com/foreverwin/mesnac/equip/service/impl/ResourceRepairTaskServiceImpl.java b/equip/src/main/java/com/foreverwin/mesnac/equip/service/impl/ResourceRepairTaskServiceImpl.java index 2fee846c..f3e68108 100644 --- a/equip/src/main/java/com/foreverwin/mesnac/equip/service/impl/ResourceRepairTaskServiceImpl.java +++ b/equip/src/main/java/com/foreverwin/mesnac/equip/service/impl/ResourceRepairTaskServiceImpl.java @@ -6,7 +6,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.foreverwin.mesnac.common.constant.Constants; import com.foreverwin.mesnac.common.enums.HandleEnum; import com.foreverwin.mesnac.common.helper.NextNumberHelper; +import com.foreverwin.mesnac.common.model.Message; import com.foreverwin.mesnac.common.service.AnomalyService; +import com.foreverwin.mesnac.common.service.MessageService; +import com.foreverwin.mesnac.common.util.ActiveMQUtil; +import com.foreverwin.mesnac.common.util.StringUtil; import com.foreverwin.mesnac.equip.mapper.ResourceInspectTaskMapper; import com.foreverwin.mesnac.equip.mapper.ResourceRepairTaskMapper; import com.foreverwin.mesnac.equip.model.ResourceInspectTask; @@ -15,14 +19,20 @@ import com.foreverwin.mesnac.equip.model.ResourceRepairTask; import com.foreverwin.mesnac.equip.service.ResourceInspectPlanService; import com.foreverwin.mesnac.equip.service.ResourceInspectTaskSpareService; import com.foreverwin.mesnac.equip.service.ResourceRepairTaskService; +import com.foreverwin.mesnac.listener.mapper.UsrMapper; +import com.foreverwin.mesnac.meapi.mapper.MessageTypeMapper; import com.foreverwin.mesnac.meapi.mapper.NcCodeMapper; import com.foreverwin.mesnac.meapi.mapper.NwaUserMapper; +import com.foreverwin.mesnac.meapi.mapper.UserGroupMapper; import com.foreverwin.mesnac.meapi.model.DataField; +import com.foreverwin.mesnac.meapi.model.MessageType; import com.foreverwin.mesnac.meapi.model.NwaUser; +import com.foreverwin.mesnac.meapi.model.UserGroup; import com.foreverwin.mesnac.meapi.service.DataFieldListService; import com.foreverwin.mesnac.meapi.service.NcCodeService; import com.foreverwin.mesnac.meapi.service.NwaUserService; import com.foreverwin.mesnac.meapi.service.ResrceService; +import com.foreverwin.modular.core.exception.BaseException; import com.foreverwin.modular.core.exception.BusinessException; import com.foreverwin.modular.core.util.CommonMethods; import com.foreverwin.modular.core.util.FrontPage; @@ -34,10 +44,7 @@ import org.springframework.transaction.annotation.Transactional; import java.time.Duration; import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.UUID; +import java.util.*; /** *

@@ -77,6 +84,16 @@ public class ResourceRepairTaskServiceImpl extends ServiceImpl init() { @@ -155,6 +172,7 @@ public class ResourceRepairTaskServiceImpl extends ServiceImpl nwaUsers = nwaUserService.checkUserGroup(site,message.getSendUserGroup()); + if(nwaUsers != null && nwaUsers.size() <= 0){ + throw new BaseException("消息发送失败,发送的用户组下面没有用户"); + } + List customFieldByUserId = usrMapper.findCustomFieldByUserId(site, nwaUsers); + if(customFieldByUserId != null && customFieldByUserId.size() <= 0){ + throw new BaseException("消息发送失败,发送的用户组下面的用户的自定义数据没有维护"); + } + StringBuilder sendUsers = new StringBuilder(); + for (int i = 0; i < Objects.requireNonNull(customFieldByUserId).size(); i++) { + if(i == (customFieldByUserId.size() - 1)){ + sendUsers.append(customFieldByUserId.get(i)); + }else{ + sendUsers.append(customFieldByUserId.get(i)).append("|"); + } + } + activeMQUtil.wechatSendMessage(sendUsers.toString(),message.getContent()); + messageService.saveOrUpdate(message); + } + + @Override + public String formatMessage(ResourceRepairTask resourceRepairTask, String messageType, String site) { + /* + * 找到对应的消息内容 + */ + MessageType messageTypeEntity = new MessageType(); + messageTypeEntity.setSite(site); + messageTypeEntity.setMessageType(messageType); + QueryWrapper messageTypeQueryWrapper = new QueryWrapper(); + messageTypeQueryWrapper.setEntity(messageTypeEntity); + MessageType sendMessageType = messageTypeMapper.selectOne(messageTypeQueryWrapper); + if(sendMessageType == null){ + throw new BaseException("维修提报找不到要发送的消息类型"); + } + + /** + * 把消息内容中,对应的map的key替换为 resourceRepairTask中对应的字段(变量) + */ + Map replaceMessageMap = resourceRepairTaskMapper.findReplaceMessageByResourceRepairTask(resourceRepairTask); + String messageBody = sendMessageType.getBody(); + //格式化之后的消息 + return com.foreverwin.mesnac.meapi.util.StringUtils.format(messageBody, replaceMessageMap); + } } \ No newline at end of file diff --git a/equip/src/main/resources/mapper/ResourceRepairTaskMapper.xml b/equip/src/main/resources/mapper/ResourceRepairTaskMapper.xml index 7f805ada..727b9a21 100644 --- a/equip/src/main/resources/mapper/ResourceRepairTaskMapper.xml +++ b/equip/src/main/resources/mapper/ResourceRepairTaskMapper.xml @@ -1051,5 +1051,16 @@ - + diff --git a/meapi/src/main/java/com/foreverwin/mesnac/meapi/util/StringUtils.java b/meapi/src/main/java/com/foreverwin/mesnac/meapi/util/StringUtils.java index cb2185f6..fd232af5 100644 --- a/meapi/src/main/java/com/foreverwin/mesnac/meapi/util/StringUtils.java +++ b/meapi/src/main/java/com/foreverwin/mesnac/meapi/util/StringUtils.java @@ -214,7 +214,8 @@ public class StringUtils { } } } - Pattern pattern = Pattern.compile("#.*#"); + Pattern pattern = Pattern.compile("#.*?#"); + Matcher matcher = pattern.matcher(message); message = matcher.replaceAll("[空]"); return message;