物解析功能

This commit is contained in:
2023-08-16 19:47:54 +08:00
parent 93fb513166
commit 4740f2b4d0
8 changed files with 108 additions and 47 deletions

View File

@@ -21,15 +21,17 @@ import com.njcn.access.service.ICsEquipmentDeliveryService;
import com.njcn.access.service.ICsLineModelService;
import com.njcn.access.service.ICsTopicService;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.api.DataSetFeignClient;
import com.njcn.csdevice.api.DevModelFeignClient;
import com.njcn.csdevice.pojo.po.CsDataSet;
import com.njcn.csdevice.pojo.po.CsDevModelPO;
import com.njcn.mq.message.AppAutoDataMessage;
import com.njcn.mq.template.AppAutoDataMessageTemplate;
import com.njcn.redis.pojo.enums.AppRedisKey;
import com.njcn.redis.utils.RedisUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@@ -65,6 +67,8 @@ public class MqttMessageHandler {
private final AppAutoDataMessageTemplate appAutoDataMessageTemplate;
private final DataSetFeignClient dataSetFeignClient;
@Autowired
Validator validator;
@@ -172,6 +176,13 @@ public class MqttMessageHandler {
log.error(AccessResponseEnum.MODEL_NO_FIND.getMessage());
throw new BusinessException(AccessResponseEnum.MODEL_NO_FIND);
}
if (Objects.equals(po.getType(),0)){
List<CsDataSet> dataSetList = dataSetFeignClient.getModuleDataSet(po.getId()).getData();
if (CollectionUtils.isEmpty(dataSetList)){
throw new BusinessException(AccessResponseEnum.MODULE_NUMBER_IS_NULL);
}
csModelDto.setModuleNumber(dataSetList.size());
}
csModelDto.setDevType(po.getDevTypeName());
csModelDto.setModelId(po.getId());
csModelDto.setDid(did);
@@ -179,12 +190,12 @@ public class MqttMessageHandler {
modelList.add(csModelDto);
});
//存储模板id
String key2 = "MODEL" + nDid;
String key2 = AppRedisKey.MODEL + nDid;
redisUtil.saveByKeyWithExpire(key2,modelList,600L);
//存储监测点模板信息,用于界面回显
List<String> modelId = modelList.stream().map(CsModelDto::getModelId).collect(Collectors.toList());
List<CsLineModel> lineList = csLineModelService.getMonitorNumByModelId(modelId);
String key = "LINE" + nDid;
String key = AppRedisKey.LINE + nDid;
redisUtil.saveByKeyWithExpire(key,lineList,600L);
}
}
@@ -219,12 +230,12 @@ public class MqttMessageHandler {
switch (rspDataDto.getDataType()){
case 1:
RspDataDto.SoftInfo softInfo = JSON.parseObject(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.SoftInfo.class);
redisUtil.saveByKeyWithExpire("SOFTINFO"+nDid,softInfo,600L);
redisUtil.saveByKeyWithExpire(AppRedisKey.SOFTINFO+nDid,softInfo,600L);
break;
case 2:
List<RspDataDto.LdevInfo> ldevInfo = JSON.parseArray(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.LdevInfo.class);
//fixme 默认第一个监测点是负载侧,第二个是电网测,后期数据错误可以在移动端调整
redisUtil.saveByKeyWithExpire("LINEDATA"+nDid,ldevInfo,600L);
redisUtil.saveByKeyWithExpire(AppRedisKey.LINE_DATA+nDid,ldevInfo,600L);
break;
default:
break;

View File

@@ -33,7 +33,7 @@ public interface ICsEquipmentDeliveryService extends IService<CsEquipmentDeliver
* 根据网关id修改软件信息
* @param nDid 网关id
*/
void updateSoftInfoBynDid(String nDid,String id);
void updateSoftInfoBynDid(String nDid,String id,Integer moduleNumber);
/**
* 根据网关id修改设备运行状态

View File

@@ -27,6 +27,7 @@ import com.njcn.csdevice.pojo.po.AppLineTopologyDiagramPO;
import com.njcn.csdevice.pojo.po.CsDeviceUserPO;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
import com.njcn.redis.pojo.enums.AppRedisKey;
import com.njcn.redis.utils.RedisUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.api.DictTreeFeignClient;
@@ -128,7 +129,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
Object model = null;
try {
Thread.sleep(1500);
String key = "LINE" + nDid;
String key = AppRedisKey.LINE + nDid;
model = redisUtil.getObjectByKey(key);
if (Objects.isNull(model)){
throw new BusinessException(AccessResponseEnum.MODEL_MISS);
@@ -155,8 +156,8 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
csLedgerParam.setLevel(2);
csLedgerParam.setSort(0);
csLedgerService.addLedgerTree(csLedgerParam);
List<CsModelDto> modelId = objectToList(redisUtil.getObjectByKey("MODEL" + devAccessParam.getNDid()));
Integer clDid = null;
List<CsModelDto> modelId = objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + devAccessParam.getNDid()));
Integer clDid = null, moduleNumber = null;
//2.新增装置-模板关系、获取电能质量的逻辑设备id
for (CsModelDto item : modelId) {
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
@@ -167,15 +168,21 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
if (Objects.equals(item.getType(),1)){
clDid = item.getDid();
}
if (Objects.equals(item.getType(),0)){
moduleNumber = item.getModuleNumber();
}
}
if (Objects.isNull(clDid)){
throw new BusinessException(AccessResponseEnum.CLDID_IS_NULL);
}
if (Objects.isNull(moduleNumber)){
throw new BusinessException(AccessResponseEnum.MODULE_NUMBER_IS_NULL);
}
askDevData(devAccessParam.getNDid(),AccessEnum.L_DEV_INFO.getCode(),version,clDid);
List<RspDataDto.LdevInfo> list = new ArrayList<>();
//等待mqtt数据
Thread.sleep(500);
String key = "LINEDATA" + devAccessParam.getNDid();
String key = AppRedisKey.LINE_DATA + devAccessParam.getNDid();
list = objectToList2(redisUtil.getObjectByKey(key));
if (CollectionUtils.isEmpty(list)){
throw new BusinessException(AccessResponseEnum.LDEVINFO_IS_NULL);
@@ -188,18 +195,21 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
po.setLineId(id);
po.setName(item.getName());
po.setPosition(item.getPosition());
po.setClDid(0);
if (Objects.equals(DicDataEnum.LOAD_SIDE.getCode(),location)){
RspDataDto.LdevInfo po1 = list.stream().filter(s -> Objects.equals(s.getClDid(),1)).findFirst().orElse(null);
po.setVolGrade(po1.getVolGrade());
po.setPtRatio(po1.getPtRatio());
po.setCtRatio(po1.getCtRatio());
po.setConType(po1.getConType());
po.setClDid(1);
} else if (Objects.equals(DicDataEnum.GRID_SIDE.getCode(),location)){
RspDataDto.LdevInfo po1 = list.stream().filter(s -> Objects.equals(s.getClDid(),2)).findFirst().orElse(null);
po.setVolGrade(po1.getVolGrade());
po.setPtRatio(po1.getPtRatio());
po.setCtRatio(po1.getCtRatio());
po.setConType(po1.getConType());
po.setClDid(2);
}
po.setStatus(1);
csLinePoList.add(po);
@@ -232,7 +242,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
askDevData(devAccessParam.getNDid(),AccessEnum.SOFT_INFO.getCode(),version,0);
//等待mqtt数据
Thread.sleep(500);
String key2 = "SOFTINFO" + devAccessParam.getNDid();
String key2 = AppRedisKey.SOFTINFO + devAccessParam.getNDid();
RspDataDto.SoftInfo softInfo = JSON.parseObject(JSON.toJSONString(redisUtil.getObjectByKey(key2)), RspDataDto.SoftInfo.class);
if (Objects.isNull(softInfo)){
throw new BusinessException(AccessResponseEnum.SOFTINFO_IS_NULL);
@@ -243,16 +253,16 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
csSoftInfoPo.setAppDate(new SimpleDateFormat("yyyy-MM-dd").parse(softInfo.getAppDate()));
csSoftInfoService.save(csSoftInfoPo);
//更新设备表软件信息
csEquipmentDeliveryService.updateSoftInfoBynDid(devAccessParam.getNDid(),csSoftInfoPo.getId());
csEquipmentDeliveryService.updateSoftInfoBynDid(devAccessParam.getNDid(),csSoftInfoPo.getId(),moduleNumber);
//修改装置状态
csEquipmentDeliveryService.updateStatusBynDid(devAccessParam.getNDid(), AccessEnum.REGISTERED.getCode());
//7.发起自动接入请求
devAccess(devAccessParam.getNDid(),version);
//8.删除redis监测点模板信息
redisUtil.delete("MODEL" + devAccessParam.getNDid());
redisUtil.delete("LINE" + devAccessParam.getNDid());
redisUtil.delete("LINEDATA" + devAccessParam.getNDid());
redisUtil.delete("SOFTINFO" + devAccessParam.getNDid());
redisUtil.delete(AppRedisKey.MODEL + devAccessParam.getNDid());
redisUtil.delete(AppRedisKey.LINE + devAccessParam.getNDid());
redisUtil.delete(AppRedisKey.LINE_DATA + devAccessParam.getNDid());
redisUtil.delete(AppRedisKey.SOFTINFO + devAccessParam.getNDid());
} catch (Exception e) {
throw new BusinessException(CommonResponseEnum.FAIL);
}

View File

@@ -34,9 +34,9 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
}
@Override
public void updateSoftInfoBynDid(String nDid, String id) {
public void updateSoftInfoBynDid(String nDid, String id, Integer moduleNumber) {
LambdaUpdateWrapper<CsEquipmentDeliveryPO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper.set(CsEquipmentDeliveryPO::getSoftinfoId,id).eq(CsEquipmentDeliveryPO::getNdid,nDid);
lambdaUpdateWrapper.set(CsEquipmentDeliveryPO::getSoftinfoId,id).set(CsEquipmentDeliveryPO::getModuleNumber,moduleNumber).eq(CsEquipmentDeliveryPO::getNdid,nDid);
this.update(lambdaUpdateWrapper);
}