Browse Source

1、网关设备离线异常微信通知添加模板;

2、计算项目数据更改处理时间
dev
25604 4 weeks ago
parent
commit
fc543d7ff5
  1. 2
      2025新增脚本.sql
  2. 2
      user-service/src/main/java/com/mh/user/job/DealDataJob.java
  3. 35
      user-service/src/main/java/com/mh/user/job/PushDataToWechatJob.java
  4. 2
      user-service/src/main/java/com/mh/user/netty/ServerChannelInitializer.java
  5. 10
      user-service/src/main/java/com/mh/user/utils/TemplateType.java

2
2025新增脚本.sql

@ -0,0 +1,2 @@
-- 2025-09-16 新增网关id
ALTER TABLE wechat_template_project ADD gw_id int null;

2
user-service/src/main/java/com/mh/user/job/DealDataJob.java

@ -86,7 +86,7 @@ public class DealDataJob {
try { try {
// 添加开始程序时间 // 添加开始程序时间
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
String curDate = ExchangeStringUtil.dateTime(3, ""); String curDate = ExchangeStringUtil.dateTime(5, "");
List<String> list = dealDataService.queryProjectId("1"); List<String> list = dealDataService.queryProjectId("1");
if (!list.isEmpty()) { if (!list.isEmpty()) {
// 使用较小的线程池,减少并发冲突 // 使用较小的线程池,减少并发冲突

35
user-service/src/main/java/com/mh/user/job/PushDataToWechatJob.java

@ -73,9 +73,11 @@ public class PushDataToWechatJob {
PushMsgEntity pushMsgEntity = new PushMsgEntity(); PushMsgEntity pushMsgEntity = new PushMsgEntity();
// 判断模板id种类 // 判断模板id种类
switch (map.get("template_id").toString()) { 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; break;
default: default:
break; break;
@ -92,6 +94,35 @@ public class PushDataToWechatJob {
} }
private void pushOffLineGw1(GatewayManageEntity gw, Map<String, Object> 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 * * ? ") //每天八点钟推送上一天的数据能耗 @Scheduled(cron = " 0 0 8 * * ? ") //每天八点钟推送上一天的数据能耗
public void pushDataToWechat() { public void pushDataToWechat() {
log.info("推送给微信公众号"); log.info("推送给微信公众号");

2
user-service/src/main/java/com/mh/user/netty/ServerChannelInitializer.java

@ -25,7 +25,7 @@ public class ServerChannelInitializer extends ChannelInitializer<SocketChannel>{
// pipeline.addLast( new StringEncoder()); // 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()); pipeline.addLast("handler", new EchoServerHandler());
} }

10
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("thing4", pushMsgEntity.getKey4());
data.put("time3", pushMsgEntity.getKey5()); 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; private final String templateId;

Loading…
Cancel
Save