作者 钟来

新版x6开发

正在显示 37 个修改的文件 包含 1244 行增加368 行删除
1 package com.zhonglai.luhui.admin.controller.iot; 1 package com.zhonglai.luhui.admin.controller.iot;
2 2
3 -import com.alibaba.fastjson.JSONObject;  
4 import com.ruoyi.common.annotation.Log; 3 import com.ruoyi.common.annotation.Log;
5 -import com.ruoyi.common.core.domain.AjaxResult;  
6 import com.ruoyi.common.core.domain.Message; 4 import com.ruoyi.common.core.domain.Message;
7 -import com.ruoyi.common.core.domain.MessageCode;  
8 import com.ruoyi.common.enums.BusinessType; 5 import com.ruoyi.common.enums.BusinessType;
9 -import com.ruoyi.common.utils.StringUtils;  
10 -import com.ruoyi.common.utils.html.HttpUtils;  
11 -import com.ruoyi.system.domain.IotDevice;  
12 -import com.ruoyi.system.service.IIotDeviceService;  
13 -import com.ruoyi.system.service.IIotTerminalService; 6 +import com.ruoyi.system.service.DeviceControlService;
14 import io.swagger.annotations.Api; 7 import io.swagger.annotations.Api;
15 import io.swagger.annotations.ApiImplicitParam; 8 import io.swagger.annotations.ApiImplicitParam;
16 import io.swagger.annotations.ApiImplicitParams; 9 import io.swagger.annotations.ApiImplicitParams;
17 import io.swagger.annotations.ApiOperation; 10 import io.swagger.annotations.ApiOperation;
18 -import okhttp3.Response;  
19 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.security.access.prepost.PreAuthorize; 12 import org.springframework.security.access.prepost.PreAuthorize;
21 import org.springframework.stereotype.Controller; 13 import org.springframework.stereotype.Controller;
22 import org.springframework.transaction.annotation.Transactional; 14 import org.springframework.transaction.annotation.Transactional;
23 import org.springframework.web.bind.annotation.*; 15 import org.springframework.web.bind.annotation.*;
24 16
25 -import javax.servlet.http.HttpServletResponse;  
26 import java.io.IOException; 17 import java.io.IOException;
27 -import java.util.HashMap;  
28 import java.util.Map; 18 import java.util.Map;
29 19
30 @Api(tags = "设备控制") 20 @Api(tags = "设备控制")
@@ -32,19 +22,7 @@ import java.util.Map; @@ -32,19 +22,7 @@ import java.util.Map;
32 @RequestMapping("/iot/iotDeviceControl") 22 @RequestMapping("/iot/iotDeviceControl")
33 public class IotDeviceControlController { 23 public class IotDeviceControlController {
34 @Autowired 24 @Autowired
35 - private IIotDeviceService iotDeviceService;  
36 - @Autowired  
37 - private IIotTerminalService iIotTerminalService;  
38 - private String getServiceAdrres(HttpServletResponse response,String imei) throws IOException {  
39 - IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);  
40 - response.setCharacterEncoding("UTF-8");  
41 - if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))  
42 - {  
43 - response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));  
44 - return null;  
45 - }  
46 - return "http://"+iotDevice.getListen_service_ip()+"device/control/"+imei;  
47 - } 25 + private DeviceControlService deviceControlService;
48 26
49 @ApiOperation("固件版本更新") 27 @ApiOperation("固件版本更新")
50 @ApiImplicitParams({ 28 @ApiImplicitParams({
@@ -55,20 +33,8 @@ public class IotDeviceControlController { @@ -55,20 +33,8 @@ public class IotDeviceControlController {
55 @Log(title = "设备控制", businessType = BusinessType.UPDATE) 33 @Log(title = "设备控制", businessType = BusinessType.UPDATE)
56 @ResponseBody 34 @ResponseBody
57 @PostMapping("/firmwareUp/{imei}") 35 @PostMapping("/firmwareUp/{imei}")
58 - public String firmwareUp(HttpServletResponse response,@PathVariable String imei,String firmwareVersion,Integer code) throws IOException {  
59 - String url = getServiceAdrres(response,imei);  
60 - if(null == url)  
61 - {  
62 - return null;  
63 - }  
64 - Map<String,Object> map = new HashMap<>();  
65 - Map<String,Object> valueMap = new HashMap<>();  
66 - valueMap.put("firmwareVersion",firmwareVersion);  
67 - valueMap.put("code",code);  
68 - Response response1 = HttpUtils.postJsonBody(url, formBody -> {  
69 - formBody.put("0", valueMap);  
70 - });  
71 - return response1.body().string(); 36 + public Message firmwareUp(@PathVariable String imei,String firmwareVersion,Integer code) throws IOException {
  37 + return deviceControlService.firmwareUp(imei,firmwareVersion,code);
72 } 38 }
73 39
74 @ApiOperation("设备重启") 40 @ApiOperation("设备重启")
@@ -80,18 +46,8 @@ public class IotDeviceControlController { @@ -80,18 +46,8 @@ public class IotDeviceControlController {
80 @Log(title = "设备控制", businessType = BusinessType.UPDATE) 46 @Log(title = "设备控制", businessType = BusinessType.UPDATE)
81 @ResponseBody 47 @ResponseBody
82 @PostMapping("/restart/{imei}/{restart}") 48 @PostMapping("/restart/{imei}/{restart}")
83 - public String restart(HttpServletResponse response,@PathVariable String imei ,@PathVariable Integer restart) throws IOException {  
84 - String url = getServiceAdrres(response,imei);  
85 - if(null == url)  
86 - {  
87 - return null;  
88 - }  
89 - Map<String,Object> valueMap = new HashMap<>();  
90 - valueMap.put("restart",restart);  
91 - Response response1 = HttpUtils.postJsonBody(url, formBody -> {  
92 - formBody.put("0",valueMap);  
93 - });  
94 - return response1.body().string(); 49 + public Message restart(@PathVariable String imei ,@PathVariable Integer restart) {
  50 + return deviceControlService.restart(imei,restart);
95 } 51 }
96 52
97 @ApiOperation("获取指定设备版本信息") 53 @ApiOperation("获取指定设备版本信息")
@@ -100,20 +56,8 @@ public class IotDeviceControlController { @@ -100,20 +56,8 @@ public class IotDeviceControlController {
100 }) 56 })
101 @ResponseBody 57 @ResponseBody
102 @PostMapping("/getFirmwareVersion/{imei}") 58 @PostMapping("/getFirmwareVersion/{imei}")
103 - public String getFirmwareVersion(HttpServletResponse response,@PathVariable String imei) throws IOException {  
104 - IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);  
105 - response.setCharacterEncoding("UTF-8");  
106 - if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))  
107 - {  
108 - response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));  
109 - return null;  
110 - }  
111 - String url = "http://"+iotDevice.getListen_service_ip()+"device/getFirmwareVersion/"+iotDevice.getMqtt_username();  
112 -  
113 - Response response1 = HttpUtils.postFromBody(url, builder -> {  
114 - }, formBody -> {  
115 - });  
116 - return response1.body().string(); 59 + public Message getFirmwareVersion(@PathVariable String imei) {
  60 + return deviceControlService.getFirmwareVersion(imei);
117 } 61 }
118 62
119 @ApiOperation("强行断开链接") 63 @ApiOperation("强行断开链接")
@@ -122,20 +66,8 @@ public class IotDeviceControlController { @@ -122,20 +66,8 @@ public class IotDeviceControlController {
122 }) 66 })
123 @ResponseBody 67 @ResponseBody
124 @PostMapping("/closeSession/{imei}") 68 @PostMapping("/closeSession/{imei}")
125 - public String closeSession(HttpServletResponse response,@PathVariable String imei) throws IOException {  
126 - IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);  
127 - response.setCharacterEncoding("UTF-8");  
128 - if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))  
129 - {  
130 - response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));  
131 - return null;  
132 - }  
133 - String url = "http://"+iotDevice.getListen_service_ip()+"device/closeSession/"+imei;  
134 -  
135 - Response response1 = HttpUtils.postFromBody(url, builder -> {  
136 - }, formBody -> {  
137 - });  
138 - return response1.body().string(); 69 + public Message closeSession(@PathVariable String imei) {
  70 + return deviceControlService.closeSession(imei);
139 } 71 }
140 72
141 @ApiOperation("删除主机") 73 @ApiOperation("删除主机")
@@ -145,28 +77,8 @@ public class IotDeviceControlController { @@ -145,28 +77,8 @@ public class IotDeviceControlController {
145 @Transactional 77 @Transactional
146 @ResponseBody 78 @ResponseBody
147 @PostMapping("/delIotDevice/{imei}") 79 @PostMapping("/delIotDevice/{imei}")
148 - public String delIotDevice(HttpServletResponse response,@PathVariable String imei) {  
149 - IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);  
150 - iotDeviceService.deleteIotDeviceByClient_id(imei);  
151 - iIotTerminalService.deleteIotTerminalByDeviceId(imei);  
152 - response.setCharacterEncoding("UTF-8");  
153 - if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))  
154 - {  
155 - return JSONObject.toJSONString(new Message(MessageCode.DEFAULT_SUCCESS_CODE,"删除成功"));  
156 - }  
157 - String url = "http://"+iotDevice.getListen_service_ip()+"device/delIotDevice/"+imei;  
158 -  
159 - try {  
160 - String str = HttpUtils.getResponseString(HttpUtils.postFromBody(url, builder -> {  
161 - }, formBody -> {  
162 - }));  
163 - if(null != str)  
164 - {  
165 - return str;  
166 - }  
167 - } catch (IOException e) {  
168 - }  
169 - return JSONObject.toJSONString(new Message(MessageCode.DEFAULT_SUCCESS_CODE,"删除成功")); 80 + public Message delIotDevice(@PathVariable String imei) {
  81 + return deviceControlService.delIotDevice(imei);
170 82
171 } 83 }
172 84
@@ -176,9 +88,8 @@ public class IotDeviceControlController { @@ -176,9 +88,8 @@ public class IotDeviceControlController {
176 }) 88 })
177 @ResponseBody 89 @ResponseBody
178 @PostMapping("/delIotTerminal/{imei}/{number}") 90 @PostMapping("/delIotTerminal/{imei}/{number}")
179 - public String delIotTerminal(HttpServletResponse response,@PathVariable String imei,@PathVariable String number) {  
180 - response.setCharacterEncoding("UTF-8");  
181 - return iIotTerminalService.deleteIotTerminalById(imei,number); 91 + public Message delIotTerminal(@PathVariable String imei,@PathVariable String number) {
  92 + return deviceControlService.delIotTerminal(imei,number);
182 } 93 }
183 94
184 @ApiOperation(value = "读取属性") 95 @ApiOperation(value = "读取属性")
@@ -191,19 +102,8 @@ public class IotDeviceControlController { @@ -191,19 +102,8 @@ public class IotDeviceControlController {
191 @Log(title = "设备控制", businessType = BusinessType.UPDATE) 102 @Log(title = "设备控制", businessType = BusinessType.UPDATE)
192 @ResponseBody 103 @ResponseBody
193 @PostMapping("/readAttribute/{imei}/{sensor_number}") 104 @PostMapping("/readAttribute/{imei}/{sensor_number}")
194 - public String readAttribute(HttpServletResponse response,@PathVariable String imei,@PathVariable String sensor_number,String attributes) throws IOException {  
195 - IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);  
196 - response.setCharacterEncoding("UTF-8");  
197 - if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))  
198 - {  
199 - response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));  
200 - return null;  
201 - }  
202 - String url = "http://"+iotDevice.getListen_service_ip()+"device/read/"+imei;  
203 - Map<String,Object> map = new HashMap<>();  
204 - map.put(sensor_number,attributes);  
205 - Response response1 = HttpUtils.postJsonBody(url, jsonObject -> jsonObject.putAll(map));  
206 - return response1.body().string(); 105 + public Message readAttribute(@PathVariable String imei,@PathVariable String sensor_number,String attributes) {
  106 + return deviceControlService.readAttribute(imei,sensor_number,attributes);
207 } 107 }
208 108
209 @ApiOperation(value = "设置主机自定义参数",notes = "自定义数据模型:\n" + 109 @ApiOperation(value = "设置主机自定义参数",notes = "自定义数据模型:\n" +
@@ -222,18 +122,8 @@ public class IotDeviceControlController { @@ -222,18 +122,8 @@ public class IotDeviceControlController {
222 @Log(title = "设备控制", businessType = BusinessType.UPDATE) 122 @Log(title = "设备控制", businessType = BusinessType.UPDATE)
223 @ResponseBody 123 @ResponseBody
224 @PostMapping("/upSummary/{imei}") 124 @PostMapping("/upSummary/{imei}")
225 - public String upSummary(HttpServletResponse response,@PathVariable String imei,String summary) throws IOException {  
226 - String url = getServiceAdrres(response,imei);  
227 - if(null == url)  
228 - {  
229 - return null;  
230 - }  
231 - Map<String,Object> valueMap = new HashMap<>();  
232 - valueMap.put("summary",JSONObject.parseObject(summary));  
233 - Response response1 = HttpUtils.postJsonBody(url,formBody -> {  
234 - formBody.put("0", valueMap);  
235 - });  
236 - return response1.body().string(); 125 + public Message upSummary(@PathVariable String imei,String summary) {
  126 + return deviceControlService.upSummary(imei,summary);
237 } 127 }
238 128
239 @ApiOperation(value = "修改指定终端属性",notes = "配置参数模型:\n" + 129 @ApiOperation(value = "修改指定终端属性",notes = "配置参数模型:\n" +
@@ -251,16 +141,8 @@ public class IotDeviceControlController { @@ -251,16 +141,8 @@ public class IotDeviceControlController {
251 @Log(title = "设备控制", businessType = BusinessType.UPDATE) 141 @Log(title = "设备控制", businessType = BusinessType.UPDATE)
252 @ResponseBody 142 @ResponseBody
253 @PostMapping("/upTerminalConfig/{imei}/{number}") 143 @PostMapping("/upTerminalConfig/{imei}/{number}")
254 - public String upTerminalConfig(HttpServletResponse response, @PathVariable String imei,@PathVariable String number,@RequestBody Map<String,Object> config) throws IOException {  
255 - String url = getServiceAdrres(response,imei);  
256 - if(null == url)  
257 - {  
258 - return null;  
259 - }  
260 - Map<String,Object> map = new HashMap<>();  
261 - map.put(number,config);  
262 - Response response1 = HttpUtils.postJsonBody(url, jsonObject -> jsonObject.putAll(map));  
263 - return response1.body().string(); 144 + public Message upTerminalConfig(@PathVariable String imei,@PathVariable String number,@RequestBody Map<String,Object> config) {
  145 + return deviceControlService.upTerminalConfig(imei,number,config);
264 } 146 }
265 147
266 @ApiOperation(value = "批量修改终端属性",notes = "批量数据模型:\n" + 148 @ApiOperation(value = "批量修改终端属性",notes = "批量数据模型:\n" +
@@ -286,22 +168,8 @@ public class IotDeviceControlController { @@ -286,22 +168,8 @@ public class IotDeviceControlController {
286 @Log(title = "设备控制", businessType = BusinessType.UPDATE) 168 @Log(title = "设备控制", businessType = BusinessType.UPDATE)
287 @ResponseBody 169 @ResponseBody
288 @PostMapping("/batchUpTerminalConfig/{imei}") 170 @PostMapping("/batchUpTerminalConfig/{imei}")
289 - public String batchUpTerminalConfig(HttpServletResponse response,@PathVariable String imei,@RequestBody Map<String,Object> map) throws IOException {  
290 - String url = getServiceAdrres(response,imei);  
291 - if(null == url)  
292 - {  
293 - return null;  
294 - }  
295 - Response response1 = HttpUtils.postJsonBody(url, builder -> {  
296 -  
297 - }, formBody -> {  
298 - for (String key:map.keySet())  
299 - {  
300 - formBody.put(key, map.get(key));  
301 - }  
302 -  
303 - });  
304 - return response1.body().string(); 171 + public Message batchUpTerminalConfig(@PathVariable String imei,@RequestBody Map<String,Object> map) {
  172 + return deviceControlService.batchUpTerminalConfig(imei,map);
305 } 173 }
306 174
307 } 175 }
1 -# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8080 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-admin # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login,/register,/captchaImage,/getCacheObject,/v2/api-docs,/tool/gen/generatorCodeFromDb  
  1 +# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8080 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-admin # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login,/register,/captchaImage,/getCacheObject,/v2/api-docs,/tool/gen/generatorCodeFromDb # NameServer地址 rocketmq: name-server: 47.115.144.179:9876 # 默认的消息组 producer: group: deviceCommand send-message-timeout: 30000 send-topic: lh-mqtt-service-deviceCommand-test send-tags: 1
1 package com.zhonglai.luhui.api.controller.iot; 1 package com.zhonglai.luhui.api.controller.iot;
2 2
3 -import com.alibaba.fastjson.JSONObject;  
4 import com.ruoyi.common.annotation.Log; 3 import com.ruoyi.common.annotation.Log;
5 import com.ruoyi.common.core.domain.Message; 4 import com.ruoyi.common.core.domain.Message;
6 -import com.ruoyi.common.core.domain.MessageCode;  
7 import com.ruoyi.common.enums.BusinessType; 5 import com.ruoyi.common.enums.BusinessType;
8 -import com.ruoyi.common.utils.StringUtils;  
9 -import com.ruoyi.common.utils.html.HttpUtils;  
10 -import com.ruoyi.system.domain.IotDevice;  
11 -import com.ruoyi.system.service.IIotDeviceService;  
12 -import com.ruoyi.system.service.IIotTerminalService; 6 +import com.ruoyi.system.service.DeviceControlService;
13 import io.swagger.annotations.Api; 7 import io.swagger.annotations.Api;
14 import io.swagger.annotations.ApiImplicitParam; 8 import io.swagger.annotations.ApiImplicitParam;
15 import io.swagger.annotations.ApiImplicitParams; 9 import io.swagger.annotations.ApiImplicitParams;
16 import io.swagger.annotations.ApiOperation; 10 import io.swagger.annotations.ApiOperation;
17 -import okhttp3.Response;  
18 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.beans.factory.annotation.Autowired;
19 -import org.springframework.security.access.prepost.PreAuthorize;  
20 import org.springframework.stereotype.Controller; 12 import org.springframework.stereotype.Controller;
21 import org.springframework.transaction.annotation.Transactional; 13 import org.springframework.transaction.annotation.Transactional;
22 import org.springframework.web.bind.annotation.*; 14 import org.springframework.web.bind.annotation.*;
23 15
24 -import javax.servlet.http.HttpServletResponse;  
25 import java.io.IOException; 16 import java.io.IOException;
26 -import java.util.HashMap;  
27 import java.util.Map; 17 import java.util.Map;
28 18
29 @Api(tags = "设备控制") 19 @Api(tags = "设备控制")
@@ -31,20 +21,8 @@ import java.util.Map; @@ -31,20 +21,8 @@ import java.util.Map;
31 @RequestMapping("/iot/iotDeviceControl") 21 @RequestMapping("/iot/iotDeviceControl")
32 public class IotDeviceControlController { 22 public class IotDeviceControlController {
33 @Autowired 23 @Autowired
34 - private IIotDeviceService iotDeviceService;  
35 - @Autowired  
36 - private IIotTerminalService iIotTerminalService;  
37 - private String getServiceAdrres(HttpServletResponse response,String imei) throws IOException {  
38 - IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);  
39 - response.setCharacterEncoding("UTF-8");  
40 - if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))  
41 - {  
42 - response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));  
43 - return null;  
44 - }  
45 - return "http://"+iotDevice.getListen_service_ip()+"device/control/"+imei;  
46 - }  
47 - 24 + private DeviceControlService deviceControlService;
  25 +
48 @ApiOperation("固件版本更新") 26 @ApiOperation("固件版本更新")
49 @ApiImplicitParams({ 27 @ApiImplicitParams({
50 @ApiImplicitParam(value = "主机imei",name = "imei"), 28 @ApiImplicitParam(value = "主机imei",name = "imei"),
@@ -53,20 +31,8 @@ public class IotDeviceControlController { @@ -53,20 +31,8 @@ public class IotDeviceControlController {
53 @Log(title = "设备控制", businessType = BusinessType.UPDATE) 31 @Log(title = "设备控制", businessType = BusinessType.UPDATE)
54 @ResponseBody 32 @ResponseBody
55 @PostMapping("/firmwareUp/{imei}") 33 @PostMapping("/firmwareUp/{imei}")
56 - public String firmwareUp(HttpServletResponse response,@PathVariable String imei,String firmwareVersion,Integer code) throws IOException {  
57 - String url = getServiceAdrres(response,imei);  
58 - if(null == url)  
59 - {  
60 - return null;  
61 - }  
62 - Map<String,Object> map = new HashMap<>();  
63 - Map<String,Object> valueMap = new HashMap<>();  
64 - valueMap.put("firmwareVersion",firmwareVersion);  
65 - valueMap.put("code",code);  
66 - Response response1 = HttpUtils.postJsonBody(url, formBody -> {  
67 - formBody.put("0", valueMap);  
68 - });  
69 - return response1.body().string(); 34 + public Message firmwareUp(@PathVariable String imei,String firmwareVersion,Integer code) throws IOException {
  35 + return deviceControlService.firmwareUp(imei,firmwareVersion,code);
70 } 36 }
71 37
72 @ApiOperation("设备重启") 38 @ApiOperation("设备重启")
@@ -77,18 +43,8 @@ public class IotDeviceControlController { @@ -77,18 +43,8 @@ public class IotDeviceControlController {
77 @Log(title = "设备控制", businessType = BusinessType.UPDATE) 43 @Log(title = "设备控制", businessType = BusinessType.UPDATE)
78 @ResponseBody 44 @ResponseBody
79 @PostMapping("/restart/{imei}/{restart}") 45 @PostMapping("/restart/{imei}/{restart}")
80 - public String restart(HttpServletResponse response,@PathVariable String imei ,@PathVariable Integer restart) throws IOException {  
81 - String url = getServiceAdrres(response,imei);  
82 - if(null == url)  
83 - {  
84 - return null;  
85 - }  
86 - Map<String,Object> valueMap = new HashMap<>();  
87 - valueMap.put("restart",restart);  
88 - Response response1 = HttpUtils.postJsonBody(url, formBody -> {  
89 - formBody.put("0",valueMap);  
90 - });  
91 - return response1.body().string(); 46 + public Message restart(@PathVariable String imei ,@PathVariable Integer restart) {
  47 + return deviceControlService.restart(imei,restart);
92 } 48 }
93 49
94 @ApiOperation("获取指定设备版本信息") 50 @ApiOperation("获取指定设备版本信息")
@@ -97,20 +53,8 @@ public class IotDeviceControlController { @@ -97,20 +53,8 @@ public class IotDeviceControlController {
97 }) 53 })
98 @ResponseBody 54 @ResponseBody
99 @PostMapping("/getFirmwareVersion/{imei}") 55 @PostMapping("/getFirmwareVersion/{imei}")
100 - public String getFirmwareVersion(HttpServletResponse response,@PathVariable String imei) throws IOException {  
101 - IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);  
102 - response.setCharacterEncoding("UTF-8");  
103 - if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))  
104 - {  
105 - response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));  
106 - return null;  
107 - }  
108 - String url = "http://"+iotDevice.getListen_service_ip()+"device/getFirmwareVersion/"+iotDevice.getMqtt_username();  
109 -  
110 - Response response1 = HttpUtils.postFromBody(url, builder -> {  
111 - }, formBody -> {  
112 - });  
113 - return response1.body().string(); 56 + public Message getFirmwareVersion(@PathVariable String imei) {
  57 + return deviceControlService.getFirmwareVersion(imei);
114 } 58 }
115 59
116 @ApiOperation("强行断开链接") 60 @ApiOperation("强行断开链接")
@@ -119,20 +63,8 @@ public class IotDeviceControlController { @@ -119,20 +63,8 @@ public class IotDeviceControlController {
119 }) 63 })
120 @ResponseBody 64 @ResponseBody
121 @PostMapping("/closeSession/{imei}") 65 @PostMapping("/closeSession/{imei}")
122 - public String closeSession(HttpServletResponse response,@PathVariable String imei) throws IOException {  
123 - IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);  
124 - response.setCharacterEncoding("UTF-8");  
125 - if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))  
126 - {  
127 - response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));  
128 - return null;  
129 - }  
130 - String url = "http://"+iotDevice.getListen_service_ip()+"device/closeSession/"+imei;  
131 -  
132 - Response response1 = HttpUtils.postFromBody(url, builder -> {  
133 - }, formBody -> {  
134 - });  
135 - return response1.body().string(); 66 + public Message closeSession(@PathVariable String imei) {
  67 + return deviceControlService.closeSession(imei);
136 } 68 }
137 69
138 @ApiOperation("删除主机") 70 @ApiOperation("删除主机")
@@ -142,29 +74,8 @@ public class IotDeviceControlController { @@ -142,29 +74,8 @@ public class IotDeviceControlController {
142 @Transactional 74 @Transactional
143 @ResponseBody 75 @ResponseBody
144 @PostMapping("/delIotDevice/{imei}") 76 @PostMapping("/delIotDevice/{imei}")
145 - public String delIotDevice(HttpServletResponse response,@PathVariable String imei) {  
146 - IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);  
147 - iotDeviceService.deleteIotDeviceByClient_id(imei);  
148 - iIotTerminalService.deleteIotTerminalByDeviceId(imei);  
149 - response.setCharacterEncoding("UTF-8");  
150 - if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))  
151 - {  
152 - return JSONObject.toJSONString(new Message(MessageCode.DEFAULT_SUCCESS_CODE,"删除成功"));  
153 - }  
154 - String url = "http://"+iotDevice.getListen_service_ip()+"device/delIotDevice/"+imei;  
155 -  
156 - try {  
157 - String str = HttpUtils.getResponseString(HttpUtils.postFromBody(url, builder -> {  
158 - }, formBody -> {  
159 - }));  
160 - if(null != str)  
161 - {  
162 - return str;  
163 - }  
164 - } catch (IOException e) {  
165 - }  
166 - return JSONObject.toJSONString(new Message(MessageCode.DEFAULT_SUCCESS_CODE,"删除成功"));  
167 - 77 + public Message delIotDevice(@PathVariable String imei) {
  78 + return deviceControlService.delIotDevice(imei);
168 } 79 }
169 80
170 @ApiOperation("删除终端") 81 @ApiOperation("删除终端")
@@ -173,8 +84,8 @@ public class IotDeviceControlController { @@ -173,8 +84,8 @@ public class IotDeviceControlController {
173 }) 84 })
174 @ResponseBody 85 @ResponseBody
175 @PostMapping("/delIotTerminal/{imei}/{number}") 86 @PostMapping("/delIotTerminal/{imei}/{number}")
176 - public String delIotTerminal(@PathVariable String imei,@PathVariable String number) {  
177 - return iIotTerminalService.deleteIotTerminalById(imei,number); 87 + public Message delIotTerminal(@PathVariable String imei,@PathVariable String number) {
  88 + return deviceControlService.delIotTerminal(imei,number);
178 } 89 }
179 90
180 @ApiOperation(value = "读取属性") 91 @ApiOperation(value = "读取属性")
@@ -186,19 +97,8 @@ public class IotDeviceControlController { @@ -186,19 +97,8 @@ public class IotDeviceControlController {
186 @Log(title = "设备控制", businessType = BusinessType.UPDATE) 97 @Log(title = "设备控制", businessType = BusinessType.UPDATE)
187 @ResponseBody 98 @ResponseBody
188 @PostMapping("/readAttribute/{imei}/{sensor_number}") 99 @PostMapping("/readAttribute/{imei}/{sensor_number}")
189 - public String readAttribute(HttpServletResponse response,@PathVariable String imei,@PathVariable String sensor_number,String attributes) throws IOException {  
190 - IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);  
191 - response.setCharacterEncoding("UTF-8");  
192 - if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))  
193 - {  
194 - response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));  
195 - return null;  
196 - }  
197 - String url = "http://"+iotDevice.getListen_service_ip()+"device/read/"+imei;  
198 - Map<String,Object> map = new HashMap<>();  
199 - map.put(sensor_number,attributes);  
200 - Response response1 = HttpUtils.postJsonBody(url, jsonObject -> jsonObject.putAll(map));  
201 - return response1.body().string(); 100 + public Message readAttribute(@PathVariable String imei,@PathVariable String sensor_number,String attributes) {
  101 + return deviceControlService.readAttribute(imei,sensor_number,attributes);
202 } 102 }
203 103
204 @ApiOperation(value = "设置主机自定义参数",notes = "自定义数据模型:\n" + 104 @ApiOperation(value = "设置主机自定义参数",notes = "自定义数据模型:\n" +
@@ -216,18 +116,8 @@ public class IotDeviceControlController { @@ -216,18 +116,8 @@ public class IotDeviceControlController {
216 @Log(title = "设备控制", businessType = BusinessType.UPDATE) 116 @Log(title = "设备控制", businessType = BusinessType.UPDATE)
217 @ResponseBody 117 @ResponseBody
218 @PostMapping("/upSummary/{imei}") 118 @PostMapping("/upSummary/{imei}")
219 - public String upSummary(HttpServletResponse response,@PathVariable String imei,String summary) throws IOException {  
220 - String url = getServiceAdrres(response,imei);  
221 - if(null == url)  
222 - {  
223 - return null;  
224 - }  
225 - Map<String,Object> valueMap = new HashMap<>();  
226 - valueMap.put("summary",JSONObject.parseObject(summary));  
227 - Response response1 = HttpUtils.postJsonBody(url,formBody -> {  
228 - formBody.put("0", valueMap);  
229 - });  
230 - return response1.body().string(); 119 + public Message upSummary(@PathVariable String imei,String summary) {
  120 + return deviceControlService.upSummary(imei,summary);
231 } 121 }
232 122
233 @ApiOperation(value = "修改指定终端属性",notes = "配置参数模型:\n" + 123 @ApiOperation(value = "修改指定终端属性",notes = "配置参数模型:\n" +
@@ -244,16 +134,8 @@ public class IotDeviceControlController { @@ -244,16 +134,8 @@ public class IotDeviceControlController {
244 @Log(title = "设备控制", businessType = BusinessType.UPDATE) 134 @Log(title = "设备控制", businessType = BusinessType.UPDATE)
245 @ResponseBody 135 @ResponseBody
246 @PostMapping("/upTerminalConfig/{imei}/{number}") 136 @PostMapping("/upTerminalConfig/{imei}/{number}")
247 - public String upTerminalConfig(HttpServletResponse response, @PathVariable String imei,@PathVariable String number,@RequestBody Map<String,Object> config) throws IOException {  
248 - String url = getServiceAdrres(response,imei);  
249 - if(null == url)  
250 - {  
251 - return null;  
252 - }  
253 - Map<String,Object> map = new HashMap<>();  
254 - map.put(number,config);  
255 - Response response1 = HttpUtils.postJsonBody(url, jsonObject -> jsonObject.putAll(map));  
256 - return response1.body().string(); 137 + public Message upTerminalConfig( @PathVariable String imei,@PathVariable String number,@RequestBody Map<String,Object> config) {
  138 + return deviceControlService.upTerminalConfig(imei,number,config);
257 } 139 }
258 140
259 @ApiOperation(value = "批量修改终端属性",notes = "批量数据模型:\n" + 141 @ApiOperation(value = "批量修改终端属性",notes = "批量数据模型:\n" +
@@ -278,23 +160,7 @@ public class IotDeviceControlController { @@ -278,23 +160,7 @@ public class IotDeviceControlController {
278 @Log(title = "设备控制", businessType = BusinessType.UPDATE) 160 @Log(title = "设备控制", businessType = BusinessType.UPDATE)
279 @ResponseBody 161 @ResponseBody
280 @PostMapping("/batchUpTerminalConfig/{imei}") 162 @PostMapping("/batchUpTerminalConfig/{imei}")
281 - public String batchUpTerminalConfig(HttpServletResponse response,@PathVariable String imei,@RequestBody Map<String,Object> map) throws IOException {  
282 - String url = getServiceAdrres(response,imei);  
283 - if(null == url)  
284 - {  
285 - return null;  
286 - }  
287 - Response response1 = HttpUtils.postJsonBody(url, builder -> {  
288 -  
289 - }, formBody -> {  
290 - for (String key:map.keySet())  
291 - {  
292 - formBody.put(key, map.get(key));  
293 - }  
294 -  
295 - });  
296 - return response1.body().string(); 163 + public Message batchUpTerminalConfig(@PathVariable String imei,@RequestBody Map<String,Object> map) {
  164 + return deviceControlService.batchUpTerminalConfig(imei,map);
297 } 165 }
298 -  
299 -  
300 } 166 }
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5 + <parent>
  6 + <artifactId>Luhui</artifactId>
  7 + <groupId>com.zhonglai.luhui</groupId>
  8 + <version>1.0-SNAPSHOT</version>
  9 + </parent>
  10 + <modelVersion>4.0.0</modelVersion>
  11 +
  12 + <artifactId>lh-backups</artifactId>
  13 +
  14 + <dependencies>
  15 + <!-- spring-boot-devtools -->
  16 + <dependency>
  17 + <groupId>org.springframework.boot</groupId>
  18 + <artifactId>spring-boot-devtools</artifactId>
  19 + <optional>true</optional> <!-- 表示依赖不会传递 -->
  20 + </dependency>
  21 + <!-- SpringBoot Web容器 -->
  22 + <dependency>
  23 + <groupId>org.springframework.boot</groupId>
  24 + <artifactId>spring-boot-starter-web</artifactId>
  25 + </dependency>
  26 + <!-- Spring框架基本的核心工具 -->
  27 + <dependency>
  28 + <groupId>org.springframework</groupId>
  29 + <artifactId>spring-context-support</artifactId>
  30 + </dependency>
  31 + <!-- SpringWeb模块 -->
  32 + <dependency>
  33 + <groupId>org.springframework</groupId>
  34 + <artifactId>spring-web</artifactId>
  35 + </dependency>
  36 + <dependency>
  37 + <groupId>com.zhonglai.luhui</groupId>
  38 + <artifactId>ruoyi-framework</artifactId>
  39 + </dependency>
  40 +
  41 + <!-- Mysql驱动包 -->
  42 + <dependency>
  43 + <groupId>mysql</groupId>
  44 + <artifactId>mysql-connector-java</artifactId>
  45 + </dependency>
  46 + <!-- 文档 -->
  47 + <dependency >
  48 + <groupId>io.springfox</groupId>
  49 + <artifactId>springfox-swagger2</artifactId>
  50 + <version>${swagger.version}</version>
  51 + <exclusions>
  52 + <exclusion>
  53 + <groupId>io.swagger</groupId>
  54 + <artifactId>swagger-models</artifactId>
  55 + </exclusion>
  56 + <exclusion>
  57 + <groupId>com.google.guava</groupId>
  58 + <artifactId>guava</artifactId>
  59 + </exclusion>
  60 + </exclusions>
  61 + </dependency>
  62 + <!--https://mvnrepository.com/artifact/io.swagger/swagger-models-->
  63 + <dependency>
  64 + <groupId>io.swagger</groupId>
  65 + <artifactId>swagger-models</artifactId>
  66 + <version>${swagger-models.version}</version>
  67 + </dependency>
  68 + <dependency>
  69 + <groupId>io.springfox</groupId>
  70 + <artifactId>springfox-swagger-ui</artifactId>
  71 + <version>${swagger.version}</version>
  72 + </dependency>
  73 + <!--&lt;!&ndash; https://mvnrepository.com/artifact/com.github.xiaoymin/swagger-bootstrap-ui &ndash;&gt;-->
  74 + <dependency>
  75 + <groupId>com.github.xiaoymin</groupId>
  76 + <artifactId>swagger-bootstrap-ui</artifactId>
  77 + <version>${swagger-ui.version}</version>
  78 + </dependency>
  79 +
  80 + <dependency>
  81 + <groupId>org.aspectj</groupId>
  82 + <artifactId>aspectjweaver</artifactId>
  83 + </dependency>
  84 + <dependency>
  85 + <groupId>org.aspectj</groupId>
  86 + <artifactId>aspectjrt</artifactId>
  87 + </dependency>
  88 +
  89 + </dependencies>
  90 +
  91 + <build>
  92 + <finalName>lh-backups</finalName>
  93 + <plugins>
  94 + <plugin>
  95 + <groupId>org.apache.maven.plugins</groupId>
  96 + <artifactId>maven-jar-plugin</artifactId>
  97 + <version>2.4</version>
  98 + <configuration>
  99 + <archive>
  100 + <!--
  101 + 生成的jar中,不要包含pom.xml和pom.properties这两个文件
  102 + -->
  103 + <addMavenDescriptor>false</addMavenDescriptor>
  104 + <manifest>
  105 + <!--
  106 + 是否要把第三方jar放到manifest的classpath中
  107 + -->
  108 + <addClasspath>true</addClasspath>
  109 +
  110 + <!--
  111 + 生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/
  112 + -->
  113 + <classpathPrefix>lib/</classpathPrefix>
  114 + <mainClass>com.zhonglai.luhui.backups.LhBackupsApplication</mainClass>
  115 + </manifest>
  116 + </archive>
  117 + </configuration>
  118 + </plugin>
  119 +
  120 + <!-- The configuration of maven-assembly-plugin -->
  121 + <plugin>
  122 + <groupId>org.apache.maven.plugins</groupId>
  123 + <artifactId>maven-assembly-plugin</artifactId>
  124 + <version>2.4</version>
  125 + <configuration>
  126 + <descriptors>
  127 + <descriptor>src/main/resources/package.xml</descriptor>
  128 + </descriptors>
  129 + </configuration>
  130 + <executions>
  131 + <execution>
  132 + <id>make-assembly</id>
  133 + <phase>package</phase>
  134 + <goals>
  135 + <goal>single</goal>
  136 + </goals>
  137 + </execution>
  138 + </executions>
  139 + </plugin>
  140 + </plugins>
  141 + </build>
  142 +</project>
  1 +package com.zhonglai.luhui.backups;
  2 +
  3 +import org.springframework.boot.SpringApplication;
  4 +import org.springframework.boot.autoconfigure.SpringBootApplication;
  5 +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  6 +import org.springframework.context.annotation.ComponentScan;
  7 +
  8 +@ComponentScan(basePackages = {
  9 + "com.ruoyi.common",
  10 + "com.ruoyi.system",
  11 + "com.zhonglai.luhui.backups.config",
  12 + "com.zhonglai.luhui.backups.controller",
  13 +})
  14 +@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
  15 +public class LhBackupsApplication {
  16 + public static void main(String[] args) {
  17 + SpringApplication.run(LhBackupsApplication.class,args);
  18 + System.out.println("启动成功");
  19 + }
  20 +}
  1 +package com.zhonglai.luhui.backups.config;
  2 +
  3 +import com.ruoyi.common.config.RuoYiConfig;
  4 +import io.swagger.annotations.ApiOperation;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.context.annotation.Bean;
  7 +import org.springframework.context.annotation.Configuration;
  8 +import springfox.documentation.builders.ApiInfoBuilder;
  9 +import springfox.documentation.builders.PathSelectors;
  10 +import springfox.documentation.builders.RequestHandlerSelectors;
  11 +import springfox.documentation.service.ApiInfo;
  12 +import springfox.documentation.service.Contact;
  13 +import springfox.documentation.spi.DocumentationType;
  14 +import springfox.documentation.spring.web.plugins.Docket;
  15 +import springfox.documentation.swagger2.annotations.EnableSwagger2;
  16 +
  17 +
  18 +@Configuration
  19 +@EnableSwagger2
  20 +public class SwaggerConfig {
  21 + /** 系统基础配置 */
  22 + @Autowired
  23 + private RuoYiConfig ruoyiConfig;
  24 + @Bean
  25 + public Docket createRestApi() {
  26 + return new Docket(DocumentationType.SWAGGER_2)
  27 + .apiInfo(apiInfo())
  28 + .select()
  29 + .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
  30 + .paths(PathSelectors.any())
  31 + .build();
  32 + }
  33 +
  34 + /**
  35 + * 添加摘要信息
  36 + */
  37 + private ApiInfo apiInfo()
  38 + {
  39 + // 用ApiInfoBuilder进行定制
  40 + return new ApiInfoBuilder()
  41 + // 设置标题
  42 + .title("标题:后台管理员端")
  43 + // 描述
  44 + .description("描述:用于通过mqtt发送指令控制PC端操作")
  45 + // 作者信息
  46 + .contact(new Contact(ruoyiConfig.getName(), null, null))
  47 + // 版本
  48 + .version("版本号:" + ruoyiConfig.getVersion())
  49 + .build();
  50 + }
  51 +
  52 +}
  1 +package com.zhonglai.luhui.backups.task;
  2 +
  3 +import com.ruoyi.common.utils.StringUtils;
  4 +import com.ruoyi.system.service.PublicService;
  5 +import org.apache.commons.lang3.ArrayUtils;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.context.annotation.Configuration;
  8 +import org.springframework.scheduling.annotation.EnableScheduling;
  9 +import org.springframework.scheduling.annotation.Scheduled;
  10 +
  11 +import java.io.File;
  12 +import java.io.FileWriter;
  13 +import java.io.IOException;
  14 +import java.util.List;
  15 +import java.util.Map;
  16 +
  17 +@Configuration //1.主要用于标记配置类,兼备Component的效果。
  18 +@EnableScheduling // 2.开启定时任务
  19 +public class BackupsDb {
  20 + @Autowired
  21 + private PublicService publicService;
  22 +
  23 + private static String savePath = "F:/webdav/db";
  24 + /**
  25 + * 归档
  26 + */
  27 + @Scheduled(fixedRate=1000)
  28 + private void file() {
  29 + Long ct = publicService.selectCountBySql("SELECT COUNT(*) FROM information_schema.TABLES WHERE table_schema = 'ly-device-data'");
  30 + if(null != ct)
  31 + {
  32 + int pageSize = 10;
  33 + Long pageNo = ct/pageSize;
  34 + if(ct%pageSize>0)
  35 + {
  36 + pageNo +=1;
  37 + }
  38 +
  39 + for(int i=0;i<pageNo;i++)
  40 + {
  41 + StringBuffer tablesql = new StringBuffer("SELECT TABLE_NAME FROM information_schema.TABLES WHERE table_schema = 'ly-device-data' LIMIT ");
  42 + tablesql.append(pageNo);
  43 + tablesql.append(",");
  44 + tablesql.append(pageSize);
  45 + List<Map<String,Object>> tableList = publicService.getObjectListBySQL(""+pageNo+","+pageSize);
  46 + if(null != tableList && tableList.size() !=0)
  47 + {
  48 + for(Map<String,Object> map:tableList)
  49 + {
  50 + String table_name = (String) map.get("TABLE_NAME");
  51 + String path = table_name.split("-")[0];
  52 + File pathFile = new File(savePath+"/"+path);
  53 + if(!pathFile.exists())
  54 + {
  55 + pathFile.mkdirs();
  56 + }
  57 + List<Map<String,Object>> dataList = publicService.getObjectListBySQL("SELECT * FROM `"+table_name+"`");
  58 + if(null != dataList && dataList.size() != 0)
  59 + {
  60 + File saveFile = new File(pathFile.getAbsolutePath()+"/"+table_name+".csv");
  61 + try {
  62 + FileWriter fileWriter = new FileWriter(saveFile);
  63 + for(Map<String,Object> data:dataList)
  64 + {
  65 + fileWriter.write(mapToString(data));
  66 + }
  67 + } catch (IOException e) {
  68 + e.printStackTrace();
  69 + }
  70 +
  71 + }
  72 + }
  73 + }
  74 + }
  75 + }
  76 + }
  77 +
  78 + private String mapToString(Map<String,Object> data)
  79 + {
  80 + if(null == data)
  81 + {
  82 + return null;
  83 + }
  84 + StringBuffer stringBuffer = new StringBuffer();
  85 + for(String key:data.keySet())
  86 + {
  87 + if(stringBuffer.length()!=0)
  88 + {
  89 + stringBuffer.append(",");
  90 + }
  91 + stringBuffer.append(data.get(key));
  92 + }
  93 + return stringBuffer.toString();
  94 + }
  95 +
  96 + /**
  97 + * 转移
  98 + */
  99 + @Scheduled(fixedRate=1000)
  100 + private void transfer() {
  101 +
  102 + }
  103 +}
  1 +# 数据源配置
  2 +spring:
  3 + datasource:
  4 + type: com.alibaba.druid.pool.DruidDataSource
  5 + driverClassName: com.mysql.cj.jdbc.Driver
  6 + druid:
  7 + # 主库数据源
  8 + master:
  9 + url: jdbc:mysql://rm-wz9740un21f09iokuao.mysql.rds.aliyuncs.com:3306/mqtt_broker?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
  10 + username: luhui
  11 + password: Luhui586
  12 + # 从库数据源
  13 + slave:
  14 + # 从数据源开关/默认关闭
  15 + enabled: false
  16 + url:
  17 + username:
  18 + password:
  19 + # 初始连接数
  20 + initialSize: 5
  21 + # 最小连接池数量
  22 + minIdle: 10
  23 + # 最大连接池数量
  24 + maxActive: 20
  25 + # 配置获取连接等待超时的时间
  26 + maxWait: 60000
  27 + # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
  28 + timeBetweenEvictionRunsMillis: 60000
  29 + # 配置一个连接在池中最小生存的时间,单位是毫秒
  30 + minEvictableIdleTimeMillis: 300000
  31 + # 配置一个连接在池中最大生存的时间,单位是毫秒
  32 + maxEvictableIdleTimeMillis: 900000
  33 + # 配置检测连接是否有效
  34 + validationQuery: SELECT 1 FROM DUAL
  35 + testWhileIdle: true
  36 + testOnBorrow: false
  37 + testOnReturn: false
  38 + webStatFilter:
  39 + enabled: true
  40 + statViewServlet:
  41 + enabled: true
  42 + # 设置白名单,不填则允许所有访问
  43 + allow:
  44 + url-pattern: /druid/*
  45 + # 控制台管理用户名和密码
  46 + login-username: ruoyi
  47 + login-password: 123456
  48 + filter:
  49 + stat:
  50 + enabled: true
  51 + # 慢SQL记录
  52 + log-slow-sql: true
  53 + slow-sql-millis: 1000
  54 + merge-sql: true
  55 + wall:
  56 + config:
  57 + multi-statement-allow: true
  1 +# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 18080 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-api # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login/ApiLogin/*
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +
  3 +<assembly>
  4 + <id>bin</id>
  5 + <!-- 最终打包成一个用于发布的zip文件 -->
  6 + <formats>
  7 + <format>zip</format>
  8 + </formats>
  9 +
  10 + <!-- Adds dependencies to zip package under lib directory -->
  11 + <dependencySets>
  12 + <dependencySet>
  13 + <!--
  14 + 不使用项目的artifact,第三方jar不要解压,打包进zip文件的lib目录
  15 + -->
  16 + <useProjectArtifact>false</useProjectArtifact>
  17 + <outputDirectory>lib</outputDirectory>
  18 + <unpack>false</unpack>
  19 + </dependencySet>
  20 + </dependencySets>
  21 +
  22 + <fileSets>
  23 + <!-- 把项目相关的说明文件,打包进zip文件的根目录 -->
  24 + <fileSet>
  25 + <directory>${project.basedir}</directory>
  26 + <outputDirectory>/</outputDirectory>
  27 + <includes>
  28 + <include>README*</include>
  29 + <include>LICENSE*</include>
  30 + <include>NOTICE*</include>
  31 + </includes>
  32 + </fileSet>
  33 +
  34 + <!-- 把项目的配置文件,打包进zip文件的config目录 -->
  35 + <fileSet>
  36 + <directory>${project.basedir}\src\main\resources\configs</directory>
  37 + <outputDirectory>../configs</outputDirectory>
  38 + <includes>
  39 + <include>*.properties</include>
  40 + </includes>
  41 + </fileSet>
  42 +
  43 + <!-- 把项目的配置文件,提出来 -->
  44 + <fileSet>
  45 + <directory>${project.basedir}\src\main\resources</directory>
  46 + <outputDirectory>/</outputDirectory>
  47 + <includes>
  48 + <include>*.properties</include>
  49 + <include>*.yml</include>
  50 + </includes>
  51 + </fileSet>
  52 +
  53 + <!-- 把项目的脚本文件目录( src/main/scripts )中的启动脚本文件,打包进zip文件的跟目录 -->
  54 + <fileSet>
  55 + <directory>${project.basedir}\bin</directory>
  56 + <outputDirectory></outputDirectory>
  57 + <includes>
  58 + <include>start.*</include>
  59 + <include>stop.*</include>
  60 + </includes>
  61 + </fileSet>
  62 +
  63 + <!-- 把项目自己编译出来的jar文件,打包进zip文件的根目录 -->
  64 + <fileSet>
  65 + <directory>${project.build.directory}</directory>
  66 + <outputDirectory></outputDirectory>
  67 + <includes>
  68 + <include>*.jar</include>
  69 + </includes>
  70 + </fileSet>
  71 + </fileSets>
  72 +</assembly>
@@ -19,7 +19,7 @@ import org.springframework.stereotype.Service; @@ -19,7 +19,7 @@ import org.springframework.stereotype.Service;
19 @Service 19 @Service
20 @RocketMQMessageListener(consumerGroup = "deviceCommand", topic = "${rocketmq.send-topic:}",selectorType = SelectorType.TAG,selectorExpression = "${rocketmq.send-tag:}") 20 @RocketMQMessageListener(consumerGroup = "deviceCommand", topic = "${rocketmq.send-topic:}",selectorType = SelectorType.TAG,selectorExpression = "${rocketmq.send-tag:}")
21 public class RocketMqService implements RocketMQReplyListener<MessageExt, Message> { 21 public class RocketMqService implements RocketMQReplyListener<MessageExt, Message> {
22 - private static final Logger log = LoggerFactory.getLogger(MqttCallback.class); 22 + private static final Logger log = LoggerFactory.getLogger(RocketMqService.class);
23 23
24 @Autowired 24 @Autowired
25 private DeviceService deviceService ; 25 private DeviceService deviceService ;
@@ -58,7 +58,7 @@ public class BusinessDataUpdateService { @@ -58,7 +58,7 @@ public class BusinessDataUpdateService {
58 * @param type 58 * @param type
59 * @param topic 59 * @param topic
60 */ 60 */
61 - public void updataDta(Type type, Topic topic, boolean isOperLog, ServerDto serverDto) 61 + public void updataDta(Type type, Topic topic, ServerDto serverDto)
62 { 62 {
63 IotDevice olddevice = cacheService.getIotDevice(topic.getClientid()); 63 IotDevice olddevice = cacheService.getIotDevice(topic.getClientid());
64 64
@@ -81,7 +81,7 @@ public class BusinessDataUpdateService { @@ -81,7 +81,7 @@ public class BusinessDataUpdateService {
81 JSONObject jsData = data.getJSONObject(key); 81 JSONObject jsData = data.getJSONObject(key);
82 if("0".equals(key)) //主机 82 if("0".equals(key)) //主机
83 { 83 {
84 - IotDevice iotDevice = translateDevice(type,olddevice,jsData,isOperLog,serverDto); 84 + IotDevice iotDevice = translateDevice(type,olddevice,jsData,serverDto);
85 if(isText) 85 if(isText)
86 { 86 {
87 iotDevice.setListen_service_ip("127.0.0.1"+":"+port+contextPath); 87 iotDevice.setListen_service_ip("127.0.0.1"+":"+port+contextPath);
@@ -97,7 +97,7 @@ public class BusinessDataUpdateService { @@ -97,7 +97,7 @@ public class BusinessDataUpdateService {
97 iotDevice.setName(olddevice.getName()); 97 iotDevice.setName(olddevice.getName());
98 serverDto.setIotDevice(iotDevice); 98 serverDto.setIotDevice(iotDevice);
99 }else{ //终端 99 }else{ //终端
100 - IotTerminal iotTerminal = translateTerminal(type,key,olddevice,jsData,isOperLog,serverDto); 100 + IotTerminal iotTerminal = translateTerminal(type,key,olddevice,jsData,serverDto);
101 iotTerminal.setData_update_time(DateUtils.getNowTimeMilly()); 101 iotTerminal.setData_update_time(DateUtils.getNowTimeMilly());
102 if(null== iotTerminal.getOnline() || 1 == iotTerminal.getOnline() || 4==iotTerminal.getOnline()) 102 if(null== iotTerminal.getOnline() || 1 == iotTerminal.getOnline() || 4==iotTerminal.getOnline())
103 { 103 {
@@ -117,7 +117,7 @@ public class BusinessDataUpdateService { @@ -117,7 +117,7 @@ public class BusinessDataUpdateService {
117 * @param serverDto 117 * @param serverDto
118 * @return 118 * @return
119 */ 119 */
120 - private IotDevice translateDevice(Type type, IotDevice olddevice , JSONObject jsData,boolean isOperLog, ServerDto serverDto) 120 + private IotDevice translateDevice(Type type, IotDevice olddevice , JSONObject jsData, ServerDto serverDto)
121 { 121 {
122 JSONObject summaryObjec = null; 122 JSONObject summaryObjec = null;
123 if(jsData.containsKey("summary") && null != jsData.get("summary") && jsData.get("summary") instanceof JSONObject) 123 if(jsData.containsKey("summary") && null != jsData.get("summary") && jsData.get("summary") instanceof JSONObject)
@@ -134,19 +134,19 @@ public class BusinessDataUpdateService { @@ -134,19 +134,19 @@ public class BusinessDataUpdateService {
134 device.setSummary(summaryObjec.toString()); 134 device.setSummary(summaryObjec.toString());
135 } 135 }
136 136
137 - SaveDataDto saveDataDto = dataModeAnalysisService.analysisThingsModelValue( olddevice.getClient_id(),olddevice.getMqtt_username(),jsData,"主机本地",isOperLog,serverDto); 137 + SaveDataDto saveDataDto = dataModeAnalysisService.analysisThingsModelValue( olddevice.getClient_id(),olddevice.getMqtt_username(),jsData,serverDto);
138 //更新数据 138 //更新数据
139 if(null != olddevice && ("ADD".equals(type.name())|| "READ".equals(type.name()))) 139 if(null != olddevice && ("ADD".equals(type.name())|| "READ".equals(type.name())))
140 { 140 {
141 String str = olddevice.getThings_model_value(); 141 String str = olddevice.getThings_model_value();
142 - String newStr = deviceService.getNewAdddate(str,saveDataDto.getData()).toJSONString(); 142 + String newStr = deviceService.getNewAdddate(device.getClient_id(),str,saveDataDto.getData(),serverDto.getLogDeviceOperationList()).toJSONString();
143 device.setThings_model_value(newStr); 143 device.setThings_model_value(newStr);
144 }else{ 144 }else{
145 device.setThings_model_value(saveDataDto.getData().toJSONString()); 145 device.setThings_model_value(saveDataDto.getData().toJSONString());
146 } 146 }
147 //配置只做增量 147 //配置只做增量
148 String str = (null!=olddevice?olddevice.getThings_model_config():null); 148 String str = (null!=olddevice?olddevice.getThings_model_config():null);
149 - String newStr = deviceService.getNewAdddate(str,saveDataDto.getConfig()).toJSONString(); 149 + String newStr = deviceService.getNewAdddate(device.getClient_id(),str,saveDataDto.getConfig(),serverDto.getLogDeviceOperationList()).toJSONString();
150 device.setThings_model_config(newStr); 150 device.setThings_model_config(newStr);
151 151
152 return device; 152 return device;
@@ -161,10 +161,10 @@ public class BusinessDataUpdateService { @@ -161,10 +161,10 @@ public class BusinessDataUpdateService {
161 * @param serverDto 161 * @param serverDto
162 * @return 162 * @return
163 */ 163 */
164 - private IotTerminal translateTerminal(Type type,String key, IotDevice olddevice , JSONObject jsData,boolean isOperLog,ServerDto serverDto) 164 + private IotTerminal translateTerminal(Type type,String key, IotDevice olddevice , JSONObject jsData,ServerDto serverDto)
165 { 165 {
166 String id = olddevice.getClient_id()+"_"+key; 166 String id = olddevice.getClient_id()+"_"+key;
167 - SaveDataDto saveDataDto = dataModeAnalysisService.analysisThingsModelValue( id,olddevice.getMqtt_username(),jsData,"终端本地",isOperLog,serverDto); 167 + SaveDataDto saveDataDto = dataModeAnalysisService.analysisThingsModelValue( id,olddevice.getMqtt_username(),jsData,serverDto);
168 IotTerminal terminal = new IotTerminal(); 168 IotTerminal terminal = new IotTerminal();
169 terminal.setId(id); 169 terminal.setId(id);
170 terminal.setDevice_id(olddevice.getClient_id()); 170 terminal.setDevice_id(olddevice.getClient_id());
@@ -172,10 +172,12 @@ public class BusinessDataUpdateService { @@ -172,10 +172,12 @@ public class BusinessDataUpdateService {
172 terminal.setMqtt_username(olddevice.getMqtt_username()); 172 terminal.setMqtt_username(olddevice.getMqtt_username());
173 //更新数据 173 //更新数据
174 IotTerminal oldterminal = cacheService.getIotTerminal(id); 174 IotTerminal oldterminal = cacheService.getIotTerminal(id);
  175 +
  176 + //记录操作日志
175 if(null != oldterminal && ("ADD".equals(type.name())|| "READ".equals(type.name()))) 177 if(null != oldterminal && ("ADD".equals(type.name())|| "READ".equals(type.name())))
176 { 178 {
177 String str = oldterminal.getThings_model_value(); 179 String str = oldterminal.getThings_model_value();
178 - terminal.setThings_model_value(deviceService.getNewAdddate(str,saveDataDto.getData()).toJSONString()); 180 + terminal.setThings_model_value(deviceService.getNewAdddate(id,str,saveDataDto.getData(),serverDto.getLogDeviceOperationList()).toJSONString());
179 }else{ 181 }else{
180 terminal.setThings_model_value(saveDataDto.getData().toJSONString()); 182 terminal.setThings_model_value(saveDataDto.getData().toJSONString());
181 } 183 }
@@ -184,7 +186,7 @@ public class BusinessDataUpdateService { @@ -184,7 +186,7 @@ public class BusinessDataUpdateService {
184 System.out.println(saveDataDto); 186 System.out.println(saveDataDto);
185 } 187 }
186 String str = (null!=oldterminal?oldterminal.getThings_model_config():null); 188 String str = (null!=oldterminal?oldterminal.getThings_model_config():null);
187 - terminal.setThings_model_config(deviceService.getNewAdddate(str,saveDataDto.getConfig()).toJSONString()); 189 + terminal.setThings_model_config(deviceService.getNewAdddate(id,str,saveDataDto.getConfig(),serverDto.getLogDeviceOperationList()).toJSONString());
188 terminal.setName(oldterminal.getName()); 190 terminal.setName(oldterminal.getName());
189 return terminal; 191 return terminal;
190 } 192 }
@@ -33,9 +33,6 @@ public class DataModeAnalysisService { @@ -33,9 +33,6 @@ public class DataModeAnalysisService {
33 private BaseDao baseDao = new BaseDao(); 33 private BaseDao baseDao = new BaseDao();
34 34
35 @Autowired 35 @Autowired
36 - private DeviceLogService dviceLogService;  
37 -  
38 - @Autowired  
39 private TerminalDataThingsModeService terminalDataThingsModeService; 36 private TerminalDataThingsModeService terminalDataThingsModeService;
40 37
41 /** 38 /**
@@ -64,7 +61,7 @@ public class DataModeAnalysisService { @@ -64,7 +61,7 @@ public class DataModeAnalysisService {
64 /** 61 /**
65 * 解析物模型数据 62 * 解析物模型数据
66 */ 63 */
67 - public SaveDataDto analysisThingsModelValue(String id,String userName ,JSONObject jsData,String controlModel,boolean isOperLog, ServerDto serverDto) 64 + public SaveDataDto analysisThingsModelValue(String id,String userName ,JSONObject jsData, ServerDto serverDto)
68 { 65 {
69 if(null != jsData && jsData.size() != 0 ) 66 if(null != jsData && jsData.size() != 0 )
70 { 67 {
@@ -113,12 +110,6 @@ public class DataModeAnalysisService { @@ -113,12 +110,6 @@ public class DataModeAnalysisService {
113 serverDto.getDeviceSensorDataList().add(sensorData); 110 serverDto.getDeviceSensorDataList().add(sensorData);
114 } 111 }
115 112
116 - //记录操作日志  
117 - if(isOperLog && null != serverDto.getLogDeviceOperationList())  
118 - {  
119 - serverDto.getLogDeviceOperationList().add(dviceLogService.newLogDeviceOperation(id,thingsModelBase.getSaveView(),null,controlModel+thingsModelItemBase.getName()+"为"+thingsModelBase.getView(),jsData.toString()));  
120 - }  
121 -  
122 switch (thingsModel.getIs_config()) 113 switch (thingsModel.getIs_config())
123 { 114 {
124 case 0: 115 case 0:
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONArray; 4 import com.alibaba.fastjson.JSONArray;
5 import com.alibaba.fastjson.JSONObject; 5 import com.alibaba.fastjson.JSONObject;
6 import com.ruoyi.system.domain.IotDevice; 6 import com.ruoyi.system.domain.IotDevice;
  7 +import com.ruoyi.system.domain.IotTerminal;
7 import com.ruoyi.system.domain.IotThingsModel; 8 import com.ruoyi.system.domain.IotThingsModel;
8 import com.zhonglai.luhui.mqtt.comm.dao.BaseDao; 9 import com.zhonglai.luhui.mqtt.comm.dao.BaseDao;
9 import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelBase; 10 import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelBase;
@@ -89,4 +90,17 @@ public class DeviceController { @@ -89,4 +90,17 @@ public class DeviceController {
89 return new Message(MessageCode.DEFAULT_SUCCESS_CODE,map); 90 return new Message(MessageCode.DEFAULT_SUCCESS_CODE,map);
90 } 91 }
91 92
  93 +
  94 + @ApiOperation("更新主机")
  95 + @RequestMapping(value = "updateIotDevice",method = RequestMethod.POST)
  96 + public Message updateIotDevice(@RequestBody IotDevice iotDevice) {
  97 + return deviceService.updateIotDevice(iotDevice);
  98 + }
  99 +
  100 + @ApiOperation("更新终端")
  101 + @RequestMapping(value = "updateIotTerminal",method = RequestMethod.POST)
  102 + public Message updateIotTerminal(@RequestBody IotTerminal iotTerminal) {
  103 + return deviceService.updateIotTerminal(iotTerminal);
  104 + }
  105 +
92 } 106 }
@@ -8,4 +8,11 @@ public enum ApiName { @@ -8,4 +8,11 @@ public enum ApiName {
8 delIotTerminal, 8 delIotTerminal,
9 control, 9 control,
10 getFirmwareVersion, 10 getFirmwareVersion,
  11 + updateIotDevice,
  12 + updateIotTerminal,
  13 + delDeviceHost,
  14 + delDeviceInfoFromDeviceId,
  15 + delDeviceInfo,
  16 + transferPond,
  17 + updateDeviceInfo
11 } 18 }
1 package com.zhonglai.luhui.mqtt.dto; 1 package com.zhonglai.luhui.mqtt.dto;
2 2
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.ruoyi.system.domain.IotDevice;
  5 +import com.ruoyi.system.domain.IotTerminal;
3 import com.zhonglai.luhui.mqtt.service.db.DeviceService; 6 import com.zhonglai.luhui.mqtt.service.db.DeviceService;
4 import org.eclipse.paho.client.mqttv3.MqttException; 7 import org.eclipse.paho.client.mqttv3.MqttException;
5 8
@@ -26,7 +29,27 @@ public class DeviceCommandApi { @@ -26,7 +29,27 @@ public class DeviceCommandApi {
26 case delIotTerminal: 29 case delIotTerminal:
27 return deviceService.delIotTerminal(deviceCommandApiParameter.getClient_id(),deviceCommandApiParameter.getNumber()); 30 return deviceService.delIotTerminal(deviceCommandApiParameter.getClient_id(),deviceCommandApiParameter.getNumber());
28 case getFirmwareVersion: 31 case getFirmwareVersion:
  32 + deviceCommandApiParameter.setClient_id(deviceCommandApiParameter.getData());
29 return deviceService.getFirmwareVersion(deviceCommandApiParameter.getData()); 33 return deviceService.getFirmwareVersion(deviceCommandApiParameter.getData());
  34 + case updateIotDevice:
  35 + IotDevice iotDevice = JSONObject.parseObject(JSONObject.toJSONString(deviceCommandApiParameter.getMap()), IotDevice.class);
  36 + deviceCommandApiParameter.setClient_id(iotDevice.getClient_id());
  37 + return deviceService.updateIotDevice(iotDevice);
  38 + case updateIotTerminal:
  39 + IotTerminal iotTerminal = JSONObject.parseObject(JSONObject.toJSONString(deviceCommandApiParameter.getMap()), IotTerminal.class);
  40 + deviceCommandApiParameter.setClient_id(iotTerminal.getId());
  41 + return deviceService.updateIotTerminal(iotTerminal);
  42 + case delDeviceHost:
  43 + return deviceService.delDeviceHost(deviceCommandApiParameter.getClient_id());
  44 + case delDeviceInfo:
  45 + deviceCommandApiParameter.setClient_id(deviceCommandApiParameter.getData());
  46 + return deviceService.delDeviceInfo(deviceCommandApiParameter.getData());
  47 + case delDeviceInfoFromDeviceId:
  48 + return deviceService.delDeviceInfoFromDeviceId(deviceCommandApiParameter.getClient_id());
  49 + case transferPond:
  50 + return deviceService.transferPond(deviceCommandApiParameter.getClient_id(),deviceCommandApiParameter.getMap());
  51 + case updateDeviceInfo:
  52 + return deviceService.updateDeviceInfo(deviceCommandApiParameter.getClient_id(),deviceCommandApiParameter.getMap());
30 default: 53 default:
31 return new Message(MessageCode.DEFAULT_FAIL_CODE,"接口不存在"); 54 return new Message(MessageCode.DEFAULT_FAIL_CODE,"接口不存在");
32 } 55 }
@@ -140,11 +140,25 @@ public class CacheServiceImpl implements CacheService { @@ -140,11 +140,25 @@ public class CacheServiceImpl implements CacheService {
140 return null; 140 return null;
141 } 141 }
142 142
  143 + public boolean hasIotDeviceToRedis(String iotDeviceId)
  144 + {
  145 + return redisService.hasKey(getRedicDeviceKey(iotDeviceId));
  146 + }
  147 +
  148 + /**
  149 + * 设置缓存终端
  150 + */
  151 + public boolean hasIotTerminalToRedis(String iotTerminalId)
  152 + {
  153 + return redisService.hasKey(getRedicTerminalKey(iotTerminalId));
  154 + }
  155 +
  156 +
143 /** 157 /**
144 * 设置缓存主机 158 * 设置缓存主机
145 * @param iotDevice 159 * @param iotDevice
146 */ 160 */
147 - private void setIotDeviceToRedis(IotDevice iotDevice) 161 + public void setIotDeviceToRedis(IotDevice iotDevice)
148 { 162 {
149 redisService.hmset(getRedicDeviceKey(iotDevice.getClient_id()),iotDevice); 163 redisService.hmset(getRedicDeviceKey(iotDevice.getClient_id()),iotDevice);
150 } 164 }
@@ -153,7 +167,7 @@ public class CacheServiceImpl implements CacheService { @@ -153,7 +167,7 @@ public class CacheServiceImpl implements CacheService {
153 * 设置缓存终端 167 * 设置缓存终端
154 * @param iotTerminal 168 * @param iotTerminal
155 */ 169 */
156 - private void setIotTerminalToRedis(IotTerminal iotTerminal) 170 + public void setIotTerminalToRedis(IotTerminal iotTerminal)
157 { 171 {
158 redisService.hmset(getRedicTerminalKey(iotTerminal.getId()),iotTerminal); 172 redisService.hmset(getRedicTerminalKey(iotTerminal.getId()),iotTerminal);
159 } 173 }
@@ -8,10 +8,14 @@ import com.ruoyi.system.domain.IotTerminal; @@ -8,10 +8,14 @@ import com.ruoyi.system.domain.IotTerminal;
8 import com.ruoyi.system.domain.IotThingsModel; 8 import com.ruoyi.system.domain.IotThingsModel;
9 import com.zhonglai.luhui.mqtt.comm.config.RedisConfig; 9 import com.zhonglai.luhui.mqtt.comm.config.RedisConfig;
10 import com.zhonglai.luhui.mqtt.comm.dao.BaseDao; 10 import com.zhonglai.luhui.mqtt.comm.dao.BaseDao;
  11 +import com.zhonglai.luhui.mqtt.comm.dto.DeviceInfoDto;
  12 +import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation;
11 import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelBase; 13 import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelBase;
12 import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelDataTypeEnum; 14 import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelDataTypeEnum;
  15 +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase;
13 import com.zhonglai.luhui.mqtt.comm.factory.Topic; 16 import com.zhonglai.luhui.mqtt.comm.factory.Topic;
14 import com.zhonglai.luhui.mqtt.comm.service.ClienNoticeService; 17 import com.zhonglai.luhui.mqtt.comm.service.ClienNoticeService;
  18 +import com.zhonglai.luhui.mqtt.comm.service.DeviceLogService;
15 import com.zhonglai.luhui.mqtt.comm.service.redis.RedisService; 19 import com.zhonglai.luhui.mqtt.comm.service.redis.RedisService;
16 import com.zhonglai.luhui.mqtt.comm.util.DateUtils; 20 import com.zhonglai.luhui.mqtt.comm.util.DateUtils;
17 import com.zhonglai.luhui.mqtt.dto.Message; 21 import com.zhonglai.luhui.mqtt.dto.Message;
@@ -26,10 +30,7 @@ import org.slf4j.LoggerFactory; @@ -26,10 +30,7 @@ import org.slf4j.LoggerFactory;
26 import org.springframework.beans.factory.annotation.Autowired; 30 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.stereotype.Service; 31 import org.springframework.stereotype.Service;
28 32
29 -import java.util.Arrays;  
30 -import java.util.List;  
31 -import java.util.Map;  
32 -import java.util.Set; 33 +import java.util.*;
33 34
34 @Service 35 @Service
35 public class DeviceService { 36 public class DeviceService {
@@ -44,6 +45,12 @@ public class DeviceService { @@ -44,6 +45,12 @@ public class DeviceService {
44 @Autowired 45 @Autowired
45 private CacheServiceImpl cacheServiceImpl; 46 private CacheServiceImpl cacheServiceImpl;
46 47
  48 + @Autowired
  49 + private RedisService redisService ;
  50 +
  51 + @Autowired
  52 + private DeviceLogService dviceLogService;
  53 +
47 private BaseDao baseDao = new BaseDao(); 54 private BaseDao baseDao = new BaseDao();
48 55
49 /** 56 /**
@@ -83,15 +90,24 @@ public class DeviceService { @@ -83,15 +90,24 @@ public class DeviceService {
83 * @param saveJson 90 * @param saveJson
84 * @return 91 * @return
85 */ 92 */
86 - public JSONObject getNewAdddate(String oldstr, JSONObject saveJson) 93 + public JSONObject getNewAdddate(String id,String oldstr, JSONObject saveJson, List<LogDeviceOperation> logDeviceOperationList)
87 { 94 {
88 JSONObject oldjs = new JSONObject(); 95 JSONObject oldjs = new JSONObject();
89 if(StringUtils.isNoneBlank(oldstr)) 96 if(StringUtils.isNoneBlank(oldstr))
90 { 97 {
91 oldjs = JSONObject.parseObject(oldstr); 98 oldjs = JSONObject.parseObject(oldstr);
92 } 99 }
  100 +
93 for (String sk:saveJson.keySet()) 101 for (String sk:saveJson.keySet())
94 { 102 {
  103 + ThingsModelItemBase thingsModelItemBase = (ThingsModelItemBase) saveJson.get(sk);
  104 + if(null != thingsModelItemBase.getIs_save_log() && 1==thingsModelItemBase.getIs_save_log() && null != logDeviceOperationList)
  105 + {
  106 + if(null!=thingsModelItemBase.getSaveView() && null != oldjs && oldjs.containsKey(sk) && !thingsModelItemBase.getSaveView().equals(oldjs.getJSONObject(sk).getString("saveView")))
  107 + {
  108 + logDeviceOperationList.add(dviceLogService.newLogDeviceOperation(id,thingsModelItemBase.getSaveView(),oldjs.getJSONObject(sk).getString("saveView"),"本地操作"+thingsModelItemBase.getName()+"为"+thingsModelItemBase.getView(),null));
  109 + }
  110 + }
95 oldjs.put(sk,saveJson.get(sk)); 111 oldjs.put(sk,saveJson.get(sk));
96 } 112 }
97 return oldjs; 113 return oldjs;
@@ -143,6 +159,12 @@ public class DeviceService { @@ -143,6 +159,12 @@ public class DeviceService {
143 mqttMessage.setPayload(bs); 159 mqttMessage.setPayload(bs);
144 160
145 Message message = clienNoticeService.sendMessage(topic,mqttMessage); 161 Message message = clienNoticeService.sendMessage(topic,mqttMessage);
  162 + if(1==message.getCode())
  163 + {
  164 + List<LogDeviceOperation> list = new ArrayList<>();
  165 + list.add(dviceLogService.newLogDeviceOperation(clienid,null!=message.getData()?JSON.toJSONString(message.getData()):null,null,"远程操作控制设备","controlHex?"+data));
  166 + dviceLogService.saveOperationLog(list);
  167 + }
146 return message; 168 return message;
147 } 169 }
148 170
@@ -171,10 +193,54 @@ public class DeviceService { @@ -171,10 +193,54 @@ public class DeviceService {
171 MqttMessage mqttMessage = new MqttMessage(); 193 MqttMessage mqttMessage = new MqttMessage();
172 mqttMessage.setPayload(JSON.toJSONString(map).trim().getBytes()); 194 mqttMessage.setPayload(JSON.toJSONString(map).trim().getBytes());
173 Message message = clienNoticeService.sendMessage(topic,mqttMessage); 195 Message message = clienNoticeService.sendMessage(topic,mqttMessage);
  196 +
  197 + if(1==message.getCode())
  198 + {
  199 + List<LogDeviceOperation> list = new ArrayList<>();
  200 + list.add(dviceLogService.newLogDeviceOperation(clienid,JSON.toJSONString(message.getData()),null,"远程操作读取配置参数","read?"+JSON.toJSONString(map).trim()));
  201 + dviceLogService.saveOperationLog(list);
  202 + }
  203 +
174 return message; 204 return message;
175 } 205 }
176 206
177 /** 207 /**
  208 + * 更新主机
  209 + * @return
  210 + * @throws MqttException
  211 + * @throws InterruptedException
  212 + */
  213 + public Message updateIotDevice(IotDevice iotDevice) {
  214 + if(cacheServiceImpl.hasIotDeviceToRedis(iotDevice.getClient_id()))
  215 + {
  216 + cacheServiceImpl.setIotDeviceToRedis(iotDevice);
  217 + }
  218 + baseDao.update(iotDevice,"client_id");
  219 + List<LogDeviceOperation> list = new ArrayList<>();
  220 + list.add(dviceLogService.newLogDeviceOperation(iotDevice.getClient_id(),null,null,"远程操作更新主机","updateIotDevice?"+JSON.toJSONString(iotDevice)));
  221 + dviceLogService.saveOperationLog(list);
  222 + return new Message(MessageCode.DEFAULT_SUCCESS_CODE);
  223 + }
  224 +
  225 + /**
  226 + * 更新终端
  227 + * @return
  228 + * @throws MqttException
  229 + * @throws InterruptedException
  230 + */
  231 + public Message updateIotTerminal(IotTerminal iotTerminal) {
  232 + if(cacheServiceImpl.hasIotTerminalToRedis(iotTerminal.getId()))
  233 + {
  234 + cacheServiceImpl.setIotTerminalToRedis(iotTerminal);
  235 + }
  236 + baseDao.update(iotTerminal,"id");
  237 + List<LogDeviceOperation> list = new ArrayList<>();
  238 + list.add(dviceLogService.newLogDeviceOperation(iotTerminal.getId(),null,null,"远程操作更新终端","updateIotTerminal?"+JSON.toJSONString(iotTerminal)));
  239 + dviceLogService.saveOperationLog(list);
  240 + return new Message(MessageCode.DEFAULT_SUCCESS_CODE);
  241 + }
  242 +
  243 + /**
178 * 强行断开链接 244 * 强行断开链接
179 * @param clienid 245 * @param clienid
180 * @return 246 * @return
@@ -188,6 +254,9 @@ public class DeviceService { @@ -188,6 +254,9 @@ public class DeviceService {
188 mqttMessage.setPayload(bs); 254 mqttMessage.setPayload(bs);
189 255
190 clienNoticeService.sendMessage("CLOSE",mqttMessage); 256 clienNoticeService.sendMessage("CLOSE",mqttMessage);
  257 + List<LogDeviceOperation> list = new ArrayList<>();
  258 + list.add(dviceLogService.newLogDeviceOperation(clienid,null,null,"远程操作强行断开链接","closeSession?"));
  259 + dviceLogService.saveOperationLog(list);
191 return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"端口请求已发送"); 260 return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"端口请求已发送");
192 } 261 }
193 262
@@ -201,6 +270,11 @@ public class DeviceService { @@ -201,6 +270,11 @@ public class DeviceService {
201 public Message delIotDevice(String client_id) throws MqttException, InterruptedException { 270 public Message delIotDevice(String client_id) throws MqttException, InterruptedException {
202 closeSession(client_id); //强制下线 271 closeSession(client_id); //强制下线
203 cacheServiceImpl.deletRedisDevice(client_id); 272 cacheServiceImpl.deletRedisDevice(client_id);
  273 + baseDao.updateBySql("delete from iot_device where client_id='"+client_id+"'");
  274 + baseDao.updateBySql("delete from iot_terminal where device_id='"+client_id+"'");
  275 + List<LogDeviceOperation> list = new ArrayList<>();
  276 + list.add(dviceLogService.newLogDeviceOperation(client_id,null,null,"远程操作删除主机","delIotDevice?"));
  277 + dviceLogService.saveOperationLog(list);
204 return new Message(MessageCode.DEFAULT_SUCCESS_CODE); 278 return new Message(MessageCode.DEFAULT_SUCCESS_CODE);
205 } 279 }
206 280
@@ -215,6 +289,10 @@ public class DeviceService { @@ -215,6 +289,10 @@ public class DeviceService {
215 public Message delIotTerminal(String client_id,String number) throws MqttException, InterruptedException { 289 public Message delIotTerminal(String client_id,String number) throws MqttException, InterruptedException {
216 closeSession(client_id); //强制下线 290 closeSession(client_id); //强制下线
217 cacheServiceImpl.deletRedisTerminal(client_id+"_"+number); 291 cacheServiceImpl.deletRedisTerminal(client_id+"_"+number);
  292 + baseDao.updateBySql("delete from iot_terminal where id='"+client_id+"_"+number+"'");
  293 + List<LogDeviceOperation> list = new ArrayList<>();
  294 + list.add(dviceLogService.newLogDeviceOperation(client_id,null,null,"远程操作删除终端","delIotTerminal?"));
  295 + dviceLogService.saveOperationLog(list);
218 return new Message(MessageCode.DEFAULT_SUCCESS_CODE); 296 return new Message(MessageCode.DEFAULT_SUCCESS_CODE);
219 } 297 }
220 298
@@ -274,6 +352,12 @@ public class DeviceService { @@ -274,6 +352,12 @@ public class DeviceService {
274 MqttMessage mqttMessage = new MqttMessage(); 352 MqttMessage mqttMessage = new MqttMessage();
275 mqttMessage.setPayload(JSON.toJSONString(map).trim().getBytes()); 353 mqttMessage.setPayload(JSON.toJSONString(map).trim().getBytes());
276 Message message = clienNoticeService.sendMessage(topic,mqttMessage); 354 Message message = clienNoticeService.sendMessage(topic,mqttMessage);
  355 + if(1==message.getCode())
  356 + {
  357 + List<LogDeviceOperation> list = new ArrayList<>();
  358 + list.add(dviceLogService.newLogDeviceOperation(clienid,JSON.toJSONString(message.getData()),null,"远程操作控制","control?"+JSON.toJSONString(map).trim()));
  359 + dviceLogService.saveOperationLog(list);
  360 + }
277 return message; 361 return message;
278 } 362 }
279 363
@@ -305,6 +389,85 @@ public class DeviceService { @@ -305,6 +389,85 @@ public class DeviceService {
305 topic.setMessageid(DateUtils.getNowTimeMilly()+""); 389 topic.setMessageid(DateUtils.getNowTimeMilly()+"");
306 return topic; 390 return topic;
307 } 391 }
  392 +
  393 + private static String x6deviceKeyPath = "ly:x6:devices:";
  394 + private static String x6hostKeyPath = "ly:x6:hosts:";
  395 + public Message delDeviceHost(String deviceId)
  396 + {
  397 + String key =x6hostKeyPath+deviceId;
  398 + if(redisService.hasKey(key))
  399 + {
  400 + redisService.del(key);
  401 + }
  402 + List<LogDeviceOperation> oplist = new ArrayList<>();
  403 + oplist.add(dviceLogService.newLogDeviceOperation(deviceId,null,null,"远程操作删除x6主机","delDeviceHost?"));
  404 + dviceLogService.saveOperationLog(oplist);
  405 +
  406 + return new Message(MessageCode.DEFAULT_SUCCESS_CODE);
  407 + }
  408 +
  409 + public Message delDeviceInfoFromDeviceId(String deviceId)
  410 + {
  411 + String key =x6deviceKeyPath+deviceId;
  412 + redisService.del(key);
  413 + Set<String> keys = redisService.keys(x6deviceKeyPath+deviceId+"*");
  414 + redisService.del(keys.toArray(new String[keys.size()]));
  415 +
  416 + List<LogDeviceOperation> oplist = new ArrayList<>();
  417 + oplist.add(dviceLogService.newLogDeviceOperation(deviceId,null,null,"远程操作删除x6终端","delDeviceInfoFromDeviceId?"));
  418 + dviceLogService.saveOperationLog(oplist);
  419 + return new Message(MessageCode.DEFAULT_SUCCESS_CODE);
  420 + }
  421 +
  422 + public Message delDeviceInfo(String deviceInfoId)
  423 + {
  424 + String key =x6deviceKeyPath+deviceInfoId;
  425 + if(redisService.hasKey(key))
  426 + {
  427 + redisService.del(key);
  428 + }
  429 +
  430 + List<LogDeviceOperation> oplist = new ArrayList<>();
  431 + oplist.add(dviceLogService.newLogDeviceOperation(deviceInfoId,null,null,"远程操作删除x6终端","delDeviceInfo?"));
  432 + dviceLogService.saveOperationLog(oplist);
  433 +
  434 + return new Message(MessageCode.DEFAULT_SUCCESS_CODE);
  435 + }
  436 +
  437 + /**
  438 + * 移塘
  439 + * @return
  440 + */
  441 + public Message transferPond(String deviceInfoId,Map<String,Object> map)
  442 + {
  443 + String key =x6deviceKeyPath+deviceInfoId;
  444 + if(redisService.hasKey(key))
  445 + {
  446 + redisService.hmset(key,map);
  447 + }
  448 + List<LogDeviceOperation> oplist = new ArrayList<>();
  449 + oplist.add(dviceLogService.newLogDeviceOperation(deviceInfoId,null,null,"远程操作移塘","updateDeviceInfo?"));
  450 + dviceLogService.saveOperationLog(oplist);
  451 + return updateDeviceInfo(deviceInfoId,map);
  452 + }
  453 +
  454 + /**
  455 + * 修改设备信息
  456 + * @return
  457 + */
  458 + public Message updateDeviceInfo(String deviceInfoId,Map<String,Object> map)
  459 + {
  460 + String key =x6deviceKeyPath+deviceInfoId;
  461 + if(redisService.hasKey(key))
  462 + {
  463 + redisService.hmset(key,map);
  464 + }
  465 +
  466 + List<LogDeviceOperation> oplist = new ArrayList<>();
  467 + oplist.add(dviceLogService.newLogDeviceOperation(deviceInfoId,null,null,"远程操作修改终端信息","updateDeviceInfo?"));
  468 + dviceLogService.saveOperationLog(oplist);
  469 + return new Message(MessageCode.DEFAULT_SUCCESS_CODE);
  470 + }
308 /** 471 /**
309 * 把16进制字符串转换成字节数组 472 * 把16进制字符串转换成字节数组
310 * 473 *
@@ -22,7 +22,7 @@ public class AddPostTopic implements BusinessAgreement<AddPostDto> { @@ -22,7 +22,7 @@ public class AddPostTopic implements BusinessAgreement<AddPostDto> {
22 private BusinessDataUpdateService businessDataUpdateService ; 22 private BusinessDataUpdateService businessDataUpdateService ;
23 @Override 23 @Override
24 public ServerDto analysis(Topic topic, AddPostDto data) { 24 public ServerDto analysis(Topic topic, AddPostDto data) {
25 - businessDataUpdateService.updataDta(BusinessDataUpdateService.Type.ADD,topic,true,data); 25 + businessDataUpdateService.updataDta(BusinessDataUpdateService.Type.ADD,topic,data);
26 return data; 26 return data;
27 } 27 }
28 28
@@ -23,7 +23,7 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { @@ -23,7 +23,7 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> {
23 private BusinessDataUpdateService businessDataUpdateService ; 23 private BusinessDataUpdateService businessDataUpdateService ;
24 @Override 24 @Override
25 public ServerDto analysis(Topic topic, AllPostDto data) throws Exception { 25 public ServerDto analysis(Topic topic, AllPostDto data) throws Exception {
26 - businessDataUpdateService.updataDta(BusinessDataUpdateService.Type.ALL,topic,false,data); 26 + businessDataUpdateService.updataDta(BusinessDataUpdateService.Type.ALL,topic,data);
27 return data; 27 return data;
28 } 28 }
29 29
1 package com.zhonglai.luhui.mqtt.service.topic; 1 package com.zhonglai.luhui.mqtt.service.topic;
2 2
  3 +import com.ruoyi.system.domain.IotDevice;
3 import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; 4 import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
4 import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto; 5 import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto;
5 import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement; 6 import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement;
6 import com.zhonglai.luhui.mqtt.comm.factory.Topic; 7 import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  8 +import com.zhonglai.luhui.mqtt.comm.service.redis.RedisService;
7 import com.zhonglai.luhui.mqtt.dto.topic.OnlineDto; 9 import com.zhonglai.luhui.mqtt.dto.topic.OnlineDto;
  10 +import com.zhonglai.luhui.mqtt.service.CacheServiceImpl;
8 import com.zhonglai.luhui.mqtt.service.db.DeviceService; 11 import com.zhonglai.luhui.mqtt.service.db.DeviceService;
9 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Service; 13 import org.springframework.stereotype.Service;
@@ -14,11 +17,16 @@ import org.springframework.stereotype.Service; @@ -14,11 +17,16 @@ import org.springframework.stereotype.Service;
14 public class OnlineTopic implements BusinessAgreement<OnlineDto> { 17 public class OnlineTopic implements BusinessAgreement<OnlineDto> {
15 @Autowired 18 @Autowired
16 private DeviceService deviceService ; 19 private DeviceService deviceService ;
  20 +
  21 + @Autowired
  22 + private CacheServiceImpl cacheServiceImpl;
  23 +
17 @Override 24 @Override
18 public ServerDto analysis(Topic topic, OnlineDto data) throws Exception { 25 public ServerDto analysis(Topic topic, OnlineDto data) throws Exception {
19 if(1==data.getState()) //在线 26 if(1==data.getState()) //在线
20 { 27 {
21 - 28 + IotDevice iotDevice = deviceService.getDeviceById(topic.getClientid());
  29 + cacheServiceImpl.setIotDeviceToRedis(iotDevice);
22 }else{ //离线 30 }else{ //离线
23 deviceService.deviceOffLine(topic.getClientid()); 31 deviceService.deviceOffLine(topic.getClientid());
24 } 32 }
@@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
17 <module>lh-domain</module> 17 <module>lh-domain</module>
18 <module>lh-api</module> 18 <module>lh-api</module>
19 <module>lh-central-control</module> 19 <module>lh-central-control</module>
  20 + <module>lh-backups</module>
20 </modules> 21 </modules>
21 22
22 <packaging>pom</packaging> 23 <packaging>pom</packaging>
@@ -48,6 +49,7 @@ @@ -48,6 +49,7 @@
48 <zxing.version>3.4.0</zxing.version> 49 <zxing.version>3.4.0</zxing.version>
49 <okhttp.version>3.3.1</okhttp.version> 50 <okhttp.version>3.3.1</okhttp.version>
50 <tkmapper.version>4.2.1</tkmapper.version> 51 <tkmapper.version>4.2.1</tkmapper.version>
  52 + <shiro.version>1.10.1</shiro.version>
51 </properties> 53 </properties>
52 54
53 <!-- 依赖声明 --> 55 <!-- 依赖声明 -->
@@ -336,6 +338,7 @@ @@ -336,6 +338,7 @@
336 <artifactId>rocketmq-spring-boot-starter</artifactId> 338 <artifactId>rocketmq-spring-boot-starter</artifactId>
337 <version>2.1.1</version> 339 <version>2.1.1</version>
338 </dependency> 340 </dependency>
  341 +
339 </dependencies> 342 </dependencies>
340 343
341 344
@@ -25,4 +25,19 @@ public enum MessageCode implements MessageCodeType{ @@ -25,4 +25,19 @@ public enum MessageCode implements MessageCodeType{
25 this.code = code; 25 this.code = code;
26 this.message = message; 26 this.message = message;
27 } 27 }
  28 +
  29 +
  30 + public static MessageCode getMessageCode(int code)
  31 + {
  32 + MessageCode[] messageCodes = MessageCode.values();
  33 + for(MessageCode messageCode:messageCodes)
  34 + {
  35 + if(messageCode.code==code)
  36 + {
  37 + return messageCode;
  38 + }
  39 + }
  40 + return DEFAULT_FAIL_CODE;
  41 + }
  42 +
28 } 43 }
1 package com.ruoyi.common.core.redis; 1 package com.ruoyi.common.core.redis;
2 2
  3 +import com.alibaba.fastjson.JSONObject;
3 import org.springframework.beans.factory.annotation.Autowired; 4 import org.springframework.beans.factory.annotation.Autowired;
4 import org.springframework.data.redis.core.BoundSetOperations; 5 import org.springframework.data.redis.core.BoundSetOperations;
5 import org.springframework.data.redis.core.HashOperations; 6 import org.springframework.data.redis.core.HashOperations;
@@ -240,4 +241,19 @@ public class RedisCache @@ -240,4 +241,19 @@ public class RedisCache
240 { 241 {
241 return redisTemplate.keys(pattern); 242 return redisTemplate.keys(pattern);
242 } 243 }
  244 +
  245 + /**
  246 + *
  247 + * @param key
  248 + * @return 判断key是否存在
  249 + */
  250 + public boolean hasKey(String key){
  251 + return redisTemplate.hasKey(key);
  252 + }
  253 +
  254 + public void hmset(String key,Object object){
  255 + String s = JSONObject.toJSONString(object);
  256 + Map<String, String> map = JSONObject.parseObject(s,HashMap.class);
  257 + setCacheMap(key, map);
  258 + }
243 } 259 }
@@ -72,6 +72,11 @@ @@ -72,6 +72,11 @@
72 <groupId>tk.mybatis</groupId> 72 <groupId>tk.mybatis</groupId>
73 <artifactId>mapper-spring-boot-starter</artifactId> 73 <artifactId>mapper-spring-boot-starter</artifactId>
74 </dependency> 74 </dependency>
  75 +
  76 + <dependency>
  77 + <groupId>org.apache.rocketmq</groupId>
  78 + <artifactId>rocketmq-spring-boot-starter</artifactId>
  79 + </dependency>
75 </dependencies> 80 </dependencies>
76 81
77 </project> 82 </project>
  1 +package com.ruoyi.system.dto;
  2 +
  3 +public enum ApiName {
  4 + controlHex,
  5 + read,
  6 + closeSession,
  7 + delIotDevice,
  8 + delIotTerminal,
  9 + control,
  10 + getFirmwareVersion,
  11 + updateIotDevice,
  12 + updateIotTerminal
  13 +}
  1 +package com.ruoyi.system.dto;
  2 +
  3 +/**
  4 + * 设备指令接口
  5 + */
  6 +public class DeviceCommandApi {
  7 + private ApiName apiName; //指令接口名称
  8 + private DeviceCommandApiParameter deviceCommandApiParameter; //参数
  9 +
  10 + public static DeviceCommandApi getDeviceCommandApi()
  11 + {
  12 + return new DeviceCommandApi();
  13 + }
  14 + public DeviceCommandApi bindApiName(ApiName apiName)
  15 + {
  16 + setApiName(apiName);
  17 + return this;
  18 + }
  19 +
  20 + public DeviceCommandApi bindDeviceCommandApiParameter(DeviceCommandApiParameter deviceCommandApiParameter)
  21 + {
  22 + setDeviceCommandApiParameter(deviceCommandApiParameter);
  23 + return this;
  24 + }
  25 +
  26 +
  27 +
  28 + public ApiName getApiName() {
  29 + return apiName;
  30 + }
  31 +
  32 + public void setApiName(ApiName apiName) {
  33 + this.apiName = apiName;
  34 + }
  35 +
  36 + public DeviceCommandApiParameter getDeviceCommandApiParameter() {
  37 + return deviceCommandApiParameter;
  38 + }
  39 +
  40 + public void setDeviceCommandApiParameter(DeviceCommandApiParameter deviceCommandApiParameter) {
  41 + this.deviceCommandApiParameter = deviceCommandApiParameter;
  42 + }
  43 +}
  1 +package com.ruoyi.system.dto;
  2 +
  3 +import java.util.Map;
  4 +
  5 +
  6 +public class DeviceCommandApiParameter {
  7 + private String client_id;
  8 + private Map<String,Object> map;
  9 + private String data;
  10 + private String number;
  11 + public static DeviceCommandApiParameter getDeviceCommandApiParameter()
  12 + {
  13 + return new DeviceCommandApiParameter();
  14 + }
  15 +
  16 + public DeviceCommandApiParameter bindClient_id(String client_id)
  17 + {
  18 + setClient_id(client_id);
  19 + return this;
  20 + }
  21 +
  22 + public DeviceCommandApiParameter bindMap(Map<String,Object> map)
  23 + {
  24 + setMap(map);
  25 + return this;
  26 + }
  27 +
  28 + public DeviceCommandApiParameter bindData(String data)
  29 + {
  30 + setData(data);
  31 + return this;
  32 + }
  33 +
  34 + public DeviceCommandApiParameter bindNumber(String number)
  35 + {
  36 + setNumber(number);
  37 + return this;
  38 + }
  39 +
  40 + public String getClient_id() {
  41 + return client_id;
  42 + }
  43 +
  44 + public void setClient_id(String client_id) {
  45 + this.client_id = client_id;
  46 + }
  47 +
  48 + public Map<String,Object> getMap() {
  49 + return map;
  50 + }
  51 +
  52 + public void setMap(Map<String,Object> map) {
  53 + this.map = map;
  54 + }
  55 +
  56 + public String getData() {
  57 + return data;
  58 + }
  59 +
  60 + public void setData(String data) {
  61 + this.data = data;
  62 + }
  63 +
  64 + public String getNumber() {
  65 + return number;
  66 + }
  67 +
  68 + public void setNumber(String number) {
  69 + this.number = number;
  70 + }
  71 +}
@@ -757,6 +757,19 @@ public class PublicSQL { @@ -757,6 +757,19 @@ public class PublicSQL {
757 return sql; 757 return sql;
758 } 758 }
759 759
  760 + public String selectCountBySql(String sql)
  761 + {
  762 + if(!sql.toUpperCase().startsWith("SELECT COUNT("))
  763 + {
  764 + try {
  765 + throw new Exception("不是count查询");
  766 + } catch (Exception e) {
  767 + e.printStackTrace();
  768 + }
  769 + }
  770 + return sql;
  771 + }
  772 +
760 public static String escapeSql(String str) { 773 public static String escapeSql(String str) {
761 return str == null ? null : StringUtils.replace(str, "'", "''"); 774 return str == null ? null : StringUtils.replace(str, "'", "''");
762 } 775 }
@@ -63,7 +63,7 @@ public class LoginService { @@ -63,7 +63,7 @@ public class LoginService {
63 // } 63 // }
64 // 用户验证 64 // 用户验证
65 Authentication authentication = userPasswordVerification(username,password,SysLogininforType.lhAdmin); 65 Authentication authentication = userPasswordVerification(username,password,SysLogininforType.lhAdmin);
66 - AsyncManager.me().execute(AsyncFactory.recordLogininfor(username,SysLogininforType.lhAdmin, Constants.LOGIN_SUCCESS, MessageUtils.message("sysuser.login.success"))); 66 + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username,SysLogininforType.lhAdmin, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
67 SysLoginUser loginUser = (SysLoginUser) authentication.getPrincipal(); 67 SysLoginUser loginUser = (SysLoginUser) authentication.getPrincipal();
68 loginUser.setSysLogininforType(SysLogininforType.lhAdmin); 68 loginUser.setSysLogininforType(SysLogininforType.lhAdmin);
69 recordLoginInfo(loginUser.getUserId()); 69 recordLoginInfo(loginUser.getUserId());
@@ -64,6 +64,8 @@ public interface PublicMapper { @@ -64,6 +64,8 @@ public interface PublicMapper {
64 @SelectProvider(type = PublicSQL.class, method = "getObject") 64 @SelectProvider(type = PublicSQL.class, method = "getObject")
65 <T> T getObject(@Param("class") Class<?> clas, @Param("idName") String idName, @Param("values") String values); 65 <T> T getObject(@Param("class") Class<?> clas, @Param("idName") String idName, @Param("values") String values);
66 66
  67 + @SelectProvider(type = PublicSQL.class, method = "selectCountBySql")
  68 + Long selectCountBySql(@Param("sql") String sql);
67 /** 69 /**
68 * 查询 通过条件查询 70 * 查询 通过条件查询
69 * @param clas 71 * @param clas
  1 +package com.ruoyi.system.rocketmq;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.ruoyi.common.core.domain.Message;
  6 +import com.ruoyi.common.core.domain.MessageCode;
  7 +import com.ruoyi.common.core.domain.MessageCodeType;
  8 +import com.ruoyi.system.dto.DeviceCommandApi;
  9 +import org.apache.rocketmq.client.exception.MQBrokerException;
  10 +import org.apache.rocketmq.client.exception.MQClientException;
  11 +import org.apache.rocketmq.client.exception.RequestTimeoutException;
  12 +import org.apache.rocketmq.remoting.exception.RemotingException;
  13 +import org.apache.rocketmq.spring.core.RocketMQTemplate;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.beans.factory.annotation.Value;
  16 +import org.springframework.stereotype.Service;
  17 +
  18 +
  19 +@Service
  20 +public class RocketMqService {
  21 + @Value("${rocketmq.producer.send-topic}")
  22 + private String sendTopic; //客户端操作时间
  23 + @Value("${rocketmq.producer.send-tags}")
  24 + private String sendTags; //客户端操作时间
  25 + @Autowired
  26 + private RocketMQTemplate rocketMQTemplate;
  27 +
  28 + public Message send(DeviceCommandApi deviceCommandApi)
  29 + {
  30 + return send(sendTopic, JSONObject.toJSONBytes(deviceCommandApi));
  31 + }
  32 +
  33 + public Message send(String topic,String payload)
  34 + {
  35 + return send(topic,payload.getBytes());
  36 + }
  37 +
  38 + public Message send(String topic,byte[] payload)
  39 + {
  40 + org.apache.rocketmq.common.message.Message msg = new org.apache.rocketmq.common.message.Message(topic,sendTags,payload);
  41 + try {
  42 + org.apache.rocketmq.common.message.Message ms = rocketMQTemplate.getProducer().request(msg,30000l);
  43 + JSONObject jsonObject = (JSONObject) JSON.parse(new String(ms.getBody()));
  44 + return new Message(MessageCode.getMessageCode(jsonObject.getInteger("code")),jsonObject.getString("message"),jsonObject.get("data"));
  45 + } catch (RequestTimeoutException e) {
  46 + e.printStackTrace();
  47 + } catch (MQClientException e) {
  48 + e.printStackTrace();
  49 + } catch (RemotingException e) {
  50 + e.printStackTrace();
  51 + } catch (MQBrokerException e) {
  52 + e.printStackTrace();
  53 + } catch (InterruptedException e) {
  54 + e.printStackTrace();
  55 + }
  56 +
  57 + return new Message(MessageCode.DEFAULT_FAIL_CODE);
  58 + }
  59 +}
  1 +package com.ruoyi.system.service;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.ruoyi.common.core.domain.Message;
  5 +import com.ruoyi.common.core.domain.MessageCode;
  6 +import com.ruoyi.common.utils.StringUtils;
  7 +import com.ruoyi.system.domain.IotDevice;
  8 +import com.ruoyi.system.dto.ApiName;
  9 +import com.ruoyi.system.dto.DeviceCommandApi;
  10 +import com.ruoyi.system.dto.DeviceCommandApiParameter;
  11 +import com.ruoyi.system.rocketmq.RocketMqService;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.stereotype.Service;
  14 +
  15 +import java.io.IOException;
  16 +import java.util.HashMap;
  17 +import java.util.Map;
  18 +
  19 +@Service
  20 +public class DeviceControlService {
  21 + @Autowired
  22 + protected RocketMqService rocketMqService;
  23 +
  24 + @Autowired
  25 + private IIotDeviceService iIotDeviceService;
  26 +
  27 + private DeviceCommandApi getDeviceCommandApi(String imei, Map<String,Object> map) {
  28 + DeviceCommandApi deviceCommandApi = new DeviceCommandApi();
  29 + deviceCommandApi.setApiName(ApiName.control);
  30 + DeviceCommandApiParameter deviceCommandApiParameter = new DeviceCommandApiParameter();
  31 + deviceCommandApiParameter.setClient_id(imei);
  32 + deviceCommandApiParameter.setMap(map);
  33 + deviceCommandApi.setDeviceCommandApiParameter(deviceCommandApiParameter);
  34 + return deviceCommandApi;
  35 + }
  36 +
  37 + /**
  38 + * 固件版本更新
  39 + * @param imei
  40 + * @param firmwareVersion
  41 + * @param code
  42 + * @return
  43 + * @throws IOException
  44 + */
  45 + public Message firmwareUp( String imei, String firmwareVersion, Integer code) throws IOException {
  46 + Map<String,Object> map = new HashMap<>();
  47 + Map<String,Object> valueMap = new HashMap<>();
  48 + valueMap.put("firmwareVersion",firmwareVersion);
  49 + valueMap.put("code",code);
  50 + map.put("0",valueMap);
  51 + DeviceCommandApi deviceCommandApi = getDeviceCommandApi(imei,map);
  52 + return rocketMqService.send(deviceCommandApi);
  53 + }
  54 +
  55 + /**
  56 + * 设备重启
  57 + * @param imei
  58 + * @param restart
  59 + * @return
  60 + * @throws IOException
  61 + */
  62 + public Message restart( String imei , Integer restart) {
  63 + Map<String,Object> map = new HashMap<>();
  64 + Map<String,Object> valueMap = new HashMap<>();
  65 + valueMap.put("restart",restart);
  66 + map.put("0",valueMap);
  67 + DeviceCommandApi deviceCommandApi = getDeviceCommandApi(imei,map);
  68 + return rocketMqService.send(deviceCommandApi);
  69 + }
  70 +
  71 + /**
  72 + * 获取指定设备版本信息
  73 + * @param imei
  74 + * @return
  75 + */
  76 + public Message getFirmwareVersion( String imei) {
  77 + IotDevice iotDevice = iIotDeviceService.selectIotDeviceByClient_id(imei);
  78 + if(null == iotDevice || StringUtils.isBlank(iotDevice.getMqtt_username()))
  79 + {
  80 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"设备或者设备类型不存在");
  81 + }
  82 + DeviceCommandApi deviceCommandApi = new DeviceCommandApi();
  83 + deviceCommandApi.setApiName(ApiName.getFirmwareVersion);
  84 + DeviceCommandApiParameter deviceCommandApiParameter = new DeviceCommandApiParameter();
  85 + deviceCommandApiParameter.setClient_id(imei);
  86 + deviceCommandApiParameter.setData(iotDevice.getMqtt_username());
  87 + deviceCommandApi.setDeviceCommandApiParameter(deviceCommandApiParameter);
  88 + return rocketMqService.send(deviceCommandApi);
  89 + }
  90 +
  91 + /**
  92 + * 强行断开链接
  93 + * @param imei
  94 + * @return
  95 + */
  96 + public Message closeSession( String imei) {
  97 + DeviceCommandApi deviceCommandApi = new DeviceCommandApi();
  98 + deviceCommandApi.setApiName(ApiName.closeSession);
  99 + DeviceCommandApiParameter deviceCommandApiParameter = new DeviceCommandApiParameter();
  100 + deviceCommandApiParameter.setClient_id(imei);
  101 + deviceCommandApi.setDeviceCommandApiParameter(deviceCommandApiParameter);
  102 + return rocketMqService.send(deviceCommandApi);
  103 + }
  104 +
  105 + /**
  106 + * 删除主机
  107 + * @param imei
  108 + * @return
  109 + */
  110 + public Message delIotDevice( String imei) {
  111 + DeviceCommandApi deviceCommandApi = new DeviceCommandApi();
  112 + deviceCommandApi.setApiName(ApiName.delIotDevice);
  113 + DeviceCommandApiParameter deviceCommandApiParameter = new DeviceCommandApiParameter();
  114 + deviceCommandApiParameter.setClient_id(imei);
  115 + deviceCommandApi.setDeviceCommandApiParameter(deviceCommandApiParameter);
  116 + return rocketMqService.send(deviceCommandApi);
  117 +
  118 + }
  119 +
  120 + /**
  121 + * 删除终端
  122 + * @param imei
  123 + * @param number
  124 + * @return
  125 + */
  126 + public Message delIotTerminal( String imei, String number) {
  127 + DeviceCommandApi deviceCommandApi = new DeviceCommandApi();
  128 + deviceCommandApi.setApiName(ApiName.delIotTerminal);
  129 + DeviceCommandApiParameter deviceCommandApiParameter = new DeviceCommandApiParameter();
  130 + deviceCommandApiParameter.setClient_id(imei);
  131 + deviceCommandApiParameter.setNumber(number);
  132 + deviceCommandApi.setDeviceCommandApiParameter(deviceCommandApiParameter);
  133 + return rocketMqService.send(deviceCommandApi);
  134 + }
  135 +
  136 + /**
  137 + * 读取属性
  138 + * @param imei
  139 + * @param sensor_number
  140 + * @param attributes
  141 + * @return
  142 + */
  143 + public Message readAttribute( String imei, String sensor_number,String attributes) {
  144 + Map<String,Object> map = new HashMap<>();
  145 + map.put(sensor_number,attributes);
  146 + DeviceCommandApi deviceCommandApi = new DeviceCommandApi();
  147 + deviceCommandApi.setApiName(ApiName.read);
  148 + DeviceCommandApiParameter deviceCommandApiParameter = new DeviceCommandApiParameter();
  149 + deviceCommandApiParameter.setClient_id(imei);
  150 + deviceCommandApiParameter.setMap(map);
  151 + deviceCommandApi.setDeviceCommandApiParameter(deviceCommandApiParameter);
  152 + return rocketMqService.send(deviceCommandApi);
  153 + }
  154 +
  155 + /**
  156 + * 设置主机自定义参数
  157 + * @param imei
  158 + * @param summary
  159 + * @return
  160 + */
  161 + public Message upSummary( String imei,String summary) {
  162 + Map<String,Object> map = new HashMap<>();
  163 + Map<String,Object> valueMap = new HashMap<>();
  164 + valueMap.put("summary", JSONObject.parseObject(summary));
  165 + map.put("0", valueMap);
  166 + DeviceCommandApi deviceCommandApi = getDeviceCommandApi(imei,map);
  167 + return rocketMqService.send(deviceCommandApi);
  168 + }
  169 +
  170 + /**
  171 + * 修改指定终端属性
  172 + * @param imei
  173 + * @param number
  174 + * @param config
  175 + * @return
  176 + */
  177 + public Message upTerminalConfig( String imei, String number, Map<String,Object> config) {
  178 + Map<String,Object> map = new HashMap<>();
  179 + map.put(number,config);
  180 + DeviceCommandApi deviceCommandApi = getDeviceCommandApi(imei,map);
  181 + return rocketMqService.send(deviceCommandApi);
  182 + }
  183 +
  184 + /**
  185 + * 批量修改终端属性
  186 + * @param imei
  187 + * @param map
  188 + * @return
  189 + */
  190 + public Message batchUpTerminalConfig( String imei, Map<String,Object> map) {
  191 + DeviceCommandApi deviceCommandApi = getDeviceCommandApi(imei,map);
  192 + return rocketMqService.send(deviceCommandApi);
  193 + }
  194 +}
@@ -124,4 +124,6 @@ public interface PublicService { @@ -124,4 +124,6 @@ public interface PublicService {
124 int deleteObjectById( Class<?> oClass, String id); 124 int deleteObjectById( Class<?> oClass, String id);
125 125
126 int insertIntoBySql(String sql); 126 int insertIntoBySql(String sql);
  127 +
  128 + public Long selectCountBySql(String sql);
127 } 129 }
1 package com.ruoyi.system.service.impl; 1 package com.ruoyi.system.service.impl;
2 2
  3 +import java.util.HashMap;
3 import java.util.List; 4 import java.util.List;
  5 +import java.util.Map;
4 6
  7 +import com.alibaba.fastjson.JSONObject;
  8 +import com.ruoyi.common.core.domain.Message;
5 import com.ruoyi.common.exception.ServiceException; 9 import com.ruoyi.common.exception.ServiceException;
6 import com.ruoyi.common.utils.DateUtils; 10 import com.ruoyi.common.utils.DateUtils;
7 import com.ruoyi.system.domain.IotProduct; 11 import com.ruoyi.system.domain.IotProduct;
  12 +import com.ruoyi.system.dto.ApiName;
  13 +import com.ruoyi.system.dto.DeviceCommandApi;
  14 +import com.ruoyi.system.dto.DeviceCommandApiParameter;
  15 +import com.ruoyi.system.rocketmq.RocketMqService;
8 import com.ruoyi.system.service.IIotProductService; 16 import com.ruoyi.system.service.IIotProductService;
9 import org.springframework.beans.factory.annotation.Autowired; 17 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Service; 18 import org.springframework.stereotype.Service;
@@ -25,6 +33,8 @@ public class IotDeviceServiceImpl implements IIotDeviceService @@ -25,6 +33,8 @@ public class IotDeviceServiceImpl implements IIotDeviceService
25 private IotDeviceMapper iotDeviceMapper; 33 private IotDeviceMapper iotDeviceMapper;
26 @Autowired 34 @Autowired
27 private IIotProductService iIotProductService; 35 private IIotProductService iIotProductService;
  36 + @Autowired
  37 + protected RocketMqService rocketMqService;
28 /** 38 /**
29 * 查询null 39 * 查询null
30 * 40 *
@@ -83,7 +93,18 @@ public class IotDeviceServiceImpl implements IIotDeviceService @@ -83,7 +93,18 @@ public class IotDeviceServiceImpl implements IIotDeviceService
83 @Override 93 @Override
84 public int updateIotDevice(IotDevice iotDevice) 94 public int updateIotDevice(IotDevice iotDevice)
85 { 95 {
86 - return iotDeviceMapper.updateIotDevice(iotDevice); 96 + DeviceCommandApi deviceCommandApi = new DeviceCommandApi();
  97 + deviceCommandApi.setApiName(ApiName.updateIotDevice);
  98 + DeviceCommandApiParameter deviceCommandApiParameter = new DeviceCommandApiParameter();
  99 + Map<String,Object> map = JSONObject.parseObject(JSONObject.toJSONString(iotDevice), HashMap.class);
  100 + deviceCommandApiParameter.setMap(map);
  101 + deviceCommandApi.setDeviceCommandApiParameter(deviceCommandApiParameter);
  102 + Message clJs = rocketMqService.send(deviceCommandApi);
  103 + if(clJs.getCode()==1)
  104 + {
  105 + return 1;
  106 + }
  107 + return 0;
87 } 108 }
88 109
89 /** 110 /**
1 package com.ruoyi.system.service.impl; 1 package com.ruoyi.system.service.impl;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
  4 +import java.util.HashMap;
4 import java.util.List; 5 import java.util.List;
5 import java.util.Map; 6 import java.util.Map;
6 7
@@ -11,6 +12,10 @@ import com.ruoyi.common.utils.DateUtils; @@ -11,6 +12,10 @@ import com.ruoyi.common.utils.DateUtils;
11 import com.ruoyi.common.utils.StringUtils; 12 import com.ruoyi.common.utils.StringUtils;
12 import com.ruoyi.common.utils.html.HttpUtils; 13 import com.ruoyi.common.utils.html.HttpUtils;
13 import com.ruoyi.system.domain.IotDevice; 14 import com.ruoyi.system.domain.IotDevice;
  15 +import com.ruoyi.system.dto.ApiName;
  16 +import com.ruoyi.system.dto.DeviceCommandApi;
  17 +import com.ruoyi.system.dto.DeviceCommandApiParameter;
  18 +import com.ruoyi.system.rocketmq.RocketMqService;
14 import com.ruoyi.system.service.IIotDeviceService; 19 import com.ruoyi.system.service.IIotDeviceService;
15 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
16 import org.springframework.stereotype.Service; 21 import org.springframework.stereotype.Service;
@@ -31,6 +36,9 @@ public class IotTerminalServiceImpl implements IIotTerminalService @@ -31,6 +36,9 @@ public class IotTerminalServiceImpl implements IIotTerminalService
31 private IotTerminalMapper iotTerminalMapper; 36 private IotTerminalMapper iotTerminalMapper;
32 @Autowired 37 @Autowired
33 private IIotDeviceService iotDeviceService; 38 private IIotDeviceService iotDeviceService;
  39 +
  40 + @Autowired
  41 + protected RocketMqService rocketMqService;
34 /** 42 /**
35 * 查询null 43 * 查询null
36 * 44 *
@@ -87,7 +95,18 @@ public class IotTerminalServiceImpl implements IIotTerminalService @@ -87,7 +95,18 @@ public class IotTerminalServiceImpl implements IIotTerminalService
87 @Override 95 @Override
88 public int updateIotTerminal(IotTerminal iotTerminal) 96 public int updateIotTerminal(IotTerminal iotTerminal)
89 { 97 {
90 - return iotTerminalMapper.updateIotTerminal(iotTerminal); 98 + DeviceCommandApi deviceCommandApi = new DeviceCommandApi();
  99 + deviceCommandApi.setApiName(ApiName.updateIotTerminal);
  100 + DeviceCommandApiParameter deviceCommandApiParameter = new DeviceCommandApiParameter();
  101 + Map<String,Object> map = JSONObject.parseObject(JSONObject.toJSONString(iotTerminal), HashMap.class);
  102 + deviceCommandApiParameter.setMap(map);
  103 + deviceCommandApi.setDeviceCommandApiParameter(deviceCommandApiParameter);
  104 + Message clJs = rocketMqService.send(deviceCommandApi);
  105 + if(clJs.getCode()==1)
  106 + {
  107 + return 1;
  108 + }
  109 + return 0;
91 } 110 }
92 111
93 /** 112 /**
@@ -110,27 +129,12 @@ public class IotTerminalServiceImpl implements IIotTerminalService @@ -110,27 +129,12 @@ public class IotTerminalServiceImpl implements IIotTerminalService
110 @Override 129 @Override
111 public String deleteIotTerminalById(String imei, String number) 130 public String deleteIotTerminalById(String imei, String number)
112 { 131 {
113 - IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);  
114 -  
115 - if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))  
116 - {  
117 - return JSONObject.toJSONString(new Message(MessageCode.DEFAULT_SUCCESS_CODE,"删除成功"));  
118 - }  
119 - String url = "http://"+iotDevice.getListen_service_ip()+"device/delIotTerminal/"+imei+"/"+number;  
120 -  
121 - String str = null;  
122 - try {  
123 - str = HttpUtils.getResponseString(HttpUtils.postFromBody(url, builder -> {  
124 - }, formBody -> {  
125 - }));  
126 - } catch (IOException e) {  
127 - }  
128 - iotTerminalMapper.deleteIotTerminalById(imei+"_"+number);  
129 - if(null != str)  
130 - {  
131 - return str;  
132 - }  
133 - return JSONObject.toJSONString(new Message(MessageCode.DEFAULT_SUCCESS_CODE,"删除成功")); 132 + DeviceCommandApi deviceCommandApi = new DeviceCommandApi();
  133 + deviceCommandApi.setApiName(ApiName.delIotTerminal);
  134 + DeviceCommandApiParameter deviceCommandApiParameter = new DeviceCommandApiParameter();
  135 + deviceCommandApiParameter.setClient_id(imei);
  136 + deviceCommandApi.setDeviceCommandApiParameter(deviceCommandApiParameter);
  137 + return JSONObject.toJSONString(rocketMqService.send(deviceCommandApi));
134 } 138 }
135 139
136 @Override 140 @Override
@@ -3,6 +3,7 @@ package com.ruoyi.system.service.impl; @@ -3,6 +3,7 @@ package com.ruoyi.system.service.impl;
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.ruoyi.system.mapper.PublicMapper; 4 import com.ruoyi.system.mapper.PublicMapper;
5 import com.ruoyi.system.service.PublicService; 5 import com.ruoyi.system.service.PublicService;
  6 +import org.apache.ibatis.annotations.Param;
6 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.stereotype.Service; 8 import org.springframework.stereotype.Service;
8 9
@@ -164,6 +165,17 @@ public class PublicServiceImpl implements PublicService { @@ -164,6 +165,17 @@ public class PublicServiceImpl implements PublicService {
164 { 165 {
165 return publicMapper.getObjectListBySQL(sql); 166 return publicMapper.getObjectListBySQL(sql);
166 } 167 }
  168 +
  169 + /**
  170 + * 自定义sql语句查询数量
  171 + * @param sql
  172 + * @return
  173 + */
  174 + public Long selectCountBySql(String sql)
  175 + {
  176 + return publicMapper.selectCountBySql(sql);
  177 + }
  178 +
167 /** 179 /**
168 * 添加或更新对象列表 180 * 添加或更新对象列表
169 * INSERT INTO `test` (`in1`,`str1`)VALUES ('1','2'),('2','2') ON DUPLICATE KEY UPDATE `in1`=VALUES(`in1`),`str1`=VALUES(`str1`); 181 * INSERT INTO `test` (`in1`,`str1`)VALUES ('1','2'),('2','2') ON DUPLICATE KEY UPDATE `in1`=VALUES(`in1`),`str1`=VALUES(`str1`);