From fc543d7ff5cc32d86a375d1f7948804bf85b077e Mon Sep 17 00:00:00 2001 From: 25604 Date: Tue, 16 Sep 2025 11:02:56 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E7=BD=91=E5=85=B3=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=A6=BB=E7=BA=BF=E5=BC=82=E5=B8=B8=E5=BE=AE=E4=BF=A1=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E6=B7=BB=E5=8A=A0=E6=A8=A1=E6=9D=BF=EF=BC=9B=202?= =?UTF-8?q?=E3=80=81=E8=AE=A1=E7=AE=97=E9=A1=B9=E7=9B=AE=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=A4=84=E7=90=86=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2025新增脚本.sql | 2 ++ .../java/com/mh/user/job/DealDataJob.java | 2 +- .../com/mh/user/job/PushDataToWechatJob.java | 35 +++++++++++++++++-- .../user/netty/ServerChannelInitializer.java | 2 +- .../java/com/mh/user/utils/TemplateType.java | 10 ++++++ 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 2025新增脚本.sql diff --git a/2025新增脚本.sql b/2025新增脚本.sql new file mode 100644 index 0000000..c69b53f --- /dev/null +++ b/2025新增脚本.sql @@ -0,0 +1,2 @@ +-- 2025-09-16 新增网关id +ALTER TABLE wechat_template_project ADD gw_id int null; diff --git a/user-service/src/main/java/com/mh/user/job/DealDataJob.java b/user-service/src/main/java/com/mh/user/job/DealDataJob.java index 5aef4d6..9eb38ee 100644 --- a/user-service/src/main/java/com/mh/user/job/DealDataJob.java +++ b/user-service/src/main/java/com/mh/user/job/DealDataJob.java @@ -86,7 +86,7 @@ public class DealDataJob { try { // 添加开始程序时间 long startTime = System.currentTimeMillis(); - String curDate = ExchangeStringUtil.dateTime(3, ""); + String curDate = ExchangeStringUtil.dateTime(5, ""); List list = dealDataService.queryProjectId("1"); if (!list.isEmpty()) { // 使用较小的线程池,减少并发冲突 diff --git a/user-service/src/main/java/com/mh/user/job/PushDataToWechatJob.java b/user-service/src/main/java/com/mh/user/job/PushDataToWechatJob.java index 6eb90e7..9931ced 100644 --- a/user-service/src/main/java/com/mh/user/job/PushDataToWechatJob.java +++ b/user-service/src/main/java/com/mh/user/job/PushDataToWechatJob.java @@ -73,9 +73,11 @@ public class PushDataToWechatJob { PushMsgEntity pushMsgEntity = new PushMsgEntity(); // 判断模板id种类 switch (map.get("template_id").toString()) { - case "LrSu6VlICV9sTIWZgl8SF7bFI7TfqbSpeJ-cvPaTe6I": +// case "LrSu6VlICV9sTIWZgl8SF7bFI7TfqbSpeJ-cvPaTe6I": + case "SiyBtZeZuF0Qo8V3NlvGwhc95-vX-a6wsvIxpAq3d_Y": // 推送单种设备消息 - pushOffLineGw(val, map, pushMsgEntity); +// pushOffLineGw(val, map, pushMsgEntity); + pushOffLineGw1(val, map, pushMsgEntity); break; default: break; @@ -92,6 +94,35 @@ public class PushDataToWechatJob { } + private void pushOffLineGw1(GatewayManageEntity gw, Map map, PushMsgEntity pushMsgEntity) { + // 项目名称 {{thing95.DATA}} + // 设备名称 {{thing23.DATA}} + // 告警等级 {{phrase20.DATA}} + // 异常原因 {{thing25.DATA}} + // 发生时间 {{time51.DATA}} + pushMsgEntity.setTouser(map.get("open_id").toString()); + pushMsgEntity.setTemplateId(map.get("template_id").toString()); + pushMsgEntity.setUrl("http://jnd2.mhwsh.net:8765/"); + First first = new First(); + first.setValue("设备报警提醒"); + pushMsgEntity.setFirst(first); + Key1 key1 = new Key1(); + key1.setValue(map.get("project_name").toString()); + pushMsgEntity.setKey1(key1); + Key2 key2 = new Key2(); + key2.setValue(gw.getGwName()); + pushMsgEntity.setKey2(key2); + Key3 key3 = new Key3(); + key3.setValue("报警"); + pushMsgEntity.setKey3(key3); + Key4 key4 = new Key4(); + key4.setValue("设备已离线,请及时查看处理!"); + pushMsgEntity.setKey4(key4); + Key5 key5 = new Key5(); + key5.setValue(DateUtil.dateToString(gw.getConnectTime(), "yyyy-MM-dd HH:mm:ss")); + pushMsgEntity.setKey5(key5); + } + @Scheduled(cron = " 0 0 8 * * ? ") //每天八点钟推送上一天的数据能耗 public void pushDataToWechat() { log.info("推送给微信公众号"); diff --git a/user-service/src/main/java/com/mh/user/netty/ServerChannelInitializer.java b/user-service/src/main/java/com/mh/user/netty/ServerChannelInitializer.java index a66af56..231a33a 100644 --- a/user-service/src/main/java/com/mh/user/netty/ServerChannelInitializer.java +++ b/user-service/src/main/java/com/mh/user/netty/ServerChannelInitializer.java @@ -25,7 +25,7 @@ public class ServerChannelInitializer extends ChannelInitializer{ // pipeline.addLast( new StringEncoder()); // 设置读写超时操作 // 入参说明: 读超时时间、写超时时间、所有类型的超时时间、时间格式 - pipeline.addLast(new IdleStateHandler(40, 40, 40, TimeUnit.SECONDS)); + pipeline.addLast(new IdleStateHandler(50, 50, 50, TimeUnit.SECONDS)); //服务器的逻辑 pipeline.addLast("handler", new EchoServerHandler()); } diff --git a/user-service/src/main/java/com/mh/user/utils/TemplateType.java b/user-service/src/main/java/com/mh/user/utils/TemplateType.java index ff73d9c..e62dfd6 100644 --- a/user-service/src/main/java/com/mh/user/utils/TemplateType.java +++ b/user-service/src/main/java/com/mh/user/utils/TemplateType.java @@ -40,6 +40,16 @@ public enum TemplateType { data.put("thing4", pushMsgEntity.getKey4()); data.put("time3", pushMsgEntity.getKey5()); } + }, + DEVICE_OFFLINE1("SiyBtZeZuF0Qo8V3NlvGwhc95-vX-a6wsvIxpAq3d_Y") { + @Override + public void fillData(JSONObject data, PushMsgEntity pushMsgEntity) { + data.put("thing95", pushMsgEntity.getKey1()); + data.put("thing23", pushMsgEntity.getKey2()); + data.put("phrase20", pushMsgEntity.getKey3()); + data.put("thing25", pushMsgEntity.getKey4()); + data.put("time51", pushMsgEntity.getKey5()); + } }; private final String templateId;