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;