From 77d0c382e4b171b897c6e9f405ea0cff858a0072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=98=89=E4=BC=9F?= <1724121454@qq.com> Date: Tue, 12 Oct 2021 14:27:14 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=BC=82=E5=B8=B8=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=E5=86=85=E5=AE=B9=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=8F=96=E6=B6=88=E5=8E=9F=E5=9B=A0=202.=20=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E4=BF=AE=E6=94=B9=203.=20=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=BE=85=E5=8A=9E=E4=BA=8B=E9=A1=B9=E5=8F=91?= =?UTF-8?q?=E9=80=81=E6=B6=88=E6=81=AF=204.=20=E5=BC=82=E5=B8=B8=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E5=99=A8=E5=86=99=E6=97=A5=E5=BF=97=E7=9A=84=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E4=BF=A1=E6=81=AF=E4=BF=AE=E6=94=B9=205.=20=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=BB=B4=E4=BF=AE=E6=8F=90=E6=8A=A5=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=B6=88=E6=81=AF=206.=20=E6=8A=8AStringUtils=E7=9A=84?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=B6=88=E6=81=AF=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E7=9A=84=E6=AD=A3=E5=88=99=E8=A1=A8=E8=BE=BE=E5=BC=8F=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../anomaly/service/AbnormalBillService.java | 2 +- .../service/impl/AbnormalBillServiceImpl.java | 4 +- .../service/impl/AbnormalPlanServiceImpl.java | 37 ++++-- .../service/impl/AnomalyJobServiceImpl.java | 17 ++- .../resources/mapper/AbnormalBillMapper.xml | 7 +- equip/pom.xml | 4 + .../mapper/ResourceRepairTaskMapper.java | 6 +- .../service/ResourceRepairTaskService.java | 21 +++ .../impl/ResourceRepairTaskServiceImpl.java | 121 +++++++++++++++++- .../mapper/ResourceRepairTaskMapper.xml | 13 +- .../mesnac/meapi/util/StringUtils.java | 3 +- 11 files changed, 209 insertions(+), 26 deletions(-) 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;