refactor(service): 优化设备容量计算和事件处理逻辑

- 重构CsDevCapacityPOServiceImpl中的设备容量获取方法,简化代码逻辑并添加空值检查
- 在CsEquipmentDeliveryServiceImpl中添加二维码信息更新功能
- 优化CsEventPOServiceImpl中的事件处理,添加处理标志位设置和幅度值转换
- 增强CsFeedbackServiceImpl中的工程ID验证,防止空值异常
- 优化CsLinePOServiceImpl中的线路数据处理,统一设备ID格式化
- 移除无用的包导入并修复MQTT消息处理器中的大小写问题
- 更新离线数据上传服务中的等待逻辑和设备版本获取方式
- 修复InfluxDB查询中的值类型大小写问题
This commit is contained in:
xy
2026-06-24 20:32:59 +08:00
parent 6f66e1d336
commit a27315075c
10 changed files with 66 additions and 61 deletions

View File

@@ -1,25 +1,19 @@
package com.njcn.csdevice.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.service.CsLinePOService;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.csdevice.mapper.CsDevCapacityPOMapper;
import com.njcn.csdevice.pojo.po.CsDevCapacityPO;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.service.CsDevCapacityPOService;
import com.njcn.csdevice.service.CsLinePOService;
import com.njcn.system.api.DicDataFeignClient;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
*
@@ -48,16 +42,13 @@ public class CsDevCapacityPOServiceImpl extends ServiceImpl<CsDevCapacityPOMappe
@Override
public Double getDevCapacity(String id) {
List<CsLinePO> csLinePOS = csLinePOService.queryByDevId(id);
//String areaId = dicDataFeignClient.getDicDataByCode(DicDataEnum.OUTPUT_SIDE.getCode()).getData().getId();
//Optional.ofNullable(csLinePOS).orElseThrow(()-> new BusinessException(AlgorithmResponseEnum.LINE_DATA_ERROR));
//List<CsLinePO> collect1 = csLinePOS.stream().filter(temp -> Objects.equals(areaId, temp.getPosition())).collect(Collectors.toList());
List<CsLinePO> pos = csLinePOService.queryByDevId(id);
/*治理侧监测点*/
CsLinePO csLinePO = csLinePOS.get(0);
CsDevCapacityPO one = this.lambdaQuery().eq(CsDevCapacityPO::getLineId, csLinePO.getLineId()).eq(CsDevCapacityPO::getCldid, 0).one();
// Optional.ofNullable(one).orElseThrow(()-> new BusinessException(AlgorithmResponseEnum.DATA_MISSING));
CsLinePO po = pos.stream().filter(item -> Objects.equals(item.getClDid(),0)).findFirst().orElse(null);
if (po == null) {
return 0.0;
}
CsDevCapacityPO one = this.lambdaQuery().eq(CsDevCapacityPO::getLineId, po.getLineId()).eq(CsDevCapacityPO::getCldid, 0).one();
if(Objects.isNull(one)){
return 0.0;
}

View File

@@ -396,6 +396,9 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
csEquipmentDeliveryPo.setStatus(2);
//4.清空老mac的数据模板
stringRedisTemplate.convertAndSend("model_cache_clear", "clear");
//5.修改二维码信息
String qr = this.createQr(csEquipmentDeliveryAuditParm.getNdid());
csEquipmentDeliveryPo.setQrPath(qr);
}
List<CsEquipmentDeliveryPO> list = this.lambdaQuery().ne(CsEquipmentDeliveryPO::getId, csEquipmentDeliveryAuditParm.getId()).ne(CsEquipmentDeliveryPO::getNdid, csEquipmentDeliveryAuditParm.getNdid()).eq(CsEquipmentDeliveryPO::getName, csEquipmentDeliveryAuditParm.getName()).ne(CsEquipmentDeliveryPO::getRunStatus, 0).list();
if (!CollectionUtils.isEmpty(list)) {

View File

@@ -154,7 +154,8 @@ public class CsLinePOServiceImpl extends ServiceImpl<CsLinePOMapper, CsLinePO> i
@Transactional(rollbackFor = Exception.class)
public CsLinePO addCldLine(CsLineParam param) {
String lineId = IdUtil.fastSimpleUUID();
List<CsDeviceRegistry> data = csDeviceRegistryService.queryByCurrentNdid(param.getDevMac().replace(":", ""));
String nDid = param.getDevMac().replace(":", "");
List<CsDeviceRegistry> data = csDeviceRegistryService.queryByCurrentNdid(nDid);
Map<Integer, String> clDidToIdMap;
if (CollUtil.isNotEmpty(data)) {
clDidToIdMap = data.stream().collect(Collectors.toMap(CsDeviceRegistry::getClDid, CsDeviceRegistry::getId, (a, b) -> a));
@@ -208,8 +209,8 @@ public class CsLinePOServiceImpl extends ServiceImpl<CsLinePOMapper, CsLinePO> i
if (Objects.isNull(clDidToIdMap.get(param.getLineNo()))) {
CsDeviceRegistry registry = new CsDeviceRegistry();
registry.setId(lineId);
registry.setCurrentNdid(param.getDevMac());
registry.setOldNdid(param.getDevMac());
registry.setCurrentNdid(nDid);
registry.setOldNdid(nDid);
registry.setClDid(param.getLineNo());
registry.setFirstSeenTime(LocalDateTime.now());
csDeviceRegistryService.add(Collections.singletonList(registry));

View File

@@ -50,7 +50,6 @@ public class OfflineDataUploadController extends BaseController {
@PostMapping(value = "/makeUpData")
@ApiOperation("补招数据-界面")
@ApiImplicitParam(name = "lineId", value = "监测点id", required = true)
@Deprecated
public HttpResult<List<MakeUpVo>> makeUpData(@RequestParam("lineId") String lineId){
String methodDescribe = getMethodDescribe("makeUpData");
List<MakeUpVo> list = offlineDataUploadService.getMakeUpData(lineId);

View File

@@ -137,21 +137,19 @@ public class MqttMessageHandler {
FrequencyStatisticalQueryParam frequencyStatisticalQueryParam = new FrequencyStatisticalQueryParam();
frequencyStatisticalQueryParam.setDevId(devId);
frequencyStatisticalQueryParam.setStatisticalId(temp.getId());
frequencyStatisticalQueryParam.setValueType("avg");
frequencyStatisticalQueryParam.setValueType("AVG");
frequencyStatisticalQueryParam.setFrequencyStart(temp.getHarmStart());
frequencyStatisticalQueryParam.setFrequencyEnd(temp.getHarmEnd());
List<ThdDataVO> thdDataVOList = stableDataService.QuerySqlData(frequencyStatisticalQueryParam);
tempList.addAll(thdDataVOList);
} else {
CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam();
commonStatisticalQueryParam.setDevId(devId);
commonStatisticalQueryParam.setStatisticalId(temp.getId());
commonStatisticalQueryParam.setValueType("avg");
commonStatisticalQueryParam.setValueType("AVG");
List<ThdDataVO> listFuture = stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam);
tempList.addAll(listFuture);
}
});
//过滤T相
@@ -185,7 +183,7 @@ public class MqttMessageHandler {
CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam();
commonStatisticalQueryParam.setDevId(devId);
commonStatisticalQueryParam.setStatisticalId(temp.getId());
commonStatisticalQueryParam.setValueType("avg");
commonStatisticalQueryParam.setValueType("AVG");
List<ThdDataVO> listFuture = stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam);
l1.addAll(listFuture);
});
@@ -224,7 +222,7 @@ public class MqttMessageHandler {
CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam();
commonStatisticalQueryParam.setDevId(devId);
commonStatisticalQueryParam.setStatisticalId(temp.getId());
commonStatisticalQueryParam.setValueType("avg");
commonStatisticalQueryParam.setValueType("AVG");
List<ThdDataVO> listFuture = stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam);
l1.addAll(listFuture);
});
@@ -265,7 +263,7 @@ public class MqttMessageHandler {
CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam();
commonStatisticalQueryParam.setDevId(devId);
commonStatisticalQueryParam.setStatisticalId(temp.getId());
commonStatisticalQueryParam.setValueType("avg");
commonStatisticalQueryParam.setValueType("AVG");
List<ThdDataVO> listFuture = stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam);
l1.addAll(listFuture);
});

