正在显示
66 个修改的文件
包含
2132 行增加
和
222 行删除
| 1 | +package com.ruoyi.system.domain.user; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | + | ||
| 6 | +@ApiModel("终端分组") | ||
| 7 | +public class UserOpenid { | ||
| 8 | + @ApiModelProperty("主键") | ||
| 9 | + private Integer id; // int DEFAULT NULL COMMENT '主键', | ||
| 10 | + @ApiModelProperty("用户id") | ||
| 11 | + private Integer user_id; // int DEFAULT NULL COMMENT '用户id', | ||
| 12 | + @ApiModelProperty("微信用户的唯一标识") | ||
| 13 | + private String openid; // varchar(50) DEFAULT NULL COMMENT '微信用户的唯一标识', | ||
| 14 | + @ApiModelProperty("微信平台的配置参数表id") | ||
| 15 | + private Integer xcx_config_id; // int DEFAULT NULL COMMENT '微信平台的配置参数表id', | ||
| 16 | + @ApiModelProperty("创建时间") | ||
| 17 | + private String create_time ; //timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | ||
| 18 | + | ||
| 19 | + public String getCreate_time() { | ||
| 20 | + return create_time; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public void setCreate_time(String create_time) { | ||
| 24 | + this.create_time = create_time; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public Integer getId() { | ||
| 28 | + return id; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public void setId(Integer id) { | ||
| 32 | + this.id = id; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public Integer getUser_id() { | ||
| 36 | + return user_id; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public void setUser_id(Integer user_id) { | ||
| 40 | + this.user_id = user_id; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public String getOpenid() { | ||
| 44 | + return openid; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public void setOpenid(String openid) { | ||
| 48 | + this.openid = openid; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public Integer getXcx_config_id() { | ||
| 52 | + return xcx_config_id; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public void setXcx_config_id(Integer xcx_config_id) { | ||
| 56 | + this.xcx_config_id = xcx_config_id; | ||
| 57 | + } | ||
| 58 | +} |
| @@ -71,7 +71,7 @@ public class SecurityConfigService { | @@ -71,7 +71,7 @@ public class SecurityConfigService { | ||
| 71 | // 过滤请求 | 71 | // 过滤请求 |
| 72 | .authorizeRequests() | 72 | .authorizeRequests() |
| 73 | // 对于登录login 注册register 验证码captchaImage 允许匿名访问 | 73 | // 对于登录login 注册register 验证码captchaImage 允许匿名访问 |
| 74 | - .antMatchers(antMatchers.split(",")).anonymous() | 74 | + .antMatchers(antMatchers.split(",")).permitAll() |
| 75 | .antMatchers( | 75 | .antMatchers( |
| 76 | HttpMethod.GET, | 76 | HttpMethod.GET, |
| 77 | "/", | 77 | "/", |
| @@ -81,11 +81,7 @@ public class SecurityConfigService { | @@ -81,11 +81,7 @@ public class SecurityConfigService { | ||
| 81 | "/**/*.js", | 81 | "/**/*.js", |
| 82 | "/profile/**" | 82 | "/profile/**" |
| 83 | ).permitAll() | 83 | ).permitAll() |
| 84 | - .antMatchers("/swagger-ui.html").anonymous() | ||
| 85 | - .antMatchers("/swagger-resources/**").anonymous() | ||
| 86 | - .antMatchers("/webjars/**").anonymous() | ||
| 87 | - .antMatchers("/*/api-docs").anonymous() | ||
| 88 | - .antMatchers("/druid/**").anonymous() | 84 | + .antMatchers("/swagger-ui.html","/swagger-resources/**","/webjars/**","/*/api-docs","/druid/**").permitAll() |
| 89 | // 除上面外的所有请求全部需要鉴权认证 | 85 | // 除上面外的所有请求全部需要鉴权认证 |
| 90 | .anyRequest().authenticated() | 86 | .anyRequest().authenticated() |
| 91 | .and() | 87 | .and() |
| @@ -18,7 +18,7 @@ public class Topic { | @@ -18,7 +18,7 @@ public class Topic { | ||
| 18 | private String topicType; | 18 | private String topicType; |
| 19 | private String messageid; | 19 | private String messageid; |
| 20 | private String payloadtype; | 20 | private String payloadtype; |
| 21 | - | 21 | + private boolean isAllup; |
| 22 | public Topic() { | 22 | public Topic() { |
| 23 | } | 23 | } |
| 24 | 24 |
| @@ -46,6 +46,16 @@ public class IotAlertLog extends BaseEntity | @@ -46,6 +46,16 @@ public class IotAlertLog extends BaseEntity | ||
| 46 | private Long create_time; // datetime DEFAULT NULL COMMENT '创建时间', | 46 | private Long create_time; // datetime DEFAULT NULL COMMENT '创建时间', |
| 47 | @ApiModelProperty("类型(1=告警,2=场景联动)") | 47 | @ApiModelProperty("类型(1=告警,2=场景联动)") |
| 48 | private Integer type; // tinyint DEFAULT NULL COMMENT '类型(1=告警,2=场景联动)', | 48 | private Integer type; // tinyint DEFAULT NULL COMMENT '类型(1=告警,2=场景联动)', |
| 49 | + @ApiModelProperty("关联的用户id(0为系统生成)") | ||
| 50 | + private Integer user_id; | ||
| 51 | + | ||
| 52 | + public Integer getUser_id() { | ||
| 53 | + return user_id; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public void setUser_id(Integer user_id) { | ||
| 57 | + this.user_id = user_id; | ||
| 58 | + } | ||
| 49 | 59 | ||
| 50 | public Long getAlertId() { | 60 | public Long getAlertId() { |
| 51 | return alertId; | 61 | return alertId; |
| 1 | +package com.zhonglai.luhui.device.domain; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 告警通知渠道 | ||
| 8 | + */ | ||
| 9 | +@ApiModel("告警通知渠道") | ||
| 10 | +public class IotAlertNoticeChannel { | ||
| 11 | + @ApiModelProperty("主键") | ||
| 12 | + private Integer id; // int NOT NULL AUTO_INCREMENT COMMENT '主键', | ||
| 13 | + @ApiModelProperty("渠道类型(1公众号,2小程序,3鱼儿乐app,4短信,5电话)") | ||
| 14 | + private Integer type; // int NOT NULL COMMENT '渠道类型(1公众号,2小程序,3鱼儿乐app,4短信,5电话)', | ||
| 15 | + @ApiModelProperty("渠道配置") | ||
| 16 | + private String config; // json NOT NULL COMMENT '渠道配置', | ||
| 17 | + @ApiModelProperty("名称") | ||
| 18 | + private String name; // varchar(50) NOT NULL COMMENT '名称', | ||
| 19 | + @ApiModelProperty("创建时间") | ||
| 20 | + private String create_time; // varchar(50) NOT NULL COMMENT '创建时间', | ||
| 21 | + @ApiModelProperty("修改时间") | ||
| 22 | + private String update_time; // varchar(50) NOT NULL COMMENT '修改时间', | ||
| 23 | + | ||
| 24 | + public String getCreate_time() { | ||
| 25 | + return create_time; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public void setCreate_time(String create_time) { | ||
| 29 | + this.create_time = create_time; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public String getUpdate_time() { | ||
| 33 | + return update_time; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public void setUpdate_time(String update_time) { | ||
| 37 | + this.update_time = update_time; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public Integer getId() { | ||
| 41 | + return id; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public void setId(Integer id) { | ||
| 45 | + this.id = id; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public Integer getType() { | ||
| 49 | + return type; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public void setType(Integer type) { | ||
| 53 | + this.type = type; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public String getConfig() { | ||
| 57 | + return config; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public void setConfig(String config) { | ||
| 61 | + this.config = config; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public String getName() { | ||
| 65 | + return name; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public void setName(String name) { | ||
| 69 | + this.name = name; | ||
| 70 | + } | ||
| 71 | +} |
lh-jar/lh-jar-device-service/src/main/java/com/zhonglai/luhui/device/domain/IotAlertUserNotice.java
0 → 100644
| 1 | +package com.zhonglai.luhui.device.domain; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 用户告警通知配置 | ||
| 8 | + */ | ||
| 9 | +@ApiModel("用户告警通知配置") | ||
| 10 | +public class IotAlertUserNotice { | ||
| 11 | + @ApiModelProperty("主键") | ||
| 12 | + private Integer id; // int NOT NULL AUTO_INCREMENT COMMENT '主键id', | ||
| 13 | + @ApiModelProperty("通知渠道(iot_alert_notice_channel表的id集合,多个英文逗号分割)") | ||
| 14 | + private String channels; // varchar(100) DEFAULT NULL COMMENT '通知渠道(iot_alert_notice_channel表的id集合,多个英文逗号分割)', | ||
| 15 | + @ApiModelProperty("告警类型(1系统告警,2用户告警)") | ||
| 16 | + private Integer type; // int DEFAULT NULL COMMENT '告警类型(1系统告警,2用户告警)', | ||
| 17 | + @ApiModelProperty("告警id集合(关联iot_alert_log和iot_alert_user表的id,多个英文逗号分割,*表示所有)") | ||
| 18 | + private String alert_ids; // varchar(100) DEFAULT '*' COMMENT '告警id集合(关联iot_alert_log和iot_alert_user表的id,多个英文逗号分割,*表示所有)' | ||
| 19 | + @ApiModelProperty("用户id") | ||
| 20 | + private Integer user_id; // int DEFAULT NULL COMMENT '用户id' | ||
| 21 | + @ApiModelProperty("创建时间") | ||
| 22 | + private String create_time; // int DEFAULT NULL COMMENT '创建时间' | ||
| 23 | + @ApiModelProperty("更新时间") | ||
| 24 | + private String update_time; // int DEFAULT NULL COMMENT '更新时间' | ||
| 25 | + | ||
| 26 | + public Integer getId() { | ||
| 27 | + return id; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public void setId(Integer id) { | ||
| 31 | + this.id = id; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + public Integer getType() { | ||
| 35 | + return type; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public void setType(Integer type) { | ||
| 39 | + this.type = type; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public Integer getUser_id() { | ||
| 43 | + return user_id; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + public void setUser_id(Integer user_id) { | ||
| 47 | + this.user_id = user_id; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + public String getCreate_time() { | ||
| 51 | + return create_time; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + public void setCreate_time(String create_time) { | ||
| 55 | + this.create_time = create_time; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public String getUpdate_time() { | ||
| 59 | + return update_time; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public void setUpdate_time(String update_time) { | ||
| 63 | + this.update_time = update_time; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public String getChannels() { | ||
| 67 | + return channels; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + public void setChannels(String channels) { | ||
| 71 | + this.channels = channels; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + | ||
| 75 | + public String getAlert_ids() { | ||
| 76 | + return alert_ids; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public void setAlert_ids(String alert_ids) { | ||
| 80 | + this.alert_ids = alert_ids; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | +} |
| @@ -127,6 +127,16 @@ public class IotDevice implements Serializable | @@ -127,6 +127,16 @@ public class IotDevice implements Serializable | ||
| 127 | @ApiModelProperty("数据更新时间") | 127 | @ApiModelProperty("数据更新时间") |
| 128 | private Integer data_update_time; | 128 | private Integer data_update_time; |
| 129 | 129 | ||
| 130 | + @ApiModelProperty("操作令牌") | ||
| 131 | + private String operation_token; | ||
| 132 | + | ||
| 133 | + public String getOperation_token() { | ||
| 134 | + return operation_token; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + public void setOperation_token(String operation_token) { | ||
| 138 | + this.operation_token = operation_token; | ||
| 139 | + } | ||
| 130 | 140 | ||
| 131 | public Integer getData_update_time() { | 141 | public Integer getData_update_time() { |
| 132 | return data_update_time; | 142 | return data_update_time; |
| @@ -64,6 +64,16 @@ public class IotTerminal implements Serializable | @@ -64,6 +64,16 @@ public class IotTerminal implements Serializable | ||
| 64 | @ApiModelProperty("在线状态") | 64 | @ApiModelProperty("在线状态") |
| 65 | private Integer online; | 65 | private Integer online; |
| 66 | 66 | ||
| 67 | + @ApiModelProperty("操作令牌") | ||
| 68 | + private String operation_token; | ||
| 69 | + | ||
| 70 | + public String getOperation_token() { | ||
| 71 | + return operation_token; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public void setOperation_token(String operation_token) { | ||
| 75 | + this.operation_token = operation_token; | ||
| 76 | + } | ||
| 67 | private UserTerminalGroupRelation userTerminalGroupRelation; | 77 | private UserTerminalGroupRelation userTerminalGroupRelation; |
| 68 | 78 | ||
| 69 | private IotDevice iotDevice; | 79 | private IotDevice iotDevice; |
| 1 | +package com.zhonglai.luhui.device.dto; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 公众号通知的配置 | ||
| 5 | + */ | ||
| 6 | +public class WeiXinGongZhongHaoNoticeDto { | ||
| 7 | + private Integer xcxConfigId; | ||
| 8 | + private String xcxappid; | ||
| 9 | + private String xcxsecret; | ||
| 10 | + private String gzhappid; | ||
| 11 | + private String gzhsecret; | ||
| 12 | + private String templateId; | ||
| 13 | + private String redirectUrl; | ||
| 14 | + | ||
| 15 | + public String getGzhsecret() { | ||
| 16 | + return gzhsecret; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public void setGzhsecret(String gzhsecret) { | ||
| 20 | + this.gzhsecret = gzhsecret; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public Integer getXcxConfigId() { | ||
| 24 | + return xcxConfigId; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public void setXcxConfigId(Integer xcxConfigId) { | ||
| 28 | + this.xcxConfigId = xcxConfigId; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public String getXcxappid() { | ||
| 32 | + return xcxappid; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public void setXcxappid(String xcxappid) { | ||
| 36 | + this.xcxappid = xcxappid; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public String getXcxsecret() { | ||
| 40 | + return xcxsecret; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public void setXcxsecret(String xcxsecret) { | ||
| 44 | + this.xcxsecret = xcxsecret; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public String getGzhappid() { | ||
| 48 | + return gzhappid; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setGzhappid(String gzhappid) { | ||
| 52 | + this.gzhappid = gzhappid; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public String getTemplateId() { | ||
| 56 | + return templateId; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void setTemplateId(String templateId) { | ||
| 60 | + this.templateId = templateId; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public String getRedirectUrl() { | ||
| 64 | + return redirectUrl; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public void setRedirectUrl(String redirectUrl) { | ||
| 68 | + this.redirectUrl = redirectUrl; | ||
| 69 | + } | ||
| 70 | +} |
| @@ -67,5 +67,5 @@ public interface IIotTerminalService | @@ -67,5 +67,5 @@ public interface IIotTerminalService | ||
| 67 | 67 | ||
| 68 | List<IotTerminal> selectNotUserIotTerminalListByImei(String device_id); | 68 | List<IotTerminal> selectNotUserIotTerminalListByImei(String device_id); |
| 69 | 69 | ||
| 70 | - int batchUpName(List<String> ids,List<String> names); | 70 | + int batchUpName(List<String> ids,List<String> names,Integer user_id); |
| 71 | } | 71 | } |
| @@ -155,8 +155,8 @@ public class IotTerminalServiceImpl implements IIotTerminalService | @@ -155,8 +155,8 @@ public class IotTerminalServiceImpl implements IIotTerminalService | ||
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | @Override | 157 | @Override |
| 158 | - public int batchUpName(List<String> ids, List<String> names) { | ||
| 159 | - StringBuffer sql = new StringBuffer("UPDATE `mqtt_broker`.`iot_terminal` SET `name` = CASE"); | 158 | + public int batchUpName(List<String> ids, List<String> names,Integer user_id) { |
| 159 | + StringBuffer sql = new StringBuffer("UPDATE `mqtt_broker`.`iot_terminal` SET `user_info_id`="+user_id+",`name` = CASE"); | ||
| 160 | StringBuffer where = new StringBuffer(" where id in("); | 160 | StringBuffer where = new StringBuffer(" where id in("); |
| 161 | for (int i=0;i<ids.size();i++) | 161 | for (int i=0;i<ids.size();i++) |
| 162 | { | 162 | { |
| @@ -5,7 +5,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -5,7 +5,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 5 | <mapper namespace="com.zhonglai.luhui.device.mapper.IotAlertLogMapper"> | 5 | <mapper namespace="com.zhonglai.luhui.device.mapper.IotAlertLogMapper"> |
| 6 | 6 | ||
| 7 | <resultMap type="com.zhonglai.luhui.device.domain.IotAlertLog" id="AlertLogResult"> | 7 | <resultMap type="com.zhonglai.luhui.device.domain.IotAlertLog" id="AlertLogResult"> |
| 8 | - <result property="alertLogId" column="alert_log__id" /> | 8 | + <result property="alertLogId" column="alert_log_id" /> |
| 9 | <result property="alertName" column="alert_name" /> | 9 | <result property="alertName" column="alert_name" /> |
| 10 | <result property="alertId" column="alert_id" /> | 10 | <result property="alertId" column="alert_id" /> |
| 11 | <result property="alertLevel" column="alert_level" /> | 11 | <result property="alertLevel" column="alert_level" /> |
| @@ -13,10 +13,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -13,10 +13,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 13 | <result property="deviceId" column="device_id" /> | 13 | <result property="deviceId" column="device_id" /> |
| 14 | <result property="create_time" column="create_time" /> | 14 | <result property="create_time" column="create_time" /> |
| 15 | <result property="type" column="type" /> | 15 | <result property="type" column="type" /> |
| 16 | + <result property="user_id" column="user_id" /> | ||
| 16 | </resultMap> | 17 | </resultMap> |
| 17 | 18 | ||
| 18 | <sql id="selectAlertLogVo"> | 19 | <sql id="selectAlertLogVo"> |
| 19 | - select alert_log__id, alert_name,alert_id, alert_level, status, device_id, create_time, type from iot_alert_log | 20 | + select alert_log_id, alert_name,alert_id, alert_level, `status`, device_id, create_time, `type`,user_id from iot_alert_log |
| 20 | </sql> | 21 | </sql> |
| 21 | 22 | ||
| 22 | <select id="selectAlertLogList" parameterType="com.zhonglai.luhui.device.domain.IotAlertLog" resultMap="AlertLogResult"> | 23 | <select id="selectAlertLogList" parameterType="com.zhonglai.luhui.device.domain.IotAlertLog" resultMap="AlertLogResult"> |
| @@ -34,11 +34,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -34,11 +34,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 34 | <result property="listen_service_ip" column="listen_service_ip" /> | 34 | <result property="listen_service_ip" column="listen_service_ip" /> |
| 35 | <result property="device_life" column="device_life" /> | 35 | <result property="device_life" column="device_life" /> |
| 36 | <result property="data_update_time" column="data_update_time" /> | 36 | <result property="data_update_time" column="data_update_time" /> |
| 37 | - | 37 | + <result property="operation_token" column="operation_token" /> |
| 38 | </resultMap> | 38 | </resultMap> |
| 39 | 39 | ||
| 40 | <sql id="selectIotDeviceVo"> | 40 | <sql id="selectIotDeviceVo"> |
| 41 | - select active_time, client_id, completion_auth, create_by, create_time, del_flag, firmware_version, img_url, is_shadow, latitude, location_way, longitude, `name`, network_address, network_ip, remark, rssi, status, summary, things_model_value, update_by, update_time, product_id,mqtt_username,payload_type,things_model_config,listen_service_ip,device_life,data_update_time,mqtt_username from iot_device | 41 | + select active_time, client_id, completion_auth, create_by, create_time, del_flag, firmware_version, img_url, is_shadow, latitude, location_way, longitude, `name`, network_address, network_ip, remark, rssi, status, summary, things_model_value, update_by, update_time, product_id,mqtt_username,payload_type,things_model_config,listen_service_ip,device_life,data_update_time,mqtt_username,operation_token from iot_device |
| 42 | </sql> | 42 | </sql> |
| 43 | 43 | ||
| 44 | <select id="selectIotDeviceList" parameterType="IotDevice" resultMap="IotDeviceResult"> | 44 | <select id="selectIotDeviceList" parameterType="IotDevice" resultMap="IotDeviceResult"> |
| @@ -5,11 +5,15 @@ import com.alibaba.fastjson.JSONObject; | @@ -5,11 +5,15 @@ import com.alibaba.fastjson.JSONObject; | ||
| 5 | import com.ruoyi.common.core.domain.DeviceCommandApi; | 5 | import com.ruoyi.common.core.domain.DeviceCommandApi; |
| 6 | import com.ruoyi.common.core.domain.Message; | 6 | import com.ruoyi.common.core.domain.Message; |
| 7 | import com.ruoyi.common.core.domain.MessageCode; | 7 | import com.ruoyi.common.core.domain.MessageCode; |
| 8 | +import com.ruoyi.common.utils.StringUtils; | ||
| 9 | +import lombok.val; | ||
| 8 | import org.apache.rocketmq.client.exception.MQBrokerException; | 10 | import org.apache.rocketmq.client.exception.MQBrokerException; |
| 9 | import org.apache.rocketmq.client.exception.MQClientException; | 11 | import org.apache.rocketmq.client.exception.MQClientException; |
| 10 | import org.apache.rocketmq.client.exception.RequestTimeoutException; | 12 | import org.apache.rocketmq.client.exception.RequestTimeoutException; |
| 13 | +import org.apache.rocketmq.client.producer.DefaultMQProducer; | ||
| 11 | import org.apache.rocketmq.client.producer.SendCallback; | 14 | import org.apache.rocketmq.client.producer.SendCallback; |
| 12 | import org.apache.rocketmq.client.producer.SendResult; | 15 | import org.apache.rocketmq.client.producer.SendResult; |
| 16 | +import org.apache.rocketmq.remoting.common.RemotingHelper; | ||
| 13 | import org.apache.rocketmq.remoting.exception.RemotingException; | 17 | import org.apache.rocketmq.remoting.exception.RemotingException; |
| 14 | import org.apache.rocketmq.spring.core.RocketMQTemplate; | 18 | import org.apache.rocketmq.spring.core.RocketMQTemplate; |
| 15 | import org.slf4j.Logger; | 19 | import org.slf4j.Logger; |
| @@ -19,6 +23,8 @@ import org.springframework.beans.factory.annotation.Value; | @@ -19,6 +23,8 @@ import org.springframework.beans.factory.annotation.Value; | ||
| 19 | import org.springframework.messaging.support.MessageBuilder; | 23 | import org.springframework.messaging.support.MessageBuilder; |
| 20 | import org.springframework.stereotype.Service; | 24 | import org.springframework.stereotype.Service; |
| 21 | 25 | ||
| 26 | +import java.io.UnsupportedEncodingException; | ||
| 27 | + | ||
| 22 | 28 | ||
| 23 | @Service | 29 | @Service |
| 24 | public class RocketMqService { | 30 | public class RocketMqService { |
| @@ -42,7 +48,11 @@ public class RocketMqService { | @@ -42,7 +48,11 @@ public class RocketMqService { | ||
| 42 | 48 | ||
| 43 | public Message send(String topic,byte[] payload) | 49 | public Message send(String topic,byte[] payload) |
| 44 | { | 50 | { |
| 45 | - org.apache.rocketmq.common.message.Message msg = new org.apache.rocketmq.common.message.Message(topic,sendTags,payload); | 51 | + return send(topic,payload,null); |
| 52 | + } | ||
| 53 | + public Message send(String topic,byte[] payload,String operation_token) | ||
| 54 | + { | ||
| 55 | + org.apache.rocketmq.common.message.Message msg = new org.apache.rocketmq.common.message.Message(topic,null==operation_token?sendTags:operation_token,payload); | ||
| 46 | try { | 56 | try { |
| 47 | org.apache.rocketmq.common.message.Message ms = rocketMQTemplate.getProducer().request(msg,30000l); | 57 | org.apache.rocketmq.common.message.Message ms = rocketMQTemplate.getProducer().request(msg,30000l); |
| 48 | JSONObject jsonObject = (JSONObject) JSON.parse(new String(ms.getBody())); | 58 | JSONObject jsonObject = (JSONObject) JSON.parse(new String(ms.getBody())); |
| @@ -62,8 +72,9 @@ public class RocketMqService { | @@ -62,8 +72,9 @@ public class RocketMqService { | ||
| 62 | return new Message(MessageCode.DEFAULT_FAIL_CODE); | 72 | return new Message(MessageCode.DEFAULT_FAIL_CODE); |
| 63 | } | 73 | } |
| 64 | 74 | ||
| 65 | - public void syncSend(String topic, Object message) | 75 | + public void syncSend(String topic,byte[] payload,String operation_token) |
| 66 | { | 76 | { |
| 67 | - rocketMQTemplate.syncSend(topic, MessageBuilder.withPayload(message).build(), 3000, 1); | 77 | + rocketMQTemplate.sendOneWay(topic+":"+(null==operation_token?sendTags:operation_token),payload); |
| 68 | } | 78 | } |
| 79 | + | ||
| 69 | } | 80 | } |
| @@ -8,8 +8,10 @@ import com.ruoyi.common.core.domain.Message; | @@ -8,8 +8,10 @@ import com.ruoyi.common.core.domain.Message; | ||
| 8 | import com.ruoyi.common.enums.BusinessType; | 8 | import com.ruoyi.common.enums.BusinessType; |
| 9 | import com.ruoyi.common.utils.GsonConstructor; | 9 | import com.ruoyi.common.utils.GsonConstructor; |
| 10 | import com.zhonglai.luhui.action.BaseController; | 10 | import com.zhonglai.luhui.action.BaseController; |
| 11 | +import com.zhonglai.luhui.device.domain.IotDevice; | ||
| 11 | import com.zhonglai.luhui.device.dto.CommandType; | 12 | import com.zhonglai.luhui.device.dto.CommandType; |
| 12 | import com.zhonglai.luhui.device.dto.DeviceCommand; | 13 | import com.zhonglai.luhui.device.dto.DeviceCommand; |
| 14 | +import com.zhonglai.luhui.device.service.IIotDeviceService; | ||
| 13 | import com.zhonglai.luhui.rocketmq.service.RocketMqService; | 15 | import com.zhonglai.luhui.rocketmq.service.RocketMqService; |
| 14 | import io.swagger.annotations.Api; | 16 | import io.swagger.annotations.Api; |
| 15 | import io.swagger.annotations.ApiImplicitParam; | 17 | import io.swagger.annotations.ApiImplicitParam; |
| @@ -32,6 +34,9 @@ import java.io.IOException; | @@ -32,6 +34,9 @@ import java.io.IOException; | ||
| 32 | public class ControlDeviceConreoller extends BaseController { | 34 | public class ControlDeviceConreoller extends BaseController { |
| 33 | @Autowired | 35 | @Autowired |
| 34 | private RocketMqService rocketMqService; | 36 | private RocketMqService rocketMqService; |
| 37 | + | ||
| 38 | + @Autowired | ||
| 39 | + private IIotDeviceService iotDeviceService; | ||
| 35 | @ApiOperation(value = "写指令",notes = "body参数描述:\r\n" + | 40 | @ApiOperation(value = "写指令",notes = "body参数描述:\r\n" + |
| 36 | "{\n" + | 41 | "{\n" + |
| 37 | " \"0\":{\n" + | 42 | " \"0\":{\n" + |
| @@ -66,7 +71,46 @@ public class ControlDeviceConreoller extends BaseController { | @@ -66,7 +71,46 @@ public class ControlDeviceConreoller extends BaseController { | ||
| 66 | deviceCommand.setDeviceId(deviceId); | 71 | deviceCommand.setDeviceId(deviceId); |
| 67 | deviceCommand.setCommandType(CommandType.write); | 72 | deviceCommand.setCommandType(CommandType.write); |
| 68 | deviceCommand.setData(GsonConstructor.get().fromJson(body,JsonObject.class)); | 73 | deviceCommand.setData(GsonConstructor.get().fromJson(body,JsonObject.class)); |
| 69 | - return control(deviceCommand); | 74 | + |
| 75 | + return deviceControl(deviceCommand); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + @ApiOperation(value = "读指令",notes = "body参数描述:\r\n" + | ||
| 79 | + "{\n" + | ||
| 80 | + " \"0\":{\n" + | ||
| 81 | + " \"rssi\": -43,\n" + | ||
| 82 | + " \"firmware_version\": 1.2,\n" + | ||
| 83 | + " \"longitude\": 0,\n" + | ||
| 84 | + " \"latitude\": 0,\n" + | ||
| 85 | + " \"summary\": {\n" + | ||
| 86 | + " \t \"name\": \"wumei-smart\",\n" + | ||
| 87 | + " \t \"chip\": \"esp8266\",\n" + | ||
| 88 | + " \t \"author\": \"kerwincui\",\n" + | ||
| 89 | + " \t \"version\": 1.2,\n" + | ||
| 90 | + " \t \"createTime\": \"2022-06-06\"\n" + | ||
| 91 | + " }\n" + | ||
| 92 | + " },\n" + | ||
| 93 | + " \"1\":{\n" + | ||
| 94 | + " \"id1\":\"value1\",\n" + | ||
| 95 | + " \"id2\":\"value2\",\n" + | ||
| 96 | + " \"id3\":\"value3\"\n" + | ||
| 97 | + " }\n" + | ||
| 98 | + "}") | ||
| 99 | + @ApiImplicitParams({ | ||
| 100 | + @ApiImplicitParam(value = "网关id",name = "deviceId"), | ||
| 101 | + }) | ||
| 102 | + @PreAuthorize("@ss.hasPermi('iot:controlDevice:write')") | ||
| 103 | + @Log(title = "读指令", businessType = BusinessType.WRITE) | ||
| 104 | + @PostMapping("/read/{deviceId}") | ||
| 105 | + public AjaxResult read(@PathVariable String deviceId, HttpServletRequest request) throws IOException { | ||
| 106 | + | ||
| 107 | + byte[] bodyBytes = StreamUtils.copyToByteArray(request.getInputStream()); | ||
| 108 | + String body = new String(bodyBytes, request.getCharacterEncoding()); | ||
| 109 | + DeviceCommand deviceCommand = new DeviceCommand(); | ||
| 110 | + deviceCommand.setDeviceId(deviceId); | ||
| 111 | + deviceCommand.setCommandType(CommandType.write); | ||
| 112 | + deviceCommand.setData(GsonConstructor.get().fromJson(body,JsonObject.class)); | ||
| 113 | + return deviceControl(deviceCommand); | ||
| 70 | } | 114 | } |
| 71 | 115 | ||
| 72 | @ApiOperation("更新缓存模型") | 116 | @ApiOperation("更新缓存模型") |
| @@ -80,7 +124,7 @@ public class ControlDeviceConreoller extends BaseController { | @@ -80,7 +124,7 @@ public class ControlDeviceConreoller extends BaseController { | ||
| 80 | JsonObject jsonObject = new JsonObject(); | 124 | JsonObject jsonObject = new JsonObject(); |
| 81 | jsonObject.addProperty("product_id",product_id); | 125 | jsonObject.addProperty("product_id",product_id); |
| 82 | deviceCommand.setData(jsonObject); | 126 | deviceCommand.setData(jsonObject); |
| 83 | - return control(deviceCommand); | 127 | + return sysControl(deviceCommand); |
| 84 | } | 128 | } |
| 85 | 129 | ||
| 86 | @ApiOperation("更新缓存翻译模型") | 130 | @ApiOperation("更新缓存翻译模型") |
| @@ -94,7 +138,7 @@ public class ControlDeviceConreoller extends BaseController { | @@ -94,7 +138,7 @@ public class ControlDeviceConreoller extends BaseController { | ||
| 94 | JsonObject jsonObject = new JsonObject(); | 138 | JsonObject jsonObject = new JsonObject(); |
| 95 | jsonObject.addProperty("product_id",product_id); | 139 | jsonObject.addProperty("product_id",product_id); |
| 96 | deviceCommand.setData(jsonObject); | 140 | deviceCommand.setData(jsonObject); |
| 97 | - return control(deviceCommand); | 141 | + return sysControl(deviceCommand); |
| 98 | } | 142 | } |
| 99 | 143 | ||
| 100 | @ApiOperation("清除网关缓存") | 144 | @ApiOperation("清除网关缓存") |
| @@ -106,7 +150,7 @@ public class ControlDeviceConreoller extends BaseController { | @@ -106,7 +150,7 @@ public class ControlDeviceConreoller extends BaseController { | ||
| 106 | DeviceCommand deviceCommand = new DeviceCommand(); | 150 | DeviceCommand deviceCommand = new DeviceCommand(); |
| 107 | deviceCommand.setDeviceId(deviceId); | 151 | deviceCommand.setDeviceId(deviceId); |
| 108 | deviceCommand.setCommandType(CommandType.cleanDeviceHost); | 152 | deviceCommand.setCommandType(CommandType.cleanDeviceHost); |
| 109 | - return control(deviceCommand); | 153 | + return sysControl(deviceCommand); |
| 110 | } | 154 | } |
| 111 | 155 | ||
| 112 | @ApiOperation("更新终端缓存") | 156 | @ApiOperation("更新终端缓存") |
| @@ -124,7 +168,7 @@ public class ControlDeviceConreoller extends BaseController { | @@ -124,7 +168,7 @@ public class ControlDeviceConreoller extends BaseController { | ||
| 124 | JsonObject jsonObject = new JsonObject(); | 168 | JsonObject jsonObject = new JsonObject(); |
| 125 | jsonObject.addProperty("sensor_number",sensor_number); | 169 | jsonObject.addProperty("sensor_number",sensor_number); |
| 126 | deviceCommand.setData(jsonObject); | 170 | deviceCommand.setData(jsonObject); |
| 127 | - return control(deviceCommand); | 171 | + return sysControl(deviceCommand); |
| 128 | } | 172 | } |
| 129 | 173 | ||
| 130 | @ApiOperation("添加订阅") | 174 | @ApiOperation("添加订阅") |
| @@ -142,7 +186,7 @@ public class ControlDeviceConreoller extends BaseController { | @@ -142,7 +186,7 @@ public class ControlDeviceConreoller extends BaseController { | ||
| 142 | jsonObject.addProperty("product_ids",product_ids); | 186 | jsonObject.addProperty("product_ids",product_ids); |
| 143 | jsonObject.addProperty("ip",ip); | 187 | jsonObject.addProperty("ip",ip); |
| 144 | deviceCommand.setData(jsonObject); | 188 | deviceCommand.setData(jsonObject); |
| 145 | - return control(deviceCommand); | 189 | + return sysControl(deviceCommand); |
| 146 | } | 190 | } |
| 147 | 191 | ||
| 148 | @ApiOperation(value = "通知",notes = "body参数描述:\r\n" + | 192 | @ApiOperation(value = "通知",notes = "body参数描述:\r\n" + |
| @@ -166,12 +210,28 @@ public class ControlDeviceConreoller extends BaseController { | @@ -166,12 +210,28 @@ public class ControlDeviceConreoller extends BaseController { | ||
| 166 | deviceCommand.setDeviceId(deviceId); | 210 | deviceCommand.setDeviceId(deviceId); |
| 167 | deviceCommand.setCommandType(CommandType.notice); | 211 | deviceCommand.setCommandType(CommandType.notice); |
| 168 | deviceCommand.setData(GsonConstructor.get().fromJson(body,JsonObject.class)); | 212 | deviceCommand.setData(GsonConstructor.get().fromJson(body,JsonObject.class)); |
| 169 | - return control(deviceCommand); | 213 | + return deviceControl(deviceCommand); |
| 214 | + } | ||
| 215 | + | ||
| 216 | + private AjaxResult deviceControl(DeviceCommand deviceCommand) | ||
| 217 | + { | ||
| 218 | + IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(deviceCommand.getDeviceId()); | ||
| 219 | + if(null == iotDevice || iotDevice.getStatus()!=3) | ||
| 220 | + { | ||
| 221 | + return AjaxResult.error("设备不存在或者不在线"); | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + Message message = rocketMqService.send("deviceCommandListen",GsonConstructor.get().toJson(deviceCommand).getBytes(),iotDevice.getOperation_token()); | ||
| 225 | + if(message.getCode()==1) | ||
| 226 | + { | ||
| 227 | + return new AjaxResult(HttpStatus.SUCCESS, message.getMessage(), message.getData()); | ||
| 228 | + } | ||
| 229 | + return new AjaxResult(HttpStatus.ERROR, message.getMessage(), message.getData()); | ||
| 170 | } | 230 | } |
| 171 | 231 | ||
| 172 | - private AjaxResult control( DeviceCommand deviceCommand) | 232 | + private AjaxResult sysControl(DeviceCommand deviceCommand) |
| 173 | { | 233 | { |
| 174 | - Message message = rocketMqService.send("deviceCommandListen",GsonConstructor.get().toJson(deviceCommand).getBytes()); | 234 | + Message message = rocketMqService.send("deviceCommandListen",GsonConstructor.get().toJson(deviceCommand).getBytes(),"SysCommand"); |
| 175 | if(message.getCode()==1) | 235 | if(message.getCode()==1) |
| 176 | { | 236 | { |
| 177 | return new AjaxResult(HttpStatus.SUCCESS, message.getMessage(), message.getData()); | 237 | return new AjaxResult(HttpStatus.SUCCESS, message.getMessage(), message.getData()); |
| @@ -2,10 +2,13 @@ package com.zhonglai.luhui.admin.controller.iot; | @@ -2,10 +2,13 @@ package com.zhonglai.luhui.admin.controller.iot; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
| 5 | +import com.google.gson.JsonArray; | ||
| 6 | +import com.google.gson.JsonElement; | ||
| 5 | import com.ruoyi.common.annotation.Log; | 7 | import com.ruoyi.common.annotation.Log; |
| 6 | import com.ruoyi.common.core.domain.AjaxResult; | 8 | import com.ruoyi.common.core.domain.AjaxResult; |
| 7 | import com.ruoyi.common.core.page.TableDataInfo; | 9 | import com.ruoyi.common.core.page.TableDataInfo; |
| 8 | import com.ruoyi.common.enums.BusinessType; | 10 | import com.ruoyi.common.enums.BusinessType; |
| 11 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 9 | import com.ruoyi.common.utils.StringUtils; | 12 | import com.ruoyi.common.utils.StringUtils; |
| 10 | import com.zhonglai.luhui.admin.dto.*; | 13 | import com.zhonglai.luhui.admin.dto.*; |
| 11 | import com.zhonglai.luhui.action.BaseController; | 14 | import com.zhonglai.luhui.action.BaseController; |
| @@ -87,7 +90,7 @@ public class IotAlertController extends BaseController | @@ -87,7 +90,7 @@ public class IotAlertController extends BaseController | ||
| 87 | { | 90 | { |
| 88 | if (checkTriggers(alert)) | 91 | if (checkTriggers(alert)) |
| 89 | { | 92 | { |
| 90 | - return AjaxResult.error("触发器参数必填"); | 93 | + return AjaxResult.error("触发器参数校验失败"); |
| 91 | } | 94 | } |
| 92 | // if (checkActions(alert)) | 95 | // if (checkActions(alert)) |
| 93 | // { | 96 | // { |
| @@ -107,7 +110,7 @@ public class IotAlertController extends BaseController | @@ -107,7 +110,7 @@ public class IotAlertController extends BaseController | ||
| 107 | { | 110 | { |
| 108 | if (checkTriggers(alert)) | 111 | if (checkTriggers(alert)) |
| 109 | { | 112 | { |
| 110 | - return AjaxResult.error("触发器参数必填"); | 113 | + return AjaxResult.error("触发器参数校验失败"); |
| 111 | } | 114 | } |
| 112 | // if (checkActions(alert)) | 115 | // if (checkActions(alert)) |
| 113 | // { | 116 | // { |
| @@ -132,7 +135,7 @@ public class IotAlertController extends BaseController | @@ -132,7 +135,7 @@ public class IotAlertController extends BaseController | ||
| 132 | * 检验触发器 | 135 | * 检验触发器 |
| 133 | * @return | 136 | * @return |
| 134 | */ | 137 | */ |
| 135 | - private boolean checkTriggers(IotAlert alert) | 138 | + private static boolean checkTriggers(IotAlert alert) |
| 136 | { | 139 | { |
| 137 | String triggers = Optional.ofNullable(alert).orElse(new IotAlert()).getTriggers(); | 140 | String triggers = Optional.ofNullable(alert).orElse(new IotAlert()).getTriggers(); |
| 138 | if(StringUtils.isNotEmpty(triggers)) | 141 | if(StringUtils.isNotEmpty(triggers)) |
| @@ -143,8 +146,18 @@ public class IotAlertController extends BaseController | @@ -143,8 +146,18 @@ public class IotAlertController extends BaseController | ||
| 143 | AttributeTriggers attributeTriggers = JSONObject.parseObject(triggers, AttributeTriggers.class); | 146 | AttributeTriggers attributeTriggers = JSONObject.parseObject(triggers, AttributeTriggers.class); |
| 144 | return BeanUtil.hasNullField(attributeTriggers); | 147 | return BeanUtil.hasNullField(attributeTriggers); |
| 145 | case 2: | 148 | case 2: |
| 146 | - TriggerTriggers triggerTriggers = JSONObject.parseObject(triggers, TriggerTriggers.class); | 149 | + JsonElement jsonElement = GsonConstructor.get().fromJson(triggers, JsonElement.class); |
| 150 | + if(!jsonElement.isJsonArray()) | ||
| 151 | + { | ||
| 152 | + return false; | ||
| 153 | + } | ||
| 154 | + JsonArray jsonArray = jsonElement.getAsJsonArray(); | ||
| 155 | + for (int i=0;i<jsonArray.size();i++) | ||
| 156 | + { | ||
| 157 | + TriggerTriggers triggerTriggers = JSONObject.parseObject(jsonArray.get(i).toString(), TriggerTriggers.class); | ||
| 147 | return BeanUtil.hasNullField(triggerTriggers); | 158 | return BeanUtil.hasNullField(triggerTriggers); |
| 159 | + } | ||
| 160 | + | ||
| 148 | case 3: | 161 | case 3: |
| 149 | TimerTriggers timerTriggers = JSONObject.parseObject(triggers, TimerTriggers.class); | 162 | TimerTriggers timerTriggers = JSONObject.parseObject(triggers, TimerTriggers.class); |
| 150 | return BeanUtil.hasNullField(timerTriggers,"terminalids"); | 163 | return BeanUtil.hasNullField(timerTriggers,"terminalids"); |
| @@ -154,18 +167,6 @@ public class IotAlertController extends BaseController | @@ -154,18 +167,6 @@ public class IotAlertController extends BaseController | ||
| 154 | return false; | 167 | return false; |
| 155 | } | 168 | } |
| 156 | 169 | ||
| 157 | - public static void main(String[] args) { | ||
| 158 | - String triggers = "{\"model_name\":\"alarm\",\"valueMapName\":{{\"1\":\"传感器检测失败故障\"},{\"3\",\"超低氧告警\"}}}"; | ||
| 159 | - AttributeTriggers attributeTriggers = new AttributeTriggers(); | ||
| 160 | - attributeTriggers.setModel_name("alarm"); | ||
| 161 | - Map<Object,String> valueMapName = new HashMap<>(); | ||
| 162 | - valueMapName.put("1","传感器检测失败故障"); | ||
| 163 | - valueMapName.put("3","超低氧告警"); | ||
| 164 | - attributeTriggers.setValueMapName(valueMapName); | ||
| 165 | - System.out.println(triggers); | ||
| 166 | - System.out.println(JSONObject.toJSON(attributeTriggers)); | ||
| 167 | - } | ||
| 168 | - | ||
| 169 | /** | 170 | /** |
| 170 | * 检验执行动作 | 171 | * 检验执行动作 |
| 171 | * @return | 172 | * @return |
| 1 | +package com.zhonglai.luhui.admin.controller.iot; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.bean.BeanUtil; | ||
| 4 | +import com.alibaba.fastjson.JSONObject; | ||
| 5 | +import com.ruoyi.common.annotation.Log; | ||
| 6 | +import com.ruoyi.common.core.domain.AjaxResult; | ||
| 7 | +import com.ruoyi.common.core.page.TableDataInfo; | ||
| 8 | +import com.ruoyi.common.enums.BusinessType; | ||
| 9 | +import com.ruoyi.common.utils.StringUtils; | ||
| 10 | +import com.zhonglai.luhui.action.BaseController; | ||
| 11 | +import com.zhonglai.luhui.admin.dto.AttributeTriggers; | ||
| 12 | +import com.zhonglai.luhui.dao.service.PublicService; | ||
| 13 | +import com.zhonglai.luhui.device.domain.IotAlertLog; | ||
| 14 | +import com.zhonglai.luhui.device.domain.IotAlertNoticeChannel; | ||
| 15 | +import com.zhonglai.luhui.device.domain.IotPermission; | ||
| 16 | +import com.zhonglai.luhui.device.dto.WeiXinGongZhongHaoNoticeDto; | ||
| 17 | +import io.swagger.annotations.Api; | ||
| 18 | +import io.swagger.annotations.ApiOperation; | ||
| 19 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 20 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 21 | +import org.springframework.web.bind.annotation.*; | ||
| 22 | + | ||
| 23 | +import java.util.HashMap; | ||
| 24 | +import java.util.List; | ||
| 25 | +import java.util.Map; | ||
| 26 | + | ||
| 27 | +@Api(tags = "告警通知渠道") | ||
| 28 | +@RestController | ||
| 29 | +@RequestMapping("/iot/alertNoticeChannel") | ||
| 30 | +public class IotAlertNoticeChannelController extends BaseController { | ||
| 31 | + @Autowired | ||
| 32 | + private PublicService publicService; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 查询设备告警列表 | ||
| 36 | + */ | ||
| 37 | + @ApiOperation("查询告警通知渠道列表") | ||
| 38 | + @PreAuthorize("@ss.hasPermi('iot:alertNoticeChannel:list')") | ||
| 39 | + @GetMapping("/list") | ||
| 40 | + public TableDataInfo list(IotAlertNoticeChannel iotAlertNoticeChannel) | ||
| 41 | + { | ||
| 42 | + startPage(); | ||
| 43 | + Map<String, String> whereMap = new HashMap<>(); | ||
| 44 | + whereMap.put("name","like"); | ||
| 45 | + List<Map<String,Object>> list = publicService.getObjectList(iotAlertNoticeChannel,"*",whereMap,"id desc",0,0); | ||
| 46 | + return getDataTable(list); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + @ApiOperation("新增告警通知渠道") | ||
| 50 | + @PreAuthorize("@ss.hasPermi('iot:alertNoticeChannel:add')") | ||
| 51 | + @Log(title = "新增告警通知渠道", businessType = BusinessType.INSERT) | ||
| 52 | + @PostMapping | ||
| 53 | + public AjaxResult add(@RequestBody IotAlertNoticeChannel iotAlertNoticeChannel) | ||
| 54 | + { | ||
| 55 | + if (StringUtils.isEmpty(iotAlertNoticeChannel.getConfig())) | ||
| 56 | + { | ||
| 57 | + return AjaxResult.error("请输入渠道配置"); | ||
| 58 | + } | ||
| 59 | + switch (iotAlertNoticeChannel.getType()) | ||
| 60 | + { | ||
| 61 | + case 1: | ||
| 62 | + WeiXinGongZhongHaoNoticeDto weiXinGongZhongHaoNoticeDto = JSONObject.parseObject(iotAlertNoticeChannel.getConfig(), WeiXinGongZhongHaoNoticeDto.class); | ||
| 63 | + if(BeanUtil.isNotEmpty(weiXinGongZhongHaoNoticeDto)) | ||
| 64 | + { | ||
| 65 | + return AjaxResult.error("渠道配置填写错误"); | ||
| 66 | + } | ||
| 67 | + break; | ||
| 68 | + } | ||
| 69 | + return toAjax(publicService.insert(iotAlertNoticeChannel)); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + @ApiOperation("修改告警通知渠道") | ||
| 73 | + @PreAuthorize("@ss.hasPermi('iot:alertNoticeChannel:edit')") | ||
| 74 | + @Log(title = "topic权限控制", businessType = BusinessType.UPDATE) | ||
| 75 | + @PutMapping | ||
| 76 | + public AjaxResult edit(@RequestBody IotAlertNoticeChannel iotAlertNoticeChannel) | ||
| 77 | + { | ||
| 78 | + return toAjax(publicService.updateObject(iotAlertNoticeChannel,"id")); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + @ApiOperation("删除告警通知渠道") | ||
| 82 | + @PreAuthorize("@ss.hasPermi('iot:IotPermission:remove')") | ||
| 83 | + @Log(title = "topic权限控制", businessType = BusinessType.DELETE) | ||
| 84 | + @DeleteMapping("/{ids}") | ||
| 85 | + public AjaxResult remove(@PathVariable Integer[] ids) | ||
| 86 | + { | ||
| 87 | + Long ct = publicService.selectCountBySql("SELECT COUNT(*) ct FROM iot_alert_user_notice WHERE CONCAT(',', channels, ',') LIKE '%,1,%'"); | ||
| 88 | + if(ct>0) | ||
| 89 | + { | ||
| 90 | + return AjaxResult.error("该告警通知渠道有用户告警通知配置使用,请先删除用户告警通知配置再删除此通道"); | ||
| 91 | + } | ||
| 92 | + int i=0; | ||
| 93 | + for (Integer id:ids) | ||
| 94 | + { | ||
| 95 | + i+=publicService.deleteObjectById(IotAlertNoticeChannel.class,id+""); | ||
| 96 | + } | ||
| 97 | + return toAjax(i); | ||
| 98 | + } | ||
| 99 | +} |
| @@ -37,6 +37,10 @@ | @@ -37,6 +37,10 @@ | ||
| 37 | <groupId>org.quartz-scheduler</groupId> | 37 | <groupId>org.quartz-scheduler</groupId> |
| 38 | <artifactId>quartz</artifactId> | 38 | <artifactId>quartz</artifactId> |
| 39 | </dependency> | 39 | </dependency> |
| 40 | + <dependency> | ||
| 41 | + <groupId>com.zhonglai</groupId> | ||
| 42 | + <artifactId>weixin-api</artifactId> | ||
| 43 | + </dependency> | ||
| 40 | </dependencies> | 44 | </dependencies> |
| 41 | 45 | ||
| 42 | <build> | 46 | <build> |
| @@ -62,7 +66,7 @@ | @@ -62,7 +66,7 @@ | ||
| 62 | 生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/ | 66 | 生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/ |
| 63 | --> | 67 | --> |
| 64 | <classpathPrefix>lib/</classpathPrefix> | 68 | <classpathPrefix>lib/</classpathPrefix> |
| 65 | - <mainClass>com.zhonglai.luhui.alarm.AlarmApplication</mainClass> | 69 | + <mainClass>com.zhonglai.luhui.alarm.LhAlarmMain</mainClass> |
| 66 | </manifest> | 70 | </manifest> |
| 67 | </archive> | 71 | </archive> |
| 68 | </configuration> | 72 | </configuration> |
| @@ -3,6 +3,7 @@ package com.zhonglai.luhui.alarm; | @@ -3,6 +3,7 @@ package com.zhonglai.luhui.alarm; | ||
| 3 | 3 | ||
| 4 | import com.zhonglai.luhui.alarm.config.CachAlarmConfig; | 4 | import com.zhonglai.luhui.alarm.config.CachAlarmConfig; |
| 5 | import com.zhonglai.luhui.alarm.handle.CleanupTask; | 5 | import com.zhonglai.luhui.alarm.handle.CleanupTask; |
| 6 | +import com.zhonglai.luhui.alarm.service.SendAlarmService; | ||
| 6 | import com.zhonglai.luhui.alarm.service.TimerAlarmService; | 7 | import com.zhonglai.luhui.alarm.service.TimerAlarmService; |
| 7 | import com.zhonglai.luhui.alarm.service.TriggerAlarmService; | 8 | import com.zhonglai.luhui.alarm.service.TriggerAlarmService; |
| 8 | 9 | ||
| @@ -18,6 +19,7 @@ public class LhAlarmMain { | @@ -18,6 +19,7 @@ public class LhAlarmMain { | ||
| 18 | //启动定时任务告警 | 19 | //启动定时任务告警 |
| 19 | TimerAlarmService.start(); | 20 | TimerAlarmService.start(); |
| 20 | 21 | ||
| 21 | - | 22 | + //启动告警定时发送 |
| 23 | + SendAlarmService.start(); | ||
| 22 | } | 24 | } |
| 23 | } | 25 | } |
| @@ -34,7 +34,8 @@ public class IotAlertAlarm extends UpAlarmFactory<IotAlert> implements Serializa | @@ -34,7 +34,8 @@ public class IotAlertAlarm extends UpAlarmFactory<IotAlert> implements Serializa | ||
| 34 | 34 | ||
| 35 | @Override | 35 | @Override |
| 36 | void updateGenerateAlarm() { | 36 | void updateGenerateAlarm() { |
| 37 | - switch (afterupAlarmDb.getAlertType()) | 37 | + int alertType = null==afterupAlarmDb.getAlertType()?beforeupAlarmDb.getAlertType():afterupAlarmDb.getAlertType(); |
| 38 | + switch (alertType) | ||
| 38 | { | 39 | { |
| 39 | case 1: | 40 | case 1: |
| 40 | CachAlarmConfig.addAttributeAlarmRoute(afterupAlarmDb); | 41 | CachAlarmConfig.addAttributeAlarmRoute(afterupAlarmDb); |
| @@ -41,7 +41,7 @@ public class IotDeviceAlarm extends UpAlarmFactory<IotDevice> implements Seriali | @@ -41,7 +41,7 @@ public class IotDeviceAlarm extends UpAlarmFactory<IotDevice> implements Seriali | ||
| 41 | CachAlarmConfig.putDeviceProduct(afterupAlarmDb.getClient_id(), afterupAlarmDb.getProduct_id()); | 41 | CachAlarmConfig.putDeviceProduct(afterupAlarmDb.getClient_id(), afterupAlarmDb.getProduct_id()); |
| 42 | } | 42 | } |
| 43 | //通过变更的数据获得对应的告警规则 | 43 | //通过变更的数据获得对应的告警规则 |
| 44 | - valueUp(beforeupAlarmDb.getClient_id(),CachAlarmConfig.getDeviceProduct(beforeupAlarmDb.getClient_id()),beforeupAlarmDb.getThings_model_value(),afterupAlarmDb.getThings_model_value()); | 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 | } | 46 | } |
| 47 | Object getNowValue(Object model_name,Integer type) { | 47 | Object getNowValue(Object model_name,Integer type) { |
| @@ -38,7 +38,7 @@ public class IotTerminalAlarm extends UpAlarmFactory<IotTerminal> implements Ser | @@ -38,7 +38,7 @@ public class IotTerminalAlarm extends UpAlarmFactory<IotTerminal> implements Ser | ||
| 38 | @Override | 38 | @Override |
| 39 | public void updateGenerateAlarm() { | 39 | public void updateGenerateAlarm() { |
| 40 | //通过变更的数据获得对应的告警规则 | 40 | //通过变更的数据获得对应的告警规则 |
| 41 | - valueUp(beforeupAlarmDb.getId(), CachAlarmConfig.getDeviceProduct(beforeupAlarmDb.getId()),beforeupAlarmDb.getThings_model_value(),afterupAlarmDb.getThings_model_value()); | 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 | 42 | ||
| 43 | } | 43 | } |
| 44 | 44 |
| 1 | package com.zhonglai.luhui.alarm.clas; | 1 | package com.zhonglai.luhui.alarm.clas; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
| 4 | +import com.alibaba.fastjson.JSONException; | ||
| 4 | import com.alibaba.fastjson.JSONObject; | 5 | import com.alibaba.fastjson.JSONObject; |
| 5 | import com.alibaba.otter.canal.protocol.CanalEntry; | 6 | import com.alibaba.otter.canal.protocol.CanalEntry; |
| 6 | import com.zhonglai.luhui.alarm.config.CachAlarmConfig; | 7 | import com.zhonglai.luhui.alarm.config.CachAlarmConfig; |
| 7 | import com.zhonglai.luhui.alarm.dto.*; | 8 | import com.zhonglai.luhui.alarm.dto.*; |
| 9 | +import com.zhonglai.luhui.alarm.service.TriggerAlarmService; | ||
| 8 | import com.zhonglai.luhui.alarm.util.GenericComparator; | 10 | import com.zhonglai.luhui.alarm.util.GenericComparator; |
| 9 | import com.zhonglai.luhui.service.dao.util.StringUtils; | 11 | import com.zhonglai.luhui.service.dao.util.StringUtils; |
| 12 | +import org.slf4j.Logger; | ||
| 13 | +import org.slf4j.LoggerFactory; | ||
| 10 | 14 | ||
| 11 | import java.util.ArrayList; | 15 | import java.util.ArrayList; |
| 12 | import java.util.List; | 16 | import java.util.List; |
| @@ -15,7 +19,7 @@ import java.util.List; | @@ -15,7 +19,7 @@ import java.util.List; | ||
| 15 | * 告警工厂 | 19 | * 告警工厂 |
| 16 | */ | 20 | */ |
| 17 | public abstract class UpAlarmFactory<T> { | 21 | public abstract class UpAlarmFactory<T> { |
| 18 | - | 22 | + private static final Logger logger = LoggerFactory.getLogger(UpAlarmFactory.class); |
| 19 | protected List<IotAlertLog> list = new ArrayList<>(); | 23 | protected List<IotAlertLog> list = new ArrayList<>(); |
| 20 | 24 | ||
| 21 | protected T beforeupAlarmDb; | 25 | protected T beforeupAlarmDb; |
| @@ -69,7 +73,7 @@ public abstract class UpAlarmFactory<T> { | @@ -69,7 +73,7 @@ public abstract class UpAlarmFactory<T> { | ||
| 69 | } | 73 | } |
| 70 | 74 | ||
| 71 | 75 | ||
| 72 | - protected void valueUp(String client_id,Integer product_id,String oldvalue,String newValue) | 76 | + protected void valueUp(String client_id,Integer product_id,String oldvalue,String newValue,Integer user_id,String device_name) |
| 73 | { | 77 | { |
| 74 | if(StringUtils.isNotEmpty(newValue)) | 78 | if(StringUtils.isNotEmpty(newValue)) |
| 75 | { | 79 | { |
| @@ -81,50 +85,71 @@ public abstract class UpAlarmFactory<T> { | @@ -81,50 +85,71 @@ public abstract class UpAlarmFactory<T> { | ||
| 81 | } | 85 | } |
| 82 | for (String key:newjson.keySet()) | 86 | for (String key:newjson.keySet()) |
| 83 | { | 87 | { |
| 84 | - if(!newjson.get(key).equals(oldjson.get(key))) //新老不一致,触发告警 | 88 | + Object nv ; |
| 89 | + Object ov ; | ||
| 90 | + try { | ||
| 91 | + JSONObject newObject = newjson.getJSONObject(key); | ||
| 92 | + String type = newObject.getString("type"); | ||
| 93 | + nv = GenericComparator.convertToType(newObject.getString("saveView"),type); | ||
| 94 | + ov = GenericComparator.convertToType(oldjson.getJSONObject(key).getString("saveView"),type); | ||
| 95 | + }catch (JSONException e ) //如果不是json,就按照字符串来对比 | ||
| 96 | + { | ||
| 97 | + nv = newjson.get(key); | ||
| 98 | + ov = oldjson.get(key); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + if(!nv.equals(ov)) //新老不一致,触发告警 | ||
| 85 | { | 102 | { |
| 86 | //属性告警 | 103 | //属性告警 |
| 87 | List<IotAlert> listAttribute = CachAlarmConfig.getAttributeIotAlert(product_id,key); | 104 | List<IotAlert> listAttribute = CachAlarmConfig.getAttributeIotAlert(product_id,key); |
| 88 | if (null != listAttribute && listAttribute.size() != 0) | 105 | if (null != listAttribute && listAttribute.size() != 0) |
| 89 | { | 106 | { |
| 90 | - alarmAttribute(client_id,listAttribute,oldjson.get(key)); | 107 | + alarmAttribute(client_id,listAttribute,nv,user_id,device_name); |
| 91 | } | 108 | } |
| 92 | //触发告警 | 109 | //触发告警 |
| 93 | List<IotAlert> listTrigger = CachAlarmConfig.getTriggerIotAlert(product_id,key); | 110 | List<IotAlert> listTrigger = CachAlarmConfig.getTriggerIotAlert(product_id,key); |
| 94 | if (null != listTrigger && listTrigger.size() != 0) | 111 | if (null != listTrigger && listTrigger.size() != 0) |
| 95 | { | 112 | { |
| 96 | - alarmTrigger(client_id,listTrigger,oldjson.get(key)); | 113 | + alarmTrigger(client_id,listTrigger,nv,user_id,device_name); |
| 97 | } | 114 | } |
| 98 | } | 115 | } |
| 99 | } | 116 | } |
| 100 | } | 117 | } |
| 101 | } | 118 | } |
| 102 | 119 | ||
| 103 | - protected void alarmAttribute(String client_id,List<IotAlert> listAttribute,Object newValue) | 120 | + protected void alarmAttribute(String client_id,List<IotAlert> listAttribute,Object newValue,Integer user_id,String device_name) |
| 104 | { | 121 | { |
| 105 | for (IotAlert iotAlert:listAttribute) | 122 | for (IotAlert iotAlert:listAttribute) |
| 106 | { | 123 | { |
| 124 | + if(null != user_id && null != iotAlert.getUser_id() && user_id - iotAlert.getUser_id()!=0) //不是指定用户的设备就不需要生产 | ||
| 125 | + { | ||
| 126 | + continue; | ||
| 127 | + } | ||
| 107 | AttributeTriggers attributeTriggers = JSONObject.parseObject(iotAlert.getTriggers(),AttributeTriggers.class); | 128 | AttributeTriggers attributeTriggers = JSONObject.parseObject(iotAlert.getTriggers(),AttributeTriggers.class); |
| 108 | String alrmname = attributeTriggers.getValueMapName().get(newValue); | 129 | String alrmname = attributeTriggers.getValueMapName().get(newValue); |
| 109 | if(StringUtils.isNotEmpty(alrmname)) | 130 | if(StringUtils.isNotEmpty(alrmname)) |
| 110 | { | 131 | { |
| 111 | - IotAlertLog iotAlertLog = new IotAlertLog(iotAlert.getAlertId(),alrmname,iotAlert.getAlertLevel().intValue(),2,client_id,System.currentTimeMillis(),1,iotAlert.getCreateBy()); | 132 | + IotAlertLog iotAlertLog = new IotAlertLog(iotAlert.getAlertId(),alrmname,iotAlert.getAlertLevel().intValue(),2,client_id,System.currentTimeMillis(),1,iotAlert.getUser_id() ,device_name,null==iotAlert.getUser_id()?1:2); |
| 112 | list.add(iotAlertLog); | 133 | list.add(iotAlertLog); |
| 113 | } | 134 | } |
| 114 | } | 135 | } |
| 115 | } | 136 | } |
| 116 | 137 | ||
| 117 | - protected void alarmTrigger(String client_id,List<IotAlert> listAttribute,Object newValue) | 138 | + protected void alarmTrigger(String client_id,List<IotAlert> listAttribute,Object newValue,Integer user_id,String device_name) |
| 118 | { | 139 | { |
| 119 | 140 | ||
| 120 | for (IotAlert iotAlert:listAttribute) | 141 | for (IotAlert iotAlert:listAttribute) |
| 121 | { | 142 | { |
| 143 | + if(null != user_id && null != iotAlert.getUser_id() && user_id - iotAlert.getUser_id()!=0) //不是指定用户的设备就不需要生产 | ||
| 144 | + { | ||
| 145 | + continue; | ||
| 146 | + } | ||
| 122 | List<TriggerTriggers> attributeTriggersList = JSON.parseArray(iotAlert.getTriggers(),TriggerTriggers.class); | 147 | List<TriggerTriggers> attributeTriggersList = JSON.parseArray(iotAlert.getTriggers(),TriggerTriggers.class); |
| 123 | - alarmTriggerTriggers(attributeTriggersList,newValue,iotAlert.getAlertId(),iotAlert.getAlertName(),iotAlert.getAlertLevel().intValue(),client_id,iotAlert.getCreateBy()); | 148 | + alarmTriggerTriggers(attributeTriggersList,newValue,iotAlert.getAlertId(),iotAlert.getAlertName(),iotAlert.getAlertLevel().intValue(),client_id,iotAlert.getUser_id(),device_name); |
| 124 | } | 149 | } |
| 125 | } | 150 | } |
| 126 | 151 | ||
| 127 | - public void alarmTriggerTriggers( List<TriggerTriggers> attributeTriggersList,Object newValue,Long alert_id, String alert_name, Integer alert_level, String device_id,String userId) | 152 | + public void alarmTriggerTriggers( List<TriggerTriggers> attributeTriggersList,Object newValue,Long alert_id, String alert_name, Integer alert_level, String device_id,Integer userId,String device_name ) |
| 128 | { | 153 | { |
| 129 | if(null != attributeTriggersList && attributeTriggersList.size() != 0) | 154 | if(null != attributeTriggersList && attributeTriggersList.size() != 0) |
| 130 | { | 155 | { |
| @@ -163,7 +188,7 @@ public abstract class UpAlarmFactory<T> { | @@ -163,7 +188,7 @@ public abstract class UpAlarmFactory<T> { | ||
| 163 | 188 | ||
| 164 | if(jieguo) | 189 | if(jieguo) |
| 165 | { | 190 | { |
| 166 | - IotAlertLog iotAlertLog = new IotAlertLog(alert_id,alert_name,alert_level,2,device_id,System.currentTimeMillis(),1,userId); | 191 | + IotAlertLog iotAlertLog = new IotAlertLog(alert_id,alert_name,alert_level,2,device_id,System.currentTimeMillis(),1,userId,device_name,null==userId?1:2); |
| 167 | list.add(iotAlertLog); | 192 | list.add(iotAlertLog); |
| 168 | } | 193 | } |
| 169 | } | 194 | } |
| @@ -171,7 +196,7 @@ public abstract class UpAlarmFactory<T> { | @@ -171,7 +196,7 @@ public abstract class UpAlarmFactory<T> { | ||
| 171 | 196 | ||
| 172 | protected Object getValueFromJSON(String key,JSONObject jsonObject) | 197 | protected Object getValueFromJSON(String key,JSONObject jsonObject) |
| 173 | { | 198 | { |
| 174 | - if(null != jsonObject && jsonObject.containsKey(jsonObject)) | 199 | + if(null != jsonObject && jsonObject.containsKey(key)) |
| 175 | { | 200 | { |
| 176 | return jsonObject.getJSONObject(key).get("value"); | 201 | return jsonObject.getJSONObject(key).get("value"); |
| 177 | } | 202 | } |
| @@ -3,23 +3,14 @@ package com.zhonglai.luhui.alarm.config; | @@ -3,23 +3,14 @@ package com.zhonglai.luhui.alarm.config; | ||
| 3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
| 4 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
| 5 | import com.zhonglai.luhui.alarm.dao.DbOperateUtil; | 5 | import com.zhonglai.luhui.alarm.dao.DbOperateUtil; |
| 6 | -import com.zhonglai.luhui.alarm.dto.AttributeTriggers; | ||
| 7 | -import com.zhonglai.luhui.alarm.dto.IotAlert; | ||
| 8 | -import com.zhonglai.luhui.alarm.dto.TimerTriggers; | ||
| 9 | -import com.zhonglai.luhui.alarm.dto.TriggerTriggers; | ||
| 10 | -import com.zhonglai.luhui.alarm.handle.TimerAlarmJob; | 6 | +import com.zhonglai.luhui.alarm.dto.*; |
| 11 | import com.zhonglai.luhui.alarm.service.TimerAlarmService; | 7 | import com.zhonglai.luhui.alarm.service.TimerAlarmService; |
| 12 | import com.zhonglai.luhui.service.dao.util.StringUtils; | 8 | import com.zhonglai.luhui.service.dao.util.StringUtils; |
| 13 | -import org.quartz.*; | ||
| 14 | -import org.quartz.impl.StdSchedulerFactory; | ||
| 15 | import org.slf4j.Logger; | 9 | import org.slf4j.Logger; |
| 16 | import org.slf4j.LoggerFactory; | 10 | import org.slf4j.LoggerFactory; |
| 17 | 11 | ||
| 18 | import java.sql.SQLException; | 12 | import java.sql.SQLException; |
| 19 | -import java.util.ArrayList; | ||
| 20 | -import java.util.HashMap; | ||
| 21 | -import java.util.List; | ||
| 22 | -import java.util.Map; | 13 | +import java.util.*; |
| 23 | 14 | ||
| 24 | /** | 15 | /** |
| 25 | * 缓存的告警配置 | 16 | * 缓存的告警配置 |
| @@ -41,6 +32,15 @@ public class CachAlarmConfig { | @@ -41,6 +32,15 @@ public class CachAlarmConfig { | ||
| 41 | private static Map<String, Integer> device_product = new HashMap<>(); | 32 | private static Map<String, Integer> device_product = new HashMap<>(); |
| 42 | 33 | ||
| 43 | 34 | ||
| 35 | + /** 用户告警通知配置 */ | ||
| 36 | + private static Map<String, IotAlertUserNotice> user_alarm_config = new HashMap<>(); | ||
| 37 | + | ||
| 38 | + /** 用户告警通知渠道 */ | ||
| 39 | + private static Map<Integer, IotAlertNoticeChannel> user_alarm_notice_channel = new HashMap<>(); | ||
| 40 | + | ||
| 41 | + /** 用户微信小程序关系 */ | ||
| 42 | + private static Map<Integer, Map<Integer, Set<String>>> xcx_user_openid = new HashMap<>(); | ||
| 43 | + | ||
| 44 | public static void loadConfig() | 44 | public static void loadConfig() |
| 45 | { | 45 | { |
| 46 | //加载属性告警配置 | 46 | //加载属性告警配置 |
| @@ -54,6 +54,15 @@ public class CachAlarmConfig { | @@ -54,6 +54,15 @@ public class CachAlarmConfig { | ||
| 54 | 54 | ||
| 55 | //加载用户告警配置 | 55 | //加载用户告警配置 |
| 56 | loadUserAlarmConfig(); | 56 | loadUserAlarmConfig(); |
| 57 | + | ||
| 58 | + //加载用户告警通知配置 | ||
| 59 | + loadUserAlarmNoticeConfig(); | ||
| 60 | + | ||
| 61 | + //加载用户告警通知渠道 | ||
| 62 | + loadUserAlarmNoticeChannel(); | ||
| 63 | + | ||
| 64 | + //加载用户微信小程序关系 | ||
| 65 | + loadXcxUserOpenid(); | ||
| 57 | } | 66 | } |
| 58 | 67 | ||
| 59 | /** | 68 | /** |
| @@ -66,6 +75,7 @@ public class CachAlarmConfig { | @@ -66,6 +75,7 @@ public class CachAlarmConfig { | ||
| 66 | { | 75 | { |
| 67 | for (IotAlert iotAlert:list) | 76 | for (IotAlert iotAlert:list) |
| 68 | { | 77 | { |
| 78 | + iotAlert.setCreateBy(null); | ||
| 69 | addAttributeAlarmRoute(iotAlert); | 79 | addAttributeAlarmRoute(iotAlert); |
| 70 | } | 80 | } |
| 71 | } | 81 | } |
| @@ -83,6 +93,7 @@ public class CachAlarmConfig { | @@ -83,6 +93,7 @@ public class CachAlarmConfig { | ||
| 83 | { | 93 | { |
| 84 | for (IotAlert iotAlert:list) | 94 | for (IotAlert iotAlert:list) |
| 85 | { | 95 | { |
| 96 | + iotAlert.setCreateBy(null); | ||
| 86 | addTriggerAlarmRoute(iotAlert); | 97 | addTriggerAlarmRoute(iotAlert); |
| 87 | } | 98 | } |
| 88 | } | 99 | } |
| @@ -98,6 +109,7 @@ public class CachAlarmConfig { | @@ -98,6 +109,7 @@ public class CachAlarmConfig { | ||
| 98 | { | 109 | { |
| 99 | for (IotAlert iotAlert:list) | 110 | for (IotAlert iotAlert:list) |
| 100 | { | 111 | { |
| 112 | + iotAlert.setCreateBy(null); | ||
| 101 | TimerAlarmService.addTimerAlarm(iotAlert); | 113 | TimerAlarmService.addTimerAlarm(iotAlert); |
| 102 | } | 114 | } |
| 103 | } | 115 | } |
| @@ -134,6 +146,63 @@ public class CachAlarmConfig { | @@ -134,6 +146,63 @@ public class CachAlarmConfig { | ||
| 134 | } | 146 | } |
| 135 | } | 147 | } |
| 136 | 148 | ||
| 149 | + /** | ||
| 150 | + * 加载用户告警通知配置 | ||
| 151 | + */ | ||
| 152 | + private static void loadUserAlarmNoticeConfig() | ||
| 153 | + { | ||
| 154 | + List<IotAlertUserNotice> list = DbOperateUtil.getAlertUserNoticeList(); | ||
| 155 | + if(null != list && list.size() != 0) | ||
| 156 | + { | ||
| 157 | + for (IotAlertUserNotice iotAlertUserNotice:list) | ||
| 158 | + { | ||
| 159 | + user_alarm_config.put(iotAlertUserNotice.getUser_id()+"|"+iotAlertUserNotice.getType(),iotAlertUserNotice); | ||
| 160 | + } | ||
| 161 | + } | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + /** | ||
| 165 | + * 加载用户告警通知渠道 | ||
| 166 | + */ | ||
| 167 | + private static void loadUserAlarmNoticeChannel() | ||
| 168 | + { | ||
| 169 | + List<IotAlertNoticeChannel> list = DbOperateUtil.getAlertNoticeChannelList(); | ||
| 170 | + if(null != list && list.size() != 0) | ||
| 171 | + { | ||
| 172 | + for (IotAlertNoticeChannel iotAlertNoticeChannel:list) | ||
| 173 | + { | ||
| 174 | + user_alarm_notice_channel.put(iotAlertNoticeChannel.getId(),iotAlertNoticeChannel); | ||
| 175 | + } | ||
| 176 | + } | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + /** | ||
| 180 | + * 加载用户微信小程序关系 | ||
| 181 | + */ | ||
| 182 | + private static void loadXcxUserOpenid() | ||
| 183 | + { | ||
| 184 | + List<UserOpenid> list = DbOperateUtil.getUserOpenidList(); | ||
| 185 | + if(null != list && list.size() != 0) | ||
| 186 | + { | ||
| 187 | + for (UserOpenid userOpenid:list) | ||
| 188 | + { | ||
| 189 | + Map<Integer, Set<String>> mapset = xcx_user_openid.get(userOpenid.getXcx_config_id()); | ||
| 190 | + if(null == mapset) | ||
| 191 | + { | ||
| 192 | + mapset = new HashMap<>(); | ||
| 193 | + xcx_user_openid.put(userOpenid.getXcx_config_id(),mapset); | ||
| 194 | + } | ||
| 195 | + Set<String> set = mapset.get(userOpenid.getUser_id()); | ||
| 196 | + if(null == set) | ||
| 197 | + { | ||
| 198 | + set = new HashSet<>(); | ||
| 199 | + mapset.put(userOpenid.getUser_id(),set); | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + set.add(userOpenid.getOpenid()); | ||
| 203 | + } | ||
| 204 | + } | ||
| 205 | + } | ||
| 137 | 206 | ||
| 138 | /** | 207 | /** |
| 139 | * 添加属性告警路由 | 208 | * 添加属性告警路由 |
| @@ -320,4 +389,47 @@ public class CachAlarmConfig { | @@ -320,4 +389,47 @@ public class CachAlarmConfig { | ||
| 320 | { | 389 | { |
| 321 | alarmConfig.put(iotAlert.getAlertId(),iotAlert); | 390 | alarmConfig.put(iotAlert.getAlertId(),iotAlert); |
| 322 | } | 391 | } |
| 392 | + | ||
| 393 | + public static List<UserAlarmNoticeConfig> getUserAlarmNoticeConfig(Integer user_id,Integer getAlert_config_type,Long alert_id) | ||
| 394 | + { | ||
| 395 | + IotAlertUserNotice iotAlertUserNotice = user_alarm_config.get(user_id+"|"+getAlert_config_type); | ||
| 396 | + if(null != iotAlertUserNotice && "*".equals(iotAlertUserNotice.getAlert_ids()) || (","+iotAlertUserNotice.getAlert_ids()+",").indexOf(","+alert_id+",")>=0) //*或者包含 | ||
| 397 | + { | ||
| 398 | + return channelIdsToUserAlarmNoticeConfig(iotAlertUserNotice.getChannels()); | ||
| 399 | + } | ||
| 400 | + return null; | ||
| 401 | + } | ||
| 402 | + | ||
| 403 | + private static List<UserAlarmNoticeConfig> channelIdsToUserAlarmNoticeConfig(String iot_alert_notice_channel_ids) | ||
| 404 | + { | ||
| 405 | + if(StringUtils.isNotEmpty(iot_alert_notice_channel_ids)) | ||
| 406 | + { | ||
| 407 | + List<UserAlarmNoticeConfig> list = new ArrayList<>(); | ||
| 408 | + | ||
| 409 | + String[] ids = iot_alert_notice_channel_ids.split(","); | ||
| 410 | + for (String id:ids) | ||
| 411 | + { | ||
| 412 | + Integer iid = Integer.parseInt(id); | ||
| 413 | + IotAlertNoticeChannel iotAlertNoticeChannel = user_alarm_notice_channel.get(iid); | ||
| 414 | + if(null != iotAlertNoticeChannel ) | ||
| 415 | + { | ||
| 416 | + UserAlarmNoticeConfig userAlarmNoticeConfig = new UserAlarmNoticeConfig(); | ||
| 417 | + userAlarmNoticeConfig.setFromConfig(iotAlertNoticeChannel.getConfig()); | ||
| 418 | + userAlarmNoticeConfig.setChannelType(iotAlertNoticeChannel.getType()); | ||
| 419 | + list.add(userAlarmNoticeConfig); | ||
| 420 | + } | ||
| 421 | + } | ||
| 422 | + return list; | ||
| 423 | + } | ||
| 424 | + return null; | ||
| 425 | + } | ||
| 426 | + | ||
| 427 | + public static Set<String> getUserXcxOpenid(Integer userId,Integer xcxConfigId) | ||
| 428 | + { | ||
| 429 | + if(xcx_user_openid.containsKey(xcxConfigId) && xcx_user_openid.get(xcxConfigId).containsKey(userId) ) | ||
| 430 | + { | ||
| 431 | + return xcx_user_openid.get(xcxConfigId).get(userId); | ||
| 432 | + } | ||
| 433 | + return null; | ||
| 434 | + } | ||
| 323 | } | 435 | } |
| 1 | package com.zhonglai.luhui.alarm.dao; | 1 | package com.zhonglai.luhui.alarm.dao; |
| 2 | 2 | ||
| 3 | -import com.zhonglai.luhui.alarm.dto.IotAlert; | ||
| 4 | -import com.zhonglai.luhui.alarm.dto.IotAlertLog; | ||
| 5 | -import com.zhonglai.luhui.alarm.dto.IotTerminal; | 3 | +import com.zhonglai.luhui.alarm.dto.*; |
| 6 | import com.zhonglai.luhui.service.dao.BaseDao; | 4 | import com.zhonglai.luhui.service.dao.BaseDao; |
| 7 | import com.zhonglai.luhui.service.dao.util.StringUtils; | 5 | import com.zhonglai.luhui.service.dao.util.StringUtils; |
| 8 | import org.apache.commons.dbutils.handlers.ScalarHandler; | 6 | import org.apache.commons.dbutils.handlers.ScalarHandler; |
| 9 | 7 | ||
| 10 | import java.sql.SQLException; | 8 | import java.sql.SQLException; |
| 11 | import java.util.List; | 9 | import java.util.List; |
| 10 | +import java.util.stream.Collectors; | ||
| 12 | 11 | ||
| 13 | public class DbOperateUtil { | 12 | public class DbOperateUtil { |
| 14 | private static BaseDao baseDao = new BaseDao(); | 13 | private static BaseDao baseDao = new BaseDao(); |
| @@ -36,13 +35,19 @@ public class DbOperateUtil { | @@ -36,13 +35,19 @@ public class DbOperateUtil { | ||
| 36 | return baseDao.insertList(list,null); | 35 | return baseDao.insertList(list,null); |
| 37 | } | 36 | } |
| 38 | 37 | ||
| 39 | - public static List<IotTerminal> getTimerAlarmIotTerminal(Long productId,String terminalids) | 38 | + public static List<IotTerminal> getTimerAlarmIotTerminal(Long productId,String terminalids, Integer user_id) |
| 40 | { | 39 | { |
| 40 | + String where = ""; | ||
| 41 | + if(null != user_id) | ||
| 42 | + { | ||
| 43 | + where = " and user_info_id = "+user_id; | ||
| 44 | + } | ||
| 41 | if(StringUtils.isNotEmpty(terminalids)) | 45 | if(StringUtils.isNotEmpty(terminalids)) |
| 42 | { | 46 | { |
| 43 | - return baseDao.findBysql("SELECT * FROM `iot_terminal` WHERE product_id=? AND id IN(?)",IotTerminal.class,productId,terminalids.split(",")); | 47 | + return baseDao.findBysql("SELECT * FROM `iot_terminal` WHERE product_id=? AND id IN(?)"+where,IotTerminal.class,productId,terminalids.split(",")); |
| 44 | } | 48 | } |
| 45 | - return baseDao.findBysql("SELECT * FROM `iot_terminal` WHERE product_id=?",IotTerminal.class,productId); | 49 | + |
| 50 | + return baseDao.findBysql("SELECT * FROM `iot_terminal` WHERE product_id=?"+where,IotTerminal.class,productId); | ||
| 46 | } | 51 | } |
| 47 | 52 | ||
| 48 | public static List<IotAlertLog> getIotAlertLogList(Integer status,Integer limit) | 53 | public static List<IotAlertLog> getIotAlertLogList(Integer status,Integer limit) |
| @@ -53,6 +58,21 @@ public class DbOperateUtil { | @@ -53,6 +58,21 @@ public class DbOperateUtil { | ||
| 53 | 58 | ||
| 54 | public static int updateIotAlertLogStatus(List<Long> ids,Integer status) | 59 | public static int updateIotAlertLogStatus(List<Long> ids,Integer status) |
| 55 | { | 60 | { |
| 56 | - return baseDao.updateBySql("update iot_alert_log set `status`=? where id in(?)",status,ids); | 61 | + return baseDao.updateBySql("update iot_alert_log set `status`="+status+" where alert_log_id in("+ids.stream().map(Object::toString).collect(Collectors.joining(", "))+")"); |
| 62 | + } | ||
| 63 | + | ||
| 64 | + public static List<IotAlertUserNotice> getAlertUserNoticeList() | ||
| 65 | + { | ||
| 66 | + return baseDao.findBysql("SELECT * FROM `iot_alert_user_notice` where channels is not null and alert_ids is not null",IotAlertUserNotice.class); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + public static List<IotAlertNoticeChannel> getAlertNoticeChannelList() | ||
| 70 | + { | ||
| 71 | + return baseDao.findBysql("SELECT * FROM `iot_alert_notice_channel`",IotAlertNoticeChannel.class); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public static List<UserOpenid> getUserOpenidList() | ||
| 75 | + { | ||
| 76 | + return baseDao.findBysql("SELECT * FROM `user_openid`",UserOpenid.class); | ||
| 57 | } | 77 | } |
| 58 | } | 78 | } |
| 1 | package com.zhonglai.luhui.alarm.dto; | 1 | package com.zhonglai.luhui.alarm.dto; |
| 2 | 2 | ||
| 3 | import com.alibaba.otter.canal.protocol.CanalEntry; | 3 | import com.alibaba.otter.canal.protocol.CanalEntry; |
| 4 | +import com.zhonglai.luhui.service.dao.util.StringUtils; | ||
| 4 | 5 | ||
| 5 | import java.lang.reflect.InvocationTargetException; | 6 | import java.lang.reflect.InvocationTargetException; |
| 6 | import java.lang.reflect.Method; | 7 | import java.lang.reflect.Method; |
| @@ -35,6 +36,15 @@ public class IotAlert { | @@ -35,6 +36,15 @@ public class IotAlert { | ||
| 35 | private Integer status; | 36 | private Integer status; |
| 36 | 37 | ||
| 37 | private String createBy; | 38 | private String createBy; |
| 39 | + private Integer user_id; | ||
| 40 | + | ||
| 41 | + public Integer getUser_id() { | ||
| 42 | + return user_id; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public void setUser_id(Integer user_id) { | ||
| 46 | + this.user_id = user_id; | ||
| 47 | + } | ||
| 38 | 48 | ||
| 39 | public String getCreateBy() { | 49 | public String getCreateBy() { |
| 40 | return createBy; | 50 | return createBy; |
| @@ -124,10 +134,41 @@ public class IotAlert { | @@ -124,10 +134,41 @@ public class IotAlert { | ||
| 124 | IotAlert iotAlert = new IotAlert(); | 134 | IotAlert iotAlert = new IotAlert(); |
| 125 | for (CanalEntry.Column column : columns) | 135 | for (CanalEntry.Column column : columns) |
| 126 | { | 136 | { |
| 127 | - try { | ||
| 128 | - Method method = iotAlert.getClass().getMethod("set"+getName(column.getName())); | ||
| 129 | - method.invoke(iotAlert, column.getValue()); | ||
| 130 | - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { | 137 | + switch (column.getName()) |
| 138 | + { | ||
| 139 | + case "alert_id": | ||
| 140 | + iotAlert.setAlertId(Long.parseLong(column.getValue())); | ||
| 141 | + break; | ||
| 142 | + case "alert_name": | ||
| 143 | + iotAlert.setAlertName(column.getValue()); | ||
| 144 | + break; | ||
| 145 | + case "alert_level": | ||
| 146 | + iotAlert.setAlertLevel(Long.parseLong(column.getValue())); | ||
| 147 | + break; | ||
| 148 | + case "alert_type": | ||
| 149 | + iotAlert.setAlertType(Integer.parseInt(column.getValue())); | ||
| 150 | + break; | ||
| 151 | + case "product_id": | ||
| 152 | + iotAlert.setProductId(Long.parseLong(column.getValue())); | ||
| 153 | + break; | ||
| 154 | + case "product_name": | ||
| 155 | + iotAlert.setProductName(column.getValue()); | ||
| 156 | + break; | ||
| 157 | + case "triggers": | ||
| 158 | + iotAlert.setTriggers(column.getValue()); | ||
| 159 | + break; | ||
| 160 | + case "actions": | ||
| 161 | + iotAlert.setActions(column.getValue()); | ||
| 162 | + break; | ||
| 163 | + case "status": | ||
| 164 | + iotAlert.setStatus(Integer.parseInt(column.getValue())); | ||
| 165 | + break; | ||
| 166 | + case "create_by": | ||
| 167 | + iotAlert.setCreateBy(column.getValue()); | ||
| 168 | + break; | ||
| 169 | + case "user_id": | ||
| 170 | + iotAlert.setUser_id(Integer.parseInt(column.getValue())); | ||
| 171 | + break; | ||
| 131 | } | 172 | } |
| 132 | } | 173 | } |
| 133 | if(null == iotAlert.getAlertId()) | 174 | if(null == iotAlert.getAlertId()) |
| @@ -19,10 +19,12 @@ public class IotAlertLog | @@ -19,10 +19,12 @@ public class IotAlertLog | ||
| 19 | private Long create_time; // datetime DEFAULT NULL COMMENT '创建时间', | 19 | private Long create_time; // datetime DEFAULT NULL COMMENT '创建时间', |
| 20 | private Integer type; // tinyint DEFAULT NULL COMMENT '类型(1=告警,2=场景联动)', | 20 | private Integer type; // tinyint DEFAULT NULL COMMENT '类型(1=告警,2=场景联动)', |
| 21 | private Integer user_id; //关联的用户id(0为系统生成) | 21 | private Integer user_id; //关联的用户id(0为系统生成) |
| 22 | + private Integer alert_config_type; //告警配置类型(1系统配置,2用户配置) | ||
| 23 | + private String device_name; | ||
| 22 | public IotAlertLog() { | 24 | public IotAlertLog() { |
| 23 | } | 25 | } |
| 24 | 26 | ||
| 25 | - public IotAlertLog(Long alert_id, String alert_name, Integer alert_level, Integer status, String device_id, Long create_time, Integer type,String user_id) { | 27 | + public IotAlertLog(Long alert_id, String alert_name, Integer alert_level, Integer status, String device_id, Long create_time, Integer type,Integer user_id,String device_name,Integer alert_config_type) { |
| 26 | this.alert_id = alert_id; | 28 | this.alert_id = alert_id; |
| 27 | this.alert_name = alert_name; | 29 | this.alert_name = alert_name; |
| 28 | this.alert_level = alert_level; | 30 | this.alert_level = alert_level; |
| @@ -30,11 +32,25 @@ public class IotAlertLog | @@ -30,11 +32,25 @@ public class IotAlertLog | ||
| 30 | this.device_id = device_id; | 32 | this.device_id = device_id; |
| 31 | this.create_time = create_time; | 33 | this.create_time = create_time; |
| 32 | this.type = type; | 34 | this.type = type; |
| 33 | - if(StringUtils.isNotEmpty(user_id)) | ||
| 34 | - { | ||
| 35 | - this.user_id = Integer.parseInt(user_id); | 35 | + this.user_id = user_id; |
| 36 | + this.device_name = device_name; | ||
| 37 | + this.alert_config_type = alert_config_type; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public Integer getAlert_config_type() { | ||
| 41 | + return alert_config_type; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public void setAlert_config_type(Integer alert_config_type) { | ||
| 45 | + this.alert_config_type = alert_config_type; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public String getDevice_name() { | ||
| 49 | + return device_name; | ||
| 36 | } | 50 | } |
| 37 | 51 | ||
| 52 | + public void setDevice_name(String device_name) { | ||
| 53 | + this.device_name = device_name; | ||
| 38 | } | 54 | } |
| 39 | 55 | ||
| 40 | public Integer getUser_id() { | 56 | public Integer getUser_id() { |
lh-modules/lh-alarm/src/main/java/com/zhonglai/luhui/alarm/dto/IotAlertNoticeChannel.java
0 → 100644
| 1 | +package com.zhonglai.luhui.alarm.dto; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 告警通知渠道 | ||
| 5 | + */ | ||
| 6 | +public class IotAlertNoticeChannel { | ||
| 7 | + private Integer id; // int NOT NULL AUTO_INCREMENT COMMENT '主键', | ||
| 8 | + private Integer type; // int NOT NULL COMMENT '渠道类型(1公众号,2小程序,3鱼儿乐app,4短信,5电话)', | ||
| 9 | + private String config; // json NOT NULL COMMENT '渠道配置', | ||
| 10 | + private String name; // varchar(50) NOT NULL COMMENT '名称', | ||
| 11 | + | ||
| 12 | + public Integer getId() { | ||
| 13 | + return id; | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + public void setId(Integer id) { | ||
| 17 | + this.id = id; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public Integer getType() { | ||
| 21 | + return type; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public void setType(Integer type) { | ||
| 25 | + this.type = type; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public String getConfig() { | ||
| 29 | + return config; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public void setConfig(String config) { | ||
| 33 | + this.config = config; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public String getName() { | ||
| 37 | + return name; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public void setName(String name) { | ||
| 41 | + this.name = name; | ||
| 42 | + } | ||
| 43 | +} |
| 1 | +package com.zhonglai.luhui.alarm.dto; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 用户告警通知配置 | ||
| 5 | + */ | ||
| 6 | +public class IotAlertUserNotice { | ||
| 7 | + private Integer id; // int NOT NULL AUTO_INCREMENT COMMENT '主键id', | ||
| 8 | + private String channels; // varchar(100) DEFAULT NULL COMMENT '通知渠道(iot_alert_notice_channel表的id集合,多个英文逗号分割)', | ||
| 9 | + private Integer type; // int DEFAULT NULL COMMENT '告警类型(1系统告警,2用户告警)', | ||
| 10 | + private String alert_ids; // varchar(100) DEFAULT '*' COMMENT '告警id集合(关联iot_alert_log和iot_alert_user表的id,多个英文逗号分割,*表示所有)', | ||
| 11 | + private Integer user_id; // int DEFAULT NULL COMMENT '用户id' | ||
| 12 | + | ||
| 13 | + public Integer getId() { | ||
| 14 | + return id; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + public void setId(Integer id) { | ||
| 18 | + this.id = id; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public Integer getType() { | ||
| 22 | + return type; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public void setType(Integer type) { | ||
| 26 | + this.type = type; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public Integer getUser_id() { | ||
| 30 | + return user_id; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public void setUser_id(Integer user_id) { | ||
| 34 | + this.user_id = user_id; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public String getChannels() { | ||
| 38 | + return channels; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public void setChannels(String channels) { | ||
| 42 | + this.channels = channels; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + | ||
| 46 | + public String getAlert_ids() { | ||
| 47 | + return alert_ids; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + public void setAlert_ids(String alert_ids) { | ||
| 51 | + this.alert_ids = alert_ids; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | +} |
| @@ -72,7 +72,7 @@ public class IotDevice { | @@ -72,7 +72,7 @@ public class IotDevice { | ||
| 72 | break; | 72 | break; |
| 73 | } | 73 | } |
| 74 | } | 74 | } |
| 75 | - if(null == iotDevice.getSummary() || null == iotDevice.getThings_model_value() || null == iotDevice.getClient_id()) | 75 | + if(null == iotDevice.getSummary() || null == iotDevice.getThings_model_value() || null == iotDevice.getClient_id() ) |
| 76 | { | 76 | { |
| 77 | return null; | 77 | return null; |
| 78 | } | 78 | } |
| @@ -20,6 +20,26 @@ public class IotTerminal { | @@ -20,6 +20,26 @@ public class IotTerminal { | ||
| 20 | 20 | ||
| 21 | private Integer product_id; | 21 | private Integer product_id; |
| 22 | 22 | ||
| 23 | + private Integer user_info_id; | ||
| 24 | + private String name; | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + public String getName() { | ||
| 28 | + return name; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public void setName(String name) { | ||
| 32 | + this.name = name; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public Integer getUser_info_id() { | ||
| 36 | + return user_info_id; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public void setUser_info_id(Integer user_info_id) { | ||
| 40 | + this.user_info_id = user_info_id; | ||
| 41 | + } | ||
| 42 | + | ||
| 23 | public String getDevice_id() { | 43 | public String getDevice_id() { |
| 24 | return device_id; | 44 | return device_id; |
| 25 | } | 45 | } |
| @@ -85,6 +105,12 @@ public class IotTerminal { | @@ -85,6 +105,12 @@ public class IotTerminal { | ||
| 85 | case "product_id": | 105 | case "product_id": |
| 86 | iotTerminal.setProduct_id(null!=column.getValue()&&!"".equals(column.getValue())?Integer.parseInt(column.getValue()):null); | 106 | iotTerminal.setProduct_id(null!=column.getValue()&&!"".equals(column.getValue())?Integer.parseInt(column.getValue()):null); |
| 87 | break; | 107 | break; |
| 108 | + case "user_info_id": | ||
| 109 | + iotTerminal.setUser_info_id(null!=column.getValue()&&!"".equals(column.getValue())?Integer.parseInt(column.getValue()):null); | ||
| 110 | + break; | ||
| 111 | + case "name": | ||
| 112 | + iotTerminal.setName(column.getValue()); | ||
| 113 | + break; | ||
| 88 | } | 114 | } |
| 89 | } | 115 | } |
| 90 | if(null == iotTerminal.getThings_model_value() || null == iotTerminal.getThings_model_config() || null == iotTerminal.getId()) | 116 | if(null == iotTerminal.getThings_model_value() || null == iotTerminal.getThings_model_config() || null == iotTerminal.getId()) |
lh-modules/lh-alarm/src/main/java/com/zhonglai/luhui/alarm/dto/UserAlarmNoticeConfig.java
0 → 100644
| 1 | +package com.zhonglai.luhui.alarm.dto; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 5 | +public class UserAlarmNoticeConfig { | ||
| 6 | + | ||
| 7 | + private String fromConfig; | ||
| 8 | + private Integer channelType; | ||
| 9 | + | ||
| 10 | + public String getFromConfig() { | ||
| 11 | + return fromConfig; | ||
| 12 | + } | ||
| 13 | + | ||
| 14 | + public void setFromConfig(String fromConfig) { | ||
| 15 | + this.fromConfig = fromConfig; | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + public Integer getChannelType() { | ||
| 19 | + return channelType; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public void setChannelType(Integer channelType) { | ||
| 23 | + this.channelType = channelType; | ||
| 24 | + } | ||
| 25 | +} |
| 1 | +package com.zhonglai.luhui.alarm.dto; | ||
| 2 | + | ||
| 3 | +public class UserOpenid { | ||
| 4 | + private Integer user_id; // int DEFAULT NULL COMMENT '用户id', | ||
| 5 | + private String openid; // varchar(50) DEFAULT NULL COMMENT '微信用户的唯一标识', | ||
| 6 | + private Integer xcx_config_id; // int DEFAULT NULL COMMENT '微信平台的配置参数表id', | ||
| 7 | + | ||
| 8 | + public Integer getUser_id() { | ||
| 9 | + return user_id; | ||
| 10 | + } | ||
| 11 | + | ||
| 12 | + public void setUser_id(Integer user_id) { | ||
| 13 | + this.user_id = user_id; | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + public String getOpenid() { | ||
| 17 | + return openid; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public void setOpenid(String openid) { | ||
| 21 | + this.openid = openid; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public Integer getXcx_config_id() { | ||
| 25 | + return xcx_config_id; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public void setXcx_config_id(Integer xcx_config_id) { | ||
| 29 | + this.xcx_config_id = xcx_config_id; | ||
| 30 | + } | ||
| 31 | +} |
| @@ -27,17 +27,18 @@ public class TimerAlarmJob implements Job { | @@ -27,17 +27,18 @@ public class TimerAlarmJob implements Job { | ||
| 27 | List<TriggerTriggers> triggersList = timerTriggers.getTriggersList(); | 27 | List<TriggerTriggers> triggersList = timerTriggers.getTriggersList(); |
| 28 | String alertName = iotAlert.getAlertName(); | 28 | String alertName = iotAlert.getAlertName(); |
| 29 | Long productId = iotAlert.getProductId(); | 29 | Long productId = iotAlert.getProductId(); |
| 30 | + Integer user_id = iotAlert.getUser_id(); | ||
| 30 | String terminalids = timerTriggers.getTerminalids(); | 31 | String terminalids = timerTriggers.getTerminalids(); |
| 31 | 32 | ||
| 32 | List<IotAlertLog> list = new ArrayList<>(); | 33 | List<IotAlertLog> list = new ArrayList<>(); |
| 33 | 34 | ||
| 34 | - List<IotTerminal> iotTerminallist = DbOperateUtil.getTimerAlarmIotTerminal(productId,terminalids); | 35 | + List<IotTerminal> iotTerminallist = DbOperateUtil.getTimerAlarmIotTerminal(productId,terminalids,user_id); |
| 35 | if (null != iotTerminallist && iotTerminallist.size() != 0 ) | 36 | if (null != iotTerminallist && iotTerminallist.size() != 0 ) |
| 36 | { | 37 | { |
| 37 | for (IotTerminal iotTerminal:iotTerminallist) | 38 | for (IotTerminal iotTerminal:iotTerminallist) |
| 38 | { | 39 | { |
| 39 | IotTerminalAlarm iotTerminalAlarm = new IotTerminalAlarm(iotTerminal,iotTerminal); | 40 | IotTerminalAlarm iotTerminalAlarm = new IotTerminalAlarm(iotTerminal,iotTerminal); |
| 40 | - iotTerminalAlarm.alarmTriggerTriggers(triggersList,iotTerminal.getThings_model_value(),iotAlert.getAlertId(),alertName,iotAlert.getAlertLevel().intValue(),iotTerminal.getId(),iotAlert.getCreateBy()); | 41 | + iotTerminalAlarm.alarmTriggerTriggers(triggersList,iotTerminal.getThings_model_value(),iotAlert.getAlertId(),alertName,iotAlert.getAlertLevel().intValue(),iotTerminal.getId(),iotAlert.getUser_id(), iotTerminal.getName()); |
| 41 | List<IotAlertLog> serviceDtolist = iotTerminalAlarm.getList(); | 42 | List<IotAlertLog> serviceDtolist = iotTerminalAlarm.getList(); |
| 42 | if(null != serviceDtolist && serviceDtolist.size()!=0) | 43 | if(null != serviceDtolist && serviceDtolist.size()!=0) |
| 43 | { | 44 | { |
| 1 | +package com.zhonglai.luhui.alarm.notice; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | +import com.zhonglai.luhui.alarm.config.CachAlarmConfig; | ||
| 5 | +import com.zhonglai.luhui.alarm.dto.IotAlertLog; | ||
| 6 | +import com.zhonglai.luhui.alarm.dto.UserAlarmNoticeConfig; | ||
| 7 | +import com.zhonglai.luhui.alarm.notice.dto.WeiXinGongZhongHaoNoticeDto; | ||
| 8 | +import com.zhonglai.luhui.alarm.notice.impl.WeiXinGongZhongHaoNoticeImpl; | ||
| 9 | + | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | +public interface NoticeFactory { | ||
| 13 | + boolean send(IotAlertLog iotAlertLog); | ||
| 14 | + static boolean notice(IotAlertLog iotAlertLog) | ||
| 15 | + { | ||
| 16 | + //获取通知配置 | ||
| 17 | + List<UserAlarmNoticeConfig> userAlarmNoticeConfigList = CachAlarmConfig.getUserAlarmNoticeConfig(iotAlertLog.getUser_id(),iotAlertLog.getAlert_config_type(),iotAlertLog.getAlert_id()); | ||
| 18 | + if(null != userAlarmNoticeConfigList && userAlarmNoticeConfigList.size()!=0) //有配置告警通知的才发送 | ||
| 19 | + { | ||
| 20 | + boolean rb = true; | ||
| 21 | + for (UserAlarmNoticeConfig userAlarmNoticeConfig:userAlarmNoticeConfigList) | ||
| 22 | + { | ||
| 23 | + NoticeFactory noticeFactory = null; | ||
| 24 | + //通过配置的通知渠道,分发消息 | ||
| 25 | + switch (userAlarmNoticeConfig.getChannelType()) //渠道类型(1公众号,2小程序,3鱼儿乐app,4短信,5电话) | ||
| 26 | + { | ||
| 27 | + case 1: | ||
| 28 | + WeiXinGongZhongHaoNoticeDto weiXinGongZhongHaoNoticeDto = JSONObject.parseObject(userAlarmNoticeConfig.getFromConfig(),WeiXinGongZhongHaoNoticeDto.class); | ||
| 29 | + noticeFactory = new WeiXinGongZhongHaoNoticeImpl(iotAlertLog.getUser_id(),weiXinGongZhongHaoNoticeDto); | ||
| 30 | + break; | ||
| 31 | + case 2: | ||
| 32 | + break; | ||
| 33 | + case 3: | ||
| 34 | + break; | ||
| 35 | + case 4: | ||
| 36 | + break; | ||
| 37 | + case 5: | ||
| 38 | + break; | ||
| 39 | + } | ||
| 40 | + if(null != noticeFactory) | ||
| 41 | + { | ||
| 42 | + rb=rb&¬iceFactory.send(iotAlertLog); | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + return rb; | ||
| 46 | + | ||
| 47 | + }else { | ||
| 48 | + return false; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + static boolean request(IotAlertLog iotAlertLog) | ||
| 54 | + { | ||
| 55 | + //先通知 | ||
| 56 | + boolean rb = notice(iotAlertLog); | ||
| 57 | + //确认到达 | ||
| 58 | + return rb; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + | ||
| 62 | +} |
| 1 | +package com.zhonglai.luhui.alarm.notice.dto; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 公众号通知的配置 | ||
| 5 | + */ | ||
| 6 | +public class WeiXinGongZhongHaoNoticeDto { | ||
| 7 | + private Integer xcxConfigId; | ||
| 8 | + private String xcxappid; | ||
| 9 | + private String xcxsecret; | ||
| 10 | + private String gzhappid; | ||
| 11 | + private String gzhsecret; | ||
| 12 | + private String templateId; | ||
| 13 | + private String redirectUrl; | ||
| 14 | + | ||
| 15 | + public String getGzhsecret() { | ||
| 16 | + return gzhsecret; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public void setGzhsecret(String gzhsecret) { | ||
| 20 | + this.gzhsecret = gzhsecret; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public Integer getXcxConfigId() { | ||
| 24 | + return xcxConfigId; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public void setXcxConfigId(Integer xcxConfigId) { | ||
| 28 | + this.xcxConfigId = xcxConfigId; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public String getXcxappid() { | ||
| 32 | + return xcxappid; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public void setXcxappid(String xcxappid) { | ||
| 36 | + this.xcxappid = xcxappid; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public String getXcxsecret() { | ||
| 40 | + return xcxsecret; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public void setXcxsecret(String xcxsecret) { | ||
| 44 | + this.xcxsecret = xcxsecret; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public String getGzhappid() { | ||
| 48 | + return gzhappid; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setGzhappid(String gzhappid) { | ||
| 52 | + this.gzhappid = gzhappid; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public String getTemplateId() { | ||
| 56 | + return templateId; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void setTemplateId(String templateId) { | ||
| 60 | + this.templateId = templateId; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public String getRedirectUrl() { | ||
| 64 | + return redirectUrl; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public void setRedirectUrl(String redirectUrl) { | ||
| 68 | + this.redirectUrl = redirectUrl; | ||
| 69 | + } | ||
| 70 | +} |
lh-modules/lh-alarm/src/main/java/com/zhonglai/luhui/alarm/notice/dto/wxUniformSend/Miniprogram.java
0 → 100644
| 1 | +package com.zhonglai.luhui.alarm.notice.dto.wxUniformSend; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +public class Miniprogram { | ||
| 5 | + private String appid; //小程序appid | ||
| 6 | + private String pagepath; // | ||
| 7 | + | ||
| 8 | + public String getAppid() { | ||
| 9 | + return appid; | ||
| 10 | + } | ||
| 11 | + | ||
| 12 | + public void setAppid(String appid) { | ||
| 13 | + this.appid = appid; | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + public String getPagepath() { | ||
| 17 | + return pagepath; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public void setPagepath(String pagepath) { | ||
| 21 | + this.pagepath = pagepath; | ||
| 22 | + } | ||
| 23 | +} |
| 1 | +package com.zhonglai.luhui.alarm.notice.dto.wxUniformSend; | ||
| 2 | + | ||
| 3 | +import weixin.popular.bean.message.templatemessage.TemplateMessageItem; | ||
| 4 | + | ||
| 5 | +import java.util.LinkedHashMap; | ||
| 6 | + | ||
| 7 | +public class MpTemplateMsg { | ||
| 8 | + private String appid; //公众号appid,要求与小程序有绑定且同主体 | ||
| 9 | + private String template_id; //公众号模板id | ||
| 10 | + private String url; //公众号模板消息所要跳转的url | ||
| 11 | + private Miniprogram miniprogram; //公众号模板消息所要跳转的小程序,小程序的必须与公众号具有绑定关系 | ||
| 12 | + private LinkedHashMap<String, TemplateMessageItem> data; //公众号模板消息的数据 | ||
| 13 | + | ||
| 14 | + public String getAppid() { | ||
| 15 | + return appid; | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + public void setAppid(String appid) { | ||
| 19 | + this.appid = appid; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public String getTemplate_id() { | ||
| 23 | + return template_id; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + public void setTemplate_id(String template_id) { | ||
| 27 | + this.template_id = template_id; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public String getUrl() { | ||
| 31 | + return url; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + public void setUrl(String url) { | ||
| 35 | + this.url = url; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public Miniprogram getMiniprogram() { | ||
| 39 | + return miniprogram; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public void setMiniprogram(Miniprogram miniprogram) { | ||
| 43 | + this.miniprogram = miniprogram; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + public LinkedHashMap<String, TemplateMessageItem> getData() { | ||
| 47 | + return data; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + public void setData(LinkedHashMap<String, TemplateMessageItem> data) { | ||
| 51 | + this.data = data; | ||
| 52 | + } | ||
| 53 | +} |
| 1 | +package com.zhonglai.luhui.alarm.notice.dto.wxUniformSend; | ||
| 2 | + | ||
| 3 | +import weixin.popular.bean.message.templatemessage.TemplateMessageItem; | ||
| 4 | + | ||
| 5 | +import java.util.LinkedHashMap; | ||
| 6 | + | ||
| 7 | +public class WeappTemplateMsg { | ||
| 8 | + private String touser; | ||
| 9 | + private String template_id; | ||
| 10 | + private String page; | ||
| 11 | + private String form_id; | ||
| 12 | + private String emphasis_keyword; | ||
| 13 | + private LinkedHashMap<String, TemplateMessageItem> data; | ||
| 14 | + | ||
| 15 | + public String getTouser() { | ||
| 16 | + return touser; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public void setTouser(String touser) { | ||
| 20 | + this.touser = touser; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public String getTemplate_id() { | ||
| 24 | + return template_id; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public void setTemplate_id(String template_id) { | ||
| 28 | + this.template_id = template_id; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public String getPage() { | ||
| 32 | + return page; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public void setPage(String page) { | ||
| 36 | + this.page = page; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public String getForm_id() { | ||
| 40 | + return form_id; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public void setForm_id(String form_id) { | ||
| 44 | + this.form_id = form_id; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public String getEmphasis_keyword() { | ||
| 48 | + return emphasis_keyword; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setEmphasis_keyword(String emphasis_keyword) { | ||
| 52 | + this.emphasis_keyword = emphasis_keyword; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public LinkedHashMap<String, TemplateMessageItem> getData() { | ||
| 56 | + return data; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void setData(LinkedHashMap<String, TemplateMessageItem> data) { | ||
| 60 | + this.data = data; | ||
| 61 | + } | ||
| 62 | +} |
| 1 | +package com.zhonglai.luhui.alarm.notice.dto.wxUniformSend; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | +import com.zhonglai.luhui.alarm.notice.dto.wxUniformSend.Miniprogram; | ||
| 5 | +import com.zhonglai.luhui.alarm.notice.dto.wxUniformSend.MpTemplateMsg; | ||
| 6 | +import com.zhonglai.luhui.alarm.notice.dto.wxUniformSend.WxUniformSendMessage; | ||
| 7 | +import org.apache.http.Header; | ||
| 8 | +import org.apache.http.client.methods.HttpUriRequest; | ||
| 9 | +import org.apache.http.client.methods.RequestBuilder; | ||
| 10 | +import org.apache.http.entity.ContentType; | ||
| 11 | +import org.apache.http.entity.StringEntity; | ||
| 12 | +import org.apache.http.message.BasicHeader; | ||
| 13 | +import weixin.popular.api.MessageAPI; | ||
| 14 | +import weixin.popular.api.TokenAPI; | ||
| 15 | +import weixin.popular.bean.message.templatemessage.TemplateMessage; | ||
| 16 | +import weixin.popular.bean.message.templatemessage.TemplateMessageItem; | ||
| 17 | +import weixin.popular.bean.message.templatemessage.TemplateMessageResult; | ||
| 18 | +import weixin.popular.bean.token.Token; | ||
| 19 | +import weixin.popular.client.LocalHttpClient; | ||
| 20 | +import weixin.popular.util.JsonUtil; | ||
| 21 | + | ||
| 22 | +import java.nio.charset.Charset; | ||
| 23 | +import java.util.HashMap; | ||
| 24 | +import java.util.LinkedHashMap; | ||
| 25 | +import java.util.Map; | ||
| 26 | + | ||
| 27 | +public class WeiXinMessage { | ||
| 28 | + | ||
| 29 | + private static Map<String,Token> tokenMap = new HashMap<>(); | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 发送公众号模版消息 | ||
| 33 | + * | ||
| 34 | + * @param openid 用户标识 | ||
| 35 | + * @param templateId 模版id | ||
| 36 | + * @param redirectUrl 模版消息重定向地址 | ||
| 37 | + * @param parameters 模版消息参数 | ||
| 38 | + */ | ||
| 39 | + public static void sendTemplateMsg(String appid, String secret,String openid, String templateId, String redirectUrl, Map<String, String> parameters) { | ||
| 40 | + TemplateMessage templateMessage = new TemplateMessage(); | ||
| 41 | + templateMessage.setTemplate_id(templateId); | ||
| 42 | + templateMessage.setTouser(openid); | ||
| 43 | + templateMessage.setData(parametersToData(parameters)); | ||
| 44 | + templateMessage.setUrl(redirectUrl); | ||
| 45 | + String defaultToken = getWechatServerToken(appid,secret); | ||
| 46 | + TemplateMessageResult templateMessageResult = MessageAPI.messageTemplateSend(defaultToken, templateMessage); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * 下发小程序和公众号统一的服务消息 | ||
| 51 | + * | ||
| 52 | + * @param openid 用户标识 | ||
| 53 | + * @param templateId 模版id | ||
| 54 | + * @param redirectUrl 模版消息重定向地址 | ||
| 55 | + * @param parameters 模版消息参数 | ||
| 56 | + */ | ||
| 57 | + public static void sendUniformMessage(String gzhappid,String xcxappid, String secret,String openid, String templateId, String redirectUrl, Map<String, String> parameters) { | ||
| 58 | + WxUniformSendMessage wxUniformSendMessage = new WxUniformSendMessage(); | ||
| 59 | + wxUniformSendMessage.setTouser(openid); | ||
| 60 | +// wxUniformSendMessage.setWeapp_template_msg(parametersToData(parameters)); | ||
| 61 | + MpTemplateMsg mpTemplateMsg = new MpTemplateMsg(); | ||
| 62 | + mpTemplateMsg.setAppid(gzhappid); | ||
| 63 | + mpTemplateMsg.setData(parametersToData(parameters)); | ||
| 64 | + Miniprogram miniprogram = new Miniprogram(); | ||
| 65 | + miniprogram.setAppid(xcxappid); | ||
| 66 | + miniprogram.setPagepath(redirectUrl); | ||
| 67 | + mpTemplateMsg.setMiniprogram(miniprogram); | ||
| 68 | + mpTemplateMsg.setTemplate_id(templateId); | ||
| 69 | +// mpTemplateMsg.setUrl(redirectUrl); | ||
| 70 | + wxUniformSendMessage.setMp_template_msg(mpTemplateMsg); | ||
| 71 | + String defaultToken = getWechatServerToken(xcxappid,secret); | ||
| 72 | + TemplateMessageResult templateMessageResult = uniform_send(defaultToken, wxUniformSendMessage); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + private static LinkedHashMap<String, TemplateMessageItem> parametersToData(Map<String, String> parameters) | ||
| 76 | + { | ||
| 77 | + LinkedHashMap<String, TemplateMessageItem> msgMap = new LinkedHashMap<>(); | ||
| 78 | + if (parameters != null && parameters.size() > 0) { | ||
| 79 | + for (String key : parameters.keySet()) { | ||
| 80 | + msgMap.put(key, new TemplateMessageItem(parameters.get(key), "")); | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + return msgMap; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + private static Header jsonHeader = new BasicHeader("Content-Type", ContentType.APPLICATION_JSON.toString()); | ||
| 87 | + | ||
| 88 | + /** | ||
| 89 | + * 下发小程序和公众号统一的服务消息 | ||
| 90 | + * @param access_token | ||
| 91 | + * @return | ||
| 92 | + */ | ||
| 93 | + public static TemplateMessageResult uniform_send(String access_token, WxUniformSendMessage wxUniformSendMessage) { | ||
| 94 | + String messageJson = JsonUtil.toJSONString(wxUniformSendMessage); | ||
| 95 | + HttpUriRequest httpUriRequest = RequestBuilder.post().setHeader(jsonHeader).setUri("https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send").addParameter("access_token", access_token).setEntity(new StringEntity(messageJson, Charset.forName("utf-8"))).build(); | ||
| 96 | + return LocalHttpClient.executeJsonResult(httpUriRequest, TemplateMessageResult.class); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * 发送模板消息 | ||
| 101 | + * @return | ||
| 102 | + */ | ||
| 103 | + public static TemplateMessageResult messageTemplateSend(String appid, String secret, JSONObject jsonObject) { | ||
| 104 | + String messageJson = jsonObject.toJSONString(); | ||
| 105 | + HttpUriRequest httpUriRequest = RequestBuilder.post().setHeader(jsonHeader).setUri("https://api.weixin.qq.com/cgi-bin/message/template/send").addParameter("access_token", getWechatServerToken(appid,secret)).setEntity(new StringEntity(messageJson, Charset.forName("utf-8"))).build(); | ||
| 106 | + return LocalHttpClient.executeJsonResult(httpUriRequest, TemplateMessageResult.class); | ||
| 107 | + } | ||
| 108 | + /** | ||
| 109 | + * 获取服务号的token | ||
| 110 | + * | ||
| 111 | + * @return | ||
| 112 | + */ | ||
| 113 | + public static String getWechatServerToken(String appid, String secret) { | ||
| 114 | + | ||
| 115 | + Token token = tokenMap.get(appid); | ||
| 116 | + int time =new Long(System.currentTimeMillis()).intValue(); | ||
| 117 | + if(null != token && token.getExpires_in()-time>0) | ||
| 118 | + { | ||
| 119 | + return token.getAccess_token(); | ||
| 120 | + } | ||
| 121 | + token = TokenAPI.token(appid,secret); | ||
| 122 | + token.setExpires_in(time+token.getExpires_in()-600); //提前10分钟 | ||
| 123 | + return token.getAccess_token(); | ||
| 124 | + } | ||
| 125 | +} |
| 1 | +package com.zhonglai.luhui.alarm.notice.dto.wxUniformSend; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +public class WxUniformSendMessage { | ||
| 5 | + private String touser; | ||
| 6 | + private WeappTemplateMsg weapp_template_msg; | ||
| 7 | + private MpTemplateMsg mp_template_msg; | ||
| 8 | + | ||
| 9 | + public String getTouser() { | ||
| 10 | + return touser; | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + public void setTouser(String touser) { | ||
| 14 | + this.touser = touser; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + public WeappTemplateMsg getWeapp_template_msg() { | ||
| 18 | + return weapp_template_msg; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public void setWeapp_template_msg(WeappTemplateMsg weapp_template_msg) { | ||
| 22 | + this.weapp_template_msg = weapp_template_msg; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public MpTemplateMsg getMp_template_msg() { | ||
| 26 | + return mp_template_msg; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public void setMp_template_msg(MpTemplateMsg mp_template_msg) { | ||
| 30 | + this.mp_template_msg = mp_template_msg; | ||
| 31 | + } | ||
| 32 | +} |
| 1 | +package com.zhonglai.luhui.alarm.notice.impl; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | +import com.zhonglai.luhui.alarm.config.CachAlarmConfig; | ||
| 5 | +import com.zhonglai.luhui.alarm.dto.IotAlertLog; | ||
| 6 | +import com.zhonglai.luhui.alarm.notice.NoticeFactory; | ||
| 7 | +import com.zhonglai.luhui.alarm.notice.dto.WeiXinGongZhongHaoNoticeDto; | ||
| 8 | +import com.zhonglai.luhui.alarm.notice.dto.wxUniformSend.WeiXinMessage; | ||
| 9 | +import org.springframework.beans.factory.annotation.Value; | ||
| 10 | +import weixin.popular.api.MessageAPI; | ||
| 11 | +import weixin.popular.bean.message.templatemessage.Miniprogram; | ||
| 12 | +import weixin.popular.bean.message.templatemessage.TemplateMessage; | ||
| 13 | +import weixin.popular.bean.message.templatemessage.TemplateMessageItem; | ||
| 14 | + | ||
| 15 | +import java.text.SimpleDateFormat; | ||
| 16 | +import java.util.*; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * 微信公众号 | ||
| 20 | + */ | ||
| 21 | +public class WeiXinGongZhongHaoNoticeImpl implements NoticeFactory { | ||
| 22 | + | ||
| 23 | + private Set<String> toOpenIds; | ||
| 24 | + | ||
| 25 | + private WeiXinGongZhongHaoNoticeDto weiXinGongZhongHaoNoticeDto; | ||
| 26 | + public WeiXinGongZhongHaoNoticeImpl(Integer userId,WeiXinGongZhongHaoNoticeDto weiXinGongZhongHaoNoticeDto) | ||
| 27 | + { | ||
| 28 | + this.weiXinGongZhongHaoNoticeDto = weiXinGongZhongHaoNoticeDto; | ||
| 29 | + toOpenIds = CachAlarmConfig.getUserXcxOpenid(userId,weiXinGongZhongHaoNoticeDto.getXcxConfigId()); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + @Override | ||
| 33 | + public boolean send(IotAlertLog iotAlertLog) { | ||
| 34 | + if(null != toOpenIds && toOpenIds.size() != 0) | ||
| 35 | + { | ||
| 36 | + return sendMessage(iotAlertLog,toOpenIds.toArray(new String[toOpenIds.size()])); | ||
| 37 | + } | ||
| 38 | + return false; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 设备告警消息 | ||
| 44 | + * @param os openid | ||
| 45 | + */ | ||
| 46 | + public boolean sendMessage(IotAlertLog iotAlertLog, String ... os) | ||
| 47 | + { | ||
| 48 | + JSONObject data = new JSONObject(); | ||
| 49 | + data.put("thing23",new org.json.JSONObject().put("value",iotAlertLog.getDevice_name())); | ||
| 50 | + data.put("character_string11",new org.json.JSONObject().put("value",iotAlertLog.getDevice_id())); | ||
| 51 | + data.put("time3",new org.json.JSONObject().put("value",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(iotAlertLog.getCreate_time())))); | ||
| 52 | + data.put("thing33",new org.json.JSONObject().put("value",iotAlertLog.getAlert_name())); | ||
| 53 | + Miniprogram miniprogram = new Miniprogram(); | ||
| 54 | + miniprogram.setAppid(weiXinGongZhongHaoNoticeDto.getXcxappid()); | ||
| 55 | + miniprogram.setPagepath(weiXinGongZhongHaoNoticeDto.getRedirectUrl()); | ||
| 56 | + | ||
| 57 | + for(String o:os) | ||
| 58 | + { | ||
| 59 | + JSONObject templateMessage = new JSONObject(); | ||
| 60 | + templateMessage.put("touser",o); | ||
| 61 | + templateMessage.put("template_id",weiXinGongZhongHaoNoticeDto.getTemplateId()); | ||
| 62 | + templateMessage.put("data",data); | ||
| 63 | + templateMessage.put("miniprogram",miniprogram); | ||
| 64 | + | ||
| 65 | + WeiXinMessage.messageTemplateSend(weiXinGongZhongHaoNoticeDto.getGzhappid(),weiXinGongZhongHaoNoticeDto.getGzhsecret(),templateMessage); | ||
| 66 | + } | ||
| 67 | + return true; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | +} |
| 1 | package com.zhonglai.luhui.alarm.service; | 1 | package com.zhonglai.luhui.alarm.service; |
| 2 | 2 | ||
| 3 | +import com.zhonglai.luhui.alarm.config.CachAlarmConfig; | ||
| 3 | import com.zhonglai.luhui.alarm.dao.DbOperateUtil; | 4 | import com.zhonglai.luhui.alarm.dao.DbOperateUtil; |
| 4 | import com.zhonglai.luhui.alarm.dto.IotAlertLog; | 5 | import com.zhonglai.luhui.alarm.dto.IotAlertLog; |
| 6 | +import com.zhonglai.luhui.alarm.notice.NoticeFactory; | ||
| 7 | +import com.zhonglai.luhui.alarm.util.ThreadPoolUtil; | ||
| 8 | +import org.slf4j.Logger; | ||
| 9 | +import org.slf4j.LoggerFactory; | ||
| 5 | 10 | ||
| 6 | import java.util.ArrayList; | 11 | import java.util.ArrayList; |
| 7 | import java.util.List; | 12 | import java.util.List; |
| 13 | +import java.util.concurrent.ScheduledFuture; | ||
| 14 | +import java.util.concurrent.ScheduledThreadPoolExecutor; | ||
| 15 | +import java.util.concurrent.TimeUnit; | ||
| 8 | 16 | ||
| 9 | /** | 17 | /** |
| 10 | * 发送告警业务 | 18 | * 发送告警业务 |
| 11 | */ | 19 | */ |
| 12 | public class SendAlarmService { | 20 | public class SendAlarmService { |
| 21 | + private static final Logger logger = LoggerFactory.getLogger(SendAlarmService.class); | ||
| 22 | + | ||
| 13 | public static void start() | 23 | public static void start() |
| 14 | { | 24 | { |
| 25 | + /**该方法相对起始时间点以固定频率调用指定的任务(fixed-rate任务)。当把任务提交到线程池并延迟initialDelay时间后开始执行任务command。 | ||
| 26 | + * 然后从initialDelay+period时间点再次执行,而后在initialDelay+2*period时间点再次执行,循环往复,直到抛出异常或者调用了任务的cancel方法取消了任务, | ||
| 27 | + * 或者关闭了线程池。 | ||
| 28 | + */ | ||
| 29 | + ThreadPoolUtil.executor.scheduleWithFixedDelay(() -> runSend(),0,15, TimeUnit.SECONDS); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + private static void runSend() | ||
| 33 | + { | ||
| 15 | List<IotAlertLog> list = DbOperateUtil.getIotAlertLogList(2,100); //未处理的告警 | 34 | List<IotAlertLog> list = DbOperateUtil.getIotAlertLogList(2,100); //未处理的告警 |
| 16 | if(null != list && list.size()!=0) | 35 | if(null != list && list.size()!=0) |
| 17 | { | 36 | { |
| @@ -20,31 +39,48 @@ public class SendAlarmService { | @@ -20,31 +39,48 @@ public class SendAlarmService { | ||
| 20 | 39 | ||
| 21 | for (IotAlertLog iotAlertLog:list) | 40 | for (IotAlertLog iotAlertLog:list) |
| 22 | { | 41 | { |
| 42 | + if(null == iotAlertLog.getUser_id()) | ||
| 43 | + { | ||
| 44 | + notids.add(iotAlertLog.getAlert_log_id()); | ||
| 45 | + continue; | ||
| 46 | + } | ||
| 23 | switch (iotAlertLog.getAlert_level()) | 47 | switch (iotAlertLog.getAlert_level()) |
| 24 | { | 48 | { |
| 25 | case 1: //轻微问题 | 49 | case 1: //轻微问题 |
| 26 | notids.add(iotAlertLog.getAlert_log_id()); | 50 | notids.add(iotAlertLog.getAlert_log_id()); |
| 27 | break; | 51 | break; |
| 28 | case 2: //提醒通知 | 52 | case 2: //提醒通知 |
| 53 | + if(NoticeFactory.notice(iotAlertLog)) | ||
| 54 | + { | ||
| 29 | ids.add(iotAlertLog.getAlert_log_id()); | 55 | ids.add(iotAlertLog.getAlert_log_id()); |
| 30 | - notice(iotAlertLog); | 56 | + }else { |
| 57 | + notids.add(iotAlertLog.getAlert_log_id()); | ||
| 58 | + } | ||
| 31 | break; | 59 | break; |
| 32 | case 3: //严重警告 | 60 | case 3: //严重警告 |
| 61 | + | ||
| 62 | + if(NoticeFactory.request(iotAlertLog)) | ||
| 63 | + { | ||
| 33 | ids.add(iotAlertLog.getAlert_log_id()); | 64 | ids.add(iotAlertLog.getAlert_log_id()); |
| 65 | + }else{ | ||
| 66 | + notids.add(iotAlertLog.getAlert_log_id()); | ||
| 67 | + } | ||
| 34 | break; | 68 | break; |
| 35 | default: | 69 | default: |
| 36 | notids.add(iotAlertLog.getAlert_log_id()); | 70 | notids.add(iotAlertLog.getAlert_log_id()); |
| 37 | break; | 71 | break; |
| 38 | } | 72 | } |
| 39 | } | 73 | } |
| 74 | + if(ids.size()!=0) | ||
| 75 | + { | ||
| 40 | DbOperateUtil.updateIotAlertLogStatus(ids,3); | 76 | DbOperateUtil.updateIotAlertLogStatus(ids,3); |
| 77 | + } | ||
| 78 | + if(notids.size()!=0) | ||
| 79 | + { | ||
| 41 | DbOperateUtil.updateIotAlertLogStatus(notids,1); | 80 | DbOperateUtil.updateIotAlertLogStatus(notids,1); |
| 42 | } | 81 | } |
| 43 | } | 82 | } |
| 44 | - | ||
| 45 | - public static void notice(IotAlertLog iotAlertLog) | ||
| 46 | - { | ||
| 47 | - | 83 | + logger.info("发送任务执行完成"); |
| 48 | } | 84 | } |
| 49 | 85 | ||
| 50 | } | 86 | } |
| @@ -7,10 +7,12 @@ import com.alibaba.otter.canal.protocol.CanalEntry.Entry; | @@ -7,10 +7,12 @@ import com.alibaba.otter.canal.protocol.CanalEntry.Entry; | ||
| 7 | import com.alibaba.otter.canal.protocol.CanalEntry.EntryType; | 7 | import com.alibaba.otter.canal.protocol.CanalEntry.EntryType; |
| 8 | import com.alibaba.otter.canal.protocol.CanalEntry.RowChange; | 8 | import com.alibaba.otter.canal.protocol.CanalEntry.RowChange; |
| 9 | import com.alibaba.otter.canal.protocol.CanalEntry.RowData; | 9 | import com.alibaba.otter.canal.protocol.CanalEntry.RowData; |
| 10 | +import com.google.protobuf.InvalidProtocolBufferException; | ||
| 10 | import com.zhonglai.luhui.alarm.clas.UpAlarmFactory; | 11 | import com.zhonglai.luhui.alarm.clas.UpAlarmFactory; |
| 11 | import com.zhonglai.luhui.alarm.config.CachAlarmConfig; | 12 | import com.zhonglai.luhui.alarm.config.CachAlarmConfig; |
| 12 | import com.zhonglai.luhui.alarm.dao.DbOperateUtil; | 13 | import com.zhonglai.luhui.alarm.dao.DbOperateUtil; |
| 13 | import com.zhonglai.luhui.alarm.dto.IotAlertLog; | 14 | import com.zhonglai.luhui.alarm.dto.IotAlertLog; |
| 15 | +import com.zhonglai.luhui.alarm.util.ThreadPoolUtil; | ||
| 14 | import org.slf4j.Logger; | 16 | import org.slf4j.Logger; |
| 15 | import org.slf4j.LoggerFactory; | 17 | import org.slf4j.LoggerFactory; |
| 16 | 18 | ||
| @@ -24,13 +26,10 @@ import java.util.concurrent.*; | @@ -24,13 +26,10 @@ import java.util.concurrent.*; | ||
| 24 | */ | 26 | */ |
| 25 | public class TriggerAlarmService { | 27 | public class TriggerAlarmService { |
| 26 | private static final Logger logger = LoggerFactory.getLogger(TriggerAlarmService.class); | 28 | private static final Logger logger = LoggerFactory.getLogger(TriggerAlarmService.class); |
| 27 | - private static int poolSize = 100; // 线程池大小 | ||
| 28 | - private static ScheduledExecutorService executor = Executors.newScheduledThreadPool(poolSize); | ||
| 29 | - private static Semaphore semaphore = new Semaphore(poolSize); // 信号量,许可数等于线程池大小 | ||
| 30 | 29 | ||
| 31 | // 创建Canal连接器 | 30 | // 创建Canal连接器 |
| 32 | private static CanalConnector connector = CanalConnectors.newSingleConnector( | 31 | private static CanalConnector connector = CanalConnectors.newSingleConnector( |
| 33 | - new InetSocketAddress("8.129.82.37", 11111), | 32 | + new InetSocketAddress("127.0.0.1", 11111), |
| 34 | "example", | 33 | "example", |
| 35 | "", | 34 | "", |
| 36 | "" | 35 | "" |
| @@ -38,18 +37,21 @@ public class TriggerAlarmService { | @@ -38,18 +37,21 @@ public class TriggerAlarmService { | ||
| 38 | 37 | ||
| 39 | public static void start() { | 38 | public static void start() { |
| 40 | 39 | ||
| 40 | + try { | ||
| 41 | + connect(); | ||
| 42 | + } catch (InterruptedException e) { | ||
| 43 | + throw new RuntimeException(e); | ||
| 44 | + } | ||
| 45 | + | ||
| 41 | // 异步获取数据 | 46 | // 异步获取数据 |
| 42 | - executor.scheduleWithFixedDelay(new Runnable() { | 47 | + ThreadPoolUtil.executor.scheduleWithFixedDelay(new Runnable() { |
| 43 | @Override | 48 | @Override |
| 44 | public void run() { | 49 | public void run() { |
| 45 | try { | 50 | try { |
| 46 | - semaphore.acquire(); // 获取信号量许可,如果没有可用许可则阻塞等待 | ||
| 47 | - connect(); | 51 | + handle(); |
| 48 | }catch (Exception e) | 52 | }catch (Exception e) |
| 49 | { | 53 | { |
| 50 | logger.info("触发告警业务异常",e); | 54 | logger.info("触发告警业务异常",e); |
| 51 | - }finally { | ||
| 52 | - semaphore.release(); // 释放信号量许可 | ||
| 53 | } | 55 | } |
| 54 | 56 | ||
| 55 | } | 57 | } |
| @@ -62,37 +64,40 @@ public class TriggerAlarmService { | @@ -62,37 +64,40 @@ public class TriggerAlarmService { | ||
| 62 | connector.connect(); | 64 | connector.connect(); |
| 63 | // 订阅指定的表(这里以database.table为例) | 65 | // 订阅指定的表(这里以database.table为例) |
| 64 | connector.subscribe("mqtt_broker\\.(iot_device|iot_terminal|iot_alert)"); | 66 | connector.subscribe("mqtt_broker\\.(iot_device|iot_terminal|iot_alert)"); |
| 67 | + } | ||
| 65 | 68 | ||
| 66 | - while (true) { | ||
| 67 | - semaphore.acquire(); // 获取信号量许可,如果没有可用许可则阻塞等待 | 69 | + private static void handle() throws InterruptedException { |
| 70 | + while (ThreadPoolUtil.executor.getPoolSize()-ThreadPoolUtil.executor.getActiveCount()>0) | ||
| 71 | + { | ||
| 72 | + logger.info("总线程数{},已使用线程数{},剩下线程数{}",ThreadPoolUtil.executor.getPoolSize(),ThreadPoolUtil.executor.getActiveCount(),ThreadPoolUtil.executor.getPoolSize()-ThreadPoolUtil.executor.getActiveCount()); | ||
| 68 | 73 | ||
| 69 | - executor.schedule(() -> { | ||
| 70 | // 获取指定数量的数据 | 74 | // 获取指定数量的数据 |
| 71 | Message message = connector.getWithoutAck(100); | 75 | Message message = connector.getWithoutAck(100); |
| 72 | long batchId = message.getId(); | 76 | long batchId = message.getId(); |
| 73 | int size = message.getEntries().size(); | 77 | int size = message.getEntries().size(); |
| 74 | - | 78 | + logger.info("拉取的数据库同步数据量{}",size); |
| 75 | if (batchId != -1 && size > 0) { | 79 | if (batchId != -1 && size > 0) { |
| 80 | + ThreadPoolUtil.executor.schedule(() -> { | ||
| 81 | + try { | ||
| 76 | processEntries(message.getEntries()); | 82 | processEntries(message.getEntries()); |
| 83 | + }catch (Exception e) | ||
| 84 | + { | ||
| 85 | + logger.info("数据处理异常"+message.toString(),e); | ||
| 86 | + } | ||
| 87 | + },0, TimeUnit.SECONDS); | ||
| 77 | } | 88 | } |
| 78 | - | ||
| 79 | // 确认消息被消费 | 89 | // 确认消息被消费 |
| 80 | connector.ack(batchId); | 90 | connector.ack(batchId); |
| 81 | - },0, TimeUnit.SECONDS); | ||
| 82 | - | ||
| 83 | } | 91 | } |
| 84 | } | 92 | } |
| 85 | 93 | ||
| 86 | - private static void processEntries(List<Entry> entries) { | 94 | + |
| 95 | + private static void processEntries(List<Entry> entries) throws InvalidProtocolBufferException { | ||
| 96 | + | ||
| 87 | List<IotAlertLog> list = new ArrayList<>(); | 97 | List<IotAlertLog> list = new ArrayList<>(); |
| 88 | for (Entry entry : entries) { | 98 | for (Entry entry : entries) { |
| 89 | if (entry.getEntryType() == EntryType.ROWDATA) { | 99 | if (entry.getEntryType() == EntryType.ROWDATA) { |
| 90 | - RowChange rowChange = null; | ||
| 91 | - try { | ||
| 92 | - rowChange = RowChange.parseFrom(entry.getStoreValue()); | ||
| 93 | - } catch (Exception e) { | ||
| 94 | - throw new RuntimeException("ERROR ## parser of eromanga-event has an error, data:" + entry.toString(), e); | ||
| 95 | - } | 100 | + RowChange rowChange = RowChange.parseFrom(entry.getStoreValue());; |
| 96 | // 获取数据库名和表名 | 101 | // 获取数据库名和表名 |
| 97 | String dbName = entry.getHeader().getSchemaName(); | 102 | String dbName = entry.getHeader().getSchemaName(); |
| 98 | String tableName = entry.getHeader().getTableName(); | 103 | String tableName = entry.getHeader().getTableName(); |
| @@ -124,16 +129,6 @@ public class TriggerAlarmService { | @@ -124,16 +129,6 @@ public class TriggerAlarmService { | ||
| 124 | { | 129 | { |
| 125 | // 断开连接 | 130 | // 断开连接 |
| 126 | connector.disconnect(); | 131 | connector.disconnect(); |
| 127 | - // 关闭调度器 | ||
| 128 | - executor.shutdown(); | ||
| 129 | - | ||
| 130 | - try { | ||
| 131 | - if (!executor.awaitTermination(5, TimeUnit.SECONDS)) { | ||
| 132 | - executor.shutdownNow(); | ||
| 133 | - } | ||
| 134 | - } catch (InterruptedException e) { | ||
| 135 | - executor.shutdownNow(); | ||
| 136 | - Thread.currentThread().interrupt(); | ||
| 137 | - } | 132 | + ThreadPoolUtil.close(); |
| 138 | } | 133 | } |
| 139 | } | 134 | } |
| 1 | package com.zhonglai.luhui.alarm.util; | 1 | package com.zhonglai.luhui.alarm.util; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.JSON; | ||
| 4 | +import com.alibaba.fastjson.JSONArray; | ||
| 5 | +import com.alibaba.fastjson.JSONObject; | ||
| 6 | + | ||
| 7 | +import java.math.BigDecimal; | ||
| 8 | + | ||
| 9 | +import static com.alibaba.fastjson.JSON.parseArray; | ||
| 10 | + | ||
| 3 | public class GenericComparator { | 11 | public class GenericComparator { |
| 4 | 12 | ||
| 5 | public static <T> boolean compare(T a, T b, String equation) { | 13 | public static <T> boolean compare(T a, T b, String equation) { |
| 6 | if (a == null || b == null || equation == null) { | 14 | if (a == null || b == null || equation == null) { |
| 7 | - throw new IllegalArgumentException("Arguments cannot be null"); | 15 | + return false; |
| 8 | } | 16 | } |
| 9 | 17 | ||
| 10 | if (!a.getClass().equals(b.getClass())) { | 18 | if (!a.getClass().equals(b.getClass())) { |
| 11 | - throw new IllegalArgumentException("Arguments must be of the same type"); | 19 | + b = (T) convertToType(b, a.getClass()); |
| 12 | } | 20 | } |
| 13 | 21 | ||
| 14 | Comparable<T> compA = (Comparable<T>) a; | 22 | Comparable<T> compA = (Comparable<T>) a; |
| @@ -32,13 +40,63 @@ public class GenericComparator { | @@ -32,13 +40,63 @@ public class GenericComparator { | ||
| 32 | } | 40 | } |
| 33 | } | 41 | } |
| 34 | 42 | ||
| 43 | + public static Object convertToType(Object obj, String targetType) { | ||
| 44 | + | ||
| 45 | + switch (targetType.toUpperCase()) | ||
| 46 | + { | ||
| 47 | + case "INTEGER": | ||
| 48 | + return new BigDecimal(obj.toString()); | ||
| 49 | + case "DECIMAL": | ||
| 50 | + return new BigDecimal(obj.toString()); | ||
| 51 | + case "BOOL": | ||
| 52 | + return Boolean.valueOf(obj.toString()); | ||
| 53 | + case "ARRAY": | ||
| 54 | + return obj.toString(); | ||
| 55 | + default: | ||
| 56 | + return obj; | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + private static Object convertToType(Object obj, Class<?> targetType) { | ||
| 61 | + if (targetType.isInstance(obj)) { | ||
| 62 | + return obj; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + if (targetType == Integer.class) { | ||
| 66 | + return Integer.valueOf(obj.toString()); | ||
| 67 | + } else if (targetType == Double.class) { | ||
| 68 | + return Double.valueOf(obj.toString()); | ||
| 69 | + } else if (targetType == Float.class) { | ||
| 70 | + return Float.valueOf(obj.toString()); | ||
| 71 | + } else if (targetType == Long.class) { | ||
| 72 | + return Long.valueOf(obj.toString()); | ||
| 73 | + } else if (targetType == Short.class) { | ||
| 74 | + return Short.valueOf(obj.toString()); | ||
| 75 | + } else if (targetType == Byte.class) { | ||
| 76 | + return Byte.valueOf(obj.toString()); | ||
| 77 | + } else if (targetType == Boolean.class) { | ||
| 78 | + return Boolean.valueOf(obj.toString()); | ||
| 79 | + } else if (targetType == Character.class) { | ||
| 80 | + return obj.toString().charAt(0); | ||
| 81 | + }else if(targetType == BigDecimal.class) | ||
| 82 | + { | ||
| 83 | + return new BigDecimal(obj.toString()); | ||
| 84 | + } | ||
| 85 | + else { | ||
| 86 | + return obj.toString(); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + } | ||
| 90 | + | ||
| 35 | public static void main(String[] args) { | 91 | public static void main(String[] args) { |
| 36 | // 示例测试 | 92 | // 示例测试 |
| 37 | - System.out.println(compare(5, 3, ">")); // true | ||
| 38 | - System.out.println(compare(5.5, 3.3, "==")); // false | ||
| 39 | - System.out.println(compare("apple", "banana", "<")); // true | ||
| 40 | - System.out.println(compare(5, 5, "==")); // true | ||
| 41 | - System.out.println(compare("a", "a", "==")); // true | ||
| 42 | - System.out.println(compare(5.5, 5.3, "<=")); // false | 93 | +// System.out.println(compare(5, "3", ">")); // true |
| 94 | +// System.out.println(compare(5.5, 3.3, "==")); // false | ||
| 95 | +// System.out.println(compare("apple", "banana", "<")); // true | ||
| 96 | +// System.out.println(compare(5, 5, "==")); // true | ||
| 97 | +// System.out.println(compare("a", "a", "==")); // true | ||
| 98 | +// System.out.println(compare(5.5, 5.3, "<=")); // false | ||
| 99 | + | ||
| 100 | + System.out.println(compare(new BigDecimal(5.3),"5.3", "<")); // false | ||
| 43 | } | 101 | } |
| 44 | } | 102 | } |
| 1 | +package com.zhonglai.luhui.alarm.util; | ||
| 2 | + | ||
| 3 | +import java.util.concurrent.ScheduledThreadPoolExecutor; | ||
| 4 | +import java.util.concurrent.TimeUnit; | ||
| 5 | + | ||
| 6 | +public class ThreadPoolUtil { | ||
| 7 | + private static int poolSize = 100; // 线程池大小 | ||
| 8 | + public static ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor (poolSize); | ||
| 9 | + | ||
| 10 | + public static void close() | ||
| 11 | + { | ||
| 12 | + // 关闭调度器 | ||
| 13 | + executor.shutdown(); | ||
| 14 | + | ||
| 15 | + try { | ||
| 16 | + if (!executor.awaitTermination(5, TimeUnit.SECONDS)) { | ||
| 17 | + executor.shutdownNow(); | ||
| 18 | + } | ||
| 19 | + } catch (InterruptedException e) { | ||
| 20 | + executor.shutdownNow(); | ||
| 21 | + Thread.currentThread().interrupt(); | ||
| 22 | + } | ||
| 23 | + } | ||
| 24 | +} |
| @@ -69,6 +69,10 @@ | @@ -69,6 +69,10 @@ | ||
| 69 | <groupId>org.aspectj</groupId> | 69 | <groupId>org.aspectj</groupId> |
| 70 | <artifactId>aspectjrt</artifactId> | 70 | <artifactId>aspectjrt</artifactId> |
| 71 | </dependency> | 71 | </dependency> |
| 72 | + <dependency> | ||
| 73 | + <groupId>com.zhonglai</groupId> | ||
| 74 | + <artifactId>weixin-api</artifactId> | ||
| 75 | + </dependency> | ||
| 72 | </dependencies> | 76 | </dependencies> |
| 73 | 77 | ||
| 74 | <build> | 78 | <build> |
| @@ -8,14 +8,17 @@ import com.ruoyi.common.core.domain.Message; | @@ -8,14 +8,17 @@ import com.ruoyi.common.core.domain.Message; | ||
| 8 | import com.ruoyi.common.enums.BusinessType; | 8 | import com.ruoyi.common.enums.BusinessType; |
| 9 | import com.ruoyi.common.utils.GsonConstructor; | 9 | import com.ruoyi.common.utils.GsonConstructor; |
| 10 | import com.zhonglai.luhui.action.BaseController; | 10 | import com.zhonglai.luhui.action.BaseController; |
| 11 | +import com.zhonglai.luhui.device.domain.IotDevice; | ||
| 11 | import com.zhonglai.luhui.device.dto.CommandType; | 12 | import com.zhonglai.luhui.device.dto.CommandType; |
| 12 | import com.zhonglai.luhui.device.dto.DeviceCommand; | 13 | import com.zhonglai.luhui.device.dto.DeviceCommand; |
| 14 | +import com.zhonglai.luhui.device.service.IIotDeviceService; | ||
| 13 | import com.zhonglai.luhui.rocketmq.service.RocketMqService; | 15 | import com.zhonglai.luhui.rocketmq.service.RocketMqService; |
| 14 | import io.swagger.annotations.Api; | 16 | import io.swagger.annotations.Api; |
| 15 | import io.swagger.annotations.ApiImplicitParam; | 17 | import io.swagger.annotations.ApiImplicitParam; |
| 16 | import io.swagger.annotations.ApiImplicitParams; | 18 | import io.swagger.annotations.ApiImplicitParams; |
| 17 | import io.swagger.annotations.ApiOperation; | 19 | import io.swagger.annotations.ApiOperation; |
| 18 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
| 21 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 19 | import org.springframework.util.StreamUtils; | 22 | import org.springframework.util.StreamUtils; |
| 20 | import org.springframework.web.bind.annotation.PathVariable; | 23 | import org.springframework.web.bind.annotation.PathVariable; |
| 21 | import org.springframework.web.bind.annotation.PostMapping; | 24 | import org.springframework.web.bind.annotation.PostMapping; |
| @@ -25,12 +28,15 @@ import org.springframework.web.bind.annotation.RestController; | @@ -25,12 +28,15 @@ import org.springframework.web.bind.annotation.RestController; | ||
| 25 | import javax.servlet.http.HttpServletRequest; | 28 | import javax.servlet.http.HttpServletRequest; |
| 26 | import java.io.IOException; | 29 | import java.io.IOException; |
| 27 | 30 | ||
| 28 | -@Api(tags = "设备控制") | 31 | +@Api(tags = "控制器") |
| 29 | @RestController | 32 | @RestController |
| 30 | @RequestMapping("/iot/controlDevice") | 33 | @RequestMapping("/iot/controlDevice") |
| 31 | public class ControlDeviceConreoller extends BaseController { | 34 | public class ControlDeviceConreoller extends BaseController { |
| 32 | @Autowired | 35 | @Autowired |
| 33 | private RocketMqService rocketMqService; | 36 | private RocketMqService rocketMqService; |
| 37 | + | ||
| 38 | + @Autowired | ||
| 39 | + private IIotDeviceService iotDeviceService; | ||
| 34 | @ApiOperation(value = "写指令",notes = "body参数描述:\r\n" + | 40 | @ApiOperation(value = "写指令",notes = "body参数描述:\r\n" + |
| 35 | "{\n" + | 41 | "{\n" + |
| 36 | " \"0\":{\n" + | 42 | " \"0\":{\n" + |
| @@ -64,7 +70,45 @@ public class ControlDeviceConreoller extends BaseController { | @@ -64,7 +70,45 @@ public class ControlDeviceConreoller extends BaseController { | ||
| 64 | deviceCommand.setDeviceId(deviceId); | 70 | deviceCommand.setDeviceId(deviceId); |
| 65 | deviceCommand.setCommandType(CommandType.write); | 71 | deviceCommand.setCommandType(CommandType.write); |
| 66 | deviceCommand.setData(GsonConstructor.get().fromJson(body,JsonObject.class)); | 72 | deviceCommand.setData(GsonConstructor.get().fromJson(body,JsonObject.class)); |
| 67 | - return control(deviceCommand); | 73 | + |
| 74 | + return deviceControl(deviceCommand); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + @ApiOperation(value = "读指令",notes = "body参数描述:\r\n" + | ||
| 78 | + "{\n" + | ||
| 79 | + " \"0\":{\n" + | ||
| 80 | + " \"rssi\": -43,\n" + | ||
| 81 | + " \"firmware_version\": 1.2,\n" + | ||
| 82 | + " \"longitude\": 0,\n" + | ||
| 83 | + " \"latitude\": 0,\n" + | ||
| 84 | + " \"summary\": {\n" + | ||
| 85 | + " \t \"name\": \"wumei-smart\",\n" + | ||
| 86 | + " \t \"chip\": \"esp8266\",\n" + | ||
| 87 | + " \t \"author\": \"kerwincui\",\n" + | ||
| 88 | + " \t \"version\": 1.2,\n" + | ||
| 89 | + " \t \"createTime\": \"2022-06-06\"\n" + | ||
| 90 | + " }\n" + | ||
| 91 | + " },\n" + | ||
| 92 | + " \"1\":{\n" + | ||
| 93 | + " \"id1\":\"value1\",\n" + | ||
| 94 | + " \"id2\":\"value2\",\n" + | ||
| 95 | + " \"id3\":\"value3\"\n" + | ||
| 96 | + " }\n" + | ||
| 97 | + "}") | ||
| 98 | + @ApiImplicitParams({ | ||
| 99 | + @ApiImplicitParam(value = "网关id",name = "deviceId"), | ||
| 100 | + }) | ||
| 101 | + @Log(title = "读指令", businessType = BusinessType.WRITE) | ||
| 102 | + @PostMapping("/read/{deviceId}") | ||
| 103 | + public AjaxResult read(@PathVariable String deviceId, HttpServletRequest request) throws IOException { | ||
| 104 | + | ||
| 105 | + byte[] bodyBytes = StreamUtils.copyToByteArray(request.getInputStream()); | ||
| 106 | + String body = new String(bodyBytes, request.getCharacterEncoding()); | ||
| 107 | + DeviceCommand deviceCommand = new DeviceCommand(); | ||
| 108 | + deviceCommand.setDeviceId(deviceId); | ||
| 109 | + deviceCommand.setCommandType(CommandType.write); | ||
| 110 | + deviceCommand.setData(GsonConstructor.get().fromJson(body,JsonObject.class)); | ||
| 111 | + return deviceControl(deviceCommand); | ||
| 68 | } | 112 | } |
| 69 | 113 | ||
| 70 | @ApiOperation("更新缓存模型") | 114 | @ApiOperation("更新缓存模型") |
| @@ -77,7 +121,7 @@ public class ControlDeviceConreoller extends BaseController { | @@ -77,7 +121,7 @@ public class ControlDeviceConreoller extends BaseController { | ||
| 77 | JsonObject jsonObject = new JsonObject(); | 121 | JsonObject jsonObject = new JsonObject(); |
| 78 | jsonObject.addProperty("product_id",product_id); | 122 | jsonObject.addProperty("product_id",product_id); |
| 79 | deviceCommand.setData(jsonObject); | 123 | deviceCommand.setData(jsonObject); |
| 80 | - return control(deviceCommand); | 124 | + return sysControl(deviceCommand); |
| 81 | } | 125 | } |
| 82 | 126 | ||
| 83 | @ApiOperation("更新缓存翻译模型") | 127 | @ApiOperation("更新缓存翻译模型") |
| @@ -90,7 +134,7 @@ public class ControlDeviceConreoller extends BaseController { | @@ -90,7 +134,7 @@ public class ControlDeviceConreoller extends BaseController { | ||
| 90 | JsonObject jsonObject = new JsonObject(); | 134 | JsonObject jsonObject = new JsonObject(); |
| 91 | jsonObject.addProperty("product_id",product_id); | 135 | jsonObject.addProperty("product_id",product_id); |
| 92 | deviceCommand.setData(jsonObject); | 136 | deviceCommand.setData(jsonObject); |
| 93 | - return control(deviceCommand); | 137 | + return sysControl(deviceCommand); |
| 94 | } | 138 | } |
| 95 | 139 | ||
| 96 | @ApiOperation("清除网关缓存") | 140 | @ApiOperation("清除网关缓存") |
| @@ -101,7 +145,7 @@ public class ControlDeviceConreoller extends BaseController { | @@ -101,7 +145,7 @@ public class ControlDeviceConreoller extends BaseController { | ||
| 101 | DeviceCommand deviceCommand = new DeviceCommand(); | 145 | DeviceCommand deviceCommand = new DeviceCommand(); |
| 102 | deviceCommand.setDeviceId(deviceId); | 146 | deviceCommand.setDeviceId(deviceId); |
| 103 | deviceCommand.setCommandType(CommandType.cleanDeviceHost); | 147 | deviceCommand.setCommandType(CommandType.cleanDeviceHost); |
| 104 | - return control(deviceCommand); | 148 | + return sysControl(deviceCommand); |
| 105 | } | 149 | } |
| 106 | 150 | ||
| 107 | @ApiOperation("更新终端缓存") | 151 | @ApiOperation("更新终端缓存") |
| @@ -118,13 +162,68 @@ public class ControlDeviceConreoller extends BaseController { | @@ -118,13 +162,68 @@ public class ControlDeviceConreoller extends BaseController { | ||
| 118 | JsonObject jsonObject = new JsonObject(); | 162 | JsonObject jsonObject = new JsonObject(); |
| 119 | jsonObject.addProperty("sensor_number",sensor_number); | 163 | jsonObject.addProperty("sensor_number",sensor_number); |
| 120 | deviceCommand.setData(jsonObject); | 164 | deviceCommand.setData(jsonObject); |
| 121 | - return control(deviceCommand); | 165 | + return sysControl(deviceCommand); |
| 122 | } | 166 | } |
| 123 | 167 | ||
| 168 | + @ApiOperation("添加订阅") | ||
| 169 | + @ApiImplicitParams({ | ||
| 170 | + @ApiImplicitParam(value = "监听服务器的ip",name = "ip"), | ||
| 171 | + @ApiImplicitParam(value = "产品集合",name = "product_ids"), | ||
| 172 | + }) | ||
| 173 | + @Log(title = "添加订阅", businessType = BusinessType.CAHE) | ||
| 174 | + @PostMapping("/addSubscribe") | ||
| 175 | + public AjaxResult addSubscribe(String product_ids,String ip) { | ||
| 176 | + DeviceCommand deviceCommand = new DeviceCommand(); | ||
| 177 | + deviceCommand.setCommandType(CommandType.addSubscribe); | ||
| 178 | + JsonObject jsonObject = new JsonObject(); | ||
| 179 | + jsonObject.addProperty("product_ids",product_ids); | ||
| 180 | + jsonObject.addProperty("ip",ip); | ||
| 181 | + deviceCommand.setData(jsonObject); | ||
| 182 | + return sysControl(deviceCommand); | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + @ApiOperation(value = "通知",notes = "body参数描述:\r\n" + | ||
| 186 | + "{\n" + | ||
| 187 | + " \"1\":{\n" + | ||
| 188 | + " \"id1\":\"value1\",\n" + | ||
| 189 | + " \"id2\":\"value2\",\n" + | ||
| 190 | + " \"id3\":\"value3\"\n" + | ||
| 191 | + " }\n" + | ||
| 192 | + "}") | ||
| 193 | + @ApiImplicitParams({ | ||
| 194 | + @ApiImplicitParam(value = "网关id",name = "deviceId"), | ||
| 195 | + }) | ||
| 196 | + @Log(title = "通知", businessType = BusinessType.CAHE) | ||
| 197 | + @PostMapping("/notice/{deviceId}") | ||
| 198 | + public AjaxResult notice(@PathVariable String deviceId, HttpServletRequest request) throws IOException { | ||
| 199 | + byte[] bodyBytes = StreamUtils.copyToByteArray(request.getInputStream()); | ||
| 200 | + String body = new String(bodyBytes, request.getCharacterEncoding()); | ||
| 201 | + DeviceCommand deviceCommand = new DeviceCommand(); | ||
| 202 | + deviceCommand.setDeviceId(deviceId); | ||
| 203 | + deviceCommand.setCommandType(CommandType.notice); | ||
| 204 | + deviceCommand.setData(GsonConstructor.get().fromJson(body,JsonObject.class)); | ||
| 205 | + return deviceControl(deviceCommand); | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + private AjaxResult deviceControl(DeviceCommand deviceCommand) | ||
| 209 | + { | ||
| 210 | + IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(deviceCommand.getDeviceId()); | ||
| 211 | + if(null == iotDevice || iotDevice.getStatus()!=3) | ||
| 212 | + { | ||
| 213 | + return AjaxResult.error("设备不存在或者不在线"); | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + Message message = rocketMqService.send("deviceCommandListen",GsonConstructor.get().toJson(deviceCommand).getBytes(),iotDevice.getOperation_token()); | ||
| 217 | + if(message.getCode()==1) | ||
| 218 | + { | ||
| 219 | + return new AjaxResult(HttpStatus.SUCCESS, message.getMessage(), message.getData()); | ||
| 220 | + } | ||
| 221 | + return new AjaxResult(HttpStatus.ERROR, message.getMessage(), message.getData()); | ||
| 222 | + } | ||
| 124 | 223 | ||
| 125 | - private AjaxResult control( DeviceCommand deviceCommand) | 224 | + private AjaxResult sysControl(DeviceCommand deviceCommand) |
| 126 | { | 225 | { |
| 127 | - Message message = rocketMqService.send("deviceCommandListen",GsonConstructor.get().toJson(deviceCommand).getBytes()); | 226 | + Message message = rocketMqService.send("deviceCommandListen",GsonConstructor.get().toJson(deviceCommand).getBytes(),"SysCommand"); |
| 128 | if(message.getCode()==1) | 227 | if(message.getCode()==1) |
| 129 | { | 228 | { |
| 130 | return new AjaxResult(HttpStatus.SUCCESS, message.getMessage(), message.getData()); | 229 | return new AjaxResult(HttpStatus.SUCCESS, message.getMessage(), message.getData()); |
| @@ -39,6 +39,8 @@ public class IotTerminalController extends BaseController | @@ -39,6 +39,8 @@ public class IotTerminalController extends BaseController | ||
| 39 | private IIotTerminalService iotTerminalService; | 39 | private IIotTerminalService iotTerminalService; |
| 40 | @Autowired | 40 | @Autowired |
| 41 | private IUserTerminalGroupRelationService userTerminalGroupRelationService; | 41 | private IUserTerminalGroupRelationService userTerminalGroupRelationService; |
| 42 | + @Autowired | ||
| 43 | + private PublicService publicService; | ||
| 42 | @ApiOperation("查询终端列表") | 44 | @ApiOperation("查询终端列表") |
| 43 | @GetMapping("/list") | 45 | @GetMapping("/list") |
| 44 | public TableDataInfo list(IotTerminal iotTerminal) | 46 | public TableDataInfo list(IotTerminal iotTerminal) |
| @@ -91,6 +93,33 @@ public class IotTerminalController extends BaseController | @@ -91,6 +93,33 @@ public class IotTerminalController extends BaseController | ||
| 91 | return toAjax(iotTerminalService.updateIotTerminal(iotTerminal)); | 93 | return toAjax(iotTerminalService.updateIotTerminal(iotTerminal)); |
| 92 | } | 94 | } |
| 93 | 95 | ||
| 96 | + @ApiOperation("删除") | ||
| 97 | + @ApiImplicitParams({ | ||
| 98 | + @ApiImplicitParam(value = "终端id",name = "id"), | ||
| 99 | + }) | ||
| 100 | + @Log(title = "删除", businessType = BusinessType.DELETE) | ||
| 101 | + @Transactional | ||
| 102 | + @PostMapping("/del") | ||
| 103 | + public AjaxResult del(String id) | ||
| 104 | + { | ||
| 105 | + IotTerminal iotTerminal = iotTerminalService.selectIotTerminalById(id); | ||
| 106 | + if(null == iotTerminal) | ||
| 107 | + { | ||
| 108 | + return AjaxResult.error("终端不存在"); | ||
| 109 | + } | ||
| 110 | + Integer userid= SecurityUtils.getUserId().intValue(); | ||
| 111 | + | ||
| 112 | + if(null!=iotTerminal.getUser_info_id() && iotTerminal.getUser_info_id()-userid!=0) | ||
| 113 | + { | ||
| 114 | + return AjaxResult.error("该设备不是你的无法删除"); | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + publicService.updateBySql("update iot_terminal set user_info_id=null where id='"+id+"'"); | ||
| 118 | + publicService.updateBySql("DELETE FROM `user_terminal_group_relation` WHERE user_info_id="+userid+" AND iot_terminal_id='"+id+"'"); | ||
| 119 | + | ||
| 120 | + return toAjax(iotTerminalService.updateIotTerminal(iotTerminal)); | ||
| 121 | + } | ||
| 122 | + | ||
| 94 | @ApiOperation("分组终端") | 123 | @ApiOperation("分组终端") |
| 95 | @ApiImplicitParams({ | 124 | @ApiImplicitParams({ |
| 96 | @ApiImplicitParam(value = "分组id",name = "iot_terminal_group_id"), | 125 | @ApiImplicitParam(value = "分组id",name = "iot_terminal_group_id"), |
| @@ -124,7 +153,7 @@ public class IotTerminalController extends BaseController | @@ -124,7 +153,7 @@ public class IotTerminalController extends BaseController | ||
| 124 | { | 153 | { |
| 125 | return AjaxResult.error("请给所有设备都设置名称"); | 154 | return AjaxResult.error("请给所有设备都设置名称"); |
| 126 | } | 155 | } |
| 127 | - iotTerminalService.batchUpName(ids,names); | 156 | + iotTerminalService.batchUpName(ids,names,userid); |
| 128 | return toAjax( userTerminalGroupRelationService.groupTerminal(iot_terminal_group_id,ids,userid)); | 157 | return toAjax( userTerminalGroupRelationService.groupTerminal(iot_terminal_group_id,ids,userid)); |
| 129 | } | 158 | } |
| 130 | } | 159 | } |
lh-modules/lh-api/src/main/java/com/zhonglai/luhui/api/controller/user/UserInfoController.java
0 → 100644
| 1 | +package com.zhonglai.luhui.api.controller.user; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | +import com.ruoyi.common.annotation.Log; | ||
| 5 | +import com.ruoyi.common.core.domain.AjaxResult; | ||
| 6 | +import com.ruoyi.common.enums.BusinessType; | ||
| 7 | +import com.ruoyi.common.utils.StringUtils; | ||
| 8 | +import com.ruoyi.system.domain.user.UserOpenid; | ||
| 9 | +import com.zhonglai.luhui.action.BaseController; | ||
| 10 | +import com.zhonglai.luhui.dao.service.PublicService; | ||
| 11 | +import com.zhonglai.luhui.device.domain.IotAlertNoticeChannel; | ||
| 12 | +import com.zhonglai.luhui.device.domain.IotAlertUserNotice; | ||
| 13 | +import com.zhonglai.luhui.device.dto.WeiXinGongZhongHaoNoticeDto; | ||
| 14 | +import com.zhonglai.luhui.security.utils.SecurityUtils; | ||
| 15 | +import io.swagger.annotations.Api; | ||
| 16 | +import io.swagger.annotations.ApiImplicitParam; | ||
| 17 | +import io.swagger.annotations.ApiImplicitParams; | ||
| 18 | +import io.swagger.annotations.ApiOperation; | ||
| 19 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 20 | +import org.springframework.transaction.annotation.Transactional; | ||
| 21 | +import org.springframework.web.bind.annotation.*; | ||
| 22 | +import weixin.popular.api.SnsAPI; | ||
| 23 | +import weixin.popular.bean.sns.SnsToken; | ||
| 24 | + | ||
| 25 | +import javax.servlet.http.HttpServletRequest; | ||
| 26 | +import java.io.UnsupportedEncodingException; | ||
| 27 | +import java.net.URLEncoder; | ||
| 28 | + | ||
| 29 | + | ||
| 30 | +@Api(tags = "用户管理") | ||
| 31 | +@RestController | ||
| 32 | +@RequestMapping("/user/userInfo") | ||
| 33 | +public class UserInfoController extends BaseController { | ||
| 34 | + @Autowired | ||
| 35 | + private PublicService publicService; | ||
| 36 | + | ||
| 37 | + @ApiOperation("提交小程序或者微信公众号通知服务") | ||
| 38 | + @ApiImplicitParams({ | ||
| 39 | + @ApiImplicitParam(value = "渠道id(管理员提供)",name = "channel_id"), | ||
| 40 | + @ApiImplicitParam(value = "授权获取到的code",name = "code"), | ||
| 41 | + }) | ||
| 42 | + @Log(title = "提交小程序或者微信公众号通知服务", businessType = BusinessType.INSERT) | ||
| 43 | + @Transactional | ||
| 44 | + @PostMapping(value = "subXcxNoticeService/{channel_id}") | ||
| 45 | + public AjaxResult subXcxNoticeService(@PathVariable Integer channel_id, String code) | ||
| 46 | + { | ||
| 47 | + //检查渠道是否存在 | ||
| 48 | + IotAlertNoticeChannel iotAlertNoticeChannel = publicService.getObject(IotAlertNoticeChannel.class,"id",channel_id+""); | ||
| 49 | + if(null == iotAlertNoticeChannel) | ||
| 50 | + { | ||
| 51 | + return AjaxResult.error("通知渠道不存在"); | ||
| 52 | + } | ||
| 53 | + if(iotAlertNoticeChannel.getType()!=1) | ||
| 54 | + { | ||
| 55 | + return AjaxResult.error("该渠道不是公众号通知渠道"); | ||
| 56 | + } | ||
| 57 | + WeiXinGongZhongHaoNoticeDto weiXinGongZhongHaoNoticeDto = JSONObject.parseObject(iotAlertNoticeChannel.getConfig(),WeiXinGongZhongHaoNoticeDto.class); | ||
| 58 | + | ||
| 59 | + Integer user_id = SecurityUtils.getUserId().intValue(); | ||
| 60 | + SnsToken snsToken = SnsAPI.oauth2AccessToken(weiXinGongZhongHaoNoticeDto.getGzhappid(), weiXinGongZhongHaoNoticeDto.getGzhsecret(),code); | ||
| 61 | + if(StringUtils.isEmpty(snsToken.getOpenid())) | ||
| 62 | + { | ||
| 63 | + return AjaxResult.error("公众号授权失败"); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + //更新用户openid表 | ||
| 67 | + UserOpenid userOpenid = new UserOpenid(); | ||
| 68 | + userOpenid.setUser_id(user_id); | ||
| 69 | + userOpenid.setOpenid(snsToken.getOpenid()); | ||
| 70 | + userOpenid.setXcx_config_id(weiXinGongZhongHaoNoticeDto.getXcxConfigId()); | ||
| 71 | + Long ct = publicService.getObjectListTotle(userOpenid,null); | ||
| 72 | + if(0 == ct) | ||
| 73 | + { | ||
| 74 | + publicService.insert(userOpenid); | ||
| 75 | + } | ||
| 76 | + //更新用户通知 | ||
| 77 | + IotAlertUserNotice iotAlertUserNotice = new IotAlertUserNotice(); | ||
| 78 | + iotAlertUserNotice.setUser_id(user_id); | ||
| 79 | + ct = publicService.getObjectListTotle(userOpenid,null); | ||
| 80 | + if(0 < ct) | ||
| 81 | + { | ||
| 82 | + return AjaxResult.success("您已经开通过通知服务了,请到通知服务编辑页面进行编辑"); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + IotAlertUserNotice sysIotAlertUserNotice = new IotAlertUserNotice(); | ||
| 86 | + sysIotAlertUserNotice.setChannels(channel_id+""); | ||
| 87 | + sysIotAlertUserNotice.setType(1); | ||
| 88 | + sysIotAlertUserNotice.setUser_id(user_id); | ||
| 89 | + publicService.insert(sysIotAlertUserNotice); | ||
| 90 | + | ||
| 91 | + IotAlertUserNotice userIotAlertUserNotice = new IotAlertUserNotice(); | ||
| 92 | + userIotAlertUserNotice.setChannels(channel_id+""); | ||
| 93 | + userIotAlertUserNotice.setType(2); | ||
| 94 | + userIotAlertUserNotice.setUser_id(user_id); | ||
| 95 | + publicService.insert(userIotAlertUserNotice); | ||
| 96 | + return AjaxResult.success(); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + @ApiOperation("生成告警授权连接") | ||
| 100 | + @RequestMapping(value = "getAlarmOauth2URL/{channel_id}", method = RequestMethod.GET) | ||
| 101 | + public AjaxResult getAlarmOauth2URL(@PathVariable Integer channel_id, @RequestParam(value="redirect_uri") String redirect_uri,String state) | ||
| 102 | + { | ||
| 103 | + //检查渠道是否存在 | ||
| 104 | + IotAlertNoticeChannel iotAlertNoticeChannel = publicService.getObject(IotAlertNoticeChannel.class,"id",channel_id+""); | ||
| 105 | + if(null == iotAlertNoticeChannel) | ||
| 106 | + { | ||
| 107 | + return AjaxResult.error("通知渠道不存在"); | ||
| 108 | + } | ||
| 109 | + if(iotAlertNoticeChannel.getType()!=1) | ||
| 110 | + { | ||
| 111 | + return AjaxResult.error("该渠道不是公众号通知渠道"); | ||
| 112 | + } | ||
| 113 | + WeiXinGongZhongHaoNoticeDto weiXinGongZhongHaoNoticeDto = JSONObject.parseObject(iotAlertNoticeChannel.getConfig(),WeiXinGongZhongHaoNoticeDto.class); | ||
| 114 | + String authorizeUrl = SnsAPI.connectOauth2Authorize(weiXinGongZhongHaoNoticeDto.getGzhappid(), redirect_uri, true, state); | ||
| 115 | + return AjaxResult.success("",authorizeUrl); | ||
| 116 | + } | ||
| 117 | +} |
| @@ -27,6 +27,7 @@ public class ProtocolParserServiceImpl implements ProtocolParserFactory<JsonObje | @@ -27,6 +27,7 @@ public class ProtocolParserServiceImpl implements ProtocolParserFactory<JsonObje | ||
| 27 | case "ONLINE": | 27 | case "ONLINE": |
| 28 | return new Online().analysisPayload(payload); | 28 | return new Online().analysisPayload(payload); |
| 29 | case "ALL_POST": | 29 | case "ALL_POST": |
| 30 | + topic.setAllup(true); | ||
| 30 | return new AllPost().analysisPayload(payload); | 31 | return new AllPost().analysisPayload(payload); |
| 31 | case "ADD_POST": | 32 | case "ADD_POST": |
| 32 | return new AddPost().analysisPayload(payload); | 33 | return new AddPost().analysisPayload(payload); |
| @@ -62,6 +62,7 @@ public class ProtocolParserAndPurificationFactory<T> { | @@ -62,6 +62,7 @@ public class ProtocolParserAndPurificationFactory<T> { | ||
| 62 | ProtocolPurificationModel protocolPurificationModel = protocolPurificationFactory.purification(iotProduct.getId(),topic,analysisResult); | 62 | ProtocolPurificationModel protocolPurificationModel = protocolPurificationFactory.purification(iotProduct.getId(),topic,analysisResult); |
| 63 | protocolPurificationModel.setNoticeClien(analysisResult.isNoticeClien()); | 63 | protocolPurificationModel.setNoticeClien(analysisResult.isNoticeClien()); |
| 64 | protocolPurificationModel.setNoticeMessage(analysisResult.getNoticeMessage()); | 64 | protocolPurificationModel.setNoticeMessage(analysisResult.getNoticeMessage()); |
| 65 | + protocolPurificationModel.setAllUp(topic.isAllup()); | ||
| 65 | return protocolPurificationModel; | 66 | return protocolPurificationModel; |
| 66 | 67 | ||
| 67 | } | 68 | } |
| @@ -26,6 +26,7 @@ public class DefaultProtocolParserFactoryImpl implements ProtocolParserFactory<b | @@ -26,6 +26,7 @@ public class DefaultProtocolParserFactoryImpl implements ProtocolParserFactory<b | ||
| 26 | case "ONLINE": | 26 | case "ONLINE": |
| 27 | return new Online().analysisPayload(payload); | 27 | return new Online().analysisPayload(payload); |
| 28 | case "ALL_POST": | 28 | case "ALL_POST": |
| 29 | + topic.setAllup(true); | ||
| 29 | return new AllPost().analysisPayload(payload); | 30 | return new AllPost().analysisPayload(payload); |
| 30 | case "ADD_POST": | 31 | case "ADD_POST": |
| 31 | return new AddPost().analysisPayload(payload); | 32 | return new AddPost().analysisPayload(payload); |
| 1 | package com.zhonglai.luhui.device.protocol.factory.config; | 1 | package com.zhonglai.luhui.device.protocol.factory.config; |
| 2 | 2 | ||
| 3 | import com.google.gson.JsonObject; | 3 | import com.google.gson.JsonObject; |
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 4 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | 5 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; |
| 5 | import net.jodah.expiringmap.ExpirationListener; | 6 | import net.jodah.expiringmap.ExpirationListener; |
| 6 | import net.jodah.expiringmap.ExpirationPolicy; | 7 | import net.jodah.expiringmap.ExpirationPolicy; |
| @@ -8,6 +9,8 @@ import net.jodah.expiringmap.ExpiringMap; | @@ -8,6 +9,8 @@ import net.jodah.expiringmap.ExpiringMap; | ||
| 8 | import org.slf4j.Logger; | 9 | import org.slf4j.Logger; |
| 9 | import org.slf4j.LoggerFactory; | 10 | import org.slf4j.LoggerFactory; |
| 10 | 11 | ||
| 12 | +import java.util.HashMap; | ||
| 13 | +import java.util.Map; | ||
| 11 | import java.util.concurrent.TimeUnit; | 14 | import java.util.concurrent.TimeUnit; |
| 12 | 15 | ||
| 13 | /** | 16 | /** |
| @@ -15,11 +18,11 @@ import java.util.concurrent.TimeUnit; | @@ -15,11 +18,11 @@ import java.util.concurrent.TimeUnit; | ||
| 15 | */ | 18 | */ |
| 16 | public class HttpNoticeCach { | 19 | public class HttpNoticeCach { |
| 17 | private static Logger log = LoggerFactory.getLogger(HttpNoticeCach.class); | 20 | private static Logger log = LoggerFactory.getLogger(HttpNoticeCach.class); |
| 18 | - private static ExpiringMap<String, JsonObject> noticeUpdataData = ExpiringMap.builder().maxSize(20000).expiration(60, TimeUnit.SECONDS) | 21 | + private static ExpiringMap<String, Map<String,Object>> noticeUpdataData = ExpiringMap.builder().maxSize(20000).expiration(60, TimeUnit.SECONDS) |
| 19 | .variableExpiration() | 22 | .variableExpiration() |
| 20 | - .asyncExpirationListener(new ExpirationListener<String, JsonObject>() { | 23 | + .asyncExpirationListener(new ExpirationListener<String, Map<String,Object>>() { |
| 21 | @Override | 24 | @Override |
| 22 | - public void expired(String s, JsonObject parserDeviceHostDto) { | 25 | + public void expired(String s, Map<String,Object> parserDeviceHostDto) { |
| 23 | log.info("超时清除>>>>>>>:{} ",s); | 26 | log.info("超时清除>>>>>>>:{} ",s); |
| 24 | } | 27 | } |
| 25 | }) | 28 | }) |
| @@ -29,17 +32,17 @@ public class HttpNoticeCach { | @@ -29,17 +32,17 @@ public class HttpNoticeCach { | ||
| 29 | { | 32 | { |
| 30 | if(noticeUpdataData.containsKey(parserDeviceHostDto.getId())) | 33 | if(noticeUpdataData.containsKey(parserDeviceHostDto.getId())) |
| 31 | { | 34 | { |
| 32 | - noticeUpdataData.put(parserDeviceHostDto.getId(),jsonObject); | 35 | + noticeUpdataData.put(parserDeviceHostDto.getId(), GsonConstructor.get().fromJson(jsonObject.toString(), HashMap.class)); |
| 33 | }else { | 36 | }else { |
| 34 | - noticeUpdataData.put(parserDeviceHostDto.getId(),jsonObject,parserDeviceHostDto.getDevice_life()*3,TimeUnit.SECONDS); | 37 | + noticeUpdataData.put(parserDeviceHostDto.getId(),GsonConstructor.get().fromJson(jsonObject.toString(), HashMap.class),parserDeviceHostDto.getDevice_life()*3,TimeUnit.SECONDS); |
| 35 | } | 38 | } |
| 36 | } | 39 | } |
| 37 | 40 | ||
| 38 | - public static JsonObject consumer(String imei) | 41 | + public static Map<String,Object> consumer(String imei) |
| 39 | { | 42 | { |
| 40 | if(noticeUpdataData.containsKey(imei)) | 43 | if(noticeUpdataData.containsKey(imei)) |
| 41 | { | 44 | { |
| 42 | - JsonObject jsonObject = noticeUpdataData.get(imei); | 45 | + Map<String,Object> jsonObject = noticeUpdataData.get(imei); |
| 43 | noticeUpdataData.remove(imei); | 46 | noticeUpdataData.remove(imei); |
| 44 | return jsonObject; | 47 | return jsonObject; |
| 45 | } | 48 | } |
| @@ -171,8 +171,6 @@ public class PluginsClassLoader extends URLClassLoader { | @@ -171,8 +171,6 @@ public class PluginsClassLoader extends URLClassLoader { | ||
| 171 | Class clazz = classMap.get(classname); | 171 | Class clazz = classMap.get(classname); |
| 172 | if (null != clazz) | 172 | if (null != clazz) |
| 173 | { | 173 | { |
| 174 | - System.out.println("接口的类加载器:"+tClass.getClassLoader()); | ||
| 175 | - System.out.println("实现类的类加载器:"+clazz.getClassLoader()); | ||
| 176 | try { | 174 | try { |
| 177 | if (tClass.isAssignableFrom(clazz) && !clazz.equals(tClass)) { | 175 | if (tClass.isAssignableFrom(clazz) && !clazz.equals(tClass)) { |
| 178 | return tClass.cast(clazz.getDeclaredConstructor().newInstance()); | 176 | return tClass.cast(clazz.getDeclaredConstructor().newInstance()); |
| 1 | package com.zhonglai.luhui.device.protocol.factory.control; | 1 | package com.zhonglai.luhui.device.protocol.factory.control; |
| 2 | 2 | ||
| 3 | +import cn.hutool.extra.spring.SpringUtil; | ||
| 3 | import com.google.gson.JsonObject; | 4 | import com.google.gson.JsonObject; |
| 4 | import com.ruoyi.common.utils.GsonConstructor; | 5 | import com.ruoyi.common.utils.GsonConstructor; |
| 5 | import com.zhonglai.luhui.device.analysis.comm.clien.ClienConnection; | 6 | import com.zhonglai.luhui.device.analysis.comm.clien.ClienConnection; |
| 6 | import com.zhonglai.luhui.device.analysis.comm.clien.impl.ClienConnectionImpl; | 7 | import com.zhonglai.luhui.device.analysis.comm.clien.impl.ClienConnectionImpl; |
| 8 | +import com.zhonglai.luhui.device.analysis.comm.config.SysParameter; | ||
| 7 | import com.zhonglai.luhui.device.analysis.comm.dto.ApiClientRePlyDto; | 9 | import com.zhonglai.luhui.device.analysis.comm.dto.ApiClientRePlyDto; |
| 8 | import com.zhonglai.luhui.device.analysis.comm.dto.TerminalClientRePlyDto; | 10 | import com.zhonglai.luhui.device.analysis.comm.dto.TerminalClientRePlyDto; |
| 9 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 11 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| @@ -23,17 +25,27 @@ import com.zhonglai.luhui.device.protocol.factory.service.PersistenceDBService; | @@ -23,17 +25,27 @@ import com.zhonglai.luhui.device.protocol.factory.service.PersistenceDBService; | ||
| 23 | import net.jodah.expiringmap.ExpirationListener; | 25 | import net.jodah.expiringmap.ExpirationListener; |
| 24 | import net.jodah.expiringmap.ExpirationPolicy; | 26 | import net.jodah.expiringmap.ExpirationPolicy; |
| 25 | import net.jodah.expiringmap.ExpiringMap; | 27 | import net.jodah.expiringmap.ExpiringMap; |
| 28 | +import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; | ||
| 29 | +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; | ||
| 30 | +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; | ||
| 31 | +import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; | ||
| 32 | +import org.apache.rocketmq.client.exception.MQClientException; | ||
| 26 | import org.apache.rocketmq.common.message.MessageExt; | 33 | import org.apache.rocketmq.common.message.MessageExt; |
| 27 | import org.apache.rocketmq.spring.annotation.MessageModel; | 34 | import org.apache.rocketmq.spring.annotation.MessageModel; |
| 28 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; | 35 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; |
| 36 | +import org.apache.rocketmq.spring.annotation.SelectorType; | ||
| 37 | +import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener; | ||
| 29 | import org.apache.rocketmq.spring.core.RocketMQReplyListener; | 38 | import org.apache.rocketmq.spring.core.RocketMQReplyListener; |
| 39 | +import org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer; | ||
| 30 | import org.slf4j.Logger; | 40 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; | 41 | import org.slf4j.LoggerFactory; |
| 32 | import org.springframework.beans.factory.annotation.Autowired; | 42 | import org.springframework.beans.factory.annotation.Autowired; |
| 33 | import org.springframework.beans.factory.annotation.Value; | 43 | import org.springframework.beans.factory.annotation.Value; |
| 34 | import org.springframework.stereotype.Service; | 44 | import org.springframework.stereotype.Service; |
| 35 | 45 | ||
| 46 | +import javax.annotation.PostConstruct; | ||
| 36 | import java.util.Arrays; | 47 | import java.util.Arrays; |
| 48 | +import java.util.List; | ||
| 37 | import java.util.Map; | 49 | import java.util.Map; |
| 38 | import java.util.Set; | 50 | import java.util.Set; |
| 39 | import java.util.concurrent.TimeUnit; | 51 | import java.util.concurrent.TimeUnit; |
| @@ -42,8 +54,8 @@ import java.util.concurrent.TimeUnit; | @@ -42,8 +54,8 @@ import java.util.concurrent.TimeUnit; | ||
| 42 | * 设备指令监听服务 | 54 | * 设备指令监听服务 |
| 43 | */ | 55 | */ |
| 44 | @Service | 56 | @Service |
| 45 | -@RocketMQMessageListener(consumerGroup = "deviceCommand", topic = "deviceCommandListen",messageModel = MessageModel.BROADCASTING) | ||
| 46 | -public class DeviceCommandListenService implements RocketMQReplyListener<MessageExt, Message> { | 57 | +@RocketMQMessageListener(consumerGroup = "deviceCommand", topic = "deviceCommandListen",selectorType = SelectorType.TAG,selectorExpression = "${rocketmq.operationToken}",messageModel = MessageModel.BROADCASTING) |
| 58 | +public class DeviceCommandListenService implements RocketMQReplyListener<MessageExt, Message>, RocketMQPushConsumerLifecycleListener { | ||
| 47 | private static final Logger log = LoggerFactory.getLogger(DeviceCommandListenService.class); | 59 | private static final Logger log = LoggerFactory.getLogger(DeviceCommandListenService.class); |
| 48 | 60 | ||
| 49 | private static ExpiringMap<String, ClienConnection> clienConnectionMap = ExpiringMap.builder().maxSize(20000).expiration(15, TimeUnit.SECONDS) | 61 | private static ExpiringMap<String, ClienConnection> clienConnectionMap = ExpiringMap.builder().maxSize(20000).expiration(15, TimeUnit.SECONDS) |
| @@ -63,15 +75,11 @@ public class DeviceCommandListenService implements RocketMQReplyListener<Message | @@ -63,15 +75,11 @@ public class DeviceCommandListenService implements RocketMQReplyListener<Message | ||
| 63 | @Autowired | 75 | @Autowired |
| 64 | private ClienNoticeServiceFactory clienNoticeServiceFactory; | 76 | private ClienNoticeServiceFactory clienNoticeServiceFactory; |
| 65 | 77 | ||
| 66 | - @Autowired | ||
| 67 | - private IotThingsModelService iotThingsModelService; | ||
| 68 | - | ||
| 69 | - @Autowired | ||
| 70 | - private MqttSubscribeService mqttSubscribeService; | ||
| 71 | - | ||
| 72 | @Value("${mqtt.client.operationTime}") | 78 | @Value("${mqtt.client.operationTime}") |
| 73 | private long operationTime; //客户端操作时间 | 79 | private long operationTime; //客户端操作时间 |
| 74 | 80 | ||
| 81 | + private String selectorExpression; | ||
| 82 | + private DefaultMQPushConsumer defaultMQPushConsumer; | ||
| 75 | @Override | 83 | @Override |
| 76 | public Message onMessage(MessageExt messageExt) { | 84 | public Message onMessage(MessageExt messageExt) { |
| 77 | log.info("监听到消息{}",messageExt); | 85 | log.info("监听到消息{}",messageExt); |
| @@ -81,8 +89,6 @@ public class DeviceCommandListenService implements RocketMQReplyListener<Message | @@ -81,8 +89,6 @@ public class DeviceCommandListenService implements RocketMQReplyListener<Message | ||
| 81 | 89 | ||
| 82 | DeviceCommand deviceCommand = GsonConstructor.get().fromJson(str, DeviceCommand.class); | 90 | DeviceCommand deviceCommand = GsonConstructor.get().fromJson(str, DeviceCommand.class); |
| 83 | 91 | ||
| 84 | - if (deviceCommand.getCommandType().equals(CommandType.read) || deviceCommand.getCommandType().equals(CommandType.write) || deviceCommand.getCommandType().equals(CommandType.notice)) | ||
| 85 | - { | ||
| 86 | ParserDeviceHostDto parserDeviceHostDto = DeviceCach.getDeviceHost(deviceCommand.getDeviceId()); | 92 | ParserDeviceHostDto parserDeviceHostDto = DeviceCach.getDeviceHost(deviceCommand.getDeviceId()); |
| 87 | if(null == parserDeviceHostDto) | 93 | if(null == parserDeviceHostDto) |
| 88 | { | 94 | { |
| @@ -134,34 +140,8 @@ public class DeviceCommandListenService implements RocketMQReplyListener<Message | @@ -134,34 +140,8 @@ public class DeviceCommandListenService implements RocketMQReplyListener<Message | ||
| 134 | log.error("消息发送失败",e); | 140 | log.error("消息发送失败",e); |
| 135 | return new Message(MessageCode.DEFAULT_FAIL_CODE,"等待通知错误"); | 141 | return new Message(MessageCode.DEFAULT_FAIL_CODE,"等待通知错误"); |
| 136 | } | 142 | } |
| 137 | - }else{ | ||
| 138 | - switch (deviceCommand.getCommandType()) | ||
| 139 | - { | ||
| 140 | - case cleanDeviceHost: | ||
| 141 | - DeviceCach.cleanDeviceHost(deviceCommand.getDeviceId()); | ||
| 142 | - return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"指令发送成功"); | ||
| 143 | - case cleanDeviceInfo: | ||
| 144 | - DeviceCach.cleanDeviceInfo(deviceCommand.getDeviceId()+"_"+deviceCommand.getData().get("sensor_number").getAsString()); | ||
| 145 | - return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"指令发送成功"); | ||
| 146 | - case upIotThingsModel: | ||
| 147 | - iotThingsModelService.upIotThingsModel(deviceCommand.getData().get("product_id").getAsInt()); | ||
| 148 | - return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"指令发送成功"); | ||
| 149 | - case upIotThingsModelTranslate: | ||
| 150 | - iotThingsModelService.upIotThingsModelTranslate(deviceCommand.getData().get("product_id").getAsInt()); | ||
| 151 | - return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"指令发送成功"); | ||
| 152 | - case addSubscribe: | ||
| 153 | - Set<Integer> okProduct = mqttSubscribeService.assignIpAddSubscribe(deviceCommand.getData().get("ip").getAsString(),deviceCommand.getData().get("product_ids").getAsString()); | ||
| 154 | - if (null == okProduct || okProduct.size() ==0) | ||
| 155 | - { | ||
| 156 | - return new Message(MessageCode.DEFAULT_FAIL_CODE,"订阅未成功请检查原因"); | ||
| 157 | - } | ||
| 158 | - return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"订阅成功", Arrays.toString(okProduct.toArray())); | ||
| 159 | - default: | ||
| 160 | - return new Message(MessageCode.DEFAULT_FAIL_CODE,"指令类型不存在,请联系管理员"); | ||
| 161 | - } | ||
| 162 | } | 143 | } |
| 163 | 144 | ||
| 164 | - } | ||
| 165 | 145 | ||
| 166 | public Message sendMessage( NoticeMessageDto noticeMessageDomain) throws InterruptedException { | 146 | public Message sendMessage( NoticeMessageDto noticeMessageDomain) throws InterruptedException { |
| 167 | 147 | ||
| @@ -196,19 +176,6 @@ public class DeviceCommandListenService implements RocketMQReplyListener<Message | @@ -196,19 +176,6 @@ public class DeviceCommandListenService implements RocketMQReplyListener<Message | ||
| 196 | return clienConnectionMap.containsKey(clientid); | 176 | return clienConnectionMap.containsKey(clientid); |
| 197 | } | 177 | } |
| 198 | 178 | ||
| 199 | - private void log(Topic topic,JsonObject jsonObject) | ||
| 200 | - { | ||
| 201 | -// AddPostDto addPostDto = new AddPostDto(); | ||
| 202 | -// addPostDto.setData(JSON.parseObject(jsonObject.toString())); | ||
| 203 | -// addPostDto.setIotTerminalList(new ArrayList<>()); | ||
| 204 | -// addPostDto.setDeviceSensorDataList(new ArrayList<>()); | ||
| 205 | -// addPostDto.setLogDeviceOperationList(new ArrayList<>()); | ||
| 206 | -// businessDataUpdateService.updataDta(BusinessDataUpdateService.Type.ADD,topic,addPostDto,"远程控制",true); | ||
| 207 | -// cacheServiceImpl.updateCache(topic,addPostDto); | ||
| 208 | -// addPostDto.setLogDeviceOperationList(logDeviceOperationList); | ||
| 209 | -// dataPersistenceService.persistence(topic,addPostDto); | ||
| 210 | - } | ||
| 211 | - | ||
| 212 | /** | 179 | /** |
| 213 | * 通知给api操作端 | 180 | * 通知给api操作端 |
| 214 | * @param clientid | 181 | * @param clientid |
| @@ -230,4 +197,29 @@ public class DeviceCommandListenService implements RocketMQReplyListener<Message | @@ -230,4 +197,29 @@ public class DeviceCommandListenService implements RocketMQReplyListener<Message | ||
| 230 | log.info("结束通知{}",clientid); | 197 | log.info("结束通知{}",clientid); |
| 231 | } | 198 | } |
| 232 | 199 | ||
| 200 | + @Override | ||
| 201 | + public void prepareStart(DefaultMQPushConsumer consumer) { | ||
| 202 | + //设置当前实例的名称 | ||
| 203 | + consumer.setInstanceName(this.getClass().getSimpleName()); | ||
| 204 | + this.defaultMQPushConsumer = consumer; | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + public String getSelectorExpression() | ||
| 208 | + { | ||
| 209 | + if(null == selectorExpression) | ||
| 210 | + { | ||
| 211 | + String[] beannames = SpringUtil.getBeanNamesForType(DefaultRocketMQListenerContainer.class); | ||
| 212 | + if(null != beannames) | ||
| 213 | + { | ||
| 214 | + for (String beanname:beannames) | ||
| 215 | + { | ||
| 216 | + DefaultRocketMQListenerContainer container = SpringUtil.getBean(beanname); | ||
| 217 | + if (container.getConsumer().equals(this.defaultMQPushConsumer)) { | ||
| 218 | + selectorExpression = container.getSelectorExpression(); | ||
| 219 | + } | ||
| 220 | + } | ||
| 221 | + } | ||
| 222 | + } | ||
| 223 | + return selectorExpression; | ||
| 224 | + } | ||
| 233 | } | 225 | } |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.control; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 4 | +import com.zhonglai.luhui.device.analysis.dto.Message; | ||
| 5 | +import com.zhonglai.luhui.device.analysis.dto.MessageCode; | ||
| 6 | +import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; | ||
| 7 | +import com.zhonglai.luhui.device.protocol.factory.dto.DeviceCommand; | ||
| 8 | +import com.zhonglai.luhui.device.protocol.factory.service.IotThingsModelService; | ||
| 9 | +import com.zhonglai.luhui.device.protocol.factory.service.MqttSubscribeService; | ||
| 10 | +import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; | ||
| 11 | +import org.apache.rocketmq.common.message.MessageExt; | ||
| 12 | +import org.apache.rocketmq.spring.annotation.MessageModel; | ||
| 13 | +import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; | ||
| 14 | +import org.apache.rocketmq.spring.annotation.SelectorType; | ||
| 15 | +import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener; | ||
| 16 | +import org.apache.rocketmq.spring.core.RocketMQReplyListener; | ||
| 17 | +import org.slf4j.Logger; | ||
| 18 | +import org.slf4j.LoggerFactory; | ||
| 19 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 20 | +import org.springframework.stereotype.Service; | ||
| 21 | + | ||
| 22 | +import java.util.Arrays; | ||
| 23 | +import java.util.Set; | ||
| 24 | + | ||
| 25 | +@Service | ||
| 26 | +@RocketMQMessageListener(consumerGroup = "deviceCommand", topic = "deviceCommandListen",selectorType = SelectorType.TAG,selectorExpression = "SysCommand",messageModel = MessageModel.BROADCASTING) | ||
| 27 | +public class SysCommandListenService implements RocketMQReplyListener<MessageExt, Message> , RocketMQPushConsumerLifecycleListener { | ||
| 28 | + private static final Logger log = LoggerFactory.getLogger(DeviceCommandListenService.class); | ||
| 29 | + | ||
| 30 | + @Autowired | ||
| 31 | + private IotThingsModelService iotThingsModelService; | ||
| 32 | + | ||
| 33 | + @Autowired | ||
| 34 | + private MqttSubscribeService mqttSubscribeService; | ||
| 35 | + @Override | ||
| 36 | + public Message onMessage(MessageExt messageExt) { | ||
| 37 | + log.info("监听到消息{}",messageExt); | ||
| 38 | + | ||
| 39 | + String str = new String(messageExt.getBody()); | ||
| 40 | + log.info("消息body{}",str); | ||
| 41 | + | ||
| 42 | + DeviceCommand deviceCommand = GsonConstructor.get().fromJson(str, DeviceCommand.class); | ||
| 43 | + | ||
| 44 | + switch (deviceCommand.getCommandType()) | ||
| 45 | + { | ||
| 46 | + case cleanDeviceHost: | ||
| 47 | + DeviceCach.cleanDeviceHost(deviceCommand.getDeviceId()); | ||
| 48 | + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"指令发送成功"); | ||
| 49 | + case cleanDeviceInfo: | ||
| 50 | + DeviceCach.cleanDeviceInfo(deviceCommand.getDeviceId()+"_"+deviceCommand.getData().get("sensor_number").getAsString()); | ||
| 51 | + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"指令发送成功"); | ||
| 52 | + case upIotThingsModel: | ||
| 53 | + iotThingsModelService.upIotThingsModel(deviceCommand.getData().get("product_id").getAsInt()); | ||
| 54 | + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"指令发送成功"); | ||
| 55 | + case upIotThingsModelTranslate: | ||
| 56 | + iotThingsModelService.upIotThingsModelTranslate(deviceCommand.getData().get("product_id").getAsInt()); | ||
| 57 | + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"指令发送成功"); | ||
| 58 | + case addSubscribe: | ||
| 59 | + Set<Integer> okProduct = mqttSubscribeService.assignIpAddSubscribe(deviceCommand.getData().get("ip").getAsString(),deviceCommand.getData().get("product_ids").getAsString()); | ||
| 60 | + if (null == okProduct || okProduct.size() ==0) | ||
| 61 | + { | ||
| 62 | + return new Message(MessageCode.DEFAULT_FAIL_CODE,"订阅未成功请检查原因"); | ||
| 63 | + } | ||
| 64 | + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"订阅成功", Arrays.toString(okProduct.toArray())); | ||
| 65 | + default: | ||
| 66 | + return new Message(MessageCode.DEFAULT_FAIL_CODE,"指令类型不存在,请联系管理员"); | ||
| 67 | + } | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + @Override | ||
| 71 | + public void prepareStart(DefaultMQPushConsumer consumer) { | ||
| 72 | + //设置当前实例的名称 | ||
| 73 | + consumer.setInstanceName(this.getClass().getSimpleName()); | ||
| 74 | + } | ||
| 75 | +} |
| @@ -26,6 +26,16 @@ public class ProtocolPurificationModel { | @@ -26,6 +26,16 @@ public class ProtocolPurificationModel { | ||
| 26 | private List<DeviceSensorData> deviceSensorDataList = new ArrayList<>(); | 26 | private List<DeviceSensorData> deviceSensorDataList = new ArrayList<>(); |
| 27 | private List<LogDeviceOperation> logDeviceOperationList = new ArrayList<>(); | 27 | private List<LogDeviceOperation> logDeviceOperationList = new ArrayList<>(); |
| 28 | 28 | ||
| 29 | + private boolean isAllUp = false; | ||
| 30 | + | ||
| 31 | + public boolean isAllUp() { | ||
| 32 | + return isAllUp; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public void setAllUp(boolean allUp) { | ||
| 36 | + isAllUp = allUp; | ||
| 37 | + } | ||
| 38 | + | ||
| 29 | public ParserDeviceHostDto getParserDeviceHostDto() { | 39 | public ParserDeviceHostDto getParserDeviceHostDto() { |
| 30 | return parserDeviceHostDto; | 40 | return parserDeviceHostDto; |
| 31 | } | 41 | } |
| @@ -48,13 +48,13 @@ public abstract class BaseCallback<T> { | @@ -48,13 +48,13 @@ public abstract class BaseCallback<T> { | ||
| 48 | /** | 48 | /** |
| 49 | * 数据处理的工作流 | 49 | * 数据处理的工作流 |
| 50 | */ | 50 | */ |
| 51 | - protected void messageArrived(String imei,String s,T payload) throws ClassNotFoundException, InstantiationException, IllegalAccessException { | 51 | + protected ProtocolPurificationModel messageArrived(String imei,String s,T payload) throws ClassNotFoundException, InstantiationException, IllegalAccessException { |
| 52 | //判断网关是否存在 | 52 | //判断网关是否存在 |
| 53 | ParserDeviceHostDto oldparserDeviceHostDto = persistenceDBService.getOldParserDeviceHostDto(imei); | 53 | ParserDeviceHostDto oldparserDeviceHostDto = persistenceDBService.getOldParserDeviceHostDto(imei); |
| 54 | if(null == oldparserDeviceHostDto) | 54 | if(null == oldparserDeviceHostDto) |
| 55 | { | 55 | { |
| 56 | log.info("设备{}不存在",imei); | 56 | log.info("设备{}不存在",imei); |
| 57 | - return; | 57 | + return null; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | //解析和清洗body | 60 | //解析和清洗body |
| @@ -75,6 +75,7 @@ public abstract class BaseCallback<T> { | @@ -75,6 +75,7 @@ public abstract class BaseCallback<T> { | ||
| 75 | deviceCommandListenService.replySendMessage(oldparserDeviceHostDto.getId(),protocolPurificationModel.getNoticeMessage()); | 75 | deviceCommandListenService.replySendMessage(oldparserDeviceHostDto.getId(),protocolPurificationModel.getNoticeMessage()); |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | + return protocolPurificationModel; | ||
| 78 | } | 79 | } |
| 79 | 80 | ||
| 80 | 81 |
| @@ -8,6 +8,7 @@ import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; | @@ -8,6 +8,7 @@ import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; | ||
| 8 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; | 8 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; |
| 9 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; | 9 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; |
| 10 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.specs.StringModelOutput; | 10 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.specs.StringModelOutput; |
| 11 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 11 | import com.zhonglai.luhui.device.domain.IotThingsModel; | 12 | import com.zhonglai.luhui.device.domain.IotThingsModel; |
| 12 | import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; | 13 | import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; |
| 13 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | 14 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; |
| @@ -81,6 +82,10 @@ public class DeviceCashUpService { | @@ -81,6 +82,10 @@ public class DeviceCashUpService { | ||
| 81 | oldparserDeviceHostDto.set_data_up(true); | 82 | oldparserDeviceHostDto.set_data_up(true); |
| 82 | } | 83 | } |
| 83 | } | 84 | } |
| 85 | + if(protocolPurificationModel.isAllUp()) | ||
| 86 | + { | ||
| 87 | + oldparserDeviceHostDto.setData(newData); | ||
| 88 | + } | ||
| 84 | } | 89 | } |
| 85 | 90 | ||
| 86 | JsonObject oldConfig = oldparserDeviceHostDto.getConfig(); | 91 | JsonObject oldConfig = oldparserDeviceHostDto.getConfig(); |
| @@ -99,12 +104,17 @@ public class DeviceCashUpService { | @@ -99,12 +104,17 @@ public class DeviceCashUpService { | ||
| 99 | oldparserDeviceHostDto.set_config_up(true); | 104 | oldparserDeviceHostDto.set_config_up(true); |
| 100 | } | 105 | } |
| 101 | } | 106 | } |
| 107 | + if(protocolPurificationModel.isAllUp()) | ||
| 108 | + { | ||
| 109 | + oldparserDeviceHostDto.setConfig(newConfig); | ||
| 110 | + } | ||
| 102 | } | 111 | } |
| 103 | 112 | ||
| 104 | JsonObject oldSummary = oldparserDeviceHostDto.getSummary(); | 113 | JsonObject oldSummary = oldparserDeviceHostDto.getSummary(); |
| 105 | JsonObject newSummary = parserDeviceHostDto.getSummary(); | 114 | JsonObject newSummary = parserDeviceHostDto.getSummary(); |
| 106 | if(null != newSummary) | 115 | if(null != newSummary) |
| 107 | { | 116 | { |
| 117 | + | ||
| 108 | if(null == oldSummary) | 118 | if(null == oldSummary) |
| 109 | { | 119 | { |
| 110 | oldparserDeviceHostDto.setSummary(newSummary); | 120 | oldparserDeviceHostDto.setSummary(newSummary); |
| @@ -117,11 +127,17 @@ public class DeviceCashUpService { | @@ -117,11 +127,17 @@ public class DeviceCashUpService { | ||
| 117 | oldparserDeviceHostDto.set_summary_up(true); | 127 | oldparserDeviceHostDto.set_summary_up(true); |
| 118 | } | 128 | } |
| 119 | } | 129 | } |
| 130 | + if(protocolPurificationModel.isAllUp()) | ||
| 131 | + { | ||
| 132 | + oldparserDeviceHostDto.setSummary(newSummary); | ||
| 133 | + } | ||
| 134 | + | ||
| 120 | } | 135 | } |
| 121 | oldparserDeviceHostDto.setUpdateTime(parserDeviceHostDto.getUpdateTime()); | 136 | oldparserDeviceHostDto.setUpdateTime(parserDeviceHostDto.getUpdateTime()); |
| 122 | oldparserDeviceHostDto.setOnline(parserDeviceHostDto.getOnline()); | 137 | oldparserDeviceHostDto.setOnline(parserDeviceHostDto.getOnline()); |
| 123 | oldparserDeviceHostDto.setRssi(parserDeviceHostDto.getRssi()); | 138 | oldparserDeviceHostDto.setRssi(parserDeviceHostDto.getRssi()); |
| 124 | oldparserDeviceHostDto.setSummary(parserDeviceHostDto.getSummary()); | 139 | oldparserDeviceHostDto.setSummary(parserDeviceHostDto.getSummary()); |
| 140 | + | ||
| 125 | protocolPurificationModel.setParserDeviceHostDto(oldparserDeviceHostDto); | 141 | protocolPurificationModel.setParserDeviceHostDto(oldparserDeviceHostDto); |
| 126 | 142 | ||
| 127 | //更新主机缓存 | 143 | //更新主机缓存 |
| @@ -188,6 +204,10 @@ public class DeviceCashUpService { | @@ -188,6 +204,10 @@ public class DeviceCashUpService { | ||
| 188 | oldparserDeviceInfoDto.set_data_up(true); | 204 | oldparserDeviceInfoDto.set_data_up(true); |
| 189 | } | 205 | } |
| 190 | } | 206 | } |
| 207 | + if(protocolPurificationModel.isAllUp()) | ||
| 208 | + { | ||
| 209 | + oldparserDeviceInfoDto.setData(newData); | ||
| 210 | + } | ||
| 191 | } | 211 | } |
| 192 | 212 | ||
| 193 | JsonObject oldConfig = oldparserDeviceInfoDto.getConfig(); | 213 | JsonObject oldConfig = oldparserDeviceInfoDto.getConfig(); |
| @@ -206,6 +226,10 @@ public class DeviceCashUpService { | @@ -206,6 +226,10 @@ public class DeviceCashUpService { | ||
| 206 | oldparserDeviceInfoDto.set_conf_up(true); | 226 | oldparserDeviceInfoDto.set_conf_up(true); |
| 207 | } | 227 | } |
| 208 | } | 228 | } |
| 229 | + if(protocolPurificationModel.isAllUp()) | ||
| 230 | + { | ||
| 231 | + oldparserDeviceInfoDto.setConfig(newConfig); | ||
| 232 | + } | ||
| 209 | } | 233 | } |
| 210 | return i; | 234 | return i; |
| 211 | } | 235 | } |
| @@ -9,11 +9,16 @@ import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; | @@ -9,11 +9,16 @@ import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; | ||
| 9 | import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; | 9 | import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; |
| 10 | import com.zhonglai.luhui.device.analysis.comm.dto.TableGenerateSqlEnum; | 10 | import com.zhonglai.luhui.device.analysis.comm.dto.TableGenerateSqlEnum; |
| 11 | import com.zhonglai.luhui.device.domain.*; | 11 | import com.zhonglai.luhui.device.domain.*; |
| 12 | +import com.zhonglai.luhui.device.protocol.factory.control.DeviceCommandListenService; | ||
| 12 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | 13 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; |
| 13 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | 14 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; |
| 14 | import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolSubTopics; | 15 | import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolSubTopics; |
| 16 | +import com.zhonglai.luhui.device.protocol.factory.service.PersistenceDBService; | ||
| 17 | +import org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer; | ||
| 15 | import org.slf4j.Logger; | 18 | import org.slf4j.Logger; |
| 16 | import org.slf4j.LoggerFactory; | 19 | import org.slf4j.LoggerFactory; |
| 20 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 21 | +import org.springframework.beans.factory.annotation.Value; | ||
| 17 | import org.springframework.stereotype.Service; | 22 | import org.springframework.stereotype.Service; |
| 18 | 23 | ||
| 19 | import java.util.ArrayList; | 24 | import java.util.ArrayList; |
| @@ -26,6 +31,8 @@ public class DefaultDbService { | @@ -26,6 +31,8 @@ public class DefaultDbService { | ||
| 26 | 31 | ||
| 27 | private BaseDao baseDao = new BaseDao(); | 32 | private BaseDao baseDao = new BaseDao(); |
| 28 | 33 | ||
| 34 | + @Autowired | ||
| 35 | + private DeviceCommandListenService deviceCommandListenService; | ||
| 29 | 36 | ||
| 30 | public List<String> getTopicFromRole() | 37 | public List<String> getTopicFromRole() |
| 31 | { | 38 | { |
| @@ -162,8 +169,11 @@ public class DefaultDbService { | @@ -162,8 +169,11 @@ public class DefaultDbService { | ||
| 162 | baseDao.updateBySql("UPDATE `iot_terminal` SET online=4 WHERE device_id=?",iotDevice.getClient_id()); | 169 | baseDao.updateBySql("UPDATE `iot_terminal` SET online=4 WHERE device_id=?",iotDevice.getClient_id()); |
| 163 | break; | 170 | break; |
| 164 | } | 171 | } |
| 172 | + }else { | ||
| 173 | + iotDevice.setStatus(3); | ||
| 165 | } | 174 | } |
| 166 | 175 | ||
| 176 | + iotDevice.setOperation_token(deviceCommandListenService.getSelectorExpression()); | ||
| 167 | int i = baseDao.update(iotDevice); | 177 | int i = baseDao.update(iotDevice); |
| 168 | return i; | 178 | return i; |
| 169 | } | 179 | } |
| @@ -188,6 +198,7 @@ public class DefaultDbService { | @@ -188,6 +198,7 @@ public class DefaultDbService { | ||
| 188 | iotTerminal.setThings_model_config(parserDeviceInfoDto.getConfig().toString()); | 198 | iotTerminal.setThings_model_config(parserDeviceInfoDto.getConfig().toString()); |
| 189 | parserDeviceInfoDto.set_conf_up(false); | 199 | parserDeviceInfoDto.set_conf_up(false); |
| 190 | } | 200 | } |
| 201 | + iotTerminal.setOperation_token(deviceCommandListenService.getSelectorExpression()); | ||
| 191 | i+=baseDao.update(iotTerminal); | 202 | i+=baseDao.update(iotTerminal); |
| 192 | 203 | ||
| 193 | } | 204 | } |
| 1 | package com.zhonglai.luhui.http.service.proxy.controller; | 1 | package com.zhonglai.luhui.http.service.proxy.controller; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.JSON; | ||
| 4 | +import com.google.gson.JsonElement; | ||
| 3 | import com.google.gson.JsonObject; | 5 | import com.google.gson.JsonObject; |
| 4 | import com.ruoyi.common.core.domain.AjaxResult; | 6 | import com.ruoyi.common.core.domain.AjaxResult; |
| 5 | import com.ruoyi.common.utils.GsonConstructor; | 7 | import com.ruoyi.common.utils.GsonConstructor; |
| @@ -11,6 +13,7 @@ import com.zhonglai.luhui.device.protocol.factory.comm.DataLogType; | @@ -11,6 +13,7 @@ import com.zhonglai.luhui.device.protocol.factory.comm.DataLogType; | ||
| 11 | import com.zhonglai.luhui.device.protocol.factory.comm.DeviceDataLog; | 13 | import com.zhonglai.luhui.device.protocol.factory.comm.DeviceDataLog; |
| 12 | import com.zhonglai.luhui.device.protocol.factory.config.HttpNoticeCach; | 14 | import com.zhonglai.luhui.device.protocol.factory.config.HttpNoticeCach; |
| 13 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | 15 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; |
| 16 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | ||
| 14 | import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | 17 | import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; |
| 15 | import com.zhonglai.luhui.device.protocol.factory.service.DeviceCashUpService; | 18 | import com.zhonglai.luhui.device.protocol.factory.service.DeviceCashUpService; |
| 16 | import com.zhonglai.luhui.device.protocol.factory.service.PersistenceDBService; | 19 | import com.zhonglai.luhui.device.protocol.factory.service.PersistenceDBService; |
| @@ -29,6 +32,7 @@ import org.springframework.web.bind.annotation.*; | @@ -29,6 +32,7 @@ import org.springframework.web.bind.annotation.*; | ||
| 29 | import javax.servlet.http.HttpServletRequest; | 32 | import javax.servlet.http.HttpServletRequest; |
| 30 | import java.io.IOException; | 33 | import java.io.IOException; |
| 31 | import java.util.HashMap; | 34 | import java.util.HashMap; |
| 35 | +import java.util.List; | ||
| 32 | import java.util.Map; | 36 | import java.util.Map; |
| 33 | import java.util.concurrent.ExecutorService; | 37 | import java.util.concurrent.ExecutorService; |
| 34 | import java.util.concurrent.LinkedBlockingQueue; | 38 | import java.util.concurrent.LinkedBlockingQueue; |
| @@ -39,6 +43,7 @@ import java.util.concurrent.TimeUnit; | @@ -39,6 +43,7 @@ import java.util.concurrent.TimeUnit; | ||
| 39 | @RestController | 43 | @RestController |
| 40 | @RequestMapping("/httpDataProxy") | 44 | @RequestMapping("/httpDataProxy") |
| 41 | public class HttpDataProxyController { | 45 | public class HttpDataProxyController { |
| 46 | + private static Logger log = LoggerFactory.getLogger(HttpDataProxyController.class); | ||
| 42 | 47 | ||
| 43 | @Autowired | 48 | @Autowired |
| 44 | private HttpCallback httpCallback; | 49 | private HttpCallback httpCallback; |
| @@ -49,17 +54,66 @@ public class HttpDataProxyController { | @@ -49,17 +54,66 @@ public class HttpDataProxyController { | ||
| 49 | @ApiImplicitParam(value = "设备imei",name = "imei"), | 54 | @ApiImplicitParam(value = "设备imei",name = "imei"), |
| 50 | @ApiImplicitParam(value = "产品id",name = "role"), | 55 | @ApiImplicitParam(value = "产品id",name = "role"), |
| 51 | @ApiImplicitParam(value = "用户名",name = "username"), | 56 | @ApiImplicitParam(value = "用户名",name = "username"), |
| 57 | + @ApiImplicitParam(value = "目前支持,ALL_POST 全量上报数据、ADD_POST 增量上报数据",name = "topicType"), | ||
| 52 | }) | 58 | }) |
| 53 | - @RequestMapping(value = "post/{role}/{username}/{imei}/{time}",method = RequestMethod.POST) | ||
| 54 | - public AjaxResult post(@PathVariable String role, @PathVariable String username, @PathVariable String imei, @PathVariable Integer time, HttpServletRequest request) throws IOException { | 59 | + @RequestMapping(value = "post/{role}/{username}/{imei}/{time}/{topicType}",method = RequestMethod.POST) |
| 60 | + public AjaxResult post(@PathVariable String role, @PathVariable String username, @PathVariable String imei, @PathVariable Integer time, @PathVariable String topicType, HttpServletRequest request) throws IOException { | ||
| 55 | byte[] bodyBytes = StreamUtils.copyToByteArray(request.getInputStream()); | 61 | byte[] bodyBytes = StreamUtils.copyToByteArray(request.getInputStream()); |
| 56 | String body = new String(bodyBytes, request.getCharacterEncoding()); | 62 | String body = new String(bodyBytes, request.getCharacterEncoding()); |
| 57 | JsonObject jsonObject = GsonConstructor.get().fromJson(body,JsonObject.class); | 63 | JsonObject jsonObject = GsonConstructor.get().fromJson(body,JsonObject.class); |
| 58 | - String topic = "/"+role+"/"+username+"/"+imei+"/Json/ALL_POST/"+time; | 64 | + String topic = "/"+role+"/"+username+"/"+imei+"/Json/"+topicType+"/"+time; |
| 59 | DeviceDataLog.info(imei, DataLogType.发来数据,topic,jsonObject); | 65 | DeviceDataLog.info(imei, DataLogType.发来数据,topic,jsonObject); |
| 60 | 66 | ||
| 61 | - httpCallback.messageArrived(imei,topic,jsonObject); | 67 | + ProtocolPurificationModel protocolPurificationModel = httpCallback.messageArrived(imei,topic,jsonObject); |
| 62 | 68 | ||
| 63 | - return AjaxResult.success(HttpNoticeCach.consumer(imei)); | 69 | + Map<String,Object> map = HttpNoticeCach.consumer(imei); |
| 70 | + if (null == map) | ||
| 71 | + { | ||
| 72 | + Map<String,Map<String,Object>> rmap = new HashMap<>(); | ||
| 73 | + ParserDeviceHostDto parserDeviceHostDto = protocolPurificationModel.getParserDeviceHostDto(); | ||
| 74 | + if (null != parserDeviceHostDto.getConfig() && parserDeviceHostDto.getConfig().size()>0) | ||
| 75 | + { | ||
| 76 | + Map<String,Object> config= new HashMap<>(); | ||
| 77 | + for (String key:parserDeviceHostDto.getConfig().keySet()) | ||
| 78 | + { | ||
| 79 | + JsonElement jsonElement = parserDeviceHostDto.getConfig().get(key); | ||
| 80 | + if(jsonElement.isJsonObject()) | ||
| 81 | + { | ||
| 82 | + JsonObject value = jsonElement.getAsJsonObject(); | ||
| 83 | + config.put(value.get("id").getAsString(),JSON.parse(value.get("value").toString())); | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + rmap.put("0",config); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + List<ParserDeviceInfoDto> parserDeviceInfoDtoList = protocolPurificationModel.getParserDeviceInfoDtoList(); | ||
| 90 | + if (null != parserDeviceInfoDtoList && parserDeviceInfoDtoList.size() != 0) | ||
| 91 | + { | ||
| 92 | + for (ParserDeviceInfoDto parserDeviceInfoDto:parserDeviceInfoDtoList) | ||
| 93 | + { | ||
| 94 | + if (null != parserDeviceInfoDto.getConfig() && parserDeviceInfoDto.getConfig().size()>0) | ||
| 95 | + { | ||
| 96 | + Map<String,Object> config= new HashMap<>(); | ||
| 97 | + for (String key:parserDeviceInfoDto.getConfig().keySet()) | ||
| 98 | + { | ||
| 99 | + JsonElement jsonElement = parserDeviceInfoDto.getConfig().get(key); | ||
| 100 | + if(jsonElement.isJsonObject()) | ||
| 101 | + { | ||
| 102 | + JsonObject value = jsonElement.getAsJsonObject(); | ||
| 103 | + config.put(value.get("id").getAsString(), JSON.parse(value.get("value").toString())); | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + rmap.put(parserDeviceInfoDto.getId().substring(parserDeviceInfoDto.getId().indexOf("_")+1),config); | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + if(rmap.size()!= 0) | ||
| 111 | + { | ||
| 112 | + log.info("返回的数据【{}】",rmap); | ||
| 113 | + return AjaxResult.success(rmap); | ||
| 114 | + } | ||
| 115 | + } | ||
| 116 | + log.info("返回的数据【{}】",map); | ||
| 117 | + return AjaxResult.success(map); | ||
| 64 | } | 118 | } |
| 65 | } | 119 | } |
| @@ -21,22 +21,13 @@ import java.util.TimerTask; | @@ -21,22 +21,13 @@ import java.util.TimerTask; | ||
| 21 | @Service | 21 | @Service |
| 22 | public class HttpCallback extends BaseCallback<JsonObject> { | 22 | public class HttpCallback extends BaseCallback<JsonObject> { |
| 23 | 23 | ||
| 24 | - @Autowired | ||
| 25 | - private AsyncManager asyncManager; | ||
| 26 | - | ||
| 27 | - public void messageArrived(String imei, String topic, JsonObject data) | 24 | + public ProtocolPurificationModel messageArrived(String imei, String topic, JsonObject data) |
| 28 | { | 25 | { |
| 29 | try { | 26 | try { |
| 30 | - HttpCallback.super.messageArrived(imei,topic,data); | 27 | + return HttpCallback.super.messageArrived(imei,topic,data); |
| 31 | } catch (Exception e) { | 28 | } catch (Exception e) { |
| 32 | log.error(imei+"解析数据失败",e); | 29 | log.error(imei+"解析数据失败",e); |
| 33 | } | 30 | } |
| 34 | -// asyncManager.execute(new TimerTask() { | ||
| 35 | -// @Override | ||
| 36 | -// public void run() { | ||
| 37 | -// | ||
| 38 | -// } | ||
| 39 | -// }); | ||
| 40 | - | 31 | + return null; |
| 41 | } | 32 | } |
| 42 | } | 33 | } |
| @@ -28,9 +28,10 @@ mqtt: | @@ -28,9 +28,10 @@ mqtt: | ||
| 28 | client: | 28 | client: |
| 29 | #客户端操作时间 | 29 | #客户端操作时间 |
| 30 | operationTime: 10 | 30 | operationTime: 10 |
| 31 | - productids: 27,23 | 31 | +# productids: 27,23 |
| 32 | 32 | ||
| 33 | #rocketmq配置信息 | 33 | #rocketmq配置信息 |
| 34 | rocketmq: | 34 | rocketmq: |
| 35 | #nameservice服务器地址(多个以英文逗号隔开) | 35 | #nameservice服务器地址(多个以英文逗号隔开) |
| 36 | name-server: 47.115.144.179:9876 | 36 | name-server: 47.115.144.179:9876 |
| 37 | + operationToken: ${random.uuid} |
| @@ -591,6 +591,12 @@ | @@ -591,6 +591,12 @@ | ||
| 591 | <artifactId>canal.protocol</artifactId> | 591 | <artifactId>canal.protocol</artifactId> |
| 592 | <version>${canal.version}</version> | 592 | <version>${canal.version}</version> |
| 593 | </dependency> | 593 | </dependency> |
| 594 | + | ||
| 595 | + <dependency> | ||
| 596 | + <groupId>com.zhonglai</groupId> | ||
| 597 | + <artifactId>weixin-api</artifactId> | ||
| 598 | + <version>1.3.2</version> | ||
| 599 | + </dependency> | ||
| 594 | </dependencies> | 600 | </dependencies> |
| 595 | 601 | ||
| 596 | 602 |
-
请 注册 或 登录 后发表评论