作者 钟来

初始提交

正在显示 94 个修改的文件 包含 2069 行增加1168 行删除

要显示太多修改。

为保证性能只显示 94 of 94+ 个文件。

@@ -12,6 +12,8 @@ import org.springframework.context.annotation.ComponentScan; @@ -12,6 +12,8 @@ import org.springframework.context.annotation.ComponentScan;
12 "com.ruoyi.generator", 12 "com.ruoyi.generator",
13 "com.zhonglai.luhui.admin.config", 13 "com.zhonglai.luhui.admin.config",
14 "com.zhonglai.luhui.admin.controller", 14 "com.zhonglai.luhui.admin.controller",
  15 + "com.zhonglai.luhui.mqtt.comm.service.redis",
  16 + "com.zhonglai.luhui.mqtt.service.db.mode"
15 }) 17 })
16 @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) 18 @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
17 public class AdminApplication { 19 public class AdminApplication {
  1 +package com.zhonglai.luhui.admin.controller.iot;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.ruoyi.common.annotation.Log;
  5 +import com.ruoyi.common.core.domain.AjaxResult;
  6 +import com.ruoyi.common.core.domain.Message;
  7 +import com.ruoyi.common.core.domain.MessageCode;
  8 +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 io.swagger.annotations.Api;
  14 +import io.swagger.annotations.ApiImplicitParam;
  15 +import io.swagger.annotations.ApiImplicitParams;
  16 +import io.swagger.annotations.ApiOperation;
  17 +import okhttp3.FormBody;
  18 +import okhttp3.Request;
  19 +import okhttp3.Response;
  20 +import org.springframework.beans.factory.annotation.Autowired;
  21 +import org.springframework.security.access.prepost.PreAuthorize;
  22 +import org.springframework.stereotype.Controller;
  23 +import org.springframework.web.bind.annotation.*;
  24 +
  25 +import javax.servlet.http.HttpServletResponse;
  26 +import java.io.IOException;
  27 +import java.util.HashMap;
  28 +import java.util.Map;
  29 +
  30 +@Api(tags = "设备控制")
  31 +@Controller
  32 +@RequestMapping("/iot/iotDeviceControl")
  33 +public class IotDeviceControlController {
  34 + @Autowired
  35 + private IIotDeviceService iotDeviceService;
  36 +
  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 +
  48 + @ApiOperation("固件版本更新")
  49 + @ApiImplicitParams({
  50 + @ApiImplicitParam(value = "主机imei",name = "imei"),
  51 + @ApiImplicitParam(value = "版本号",name = "firmwareVersion")
  52 + })
  53 + @PreAuthorize("@ss.hasPermi('iot:iotDeviceControl:firmwareUp')")
  54 + @Log(title = "设备控制", businessType = BusinessType.UPDATE)
  55 + @ResponseBody
  56 + @PostMapping("/firmwareUp/{imei}")
  57 + public String firmwareUp(HttpServletResponse response,@PathVariable String imei,String firmwareVersion) throws IOException {
  58 + String url = getServiceAdrres(response,imei);
  59 + if(null == url)
  60 + {
  61 + return null;
  62 + }
  63 + Map<String,Object> map = new HashMap<>();
  64 + Map<String,Object> valueMap = new HashMap<>();
  65 + valueMap.put("firmwareVersion",firmwareVersion);
  66 + map.put("0",valueMap);
  67 + Response response1 = HttpUtils.postFromBody(url, builder -> {
  68 +
  69 + }, formBody -> {
  70 + formBody.add("map", JSONObject.toJSONString(map));
  71 + });
  72 + return response1.body().string();
  73 + }
  74 +
  75 + @ApiOperation("设备重启")
  76 + @ApiImplicitParams({
  77 + @ApiImplicitParam(value = "主机imei",name = "imei"),
  78 + @ApiImplicitParam(value = "restart 1重启,2复位,3恢复出厂值",name = "restart"),
  79 + })
  80 + @PreAuthorize("@ss.hasPermi('iot:iotDeviceControl:restart')")
  81 + @Log(title = "设备控制", businessType = BusinessType.UPDATE)
  82 + @ResponseBody
  83 + @PostMapping("/restart/{imei}/{restart}")
  84 + public String restart(HttpServletResponse response,@PathVariable String imei ,@PathVariable Integer restart) throws IOException {
  85 + String url = getServiceAdrres(response,imei);
  86 + if(null == url)
  87 + {
  88 + return null;
  89 + }
  90 + Map<String,Object> map = new HashMap<>();
  91 + Map<String,Object> valueMap = new HashMap<>();
  92 + valueMap.put("restart",restart);
  93 + map.put("0",valueMap);
  94 + Response response1 = HttpUtils.postFromBody(url, builder -> {
  95 +
  96 + }, formBody -> {
  97 + formBody.add("map", JSONObject.toJSONString(map));
  98 + });
  99 + return response1.body().string();
  100 + }
  101 +
  102 + @ApiOperation("获取指定设备版本信息")
  103 + @ApiImplicitParams({
  104 + @ApiImplicitParam(value = "主机imei",name = "imei"),
  105 + })
  106 + @ResponseBody
  107 + @PostMapping("/getFirmwareVersion/{imei}")
  108 + public String getFirmwareVersion(HttpServletResponse response,@PathVariable String imei) throws IOException {
  109 + IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);
  110 + response.setCharacterEncoding("UTF-8");
  111 + if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  112 + {
  113 + response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));
  114 + return null;
  115 + }
  116 + String url = "http://"+iotDevice.getListen_service_ip()+"device/getFirmwareVersion/"+iotDevice.getMqtt_username();
  117 +
  118 + Response response1 = HttpUtils.postFromBody(url, builder -> {
  119 + }, formBody -> {
  120 + });
  121 + return response1.body().string();
  122 + }
  123 +
  124 + @ApiOperation("强行断开链接")
  125 + @ApiImplicitParams({
  126 + @ApiImplicitParam(value = "主机imei",name = "imei"),
  127 + })
  128 + @ResponseBody
  129 + @PostMapping("/closeSession/{imei}")
  130 + public String closeSession(HttpServletResponse response,@PathVariable String imei) throws IOException {
  131 + IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);
  132 + response.setCharacterEncoding("UTF-8");
  133 + if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  134 + {
  135 + response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));
  136 + return null;
  137 + }
  138 + String url = "http://"+iotDevice.getListen_service_ip()+"device/closeSession/"+imei;
  139 +
  140 + Response response1 = HttpUtils.postFromBody(url, builder -> {
  141 + }, formBody -> {
  142 + });
  143 + return response1.body().string();
  144 + }
  145 +
  146 + @ApiOperation("删除主机")
  147 + @ApiImplicitParams({
  148 + @ApiImplicitParam(value = "主机imei",name = "imei"),
  149 + })
  150 + @ResponseBody
  151 + @PostMapping("/delIotDevice/{imei}")
  152 + public String delIotDevice(HttpServletResponse response,@PathVariable String imei) throws IOException {
  153 + IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);
  154 + response.setCharacterEncoding("UTF-8");
  155 + if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  156 + {
  157 + response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));
  158 + return null;
  159 + }
  160 + String url = "http://"+iotDevice.getListen_service_ip()+"device/delIotDevice/"+imei;
  161 +
  162 + Response response1 = HttpUtils.postFromBody(url, builder -> {
  163 + }, formBody -> {
  164 + });
  165 + return response1.body().string();
  166 + }
  167 +
  168 + @ApiOperation("删除终端")
  169 + @ApiImplicitParams({
  170 + @ApiImplicitParam(value = "主机imei",name = "imei"),
  171 + })
  172 + @ResponseBody
  173 + @PostMapping("/delIotTerminal/{imei}/{number}")
  174 + public String delIotTerminal(HttpServletResponse response,@PathVariable String imei,@PathVariable String number) throws IOException {
  175 + IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);
  176 + response.setCharacterEncoding("UTF-8");
  177 + if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  178 + {
  179 + response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));
  180 + return null;
  181 + }
  182 + String url = "http://"+iotDevice.getListen_service_ip()+"device/delIotTerminal/"+imei+"/"+number;
  183 +
  184 + Response response1 = HttpUtils.postFromBody(url, builder -> {
  185 + }, formBody -> {
  186 + });
  187 + return response1.body().string();
  188 + }
  189 +
  190 + @ApiOperation(value = "读取属性")
  191 + @ApiImplicitParams({
  192 + @ApiImplicitParam(value = "主机imei",name = "imei"),
  193 + @ApiImplicitParam(value = "传感器编号(0,1_1,10_1)",name = "sensor_number"),
  194 + @ApiImplicitParam(value = "属性集合(id1,id2,id3)",name = "attributes"),
  195 + })
  196 + @PreAuthorize("@ss.hasPermi('iot:iotDeviceControl:upSummary')")
  197 + @Log(title = "设备控制", businessType = BusinessType.UPDATE)
  198 + @ResponseBody
  199 + @PostMapping("/readAttribute/{imei}/{sensor_number}")
  200 + public String readAttribute(HttpServletResponse response,@PathVariable String imei,@PathVariable String sensor_number,String attributes) throws IOException {
  201 + IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);
  202 + response.setCharacterEncoding("UTF-8");
  203 + if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))
  204 + {
  205 + response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));
  206 + return null;
  207 + }
  208 + String url = "http://"+iotDevice.getListen_service_ip()+"device/read/"+imei;
  209 + Map<String,Object> map = new HashMap<>();
  210 + map.put(sensor_number,attributes);
  211 + Response response1 = HttpUtils.postJsonBody(url, jsonObject -> jsonObject.putAll(map));
  212 + return response1.body().string();
  213 + }
  214 +
  215 + @ApiOperation(value = "设置主机自定义参数",notes = "自定义数据模型:\n" +
  216 + "{\n" +
  217 + " \t \"name\": \"wumei-smart\",\n" +
  218 + " \t \"chip\": \"esp8266\",\n" +
  219 + " \t \"author\": \"kerwincui\",\n" +
  220 + " \t \"version\": 1.2,\n" +
  221 + " \t \"createTime\": \"2022-06-06\"\n" +
  222 + " }")
  223 + @ApiImplicitParams({
  224 + @ApiImplicitParam(value = "主机imei",name = "imei"),
  225 + @ApiImplicitParam(value = "自定义数据json字符串",name = "summary")
  226 + })
  227 + @PreAuthorize("@ss.hasPermi('iot:iotDeviceControl:upSummary')")
  228 + @Log(title = "设备控制", businessType = BusinessType.UPDATE)
  229 + @ResponseBody
  230 + @PostMapping("/upSummary/{imei}")
  231 + public String upSummary(HttpServletResponse response,@PathVariable String imei,String summary) throws IOException {
  232 + String url = getServiceAdrres(response,imei);
  233 + if(null == url)
  234 + {
  235 + return null;
  236 + }
  237 + Map<String,Object> map = new HashMap<>();
  238 + Map<String,Object> valueMap = new HashMap<>();
  239 + valueMap.put("summary",JSONObject.parseObject(summary));
  240 + map.put("0",valueMap);
  241 + Response response1 = HttpUtils.postFromBody(url, builder -> {
  242 +
  243 + }, formBody -> {
  244 + formBody.add("map", JSONObject.toJSONString(map));
  245 + });
  246 + return response1.body().string();
  247 + }
  248 +
  249 + @ApiOperation(value = "修改指定终端属性",notes = "配置参数模型:\n" +
  250 + "{\n" +
  251 + " \"id1\":\"value1\",\n" +
  252 + " \"id2\":\"value2\",\n" +
  253 + " \"id3\":\"value3\"\n" +
  254 + " }")
  255 + @ApiImplicitParams({
  256 + @ApiImplicitParam(value = "主机imei",name = "imei"),
  257 + @ApiImplicitParam(value = "终端编号(如:1_1)",name = "number"),
  258 + @ApiImplicitParam(value = "配置参数json字符串",name = "config")
  259 + })
  260 + @PreAuthorize("@ss.hasPermi('iot:iotDeviceControl:upTerminalConfig')")
  261 + @Log(title = "设备控制", businessType = BusinessType.UPDATE)
  262 + @ResponseBody
  263 + @PostMapping("/upTerminalConfig/{imei}/{number}")
  264 + public String upTerminalConfig(HttpServletResponse response, @PathVariable String imei,@PathVariable String number,@RequestBody Map<String,Object> config) throws IOException {
  265 + String url = getServiceAdrres(response,imei);
  266 + if(null == url)
  267 + {
  268 + return null;
  269 + }
  270 + Map<String,Object> map = new HashMap<>();
  271 + map.put(number,config);
  272 + Response response1 = HttpUtils.postJsonBody(url, jsonObject -> jsonObject.putAll(map));
  273 + return response1.body().string();
  274 + }
  275 +
  276 + @ApiOperation(value = "批量修改终端属性",notes = "批量数据模型:\n" +
  277 + "{\n" +
  278 + " \"1\":{\n" +
  279 + " \"id1\":\"value1\",\n" +
  280 + " \"id2\":\"value2\",\n" +
  281 + " \"id3\":\"value3\"\n" +
  282 + " },\n" +
  283 + " \"3\":{\n" +
  284 + " \"id1\":\"value1\",\n" +
  285 + " \"id2\":\"value2\",\n" +
  286 + " \"id3\":\"value3\"\n" +
  287 + " },\n" +
  288 + " \"4\":{\n" +
  289 + " \"id1\":\"value1\",\n" +
  290 + " \"id2\":\"value2\",\n" +
  291 + " \"id3\":\"value3\"\n" +
  292 + " }\n" +
  293 + "}")
  294 + @ApiImplicitParam(value = "批量数据json字符串",name = "map")
  295 + @PreAuthorize("@ss.hasPermi('iot:iotDeviceControl:batchUpTerminalConfig')")
  296 + @Log(title = "设备控制", businessType = BusinessType.UPDATE)
  297 + @ResponseBody
  298 + @PostMapping("/batchUpTerminalConfig/{imei}")
  299 + public String batchUpTerminalConfig(HttpServletResponse response,@PathVariable String imei,@RequestBody Map<String,Object> map) throws IOException {
  300 + String url = getServiceAdrres(response,imei);
  301 + if(null == url)
  302 + {
  303 + return null;
  304 + }
  305 + Response response1 = HttpUtils.postFromBody(url, builder -> {
  306 +
  307 + }, formBody -> {
  308 + formBody.add("map", JSONObject.toJSONString(map));
  309 + });
  310 + return response1.body().string();
  311 + }
  312 +
  313 +
  314 +}
@@ -3,9 +3,11 @@ package com.zhonglai.luhui.admin.controller.iot; @@ -3,9 +3,11 @@ package com.zhonglai.luhui.admin.controller.iot;
3 import java.util.List; 3 import java.util.List;
4 import javax.servlet.http.HttpServletResponse; 4 import javax.servlet.http.HttpServletResponse;
5 5
6 -import com.ruoyi.common.utils.http.HttpUtils; 6 +import com.ruoyi.common.core.domain.Message;
  7 +import com.ruoyi.common.utils.DateUtils;
  8 +import com.ruoyi.system.domain.IotProduct;
  9 +import com.ruoyi.system.service.IIotProductService;
7 import io.swagger.annotations.Api; 10 import io.swagger.annotations.Api;
8 -import io.swagger.annotations.ApiImplicitParam;  
9 import io.swagger.annotations.ApiOperation; 11 import io.swagger.annotations.ApiOperation;
10 import org.springframework.security.access.prepost.PreAuthorize; 12 import org.springframework.security.access.prepost.PreAuthorize;
11 import org.springframework.beans.factory.annotation.Autowired; 13 import org.springframework.beans.factory.annotation.Autowired;
@@ -39,7 +41,8 @@ public class IotDeviceController extends BaseController @@ -39,7 +41,8 @@ public class IotDeviceController extends BaseController
39 { 41 {
40 @Autowired 42 @Autowired
41 private IIotDeviceService iotDeviceService; 43 private IIotDeviceService iotDeviceService;
42 - 44 + @Autowired
  45 + private IIotProductService iIotProductService;
43 /** 46 /**
44 * 查询主机/网关列表 47 * 查询主机/网关列表
45 */ 48 */
@@ -87,6 +90,11 @@ public class IotDeviceController extends BaseController @@ -87,6 +90,11 @@ public class IotDeviceController extends BaseController
87 @PostMapping("add") 90 @PostMapping("add")
88 public AjaxResult add(@RequestBody IotDevice iotDevice) 91 public AjaxResult add(@RequestBody IotDevice iotDevice)
89 { 92 {
  93 +
  94 + IotProduct iotProduct = iIotProductService.selectIotProductById(iotDevice.getProduct_id());
  95 + iotDevice.setMqtt_username(iotProduct.getMqtt_username());
  96 + iotDevice.setCreate_by(getUsername());
  97 + iotDevice.setCreate_time(DateUtils.getNowTimeMilly());
90 return toAjax(iotDeviceService.insertIotDevice(iotDevice)); 98 return toAjax(iotDeviceService.insertIotDevice(iotDevice));
91 } 99 }
92 100
@@ -99,6 +107,8 @@ public class IotDeviceController extends BaseController @@ -99,6 +107,8 @@ public class IotDeviceController extends BaseController
99 @PutMapping("edit") 107 @PutMapping("edit")
100 public AjaxResult edit(@RequestBody IotDevice iotDevice) 108 public AjaxResult edit(@RequestBody IotDevice iotDevice)
101 { 109 {
  110 + iotDevice.setUpdate_by(getUsername());
  111 + iotDevice.setUpdate_time(DateUtils.getNowTimeMilly());
102 return toAjax(iotDeviceService.updateIotDevice(iotDevice)); 112 return toAjax(iotDeviceService.updateIotDevice(iotDevice));
103 } 113 }
104 114
@@ -113,27 +123,4 @@ public class IotDeviceController extends BaseController @@ -113,27 +123,4 @@ public class IotDeviceController extends BaseController
113 { 123 {
114 return toAjax(iotDeviceService.deleteIotDeviceByClient_ids(client_ids)); 124 return toAjax(iotDeviceService.deleteIotDeviceByClient_ids(client_ids));
115 } 125 }
116 -  
117 -  
118 - /**  
119 - * 修改主机/网关  
120 - */  
121 - @ApiOperation("修改主机/网关")  
122 - @PreAuthorize("@ss.hasPermi('iot:IotDevice:restart')")  
123 - @Log(title = "主机/网关", businessType = BusinessType.UPDATE)  
124 - @PutMapping("restart")  
125 - public AjaxResult restart(@RequestBody IotDevice iotDevice)  
126 - {  
127 - return toAjax(iotDeviceService.updateIotDevice(iotDevice));  
128 - }  
129 -  
130 -// @ApiOperation("固件版本更新")  
131 -// @ApiImplicitParam(value = "版本号",name = "firmwareVersion")  
132 -// @PreAuthorize("@ss.hasPermi('iot:IotDevice:firmwareUp')")  
133 -// @Log(title = "主机/网关", businessType = BusinessType.UPDATE)  
134 -// @PutMapping  
135 -// public AjaxResult firmwareUp(String firmwareVersion)  
136 -// {  
137 -// return redirect("/device/control");  
138 -// }  
139 } 126 }
@@ -19,8 +19,8 @@ import com.ruoyi.common.annotation.Log; @@ -19,8 +19,8 @@ import com.ruoyi.common.annotation.Log;
19 import com.ruoyi.common.core.controller.BaseController; 19 import com.ruoyi.common.core.controller.BaseController;
20 import com.ruoyi.common.core.domain.AjaxResult; 20 import com.ruoyi.common.core.domain.AjaxResult;
21 import com.ruoyi.common.enums.BusinessType; 21 import com.ruoyi.common.enums.BusinessType;
22 -import com.ruoyi.system.domain.IotUser;  
23 -import com.ruoyi.system.service.IIotUserService; 22 +import com.ruoyi.system.domain.IotProduct;
  23 +import com.ruoyi.system.service.IIotProductService;
24 import com.ruoyi.common.utils.poi.ExcelUtil; 24 import com.ruoyi.common.utils.poi.ExcelUtil;
25 import com.ruoyi.common.core.page.TableDataInfo; 25 import com.ruoyi.common.core.page.TableDataInfo;
26 26
@@ -32,22 +32,22 @@ import com.ruoyi.common.core.page.TableDataInfo; @@ -32,22 +32,22 @@ import com.ruoyi.common.core.page.TableDataInfo;
32 */ 32 */
33 @Api(tags = "产品") 33 @Api(tags = "产品")
34 @RestController 34 @RestController
35 -@RequestMapping("/iot/IotUser")  
36 -public class IotUserController extends BaseController 35 +@RequestMapping("/iot/IotProduct")
  36 +public class IotProductController extends BaseController
37 { 37 {
38 @Autowired 38 @Autowired
39 - private IIotUserService iotUserService; 39 + private IIotProductService IotProductService;
40 40
41 /** 41 /**
42 * 查询产品列表 42 * 查询产品列表
43 */ 43 */
44 @ApiOperation("查询产品列表") 44 @ApiOperation("查询产品列表")
45 - @PreAuthorize("@ss.hasPermi('iot:IotUser:list')") 45 + @PreAuthorize("@ss.hasPermi('iot:IotProduct:list')")
46 @GetMapping("/list") 46 @GetMapping("/list")
47 - public TableDataInfo list(IotUser iotUser) 47 + public TableDataInfo list(IotProduct iotProduct)
48 { 48 {
49 startPage(); 49 startPage();
50 - List<IotUser> list = iotUserService.selectIotUserList(iotUser); 50 + List<IotProduct> list = IotProductService.selectIotProductList(iotProduct);
51 return getDataTable(list); 51 return getDataTable(list);
52 } 52 }
53 53
@@ -55,13 +55,13 @@ public class IotUserController extends BaseController @@ -55,13 +55,13 @@ public class IotUserController extends BaseController
55 * 导出产品列表 55 * 导出产品列表
56 */ 56 */
57 @ApiOperation("导出产品列表") 57 @ApiOperation("导出产品列表")
58 - @PreAuthorize("@ss.hasPermi('iot:IotUser:export')") 58 + @PreAuthorize("@ss.hasPermi('iot:IotProduct:export')")
59 @Log(title = "产品", businessType = BusinessType.EXPORT) 59 @Log(title = "产品", businessType = BusinessType.EXPORT)
60 @PostMapping("/export") 60 @PostMapping("/export")
61 - public void export(HttpServletResponse response, IotUser iotUser) 61 + public void export(HttpServletResponse response, IotProduct iotProduct)
62 { 62 {
63 - List<IotUser> list = iotUserService.selectIotUserList(iotUser);  
64 - ExcelUtil<IotUser> util = new ExcelUtil<IotUser>(IotUser.class); 63 + List<IotProduct> list = IotProductService.selectIotProductList(iotProduct);
  64 + ExcelUtil<IotProduct> util = new ExcelUtil<IotProduct>(IotProduct.class);
65 util.exportExcel(response, list, "产品数据"); 65 util.exportExcel(response, list, "产品数据");
66 } 66 }
67 67
@@ -69,46 +69,46 @@ public class IotUserController extends BaseController @@ -69,46 +69,46 @@ public class IotUserController extends BaseController
69 * 获取产品详细信息 69 * 获取产品详细信息
70 */ 70 */
71 @ApiOperation("获取产品详细信息") 71 @ApiOperation("获取产品详细信息")
72 - @PreAuthorize("@ss.hasPermi('iot:IotUser:query')") 72 + @PreAuthorize("@ss.hasPermi('iot:IotProduct:query')")
73 @GetMapping(value = "/{id}") 73 @GetMapping(value = "/{id}")
74 public AjaxResult getInfo(@PathVariable("id") Integer id) 74 public AjaxResult getInfo(@PathVariable("id") Integer id)
75 { 75 {
76 - return AjaxResult.success(iotUserService.selectIotUserById(id)); 76 + return AjaxResult.success(IotProductService.selectIotProductById(id));
77 } 77 }
78 78
79 /** 79 /**
80 * 新增产品 80 * 新增产品
81 */ 81 */
82 @ApiOperation("新增产品") 82 @ApiOperation("新增产品")
83 - @PreAuthorize("@ss.hasPermi('iot:IotUser:add')") 83 + @PreAuthorize("@ss.hasPermi('iot:IotProduct:add')")
84 @Log(title = "产品", businessType = BusinessType.INSERT) 84 @Log(title = "产品", businessType = BusinessType.INSERT)
85 @PostMapping 85 @PostMapping
86 - public AjaxResult add(@RequestBody IotUser iotUser) 86 + public AjaxResult add(@RequestBody IotProduct iotProduct)
87 { 87 {
88 - return toAjax(iotUserService.insertIotUser(iotUser)); 88 + return toAjax(IotProductService.insertIotProduct(iotProduct));
89 } 89 }
90 90
91 /** 91 /**
92 * 修改产品 92 * 修改产品
93 */ 93 */
94 @ApiOperation("修改产品") 94 @ApiOperation("修改产品")
95 - @PreAuthorize("@ss.hasPermi('iot:IotUser:edit')") 95 + @PreAuthorize("@ss.hasPermi('iot:IotProduct:edit')")
96 @Log(title = "产品", businessType = BusinessType.UPDATE) 96 @Log(title = "产品", businessType = BusinessType.UPDATE)
97 @PutMapping 97 @PutMapping
98 - public AjaxResult edit(@RequestBody IotUser iotUser) 98 + public AjaxResult edit(@RequestBody IotProduct iotProduct)
99 { 99 {
100 - return toAjax(iotUserService.updateIotUser(iotUser)); 100 + return toAjax(IotProductService.updateIotProduct(iotProduct));
101 } 101 }
102 102
103 /** 103 /**
104 * 删除产品 104 * 删除产品
105 */ 105 */
106 @ApiOperation("删除产品") 106 @ApiOperation("删除产品")
107 - @PreAuthorize("@ss.hasPermi('iot:IotUser:remove')") 107 + @PreAuthorize("@ss.hasPermi('iot:IotProduct:remove')")
108 @Log(title = "产品", businessType = BusinessType.DELETE) 108 @Log(title = "产品", businessType = BusinessType.DELETE)
109 @DeleteMapping("/{ids}") 109 @DeleteMapping("/{ids}")
110 public AjaxResult remove(@PathVariable Integer[] ids) 110 public AjaxResult remove(@PathVariable Integer[] ids)
111 { 111 {
112 - return toAjax(iotUserService.deleteIotUserByIds(ids)); 112 + return toAjax(IotProductService.deleteIotProductByIds(ids));
113 } 113 }
114 } 114 }
1 package com.zhonglai.luhui.admin.controller.iot; 1 package com.zhonglai.luhui.admin.controller.iot;
2 2
3 -import java.util.Date;  
4 -import java.util.List; 3 +import java.util.*;
5 import javax.servlet.http.HttpServletResponse; 4 import javax.servlet.http.HttpServletResponse;
6 5
7 import com.alibaba.fastjson.JSON; 6 import com.alibaba.fastjson.JSON;
8 import com.alibaba.fastjson.JSONObject; 7 import com.alibaba.fastjson.JSONObject;
9 -import com.ruoyi.common.utils.DateUtils; 8 +import com.ruoyi.system.domain.IotProduct;
  9 +import com.ruoyi.system.service.IIotProductService;
10 import com.zhonglai.luhui.admin.dto.IotThingsModelAddApi; 10 import com.zhonglai.luhui.admin.dto.IotThingsModelAddApi;
11 import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase; 11 import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase;
12 import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.specs.*; 12 import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.specs.*;
  13 +import com.zhonglai.luhui.mqtt.service.db.mode.TerminalDataThingsModeService;
13 import io.swagger.annotations.Api; 14 import io.swagger.annotations.Api;
14 import io.swagger.annotations.ApiOperation; 15 import io.swagger.annotations.ApiOperation;
15 import org.springframework.security.access.prepost.PreAuthorize; 16 import org.springframework.security.access.prepost.PreAuthorize;
16 import org.springframework.beans.factory.annotation.Autowired; 17 import org.springframework.beans.factory.annotation.Autowired;
  18 +import org.springframework.transaction.annotation.Transactional;
17 import org.springframework.web.bind.annotation.GetMapping; 19 import org.springframework.web.bind.annotation.GetMapping;
18 import org.springframework.web.bind.annotation.PostMapping; 20 import org.springframework.web.bind.annotation.PostMapping;
19 import org.springframework.web.bind.annotation.PutMapping; 21 import org.springframework.web.bind.annotation.PutMapping;
@@ -33,7 +35,7 @@ import com.ruoyi.common.core.page.TableDataInfo; @@ -33,7 +35,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
33 35
34 /** 36 /**
35 * 物模型模板Controller 37 * 物模型模板Controller
36 - * 38 + *
37 * @author 钟来 39 * @author 钟来
38 * @date 2022-08-26 40 * @date 2022-08-26
39 */ 41 */
@@ -45,6 +47,11 @@ public class IotThingsModelController extends BaseController @@ -45,6 +47,11 @@ public class IotThingsModelController extends BaseController
45 @Autowired 47 @Autowired
46 private IIotThingsModelService iotThingsModelService; 48 private IIotThingsModelService iotThingsModelService;
47 49
  50 + @Autowired
  51 + private TerminalDataThingsModeService terminalDataThingsModeService;
  52 +
  53 + @Autowired
  54 + private IIotProductService iIotProductService;
