From 42332e9882eca77c11738c5374065cbd66e0f4d8 Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Wed, 3 Apr 2024 18:05:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E9=80=81=E5=91=8A=E8=AD=A6=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E9=82=AE=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hnac/hzims/alarm/monitor/listener/AlarmListener.java | 2 +- .../hzims/alarm/source/service/impl/MessageServiceImpl.java | 4 ++-- .../hzims/message/service/impl/WxMessageServiceImpl.java | 13 ++++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java index bb125ac..cff87ff 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java @@ -46,7 +46,7 @@ public class AlarmListener implements IQueueConsume { // 步骤4.微信公众号发送 if(ObjectUtil.isNotEmpty(alarm.getIsWxMessage()) && alarm.getIsWxMessage() == 0){ - //messageService.weChatMessage(alarm); + messageService.weChatMessage(alarm); } } } \ No newline at end of file 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 8ef2624..3415705 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 @@ -148,7 +148,7 @@ public class MessageServiceImpl implements MessageService { } WxMessageDTO message = new WxMessageDTO(); // 模板Id - message.setTemplateId("hIgINCsjpG-gyCKh8wzwBWjR-hkbjkNLFTXQEsnR_Z8"); + message.setTemplateId("Ce2YAZtX0UyoNrAag6CANtC8XQeLuil7domvJrUivhM"); // 微信消息跳转地址 message.setSkipUrl("http://baidu.com"); // 机构Id @@ -164,7 +164,7 @@ public class MessageServiceImpl implements MessageService { map.put("thing18",entity.getStationName()); map.put("thing5",Optional.ofNullable(entity.getDeviceCode()).orElse("未知设备")); map.put("thing11",entity.getAlarmContext()); - map.put("thing14", DictCache.getValue("alarm_source", entity.getAlarmType())); + map.put("thing14", DictCache.getValue("alarm_source", entity.getAlarmSource())); map.put("time2",entity.getAlarmTime()); message.setMap(map); // 消息内容 diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/WxMessageServiceImpl.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/WxMessageServiceImpl.java index aea5845..cb04c86 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/WxMessageServiceImpl.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/WxMessageServiceImpl.java @@ -86,9 +86,20 @@ public class WxMessageServiceImpl implements IMessageService { PushTemplate template = new PushTemplate(); template.setTemplateId(message.getTemplateId()); template.setSkipUrl(message.getSkipUrl()); - template.setMap(message.getMap()); + Map map = message.getMap(); + map.replaceAll((key,value)->getTruncateString(value.toString(),27)); + template.setMap(map); template.setUserIds(Arrays.stream(message.getUserIds().split(",")).collect(Collectors.toList())); + template.setTenantId("200000"); R result = wxPushClient.sendPushTemplateByUserId(template); return result.isSuccess(); } + + private String getTruncateString(String ruleDefName, int maxSize) { + if (ruleDefName.length()<= maxSize){ + return ruleDefName; + }else { + return ruleDefName.substring(0, maxSize - 3) + "..."; + } + } }