正在显示
66 个修改的文件
包含
1913 行增加
和
151 行删除
lh-modules/lh-admin/src/main/java/com/zhonglai/luhui/admin/controller/data/SenserDataController.java
| @@ -31,11 +31,11 @@ public class SenserDataController { | @@ -31,11 +31,11 @@ public class SenserDataController { | ||
| 31 | @ApiImplicitParam(value = "数据类型",name = "type"), | 31 | @ApiImplicitParam(value = "数据类型",name = "type"), |
| 32 | @ApiImplicitParam(value = "日期(2024-06-05)",name = "day") | 32 | @ApiImplicitParam(value = "日期(2024-06-05)",name = "day") |
| 33 | }) | 33 | }) |
| 34 | - @GetMapping(value = "/oneDay/{deviceInfiId}/{type}/{day}") | 34 | + @GetMapping(value = "/oneDay/{deviceInfoId}/{type}/{day}") |
| 35 | public AjaxResult oneDay(@PathVariable String deviceInfoId, @PathVariable String type, @PathVariable String day) | 35 | public AjaxResult oneDay(@PathVariable String deviceInfoId, @PathVariable String type, @PathVariable String day) |
| 36 | { | 36 | { |
| 37 | String table = TableUtil.getTableName(day,"ly_sensor_data","device_sensor_data",3); | 37 | String table = TableUtil.getTableName(day,"ly_sensor_data","device_sensor_data",3); |
| 38 | - List<Map<String,Object>> list = publicService.getObjectListBySQL("select creat_time,data_value from `"+table+"` where device_info_id='"+deviceInfoId+"' and data_type='"+type+"'"); | 38 | + List<Map<String,Object>> list = publicService.getObjectListBySQL("select DATE_FORMAT(FROM_UNIXTIME(creat_time), '%Y-%m-%d %H:%i:%s') `time`,data_value from `"+table.replace(".","`.`")+"` where device_info_id='"+deviceInfoId+"' and data_type='"+type+"'"); |
| 39 | return AjaxResult.success(list); | 39 | return AjaxResult.success(list); |
| 40 | } | 40 | } |
| 41 | 41 |
| 1 | +package com.zhonglai.luhui.admin.controller.iot; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.annotation.Log; | ||
| 5 | +import com.ruoyi.common.constant.HttpStatus; | ||
| 6 | +import com.ruoyi.common.core.domain.AjaxResult; | ||
| 7 | +import com.ruoyi.common.core.domain.Message; | ||
| 8 | +import com.ruoyi.common.enums.BusinessType; | ||
| 9 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 10 | +import com.zhonglai.luhui.action.BaseController; | ||
| 11 | +import com.zhonglai.luhui.device.dto.CommandType; | ||
| 12 | +import com.zhonglai.luhui.device.dto.DeviceCommand; | ||
| 13 | +import com.zhonglai.luhui.rocketmq.service.RocketMqService; | ||
| 14 | +import io.swagger.annotations.Api; | ||
| 15 | +import io.swagger.annotations.ApiImplicitParam; | ||
| 16 | +import io.swagger.annotations.ApiImplicitParams; | ||
| 17 | +import io.swagger.annotations.ApiOperation; | ||
| 18 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 19 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 20 | +import org.springframework.util.StreamUtils; | ||
| 21 | +import org.springframework.web.bind.annotation.PathVariable; | ||
| 22 | +import org.springframework.web.bind.annotation.PostMapping; | ||
| 23 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 24 | +import org.springframework.web.bind.annotation.RestController; | ||
| 25 | + | ||
| 26 | +import javax.servlet.http.HttpServletRequest; | ||
| 27 | +import java.io.IOException; | ||
| 28 | + | ||
| 29 | +@Api(tags = "设备控制") | ||
| 30 | +@RestController | ||
| 31 | +@RequestMapping("/iot/controlDevice") | ||
| 32 | +public class ControlDeviceConreoller extends BaseController { | ||
| 33 | + @Autowired | ||
| 34 | + private RocketMqService rocketMqService; | ||
| 35 | + @ApiOperation(value = "写指令",notes = "body参数描述:\r\n" + | ||
| 36 | + "{\n" + | ||
| 37 | + " \"0\":{\n" + | ||
| 38 | + " \"rssi\": -43,\n" + | ||
| 39 | + " \"firmware_version\": 1.2,\n" + | ||
| 40 | + " \"longitude\": 0,\n" + | ||
| 41 | + " \"latitude\": 0,\n" + | ||
| 42 | + " \"summary\": {\n" + | ||
| 43 | + " \t \"name\": \"wumei-smart\",\n" + | ||
| 44 | + " \t \"chip\": \"esp8266\",\n" + | ||
| 45 | + " \t \"author\": \"kerwincui\",\n" + | ||
| 46 | + " \t \"version\": 1.2,\n" + | ||
| 47 | + " \t \"createTime\": \"2022-06-06\"\n" + | ||
| 48 | + " }\n" + | ||
| 49 | + " },\n" + | ||
| 50 | + " \"1\":{\n" + | ||
| 51 | + " \"id1\":\"value1\",\n" + | ||
| 52 | + " \"id2\":\"value2\",\n" + | ||
| 53 | + " \"id3\":\"value3\"\n" + | ||
| 54 | + " }\n" + | ||
| 55 | + "}") | ||
| 56 | + @ApiImplicitParams({ | ||
| 57 | + @ApiImplicitParam(value = "网关id",name = "deviceId"), | ||
| 58 | + }) | ||
| 59 | + @PreAuthorize("@ss.hasPermi('iot:controlDevice:write')") | ||
| 60 | + @Log(title = "写指令", businessType = BusinessType.WRITE) | ||
| 61 | + @PostMapping("/write/{deviceId}") | ||
| 62 | + public AjaxResult write(@PathVariable String deviceId, HttpServletRequest request) throws IOException { | ||
| 63 | + byte[] bodyBytes = StreamUtils.copyToByteArray(request.getInputStream()); | ||
| 64 | + String body = new String(bodyBytes, request.getCharacterEncoding()); | ||
| 65 | + DeviceCommand deviceCommand = new DeviceCommand(); | ||
| 66 | + deviceCommand.setDeviceId(deviceId); | ||
| 67 | + deviceCommand.setCommandType(CommandType.write); | ||
| 68 | + deviceCommand.setData(GsonConstructor.get().fromJson(body,JsonObject.class)); | ||
| 69 | + return control(deviceCommand); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + @ApiOperation("更新缓存模型") | ||
| 73 | + @ApiImplicitParam(value = "产品id",name = "product_id") | ||
| 74 | + @PreAuthorize("@ss.hasPermi('iot:controlDevice:upIotThingsModel')") | ||
| 75 | + @Log(title = "更新缓存模型", businessType = BusinessType.CAHE) | ||
| 76 | + @PostMapping("/upIotThingsModel/{product_id}") | ||
| 77 | + public AjaxResult upIotThingsModel(@PathVariable Integer product_id) throws IOException { | ||
| 78 | + DeviceCommand deviceCommand = new DeviceCommand(); | ||
| 79 | + deviceCommand.setCommandType(CommandType.upIotThingsModel); | ||
| 80 | + JsonObject jsonObject = new JsonObject(); | ||
| 81 | + jsonObject.addProperty("product_id",product_id); | ||
| 82 | + deviceCommand.setData(jsonObject); | ||
| 83 | + return control(deviceCommand); | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + @ApiOperation("更新缓存翻译模型") | ||
| 87 | + @ApiImplicitParam(value = "产品id",name = "product_id") | ||
| 88 | + @PreAuthorize("@ss.hasPermi('iot:controlDevice:upIotThingsModelTranslate')") | ||
| 89 | + @Log(title = "更新缓存翻译模型", businessType = BusinessType.CAHE) | ||
| 90 | + @PostMapping("/upIotThingsModelTranslate/{product_id}") | ||
| 91 | + public AjaxResult upIotThingsModelTranslate(@PathVariable Integer product_id) throws IOException { | ||
| 92 | + DeviceCommand deviceCommand = new DeviceCommand(); | ||
| 93 | + deviceCommand.setCommandType(CommandType.upIotThingsModelTranslate); | ||
| 94 | + JsonObject jsonObject = new JsonObject(); | ||
| 95 | + jsonObject.addProperty("product_id",product_id); | ||
| 96 | + deviceCommand.setData(jsonObject); | ||
| 97 | + return control(deviceCommand); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + @ApiOperation("清除网关缓存") | ||
| 101 | + @ApiImplicitParam(value = "网关id",name = "deviceId") | ||
| 102 | + @PreAuthorize("@ss.hasPermi('iot:controlDevice:cleanDeviceHost')") | ||
| 103 | + @Log(title = "清除网关缓存", businessType = BusinessType.CAHE) | ||
| 104 | + @PostMapping("/cleanDeviceHost/{deviceId}") | ||
| 105 | + public AjaxResult cleanDeviceHost(@PathVariable String deviceId) throws IOException { | ||
| 106 | + DeviceCommand deviceCommand = new DeviceCommand(); | ||
| 107 | + deviceCommand.setDeviceId(deviceId); | ||
| 108 | + deviceCommand.setCommandType(CommandType.cleanDeviceHost); | ||
| 109 | + return control(deviceCommand); | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + @ApiOperation("更新终端缓存") | ||
| 113 | + @ApiImplicitParams({ | ||
| 114 | + @ApiImplicitParam(value = "网关id",name = "deviceId"), | ||
| 115 | + @ApiImplicitParam(value = "终端编号",name = "sensor_number"), | ||
| 116 | + }) | ||
| 117 | + @PreAuthorize("@ss.hasPermi('iot:controlDevice:cleanDeviceInfo')") | ||
| 118 | + @Log(title = "更新终端缓存", businessType = BusinessType.CAHE) | ||
| 119 | + @PostMapping("/cleanDeviceInfo/{deviceId}") | ||
| 120 | + public AjaxResult cleanDeviceInfo(@PathVariable String deviceId,@PathVariable String sensor_number) { | ||
| 121 | + DeviceCommand deviceCommand = new DeviceCommand(); | ||
| 122 | + deviceCommand.setDeviceId(deviceId); | ||
| 123 | + deviceCommand.setCommandType(CommandType.cleanDeviceInfo); | ||
| 124 | + JsonObject jsonObject = new JsonObject(); | ||
| 125 | + jsonObject.addProperty("sensor_number",sensor_number); | ||
| 126 | + deviceCommand.setData(jsonObject); | ||
| 127 | + return control(deviceCommand); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + | ||
| 131 | + private AjaxResult control( DeviceCommand deviceCommand) | ||
| 132 | + { | ||
| 133 | + Message message = rocketMqService.send("deviceCommandListen",GsonConstructor.get().toJson(deviceCommand).getBytes()); | ||
| 134 | + if(message.getCode()==1) | ||
| 135 | + { | ||
| 136 | + return new AjaxResult(HttpStatus.SUCCESS, message.getMessage(), message.getData()); | ||
| 137 | + } | ||
| 138 | + return new AjaxResult(HttpStatus.ERROR, message.getMessage(), message.getData()); | ||
| 139 | + } | ||
| 140 | +} |
| @@ -44,7 +44,11 @@ | @@ -44,7 +44,11 @@ | ||
| 44 | <groupId>com.zhonglai.luhui</groupId> | 44 | <groupId>com.zhonglai.luhui</groupId> |
| 45 | <artifactId>lh-login</artifactId> | 45 | <artifactId>lh-login</artifactId> |
| 46 | </dependency> | 46 | </dependency> |
| 47 | - | 47 | + <!-- log --> |
| 48 | + <dependency> | ||
| 49 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 50 | + <artifactId>lh-common-log</artifactId> | ||
| 51 | + </dependency> | ||
| 48 | <!-- 其它模块 --> | 52 | <!-- 其它模块 --> |
| 49 | <dependency> | 53 | <dependency> |
| 50 | <groupId>com.zhonglai.luhui</groupId> | 54 | <groupId>com.zhonglai.luhui</groupId> |
| @@ -10,6 +10,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy; | @@ -10,6 +10,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy; | ||
| 10 | "com.ruoyi.common", | 10 | "com.ruoyi.common", |
| 11 | "com.ruoyi.system", | 11 | "com.ruoyi.system", |
| 12 | "com.ruoyi.framework", | 12 | "com.ruoyi.framework", |
| 13 | + "com.zhonglai.luhui.config", | ||
| 13 | "com.zhonglai.luhui.datasource", | 14 | "com.zhonglai.luhui.datasource", |
| 14 | "com.zhonglai.luhui.dao", | 15 | "com.zhonglai.luhui.dao", |
| 15 | "com.zhonglai.luhui.sys", | 16 | "com.zhonglai.luhui.sys", |
| @@ -20,6 +21,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy; | @@ -20,6 +21,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy; | ||
| 20 | "com.zhonglai.luhui.login.service", | 21 | "com.zhonglai.luhui.login.service", |
| 21 | "com.zhonglai.luhui.api", | 22 | "com.zhonglai.luhui.api", |
| 22 | "com.zhonglai.luhui.order.service", | 23 | "com.zhonglai.luhui.order.service", |
| 24 | + "com.zhonglai.luhui.log.aspectj" | ||
| 23 | }) | 25 | }) |
| 24 | @EnableAspectJAutoProxy(proxyTargetClass=true) | 26 | @EnableAspectJAutoProxy(proxyTargetClass=true) |
| 25 | @SpringBootApplication | 27 | @SpringBootApplication |
| @@ -18,7 +18,7 @@ public class JwtAuthenticationTokenFilterImpl extends JwtAuthenticationTokenFilt | @@ -18,7 +18,7 @@ public class JwtAuthenticationTokenFilterImpl extends JwtAuthenticationTokenFilt | ||
| 18 | 18 | ||
| 19 | @Override | 19 | @Override |
| 20 | public BaseLoginUser getBaseLoginUser(HttpServletRequest request) { | 20 | public BaseLoginUser getBaseLoginUser(HttpServletRequest request) { |
| 21 | - return tokenService.getLoginUser(request); | 21 | + return tokenService.getApiLoginUser(request); |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | @Override | 24 | @Override |
lh-modules/lh-api/src/main/java/com/zhonglai/luhui/api/controller/iot/ControlDeviceConreoller.java
0 → 100644
| 1 | +package com.zhonglai.luhui.api.controller.iot; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.annotation.Log; | ||
| 5 | +import com.ruoyi.common.constant.HttpStatus; | ||
| 6 | +import com.ruoyi.common.core.domain.AjaxResult; | ||
| 7 | +import com.ruoyi.common.core.domain.Message; | ||
| 8 | +import com.ruoyi.common.enums.BusinessType; | ||
| 9 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 10 | +import com.zhonglai.luhui.action.BaseController; | ||
| 11 | +import com.zhonglai.luhui.device.dto.CommandType; | ||
| 12 | +import com.zhonglai.luhui.device.dto.DeviceCommand; | ||
| 13 | +import com.zhonglai.luhui.rocketmq.service.RocketMqService; | ||
| 14 | +import io.swagger.annotations.Api; | ||
| 15 | +import io.swagger.annotations.ApiImplicitParam; | ||
| 16 | +import io.swagger.annotations.ApiImplicitParams; | ||
| 17 | +import io.swagger.annotations.ApiOperation; | ||
| 18 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 19 | +import org.springframework.util.StreamUtils; | ||
| 20 | +import org.springframework.web.bind.annotation.PathVariable; | ||
| 21 | +import org.springframework.web.bind.annotation.PostMapping; | ||
| 22 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 23 | +import org.springframework.web.bind.annotation.RestController; | ||
| 24 | + | ||
| 25 | +import javax.servlet.http.HttpServletRequest; | ||
| 26 | +import java.io.IOException; | ||
| 27 | + | ||
| 28 | +@Api(tags = "设备控制") | ||
| 29 | +@RestController | ||
| 30 | +@RequestMapping("/iot/controlDevice") | ||
| 31 | +public class ControlDeviceConreoller extends BaseController { | ||
| 32 | + @Autowired | ||
| 33 | + private RocketMqService rocketMqService; | ||
| 34 | + @ApiOperation(value = "写指令",notes = "body参数描述:\r\n" + | ||
| 35 | + "{\n" + | ||
| 36 | + " \"0\":{\n" + | ||
| 37 | + " \"rssi\": -43,\n" + | ||
| 38 | + " \"firmware_version\": 1.2,\n" + | ||
| 39 | + " \"longitude\": 0,\n" + | ||
| 40 | + " \"latitude\": 0,\n" + | ||
| 41 | + " \"summary\": {\n" + | ||
| 42 | + " \t \"name\": \"wumei-smart\",\n" + | ||
| 43 | + " \t \"chip\": \"esp8266\",\n" + | ||
| 44 | + " \t \"author\": \"kerwincui\",\n" + | ||
| 45 | + " \t \"version\": 1.2,\n" + | ||
| 46 | + " \t \"createTime\": \"2022-06-06\"\n" + | ||
| 47 | + " }\n" + | ||
| 48 | + " },\n" + | ||
| 49 | + " \"1\":{\n" + | ||
| 50 | + " \"id1\":\"value1\",\n" + | ||
| 51 | + " \"id2\":\"value2\",\n" + | ||
| 52 | + " \"id3\":\"value3\"\n" + | ||
| 53 | + " }\n" + | ||
| 54 | + "}") | ||
| 55 | + @ApiImplicitParams({ | ||
| 56 | + @ApiImplicitParam(value = "网关id",name = "deviceId"), | ||
| 57 | + }) | ||
| 58 | + @Log(title = "写指令", businessType = BusinessType.WRITE) | ||
| 59 | + @PostMapping("/write/{deviceId}") | ||
| 60 | + public AjaxResult write(@PathVariable String deviceId, HttpServletRequest request) throws IOException { | ||
| 61 | + byte[] bodyBytes = StreamUtils.copyToByteArray(request.getInputStream()); | ||
| 62 | + String body = new String(bodyBytes, request.getCharacterEncoding()); | ||
| 63 | + DeviceCommand deviceCommand = new DeviceCommand(); | ||
| 64 | + deviceCommand.setDeviceId(deviceId); | ||
| 65 | + deviceCommand.setCommandType(CommandType.write); | ||
| 66 | + deviceCommand.setData(GsonConstructor.get().fromJson(body,JsonObject.class)); | ||
| 67 | + return control(deviceCommand); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + @ApiOperation("更新缓存模型") | ||
| 71 | + @ApiImplicitParam(value = "产品id",name = "product_id") | ||
| 72 | + @Log(title = "更新缓存模型", businessType = BusinessType.CAHE) | ||
| 73 | + @PostMapping("/upIotThingsModel/{product_id}") | ||
| 74 | + public AjaxResult upIotThingsModel(@PathVariable Integer product_id) throws IOException { | ||
| 75 | + DeviceCommand deviceCommand = new DeviceCommand(); | ||
| 76 | + deviceCommand.setCommandType(CommandType.upIotThingsModel); | ||
| 77 | + JsonObject jsonObject = new JsonObject(); | ||
| 78 | + jsonObject.addProperty("product_id",product_id); | ||
| 79 | + deviceCommand.setData(jsonObject); | ||
| 80 | + return control(deviceCommand); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + @ApiOperation("更新缓存翻译模型") | ||
| 84 | + @ApiImplicitParam(value = "产品id",name = "product_id") | ||
| 85 | + @Log(title = "更新缓存翻译模型", businessType = BusinessType.CAHE) | ||
| 86 | + @PostMapping("/upIotThingsModelTranslate/{product_id}") | ||
| 87 | + public AjaxResult upIotThingsModelTranslate(@PathVariable Integer product_id) throws IOException { | ||
| 88 | + DeviceCommand deviceCommand = new DeviceCommand(); | ||
| 89 | + deviceCommand.setCommandType(CommandType.upIotThingsModelTranslate); | ||
| 90 | + JsonObject jsonObject = new JsonObject(); | ||
| 91 | + jsonObject.addProperty("product_id",product_id); | ||
| 92 | + deviceCommand.setData(jsonObject); | ||
| 93 | + return control(deviceCommand); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + @ApiOperation("清除网关缓存") | ||
| 97 | + @ApiImplicitParam(value = "网关id",name = "deviceId") | ||
| 98 | + @Log(title = "清除网关缓存", businessType = BusinessType.CAHE) | ||
| 99 | + @PostMapping("/cleanDeviceHost/{deviceId}") | ||
| 100 | + public AjaxResult cleanDeviceHost(@PathVariable String deviceId) throws IOException { | ||
| 101 | + DeviceCommand deviceCommand = new DeviceCommand(); | ||
| 102 | + deviceCommand.setDeviceId(deviceId); | ||
| 103 | + deviceCommand.setCommandType(CommandType.cleanDeviceHost); | ||
| 104 | + return control(deviceCommand); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + @ApiOperation("更新终端缓存") | ||
| 108 | + @ApiImplicitParams({ | ||
| 109 | + @ApiImplicitParam(value = "网关id",name = "deviceId"), | ||
| 110 | + @ApiImplicitParam(value = "终端编号",name = "sensor_number"), | ||
| 111 | + }) | ||
| 112 | + @Log(title = "更新终端缓存", businessType = BusinessType.CAHE) | ||
| 113 | + @PostMapping("/cleanDeviceInfo/{deviceId}") | ||
| 114 | + public AjaxResult cleanDeviceInfo(@PathVariable String deviceId,@PathVariable String sensor_number) { | ||
| 115 | + DeviceCommand deviceCommand = new DeviceCommand(); | ||
| 116 | + deviceCommand.setDeviceId(deviceId); | ||
| 117 | + deviceCommand.setCommandType(CommandType.cleanDeviceInfo); | ||
| 118 | + JsonObject jsonObject = new JsonObject(); | ||
| 119 | + jsonObject.addProperty("sensor_number",sensor_number); | ||
| 120 | + deviceCommand.setData(jsonObject); | ||
| 121 | + return control(deviceCommand); | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + | ||
| 125 | + private AjaxResult control( DeviceCommand deviceCommand) | ||
| 126 | + { | ||
| 127 | + Message message = rocketMqService.send("deviceCommandListen",GsonConstructor.get().toJson(deviceCommand).getBytes()); | ||
| 128 | + if(message.getCode()==1) | ||
| 129 | + { | ||
| 130 | + return new AjaxResult(HttpStatus.SUCCESS, message.getMessage(), message.getData()); | ||
| 131 | + } | ||
| 132 | + return new AjaxResult(HttpStatus.ERROR, message.getMessage(), message.getData()); | ||
| 133 | + } | ||
| 134 | +} |
| @@ -43,7 +43,7 @@ public class IotTerminalController extends BaseController | @@ -43,7 +43,7 @@ public class IotTerminalController extends BaseController | ||
| 43 | { | 43 | { |
| 44 | startPage(); | 44 | startPage(); |
| 45 | UserTerminalGroupRelation userTerminalGroupRelation = new UserTerminalGroupRelation(); | 45 | UserTerminalGroupRelation userTerminalGroupRelation = new UserTerminalGroupRelation(); |
| 46 | - userTerminalGroupRelation.setUser_info_id(SecurityUtils.getUserId().intValue()); | 46 | + userTerminalGroupRelation.setUser_info_id(Integer.parseInt(getLoginToken().getId())); |
| 47 | iotTerminal.setUserTerminalGroupRelation(userTerminalGroupRelation); | 47 | iotTerminal.setUserTerminalGroupRelation(userTerminalGroupRelation); |
| 48 | List<IotTerminal> list = iotTerminalService.selectIotTerminalListByUserId(iotTerminal); | 48 | List<IotTerminal> list = iotTerminalService.selectIotTerminalListByUserId(iotTerminal); |
| 49 | return getDataTable(list); | 49 | return getDataTable(list); |
| 1 | package com.zhonglai.luhui.api.service; | 1 | package com.zhonglai.luhui.api.service; |
| 2 | 2 | ||
| 3 | import com.ruoyi.common.exception.ServiceException; | 3 | import com.ruoyi.common.exception.ServiceException; |
| 4 | +import com.ruoyi.common.utils.DESUtil; | ||
| 4 | import com.ruoyi.common.utils.StringUtils; | 5 | import com.ruoyi.common.utils.StringUtils; |
| 5 | import com.zhonglai.luhui.dao.service.PublicService; | 6 | import com.zhonglai.luhui.dao.service.PublicService; |
| 6 | import com.zhonglai.luhui.security.dto.ApiLoginUser; | 7 | import com.zhonglai.luhui.security.dto.ApiLoginUser; |
| @@ -33,6 +34,7 @@ public class ApiUserDetailsServiceImpl implements UserDetailsService { | @@ -33,6 +34,7 @@ public class ApiUserDetailsServiceImpl implements UserDetailsService { | ||
| 33 | log.info("登录用户:{} 已被停用.", username); | 34 | log.info("登录用户:{} 已被停用.", username); |
| 34 | throw new ServiceException("对不起,您的账号:" + username + " 已停用"); | 35 | throw new ServiceException("对不起,您的账号:" + username + " 已停用"); |
| 35 | } | 36 | } |
| 37 | +// yu2leUserLogin.setLoginPass(DESUtil.decode(yu2leUserLogin.getLoginPass(),yu2leUserLogin.getUserLoginPassKey())); //接码 | ||
| 36 | return new ApiLoginUser(yu2leUserInfo, yu2leUserLogin); | 38 | return new ApiLoginUser(yu2leUserInfo, yu2leUserLogin); |
| 37 | } | 39 | } |
| 38 | } | 40 | } |
| @@ -4,6 +4,8 @@ import com.google.gson.JsonObject; | @@ -4,6 +4,8 @@ import com.google.gson.JsonObject; | ||
| 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 5 | import com.zhonglai.luhui.device.analysis.util.TopicUtil; | 5 | import com.zhonglai.luhui.device.analysis.util.TopicUtil; |
| 6 | import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory; | 6 | import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory; |
| 7 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 8 | +import com.zhonglai.luhui.device.protocol.http.analysis.analysis.topic.*; | ||
| 7 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
| 8 | 10 | ||
| 9 | public class ProtocolParserServiceImpl implements ProtocolParserFactory<JsonObject> { | 11 | public class ProtocolParserServiceImpl implements ProtocolParserFactory<JsonObject> { |
| @@ -17,7 +19,25 @@ public class ProtocolParserServiceImpl implements ProtocolParserFactory<JsonObje | @@ -17,7 +19,25 @@ public class ProtocolParserServiceImpl implements ProtocolParserFactory<JsonObje | ||
| 17 | } | 19 | } |
| 18 | 20 | ||
| 19 | @Override | 21 | @Override |
| 20 | - public JsonObject analysisPayload(Topic topic, JsonObject payload) { | ||
| 21 | - return payload; | 22 | + public AnalysisResult analysisPayload(Topic topic, JsonObject payload) { |
| 23 | + switch (topic.getTopicType()) | ||
| 24 | + { | ||
| 25 | + case "online": | ||
| 26 | + return new Online().analysisPayload(payload); | ||
| 27 | + case "ONLINE": | ||
| 28 | + return new Online().analysisPayload(payload); | ||
| 29 | + case "ALL_POST": | ||
| 30 | + return new AllPost().analysisPayload(payload); | ||
| 31 | + case "ADD_POST": | ||
| 32 | + return new AddPost().analysisPayload(payload); | ||
| 33 | + case "GET": | ||
| 34 | + return new Get().analysisPayload(payload); | ||
| 35 | + case "PUT_REQ": | ||
| 36 | + return new PutReq().analysisPayload(payload); | ||
| 37 | + case "READ_REQ": | ||
| 38 | + return new ReadReq().analysisPayload(payload); | ||
| 39 | + default: | ||
| 40 | + return new AnalysisResult(false,false,null); | ||
| 41 | + } | ||
| 22 | } | 42 | } |
| 23 | } | 43 | } |
| 1 | +package com.zhonglai.luhui.device.protocol.http.analysis.analysis.topic; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 6 | + | ||
| 7 | +public class AddPost { | ||
| 8 | + public AnalysisResult analysisPayload( JsonObject payload) | ||
| 9 | + { | ||
| 10 | + return new AnalysisResult(false,false,payload); | ||
| 11 | + } | ||
| 12 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.http.analysis.analysis.topic; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 6 | + | ||
| 7 | +public class AllPost { | ||
| 8 | + public AnalysisResult analysisPayload( JsonObject payload) | ||
| 9 | + { | ||
| 10 | + return new AnalysisResult(true,false,payload); | ||
| 11 | + } | ||
| 12 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.http.analysis.analysis.topic; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 6 | + | ||
| 7 | +public class Get { | ||
| 8 | + public AnalysisResult analysisPayload( JsonObject payload) | ||
| 9 | + { | ||
| 10 | + return new AnalysisResult(false,false,payload); | ||
| 11 | + } | ||
| 12 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.http.analysis.analysis.topic; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 5 | + | ||
| 6 | +public class Online { | ||
| 7 | + public AnalysisResult analysisPayload( JsonObject payload) | ||
| 8 | + { | ||
| 9 | + return new AnalysisResult(false,false,payload); | ||
| 10 | + } | ||
| 11 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.http.analysis.analysis.topic; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 6 | + | ||
| 7 | +public class PutReq { | ||
| 8 | + public AnalysisResult analysisPayload( JsonObject payload) | ||
| 9 | + { | ||
| 10 | + return new AnalysisResult(false,true,payload); | ||
| 11 | + } | ||
| 12 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.http.analysis.analysis.topic; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 6 | + | ||
| 7 | +public class ReadReq { | ||
| 8 | + public AnalysisResult analysisPayload( JsonObject payload) | ||
| 9 | + { | ||
| 10 | + return new AnalysisResult(false,true,payload); | ||
| 11 | + } | ||
| 12 | +} |
| @@ -4,19 +4,20 @@ import com.google.gson.JsonObject; | @@ -4,19 +4,20 @@ import com.google.gson.JsonObject; | ||
| 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 5 | import com.zhonglai.luhui.device.analysis.util.TopicUtil; | 5 | import com.zhonglai.luhui.device.analysis.util.TopicUtil; |
| 6 | import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory; | 6 | import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory; |
| 7 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 8 | +import com.zhonglai.luhui.device.protocol.modbus.TopicConfig; | ||
| 7 | import com.zhonglai.luhui.device.protocol.modbus.dto.ModbusDto; | 9 | import com.zhonglai.luhui.device.protocol.modbus.dto.ModbusDto; |
| 8 | 10 | ||
| 9 | public class ModbusProtocolParserFactoryImpl implements ProtocolParserFactory<byte[]> { | 11 | public class ModbusProtocolParserFactoryImpl implements ProtocolParserFactory<byte[]> { |
| 10 | - private static final String topicModel = "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{imei}}/{{topicType}}"; | ||
| 11 | 12 | ||
| 12 | @Override | 13 | @Override |
| 13 | public Topic analysisTopic(String topicStr) { | 14 | public Topic analysisTopic(String topicStr) { |
| 14 | - Topic topic = TopicUtil.initTopicFromModelStr(topicStr,topicModel); | 15 | + Topic topic = TopicUtil.initTopicFromModelStr(topicStr, TopicConfig.topicModel); |
| 15 | return topic; | 16 | return topic; |
| 16 | } | 17 | } |
| 17 | 18 | ||
| 18 | @Override | 19 | @Override |
| 19 | - public JsonObject analysisPayload(Topic topic, byte[] payload) { | 20 | + public AnalysisResult analysisPayload(Topic topic, byte[] payload) { |
| 20 | ModbusDto modbusDto = new ModbusDto(payload); | 21 | ModbusDto modbusDto = new ModbusDto(payload); |
| 21 | String senserNumber = "1"; | 22 | String senserNumber = "1"; |
| 22 | modbusDto.getCommdcode(); | 23 | modbusDto.getCommdcode(); |
| @@ -11,6 +11,8 @@ import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory | @@ -11,6 +11,8 @@ import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory | ||
| 11 | import com.zhonglai.luhui.device.protocol.factory.comm.DataLogType; | 11 | import com.zhonglai.luhui.device.protocol.factory.comm.DataLogType; |
| 12 | import com.zhonglai.luhui.device.protocol.factory.comm.DeviceDataLog; | 12 | import com.zhonglai.luhui.device.protocol.factory.comm.DeviceDataLog; |
| 13 | import com.zhonglai.luhui.device.protocol.factory.config.PluginsClassLoader; | 13 | import com.zhonglai.luhui.device.protocol.factory.config.PluginsClassLoader; |
| 14 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 15 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 14 | import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | 16 | import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; |
| 15 | import com.zhonglai.luhui.device.protocol.factory.plugins.InitPlugins; | 17 | import com.zhonglai.luhui.device.protocol.factory.plugins.InitPlugins; |
| 16 | import com.zhonglai.luhui.device.protocol.factory.purification.DefaultProtocolPurificationFactoryImpl; | 18 | import com.zhonglai.luhui.device.protocol.factory.purification.DefaultProtocolPurificationFactoryImpl; |
| @@ -50,10 +52,16 @@ public class ProtocolParserAndPurificationFactory<T> { | @@ -50,10 +52,16 @@ public class ProtocolParserAndPurificationFactory<T> { | ||
| 50 | //通过解析服务获取到topic | 52 | //通过解析服务获取到topic |
| 51 | Topic topic = protocolParserFactory.analysisTopic(topicStr); | 53 | Topic topic = protocolParserFactory.analysisTopic(topicStr); |
| 52 | //通过解析服务器将数据解析成键值对的形式存储到json对象里面,方便清洗 | 54 | //通过解析服务器将数据解析成键值对的形式存储到json对象里面,方便清洗 |
| 53 | - JsonObject jsonObject = protocolParserFactory.analysisPayload(topic,payload); | 55 | + AnalysisResult analysisResult = protocolParserFactory.analysisPayload(topic,payload); |
| 56 | + if(null == analysisResult.getJsonObject()) | ||
| 57 | + { | ||
| 58 | + return null; | ||
| 59 | + } | ||
| 54 | 60 | ||
| 55 | //通过模式对解析结果进行清洗,获得到的数据就是业务数据 | 61 | //通过模式对解析结果进行清洗,获得到的数据就是业务数据 |
| 56 | - ProtocolPurificationModel protocolPurificationModel = protocolPurificationFactory.purification(iotProduct.getId(),topic,jsonObject); | 62 | + ProtocolPurificationModel protocolPurificationModel = protocolPurificationFactory.purification(iotProduct.getId(),topic,analysisResult); |
| 63 | + protocolPurificationModel.setNoticeClien(analysisResult.isNoticeClien()); | ||
| 64 | + protocolPurificationModel.setNoticeMessage(analysisResult.getNoticeMessage()); | ||
| 57 | return protocolPurificationModel; | 65 | return protocolPurificationModel; |
| 58 | 66 | ||
| 59 | } | 67 | } |
| @@ -4,6 +4,8 @@ import com.google.gson.JsonObject; | @@ -4,6 +4,8 @@ import com.google.gson.JsonObject; | ||
| 4 | import com.ruoyi.common.utils.GsonConstructor; | 4 | import com.ruoyi.common.utils.GsonConstructor; |
| 5 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 5 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 6 | import com.zhonglai.luhui.device.analysis.util.TopicUtil; | 6 | import com.zhonglai.luhui.device.analysis.util.TopicUtil; |
| 7 | +import com.zhonglai.luhui.device.protocol.factory.analysis.topic.*; | ||
| 8 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 7 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
| 8 | 10 | ||
| 9 | public class DefaultProtocolParserFactoryImpl implements ProtocolParserFactory<byte[]>{ | 11 | public class DefaultProtocolParserFactoryImpl implements ProtocolParserFactory<byte[]>{ |
| @@ -16,8 +18,27 @@ public class DefaultProtocolParserFactoryImpl implements ProtocolParserFactory<b | @@ -16,8 +18,27 @@ public class DefaultProtocolParserFactoryImpl implements ProtocolParserFactory<b | ||
| 16 | } | 18 | } |
| 17 | 19 | ||
| 18 | @Override | 20 | @Override |
| 19 | - public JsonObject analysisPayload(Topic topic, byte[] payload) { | ||
| 20 | - return GsonConstructor.get().fromJson(new String(payload), JsonObject.class); | 21 | + public AnalysisResult analysisPayload(Topic topic, byte[] payload) { |
| 22 | + switch (topic.getTopicType()) | ||
| 23 | + { | ||
| 24 | + case "online": | ||
| 25 | + return new Online().analysisPayload(payload); | ||
| 26 | + case "ONLINE": | ||
| 27 | + return new Online().analysisPayload(payload); | ||
| 28 | + case "ALL_POST": | ||
| 29 | + return new AllPost().analysisPayload(payload); | ||
| 30 | + case "ADD_POST": | ||
| 31 | + return new AddPost().analysisPayload(payload); | ||
| 32 | + case "GET": | ||
| 33 | + return new Get().analysisPayload(payload); | ||
| 34 | + case "PUT_REQ": | ||
| 35 | + return new PutReq().analysisPayload(payload); | ||
| 36 | + case "READ_REQ": | ||
| 37 | + return new ReadReq().analysisPayload(payload); | ||
| 38 | + default: | ||
| 39 | + return new AnalysisResult(false,false,null); | ||
| 40 | + } | ||
| 41 | + | ||
| 21 | } | 42 | } |
| 22 | 43 | ||
| 23 | } | 44 | } |
| @@ -2,6 +2,7 @@ package com.zhonglai.luhui.device.protocol.factory.analysis; | @@ -2,6 +2,7 @@ package com.zhonglai.luhui.device.protocol.factory.analysis; | ||
| 2 | 2 | ||
| 3 | import com.google.gson.JsonObject; | 3 | import com.google.gson.JsonObject; |
| 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 5 | 6 | ||
| 6 | /** | 7 | /** |
| 7 | * 协议解析工厂 | 8 | * 协议解析工厂 |
| @@ -9,5 +10,5 @@ import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | @@ -9,5 +10,5 @@ import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 9 | */ | 10 | */ |
| 10 | public interface ProtocolParserFactory<T> { | 11 | public interface ProtocolParserFactory<T> { |
| 11 | Topic analysisTopic(String topicStr); | 12 | Topic analysisTopic(String topicStr); |
| 12 | - JsonObject analysisPayload(Topic topic, T payload); | 13 | + AnalysisResult analysisPayload(Topic topic, T payload); |
| 13 | } | 14 | } |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.analysis.topic; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 6 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 7 | + | ||
| 8 | +public class AddPost { | ||
| 9 | + public AnalysisResult analysisPayload( byte[] payload) | ||
| 10 | + { | ||
| 11 | + JsonObject jsonObject = GsonConstructor.get().fromJson(new String(payload), JsonObject.class); | ||
| 12 | + return new AnalysisResult(false,false,jsonObject); | ||
| 13 | + } | ||
| 14 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.analysis.topic; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 6 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 7 | + | ||
| 8 | +public class AllPost { | ||
| 9 | + public AnalysisResult analysisPayload( byte[] payload) | ||
| 10 | + { | ||
| 11 | + JsonObject jsonObject = GsonConstructor.get().fromJson(new String(payload), JsonObject.class); | ||
| 12 | + return new AnalysisResult(true,false,jsonObject); | ||
| 13 | + } | ||
| 14 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.analysis.topic; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 6 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 7 | + | ||
| 8 | +public class Get { | ||
| 9 | + public AnalysisResult analysisPayload( byte[] payload) | ||
| 10 | + { | ||
| 11 | + JsonObject jsonObject = GsonConstructor.get().fromJson(new String(payload), JsonObject.class); | ||
| 12 | + return new AnalysisResult(false,false,jsonObject); | ||
| 13 | + } | ||
| 14 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.analysis.topic; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 6 | + | ||
| 7 | +public class Online { | ||
| 8 | + public AnalysisResult analysisPayload( byte[] payload) | ||
| 9 | + { | ||
| 10 | + JsonObject jsonObject = new JsonObject(); | ||
| 11 | + JsonObject object = new JsonObject(); | ||
| 12 | + object.addProperty("online",new String(payload)); | ||
| 13 | + jsonObject.add("0",object); | ||
| 14 | + return new AnalysisResult(false,false,jsonObject); | ||
| 15 | + } | ||
| 16 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.analysis.topic; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 6 | + | ||
| 7 | +public class PutReq { | ||
| 8 | + public AnalysisResult analysisPayload(byte[] payload) | ||
| 9 | + { | ||
| 10 | + JsonObject jsonObject = GsonConstructor.get().fromJson(new String(payload), JsonObject.class); | ||
| 11 | + return new AnalysisResult(false,true,jsonObject); | ||
| 12 | + } | ||
| 13 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.analysis.topic; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 6 | + | ||
| 7 | +public class ReadReq { | ||
| 8 | + public AnalysisResult analysisPayload(byte[] payload) | ||
| 9 | + { | ||
| 10 | + JsonObject jsonObject = GsonConstructor.get().fromJson(new String(payload), JsonObject.class); | ||
| 11 | + return new AnalysisResult(false,true,jsonObject); | ||
| 12 | + } | ||
| 13 | +} |
| @@ -30,7 +30,7 @@ public class DeviceCach { | @@ -30,7 +30,7 @@ public class DeviceCach { | ||
| 30 | log.info("超时清除>>>>>>>:{} ",s); | 30 | log.info("超时清除>>>>>>>:{} ",s); |
| 31 | } | 31 | } |
| 32 | }) | 32 | }) |
| 33 | - .expirationPolicy(ExpirationPolicy.CREATED).build(); | 33 | + .expirationPolicy(ExpirationPolicy.ACCESSED).build(); |
| 34 | 34 | ||
| 35 | private static ExpiringMap<String, ParserDeviceHostDto> parserDeviceHostDtoMap = ExpiringMap.builder().maxSize(20000).expiration(60, TimeUnit.SECONDS) | 35 | private static ExpiringMap<String, ParserDeviceHostDto> parserDeviceHostDtoMap = ExpiringMap.builder().maxSize(20000).expiration(60, TimeUnit.SECONDS) |
| 36 | .variableExpiration() | 36 | .variableExpiration() |
| @@ -40,17 +40,50 @@ public class DeviceCach { | @@ -40,17 +40,50 @@ public class DeviceCach { | ||
| 40 | log.info("超时清除>>>>>>>:{} ",s); | 40 | log.info("超时清除>>>>>>>:{} ",s); |
| 41 | } | 41 | } |
| 42 | }) | 42 | }) |
| 43 | - .expirationPolicy(ExpirationPolicy.CREATED).build(); | 43 | + .expirationPolicy(ExpirationPolicy.ACCESSED).build(); |
| 44 | 44 | ||
| 45 | public static void putDeviceInfo(ParserDeviceInfoDto parserDeviceInfoDto,Long device_life) | 45 | public static void putDeviceInfo(ParserDeviceInfoDto parserDeviceInfoDto,Long device_life) |
| 46 | { | 46 | { |
| 47 | - parserDeviceInfoDtoMap.put(parserDeviceInfoDto.getId(),parserDeviceInfoDto,device_life,TimeUnit.SECONDS); | 47 | + if (parserDeviceInfoDtoMap.containsKey(parserDeviceInfoDto.getId())) |
| 48 | + { | ||
| 49 | + parserDeviceInfoDtoMap.put(parserDeviceInfoDto.getId(),parserDeviceInfoDto); | ||
| 50 | + }else{ | ||
| 51 | + parserDeviceInfoDtoMap.put(parserDeviceInfoDto.getId(),parserDeviceInfoDto,device_life*3,TimeUnit.SECONDS); | ||
| 52 | + } | ||
| 48 | } | 53 | } |
| 49 | 54 | ||
| 50 | public static void putDeviceHost(ParserDeviceHostDto parserDeviceHostDto,Long device_life) | 55 | public static void putDeviceHost(ParserDeviceHostDto parserDeviceHostDto,Long device_life) |
| 51 | { | 56 | { |
| 52 | - parserDeviceHostDtoMap.put(parserDeviceHostDto.getId(),parserDeviceHostDto,device_life,TimeUnit.SECONDS); | 57 | + if(parserDeviceHostDtoMap.containsKey(parserDeviceHostDto.getId())) |
| 58 | + { | ||
| 59 | + parserDeviceHostDtoMap.put(parserDeviceHostDto.getId(),parserDeviceHostDto); | ||
| 60 | + }else { | ||
| 61 | + parserDeviceHostDtoMap.put(parserDeviceHostDto.getId(),parserDeviceHostDto,device_life*3,TimeUnit.SECONDS); | ||
| 62 | + } | ||
| 53 | } | 63 | } |
| 64 | + public static void cleanDeviceHost(String deviceId) | ||
| 65 | + { | ||
| 66 | + if (parserDeviceHostDtoMap.containsKey(deviceId)) | ||
| 67 | + { | ||
| 68 | + parserDeviceHostDtoMap.remove(deviceId); | ||
| 69 | + } | ||
| 70 | + for (String key :parserDeviceInfoDtoMap.keySet()) | ||
| 71 | + { | ||
| 72 | + if(key.startsWith(deviceId+"_")) | ||
| 73 | + { | ||
| 74 | + parserDeviceInfoDtoMap.remove(key); | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public static void cleanDeviceInfo(String deviceInfoId) | ||
| 80 | + { | ||
| 81 | + if (parserDeviceInfoDtoMap.containsKey(deviceInfoId)) | ||
| 82 | + { | ||
| 83 | + parserDeviceInfoDtoMap.remove(deviceInfoId); | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + | ||
| 54 | 87 | ||
| 55 | public static ParserDeviceInfoDto getDeviceInfo(String deviceInfoId) | 88 | public static ParserDeviceInfoDto getDeviceInfo(String deviceInfoId) |
| 56 | { | 89 | { |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.control; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 4 | +import com.zhonglai.luhui.device.analysis.dto.Message; | ||
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.NoticeMessageDto; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 指令通知服务工厂 | ||
| 9 | + */ | ||
| 10 | +public interface ClienNoticeServiceFactory { | ||
| 11 | + boolean sendMessage(NoticeMessageDto noticeMessageDomain); | ||
| 12 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.control; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.device.analysis.comm.clien.ClienConnection; | ||
| 6 | +import com.zhonglai.luhui.device.analysis.comm.clien.impl.ClienConnectionImpl; | ||
| 7 | +import com.zhonglai.luhui.device.analysis.comm.dto.ApiClientRePlyDto; | ||
| 8 | +import com.zhonglai.luhui.device.analysis.comm.dto.TerminalClientRePlyDto; | ||
| 9 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 10 | +import com.zhonglai.luhui.device.analysis.dto.Message; | ||
| 11 | +import com.zhonglai.luhui.device.analysis.dto.MessageCode; | ||
| 12 | +import com.zhonglai.luhui.device.analysis.util.TopicUtil; | ||
| 13 | +import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory; | ||
| 14 | +import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; | ||
| 15 | +import com.zhonglai.luhui.device.protocol.factory.config.PluginsClassLoader; | ||
| 16 | +import com.zhonglai.luhui.device.protocol.factory.dto.DeviceCommand; | ||
| 17 | +import com.zhonglai.luhui.device.protocol.factory.dto.NoticeMessageDto; | ||
| 18 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 19 | +import com.zhonglai.luhui.device.protocol.factory.service.IotThingsModelService; | ||
| 20 | +import com.zhonglai.luhui.device.protocol.factory.service.PersistenceDBService; | ||
| 21 | +import net.jodah.expiringmap.ExpirationListener; | ||
| 22 | +import net.jodah.expiringmap.ExpirationPolicy; | ||
| 23 | +import net.jodah.expiringmap.ExpiringMap; | ||
| 24 | +import org.apache.rocketmq.common.message.MessageExt; | ||
| 25 | +import org.apache.rocketmq.spring.annotation.MessageModel; | ||
| 26 | +import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; | ||
| 27 | +import org.apache.rocketmq.spring.annotation.SelectorType; | ||
| 28 | +import org.apache.rocketmq.spring.core.RocketMQReplyListener; | ||
| 29 | +import org.eclipse.paho.client.mqttv3.MqttException; | ||
| 30 | +import org.eclipse.paho.client.mqttv3.MqttMessage; | ||
| 31 | +import org.slf4j.Logger; | ||
| 32 | +import org.slf4j.LoggerFactory; | ||
| 33 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 34 | +import org.springframework.beans.factory.annotation.Value; | ||
| 35 | +import org.springframework.stereotype.Service; | ||
| 36 | + | ||
| 37 | +import java.util.Map; | ||
| 38 | +import java.util.concurrent.TimeUnit; | ||
| 39 | + | ||
| 40 | +/** | ||
| 41 | + * 设备指令监听服务 | ||
| 42 | + */ | ||
| 43 | +@Service | ||
| 44 | +@RocketMQMessageListener(consumerGroup = "deviceCommand", topic = "deviceCommandListen",messageModel = MessageModel.BROADCASTING) | ||
| 45 | +public class DeviceCommandListenService implements RocketMQReplyListener<MessageExt, Message> { | ||
| 46 | + private static final Logger log = LoggerFactory.getLogger(DeviceCommandListenService.class); | ||
| 47 | + | ||
| 48 | + private static ExpiringMap<String, ClienConnection> clienConnectionMap = ExpiringMap.builder().maxSize(20000).expiration(15, TimeUnit.SECONDS) | ||
| 49 | + .asyncExpirationListener(new ExpirationListener<String, ClienConnection>() { | ||
| 50 | + @Override | ||
| 51 | + public void expired(String s, ClienConnection clienConnection) { | ||
| 52 | + log.info("{} 通道消失了>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",s); | ||
| 53 | + clienConnection.close(); | ||
| 54 | + } | ||
| 55 | + }) | ||
| 56 | + .expirationPolicy(ExpirationPolicy.CREATED).build(); | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + @Autowired | ||
| 60 | + private PersistenceDBService persistenceDBService; | ||
| 61 | + | ||
| 62 | + @Autowired | ||
| 63 | + private ClienNoticeServiceFactory clienNoticeServiceFactory; | ||
| 64 | + | ||
| 65 | + @Autowired | ||
| 66 | + private IotThingsModelService iotThingsModelService; | ||
| 67 | + | ||
| 68 | + @Value("${mqtt.client.operationTime}") | ||
| 69 | + private long operationTime; //客户端操作时间 | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public Message onMessage(MessageExt messageExt) { | ||
| 73 | + log.info("监听到消息{}",messageExt); | ||
| 74 | + | ||
| 75 | + String str = new String(messageExt.getBody()); | ||
| 76 | + log.info("消息body{}",str); | ||
| 77 | + | ||
| 78 | + DeviceCommand deviceCommand = GsonConstructor.get().fromJson(str, DeviceCommand.class); | ||
| 79 | + ParserDeviceHostDto parserDeviceHostDto = DeviceCach.getDeviceHost(deviceCommand.getDeviceId()); | ||
| 80 | + if(null == parserDeviceHostDto) | ||
| 81 | + { | ||
| 82 | + return new Message(MessageCode.DEFAULT_FAIL_CODE,"设备连接丢失,请稍后尝试"); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + if (clienConnectionMap.containsKey(deviceCommand.getDeviceId())) | ||
| 86 | + { | ||
| 87 | + return new Message(MessageCode.DEFAULT_FAIL_CODE,"有其他人在控制设备,请稍后重试!"); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + String classname = persistenceDBService.getClassnameFromIotProtocolClassId(parserDeviceHostDto.getIotProduct().getAnalysis_clas()); | ||
| 91 | + try { | ||
| 92 | + ; | ||
| 93 | + ProtocolParserFactory protocolParserFactory = PluginsClassLoader.getJarClass(ProtocolParserFactory.class,classname); | ||
| 94 | + String controlCls = classname.replace("analysis."+protocolParserFactory.getClass().getSimpleName(),"control.DeviceCommandListenServiceImpl"); | ||
| 95 | + DeviceCommandServiceFactory deviceCommandServiceFactory = PluginsClassLoader.getJarClass(DeviceCommandServiceFactory.class,controlCls); | ||
| 96 | + if(null != deviceCommandServiceFactory) | ||
| 97 | + { | ||
| 98 | + switch (deviceCommand.getCommandType()) | ||
| 99 | + { | ||
| 100 | + case read: | ||
| 101 | + NoticeMessageDto noticeMessageDomain = deviceCommandServiceFactory.read(deviceCommand.getDeviceId(), deviceCommand.getData()); | ||
| 102 | + if(null == noticeMessageDomain) | ||
| 103 | + { | ||
| 104 | + new Message(MessageCode.DEFAULT_FAIL_CODE,"该设备不支持读取功能"); | ||
| 105 | + } | ||
| 106 | + return sendMessage(noticeMessageDomain); | ||
| 107 | + case write: | ||
| 108 | + noticeMessageDomain = deviceCommandServiceFactory.write(deviceCommand.getDeviceId(), deviceCommand.getData()); | ||
| 109 | + if(null == noticeMessageDomain) | ||
| 110 | + { | ||
| 111 | + new Message(MessageCode.DEFAULT_FAIL_CODE,"该设备不支持写入功能"); | ||
| 112 | + } | ||
| 113 | + return sendMessage(noticeMessageDomain); | ||
| 114 | + case notice: | ||
| 115 | + if(deviceCommandServiceFactory.notice(deviceCommand.getDeviceId(), deviceCommand.getData())) | ||
| 116 | + { | ||
| 117 | + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"指令发送成功"); | ||
| 118 | + }else { | ||
| 119 | + return new Message(MessageCode.DEFAULT_FAIL_CODE,"指令发送失败"); | ||
| 120 | + } | ||
| 121 | + case cleanDeviceHost: | ||
| 122 | + DeviceCach.cleanDeviceHost(deviceCommand.getDeviceId()); | ||
| 123 | + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"指令发送成功"); | ||
| 124 | + case cleanDeviceInfo: | ||
| 125 | + DeviceCach.cleanDeviceInfo(deviceCommand.getDeviceId()+"_"+deviceCommand.getData().get("sensor_number").getAsString()); | ||
| 126 | + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"指令发送成功"); | ||
| 127 | + case upIotThingsModel: | ||
| 128 | + iotThingsModelService.upIotThingsModel(deviceCommand.getData().get("product_id").getAsInt()); | ||
| 129 | + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"指令发送成功"); | ||
| 130 | + case upIotThingsModelTranslate: | ||
| 131 | + iotThingsModelService.upIotThingsModelTranslate(deviceCommand.getData().get("product_id").getAsInt()); | ||
| 132 | + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"指令发送成功"); | ||
| 133 | + default: | ||
| 134 | + return new Message(MessageCode.DEFAULT_FAIL_CODE,"指令类型不存在,请联系管理员"); | ||
| 135 | + } | ||
| 136 | + }else { | ||
| 137 | + return new Message(MessageCode.DEFAULT_FAIL_CODE,"该设备的控制服务异常,请联系管理员"); | ||
| 138 | + } | ||
| 139 | + } catch (InterruptedException e) { | ||
| 140 | + log.error("消息发送失败",e); | ||
| 141 | + return new Message(MessageCode.DEFAULT_FAIL_CODE,"等待通知错误"); | ||
| 142 | + } | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + public Message sendMessage( NoticeMessageDto noticeMessageDomain) throws InterruptedException { | ||
| 146 | + | ||
| 147 | + Topic topic = noticeMessageDomain.getTopic(); | ||
| 148 | + | ||
| 149 | + //设置通知渠道 | ||
| 150 | + ClienConnection clienConnection = new ClienConnectionImpl(); | ||
| 151 | + log.info("设置通知渠道 {} {}",topic.getClientid(),clienConnection); | ||
| 152 | + clienConnectionMap.put(topic.getClientid(),clienConnection); | ||
| 153 | + clienNoticeServiceFactory.sendMessage(noticeMessageDomain); | ||
| 154 | + synchronized(clienConnection) | ||
| 155 | + { | ||
| 156 | + log.info("{}等待通知",topic.getClientid()); | ||
| 157 | + clienConnection.wait(operationTime*1000+3000l); | ||
| 158 | + } | ||
| 159 | + //清楚通道 | ||
| 160 | + clienConnectionMap.remove(topic.getClientid()); | ||
| 161 | + log.info("{}收到通知{}",topic.getClientid(),clienConnection.getReplyMessage()); | ||
| 162 | + Message message = clienConnection.getReplyMessage(); | ||
| 163 | + log.info("{}返回通知{}",topic.getClientid(),message); | ||
| 164 | + | ||
| 165 | + return message; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + public ClienConnection getClienConnection(String clientid) | ||
| 169 | + { | ||
| 170 | + return clienConnectionMap.get(clientid); | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + public static boolean hasClienConnection(String clientid) | ||
| 174 | + { | ||
| 175 | + return clienConnectionMap.containsKey(clientid); | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + private void log(Topic topic,JsonObject jsonObject) | ||
| 179 | + { | ||
| 180 | +// AddPostDto addPostDto = new AddPostDto(); | ||
| 181 | +// addPostDto.setData(JSON.parseObject(jsonObject.toString())); | ||
| 182 | +// addPostDto.setIotTerminalList(new ArrayList<>()); | ||
| 183 | +// addPostDto.setDeviceSensorDataList(new ArrayList<>()); | ||
| 184 | +// addPostDto.setLogDeviceOperationList(new ArrayList<>()); | ||
| 185 | +// businessDataUpdateService.updataDta(BusinessDataUpdateService.Type.ADD,topic,addPostDto,"远程控制",true); | ||
| 186 | +// cacheServiceImpl.updateCache(topic,addPostDto); | ||
| 187 | +// addPostDto.setLogDeviceOperationList(logDeviceOperationList); | ||
| 188 | +// dataPersistenceService.persistence(topic,addPostDto); | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + /** | ||
| 192 | + * 通知给api操作端 | ||
| 193 | + * @param clientid | ||
| 194 | + * @param apiClientRePlyDto | ||
| 195 | + */ | ||
| 196 | + public void replySendMessage(String clientid, ApiClientRePlyDto apiClientRePlyDto) | ||
| 197 | + { | ||
| 198 | + log.info("开始通知{},数据:{}",clientid,apiClientRePlyDto); | ||
| 199 | + //判断有没有需要回复的客户端,如果有就回复 | ||
| 200 | + ClienConnection clienConnection = getClienConnection(clientid); | ||
| 201 | + if(null != clienConnection) | ||
| 202 | + { | ||
| 203 | + synchronized(clienConnection) | ||
| 204 | + { | ||
| 205 | + log.info("正在通知{},通知结果{}",clientid,apiClientRePlyDto); | ||
| 206 | + clienConnection.reply(apiClientRePlyDto); | ||
| 207 | + } | ||
| 208 | + } | ||
| 209 | + log.info("结束通知{}",clientid); | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.control; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.zhonglai.luhui.device.protocol.factory.dto.NoticeMessageDto; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 设备指令服务工厂 | ||
| 8 | + */ | ||
| 9 | +public interface DeviceCommandServiceFactory { | ||
| 10 | + NoticeMessageDto read(String deviceId, JsonObject jsonObject); | ||
| 11 | + NoticeMessageDto write(String deviceId, JsonObject jsonObject); | ||
| 12 | + | ||
| 13 | + boolean notice(String deviceId, JsonObject jsonObject); | ||
| 14 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.dto; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.zhonglai.luhui.device.analysis.comm.dto.ApiClientRePlyDto; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 解析结果 | ||
| 9 | + */ | ||
| 10 | +public class AnalysisResult { | ||
| 11 | + /** | ||
| 12 | + * 是否需要全部更新 | ||
| 13 | + */ | ||
| 14 | + private boolean isAllUp; | ||
| 15 | + /** | ||
| 16 | + * 是否需要通知 | ||
| 17 | + */ | ||
| 18 | + private boolean isNoticeClien; | ||
| 19 | + /** | ||
| 20 | + * 解析的数据 | ||
| 21 | + */ | ||
| 22 | + private JsonObject jsonObject; | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 通知消息 | ||
| 26 | + */ | ||
| 27 | + private ApiClientRePlyDto noticeMessage; | ||
| 28 | + | ||
| 29 | + public AnalysisResult(boolean isAllUp, boolean isNoticeClien, JsonObject jsonObject, ApiClientRePlyDto noticeMessage) { | ||
| 30 | + this.isAllUp = isAllUp; | ||
| 31 | + this.isNoticeClien = isNoticeClien; | ||
| 32 | + this.jsonObject = jsonObject; | ||
| 33 | + this.noticeMessage = noticeMessage; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public AnalysisResult(boolean isAllUp, boolean isNoticeClien, JsonObject jsonObject) { | ||
| 37 | + this.isAllUp = isAllUp; | ||
| 38 | + this.isNoticeClien = isNoticeClien; | ||
| 39 | + this.jsonObject = jsonObject; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public AnalysisResult() | ||
| 43 | + { | ||
| 44 | + this.isAllUp = false; | ||
| 45 | + this.isNoticeClien = false; | ||
| 46 | + this.jsonObject = null; | ||
| 47 | + this.noticeMessage = null; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + public ApiClientRePlyDto getNoticeMessage() { | ||
| 51 | + return noticeMessage; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + public void setNoticeMessage(ApiClientRePlyDto noticeMessage) { | ||
| 55 | + this.noticeMessage = noticeMessage; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public boolean isAllUp() { | ||
| 59 | + return isAllUp; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public void setAllUp(boolean allUp) { | ||
| 63 | + isAllUp = allUp; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public boolean isNoticeClien() { | ||
| 67 | + return isNoticeClien; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + public void setNoticeClien(boolean noticeClien) { | ||
| 71 | + isNoticeClien = noticeClien; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public JsonObject getJsonObject() { | ||
| 75 | + return jsonObject; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + public void setJsonObject(JsonObject jsonObject) { | ||
| 79 | + this.jsonObject = jsonObject; | ||
| 80 | + } | ||
| 81 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.dto; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +import java.math.BigDecimal; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 设备主机 | ||
| 9 | + * Created by zhonglai on 2017/5/24. | ||
| 10 | + */ | ||
| 11 | +@Data | ||
| 12 | +public class DeviceHost { | ||
| 13 | + private String id; // VARCHAR(50) NOT NULL COMMENT '设备IMEI号', | ||
| 14 | + private String deviceName; // VARCHAR(50) NOT NULL COMMENT '设备名称', | ||
| 15 | + private Integer userId; // INT(11) NOT NULL COMMENT '用户登录id', | ||
| 16 | + private String userLoginName; // VARCHAR(50) NOT NULL COMMENT '用户登录名', | ||
| 17 | + private String deviceModel; // VARCHAR(10) NOT NULL COMMENT '设备型号,(3,5,6_Y,6_P)', | ||
| 18 | + private String online; // VARCHAR(11) DEFAULT '00' COMMENT '设备在线状态(00-不在线,01-在线)', | ||
| 19 | + private Integer createTime; // INT(11) DEFAULT NULL COMMENT '添加时间', | ||
| 20 | + private String alarmCode; // VARCHAR(2) DEFAULT '00' COMMENT '设备告警状态', | ||
| 21 | + private Integer dataUpdateTime; // INT(11) DEFAULT NULL COMMENT '数据更新时间', | ||
| 22 | + private String deviceServiceIp; // VARCHAR(50) DEFAULT NULL COMMENT '设备连接服务器ip地址', | ||
| 23 | + private String data; // TEXT COMMENT '数据', | ||
| 24 | + private String userNickname; // VARCHAR(50) DEFAULT NULL COMMENT '用户昵称', | ||
| 25 | + private Integer alarmLastCreateTime; // int(11) DEFAULT NULL COMMENT '告警最后一次产生的时间', | ||
| 26 | + private Integer state; //0失效,1有效 | ||
| 27 | + private String alDeviceSecret; //阿里云的设备密钥 | ||
| 28 | + private Integer isInsertAl; //是否加入阿里云 | ||
| 29 | + | ||
| 30 | + private BigDecimal longitude; //经度 | ||
| 31 | + private BigDecimal latitude; //纬度 | ||
| 32 | + private String provinceId; // varchar(50) DEFAULT NULL COMMENT '省id', | ||
| 33 | + private String cityId; // varchar(50) DEFAULT NULL COMMENT '市id', | ||
| 34 | + private String countyId; // varchar(50) DEFAULT NULL COMMENT '县id', | ||
| 35 | + private String provinceName; // varchar(50) DEFAULT NULL COMMENT '省名称', | ||
| 36 | + private String cityName; // varchar(50) DEFAULT NULL COMMENT '市名称', | ||
| 37 | + private String countyName; // varchar(50) DEFAULT NULL COMMENT '县名称', | ||
| 38 | + private String address; // varchar(50) DEFAULT NULL COMMENT '地址', | ||
| 39 | + | ||
| 40 | + private String remoteAddress; //远程地址 | ||
| 41 | + private String addressId; //远程地址id | ||
| 42 | + private Integer intervalTime; //数据更新离线间隔时间(单位s) | ||
| 43 | + | ||
| 44 | + public String getTableName() | ||
| 45 | + { | ||
| 46 | + return "`liu_yu_le`.`device_host`"; | ||
| 47 | + } | ||
| 48 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.dto; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 设备信息表 | ||
| 7 | + * @author Administrator | ||
| 8 | + * | ||
| 9 | + */ | ||
| 10 | +public class DeviceInfo { | ||
| 11 | + | ||
| 12 | + private String id; // varchar(50) NOT NULL COMMENT '设备编号,如:设备imei号_传感器编号', | ||
| 13 | + private String deviceId; // varchar(50) NOT NULL COMMENT '设备IMEI号', | ||
| 14 | + private String deviceName; // varchar(50) DEFAULT NULL COMMENT '设备名称', | ||
| 15 | + private Integer userId; // int(11) DEFAULT NULL COMMENT '用户登录id', | ||
| 16 | + private String userLoginName; // varchar(50) DEFAULT NULL COMMENT '用户登录名', | ||
| 17 | + private Integer pondId; // int(11) DEFAULT NULL COMMENT '塘口id', | ||
| 18 | + private String sensorNumber; // varchar(10) NOT NULL DEFAULT '01' COMMENT '传感器编号,默认01', | ||
| 19 | + private String deviceModel; // varchar(10) NOT NULL COMMENT '设备型号,(3,5,6)', | ||
| 20 | + private String deviceType; // varchar(10) DEFAULT NULL COMMENT '设备类型(0传感器,1开关控制器)', | ||
| 21 | + private String online; // varchar(10) DEFAULT NULL COMMENT '设备在线状态(00-不在线,01-在线)', | ||
| 22 | + private Integer createTime; // int(11) DEFAULT NULL COMMENT '添加时间', | ||
| 23 | + private String alarmCode; // varchar(10) DEFAULT NULL COMMENT '设备告警状态', | ||
| 24 | + private Integer dataUpdateTime; // int(11) DEFAULT NULL COMMENT '数据更新时间', | ||
| 25 | + private String dataState; // text COMMENT '数据状态(json串)', | ||
| 26 | + private String pondName; // varchar(50) DEFAULT NULL COMMENT '塘口名称', | ||
| 27 | + private String userNickname; // varchar(50) DEFAULT NULL COMMENT '用户昵称', | ||
| 28 | + private Integer alarmLastCreateTime; // int(11) DEFAULT NULL COMMENT '告警最后一次产生的时间', | ||
| 29 | + private String deviceServiceIp; //设备链接服务器地址 | ||
| 30 | + private Integer alarmSqlApply; //告警sql规则申请(0-未申请,1-已申请) | ||
| 31 | + private String deviceConfig; //设备配置 | ||
| 32 | + private Integer sensor_type; //传感器类型(0禹山,1北京的) | ||
| 33 | + private Integer deviceClose; //是否关闭设备(0否,1是) | ||
| 34 | + | ||
| 35 | + public Integer getDeviceClose() { | ||
| 36 | + return deviceClose; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public void setDeviceClose(Integer deviceClose) { | ||
| 40 | + this.deviceClose = deviceClose; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public Integer getSensor_type() { | ||
| 44 | + return sensor_type; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public void setSensor_type(Integer sensor_type) { | ||
| 48 | + this.sensor_type = sensor_type; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public Integer getAlarmSqlApply() { | ||
| 52 | + return alarmSqlApply; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public String getDeviceConfig() { | ||
| 56 | + return deviceConfig; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void setDeviceConfig(String deviceConfig) { | ||
| 60 | + this.deviceConfig = deviceConfig; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public void setAlarmSqlApply(Integer alarmSqlApply) { | ||
| 64 | + this.alarmSqlApply = alarmSqlApply; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public String getId() { | ||
| 68 | + return id; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public void setId(String id) { | ||
| 72 | + this.id = id; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public String getDeviceId() { | ||
| 76 | + return deviceId; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public void setDeviceId(String deviceId) { | ||
| 80 | + this.deviceId = deviceId; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public String getDeviceName() { | ||
| 84 | + return deviceName; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public void setDeviceName(String deviceName) { | ||
| 88 | + this.deviceName = deviceName; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public Integer getUserId() { | ||
| 92 | + return userId; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + public void setUserId(Integer userId) { | ||
| 96 | + this.userId = userId; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public String getUserLoginName() { | ||
| 100 | + return userLoginName; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + public void setUserLoginName(String userLoginName) { | ||
| 104 | + this.userLoginName = userLoginName; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + public Integer getPondId() { | ||
| 108 | + return pondId; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public void setPondId(Integer pondId) { | ||
| 112 | + this.pondId = pondId; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + public String getSensorNumber() { | ||
| 116 | + return sensorNumber; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + public void setSensorNumber(String sensorNumber) { | ||
| 120 | + this.sensorNumber = sensorNumber; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + public String getDeviceModel() { | ||
| 124 | + return deviceModel; | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + public void setDeviceModel(String deviceModel) { | ||
| 128 | + this.deviceModel = deviceModel; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + public String getDeviceType() { | ||
| 132 | + return deviceType; | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + public void setDeviceType(String deviceType) { | ||
| 136 | + this.deviceType = deviceType; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + public String getOnline() { | ||
| 140 | + return online; | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + public void setOnline(String online) { | ||
| 144 | + this.online = online; | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + public Integer getCreateTime() { | ||
| 148 | + return createTime; | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + public void setCreateTime(Integer createTime) { | ||
| 152 | + this.createTime = createTime; | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + public String getAlarmCode() { | ||
| 156 | + return alarmCode; | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + public void setAlarmCode(String alarmCode) { | ||
| 160 | + this.alarmCode = alarmCode; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + public Integer getDataUpdateTime() { | ||
| 164 | + return dataUpdateTime; | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + public void setDataUpdateTime(Integer dataUpdateTime) { | ||
| 168 | + this.dataUpdateTime = dataUpdateTime; | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + public String getDataState() { | ||
| 172 | + return dataState; | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + public void setDataState(String dataState) { | ||
| 176 | + this.dataState = dataState; | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + public String getPondName() { | ||
| 180 | + return pondName; | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + public void setPondName(String pondName) { | ||
| 184 | + this.pondName = pondName; | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + public String getUserNickname() { | ||
| 188 | + return userNickname; | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + public void setUserNickname(String userNickname) { | ||
| 192 | + this.userNickname = userNickname; | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + public Integer getAlarmLastCreateTime() { | ||
| 196 | + return alarmLastCreateTime; | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + public void setAlarmLastCreateTime(Integer alarmLastCreateTime) { | ||
| 200 | + this.alarmLastCreateTime = alarmLastCreateTime; | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + public String getDeviceServiceIp() { | ||
| 204 | + return deviceServiceIp; | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + public void setDeviceServiceIp(String deviceServiceIp) { | ||
| 208 | + this.deviceServiceIp = deviceServiceIp; | ||
| 209 | + } | ||
| 210 | + public String getTableName() | ||
| 211 | + { | ||
| 212 | + return "`liu_yu_le`.`device_info`"; | ||
| 213 | + } | ||
| 214 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.dto; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 通知消息 | ||
| 7 | + */ | ||
| 8 | +public class NoticeMessageDto { | ||
| 9 | + private Topic topic; | ||
| 10 | + private String topicconfig; | ||
| 11 | + private byte[] commd; | ||
| 12 | + | ||
| 13 | + public Topic getTopic() { | ||
| 14 | + return topic; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + public void setTopic(Topic topic) { | ||
| 18 | + this.topic = topic; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public byte[] getCommd() { | ||
| 22 | + return commd; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public void setCommd(byte[] commd) { | ||
| 26 | + this.commd = commd; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public String getTopicconfig() { | ||
| 30 | + return topicconfig; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public void setTopicconfig(String topicconfig) { | ||
| 34 | + this.topicconfig = topicconfig; | ||
| 35 | + } | ||
| 36 | +} |
| @@ -36,10 +36,10 @@ public class ParserDeviceHostDto { | @@ -36,10 +36,10 @@ public class ParserDeviceHostDto { | ||
| 36 | * 设备摘要,格式{{"name":"device"},{"chip":"esp8266"}} | 36 | * 设备摘要,格式{{"name":"device"},{"chip":"esp8266"}} |
| 37 | */ | 37 | */ |
| 38 | private JsonObject summary; | 38 | private JsonObject summary; |
| 39 | - | 39 | + private Integer rssi; //信号 |
| 40 | private boolean is_config_up; | 40 | private boolean is_config_up; |
| 41 | private boolean is_data_up; | 41 | private boolean is_data_up; |
| 42 | private boolean is_summary_up; | 42 | private boolean is_summary_up; |
| 43 | - | 43 | + private String online; |
| 44 | private IotProduct iotProduct; | 44 | private IotProduct iotProduct; |
| 45 | } | 45 | } |
| 1 | package com.zhonglai.luhui.device.protocol.factory.dto; | 1 | package com.zhonglai.luhui.device.protocol.factory.dto; |
| 2 | 2 | ||
| 3 | import com.google.gson.JsonObject; | 3 | import com.google.gson.JsonObject; |
| 4 | +import com.zhonglai.luhui.device.analysis.comm.dto.ApiClientRePlyDto; | ||
| 4 | import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; | 5 | import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; |
| 5 | import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; | 6 | import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; |
| 6 | import lombok.Data; | 7 | import lombok.Data; |
| @@ -12,6 +13,14 @@ import java.util.List; | @@ -12,6 +13,14 @@ import java.util.List; | ||
| 12 | * 协议清洗模型 | 13 | * 协议清洗模型 |
| 13 | */ | 14 | */ |
| 14 | public class ProtocolPurificationModel { | 15 | public class ProtocolPurificationModel { |
| 16 | + /** | ||
| 17 | + * 通知消息 | ||
| 18 | + */ | ||
| 19 | + private ApiClientRePlyDto noticeMessage; | ||
| 20 | + /** | ||
| 21 | + * 是否需要通知 | ||
| 22 | + */ | ||
| 23 | + private boolean isNoticeClien; | ||
| 15 | private ParserDeviceHostDto parserDeviceHostDto = new ParserDeviceHostDto(); | 24 | private ParserDeviceHostDto parserDeviceHostDto = new ParserDeviceHostDto(); |
| 16 | private List<ParserDeviceInfoDto> parserDeviceInfoDtoList = new ArrayList<>(); | 25 | private List<ParserDeviceInfoDto> parserDeviceInfoDtoList = new ArrayList<>(); |
| 17 | private List<DeviceSensorData> deviceSensorDataList = new ArrayList<>(); | 26 | private List<DeviceSensorData> deviceSensorDataList = new ArrayList<>(); |
| @@ -48,4 +57,20 @@ public class ProtocolPurificationModel { | @@ -48,4 +57,20 @@ public class ProtocolPurificationModel { | ||
| 48 | public void setLogDeviceOperationList(List<LogDeviceOperation> logDeviceOperationList) { | 57 | public void setLogDeviceOperationList(List<LogDeviceOperation> logDeviceOperationList) { |
| 49 | this.logDeviceOperationList = logDeviceOperationList; | 58 | this.logDeviceOperationList = logDeviceOperationList; |
| 50 | } | 59 | } |
| 60 | + | ||
| 61 | + public ApiClientRePlyDto getNoticeMessage() { | ||
| 62 | + return noticeMessage; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public void setNoticeMessage(ApiClientRePlyDto noticeMessage) { | ||
| 66 | + this.noticeMessage = noticeMessage; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + public boolean isNoticeClien() { | ||
| 70 | + return isNoticeClien; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + public void setNoticeClien(boolean noticeClien) { | ||
| 74 | + isNoticeClien = noticeClien; | ||
| 75 | + } | ||
| 51 | } | 76 | } |
| @@ -11,10 +11,7 @@ import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemB | @@ -11,10 +11,7 @@ import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemB | ||
| 11 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 11 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 12 | import com.zhonglai.luhui.device.analysis.comm.util.DateUtils; | 12 | import com.zhonglai.luhui.device.analysis.comm.util.DateUtils; |
| 13 | import com.zhonglai.luhui.device.domain.IotThingsModel; | 13 | import com.zhonglai.luhui.device.domain.IotThingsModel; |
| 14 | -import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisDto; | ||
| 15 | -import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 16 | -import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | ||
| 17 | -import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | 14 | +import com.zhonglai.luhui.device.protocol.factory.dto.*; |
| 18 | import com.zhonglai.luhui.device.protocol.factory.service.IotThingsModelService; | 15 | import com.zhonglai.luhui.device.protocol.factory.service.IotThingsModelService; |
| 19 | import org.apache.commons.lang3.EnumUtils; | 16 | import org.apache.commons.lang3.EnumUtils; |
| 20 | 17 | ||
| @@ -27,7 +24,8 @@ import java.util.List; | @@ -27,7 +24,8 @@ import java.util.List; | ||
| 27 | public class DefaultProtocolPurificationFactoryImpl implements ProtocolPurificationFactory{ | 24 | public class DefaultProtocolPurificationFactoryImpl implements ProtocolPurificationFactory{ |
| 28 | 25 | ||
| 29 | @Override | 26 | @Override |
| 30 | - public ProtocolPurificationModel purification(Integer product_id,Topic topic, JsonObject protocolParserModel ) { | 27 | + public ProtocolPurificationModel purification(Integer product_id,Topic topic, AnalysisResult analysisResult ) { |
| 28 | + JsonObject protocolParserModel = analysisResult.getJsonObject(); | ||
| 31 | if(null != protocolParserModel && protocolParserModel.size()!=0) | 29 | if(null != protocolParserModel && protocolParserModel.size()!=0) |
| 32 | { | 30 | { |
| 33 | ProtocolPurificationModel protocolPurificationModel = new ProtocolPurificationModel(); | 31 | ProtocolPurificationModel protocolPurificationModel = new ProtocolPurificationModel(); |
| @@ -43,9 +41,10 @@ public class DefaultProtocolPurificationFactoryImpl implements ProtocolPurificat | @@ -43,9 +41,10 @@ public class DefaultProtocolPurificationFactoryImpl implements ProtocolPurificat | ||
| 43 | 41 | ||
| 44 | private ParserDeviceHostDto analysisHost(Integer product_id,Topic topic, JsonObject data,List<DeviceSensorData> deviceSensorDataList ) | 42 | private ParserDeviceHostDto analysisHost(Integer product_id,Topic topic, JsonObject data,List<DeviceSensorData> deviceSensorDataList ) |
| 45 | { | 43 | { |
| 44 | + int time = DateUtils.getNowTimeMilly(); | ||
| 46 | if(data.has("0")) | 45 | if(data.has("0")) |
| 47 | { | 46 | { |
| 48 | - JsonObject jsonObjectData = GsonConstructor.get().fromJson(GsonConstructor.get().toJson(data.get("0")),JsonObject.class); | 47 | + JsonObject jsonObjectData = data.get("0").getAsJsonObject(); |
| 49 | JsonObject summary = null; | 48 | JsonObject summary = null; |
| 50 | //解析设备摘要 | 49 | //解析设备摘要 |
| 51 | if(jsonObjectData.has("summary") && null != jsonObjectData.get("summary") && jsonObjectData.get("summary").isJsonObject()) | 50 | if(jsonObjectData.has("summary") && null != jsonObjectData.get("summary") && jsonObjectData.get("summary").isJsonObject()) |
| @@ -53,26 +52,46 @@ public class DefaultProtocolPurificationFactoryImpl implements ProtocolPurificat | @@ -53,26 +52,46 @@ public class DefaultProtocolPurificationFactoryImpl implements ProtocolPurificat | ||
| 53 | summary = jsonObjectData.get("summary").getAsJsonObject(); | 52 | summary = jsonObjectData.get("summary").getAsJsonObject(); |
| 54 | jsonObjectData.remove("summary"); | 53 | jsonObjectData.remove("summary"); |
| 55 | } | 54 | } |
| 56 | - int time = DateUtils.getNowTimeMilly(); | 55 | + |
| 56 | + String online = null; | ||
| 57 | + //解析在线状态 | ||
| 58 | + if(jsonObjectData.has("online") && null != jsonObjectData.get("online")) | ||
| 59 | + { | ||
| 60 | + online = jsonObjectData.get("online").getAsString(); | ||
| 61 | + jsonObjectData.remove("online"); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + //信号 | ||
| 65 | + Integer rssi = null; | ||
| 66 | + if(jsonObjectData.has("rssi") && null != jsonObjectData.get("rssi")) | ||
| 67 | + { | ||
| 68 | + rssi = jsonObjectData.get("rssi").getAsInt(); | ||
| 69 | + jsonObjectData.remove("rssi"); | ||
| 70 | + } | ||
| 71 | + | ||
| 57 | ParserDeviceHostDto parserDeviceHostDto = null; | 72 | ParserDeviceHostDto parserDeviceHostDto = null; |
| 58 | if(null != jsonObjectData && jsonObjectData.size() != 0) | 73 | if(null != jsonObjectData && jsonObjectData.size() != 0) |
| 59 | { | 74 | { |
| 60 | parserDeviceHostDto = analysisJsonData(time,"0",product_id,topic,jsonObjectData).pushDeviceSensorData(deviceSensorDataList).toParserDeviceHostDto(topic.getClientid(),time); | 75 | parserDeviceHostDto = analysisJsonData(time,"0",product_id,topic,jsonObjectData).pushDeviceSensorData(deviceSensorDataList).toParserDeviceHostDto(topic.getClientid(),time); |
| 61 | } | 76 | } |
| 62 | - | 77 | + if(null == parserDeviceHostDto) |
| 78 | + { | ||
| 79 | + parserDeviceHostDto = new ParserDeviceHostDto(); | ||
| 80 | + parserDeviceHostDto.setId(topic.getClientid()); | ||
| 81 | + } | ||
| 63 | if(null != summary && summary.size() != 0) | 82 | if(null != summary && summary.size() != 0) |
| 64 | { | 83 | { |
| 65 | - if(null == parserDeviceHostDto) | ||
| 66 | - { | ||
| 67 | - parserDeviceHostDto = new ParserDeviceHostDto(); | ||
| 68 | - parserDeviceHostDto.setId(topic.getClientid()); | ||
| 69 | - } | ||
| 70 | parserDeviceHostDto.setSummary(summary); | 84 | parserDeviceHostDto.setSummary(summary); |
| 71 | } | 85 | } |
| 86 | + parserDeviceHostDto.setOnline(online); | ||
| 87 | + parserDeviceHostDto.setRssi(rssi); | ||
| 72 | parserDeviceHostDto.setUpdateTime(time); | 88 | parserDeviceHostDto.setUpdateTime(time); |
| 73 | return parserDeviceHostDto; | 89 | return parserDeviceHostDto; |
| 74 | } | 90 | } |
| 75 | - return null; | 91 | + ParserDeviceHostDto parserDeviceHostDto = new ParserDeviceHostDto(); |
| 92 | + parserDeviceHostDto.setId(topic.getClientid()); | ||
| 93 | + parserDeviceHostDto.setUpdateTime(time); | ||
| 94 | + return parserDeviceHostDto; | ||
| 76 | } | 95 | } |
| 77 | 96 | ||
| 78 | private List<ParserDeviceInfoDto> analysisDeviceInfo(Integer time,Integer product_id,Topic topic, JsonObject data,List<DeviceSensorData> deviceSensorDataList) | 97 | private List<ParserDeviceInfoDto> analysisDeviceInfo(Integer time,Integer product_id,Topic topic, JsonObject data,List<DeviceSensorData> deviceSensorDataList) |
| @@ -2,11 +2,12 @@ package com.zhonglai.luhui.device.protocol.factory.purification; | @@ -2,11 +2,12 @@ package com.zhonglai.luhui.device.protocol.factory.purification; | ||
| 2 | 2 | ||
| 3 | import com.google.gson.JsonObject; | 3 | import com.google.gson.JsonObject; |
| 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 5 | import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | 6 | import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; |
| 6 | 7 | ||
| 7 | /** | 8 | /** |
| 8 | * 协议清洗工厂 | 9 | * 协议清洗工厂 |
| 9 | */ | 10 | */ |
| 10 | public interface ProtocolPurificationFactory { | 11 | public interface ProtocolPurificationFactory { |
| 11 | - ProtocolPurificationModel purification(Integer product_id,Topic topic, JsonObject analysisObject ); | 12 | + ProtocolPurificationModel purification(Integer product_id,Topic topic, AnalysisResult analysisResult ); |
| 12 | } | 13 | } |
| @@ -2,6 +2,7 @@ package com.zhonglai.luhui.device.protocol.factory.service; | @@ -2,6 +2,7 @@ package com.zhonglai.luhui.device.protocol.factory.service; | ||
| 2 | 2 | ||
| 3 | import com.zhonglai.luhui.device.protocol.factory.ProtocolParserAndPurificationFactory; | 3 | import com.zhonglai.luhui.device.protocol.factory.ProtocolParserAndPurificationFactory; |
| 4 | import com.zhonglai.luhui.device.protocol.factory.control.ControlFactory; | 4 | import com.zhonglai.luhui.device.protocol.factory.control.ControlFactory; |
| 5 | +import com.zhonglai.luhui.device.protocol.factory.control.DeviceCommandListenService; | ||
| 5 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | 6 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; |
| 6 | import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | 7 | import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; |
| 7 | import com.zhonglai.luhui.device.protocol.factory.sync.ProtocolSyncFactory; | 8 | import com.zhonglai.luhui.device.protocol.factory.sync.ProtocolSyncFactory; |
| @@ -38,6 +39,9 @@ public abstract class BaseCallback<T> { | @@ -38,6 +39,9 @@ public abstract class BaseCallback<T> { | ||
| 38 | protected PersistenceDBService persistenceDBService; | 39 | protected PersistenceDBService persistenceDBService; |
| 39 | 40 | ||
| 40 | 41 | ||
| 42 | + @Autowired | ||
| 43 | + protected DeviceCommandListenService deviceCommandListenService; | ||
| 44 | + | ||
| 41 | /** | 45 | /** |
| 42 | * 数据处理的工作流 | 46 | * 数据处理的工作流 |
| 43 | */ | 47 | */ |
| @@ -62,7 +66,11 @@ public abstract class BaseCallback<T> { | @@ -62,7 +66,11 @@ public abstract class BaseCallback<T> { | ||
| 62 | //同步 | 66 | //同步 |
| 63 | persistenceDBService.syncDB(protocolPurificationModel); | 67 | persistenceDBService.syncDB(protocolPurificationModel); |
| 64 | 68 | ||
| 65 | - //返回 | 69 | + //通知 |
| 70 | + if(protocolPurificationModel.isNoticeClien()) | ||
| 71 | + { | ||
| 72 | + deviceCommandListenService.replySendMessage(oldparserDeviceHostDto.getId(),protocolPurificationModel.getNoticeMessage()); | ||
| 73 | + } | ||
| 66 | 74 | ||
| 67 | } | 75 | } |
| 68 | 76 |
| 1 | package com.zhonglai.luhui.device.protocol.factory.service; | 1 | package com.zhonglai.luhui.device.protocol.factory.service; |
| 2 | 2 | ||
| 3 | import com.google.gson.JsonObject; | 3 | import com.google.gson.JsonObject; |
| 4 | +import com.ruoyi.common.utils.DateUtils; | ||
| 5 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 6 | +import com.ruoyi.common.utils.spring.SpringUtils; | ||
| 7 | +import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; | ||
| 8 | +import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; | ||
| 9 | +import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; | ||
| 10 | +import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.specs.StringModelOutput; | ||
| 11 | +import com.zhonglai.luhui.device.domain.IotThingsModel; | ||
| 4 | import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; | 12 | import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; |
| 5 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | 13 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; |
| 6 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | 14 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; |
| @@ -26,6 +34,15 @@ public class DeviceCashUpService { | @@ -26,6 +34,15 @@ public class DeviceCashUpService { | ||
| 26 | */ | 34 | */ |
| 27 | public int upProtocolPurificationModel(ProtocolPurificationModel protocolPurificationModel,ParserDeviceHostDto oldparserDeviceHostDto ) | 35 | public int upProtocolPurificationModel(ProtocolPurificationModel protocolPurificationModel,ParserDeviceHostDto oldparserDeviceHostDto ) |
| 28 | { | 36 | { |
| 37 | + if(null == protocolPurificationModel) | ||
| 38 | + { | ||
| 39 | + return 0; | ||
| 40 | + } | ||
| 41 | + if("0".equals(oldparserDeviceHostDto.getOnline())) //如果是离线消息 | ||
| 42 | + { | ||
| 43 | + DeviceCach.cleanDeviceHost(oldparserDeviceHostDto.getId()); | ||
| 44 | + return 0; | ||
| 45 | + } | ||
| 29 | //更新主机信息 | 46 | //更新主机信息 |
| 30 | int i = upParserDeviceHostDto(protocolPurificationModel,oldparserDeviceHostDto); | 47 | int i = upParserDeviceHostDto(protocolPurificationModel,oldparserDeviceHostDto); |
| 31 | 48 | ||
| @@ -42,8 +59,12 @@ public class DeviceCashUpService { | @@ -42,8 +59,12 @@ public class DeviceCashUpService { | ||
| 42 | */ | 59 | */ |
| 43 | private int upParserDeviceHostDto( ProtocolPurificationModel protocolPurificationModel , ParserDeviceHostDto oldparserDeviceHostDto) | 60 | private int upParserDeviceHostDto( ProtocolPurificationModel protocolPurificationModel , ParserDeviceHostDto oldparserDeviceHostDto) |
| 44 | { | 61 | { |
| 62 | + if(null == protocolPurificationModel) | ||
| 63 | + { | ||
| 64 | + return 0; | ||
| 65 | + } | ||
| 45 | ParserDeviceHostDto parserDeviceHostDto = protocolPurificationModel.getParserDeviceHostDto(); | 66 | ParserDeviceHostDto parserDeviceHostDto = protocolPurificationModel.getParserDeviceHostDto(); |
| 46 | - int i=0; | 67 | + int i=1; |
| 47 | JsonObject oldData = oldparserDeviceHostDto.getData(); | 68 | JsonObject oldData = oldparserDeviceHostDto.getData(); |
| 48 | JsonObject newData = parserDeviceHostDto.getData(); | 69 | JsonObject newData = parserDeviceHostDto.getData(); |
| 49 | if(null != newData) | 70 | if(null != newData) |
| @@ -54,7 +75,7 @@ public class DeviceCashUpService { | @@ -54,7 +75,7 @@ public class DeviceCashUpService { | ||
| 54 | i++; | 75 | i++; |
| 55 | oldparserDeviceHostDto.set_data_up(true); | 76 | oldparserDeviceHostDto.set_data_up(true); |
| 56 | }else { | 77 | }else { |
| 57 | - if(newToOldJsonObject(oldData,newData)) | 78 | + if(newToOldJsonObject(oldparserDeviceHostDto.getId(),protocolPurificationModel,oldData,newData)) |
| 58 | { | 79 | { |
| 59 | i++; | 80 | i++; |
| 60 | oldparserDeviceHostDto.set_data_up(true); | 81 | oldparserDeviceHostDto.set_data_up(true); |
| @@ -72,7 +93,7 @@ public class DeviceCashUpService { | @@ -72,7 +93,7 @@ public class DeviceCashUpService { | ||
| 72 | i++; | 93 | i++; |
| 73 | oldparserDeviceHostDto.set_config_up(true); | 94 | oldparserDeviceHostDto.set_config_up(true); |
| 74 | }else { | 95 | }else { |
| 75 | - if(newToOldJsonObject(oldConfig,newConfig)) | 96 | + if(newToOldJsonObject(oldparserDeviceHostDto.getId(),protocolPurificationModel,oldConfig,newConfig)) |
| 76 | { | 97 | { |
| 77 | i++; | 98 | i++; |
| 78 | oldparserDeviceHostDto.set_config_up(true); | 99 | oldparserDeviceHostDto.set_config_up(true); |
| @@ -90,18 +111,22 @@ public class DeviceCashUpService { | @@ -90,18 +111,22 @@ public class DeviceCashUpService { | ||
| 90 | i++; | 111 | i++; |
| 91 | oldparserDeviceHostDto.set_summary_up(true); | 112 | oldparserDeviceHostDto.set_summary_up(true); |
| 92 | }else { | 113 | }else { |
| 93 | - if(newToOldJsonObject(oldSummary,newSummary)) | 114 | + if(newToOldJsonObject(oldparserDeviceHostDto.getId(),protocolPurificationModel,oldSummary,newSummary)) |
| 94 | { | 115 | { |
| 95 | i++; | 116 | i++; |
| 96 | oldparserDeviceHostDto.set_summary_up(true); | 117 | oldparserDeviceHostDto.set_summary_up(true); |
| 97 | } | 118 | } |
| 98 | } | 119 | } |
| 99 | } | 120 | } |
| 100 | - | 121 | + oldparserDeviceHostDto.setUpdateTime(parserDeviceHostDto.getUpdateTime()); |
| 122 | + oldparserDeviceHostDto.setOnline(parserDeviceHostDto.getOnline()); | ||
| 123 | + oldparserDeviceHostDto.setRssi(parserDeviceHostDto.getRssi()); | ||
| 124 | + oldparserDeviceHostDto.setSummary(parserDeviceHostDto.getSummary()); | ||
| 101 | protocolPurificationModel.setParserDeviceHostDto(oldparserDeviceHostDto); | 125 | protocolPurificationModel.setParserDeviceHostDto(oldparserDeviceHostDto); |
| 102 | 126 | ||
| 103 | //更新主机缓存 | 127 | //更新主机缓存 |
| 104 | DeviceCach.putDeviceHost(oldparserDeviceHostDto,oldparserDeviceHostDto.getDevice_life()); | 128 | DeviceCach.putDeviceHost(oldparserDeviceHostDto,oldparserDeviceHostDto.getDevice_life()); |
| 129 | + | ||
| 105 | return i; | 130 | return i; |
| 106 | } | 131 | } |
| 107 | 132 | ||
| @@ -126,7 +151,7 @@ public class DeviceCashUpService { | @@ -126,7 +151,7 @@ public class DeviceCashUpService { | ||
| 126 | continue; | 151 | continue; |
| 127 | } | 152 | } |
| 128 | oldparserDeviceInfoDto.setUpdateTime(parserDeviceInfoDto.getUpdateTime()); | 153 | oldparserDeviceInfoDto.setUpdateTime(parserDeviceInfoDto.getUpdateTime()); |
| 129 | - i+=upParserDeviceInfoDto(parserDeviceInfoDto,oldparserDeviceInfoDto); | 154 | + i+=upParserDeviceInfoDto(protocolPurificationModel,parserDeviceInfoDto,oldparserDeviceInfoDto); |
| 130 | 155 | ||
| 131 | oldParserDeviceInfoDtoList.add(oldparserDeviceInfoDto); | 156 | oldParserDeviceInfoDtoList.add(oldparserDeviceInfoDto); |
| 132 | //更新缓存 | 157 | //更新缓存 |
| @@ -144,7 +169,7 @@ public class DeviceCashUpService { | @@ -144,7 +169,7 @@ public class DeviceCashUpService { | ||
| 144 | * @param parserDeviceInfoDto | 169 | * @param parserDeviceInfoDto |
| 145 | * @return | 170 | * @return |
| 146 | */ | 171 | */ |
| 147 | - private int upParserDeviceInfoDto( ParserDeviceInfoDto parserDeviceInfoDto , ParserDeviceInfoDto oldparserDeviceInfoDto) | 172 | + private int upParserDeviceInfoDto(ProtocolPurificationModel protocolPurificationModel, ParserDeviceInfoDto parserDeviceInfoDto , ParserDeviceInfoDto oldparserDeviceInfoDto) |
| 148 | { | 173 | { |
| 149 | int i=0; | 174 | int i=0; |
| 150 | JsonObject oldData = oldparserDeviceInfoDto.getData(); | 175 | JsonObject oldData = oldparserDeviceInfoDto.getData(); |
| @@ -157,7 +182,7 @@ public class DeviceCashUpService { | @@ -157,7 +182,7 @@ public class DeviceCashUpService { | ||
| 157 | i++; | 182 | i++; |
| 158 | oldparserDeviceInfoDto.set_data_up(true); | 183 | oldparserDeviceInfoDto.set_data_up(true); |
| 159 | }else { | 184 | }else { |
| 160 | - if(newToOldJsonObject(oldData,newData)) | 185 | + if(newToOldJsonObject(oldparserDeviceInfoDto.getId(),protocolPurificationModel,oldData,newData)) |
| 161 | { | 186 | { |
| 162 | i++; | 187 | i++; |
| 163 | oldparserDeviceInfoDto.set_data_up(true); | 188 | oldparserDeviceInfoDto.set_data_up(true); |
| @@ -175,7 +200,7 @@ public class DeviceCashUpService { | @@ -175,7 +200,7 @@ public class DeviceCashUpService { | ||
| 175 | i++; | 200 | i++; |
| 176 | oldparserDeviceInfoDto.set_conf_up(true); | 201 | oldparserDeviceInfoDto.set_conf_up(true); |
| 177 | }else { | 202 | }else { |
| 178 | - if(newToOldJsonObject(oldConfig,newConfig)) | 203 | + if(newToOldJsonObject(oldparserDeviceInfoDto.getId(),protocolPurificationModel,oldConfig,newConfig)) |
| 179 | { | 204 | { |
| 180 | i++; | 205 | i++; |
| 181 | oldparserDeviceInfoDto.set_conf_up(true); | 206 | oldparserDeviceInfoDto.set_conf_up(true); |
| @@ -202,7 +227,7 @@ public class DeviceCashUpService { | @@ -202,7 +227,7 @@ public class DeviceCashUpService { | ||
| 202 | } | 227 | } |
| 203 | 228 | ||
| 204 | 229 | ||
| 205 | - private boolean newToOldJsonObject(JsonObject oldJson,JsonObject newJson) | 230 | + private boolean newToOldJsonObject(String id, ProtocolPurificationModel protocolPurificationModel , JsonObject oldJson,JsonObject newJson) |
| 206 | { | 231 | { |
| 207 | boolean ischange = false; | 232 | boolean ischange = false; |
| 208 | for(String key:newJson.keySet()) | 233 | for(String key:newJson.keySet()) |
| @@ -212,6 +237,30 @@ public class DeviceCashUpService { | @@ -212,6 +237,30 @@ public class DeviceCashUpService { | ||
| 212 | oldJson.add(key,newJson.get(key)); | 237 | oldJson.add(key,newJson.get(key)); |
| 213 | ischange = true; | 238 | ischange = true; |
| 214 | } | 239 | } |
| 240 | + if (newJson.get(key).isJsonObject()) | ||
| 241 | + { | ||
| 242 | + ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModelItem(newJson.get(key).getAsJsonObject()); | ||
| 243 | + | ||
| 244 | + //记录操作 | ||
| 245 | + if(1==thingsModelItemBase.getIsMonitor()) | ||
| 246 | + { | ||
| 247 | + if(ischange || protocolPurificationModel.isNoticeClien()) | ||
| 248 | + { | ||
| 249 | + LogDeviceOperation logDeviceOperation = new LogDeviceOperation(); | ||
| 250 | + logDeviceOperation.setDeviceInfoId(id); | ||
| 251 | + logDeviceOperation.setDeviceOldState(oldJson.get(key).toString()); | ||
| 252 | + logDeviceOperation.setDeviceNewState(newJson.get(key).toString()); | ||
| 253 | + logDeviceOperation.setDeviceOperationTime(DateUtils.getNowTimeMilly()); | ||
| 254 | + logDeviceOperation.setDeviceOperationType(-1); | ||
| 255 | + logDeviceOperation.setIsStateChange(1); | ||
| 256 | + logDeviceOperation.setOperationDescribe(thingsModelItemBase.getName()+(protocolPurificationModel.isNoticeClien()?"远程":"本地")+"设置"+thingsModelItemBase.getView()); | ||
| 257 | + logDeviceOperation.setOperationInstruction((protocolPurificationModel.isNoticeClien()?GsonConstructor.get().toJson(protocolPurificationModel.getNoticeMessage()):null)); | ||
| 258 | + protocolPurificationModel.getLogDeviceOperationList().add(logDeviceOperation); | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + } | ||
| 262 | + } | ||
| 263 | + | ||
| 215 | } | 264 | } |
| 216 | return ischange; | 265 | return ischange; |
| 217 | } | 266 | } |
| @@ -2,11 +2,14 @@ package com.zhonglai.luhui.device.protocol.factory.service; | @@ -2,11 +2,14 @@ package com.zhonglai.luhui.device.protocol.factory.service; | ||
| 2 | 2 | ||
| 3 | import com.google.gson.JsonObject; | 3 | import com.google.gson.JsonObject; |
| 4 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; | 4 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; |
| 5 | +import com.zhonglai.luhui.device.domain.IotProductTranslate; | ||
| 5 | import com.zhonglai.luhui.device.domain.IotThingsModel; | 6 | import com.zhonglai.luhui.device.domain.IotThingsModel; |
| 6 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
| 7 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
| 8 | 9 | ||
| 10 | +import javax.annotation.PostConstruct; | ||
| 9 | import java.util.HashMap; | 11 | import java.util.HashMap; |
| 12 | +import java.util.List; | ||
| 10 | import java.util.Map; | 13 | import java.util.Map; |
| 11 | 14 | ||
| 12 | /** | 15 | /** |
| @@ -17,9 +20,29 @@ public class IotThingsModelService { | @@ -17,9 +20,29 @@ public class IotThingsModelService { | ||
| 17 | 20 | ||
| 18 | private static Map<Integer, Map<String, IotThingsModel>> iotThingsModelMap = new HashMap<>(); | 21 | private static Map<Integer, Map<String, IotThingsModel>> iotThingsModelMap = new HashMap<>(); |
| 19 | 22 | ||
| 23 | + private static Map<Integer, Map<String, String>> iotProductTranslateMap = new HashMap<>(); | ||
| 20 | @Autowired | 24 | @Autowired |
| 21 | private PersistenceDBService persistenceDBService; | 25 | private PersistenceDBService persistenceDBService; |
| 22 | 26 | ||
| 27 | + @PostConstruct | ||
| 28 | + public void load() | ||
| 29 | + { | ||
| 30 | + List<IotProductTranslate> list = persistenceDBService.getIotProductTranslateList(null); | ||
| 31 | + if(null == list || list.size() == 0) | ||
| 32 | + { | ||
| 33 | + for (IotProductTranslate iotProductTranslate:list) | ||
| 34 | + { | ||
| 35 | + Map<String, String> map = iotProductTranslateMap.get(iotProductTranslate.getProduct_id()); | ||
| 36 | + if(null == map) | ||
| 37 | + { | ||
| 38 | + map = new HashMap<>(); | ||
| 39 | + iotProductTranslateMap.put(iotProductTranslate.getProduct_id(),map); | ||
| 40 | + } | ||
| 41 | + map.put(iotProductTranslate.getModel_identifier(),iotProductTranslate.getTranslate_identifier()); | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + | ||
| 23 | 46 | ||
| 24 | public IotThingsModel getIotThingsModel(Integer product_id,String identifier) | 47 | public IotThingsModel getIotThingsModel(Integer product_id,String identifier) |
| 25 | { | 48 | { |
| @@ -56,4 +79,31 @@ public class IotThingsModelService { | @@ -56,4 +79,31 @@ public class IotThingsModelService { | ||
| 56 | } | 79 | } |
| 57 | return iotThingsModelMap.get(product_id); | 80 | return iotThingsModelMap.get(product_id); |
| 58 | } | 81 | } |
| 82 | + | ||
| 83 | + public Map<String, String> getIotProductTranslateMap(Integer product_id) | ||
| 84 | + { | ||
| 85 | + if(!iotProductTranslateMap.containsKey(product_id)) | ||
| 86 | + { | ||
| 87 | + return null; | ||
| 88 | + } | ||
| 89 | + return iotProductTranslateMap.get(product_id); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public void upIotThingsModel(Integer product_id) | ||
| 93 | + { | ||
| 94 | + Map<String,IotThingsModel> map = persistenceDBService.getIotThingsModelMap(product_id); | ||
| 95 | + if(null != map && map.size() > 0) | ||
| 96 | + { | ||
| 97 | + iotThingsModelMap.put(product_id,map); | ||
| 98 | + } | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public void upIotThingsModelTranslate(Integer product_id) | ||
| 102 | + { | ||
| 103 | + Map<String,String> map = persistenceDBService.getIotProductTranslateMap(product_id); | ||
| 104 | + if(null != map && map.size() > 0) | ||
| 105 | + { | ||
| 106 | + iotProductTranslateMap.put(product_id,map); | ||
| 107 | + } | ||
| 108 | + } | ||
| 59 | } | 109 | } |
| @@ -7,10 +7,7 @@ import com.ruoyi.common.utils.spring.SpringUtils; | @@ -7,10 +7,7 @@ import com.ruoyi.common.utils.spring.SpringUtils; | ||
| 7 | import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; | 7 | import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; |
| 8 | import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; | 8 | import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; |
| 9 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; | 9 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; |
| 10 | -import com.zhonglai.luhui.device.domain.IotDevice; | ||
| 11 | -import com.zhonglai.luhui.device.domain.IotProduct; | ||
| 12 | -import com.zhonglai.luhui.device.domain.IotProtocolClass; | ||
| 13 | -import com.zhonglai.luhui.device.domain.IotThingsModel; | 10 | +import com.zhonglai.luhui.device.domain.*; |
| 14 | import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; | 11 | import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; |
| 15 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | 12 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; |
| 16 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | 13 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; |
| @@ -32,6 +29,8 @@ public class PersistenceDBService { | @@ -32,6 +29,8 @@ public class PersistenceDBService { | ||
| 32 | private static Map<Integer, IotProtocolClass> iotProtocolClassMap = new HashMap<>(); | 29 | private static Map<Integer, IotProtocolClass> iotProtocolClassMap = new HashMap<>(); |
| 33 | @Autowired | 30 | @Autowired |
| 34 | private DefaultDbService defaultDbService; | 31 | private DefaultDbService defaultDbService; |
| 32 | + @Autowired | ||
| 33 | + private PersistenceDBService persistenceDBService; | ||
| 35 | 34 | ||
| 36 | /** | 35 | /** |
| 37 | * 更新数据库 | 36 | * 更新数据库 |
| @@ -62,16 +61,16 @@ public class PersistenceDBService { | @@ -62,16 +61,16 @@ public class PersistenceDBService { | ||
| 62 | public void syncDB(ProtocolPurificationModel protocolPurificationModel) throws ClassNotFoundException { | 61 | public void syncDB(ProtocolPurificationModel protocolPurificationModel) throws ClassNotFoundException { |
| 63 | //主机 | 62 | //主机 |
| 64 | ParserDeviceHostDto parserDeviceHostDto = protocolPurificationModel.getParserDeviceHostDto(); | 63 | ParserDeviceHostDto parserDeviceHostDto = protocolPurificationModel.getParserDeviceHostDto(); |
| 65 | - if (parserDeviceHostDto.getIotProduct().getIs_sync_db()==1 && StringUtils.isNotEmpty(parserDeviceHostDto.getIotProduct().getSync_db())) | 64 | + if (parserDeviceHostDto.getIotProduct().getIs_sync_db()==1 && null !=parserDeviceHostDto.getIotProduct().getSync_db() && 0!=parserDeviceHostDto.getIotProduct().getSync_db()) |
| 66 | { | 65 | { |
| 67 | - ProtocolSyncFactory protocolSyncFactory = getProtocolSyncService(parserDeviceHostDto.getIotProduct().getSync_db()); | 66 | + ProtocolSyncFactory protocolSyncFactory = getProtocolSyncService(persistenceDBService.getClassnameFromIotProtocolClassId(parserDeviceHostDto.getIotProduct().getSync_db())); |
| 68 | if(null != protocolSyncFactory) | 67 | if(null != protocolSyncFactory) |
| 69 | { | 68 | { |
| 70 | protocolSyncFactory.updateParserDeviceHostDto(parserDeviceHostDto); | 69 | protocolSyncFactory.updateParserDeviceHostDto(parserDeviceHostDto); |
| 71 | 70 | ||
| 72 | //终端 | 71 | //终端 |
| 73 | List<ParserDeviceInfoDto> parserDeviceInfoDtoList = protocolPurificationModel.getParserDeviceInfoDtoList(); | 72 | List<ParserDeviceInfoDto> parserDeviceInfoDtoList = protocolPurificationModel.getParserDeviceInfoDtoList(); |
| 74 | - protocolSyncFactory.updateParserDeviceInfoDtoList(parserDeviceInfoDtoList); | 73 | + protocolSyncFactory.updateParserDeviceInfoDtoList(protocolPurificationModel.getParserDeviceHostDto().getIotProduct().getId(),parserDeviceInfoDtoList); |
| 75 | 74 | ||
| 76 | //传感器指标 | 75 | //传感器指标 |
| 77 | List<DeviceSensorData> deviceSensorDataList = protocolPurificationModel.getDeviceSensorDataList(); | 76 | List<DeviceSensorData> deviceSensorDataList = protocolPurificationModel.getDeviceSensorDataList(); |
| @@ -144,6 +143,26 @@ public class PersistenceDBService { | @@ -144,6 +143,26 @@ public class PersistenceDBService { | ||
| 144 | return null; | 143 | return null; |
| 145 | } | 144 | } |
| 146 | 145 | ||
| 146 | + public Map<String,String> getIotProductTranslateMap(Integer product_id) | ||
| 147 | + { | ||
| 148 | + List<IotProductTranslate> list = defaultDbService.getIotProductTranslateList(product_id); | ||
| 149 | + if(null != list && list.size() != 0 ) | ||
| 150 | + { | ||
| 151 | + Map<String,String> map = new HashMap<>(); | ||
| 152 | + for (IotProductTranslate iotProductTranslate:list) | ||
| 153 | + { | ||
| 154 | + map.put(iotProductTranslate.getModel_identifier(),iotProductTranslate.getTranslate_identifier()); | ||
| 155 | + } | ||
| 156 | + return map; | ||
| 157 | + } | ||
| 158 | + return null; | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + public List<IotProductTranslate> getIotProductTranslateList(Integer product_id) | ||
| 162 | + { | ||
| 163 | + return defaultDbService.getIotProductTranslateList(product_id); | ||
| 164 | + } | ||
| 165 | + | ||
| 147 | /** | 166 | /** |
| 148 | * 获取默认数据库的操作服务 | 167 | * 获取默认数据库的操作服务 |
| 149 | * @return | 168 | * @return |
| @@ -63,6 +63,16 @@ public class DefaultDbService { | @@ -63,6 +63,16 @@ public class DefaultDbService { | ||
| 63 | return baseDao.find(iotThingsModel); | 63 | return baseDao.find(iotThingsModel); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | + public List<IotProductTranslate> getIotProductTranslateList(Integer product_id) | ||
| 67 | + { | ||
| 68 | + IotProductTranslate iotProductTranslate = new IotProductTranslate(); | ||
| 69 | + if(null != product_id) | ||
| 70 | + { | ||
| 71 | + iotProductTranslate.setProduct_id(product_id); | ||
| 72 | + } | ||
| 73 | + return baseDao.find(iotProductTranslate,"product_id,model_identifier,translate_identifier"); | ||
| 74 | + } | ||
| 75 | + | ||
| 66 | public void insertIotTerminal(IotTerminal iotTerminal) | 76 | public void insertIotTerminal(IotTerminal iotTerminal) |
| 67 | { | 77 | { |
| 68 | baseDao.insert(iotTerminal); | 78 | baseDao.insert(iotTerminal); |
| @@ -106,6 +116,7 @@ public class DefaultDbService { | @@ -106,6 +116,7 @@ public class DefaultDbService { | ||
| 106 | iotDevice.setClient_id(parserDeviceHostDto.getId()); | 116 | iotDevice.setClient_id(parserDeviceHostDto.getId()); |
| 107 | iotDevice.setData_update_time(parserDeviceHostDto.getUpdateTime()); | 117 | iotDevice.setData_update_time(parserDeviceHostDto.getUpdateTime()); |
| 108 | iotDevice.setListen_service_ip(SysParameter.service_ip); | 118 | iotDevice.setListen_service_ip(SysParameter.service_ip); |
| 119 | + iotDevice.setRssi(parserDeviceHostDto.getRssi()); | ||
| 109 | if(parserDeviceHostDto.is_summary_up()) | 120 | if(parserDeviceHostDto.is_summary_up()) |
| 110 | { | 121 | { |
| 111 | if(null != parserDeviceHostDto.getSummary() && parserDeviceHostDto.getSummary().size() != 0) | 122 | if(null != parserDeviceHostDto.getSummary() && parserDeviceHostDto.getSummary().size() != 0) |
| @@ -130,6 +141,19 @@ public class DefaultDbService { | @@ -130,6 +141,19 @@ public class DefaultDbService { | ||
| 130 | } | 141 | } |
| 131 | parserDeviceHostDto.set_config_up(false); | 142 | parserDeviceHostDto.set_config_up(false); |
| 132 | } | 143 | } |
| 144 | + if(StringUtils.isNotEmpty(parserDeviceHostDto.getOnline())) | ||
| 145 | + { | ||
| 146 | + String online = parserDeviceHostDto.getOnline(); | ||
| 147 | + switch (online) | ||
| 148 | + { | ||
| 149 | + case "1": | ||
| 150 | + iotDevice.setStatus(3); | ||
| 151 | + break; | ||
| 152 | + default: | ||
| 153 | + iotDevice.setStatus(4); | ||
| 154 | + break; | ||
| 155 | + } | ||
| 156 | + } | ||
| 133 | 157 | ||
| 134 | int i = baseDao.update(iotDevice); | 158 | int i = baseDao.update(iotDevice); |
| 135 | return i; | 159 | return i; |
| 1 | package com.zhonglai.luhui.device.protocol.factory.sync; | 1 | package com.zhonglai.luhui.device.protocol.factory.sync; |
| 2 | 2 | ||
| 3 | -import com.ruoyi.common.utils.StringUtils; | 3 | +import com.alibaba.fastjson.JSONObject; |
| 4 | +import com.google.gson.JsonObject; | ||
| 5 | +import com.ruoyi.common.utils.spring.SpringUtils; | ||
| 6 | +import com.zhonglai.luhui.device.analysis.comm.config.SysParameter; | ||
| 4 | import com.zhonglai.luhui.device.analysis.comm.dao.BaseDao; | 7 | import com.zhonglai.luhui.device.analysis.comm.dao.BaseDao; |
| 5 | import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; | 8 | import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; |
| 6 | import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; | 9 | import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; |
| 10 | +import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; | ||
| 11 | +import com.zhonglai.luhui.device.domain.IotThingsModel; | ||
| 12 | +import com.zhonglai.luhui.device.protocol.factory.dto.DeviceHost; | ||
| 13 | +import com.zhonglai.luhui.device.protocol.factory.dto.DeviceInfo; | ||
| 7 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | 14 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; |
| 8 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | 15 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; |
| 9 | -import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | ||
| 10 | -import org.springframework.stereotype.Component; | 16 | +import com.zhonglai.luhui.device.protocol.factory.service.IotThingsModelService; |
| 11 | import org.springframework.stereotype.Service; | 17 | import org.springframework.stereotype.Service; |
| 12 | 18 | ||
| 19 | +import java.util.HashMap; | ||
| 13 | import java.util.List; | 20 | import java.util.List; |
| 21 | +import java.util.Map; | ||
| 14 | 22 | ||
| 15 | @Service | 23 | @Service |
| 16 | public class DefaultProtocolSyncFactoryImpl implements ProtocolSyncFactory{ | 24 | public class DefaultProtocolSyncFactoryImpl implements ProtocolSyncFactory{ |
| 17 | - private BaseDao lsy_baseDao = new BaseDao(); | 25 | + private BaseDao ly_baseDao = new BaseDao(); |
| 18 | @Override | 26 | @Override |
| 19 | public void updateParserDeviceHostDto(ParserDeviceHostDto parserDeviceHostDto) { | 27 | public void updateParserDeviceHostDto(ParserDeviceHostDto parserDeviceHostDto) { |
| 28 | + DeviceHost deviceHost = new DeviceHost(); | ||
| 29 | + deviceHost.setId(parserDeviceHostDto.getId()); | ||
| 30 | + deviceHost.setDataUpdateTime(parserDeviceHostDto.getUpdateTime()); | ||
| 31 | + deviceHost.setDeviceServiceIp(SysParameter.service_ip); | ||
| 32 | + deviceHost.setOnline("01"); | ||
| 33 | + JSONObject data = new JSONObject(); | ||
| 20 | 34 | ||
| 35 | + Map<String, String> translateMap = SpringUtils.getBean(IotThingsModelService.class).getIotProductTranslateMap(parserDeviceHostDto.getIotProduct().getId()); | ||
| 36 | + | ||
| 37 | + if(parserDeviceHostDto.is_summary_up()) | ||
| 38 | + { | ||
| 39 | + if(null != parserDeviceHostDto.getSummary() && parserDeviceHostDto.getSummary().size() != 0) | ||
| 40 | + { | ||
| 41 | + for (String key:parserDeviceHostDto.getSummary().keySet()) | ||
| 42 | + { | ||
| 43 | + ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModelItem(parserDeviceHostDto.getSummary().get(key).getAsJsonObject()); | ||
| 44 | + data.put(key,translate(key,thingsModelItemBase.getSaveView(),translateMap)); | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + if(parserDeviceHostDto.is_data_up()) | ||
| 49 | + { | ||
| 50 | + if(null != parserDeviceHostDto.getData() && parserDeviceHostDto.getData().size() != 0) | ||
| 51 | + { | ||
| 52 | + for (String key:parserDeviceHostDto.getData().keySet()) | ||
| 53 | + { | ||
| 54 | + ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModelItem(parserDeviceHostDto.getData().get(key).getAsJsonObject()); | ||
| 55 | + data.put(key,translate(key,thingsModelItemBase.getSaveView(),translateMap)); | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + } | ||
| 60 | + if(parserDeviceHostDto.is_config_up()) | ||
| 61 | + { | ||
| 62 | + if(null != parserDeviceHostDto.getConfig() && parserDeviceHostDto.getConfig().size() != 0) | ||
| 63 | + { | ||
| 64 | + for (String key:parserDeviceHostDto.getConfig().keySet()) | ||
| 65 | + { | ||
| 66 | + ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModelItem(parserDeviceHostDto.getConfig().get(key).getAsJsonObject()); | ||
| 67 | + data.put(key,translate(key,thingsModelItemBase.getSaveView(),translateMap)); | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + } | ||
| 71 | + if(data.size()>0) | ||
| 72 | + { | ||
| 73 | + deviceHost.setData(data.toString()); | ||
| 74 | + } | ||
| 75 | + ly_baseDao.update(deviceHost); | ||
| 21 | } | 76 | } |
| 22 | 77 | ||
| 23 | @Override | 78 | @Override |
| 24 | - public void updateParserDeviceInfoDtoList(List<ParserDeviceInfoDto> parserDeviceInfoDtoList) { | 79 | + public void updateParserDeviceInfoDtoList(Integer productId, List<ParserDeviceInfoDto> parserDeviceInfoDtoList) { |
| 80 | + if(null != parserDeviceInfoDtoList && parserDeviceInfoDtoList.size() != 0) | ||
| 81 | + { | ||
| 82 | + Map<String, String> translateMap = SpringUtils.getBean(IotThingsModelService.class).getIotProductTranslateMap(productId); | ||
| 83 | + | ||
| 84 | + for (ParserDeviceInfoDto parserDeviceInfoDto:parserDeviceInfoDtoList) | ||
| 85 | + { | ||
| 86 | + DeviceInfo deviceInfo = new DeviceInfo(); | ||
| 87 | + deviceInfo.setId(parserDeviceInfoDto.getId()); | ||
| 88 | + deviceInfo.setDataUpdateTime(parserDeviceInfoDto.getUpdateTime()); | ||
| 89 | + deviceInfo.setOnline("01"); | ||
| 90 | + | ||
| 91 | + if(parserDeviceInfoDto.is_data_up()) | ||
| 92 | + { | ||
| 93 | + JSONObject data = new JSONObject(); | ||
| 94 | + for (String key:parserDeviceInfoDto.getData().keySet()) | ||
| 95 | + { | ||
| 96 | + ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModelItem(parserDeviceInfoDto.getConfig().get(key).getAsJsonObject()); | ||
| 97 | + data.put(key,translate(key,thingsModelItemBase.getSaveView(),translateMap)); | ||
| 98 | + } | ||
| 99 | + deviceInfo.setDataState(data.toString()); | ||
| 100 | + } | ||
| 101 | + if(parserDeviceInfoDto.is_conf_up()) | ||
| 102 | + { | ||
| 103 | + JSONObject data = new JSONObject(); | ||
| 104 | + for (String key:parserDeviceInfoDto.getConfig().keySet()) | ||
| 105 | + { | ||
| 106 | + ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModelItem(parserDeviceInfoDto.getConfig().get(key).getAsJsonObject()); | ||
| 107 | + data.put(key,translate(key,thingsModelItemBase.getSaveView(),translateMap)); | ||
| 108 | + } | ||
| 109 | + deviceInfo.setDeviceConfig(data.toString()); | ||
| 110 | + } | ||
| 111 | + ly_baseDao.update(deviceInfo); | ||
| 25 | 112 | ||
| 113 | + } | ||
| 114 | + } | ||
| 26 | } | 115 | } |
| 27 | 116 | ||
| 28 | @Override | 117 | @Override |
| @@ -34,4 +123,81 @@ public class DefaultProtocolSyncFactoryImpl implements ProtocolSyncFactory{ | @@ -34,4 +123,81 @@ public class DefaultProtocolSyncFactoryImpl implements ProtocolSyncFactory{ | ||
| 34 | public void updateLogDeviceOperationList(List<LogDeviceOperation> logDeviceOperationList) { | 123 | public void updateLogDeviceOperationList(List<LogDeviceOperation> logDeviceOperationList) { |
| 35 | 124 | ||
| 36 | } | 125 | } |
| 126 | + | ||
| 127 | + private Object translate(String key,Object value ,Map<String, String> translateMap) | ||
| 128 | + { | ||
| 129 | + if (null == translateMap) | ||
| 130 | + { | ||
| 131 | + return value; | ||
| 132 | + } | ||
| 133 | + JSONObject temp = new JSONObject(); | ||
| 134 | + String translateKey = key; | ||
| 135 | + if(translateMap.containsKey(key) ) | ||
| 136 | + { | ||
| 137 | + translateKey = translateMap.get(key); | ||
| 138 | + } | ||
| 139 | + if(translateKey.equals("3l")) | ||
| 140 | + { | ||
| 141 | + byte[] old3l = new byte[]{(value+"").getBytes()[0],49}; | ||
| 142 | + if(null != temp && temp.containsKey("3") && null !=temp.get("3")) | ||
| 143 | + { | ||
| 144 | + byte[] bs = temp.getString("3").getBytes(); | ||
| 145 | + if(bs.length==2) | ||
| 146 | + { | ||
| 147 | + old3l[1] = bs[1]; | ||
| 148 | + } | ||
| 149 | + } | ||
| 150 | + translateKey = "3"; | ||
| 151 | + value = new String(old3l); | ||
| 152 | + }else if(translateKey.equals("3r")) | ||
| 153 | + { | ||
| 154 | + byte[] old3r = new byte[]{49,(value+"").getBytes()[0]}; | ||
| 155 | + if(null != temp && temp.containsKey("3") && null !=temp.get("3")) | ||
| 156 | + { | ||
| 157 | + byte[] bs = temp.getString("3").getBytes(); | ||
| 158 | + if(bs.length==2) | ||
| 159 | + { | ||
| 160 | + old3r[0] = bs[0]; | ||
| 161 | + } | ||
| 162 | + } | ||
| 163 | + translateKey = "3"; | ||
| 164 | + value = new String(old3r); | ||
| 165 | + }else{ | ||
| 166 | + String[] ss = translateKey.split(":"); | ||
| 167 | + switch (ss.length) | ||
| 168 | + { | ||
| 169 | + case 1: | ||
| 170 | + break; | ||
| 171 | + case 2: | ||
| 172 | + translateKey = ss[0]; | ||
| 173 | + JSONObject jsonObject = new JSONObject(); | ||
| 174 | + if(null != temp && temp.containsKey(translateKey) && null !=temp.get(translateKey)) | ||
| 175 | + { | ||
| 176 | + jsonObject = temp.getJSONObject(translateKey); | ||
| 177 | + } | ||
| 178 | + jsonObject.put(ss[1],value); | ||
| 179 | + value = jsonObject; | ||
| 180 | + break; | ||
| 181 | + case 3: | ||
| 182 | + translateKey = ss[0]; | ||
| 183 | + JSONObject jsonObject1 = new JSONObject(); | ||
| 184 | + if(null != temp && temp.containsKey(translateKey) && null !=temp.get(translateKey)) | ||
| 185 | + { | ||
| 186 | + jsonObject1 = temp.getJSONObject(translateKey); | ||
| 187 | + } | ||
| 188 | + String translateKey2 = ss[1]; | ||
| 189 | + JSONObject jsonObject2 = new JSONObject(); | ||
| 190 | + if(null != jsonObject1 && jsonObject1.containsKey(translateKey2) && null !=jsonObject1.get(translateKey2)) | ||
| 191 | + { | ||
| 192 | + jsonObject2 = jsonObject1.getJSONObject(translateKey2); | ||
| 193 | + } | ||
| 194 | + jsonObject2.put(ss[2],value); | ||
| 195 | + jsonObject1.put(ss[1],jsonObject2); | ||
| 196 | + value = jsonObject1; | ||
| 197 | + break; | ||
| 198 | + } | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + return value; | ||
| 202 | + } | ||
| 37 | } | 203 | } |
| @@ -12,7 +12,7 @@ public interface ProtocolSyncFactory { | @@ -12,7 +12,7 @@ public interface ProtocolSyncFactory { | ||
| 12 | void updateParserDeviceHostDto(ParserDeviceHostDto parserDeviceHostDto); | 12 | void updateParserDeviceHostDto(ParserDeviceHostDto parserDeviceHostDto); |
| 13 | 13 | ||
| 14 | //终端 | 14 | //终端 |
| 15 | - void updateParserDeviceInfoDtoList( List<ParserDeviceInfoDto> parserDeviceInfoDtoList); | 15 | + void updateParserDeviceInfoDtoList(Integer productId, List<ParserDeviceInfoDto> parserDeviceInfoDtoList); |
| 16 | 16 | ||
| 17 | //传感器指标 | 17 | //传感器指标 |
| 18 | void updateDeviceSensorDataList(List<DeviceSensorData> deviceSensorDataList); | 18 | void updateDeviceSensorDataList(List<DeviceSensorData> deviceSensorDataList); |
| @@ -5,9 +5,14 @@ import com.ruoyi.common.utils.ByteUtil; | @@ -5,9 +5,14 @@ import com.ruoyi.common.utils.ByteUtil; | ||
| 5 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 5 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 6 | import com.zhonglai.luhui.device.analysis.util.TopicUtil; | 6 | import com.zhonglai.luhui.device.analysis.util.TopicUtil; |
| 7 | import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory; | 7 | import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory; |
| 8 | +import com.zhonglai.luhui.device.protocol.factory.analysis.topic.Online; | ||
| 9 | +import com.zhonglai.luhui.device.protocol.factory.control.DeviceCommandListenService; | ||
| 10 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 11 | +import com.zhonglai.luhui.device.protocol.uyu.analysis.topic.CkaDtSndR; | ||
| 12 | +import com.zhonglai.luhui.device.protocol.uyu.analysis.topic.CkaDtSndS; | ||
| 8 | 13 | ||
| 9 | public class UyuProtocolParserFactoryImpl implements ProtocolParserFactory<byte[]> { | 14 | public class UyuProtocolParserFactoryImpl implements ProtocolParserFactory<byte[]> { |
| 10 | - private static final String topicModel = "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{imei}}/{{topicType}}"; | 15 | + private static final String topicModel = "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{topicType}}/{{sorclientid}}"; |
| 11 | @Override | 16 | @Override |
| 12 | public Topic analysisTopic(String topicStr) { | 17 | public Topic analysisTopic(String topicStr) { |
| 13 | Topic topic = TopicUtil.initTopicFromModelStr(topicStr,topicModel); | 18 | Topic topic = TopicUtil.initTopicFromModelStr(topicStr,topicModel); |
| @@ -15,40 +20,17 @@ public class UyuProtocolParserFactoryImpl implements ProtocolParserFactory<byte[ | @@ -15,40 +20,17 @@ public class UyuProtocolParserFactoryImpl implements ProtocolParserFactory<byte[ | ||
| 15 | } | 20 | } |
| 16 | 21 | ||
| 17 | @Override | 22 | @Override |
| 18 | - public JsonObject analysisPayload(Topic topic, byte[] payload) { | ||
| 19 | - JsonObject jsonObject = new JsonObject(); | ||
| 20 | - int addres = 1; //应该用第3字节:地址(目前定为0x80),但是下位机没有用到 我们现在也不用就写死 | ||
| 21 | - JsonObject senserData = new JsonObject(); | ||
| 22 | - jsonObject.add(addres+"",senserData); | 23 | + public AnalysisResult analysisPayload(Topic topic, byte[] payload) { |
| 23 | 24 | ||
| 24 | - byte b5 = payload[4]; | ||
| 25 | - int dangwei = ByteUtil.getBitsValue(b5,0,3); | ||
| 26 | - int kaiguan = ByteUtil.getBitValue(b5,7); | ||
| 27 | - | ||
| 28 | - int zhuanshu = new Long(ByteUtil.bytesToLongDESC(payload,5,2)).intValue(); | ||
| 29 | - int dianliu = new Long(ByteUtil.bytesToLongDESC(payload,7,2)).intValue(); | ||
| 30 | - int dianya = new Long(ByteUtil.bytesToLongDESC(payload,9,2)).intValue(); | ||
| 31 | - int gonglv = new Long(ByteUtil.bytesToLongDESC(payload,11,2)).intValue(); | ||
| 32 | - | ||
| 33 | - //第14字节:故障码 (转成2进制对应下表) | ||
| 34 | - byte b14 = payload[13]; | ||
| 35 | - int qianyabaoh = ByteUtil.getBitValue(b14,0); | ||
| 36 | - int duanlubaohu = ByteUtil.getBitValue(b14,1); | ||
| 37 | - int qidongyichangbaohu = ByteUtil.getBitValue(b14,2); | ||
| 38 | - int guowenbaohu = ByteUtil.getBitValue(b14,2); | ||
| 39 | - int qiexiangbaohu = ByteUtil.getBitValue(b14,2); | ||
| 40 | - | ||
| 41 | - jsonObject.addProperty("106",dangwei); | ||
| 42 | - jsonObject.addProperty("3",kaiguan); | ||
| 43 | - jsonObject.addProperty("67",zhuanshu); | ||
| 44 | - jsonObject.addProperty("61",dianliu); | ||
| 45 | - jsonObject.addProperty("57",dianya); | ||
| 46 | - jsonObject.addProperty("59",gonglv); | ||
| 47 | - jsonObject.addProperty("107",qianyabaoh); | ||
| 48 | - jsonObject.addProperty("108",duanlubaohu); | ||
| 49 | - jsonObject.addProperty("109",qidongyichangbaohu); | ||
| 50 | - jsonObject.addProperty("110",guowenbaohu); | ||
| 51 | - jsonObject.addProperty("111",qiexiangbaohu); | ||
| 52 | - return jsonObject; | 25 | + switch (topic.getTopicType()) |
| 26 | + { | ||
| 27 | +// case "CKA-DT-SND_R": | ||
| 28 | +// return new CkaDtSndR().analysisPayload(payload); | ||
| 29 | + case "CKA-DT-SND_S": | ||
| 30 | + return new CkaDtSndS().analysisPayload( topic.getClientid(),payload); | ||
| 31 | + case "online": | ||
| 32 | + return new Online().analysisPayload(payload); | ||
| 33 | + } | ||
| 34 | + return null; | ||
| 53 | } | 35 | } |
| 54 | } | 36 | } |
| 1 | +package com.zhonglai.luhui.device.protocol.uyu.analysis.topic; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.ByteUtil; | ||
| 5 | +import com.zhonglai.luhui.device.analysis.comm.dto.ApiClientRePlyDto; | ||
| 6 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 7 | +import com.zhonglai.luhui.device.analysis.dto.Message; | ||
| 8 | +import com.zhonglai.luhui.device.analysis.dto.MessageCode; | ||
| 9 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 10 | + | ||
| 11 | +import java.util.HashMap; | ||
| 12 | +import java.util.Map; | ||
| 13 | + | ||
| 14 | +public class CkaDtSndR { | ||
| 15 | + public AnalysisResult analysisPayload(byte[] payload) | ||
| 16 | + { | ||
| 17 | + JsonObject jsonObject = new JsonObject(); | ||
| 18 | + int addres = 1; //应该用第3字节:地址(目前定为0x80),但是下位机没有用到 我们现在也不用就写死 | ||
| 19 | + JsonObject senserData = new JsonObject(); | ||
| 20 | + jsonObject.add(addres+"",senserData); | ||
| 21 | + int kaiguan = payload[4]; | ||
| 22 | + int dangwei = payload[5]+1; | ||
| 23 | + | ||
| 24 | + senserData.addProperty("106",dangwei); | ||
| 25 | + senserData.addProperty("3",kaiguan); | ||
| 26 | + | ||
| 27 | + Map<String,Object> map = new HashMap<>(); | ||
| 28 | + map.put("106",dangwei); | ||
| 29 | + map.put("3",kaiguan); | ||
| 30 | + | ||
| 31 | + Map<String,Object> wmap = new HashMap<>(); | ||
| 32 | + wmap.put("1",map); | ||
| 33 | + return new AnalysisResult(false, true, jsonObject, new ApiClientRePlyDto() { | ||
| 34 | + @Override | ||
| 35 | + public void setReplyMessage(Message message) { | ||
| 36 | + message.setCode(MessageCode.DEFAULT_SUCCESS_CODE); | ||
| 37 | + message.setData(wmap); | ||
| 38 | + } | ||
| 39 | + }); | ||
| 40 | + } | ||
| 41 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.uyu.analysis.topic; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.constant.GenConstants; | ||
| 5 | +import com.ruoyi.common.utils.ByteUtil; | ||
| 6 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 7 | +import com.zhonglai.luhui.device.analysis.comm.dto.ApiClientRePlyDto; | ||
| 8 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 9 | +import com.zhonglai.luhui.device.analysis.dto.Message; | ||
| 10 | +import com.zhonglai.luhui.device.analysis.dto.MessageCode; | ||
| 11 | +import com.zhonglai.luhui.device.protocol.factory.control.DeviceCommandListenService; | ||
| 12 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 13 | + | ||
| 14 | +import java.util.Arrays; | ||
| 15 | +import java.util.HashMap; | ||
| 16 | + | ||
| 17 | +public class CkaDtSndS { | ||
| 18 | + public AnalysisResult analysisPayload(String clientid, byte[] payload) | ||
| 19 | + { | ||
| 20 | + switch (payload[0]) | ||
| 21 | + { | ||
| 22 | + case (byte) 0xA5: | ||
| 23 | + return subData(clientid,payload); | ||
| 24 | + case (byte) 0xA6: | ||
| 25 | + return subSim(payload); | ||
| 26 | + case (byte) 0xA7: | ||
| 27 | + return subRssi(payload); | ||
| 28 | + default: | ||
| 29 | + return subData(clientid,payload); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + private AnalysisResult subRssi(byte[] payload) | ||
| 36 | + { | ||
| 37 | + JsonObject data = new JsonObject(); | ||
| 38 | + data.addProperty("rssi",payload[1]); | ||
| 39 | + JsonObject jsonObject = new JsonObject(); | ||
| 40 | + jsonObject.add("0",data); | ||
| 41 | + return new AnalysisResult(false,false,jsonObject); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + private AnalysisResult subSim(byte[] payload) | ||
| 45 | + { | ||
| 46 | + byte[] subPayload = Arrays.copyOfRange(payload, 1, payload.length-1); | ||
| 47 | + JsonObject data = new JsonObject(); | ||
| 48 | + data.addProperty("sim",new String(subPayload)); | ||
| 49 | + JsonObject summary = new JsonObject(); | ||
| 50 | + summary.add("summary",data); | ||
| 51 | + JsonObject jsonObject = new JsonObject(); | ||
| 52 | + jsonObject.add("0",summary); | ||
| 53 | + return new AnalysisResult(false,false,jsonObject); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + private AnalysisResult subData(String clientid, byte[] payload) | ||
| 57 | + { | ||
| 58 | + JsonObject jsonObject = new JsonObject(); | ||
| 59 | + int addres = 1; //应该用第3字节:地址(目前定为0x80),但是下位机没有用到 我们现在也不用就写死 | ||
| 60 | + JsonObject senserData = new JsonObject(); | ||
| 61 | + jsonObject.add(addres+"",senserData); | ||
| 62 | + byte b5 = payload[4]; | ||
| 63 | + int dangwei = ByteUtil.getBitsValue(b5,0,3); | ||
| 64 | + int kaiguan = ByteUtil.getBitValue(b5,7); | ||
| 65 | + | ||
| 66 | + int zhuanshu = new Long(ByteUtil.bytesToLongDESC(payload,5,2)).intValue(); | ||
| 67 | + int dianliu = new Long(ByteUtil.bytesToLongDESC(payload,7,2)).intValue(); | ||
| 68 | + int dianya = new Long(ByteUtil.bytesToLongDESC(payload,9,2)).intValue(); | ||
| 69 | + int gonglv = new Long(ByteUtil.bytesToLongDESC(payload,11,2)).intValue(); | ||
| 70 | + | ||
| 71 | + //第14字节:故障码 (转成2进制对应下表) | ||
| 72 | + byte b14 = payload[13]; | ||
| 73 | + int qianyabaoh = ByteUtil.getBitValue(b14,0); | ||
| 74 | + int duanlubaohu = ByteUtil.getBitValue(b14,1); | ||
| 75 | + int qidongyichangbaohu = ByteUtil.getBitValue(b14,2); | ||
| 76 | + int guowenbaohu = ByteUtil.getBitValue(b14,2); | ||
| 77 | + int qiexiangbaohu = ByteUtil.getBitValue(b14,2); | ||
| 78 | + | ||
| 79 | + senserData.addProperty("106",dangwei); | ||
| 80 | + senserData.addProperty("3",kaiguan); | ||
| 81 | + senserData.addProperty("67",zhuanshu); | ||
| 82 | + senserData.addProperty("61",dianliu); | ||
| 83 | + senserData.addProperty("57",dianya); | ||
| 84 | + senserData.addProperty("59",gonglv); | ||
| 85 | + senserData.addProperty("107",qianyabaoh); | ||
| 86 | + senserData.addProperty("108",duanlubaohu); | ||
| 87 | + senserData.addProperty("109",qidongyichangbaohu); | ||
| 88 | + senserData.addProperty("110",guowenbaohu); | ||
| 89 | + senserData.addProperty("111",qiexiangbaohu); | ||
| 90 | + if(DeviceCommandListenService.hasClienConnection(clientid)) | ||
| 91 | + { | ||
| 92 | + return new AnalysisResult(true,true,jsonObject,new ApiClientRePlyDto() { | ||
| 93 | + @Override | ||
| 94 | + public void setReplyMessage(Message message) { | ||
| 95 | + message.setCode(MessageCode.DEFAULT_SUCCESS_CODE); | ||
| 96 | + message.setData(GsonConstructor.get().fromJson(jsonObject.toString(), HashMap.class)); | ||
| 97 | + } | ||
| 98 | + }); | ||
| 99 | + } | ||
| 100 | + return new AnalysisResult(true,false,jsonObject); | ||
| 101 | + } | ||
| 102 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.uyu.control; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 5 | +import com.zhonglai.luhui.device.analysis.comm.util.ByteUtil; | ||
| 6 | +import com.zhonglai.luhui.device.analysis.comm.util.DateUtils; | ||
| 7 | +import com.zhonglai.luhui.device.domain.IotProduct; | ||
| 8 | +import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; | ||
| 9 | +import com.zhonglai.luhui.device.protocol.factory.control.DeviceCommandServiceFactory; | ||
| 10 | +import com.zhonglai.luhui.device.protocol.factory.dto.NoticeMessageDto; | ||
| 11 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 12 | +import org.slf4j.Logger; | ||
| 13 | +import org.slf4j.LoggerFactory; | ||
| 14 | + | ||
| 15 | +import java.util.Arrays; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * 指令控制监听实现 | ||
| 19 | + */ | ||
| 20 | +public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFactory { | ||
| 21 | + private static final String topicconfig = "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{topicType}}"; | ||
| 22 | + private static final Logger log = LoggerFactory.getLogger(DeviceCommandListenServiceImpl.class); | ||
| 23 | + @Override | ||
| 24 | + public NoticeMessageDto read(String deviceId, JsonObject jsonObject) { | ||
| 25 | + return null; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + @Override | ||
| 29 | + public NoticeMessageDto write(String deviceId, JsonObject jsonObject) { | ||
| 30 | + ParserDeviceHostDto parserDeviceHostDto = DeviceCach.getDeviceHost(deviceId); | ||
| 31 | + | ||
| 32 | + Topic topic = getWriteTopic(deviceId,parserDeviceHostDto.getIotProduct()); | ||
| 33 | + NoticeMessageDto noticeMessageDto = new NoticeMessageDto(); | ||
| 34 | + noticeMessageDto.setTopic(topic); | ||
| 35 | + noticeMessageDto.setTopicconfig(topicconfig); | ||
| 36 | + if (jsonObject.has("1")) | ||
| 37 | + { | ||
| 38 | + JsonObject data = jsonObject.get("1").getAsJsonObject(); | ||
| 39 | + if (data.has("3") && data.has("106")) | ||
| 40 | + { | ||
| 41 | + byte[] bytes = new byte[]{(byte) 0xA5, 0x07, 0x01, 0x20, (byte) data.get("3").getAsInt(), (byte) (data.get("106").getAsInt() - 1)}; | ||
| 42 | + bytes = Arrays.copyOf(bytes, bytes.length + 1); | ||
| 43 | + bytes[bytes.length - 1] = ByteUtil.calculateChecksum(bytes); | ||
| 44 | + noticeMessageDto.setCommd(bytes); | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + return noticeMessageDto; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + @Override | ||
| 51 | + public boolean notice(String deviceId, JsonObject jsonObject) { | ||
| 52 | + return false; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + private Topic getWriteTopic(String deviceId, IotProduct iotProduct) | ||
| 57 | + { | ||
| 58 | + Topic topic = new Topic(); | ||
| 59 | + if (deviceId.indexOf("_")>0) | ||
| 60 | + { | ||
| 61 | + topic.setTopicType("CKA-DT-SND_R/"+deviceId.split("_")[1]); | ||
| 62 | + }else{ | ||
| 63 | + topic.setTopicType("CKA-DT-SND_R/"+deviceId); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + topic.setClientid(deviceId); | ||
| 67 | + topic.setRoleid(iotProduct.getRole_id()+""); | ||
| 68 | + topic.setUsername(iotProduct.getMqtt_username()); | ||
| 69 | + topic.setPayloadtype("Bite16"); | ||
| 70 | + topic.setMessageid(DateUtils.getNowTimeMilly()+""); | ||
| 71 | + return topic; | ||
| 72 | + } | ||
| 73 | +} |
| 1 | -package com.zhonglai.luhui.device.protocol.uyu.control; | ||
| 2 | - | ||
| 3 | -import com.zhonglai.luhui.device.protocol.factory.control.ControlFactory; | ||
| 4 | -import org.apache.rocketmq.spring.annotation.MessageModel; | ||
| 5 | -import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; | ||
| 6 | -import org.apache.rocketmq.spring.annotation.SelectorType; | ||
| 7 | -import org.springframework.stereotype.Component; | ||
| 8 | - | ||
| 9 | -@Component | ||
| 10 | -@RocketMQMessageListener(consumerGroup = "lh-device-uyu", topic = "control-device-uyu",selectorType = SelectorType.TAG,selectorExpression = "1",messageModel = MessageModel.BROADCASTING) | ||
| 11 | -public class UyuControlFactoryImpl extends ControlFactory { | ||
| 12 | - | ||
| 13 | - @Override | ||
| 14 | - protected String analysisMessageKey() { | ||
| 15 | - return null; | ||
| 16 | - } | ||
| 17 | - | ||
| 18 | - @Override | ||
| 19 | - protected Boolean transmitMessage(String str) { | ||
| 20 | - return null; | ||
| 21 | - } | ||
| 22 | - | ||
| 23 | - @Override | ||
| 24 | - protected long getOperationTime() { | ||
| 25 | - return 10000; | ||
| 26 | - } | ||
| 27 | -} |
| @@ -8,6 +8,7 @@ import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | @@ -8,6 +8,7 @@ import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 8 | import com.zhonglai.luhui.device.analysis.comm.util.ByteUtil; | 8 | import com.zhonglai.luhui.device.analysis.comm.util.ByteUtil; |
| 9 | import com.zhonglai.luhui.device.analysis.util.TopicUtil; | 9 | import com.zhonglai.luhui.device.analysis.util.TopicUtil; |
| 10 | import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory; | 10 | import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory; |
| 11 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 11 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | 12 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; |
| 12 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | 13 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; |
| 13 | import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | 14 | import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; |
| @@ -34,7 +35,7 @@ public class ProtocolParserServiceImpl implements ProtocolParserFactory<byte[]> | @@ -34,7 +35,7 @@ public class ProtocolParserServiceImpl implements ProtocolParserFactory<byte[]> | ||
| 34 | } | 35 | } |
| 35 | 36 | ||
| 36 | @Override | 37 | @Override |
| 37 | - public JsonObject analysisPayload(Topic topic, byte[] payload) { | 38 | + public AnalysisResult analysisPayload(Topic topic, byte[] payload) { |
| 38 | switch (topic.getTopicType()) | 39 | switch (topic.getTopicType()) |
| 39 | { | 40 | { |
| 40 | case "pub_data": | 41 | case "pub_data": |
| @@ -2,7 +2,8 @@ package com.zhonglai.luhui.device.protocol.xinjie.analysis; | @@ -2,7 +2,8 @@ package com.zhonglai.luhui.device.protocol.xinjie.analysis; | ||
| 2 | 2 | ||
| 3 | import com.google.gson.JsonObject; | 3 | import com.google.gson.JsonObject; |
| 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 5 | 6 | ||
| 6 | public interface ProtocolTopicParser<T> { | 7 | public interface ProtocolTopicParser<T> { |
| 7 | - JsonObject analysisPayload(Topic topic, T payload); | 8 | + AnalysisResult analysisPayload(Topic topic, T payload); |
| 8 | } | 9 | } |
| @@ -4,6 +4,7 @@ import com.google.gson.JsonObject; | @@ -4,6 +4,7 @@ import com.google.gson.JsonObject; | ||
| 4 | import com.ruoyi.common.utils.GsonConstructor; | 4 | import com.ruoyi.common.utils.GsonConstructor; |
| 5 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 5 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 6 | import com.zhonglai.luhui.device.analysis.comm.util.ByteUtil; | 6 | import com.zhonglai.luhui.device.analysis.comm.util.ByteUtil; |
| 7 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 7 | import com.zhonglai.luhui.device.protocol.xinjie.analysis.ProtocolTopicParser; | 8 | import com.zhonglai.luhui.device.protocol.xinjie.analysis.ProtocolTopicParser; |
| 8 | import com.zhonglai.luhui.device.protocol.xinjie.dto.Variant; | 9 | import com.zhonglai.luhui.device.protocol.xinjie.dto.Variant; |
| 9 | import com.zhonglai.luhui.device.protocol.xinjie.dto.XinJieDto; | 10 | import com.zhonglai.luhui.device.protocol.xinjie.dto.XinJieDto; |
| @@ -11,7 +12,7 @@ import com.zhonglai.luhui.device.protocol.xinjie.dto.XinJieDto; | @@ -11,7 +12,7 @@ import com.zhonglai.luhui.device.protocol.xinjie.dto.XinJieDto; | ||
| 11 | public class PubData implements ProtocolTopicParser<byte[]> { | 12 | public class PubData implements ProtocolTopicParser<byte[]> { |
| 12 | 13 | ||
| 13 | @Override | 14 | @Override |
| 14 | - public JsonObject analysisPayload(Topic topic, byte[] payload) { | 15 | + public AnalysisResult analysisPayload(Topic topic, byte[] payload) { |
| 15 | String data = new String(payload); | 16 | String data = new String(payload); |
| 16 | XinJieDto xinJieDto = GsonConstructor.get().fromJson(data, XinJieDto.class); | 17 | XinJieDto xinJieDto = GsonConstructor.get().fromJson(data, XinJieDto.class); |
| 17 | if(null != xinJieDto.getVariant() && xinJieDto.getVariant().size()!=0) | 18 | if(null != xinJieDto.getVariant() && xinJieDto.getVariant().size()!=0) |
| @@ -21,9 +22,9 @@ public class PubData implements ProtocolTopicParser<byte[]> { | @@ -21,9 +22,9 @@ public class PubData implements ProtocolTopicParser<byte[]> { | ||
| 21 | analysisHost(rj,xinJieDto); | 22 | analysisHost(rj,xinJieDto); |
| 22 | analysisDeviceInfo(rj,xinJieDto); | 23 | analysisDeviceInfo(rj,xinJieDto); |
| 23 | 24 | ||
| 24 | - return rj; | 25 | + return new AnalysisResult(false,false,rj); |
| 25 | } | 26 | } |
| 26 | - return GsonConstructor.get().fromJson(data, JsonObject.class); | 27 | + return new AnalysisResult(false,false,GsonConstructor.get().fromJson(data, JsonObject.class)); |
| 27 | } | 28 | } |
| 28 | 29 | ||
| 29 | private void analysisHost(JsonObject rj,XinJieDto xinJieDto) | 30 | private void analysisHost(JsonObject rj,XinJieDto xinJieDto) |
| @@ -2,11 +2,12 @@ package com.zhonglai.luhui.device.protocol.xinjie.analysis.topic; | @@ -2,11 +2,12 @@ package com.zhonglai.luhui.device.protocol.xinjie.analysis.topic; | ||
| 2 | 2 | ||
| 3 | import com.google.gson.JsonObject; | 3 | import com.google.gson.JsonObject; |
| 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 5 | import com.zhonglai.luhui.device.protocol.xinjie.analysis.ProtocolTopicParser; | 6 | import com.zhonglai.luhui.device.protocol.xinjie.analysis.ProtocolTopicParser; |
| 6 | 7 | ||
| 7 | public class WriteData implements ProtocolTopicParser<byte[]> { | 8 | public class WriteData implements ProtocolTopicParser<byte[]> { |
| 8 | @Override | 9 | @Override |
| 9 | - public JsonObject analysisPayload(Topic topic, byte[] payload) { | 10 | + public AnalysisResult analysisPayload(Topic topic, byte[] payload) { |
| 10 | return null; | 11 | return null; |
| 11 | } | 12 | } |
| 12 | } | 13 | } |
| @@ -2,11 +2,12 @@ package com.zhonglai.luhui.device.protocol.xinjie.analysis.topic; | @@ -2,11 +2,12 @@ package com.zhonglai.luhui.device.protocol.xinjie.analysis.topic; | ||
| 2 | 2 | ||
| 3 | import com.google.gson.JsonObject; | 3 | import com.google.gson.JsonObject; |
| 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 5 | import com.zhonglai.luhui.device.protocol.xinjie.analysis.ProtocolTopicParser; | 6 | import com.zhonglai.luhui.device.protocol.xinjie.analysis.ProtocolTopicParser; |
| 6 | 7 | ||
| 7 | public class WriteReply implements ProtocolTopicParser<byte[]> { | 8 | public class WriteReply implements ProtocolTopicParser<byte[]> { |
| 8 | @Override | 9 | @Override |
| 9 | - public JsonObject analysisPayload(Topic topic, byte[] payload) { | 10 | + public AnalysisResult analysisPayload(Topic topic, byte[] payload) { |
| 10 | return null; | 11 | return null; |
| 11 | } | 12 | } |
| 12 | } | 13 | } |
| @@ -27,7 +27,7 @@ public class LsyProtocolSyncFactoryImpl implements ProtocolSyncFactory { | @@ -27,7 +27,7 @@ public class LsyProtocolSyncFactoryImpl implements ProtocolSyncFactory { | ||
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | @Override | 29 | @Override |
| 30 | - public void updateParserDeviceInfoDtoList(List<ParserDeviceInfoDto> parserDeviceInfoDtoList) { | 30 | + public void updateParserDeviceInfoDtoList(Integer productId, List<ParserDeviceInfoDto> parserDeviceInfoDtoList) { |
| 31 | if(null != parserDeviceInfoDtoList && parserDeviceInfoDtoList.size() != 0) | 31 | if(null != parserDeviceInfoDtoList && parserDeviceInfoDtoList.size() != 0) |
| 32 | { | 32 | { |
| 33 | for (ParserDeviceInfoDto parserDeviceInfoDto:parserDeviceInfoDtoList) | 33 | for (ParserDeviceInfoDto parserDeviceInfoDto:parserDeviceInfoDtoList) |
| @@ -2,6 +2,7 @@ package com.zhonglai.luhui.http.service.proxy; | @@ -2,6 +2,7 @@ package com.zhonglai.luhui.http.service.proxy; | ||
| 2 | 2 | ||
| 3 | import com.zhonglai.luhui.device.analysis.comm.config.CacheConfig; | 3 | import com.zhonglai.luhui.device.analysis.comm.config.CacheConfig; |
| 4 | import com.zhonglai.luhui.device.analysis.comm.config.FastJson2JsonRedisSerializer; | 4 | import com.zhonglai.luhui.device.analysis.comm.config.FastJson2JsonRedisSerializer; |
| 5 | +import com.zhonglai.luhui.device.protocol.factory.control.DeviceCommandListenService; | ||
| 5 | import org.slf4j.Logger; | 6 | import org.slf4j.Logger; |
| 6 | import org.slf4j.LoggerFactory; | 7 | import org.slf4j.LoggerFactory; |
| 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; | 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| @@ -18,7 +19,7 @@ import org.springframework.context.annotation.FilterType; | @@ -18,7 +19,7 @@ import org.springframework.context.annotation.FilterType; | ||
| 18 | "com.zhonglai.luhui.http.service.proxy" | 19 | "com.zhonglai.luhui.http.service.proxy" |
| 19 | },excludeFilters = @ComponentScan.Filter( | 20 | },excludeFilters = @ComponentScan.Filter( |
| 20 | type = FilterType.ASSIGNABLE_TYPE, | 21 | type = FilterType.ASSIGNABLE_TYPE, |
| 21 | - classes = {CacheConfig.class, FastJson2JsonRedisSerializer.class} | 22 | + classes = {CacheConfig.class, FastJson2JsonRedisSerializer.class, DeviceCommandListenService.class} |
| 22 | ) ) | 23 | ) ) |
| 23 | @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}) | 24 | @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}) |
| 24 | public class LhHttpServiceProxyApplication { | 25 | public class LhHttpServiceProxyApplication { |
| @@ -80,7 +80,7 @@ public class LoginService { | @@ -80,7 +80,7 @@ public class LoginService { | ||
| 80 | yu2leUserInfo.setLastLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest())); | 80 | yu2leUserInfo.setLastLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest())); |
| 81 | yu2leUserInfo.setLastLoginTime(DateUtils.getNowTimeMilly()); | 81 | yu2leUserInfo.setLastLoginTime(DateUtils.getNowTimeMilly()); |
| 82 | publicService.updateObjectByTable(yu2leUserInfo,"id","`liu_yu_le`.`user_info`"); | 82 | publicService.updateObjectByTable(yu2leUserInfo,"id","`liu_yu_le`.`user_info`"); |
| 83 | - return tokenService.createToken(loginUser); | 83 | + return tokenService.creatApiToken(loginUser); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | public String openaiLoginByPass(String user,String pass) { | 86 | public String openaiLoginByPass(String user,String pass) { |
| @@ -31,7 +31,7 @@ public class MqttServiceListenApplication { | @@ -31,7 +31,7 @@ public class MqttServiceListenApplication { | ||
| 31 | 31 | ||
| 32 | public static void main(String[] args) { | 32 | public static void main(String[] args) { |
| 33 | log.info("启动服务"); | 33 | log.info("启动服务"); |
| 34 | - System.setProperty("RunInIDEA",checkRunInIDEA()); | 34 | +// System.setProperty("RunInIDEA",checkRunInIDEA()); |
| 35 | 35 | ||
| 36 | SpringApplicationBuilder builder = new SpringApplicationBuilder(MqttServiceListenApplication.class); | 36 | SpringApplicationBuilder builder = new SpringApplicationBuilder(MqttServiceListenApplication.class); |
| 37 | builder.run( args); | 37 | builder.run( args); |
| @@ -17,7 +17,7 @@ import org.springframework.stereotype.Component; | @@ -17,7 +17,7 @@ import org.springframework.stereotype.Component; | ||
| 17 | @Component | 17 | @Component |
| 18 | public class MqttCallback extends BaseCallback implements MqttCallbackExtended { | 18 | public class MqttCallback extends BaseCallback implements MqttCallbackExtended { |
| 19 | 19 | ||
| 20 | - private static final String topicOnlineModel = "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{imei}}/{{topicType}}"; | 20 | + private static final String topicOnlineModel = "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{topicType}}"; |
| 21 | 21 | ||
| 22 | @Autowired | 22 | @Autowired |
| 23 | private TerminalService terminalService; //客户端服务 | 23 | private TerminalService terminalService; //客户端服务 |
| @@ -47,12 +47,12 @@ public class MqttCallback extends BaseCallback implements MqttCallbackExtended { | @@ -47,12 +47,12 @@ public class MqttCallback extends BaseCallback implements MqttCallbackExtended { | ||
| 47 | 47 | ||
| 48 | try { | 48 | try { |
| 49 | //过滤在线消息 | 49 | //过滤在线消息 |
| 50 | - if (s.endsWith("online")) | ||
| 51 | - { | ||
| 52 | - String state = new String(mqttMessage.getPayload()); | ||
| 53 | - deviceCashUpService.upOnline(state); | ||
| 54 | - return ; | ||
| 55 | - } | 50 | +// if (s.endsWith("online")) |
| 51 | +// { | ||
| 52 | +// String state = new String(mqttMessage.getPayload()); | ||
| 53 | +// deviceCashUpService.upOnline(state); | ||
| 54 | +// return ; | ||
| 55 | +// } | ||
| 56 | 56 | ||
| 57 | messageArrived(baseTopic.getClientid(),s,mqttMessage.getPayload()); | 57 | messageArrived(baseTopic.getClientid(),s,mqttMessage.getPayload()); |
| 58 | 58 |
| 1 | +package com.zhonglai.luhui.mqtt.service.proxy.comm.service; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 4 | +import com.zhonglai.luhui.device.analysis.dto.Message; | ||
| 5 | +import com.zhonglai.luhui.device.analysis.dto.MessageCode; | ||
| 6 | +import com.zhonglai.luhui.device.analysis.dto.MessageCodeType; | ||
| 7 | +import com.zhonglai.luhui.device.analysis.util.TopicUtil; | ||
| 8 | +import com.zhonglai.luhui.device.protocol.factory.control.ClienNoticeServiceFactory; | ||
| 9 | +import com.zhonglai.luhui.device.protocol.factory.dto.NoticeMessageDto; | ||
| 10 | +import org.eclipse.paho.client.mqttv3.MqttException; | ||
| 11 | +import org.eclipse.paho.client.mqttv3.MqttMessage; | ||
| 12 | +import org.slf4j.Logger; | ||
| 13 | +import org.slf4j.LoggerFactory; | ||
| 14 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 15 | +import org.springframework.stereotype.Service; | ||
| 16 | + | ||
| 17 | +@Service | ||
| 18 | +public class MqttClienNoticeServiceImpl implements ClienNoticeServiceFactory { | ||
| 19 | + private static final Logger log = LoggerFactory.getLogger(MqttClienNoticeServiceImpl.class); | ||
| 20 | + @Autowired | ||
| 21 | + private TerminalService terminalService; | ||
| 22 | + @Override | ||
| 23 | + public boolean sendMessage( NoticeMessageDto noticeMessageDomain) { | ||
| 24 | + if(null == noticeMessageDomain || null == noticeMessageDomain.getCommd()) | ||
| 25 | + { | ||
| 26 | + return false; | ||
| 27 | + } | ||
| 28 | + MqttMessage mqttMessage = new MqttMessage(); | ||
| 29 | + mqttMessage.setPayload(noticeMessageDomain.getCommd()); | ||
| 30 | + try { | ||
| 31 | + terminalService.publish(TopicUtil.generateSendMessageTopic(noticeMessageDomain.getTopic(),noticeMessageDomain.getTopicconfig()),mqttMessage); | ||
| 32 | + return true; | ||
| 33 | + } catch (MqttException e) { | ||
| 34 | + log.error("转发消息异常",e); | ||
| 35 | + } | ||
| 36 | + return false; | ||
| 37 | + } | ||
| 38 | +} |
| @@ -2,10 +2,15 @@ package com.zhonglai.luhui.mqtt.service.proxy.comm.service; | @@ -2,10 +2,15 @@ package com.zhonglai.luhui.mqtt.service.proxy.comm.service; | ||
| 2 | 2 | ||
| 3 | import com.ruoyi.common.utils.StringUtils; | 3 | import com.ruoyi.common.utils.StringUtils; |
| 4 | import com.zhonglai.luhui.device.analysis.comm.config.SysParameter; | 4 | import com.zhonglai.luhui.device.analysis.comm.config.SysParameter; |
| 5 | +import com.zhonglai.luhui.device.analysis.comm.util.ByteUtil; | ||
| 6 | +import com.zhonglai.luhui.device.analysis.util.TopicUtil; | ||
| 7 | +import com.zhonglai.luhui.device.protocol.factory.comm.DataLogType; | ||
| 8 | +import com.zhonglai.luhui.device.protocol.factory.comm.DeviceDataLog; | ||
| 5 | import com.zhonglai.luhui.device.protocol.factory.service.impl.DefaultDbService; | 9 | import com.zhonglai.luhui.device.protocol.factory.service.impl.DefaultDbService; |
| 6 | import org.eclipse.paho.client.mqttv3.MqttClient; | 10 | import org.eclipse.paho.client.mqttv3.MqttClient; |
| 7 | import org.eclipse.paho.client.mqttv3.MqttConnectOptions; | 11 | import org.eclipse.paho.client.mqttv3.MqttConnectOptions; |
| 8 | import org.eclipse.paho.client.mqttv3.MqttException; | 12 | import org.eclipse.paho.client.mqttv3.MqttException; |
| 13 | +import org.eclipse.paho.client.mqttv3.MqttMessage; | ||
| 9 | import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; | 14 | import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; |
| 10 | import org.slf4j.Logger; | 15 | import org.slf4j.Logger; |
| 11 | import org.slf4j.LoggerFactory; | 16 | import org.slf4j.LoggerFactory; |
| @@ -45,8 +50,8 @@ public class TerminalService { | @@ -45,8 +50,8 @@ public class TerminalService { | ||
| 45 | private String username; | 50 | private String username; |
| 46 | @Value("${mqtt.password}") | 51 | @Value("${mqtt.password}") |
| 47 | private String password; | 52 | private String password; |
| 48 | - @Value("${mqtt.textTopic:null}") | ||
| 49 | - private String textTopic; | 53 | + @Value("${mqtt.topics}") |
| 54 | + private List<String> topics; | ||
| 50 | 55 | ||
| 51 | private MqttClient mqttclient; | 56 | private MqttClient mqttclient; |
| 52 | 57 | ||
| @@ -82,13 +87,13 @@ public class TerminalService { | @@ -82,13 +87,13 @@ public class TerminalService { | ||
| 82 | 87 | ||
| 83 | public List<String> getCompletionTopics() | 88 | public List<String> getCompletionTopics() |
| 84 | { | 89 | { |
| 85 | - if ("1".equals(System.getProperty("RunInIDEA")) && StringUtils.isNotEmpty(textTopic)) | ||
| 86 | - { | ||
| 87 | - List<String> list = new ArrayList<>(); | ||
| 88 | - list.add(textTopic); | ||
| 89 | - return list; | ||
| 90 | - } | ||
| 91 | - return dbService.getTopicFromRole(); | 90 | +// if ("1".equals(System.getProperty("RunInIDEA")) && StringUtils.isNotEmpty(textTopic)) |
| 91 | +// { | ||
| 92 | +// List<String> list = new ArrayList<>(); | ||
| 93 | +// list.add(textTopic); | ||
| 94 | +// return list; | ||
| 95 | +// } | ||
| 96 | + return topics; | ||
| 92 | } | 97 | } |
| 93 | 98 | ||
| 94 | @PostConstruct | 99 | @PostConstruct |
| @@ -112,4 +117,10 @@ public class TerminalService { | @@ -112,4 +117,10 @@ public class TerminalService { | ||
| 112 | mqttclient.close(); | 117 | mqttclient.close(); |
| 113 | } | 118 | } |
| 114 | } | 119 | } |
| 120 | + public void publish(String topic, MqttMessage message) throws MqttException { | ||
| 121 | + log.info("mqtt发送消息>>>>>>>:{} 《===============》 字符串:【{}】 十六进制:【{}】",topic,new String(message.getPayload()), ByteUtil.hexStringToSpace(ByteUtil.toHexString(message.getPayload()))); | ||
| 122 | + DeviceDataLog.info(TopicUtil.initTopic(topic).getClientid(), DataLogType.发送数据,topic,message); | ||
| 123 | + | ||
| 124 | + mqttclient.publish(topic,message); | ||
| 125 | + } | ||
| 115 | } | 126 | } |
| @@ -28,4 +28,9 @@ mqtt: | @@ -28,4 +28,9 @@ mqtt: | ||
| 28 | client: | 28 | client: |
| 29 | #客户端操作时间 | 29 | #客户端操作时间 |
| 30 | operationTime: 10 | 30 | operationTime: 10 |
| 31 | - textTopic: "/2/6_WP/866520067451609/#" | ||
| 31 | + topics: /2/UY_ZYJ_V001/# | ||
| 32 | + | ||
| 33 | +#rocketmq配置信息 | ||
| 34 | +rocketmq: | ||
| 35 | + #nameservice服务器地址(多个以英文逗号隔开) | ||
| 36 | + name-server: 47.115.144.179:9876 |
| @@ -377,7 +377,11 @@ | @@ -377,7 +377,11 @@ | ||
| 377 | <artifactId>lh-device-modbus</artifactId> | 377 | <artifactId>lh-device-modbus</artifactId> |
| 378 | <version>${ruoyi.version}</version> | 378 | <version>${ruoyi.version}</version> |
| 379 | </dependency> | 379 | </dependency> |
| 380 | - | 380 | + <dependency> |
| 381 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 382 | + <artifactId>lh-common-log</artifactId> | ||
| 383 | + <version>${ruoyi.version}</version> | ||
| 384 | + </dependency> | ||
| 381 | <dependency> | 385 | <dependency> |
| 382 | <groupId>com.zhonglai</groupId> | 386 | <groupId>com.zhonglai</groupId> |
| 383 | <artifactId>ServiceDao</artifactId> | 387 | <artifactId>ServiceDao</artifactId> |
-
请 注册 或 登录 后发表评论