48 /** 55 /**
49 * 查询物模型模板列表 56 * 查询物模型模板列表
50 */ 57 */
@@ -124,7 +131,12 @@ public class IotThingsModelController extends BaseController @@ -124,7 +131,12 @@ public class IotThingsModelController extends BaseController
124 return AjaxResult.error("请输入数模型"); 131 return AjaxResult.error("请输入数模型");
125 } 132 }
126 iotThingsModel.setSpecs(JSONObject.toJSONString(thingsModelItemBase)); 133 iotThingsModel.setSpecs(JSONObject.toJSONString(thingsModelItemBase));
127 - return toAjax(iotThingsModelService.insertIotThingsModel(iotThingsModel)); 134 +
  135 + IotProduct iotProduct = iIotProductService.selectIotProductById(iotThingsModel.getProduct_id());
  136 + iotThingsModel.setMqtt_username(iotProduct.getMqtt_username());
  137 + int ri = iotThingsModelService.insertIotThingsModel(iotThingsModel);
  138 + terminalDataThingsModeService.saveIotThingsModel(JSON.parseObject(JSONObject.toJSONString(iotThingsModel),IotThingsModel.class));
  139 + return toAjax(ri);
128 } 140 }
129 141
130 /** 142 /**
@@ -134,9 +146,47 @@ public class IotThingsModelController extends BaseController @@ -134,9 +146,47 @@ public class IotThingsModelController extends BaseController
134 @PreAuthorize("@ss.hasPermi('iot:IotThingsModel:edit')") 146 @PreAuthorize("@ss.hasPermi('iot:IotThingsModel:edit')")
135 @Log(title = "物模型模板", businessType = BusinessType.UPDATE) 147 @Log(title = "物模型模板", businessType = BusinessType.UPDATE)
136 @PutMapping 148 @PutMapping
137 - public AjaxResult edit(@RequestBody IotThingsModel iotThingsModel) 149 + public AjaxResult edit(@RequestBody IotThingsModelAddApi iotThingsModelAddApi)
138 { 150 {
139 - return toAjax(iotThingsModelService.updateIotThingsModel(iotThingsModel)); 151 + IotThingsModel iotThingsModel = iotThingsModelAddApi.getIotThingsModel();
  152 + iotThingsModel.setCreate_by(getUsername());
  153 + ThingsModelItemBase thingsModelItemBase = null;
  154 + switch (iotThingsModel.getData_type())
  155 + {
  156 + case "integer":
  157 + thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), IntegerModelOutput.class);
  158 + break;
  159 + case "decimal":
  160 + thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), DecimalModelOutput.class);
  161 + break;
  162 + case "string":
  163 + thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), StringModelOutput.class);
  164 +
  165 + break;
  166 + case "bool":
  167 + thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), BoolModelOutput.class);
  168 +
  169 + break;
  170 + case "array":
  171 + thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), ArrayModelOutput.class);
  172 +
  173 + break;
  174 + case "enum":
  175 + thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), EnumModelOutput.class);
  176 + break;
  177 + }
  178 + if(null == thingsModelItemBase)
  179 + {
  180 + return AjaxResult.error("请输入数模型");
  181 + }
  182 + iotThingsModel.setSpecs(JSONObject.toJSONString(thingsModelItemBase));
  183 + int ri =iotThingsModelService.updateIotThingsModel(iotThingsModel);
  184 +
  185 + IotThingsModel oldiotThingsModel = iotThingsModelService.selectIotThingsModelByModel_id(iotThingsModel.getModel_id());
  186 + IotProduct iotProduct = iIotProductService.selectIotProductById(oldiotThingsModel.getProduct_id());
  187 + iotThingsModel.setMqtt_username(iotProduct.getMqtt_username());
  188 + terminalDataThingsModeService.saveIotThingsModel(JSON.parseObject(JSONObject.toJSONString(iotThingsModel),IotThingsModel.class));
  189 + return toAjax(ri);
140 } 190 }
141 191
142 /** 192 /**
@@ -145,9 +195,34 @@ public class IotThingsModelController extends BaseController @@ -145,9 +195,34 @@ public class IotThingsModelController extends BaseController
145 @ApiOperation("删除物模型模板") 195 @ApiOperation("删除物模型模板")
146 @PreAuthorize("@ss.hasPermi('iot:IotThingsModel:remove')") 196 @PreAuthorize("@ss.hasPermi('iot:IotThingsModel:remove')")
147 @Log(title = "物模型模板", businessType = BusinessType.DELETE) 197 @Log(title = "物模型模板", businessType = BusinessType.DELETE)
  198 + @Transactional
148 @DeleteMapping("/{model_ids}") 199 @DeleteMapping("/{model_ids}")
149 public AjaxResult remove(@PathVariable Integer[] model_ids) 200 public AjaxResult remove(@PathVariable Integer[] model_ids)
150 { 201 {
151 - return toAjax(iotThingsModelService.deleteIotThingsModelByModel_ids(model_ids)); 202 + Map<String,List<String>> map = new HashMap<>();
  203 + List<IotThingsModel> list = iotThingsModelService.selectIotThingsModelListByIds(model_ids);
  204 + if(null != list && list.size() !=0)
  205 + {
  206 + for(IotThingsModel iotThingsModel:list)
  207 + {
  208 + List<String> identifiers = map.get(iotThingsModel.getMqtt_username());
  209 + if(null == identifiers )
  210 + {
  211 + identifiers = new ArrayList<>();
  212 + map.put(iotThingsModel.getMqtt_username(),identifiers);
  213 + }
  214 + identifiers.add(iotThingsModel.getIdentifier());
  215 + }
  216 + }
  217 + int ri =iotThingsModelService.deleteIotThingsModelByModel_ids(model_ids);
  218 + if(null != map && map.size() !=0)
  219 + {
  220 + for(String key:map.keySet())
  221 + {
  222 + terminalDataThingsModeService.delIotThingsModel(key, map.get(key).toArray());
  223 + }
  224 + }
  225 +
  226 + return toAjax(ri);
152 } 227 }
153 } 228 }
  1 +package com.zhonglai.luhui.admin.controller.iot;
  2 +
  3 +import java.util.List;
  4 +import javax.servlet.http.HttpServletResponse;
  5 +
  6 +import io.swagger.annotations.Api;
  7 +import io.swagger.annotations.ApiOperation;
  8 +import org.springframework.security.access.prepost.PreAuthorize;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.web.bind.annotation.GetMapping;
  11 +import org.springframework.web.bind.annotation.PostMapping;
  12 +import org.springframework.web.bind.annotation.PutMapping;
  13 +import org.springframework.web.bind.annotation.DeleteMapping;
  14 +import org.springframework.web.bind.annotation.PathVariable;
  15 +import org.springframework.web.bind.annotation.RequestBody;
  16 +import org.springframework.web.bind.annotation.RequestMapping;
  17 +import org.springframework.web.bind.annotation.RestController;
  18 +import com.ruoyi.common.annotation.Log;
  19 +import com.ruoyi.common.core.controller.BaseController;
  20 +import com.ruoyi.common.core.domain.AjaxResult;
  21 +import com.ruoyi.common.enums.BusinessType;
  22 +import com.ruoyi.system.domain.IotThingsModelTemplate;
  23 +import com.ruoyi.system.service.IIotThingsModelTemplateService;
  24 +import com.ruoyi.common.utils.poi.ExcelUtil;
  25 +import com.ruoyi.common.core.page.TableDataInfo;
  26 +
  27 +/**
  28 + * 物模型模板Controller
  29 + *
  30 + * @author 钟来
  31 + * @date 2022-10-24
  32 + */
  33 +@Api(tags = "物模型模板公用模型")
  34 +@RestController
  35 +@RequestMapping("/iot/IotThingsModelTemplate")
  36 +public class IotThingsModelTemplateController extends BaseController
  37 +{
  38 + @Autowired
  39 + private IIotThingsModelTemplateService iotThingsModelTemplateService;
  40 +
  41 + /**
  42 + * 查询物模型模板列表
  43 + */
  44 + @ApiOperation("查询物模型模板列表")
  45 + @PreAuthorize("@ss.hasPermi('iot:IotThingsModelTemplate:list')")
  46 + @GetMapping("/list")
  47 + public TableDataInfo list(IotThingsModelTemplate iotThingsModelTemplate)
  48 + {
  49 + startPage();
  50 + List<IotThingsModelTemplate> list = iotThingsModelTemplateService.selectIotThingsModelTemplateList(iotThingsModelTemplate);
  51 + return getDataTable(list);
  52 + }
  53 +
  54 + /**
  55 + * 导出物模型模板列表
  56 + */
  57 + @ApiOperation("导出物模型模板列表")
  58 + @PreAuthorize("@ss.hasPermi('iot:IotThingsModelTemplate:export')")
  59 + @Log(title = "物模型模板", businessType = BusinessType.EXPORT)
  60 + @PostMapping("/export")
  61 + public void export(HttpServletResponse response, IotThingsModelTemplate iotThingsModelTemplate)
  62 + {
  63 + List<IotThingsModelTemplate> list = iotThingsModelTemplateService.selectIotThingsModelTemplateList(iotThingsModelTemplate);
  64 + ExcelUtil<IotThingsModelTemplate> util = new ExcelUtil<IotThingsModelTemplate>(IotThingsModelTemplate.class);
  65 + util.exportExcel(response, list, "物模型模板数据");
  66 + }
  67 +
  68 + /**
  69 + * 获取物模型模板详细信息
  70 + */
  71 + @ApiOperation("获取物模型模板详细信息")
  72 + @PreAuthorize("@ss.hasPermi('iot:IotThingsModelTemplate:query')")
  73 + @GetMapping(value = "/{model_id}")
  74 + public AjaxResult getInfo(@PathVariable("model_id") Integer model_id)
  75 + {
  76 + return AjaxResult.success(iotThingsModelTemplateService.selectIotThingsModelTemplateByModel_id(model_id));
  77 + }
  78 +
  79 + /**
  80 + * 新增物模型模板
  81 + */
  82 + @ApiOperation("新增物模型模板")
  83 + @PreAuthorize("@ss.hasPermi('iot:IotThingsModelTemplate:add')")
  84 + @Log(title = "物模型模板", businessType = BusinessType.INSERT)
  85 + @PostMapping
  86 + public AjaxResult add(@RequestBody IotThingsModelTemplate iotThingsModelTemplate)
  87 + {
  88 + return toAjax(iotThingsModelTemplateService.insertIotThingsModelTemplate(iotThingsModelTemplate));
  89 + }
  90 +
  91 + /**
  92 + * 修改物模型模板
  93 + */
  94 + @ApiOperation("修改物模型模板")
  95 + @PreAuthorize("@ss.hasPermi('iot:IotThingsModelTemplate:edit')")
  96 + @Log(title = "物模型模板", businessType = BusinessType.UPDATE)
  97 + @PutMapping
  98 + public AjaxResult edit(@RequestBody IotThingsModelTemplate iotThingsModelTemplate)
  99 + {
  100 + return toAjax(iotThingsModelTemplateService.updateIotThingsModelTemplate(iotThingsModelTemplate));
  101 + }
  102 +
  103 + /**
  104 + * 删除物模型模板
  105 + */
  106 + @ApiOperation("删除物模型模板")
  107 + @PreAuthorize("@ss.hasPermi('iot:IotThingsModelTemplate:remove')")
  108 + @Log(title = "物模型模板", businessType = BusinessType.DELETE)
  109 + @DeleteMapping("/{model_ids}")
  110 + public AjaxResult remove(@PathVariable Integer[] model_ids)
  111 + {
  112 + return toAjax(iotThingsModelTemplateService.deleteIotThingsModelTemplateByModel_ids(model_ids));
  113 + }
  114 +}
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: 0 # 密码 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 # 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/* 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: 0 # 密码 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 # 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 +<?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-domain</artifactId>
  13 +
  14 + <dependencies>
  15 + <dependency>
  16 + <groupId>org.apache.commons</groupId>
  17 + <artifactId>commons-lang3</artifactId>
  18 + </dependency>
  19 + <dependency>
  20 + <groupId>org.springframework.data</groupId>
  21 + <artifactId>spring-data-commons</artifactId>
  22 + </dependency>
  23 + <dependency>
  24 + <groupId>jakarta.validation</groupId>
  25 + <artifactId>jakarta.validation-api</artifactId>
  26 + </dependency>
  27 + <!-- Swagger3依赖 -->
  28 + <dependency>
  29 + <groupId>io.springfox</groupId>
  30 + <artifactId>springfox-boot-starter</artifactId>
  31 + <version>${swagger.version}</version>
  32 + <exclusions>
  33 + <exclusion>
  34 + <groupId>io.swagger</groupId>
  35 + <artifactId>swagger-models</artifactId>
  36 + </exclusion>
  37 + </exclusions>
  38 + </dependency>
  39 + </dependencies>
  40 +</project>
1 -package com.zhonglai.luhui.mqtt.comm.dto.iot; 1 +package com.ruoyi.system.domain;
2 2
3 -import io.swagger.annotations.ApiModel;  
4 -import io.swagger.annotations.ApiModelProperty;  
5 import org.apache.commons.lang3.builder.ToStringBuilder; 3 import org.apache.commons.lang3.builder.ToStringBuilder;
6 import org.apache.commons.lang3.builder.ToStringStyle; 4 import org.apache.commons.lang3.builder.ToStringStyle;
  5 +import io.swagger.annotations.ApiModel;
  6 +import io.swagger.annotations.ApiModelProperty;
7 7
8 -import java.util.List;  
9 -import java.util.Map; 8 +import java.io.Serializable;
10 9
11 /** 10 /**
12 * 主机/网关对象 iot_device 11 * 主机/网关对象 iot_device
@@ -15,7 +14,7 @@ import java.util.Map; @@ -15,7 +14,7 @@ import java.util.Map;
15 * @date 2022-08-26 14 * @date 2022-08-26
16 */ 15 */
17 @ApiModel("主机/网关") 16 @ApiModel("主机/网关")
18 -public class IotDevice 17 +public class IotDevice implements Serializable
19 { 18 {
20 private static final long serialVersionUID = 1L; 19 private static final long serialVersionUID = 1L;
21 20
@@ -84,7 +83,7 @@ public class IotDevice @@ -84,7 +83,7 @@ public class IotDevice
84 private Integer rssi; 83 private Integer rssi;
85 84
86 /** 设备状态(1-未激活,2-禁用,3-在线,4-离线) */ 85 /** 设备状态(1-未激活,2-禁用,3-在线,4-离线) */
87 - @ApiModelProperty("设备状态(1-未激活,2-禁用,3-在线,4-离线)") 86 + @ApiModelProperty("设备状态(1-未激活,2-禁用,3-在线,4-离线,5-锁定)")
88 private Integer status; 87 private Integer status;
89 88
90 /** 设备摘要,格式[{"name":"device"},{"chip":"esp8266"}] */ 89 /** 设备摘要,格式[{"name":"device"},{"chip":"esp8266"}] */
@@ -103,23 +102,41 @@ public class IotDevice @@ -103,23 +102,41 @@ public class IotDevice
103 @ApiModelProperty("更新时间") 102 @ApiModelProperty("更新时间")
104 private Integer update_time; 103 private Integer update_time;
105 104
106 - /** 用户id */  
107 - @ApiModelProperty("用户id")  
108 - private Integer user_id; 105 + @ApiModelProperty("产品id")
  106 + private Integer product_id;
  107 +
  108 + @ApiModelProperty("mqtt用户名/设备类型")
  109 + private String mqtt_username;
109 110
110 @ApiModelProperty("负载类型(String,Json,Bite16,Bite32)") 111 @ApiModelProperty("负载类型(String,Json,Bite16,Bite32)")
111 private String payload_type; 112 private String payload_type;
112 - @ApiModelProperty("payload 协议模型")  
113 - private String business_model; //payload 协议模型  
114 113
115 - public String getBusiness_model() {  
116 - return business_model; 114 + @ApiModelProperty("物模型配置")
  115 + private String things_model_config; //payload 协议模型
  116 +
  117 + @ApiModelProperty("监听服务器的ip")
  118 + private String listen_service_ip;
  119 +
  120 + @ApiModelProperty("描述")
  121 + private String remark;
  122 +
  123 + public String getListen_service_ip() {
  124 + return listen_service_ip;
  125 + }
  126 +
  127 + public void setListen_service_ip(String listen_service_ip) {
  128 + this.listen_service_ip = listen_service_ip;
117 } 129 }
118 130
119 - public void setBusiness_model(String business_model) {  
120 - this.business_model = business_model; 131 + public String getThings_model_config() {
  132 + return things_model_config;
121 } 133 }
122 134
  135 + public void setThings_model_config(String things_model_config) {
  136 + this.things_model_config = things_model_config;
  137 + }
  138 +
  139 +
123 public String getPayload_type() { 140 public String getPayload_type() {
124 return payload_type; 141 return payload_type;
125 } 142 }
@@ -317,40 +334,29 @@ public class IotDevice @@ -317,40 +334,29 @@ public class IotDevice
317 { 334 {
318 return update_time; 335 return update_time;
319 } 336 }
320 - public void setUser_id(Integer user_id)  
321 - {  
322 - this.user_id = user_id;  
323 - }  
324 -  
325 - public Integer getUser_id()  
326 - {  
327 - return user_id;  
328 - }  
329 -  
330 - public String toString() {  
331 - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)  
332 - .append("active_time", getActive_time())  
333 - .append("client_id", getClient_id())  
334 - .append("completion_auth", getCompletion_auth())  
335 - .append("create_by", getCreate_by())  
336 - .append("create_time", getCreate_time())  
337 - .append("del_flag", getDel_flag())  
338 - .append("firmware_version", getFirmware_version())  
339 - .append("img_url", getImg_url())  
340 - .append("is_shadow", getIs_shadow())  
341 - .append("latitude", getLatitude())  
342 - .append("location_way", getLocation_way())  
343 - .append("longitude", getLongitude())  
344 - .append("name", getName())  
345 - .append("network_address", getNetwork_address())  
346 - .append("network_ip", getNetwork_ip())  
347 - .append("rssi", getRssi())  
348 - .append("status", getStatus())  
349 - .append("summary", getSummary())  
350 - .append("things_model_value", getThings_model_value())  
351 - .append("update_by", getUpdate_by())  
352 - .append("update_time", getUpdate_time())  
353 - .append("user_id", getUser_id())  
354 - .toString(); 337 +
  338 + public Integer getProduct_id() {
  339 + return product_id;
  340 + }
  341 +
  342 + public void setProduct_id(Integer product_id) {
  343 + this.product_id = product_id;
  344 + }
  345 +
  346 + public String getMqtt_username() {
  347 + return mqtt_username;
  348 + }
  349 +
  350 + public void setMqtt_username(String mqtt_username) {
  351 + this.mqtt_username = mqtt_username;
  352 + }
  353 +
  354 + public String getRemark() {
  355 + return remark;
355 } 356 }
  357 +
  358 + public void setRemark(String remark) {
  359 + this.remark = remark;
  360 + }
  361 +
356 } 362 }
1 package com.ruoyi.system.domain; 1 package com.ruoyi.system.domain;
2 2
  3 +import com.ruoyi.system.domain.tool.BaseEntity;
3 import org.apache.commons.lang3.builder.ToStringBuilder; 4 import org.apache.commons.lang3.builder.ToStringBuilder;
4 import org.apache.commons.lang3.builder.ToStringStyle; 5 import org.apache.commons.lang3.builder.ToStringStyle;
5 -import com.ruoyi.common.annotation.Excel;  
6 -import com.ruoyi.common.core.domain.BaseEntity;  
7 import io.swagger.annotations.ApiModel; 6 import io.swagger.annotations.ApiModel;
8 import io.swagger.annotations.ApiModelProperty; 7 import io.swagger.annotations.ApiModelProperty;
9 8
  9 +import java.io.Serializable;
  10 +