View File

@@ -566,6 +566,9 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
po2.setAdvanceReason(po.getAdvanceReason());
po2.setAdvanceType(po.getAdvanceType());
po2.setFileFlag(1);
if (!Objects.isNull(po.getAdvanceReason()) && !Objects.isNull(po.getAdvanceType())) {
po2.setDealFlag(1);
}
int row = wlRmpEventDetailMapper.updateById(po2);
if (row > 0) {
result = true;
@@ -580,7 +583,7 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
rmpEventDetailPO.setMeasurementPointId(param.getMonitorId());
rmpEventDetailPO.setStartTime(time);
rmpEventDetailPO.setEventType(getEventType(param.getEventType()));
rmpEventDetailPO.setFeatureAmplitude(param.getAmplitude());
rmpEventDetailPO.setFeatureAmplitude(param.getAmplitude() * 100);
rmpEventDetailPO.setDuration(param.getDuration());
rmpEventDetailPO.setEventDescribe(getTag(param.getEventType()));
rmpEventDetailPO.setPhase(param.getPhase());
@@ -598,6 +601,9 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
po.setAdvanceReason(advanceReason);
po.setAdvanceType(advanceType);
po.setFileFlag(1);
if (!Objects.isNull(advanceReason) && !Objects.isNull(advanceType)) {
po.setDealFlag(1);
}
wlRmpEventDetailMapper.updateById(po);
}

