|
@@ -56,15 +56,15 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
private MqttOutConfig.MqttGateway mqttGateway;
|
|
|
|
|
|
@Override
|
|
|
- public Map<String,Object> deviceControl(String productCode, String deviceId, String commandStr,Integer tenantId, Long userId, String userName){
|
|
|
+ public Map<String,Object> deviceControl(String productCode, String deviceUuid, String commandStr,Integer tenantId, Long userId, String userName){
|
|
|
Map<String,Object> rec_map = new HashMap<>();
|
|
|
|
|
|
|
|
|
//存储下发设备控制命令到数据库表中
|
|
|
DmpDeviceCommand command = new DmpDeviceCommand();
|
|
|
command.setProductCode(productCode);
|
|
|
- if(StringUtils.isNotBlank(deviceId)){
|
|
|
- command.setDeviceId(deviceId);
|
|
|
+ if(StringUtils.isNotBlank(deviceUuid)){
|
|
|
+ command.setDeviceUuid(deviceUuid);
|
|
|
}
|
|
|
|
|
|
command.setCommandContent(commandStr);
|
|
@@ -86,7 +86,7 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
dmpDeviceCommandService.updateById(command);
|
|
|
//推送下发设备控制mqtt
|
|
|
if(StringUtils.isNotBlank(commandStr)){
|
|
|
- String topic = "/"+productCode+"/"+deviceId+"/control";
|
|
|
+ String topic = "/"+deviceUuid+"/control";
|
|
|
mqttGateway.sendToMqtt(topic,dataJson.toJSONString());
|
|
|
}
|
|
|
|
|
@@ -106,6 +106,8 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
if((endTimeStamp - startTimeStamp) >= 3){ //请求超时3秒,返回失败
|
|
|
rec_map.put("code",-1);
|
|
|
rec_map.put("message","下发命令失败");
|
|
|
+
|
|
|
+ dmpDeviceCommandService.lambdaUpdate().set(DmpDeviceCommand::getCommandStatus,2).eq(DmpDeviceCommand::getId,commandId).update();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -137,7 +139,7 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
|
|
|
String productCode = writeVO.getProductCode();
|
|
|
String deviceUUId = writeVO.getDeviceUUId();
|
|
|
- String deviceId = tags.get("deviceId");
|
|
|
+ String deviceId = tags.get("device_id");
|
|
|
|
|
|
//判断上报数据对应产品是否注册,如未注册则为非法
|
|
|
Map<String,ProductMapVO> productMapList = dmpProductService.getProductMap();
|
|
@@ -158,7 +160,7 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
}
|
|
|
|
|
|
//判断上报数据设备是否已注册(要判断注册过的设备是不是属于本产品的),未注册自动注册
|
|
|
- Map<String,DeviceMapVO> deviceMapList = dmpProductService.getDeviceMap();
|
|
|
+ Map<String,DeviceMapVO> deviceMapList = dmpProductService.getDeviceMap(productCode);
|
|
|
if(!deviceMapList.containsKey(deviceId)){
|
|
|
DmpDevice dmpDeviceInfo = new DmpDevice();
|
|
|
ProductMapVO productMapVO = productMapList.get(productCode);
|
|
@@ -173,6 +175,7 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
dmpDeviceInfo.setServiceStatus(1);
|
|
|
dmpDeviceInfo.setDeviceUuid(UUIDUtils.uuid());
|
|
|
dmpDeviceService.save(dmpDeviceInfo);
|
|
|
+ dmpProductService.deleteDeviceCache(productCode);
|
|
|
|
|
|
deviceUUId = dmpDeviceInfo.getDeviceUuid();
|
|
|
|
|
@@ -184,7 +187,7 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
dmpDeviceStatus.setProductCode(dmpDeviceInfo.getProductCode());
|
|
|
dmpDeviceStatusService.save(dmpDeviceStatus);
|
|
|
|
|
|
- dmpProductService.deleteDeviceCache();
|
|
|
+ deviceMapList = dmpProductService.getDeviceMap(productCode);
|
|
|
}else if(deviceMapList.containsKey(deviceId)){
|
|
|
LambdaQueryWrapper<DmpDevice> queryWrapper = Wrappers.lambdaQuery();
|
|
|
queryWrapper.eq(DmpDevice::getDeleteFlag,0)
|
|
@@ -205,6 +208,7 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
dmpDeviceInfo.setServiceStatus(1);
|
|
|
dmpDeviceInfo.setDeviceUuid(UUIDUtils.uuid());
|
|
|
dmpDeviceService.save(dmpDeviceInfo);
|
|
|
+ dmpProductService.deleteDeviceCache(productCode);
|
|
|
|
|
|
deviceUUId = dmpDeviceInfo.getDeviceUuid();
|
|
|
|
|
@@ -216,7 +220,7 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
dmpDeviceStatus.setProductCode(dmpDeviceInfo.getProductCode());
|
|
|
dmpDeviceStatusService.save(dmpDeviceStatus);
|
|
|
|
|
|
- dmpProductService.deleteDeviceCache();
|
|
|
+ deviceMapList = dmpProductService.getDeviceMap(productCode);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -226,6 +230,7 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
String deviceId1 = map.getKey();
|
|
|
if((productCode.equals(productCode1)) && (deviceId.equals(deviceId1))){
|
|
|
deviceUUId = map.getValue().getDeviceUuid();
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -242,4 +247,20 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
|
return rec_map;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String,Object> mqttDeviceData(MqttDeviceDataVO mqttDeviceDataVO){
|
|
|
+ Map<String,Object> rec_map = new HashMap<>();
|
|
|
+
|
|
|
+ String topic = mqttDeviceDataVO.getTopic();
|
|
|
+ String payload = mqttDeviceDataVO.getDeviceData();
|
|
|
+
|
|
|
+ JSONObject deviceDataJson = JSONObject.parseObject(payload);
|
|
|
+
|
|
|
+ mqttGateway.sendToMqtt(topic, deviceDataJson.toJSONString());
|
|
|
+
|
|
|
+ rec_map.put("code",200);
|
|
|
+ rec_map.put("message","发送成功");
|
|
|
+
|
|
|
+ return rec_map;
|
|
|
+ }
|
|
|
}
|