正在显示
27 个修改的文件
包含
470 行增加
和
124 行删除
| @@ -7,12 +7,12 @@ import io.swagger.annotations.ApiModelProperty; | @@ -7,12 +7,12 @@ import io.swagger.annotations.ApiModelProperty; | ||
| 7 | import com.ruoyi.common.tool.BaseEntity; | 7 | import com.ruoyi.common.tool.BaseEntity; |
| 8 | 8 | ||
| 9 | /** | 9 | /** |
| 10 | - * 【请填写功能名称】对象 iot_product_label | 10 | + * 产品标签对象 iot_product_label |
| 11 | * | 11 | * |
| 12 | * @author zhonglai | 12 | * @author zhonglai |
| 13 | * @date 2024-07-22 | 13 | * @date 2024-07-22 |
| 14 | */ | 14 | */ |
| 15 | -@ApiModel("【请填写功能名称】") | 15 | +@ApiModel("产品标签") |
| 16 | public class IotProductLabel extends BaseEntity | 16 | public class IotProductLabel extends BaseEntity |
| 17 | { | 17 | { |
| 18 | private static final long serialVersionUID = 1L; | 18 | private static final long serialVersionUID = 1L; |
| 1 | +package com.zhonglai.luhui.device.domain; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | + | ||
| 6 | +@ApiModel("产品payload的属性编号关系") | ||
| 7 | +public class IotProductPayloadModelNumber { | ||
| 8 | + @ApiModelProperty(value="主键") | ||
| 9 | + private Integer id; // int NOT NULL AUTO_INCREMENT COMMENT '主键', | ||
| 10 | + @ApiModelProperty(value="产品id") | ||
| 11 | + private Integer product_id; // int NOT NULL COMMENT '产品id', | ||
| 12 | + @ApiModelProperty(value="编号") | ||
| 13 | + private String number; // varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '编号', | ||
| 14 | + @ApiModelProperty(value="编号名称") | ||
| 15 | + private String number_name; // varchar(150) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '编号名称', | ||
| 16 | + @ApiModelProperty(value="模型标识符集合(多个用英文逗号分割)") | ||
| 17 | + private String models; // varchar(250) DEFAULT NULL COMMENT '模型标识符集合(多个用英文逗号分割)', | ||
| 18 | + @ApiModelProperty(value="创建时间") | ||
| 19 | + private String create_time; // timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | ||
| 20 | + | ||
| 21 | + public Integer getId() { | ||
| 22 | + return id; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public void setId(Integer id) { | ||
| 26 | + this.id = id; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public Integer getProduct_id() { | ||
| 30 | + return product_id; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public void setProduct_id(Integer product_id) { | ||
| 34 | + this.product_id = product_id; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public String getNumber() { | ||
| 38 | + return number; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public void setNumber(String number) { | ||
| 42 | + this.number = number; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public String getNumber_name() { | ||
| 46 | + return number_name; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public void setNumber_name(String number_name) { | ||
| 50 | + this.number_name = number_name; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public String getModels() { | ||
| 54 | + return models; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public void setModels(String models) { | ||
| 58 | + this.models = models; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public String getCreate_time() { | ||
| 62 | + return create_time; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public void setCreate_time(String create_time) { | ||
| 66 | + this.create_time = create_time; | ||
| 67 | + } | ||
| 68 | +} |
| 1 | +package com.zhonglai.luhui.admin.controller.iot; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.annotation.Log; | ||
| 4 | +import com.ruoyi.common.core.domain.AjaxResult; | ||
| 5 | +import com.ruoyi.common.core.page.TableDataInfo; | ||
| 6 | +import com.ruoyi.common.enums.BusinessType; | ||
| 7 | +import com.zhonglai.luhui.action.BaseController; | ||
| 8 | +import com.zhonglai.luhui.dao.service.PublicTemplateService; | ||
| 9 | +import com.zhonglai.luhui.dao.service.impl.PublicServiceImpl; | ||
| 10 | +import com.zhonglai.luhui.device.domain.IotProductPayloadModelNumber; | ||
| 11 | +import io.swagger.annotations.Api; | ||
| 12 | +import io.swagger.annotations.ApiOperation; | ||
| 13 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 14 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 15 | +import org.springframework.web.bind.annotation.*; | ||
| 16 | + | ||
| 17 | +import java.util.List; | ||
| 18 | +import java.util.Map; | ||
| 19 | + | ||
| 20 | +@Api(tags = "模型编号关系") | ||
| 21 | +@RestController | ||
| 22 | +@RequestMapping("/iot/IotProductPayloadModelNumber") | ||
| 23 | +public class IotProductPayloadModelNumberController extends BaseController { | ||
| 24 | + @Autowired | ||
| 25 | + private PublicTemplateService publicTemplateService; | ||
| 26 | + @Autowired | ||
| 27 | + private PublicServiceImpl publicService; | ||
| 28 | + @ApiOperation(value ="查询列表") | ||
| 29 | + @GetMapping("/list/{productId}") | ||
| 30 | + public TableDataInfo list(@PathVariable Integer productId) | ||
| 31 | + { | ||
| 32 | + startPage(); | ||
| 33 | + IotProductPayloadModelNumber iotProductPayloadModelNumber = new IotProductPayloadModelNumber(); | ||
| 34 | + iotProductPayloadModelNumber.setProduct_id(productId); | ||
| 35 | + List<Map<String,Object>> list = publicService.getObjectList(iotProductPayloadModelNumber,"*",null,null,0,0); | ||
| 36 | + | ||
| 37 | +// List<IotProductPayloadModelNumber> list = publicTemplateService.selectTList(iotProductPayloadModelNumber); | ||
| 38 | + return getDataTable(list); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + @ApiOperation("获取详细信息") | ||
| 42 | + @PreAuthorize("@ss.hasPermi('iot:product_label:query')") | ||
| 43 | + @GetMapping(value = "/{id}") | ||
| 44 | + public AjaxResult getInfo(@PathVariable("id") Integer id) | ||
| 45 | + { | ||
| 46 | + return success(publicTemplateService.getTById(id, IotProductPayloadModelNumber.class)); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + @ApiOperation("新增") | ||
| 50 | + @PreAuthorize("@ss.hasPermi('iot:product_label:add')") | ||
| 51 | + @Log(title = "模型编号关系", businessType = BusinessType.INSERT) | ||
| 52 | + @PostMapping | ||
| 53 | + public AjaxResult add(@RequestBody IotProductPayloadModelNumber iotProductPayloadModelNumber) | ||
| 54 | + { | ||
| 55 | + IotProductPayloadModelNumber ippmn = publicService.getObject(IotProductPayloadModelNumber.class, "product_id,number",iotProductPayloadModelNumber.getProduct_id()+","+iotProductPayloadModelNumber.getNumber()); | ||
| 56 | + if(null != ippmn) | ||
| 57 | + { | ||
| 58 | + return AjaxResult.error("改产品对应的编号已经存在,请去列表页面编辑"); | ||
| 59 | + } | ||
| 60 | + return toAjax(publicTemplateService.add(iotProductPayloadModelNumber)); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + @ApiOperation("修改") | ||
| 64 | + @PreAuthorize("@ss.hasPermi('iot:product_label:edit')") | ||
| 65 | + @Log(title = "模型编号关系", businessType = BusinessType.UPDATE) | ||
| 66 | + @PutMapping | ||
| 67 | + public AjaxResult edit(@RequestBody IotProductPayloadModelNumber iotProductPayloadModelNumber) | ||
| 68 | + { | ||
| 69 | + return toAjax(publicTemplateService.edit((iotProductPayloadModelNumber))); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + @ApiOperation("删除") | ||
| 73 | + @PreAuthorize("@ss.hasPermi('iot:product_label:remove')") | ||
| 74 | + @Log(title = "模型编号关系", businessType = BusinessType.DELETE) | ||
| 75 | + @DeleteMapping("") | ||
| 76 | + public AjaxResult remove(@RequestBody Integer[] ids) | ||
| 77 | + { | ||
| 78 | + return toAjax(publicTemplateService.removeByIds(IotProductPayloadModelNumber.class,ids)); | ||
| 79 | + } | ||
| 80 | +} |
| @@ -11,6 +11,10 @@ | @@ -11,6 +11,10 @@ | ||
| 11 | 11 | ||
| 12 | <artifactId>lh-device-plc004</artifactId> | 12 | <artifactId>lh-device-plc004</artifactId> |
| 13 | 13 | ||
| 14 | + <description> | ||
| 15 | + 设备解析paylod自定义编号 | ||
| 16 | + </description> | ||
| 17 | + | ||
| 14 | <dependencies> | 18 | <dependencies> |
| 15 | <dependency> | 19 | <dependency> |
| 16 | <groupId>com.zhonglai.luhui</groupId> | 20 | <groupId>com.zhonglai.luhui</groupId> |
| 1 | +package com.zhonglai.luhui.device.protocol.plc004.analysis; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.ruoyi.common.utils.StringUtils; | ||
| 6 | +import com.zhonglai.luhui.device.analysis.comm.dto.ApiClientRePlyDto; | ||
| 7 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 8 | +import com.zhonglai.luhui.device.analysis.dto.Message; | ||
| 9 | +import com.zhonglai.luhui.device.analysis.dto.MessageCode; | ||
| 10 | +import com.zhonglai.luhui.device.analysis.util.TopicUtil; | ||
| 11 | +import com.zhonglai.luhui.device.domain.IotProductPayloadModelNumber; | ||
| 12 | +import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory; | ||
| 13 | +import com.zhonglai.luhui.device.protocol.factory.analysis.topic.*; | ||
| 14 | +import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; | ||
| 15 | +import com.zhonglai.luhui.device.protocol.factory.config.ProductPayloadModelNumberCach; | ||
| 16 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 17 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 18 | + | ||
| 19 | + | ||
| 20 | +public class PLC004ProtocolParserFactoryImpl implements ProtocolParserFactory<byte[]> { | ||
| 21 | + private static final String topicModel = "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{topicType}}"; | ||
| 22 | + @Override | ||
| 23 | + public Topic analysisTopic(String topicStr) { | ||
| 24 | + Topic topic = TopicUtil.initTopicFromModelStr(topicStr,topicModel); | ||
| 25 | + return topic; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + @Override | ||
| 29 | + public AnalysisResult analysisPayload(Topic topic, byte[] payload) { | ||
| 30 | + switch (topic.getTopicType()) | ||
| 31 | + { | ||
| 32 | + case "online": | ||
| 33 | + return new Online().analysisPayload(payload); | ||
| 34 | + case "ONLINE": | ||
| 35 | + return new Online().analysisPayload(payload); | ||
| 36 | + case "ADD_POST": | ||
| 37 | + return new AddPost().analysisPayload(toformatPayLoad(topic.getClientid(),payload)); | ||
| 38 | + case "PUT_REQ": | ||
| 39 | + JsonObject jsonObject = GsonConstructor.get().fromJson(new String(payload),JsonObject.class); | ||
| 40 | + return new AnalysisResult(false, false, null, new ApiClientRePlyDto() { | ||
| 41 | + @Override | ||
| 42 | + public void setReplyMessage(Message message) { | ||
| 43 | + if(jsonObject.has("result") && "1".equals(jsonObject.get("result").getAsString())) | ||
| 44 | + { | ||
| 45 | + message.setCode(MessageCode.DEFAULT_SUCCESS_CODE); | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + }); | ||
| 49 | + default: | ||
| 50 | + return new AnalysisResult(false,false,null); | ||
| 51 | + } | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + private String toformatPayLoad(String clientid,byte[] payload) | ||
| 55 | + { | ||
| 56 | + JsonObject jsonObject = GsonConstructor.get().fromJson(new String(payload),JsonObject.class); | ||
| 57 | + ParserDeviceHostDto parserDeviceHostDto = DeviceCach.getDeviceHost(clientid); | ||
| 58 | + if(null != parserDeviceHostDto && null != parserDeviceHostDto.getIotProduct()) | ||
| 59 | + { | ||
| 60 | + Integer iotProductid = parserDeviceHostDto.getIotProduct().getId(); | ||
| 61 | + | ||
| 62 | + JsonObject rj = new JsonObject(); | ||
| 63 | + for (String key : jsonObject.keySet()) | ||
| 64 | + { | ||
| 65 | + IotProductPayloadModelNumber iotProductPayloadModelNumber = ProductPayloadModelNumberCach.getNumber(iotProductid,key); | ||
| 66 | + if(null != iotProductPayloadModelNumber) | ||
| 67 | + { | ||
| 68 | + String number = iotProductPayloadModelNumber.getNumber(); | ||
| 69 | + if(StringUtils.isNotEmpty(number)) | ||
| 70 | + { | ||
| 71 | + JsonObject numberjson = rj.getAsJsonObject(number); | ||
| 72 | + if(null == numberjson) | ||
| 73 | + { | ||
| 74 | + numberjson = new JsonObject(); | ||
| 75 | + if(StringUtils.isNoneBlank(iotProductPayloadModelNumber.getNumber_name())) | ||
| 76 | + { | ||
| 77 | + numberjson.addProperty("%sysdeviceinfoname%",iotProductPayloadModelNumber.getNumber_name()); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + rj.add(number,numberjson); | ||
| 81 | + } | ||
| 82 | + numberjson.add(key,jsonObject.get(key)); | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + } | ||
| 87 | + return rj.toString(); | ||
| 88 | + } | ||
| 89 | + return new JsonObject().toString(); | ||
| 90 | + } | ||
| 91 | +} |
| 1 | -package com.zhonglai.luhui.device.protocol.plc004.analysis; | ||
| 2 | - | ||
| 3 | -import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 4 | -import com.zhonglai.luhui.device.analysis.util.TopicUtil; | ||
| 5 | -import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory; | ||
| 6 | -import com.zhonglai.luhui.device.protocol.factory.analysis.topic.Online; | ||
| 7 | -import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 8 | -import com.zhonglai.luhui.device.protocol.plc004.analysis.topic.AllPost; | ||
| 9 | -import com.zhonglai.luhui.device.protocol.plc004.analysis.topic.PutReq; | ||
| 10 | - | ||
| 11 | -public class Plc004ProtocolParserFactoryImpl implements ProtocolParserFactory<byte[]> { | ||
| 12 | - private static final String topicModel = "/{{roleid}}/{{username}}/{{topicType}}/{{clientid}}"; | ||
| 13 | - @Override | ||
| 14 | - public Topic analysisTopic(String topicStr) { | ||
| 15 | - Topic topic = TopicUtil.initTopicFromModelStr(topicStr,topicModel); | ||
| 16 | - return topic; | ||
| 17 | - } | ||
| 18 | - | ||
| 19 | - @Override | ||
| 20 | - public AnalysisResult analysisPayload(Topic topic, byte[] payload) { | ||
| 21 | - | ||
| 22 | - switch (topic.getTopicType()) | ||
| 23 | - { | ||
| 24 | - case "PUT_REQ": | ||
| 25 | - return new PutReq().analysisPayload(payload); | ||
| 26 | - case "ALL_POST": | ||
| 27 | - return new AllPost().analysisPayload(payload); | ||
| 28 | - case "online": | ||
| 29 | - return new Online().analysisPayload(payload); | ||
| 30 | - } | ||
| 31 | - return null; | ||
| 32 | - } | ||
| 33 | -} |
| 1 | -package com.zhonglai.luhui.device.protocol.plc004.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(byte[] payload) | ||
| 9 | - { | ||
| 10 | - String str = new String(payload); | ||
| 11 | - JsonObject jsonObject = GsonConstructor.get().fromJson(str,JsonObject.class); | ||
| 12 | - if(jsonObject.has("data")) | ||
| 13 | - { | ||
| 14 | - jsonObject.add("1", jsonObject.get("data").getAsJsonObject()); | ||
| 15 | - return new AnalysisResult(true,false,jsonObject); | ||
| 16 | - } | ||
| 17 | - return new AnalysisResult(false,false,null); | ||
| 18 | - } | ||
| 19 | -} |
| 1 | -package com.zhonglai.luhui.device.protocol.plc004.analysis.topic; | ||
| 2 | - | ||
| 3 | -import com.alibaba.fastjson.JSONObject; | ||
| 4 | -import com.google.gson.JsonObject; | ||
| 5 | -import com.ruoyi.common.utils.GsonConstructor; | ||
| 6 | -import com.zhonglai.luhui.device.analysis.comm.dto.ApiClientRePlyDto; | ||
| 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 PutReq { | ||
| 15 | - public AnalysisResult analysisPayload(byte[] payload) | ||
| 16 | - { | ||
| 17 | - String str = new String(payload); | ||
| 18 | - JsonObject jsonObject = GsonConstructor.get().fromJson(str,JsonObject.class); | ||
| 19 | - if(jsonObject.has("data")) | ||
| 20 | - { | ||
| 21 | - jsonObject.add("1", jsonObject.get("data").getAsJsonObject()); | ||
| 22 | - return new AnalysisResult(false, false, jsonObject, new ApiClientRePlyDto() { | ||
| 23 | - @Override | ||
| 24 | - public void setReplyMessage(Message message) { | ||
| 25 | - message.setCode(MessageCode.DEFAULT_SUCCESS_CODE); | ||
| 26 | - message.setData(JSONObject.parseObject(jsonObject.get("data").toString(),HashMap.class)); | ||
| 27 | - } | ||
| 28 | - }); | ||
| 29 | - } | ||
| 30 | - return new AnalysisResult(false,false,null); | ||
| 31 | - } | ||
| 32 | -} |
| 1 | package com.zhonglai.luhui.device.protocol.plc004.control; | 1 | package com.zhonglai.luhui.device.protocol.plc004.control; |
| 2 | 2 | ||
| 3 | +import com.google.gson.JsonElement; | ||
| 3 | import com.google.gson.JsonObject; | 4 | import com.google.gson.JsonObject; |
| 5 | +import com.google.gson.reflect.TypeToken; | ||
| 6 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 7 | 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.domain.IotProduct; |
| 8 | import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; | 9 | 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.control.DeviceCommandServiceFactory; |
| @@ -12,13 +13,14 @@ import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | @@ -12,13 +13,14 @@ import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 12 | import org.slf4j.Logger; | 13 | import org.slf4j.Logger; |
| 13 | import org.slf4j.LoggerFactory; | 14 | import org.slf4j.LoggerFactory; |
| 14 | 15 | ||
| 15 | -import java.util.Arrays; | 16 | +import java.lang.reflect.Type; |
| 17 | +import java.util.Map; | ||
| 16 | 18 | ||
| 17 | /** | 19 | /** |
| 18 | * 指令控制监听实现 | 20 | * 指令控制监听实现 |
| 19 | */ | 21 | */ |
| 20 | public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFactory { | 22 | public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFactory { |
| 21 | - private static final String topicModel = "/{{roleid}}/{{username}}/{{topicType}}/{{clientid}}"; | 23 | + private static final String topicModel = "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{topicType}}"; |
| 22 | 24 | ||
| 23 | private static final Logger log = LoggerFactory.getLogger(DeviceCommandListenServiceImpl.class); | 25 | private static final Logger log = LoggerFactory.getLogger(DeviceCommandListenServiceImpl.class); |
| 24 | @Override | 26 | @Override |
| @@ -34,17 +36,12 @@ public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFacto | @@ -34,17 +36,12 @@ public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFacto | ||
| 34 | NoticeMessageDto noticeMessageDto = new NoticeMessageDto(); | 36 | NoticeMessageDto noticeMessageDto = new NoticeMessageDto(); |
| 35 | noticeMessageDto.setTopic(topic); | 37 | noticeMessageDto.setTopic(topic); |
| 36 | noticeMessageDto.setTopicconfig(topicModel); | 38 | noticeMessageDto.setTopicconfig(topicModel); |
| 37 | - if (jsonObject.has("1")) | ||
| 38 | - { | ||
| 39 | - JsonObject data = jsonObject.get("1").getAsJsonObject(); | ||
| 40 | - if (data.has("3") && data.has("106")) | ||
| 41 | - { | ||
| 42 | - byte[] bytes = new byte[]{(byte) 0xA5, 0x07, 0x01, 0x20, (byte) data.get("3").getAsInt(), (byte) (data.get("106").getAsInt() - 1)}; | ||
| 43 | - bytes = Arrays.copyOf(bytes, bytes.length + 1); | ||
| 44 | - bytes[bytes.length - 1] = ByteUtil.calculateChecksum(bytes); | ||
| 45 | - noticeMessageDto.setCommd(bytes); | ||
| 46 | - } | ||
| 47 | - } | 39 | + |
| 40 | + //将jsonObject里面的两层键值比如:{"1":{"key","value","key1",1}}提取成一层放在commdjson里面如{"key":"value","key1":1} | ||
| 41 | + JsonObject commdjson = flattenJsonObject(jsonObject); | ||
| 42 | + | ||
| 43 | + noticeMessageDto.setCommd(commdjson.toString().getBytes()); | ||
| 44 | + | ||
| 48 | return noticeMessageDto; | 45 | return noticeMessageDto; |
| 49 | } | 46 | } |
| 50 | 47 | ||
| @@ -53,6 +50,39 @@ public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFacto | @@ -53,6 +50,39 @@ public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFacto | ||
| 53 | return false; | 50 | return false; |
| 54 | } | 51 | } |
| 55 | 52 | ||
| 53 | + /** | ||
| 54 | + * 将嵌套的JsonObject扁平化。 | ||
| 55 | + * | ||
| 56 | + * @param jsonObject 嵌套的JsonObject | ||
| 57 | + * @return 扁平化的JsonObject | ||
| 58 | + */ | ||
| 59 | + public JsonObject flattenJsonObject(JsonObject jsonObject) { | ||
| 60 | + // 使用Gson将嵌套的JsonObject转换为Map | ||
| 61 | + Type typeOfMap = new TypeToken<Map<String, JsonElement>>(){}.getType(); | ||
| 62 | + Map<String, JsonElement> map = GsonConstructor.get().fromJson(jsonObject, typeOfMap); | ||
| 63 | + | ||
| 64 | + // 创建一个新的JsonObject用于存储扁平化的结果 | ||
| 65 | + JsonObject flatJson = new JsonObject(); | ||
| 66 | + | ||
| 67 | + // 遍历Map中的所有键值对 | ||
| 68 | + for (Map.Entry<String, JsonElement> entry : map.entrySet()) { | ||
| 69 | + JsonElement value = entry.getValue(); | ||
| 70 | + | ||
| 71 | + // 检查值是否为JsonObject | ||
| 72 | + if (value.isJsonObject()) { | ||
| 73 | + // 如果是JsonObject,则将其键值对添加到flatJson中 | ||
| 74 | + JsonObject innerJson = value.getAsJsonObject(); | ||
| 75 | + for (Map.Entry<String, JsonElement> innerEntry : innerJson.entrySet()) { | ||
| 76 | + flatJson.add(innerEntry.getKey(), innerEntry.getValue()); | ||
| 77 | + } | ||
| 78 | + } else { | ||
| 79 | + // 如果不是JsonObject,则直接添加到flatJson中 | ||
| 80 | + flatJson.add(entry.getKey(), value); | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + return flatJson; | ||
| 85 | + } | ||
| 56 | 86 | ||
| 57 | private Topic getWriteTopic(String deviceId, IotProduct iotProduct) | 87 | private Topic getWriteTopic(String deviceId, IotProduct iotProduct) |
| 58 | { | 88 | { |
| @@ -61,6 +91,7 @@ public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFacto | @@ -61,6 +91,7 @@ public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFacto | ||
| 61 | topic.setClientid(deviceId); | 91 | topic.setClientid(deviceId); |
| 62 | topic.setRoleid(iotProduct.getRole_id()+""); | 92 | topic.setRoleid(iotProduct.getRole_id()+""); |
| 63 | topic.setUsername(iotProduct.getMqtt_username()); | 93 | topic.setUsername(iotProduct.getMqtt_username()); |
| 94 | + topic.setPayloadtype("Json"); | ||
| 64 | return topic; | 95 | return topic; |
| 65 | } | 96 | } |
| 66 | } | 97 | } |
| 1 | package com.zhonglai.luhui.device.protocol.factory; | 1 | package com.zhonglai.luhui.device.protocol.factory; |
| 2 | 2 | ||
| 3 | import com.google.gson.JsonObject; | 3 | import com.google.gson.JsonObject; |
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 4 | import com.ruoyi.common.utils.StringUtils; | 5 | import com.ruoyi.common.utils.StringUtils; |
| 5 | import com.ruoyi.common.utils.spring.SpringUtils; | 6 | import com.ruoyi.common.utils.spring.SpringUtils; |
| 6 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 7 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| @@ -12,18 +13,14 @@ import com.zhonglai.luhui.device.protocol.factory.comm.DataLogType; | @@ -12,18 +13,14 @@ import com.zhonglai.luhui.device.protocol.factory.comm.DataLogType; | ||
| 12 | import com.zhonglai.luhui.device.protocol.factory.comm.DeviceDataLog; | 13 | import com.zhonglai.luhui.device.protocol.factory.comm.DeviceDataLog; |
| 13 | import com.zhonglai.luhui.device.protocol.factory.config.PluginsClassLoader; | 14 | 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.AnalysisResult; |
| 15 | -import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 16 | import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | 16 | import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; |
| 17 | -import com.zhonglai.luhui.device.protocol.factory.plugins.InitPlugins; | ||
| 18 | import com.zhonglai.luhui.device.protocol.factory.purification.DefaultProtocolPurificationFactoryImpl; | 17 | import com.zhonglai.luhui.device.protocol.factory.purification.DefaultProtocolPurificationFactoryImpl; |
| 19 | import com.zhonglai.luhui.device.protocol.factory.purification.ProtocolPurificationFactory; | 18 | import com.zhonglai.luhui.device.protocol.factory.purification.ProtocolPurificationFactory; |
| 20 | import com.zhonglai.luhui.device.protocol.factory.service.PersistenceDBService; | 19 | import com.zhonglai.luhui.device.protocol.factory.service.PersistenceDBService; |
| 21 | -import org.slf4j.Logger; | ||
| 22 | -import org.slf4j.LoggerFactory; | ||
| 23 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
| 24 | import org.springframework.stereotype.Component; | 21 | import org.springframework.stereotype.Component; |
| 25 | 22 | ||
| 26 | -import java.util.Map; | 23 | + |
| 27 | 24 | ||
| 28 | /** | 25 | /** |
| 29 | * 协议解析工厂 | 26 | * 协议解析工厂 |
| @@ -53,18 +50,30 @@ public class ProtocolParserAndPurificationFactory<T> { | @@ -53,18 +50,30 @@ public class ProtocolParserAndPurificationFactory<T> { | ||
| 53 | Topic topic = protocolParserFactory.analysisTopic(topicStr); | 50 | Topic topic = protocolParserFactory.analysisTopic(topicStr); |
| 54 | //通过解析服务器将数据解析成键值对的形式存储到json对象里面,方便清洗 | 51 | //通过解析服务器将数据解析成键值对的形式存储到json对象里面,方便清洗 |
| 55 | AnalysisResult analysisResult = protocolParserFactory.analysisPayload(topic,payload); | 52 | AnalysisResult analysisResult = protocolParserFactory.analysisPayload(topic,payload); |
| 56 | - if(null == analysisResult || null == analysisResult.getJsonObject()) | 53 | + if(null == analysisResult) |
| 57 | { | 54 | { |
| 58 | return null; | 55 | return null; |
| 59 | } | 56 | } |
| 60 | 57 | ||
| 61 | //通过模式对解析结果进行清洗,获得到的数据就是业务数据 | 58 | //通过模式对解析结果进行清洗,获得到的数据就是业务数据 |
| 62 | ProtocolPurificationModel protocolPurificationModel = protocolPurificationFactory.purification(iotProduct.getId(),topic,analysisResult); | 59 | ProtocolPurificationModel protocolPurificationModel = protocolPurificationFactory.purification(iotProduct.getId(),topic,analysisResult); |
| 63 | - protocolPurificationModel.setNoticeClien(analysisResult.isNoticeClien()); | ||
| 64 | - protocolPurificationModel.setNoticeMessage(analysisResult.getNoticeMessage()); | ||
| 65 | - protocolPurificationModel.setAllUp(topic.isAllup()); | ||
| 66 | - return protocolPurificationModel; | ||
| 67 | - | 60 | + if(null != protocolPurificationModel) |
| 61 | + { | ||
| 62 | + protocolPurificationModel.setNoticeClien(analysisResult.isNoticeClien()); | ||
| 63 | + protocolPurificationModel.setNoticeMessage(analysisResult.getNoticeMessage()); | ||
| 64 | + protocolPurificationModel.setAllUp(topic.isAllup()); | ||
| 65 | + return protocolPurificationModel; | ||
| 66 | + }else { | ||
| 67 | + if(analysisResult.isNoticeClien()) | ||
| 68 | + { | ||
| 69 | + protocolPurificationModel = new ProtocolPurificationModel(); | ||
| 70 | + protocolPurificationModel.setNoticeClien(analysisResult.isNoticeClien()); | ||
| 71 | + protocolPurificationModel.setNoticeMessage(analysisResult.getNoticeMessage()); | ||
| 72 | + protocolPurificationModel.setAllUp(topic.isAllup()); | ||
| 73 | + return protocolPurificationModel; | ||
| 74 | + } | ||
| 75 | + DeviceDataLog.error(baseTopic.getClientid(), DataLogType.解析消息,"没有找到可以清洗的数据:"+ GsonConstructor.get().toJson(analysisResult)); | ||
| 76 | + } | ||
| 68 | } | 77 | } |
| 69 | DeviceDataLog.error(baseTopic.getClientid(), DataLogType.解析消息,"没有找到可以解析的服务:"+baseTopic.getUsername()); | 78 | DeviceDataLog.error(baseTopic.getClientid(), DataLogType.解析消息,"没有找到可以解析的服务:"+baseTopic.getUsername()); |
| 70 | 79 |
| @@ -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.domain.IotProduct; | ||
| 5 | import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | 6 | import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; |
| 6 | 7 | ||
| 7 | /** | 8 | /** |
| @@ -8,7 +8,12 @@ import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | @@ -8,7 +8,12 @@ import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 8 | public class AddPost { | 8 | public class AddPost { |
| 9 | public AnalysisResult analysisPayload( byte[] payload) | 9 | public AnalysisResult analysisPayload( byte[] payload) |
| 10 | { | 10 | { |
| 11 | - JsonObject jsonObject = GsonConstructor.get().fromJson(new String(payload), JsonObject.class); | 11 | + return analysisPayload(new String(payload)); |
| 12 | + } | ||
| 13 | + | ||
| 14 | + public AnalysisResult analysisPayload(String payload) | ||
| 15 | + { | ||
| 16 | + JsonObject jsonObject = GsonConstructor.get().fromJson(payload, JsonObject.class); | ||
| 12 | return new AnalysisResult(false,false,jsonObject); | 17 | return new AnalysisResult(false,false,jsonObject); |
| 13 | } | 18 | } |
| 14 | } | 19 | } |
| @@ -8,7 +8,12 @@ import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | @@ -8,7 +8,12 @@ import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 8 | public class AllPost { | 8 | public class AllPost { |
| 9 | public AnalysisResult analysisPayload( byte[] payload) | 9 | public AnalysisResult analysisPayload( byte[] payload) |
| 10 | { | 10 | { |
| 11 | - JsonObject jsonObject = GsonConstructor.get().fromJson(new String(payload), JsonObject.class); | 11 | + return analysisPayload(new String(payload)); |
| 12 | + } | ||
| 13 | + | ||
| 14 | + public AnalysisResult analysisPayload(String payload) | ||
| 15 | + { | ||
| 16 | + JsonObject jsonObject = GsonConstructor.get().fromJson(payload, JsonObject.class); | ||
| 12 | return new AnalysisResult(true,false,jsonObject); | 17 | return new AnalysisResult(true,false,jsonObject); |
| 13 | } | 18 | } |
| 14 | } | 19 | } |
| @@ -8,7 +8,12 @@ import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | @@ -8,7 +8,12 @@ import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 8 | public class Get { | 8 | public class Get { |
| 9 | public AnalysisResult analysisPayload( byte[] payload) | 9 | public AnalysisResult analysisPayload( byte[] payload) |
| 10 | { | 10 | { |
| 11 | - JsonObject jsonObject = GsonConstructor.get().fromJson(new String(payload), JsonObject.class); | 11 | + return analysisPayload(new String(payload)); |
| 12 | + } | ||
| 13 | + | ||
| 14 | + public AnalysisResult analysisPayload( String payload) | ||
| 15 | + { | ||
| 16 | + JsonObject jsonObject = GsonConstructor.get().fromJson(payload, JsonObject.class); | ||
| 12 | return new AnalysisResult(false,false,jsonObject); | 17 | return new AnalysisResult(false,false,jsonObject); |
| 13 | } | 18 | } |
| 14 | } | 19 | } |
| @@ -7,9 +7,14 @@ import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | @@ -7,9 +7,14 @@ import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 7 | public class Online { | 7 | public class Online { |
| 8 | public AnalysisResult analysisPayload( byte[] payload) | 8 | public AnalysisResult analysisPayload( byte[] payload) |
| 9 | { | 9 | { |
| 10 | + return analysisPayload( new String(payload)); | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + public AnalysisResult analysisPayload( String payload) | ||
| 14 | + { | ||
| 10 | JsonObject jsonObject = new JsonObject(); | 15 | JsonObject jsonObject = new JsonObject(); |
| 11 | JsonObject object = new JsonObject(); | 16 | JsonObject object = new JsonObject(); |
| 12 | - object.addProperty("online",new String(payload)); | 17 | + object.addProperty("online",payload); |
| 13 | jsonObject.add("0",object); | 18 | jsonObject.add("0",object); |
| 14 | return new AnalysisResult(false,false,jsonObject); | 19 | return new AnalysisResult(false,false,jsonObject); |
| 15 | } | 20 | } |
| @@ -7,7 +7,12 @@ import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | @@ -7,7 +7,12 @@ import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 7 | public class PutReq { | 7 | public class PutReq { |
| 8 | public AnalysisResult analysisPayload(byte[] payload) | 8 | public AnalysisResult analysisPayload(byte[] payload) |
| 9 | { | 9 | { |
| 10 | - JsonObject jsonObject = GsonConstructor.get().fromJson(new String(payload), JsonObject.class); | 10 | + return analysisPayload(new String(payload)); |
| 11 | + } | ||
| 12 | + | ||
| 13 | + public AnalysisResult analysisPayload(String payload) | ||
| 14 | + { | ||
| 15 | + JsonObject jsonObject = GsonConstructor.get().fromJson(payload, JsonObject.class); | ||
| 11 | return new AnalysisResult(false,true,jsonObject); | 16 | return new AnalysisResult(false,true,jsonObject); |
| 12 | } | 17 | } |
| 13 | } | 18 | } |
| @@ -7,7 +7,12 @@ import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | @@ -7,7 +7,12 @@ import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | ||
| 7 | public class ReadReq { | 7 | public class ReadReq { |
| 8 | public AnalysisResult analysisPayload(byte[] payload) | 8 | public AnalysisResult analysisPayload(byte[] payload) |
| 9 | { | 9 | { |
| 10 | - JsonObject jsonObject = GsonConstructor.get().fromJson(new String(payload), JsonObject.class); | 10 | + return analysisPayload(new String(payload)); |
| 11 | + } | ||
| 12 | + | ||
| 13 | + public AnalysisResult analysisPayload(String payload) | ||
| 14 | + { | ||
| 15 | + JsonObject jsonObject = GsonConstructor.get().fromJson(payload, JsonObject.class); | ||
| 11 | return new AnalysisResult(false,true,jsonObject); | 16 | return new AnalysisResult(false,true,jsonObject); |
| 12 | } | 17 | } |
| 13 | } | 18 | } |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.config; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.device.domain.IotProductPayloadModelNumber; | ||
| 4 | + | ||
| 5 | +import java.util.HashMap; | ||
| 6 | +import java.util.Map; | ||
| 7 | + | ||
| 8 | +public class ProductPayloadModelNumberCach { | ||
| 9 | + private static Map<Integer, Map<String, IotProductPayloadModelNumber>> map = new HashMap<>(); | ||
| 10 | + | ||
| 11 | + public static void putProductPayloadModelNumber(Integer product_id,String model,IotProductPayloadModelNumber iotProductPayloadModelNumber) | ||
| 12 | + { | ||
| 13 | + Map<String, IotProductPayloadModelNumber> productPayloadModelNumber = map.get(product_id); | ||
| 14 | + if(null == productPayloadModelNumber) | ||
| 15 | + { | ||
| 16 | + productPayloadModelNumber = new HashMap<>(); | ||
| 17 | + map.put(product_id,productPayloadModelNumber); | ||
| 18 | + } | ||
| 19 | + productPayloadModelNumber.put(model,iotProductPayloadModelNumber); | ||
| 20 | + } | ||
| 21 | + public static IotProductPayloadModelNumber getNumber(Integer product_id,String model) | ||
| 22 | + { | ||
| 23 | + Map<String, IotProductPayloadModelNumber> productPayloadModelNumber = map.get(product_id); | ||
| 24 | + if(null == productPayloadModelNumber) | ||
| 25 | + { | ||
| 26 | + return null; | ||
| 27 | + } | ||
| 28 | + return productPayloadModelNumber.get(model); | ||
| 29 | + } | ||
| 30 | + public static void cleanProduct(Integer product_id) | ||
| 31 | + { | ||
| 32 | + map.remove(product_id); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public static void cleanProductPayloadModelNumber(Integer product_id,String model) | ||
| 36 | + { | ||
| 37 | + Map<String, IotProductPayloadModelNumber> productPayloadModelNumber = map.get(product_id); | ||
| 38 | + if(null != productPayloadModelNumber) | ||
| 39 | + { | ||
| 40 | + productPayloadModelNumber.remove(model); | ||
| 41 | + } | ||
| 42 | + } | ||
| 43 | +} |
| @@ -62,6 +62,9 @@ public class SysCommandListenService implements RocketMQReplyListener<MessageExt | @@ -62,6 +62,9 @@ public class SysCommandListenService implements RocketMQReplyListener<MessageExt | ||
| 62 | return new Message(MessageCode.DEFAULT_FAIL_CODE,"订阅未成功请检查原因"); | 62 | return new Message(MessageCode.DEFAULT_FAIL_CODE,"订阅未成功请检查原因"); |
| 63 | } | 63 | } |
| 64 | return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"订阅成功", Arrays.toString(okProduct.toArray())); | 64 | return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"订阅成功", Arrays.toString(okProduct.toArray())); |
| 65 | + case upProductPayloadModelNumber: | ||
| 66 | + iotThingsModelService.upProductPayloadModelNumberCach(deviceCommand.getData().get("product_ids").getAsInt()); | ||
| 67 | + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"更新产品模型编号关系成功"); | ||
| 65 | default: | 68 | default: |
| 66 | return new Message(MessageCode.DEFAULT_FAIL_CODE,"指令类型不存在,请联系管理员"); | 69 | return new Message(MessageCode.DEFAULT_FAIL_CODE,"指令类型不存在,请联系管理员"); |
| 67 | } | 70 | } |
| @@ -38,6 +38,12 @@ public class AnalysisDto { | @@ -38,6 +38,12 @@ public class AnalysisDto { | ||
| 38 | parserDeviceInfoDto.setConfig(things_model_config); | 38 | parserDeviceInfoDto.setConfig(things_model_config); |
| 39 | parserDeviceInfoDto.setId(id); | 39 | parserDeviceInfoDto.setId(id); |
| 40 | parserDeviceInfoDto.setUpdateTime(time); | 40 | parserDeviceInfoDto.setUpdateTime(time); |
| 41 | + if(things_model_value.has("%sysdeviceinfoname%")) | ||
| 42 | + { | ||
| 43 | + parserDeviceInfoDto.setDeviceInfoName(things_model_value.get("%sysdeviceinfoname%").getAsJsonObject().get("value").getAsString()); | ||
| 44 | + things_model_value.remove("%sysdeviceinfoname%"); | ||
| 45 | + } | ||
| 46 | + | ||
| 41 | return parserDeviceInfoDto; | 47 | return parserDeviceInfoDto; |
| 42 | } | 48 | } |
| 43 | } | 49 | } |
| @@ -59,7 +59,10 @@ public abstract class BaseCallback<T> { | @@ -59,7 +59,10 @@ public abstract class BaseCallback<T> { | ||
| 59 | 59 | ||
| 60 | //解析和清洗body | 60 | //解析和清洗body |
| 61 | ProtocolPurificationModel protocolPurificationModel = protocolParserAndPurificationFactory.analysisAndPurification( oldparserDeviceHostDto.getIotProduct(),s,payload); | 61 | ProtocolPurificationModel protocolPurificationModel = protocolParserAndPurificationFactory.analysisAndPurification( oldparserDeviceHostDto.getIotProduct(),s,payload); |
| 62 | - | 62 | + if (null == protocolPurificationModel) |
| 63 | + { | ||
| 64 | + return null; | ||
| 65 | + } | ||
| 63 | //缓存更新 | 66 | //缓存更新 |
| 64 | int i = deviceCashUpService.upProtocolPurificationModel(protocolPurificationModel,oldparserDeviceHostDto); | 67 | int i = deviceCashUpService.upProtocolPurificationModel(protocolPurificationModel,oldparserDeviceHostDto); |
| 65 | 68 |
| 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.StringUtils; | ||
| 4 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; | 5 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; |
| 6 | +import com.zhonglai.luhui.device.domain.IotProductPayloadModelNumber; | ||
| 5 | import com.zhonglai.luhui.device.domain.IotProductTranslate; | 7 | import com.zhonglai.luhui.device.domain.IotProductTranslate; |
| 6 | import com.zhonglai.luhui.device.domain.IotThingsModel; | 8 | import com.zhonglai.luhui.device.domain.IotThingsModel; |
| 9 | +import com.zhonglai.luhui.device.protocol.factory.config.ProductPayloadModelNumberCach; | ||
| 7 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 8 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 9 | 12 | ||
| @@ -41,6 +44,8 @@ public class IotThingsModelService { | @@ -41,6 +44,8 @@ public class IotThingsModelService { | ||
| 41 | map.put(iotProductTranslate.getModel_identifier(),iotProductTranslate.getTranslate_identifier()); | 44 | map.put(iotProductTranslate.getModel_identifier(),iotProductTranslate.getTranslate_identifier()); |
| 42 | } | 45 | } |
| 43 | } | 46 | } |
| 47 | + | ||
| 48 | + upProductPayloadModelNumberCach(null); | ||
| 44 | } | 49 | } |
| 45 | 50 | ||
| 46 | 51 | ||
| @@ -106,4 +111,23 @@ public class IotThingsModelService { | @@ -106,4 +111,23 @@ public class IotThingsModelService { | ||
| 106 | iotProductTranslateMap.put(product_id,map); | 111 | iotProductTranslateMap.put(product_id,map); |
| 107 | } | 112 | } |
| 108 | } | 113 | } |
| 114 | + | ||
| 115 | + public void upProductPayloadModelNumberCach(Integer product_id) | ||
| 116 | + { | ||
| 117 | + List<IotProductPayloadModelNumber> list = persistenceDBService.getProductPayloadModelNumberList(product_id); | ||
| 118 | + if (null != list && list.size() != 0) | ||
| 119 | + { | ||
| 120 | + for (IotProductPayloadModelNumber iotProductPayloadModelNumber:list) | ||
| 121 | + { | ||
| 122 | + if (StringUtils.isNotEmpty(iotProductPayloadModelNumber.getModels())) | ||
| 123 | + { | ||
| 124 | + String[] models = iotProductPayloadModelNumber.getModels().split(","); | ||
| 125 | + for (String model:models) | ||
| 126 | + { | ||
| 127 | + ProductPayloadModelNumberCach.putProductPayloadModelNumber(iotProductPayloadModelNumber.getProduct_id(),model,iotProductPayloadModelNumber); | ||
| 128 | + } | ||
| 129 | + } | ||
| 130 | + } | ||
| 131 | + } | ||
| 132 | + } | ||
| 109 | } | 133 | } |
| @@ -192,6 +192,11 @@ public class PersistenceDBService { | @@ -192,6 +192,11 @@ public class PersistenceDBService { | ||
| 192 | return defaultDbService.getIotProductTranslateList(product_id); | 192 | return defaultDbService.getIotProductTranslateList(product_id); |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | + public List<IotProductPayloadModelNumber> getProductPayloadModelNumberList(Integer product_id) | ||
| 196 | + { | ||
| 197 | + return defaultDbService.getProductPayloadModelNumberList(product_id); | ||
| 198 | + } | ||
| 199 | + | ||
| 195 | /** | 200 | /** |
| 196 | * 获取默认数据库的操作服务 | 201 | * 获取默认数据库的操作服务 |
| 197 | * @return | 202 | * @return |
| @@ -222,7 +227,7 @@ public class PersistenceDBService { | @@ -222,7 +227,7 @@ public class PersistenceDBService { | ||
| 222 | public ParserDeviceHostDto getOldParserDeviceHostDto(String imei) | 227 | public ParserDeviceHostDto getOldParserDeviceHostDto(String imei) |
| 223 | { | 228 | { |
| 224 | ParserDeviceHostDto oldParserDeviceHostDto = DeviceCach.getDeviceHost(imei); | 229 | ParserDeviceHostDto oldParserDeviceHostDto = DeviceCach.getDeviceHost(imei); |
| 225 | - if(null == oldParserDeviceHostDto) | 230 | + if(null == oldParserDeviceHostDto) //缓存中不存在 |
| 226 | { | 231 | { |
| 227 | IotDevice iotDevice = getDeviceHostById(imei); | 232 | IotDevice iotDevice = getDeviceHostById(imei); |
| 228 | if(null == iotDevice) | 233 | if(null == iotDevice) |
| @@ -249,6 +254,9 @@ public class PersistenceDBService { | @@ -249,6 +254,9 @@ public class PersistenceDBService { | ||
| 249 | oldParserDeviceHostDto.setDevice_life(iotDevice.getDevice_life()); | 254 | oldParserDeviceHostDto.setDevice_life(iotDevice.getDevice_life()); |
| 250 | oldParserDeviceHostDto.setDevice_type(iotDevice.getMqtt_username()); | 255 | oldParserDeviceHostDto.setDevice_type(iotDevice.getMqtt_username()); |
| 251 | oldParserDeviceHostDto.setIotProduct(iotProduct); | 256 | oldParserDeviceHostDto.setIotProduct(iotProduct); |
| 257 | + | ||
| 258 | + //加入缓存 | ||
| 259 | + DeviceCach.putDeviceHost(oldParserDeviceHostDto,iotDevice.getDevice_life()); | ||
| 252 | } | 260 | } |
| 253 | return oldParserDeviceHostDto; | 261 | return oldParserDeviceHostDto; |
| 254 | } | 262 | } |
| @@ -101,11 +101,12 @@ public class DefaultDbService { | @@ -101,11 +101,12 @@ public class DefaultDbService { | ||
| 101 | iotTerminal.setMqtt_username(oldparserDeviceHostDto.getDevice_type()); | 101 | iotTerminal.setMqtt_username(oldparserDeviceHostDto.getDevice_type()); |
| 102 | iotTerminal.setCreate_time(oldparserDeviceHostDto.getUpdateTime()); | 102 | iotTerminal.setCreate_time(oldparserDeviceHostDto.getUpdateTime()); |
| 103 | iotTerminal.setProduct_id(oldparserDeviceHostDto.getIotProduct().getId()); | 103 | iotTerminal.setProduct_id(oldparserDeviceHostDto.getIotProduct().getId()); |
| 104 | + iotTerminal.setSensor_number(id.substring(-1==id.indexOf("_")?0:id.indexOf("_")+1)); | ||
| 104 | if(StringUtils.isNotEmpty(name)) | 105 | if(StringUtils.isNotEmpty(name)) |
| 105 | { | 106 | { |
| 106 | iotTerminal.setName(name); | 107 | iotTerminal.setName(name); |
| 107 | }else { | 108 | }else { |
| 108 | - iotTerminal.setName(oldparserDeviceHostDto.getIotProduct().getProduct_name()+id); | 109 | + iotTerminal.setName(oldparserDeviceHostDto.getIotProduct().getProduct_name()+getLastSixChars(iotTerminal.getDevice_id())+"设备的第"+iotTerminal.getSensor_number()+"号终端"); |
| 109 | } | 110 | } |
| 110 | baseDao.insert(iotTerminal); | 111 | baseDao.insert(iotTerminal); |
| 111 | } | 112 | } |
| @@ -124,6 +125,18 @@ public class DefaultDbService { | @@ -124,6 +125,18 @@ public class DefaultDbService { | ||
| 124 | return oldparserDeviceInfoDto; | 125 | return oldparserDeviceInfoDto; |
| 125 | } | 126 | } |
| 126 | 127 | ||
| 128 | + /** | ||
| 129 | + * 获取字符串的最后六位字符,如果字符串长度不足六位,则返回整个字符串。 | ||
| 130 | + * | ||
| 131 | + * @param input 输入的字符串 | ||
| 132 | + * @return 最后的六位字符或整个字符串 | ||
| 133 | + */ | ||
| 134 | + private static String getLastSixChars(String input) { | ||
| 135 | + int length = input.length(); | ||
| 136 | + // 如果字符串长度小于6,从头开始截取 | ||
| 137 | + int startIndex = length >= 6 ? length - 6 : 0; | ||
| 138 | + return input.substring(startIndex); | ||
| 139 | + } | ||
| 127 | public int updateParserDeviceHostDto(ParserDeviceHostDto parserDeviceHostDto) | 140 | public int updateParserDeviceHostDto(ParserDeviceHostDto parserDeviceHostDto) |
| 128 | { | 141 | { |
| 129 | IotDevice iotDevice = new IotDevice(); | 142 | IotDevice iotDevice = new IotDevice(); |
| @@ -257,4 +270,15 @@ public class DefaultDbService { | @@ -257,4 +270,15 @@ public class DefaultDbService { | ||
| 257 | { | 270 | { |
| 258 | return baseDao.findBysql("SELECT GROUP_CONCAT(id) ids FROM `iot_product` WHERE subscribe_service_ip = ? GROUP BY subscribe_service_ip",String.class,ip); | 271 | return baseDao.findBysql("SELECT GROUP_CONCAT(id) ids FROM `iot_product` WHERE subscribe_service_ip = ? GROUP BY subscribe_service_ip",String.class,ip); |
| 259 | } | 272 | } |
| 273 | + | ||
| 274 | + | ||
| 275 | + public List<IotProductPayloadModelNumber> getProductPayloadModelNumberList(Integer product_id) | ||
| 276 | + { | ||
| 277 | + if (null == product_id) | ||
| 278 | + { | ||
| 279 | + return baseDao.findBysql("SELECT * FROM `iot_product_payload_model_number`", IotProductPayloadModelNumber.class); | ||
| 280 | + } | ||
| 281 | + return baseDao.findBysql("SELECT * FROM `iot_product_payload_model_number` WHERE product_id=?", IotProductPayloadModelNumber.class,product_id); | ||
| 282 | + } | ||
| 283 | + | ||
| 260 | } | 284 | } |
| @@ -40,6 +40,7 @@ public class MqttServiceListenApplication { | @@ -40,6 +40,7 @@ public class MqttServiceListenApplication { | ||
| 40 | if(null != RunInIDEA) | 40 | if(null != RunInIDEA) |
| 41 | { | 41 | { |
| 42 | System.setProperty("RunInIDEA",RunInIDEA); | 42 | System.setProperty("RunInIDEA",RunInIDEA); |
| 43 | + System.setProperty("rocketmq.operationToken","localhost"); | ||
| 43 | } | 44 | } |
| 44 | 45 | ||
| 45 | SpringApplicationBuilder builder = new SpringApplicationBuilder(MqttServiceListenApplication.class); | 46 | SpringApplicationBuilder builder = new SpringApplicationBuilder(MqttServiceListenApplication.class); |
| @@ -35,6 +35,6 @@ mqtt: | @@ -35,6 +35,6 @@ mqtt: | ||
| 35 | rocketmq: | 35 | rocketmq: |
| 36 | #nameservice服务器地址(多个以英文逗号隔开) | 36 | #nameservice服务器地址(多个以英文逗号隔开) |
| 37 | name-server: 47.115.144.179:9876 | 37 | name-server: 47.115.144.179:9876 |
| 38 | - consumerGroup: lh-mqtt-service-listen | 38 | + consumerGroup: ${random.uuid} |
| 39 | topic: deviceCommandListen | 39 | topic: deviceCommandListen |
| 40 | - operationToken: ${random.uuid} | ||
| 40 | + operationToken: 120.79.198.245lh-mqtt-service-listen |
-
请 注册 或 登录 后发表评论