作者 钟来

修改告警bug

正在显示 27 个修改的文件 包含 161 行增加37 行删除
@@ -24,7 +24,7 @@ public class DeviceTask { @@ -24,7 +24,7 @@ public class DeviceTask {
24 public void terminalOnline() 24 public void terminalOnline()
25 { 25 {
26 int time = DateUtils.getNowTimeMilly()-6*60; 26 int time = DateUtils.getNowTimeMilly()-6*60;
27 - List<Map<String,Object>> list = publicService.getObjectListBySQL("SELECT id FROM `iot_terminal` a LEFT JOIN `iot_device` b ON a.`device_id`=b.`client_id` WHERE "+time+"-a.`data_update_time`>=b.`device_life` AND online=3"); 27 + List<Map<String,Object>> list = publicService.getObjectListBySQL("SELECT id FROM `iot_terminal` a LEFT JOIN `iot_device` b ON a.`device_id`=b.`client_id` WHERE "+time+"-a.`data_update_time`>=(b.`device_life`+15) AND online=3");
28 28
29 StringBuffer stringBuffer = new StringBuffer(); 29 StringBuffer stringBuffer = new StringBuffer();
30 Optional.ofNullable(list).orElse(new ArrayList<>()).forEach(stringObjectMap -> { 30 Optional.ofNullable(list).orElse(new ArrayList<>()).forEach(stringObjectMap -> {
@@ -49,7 +49,7 @@ public class DeviceTask { @@ -49,7 +49,7 @@ public class DeviceTask {
49 public void deviceOnline() 49 public void deviceOnline()
50 { 50 {
51 int time = DateUtils.getNowTimeMilly(); 51 int time = DateUtils.getNowTimeMilly();
52 - List<Map<String,Object>> list = publicService.getObjectListBySQL("SELECT client_id FROM `iot_device` WHERE "+time+"-data_update_time>=device_life AND status=3"); 52 + List<Map<String,Object>> list = publicService.getObjectListBySQL("SELECT client_id FROM `iot_device` WHERE "+time+"-data_update_time>=(device_life+15) AND status=3");
53 53
54 StringBuffer stringBuffer = new StringBuffer(); 54 StringBuffer stringBuffer = new StringBuffer();
55 Optional.ofNullable(list).orElse(new ArrayList<>()).forEach(stringObjectMap -> { 55 Optional.ofNullable(list).orElse(new ArrayList<>()).forEach(stringObjectMap -> {
@@ -14,4 +14,6 @@ public interface ThingsModelBase<T> { @@ -14,4 +14,6 @@ public interface ThingsModelBase<T> {
14 String getSaveView(); 14 String getSaveView();
15 Object getCmdView(Object value); 15 Object getCmdView(Object value);
16 boolean checkValue(); 16 boolean checkValue();
  17 +
  18 + void setSaveView(String value);
17 } 19 }
@@ -59,6 +59,44 @@ public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T> @@ -59,6 +59,44 @@ public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T>
59 return null; 59 return null;
60 } 60 }
61 61
  62 + public static ThingsModelItemBase newhingsModelItemFromControl(ThingsModelDataTypeEnum thingsModelDataTypeEnum,IotThingsModel thingsModel,JsonElement jsonElement)
  63 + {
  64 + if (!jsonElement.isJsonNull())
  65 + {
  66 + String specs = thingsModel.getSpecs();
  67 + if(StringUtils.isEmpty(specs))
  68 + {
  69 + specs = new JsonObject().toString();
  70 + }
  71 + ThingsModelItemBase thingsModelItemBase = GsonConstructor.get().fromJson(specs,StringModelOutput.class);
  72 + switch (thingsModelDataTypeEnum)
  73 + {
  74 + case STRING:
  75 + thingsModelItemBase.setSaveView(jsonElement.getAsString());
  76 + break;
  77 + case BOOL:
  78 + thingsModelItemBase = GsonConstructor.get().fromJson(specs,BoolModelOutput.class);
  79 + break;
  80 + case ENUM:
  81 + thingsModelItemBase = GsonConstructor.get().fromJson(specs,EnumModelOutput.class);
  82 + break;
  83 + case ARRAY:
  84 + thingsModelItemBase = GsonConstructor.get().fromJson(specs,ArrayModelOutput.class);
  85 + break;
  86 + case DECIMAL:
  87 + thingsModelItemBase = GsonConstructor.get().fromJson(specs,DecimalModelOutput.class);
  88 + break;
  89 + case INTEGER:
  90 + thingsModelItemBase = GsonConstructor.get().fromJson(specs,IntegerModelOutput.class);
  91 + break;
  92 + }
  93 + thingsModelItemBase.setSaveView(jsonElement.getAsString());
  94 + thingsModelItemBase.conversionThingsModel(thingsModel);
  95 +
  96 + return thingsModelItemBase;
  97 + }
  98 + return null;
  99 + }
62 100
63 public static ThingsModelItemBase newhingsModelItem(JsonObject jsonObject) 101 public static ThingsModelItemBase newhingsModelItem(JsonObject jsonObject)
64 { 102 {
@@ -7,6 +7,8 @@ import com.google.gson.JsonElement; @@ -7,6 +7,8 @@ import com.google.gson.JsonElement;
7 import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; 7 import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase;
8 import lombok.Data; 8 import lombok.Data;
9 9
  10 +import java.util.ArrayList;
  11 +
10 @Data 12 @Data
11 public class ArrayModelOutput extends ThingsModelItemBase<JsonArray> 13 public class ArrayModelOutput extends ThingsModelItemBase<JsonArray>
12 { 14 {
@@ -41,4 +43,9 @@ public class ArrayModelOutput extends ThingsModelItemBase<JsonArray> @@ -41,4 +43,9 @@ public class ArrayModelOutput extends ThingsModelItemBase<JsonArray>
41 public boolean checkValue() { 43 public boolean checkValue() {
42 return true; 44 return true;
43 } 45 }
  46 +
  47 + @Override
  48 + public void setSaveView(String value) {
  49 + setValue(JSONArray.parseObject(value, JsonArray.class));
  50 + }
44 } 51 }
@@ -43,4 +43,9 @@ public class BoolModelOutput extends ThingsModelItemBase<Boolean> @@ -43,4 +43,9 @@ public class BoolModelOutput extends ThingsModelItemBase<Boolean>
43 public boolean checkValue() { 43 public boolean checkValue() {
44 return true; 44 return true;
45 } 45 }
  46 +
  47 + @Override
  48 + public void setSaveView(String value) {
  49 + setValue(value.equals("1") || Boolean.parseBoolean(value) );
  50 + }
46 } 51 }
@@ -54,4 +54,9 @@ public class DecimalModelOutput extends ThingsModelItemBase<BigDecimal> @@ -54,4 +54,9 @@ public class DecimalModelOutput extends ThingsModelItemBase<BigDecimal>
54 } 54 }
55 return false; 55 return false;
56 } 56 }
  57 +
  58 + @Override
  59 + public void setSaveView(String value) {
  60 + setValue(new BigDecimal(value));
  61 + }
57 } 62 }
@@ -64,6 +64,11 @@ public class EnumModelOutput extends ThingsModelItemBase<String> @@ -64,6 +64,11 @@ public class EnumModelOutput extends ThingsModelItemBase<String>
64 return true; 64 return true;
65 } 65 }
66 66
  67 + @Override
  68 + public void setSaveView(String value) {
  69 + setValue(value);
  70 + }
  71 +
67 private static Object conversion(Object data ,String clas) { 72 private static Object conversion(Object data ,String clas) {
68 try { 73 try {
69 return stringToTarget(String.valueOf(data),Class.forName(clas)); 74 return stringToTarget(String.valueOf(data),Class.forName(clas));
@@ -71,4 +71,10 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer> @@ -71,4 +71,10 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer>
71 } 71 }
72 return false; 72 return false;
73 } 73 }
  74 +
  75 + @Override
  76 + public void setSaveView(String value) {
  77 + BigDecimal bigDecimal = new BigDecimal(value);
  78 + setValue(bigDecimal.multiply(new BigDecimal(acy)).intValue());
  79 + }
74 } 80 }
@@ -35,4 +35,9 @@ public class StringModelOutput extends ThingsModelItemBase<String> @@ -35,4 +35,9 @@ public class StringModelOutput extends ThingsModelItemBase<String>
35 } 35 }
36 return false; 36 return false;
37 } 37 }
  38 +
  39 + @Override
  40 + public void setSaveView(String value) {
  41 + setValue(value);
  42 + }
