From 80f12130a849f3934bcd441ad582d4fe925c9d72 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B5=E5=98=89=E4=BC=9F?= <1724121454@qq.com>
Date: Thu, 22 Jul 2021 13:16:53 +0800
Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E8=AE=A1=E6=97=B6=E5=99=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
anomaly/pom.xml | 5 +
.../anomaly/service/AbnormalBillService.java | 10 +-
.../anomaly/service/AnomalyJobService.java | 15 +
.../service/impl/AbnormalBillServiceImpl.java | 286 ++++++++++++------
.../service/impl/AnomalyJobServiceImpl.java | 122 ++++++++
.../mesnac/anomaly/util/ActiveMQUtil.java | 64 ++++
.../src/main/resources/application-local.yml | 4 +-
.../service/impl/NcGroupServiceImpl.java | 5 +-
.../mesnac/quartz/job/AnomalyJob.java | 43 +++
9 files changed, 453 insertions(+), 101 deletions(-)
create mode 100644 anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/AnomalyJobService.java
create mode 100644 anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AnomalyJobServiceImpl.java
create mode 100644 anomaly/src/main/java/com/foreverwin/mesnac/anomaly/util/ActiveMQUtil.java
create mode 100644 quartz/src/main/java/com/foreverwin/mesnac/quartz/job/AnomalyJob.java
diff --git a/anomaly/pom.xml b/anomaly/pom.xml
index 1796024e..47f0bbd1 100644
--- a/anomaly/pom.xml
+++ b/anomaly/pom.xml
@@ -76,5 +76,10 @@
commons-net
3.1
+
+ org.springframework.boot
+ spring-boot-starter-quartz
+ 2.0.5.RELEASE
+
\ No newline at end of file
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 965dc0fa..455099e8 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
@@ -44,6 +44,7 @@ public interface AbnormalBillService extends IService {
/**
* 生成异常单号、创建时间和更新时间
+ * 异常提报的时候调用的公共方法
* @param abnormalBill
* @param abnormalBillDispose
*/
@@ -124,8 +125,13 @@ public interface AbnormalBillService extends IService {
// void deleteFileInDatabase(String ftpPath,String fileName);
/**
- * 异常提报发送消息
+ * 异常发送消息
*/
- boolean anomalyReportSendMessage(AbnormalBill abnormalBill);
+ boolean anomalyCreatedAndSendMessage(AbnormalBill abnormalBill,AbnormalBillDispose abnormalBillDispose);
+
+ /**
+ * 格式化消息
+ */
+ String formatMessage(AbnormalBill abnormalBill,String messageType, String site);
}
\ No newline at end of file
diff --git a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/AnomalyJobService.java b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/AnomalyJobService.java
new file mode 100644
index 00000000..5ddbd382
--- /dev/null
+++ b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/AnomalyJobService.java
@@ -0,0 +1,15 @@
+package com.foreverwin.mesnac.anomaly.service;
+
+/**
+ * @Description TODO
+ * @Author zhaojiawei
+ * @Since 2021-07-22
+ */
+public interface AnomalyJobService {
+
+ /**
+ * 异常计时器进程
+ * @param site
+ */
+ void anomalyJobProcess(String site);
+}
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 536d7dca..a6f4bfe8 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
@@ -7,8 +7,10 @@ import com.foreverwin.mesnac.anomaly.dto.AbnormalBillDisposeDto;
import com.foreverwin.mesnac.anomaly.dto.AbnormalBillDto;
import com.foreverwin.mesnac.anomaly.mapper.AbnormalBillDisposeMapper;
import com.foreverwin.mesnac.anomaly.mapper.AbnormalBillMapper;
+import com.foreverwin.mesnac.anomaly.mapper.AbnormalMessageMapper;
import com.foreverwin.mesnac.anomaly.model.*;
import com.foreverwin.mesnac.anomaly.service.*;
+import com.foreverwin.mesnac.anomaly.util.ActiveMQUtil;
import com.foreverwin.mesnac.common.constant.Constants;
import com.foreverwin.mesnac.common.enums.HandleEnum;
import com.foreverwin.mesnac.common.helper.NextNumberHelper;
@@ -119,6 +121,15 @@ public class AbnormalBillServiceImpl extends ServiceImpl selectPage(FrontPage frontPage, AbnormalBill abnormalBill) {
QueryWrapper queryWrapper = new QueryWrapper<>();
@@ -142,6 +153,8 @@ public class AbnormalBillServiceImpl extends ServiceImpl status = new ArrayList<>();
status.add(Constants.PROGRAM_CONFIRM);
status.add(Constants.CANCEL);
status.add(Constants.SHUT_DOWN);
List abnormalBillList = abnormalBillMapper.findCountBySfc(abnormalBill.getSite(), abnormalBill.getType(), abnormalBill.getSfc(), status);
-
- if(abnormalBillList.size() > 1 && !"更新成功".equals(message)){
- throw BusinessException.build("设备异常有未处理完成的sfc");
- }else if(abnormalBillList.size() > 1 ){
+ if(abnormalBillList.size() >= 1 ){
throw BusinessException.build("设备异常有未处理完成的sfc");
}
}
+ abnormalBillDisposeService.saveOrUpdate(abnormalBillDispose);
+ this.saveOrUpdate(abnormalBill);
+ //发送消息
+ this.anomalyCreatedAndSendMessage(abnormalBill,null);
return message;
}
@@ -311,6 +326,8 @@ public class AbnormalBillServiceImpl extends ServiceImpl dutyCauseType,List dutyType) {
String site = CommonMethods.getSite();
- String message = null;
+ //返回的消息
+ String message = "保存成功";
LocalDateTime currentTime = LocalDateTime.now();
String user = CommonMethods.getUser();
+ //如果前台传过来的异常单为空的话,则抛出一个异常
if(StringUtil.isBlank(abnormalBill.getAbnormalNo())) {
throw BusinessException.build("异常单号不存在");
}
+ //设置异常单的handle
abnormalBill.setHandle(HandleEnum.Z_ABNORMAL_BILL.getHandle(site,abnormalBill.getAbnormalNo()));
- //更新的时候,判断该异常单的状态是否为新建
- AbnormalBill abnormalBill1 = abnormalBillMapper.selectById(abnormalBill.getHandle());
- if(abnormalBill1 != null){
- if(!"N".equals(abnormalBill1.getStatus()) && StringUtil.isBlank(abnormalBillDispose.getClosedUser())){
- throw BusinessException.build("该异常单已经被人处理,不能进行更新");
- }
- message = "更新成功";
- }else{
- message = "保存成功";
+ if(abnormalBillMapper.selectById(abnormalBill.getHandle()) != null &&
+ !Constants.SHUT_DOWN.equals(abnormalBill.getStatus())){
+ throw BusinessException.build("该异常单已经提交,请清空后提交");
}
- abnormalBillDispose.setClosedUser(null);
+ /**
+ * 取消异常提报的更新
+ */
+
+ //更新的时候,判断该异常单的状态是否为新建,如果为新建,则可以修改,否则就不能进行修改
+// AbnormalBill abnormalBill1 = abnormalBillMapper.selectById(abnormalBill.getHandle());
+// if(abnormalBill1 != null){
+// if(!"N".equals(abnormalBill1.getStatus()) && StringUtil.isBlank(abnormalBillDispose.getClosedUser())){
+// throw BusinessException.build("该异常单已经被人处理,不能进行更新");
+// }
+// message = "更新成功";
+// }else{
+// message = "保存成功";
+// }
+// abnormalBillDispose.setClosedUser(null);
+ //设置异常单详细表的handle和abnormalBillBo
abnormalBillDispose.setAbnormalBillBo(abnormalBill.getHandle());
abnormalBillDispose.setHandle(HandleEnum.Z_ABNORMAL_BILL_DISPOSE.getHandle(site,abnormalBill.getAbnormalNo()));
//设置责任划分填报人和填报时间
- if(StringUtil.isBlank(abnormalBillDispose.getDutyUser())){
- abnormalBillDispose.setDutyUser(user);
- abnormalBillDispose.setDutyDateTime(currentTime);
- }
- ArrayList causeTypes = new ArrayList<>();
+ abnormalBillDispose.setDutyUser(user);
+ abnormalBillDispose.setDutyDateTime(currentTime);
+
//判断原因分类是否为空,如果不为空,把它放进Z_ABNORMAL_CAUSE表里面
+ ArrayList causeTypes = new ArrayList<>();
if(dutyCauseType != null && dutyCauseType.size() >= 1){
for(String cause:dutyCauseType){
AbnormalCause abnormalCause = new AbnormalCause();
@@ -458,9 +492,8 @@ public class AbnormalBillServiceImpl extends ServiceImpl operationQueryWrapper = new QueryWrapper();
operationQueryWrapper.eq("OPERATION",abnormalBill.getOperation())
@@ -471,9 +504,7 @@ public class AbnormalBillServiceImpl extends ServiceImpl ncCodes = Arrays.asList(abnormalBill.getNcCode().split(","));
Integer length = ncCodeMapper.checkNcCode(ncCodes,site,"FAILURE");
@@ -528,6 +559,10 @@ public class AbnormalBillServiceImpl extends ServiceImpl 0){
@@ -582,10 +617,7 @@ public class AbnormalBillServiceImpl extends ServiceImpl sendUsersList = nwaUserService.checkUserGroup(abnormalBill.getReportSendUserGroup());
+ public boolean anomalyCreatedAndSendMessage(AbnormalBill abnormalBill,AbnormalBillDispose abnormalBillDispose){
String site = CommonMethods.getSite();
String user = CommonMethods.getUser();
String locale = LocaleContextHolder.getLocale().getLanguage();
@@ -770,37 +806,123 @@ public class AbnormalBillServiceImpl extends ServiceImpl wrapper = new QueryWrapper<>();
+ AbnormalMessage abnormalMessage1 = new AbnormalMessage();
+ abnormalMessage1.setSite(site);
+ abnormalMessage1.setAbnormalBillBo(abnormalBill.getHandle());
+ abnormalMessage1.setAbnormalNode(Constants.ABNORMAL_MESSAGE_REPORT);
+ wrapper.setEntity(abnormalMessage1);
+ AbnormalMessage _abnormalMessage = abnormalMessageMapper.selectOne(wrapper);
+ abnormalMessage.setUpUserGroup(_abnormalMessage.getUpUserGroup());
+ abnormalMessage.setGrade(_abnormalMessage.getGrade());
+ abnormalMessage.setUpDateTime(_abnormalMessage.getUpDateTime());
+ abnormalMessage.setAbnormalNode(Constants.ABNORMAL_MESSAGE_RESPONSE);
+ break;
+ case Constants.CORRECTION_CONFIRM://纠纷确认
+ abnormalMessage.setSendUserGroup(abnormalBillDispose.getDutySendUserGroup());
+ abnormalMessage.setAbnormalNode(Constants.ABNORMAL_MESSAGE_CORRECTION_CONFIRM);
+ break;
+ case Constants.PROGRAM_CONFIRM://方案确认
+ abnormalMessage.setSendUser(abnormalBillDispose.getResolveSendUser());
+ abnormalMessage.setAbnormalNode(Constants.ABNORMAL_MESSAGE_PROGRAM_CONFIRM);
+ break;
+ case Constants.CANCEL://取消
+ abnormalMessage.setSendUserGroup(abnormalBill.getCancelSendUserGroup());
+ abnormalMessage.setAbnormalNode(Constants.ABNORMAL_MESSAGE_CANCEL);
+ break;
+ case Constants.SHUT_DOWN:
+ break;
+ }
+
+ String message = this.formatMessage(abnormalBill, abnormalMessage.getMessageType(), site);
+ //得到消息触发的时间
+ abnormalMessage.setResponseDateTime(now);
+ //得到要发送的消息
+ abnormalMessage.setContent(message);
+ //得到升级的用户组
+ //新建有、响应没有、纠防确认有、方案确认没有、取消没有、关闭没有
+ if(Constants.NEW.equals(abnormalBill.getStatus()) || Constants.CORRECTION_CONFIRM.equals(abnormalBill.getStatus())){
+ abnormalMessage.setUpUserGroup(abnormalMessage.getSendUserGroup()+"_UP");
+ //得到升级的时间和等级
+
+ UserGroup customFieldByGroup = userGroupMapper.getCustomFieldByGroup(site, abnormalMessage.getSendUserGroup());
+ abnormalMessage.setUpDateTime(abnormalMessage.getResponseDateTime().plusMinutes(Integer.parseInt(customFieldByGroup.getMessageNoticeTime())));
+ abnormalMessage.setGrade(customFieldByGroup.getMessageNoticeLevel());
+ //得到升级的消息类型
+ abnormalMessage.setUpMessageType(abnormalMessage.getMessageType());
+ }
+
+
+
+ //得到异常节点
+
+ //abnormalMessage.setAbnormalNode(Constants.ABNORMAL_MESSAGE_REPORT);
+
+
+ //设置状态,新建是Y,响应为N,纠防确认是N,方案确认是Y,
+ if(Constants.ABNORMAL_MESSAGE_RESPONSE.equals(abnormalMessage.getAbnormalNode()) ||
+ Constants.ABNORMAL_MESSAGE_CORRECTION_CONFIRM.equals(abnormalMessage.getAbnormalNode())){
+ abnormalMessage.setStatus("N");
+ }else{
+ abnormalMessage.setStatus("Y");
+ }
+
+
+ abnormalMessage.setCreatedUser(user);
+ abnormalMessage.setCreatedDateTime(now);
+ abnormalMessage.setModifiedUser(user);
+ abnormalMessage.setModifiedDateTime(now);
+
+
+ //判断,如果是方案确认,则发送用户,否则,除了节点是响应之外,则发送用户
+ if(Constants.ABNORMAL_MESSAGE_PROGRAM_CONFIRM.equals(abnormalMessage.getAbnormalNode())){
+ String sendUsers = abnormalMessage.getSendUser().replace(',', '|');
+ activeMQUtil.wechatSendMessage(sendUsers,abnormalMessage.getContent());
+ }else if(!Constants.ABNORMAL_MESSAGE_RESPONSE.equals(abnormalMessage.getAbnormalNode())){
+ List nwaUsers = nwaUserService.checkUserGroup(abnormalMessage.getSendUserGroup());
+ StringBuilder sendUsers = new StringBuilder();
+ for (int i = 0; i < nwaUsers.size(); i++) {
+ if(i == (nwaUsers.size() - 1)){
+ sendUsers.append(nwaUsers.get(i));
+ }else{
+ sendUsers.append(nwaUsers.get(i)).append("|");
+ }
+ }
+ activeMQUtil.wechatSendMessage(sendUsers.toString(),abnormalMessage.getContent());
+ }
+ abnormalMessageService.saveOrUpdate(abnormalMessage);
+ return true;
+ }
+
+ @Override
+ public String formatMessage(AbnormalBill abnormalBill,String messageType, String site) {
//找到消息内容
+ String locale = LocaleContextHolder.getLocale().getLanguage();
MessageType messageTypeEntity = new MessageType();
messageTypeEntity.setSite(site);
- messageTypeEntity.setMessageType(abnormalMessage.getMessageType());
+ messageTypeEntity.setMessageType(messageType);
QueryWrapper messageTypeQueryWrapper = new QueryWrapper();
messageTypeQueryWrapper.setEntity(messageTypeEntity);
- MessageType messageType = messageTypeMapper.selectOne(messageTypeQueryWrapper);
+ MessageType sendMessageType = messageTypeMapper.selectOne(messageTypeQueryWrapper);
if(messageType == null){
throw new BaseException("异常提报时找不到要发送的消息类型");
}
//格式化消息
- String body = messageType.getBody();
+ String body = sendMessageType.getBody();
//替换消息类型中的参数
Map messageMap = new HashMap<>();
//根据车间找到对应车间的描述
@@ -813,49 +935,19 @@ public class AbnormalBillServiceImpl extends ServiceImpl _upSendUserGroups = Arrays.asList(abnormalMessage.getSendUserGroup().split(","));
-// for(int i = 0; i < _upSendUserGroups.size(); i++){
-// _upSendUserGroups.set(i,_upSendUserGroups.get(i)+"_UP");
-// }
-// List upSendUserGroups = userGroupMapper.getUserGroupListByGroups(site, _upSendUserGroups);
-// if(upSendUserGroups != null && upSendUserGroups.size() > 0){
-// abnormalMessage.setUpUserGroup(upSendUserGroups.get(0).getUserGroup());
-// }
- //得到升级的用户组
- abnormalMessage.setUpUserGroup(abnormalMessage.getSendUserGroup()+"_UP");
- //得到升级的消息类型
- abnormalMessage.setUpMessageType(abnormalMessage.getMessageType());
- //得到消息触发的时间
- abnormalMessage.setResponseDateTime(now);
- //得到升级的时间和等级
- UserGroup customFieldByGroup = userGroupMapper.getCustomFieldByGroup(site, abnormalMessage.getSendUserGroup());
- abnormalMessage.setUpDateTime(abnormalMessage.getResponseDateTime().plusMinutes(Integer.parseInt(customFieldByGroup.getMessageNoticeTime())));
- abnormalMessage.setGrade(customFieldByGroup.getMessageNoticeLevel());
- //得到异常节点
- abnormalMessage.setAbnormalNode(Constants.ABNORMAL_MESSAGE_REPORT);
- //设置状态
- if(Constants.ABNORMAL_MESSAGE_REPORT.equals(abnormalMessage.getAbnormalNode())){
- abnormalMessage.setStatus("Y");
- }else{
- abnormalMessage.setStatus("N");
- }
-
- abnormalMessage.setCreatedUser(user);
- abnormalMessage.setCreatedDateTime(now);
- abnormalMessage.setModifiedUser(user);
- abnormalMessage.setModifiedDateTime(now);
-
-
- return false;
+ //格式化之后的消息
+ return StringUtils.format(body, messageMap);
}
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
new file mode 100644
index 00000000..d3c9eb36
--- /dev/null
+++ b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AnomalyJobServiceImpl.java
@@ -0,0 +1,122 @@
+package com.foreverwin.mesnac.anomaly.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.foreverwin.mesnac.anomaly.mapper.AbnormalBillMapper;
+import com.foreverwin.mesnac.anomaly.mapper.AbnormalMessageMapper;
+import com.foreverwin.mesnac.anomaly.model.AbnormalBill;
+import com.foreverwin.mesnac.anomaly.model.AbnormalMessage;
+import com.foreverwin.mesnac.anomaly.service.AbnormalBillService;
+import com.foreverwin.mesnac.anomaly.service.AbnormalMessageService;
+import com.foreverwin.mesnac.anomaly.service.AnomalyJobService;
+import com.foreverwin.mesnac.anomaly.util.ActiveMQUtil;
+import com.foreverwin.mesnac.common.util.StringUtil;
+import com.foreverwin.mesnac.meapi.model.NwaUser;
+import com.foreverwin.mesnac.meapi.service.NwaUserService;
+import com.foreverwin.modular.core.util.CommonMethods;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * @Description TODO
+ * @Author zhaojiawei
+ * @Since 2021-07-22
+ */
+public class AnomalyJobServiceImpl implements AnomalyJobService {
+
+ @Autowired
+ private AbnormalMessageService abnormalMessageService;
+
+ @Autowired
+ private AbnormalMessageMapper abnormalMessageMapper;
+
+ @Autowired
+ private AbnormalBillMapper abnormalBillMapper;
+
+ @Autowired
+ private AbnormalBillService abnormalBillService;
+
+ @Autowired
+ private ActiveMQUtil activeMQUtil;
+
+ @Autowired
+ private NwaUserService nwaUserService;
+
+ @Override
+ public void anomalyJobProcess(String site) {
+ LocalDateTime now = LocalDateTime.now();
+ String user = CommonMethods.getUser();
+ //找到状态为N,并且升级时间大于当前时间
+ QueryWrapper abnormalMessageQueryWrapper = new QueryWrapper<>();
+ abnormalMessageQueryWrapper.eq("STATUS","N");
+ abnormalMessageQueryWrapper.gt("UP_DATE_TIME",now);
+ List abnormalMessages = abnormalMessageMapper.selectList(abnormalMessageQueryWrapper);
+ for(AbnormalMessage _abnormalMessage : abnormalMessages){
+ String uuid = UUID.randomUUID().toString();
+ AbnormalMessage abnormalMessage = new AbnormalMessage();
+ //设置abnormalMessage的handle
+ abnormalMessage.setHandle(uuid);
+ //设置abnormalMessage的site
+ abnormalMessage.setSite(_abnormalMessage.getSite());
+ //设置abnormalMessage的异常单Bo
+ abnormalMessage.setAbnormalBillBo(_abnormalMessage.getAbnormalBillBo());
+ //设置abnormalMessage的type
+ abnormalMessage.setType(_abnormalMessage.getType());
+ //设置abnormalMessage的message_type
+ abnormalMessage.setMessageType(_abnormalMessage.getUpMessageType());
+ //设置发送用户组和升级用户组
+ if(!StringUtil.isBlank(_abnormalMessage.getUpUserGroup())){
+ //当前发送用户组就等于升级用户组,升级用户组就等于空
+ abnormalMessage.setSendUserGroup(abnormalMessage.getUpUserGroup());
+ abnormalMessage.setUpUserGroup(null);
+ }
+
+ //设置发送用户和升级用户
+ if(!StringUtil.isBlank(abnormalMessage.getUpUser())){
+ //当前发送用户就等于升级用户,升级用户就等于空
+ abnormalMessage.setSendUser(abnormalMessage.getUpUser());
+ abnormalMessage.setUpUser(null);
+ }
+
+ AbnormalBill abnormalBill = abnormalBillMapper.selectById(abnormalMessage.getAbnormalBillBo());
+
+ String message = abnormalBillService.formatMessage(abnormalBill,abnormalMessage.getMessageType(),site);
+
+ abnormalMessage.setContent(message);
+
+ //设置UP_DATE_TIME、UP_MESSAGE_TYPE、GRADE、RESPONSE_DATE_TIME、ABNORMAL_NODE、STATUS
+ abnormalMessage.setUpMessageType(null);
+ abnormalMessage.setUpDateTime(null);
+
+ abnormalMessage.setGrade(abnormalMessage.getGrade() + 1);
+ abnormalMessage.setResponseDateTime(now);
+ abnormalMessage.setAbnormalNode(_abnormalMessage.getAbnormalNode());
+ abnormalMessage.setStatus("Y");
+
+ //设置时间
+ abnormalMessage.setCreatedUser(user);
+ abnormalMessage.setCreatedDateTime(now);
+ abnormalMessage.setModifiedUser(user);
+ abnormalMessage.setModifiedDateTime(now);
+
+// if(Constants.ABNORMAL_MESSAGE_PROGRAM_CONFIRM.equals(abnormalMessage.getAbnormalNode())){
+// String sendUsers = abnormalMessage.getSendUser().replace(',', '|');
+// activeMQUtil.wechatSendMessage(sendUsers,abnormalMessage.getContent());
+// }else if(!Constants.ABNORMAL_MESSAGE_RESPONSE.equals(abnormalMessage.getAbnormalNode())){
+ List nwaUsers = nwaUserService.checkUserGroup(abnormalMessage.getSendUserGroup());
+ StringBuilder sendUsers = new StringBuilder();
+ for (int i = 0; i < nwaUsers.size(); i++) {
+ if(i == (nwaUsers.size() - 1)){
+ sendUsers.append(nwaUsers.get(i));
+ }else{
+ sendUsers.append(nwaUsers.get(i)).append("|");
+ }
+ }
+ activeMQUtil.wechatSendMessage(sendUsers.toString(),abnormalMessage.getContent());
+// }
+ abnormalMessageService.saveOrUpdate(abnormalMessage);
+ }
+ }
+}
diff --git a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/util/ActiveMQUtil.java b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/util/ActiveMQUtil.java
new file mode 100644
index 00000000..08168f7a
--- /dev/null
+++ b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/util/ActiveMQUtil.java
@@ -0,0 +1,64 @@
+package com.foreverwin.mesnac.anomaly.util;
+
+import com.foreverwin.modular.core.exception.BaseException;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.json.JSONObject;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+
+import javax.jms.*;
+
+/**
+ * @Description TODO
+ * @Author zhaojiawei
+ * @Since 2021-07-21
+ */
+@Component
+@ConditionalOnProperty(prefix = "activeMq", value = {"enabled"}, matchIfMissing = true)
+public class ActiveMQUtil {
+ @Value("${activeMq.sendWeChatMessage}")
+ private String weChatUrl;
+ @Value("${activeMq.queue}")
+ private String queue;
+
+ public void wechatSendMessage(String user, String text) {
+ ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(weChatUrl);
+ Connection connection = null;
+ Session session = null;
+ MessageProducer producer = null;
+ try{
+ connection = factory.createConnection();
+ connection.start();
+ session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Destination destination = session.createQueue(this.queue);
+ producer = session.createProducer(destination);
+
+ JSONObject jsonObject = new JSONObject();
+ //jsonObject.put("TO_USER", user);
+ jsonObject.put("TO_USER", "@all");
+ jsonObject.put("CONTENT",text);
+ String sendMessage = jsonObject.toString();
+ TextMessage textMessage = session.createTextMessage(sendMessage);
+ producer.send(textMessage);
+ }catch (Exception e){
+ throw new BaseException("发送消息失败"+e.getMessage());
+ }finally {
+ try {
+ if (producer != null) {
+ producer.close();
+ }
+ if (session != null) {
+ session.close();
+ }
+ if (connection != null) {
+ connection.close();
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+
+ }
+}
diff --git a/console/src/main/resources/application-local.yml b/console/src/main/resources/application-local.yml
index a05e11ee..9b94113d 100644
--- a/console/src/main/resources/application-local.yml
+++ b/console/src/main/resources/application-local.yml
@@ -72,4 +72,6 @@ ftp:
port: 21
username: zjw
password: zhaojiawei
-
+activeMq:
+ sendWeChatMessage: tcp://localhost:61616?wireFormat.maxInactivityDuration=0
+ queue: send.weChat.notice
diff --git a/meapi/src/main/java/com/foreverwin/mesnac/meapi/service/impl/NcGroupServiceImpl.java b/meapi/src/main/java/com/foreverwin/mesnac/meapi/service/impl/NcGroupServiceImpl.java
index fe11e322..147ef90f 100644
--- a/meapi/src/main/java/com/foreverwin/mesnac/meapi/service/impl/NcGroupServiceImpl.java
+++ b/meapi/src/main/java/com/foreverwin/mesnac/meapi/service/impl/NcGroupServiceImpl.java
@@ -13,6 +13,7 @@ import com.foreverwin.modular.core.exception.BaseException;
import com.foreverwin.modular.core.util.CommonMethods;
import com.foreverwin.modular.core.util.FrontPage;
import com.sap.me.productdefinition.OperationBOHandle;
+import org.eclipse.jetty.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -63,7 +64,9 @@ public class NcGroupServiceImpl extends ServiceImpl impl
public List findNgGroupByOperationBo(Operation operation) {
String site = CommonMethods.getSite();
operation.setSite(site);
- operation.setHandle("OperationBO"+site+","+operation.getOperation()+",#");
+ if(StringUtil.isBlank(operation.getOperation())){
+ operation.setHandle("OperationBO"+site+","+operation.getOperation()+",#");
+ }
return ncGroupMapper.findNgGroupByOperationBo(operation);
}
diff --git a/quartz/src/main/java/com/foreverwin/mesnac/quartz/job/AnomalyJob.java b/quartz/src/main/java/com/foreverwin/mesnac/quartz/job/AnomalyJob.java
new file mode 100644
index 00000000..40320b56
--- /dev/null
+++ b/quartz/src/main/java/com/foreverwin/mesnac/quartz/job/AnomalyJob.java
@@ -0,0 +1,43 @@
+package com.foreverwin.mesnac.quartz.job;
+
+import com.foreverwin.mesnac.anomaly.service.AnomalyJobService;
+import com.foreverwin.mesnac.common.util.StringUtil;
+import com.foreverwin.modular.core.exception.BaseException;
+import org.quartz.DisallowConcurrentExecution;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @Description TODO
+ * @Author zhaojiawei
+ * @Since 2021-07-22
+ */
+@DisallowConcurrentExecution
+public class AnomalyJob implements Job {
+ private static final String SITE_UPPERCASE = "SITE";
+ private static final String SITE_LOWERCASE = "site";
+
+ @Autowired
+ private AnomalyJobService anomalyJobService;
+
+ @Override
+ public void execute(JobExecutionContext context) throws JobExecutionException {
+ //获取站点,若站点为空则抛出异常
+ String site = getSite(context);
+ if (StringUtil.isBlank(site)) {
+ throw new BaseException("anomaly.quartz.task.not.site", null);
+ }
+
+ anomalyJobService.anomalyJobProcess(site);
+ }
+
+ private String getSite(JobExecutionContext context) {
+ String site = context.getJobDetail().getJobDataMap().getString(SITE_LOWERCASE);
+ if (StringUtil.isBlank(site)) {
+ site = context.getJobDetail().getJobDataMap().getString(SITE_UPPERCASE);
+ }
+ return site;
+ }
+}