10 /** 11 /**
11 * topic权限控制对象 iot_permission 12 * topic权限控制对象 iot_permission
12 * 13 *
@@ -14,7 +15,7 @@ import io.swagger.annotations.ApiModelProperty; @@ -14,7 +15,7 @@ import io.swagger.annotations.ApiModelProperty;
14 * @date 2022-08-26 15 * @date 2022-08-26
15 */ 16 */
16 @ApiModel("topic权限控制") 17 @ApiModel("topic权限控制")
17 -public class IotPermission extends BaseEntity 18 +public class IotPermission implements Serializable
18 { 19 {
19 private static final long serialVersionUID = 1L; 20 private static final long serialVersionUID = 1L;
20 21
1 -package com.zhonglai.luhui.mqtt.comm.dto.iot; 1 +package com.ruoyi.system.domain;
2 2
3 -import io.swagger.annotations.ApiModel;  
4 -import io.swagger.annotations.ApiModelProperty; 3 +import com.ruoyi.system.domain.tool.BaseEntity;
5 import org.apache.commons.lang3.builder.ToStringBuilder; 4 import org.apache.commons.lang3.builder.ToStringBuilder;
6 import org.apache.commons.lang3.builder.ToStringStyle; 5 import org.apache.commons.lang3.builder.ToStringStyle;
  6 +import io.swagger.annotations.ApiModel;
  7 +import io.swagger.annotations.ApiModelProperty;
  8 +
  9 +import java.io.Serializable;
7 10
8 /** 11 /**
9 - * 产品对象 iot_user 12 + * 产品对象 iot_product
10 * 13 *
11 * @author 钟来 14 * @author 钟来
12 * @date 2022-08-26 15 * @date 2022-08-26
13 */ 16 */
14 @ApiModel("产品") 17 @ApiModel("产品")
15 -public class IotUser 18 +public class IotProduct implements Serializable
16 { 19 {
17 private static final long serialVersionUID = 1L; 20 private static final long serialVersionUID = 1L;
18 21
@@ -34,7 +37,7 @@ public class IotUser @@ -34,7 +37,7 @@ public class IotUser
34 37
35 /** 密码 */ 38 /** 密码 */
36 @ApiModelProperty("密码") 39 @ApiModelProperty("密码")
37 - private String password; 40 + private String mqtt_password;
38 41
39 /** 角色id */ 42 /** 角色id */
40 @ApiModelProperty("角色id") 43 @ApiModelProperty("角色id")
@@ -42,7 +45,7 @@ public class IotUser @@ -42,7 +45,7 @@ public class IotUser
42 45
43 /** 盐 */ 46 /** 盐 */
44 @ApiModelProperty("盐") 47 @ApiModelProperty("盐")
45 - private String salt; 48 + private String mqtt_salt;
46 49
47 /** 是否使用(0否,1是) */ 50 /** 是否使用(0否,1是) */
48 @ApiModelProperty("是否使用(0否,1是)") 51 @ApiModelProperty("是否使用(0否,1是)")
@@ -50,7 +53,11 @@ public class IotUser @@ -50,7 +53,11 @@ public class IotUser
50 53
51 /** 用户名 */ 54 /** 用户名 */
52 @ApiModelProperty("用户名") 55 @ApiModelProperty("用户名")
53 - private String username; 56 + private String mqtt_username;
  57 +
  58 + @ApiModelProperty("产品名称")
  59 + private String product_name;
  60 +
54 61
55 public void setCreate_time(Integer create_time) 62 public void setCreate_time(Integer create_time)
56 { 63 {
@@ -88,16 +95,7 @@ public class IotUser @@ -88,16 +95,7 @@ public class IotUser
88 { 95 {
89 return open_encryption; 96 return open_encryption;
90 } 97 }
91 - public void setPassword(String password)  
92 - {  
93 - this.password = password;  
94 - }  
95 -  
96 - public String getPassword()  
97 - {  
98 - return password;  
99 - }  
100 - public void setRole_id(Integer role_id) 98 + public void setRole_id(Integer role_id)
101 { 99 {
102 this.role_id = role_id; 100 this.role_id = role_id;
103 } 101 }
@@ -106,16 +104,8 @@ public class IotUser @@ -106,16 +104,8 @@ public class IotUser
106 { 104 {
107 return role_id; 105 return role_id;
108 } 106 }
109 - public void setSalt(String salt)  
110 - {  
111 - this.salt = salt;  
112 - }  
113 107
114 - public String getSalt()  
115 - {  
116 - return salt;  
117 - }  
118 - public void setUsed(Integer used) 108 + public void setUsed(Integer used)
119 { 109 {
120 this.used = used; 110 this.used = used;
121 } 111 }
@@ -124,27 +114,52 @@ public class IotUser @@ -124,27 +114,52 @@ public class IotUser
124 { 114 {
125 return used; 115 return used;
126 } 116 }
127 - public void setUsername(String username)  
128 - {  
129 - this.username = username; 117 +
  118 + public String getMqtt_password() {
  119 + return mqtt_password;
130 } 120 }
131 121
132 - public String getUsername()  
133 - {  
134 - return username; 122 + public void setMqtt_password(String mqtt_password) {
  123 + this.mqtt_password = mqtt_password;
  124 + }
  125 +
  126 + public String getMqtt_salt() {
  127 + return mqtt_salt;
  128 + }
  129 +
  130 + public void setMqtt_salt(String mqtt_salt) {
  131 + this.mqtt_salt = mqtt_salt;
  132 + }
  133 +
  134 + public String getMqtt_username() {
  135 + return mqtt_username;
  136 + }
  137 +
  138 + public void setMqtt_username(String mqtt_username) {
  139 + this.mqtt_username = mqtt_username;
  140 + }
  141 +
  142 + public String getProduct_name() {
  143 + return product_name;
  144 + }
  145 +
  146 + public void setProduct_name(String product_name) {
  147 + this.product_name = product_name;
135 } 148 }
136 149
  150 + @Override
137 public String toString() { 151 public String toString() {
138 return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) 152 return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
139 .append("create_time", getCreate_time()) 153 .append("create_time", getCreate_time())
140 .append("encryption_type", getEncryption_type()) 154 .append("encryption_type", getEncryption_type())
141 .append("id", getId()) 155 .append("id", getId())
142 .append("open_encryption", getOpen_encryption()) 156 .append("open_encryption", getOpen_encryption())
143 - .append("password", getPassword()) 157 + .append("mqtt_password", getMqtt_password())
144 .append("role_id", getRole_id()) 158 .append("role_id", getRole_id())
145 - .append("salt", getSalt()) 159 + .append("mqtt_salt", getMqtt_salt())
146 .append("used", getUsed()) 160 .append("used", getUsed())
147 - .append("username", getUsername()) 161 + .append("mqtt_username", getMqtt_username())
  162 + .append("product_name", getProduct_name())
148 .toString(); 163 .toString();
149 } 164 }
150 } 165 }
1 package com.ruoyi.system.domain; 1 package com.ruoyi.system.domain;
2 2
  3 +import com.ruoyi.system.domain.tool.BaseEntity;
3 import org.apache.commons.lang3.builder.ToStringBuilder; 4 import org.apache.commons.lang3.builder.ToStringBuilder;
4 import org.apache.commons.lang3.builder.ToStringStyle; 5 import org.apache.commons.lang3.builder.ToStringStyle;
5 -import com.ruoyi.common.annotation.Excel;  
6 -import com.ruoyi.common.core.domain.BaseEntity;  
7 import io.swagger.annotations.ApiModel; 6 import io.swagger.annotations.ApiModel;
8 import io.swagger.annotations.ApiModelProperty; 7 import io.swagger.annotations.ApiModelProperty;
9 8
  9 +import java.io.Serializable;
  10 +
10 /** 11 /**
11 * 公司对象 iot_role 12 * 公司对象 iot_role
12 * 13 *
@@ -14,7 +15,7 @@ import io.swagger.annotations.ApiModelProperty; @@ -14,7 +15,7 @@ import io.swagger.annotations.ApiModelProperty;
14 * @date 2022-08-26 15 * @date 2022-08-26
15 */ 16 */
16 @ApiModel("公司") 17 @ApiModel("公司")
17 -public class IotRole extends BaseEntity 18 +public class IotRole implements Serializable
18 { 19 {
19 private static final long serialVersionUID = 1L; 20 private static final long serialVersionUID = 1L;
20 21
@@ -2,11 +2,11 @@ package com.ruoyi.system.domain; @@ -2,11 +2,11 @@ package com.ruoyi.system.domain;
2 2
3 import org.apache.commons.lang3.builder.ToStringBuilder; 3 import org.apache.commons.lang3.builder.ToStringBuilder;
4 import org.apache.commons.lang3.builder.ToStringStyle; 4 import org.apache.commons.lang3.builder.ToStringStyle;
5 -import com.ruoyi.common.annotation.Excel;  
6 -import com.ruoyi.common.core.domain.BaseEntity;  
7 import io.swagger.annotations.ApiModel; 5 import io.swagger.annotations.ApiModel;
8 import io.swagger.annotations.ApiModelProperty; 6 import io.swagger.annotations.ApiModelProperty;
9 7
  8 +import java.io.Serializable;
  9 +
10 /** 10 /**
11 * 终端对象 iot_terminal 11 * 终端对象 iot_terminal
12 * 12 *
@@ -14,7 +14,7 @@ import io.swagger.annotations.ApiModelProperty; @@ -14,7 +14,7 @@ import io.swagger.annotations.ApiModelProperty;
14 * @date 2022-08-26 14 * @date 2022-08-26
15 */ 15 */
16 @ApiModel("终端") 16 @ApiModel("终端")
17 -public class IotTerminal extends BaseEntity 17 +public class IotTerminal implements Serializable
18 { 18 {
19 private static final long serialVersionUID = 1L; 19 private static final long serialVersionUID = 1L;
20 20
@@ -37,7 +37,38 @@ public class IotTerminal extends BaseEntity @@ -37,7 +37,38 @@ public class IotTerminal extends BaseEntity
37 /** 更新时间 */ 37 /** 更新时间 */
38 @ApiModelProperty("更新时间") 38 @ApiModelProperty("更新时间")
39 private Integer update_time; 39 private Integer update_time;
  40 + @ApiModelProperty("物模型配置")
  41 + private String things_model_config; //payload 协议模型
  42 +
  43 + @ApiModelProperty("产品id")
  44 + private Integer product_id;
  45 +
  46 + @ApiModelProperty("产品名称")
  47 + private String mqtt_username;
  48 +
  49 + public Integer getProduct_id() {
  50 + return product_id;
  51 + }
  52 +
  53 + public void setProduct_id(Integer product_id) {
  54 + this.product_id = product_id;
  55 + }
40 56
  57 + public String getMqtt_username() {
  58 + return mqtt_username;
  59 + }
  60 +
  61 + public void setMqtt_username(String mqtt_username) {
  62 + this.mqtt_username = mqtt_username;
  63 + }
  64 +
  65 + public String getThings_model_config() {
  66 + return things_model_config;
  67 + }
  68 +
  69 + public void setThings_model_config(String things_model_config) {
  70 + this.things_model_config = things_model_config;
  71 + }
41 public void setDevice_id(String device_id) 72 public void setDevice_id(String device_id)
42 { 73 {
43 this.device_id = device_id; 74 this.device_id = device_id;
@@ -92,6 +123,8 @@ public class IotTerminal extends BaseEntity @@ -92,6 +123,8 @@ public class IotTerminal extends BaseEntity
92 .append("name", getName()) 123 .append("name", getName())
93 .append("things_model_value", getThings_model_value()) 124 .append("things_model_value", getThings_model_value())
94 .append("update_time", getUpdate_time()) 125 .append("update_time", getUpdate_time())
  126 + .append("product_id", getProduct_id())
  127 + .append("mqtt_username", getMqtt_username())
95 .toString(); 128 .toString();
96 } 129 }
97 } 130 }
1 package com.ruoyi.system.domain; 1 package com.ruoyi.system.domain;
2 2
  3 +import com.ruoyi.system.domain.tool.BaseEntity;
3 import org.apache.commons.lang3.builder.ToStringBuilder; 4 import org.apache.commons.lang3.builder.ToStringBuilder;
4 import org.apache.commons.lang3.builder.ToStringStyle; 5 import org.apache.commons.lang3.builder.ToStringStyle;
5 -import com.ruoyi.common.annotation.Excel;  
6 -import com.ruoyi.common.core.domain.BaseEntity;  
7 import io.swagger.annotations.ApiModel; 6 import io.swagger.annotations.ApiModel;
8 import io.swagger.annotations.ApiModelProperty; 7 import io.swagger.annotations.ApiModelProperty;
9 8
  9 +import java.io.Serializable;
  10 +
10 /** 11 /**
11 * 物模型模板对象 iot_things_model 12 * 物模型模板对象 iot_things_model
12 * 13 *
@@ -14,7 +15,7 @@ import io.swagger.annotations.ApiModelProperty; @@ -14,7 +15,7 @@ import io.swagger.annotations.ApiModelProperty;
14 * @date 2022-08-26 15 * @date 2022-08-26
15 */ 16 */
16 @ApiModel("物模型模板") 17 @ApiModel("物模型模板")
17 -public class IotThingsModel extends BaseEntity 18 +public class IotThingsModel implements Serializable
18 { 19 {
19 private static final long serialVersionUID = 1L; 20 private static final long serialVersionUID = 1L;
20 21
@@ -74,11 +75,70 @@ public class IotThingsModel extends BaseEntity @@ -74,11 +75,70 @@ public class IotThingsModel extends BaseEntity
74 @ApiModelProperty("更新时间") 75 @ApiModelProperty("更新时间")
75 private java.util.Date update_time; 76 private java.util.Date update_time;
76 77
77 - /** 用户id */  
78 - @ApiModelProperty("用户id")  
79 - private Integer user_id; 78 + @ApiModelProperty("mqtt用户名/设备类型")
  79 + private String mqtt_username;
  80 +
  81 + @ApiModelProperty("产品id")
  82 + private Integer product_id;
  83 +
  84 + @ApiModelProperty("是否配置属性(0否,1是)")
  85 + private Integer is_config;
  86 +
  87 + @ApiModelProperty("展示类型")
  88 + private String view_type;
  89 +
  90 + @ApiModelProperty("对应配置属性名称集合(英文逗号分割)")
  91 + private String config_names;
  92 +
  93 + @ApiModelProperty("归属(0主键,1终端)")
  94 + private String ascription;
  95 +
  96 + /** 数据定义 */
  97 + @ApiModelProperty("数据定义")
  98 + private String remark;
  99 +
  100 + public String getAscription() {
  101 + return ascription;
  102 + }
  103 +
  104 + public void setAscription(String ascription) {
  105 + this.ascription = ascription;
  106 + }
  107 +
  108 + public String getRemark() {
  109 + return remark;
  110 + }
  111 +
  112 + public void setRemark(String remark) {
  113 + this.remark = remark;
  114 + }
  115 +
  116 + public String getView_type() {
  117 + return view_type;
  118 + }
80 119
81 - public void setCreate_by(String create_by) 120 + public void setView_type(String view_type) {
  121 + this.view_type = view_type;
  122 + }
  123 +
  124 + public String getConfig_names() {
  125 + return config_names;
  126 + }
  127 +
  128 + public void setConfig_names(String config_names) {
  129 + this.config_names = config_names;
  130 + }
  131 +
  132 + public Integer getIs_config() {
  133 + return is_config;
  134 + }
  135 +
  136 + public void setIs_config(Integer is_config) {
  137 + this.is_config = is_config;
  138 + }
  139 +
  140 +
  141 + public void setCreate_by(String create_by)
82 { 142 {
83 this.create_by = create_by; 143 this.create_by = create_by;
84 } 144 }
@@ -204,14 +264,21 @@ public class IotThingsModel extends BaseEntity @@ -204,14 +264,21 @@ public class IotThingsModel extends BaseEntity
204 { 264 {
205 return update_time; 265 return update_time;
206 } 266 }
207 - public void setUser_id(Integer user_id)  
208 - {  
209 - this.user_id = user_id; 267 +
  268 + public String getMqtt_username() {
  269 + return mqtt_username;
210 } 270 }
211 271
212 - public Integer getUser_id()  
213 - {  
214 - return user_id; 272 + public void setMqtt_username(String mqtt_username) {
  273 + this.mqtt_username = mqtt_username;
  274 + }
  275 +
  276 + public Integer getProduct_id() {
  277 + return product_id;
  278 + }
  279 +
  280 + public void setProduct_id(Integer product_id) {
  281 + this.product_id = product_id;
215 } 282 }
216 283
217 @Override 284 @Override
@@ -227,12 +294,12 @@ public class IotThingsModel extends BaseEntity @@ -227,12 +294,12 @@ public class IotThingsModel extends BaseEntity
227 .append("is_top", getIs_top()) 294 .append("is_top", getIs_top())
228 .append("model_id", getModel_id()) 295 .append("model_id", getModel_id())
229 .append("model_name", getModel_name()) 296 .append("model_name", getModel_name())
230 - .append("remark", getRemark())  
231 .append("specs", getSpecs()) 297 .append("specs", getSpecs())
232 .append("type", getType()) 298 .append("type", getType())
233 .append("update_by", getUpdate_by()) 299 .append("update_by", getUpdate_by())
234 .append("update_time", getUpdate_time()) 300 .append("update_time", getUpdate_time())
235 - .append("user_id", getUser_id()) 301 + .append("product_id", getProduct_id())
  302 + .append("mqtt_username", getMqtt_username())
236 .toString(); 303 .toString();
237 } 304 }
238 } 305 }
1 -package com.zhonglai.luhui.mqtt.comm.dto.iot; 1 +package com.ruoyi.system.domain;
2 2
  3 +import com.ruoyi.system.domain.tool.BaseEntity;
3 import io.swagger.annotations.ApiModel; 4 import io.swagger.annotations.ApiModel;
4 import io.swagger.annotations.ApiModelProperty; 5 import io.swagger.annotations.ApiModelProperty;
5 import org.apache.commons.lang3.builder.ToStringBuilder; 6 import org.apache.commons.lang3.builder.ToStringBuilder;
6 import org.apache.commons.lang3.builder.ToStringStyle; 7 import org.apache.commons.lang3.builder.ToStringStyle;
7 8
8 /** 9 /**
9 - * 物模型模板对象 iot_things_model 10 + * 物模型模板对象 iot_things_model_template
10 * 11 *
11 * @author 钟来 12 * @author 钟来
12 - * @date 2022-08-26 13 + * @date 2022-10-24
13 */ 14 */
14 @ApiModel("物模型模板") 15 @ApiModel("物模型模板")
15 -public class IotThingsModel 16 +public class IotThingsModelTemplate extends BaseEntity
16 { 17 {
17 private static final long serialVersionUID = 1L; 18 private static final long serialVersionUID = 1L;
18 19
  20 + /** 归属(0主键,1终端) */
  21 + @ApiModelProperty("归属(0主键,1终端)")
  22 + private Integer ascription;
  23 +
  24 + /** 对应配置属性名称集合(英文逗号分割) */
  25 + @ApiModelProperty("对应配置属性名称集合(英文逗号分割)")
  26 + private String config_names;
  27 +
19 /** 创建者 */ 28 /** 创建者 */
20 @ApiModelProperty("创建者") 29 @ApiModelProperty("创建者")
21 private String create_by; 30 private String create_by;
@@ -36,6 +45,10 @@ public class IotThingsModel @@ -36,6 +45,10 @@ public class IotThingsModel
36 @ApiModelProperty("标识符,用户下唯一") 45 @ApiModelProperty("标识符,用户下唯一")
37 private String identifier; 46 private String identifier;
38 47
  48 + /** 是否配置属性(0否,1是) */
  49 + @ApiModelProperty("是否配置属性(0否,1是)")
  50 + private Integer is_config;
  51 +
39 /** 是否实时监测(0-否,1-是) */ 52 /** 是否实时监测(0-否,1-是) */
40 @ApiModelProperty("是否实时监测(0-否,1-是)") 53 @ApiModelProperty("是否实时监测(0-否,1-是)")
41 private Integer is_monitor; 54 private Integer is_monitor;
@@ -56,6 +69,14 @@ public class IotThingsModel @@ -56,6 +69,14 @@ public class IotThingsModel
56 @ApiModelProperty("物模型名称") 69 @ApiModelProperty("物模型名称")
57 private String model_name; 70 private String model_name;
58 71
  72 + /** mqtt用户名/设备类型 */
  73 + @ApiModelProperty("mqtt用户名/设备类型")
  74 + private String mqtt_username;
  75 +
  76 + /** 产品id */
  77 + @ApiModelProperty("产品id")
  78 + private Integer product_id;
  79 +
59 /** 数据定义 */ 80 /** 数据定义 */
60 @ApiModelProperty("数据定义") 81 @ApiModelProperty("数据定义")
61 private String specs; 82 private String specs;
@@ -72,23 +93,29 @@ public class IotThingsModel @@ -72,23 +93,29 @@ public class IotThingsModel
72 @ApiModelProperty("更新时间") 93 @ApiModelProperty("更新时间")
73 private java.util.Date update_time; 94 private java.util.Date update_time;
74 95
75 - /** 用户id */  
76 - @ApiModelProperty("用户id")  
77 - private Integer user_id;  
78 -  
79 - /** 用户id */  
80 - @ApiModelProperty("用户名称")  
81 - private String user_name; 96 + /** 页面展示类型 */
  97 + @ApiModelProperty("页面展示类型")
  98 + private String view_type;
82 99
83 - public String getUser_name() {  
84 - return user_name; 100 + public void setAscription(Integer ascription)
  101 + {
  102 + this.ascription = ascription;
85 } 103 }
86 104
87 - public void setUser_name(String user_name) {  
88 - this.user_name = user_name; 105 + public Integer getAscription()
  106 + {
  107 + return ascription;
  108 + }
  109 + public void setConfig_names(String config_names)
  110 + {
  111 + this.config_names = config_names;
89 } 112 }
90 113
91 - public void setCreate_by(String create_by) 114 + public String getConfig_names()
  115 + {
  116 + return config_names;
  117 + }
  118 + public void setCreate_by(String create_by)
92 { 119 {
93 this.create_by = create_by; 120 this.create_by = create_by;
94 } 121 }
@@ -133,6 +160,15 @@ public class IotThingsModel @@ -133,6 +160,15 @@ public class IotThingsModel
133 { 160 {
134 return identifier; 161 return identifier;
135 } 162 }
  163 + public void setIs_config(Integer is_config)
  164 + {
  165 + this.is_config = is_config;
  166 + }
  167 +
  168 + public Integer getIs_config()
  169 + {
  170 + return is_config;
  171 + }
136 public void setIs_monitor(Integer is_monitor) 172 public void setIs_monitor(Integer is_monitor)
137 { 173 {
138 this.is_monitor = is_monitor; 174 this.is_monitor = is_monitor;
@@ -178,6 +214,24 @@ public class IotThingsModel @@ -178,6 +214,24 @@ public class IotThingsModel
178 { 214 {
179 return model_name; 215 return model_name;
180 } 216 }
  217 + public void setMqtt_username(String mqtt_username)
  218 + {
  219 + this.mqtt_username = mqtt_username;
  220 + }
  221 +
  222 + public String getMqtt_username()
  223 + {
  224 + return mqtt_username;
  225 + }
  226 + public void setProduct_id(Integer product_id)
  227 + {
  228 + this.product_id = product_id;
  229 + }
  230 +
  231 + public Integer getProduct_id()
  232 + {
  233 + return product_id;
  234 + }
181 public void setSpecs(String specs) 235 public void setSpecs(String specs)
182 { 236 {
183 this.specs = specs; 237 this.specs = specs;
@@ -214,33 +268,40 @@ public class IotThingsModel @@ -214,33 +268,40 @@ public class IotThingsModel
214 { 268 {
215 return update_time; 269 return update_time;
216 } 270 }
217 - public void setUser_id(Integer user_id) 271 + public void setView_type(String view_type)
218 { 272 {
219 - this.user_id = user_id; 273 + this.view_type = view_type;
220 } 274 }
221 275
222 - public Integer getUser_id() 276 + public String getView_type()
223 { 277 {
224 - return user_id; 278 + return view_type;
225 } 279 }
226 280
  281 + @Override
227 public String toString() { 282 public String toString() {
228 - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) 283 + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
  284 + .append("ascription", getAscription())
  285 + .append("config_names", getConfig_names())
229 .append("create_by", getCreate_by()) 286 .append("create_by", getCreate_by())
230 .append("create_time", getCreate_time()) 287 .append("create_time", getCreate_time())
231 .append("data_type", getData_type()) 288 .append("data_type", getData_type())
232 .append("del_flag", getDel_flag()) 289 .append("del_flag", getDel_flag())
233 .append("identifier", getIdentifier()) 290 .append("identifier", getIdentifier())
  291 + .append("is_config", getIs_config())
234 .append("is_monitor", getIs_monitor()) 292 .append("is_monitor", getIs_monitor())
235 .append("is_save_log", getIs_save_log()) 293 .append("is_save_log", getIs_save_log())
236 .append("is_top", getIs_top()) 294 .append("is_top", getIs_top())
237 .append("model_id", getModel_id()) 295 .append("model_id", getModel_id())
238 .append("model_name", getModel_name()) 296 .append("model_name", getModel_name())
  297 + .append("mqtt_username", getMqtt_username())
  298 + .append("product_id", getProduct_id())
  299 + .append("remark", getRemark())
239 .append("specs", getSpecs()) 300 .append("specs", getSpecs())
240 .append("type", getType()) 301 .append("type", getType())
241 .append("update_by", getUpdate_by()) 302 .append("update_by", getUpdate_by())
242 .append("update_time", getUpdate_time()) 303 .append("update_time", getUpdate_time())
243 - .append("user_id", getUser_id()) 304 + .append("view_type", getView_type())
244 .toString(); 305 .toString();
245 } 306 }
246 } 307 }
1 package com.ruoyi.system.domain; 1 package com.ruoyi.system.domain;
2 2
3 -import com.ruoyi.common.annotation.Excel;  
4 -import com.ruoyi.common.annotation.Excel.ColumnType;  
5 -import com.ruoyi.common.core.domain.BaseEntity; 3 +import com.ruoyi.system.domain.tool.BaseEntity;
  4 +import com.ruoyi.system.domain.tool.Excel;
6 import io.swagger.annotations.ApiModel; 5 import io.swagger.annotations.ApiModel;
7 import io.swagger.annotations.ApiModelProperty; 6 import io.swagger.annotations.ApiModelProperty;
8 import org.apache.commons.lang3.builder.ToStringBuilder; 7 import org.apache.commons.lang3.builder.ToStringBuilder;
@@ -23,7 +22,7 @@ public class SysConfig extends BaseEntity @@ -23,7 +22,7 @@ public class SysConfig extends BaseEntity
23 22
24 /** 参数主键 */ 23 /** 参数主键 */
25 @ApiModelProperty("参数主键") 24 @ApiModelProperty("参数主键")
26 - @Excel(name = "参数主键", cellType = ColumnType.NUMERIC) 25 + @Excel(name = "参数主键", cellType = Excel.ColumnType.NUMERIC)
27 private Long configId; 26 private Long configId;
28 27
29 /** 参数名称 */ 28 /** 参数名称 */
1 package com.ruoyi.system.domain; 1 package com.ruoyi.system.domain;
2 2
3 import com.fasterxml.jackson.annotation.JsonFormat; 3 import com.fasterxml.jackson.annotation.JsonFormat;
4 -import com.ruoyi.common.annotation.Excel;  
5 -import com.ruoyi.common.annotation.Excel.ColumnType;  
6 -import com.ruoyi.common.core.domain.BaseEntity; 4 +import com.ruoyi.system.domain.tool.BaseEntity;
  5 +import com.ruoyi.system.domain.tool.Excel;
7 6
8 import java.util.Date; 7 import java.util.Date;
9 8
@@ -17,7 +16,7 @@ public class SysLogininfor extends BaseEntity @@ -17,7 +16,7 @@ public class SysLogininfor extends BaseEntity
17 private static final long serialVersionUID = 1L; 16 private static final long serialVersionUID = 1L;
18 17
19 /** ID */ 18 /** ID */
20 - @Excel(name = "序号", cellType = ColumnType.NUMERIC) 19 + @Excel(name = "序号", cellType = Excel.ColumnType.NUMERIC)
21 private Long infoId; 20 private Long infoId;
22 21
23 /** 用户账号 */ 22 /** 用户账号 */
1 package com.ruoyi.system.domain; 1 package com.ruoyi.system.domain;
2 2
3 -import com.ruoyi.common.core.domain.BaseEntity;  
4 -import com.ruoyi.common.xss.Xss; 3 +import com.ruoyi.system.domain.tool.BaseEntity;
  4 +import com.ruoyi.system.domain.tool.Xss;
5 import io.swagger.annotations.ApiModel; 5 import io.swagger.annotations.ApiModel;
6 import io.swagger.annotations.ApiModelProperty; 6 import io.swagger.annotations.ApiModelProperty;
7 import org.apache.commons.lang3.builder.ToStringBuilder; 7 import org.apache.commons.lang3.builder.ToStringBuilder;
1 package com.ruoyi.system.domain; 1 package com.ruoyi.system.domain;
2 2
3 import com.fasterxml.jackson.annotation.JsonFormat; 3 import com.fasterxml.jackson.annotation.JsonFormat;
4 -import com.ruoyi.common.annotation.Excel;  
5 -import com.ruoyi.common.annotation.Excel.ColumnType;  
6 -import com.ruoyi.common.core.domain.BaseEntity; 4 +import com.ruoyi.system.domain.tool.BaseEntity;
  5 +import com.ruoyi.system.domain.tool.Excel;
7 import io.swagger.annotations.ApiModel; 6 import io.swagger.annotations.ApiModel;
8 import io.swagger.annotations.ApiModelProperty; 7 import io.swagger.annotations.ApiModelProperty;
9 8
@@ -21,7 +20,7 @@ public class SysOperLog extends BaseEntity @@ -21,7 +20,7 @@ public class SysOperLog extends BaseEntity
21 20
22 /** 日志主键 */ 21 /** 日志主键 */
23 @ApiModelProperty("操作序号") 22 @ApiModelProperty("操作序号")
24 - @Excel(name = "操作序号", cellType = ColumnType.NUMERIC) 23 + @Excel(name = "操作序号", cellType = Excel.ColumnType.NUMERIC)
25 private Long operId; 24 private Long operId;
26 25
27 /** 操作模块 */ 26 /** 操作模块 */
1 package com.ruoyi.system.domain; 1 package com.ruoyi.system.domain;
2 2
3 -import com.ruoyi.common.annotation.Excel;  
4 -import com.ruoyi.common.annotation.Excel.ColumnType;  
5 -import com.ruoyi.common.core.domain.BaseEntity; 3 +import com.ruoyi.system.domain.tool.BaseEntity;
  4 +import com.ruoyi.system.domain.tool.Excel;
6 import io.swagger.annotations.ApiModel; 5 import io.swagger.annotations.ApiModel;
7 import io.swagger.annotations.ApiModelProperty; 6 import io.swagger.annotations.ApiModelProperty;
8 import org.apache.commons.lang3.builder.ToStringBuilder; 7 import org.apache.commons.lang3.builder.ToStringBuilder;
@@ -23,7 +22,7 @@ public class SysPost extends BaseEntity @@ -23,7 +22,7 @@ public class SysPost extends BaseEntity
23 22
24 /** 岗位序号 */ 23 /** 岗位序号 */
25 @ApiModelProperty("岗位序号") 24 @ApiModelProperty("岗位序号")
26 - @Excel(name = "岗位序号", cellType = ColumnType.NUMERIC) 25 + @Excel(name = "岗位序号", cellType = Excel.ColumnType.NUMERIC)
27 private Long postId; 26 private Long postId;
28 27
29 /** 岗位编码 */ 28 /** 岗位编码 */
1 -package com.ruoyi.common.core.domain; 1 +package com.ruoyi.system.domain.tool;
2 2
3 import com.fasterxml.jackson.annotation.JsonFormat; 3 import com.fasterxml.jackson.annotation.JsonFormat;
4 import org.springframework.data.annotation.Transient; 4 import org.springframework.data.annotation.Transient;
1 -package com.ruoyi.common.annotation;  
2 -  
3 -import com.ruoyi.common.utils.poi.ExcelHandlerAdapter; 1 +package com.ruoyi.system.domain.tool;
4 2
5 import java.lang.annotation.ElementType; 3 import java.lang.annotation.ElementType;
6 import java.lang.annotation.Retention; 4 import java.lang.annotation.Retention;
1 -package com.ruoyi.common.utils.poi; 1 +package com.ruoyi.system.domain.tool;
2 2
3 /** 3 /**
4 * Excel数据格式处理适配器 4 * Excel数据格式处理适配器
1 -package com.ruoyi.common.xss; 1 +package com.ruoyi.system.domain.tool;
2 2
3 import javax.validation.Constraint; 3 import javax.validation.Constraint;
4 import javax.validation.Payload; 4 import javax.validation.Payload;
1 -package com.ruoyi.common.xss; 1 +package com.ruoyi.system.domain.tool;
2 2
3 -import com.ruoyi.common.utils.StringUtils; 3 +
  4 +import org.apache.commons.lang3.StringUtils;
4 5
5 import javax.validation.ConstraintValidator; 6 import javax.validation.ConstraintValidator;
6 import javax.validation.ConstraintValidatorContext; 7 import javax.validation.ConstraintValidatorContext;
1 package com.ruoyi.system.domain.vo; 1 package com.ruoyi.system.domain.vo;
2 2
3 -import com.ruoyi.common.utils.StringUtils; 3 +
  4 +import org.apache.commons.lang3.StringUtils;
4 5
5 /** 6 /**
6 * 路由显示信息 7 * 路由显示信息
@@ -58,7 +59,7 @@ public class MetaVo @@ -58,7 +59,7 @@ public class MetaVo
58 this.title = title; 59 this.title = title;
59 this.icon = icon; 60 this.icon = icon;
60 this.noCache = noCache; 61 this.noCache = noCache;
61 - if (StringUtils.ishttp(link)) 62 + if (StringUtils.startsWithAny(link, "http://", "https://"))
62 { 63 {
63 this.link = link; 64 this.link = link;
64 } 65 }
@@ -12,11 +12,42 @@ @@ -12,11 +12,42 @@
12 <artifactId>lh-mqtt-service</artifactId> 12 <artifactId>lh-mqtt-service</artifactId>
13 13
14 <dependencies> 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>
15 <!-- SpringBoot Web容器 --> 21 <!-- SpringBoot Web容器 -->
16 <dependency> 22 <dependency>
17 <groupId>org.springframework.boot</groupId> 23 <groupId>org.springframework.boot</groupId>
18 <artifactId>spring-boot-starter-web</artifactId> 24 <artifactId>spring-boot-starter-web</artifactId>
19 </dependency> 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 + <!-- yml解析器 -->
  37 + <dependency>
  38 + <groupId>org.yaml</groupId>
  39 + <artifactId>snakeyaml</artifactId>
  40 + </dependency>
  41 + <!-- servlet包 -->
  42 + <dependency>
  43 + <groupId>javax.servlet</groupId>
  44 + <artifactId>javax.servlet-api</artifactId>
  45 + </dependency>
  46 + <dependency>
  47 + <groupId>org.apache.commons</groupId>
  48 + <artifactId>commons-text</artifactId>
  49 + </dependency>
  50 +
20 <!-- 文档 --> 51 <!-- 文档 -->
21 <dependency> 52 <dependency>
22 <groupId>io.springfox</groupId> 53 <groupId>io.springfox</groupId>
@@ -58,11 +89,6 @@ @@ -58,11 +89,6 @@
58 </dependency> 89 </dependency>
59 90
60 <dependency> 91 <dependency>
61 - <groupId>org.springframework.boot</groupId>  
62 - <artifactId>spring-boot-starter-tomcat</artifactId>  
63 - <scope>provided</scope>  
64 - </dependency>  
65 - <dependency>  
66 <groupId>net.jodah</groupId> 92 <groupId>net.jodah</groupId>
67 <artifactId>expiringmap</artifactId> 93 <artifactId>expiringmap</artifactId>
68 </dependency> 94 </dependency>
@@ -126,6 +152,11 @@ @@ -126,6 +152,11 @@
126 <artifactId>okhttp</artifactId> 152 <artifactId>okhttp</artifactId>
127 </dependency> 153 </dependency>
128 154
  155 + <!-- 通用工具-->
  156 + <dependency>
  157 + <groupId>com.zhonglai.luhui</groupId>
  158 + <artifactId>lh-domain</artifactId>
  159 + </dependency>
129 160
130 </dependencies> 161 </dependencies>
131 162
@@ -6,8 +6,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -6,8 +6,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
6 import org.springframework.boot.builder.SpringApplicationBuilder; 6 import org.springframework.boot.builder.SpringApplicationBuilder;
7 import org.springframework.context.annotation.ComponentScan; 7 import org.springframework.context.annotation.ComponentScan;
8 8
9 -import javax.servlet.Filter;  
10 -  
11 9
12 @ComponentScan(basePackages = { 10 @ComponentScan(basePackages = {
13 "com.zhonglai.luhui.mqtt.comm.config", 11 "com.zhonglai.luhui.mqtt.comm.config",
@@ -14,13 +14,23 @@ import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; @@ -14,13 +14,23 @@ import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
14 import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; 14 import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
15 import org.springframework.data.redis.serializer.StringRedisSerializer; 15 import org.springframework.data.redis.serializer.StringRedisSerializer;
16 16
  17 +import javax.annotation.PostConstruct;
  18 +
17 @Configuration 19 @Configuration
18 public class RedisConfig { 20 public class RedisConfig {
19 - @Value("${sys.redis.field:#{'luhui:mqttservice:device:'}") 21 + @Value("${sys.redis.field}")
  22 + public String sysRedisField ; //域
20 public static String FIELD ; //域 23 public static String FIELD ; //域
21 public static String DEVICE = "device:"; //存放网关数据 24 public static String DEVICE = "device:"; //存放网关数据
22 public static String THINGS_MODEL = "things_model:"; //存放数据模型 25 public static String THINGS_MODEL = "things_model:"; //存放数据模型
23 public static String TERMINAL = "terminal:"; //存放终端数据 26 public static String TERMINAL = "terminal:"; //存放终端数据
  27 + public static String LOCK = "lock:"; //存放设备锁
  28 +
  29 + @PostConstruct
  30 + public void init()
  31 + {
  32 + RedisConfig.FIELD = sysRedisField;
  33 + }
24 34
25 35
26 @Bean 36 @Bean
1 package com.zhonglai.luhui.mqtt.comm.config; 1 package com.zhonglai.luhui.mqtt.comm.config;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 -import com.zhonglai.luhui.mqtt.comm.dto.iot.IotThingsModel;  
5 -import com.zhonglai.luhui.mqtt.comm.factory.Topic;  
6 -import com.zhonglai.luhui.mqtt.comm.service.DataModeAnalysisService;  
7 import com.zhonglai.luhui.mqtt.comm.util.http.HttpUtils; 4 import com.zhonglai.luhui.mqtt.comm.util.http.HttpUtils;
8 -import org.apache.commons.lang3.StringUtils;  
9 import org.slf4j.Logger; 5 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory; 6 import org.slf4j.LoggerFactory;
11 -import org.springframework.beans.factory.annotation.Autowired;  
12 import org.springframework.beans.factory.annotation.Value; 7 import org.springframework.beans.factory.annotation.Value;
13 import org.springframework.context.annotation.Configuration; 8 import org.springframework.context.annotation.Configuration;
14 9
15 import javax.annotation.PostConstruct; 10 import javax.annotation.PostConstruct;
16 -import java.util.HashMap;  
17 -import java.util.Map;  
18 11
19 @Configuration 12 @Configuration
20 public class SysParameter { 13 public class SysParameter {
@@ -30,7 +23,6 @@ public class SysParameter { @@ -30,7 +23,6 @@ public class SysParameter {
30 23
31 public static String topicconfig ; //topic 配置 24 public static String topicconfig ; //topic 配置
32 25
33 - private static Map<String, IotThingsModel> terminalDataThingsMode = new HashMap<>(); //topic 终端数据模型  
34 26
35 @PostConstruct 27 @PostConstruct
36 public void init() { 28 public void init() {
@@ -45,13 +37,4 @@ public class SysParameter { @@ -45,13 +37,4 @@ public class SysParameter {
45 topicconfig = tempTopicconfig; 37 topicconfig = tempTopicconfig;
46 } 38 }
47 39
48 - public static void setTerminalDataThingsMode(String username,IotThingsModel thingsModel)  
49 - {  
50 - terminalDataThingsMode.put(username+":"+thingsModel.getIdentifier(),thingsModel);  
51 - }  
52 -  
53 - public static IotThingsModel getTerminalDataThingsMode(String username,String identifier)  
54 - {  
55 - return terminalDataThingsMode.get(username+":"+identifier);  
56 - }  
57 } 40 }
@@ -233,7 +233,13 @@ public class BaseDao { @@ -233,7 +233,13 @@ public class BaseDao {
233 { 233 {
234 Field field = fields[i]; 234 Field field = fields[i];
235 try { 235 try {
236 - Method method = object.getClass().getMethod("get"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.getName(field.getName())); 236 +
  237 + Method method = null;
  238 + try {
  239 + method = object.getClass().getMethod("get"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.getName(field.getName()));
  240 + } catch (NoSuchMethodException e) {
  241 + continue;
  242 + }
237 Object value = method.invoke(object); 243 Object value = method.invoke(object);
238 if(null != value) 244 if(null != value)
239 { 245 {
@@ -241,14 +247,11 @@ public class BaseDao { @@ -241,14 +247,11 @@ public class BaseDao {
241 { 247 {
242 sql += ","; 248 sql += ",";
243 } 249 }
244 - sql += "`"+changTableNameFromObject(field.getName())+"`"+"=?"; 250 + sql += "`"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.toUnderScoreCase(field.getName())+"`"+"=?";
245 j++; 251 j++;
246 valueList.add(value); 252 valueList.add(value);
247 } 253 }
248 - } catch (NoSuchMethodException e) {  
249 -  
250 - e.printStackTrace();  
251 - } catch (SecurityException e) { 254 + } catch (SecurityException e) {
252 // TODO Auto-generated catch block 255 // TODO Auto-generated catch block
253 e.printStackTrace(); 256 e.printStackTrace();
254 } catch (IllegalAccessException e) { 257 } catch (IllegalAccessException e) {
@@ -276,7 +279,7 @@ public class BaseDao { @@ -276,7 +279,7 @@ public class BaseDao {
276 Method method = object.getClass().getMethod("get"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.getName(wheres[i])); 279 Method method = object.getClass().getMethod("get"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.getName(wheres[i]));
277 Object value = method.invoke(object); 280 Object value = method.invoke(object);
278 sql += " and "; 281 sql += " and ";
279 - sql += changTableNameFromObject(wheres[i]) + "=?"; 282 + sql += com.zhonglai.luhui.mqtt.comm.util.StringUtils.toUnderScoreCase(wheres[i]) + "=?";
280 valueList.add(value); 283 valueList.add(value);
281 } catch (IllegalAccessException e) { 284 } catch (IllegalAccessException e) {
282 // TODO Auto-generated catch block 285 // TODO Auto-generated catch block
@@ -774,7 +777,6 @@ public class BaseDao { @@ -774,7 +777,6 @@ public class BaseDao {
774 update += "`"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.toUnderScoreCase(field.getName())+"`"+"=VALUES("+"`"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.toUnderScoreCase(field.getName())+"`)"; 777 update += "`"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.toUnderScoreCase(field.getName())+"`"+"=VALUES("+"`"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.toUnderScoreCase(field.getName())+"`)";
775 } 778 }
776 } catch (NoSuchMethodException e) { 779 } catch (NoSuchMethodException e) {
777 - System.out.println("未找到"+field.getName()+"的get方法");  
778 } catch (SecurityException e) { 780 } catch (SecurityException e) {
779 // TODO Auto-generated catch block 781 // TODO Auto-generated catch block
780 e.printStackTrace(); 782 e.printStackTrace();
@@ -5,7 +5,6 @@ import com.zhonglai.luhui.mqtt.comm.factory.Topic; @@ -5,7 +5,6 @@ import com.zhonglai.luhui.mqtt.comm.factory.Topic;
5 import com.zhonglai.luhui.mqtt.dto.Message; 5 import com.zhonglai.luhui.mqtt.dto.Message;
6 6
7 public interface ServerAgreementContent { 7 public interface ServerAgreementContent {
8 - String getClienConnectionId();  
9 byte[] getCommd(); 8 byte[] getCommd();
10 String getReplyCommdTopic(Topic topic); 9 String getReplyCommdTopic(Topic topic);
11 void setReplyMessage(Message message); 10 void setReplyMessage(Message message);
1 -package com.zhonglai.luhui.mqtt.comm.dto.iot;  
2 -  
3 -import io.swagger.annotations.ApiModel;  
4 -import io.swagger.annotations.ApiModelProperty;  
5 -import org.apache.commons.lang3.builder.ToStringBuilder;  
6 -import org.apache.commons.lang3.builder.ToStringStyle;  
7 -  
8 -/**  
9 - * topic权限控制对象 iot_permission  
10 - *  
11 - * @author 钟来  
12 - * @date 2022-08-26  
13 - */  
14 -@ApiModel("topic权限控制")  
15 -public class IotPermission  
16 -{  
17 - private static final long serialVersionUID = 1L;  
18 -  
19 - /** 动作(PUBLISH,SUBSCRIBE,ALL) */  
20 - @ApiModelProperty("动作(PUBLISH,SUBSCRIBE,ALL)")  
21 - private String activity;  
22 -  
23 - /** 创建时间 */  
24 - @ApiModelProperty("创建时间")  
25 - private Integer create_time;  
26 -  
27 - /** 描述 */  
28 - @ApiModelProperty("描述")  
29 - private String describe;  
30 -  
31 - /** 主键 */  
32 - @ApiModelProperty("主键")  
33 - private Integer id;  
34 -  
35 - /** 质量(ZERO,ONE,TWO,ZERO_ONE,ZERO_TWO,ONE_TWO,ALL) */  
36 - @ApiModelProperty("质量(ZERO,ONE,TWO,ZERO_ONE,ZERO_TWO,ONE_TWO,ALL)")  
37 - private String qos;  
38 -  
39 - /** 是否保留(RETAINED,NOT_RETAINED,ALL) */  
40 - @ApiModelProperty("是否保留(RETAINED,NOT_RETAINED,ALL)")  
41 - private String retain;  
42 -  
43 - /** 角色id */  
44 - @ApiModelProperty("角色id")  
45 - private Integer role_id;  
46 -  
47 - /** 共享组 */  
48 - @ApiModelProperty("共享组")  
49 - private String shared_group;  
50 -  
51 - /** 共享订阅(SHARED,NOT_SHARED,ALL) */  
52 - @ApiModelProperty("共享订阅(SHARED,NOT_SHARED,ALL)")  
53 - private String shared_subscription;  
54 -  
55 - /** topic(同一角色有切只有一个) */  
56 - @ApiModelProperty("topic(同一角色有切只有一个)")  
57 - private String topic;  
58 -  
59 - public void setActivity(String activity)  
60 - {  
61 - this.activity = activity;  
62 - }  
63 -  
64 - public String getActivity()  
65 - {  
66 - return activity;  
67 - }  
68 - public void setCreate_time(Integer create_time)  
69 - {  
70 - this.create_time = create_time;  
71 - }  
72 -  
73 - public Integer getCreate_time()  
74 - {  
75 - return create_time;  
76 - }  
77 - public void setDescribe(String describe)  
78 - {  
79 - this.describe = describe;  
80 - }  
81 -  
82 - public String getDescribe()  
83 - {  
84 - return describe;  
85 - }  
86 - public void setId(Integer id)  
87 - {  
88 - this.id = id;  
89 - }  
90 -  
91 - public Integer getId()  
92 - {  
93 - return id;  
94 - }  
95 - public void setQos(String qos)  
96 - {  
97 - this.qos = qos;  
98 - }  
99 -  
100 - public String getQos()  
101 - {  
102 - return qos;  
103 - }  
104 - public void setRetain(String retain)  
105 - {  
106 - this.retain = retain;  
107 - }  
108 -  
109 - public String getRetain()  
110 - {  
111 - return retain;  
112 - }  
113 - public void setRole_id(Integer role_id)  
114 - {  
115 - this.role_id = role_id;  
116 - }  
117 -  
118 - public Integer getRole_id()  
119 - {  
120 - return role_id;  
121 - }  
122 - public void setShared_group(String shared_group)  
123 - {  
124 - this.shared_group = shared_group;  
125 - }  
126 -  
127 - public String getShared_group()  
128 - {  
129 - return shared_group;  
130 - }  
131 - public void setShared_subscription(String shared_subscription)  
132 - {  
133 - this.shared_subscription = shared_subscription;  
134 - }  
135 -  
136 - public String getShared_subscription()  
137 - {  
138 - return shared_subscription;  
139 - }  
140 - public void setTopic(String topic)  
141 - {  
142 - this.topic = topic;  
143 - }  
144 -  
145 - public String getTopic()  
146 - {  
147 - return topic;  
148 - }  
149 -  
150 - public String toString() {  
151 - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)  
152 - .append("activity", getActivity())  
153 - .append("create_time", getCreate_time())  
154 - .append("describe", getDescribe())  
155 - .append("id", getId())  
156 - .append("qos", getQos())  
157 - .append("retain", getRetain())  
158 - .append("role_id", getRole_id())  
159 - .append("shared_group", getShared_group())  
160 - .append("shared_subscription", getShared_subscription())  
161 - .append("topic", getTopic())  
162 - .toString();  
163 - }  
164 -}  
1 -package com.zhonglai.luhui.mqtt.comm.dto.iot;  
2 -  
3 -import io.swagger.annotations.ApiModel;  
4 -import io.swagger.annotations.ApiModelProperty;  
5 -import org.apache.commons.lang3.builder.ToStringBuilder;  
6 -import org.apache.commons.lang3.builder.ToStringStyle;  
7 -  
8 -/**  
9 - * 公司对象 iot_role  
10 - *  
11 - * @author 钟来  
12 - * @date 2022-08-26  
13 - */  
14 -@ApiModel("公司")  
15 -public class IotRole  
16 -{  
17 - private static final long serialVersionUID = 1L;  
18 -  
19 - /** 创建时间 */  
20 - @ApiModelProperty("创建时间")  
21 - private Integer create_time;  
22 -  
23 - /** 描述 */  
24 - @ApiModelProperty("描述")  
25 - private String describe;  
26 -  
27 - /** 主键 */  
28 - @ApiModelProperty("主键")  
29 - private Integer id;  
30 -  
31 - /** 名称 */  
32 - @ApiModelProperty("名称")  
33 - private String name;  
34 -  
35 - /** 是否使用(0否,1是) */  
36 - @ApiModelProperty("是否使用(0否,1是)")  
37 - private Integer used;  
38 -  
39 - public void setCreate_time(Integer create_time)  
40 - {  
41 - this.create_time = create_time;  
42 - }  
43 -  
44 - public Integer getCreate_time()  
45 - {  
46 - return create_time;  
47 - }  
48 - public void setDescribe(String describe)  
49 - {  
50 - this.describe = describe;  
51 - }  
52 -  
53 - public String getDescribe()  
54 - {  
55 - return describe;  
56 - }  
57 - public void setId(Integer id)  
58 - {  
59 - this.id = id;  
60 - }  
61 -  
62 - public Integer getId()  
63 - {  
64 - return id;  
65 - }  
66 - public void setName(String name)  
67 - {  
68 - this.name = name;  
69 - }  
70 -  
71 - public String getName()  
72 - {  
73 - return name;  
74 - }  
75 - public void setUsed(Integer used)  
76 - {  
77 - this.used = used;  
78 - }  
79 -  
80 - public Integer getUsed()  
81 - {  
82 - return used;  
83 - }  
84 -  
85 - public String toString() {  
86 - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)  
87 - .append("create_time", getCreate_time())  
88 - .append("describe", getDescribe())  
89 - .append("id", getId())  
90 - .append("name", getName())  
91 - .append("used", getUsed())  
92 - .toString();  
93 - }  
94 -}  
1 -package com.zhonglai.luhui.mqtt.comm.dto.iot;  
2 -  
3 -import io.swagger.annotations.ApiModel;  
4 -import io.swagger.annotations.ApiModelProperty;  
5 -import org.apache.commons.lang3.builder.ToStringBuilder;  
6 -import org.apache.commons.lang3.builder.ToStringStyle;  
7 -  
8 -/**  
9 - * 终端对象 iot_terminal  
10 - *  
11 - * @author 钟来  
12 - * @date 2022-08-26  
13 - */  
14 -@ApiModel("终端")  
15 -public class IotTerminal  
16 -{  
17 - private static final long serialVersionUID = 1L;  
18 -  
19 - /** 网关id */  
20 - @ApiModelProperty("网关id")  
21 - private String device_id;  
22 -  
23 - /** 主键id */  
24 - @ApiModelProperty("主键id")  
25 - private String id;  
26 -  
27 - /** 终端名称 */  
28 - @ApiModelProperty("终端名称")  
29 - private String name;  
30 -  
31 - /** 物模型值 */  
32 - @ApiModelProperty("物模型值")  
33 - private String things_model_value;  
34 -  
35 - /** 更新时间 */  
36 - @ApiModelProperty("更新时间")  
37 - private Integer update_time;  
38 -  
39 - public void setDevice_id(String device_id)  
40 - {  
41 - this.device_id = device_id;  
42 - }  
43 -  
44 - public String getDevice_id()  
45 - {  
46 - return device_id;  
47 - }  
48 - public void setId(String id)  
49 - {  
50 - this.id = id;  
51 - }  
52 -  
53 - public String getId()  
54 - {  
55 - return id;  
56 - }  
57 - public void setName(String name)  
58 - {  
59 - this.name = name;  
60 - }  
61 -  
62 - public String getName()  
63 - {  
64 - return name;  
65 - }  
66 - public void setThings_model_value(String things_model_value)  
67 - {  
68 - this.things_model_value = things_model_value;  
69 - }  
70 -  
71 - public String getThings_model_value()  
72 - {  
73 - return things_model_value;  
74 - }  
75 - public void setUpdate_time(Integer update_time)  
76 - {  
77 - this.update_time = update_time;  
78 - }  
79 -  
80 - public Integer getUpdate_time()  
81 - {  
82 - return update_time;  
83 - }  
84 -  
85 - public String toString() {  
86 - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)  
87 - .append("device_id", getDevice_id())  
88 - .append("id", getId())  
89 - .append("name", getName())  
90 - .append("things_model_value", getThings_model_value())  
91 - .append("update_time", getUpdate_time())  
92 - .toString();  
93 - }  
94 -}  
1 package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels; 1 package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels;
2 2
3 -import com.alibaba.fastjson.annotation.JSONField;  
4 -import com.zhonglai.luhui.mqtt.comm.dto.iot.IotThingsModel; 3 +
  4 +import com.ruoyi.system.domain.IotThingsModel;
5 5
6 /** 6 /**
7 * 物模型工厂 7 * 物模型工厂
@@ -12,4 +12,5 @@ public interface ThingsModelBase<T> { @@ -12,4 +12,5 @@ public interface ThingsModelBase<T> {
12 // @JSONField(serialize=false) 12 // @JSONField(serialize=false)
13 String getView(); 13 String getView();
14 String getSaveView(); 14 String getSaveView();
  15 + Object getCmdView(Object value);
15 } 16 }
1 package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels; 1 package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels;
2 2
3 -import com.zhonglai.luhui.mqtt.comm.dto.iot.IotThingsModel; 3 +import com.ruoyi.system.domain.IotThingsModel;
4 import lombok.Data; 4 import lombok.Data;
5 5
6 /** 6 /**
@@ -26,6 +26,8 @@ public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T> @@ -26,6 +26,8 @@ public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T>
26 private Integer is_save_log; 26 private Integer is_save_log;
27 /** 模型类别(1-属性,2-功能,3-事件) */ 27 /** 模型类别(1-属性,2-功能,3-事件) */
28 private Integer mode_type; 28 private Integer mode_type;
  29 + /** 模型类别(1-属性,2-功能,3-事件) */
  30 + private String config_names;
29 31
30 public void conversionThingsModel(IotThingsModel thingsModel) 32 public void conversionThingsModel(IotThingsModel thingsModel)
31 { 33 {
@@ -36,6 +38,7 @@ public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T> @@ -36,6 +38,7 @@ public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T>
36 type = thingsModel.getData_type(); 38 type = thingsModel.getData_type();
37 is_save_log = thingsModel.getIs_save_log(); 39 is_save_log = thingsModel.getIs_save_log();
38 mode_type = thingsModel.getType(); 40 mode_type = thingsModel.getType();
  41 + config_names = thingsModel.getConfig_names();
39 } 42 }
40 43
41 } 44 }
@@ -33,4 +33,9 @@ public class ArrayModelOutput extends ThingsModelItemBase<JSONArray> @@ -33,4 +33,9 @@ public class ArrayModelOutput extends ThingsModelItemBase<JSONArray>
33 } 33 }
34 return JSONArray.toJSONString(getValue()); 34 return JSONArray.toJSONString(getValue());
35 } 35 }
  36 +
  37 + @Override
  38 + public Object getCmdView(Object object) {
  39 + return object;
  40 + }
