|
@@ -63,13 +63,12 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
public Map<String,Object> deviceControl(String productCode, String deviceUuid, String commandStr,Integer tenantId, Long userId, String userName){
|
|
|
Map<String,Object> rec_map = new HashMap<>();
|
|
|
|
|
|
+ JSONObject dataJson = JSONObject.parseObject(commandStr);
|
|
|
|
|
|
//存储下发设备控制命令到数据库表中
|
|
|
DmpDeviceCommand command = new DmpDeviceCommand();
|
|
|
command.setProductCode(productCode);
|
|
|
- if(StringUtils.isNotBlank(deviceUuid)){
|
|
|
- command.setDeviceUuid(deviceUuid);
|
|
|
- }
|
|
|
+ command.setDeviceUuid(dataJson.get("deviceUuid").toString());
|
|
|
|
|
|
command.setCommandContent(commandStr);
|
|
|
command.setCreatedTime(LocalDateTime.now());
|
|
@@ -83,14 +82,13 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
dmpDeviceCommandService.save(command);
|
|
|
int commandId = command.getId();
|
|
|
|
|
|
- JSONObject dataJson = JSONObject.parseObject(commandStr);
|
|
|
dataJson.put("id",commandId);
|
|
|
|
|
|
command.setCommandContent(dataJson.toJSONString());
|
|
|
dmpDeviceCommandService.updateById(command);
|
|
|
//推送下发设备控制mqtt
|
|
|
if(StringUtils.isNotBlank(commandStr)){
|
|
|
- String topic = "/"+deviceUuid+"/control";
|
|
|
+ String topic = "/usky/devices/"+deviceUuid+"/control";
|
|
|
mqttGateway.sendToMqtt(topic,dataJson.toJSONString());
|
|
|
}
|
|
|
|
|
@@ -144,6 +142,7 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
String productCode = writeVO.getProductCode();
|
|
|
String deviceUUId = writeVO.getDeviceUUId();
|
|
|
String deviceId = tags.get("device_id");
|
|
|
+ log.info("sendDeviceDataToMQ "+deviceId+" start222");
|
|
|
|
|
|
//判断上报数据对应产品是否注册,如未注册则为非法
|
|
|
Map<String,ProductMapVO> productMapList = dmpProductService.getProductMap();
|
|
@@ -177,7 +176,12 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
dmpDeviceInfo.setCreatedTime(LocalDateTime.now());
|
|
|
dmpDeviceInfo.setTenantId(productMapVO.getTenantId());
|
|
|
dmpDeviceInfo.setServiceStatus(1);
|
|
|
- dmpDeviceInfo.setDeviceUuid(UUIDUtils.uuid());
|
|
|
+ if(StringUtils.isBlank(deviceUUId)){
|
|
|
+ dmpDeviceInfo.setDeviceUuid(UUIDUtils.uuid());
|
|
|
+ }else{
|
|
|
+ dmpDeviceInfo.setDeviceUuid(deviceUUId);
|
|
|
+ }
|
|
|
+
|
|
|
dmpDeviceService.save(dmpDeviceInfo);
|
|
|
dmpProductService.deleteDeviceCache(productCode);
|
|
|
|
|
@@ -189,6 +193,7 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
dmpDeviceStatus.setDeviceStatus(2);
|
|
|
dmpDeviceStatus.setLastOfflineTime(LocalDateTime.now());
|
|
|
dmpDeviceStatus.setProductCode(dmpDeviceInfo.getProductCode());
|
|
|
+ dmpDeviceStatus.setDeviceUuid(deviceUUId);
|
|
|
dmpDeviceStatusService.save(dmpDeviceStatus);
|
|
|
|
|
|
deviceMapList = dmpProductService.getDeviceMap(productCode);
|
|
@@ -210,7 +215,11 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
dmpDeviceInfo.setCreatedTime(LocalDateTime.now());
|
|
|
dmpDeviceInfo.setTenantId(productMapVO.getTenantId());
|
|
|
dmpDeviceInfo.setServiceStatus(1);
|
|
|
- dmpDeviceInfo.setDeviceUuid(UUIDUtils.uuid());
|
|
|
+ if(StringUtils.isBlank(deviceUUId)){
|
|
|
+ dmpDeviceInfo.setDeviceUuid(UUIDUtils.uuid());
|
|
|
+ }else{
|
|
|
+ dmpDeviceInfo.setDeviceUuid(deviceUUId);
|
|
|
+ }
|
|
|
dmpDeviceService.save(dmpDeviceInfo);
|
|
|
dmpProductService.deleteDeviceCache(productCode);
|
|
|
|
|
@@ -222,6 +231,7 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
dmpDeviceStatus.setDeviceStatus(2);
|
|
|
dmpDeviceStatus.setLastOfflineTime(LocalDateTime.now());
|
|
|
dmpDeviceStatus.setProductCode(dmpDeviceInfo.getProductCode());
|
|
|
+ dmpDeviceStatus.setDeviceUuid(deviceUUId);
|
|
|
dmpDeviceStatusService.save(dmpDeviceStatus);
|
|
|
|
|
|
deviceMapList = dmpProductService.getDeviceMap(productCode);
|
|
@@ -242,8 +252,10 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
dataInfo.setProductCode(productCode);
|
|
|
dataInfo.setDeviceUUId(deviceUUId);
|
|
|
dataInfo.setTimestamp(writeVO.getTimestamp());
|
|
|
+ log.info("推送tsdb "+JSONArray.toJSON(dataInfo).toString()+" start");
|
|
|
|
|
|
myProducer.sendMessage("data-tsdb", JSONArray.toJSON(dataInfo).toString());
|
|
|
+ log.info("推送tsdb "+JSONArray.toJSON(dataInfo).toString()+" end");
|
|
|
}
|
|
|
|
|
|
rec_map.put("code",200);
|
|
@@ -257,8 +269,10 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
|
|
|
String topic = mqttDeviceDataVO.getTopic();
|
|
|
String[] topics = topic.split("/");
|
|
|
- String productCode1 = topics[1];
|
|
|
- String deviceId1 = topics[2];
|
|
|
+ //String productCode1 = topics[1];
|
|
|
+ //String deviceId1 = topics[2];
|
|
|
+ String deviceUuid = topics[3];
|
|
|
+
|
|
|
String payload = mqttDeviceDataVO.getDeviceData();
|
|
|
|
|
|
JSONObject deviceDataJson = JSONObject.parseObject(payload);
|
|
@@ -269,24 +283,33 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
Object metric = JSONObject.toJSONString(deviceDataJson.get("metrics"));
|
|
|
JSONObject metricJson = JSON.parseObject(metric.toString());
|
|
|
|
|
|
- if(!productCode1.equals(productCode2) || !deviceId1.equals(deviceId2)){
|
|
|
- throw new BusinessException("Topic和请求体中的产品编码、设备Id不一致,请修改");
|
|
|
- }
|
|
|
+// if(!productCode1.equals(productCode2) || !deviceId1.equals(deviceId2)){
|
|
|
+// throw new BusinessException("Topic和请求体中的产品编码、设备Id不一致,请修改");
|
|
|
+// }
|
|
|
|
|
|
LambdaQueryWrapper<DmpProduct> lambdaQuery = Wrappers.lambdaQuery();
|
|
|
- lambdaQuery.eq(DmpProduct::getProductCode,productCode1)
|
|
|
+ lambdaQuery.eq(DmpProduct::getProductCode,productCode2)
|
|
|
.eq(DmpProduct::getDeleteFlag,0);
|
|
|
List<DmpProduct> dmpProductList = dmpProductService.list(lambdaQuery);
|
|
|
if(dmpProductList.size() <= 0){
|
|
|
throw new BusinessException("产品编码不存在,请修改");
|
|
|
}
|
|
|
LambdaQueryWrapper<DmpDevice> lambdaQuery2 = Wrappers.lambdaQuery();
|
|
|
- lambdaQuery2.eq(DmpDevice::getDeviceId,deviceId1)
|
|
|
- .eq(DmpDevice::getProductCode,productCode1)
|
|
|
+ lambdaQuery2.eq(DmpDevice::getDeviceUuid,deviceUuid)
|
|
|
+ .eq(DmpDevice::getProductCode,productCode2)
|
|
|
.eq(DmpDevice::getServiceStatus,2)
|
|
|
.eq(DmpDevice::getDeleteFlag,0);
|
|
|
List<DmpDevice> dmpDeviceList = dmpDeviceService.list(lambdaQuery2);
|
|
|
if(dmpDeviceList.size() <= 0){
|
|
|
+ throw new BusinessException("topic主题中的设备Uuid不存在或在本产品下不存在,请修改");
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<DmpDevice> lambdaQuery3 = Wrappers.lambdaQuery();
|
|
|
+ lambdaQuery3.eq(DmpDevice::getDeviceId,deviceId2)
|
|
|
+ .eq(DmpDevice::getProductCode,productCode2)
|
|
|
+ .eq(DmpDevice::getServiceStatus,2)
|
|
|
+ .eq(DmpDevice::getDeleteFlag,0);
|
|
|
+ List<DmpDevice> dmpDeviceList1 = dmpDeviceService.list(lambdaQuery3);
|
|
|
+ if(dmpDeviceList1.size() <= 0){
|
|
|
throw new BusinessException("设备Id不存在或在本产品下不存在,请修改");
|
|
|
}
|
|
|
|
|
@@ -297,10 +320,10 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
}
|
|
|
}
|
|
|
int count1 = metricList.size();
|
|
|
- LambdaQueryWrapper<DmpProductAttribute> lambdaQuery3 = Wrappers.lambdaQuery();
|
|
|
- lambdaQuery3.eq(DmpProductAttribute::getProductId,dmpProductList.get(0).getId())
|
|
|
+ LambdaQueryWrapper<DmpProductAttribute> lambdaQuery4 = Wrappers.lambdaQuery();
|
|
|
+ lambdaQuery4.eq(DmpProductAttribute::getProductId,dmpProductList.get(0).getId())
|
|
|
.in(DmpProductAttribute::getAttributeCode,metricList);
|
|
|
- int count2 = dmpProductAttributeService.count(lambdaQuery3);
|
|
|
+ int count2 = dmpProductAttributeService.count(lambdaQuery4);
|
|
|
if(count1 > count2){
|
|
|
throw new BusinessException("设备属性编码不存在,请检查");
|
|
|
}
|