正在显示
6 个修改的文件
包含
87 行增加
和
4 行删除
| 1 | package com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.specs; | 1 | package com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.specs; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.JSON; | ||
| 4 | +import com.alibaba.fastjson.JSONObject; | ||
| 5 | +import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelBase; | ||
| 6 | +import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; | ||
| 3 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; | 7 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; |
| 8 | +import com.zhonglai.luhui.device.domain.IotThingsModel; | ||
| 4 | import lombok.Data; | 9 | import lombok.Data; |
| 10 | +import org.apache.commons.lang3.EnumUtils; | ||
| 5 | 11 | ||
| 6 | import java.math.BigDecimal; | 12 | import java.math.BigDecimal; |
| 7 | import java.math.RoundingMode; | 13 | import java.math.RoundingMode; |
| @@ -79,4 +85,63 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer> | @@ -79,4 +85,63 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer> | ||
| 79 | } | 85 | } |
| 80 | return false; | 86 | return false; |
| 81 | } | 87 | } |
| 88 | + | ||
| 89 | + public static void main(String[] args) { | ||
| 90 | + IotThingsModel thingsModel = JSONObject.parseObject("{\"@type\":\"com.zhonglai.luhui.device.domain.IotThingsModel\",\"ascription\":\"1\",\"create_by\":\"admin\",\"data_type\":\"integer\",\"identifier\":\"turbidity\",\"is_config\":0,\"is_monitor\":0,\"is_save_log\":1,\"is_top\":0,\"model_id\":395,\"model_name\":\"浊度\",\"mqtt_username\":\"6_WP\",\"product_id\":9,\"specs\":\"{\\\"acy\\\":10,\\\"max\\\":999999,\\\"min\\\":0,\\\"step\\\":0.1,\\\"unit\\\":\\\"NTU\\\"}\",\"type\":1}\n", IotThingsModel.class); | ||
| 91 | + String data_type = thingsModel.getData_type().toUpperCase(); | ||
| 92 | + if (!EnumUtils.isValidEnum(ThingsModelDataTypeEnum.class, data_type)) { | ||
| 93 | + data_type = ThingsModelDataTypeEnum.STRING.name(); | ||
| 94 | + } | ||
| 95 | + Class<ThingsModelBase> aClass = Enum.valueOf(ThingsModelDataTypeEnum.class, data_type).getaClass(); | ||
| 96 | + ThingsModelBase thingsModelBase = JSON.parseObject(thingsModel.getSpecs(), aClass); | ||
| 97 | + thingsModelBase.conversionThingsModel(thingsModel); | ||
| 98 | + | ||
| 99 | + JSONObject jsData = JSONObject.parseObject("{\n" + | ||
| 100 | + " \"id\": 1714026179,\n" + | ||
| 101 | + " \"0\": {\n" + | ||
| 102 | + " \"rssi\": 18,\n" + | ||
| 103 | + " \"at\": 369,\n" + | ||
| 104 | + " \"bar\": 107987\n" + | ||
| 105 | + " },\n" + | ||
| 106 | + " \"10_1\": {\n" + | ||
| 107 | + " \"type\": 1,\n" + | ||
| 108 | + " \"mode\": 0,\n" + | ||
| 109 | + " \"state\": 0,\n" + | ||
| 110 | + " \"map\": \"1_1\"\n" + | ||
| 111 | + " },\n" + | ||
| 112 | + " \"10_2\": {\n" + | ||
| 113 | + " \"type\": 1,\n" + | ||
| 114 | + " \"mode\": 0,\n" + | ||
| 115 | + " \"state\": 0,\n" + | ||
| 116 | + " \"map\": \"1_2\"\n" + | ||
| 117 | + " },\n" + | ||
| 118 | + " \"10_3\": {\n" + | ||
| 119 | + " \"type\": 1,\n" + | ||
| 120 | + " \"mode\": 0,\n" + | ||
| 121 | + " \"state\": 0,\n" + | ||
| 122 | + " \"map\": \"1_3\"\n" + | ||
| 123 | + " },\n" + | ||
| 124 | + " \"10_4\": {\n" + | ||
| 125 | + " \"type\": 1,\n" + | ||
| 126 | + " \"mode\": 0,\n" + | ||
| 127 | + " \"state\": 0,\n" + | ||
| 128 | + " \"map\": \"1_4\"\n" + | ||
| 129 | + " },\n" + | ||
| 130 | + " \"1_3\": {\n" + | ||
| 131 | + " \"alarm\": 0,\n" + | ||
| 132 | + " \"turbidity\": 69,\n" + | ||
| 133 | + " \"wt\": 290\n" + | ||
| 134 | + " }\n" + | ||
| 135 | + "}", JSONObject.class); | ||
| 136 | + thingsModelBase.addValue(jsData.get("turbidity")); | ||
| 137 | + | ||
| 138 | + if (!thingsModelBase.checkValue()) { | ||
| 139 | + System.out.println("校验通过"); | ||
| 140 | + ThingsModelItemBase thingsModelItemBase = (ThingsModelItemBase) thingsModelBase; | ||
| 141 | + if(1==thingsModelItemBase.getIs_save_log() ) | ||
| 142 | + { | ||
| 143 | + System.out.println("要记录日志"); | ||
| 144 | + } | ||
| 145 | + } | ||
| 146 | + } | ||
| 82 | } | 147 | } |
| @@ -56,8 +56,9 @@ public class BusinessDataUpdateService { | @@ -56,8 +56,9 @@ public class BusinessDataUpdateService { | ||
| 56 | */ | 56 | */ |
| 57 | public void updataDta(Type type, Topic topic, ServerDto serverDto, String operationType, boolean isLog) | 57 | public void updataDta(Type type, Topic topic, ServerDto serverDto, String operationType, boolean isLog) |
| 58 | { | 58 | { |
| 59 | + logger.info("{} 开始更新数据",topic.getClientid()); | ||
| 59 | IotDevice olddevice = cacheService.getIotDevice(topic.getClientid()); | 60 | IotDevice olddevice = cacheService.getIotDevice(topic.getClientid()); |
| 60 | - | 61 | + logger.info("{} 老数据获取成",topic.getClientid()); |
| 61 | JSONObject data = new JSONObject(); | 62 | JSONObject data = new JSONObject(); |
| 62 | switch (type) | 63 | switch (type) |
| 63 | { | 64 | { |
| @@ -69,9 +70,12 @@ public class BusinessDataUpdateService { | @@ -69,9 +70,12 @@ public class BusinessDataUpdateService { | ||
| 69 | break; | 70 | break; |
| 70 | } | 71 | } |
| 71 | 72 | ||
| 73 | + logger.info("{} 开始解析终端数据",topic.getClientid()); | ||
| 72 | for(String key:data.keySet()) | 74 | for(String key:data.keySet()) |
| 73 | { | 75 | { |
| 74 | Object o = data.get(key); | 76 | Object o = data.get(key); |
| 77 | + logger.info("开始解析{}终端的数据,数据类型{}",key,o.getClass()); | ||
| 78 | + | ||
| 75 | if(o instanceof JSONObject) | 79 | if(o instanceof JSONObject) |
| 76 | { | 80 | { |
| 77 | JSONObject jsData = data.getJSONObject(key); | 81 | JSONObject jsData = data.getJSONObject(key); |
| @@ -93,6 +97,7 @@ public class BusinessDataUpdateService { | @@ -93,6 +97,7 @@ public class BusinessDataUpdateService { | ||
| 93 | iotDevice.setName(olddevice.getName()); | 97 | iotDevice.setName(olddevice.getName()); |
| 94 | serverDto.setIotDevice(iotDevice); | 98 | serverDto.setIotDevice(iotDevice); |
| 95 | }else{ //终端 | 99 | }else{ //终端 |
| 100 | + logger.info("{} 解析终端 {} 的数据",key,jsData.toJSONString()); | ||
| 96 | IotTerminal iotTerminal = translateTerminal(type,key,olddevice,jsData,serverDto,operationType,isLog); | 101 | IotTerminal iotTerminal = translateTerminal(type,key,olddevice,jsData,serverDto,operationType,isLog); |
| 97 | iotTerminal.setData_update_time(DateUtils.getNowTimeMilly()); | 102 | iotTerminal.setData_update_time(DateUtils.getNowTimeMilly()); |
| 98 | if(null== iotTerminal.getOnline() || 1 == iotTerminal.getOnline() || 4==iotTerminal.getOnline()) | 103 | if(null== iotTerminal.getOnline() || 1 == iotTerminal.getOnline() || 4==iotTerminal.getOnline()) |
| @@ -175,7 +180,7 @@ public class BusinessDataUpdateService { | @@ -175,7 +180,7 @@ public class BusinessDataUpdateService { | ||
| 175 | 180 | ||
| 176 | if(null == saveDataDto) | 181 | if(null == saveDataDto) |
| 177 | { | 182 | { |
| 178 | - logger.info("无法解析到入库数据"); | 183 | + logger.info("{} 无法解析到入库数据",id); |
| 179 | return terminal; | 184 | return terminal; |
| 180 | } | 185 | } |
| 181 | //记录操作日志 | 186 | //记录操作日志 |
| @@ -46,7 +46,7 @@ public class CacheServiceImpl implements CacheService { | @@ -46,7 +46,7 @@ public class CacheServiceImpl implements CacheService { | ||
| 46 | iotDevice.setStatus(3); | 46 | iotDevice.setStatus(3); |
| 47 | } | 47 | } |
| 48 | setIotDeviceToRedis(iotDevice); | 48 | setIotDeviceToRedis(iotDevice); |
| 49 | - log.info("缓存更新 {} ",topic); | 49 | + log.info("缓存更新 {} ",iotDevice); |
| 50 | 50 | ||
| 51 | List<IotTerminal> list = serverDto.getIotTerminalList(); | 51 | List<IotTerminal> list = serverDto.getIotTerminalList(); |
| 52 | if(null != list && list.size() != 0 ) | 52 | if(null != list && list.size() != 0 ) |
| @@ -56,7 +56,7 @@ public class CacheServiceImpl implements CacheService { | @@ -56,7 +56,7 @@ public class CacheServiceImpl implements CacheService { | ||
| 56 | setIotTerminalToRedis(iotTerminal); | 56 | setIotTerminalToRedis(iotTerminal); |
| 57 | } | 57 | } |
| 58 | } | 58 | } |
| 59 | - log.info("缓存更新 {} ",topic); | 59 | + log.info("缓存更新 {} ",list); |
| 60 | return true; | 60 | return true; |
| 61 | } | 61 | } |
| 62 | 62 |
| @@ -101,6 +101,7 @@ public class DataModeAnalysisService { | @@ -101,6 +101,7 @@ public class DataModeAnalysisService { | ||
| 101 | } | 101 | } |
| 102 | ThingsModelItemBase thingsModelItemBase = (ThingsModelItemBase) thingsModelBase; | 102 | ThingsModelItemBase thingsModelItemBase = (ThingsModelItemBase) thingsModelBase; |
| 103 | //记录数据日志 | 103 | //记录数据日志 |
| 104 | + log.info("设备{}的数据{}记录日志,【条件{},{}】",id,key,thingsModelItemBase.getIs_save_log(),null != serverDto.getDeviceSensorDataList()); | ||
| 104 | if(1==thingsModelItemBase.getIs_save_log() && null != serverDto.getDeviceSensorDataList()) | 105 | if(1==thingsModelItemBase.getIs_save_log() && null != serverDto.getDeviceSensorDataList()) |
| 105 | { | 106 | { |
| 106 | DeviceSensorData sensorData = new DeviceSensorData(); | 107 | DeviceSensorData sensorData = new DeviceSensorData(); |
| @@ -43,6 +43,7 @@ public class DataPersistenceServiceImpl extends DataPersistenceService { | @@ -43,6 +43,7 @@ public class DataPersistenceServiceImpl extends DataPersistenceService { | ||
| 43 | List<DeviceSensorData> dsdList = serverDto.getDeviceSensorDataList(); | 43 | List<DeviceSensorData> dsdList = serverDto.getDeviceSensorDataList(); |
| 44 | if(null != dsdList && dsdList.size() != 0) | 44 | if(null != dsdList && dsdList.size() != 0) |
| 45 | { | 45 | { |
| 46 | + log.info("{}曲线数据入库{}条",topic.getClientid(),dsdList.size()); | ||
| 46 | dviceLogService.saveDeviceSensorDataLog(dsdList); | 47 | dviceLogService.saveDeviceSensorDataLog(dsdList); |
| 47 | } | 48 | } |
| 48 | 49 | ||
| @@ -50,6 +51,7 @@ public class DataPersistenceServiceImpl extends DataPersistenceService { | @@ -50,6 +51,7 @@ public class DataPersistenceServiceImpl extends DataPersistenceService { | ||
| 50 | List<LogDeviceOperation> doList = serverDto.getLogDeviceOperationList(); | 51 | List<LogDeviceOperation> doList = serverDto.getLogDeviceOperationList(); |
| 51 | if(null != doList && doList.size() != 0) | 52 | if(null != doList && doList.size() != 0) |
| 52 | { | 53 | { |
| 54 | + log.info("{}日志入库{}条",topic.getClientid(),doList.size()); | ||
| 53 | dviceLogService.saveOperationLog(doList); | 55 | dviceLogService.saveOperationLog(doList); |
| 54 | } | 56 | } |
| 55 | 57 |
| 1 | package com.zhonglai.luhui.mqtt.controller; | 1 | package com.zhonglai.luhui.mqtt.controller; |
| 2 | 2 | ||
| 3 | +import com.zhonglai.luhui.device.analysis.dto.MessageCodeType; | ||
| 3 | import com.zhonglai.luhui.device.domain.IotDevice; | 4 | import com.zhonglai.luhui.device.domain.IotDevice; |
| 4 | import com.zhonglai.luhui.device.domain.IotTerminal; | 5 | import com.zhonglai.luhui.device.domain.IotTerminal; |
| 5 | import com.zhonglai.luhui.device.domain.IotThingsModel; | 6 | import com.zhonglai.luhui.device.domain.IotThingsModel; |
| @@ -98,4 +99,13 @@ public class DeviceController { | @@ -98,4 +99,13 @@ public class DeviceController { | ||
| 98 | public Message updateIotTerminal(@RequestBody IotTerminal iotTerminal) { | 99 | public Message updateIotTerminal(@RequestBody IotTerminal iotTerminal) { |
| 99 | return deviceService.updateIotTerminal(iotTerminal); | 100 | return deviceService.updateIotTerminal(iotTerminal); |
| 100 | } | 101 | } |
| 102 | + @ApiOperation("获取模型配置") | ||
| 103 | + @RequestMapping(value = "getIotThingsModel",method = RequestMethod.GET) | ||
| 104 | + public Message getIotThingsModel(String userName,String key) { | ||
| 105 | + IotThingsModel thingsModel = terminalDataThingsModeService.getIotThingsModel(userName,key); | ||
| 106 | + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,thingsModel); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + | ||
| 110 | + | ||
| 101 | } | 111 | } |
-
请 注册 或 登录 后发表评论