From 45141de4f7770a60db98b3275b95d938c2d406cb Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Wed, 22 May 2024 19:02:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=EF=BC=9A=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=85=AC=E4=BC=97=E5=8F=B7=E6=9F=A5=E8=AF=A2=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alarm/config/constants/AlarmConstants.java | 1 + .../hnac/hzims/alarm/mqtt/DroolsMqttConsumer.java | 2 +- .../com/hnac/hzims/alarm/mqtt/FdpMqttConsumer.java | 3 +- .../hnac/hzims/alarm/mqtt/HZ300MqttConsumer.java | 2 +- .../java/com/hnac/hzims/alarm/mqtt/MqttConfig.java | 10 ++-- .../com/hnac/hzims/alarm/mqtt/SoeMqttConsumer.java | 3 +- .../hnac/hzims/alarm/mqtt/VideoMqttConsumer.java | 2 +- .../source/service/impl/LevelAlarmServiceImpl.java | 2 +- .../source/service/impl/MessageServiceImpl.java | 68 +++++++++++++++++----- .../service/impl/SystemAlarmServiceImpl.java | 6 +- .../hzims-alarm/src/main/resources/db/2.0.0.sql | 2 + 11 files changed, 69 insertions(+), 32 deletions(-) create mode 100644 hzims-service/hzims-alarm/src/main/resources/db/2.0.0.sql diff --git a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/constants/AlarmConstants.java b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/constants/AlarmConstants.java index 0128e39..ab035cd 100644 --- a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/constants/AlarmConstants.java +++ b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/constants/AlarmConstants.java @@ -7,6 +7,7 @@ import java.util.List; * @author ysj */ public interface AlarmConstants { + public static final String PATTERN_DATETIME_MILLIS = "yyyy-MM-dd HH:mm:ss.SSS"; String APP_NAME = "hzims-alarm"; diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/DroolsMqttConsumer.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/DroolsMqttConsumer.java index f14d600..25bea94 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/DroolsMqttConsumer.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/DroolsMqttConsumer.java @@ -26,7 +26,7 @@ public class DroolsMqttConsumer implements SubscribeCallBack { private AlarmSaveService alarmSaveService; @Override public void onMessage(Map data) { - System.out.println("监听到消息"+data.toString()); + log.info("DroolsMqttConsumer监听到消息"+data.toString()); String s = JSONObject.toJSONString(data); //消费代码 List alarmEntities = droolsAlarmService.receiveMessage(s); diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/FdpMqttConsumer.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/FdpMqttConsumer.java index c4c2d97..827825c 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/FdpMqttConsumer.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/FdpMqttConsumer.java @@ -29,9 +29,8 @@ public class FdpMqttConsumer implements SubscribeCallBack { @Override public void onMessage(Map data) { String s = JSONObject.toJSONString(data); - log.error("监听Fdp消息 : {}" ,s); + log.info("监听Fdp消息 : {}" ,s); //消费代码 - List alarmEntities = fdpAlarmService.receiveMessage(s); if(CollectionUtil.isEmpty(alarmEntities)){ return; diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/HZ300MqttConsumer.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/HZ300MqttConsumer.java index 82880ad..97c53b0 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/HZ300MqttConsumer.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/HZ300MqttConsumer.java @@ -29,7 +29,7 @@ public class HZ300MqttConsumer implements SubscribeCallBack { private AlarmSaveService alarmSaveService; @Override public void onMessage(Map data) { - log.error("HZ3000队列监听到消息 : {}",data); + log.info("HZ3000队列监听到消息 : {}",data); //消费代码 List alarmEntities = systemAlarmService.receiveMessage(JSONObject.toJSONString(data)); if(CollectionUtil.isEmpty(alarmEntities)){ diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/MqttConfig.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/MqttConfig.java index 09651fd..6a2c34e 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/MqttConfig.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/MqttConfig.java @@ -58,23 +58,23 @@ public class MqttConfig { //fdp AnalysisSubscribe analysisSubscribe = new AnalysisSubscribe(); MqttAsyncClient fdpClient = analysisSubscribe.subscribe(mqttConfig, Collections.singletonList("#"), fdpMqttConsumer); - log.info(fdpClient.toString()); + log.info(fdpClient.toString()+fdpClient.getClientId()); //drools DroolsSoeSubscribe droolsSoeSubscribe = new DroolsSoeSubscribe(); MqttAsyncClient droolsClient = droolsSoeSubscribe.subscribe(mqttConfig, Collections.singletonList("#"), droolsMqttConsumer); - log.info(droolsClient.toString()); + log.info(droolsClient.toString()+droolsClient.getClientId()); //Soe SoeSubscribe soeSubscribe = new SoeSubscribe(); MqttAsyncClient soeClient = soeSubscribe.subscribe(mqttConfig, Collections.singletonList("#"), soeMqttConsumer); - log.info(soeClient.toString()); + log.info(soeClient.toString()+soeClient.getClientId()); //hz3000 HZ3000SoeSubscribe hz3000SoeSubscribe = new HZ3000SoeSubscribe(); MqttAsyncClient hz3000Client = hz3000SoeSubscribe.subscribe(mqttConfig, Collections.singletonList("#"), hz300MqttConsumer); - log.info(hz3000Client.toString()); + log.info(hz3000Client.toString()+hz3000Client.getClientId()); //视频 SoeSubscribe subscribe = new SoeSubscribe(); MqttAsyncClient videoClient = subscribe.subscribe(mqttConfig, Collections.singletonList("#"), videoMqttConsumer); - log.info(videoClient.toString()); + log.info(videoClient.toString()+videoClient.getClientId()); }catch (MqttException e){ log.error(e.toString()) ; } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/SoeMqttConsumer.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/SoeMqttConsumer.java index 5a29fff..13fae87 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/SoeMqttConsumer.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/SoeMqttConsumer.java @@ -27,7 +27,7 @@ public class SoeMqttConsumer implements SubscribeCallBack { private AlarmSaveService alarmSaveService; @Override public void onMessage(Map data) { - System.out.println("监听到消息"+data.toString()); + log.info("SoeMqttConsumer监听到消息"+data.toString()); String s = JSONObject.toJSONString(data); //消费代码 List alarmEntities = soeAlarmService.receiveMessage(s); @@ -36,7 +36,6 @@ public class SoeMqttConsumer implements SubscribeCallBack { alarmSaveService.save(alarmEntities); }catch (Exception e){ log.error("条件告警数据处理报错(SoeAlarm):"+e); - System.out.println("规则引擎告警数据处理报错(SoeAlarm):"+e); } } } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/VideoMqttConsumer.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/VideoMqttConsumer.java index 053c4df..447db7b 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/VideoMqttConsumer.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/VideoMqttConsumer.java @@ -26,7 +26,7 @@ public class VideoMqttConsumer implements SubscribeCallBack { private AlarmSaveService alarmSaveService; @Override public void onMessage(Map data) { - System.out.println("监听到消息"+data.toString()); + log.info("VideoMqttConsumer队列监听到消息 : {}",data); String s = JSONObject.toJSONString(data); //消费代码 List alarmEntities = videoAlarmService.receiveMessage(s); diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/LevelAlarmServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/LevelAlarmServiceImpl.java index 41b318f..fe035f1 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/LevelAlarmServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/LevelAlarmServiceImpl.java @@ -91,7 +91,7 @@ public class LevelAlarmServiceImpl implements LevelAlarmService { AlarmEntity entity = new AlarmEntity(); entity.setAlarmSource(AlarmConstants.LEVEL_ALARM); entity.setAlarmId(level.getId()); - entity.setAlarmTime(DateUtil.parse(level.getTs(), "yyyy-MM-dd HH:mm:ss.s")); + entity.setAlarmTime(new Date(level.getTs())); entity.setAlarmType(level.getType()); entity.setRealId(level.getSignage()); entity.setAlarmContext(level.getName()); diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java index ffa434b..378a88d 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java @@ -15,6 +15,7 @@ import com.hnac.hzims.message.fegin.IMessageClient; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.feign.IStationClient; import lombok.AllArgsConstructor; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.api.R; import org.springblade.core.tool.jackson.JsonUtil; @@ -27,6 +28,7 @@ import org.springblade.system.feign.ISysClient; import org.springblade.system.user.entity.User; import org.springblade.system.user.entity.UserInfo; import org.springblade.system.user.feign.IUserClient; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.util.*; @@ -40,9 +42,10 @@ import static com.hnac.hzims.operational.main.constant.MainConstants.PROJECT_MAN */ @Slf4j @Service -@AllArgsConstructor +@RequiredArgsConstructor public class MessageServiceImpl implements MessageService { + private final ISysClient sysClient; private final IUserClient userClient; @@ -51,6 +54,14 @@ public class MessageServiceImpl implements MessageService { private final IStationClient stationClient; + @Value("${hzims.msg.template}") + private String msgTemplate; + @Value("${hzims.msg.enabled}") + private Boolean msgEnabled; + @Value("${hzims.wxPush.template}") + private String wxPushTemplate; + @Value("${hzims.wxPush.enabled}") + private Boolean wxPushEnabled; /** * web/app消息推送 * @param entity : 告警对象 @@ -106,14 +117,23 @@ public class MessageServiceImpl implements MessageService { // } //写死传给固定用户 // List phoneList=Arrays.asList("18351807087","18163793336","13725599914"); - List phoneList=Arrays.asList("18351807087","18163793336","18285121497"); - for (String phone : phoneList) { - R userByPhone = userClient.getUserByPhone("200000", phone); - if (userByPhone.isSuccess()&&ObjectUtils.isNotEmpty(userByPhone.getData())){ - users.add(userByPhone.getData().getUser()); + if (msgEnabled){ + users = userClient.relationUserListByRoleAlias(station.getData().getTenantId(), station.getData().getRefDept(), PROJECT_MANAGER).getData(); + if(CollectionUtil.isEmpty(users)){ + log.error("短信发送失败:获取站点项目经理用户失败 : {}",entity); + return; + } + log.info("短信发送用户列表",users); + }else { + List phoneList = Arrays.asList("18351807087", "18163793336", "18285121497"); + for (String phone : phoneList) { + R userByPhone = userClient.getUserByPhone("200000", phone); + if (userByPhone.isSuccess() && ObjectUtils.isNotEmpty(userByPhone.getData())) { + users.add(userByPhone.getData().getUser()); + } } + log.info("短信发送用户列表",users); } - SmsImmediatelyPushDTO push = SmsImmediatelyPushDTO.builder() .deptId(entity.getCreateDept()) .taskId(entity.getId()) @@ -122,7 +142,7 @@ public class MessageServiceImpl implements MessageService { .content(entity.getAlarmContext()) .subject("告警短信通知") .tenantId(entity.getTenantId()) - .resourceCode(AlarmConstants.SMS_MESSAGE_TEMPLATE_CODE) + .resourceCode(msgTemplate) .pusher(users.stream().map(o->o.getId().toString()).collect(Collectors.joining(","))) .createUser(CommonConstant.SYSTEM_USER) .params(new HashMap(){{ @@ -146,19 +166,35 @@ public class MessageServiceImpl implements MessageService { log.error("微信消息发送失败:站点code获取失败 : {}",entity); return; } + List userList=new ArrayList<>(); // 获取站点用户 - R> result = userClient.userByDeptIdLevel(station.getData().getRefDept(),0); - if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { - log.error("微信消息发送失败:用户获取失败 : {}",entity); - return; + if (wxPushEnabled){ + R> result = userClient.userByDeptIdLevel(station.getData().getRefDept(),1); + if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { + log.error("微信公众号消息发送失败:用户获取失败 : {}",entity); + return; + } + userList.addAll(result.getData()); + log.info("短信发送用户列表",userList); + }else { + //内测只推给对应的3个用户 + List phoneList = Arrays.asList("18351807087", "18163793336", "18285121497"); + for (String phone : phoneList) { + R userByPhone = userClient.getUserByPhone("200000", phone); + if (userByPhone.isSuccess() && ObjectUtils.isNotEmpty(userByPhone.getData())) { + userList.add(userByPhone.getData().getUser()); + } + } + log.info("短信发送用户列表",userList); } + String userIds = userList.stream().map(o -> String.valueOf(o.getId())).distinct().collect(Collectors.joining(",")); WxMessageDTO message = new WxMessageDTO(); // 模板Id - message.setTemplateId("hIgINCsjpG-gyCKh8wzwBeRL9tanTLqRDgv-X8B9vyc"); + message.setTemplateId(wxPushTemplate); // // 微信消息跳转地址 // message.setSkipUrl("http://baidu.com"); // 机构Id - message.setDeptId(result.getData().get(0).getId()); + message.setDeptId(station.getData().getRefDept()); // 业务关键字 message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); // 业务分类关键字 @@ -178,9 +214,9 @@ public class MessageServiceImpl implements MessageService { // 消息主题 message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); // 推送用户 - message.setUserIds(result.getData().stream().map(o->String.valueOf(o.getId())).distinct().collect(Collectors.joining(","))); + message.setUserIds(userIds); // 创建用户 - message.setCreateUser(result.getData().get(0).getId()); + message.setCreateUser(userList.get(0).getId()); // 租户Id message.setTenantId(station.getData().getTenantId()); messageClient.sendWxMessage(message); diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/SystemAlarmServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/SystemAlarmServiceImpl.java index 8f3bee4..b829956 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/SystemAlarmServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/SystemAlarmServiceImpl.java @@ -83,9 +83,9 @@ public class SystemAlarmServiceImpl implements SystemAlarmService { private AlarmEntity getAlarmEntity(SystemAlarmVo item) { AlarmEntity entity = new AlarmEntity(); entity.setAlarmId(item.getId()); - Date date = new Date(); - date.setTime(item.getTs()); - entity.setAlarmTime(DateUtil.parse(DateUtil.format(date,DateUtil.PATTERN_DATETIME),DateUtil.PATTERN_DATETIME)); +// Date date = new Date(item.getTs()); +// entity.setAlarmTime(DateUtil.parse(item.getTs().toString(),PATTERN_DATETIME_MILLIS)); + entity.setAlarmTime( new Date(item.getTs())); entity.setAlarmContext(item.getContext()); entity.setAlarmType(item.getType()); entity.setAlarmStatus(item.getState()); diff --git a/hzims-service/hzims-alarm/src/main/resources/db/2.0.0.sql b/hzims-service/hzims-alarm/src/main/resources/db/2.0.0.sql new file mode 100644 index 0000000..0c98175 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/resources/db/2.0.0.sql @@ -0,0 +1,2 @@ +ALTER TABLE `hzims_alarm` + MODIFY COLUMN `ALARM_TIME` datetime(3) NULL DEFAULT NULL COMMENT '告警时间' AFTER `ALARM_COUNT`; \ No newline at end of file