36 } 41 }
@@ -37,4 +37,9 @@ public class BoolModelOutput extends ThingsModelItemBase<Boolean> @@ -37,4 +37,9 @@ public class BoolModelOutput extends ThingsModelItemBase<Boolean>
37 } 37 }
38 return getValue().toString(); 38 return getValue().toString();
39 } 39 }
  40 +
  41 + @Override
  42 + public Object getCmdView(Object object) {
  43 + return object;
  44 + }
40 } 45 }
@@ -24,7 +24,7 @@ public class DecimalModelOutput extends ThingsModelItemBase<BigDecimal> @@ -24,7 +24,7 @@ public class DecimalModelOutput extends ThingsModelItemBase<BigDecimal>
24 { 24 {
25 return null; 25 return null;
26 } 26 }
27 - return getValue().doubleValue()+unit; 27 + return getValue().doubleValue()+(null==unit?"":unit);
28 } 28 }
29 29
30 @Override 30 @Override
@@ -35,4 +35,9 @@ public class DecimalModelOutput extends ThingsModelItemBase<BigDecimal> @@ -35,4 +35,9 @@ public class DecimalModelOutput extends ThingsModelItemBase<BigDecimal>
35 } 35 }
36 return getValue().toString(); 36 return getValue().toString();
37 } 37 }
  38 +
  39 + @Override
  40 + public Object getCmdView(Object object) {
  41 + return object;
  42 + }
38 } 43 }
@@ -7,33 +7,46 @@ import lombok.Data; @@ -7,33 +7,46 @@ import lombok.Data;
7 import java.util.List; 7 import java.util.List;
8 8
9 @Data 9 @Data
10 -public class EnumModelOutput extends ThingsModelItemBase<String> 10 +public class EnumModelOutput extends ThingsModelItemBase<Object>
11 { 11 {
12 private List<EnumItemOutput> enumList; 12 private List<EnumItemOutput> enumList;
13 13
14 @Override 14 @Override
15 - public void addValue(String object) { 15 + public void addValue(Object object) {
16 setValue(object); 16 setValue(object);
17 } 17 }
18 18
19 @Override 19 @Override
20 public String getView() { 20 public String getView() {
  21 + if(null == getValue())
  22 + {
  23 + return null;
  24 + }
21 if(null == enumList || enumList.size()==0) 25 if(null == enumList || enumList.size()==0)
22 { 26 {
23 return null; 27 return null;
24 } 28 }
25 for(EnumItemOutput enumItemOutput:enumList) 29 for(EnumItemOutput enumItemOutput:enumList)
26 { 30 {
27 - if(enumItemOutput.getValue().equals(getValue())) 31 + if(enumItemOutput.getValue().equals(getValue()+""))
28 { 32 {
29 return enumItemOutput.getText(); 33 return enumItemOutput.getText();
30 } 34 }
31 } 35 }
32 - return getValue(); 36 + return getValue()+"";
33 } 37 }
34 38
35 @Override 39 @Override
36 public String getSaveView() { 40 public String getSaveView() {
37 - return getValue(); 41 + if(null == getValue())
  42 + {
  43 + return null;
  44 + }
  45 + return getValue()+"";
  46 + }
  47 +
  48 + @Override
  49 + public Object getCmdView(Object object) {
  50 + return object;
38 } 51 }
39 } 52 }
@@ -27,7 +27,7 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer> @@ -27,7 +27,7 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer>
27 { 27 {
28 return null; 28 return null;
29 } 29 }
30 - return getSaveView()+unit; 30 + return getSaveView()+(null==unit?"":unit);
31 } 31 }
32 32
33 @Override 33 @Override
@@ -39,4 +39,14 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer> @@ -39,4 +39,14 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer>
39 BigDecimal bigDecimal = new BigDecimal(getValue().toString()); 39 BigDecimal bigDecimal = new BigDecimal(getValue().toString());
40 return bigDecimal.divide(new BigDecimal(acy),acy.toString().length()-1, RoundingMode.HALF_UP).toString(); 40 return bigDecimal.divide(new BigDecimal(acy),acy.toString().length()-1, RoundingMode.HALF_UP).toString();
41 } 41 }
  42 +
  43 + @Override
  44 + public Object getCmdView(Object object) {
  45 + if(null == object)
  46 + {
  47 + return null;
  48 + }
  49 + BigDecimal bigDecimal = new BigDecimal(object.toString());
  50 + return bigDecimal.multiply(new BigDecimal(acy)).intValue();
  51 + }
42 } 52 }
@@ -25,4 +25,9 @@ public class StringModelOutput extends ThingsModelItemBase<Object> @@ -25,4 +25,9 @@ public class StringModelOutput extends ThingsModelItemBase<Object>
25 public String getSaveView() { 25 public String getSaveView() {
26 return getView(); 26 return getView();
27 } 27 }
  28 +
  29 + @Override
  30 + public Object getCmdView(Object object) {
  31 + return object;
  32 + }
28 } 33 }
@@ -4,6 +4,7 @@ import com.zhonglai.luhui.mqtt.comm.config.RedisConfig; @@ -4,6 +4,7 @@ import com.zhonglai.luhui.mqtt.comm.config.RedisConfig;
4 import com.zhonglai.luhui.mqtt.comm.config.SysParameter; 4 import com.zhonglai.luhui.mqtt.comm.config.SysParameter;
5 import com.zhonglai.luhui.mqtt.comm.dto.MyException; 5 import com.zhonglai.luhui.mqtt.comm.dto.MyException;
6 import com.zhonglai.luhui.mqtt.comm.service.MqttCallback; 6 import com.zhonglai.luhui.mqtt.comm.service.MqttCallback;
  7 +import com.zhonglai.luhui.mqtt.comm.util.StringUtils;
7 import lombok.Data; 8 import lombok.Data;
8 import org.slf4j.Logger; 9 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory; 10 import org.slf4j.LoggerFactory;
@@ -19,9 +20,29 @@ public class Topic { @@ -19,9 +20,29 @@ public class Topic {
19 private String username; 20 private String username;
20 private String clientid; 21 private String clientid;
21 private String topicType; 22 private String topicType;
22 - private String redicKey;  
23 private String messageid; 23 private String messageid;
24 private String payloadtype; 24 private String payloadtype;
  25 +
  26 + public Topic() {
  27 + }
  28 +
  29 + public Topic(String roleid, String username, String clientid, String topicType, String payloadtype) {
  30 + this.roleid = roleid;
  31 + this.username = username;
  32 + this.clientid = clientid;
  33 + this.topicType = topicType;
  34 + this.payloadtype = payloadtype;
  35 + }
  36 +
  37 + public Topic(String roleid, String username, String clientid, String topicType, String messageid, String payloadtype) {
  38 + this.roleid = roleid;
  39 + this.username = username;
  40 + this.clientid = clientid;
  41 + this.topicType = topicType;
  42 + this.messageid = messageid;
  43 + this.payloadtype = payloadtype;
  44 + }
  45 +
25 public Topic(String topic) 46 public Topic(String topic)
26 { 47 {
27 topic = Optional.ofNullable(topic).orElseThrow(()->new MyException("topic为空")); 48 topic = Optional.ofNullable(topic).orElseThrow(()->new MyException("topic为空"));
@@ -45,17 +66,72 @@ public class Topic { @@ -45,17 +66,72 @@ public class Topic {
45 } 66 }
46 } 67 }
47 } 68 }
48 - public String getRedicKey() 69 +
  70 + /**
  71 + * 生成缓存关键字
  72 + * @return
  73 + */
  74 + public String generateRedicKey()
49 { 75 {
50 - if(null == redicKey)  
51 - {  
52 - return generateRedicKey();  
53 - }  
54 - return redicKey; 76 + return generate(":");
  77 + }
  78 +
  79 + /**
  80 + * 生成发送消息的topic
  81 + * @return
  82 + */
  83 + public String generateSendMessageTopic()
  84 + {
  85 + return "/"+generate("/");
55 } 86 }
56 - private String generateRedicKey() 87 +
  88 + /**
  89 + * 生成客户端关键字
  90 + * @return
  91 + */
  92 + public String generateClienKey()
57 { 93 {
58 - return RedisConfig.FIELD+roleid+":"+username+":"+clientid; 94 + return "/"+generate("/");
59 } 95 }
60 96
  97 + private String generate(String division)
  98 + {
  99 + String str = SysParameter.topicconfig;
  100 + if(StringUtils.isEmpty(roleid))
  101 + {
  102 + roleid = "2";
  103 + }
  104 + str = str.replace("/{{roleid}}",roleid+division);
  105 +
  106 + if(StringUtils.isEmpty(username))
  107 + {
  108 + username = "+";
  109 + }
  110 + str = str.replace("/{{username}}",username+division);
  111 +
  112 + if(StringUtils.isEmpty(clientid))
  113 + {
  114 + clientid = "+";
  115 + }
  116 + str = str.replace("/{{clientid}}",clientid+division);
  117 +
  118 + if(StringUtils.isEmpty(payloadtype))
  119 + {
  120 + payloadtype = "String";
  121 + }
  122 + str = str.replace("/{{payloadtype}}",payloadtype+division);
  123 +
  124 + if(StringUtils.isEmpty(topicType))
  125 + {
  126 + topicType = "PUT";
  127 + }
  128 + str = str.replace("/{{topicType}}",topicType+division);
  129 +
  130 + if(StringUtils.isNotEmpty(messageid))
  131 + {
  132 + str = str.replace("/{{messageid}}",messageid);
  133 + }
  134 +
  135 + return str;
  136 + }
61 } 137 }
1 package com.zhonglai.luhui.mqtt.comm.service; 1 package com.zhonglai.luhui.mqtt.comm.service;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
  4 +import com.ruoyi.system.domain.IotDevice;
  5 +import com.ruoyi.system.domain.IotTerminal;
  6 +import com.zhonglai.luhui.mqtt.comm.config.SysParameter;
4 import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData; 7 import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData;
5 import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; 8 import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation;
6 -import com.zhonglai.luhui.mqtt.comm.dto.iot.IotDevice;  
7 -import com.zhonglai.luhui.mqtt.comm.dto.iot.IotTerminal;  
8 import com.zhonglai.luhui.mqtt.comm.factory.Topic; 9 import com.zhonglai.luhui.mqtt.comm.factory.Topic;
9 import com.zhonglai.luhui.mqtt.comm.util.DateUtils; 10 import com.zhonglai.luhui.mqtt.comm.util.DateUtils;
  11 +import com.zhonglai.luhui.mqtt.dto.SaveDataDto;
10 import com.zhonglai.luhui.mqtt.dto.topic.AddPostDto; 12 import com.zhonglai.luhui.mqtt.dto.topic.AddPostDto;
11 import com.zhonglai.luhui.mqtt.service.db.DeviceService; 13 import com.zhonglai.luhui.mqtt.service.db.DeviceService;
  14 +import org.slf4j.Logger;
  15 +import org.slf4j.LoggerFactory;
12 import org.springframework.beans.factory.annotation.Autowired; 16 import org.springframework.beans.factory.annotation.Autowired;
  17 +import org.springframework.beans.factory.annotation.Value;
