Merge pull request '优化' (#1) from wireless into master

Reviewed-on: system-Backend/iot#1
This commit is contained in:
xy
2024-09-20 13:19:39 +08:00

View File

@@ -17,6 +17,7 @@ import com.njcn.access.pojo.dto.CsModelDto;
import com.njcn.access.pojo.dto.ReqAndResDto; import com.njcn.access.pojo.dto.ReqAndResDto;
import com.njcn.access.pojo.param.DeviceStatusParam; import com.njcn.access.pojo.param.DeviceStatusParam;
import com.njcn.access.service.*; import com.njcn.access.service.*;
import com.njcn.access.utils.ChannelObjectUtil;
import com.njcn.access.utils.MqttUtil; import com.njcn.access.utils.MqttUtil;
import com.njcn.common.pojo.dto.DeviceLogDTO; import com.njcn.common.pojo.dto.DeviceLogDTO;
import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.enums.response.CommonResponseEnum;
@@ -77,6 +78,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
private final CsLinePOService csLinePOService; private final CsLinePOService csLinePOService;
private final CsDeviceUserPOService csDeviceUserPOService; private final CsDeviceUserPOService csDeviceUserPOService;
private final ICsDataSetService csDataSetService; private final ICsDataSetService csDataSetService;
private final ChannelObjectUtil channelObjectUtil;
@Override @Override
@Transactional(rollbackFor = {Exception.class}) @Transactional(rollbackFor = {Exception.class})
@@ -202,7 +204,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
csLedgerParam.setLevel(2); csLedgerParam.setLevel(2);
csLedgerParam.setSort(0); csLedgerParam.setSort(0);
csLedgerService.addLedgerTree(csLedgerParam); csLedgerService.addLedgerTree(csLedgerParam);
List<CsModelDto> modelId = objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + devAccessParam.getNDid())); List<CsModelDto> modelId = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + devAccessParam.getNDid()),CsModelDto.class);
//2.新增装置-模板关系、获取电能质量的逻辑设备id //2.新增装置-模板关系、获取电能质量的逻辑设备id
for (CsModelDto item : modelId) { for (CsModelDto item : modelId) {
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm(); CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
@@ -365,14 +367,14 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
logDto.setOperate("设备"+nDid+"注册"); logDto.setOperate("设备"+nDid+"注册");
logDto.setResult(1); logDto.setResult(1);
try { try {
Thread.sleep(1000); Thread.sleep(2000);
//获取版本 //获取版本
String version = csTopicService.getVersion(nDid); String version = csTopicService.getVersion(nDid);
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData(); CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
List<CsLinePO> csLinePoList = new ArrayList<>(); List<CsLinePO> csLinePoList = new ArrayList<>();
//1.根据模板获取监测点个数,插入监测点表 //1.根据模板获取监测点个数,插入监测点表
Thread.sleep(1000); Thread.sleep(2000);
List<CsModelDto> modelList = objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid)); List<CsModelDto> modelList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
if (CollUtil.isEmpty(modelList)){ if (CollUtil.isEmpty(modelList)){
try { try {
throwExceptionAndLog(AccessResponseEnum.MODEL_ERROR, logDto); throwExceptionAndLog(AccessResponseEnum.MODEL_ERROR, logDto);
@@ -513,7 +515,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid,new Gson().toJson(reqAndResParam),1,false); publisher.send("/Pfm/DevCmd/"+version+"/"+nDid,new Gson().toJson(reqAndResParam),1,false);
//接收到模板,判断模板是否存在,替换模板,发起接入 //接收到模板,判断模板是否存在,替换模板,发起接入
Thread.sleep(2000); Thread.sleep(2000);
List<CsModelDto> modelId = objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid)); List<CsModelDto> modelId = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
if (CollUtil.isNotEmpty(modelId)) { if (CollUtil.isNotEmpty(modelId)) {
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData(); CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
//重新录入装置和模板关系信息 //重新录入装置和模板关系信息
@@ -571,16 +573,4 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
logger.info("注册报文为:{}", new Gson().toJson(reqAndResParam)); logger.info("注册报文为:{}", new Gson().toJson(reqAndResParam));
publisher.send("/Pfm/DevReg/"+nDid, new Gson().toJson(reqAndResParam),1,false); publisher.send("/Pfm/DevReg/"+nDid, new Gson().toJson(reqAndResParam),1,false);
} }
public List<CsModelDto> objectToList(Object object) {
List<CsModelDto> urlList = new ArrayList<>();
if (object != null) {
if (object instanceof ArrayList<?>) {
for (Object o : (List<?>) object) {
urlList.add((CsModelDto) o);
}
}
}
return urlList;
}
} }