38 } 43 }
@@ -128,8 +128,8 @@ public class IotDeviceController extends BaseController @@ -128,8 +128,8 @@ public class IotDeviceController extends BaseController
128 @ApiImplicitParam(value = "标签(多个英文逗号分割)",name = "label"), 128 @ApiImplicitParam(value = "标签(多个英文逗号分割)",name = "label"),
129 @ApiImplicitParam(value = "设备主键",name = "client_id") 129 @ApiImplicitParam(value = "设备主键",name = "client_id")
130 }) 130 })
131 - @PreAuthorize("@ss.hasPermi('iot:IotDevice:add')")  
132 - @Log(title = "主机/网关", businessType = BusinessType.INSERT) 131 + @PreAuthorize("@ss.hasPermi('iot:IotDevice:tagging')")
  132 + @Log(title = "主机/网关", businessType = BusinessType.UPDATE)
133 @PostMapping("tagging/{client_id}") 133 @PostMapping("tagging/{client_id}")
134 public AjaxResult tagging(@PathVariable String client_id, String label) 134 public AjaxResult tagging(@PathVariable String client_id, String label)
135 { 135 {
1 -# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8080 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-admin # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain,com.zhonglai.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login,/register,/captchaImage,/getCacheObject,/v2/api-docs,/tool/gen/generatorCodeFromDb,/data/** # NameServer地址 rocketmq: name-server: 47.115.144.179:9876 # 默认的消息组 producer: group: deviceCommand send-message-timeout: 30000 send-topic: lh-mqtt-service-deviceCommand-test send-tags: 1  
  1 +# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8080 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn com.zhonglai.luhui: debug # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-admin # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain,com.zhonglai.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login,/register,/captchaImage,/getCacheObject,/v2/api-docs,/tool/gen/generatorCodeFromDb,/data/** # NameServer地址 rocketmq: name-server: 47.115.144.179:9876 # 默认的消息组 producer: group: deviceCommand send-message-timeout: 30000 send-topic: lh-mqtt-service-deviceCommand-test send-tags: 1
@@ -14,10 +14,10 @@ public class LhAlarmMain { @@ -14,10 +14,10 @@ public class LhAlarmMain {
14 14
15 CachAlarmConfig.loadConfig(); 15 CachAlarmConfig.loadConfig();
16 //启动触发告警服务 16 //启动触发告警服务
17 - TriggerAlarmService.start(); 17 +// TriggerAlarmService.start();
18 18
19 //启动定时任务告警 19 //启动定时任务告警
20 - TimerAlarmService.start(); 20 +// TimerAlarmService.start();
21 21
22 //启动告警定时发送 22 //启动告警定时发送
23 SendAlarmService.start(); 23 SendAlarmService.start();
@@ -43,6 +43,22 @@ public class IotDeviceAlarm extends UpAlarmFactory<IotDevice> implements Seriali @@ -43,6 +43,22 @@ public class IotDeviceAlarm extends UpAlarmFactory<IotDevice> implements Seriali
43 //通过变更的数据获得对应的告警规则 43 //通过变更的数据获得对应的告警规则
44 valueUp(beforeupAlarmDb.getClient_id(),CachAlarmConfig.getDeviceProduct(beforeupAlarmDb.getClient_id()),beforeupAlarmDb.getThings_model_value(),afterupAlarmDb.getThings_model_value(),null,"主机"+afterupAlarmDb.getClient_id()); 44 valueUp(beforeupAlarmDb.getClient_id(),CachAlarmConfig.getDeviceProduct(beforeupAlarmDb.getClient_id()),beforeupAlarmDb.getThings_model_value(),afterupAlarmDb.getThings_model_value(),null,"主机"+afterupAlarmDb.getClient_id());
45 45
  46 + //在线状态
  47 + if(null != afterupAlarmDb.getStatus() && null != beforeupAlarmDb.getStatus() && beforeupAlarmDb.getStatus()-afterupAlarmDb.getStatus()!=0)
  48 + {
  49 + switch (afterupAlarmDb.getStatus())
  50 + {
  51 + case 3:
  52 +// IotAlertLog iotAlertLog = new IotAlertLog(2l,"在线",2,2,afterupAlarmDb.getClient_id(),System.currentTimeMillis(),1,CachAlarmConfig.getDeviceUser(afterupAlarmDb.getClient_id()) ,"主机"+afterupAlarmDb.getClient_id(),1);
  53 +// list.add(iotAlertLog);
  54 + break;
  55 + case 4:
  56 + IotAlertLog iotAlertLog = new IotAlertLog(1l,"离线",1,2,afterupAlarmDb.getClient_id(),System.currentTimeMillis(),1,CachAlarmConfig.getDeviceUser(afterupAlarmDb.getClient_id()) ,"主机"+afterupAlarmDb.getClient_id(),1);
  57 + list.add(iotAlertLog);
  58 + break;
  59 + }
  60 + }
  61 +
46 } 62 }
47 Object getNowValue(Object model_name,Integer type) { 63 Object getNowValue(Object model_name,Integer type) {
48 if(null != afterupAlarmDb ) 64 if(null != afterupAlarmDb )
@@ -2,6 +2,7 @@ package com.zhonglai.luhui.alarm.clas; @@ -2,6 +2,7 @@ package com.zhonglai.luhui.alarm.clas;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.zhonglai.luhui.alarm.config.CachAlarmConfig; 4 import com.zhonglai.luhui.alarm.config.CachAlarmConfig;
  5 +import com.zhonglai.luhui.alarm.dto.IotAlertLog;
5 import com.zhonglai.luhui.alarm.dto.IotDevice; 6 import com.zhonglai.luhui.alarm.dto.IotDevice;
6 import com.zhonglai.luhui.alarm.dto.IotTerminal; 7 import com.zhonglai.luhui.alarm.dto.IotTerminal;
7 import com.zhonglai.luhui.service.dao.util.StringUtils; 8 import com.zhonglai.luhui.service.dao.util.StringUtils;
@@ -40,6 +41,21 @@ public class IotTerminalAlarm extends UpAlarmFactory<IotTerminal> implements Ser @@ -40,6 +41,21 @@ public class IotTerminalAlarm extends UpAlarmFactory<IotTerminal> implements Ser
40 //通过变更的数据获得对应的告警规则 41 //通过变更的数据获得对应的告警规则
41 valueUp(beforeupAlarmDb.getId(), CachAlarmConfig.getDeviceProduct(beforeupAlarmDb.getId()),beforeupAlarmDb.getThings_model_value(),afterupAlarmDb.getThings_model_value(),beforeupAlarmDb.getUser_info_id(),null==beforeupAlarmDb.getName()?beforeupAlarmDb.getId():beforeupAlarmDb.getName()); 42 valueUp(beforeupAlarmDb.getId(), CachAlarmConfig.getDeviceProduct(beforeupAlarmDb.getId()),beforeupAlarmDb.getThings_model_value(),afterupAlarmDb.getThings_model_value(),beforeupAlarmDb.getUser_info_id(),null==beforeupAlarmDb.getName()?beforeupAlarmDb.getId():beforeupAlarmDb.getName());
42 43
  44 + //在线状态
  45 + if(null != afterupAlarmDb.getOnline() && null != beforeupAlarmDb.getOnline() && beforeupAlarmDb.getOnline()-afterupAlarmDb.getOnline()!=0)
  46 + {
  47 + switch (afterupAlarmDb.getOnline())
  48 + {
  49 + case 3:
  50 +// IotAlertLog iotAlertLog = new IotAlertLog(2l,"在线",2,2,afterupAlarmDb.getId(),System.currentTimeMillis(),1,CachAlarmConfig.getDeviceUser(afterupAlarmDb.getId()) ,afterupAlarmDb.getName(),1);
  51 +// list.add(iotAlertLog);
  52 + break;
  53 + case 4:
  54 + IotAlertLog iotAlertLog = new IotAlertLog(1l,"离线",1,2,afterupAlarmDb.getId(),System.currentTimeMillis(),1,CachAlarmConfig.getDeviceUser(afterupAlarmDb.getId()) ,afterupAlarmDb.getName(),1);
  55 + list.add(iotAlertLog);
  56 + break;
  57 + }
  58 + }
43 } 59 }
44 60
45 @Override 61 @Override
@@ -107,6 +107,10 @@ public abstract class UpAlarmFactory<T> { @@ -107,6 +107,10 @@ public abstract class UpAlarmFactory<T> {
107 { 107 {
108 nv = newjson.get(key); 108 nv = newjson.get(key);
109 ov = oldjson.get(key); 109 ov = oldjson.get(key);
  110 + }catch (NullPointerException exception)
  111 + {
  112 + logger.error("告警属性解析时异常",exception);
  113 + continue;
110 } 114 }
111 115
112 if(!nv.equals(ov)) //新老不一致,触发告警 116 if(!nv.equals(ov)) //新老不一致,触发告警
@@ -424,7 +424,7 @@ public class CachAlarmConfig { @@ -424,7 +424,7 @@ public class CachAlarmConfig {
424 public static List<UserAlarmNoticeConfig> getUserAlarmNoticeConfig(Integer user_id,Integer getAlert_config_type,Long alert_id) 424 public static List<UserAlarmNoticeConfig> getUserAlarmNoticeConfig(Integer user_id,Integer getAlert_config_type,Long alert_id)
425 { 425 {
426 IotAlertUserNotice iotAlertUserNotice = user_alarm_config.get(user_id+"|"+getAlert_config_type); 426 IotAlertUserNotice iotAlertUserNotice = user_alarm_config.get(user_id+"|"+getAlert_config_type);
427 - if(null != iotAlertUserNotice && "*".equals(iotAlertUserNotice.getAlert_ids()) || (","+iotAlertUserNotice.getAlert_ids()+",").indexOf(","+alert_id+",")>=0) //*或者包含 427 + if(null != iotAlertUserNotice && ("*".equals(iotAlertUserNotice.getAlert_ids()) || (","+iotAlertUserNotice.getAlert_ids()+",").indexOf(","+alert_id+",")>=0)) //*或者包含
428 { 428 {
429 return channelIdsToUserAlarmNoticeConfig(iotAlertUserNotice.getChannels()); 429 return channelIdsToUserAlarmNoticeConfig(iotAlertUserNotice.getChannels());
430 } 430 }
@@ -52,7 +52,9 @@ public class DbOperateUtil { @@ -52,7 +52,9 @@ public class DbOperateUtil {
52 52
53 public static List<IotAlertLog> getIotAlertLogList(Integer status,Integer limit) 53 public static List<IotAlertLog> getIotAlertLogList(Integer status,Integer limit)
54 { 54 {
55 - List<IotAlertLog> list = baseDao.findBysql("select * from iot_alert_log where `status`=? limit ?",IotAlertLog.class,status,limit); 55 + List<IotAlertLog> list = baseDao.findBysql("select * from iot_alert_log where alert_log_id=11408",IotAlertLog.class);
  56 +
  57 +// List<IotAlertLog> list = baseDao.findBysql("select * from iot_alert_log where `status`=? limit ?",IotAlertLog.class,status,limit);
56 return list; 58 return list;
57 } 59 }
58 60
@@ -15,6 +15,15 @@ public class IotDevice { @@ -15,6 +15,15 @@ public class IotDevice {
15 /** 物模型值 */ 15 /** 物模型值 */
16 private String things_model_value; 16 private String things_model_value;
17 private Integer product_id; 17 private Integer product_id;
  18 + private Integer status;
  19 +
  20 + public Integer getStatus() {
  21 + return status;
  22 + }
  23 +
  24 + public void setStatus(Integer status) {
  25 + this.status = status;
  26 + }
18 27
19 public Integer getProduct_id() { 28 public Integer getProduct_id() {
20 return product_id; 29 return product_id;
@@ -70,6 +79,9 @@ public class IotDevice { @@ -70,6 +79,9 @@ public class IotDevice {
70 case "product_id": 79 case "product_id":
71 iotDevice.setProduct_id ( null!=column.getValue()&&!"".equals(column.getValue())?Integer.parseInt(column.getValue()):null); 80 iotDevice.setProduct_id ( null!=column.getValue()&&!"".equals(column.getValue())?Integer.parseInt(column.getValue()):null);
72 break; 81 break;
  82 + case "status":
  83 + iotDevice.setStatus ( null!=column.getValue()&&!"".equals(column.getValue())?Integer.parseInt(column.getValue()):null);
  84 + break;
73 } 85 }
74 } 86 }
75 if(null == iotDevice.getSummary() || null == iotDevice.getThings_model_value() || null == iotDevice.getClient_id() ) 87 if(null == iotDevice.getSummary() || null == iotDevice.getThings_model_value() || null == iotDevice.getClient_id() )
@@ -25,6 +25,15 @@ public class IotTerminal { @@ -25,6 +25,15 @@ public class IotTerminal {
25 private Integer user_info_id; 25 private Integer user_info_id;
26 private String name; 26 private String name;
27 27
  28 + private Integer online;
  29 +
  30 + public Integer getOnline() {
  31 + return online;
  32 + }
  33 +
  34 + public void setOnline(Integer online) {
  35 + this.online = online;
  36 + }
28 37
29 public String getName() { 38 public String getName() {
30 return name; 39 return name;
@@ -113,6 +122,9 @@ public class IotTerminal { @@ -113,6 +122,9 @@ public class IotTerminal {
113 case "name": 122 case "name":
114 iotTerminal.setName(column.getValue()); 123 iotTerminal.setName(column.getValue());
115 break; 124 break;
  125 + case "online":
  126 + iotTerminal.setOnline ( null!=column.getValue()&&!"".equals(column.getValue())?Integer.parseInt(column.getValue()):null);
  127 + break;
116 } 128 }
117 } 129 }
118 if(null == iotTerminal.getThings_model_value() || null == iotTerminal.getThings_model_config() || null == iotTerminal.getId()) 130 if(null == iotTerminal.getThings_model_value() || null == iotTerminal.getThings_model_config() || null == iotTerminal.getId())
@@ -113,13 +113,14 @@ public class WeiXinMessage { @@ -113,13 +113,14 @@ public class WeiXinMessage {
113 public static String getWechatServerToken(String appid, String secret) { 113 public static String getWechatServerToken(String appid, String secret) {
114 114
115 Token token = tokenMap.get(appid); 115 Token token = tokenMap.get(appid);
116 - int time =new Long(System.currentTimeMillis()).intValue(); 116 + int time =new Long(System.currentTimeMillis()/1000).intValue();
117 if(null != token && token.getExpires_in()-time>0) 117 if(null != token && token.getExpires_in()-time>0)
118 { 118 {
119 return token.getAccess_token(); 119 return token.getAccess_token();
120 } 120 }
121 token = TokenAPI.token(appid,secret); 121 token = TokenAPI.token(appid,secret);
122 token.setExpires_in(time+token.getExpires_in()-600); //提前10分钟 122 token.setExpires_in(time+token.getExpires_in()-600); //提前10分钟
  123 + tokenMap.put(appid,token);
123 return token.getAccess_token(); 124 return token.getAccess_token();
124 } 125 }
125 } 126 }
@@ -29,7 +29,7 @@ public class TriggerAlarmService { @@ -29,7 +29,7 @@ public class TriggerAlarmService {
29 29
30 // 创建Canal连接器 30 // 创建Canal连接器
31 private static CanalConnector connector = CanalConnectors.newSingleConnector( 31 private static CanalConnector connector = CanalConnectors.newSingleConnector(
32 - new InetSocketAddress("127.0.0.1", 11111), 32 + new InetSocketAddress("8.129.82.37", 11111),
33 "example", 33 "example",
34 "", 34 "",
35 "" 35 ""
@@ -76,10 +76,10 @@ public class UserInfoController extends BaseController { @@ -76,10 +76,10 @@ public class UserInfoController extends BaseController {
76 //更新用户通知 76 //更新用户通知
77 IotAlertUserNotice iotAlertUserNotice = new IotAlertUserNotice(); 77 IotAlertUserNotice iotAlertUserNotice = new IotAlertUserNotice();
78 iotAlertUserNotice.setUser_id(user_id); 78 iotAlertUserNotice.setUser_id(user_id);
79 - ct = publicService.getObjectListTotle(userOpenid,null); 79 + ct = publicService.getObjectListTotle(iotAlertUserNotice,null);
80 if(0 < ct) 80 if(0 < ct)
81 { 81 {
82 - return AjaxResult.success("您已经开通过通知服务了,请到通知服务编辑页面进行编辑"); 82 + return AjaxResult.error("您已经开通过通知服务了,请到通知服务编辑页面进行编辑");
83 } 83 }
84 84
85 IotAlertUserNotice sysIotAlertUserNotice = new IotAlertUserNotice(); 85 IotAlertUserNotice sysIotAlertUserNotice = new IotAlertUserNotice();
1 package com.zhonglai.luhui.device.protocol.factory.config; 1 package com.zhonglai.luhui.device.protocol.factory.config;
2 2
  3 +import com.zhonglai.luhui.device.analysis.comm.dao.BaseDao;
3 import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; 4 import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto;
4 import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; 5 import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto;
  6 +import com.zhonglai.luhui.device.protocol.factory.service.impl.DefaultDbService;
5 import net.jodah.expiringmap.ExpirationListener; 7 import net.jodah.expiringmap.ExpirationListener;
6 import net.jodah.expiringmap.ExpirationPolicy; 8 import net.jodah.expiringmap.ExpirationPolicy;
7 import net.jodah.expiringmap.ExpiringMap; 9 import net.jodah.expiringmap.ExpiringMap;
@@ -24,21 +26,17 @@ public class DeviceCach { @@ -24,21 +26,17 @@ public class DeviceCach {
24 // 清零过期时间也就是重置过期时间,重新计算过期时间. 26 // 清零过期时间也就是重置过期时间,重新计算过期时间.
25 private static ExpiringMap<String, ParserDeviceInfoDto> parserDeviceInfoDtoMap = ExpiringMap.builder().maxSize(20000).expiration(60, TimeUnit.SECONDS) 27 private static ExpiringMap<String, ParserDeviceInfoDto> parserDeviceInfoDtoMap = ExpiringMap.builder().maxSize(20000).expiration(60, TimeUnit.SECONDS)
26 .variableExpiration() 28 .variableExpiration()
27 - .asyncExpirationListener(new ExpirationListener<String, ParserDeviceInfoDto>() {  
28 - @Override  
29 - public void expired(String s, ParserDeviceInfoDto parserDeviceInfoDto) { 29 + .asyncExpirationListener((ExpirationListener<String, ParserDeviceInfoDto>) (s, parserDeviceInfoDto) -> {
30 log.info("超时清除>>>>>>>:{} ",s); 30 log.info("超时清除>>>>>>>:{} ",s);
31 - } 31 + DefaultDbService.baseDao.updateBySql("update iot_terminal set online=4 where id='"+s+"'");
32 }) 32 })
33 .expirationPolicy(ExpirationPolicy.ACCESSED).build(); 33 .expirationPolicy(ExpirationPolicy.ACCESSED).build();
34 34
35 private static ExpiringMap<String, ParserDeviceHostDto> parserDeviceHostDtoMap = ExpiringMap.builder().maxSize(20000).expiration(60, TimeUnit.SECONDS) 35 private static ExpiringMap<String, ParserDeviceHostDto> parserDeviceHostDtoMap = ExpiringMap.builder().maxSize(20000).expiration(60, TimeUnit.SECONDS)
36 .variableExpiration() 36 .variableExpiration()
37 - .asyncExpirationListener(new ExpirationListener<String, ParserDeviceHostDto>() {  
38 - @Override  
39 - public void expired(String s, ParserDeviceHostDto parserDeviceHostDto) { 37 + .asyncExpirationListener((ExpirationListener<String, ParserDeviceHostDto>) (s, parserDeviceHostDto) -> {
40 log.info("超时清除>>>>>>>:{} ",s); 38 log.info("超时清除>>>>>>>:{} ",s);
41 - } 39 + DefaultDbService.baseDao.updateBySql("update iot_device set status=4 where client_id='"+s+"'");
42 }) 40 })
43 .expirationPolicy(ExpirationPolicy.ACCESSED).build(); 41 .expirationPolicy(ExpirationPolicy.ACCESSED).build();
44 42
@@ -48,7 +46,7 @@ public class DeviceCach { @@ -48,7 +46,7 @@ public class DeviceCach {
48 { 46 {
49 parserDeviceInfoDtoMap.put(parserDeviceInfoDto.getId(),parserDeviceInfoDto); 47 parserDeviceInfoDtoMap.put(parserDeviceInfoDto.getId(),parserDeviceInfoDto);
50 }else{ 48 }else{
51 - parserDeviceInfoDtoMap.put(parserDeviceInfoDto.getId(),parserDeviceInfoDto,device_life*3,TimeUnit.SECONDS); 49 + parserDeviceInfoDtoMap.put(parserDeviceInfoDto.getId(),parserDeviceInfoDto,device_life+15,TimeUnit.SECONDS);
52 } 50 }
53 } 51 }
54 52
@@ -58,7 +56,7 @@ public class DeviceCach { @@ -58,7 +56,7 @@ public class DeviceCach {
58 { 56 {
59 parserDeviceHostDtoMap.put(parserDeviceHostDto.getId(),parserDeviceHostDto); 57 parserDeviceHostDtoMap.put(parserDeviceHostDto.getId(),parserDeviceHostDto);
60 }else { 58 }else {
61 - parserDeviceHostDtoMap.put(parserDeviceHostDto.getId(),parserDeviceHostDto,device_life*3,TimeUnit.SECONDS); 59 + parserDeviceHostDtoMap.put(parserDeviceHostDto.getId(),parserDeviceHostDto,device_life+15,TimeUnit.SECONDS);
62 } 60 }
63 } 61 }
64 public static void cleanDeviceHost(String deviceId) 62 public static void cleanDeviceHost(String deviceId)
@@ -93,7 +93,7 @@ public class MqttSubscribeService { @@ -93,7 +93,7 @@ public class MqttSubscribeService {
93 sts[i++] = s; 93 sts[i++] = s;
94 } 94 }
95 mqttclient.subscribe(sts); 95 mqttclient.subscribe(sts);
96 - log.info("-----------topic【{}】订阅成功--------------------",sts); 96 + log.info("-----------topic【{}】订阅成功--------------------",ts);
97 97
98 if (!"1".equals(System.getProperty("RunInIDEA"))) //如果是本地环境不需要跟新服务器地址 98 if (!"1".equals(System.getProperty("RunInIDEA"))) //如果是本地环境不需要跟新服务器地址
99 { 99 {
@@ -29,7 +29,7 @@ import java.util.Map; @@ -29,7 +29,7 @@ import java.util.Map;
29 public class DefaultDbService { 29 public class DefaultDbService {
30 private final Logger log = LoggerFactory.getLogger(this.getClass()); 30 private final Logger log = LoggerFactory.getLogger(this.getClass());
31 31
32 - private BaseDao baseDao = new BaseDao(); 32 + public static BaseDao baseDao = new BaseDao();
33 33
34 @Autowired 34 @Autowired
35 private DeviceCommandListenService deviceCommandListenService; 35 private DeviceCommandListenService deviceCommandListenService;
@@ -133,21 +133,11 @@ public class MqttDeviceService extends DeviceService{ @@ -133,21 +133,11 @@ public class MqttDeviceService extends DeviceService{
133 thingsModel.setSpecs(spes.toString()); 133 thingsModel.setSpecs(spes.toString());
134 } 134 }
135 String data_type = thingsModel.getData_type().toUpperCase(); 135 String data_type = thingsModel.getData_type().toUpperCase();
136 -// Class<ThingsModelBase> aClass = Enum.valueOf(ThingsModelDataTypeEnum.class,data_type).getaClass();  
137 -// ThingsModelBase thingsModelBase = JSON.parseObject(thingsModel.getSpecs(),aClass);  
138 -// thingsModelBase.conversionThingsModel(thingsModel);  
139 Object object = jsonObject.get(skey); 136 Object object = jsonObject.get(skey);
140 -// Type clas = ((ParameterizedType)aClass.getGenericSuperclass()).getActualTypeArguments()[0];  
141 -// if(null != object && object.getClass()!=clas)  
142 -// {  
143 -// return new Message(MessageCode.DEFAULT_FAIL_CODE,skey+" 参数数据类型和模型数据类型("+clas+")不一致");  
144 -// }  
145 -// ThingsModelItemBase thingsModelItemBase = (ThingsModelItemBase) thingsModelBase;  
146 137
147 - ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModelItem(Enum.valueOf(ThingsModelDataTypeEnum.class,data_type),thingsModel,gsonobject.get(skey)); 138 + ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModelItemFromControl(Enum.valueOf(ThingsModelDataTypeEnum.class,data_type),thingsModel,gsonobject.get(skey));
148 139
149 jsonObject.put(skey,thingsModelItemBase.getCmdView(object)); 140 jsonObject.put(skey,thingsModelItemBase.getCmdView(object));
150 -// thingsModelItemBase.setValue(thingsModelItemBase.getCmdView(object));  
151 141
152 String id = clienid+"_"+key; 142 String id = clienid+"_"+key;
153 logDeviceOperationList.add(dviceLogService.newLogDeviceOperation(id,thingsModelItemBase.getSaveView(),null,"远程控制"+thingsModelItemBase.getName()+"为"+thingsModelItemBase.getView(),null)); 143 logDeviceOperationList.add(dviceLogService.newLogDeviceOperation(id,thingsModelItemBase.getSaveView(),null,"远程控制"+thingsModelItemBase.getName()+"为"+thingsModelItemBase.getView(),null));
@@ -49,7 +49,7 @@ mqtt: @@ -49,7 +49,7 @@ mqtt:
49 mqtt_usernames: 6_WP 49 mqtt_usernames: 6_WP
50 #订阅的topic 50 #订阅的topic
51 topics: ADD_POST,ALL_POST,DB_TOPIC_DISTRIBUTE,GET/+,online,PUT_REQ/+,READ_REQ/+ 51 topics: ADD_POST,ALL_POST,DB_TOPIC_DISTRIBUTE,GET/+,online,PUT_REQ/+,READ_REQ/+
52 - sub_clientid: '863482065281251' 52 + sub_clientid: '+'
53 topicconfig: "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{topicType}}/{{messageid}}" 53 topicconfig: "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{topicType}}/{{messageid}}"
54 top_return_map: '{"PUT":"PUT_REQ","READ":"READ_REQ"}' 54 top_return_map: '{"PUT":"PUT_REQ","READ":"READ_REQ"}'
55 username: sysuser 55 username: sysuser