13 import org.springframework.stereotype.Service; 18 import org.springframework.stereotype.Service;
14 19
15 import java.util.ArrayList; 20 import java.util.ArrayList;
@@ -20,6 +25,8 @@ import java.util.List; @@ -20,6 +25,8 @@ import java.util.List;
20 */ 25 */
21 @Service 26 @Service
22 public class BusinessDataUpdateService { 27 public class BusinessDataUpdateService {
  28 + private static final Logger logger = LoggerFactory.getLogger(BusinessDataUpdateService.class);
  29 +
23 @Autowired 30 @Autowired
24 private DataModeAnalysisService dataModeAnalysisService ; 31 private DataModeAnalysisService dataModeAnalysisService ;
25 @Autowired 32 @Autowired
@@ -27,6 +34,14 @@ public class BusinessDataUpdateService { @@ -27,6 +34,14 @@ public class BusinessDataUpdateService {
27 @Autowired 34 @Autowired
28 private DeviceService deviceService ; 35 private DeviceService deviceService ;
29 36
  37 + @Value("${server.port}")
  38 + private long port;
  39 +
  40 + @Value("${server.context-path}")
  41 + private String contextPath;
  42 +
  43 + @Value("${sys.isText:false}")
  44 + private Boolean isText;
30 /** 45 /**
31 * 更新数据 46 * 更新数据
32 * @param type 47 * @param type
@@ -35,6 +50,13 @@ public class BusinessDataUpdateService { @@ -35,6 +50,13 @@ public class BusinessDataUpdateService {
35 */ 50 */
36 public void updataDta(Type type,Topic topic, JSONObject data,boolean isOperLog,List<LogDeviceOperation> operateHisList, List<DeviceSensorData> list) 51 public void updataDta(Type type,Topic topic, JSONObject data,boolean isOperLog,List<LogDeviceOperation> operateHisList, List<DeviceSensorData> list)
37 { 52 {
  53 + if(1==deviceService.getlockIotDevice(topic.getClientid()))
  54 + {
  55 + logger.info("设备锁定等待解锁");
  56 + return;
  57 + }
  58 + IotDevice olddevice = deviceService.getRedicDevice(topic.getClientid());
  59 +
38 for(String key:data.keySet()) 60 for(String key:data.keySet())
39 { 61 {
40 Object o = data.get(key); 62 Object o = data.get(key);
@@ -43,11 +65,18 @@ public class BusinessDataUpdateService { @@ -43,11 +65,18 @@ public class BusinessDataUpdateService {
43 JSONObject jsData = data.getJSONObject(key); 65 JSONObject jsData = data.getJSONObject(key);
44 if("0".equals(key)) //主机 66 if("0".equals(key)) //主机
45 { 67 {
46 - IotDevice iotDevice = translateDevice(type,topic,jsData,isOperLog,operateHisList,list); 68 + IotDevice iotDevice = translateDevice(type,olddevice,jsData,isOperLog,operateHisList,list);
  69 + if(isText)
  70 + {
  71 + iotDevice.setListen_service_ip("127.0.0.1"+":"+port+contextPath);
  72 + }else{
  73 + iotDevice.setListen_service_ip(SysParameter.service_ip+":"+port+contextPath);
  74 + }
  75 + logger.info("更新网关数据{}",iotDevice);
47 deviceService.updataDevice(iotDevice); 76 deviceService.updataDevice(iotDevice);
48 -  
49 }else{ //终端 77 }else{ //终端
50 - IotTerminal iotTerminal = translateTerminal(type,key,topic,jsData,isOperLog,operateHisList,list); 78 + IotTerminal iotTerminal = translateTerminal(type,key,olddevice,jsData,isOperLog,operateHisList,list);
  79 + logger.info("更新终端数据{}",iotTerminal);
51 deviceService.updataTerminal(iotTerminal); 80 deviceService.updataTerminal(iotTerminal);
52 } 81 }
53 } 82 }
@@ -57,40 +86,45 @@ public class BusinessDataUpdateService { @@ -57,40 +86,45 @@ public class BusinessDataUpdateService {
57 /** 86 /**
58 * 更新网关 87 * 更新网关
59 * @param type 88 * @param type
60 - * @param topic 89 + * @param olddevice
61 * @param jsData 90 * @param jsData
62 * @param operateHisList 91 * @param operateHisList
63 * @return 92 * @return
64 */ 93 */
65 - private IotDevice translateDevice(Type type,Topic topic , JSONObject jsData,boolean isOperLog, List<LogDeviceOperation> operateHisList, List<DeviceSensorData> list) 94 + private IotDevice translateDevice(Type type, IotDevice olddevice , JSONObject jsData,boolean isOperLog, List<LogDeviceOperation> operateHisList, List<DeviceSensorData> list)
66 { 95 {
67 - IotDevice olddevice = deviceService.getRedicDevice(topic.getClientid());  
68 JSONObject summaryObjec = null; 96 JSONObject summaryObjec = null;
69 if(jsData.containsKey("summary") && null != jsData.get("summary") && jsData.get("summary") instanceof JSONObject) 97 if(jsData.containsKey("summary") && null != jsData.get("summary") && jsData.get("summary") instanceof JSONObject)
70 { 98 {
71 summaryObjec = jsData.getJSONObject("summary"); 99 summaryObjec = jsData.getJSONObject("summary");
72 //记录summary内容变更日志 100 //记录summary内容变更日志
73 - operateHisList.add(deviceLogService.newLogDeviceOperation(topic.getClientid(),summaryObjec.toString(),olddevice.getSummary(),"主机本地summary状态更新",jsData.toJSONString())); 101 + operateHisList.add(deviceLogService.newLogDeviceOperation(olddevice.getClient_id(),summaryObjec.toString(),olddevice.getSummary(),"主机本地summary状态更新",jsData.toJSONString()));
74 jsData.remove("summary"); 102 jsData.remove("summary");
75 } 103 }
76 IotDevice device = JSONObject.parseObject(JSONObject.toJSONString(jsData),IotDevice.class); 104 IotDevice device = JSONObject.parseObject(JSONObject.toJSONString(jsData),IotDevice.class);
77 - device.setClient_id(topic.getClientid()); 105 + device.setClient_id(olddevice.getClient_id());
78 device.setUpdate_time(DateUtils.getNowTimeMilly()); 106 device.setUpdate_time(DateUtils.getNowTimeMilly());
  107 + device.setMqtt_username(olddevice.getMqtt_username());
  108 + device.setProduct_id(olddevice.getProduct_id());
79 if(null != summaryObjec) 109 if(null != summaryObjec)
80 { 110 {
81 device.setSummary(summaryObjec.toString()); 111 device.setSummary(summaryObjec.toString());
82 } 112 }
83 113
84 - JSONObject saveJson = dataModeAnalysisService.analysisThingsModelValue( topic.getClientid(),topic.getUsername(),jsData,"主机本地",isOperLog,operateHisList,list); 114 + SaveDataDto saveDataDto = dataModeAnalysisService.analysisThingsModelValue( olddevice.getClient_id(),olddevice.getMqtt_username(),jsData,"主机本地",isOperLog,operateHisList,list);
85 //更新数据 115 //更新数据
86 - if(null != olddevice && "ADD".equals(type.name())) 116 + if(null != olddevice && ("ADD".equals(type.name())|| "READ".equals(type.name())))
87 { 117 {
88 String str = olddevice.getThings_model_value(); 118 String str = olddevice.getThings_model_value();
89 - String newStr = deviceService.getNewAdddate(str,saveJson).toJSONString(); 119 + String newStr = deviceService.getNewAdddate(str,saveDataDto.getData()).toJSONString();
90 device.setThings_model_value(newStr); 120 device.setThings_model_value(newStr);
91 }else{ 121 }else{
92 - device.setThings_model_value(saveJson.toJSONString()); 122 + device.setThings_model_value(saveDataDto.getData().toJSONString());
93 } 123 }
  124 + //配置只做增量
  125 + String str = (null!=olddevice?olddevice.getThings_model_config():null);
  126 + String newStr = deviceService.getNewAdddate(str,saveDataDto.getConfig()).toJSONString();
  127 + device.setThings_model_config(newStr);
94 128
95 return device; 129 return device;
96 } 130 }
@@ -99,28 +133,47 @@ public class BusinessDataUpdateService { @@ -99,28 +133,47 @@ public class BusinessDataUpdateService {
99 * 更新终端 133 * 更新终端
100 * @param type "ADD"增量更新,"ALL"全量更新 134 * @param type "ADD"增量更新,"ALL"全量更新
101 * @param key 135 * @param key
102 - * @param topic 136 + * @param olddevice
103 * @param jsData 137 * @param jsData
104 * @param operateHisList 138 * @param operateHisList
105 * @return 139 * @return
106 */ 140 */
107 - private IotTerminal translateTerminal(Type type,String key, Topic topic , JSONObject jsData,boolean isOperLog, List<LogDeviceOperation> operateHisList, List<DeviceSensorData> list) 141 + private IotTerminal translateTerminal(Type type,String key, IotDevice olddevice , JSONObject jsData,boolean isOperLog, List<LogDeviceOperation> operateHisList, List<DeviceSensorData> list)
108 { 142 {
109 - String id = topic.getClientid()+"_"+key;  
110 - JSONObject saveJson = dataModeAnalysisService.analysisThingsModelValue( id,topic.getUsername(),jsData,"终端本地",isOperLog,operateHisList,list); 143 + String id = olddevice.getClient_id()+"_"+key;
  144 + SaveDataDto saveDataDto = dataModeAnalysisService.analysisThingsModelValue( id,olddevice.getMqtt_username(),jsData,"终端本地",isOperLog,operateHisList,list);
111 IotTerminal terminal = new IotTerminal(); 145 IotTerminal terminal = new IotTerminal();
112 terminal.setId(id); 146 terminal.setId(id);
113 terminal.setUpdate_time(DateUtils.getNowTimeMilly()); 147 terminal.setUpdate_time(DateUtils.getNowTimeMilly());
114 - 148 + terminal.setDevice_id(olddevice.getClient_id());
  149 + terminal.setProduct_id(olddevice.getProduct_id());
  150 + terminal.setMqtt_username(olddevice.getMqtt_username());
115 //更新数据 151 //更新数据
116 IotTerminal oldterminal = deviceService.getRedicTerminal(id); 152 IotTerminal oldterminal = deviceService.getRedicTerminal(id);
117 - if(null != oldterminal && "ADD".equals(type.name())) 153 + if(null == oldterminal)
  154 + {
  155 + oldterminal = new IotTerminal();
  156 + oldterminal.setDevice_id(olddevice.getClient_id());
  157 + oldterminal.setId(id);
  158 + oldterminal.setMqtt_username(olddevice.getMqtt_username());
  159 + oldterminal.setName(olddevice.getMqtt_username()+"终端"+key);
  160 + oldterminal.setProduct_id(olddevice.getProduct_id());
  161 + deviceService.updataTerminal(oldterminal);
  162 + }
  163 + if(null != oldterminal && ("ADD".equals(type.name())|| "READ".equals(type.name())))
118 { 164 {
119 String str = oldterminal.getThings_model_value(); 165 String str = oldterminal.getThings_model_value();
120 - terminal.setThings_model_value(deviceService.getNewAdddate(str,saveJson).toJSONString()); 166 + terminal.setThings_model_value(deviceService.getNewAdddate(str,saveDataDto.getData()).toJSONString());
121 }else{ 167 }else{
122 - terminal.setThings_model_value(saveJson.toJSONString()); 168 + terminal.setThings_model_value(saveDataDto.getData().toJSONString());
  169 + }
  170 + if(key.startsWith("1_") && null != saveDataDto.getConfig())
  171 + {
  172 + System.out.println(saveDataDto);
123 } 173 }
  174 + String str = (null!=oldterminal?oldterminal.getThings_model_config():null);
  175 + terminal.setThings_model_config(deviceService.getNewAdddate(str,saveDataDto.getConfig()).toJSONString());
  176 +
124 return terminal; 177 return terminal;
125 } 178 }
126 179
1 package com.zhonglai.luhui.mqtt.comm.service; 1 package com.zhonglai.luhui.mqtt.comm.service;
2 2
  3 +import com.mysql.cj.x.protobuf.MysqlxDatatypes;
3 import com.zhonglai.luhui.mqtt.comm.clien.ClienConnection; 4 import com.zhonglai.luhui.mqtt.comm.clien.ClienConnection;
4 import com.zhonglai.luhui.mqtt.comm.clien.impl.ClienConnectionImpl; 5 import com.zhonglai.luhui.mqtt.comm.clien.impl.ClienConnectionImpl;
5 import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; 6 import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
@@ -18,6 +19,7 @@ import org.springframework.beans.factory.annotation.Value; @@ -18,6 +19,7 @@ import org.springframework.beans.factory.annotation.Value;
18 import org.springframework.stereotype.Service; 19 import org.springframework.stereotype.Service;
19 20
20 import javax.annotation.PostConstruct; 21 import javax.annotation.PostConstruct;
  22 +import java.util.Map;
21 import java.util.concurrent.TimeUnit; 23 import java.util.concurrent.TimeUnit;
22 24
23 /** 25 /**
@@ -30,14 +32,14 @@ public class ClienNoticeService { @@ -30,14 +32,14 @@ public class ClienNoticeService {
30 @Autowired 32 @Autowired
31 private TerminalService terminalService; 33 private TerminalService terminalService;
32 34
33 - @Autowired  
34 - private TopicsService topicsService;  
35 -  
36 private ExpiringMap<String, ClienConnection> clienConnectionMap; 35 private ExpiringMap<String, ClienConnection> clienConnectionMap;
37 36
38 @Value("${mqtt.client.operationTime}") 37 @Value("${mqtt.client.operationTime}")
39 private long operationTime; //客户端操作时间 38 private long operationTime; //客户端操作时间
40 39
  40 + @Value("#{${mqtt.top_return_map}}")
  41 + private Map<String,String> top_return_map; //topic返回的对应关系
  42 +
41 @PostConstruct 43 @PostConstruct
42 public void init() 44 public void init()
43 { 45 {
@@ -48,46 +50,45 @@ public class ClienNoticeService { @@ -48,46 +50,45 @@ public class ClienNoticeService {
48 // CREATED: 只在put和replace方法清零过期时间 50 // CREATED: 只在put和replace方法清零过期时间
49 // ACCESSED: 在CREATED策略基础上增加, 在还没过期时get方法清零过期时间。 51 // ACCESSED: 在CREATED策略基础上增加, 在还没过期时get方法清零过期时间。
50 // 清零过期时间也就是重置过期时间,重新计算过期时间. 52 // 清零过期时间也就是重置过期时间,重新计算过期时间.
51 - clienConnectionMap = ExpiringMap.builder().maxSize(2000).expiration(operationTime, TimeUnit.SECONDS) 53 + clienConnectionMap = ExpiringMap.builder().maxSize(20000).expiration(operationTime, TimeUnit.SECONDS)
52 .asyncExpirationListener((ExpirationListener<String, ClienConnection>) (s, clienConnection) -> clienConnection.close()) 54 .asyncExpirationListener((ExpirationListener<String, ClienConnection>) (s, clienConnection) -> clienConnection.close())
53 .expirationPolicy(ExpirationPolicy.CREATED).build(); 55 .expirationPolicy(ExpirationPolicy.CREATED).build();
54 } 56 }
55 57
56 - public Message sendMessage(String imei, MqttMessage mqttMessage, String messageid) throws MqttException, InterruptedException { 58 + public Message sendMessage(Topic topic, MqttMessage mqttMessage) throws MqttException, InterruptedException {
57 //设置通知渠道 59 //设置通知渠道
58 ClienConnection clienConnection = new ClienConnectionImpl(); 60 ClienConnection clienConnection = new ClienConnectionImpl();
59 - clienConnectionMap.put(topicsService.getClienConnectionMapKey(imei,messageid),clienConnection); 61 + log.info("{} {} {} {}",topic.generateClienKey(),topic.getTopicType(),top_return_map,clienConnection);
  62 + clienConnectionMap.put(topic.generateClienKey().replace(topic.getTopicType(),top_return_map.get(topic.getTopicType())),clienConnection);
60 63
61 - sendMessage(imei,messageid,mqttMessage); 64 + sendMessage(topic.generateSendMessageTopic(),mqttMessage);
62 synchronized(clienConnection) 65 synchronized(clienConnection)
63 { 66 {
64 - log.info("{}等待通知",imei); 67 + log.info("{}等待通知",topic.getClientid());
65 clienConnection.wait(operationTime*1000+3000l); 68 clienConnection.wait(operationTime*1000+3000l);
66 } 69 }
67 - log.info("{}收到通知{}",imei,clienConnection.getReplyMessage().getMessage()); 70 + log.info("{}收到通知{}",topic.getClientid(),clienConnection.getReplyMessage().getMessage());
68 Message message = clienConnection.getReplyMessage(); 71 Message message = clienConnection.getReplyMessage();
69 - log.info("{}返回通知{}",imei,message); 72 + log.info("{}返回通知{}",topic.getClientid(),message);
70 73
71 return message; 74 return message;
72 } 75 }
73 76
74 /** 77 /**
75 * 发送消息 78 * 发送消息
76 - * @param imei  
77 * @param mqttMessage 79 * @param mqttMessage
78 * @throws MqttException 80 * @throws MqttException
79 * @throws InterruptedException 81 * @throws InterruptedException
80 */ 82 */
81 - public void sendMessage(String imei,String messageid, MqttMessage mqttMessage) throws MqttException, InterruptedException { 83 + public void sendMessage(String topic,MqttMessage mqttMessage) throws MqttException, InterruptedException {
82 //发生指令,等待通知 84 //发生指令,等待通知
83 - String topic = topicsService.getTopicFromImei(imei,messageid);  
84 - System.out.println("发送的消息内容"+ ByteUtil.hexStringToSpace(ByteUtil.toHexString(mqttMessage.getPayload()).toUpperCase())); 85 + System.out.println(topic+"发送的消息内容"+ ByteUtil.hexStringToSpace(ByteUtil.toHexString(mqttMessage.getPayload()).toUpperCase())+" 转化为字符串:"+new String(mqttMessage.getPayload()));
85 terminalService.publish(topic,mqttMessage); 86 terminalService.publish(topic,mqttMessage);
86 } 87 }
87 88
88 - public ClienConnection getClienConnection(String imei, String messageid) 89 + public ClienConnection getClienConnection(Topic topic)
89 { 90 {
90 - return clienConnectionMap.get(topicsService.getClienConnectionMapKey(imei,messageid)); 91 + return clienConnectionMap.get(topic.generateClienKey());
91 } 92 }
92 93
93 public void replySendMessage(Topic topic, ServerDto dto) 94 public void replySendMessage(Topic topic, ServerDto dto)
@@ -96,7 +97,7 @@ public class ClienNoticeService { @@ -96,7 +97,7 @@ public class ClienNoticeService {
96 //判断有没有需要回复的客户端,如果有就回复 97 //判断有没有需要回复的客户端,如果有就回复
97 if(dto.isReplyMessage()) 98 if(dto.isReplyMessage())
98 { 99 {
99 - ClienConnection clienConnection = getClienConnection(topic.getClientid(),dto.getServerAgreementContent().getClienConnectionId()); 100 + ClienConnection clienConnection = getClienConnection(topic);
100 if(null != clienConnection) 101 if(null != clienConnection)
101 { 102 {
102 synchronized(clienConnection) 103 synchronized(clienConnection)
@@ -2,26 +2,24 @@ package com.zhonglai.luhui.mqtt.comm.service; @@ -2,26 +2,24 @@ package com.zhonglai.luhui.mqtt.comm.service;
2 2
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
5 -import com.zhonglai.luhui.mqtt.comm.config.RedisConfig;  
6 -import com.zhonglai.luhui.mqtt.comm.config.SysParameter; 5 +import com.ruoyi.system.domain.IotThingsModel;
7 import com.zhonglai.luhui.mqtt.comm.dao.BaseDao; 6 import com.zhonglai.luhui.mqtt.comm.dao.BaseDao;
8 import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData; 7 import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData;
9 import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; 8 import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation;
10 -import com.zhonglai.luhui.mqtt.comm.dto.iot.IotThingsModel;  
11 import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelBase; 9 import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelBase;
12 import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelDataTypeEnum; 10 import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelDataTypeEnum;
13 import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase; 11 import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase;
14 import com.zhonglai.luhui.mqtt.comm.util.DateUtils; 12 import com.zhonglai.luhui.mqtt.comm.util.DateUtils;
15 import com.zhonglai.luhui.mqtt.comm.util.StringUtils; 13 import com.zhonglai.luhui.mqtt.comm.util.StringUtils;
  14 +import com.zhonglai.luhui.mqtt.dto.SaveDataDto;
  15 +import com.zhonglai.luhui.mqtt.service.db.mode.TerminalDataThingsModeService;
  16 +import org.apache.commons.lang3.EnumUtils;
16 import org.slf4j.Logger; 17 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory; 18 import org.slf4j.LoggerFactory;
18 import org.springframework.beans.factory.annotation.Autowired; 19 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.stereotype.Service; 20 import org.springframework.stereotype.Service;
20 21
21 -import javax.annotation.PostConstruct;  
22 -import java.util.ArrayList;  
23 import java.util.List; 22 import java.util.List;
24 -import java.util.Map;  
25 23
26 /** 24 /**
27 * 数据模型解析服务 25 * 数据模型解析服务
@@ -35,40 +33,37 @@ public class DataModeAnalysisService { @@ -35,40 +33,37 @@ public class DataModeAnalysisService {
35 @Autowired 33 @Autowired
36 private DeviceLogService dviceLogService; 34 private DeviceLogService dviceLogService;
37 35
  36 + @Autowired
  37 + private TerminalDataThingsModeService terminalDataThingsModeService;
  38 +
38 /** 39 /**
39 * 初始化物模型数据 40 * 初始化物模型数据
40 */ 41 */
41 public void initDataThingsMode(String roleIds,String usernames) 42 public void initDataThingsMode(String roleIds,String usernames)
42 { 43 {
43 - String sql = "SELECT a.*,b.username user_name FROM `mqtt_broker`.`iot_things_model` a LEFT JOIN `mqtt_broker`.`iot_user` b ON a.`user_id`=b.`id` WHERE a.del_flag=0 AND b.`role_id` IN("+roleIds+")"; 44 + String sql = "SELECT a.*,b.mqtt_username mqtt_username FROM `mqtt_broker`.`iot_things_model` a LEFT JOIN `mqtt_broker`.`iot_product` b ON a.`product_id`=b.`id` WHERE a.del_flag=0 AND b.`role_id` IN("+roleIds+")";
44 if(StringUtils.isNotEmpty(usernames)) 45 if(StringUtils.isNotEmpty(usernames))
45 { 46 {
46 sql += " AND b.`username` IN("+usernames+")"; 47 sql += " AND b.`username` IN("+usernames+")";
47 } 48 }
48 List<IotThingsModel> list = baseDao.findBysql(sql, IotThingsModel.class); 49 List<IotThingsModel> list = baseDao.findBysql(sql, IotThingsModel.class);
49 -  
50 - if(null != list && list.size() != 0)  
51 - {  
52 - for(IotThingsModel thingsModel:list)  
53 - {  
54 - SysParameter.setTerminalDataThingsMode(thingsModel.getUser_name(),thingsModel);  
55 - }  
56 - } 50 + terminalDataThingsModeService.saveIotThingsModelToUser(list);
57 } 51 }
58 52
59 /** 53 /**
60 * 解析物模型数据 54 * 解析物模型数据
61 */ 55 */
62 - public JSONObject analysisThingsModelValue(String id,String userName ,JSONObject jsData,String controlModel,boolean isOperLog, List<LogDeviceOperation> operateHisList, List<DeviceSensorData> list) 56 + public SaveDataDto analysisThingsModelValue(String id,String userName ,JSONObject jsData,String controlModel,boolean isOperLog, List<LogDeviceOperation> operateHisList, List<DeviceSensorData> list)
63 { 57 {
64 if(null != jsData && jsData.size() != 0 ) 58 if(null != jsData && jsData.size() != 0 )
65 { 59 {
66 - JSONObject rObjec = new JSONObject(); 60 + JSONObject data = new JSONObject();
67 61
  62 + JSONObject config = new JSONObject();
68 63
69 for(String key:jsData.keySet()) 64 for(String key:jsData.keySet())
70 { 65 {
71 - IotThingsModel thingsModel = SysParameter.getTerminalDataThingsMode(userName,key); 66 + IotThingsModel thingsModel = terminalDataThingsModeService.getIotThingsModel(userName,key);
72 if(null == thingsModel) //没有配置的 都按字符串处理 67 if(null == thingsModel) //没有配置的 都按字符串处理
73 { 68 {
74 thingsModel = new IotThingsModel(); 69 thingsModel = new IotThingsModel();
@@ -78,12 +73,13 @@ public class DataModeAnalysisService { @@ -78,12 +73,13 @@ public class DataModeAnalysisService {
78 thingsModel.setIs_top(0); 73 thingsModel.setIs_top(0);
79 thingsModel.setIs_monitor(0); 74 thingsModel.setIs_monitor(0);
80 thingsModel.setIs_save_log(0); 75 thingsModel.setIs_save_log(0);
  76 + thingsModel.setIs_config(0);
81 JSONObject jsonObject = new JSONObject(); 77 JSONObject jsonObject = new JSONObject();
82 jsonObject.put("maxLength",255); 78 jsonObject.put("maxLength",255);
83 thingsModel.setSpecs(jsonObject.toString()); 79 thingsModel.setSpecs(jsonObject.toString());
84 } 80 }
85 String data_type = thingsModel.getData_type().toUpperCase(); 81 String data_type = thingsModel.getData_type().toUpperCase();
86 - if(!jsData.get(key).getClass().getSimpleName().toUpperCase().equals(data_type)) 82 + if(!EnumUtils.isValidEnum(ThingsModelDataTypeEnum.class,data_type))
87 { 83 {
88 data_type = ThingsModelDataTypeEnum.STRING.name(); 84 data_type = ThingsModelDataTypeEnum.STRING.name();
89 } 85 }
@@ -95,7 +91,7 @@ public class DataModeAnalysisService { @@ -95,7 +91,7 @@ public class DataModeAnalysisService {
95 91
96 ThingsModelItemBase thingsModelItemBase = (ThingsModelItemBase) thingsModelBase; 92 ThingsModelItemBase thingsModelItemBase = (ThingsModelItemBase) thingsModelBase;
97 //记录数据日志 93 //记录数据日志
98 - if(1==thingsModelItemBase.getIs_save_log()) 94 + if(1==thingsModelItemBase.getIs_save_log() && null != list)
99 { 95 {
100 DeviceSensorData sensorData = new DeviceSensorData(); 96 DeviceSensorData sensorData = new DeviceSensorData();
101 sensorData.setDataType(key); 97 sensorData.setDataType(key);
@@ -107,15 +103,22 @@ public class DataModeAnalysisService { @@ -107,15 +103,22 @@ public class DataModeAnalysisService {
107 } 103 }
108 104
109 //记录操作日志 105 //记录操作日志
110 - if(isOperLog) 106 + if(isOperLog && null != operateHisList)
111 { 107 {
112 operateHisList.add(dviceLogService.newLogDeviceOperation(id,thingsModelBase.getSaveView(),null,controlModel+thingsModelItemBase.getName()+"为"+thingsModelBase.getView(),jsData.toString())); 108 operateHisList.add(dviceLogService.newLogDeviceOperation(id,thingsModelBase.getSaveView(),null,controlModel+thingsModelItemBase.getName()+"为"+thingsModelBase.getView(),jsData.toString()));
113 } 109 }
114 110
115 - rObjec.put(key,thingsModelBase); 111 + if(1==thingsModel.getIs_config())
  112 + {
  113 + config.put(key,thingsModelBase);
  114 + }else{
  115 + data.put(key,thingsModelBase);
  116 + }
116 } 117 }
117 -  
118 - return rObjec; 118 + SaveDataDto saveDataDto = new SaveDataDto();
  119 + saveDataDto.setConfig(config);
  120 + saveDataDto.setData(data);
  121 + return saveDataDto;
119 } 122 }
120 return null; 123 return null;
121 } 124 }
@@ -17,7 +17,6 @@ public abstract class DataPersistenceService { @@ -17,7 +17,6 @@ public abstract class DataPersistenceService {
17 protected BaseDao baseDao = new BaseDao(); 17 protected BaseDao baseDao = new BaseDao();
18 18
19 public abstract void persistence(Topic topic, ServerDto serverDto); 19 public abstract void persistence(Topic topic, ServerDto serverDto);
20 - public abstract void addDeviceSensorData(Topic topic, ServerDto serverDto);  
21 20
22 /** 21 /**
23 * 记录操作日志 22 * 记录操作日志
1 package com.zhonglai.luhui.mqtt.comm.service; 1 package com.zhonglai.luhui.mqtt.comm.service;
2 2
  3 +import com.ruoyi.system.domain.IotDevice;
3 import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData; 4 import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData;
4 import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; 5 import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation;
5 import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; 6 import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
6 import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto; 7 import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto;
7 import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDtoClassNew; 8 import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDtoClassNew;
8 -import com.zhonglai.luhui.mqtt.comm.dto.iot.IotDevice;  
9 import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement; 9 import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement;
10 import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreementFactory; 10 import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreementFactory;
11 import com.zhonglai.luhui.mqtt.comm.factory.Topic; 11 import com.zhonglai.luhui.mqtt.comm.factory.Topic;
@@ -69,11 +69,15 @@ public class MqttCallback implements MqttCallbackExtended { @@ -69,11 +69,15 @@ public class MqttCallback implements MqttCallbackExtended {
69 byte[] data = mqttMessage.getPayload(); 69 byte[] data = mqttMessage.getPayload();
70 IotDevice iotDevice = deviceService.getDeviceById(topic.getClientid()); 70 IotDevice iotDevice = deviceService.getDeviceById(topic.getClientid());
71 71
72 - //转化为协议对象  
73 - BusinessDto businessDto = BusinessDtoClassNew.newBean(topic.getPayloadtype(),data).analyticalModel(iotDevice.getThings_model_value());  
74 -  
75 - BusinessAgreement businessAgreement = businessAgreementFactory.createBusinessAgreement(topic); 72 + if("ONLINE".equals(topic.getTopicType().toUpperCase()))
  73 + {
  74 + topic.setPayloadtype("String");
  75 + }
76 try { 76 try {
  77 + //转化为协议对象
  78 + BusinessDto businessDto = BusinessDtoClassNew.newBean(topic.getPayloadtype(),data).analyticalModel(iotDevice.getThings_model_value());
  79 +
  80 + BusinessAgreement businessAgreement = businessAgreementFactory.createBusinessAgreement(topic);
77 //解析为业务对象 81 //解析为业务对象
78 ServerDto dto = businessAgreement.analysis(topic,businessAgreement.toData(businessDto)); 82 ServerDto dto = businessAgreement.analysis(topic,businessAgreement.toData(businessDto));
79 if(null == dto) 83 if(null == dto)
@@ -87,7 +91,6 @@ public class MqttCallback implements MqttCallbackExtended { @@ -87,7 +91,6 @@ public class MqttCallback implements MqttCallbackExtended {
87 91
88 //数据持久化 92 //数据持久化
89 dataPersistenceService.persistence(topic,dto); 93 dataPersistenceService.persistence(topic,dto);
90 -  
91 } catch (Exception e) { 94 } catch (Exception e) {
92 log.error(s+"消息解析异常",e); 95 log.error(s+"消息解析异常",e);
93 } 96 }
1 package com.zhonglai.luhui.mqtt.comm.service; 1 package com.zhonglai.luhui.mqtt.comm.service;
2 2
3 import com.zhonglai.luhui.mqtt.comm.config.RedisConfig; 3 import com.zhonglai.luhui.mqtt.comm.config.RedisConfig;
  4 +import com.zhonglai.luhui.mqtt.comm.service.redis.RedisService;
  5 +import com.zhonglai.luhui.mqtt.service.db.DeviceService;
4 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
5 import org.springframework.data.redis.connection.Message; 7 import org.springframework.data.redis.connection.Message;
6 import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; 8 import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
@@ -15,6 +17,9 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene @@ -15,6 +17,9 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
15 @Autowired 17 @Autowired
16 private DataPersistenceService dtaPersistenceService; 18 private DataPersistenceService dtaPersistenceService;
17 19
  20 + @Autowired
  21 + private DeviceService deviceService ;
  22 +
18 public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) { 23 public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
19 super(listenerContainer); 24 super(listenerContainer);
20 } 25 }
@@ -22,9 +27,18 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene @@ -22,9 +27,18 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
22 @Override 27 @Override
23 public void onMessage(Message message, byte[] pattern) { 28 public void onMessage(Message message, byte[] pattern) {
24 String expiredKey = message.toString(); 29 String expiredKey = message.toString();
25 - if(expiredKey.startsWith(RedisConfig.getRedisKeyPath())) //指定设备离线 30 +
  31 + String devicePath = deviceService.getRedicDeviceKeyPath();
  32 + String terminalPath = deviceService.getRedicTerminalKeyPath();
  33 + if(expiredKey.startsWith(devicePath)) //如果是主机
  34 + {
  35 + String imei = expiredKey.replace(devicePath,"").replace(":","");
  36 + dtaPersistenceService.offLine(imei);
  37 + }
  38 +
  39 + if(expiredKey.startsWith(terminalPath)) //如果是终端
26 { 40 {
27 - String imei = expiredKey.replace(RedisConfig.getRedisKeyPath(),""); 41 + String imei = expiredKey.replace(devicePath,"").replace(":","");
28 dtaPersistenceService.offLine(imei); 42 dtaPersistenceService.offLine(imei);
29 } 43 }
30 } 44 }
1 package com.zhonglai.luhui.mqtt.comm.service; 1 package com.zhonglai.luhui.mqtt.comm.service;
2 2
3 -public interface TopicsService {  
4 - String getClienConnectionMapKey(String imei, String messageid);  
5 - String getTopicFromImei(String imei, String messageid);  
6 -}  
1 -package com.zhonglai.luhui.mqtt.comm.service; 1 +package com.zhonglai.luhui.mqtt.comm.service.redis;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import org.slf4j.Logger; 4 import org.slf4j.Logger;
1 package com.zhonglai.luhui.mqtt.controller; 1 package com.zhonglai.luhui.mqtt.controller;
2 2
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONArray;
3 import com.alibaba.fastjson.JSONObject; 5 import com.alibaba.fastjson.JSONObject;
  6 +import com.ruoyi.system.domain.IotDevice;
  7 +import com.ruoyi.system.domain.IotThingsModel;
  8 +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.ThingsModelDataTypeEnum;
  11 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
4 import com.zhonglai.luhui.mqtt.comm.service.ClienNoticeService; 12 import com.zhonglai.luhui.mqtt.comm.service.ClienNoticeService;
5 import com.zhonglai.luhui.mqtt.comm.util.DateUtils; 13 import com.zhonglai.luhui.mqtt.comm.util.DateUtils;
6 import com.zhonglai.luhui.mqtt.dto.Message; 14 import com.zhonglai.luhui.mqtt.dto.Message;
  15 +import com.zhonglai.luhui.mqtt.dto.MessageCode;
  16 +import com.zhonglai.luhui.mqtt.service.db.DeviceService;
  17 +import com.zhonglai.luhui.mqtt.service.db.mode.TerminalDataThingsModeService;
7 import io.swagger.annotations.Api; 18 import io.swagger.annotations.Api;
8 import io.swagger.annotations.ApiOperation; 19 import io.swagger.annotations.ApiOperation;
9 import org.eclipse.paho.client.mqttv3.MqttException; 20 import org.eclipse.paho.client.mqttv3.MqttException;
10 import org.eclipse.paho.client.mqttv3.MqttMessage; 21 import org.eclipse.paho.client.mqttv3.MqttMessage;
11 import org.springframework.beans.factory.annotation.Autowired; 22 import org.springframework.beans.factory.annotation.Autowired;
  23 +import org.springframework.transaction.annotation.Transactional;
12 import org.springframework.web.bind.annotation.*; 24 import org.springframework.web.bind.annotation.*;
13 25
  26 +import java.util.List;
14 import java.util.Map; 27 import java.util.Map;
15 28
16 @Api(tags = "设备操作") 29 @Api(tags = "设备操作")
@@ -20,25 +33,177 @@ public class DeviceController { @@ -20,25 +33,177 @@ public class DeviceController {
20 @Autowired 33 @Autowired
21 private ClienNoticeService clienNoticeService; 34 private ClienNoticeService clienNoticeService;
22 35
  36 + @Autowired
  37 + private TerminalDataThingsModeService terminalDataThingsModeService;
  38 +
  39 + private BaseDao baseDao = new BaseDao();
  40 +
  41 + @Autowired
  42 + private DeviceService deviceService ;
  43 +
23 @ApiOperation("控制发16进制指令") 44 @ApiOperation("控制发16进制指令")
24 @RequestMapping(value = "controlHex/{clienid}",method = RequestMethod.POST) 45 @RequestMapping(value = "controlHex/{clienid}",method = RequestMethod.POST)
25 public Message controlHex(@PathVariable String clienid, String data) throws MqttException, InterruptedException { 46 public Message controlHex(@PathVariable String clienid, String data) throws MqttException, InterruptedException {
  47 +
  48 + Topic topic = getTopicFromDb(clienid);
  49 + if(null == topic)
  50 + {
  51 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"mqtt_username查询失败");
  52 + }
  53 + topic.setTopicType("PUT");
  54 + topic.setMessageid(DateUtils.getNowTimeMilly()+"");
  55 +
26 MqttMessage mqttMessage = new MqttMessage(); 56 MqttMessage mqttMessage = new MqttMessage();
27 byte[] bs = hexStringToByte(data.trim().toUpperCase()); 57 byte[] bs = hexStringToByte(data.trim().toUpperCase());
28 mqttMessage.setPayload(bs); 58 mqttMessage.setPayload(bs);
29 - Message message = clienNoticeService.sendMessage(clienid,mqttMessage, DateUtils.getNowTimeMilly()+""); 59 +
  60 + Message message = clienNoticeService.sendMessage(topic,mqttMessage);
  61 + return message;
  62 + }
  63 +
  64 + @ApiOperation("读")
  65 + @RequestMapping(value = "read/{clienid}",method = RequestMethod.POST)
  66 + public Message read(@PathVariable String clienid,@RequestBody Map<String,Object> map) throws MqttException, InterruptedException {
  67 +
  68 + if(null == map || map.size() ==0)
  69 + {
  70 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"参数验证失败");
  71 + }
  72 +
  73 + Topic topic = getTopicFromDb(clienid);
  74 + if(null == topic)
  75 + {
  76 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"mqtt_username查询失败");
  77 + }
  78 + topic.setTopicType("READ");
  79 + topic.setMessageid(DateUtils.getNowTimeMilly()+"");
  80 + MqttMessage mqttMessage = new MqttMessage();
  81 + mqttMessage.setPayload(JSON.toJSONString(map).trim().getBytes());
  82 + Message message = clienNoticeService.sendMessage(topic,mqttMessage);
30 return message; 83 return message;
31 } 84 }
32 85
  86 + @ApiOperation("强行断开链接")
  87 + @RequestMapping(value = "closeSession/{clienid}",method = RequestMethod.POST)
  88 + public Message closeSession(@PathVariable String clienid) throws MqttException, InterruptedException {
  89 +
  90 + MqttMessage mqttMessage = new MqttMessage();
  91 + byte[] bs = hexStringToByte(clienid.trim().toUpperCase());
  92 + mqttMessage.setPayload(bs);
  93 +
  94 + clienNoticeService.sendMessage("CLOSE",mqttMessage);
  95 + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"端口请求已发送");
  96 + }
  97 +
  98 + @ApiOperation("删除主机")
  99 + @Transactional
  100 + @RequestMapping(value = "delIotDevice/{client_id}",method = RequestMethod.POST)
  101 + public Message delIotDevice(@PathVariable String client_id) throws MqttException, InterruptedException {
  102 + deviceService.lockIotDevice(client_id);//先锁定
  103 + closeSession(client_id); //强制下线
  104 + baseDao.updateBySql("DELETE FROM `iot_terminal` WHERE device_id='"+client_id+"'");
  105 + baseDao.updateBySql("DELETE FROM `iot_device` WHERE client_id='"+client_id+"'");
  106 + deviceService.unlockIotDevice(client_id);//解锁
  107 + return new Message(MessageCode.DEFAULT_SUCCESS_CODE);
  108 + }
  109 +
  110 + @ApiOperation("删除终端")
  111 + @Transactional
  112 + @RequestMapping(value = "delIotTerminal/{client_id}/{number}",method = RequestMethod.POST)
  113 + public Message delIotTerminal(@PathVariable String client_id,@PathVariable String number) throws MqttException, InterruptedException {
  114 + deviceService.lockIotDevice(client_id);//先锁定
  115 + closeSession(client_id); //强制下线
  116 + baseDao.updateBySql("DELETE FROM `iot_terminal` WHERE id='"+client_id+"_"+number+"'");
  117 + deviceService.unlockIotDevice(client_id);//解锁
  118 + return new Message(MessageCode.DEFAULT_SUCCESS_CODE);
  119 + }
  120 +
33 @ApiOperation("控制发json") 121 @ApiOperation("控制发json")
34 @RequestMapping(value = "control/{clienid}",method = RequestMethod.POST) 122 @RequestMapping(value = "control/{clienid}",method = RequestMethod.POST)
35 - public Message control(@PathVariable String clienid, @RequestBody String map) throws MqttException, InterruptedException { 123 + public Message control(@PathVariable String clienid,@RequestBody Map<String,Object> map) throws MqttException, InterruptedException {
  124 +
  125 + if(null == map || map.size() ==0)
  126 + {
  127 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"参数验证失败");
  128 + }
  129 +
  130 + Topic topic = getTopicFromDb(clienid);
  131 + if(null == topic)
  132 + {
  133 + return new Message(MessageCode.DEFAULT_FAIL_CODE,"mqtt_username查询失败");
  134 + }
  135 + topic.setTopicType("PUT");
  136 + topic.setMessageid(DateUtils.getNowTimeMilly()+"");
  137 +
  138 + for(String key:map.keySet())
  139 + {
  140 + Object sendMap = map.get(key);
  141 + JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(sendMap));
  142 + for(String skey:jsonObject.keySet())
  143 + {
  144 + IotThingsModel thingsModel = terminalDataThingsModeService.getIotThingsModel(topic.getUsername(),skey);
  145 + if(null == thingsModel) //没有配置的 都按字符串处理
  146 + {
  147 + thingsModel = new IotThingsModel();
  148 + thingsModel.setData_type(ThingsModelDataTypeEnum.STRING.name());
  149 + thingsModel.setIdentifier(key);
  150 + thingsModel.setModel_name(key);
  151 + thingsModel.setIs_top(0);
  152 + thingsModel.setIs_monitor(0);
  153 + thingsModel.setIs_save_log(0);
  154 + thingsModel.setIs_config(0);
  155 + JSONObject spes = new JSONObject();
  156 + spes.put("maxLength",255);
  157 + thingsModel.setSpecs(spes.toString());
  158 + }
  159 + String data_type = thingsModel.getData_type().toUpperCase();
  160 + Class<ThingsModelBase> aClass = Enum.valueOf(ThingsModelDataTypeEnum.class,data_type).getaClass();
  161 + ThingsModelBase thingsModelBase = JSON.parseObject(thingsModel.getSpecs(),aClass);
  162 + jsonObject.put(skey,thingsModelBase.getCmdView(jsonObject.get(skey)));
  163 + }
  164 +
  165 + map.put(key,jsonObject);
  166 + }
  167 +
36 MqttMessage mqttMessage = new MqttMessage(); 168 MqttMessage mqttMessage = new MqttMessage();
37 - mqttMessage.setPayload(map.trim().getBytes());  
38 - Message message = clienNoticeService.sendMessage(clienid,mqttMessage, DateUtils.getNowTimeMilly()+""); 169 + mqttMessage.setPayload(JSON.toJSONString(map).trim().getBytes());
  170 + Message message = clienNoticeService.sendMessage(topic,mqttMessage);
39 return message; 171 return message;
40 } 172 }
41 173
  174 + @ApiOperation("获取指定设备版本信息")
  175 + @RequestMapping(value = "getFirmwareVersion/{app_type}",method = RequestMethod.POST)
  176 + public Message getFirmwareVersion(@PathVariable String app_type)
  177 + {
  178 + List list = baseDao.findListBysql("SELECT md5str,upload_file_path uploadFilePath,version_number versionNumber FROM liu_yu_le.`app_file_upgrade` WHERE app_type='"+app_type+"' ORDER BY id DESC limit 5");
  179 + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,list);
  180 + }
  181 +
  182 + @ApiOperation("测试")
  183 + @RequestMapping(value = "test",method = RequestMethod.GET)
  184 + public Message test(String mqtt_username)
  185 + {
  186 + Map<String, IotThingsModel> map = terminalDataThingsModeService.getUserIotThingsModel(mqtt_username);
  187 + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,map);
  188 + }
  189 +
  190 + /**
  191 + * 通过数据获取发送消息的topic
  192 + * @param clienid
  193 + * @return
  194 + */
  195 + private Topic getTopicFromDb(String clienid)
  196 + {
  197 + JSONArray jsonArray = baseDao.findBysql("SELECT b.`role_id` roleid,b.`mqtt_username` username,a.`client_id` clientid,a.`payload_type` payloadtype FROM `iot_device` a LEFT JOIN `iot_product` b ON a.`product_id`=b.`id` WHERE client_id='"+clienid+"'");
  198 + if(null == jsonArray || jsonArray.size()==0 || null == jsonArray.getJSONObject(0).get("username"))
  199 + {
  200 + return null;
  201 + }
  202 + Topic topic = JSON.parseObject( jsonArray.getJSONObject(0).toJSONString(),Topic.class);
  203 + topic.setTopicType("PUT");
  204 + topic.setMessageid(DateUtils.getNowTimeMilly()+"");
  205 + return topic;
  206 + }
42 /** 207 /**
43 * 把16进制字符串转换成字节数组 208 * 把16进制字符串转换成字节数组
44 * 209 *
  1 +package com.zhonglai.luhui.mqtt.dto;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +
  5 +/**
  6 + * 入库数据对象
  7 + */
  8 +public class SaveDataDto {
  9 + private JSONObject data;
  10 + private JSONObject config;
  11 +
  12 + public JSONObject getData() {
  13 + return data;
  14 + }
  15 +
  16 + public void setData(JSONObject data) {
  17 + this.data = data;
  18 + }
  19 +
  20 + public JSONObject getConfig() {
  21 + return config;
  22 + }
  23 +
  24 + public void setConfig(JSONObject config) {
  25 + this.config = config;
  26 + }
  27 +}
@@ -12,6 +12,7 @@ import java.util.List; @@ -12,6 +12,7 @@ import java.util.List;
12 @Data 12 @Data
13 @Accessors(chain = true) 13 @Accessors(chain = true)
14 public class OnlineDto implements ServerDto { 14 public class OnlineDto implements ServerDto {
  15 + private Integer state;
15 @Override 16 @Override
16 public ServerAgreementContent getServerAgreementContent() { 17 public ServerAgreementContent getServerAgreementContent() {
17 return null; 18 return null;
@@ -24,10 +24,6 @@ public class PutReqDto implements ServerDto { @@ -24,10 +24,6 @@ public class PutReqDto implements ServerDto {
24 public ServerAgreementContent getServerAgreementContent() { 24 public ServerAgreementContent getServerAgreementContent() {
25 PutReqDto putReqDto = this; 25 PutReqDto putReqDto = this;
26 return new ServerAgreementContent() { 26 return new ServerAgreementContent() {
27 - @Override  
28 - public String getClienConnectionId() {  
29 - return putReqDto.getMessageid();  
30 - }  
31 27
32 @Override 28 @Override
33 public byte[] getCommd() { 29 public byte[] getCommd() {
@@ -43,12 +39,14 @@ public class PutReqDto implements ServerDto { @@ -43,12 +39,14 @@ public class PutReqDto implements ServerDto {
43 39
44 @Override 40 @Override
45 public void setReplyMessage(Message message) { 41 public void setReplyMessage(Message message) {
46 - message.setData(putReqDto); 42 + message.setData(data);
47 message.setCode(MessageCode.DEFAULT_SUCCESS_CODE); 43 message.setCode(MessageCode.DEFAULT_SUCCESS_CODE);
  44 + message.setMessage("成功");
48 switch (code) 45 switch (code)
49 { 46 {
50 case 0: 47 case 0:
51 message.setCode(MessageCode.DEFAULT_FAIL_CODE); 48 message.setCode(MessageCode.DEFAULT_FAIL_CODE);
  49 + message.setMessage("失败");
52 break; 50 break;
53 } 51 }
54 } 52 }
  1 +package com.zhonglai.luhui.mqtt.dto.topic;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData;
  5 +import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation;
  6 +import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent;
  7 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  8 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  9 +import com.zhonglai.luhui.mqtt.dto.Message;
  10 +import com.zhonglai.luhui.mqtt.dto.MessageCode;
  11 +import lombok.Data;
  12 +import lombok.experimental.Accessors;
  13 +
  14 +import java.util.ArrayList;
  15 +import java.util.HashMap;
  16 +import java.util.List;
  17 +
  18 +@Data
  19 +@Accessors(chain = true)
  20 +public class ReadReqDto implements ServerDto {
  21 + private Integer code;
  22 + private JSONObject data;
  23 + private String messageid;
  24 + private List<LogDeviceOperation> operateHisList = new ArrayList<>();
  25 + private List<DeviceSensorData> list = new ArrayList<>();
  26 + @Override
  27 + public ServerAgreementContent getServerAgreementContent() {
  28 + ReadReqDto readReqDto = this;
  29 + return new ServerAgreementContent() {
  30 +
  31 + @Override
  32 + public byte[] getCommd() {
  33 + JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(readReqDto));
  34 + jsonObject.remove("messageid");
  35 + return jsonObject.toJSONString().getBytes();
  36 + }
  37 +
  38 + @Override
  39 + public String getReplyCommdTopic(Topic topic) {
  40 + return null;
  41 + }
  42 +
  43 + @Override
  44 + public void setReplyMessage(Message message) {
  45 + if(null != readReqDto.data)
  46 + {
  47 + message.setData(JSONObject.parseObject(readReqDto.data.toJSONString(), HashMap.class));
  48 + }
  49 + message.setCode(MessageCode.DEFAULT_SUCCESS_CODE);
  50 + message.setMessage("成功");
  51 + switch (code)
  52 + {
  53 + case 0:
  54 + message.setCode(MessageCode.DEFAULT_FAIL_CODE);
  55 + message.setMessage("失败");
  56 + break;
  57 + }
  58 + }
  59 + };
  60 + }
  61 +
  62 + @Override
  63 + public boolean isReplyMessage() {
  64 + return true;
  65 + }
  66 +
  67 + @Override
  68 + public List<DeviceSensorData> getDeviceSensorData() {
  69 + return null;
  70 + }
  71 +
  72 + @Override
  73 + public List<LogDeviceOperation> getOperationLog() {
  74 + return null;
  75 + }
  76 +}
@@ -24,13 +24,14 @@ public class DataPersistenceServiceImpl extends DataPersistenceService { @@ -24,13 +24,14 @@ public class DataPersistenceServiceImpl extends DataPersistenceService {
24 @Override 24 @Override
25 public void persistence(Topic topic, ServerDto serverDto) { 25 public void persistence(Topic topic, ServerDto serverDto) {
26 26
27 - //日志入库 27 + //曲线数据入库
28 List<DeviceSensorData> dsdList = serverDto.getDeviceSensorData(); 28 List<DeviceSensorData> dsdList = serverDto.getDeviceSensorData();
29 if(null != dsdList && dsdList.size() != 0) 29 if(null != dsdList && dsdList.size() != 0)
30 { 30 {
31 dviceLogService.saveDeviceSensorDataLog(dsdList); 31 dviceLogService.saveDeviceSensorDataLog(dsdList);
32 } 32 }
33 33
  34 + //日志入库
34 List<LogDeviceOperation> doList = serverDto.getOperationLog(); 35 List<LogDeviceOperation> doList = serverDto.getOperationLog();
35 if(null != doList && doList.size() != 0) 36 if(null != doList && doList.size() != 0)
36 { 37 {
@@ -39,27 +40,6 @@ public class DataPersistenceServiceImpl extends DataPersistenceService { @@ -39,27 +40,6 @@ public class DataPersistenceServiceImpl extends DataPersistenceService {
39 } 40 }
40 41
41 @Override 42 @Override
42 - public void addDeviceSensorData(Topic topic, ServerDto serverDto) {  
43 - if(serverDto instanceof AddPostDto)  
44 - {  
45 - AddPostDto addPostDto = (AddPostDto) serverDto;  
46 - List<DeviceSensorData> list = addPostDto.getList();  
47 - if(null != list && list.size() != 0)  
48 - {  
49 - baseDao.insertList(list, TableGenerateSqlEnum.DeviceSensorData.getNowTableName());  
50 - }  
51 - }else if(serverDto instanceof AllPostDto)  
52 - {  
53 - AllPostDto allPostDto = (AllPostDto) serverDto;  
54 - List<DeviceSensorData> list = allPostDto.getList();  
55 - if(null != list && list.size() != 0)  
56 - {  
57 - baseDao.insertList(list, TableGenerateSqlEnum.DeviceSensorData.getNowTableName());  
58 - }  
59 - }  
60 - }  
61 -  
62 - @Override  
63 public String[] upDeviceInfoOffLine(String s) { 43 public String[] upDeviceInfoOffLine(String s) {
64 return new String[0]; 44 return new String[0];
65 } 45 }
1 -package com.zhonglai.luhui.mqtt.service;  
2 -  
3 -import com.zhonglai.luhui.mqtt.comm.service.TopicsService;  
4 -import org.springframework.stereotype.Service;  
5 -  
6 -@Service  
7 -public class TopicsServiceImpl implements TopicsService {  
8 - @Override  
9 - public String getClienConnectionMapKey(String imei, String messageid) {  
10 - return "/2/2/X6/"+imei+"/PUT";  
11 - }  
12 -  
13 - @Override  
14 - public String getTopicFromImei(String imei, String messageid) {  
15 - return "/2/6_W/"+imei+"/Json/PUT";  
16 - }  
17 -}  
1 package com.zhonglai.luhui.mqtt.service.db; 1 package com.zhonglai.luhui.mqtt.service.db;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
  4 +import com.ruoyi.system.domain.IotDevice;
  5 +import com.ruoyi.system.domain.IotTerminal;
4 import com.zhonglai.luhui.mqtt.comm.config.RedisConfig; 6 import com.zhonglai.luhui.mqtt.comm.config.RedisConfig;
5 import com.zhonglai.luhui.mqtt.comm.dao.BaseDao; 7 import com.zhonglai.luhui.mqtt.comm.dao.BaseDao;
6 -import com.zhonglai.luhui.mqtt.comm.dto.iot.IotDevice;  
7 -import com.zhonglai.luhui.mqtt.comm.dto.iot.IotTerminal;  
8 -import com.zhonglai.luhui.mqtt.comm.dto.iot.IotThingsModel;  
9 -import com.zhonglai.luhui.mqtt.comm.service.RedisService;  
10 -import com.zhonglai.luhui.mqtt.comm.util.DateUtils; 8 +import com.zhonglai.luhui.mqtt.comm.service.redis.RedisService;
11 import org.apache.commons.lang3.StringUtils; 9 import org.apache.commons.lang3.StringUtils;
12 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.stereotype.Service; 11 import org.springframework.stereotype.Service;
@@ -70,7 +68,7 @@ public class DeviceService { @@ -70,7 +68,7 @@ public class DeviceService {
70 public void updataDevice(IotDevice iotDevice) 68 public void updataDevice(IotDevice iotDevice)
71 { 69 {
72 setRedicDevice(iotDevice); 70 setRedicDevice(iotDevice);
73 - baseDao.saveOrUpdateObject(iotDevice); 71 + baseDao.update(iotDevice,"client_id");
74 } 72 }
75 73
76 /** 74 /**
@@ -80,7 +78,17 @@ public class DeviceService { @@ -80,7 +78,17 @@ public class DeviceService {
80 */ 78 */
81 private boolean setRedicDevice(IotDevice device) 79 private boolean setRedicDevice(IotDevice device)
82 { 80 {
83 - return redisService.setexDevice(RedisConfig.FIELD+RedisConfig.DEVICE+device.getClient_id(),device); 81 + return redisService.setexDevice(getRedicDeviceKey(device.getClient_id()),device);
  82 + }
  83 +
  84 + public String getRedicDeviceKey(String client_id)
  85 + {
  86 + return getRedicDeviceKeyPath()+client_id;
  87 + }
  88 +
  89 + public String getRedicDeviceKeyPath()
  90 + {
  91 + return RedisConfig.FIELD+RedisConfig.DEVICE;
84 } 92 }
85 93
86 /** 94 /**
@@ -95,15 +103,12 @@ public class DeviceService { @@ -95,15 +103,12 @@ public class DeviceService {
95 { 103 {
96 IotTerminal terminal = getTerminalById(id); 104 IotTerminal terminal = getTerminalById(id);
97 105
98 - IotTerminal saveTerminal = new IotTerminal();  
99 - saveTerminal.setId(id);  
100 if(null == terminal) 106 if(null == terminal)
101 { 107 {
102 - baseDao.saveOrUpdateObject(saveTerminal); 108 + return null;
103 }else{ 109 }else{
104 - saveTerminal.setThings_model_value(terminal.getThings_model_value()); 110 + return terminal;
105 } 111 }
106 - return saveTerminal;  
107 } 112 }
108 return (IotTerminal)object; 113 return (IotTerminal)object;
109 } 114 }
@@ -114,8 +119,19 @@ public class DeviceService { @@ -114,8 +119,19 @@ public class DeviceService {
114 */ 119 */
115 private boolean setRedicTerminal(IotTerminal terminal) 120 private boolean setRedicTerminal(IotTerminal terminal)
116 { 121 {
117 - return redisService.setexDevice(RedisConfig.FIELD+RedisConfig.TERMINAL+terminal.getId(),terminal); 122 + return redisService.setexDevice(getRedicTerminalKey(terminal.getId()),terminal);
118 } 123 }
  124 +
  125 + public String getRedicTerminalKey(String terminal_id)
  126 + {
  127 + return getRedicTerminalKeyPath()+terminal_id;
  128 + }
  129 +
  130 + public String getRedicTerminalKeyPath()
  131 + {
  132 + return RedisConfig.FIELD+RedisConfig.TERMINAL;
  133 + }
  134 +
119 public void updataTerminal(IotTerminal terminal) 135 public void updataTerminal(IotTerminal terminal)
120 { 136 {
121 setRedicTerminal(terminal); 137 setRedicTerminal(terminal);
@@ -141,4 +157,35 @@ public class DeviceService { @@ -141,4 +157,35 @@ public class DeviceService {
141 } 157 }
142 return oldjs; 158 return oldjs;
143 } 159 }
  160 +
  161 + /**
  162 + * 上锁
  163 + * @param clint_id
  164 + */
  165 + public void lockIotDevice(String clint_id)
  166 + {
  167 + redisService.setexDevice(RedisConfig.FIELD+RedisConfig.LOCK+clint_id,1);
  168 + }
  169 + /**
  170 + * 获取锁
  171 + * @param clint_id
  172 + */
  173 + public int getlockIotDevice(String clint_id)
  174 + {
  175 + Object object = redisService.get(RedisConfig.FIELD+RedisConfig.LOCK+clint_id);
  176 + if(null==object)
  177 + {
  178 + return 0;
  179 + }
  180 + return (int)object;
  181 + }
  182 +
  183 + /**
  184 + * 解锁锁
  185 + * @param clint_id
  186 + */
  187 + public void unlockIotDevice(String clint_id)
  188 + {
  189 + redisService.del(RedisConfig.FIELD+RedisConfig.LOCK+clint_id);
  190 + }
144 } 191 }
  1 +package com.zhonglai.luhui.mqtt.service.db.mode;
  2 +
  3 +import com.ruoyi.system.domain.IotThingsModel;
  4 +import com.zhonglai.luhui.mqtt.comm.service.redis.RedisService;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.stereotype.Service;
  7 +
  8 +import java.util.HashMap;
  9 +import java.util.List;
  10 +import java.util.Map;
  11 +
  12 +/**
  13 + * 终端数据模型服务
  14 + *
  15 + * 存储redis
  16 + * 存储结构:
  17 + * luhui:service:mqtt:terminalDataThingsMode:${deviceTypeKey}
  18 + * {
  19 + * "${identifier}":IotThingsModel
  20 + * }
  21 + */
  22 +@Service
  23 +public class TerminalDataThingsModeService {
  24 + @Autowired
  25 + private RedisService redisService;
  26 + private static String deviceTypeKeyPath="luhui:service:mqtt:terminalDataThingsMode:"; //设备类型key路径
  27 +
  28 + /**
  29 + * 保存模型
  30 + * @param iotThingsModel
  31 + */
  32 + public void saveIotThingsModel(IotThingsModel iotThingsModel)
  33 + {
  34 + redisService.hset(deviceTypeKeyPath+iotThingsModel.getMqtt_username(),iotThingsModel.getIdentifier(),iotThingsModel);
  35 + }
  36 +
  37 + /**
  38 + * 删除模型
  39 + */
  40 + public void delIotThingsModel(String mqtt_username, Object... identifiers)
  41 + {
  42 + redisService.sRemove(deviceTypeKeyPath+mqtt_username,identifiers);
  43 + }
  44 +
  45 + /**
  46 + * 批量保存指定用户模型保存模型
  47 + * @param iotThingsModels
  48 + */
  49 + public void saveIotThingsModelToUser(List<IotThingsModel> iotThingsModels)
  50 + {
  51 + if(null != iotThingsModels && iotThingsModels.size() !=0)
  52 + {
  53 + Map<String,Map<Object,Object>> all = new HashMap<>();
  54 + for(IotThingsModel iotThingsModel:iotThingsModels)
  55 + {
  56 + Map<Object,Object> map = all.get(iotThingsModel.getMqtt_username());
  57 + if(null == map)
  58 + {
  59 + map = new HashMap<>();
  60 + all.put(iotThingsModel.getMqtt_username(),map);
  61 + }
  62 + map.put(iotThingsModel.getIdentifier(),iotThingsModel);
  63 + }
  64 +
  65 + if(null != all && all.size() !=0)
  66 + {
  67 + for(Object key:all.keySet())
  68 + {
  69 + redisService.hmset(deviceTypeKeyPath+key,all.get(key));
  70 + }
  71 + }
  72 + }
  73 + }
  74 +
  75 + /**
  76 + * 获取模型
  77 + * @param mqtt_username
  78 + * @param identifier
  79 + */
  80 + public IotThingsModel getIotThingsModel(String mqtt_username,String identifier)
  81 + {
  82 + if(redisService.hHashKey(deviceTypeKeyPath+mqtt_username,identifier))
  83 + {
  84 + return (IotThingsModel) redisService.hget(deviceTypeKeyPath+mqtt_username,identifier);
  85 + }
  86 + return null;
  87 + }
  88 +
  89 + /**
  90 + * 获取用户下所有模型模型
  91 + * @param mqtt_username
  92 + */
  93 + public Map<String, IotThingsModel> getUserIotThingsModel(String mqtt_username )
  94 + {
  95 + if(redisService.hasKey(deviceTypeKeyPath+mqtt_username))
  96 + {
  97 + return redisService.hmgetObject(deviceTypeKeyPath+mqtt_username, HashMap.class);
  98 + }
  99 + return null;
  100 + }
  101 +
  102 + /**
  103 + * 获取用户下所有指定标识符模型模型
  104 + * @param mqtt_username
  105 + */
  106 + public Map<String, Object> getUserIotThingsModelByIdentifier(String mqtt_username,String... identifiers)
  107 + {
  108 + return redisService.hmget(deviceTypeKeyPath+mqtt_username,identifiers);
  109 + }
  110 +
  111 +}
@@ -21,7 +21,6 @@ public class AddPostTopic implements BusinessAgreement<AddPostDto> { @@ -21,7 +21,6 @@ public class AddPostTopic implements BusinessAgreement<AddPostDto> {
21 private BusinessDataUpdateService businessDataUpdateService ; 21 private BusinessDataUpdateService businessDataUpdateService ;
22 @Override 22 @Override
23 public ServerDto analysis(Topic topic, AddPostDto data) { 23 public ServerDto analysis(Topic topic, AddPostDto data) {
24 -  
25 businessDataUpdateService.updataDta(BusinessDataUpdateService.Type.ADD,topic,data.getData(),true,data.getOperateHisList(),data.getList()); 24 businessDataUpdateService.updataDta(BusinessDataUpdateService.Type.ADD,topic,data.getData(),true,data.getOperateHisList(),data.getList());
26 return data; 25 return data;
27 } 26 }
@@ -12,11 +12,13 @@ import org.springframework.stereotype.Service; @@ -12,11 +12,13 @@ import org.springframework.stereotype.Service;
12 public class OnlineTopic implements BusinessAgreement<OnlineDto> { 12 public class OnlineTopic implements BusinessAgreement<OnlineDto> {
13 @Override 13 @Override
14 public ServerDto analysis(Topic topic, OnlineDto data) throws Exception { 14 public ServerDto analysis(Topic topic, OnlineDto data) throws Exception {
15 - return null; 15 + return data;
16 } 16 }
17 17
18 @Override 18 @Override
19 public OnlineDto toData(BusinessDto data) { 19 public OnlineDto toData(BusinessDto data) {
20 - return null; 20 + OnlineDto onlineDto = new OnlineDto();
  21 + onlineDto.setState(Integer.parseInt(new String((byte[]) data.getContentData())));
  22 + return onlineDto;
21 } 23 }
22 } 24 }
@@ -23,17 +23,14 @@ public class PutReqTopic implements BusinessAgreement<PutReqDto> { @@ -23,17 +23,14 @@ public class PutReqTopic implements BusinessAgreement<PutReqDto> {
23 23
24 @Override 24 @Override
25 public ServerDto analysis(Topic topic, PutReqDto data) throws Exception { 25 public ServerDto analysis(Topic topic, PutReqDto data) throws Exception {
  26 + data.setMessageid(topic.getMessageid());
  27 + clienNoticeService.replySendMessage(topic,data);
26 return null; 28 return null;
27 } 29 }
28 30
29 @Override 31 @Override
30 public PutReqDto toData(BusinessDto data) { 32 public PutReqDto toData(BusinessDto data) {
31 - PutReqDto putReqDto = new PutReqDto();  
32 - return putReqDto.setData((String) data.getContentData());  
33 - }  
34 -  
35 - private void replyTerminalMessage(Topic topic,ServerDto dto) throws MqttException {  
36 - //回复终端消息  
37 - clienNoticeService.replyTerminalMessage(topic,dto); 33 + PutReqDto putReqDto = JSONObject.parseObject(((JSONObject) data.getContentData()).toJSONString(),PutReqDto.class);
  34 + return putReqDto;
38 } 35 }
39 } 36 }
  1 +package com.zhonglai.luhui.mqtt.service.topic;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.ruoyi.system.domain.IotThingsModel;
  6 +import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData;
  7 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  8 +import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto;
  9 +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelBase;
  10 +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelDataTypeEnum;
  11 +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase;
  12 +import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement;
  13 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  14 +import com.zhonglai.luhui.mqtt.comm.service.BusinessDataUpdateService;
  15 +import com.zhonglai.luhui.mqtt.comm.service.ClienNoticeService;
  16 +import com.zhonglai.luhui.mqtt.comm.service.DataModeAnalysisService;
  17 +import com.zhonglai.luhui.mqtt.comm.util.DateUtils;
  18 +import com.zhonglai.luhui.mqtt.dto.SaveDataDto;
  19 +import com.zhonglai.luhui.mqtt.dto.topic.AddPostDto;
  20 +import com.zhonglai.luhui.mqtt.dto.topic.ReadReqDto;
  21 +import com.zhonglai.luhui.mqtt.service.db.mode.TerminalDataThingsModeService;
  22 +import org.apache.commons.lang3.EnumUtils;
  23 +import org.springframework.beans.factory.annotation.Autowired;
  24 +import org.springframework.stereotype.Service;
  25 +
  26 +@Service("READ_REQ")
  27 +public class ReadReqTopic implements BusinessAgreement<ReadReqDto> {
  28 + @Autowired
  29 + private ClienNoticeService clienNoticeService; //客户端通知服务
  30 + @Autowired
  31 + private BusinessDataUpdateService businessDataUpdateService ;
  32 +
  33 + @Autowired
  34 + private TerminalDataThingsModeService terminalDataThingsModeService;
  35 +
  36 + @Override
  37 + public ServerDto analysis(Topic topic, ReadReqDto data) {
  38 + if(1==data.getCode())
  39 + {
  40 + JSONObject vjsonObject = data.getData().clone();
  41 + businessDataUpdateService.updataDta(BusinessDataUpdateService.Type.ADD,topic,data.getData(),true,data.getOperateHisList(),data.getList());
  42 +
  43 + if(null != vjsonObject && vjsonObject.size() !=0 )
  44 + {
  45 + for(String vkey:vjsonObject.keySet())
  46 + {
  47 + JSONObject jsData = vjsonObject.getJSONObject(vkey);
  48 + for(String key:jsData.keySet())
  49 + {
  50 + IotThingsModel thingsModel = terminalDataThingsModeService.getIotThingsModel(topic.getUsername(),key);
  51 + if(null == thingsModel) //没有配置的 都按字符串处理
  52 + {
  53 + thingsModel = new IotThingsModel();
  54 + thingsModel.setData_type(ThingsModelDataTypeEnum.STRING.name());
  55 + thingsModel.setIdentifier(key);
  56 + thingsModel.setModel_name(key);
  57 + thingsModel.setIs_top(0);
  58 + thingsModel.setIs_monitor(0);
  59 + thingsModel.setIs_save_log(0);
  60 + thingsModel.setIs_config(0);
  61 + JSONObject jsonObject = new JSONObject();
  62 + jsonObject.put("maxLength",255);
  63 + thingsModel.setSpecs(jsonObject.toString());
  64 + }
  65 + String data_type = thingsModel.getData_type().toUpperCase();
  66 + if(!EnumUtils.isValidEnum(ThingsModelDataTypeEnum.class,data_type))
  67 + {
  68 + data_type = ThingsModelDataTypeEnum.STRING.name();
  69 + }
  70 + Class<ThingsModelBase> aClass = Enum.valueOf(ThingsModelDataTypeEnum.class,data_type).getaClass();
  71 + ThingsModelBase thingsModelBase = JSON.parseObject(thingsModel.getSpecs(),aClass);
  72 + thingsModelBase.conversionThingsModel(thingsModel);
  73 +
  74 + thingsModelBase.addValue(jsData.get(key));
  75 + jsData.put(key,thingsModelBase);
  76 + }
  77 + vjsonObject.put(vkey,jsData);
  78 + }
  79 + data.setData(vjsonObject);
  80 + }
  81 + clienNoticeService.replySendMessage(topic,data);
  82 + return data;
  83 + }else if(0==data.getCode())
  84 + {
  85 + clienNoticeService.replySendMessage(topic,data);
  86 + return data;
  87 + }
  88 + return null;
  89 + }
  90 +
  91 + @Override
  92 + public ReadReqDto toData(BusinessDto data) {
  93 + return JSONObject.parseObject(JSONObject.toJSONString(data.getContentData()),ReadReqDto.class);
  94 + }
  95 +}
@@ -2,8 +2,8 @@ @@ -2,8 +2,8 @@
2 server: 2 server:
3 tomcat: 3 tomcat:
4 uri-encoding: UTF-8 4 uri-encoding: UTF-8
5 - port: 4881  
6 - context-path: /lh-mqtt-service 5 + port: 4883
  6 + context-path: /
7 7
8 spring: 8 spring:
9 messages: 9 messages:
@@ -42,10 +42,11 @@ mqtt: @@ -42,10 +42,11 @@ mqtt:
42 #链接地址 42 #链接地址
43 broker: tcp://175.24.61.68:1883 43 broker: tcp://175.24.61.68:1883
44 #唯一标识 44 #唯一标识
45 - clientId: lh-mqtt-service-002 45 + clientId: lh-mqtt-service-003
46 #订阅的topic 46 #订阅的topic
47 - topics: "/2/+/+/+/ADD_POST,/2/+/+/+/ALL_POST,/2/+/+/+/DB_TOPIC_DISTRIBUTE,/2/+/+/+/GET,/2/+/+/+/online,/2/+/+/+/PUT_REQ"  
48 - topicconfig: "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{topicType}}" 47 + topics: "/2/+/+/+/ADD_POST,/2/+/+/+/ALL_POST,/2/+/+/+/DB_TOPIC_DISTRIBUTE,/2/+/+/+/GET/+,/2/+/+/+/online,/2/+/+/+/PUT_REQ/+,/2/+/+/+/READ_REQ/+"
  48 + topicconfig: "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{topicType}}/{{messageid}}"
  49 + top_return_map: '{"PUT":"PUT_REQ","READ":"READ_REQ"}'
49 username: sysuser 50 username: sysuser
50 password: "!@#1qaz" 51 password: "!@#1qaz"
51 client: 52 client:
@@ -61,5 +62,5 @@ mqtt: @@ -61,5 +62,5 @@ mqtt:
61 62
62 sys: 63 sys:
63 redis: 64 redis:
64 - field: "lh:mqtt:service:"  
65 - 65 + field: "luhui:mqttservice:device:"
  66 + isText: true
@@ -14,6 +14,7 @@ @@ -14,6 +14,7 @@
14 <module>ruoyi-common</module> 14 <module>ruoyi-common</module>
15 <module>lh-admin</module> 15 <module>lh-admin</module>
16 <module>lh-mqtt-service</module> 16 <module>lh-mqtt-service</module>
  17 + <module>lh-domain</module>
17 </modules> 18 </modules>
18 19
19 <packaging>pom</packaging> 20 <packaging>pom</packaging>
@@ -60,6 +61,7 @@ @@ -60,6 +61,7 @@
60 <scope>import</scope> 61 <scope>import</scope>
61 </dependency> 62 </dependency>
62 63
  64 +
63 <!-- 阿里数据库连接池 --> 65 <!-- 阿里数据库连接池 -->
64 <dependency> 66 <dependency>
65 <groupId>com.alibaba</groupId> 67 <groupId>com.alibaba</groupId>
@@ -213,6 +215,13 @@ @@ -213,6 +215,13 @@
213 <version>${ruoyi.version}</version> 215 <version>${ruoyi.version}</version>
214 </dependency> 216 </dependency>
215 217
  218 + <!-- 模型-->
  219 + <dependency>
  220 + <groupId>com.zhonglai.luhui</groupId>
  221 + <artifactId>lh-domain</artifactId>
  222 + <version>${ruoyi.version}</version>
  223 + </dependency>
  224 +
216 <!-- 支持data --> 225 <!-- 支持data -->
217 <dependency> 226 <dependency>
218 <groupId>org.projectlombok</groupId> 227 <groupId>org.projectlombok</groupId>
@@ -17,6 +17,12 @@ @@ -17,6 +17,12 @@
17 17
18 <dependencies> 18 <dependencies>
19 19
  20 + <!-- 模型-->
  21 + <dependency>
  22 + <groupId>com.zhonglai.luhui</groupId>
  23 + <artifactId>lh-domain</artifactId>
  24 + </dependency>
  25 +
20 <!-- Spring框架基本的核心工具 --> 26 <!-- Spring框架基本的核心工具 -->
21 <dependency> 27 <dependency>
22 <groupId>org.springframework</groupId> 28 <groupId>org.springframework</groupId>
1 package com.ruoyi.common.annotation; 1 package com.ruoyi.common.annotation;
2 2
  3 +import com.ruoyi.system.domain.tool.Excel;
  4 +
3 import java.lang.annotation.ElementType; 5 import java.lang.annotation.ElementType;
4 import java.lang.annotation.Retention; 6 import java.lang.annotation.Retention;
5 import java.lang.annotation.RetentionPolicy; 7 import java.lang.annotation.RetentionPolicy;
1 package com.ruoyi.common.core.domain; 1 package com.ruoyi.common.core.domain;
2 2
  3 +import com.ruoyi.system.domain.tool.BaseEntity;
  4 +
3 import java.util.ArrayList; 5 import java.util.ArrayList;
4 import java.util.List; 6 import java.util.List;
5 7
1 package com.ruoyi.common.core.domain.entity; 1 package com.ruoyi.common.core.domain.entity;
2 2
3 -import com.ruoyi.common.core.domain.BaseEntity; 3 +import com.ruoyi.system.domain.tool.BaseEntity;
4 import org.apache.commons.lang3.builder.ToStringBuilder; 4 import org.apache.commons.lang3.builder.ToStringBuilder;
5 import org.apache.commons.lang3.builder.ToStringStyle; 5 import org.apache.commons.lang3.builder.ToStringStyle;
6 6
1 package com.ruoyi.common.core.domain.entity; 1 package com.ruoyi.common.core.domain.entity;
2 2
3 -import com.ruoyi.common.annotation.Excel;  
4 -import com.ruoyi.common.annotation.Excel.ColumnType; 3 +import com.ruoyi.system.domain.tool.Excel;
  4 +import com.ruoyi.system.domain.tool.Excel.ColumnType;
5 import com.ruoyi.common.constant.UserConstants; 5 import com.ruoyi.common.constant.UserConstants;
6 -import com.ruoyi.common.core.domain.BaseEntity; 6 +import com.ruoyi.system.domain.tool.BaseEntity;
7 import org.apache.commons.lang3.builder.ToStringBuilder; 7 import org.apache.commons.lang3.builder.ToStringBuilder;
8 import org.apache.commons.lang3.builder.ToStringStyle; 8 import org.apache.commons.lang3.builder.ToStringStyle;
9 9
1 -package com.ruoyi.common.core.domain.entity; import javax.validation.constraints.NotBlank;import javax.validation.constraints.Size;import org.apache.commons.lang3.builder.ToStringBuilder;import org.apache.commons.lang3.builder.ToStringStyle;import com.ruoyi.common.annotation.Excel;import com.ruoyi.common.annotation.Excel.ColumnType;import com.ruoyi.common.core.domain.BaseEntity; /** * 字典类型表 sys_dict_type * * @author ruoyi */public class SysDictType extends BaseEntity{ private static final long serialVersionUID = 1L; /** 字典主键 */ @Excel(name = "字典主键", cellType = ColumnType.NUMERIC) private Long dictId; /** 字典名称 */ @Excel(name = "字典名称") private String dictName; /** 字典类型 */ @Excel(name = "字典类型") private String dictType; /** 状态(0正常 1停用) */ @Excel(name = "状态", readConverterExp = "0=正常,1=停用") private String status; public Long getDictId() { return dictId; } public void setDictId(Long dictId) { this.dictId = dictId; } @NotBlank(message = "字典名称不能为空") @Size(min = 0, max = 100, message = "字典类型名称长度不能超过100个字符") public String getDictName() { return dictName; } public void setDictName(String dictName) { this.dictName = dictName; } @NotBlank(message = "字典类型不能为空") @Size(min = 0, max = 100, message = "字典类型类型长度不能超过100个字符") public String getDictType() { return dictType; } public void setDictType(String dictType) { this.dictType = dictType; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) .append("dictId", getDictId()) .append("dictName", getDictName()) .append("dictType", getDictType()) .append("status", getStatus()) .append("createBy", getCreateBy()) .append("createTime", getCreateTime()) .append("updateBy", getUpdateBy()) .append("updateTime", getUpdateTime()) .append("remark", getRemark()) .toString(); }}  
  1 +package com.ruoyi.common.core.domain.entity; import javax.validation.constraints.NotBlank;import javax.validation.constraints.Size;import org.apache.commons.lang3.builder.ToStringBuilder;import org.apache.commons.lang3.builder.ToStringStyle;import com.ruoyi.system.domain.tool.Excel;import com.ruoyi.system.domain.tool.Excel.ColumnType;import com.ruoyi.system.domain.tool.BaseEntity; /** * 字典类型表 sys_dict_type * * @author ruoyi */public class SysDictType extends BaseEntity{ private static final long serialVersionUID = 1L; /** 字典主键 */ @Excel(name = "字典主键", cellType = ColumnType.NUMERIC) private Long dictId; /** 字典名称 */ @Excel(name = "字典名称") private String dictName; /** 字典类型 */ @Excel(name = "字典类型") private String dictType; /** 状态(0正常 1停用) */ @Excel(name = "状态", readConverterExp = "0=正常,1=停用") private String status; public Long getDictId() { return dictId; } public void setDictId(Long dictId) { this.dictId = dictId; } @NotBlank(message = "字典名称不能为空") @Size(min = 0, max = 100, message = "字典类型名称长度不能超过100个字符") public String getDictName() { return dictName; } public void setDictName(String dictName) { this.dictName = dictName; } @NotBlank(message = "字典类型不能为空") @Size(min = 0, max = 100, message = "字典类型类型长度不能超过100个字符") public String getDictType() { return dictType; } public void setDictType(String dictType) { this.dictType = dictType; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) .append("dictId", getDictId()) .append("dictName", getDictName()) .append("dictType", getDictType()) .append("status", getStatus()) .append("createBy", getCreateBy()) .append("createTime", getCreateTime()) .append("updateBy", getUpdateBy()) .append("updateTime", getUpdateTime()) .append("remark", getRemark()) .toString(); }}
1 package com.ruoyi.common.core.domain.entity; 1 package com.ruoyi.common.core.domain.entity;
2 2
3 -import com.ruoyi.common.core.domain.BaseEntity; 3 +import com.ruoyi.system.domain.tool.BaseEntity;
4 import org.apache.commons.lang3.builder.ToStringBuilder; 4 import org.apache.commons.lang3.builder.ToStringBuilder;
5 import org.apache.commons.lang3.builder.ToStringStyle; 5 import org.apache.commons.lang3.builder.ToStringStyle;
6 6
1 package com.ruoyi.common.core.domain.entity; 1 package com.ruoyi.common.core.domain.entity;
2 2
3 -import com.ruoyi.common.annotation.Excel;  
4 -import com.ruoyi.common.annotation.Excel.ColumnType;  
5 -import com.ruoyi.common.core.domain.BaseEntity; 3 +import com.ruoyi.system.domain.tool.Excel;
  4 +import com.ruoyi.system.domain.tool.Excel.ColumnType;
  5 +import com.ruoyi.system.domain.tool.BaseEntity;
6 import org.apache.commons.lang3.builder.ToStringBuilder; 6 import org.apache.commons.lang3.builder.ToStringBuilder;
7 import org.apache.commons.lang3.builder.ToStringStyle; 7 import org.apache.commons.lang3.builder.ToStringStyle;
8 8
@@ -2,12 +2,12 @@ package com.ruoyi.common.core.domain.entity; @@ -2,12 +2,12 @@ package com.ruoyi.common.core.domain.entity;
2 2
3 import com.fasterxml.jackson.annotation.JsonIgnore; 3 import com.fasterxml.jackson.annotation.JsonIgnore;
4 import com.fasterxml.jackson.annotation.JsonProperty; 4 import com.fasterxml.jackson.annotation.JsonProperty;
5 -import com.ruoyi.common.annotation.Excel;  
6 -import com.ruoyi.common.annotation.Excel.ColumnType;  
7 -import com.ruoyi.common.annotation.Excel.Type; 5 +import com.ruoyi.system.domain.tool.Excel;
  6 +import com.ruoyi.system.domain.tool.Excel.ColumnType;
  7 +import com.ruoyi.system.domain.tool.Excel.Type;
8 import com.ruoyi.common.annotation.Excels; 8 import com.ruoyi.common.annotation.Excels;
9 -import com.ruoyi.common.core.domain.BaseEntity;  
10 -import com.ruoyi.common.xss.Xss; 9 +import com.ruoyi.system.domain.tool.BaseEntity;
  10 +import com.ruoyi.system.domain.tool.Xss;
11 import org.apache.commons.lang3.builder.ToStringBuilder; 11 import org.apache.commons.lang3.builder.ToStringBuilder;
12 import org.apache.commons.lang3.builder.ToStringStyle; 12 import org.apache.commons.lang3.builder.ToStringStyle;
13 13
@@ -212,7 +212,7 @@ public class RedisCache @@ -212,7 +212,7 @@ public class RedisCache
212 * @param key 212 * @param key
213 * @param hKey 213 * @param hKey
214 */ 214 */
215 - public void delCacheMapValue(final String key, final String hKey) 215 + public void delCacheMapValue(final String key, final String... hKey)
216 { 216 {
217 HashOperations hashOperations = redisTemplate.opsForHash(); 217 HashOperations hashOperations = redisTemplate.opsForHash();
218 hashOperations.delete(key, hKey); 218 hashOperations.delete(key, hKey);
  1 +package com.ruoyi.common.utils.html;
  2 +
  3 +import com.alibaba.fastjson.JSONArray;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import okhttp3.*;
  6 +
  7 +import java.io.IOException;
  8 +import java.util.concurrent.TimeUnit;
  9 +
  10 +public class HttpUtils {
  11 +
  12 + public interface Header
  13 + {
  14 + void addHeader(Request.Builder builder);
  15 + }
  16 +
  17 + public interface JsonBody
  18 + {
  19 + void addJsonBody(JSONObject jsonObject);
  20 + }
  21 +
  22 + public interface JsonListBody
  23 + {
  24 + void addJsonBody(JSONArray jsonArray);
  25 + }
  26 +
  27 + public interface FromBody
  28 + {
  29 + void addFromBody(FormBody.Builder formBody);
  30 + }
  31 +
  32 + private static OkHttpClient okHttpClient = new OkHttpClient.Builder()
  33 + .connectTimeout(10, TimeUnit.SECONDS)
  34 + .readTimeout(10, TimeUnit.SECONDS)
  35 + .writeTimeout(20, TimeUnit.SECONDS)
  36 + .build();
  37 +
  38 + public static Response postJsonBody(String url,JsonBody jsonBody) throws IOException {
  39 + return postJsonBody(url,null,jsonBody);
  40 + }
  41 +
  42 + public static Response postJsonBody(String url,Header header,JsonBody jsonBody) throws IOException {
  43 +
  44 + Request.Builder builder = new Request.Builder();
  45 + if(null != header)
  46 + {
  47 + header.addHeader(builder);
  48 + }
  49 + RequestBody requestBody = requestBody(jsonBody);
  50 + Request request = getPostRequest(url,builder,requestBody);
  51 + return response(request);
  52 + }
  53 +
  54 + public static Response postJsonListBody(String url,Header header,JsonListBody jsonListBody) throws IOException {
  55 + Request.Builder builder = new Request.Builder();
  56 + if(null != header)
  57 + {
  58 + header.addHeader(builder);
  59 + }
  60 + MediaType json = MediaType.parse("application/json; charset=utf-8");
  61 + JSONArray jsonArray = new JSONArray();
  62 + if(null != jsonArray)
  63 + {
  64 + jsonListBody.addJsonBody(jsonArray);
  65 + }
  66 + RequestBody requestBody = RequestBody.create(json,jsonArray.toString());
  67 + Request request = getPostRequest(url,builder,requestBody);
  68 + return response(request);
  69 + }
  70 +
  71 + private static RequestBody requestBody(JsonBody jsonBody)
  72 + {
  73 + JSONObject jsonObject = new JSONObject();
  74 + if(null != jsonBody)
  75 + {
  76 + jsonBody.addJsonBody(jsonObject);
  77 + }
  78 +
  79 + MediaType json = MediaType.parse("application/json; charset=utf-8");
  80 + RequestBody requestBody = RequestBody.create(json,jsonObject.toString());
  81 + return requestBody;
  82 + }
  83 + public static Response putJsonBody(String url,Header header) throws IOException {
  84 + return putJsonBody(url,header,null);
  85 + }
  86 + public static Response putJsonBody(String url,Header header,JsonBody jsonBody) throws IOException {
  87 + Request.Builder builder = new Request.Builder();
  88 + if(null != header)
  89 + {
  90 + header.addHeader(builder);
  91 + }
  92 +
  93 + RequestBody requestBody = requestBody(jsonBody);
  94 +
  95 + return response(builder.url(url)
  96 + .put(requestBody)
  97 + .build());
  98 + }
  99 +
  100 + public static Response delete(String url,Header header) throws IOException {
  101 + return delete(url,header,null);
  102 + }
  103 + public static Response delete(String url,Header header,FromBody fromBody) throws IOException {
  104 + Request.Builder builder = new Request.Builder();
  105 + if(null != header)
  106 + {
  107 + header.addHeader(builder);
  108 + }
  109 +
  110 + FormBody.Builder formB = new FormBody.Builder();
  111 + if(null != fromBody)
  112 + {
  113 + fromBody.addFromBody(formB);
  114 + }
  115 +
  116 + return response( builder.url(url)
  117 + .delete(formB.build())
  118 + .build());
  119 + }
  120 +
  121 + public static Response postFromBody(String url,Header header,FromBody fromBody) throws IOException {
  122 + Request.Builder builder = new Request.Builder();
  123 + if(null != header)
  124 + {
  125 + header.addHeader(builder);
  126 + }
  127 +
  128 + FormBody.Builder formB = new FormBody.Builder();
  129 + if(null != fromBody)
  130 + {
  131 + fromBody.addFromBody(formB);
  132 + }
  133 +
  134 + Request request = getPostRequest(url,builder,formB.build());
  135 + Response response = response(request);
  136 + return response;
  137 + }
  138 +
  139 + public static String get(String url,Header header) throws IOException {
  140 + Response response = getResponse(url,header);
  141 + return response.body().string();
  142 + }
  143 +
  144 + public static Response getResponse(String url,Header header) throws IOException {
  145 + Request.Builder builder = new Request.Builder();
  146 + if(null != header)
  147 + {
  148 + header.addHeader(builder);
  149 + }
  150 + Request request = builder.url(url).get().build();
  151 + return response(request);
  152 + }
  153 +
  154 +
  155 + public static Request getPostRequest(String url,Request.Builder builder, RequestBody requestBody)
  156 + {
  157 + return builder
  158 + .url(url)
  159 + .post(requestBody)
  160 + .build();
  161 + }
  162 +
  163 + public static Response response(Request request) throws IOException {
  164 + Response response = okHttpClient.newCall(request).execute();
  165 + try {
  166 + if (!response.isSuccessful()) {
  167 + throw new IOException("Unexpected code " + response);
  168 + }
  169 + } catch (IOException e) {
  170 + response.body().close();
  171 + }
  172 + return response;
  173 + }
  174 +}
1 package com.ruoyi.common.utils.poi; 1 package com.ruoyi.common.utils.poi;
2 2
3 -import com.ruoyi.common.annotation.Excel;  
4 -import com.ruoyi.common.annotation.Excel.ColumnType;  
5 -import com.ruoyi.common.annotation.Excel.Type;  
6 import com.ruoyi.common.annotation.Excels; 3 import com.ruoyi.common.annotation.Excels;
7 import com.ruoyi.common.config.RuoYiConfig; 4 import com.ruoyi.common.config.RuoYiConfig;
8 import com.ruoyi.common.core.domain.AjaxResult; 5 import com.ruoyi.common.core.domain.AjaxResult;
@@ -15,6 +12,8 @@ import com.ruoyi.common.utils.file.FileTypeUtils; @@ -15,6 +12,8 @@ import com.ruoyi.common.utils.file.FileTypeUtils;
15 import com.ruoyi.common.utils.file.FileUtils; 12 import com.ruoyi.common.utils.file.FileUtils;
16 import com.ruoyi.common.utils.file.ImageUtils; 13 import com.ruoyi.common.utils.file.ImageUtils;
17 import com.ruoyi.common.utils.reflect.ReflectUtils; 14 import com.ruoyi.common.utils.reflect.ReflectUtils;
  15 +import com.ruoyi.system.domain.tool.Excel;
  16 +import com.ruoyi.system.domain.tool.ExcelHandlerAdapter;
18 import org.apache.commons.lang3.RegExUtils; 17 import org.apache.commons.lang3.RegExUtils;
19 import org.apache.poi.hssf.usermodel.*; 18 import org.apache.poi.hssf.usermodel.*;
20 import org.apache.poi.ooxml.POIXMLDocumentPart; 19 import org.apache.poi.ooxml.POIXMLDocumentPart;
@@ -65,7 +64,7 @@ public class ExcelUtil<T> @@ -65,7 +64,7 @@ public class ExcelUtil<T>
65 /** 64 /**
66 * 导出类型(EXPORT:导出数据;IMPORT:导入模板) 65 * 导出类型(EXPORT:导出数据;IMPORT:导入模板)
67 */ 66 */
68 - private Type type; 67 + private Excel.Type type;
69 68
70 /** 69 /**
71 * 工作薄对象 70 * 工作薄对象
@@ -127,7 +126,7 @@ public class ExcelUtil<T> @@ -127,7 +126,7 @@ public class ExcelUtil<T>
127 this.clazz = clazz; 126 this.clazz = clazz;
128 } 127 }
129 128
130 - public void init(List<T> list, String sheetName, String title, Type type) 129 + public void init(List<T> list, String sheetName, String title, Excel.Type type)
131 { 130 {
132 if (list == null) 131 if (list == null)
133 { 132 {
@@ -192,7 +191,7 @@ public class ExcelUtil<T> @@ -192,7 +191,7 @@ public class ExcelUtil<T>
192 */ 191 */
193 public List<T> importExcel(String sheetName, InputStream is, int titleNum) throws Exception 192 public List<T> importExcel(String sheetName, InputStream is, int titleNum) throws Exception
194 { 193 {
195 - this.type = Type.IMPORT; 194 + this.type = Excel.Type.IMPORT;
196 this.wb = WorkbookFactory.create(is); 195 this.wb = WorkbookFactory.create(is);
197 List<T> list = new ArrayList<T>(); 196 List<T> list = new ArrayList<T>();
198 // 如果指定sheet名,则取指定sheet中的内容 否则默认指向第1个sheet 197 // 如果指定sheet名,则取指定sheet中的内容 否则默认指向第1个sheet
@@ -340,7 +339,7 @@ public class ExcelUtil<T> @@ -340,7 +339,7 @@ public class ExcelUtil<T>
340 { 339 {
341 val = dataFormatHandlerAdapter(val, attr); 340 val = dataFormatHandlerAdapter(val, attr);
342 } 341 }
343 - else if (ColumnType.IMAGE == attr.cellType() && StringUtils.isNotEmpty(pictures)) 342 + else if (Excel.ColumnType.IMAGE == attr.cellType() && StringUtils.isNotEmpty(pictures))
344 { 343 {
345 PictureData image = pictures.get(row.getRowNum() + "_" + entry.getKey()); 344 PictureData image = pictures.get(row.getRowNum() + "_" + entry.getKey());
346 if (image == null) 345 if (image == null)
@@ -384,7 +383,7 @@ public class ExcelUtil<T> @@ -384,7 +383,7 @@ public class ExcelUtil<T>
384 */ 383 */
385 public AjaxResult exportExcel(List<T> list, String sheetName, String title) 384 public AjaxResult exportExcel(List<T> list, String sheetName, String title)
386 { 385 {
387 - this.init(list, sheetName, title, Type.EXPORT); 386 + this.init(list, sheetName, title, Excel.Type.EXPORT);
388 return exportExcel(); 387 return exportExcel();
389 } 388 }
390 389
@@ -414,7 +413,7 @@ public class ExcelUtil<T> @@ -414,7 +413,7 @@ public class ExcelUtil<T>
414 { 413 {
415 response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); 414 response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
416 response.setCharacterEncoding("utf-8"); 415 response.setCharacterEncoding("utf-8");
417 - this.init(list, sheetName, title, Type.EXPORT); 416 + this.init(list, sheetName, title, Excel.Type.EXPORT);
418 exportExcel(response); 417 exportExcel(response);
419 } 418 }
420 419
@@ -438,7 +437,7 @@ public class ExcelUtil<T> @@ -438,7 +437,7 @@ public class ExcelUtil<T>
438 */ 437 */
439 public AjaxResult importTemplateExcel(String sheetName, String title) 438 public AjaxResult importTemplateExcel(String sheetName, String title)
440 { 439 {
441 - this.init(null, sheetName, title, Type.IMPORT); 440 + this.init(null, sheetName, title, Excel.Type.IMPORT);
442 return exportExcel(); 441 return exportExcel();
443 } 442 }
444 443
@@ -464,7 +463,7 @@ public class ExcelUtil<T> @@ -464,7 +463,7 @@ public class ExcelUtil<T>
464 { 463 {
465 response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); 464 response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
466 response.setCharacterEncoding("utf-8"); 465 response.setCharacterEncoding("utf-8");
467 - this.init(null, sheetName, title, Type.IMPORT); 466 + this.init(null, sheetName, title, Excel.Type.IMPORT);
468 exportExcel(response); 467 exportExcel(response);
469 } 468 }
470 469
@@ -538,7 +537,7 @@ public class ExcelUtil<T> @@ -538,7 +537,7 @@ public class ExcelUtil<T>
538 Excel excel = (Excel) os[1]; 537 Excel excel = (Excel) os[1];
539 this.createCell(excel, row, column++); 538 this.createCell(excel, row, column++);
540 } 539 }
541 - if (Type.EXPORT.equals(type)) 540 + if (Excel.Type.EXPORT.equals(type))
542 { 541 {
543 fillExcelData(index, row); 542 fillExcelData(index, row);
544 addStatisticsRow(); 543 addStatisticsRow();
@@ -672,7 +671,7 @@ public class ExcelUtil<T> @@ -672,7 +671,7 @@ public class ExcelUtil<T>
672 */ 671 */
673 public void setCellVo(Object value, Excel attr, Cell cell) 672 public void setCellVo(Object value, Excel attr, Cell cell)
674 { 673 {
675 - if (ColumnType.STRING == attr.cellType()) 674 + if (Excel.ColumnType.STRING == attr.cellType())
676 { 675 {
677 String cellValue = Convert.toStr(value); 676 String cellValue = Convert.toStr(value);
678 // 对于任何以表达式触发字符 =-+@开头的单元格,直接使用tab字符作为前缀,防止CSV注入。 677 // 对于任何以表达式触发字符 =-+@开头的单元格,直接使用tab字符作为前缀,防止CSV注入。
@@ -682,14 +681,14 @@ public class ExcelUtil<T> @@ -682,14 +681,14 @@ public class ExcelUtil<T>
682 } 681 }
683 cell.setCellValue(StringUtils.isNull(cellValue) ? attr.defaultValue() : cellValue + attr.suffix()); 682 cell.setCellValue(StringUtils.isNull(cellValue) ? attr.defaultValue() : cellValue + attr.suffix());
684 } 683 }
685 - else if (ColumnType.NUMERIC == attr.cellType()) 684 + else if (Excel.ColumnType.NUMERIC == attr.cellType())
686 { 685 {
687 if (StringUtils.isNotNull(value)) 686 if (StringUtils.isNotNull(value))
688 { 687 {
689 cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value)); 688 cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value));
690 } 689 }
691 } 690 }
692 - else if (ColumnType.IMAGE == attr.cellType()) 691 + else if (Excel.ColumnType.IMAGE == attr.cellType())
693 { 692 {
694 ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), cell.getRow().getRowNum() + 1); 693 ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), cell.getRow().getRowNum() + 1);
695 String imagePath = Convert.toStr(value); 694 String imagePath = Convert.toStr(value);
@@ -1117,7 +1116,7 @@ public class ExcelUtil<T> @@ -1117,7 +1116,7 @@ public class ExcelUtil<T>
1117 if (field.isAnnotationPresent(Excel.class)) 1116 if (field.isAnnotationPresent(Excel.class))
1118 { 1117 {
1119 Excel attr = field.getAnnotation(Excel.class); 1118 Excel attr = field.getAnnotation(Excel.class);
1120 - if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) 1119 + if (attr != null && (attr.type() == Excel.Type.ALL || attr.type() == type))
1121 { 1120 {
1122 field.setAccessible(true); 1121 field.setAccessible(true);
1123 fields.add(new Object[] { field, attr }); 1122 fields.add(new Object[] { field, attr });
@@ -1131,7 +1130,7 @@ public class ExcelUtil<T> @@ -1131,7 +1130,7 @@ public class ExcelUtil<T>
1131 Excel[] excels = attrs.value(); 1130 Excel[] excels = attrs.value();
1132 for (Excel attr : excels) 1131 for (Excel attr : excels)
1133 { 1132 {
1134 - if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) 1133 + if (attr != null && (attr.type() == Excel.Type.ALL || attr.type() == type))
1135 { 1134 {
1136 field.setAccessible(true); 1135 field.setAccessible(true);
1137 fields.add(new Object[] { field, attr }); 1136 fields.add(new Object[] { field, attr });
1 package com.ruoyi.framework.aspectj; 1 package com.ruoyi.framework.aspectj;
2 2
3 import com.ruoyi.common.annotation.DataScope; 3 import com.ruoyi.common.annotation.DataScope;
4 -import com.ruoyi.common.core.domain.BaseEntity; 4 +import com.ruoyi.system.domain.tool.BaseEntity;
5 import com.ruoyi.common.core.domain.entity.SysRole; 5 import com.ruoyi.common.core.domain.entity.SysRole;
6 import com.ruoyi.common.core.domain.entity.SysUser; 6 import com.ruoyi.common.core.domain.entity.SysUser;
7 import com.ruoyi.common.core.domain.model.LoginUser; 7 import com.ruoyi.common.core.domain.model.LoginUser;
@@ -218,7 +218,7 @@ public class GenController extends BaseController @@ -218,7 +218,7 @@ public class GenController extends BaseController
218 @ApiOperation("从数据库结构生成代码") 218 @ApiOperation("从数据库结构生成代码")
219 @ApiImplicitParam(value = "表名集合",name = "tableNames") 219 @ApiImplicitParam(value = "表名集合",name = "tableNames")
220 @GetMapping("/generatorCodeFromDb") 220 @GetMapping("/generatorCodeFromDb")
221 - public void generatorCodeFromDb(HttpServletResponse response,String databaseName, String tableNames) throws IOException { 221 + public void generatorCodeFromDb(HttpServletResponse response,String databaseName, String tableNames) throws IOException {
222 byte[] data = genTableService.generatorCodeFromDb(databaseName,tableNames); 222 byte[] data = genTableService.generatorCodeFromDb(databaseName,tableNames);
223 genCode(response, data); 223 genCode(response, data);
224 } 224 }
@@ -5,7 +5,7 @@ import javax.validation.Valid; @@ -5,7 +5,7 @@ import javax.validation.Valid;
5 import javax.validation.constraints.NotBlank; 5 import javax.validation.constraints.NotBlank;
6 import org.apache.commons.lang3.ArrayUtils; 6 import org.apache.commons.lang3.ArrayUtils;
7 import com.ruoyi.common.constant.GenConstants; 7 import com.ruoyi.common.constant.GenConstants;
8 -import com.ruoyi.common.core.domain.BaseEntity; 8 +import com.ruoyi.system.domain.tool.BaseEntity;
9 import com.ruoyi.common.utils.StringUtils; 9 import com.ruoyi.common.utils.StringUtils;
10 10
11 /** 11 /**
1 package com.ruoyi.generator.domain; 1 package com.ruoyi.generator.domain;
2 2
3 import javax.validation.constraints.NotBlank; 3 import javax.validation.constraints.NotBlank;
4 -import com.ruoyi.common.core.domain.BaseEntity; 4 +import com.ruoyi.system.domain.tool.BaseEntity;
5 import com.ruoyi.common.utils.StringUtils; 5 import com.ruoyi.common.utils.StringUtils;
6 6
7 /** 7 /**
@@ -3,13 +3,9 @@ package ${packageName}.domain; @@ -3,13 +3,9 @@ package ${packageName}.domain;
3 #foreach ($import in $importList) 3 #foreach ($import in $importList)
4 import ${import}; 4 import ${import};
5 #end 5 #end
6 -import org.apache.commons.lang3.builder.ToStringBuilder;  
7 -import org.apache.commons.lang3.builder.ToStringStyle;  
8 import com.ruoyi.common.annotation.Excel; 6 import com.ruoyi.common.annotation.Excel;
9 #if($table.crud || $table.sub) 7 #if($table.crud || $table.sub)
10 -import com.ruoyi.common.core.domain.BaseEntity;  
11 #elseif($table.tree) 8 #elseif($table.tree)
12 -import com.ruoyi.common.core.domain.TreeEntity;  
13 #end 9 #end
14 import io.swagger.annotations.ApiModel; 10 import io.swagger.annotations.ApiModel;
15 import io.swagger.annotations.ApiModelProperty; 11 import io.swagger.annotations.ApiModelProperty;
@@ -3,10 +3,7 @@ package ${packageName}.domain; @@ -3,10 +3,7 @@ package ${packageName}.domain;
3 #foreach ($import in $subImportList) 3 #foreach ($import in $subImportList)
4 import ${import}; 4 import ${import};
5 #end 5 #end
6 -import org.apache.commons.lang3.builder.ToStringBuilder;  
7 -import org.apache.commons.lang3.builder.ToStringStyle;  
8 import com.ruoyi.common.annotation.Excel; 6 import com.ruoyi.common.annotation.Excel;
9 -import com.ruoyi.common.core.domain.BaseEntity;  
10 7
11 /** 8 /**
12 * ${subTable.functionName}对象 ${subTableName} 9 * ${subTable.functionName}对象 ${subTableName}
@@ -20,6 +20,12 @@ @@ -20,6 +20,12 @@
20 <!-- 通用工具--> 20 <!-- 通用工具-->
21 <dependency> 21 <dependency>
22 <groupId>com.zhonglai.luhui</groupId> 22 <groupId>com.zhonglai.luhui</groupId>
  23 + <artifactId>lh-domain</artifactId>
  24 + </dependency>
  25 +
  26 + <!-- 通用工具-->
  27 + <dependency>
  28 + <groupId>com.zhonglai.luhui</groupId>
23 <artifactId>ruoyi-common</artifactId> 29 <artifactId>ruoyi-common</artifactId>
24 </dependency> 30 </dependency>
25 31
1 -package com.ruoyi.system.domain;  
2 -  
3 -import org.apache.commons.lang3.builder.ToStringBuilder;  
4 -import org.apache.commons.lang3.builder.ToStringStyle;  
5 -import com.ruoyi.common.annotation.Excel;  
6 -import com.ruoyi.common.core.domain.BaseEntity;  
7 -import io.swagger.annotations.ApiModel;  
8 -import io.swagger.annotations.ApiModelProperty;  
9 -  
10 -/**  
11 - * 主机/网关对象 iot_device  
12 - *  
13 - * @author 钟来  
14 - * @date 2022-08-26  
15 - */  
16 -@ApiModel("主机/网关")  
17 -public class IotDevice extends BaseEntity  
18 -{  
19 - private static final long serialVersionUID = 1L;  
20 -  
21 - /** 激活时间 */  
22 - @ApiModelProperty("激活时间")  
23 - private Integer active_time;  
24 -  
25 - /** 主键 */  
26 - @ApiModelProperty("主键")  
27 - private String client_id;  
28 -  
29 - /** 是否补充权限,前面加${{roleid}}/${{username}}/${{clientid}}(0否,1是) */  
30 - @ApiModelProperty("是否补充权限,前面加${{roleid}}/${{username}}/${{clientid}}(0否,1是)")  
31 - private Integer completion_auth;  
32 -  
33 - /** 创建者 */  
34 - @ApiModelProperty("创建者")  
35 - private String create_by;  
36 -  
37 - /** 创建时间 */  
38 - @ApiModelProperty("创建时间")  
39 - private Integer create_time;  
40 -  
41 - /** 删除标志(0代表存在 2代表删除) */  
42 - @ApiModelProperty("删除标志(0代表存在 2代表删除)")  
43 - private Integer del_flag;  
44 -  
45 - /** 固件版本 */  
46 - @ApiModelProperty("固件版本")  
47 - private Float firmware_version;  
48 -  
49 - /** 图片地址 */  
50 - @ApiModelProperty("图片地址")  
51 - private String img_url;  
52 -  
53 - /** 是否启用设备影子(0=禁用,1=启用) */  
54 - @ApiModelProperty("是否启用设备影子(0=禁用,1=启用)")  
55 - private Integer is_shadow;  
56 -  
57 - /** 设备纬度 */  
58 - @ApiModelProperty("设备纬度")  
59 - private Double latitude;  
60 -  
61 - /** 定位方式(1=ip自动定位,2=设备定位,3=自定义) */  
62 - @ApiModelProperty("定位方式(1=ip自动定位,2=设备定位,3=自定义)")  
63 - private Integer location_way;  
64 -  
65 - /** 设备经度 */  
66 - @ApiModelProperty("设备经度")  
67 - private Double longitude;  
68 -  
69 - /** 设备名称 */  
70 - @ApiModelProperty("设备名称")  
71 - private String name;  
72 -  
73 - /** 设备所在地址 */  
74 - @ApiModelProperty("设备所在地址")  
75 - private String network_address;  
76 -  
77 - /** 设备入网IP */  
78 - @ApiModelProperty("设备入网IP")  
79 - private String network_ip;  
80 -  
81 - /** 信号强度( 信号极好4格[-55— 0], 信号好3格[-70— -55], 信号一般2格[-85— -70], 信号差1格[-100— -85]) */  
82 - @ApiModelProperty("信号强度( 信号极好4格[-55— 0], 信号好3格[-70— -55], 信号一般2格[-85— -70], 信号差1格[-100— -85])")  
83 - private Integer rssi;  
84 -  
85 - /** 设备状态(1-未激活,2-禁用,3-在线,4-离线) */  
86 - @ApiModelProperty("设备状态(1-未激活,2-禁用,3-在线,4-离线)")  
87 - private Integer status;  
88 -  
89 - /** 设备摘要,格式[{"name":"device"},{"chip":"esp8266"}] */  
90 - @ApiModelProperty("设备摘要,格式[{\"name\":\"device\"},{\"chip\":\"esp8266\"}]")  
91 - private String summary;  
92 -  
93 - /** 物模型值 */  
94 - @ApiModelProperty("物模型值")  
95 - private String things_model_value;  
96 -  
97 - /** 更新者 */  
98 - @ApiModelProperty("更新者")  
99 - private String update_by;  
100 -  
101 - /** 更新时间 */  
102 - @ApiModelProperty("更新时间")  
103 - private Integer update_time;  
104 -  
105 - /** 用户id */  
106 - @ApiModelProperty("用户id")  
107 - private Integer user_id;  
108 -  
109 - @ApiModelProperty("负载类型(String,Json,Bite16,Bite32)")  
110 - private String payload_type;  
111 -  
112 - public String getPayload_type() {  
113 - return payload_type;  
114 - }  
115 -  
116 - public void setPayload_type(String payload_type) {  
117 - this.payload_type = payload_type;  
118 - }  
119 -  
120 - public void setActive_time(Integer active_time)  
121 - {  
122 - this.active_time = active_time;  
123 - }  
124 -  
125 - public Integer getActive_time()  
126 - {  
127 - return active_time;  
128 - }  
129 - public void setClient_id(String client_id)  
130 - {  
131 - this.client_id = client_id;  
132 - }  
133 -  
134 - public String getClient_id()  
135 - {  
136 - return client_id;  
137 - }  
138 - public void setCompletion_auth(Integer completion_auth)  
139 - {  
140 - this.completion_auth = completion_auth;  
141 - }  
142 -  
143 - public Integer getCompletion_auth()  
144 - {  
145 - return completion_auth;  
146 - }  
147 - public void setCreate_by(String create_by)  
148 - {  
149 - this.create_by = create_by;  
150 - }  
151 -  
152 - public String getCreate_by()  
153 - {  
154 - return create_by;  
155 - }  
156 - public void setCreate_time(Integer create_time)  
157 - {  
158 - this.create_time = create_time;  
159 - }  
160 -  
161 - public Integer getCreate_time()  
162 - {  
163 - return create_time;  
164 - }  
165 - public void setDel_flag(Integer del_flag)  
166 - {  
167 - this.del_flag = del_flag;  
168 - }  
169 -  
170 - public Integer getDel_flag()  
171 - {  
172 - return del_flag;  
173 - }  
174 - public void setFirmware_version(Float firmware_version)  
175 - {  
176 - this.firmware_version = firmware_version;  
177 - }  
178 -  
179 - public Float getFirmware_version()  
180 - {  
181 - return firmware_version;  
182 - }  
183 - public void setImg_url(String img_url)  
184 - {  
185 - this.img_url = img_url;  
186 - }  
187 -  
188 - public String getImg_url()  
189 - {  
190 - return img_url;  
191 - }  
192 - public void setIs_shadow(Integer is_shadow)  
193 - {  
194 - this.is_shadow = is_shadow;  
195 - }  
196 -  
197 - public Integer getIs_shadow()  
198 - {  
199 - return is_shadow;  
200 - }  
201 - public void setLatitude(Double latitude)  
202 - {  
203 - this.latitude = latitude;  
204 - }  
205 -  
206 - public Double getLatitude()  
207 - {  
208 - return latitude;  
209 - }  
210 - public void setLocation_way(Integer location_way)  
211 - {  
212 - this.location_way = location_way;  
213 - }  
214 -  
215 - public Integer getLocation_way()  
216 - {  
217 - return location_way;  
218 - }  
219 - public void setLongitude(Double longitude)  
220 - {  
221 - this.longitude = longitude;  
222 - }  
223 -  
224 - public Double getLongitude()  
225 - {  
226 - return longitude;  
227 - }  
228 - public void setName(String name)  
229 - {  
230 - this.name = name;  
231 - }  
232 -  
233 - public String getName()  
234 - {  
235 - return name;  
236 - }  
237 - public void setNetwork_address(String network_address)  
238 - {  
239 - this.network_address = network_address;  
240 - }  
241 -  
242 - public String getNetwork_address()  
243 - {  
244 - return network_address;  
245 - }  
246 - public void setNetwork_ip(String network_ip)  
247 - {  
248 - this.network_ip = network_ip;  
249 - }  
250 -  
251 - public String getNetwork_ip()  
252 - {  
253 - return network_ip;  
254 - }  
255 - public void setRssi(Integer rssi)  
256 - {  
257 - this.rssi = rssi;  
258 - }  
259 -  
260 - public Integer getRssi()  
261 - {  
262 - return rssi;  
263 - }  
264 - public void setStatus(Integer status)  
265 - {  
266 - this.status = status;  
267 - }  
268 -  
269 - public Integer getStatus()  
270 - {  
271 - return status;  
272 - }  
273 - public void setSummary(String summary)  
274 - {  
275 - this.summary = summary;  
276 - }  
277 -  
278 - public String getSummary()  
279 - {  
280 - return summary;  
281 - }  
282 - public void setThings_model_value(String things_model_value)  
283 - {  
284 - this.things_model_value = things_model_value;  
285 - }  
286 -  
287 - public String getThings_model_value()  
288 - {  
289 - return things_model_value;  
290 - }  
291 - public void setUpdate_by(String update_by)  
292 - {  
293 - this.update_by = update_by;  
294 - }  
295 -  
296 - public String getUpdate_by()  
297 - {  
298 - return update_by;  
299 - }  
300 - public void setUpdate_time(Integer update_time)  
301 - {  
302 - this.update_time = update_time;  
303 - }  
304 -  
305 - public Integer getUpdate_time()  
306 - {  
307 - return update_time;  
308 - }  
309 - public void setUser_id(Integer user_id)  
310 - {  
311 - this.user_id = user_id;  
312 - }  
313 -  
314 - public Integer getUser_id()  
315 - {  
316 - return user_id;  
317 - }  
318 -  
319 - @Override  
320 - public String toString() {  
321 - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)  
322 - .append("active_time", getActive_time())  
323 - .append("client_id", getClient_id())  
324 - .append("completion_auth", getCompletion_auth())  
325 - .append("create_by", getCreate_by())  
326 - .append("create_time", getCreate_time())  
327 - .append("del_flag", getDel_flag())  
328 - .append("firmware_version", getFirmware_version())  
329 - .append("img_url", getImg_url())  
330 - .append("is_shadow", getIs_shadow())  
331 - .append("latitude", getLatitude())  
332 - .append("location_way", getLocation_way())  
333 - .append("longitude", getLongitude())  
334 - .append("name", getName())  
335 - .append("network_address", getNetwork_address())  
336 - .append("network_ip", getNetwork_ip())  
337 - .append("remark", getRemark())  
338 - .append("rssi", getRssi())  
339 - .append("status", getStatus())  
340 - .append("summary", getSummary())  
341 - .append("things_model_value", getThings_model_value())  
342 - .append("update_by", getUpdate_by())  
343 - .append("update_time", getUpdate_time())  
344 - .append("user_id", getUser_id())  
345 - .toString();  
346 - }  
347 -}