View File

@@ -20,6 +20,7 @@ import com.njcn.csdevice.api.DeviceFtpFeignClient;
import com.njcn.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.api.PortableOffLogFeignClient;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
import com.njcn.csharmonic.enums.CsHarmonicResponseEnum;
import com.njcn.csharmonic.offline.constant.OfflineConstant;
@@ -151,30 +152,33 @@ public class OfflineDataUploadServiceImpl implements OfflineDataUploadService {
try {
//询问装置项目信息
askProjectInfo(lineId,null, Integer.parseInt(TypeEnum.TYPE_6.getCode()),null,"DevCmd");
Thread.sleep(5000);
String key = AppRedisKey.PROJECT_INFO + lineId;
Object object = redisUtil.getObjectByKey(key);
if (!Objects.isNull(object)) {
// 创建 DateTimeFormatter 对象并指定格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
List<RspDataDto.ProjectInfo> projectInfoList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(key),RspDataDto.ProjectInfo.class);
for (RspDataDto.ProjectInfo item : projectInfoList) {
MakeUpVo vo = new MakeUpVo();
vo.setType("dir");
BeanUtils.copyProperties(item,vo);
long startTime = item.getPrjTimeStart();
if (startTime != 0) {
LocalDateTime dateTime = Instant.ofEpochMilli((startTime-8*3600)*1000).atZone(ZoneId.systemDefault()).toLocalDateTime();
String formattedDate = dateTime.format(formatter);
vo.setStartTime(formattedDate);
for (int i = 0; i < 5; i++) {
Thread.sleep(1000);
String key = AppRedisKey.PROJECT_INFO + lineId;
Object object = redisUtil.getObjectByKey(key);
if (!Objects.isNull(object)) {
// 创建 DateTimeFormatter 对象并指定格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
List<RspDataDto.ProjectInfo> projectInfoList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(key),RspDataDto.ProjectInfo.class);
for (RspDataDto.ProjectInfo item : projectInfoList) {
MakeUpVo vo = new MakeUpVo();
vo.setType("dir");
BeanUtils.copyProperties(item,vo);
long startTime = item.getPrjTimeStart();
if (startTime != 0) {
LocalDateTime dateTime = Instant.ofEpochMilli((startTime-8*3600)*1000).atZone(ZoneId.systemDefault()).toLocalDateTime();
String formattedDate = dateTime.format(formatter);
vo.setStartTime(formattedDate);
}
long endTime = item.getPrjTimeEnd();
if (endTime != -1) {
LocalDateTime dateTime = Instant.ofEpochMilli((endTime-8*3600)*1000).atZone(ZoneId.systemDefault()).toLocalDateTime();
String formattedDate = dateTime.format(formatter);
vo.setEndTime(formattedDate);
}
result.add(vo);
}
long endTime = item.getPrjTimeEnd();
if (endTime != -1) {
LocalDateTime dateTime = Instant.ofEpochMilli((endTime-8*3600)*1000).atZone(ZoneId.systemDefault()).toLocalDateTime();
String formattedDate = dateTime.format(formatter);
vo.setEndTime(formattedDate);
}
result.add(vo);
break;
}
}
} catch (InterruptedException e) {
@@ -497,7 +501,8 @@ public class OfflineDataUploadServiceImpl implements OfflineDataUploadService {
CsEquipmentDeliveryPO po = equipmentFeignClient.getDevByLineId(lineId).getData();
nDid = po.getNdid();
}
String version = csTopicFeignClient.find(nDid).getData();
// String version = csTopicFeignClient.find(nDid).getData();
String version = "V1";
ReqAndResDto.Req reqAndResParam = createRequestParameters(lineId, type, path);
publisher.send("/Pfm/"+topic+"/" + version + "/" + nDid, new Gson().toJson(reqAndResParam), 1, false);
}
@@ -523,11 +528,10 @@ public class OfflineDataUploadServiceImpl implements OfflineDataUploadService {
private void handleType8454(ReqAndResDto.Req reqAndResParam, String lineId) {
if (StringUtils.isNotBlank(lineId)) {
int length = StringUtils.length(lineId);
Integer clDid = Integer.parseInt(lineId.substring(length - 1));
CsLinePO po = csLineFeignClient.getById(lineId).getData();
reqAndResParam.setType(8454);
MakeUpDto makeUpDto = new MakeUpDto();
makeUpDto.setClDid(clDid);
makeUpDto.setClDid(po.getClDid());
makeUpDto.setDataType(Integer.parseInt(DATA_48.getCode()));
makeUpDto.setDataAttr(0);
makeUpDto.setOperate(1);

View File

@@ -388,7 +388,7 @@ public class StableDataServiceImpl implements StableDataService {
stringBuilder1.append("last("+data.getName()).append("_"+i).append(") AS "+data.getName()).append("_"+i).append(",");
}
}
stringBuilder2.append ("line_id='").append (csLinePO.getLineId()).append("' and value_type = 'avg' and process='"+data1.get(0).getProcess()+"' group by phasic_type ").append(InfluxDbSqlConstant.TZ);
stringBuilder2.append ("line_id='").append (csLinePO.getLineId()).append("' and value_type = 'AVG' and process='"+data1.get(0).getProcess()+"' group by phasic_type ").append(InfluxDbSqlConstant.TZ);
String sql1 = "select "+stringBuilder1+" from "+"apf_data"+" where "+stringBuilder2;
QueryResult sqlData = influxDbUtils.query(sql1);

View File

@@ -1,7 +1,6 @@
package com.njcn.cssystem.controller.feedback;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;

View File

@@ -3,6 +3,7 @@ package com.njcn.cssystem.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.api.RoleEngineerDevFeignClient;
import com.njcn.cssystem.mapper.CsFeedbackChatMapper;
import com.njcn.cssystem.mapper.CsFeedbackMapper;
@@ -52,6 +53,9 @@ public class CsFeedbackServiceImpl extends ServiceImpl<CsFeedbackMapper, CsFeedb
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean addFeedBack(CsFeedbackAddParm csFeedbackAddParm) {
if (Objects.isNull(csFeedbackAddParm.getEngineeringId())) {
throw new BusinessException("请选择工程后,再进行反馈!");
}
CsFeedbackPO csFeedbackPO = new CsFeedbackPO ();
BeanUtils.copyProperties (csFeedbackAddParm, csFeedbackPO);
csFeedbackPO.setUserId(RequestUtil.getUserIndex());