feat(topology): 添加拓扑图目标指标功能并重构数据处理逻辑

- 在AppLineTopologyDiagram相关类中添加target字段用于绑定指标
- 重构DeviceMessageClient的getLineInfo方法参数结构
- 实现CsLineTopologyFeignClient的queryTopologyDiagram接口及降级处理
- 更新MqttMessageHandler中拓扑图数据处理逻辑,支持自定义指标查询
- 添加PqdData数据拆分服务IPqdDataSplitService及其实现
- 优化PortableOfflLogServiceImpl中的数据入库逻辑
- 修复CsTerminalReplyServiceImpl中时间范围查询条件
- 移除未使用的导入和代码,优化服务依赖注入
This commit is contained in:
xy
2026-05-25 14:38:35 +08:00
parent 1d8d714d66
commit ea2962840c
17 changed files with 1079 additions and 453 deletions

View File

@@ -4,9 +4,12 @@ import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.pojo.response.HttpResult;
import com.njcn.csdevice.api.fallback.CsLineTopologyClientFallbackFactory; import com.njcn.csdevice.api.fallback.CsLineTopologyClientFallbackFactory;
import com.njcn.csdevice.pojo.po.AppLineTopologyDiagramPO; import com.njcn.csdevice.pojo.po.AppLineTopologyDiagramPO;
import com.njcn.csdevice.pojo.vo.AppTopologyDiagramVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
@@ -19,4 +22,8 @@ public interface CsLineTopologyFeignClient {
@PostMapping("/addList") @PostMapping("/addList")
HttpResult<String> addList(@RequestBody List<AppLineTopologyDiagramPO> list); HttpResult<String> addList(@RequestBody List<AppLineTopologyDiagramPO> list);
@PostMapping("/queryTopologyDiagram")
@ApiOperation("查询装置拓扑图")
HttpResult<AppTopologyDiagramVO> queryTopologyDiagram(@RequestParam(value="devId") String devId);
} }

View File

@@ -1,17 +1,11 @@
package com.njcn.csdevice.api; package com.njcn.csdevice.api;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.ServerInfo; import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.api.fallback.DeviceMessageClientFallbackFactory; import com.njcn.csdevice.api.fallback.DeviceMessageClientFallbackFactory;
import com.njcn.csdevice.param.DeviceMessageParam; import com.njcn.csdevice.param.DeviceMessageParam;
import com.njcn.csdevice.pojo.po.CsLinePO; import com.njcn.csdevice.param.LineInfoParam;
import com.njcn.user.pojo.po.User; import com.njcn.user.pojo.po.User;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@@ -36,6 +30,6 @@ public interface DeviceMessageFeignClient {
@PostMapping("/getLineInfo") @PostMapping("/getLineInfo")
@ApiOperation("获取监测点信息") @ApiOperation("获取监测点信息")
HttpResult<String> getLineInfo(@RequestParam("id") String id, @RequestParam(value = "list", required = false) List<CsLinePO> list); HttpResult<String> getLineInfo(@RequestBody LineInfoParam param);
} }

View File

@@ -5,6 +5,7 @@ import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.pojo.response.HttpResult;
import com.njcn.csdevice.api.CsLineTopologyFeignClient; import com.njcn.csdevice.api.CsLineTopologyFeignClient;
import com.njcn.csdevice.pojo.po.AppLineTopologyDiagramPO; import com.njcn.csdevice.pojo.po.AppLineTopologyDiagramPO;
import com.njcn.csdevice.pojo.vo.AppTopologyDiagramVO;
import feign.hystrix.FallbackFactory; import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -33,6 +34,12 @@ public class CsLineTopologyClientFallbackFactory implements FallbackFactory<CsLi
throw new BusinessException(finalExceptionEnum); throw new BusinessException(finalExceptionEnum);
} }
@Override
public HttpResult<AppTopologyDiagramVO> queryTopologyDiagram(String devId) {
log.error("{}异常,降级处理,异常为:{}","查询装置拓扑图异常",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
}; };
} }
} }

View File

@@ -5,7 +5,7 @@ import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.pojo.response.HttpResult;
import com.njcn.csdevice.api.DeviceMessageFeignClient; import com.njcn.csdevice.api.DeviceMessageFeignClient;
import com.njcn.csdevice.param.DeviceMessageParam; import com.njcn.csdevice.param.DeviceMessageParam;
import com.njcn.csdevice.pojo.po.CsLinePO; import com.njcn.csdevice.param.LineInfoParam;
import com.njcn.user.pojo.po.User; import com.njcn.user.pojo.po.User;
import feign.hystrix.FallbackFactory; import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -42,7 +42,7 @@ public class DeviceMessageClientFallbackFactory implements FallbackFactory<Devic
} }
@Override @Override
public HttpResult<String> getLineInfo(String id, List<CsLinePO> list) { public HttpResult<String> getLineInfo(LineInfoParam param) {
log.error("{}异常,降级处理,异常为:{}","获取监测点信息数据异常",cause.toString()); log.error("{}异常,降级处理,异常为:{}","获取监测点信息数据异常",cause.toString());
throw new BusinessException(finalExceptionEnum); throw new BusinessException(finalExceptionEnum);
} }

View File

@@ -0,0 +1,21 @@
package com.njcn.csdevice.param;
import com.njcn.csdevice.pojo.po.CsLinePO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author xy
*/
@Data
public class LineInfoParam {
@ApiModelProperty("nDid")
private String nDid;
@ApiModelProperty("监测点集合")
List<CsLinePO> list;
}

View File

@@ -44,5 +44,6 @@ public class AppLineTopologyDiagramParm extends BaseEntity {
private Double lat; private Double lat;
private String target;
} }

View File

@@ -45,5 +45,7 @@ public class AppLineTopologyDiagramPO extends BaseEntity {
@TableField(value = "lat") @TableField(value = "lat")
private Double lat; private Double lat;
@TableField(value = "target")
private String target;
} }

View File

@@ -1,8 +1,6 @@
package com.njcn.csdevice.pojo.vo; package com.njcn.csdevice.pojo.vo;
import com.baomidou.mybatisplus.annotation.TableField; import io.swagger.annotations.ApiModelProperty;
import com.baomidou.mybatisplus.annotation.TableName;
import com.njcn.db.bo.BaseEntity;
import lombok.Data; import lombok.Data;
/** /**
@@ -43,5 +41,6 @@ public class AppLineTopologyDiagramVO {
private String linePostion; private String linePostion;
@ApiModelProperty(value="绑定的指标")
private String target;
} }

View File

@@ -7,7 +7,7 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil; import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.param.DeviceMessageParam; import com.njcn.csdevice.param.DeviceMessageParam;
import com.njcn.csdevice.pojo.po.CsLinePO; import com.njcn.csdevice.param.LineInfoParam;
import com.njcn.csdevice.service.DeviceMessageService; import com.njcn.csdevice.service.DeviceMessageService;
import com.njcn.user.pojo.po.User; import com.njcn.user.pojo.po.User;
import com.njcn.web.controller.BaseController; import com.njcn.web.controller.BaseController;
@@ -64,13 +64,10 @@ public class DeviceMessageController extends BaseController {
@OperateInfo(info = LogEnum.BUSINESS_COMMON) @OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getLineInfo") @PostMapping("/getLineInfo")
@ApiOperation("获取监测点信息") @ApiOperation("获取监测点信息")
@ApiImplicitParams({ @ApiImplicitParam(name = "param", value = "参数", required = true)
@ApiImplicitParam(name = "id", value = "参数", paramType = "query"), public HttpResult<String> getLineInfo(@RequestBody LineInfoParam param){
@ApiImplicitParam(name = "list", value = "监测点id集合", paramType = "query",required = false)
})
public HttpResult<String> getLineInfo(@RequestParam(value = "id") String id, @RequestParam(value = "list",required = false) List<CsLinePO> list){
String methodDescribe = getMethodDescribe("getLineInfo"); String methodDescribe = getMethodDescribe("getLineInfo");
deviceMessageService.getLineInfo(id,list); deviceMessageService.getLineInfo(param.getNDid(),param.getList());
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "success", methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "success", methodDescribe);
} }

View File

@@ -0,0 +1,25 @@
package com.njcn.csdevice.service;
import com.njcn.influx.pojo.po.cs.PqdData;
import java.util.List;
import java.util.Map;
/**
* PqdData数据拆分服务
*
* @author system
* @since 2026-05-22
*/
public interface IPqdDataSplitService {
/**
* 将PqdData数据拆分到不同的表中
*
* @param pqdDataList 原始PqdData数据列表
* @return 包含两部分数据:
* - "splitData": 已拆分到各表的数据 Map<表名, 数据列表>
* - "remainingPqdData": 未匹配的PqdData数据仍需插入InfluxDB
*/
Map<String, Object> splitPqdData(List<PqdData> pqdDataList);
}

View File

@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.mapper.AppLineTopologyDiagramMapper; import com.njcn.csdevice.mapper.AppLineTopologyDiagramMapper;
import com.njcn.csdevice.mapper.CsLedgerMapper;
import com.njcn.csdevice.pojo.param.AppTopologyDiagramQueryParm; import com.njcn.csdevice.pojo.param.AppTopologyDiagramQueryParm;
import com.njcn.csdevice.pojo.param.LinePostionParam; import com.njcn.csdevice.pojo.param.LinePostionParam;
import com.njcn.csdevice.pojo.po.AppLineTopologyDiagramPO; import com.njcn.csdevice.pojo.po.AppLineTopologyDiagramPO;
@@ -13,7 +12,6 @@ import com.njcn.csdevice.pojo.po.CsLedger;
import com.njcn.csdevice.pojo.po.CsLinePO; import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.pojo.vo.AppLineTopologyDiagramVO; import com.njcn.csdevice.pojo.vo.AppLineTopologyDiagramVO;
import com.njcn.csdevice.pojo.vo.AppTopologyDiagramVO; import com.njcn.csdevice.pojo.vo.AppTopologyDiagramVO;
import com.njcn.csdevice.pojo.vo.CsLineTopologyTemplateVO;
import com.njcn.csdevice.service.AppLineTopologyDiagramService; import com.njcn.csdevice.service.AppLineTopologyDiagramService;
import com.njcn.csdevice.service.AppTopologyDiagramService; import com.njcn.csdevice.service.AppTopologyDiagramService;
import com.njcn.csdevice.service.CsLinePOService; import com.njcn.csdevice.service.CsLinePOService;
@@ -73,7 +71,7 @@ public class AppLineTopologyDiagramServiceImpl extends ServiceImpl<AppLineTopolo
} }
public List<AppLineTopologyDiagramVO> queryByLineIds(List<String> lineIds) { public List<AppLineTopologyDiagramVO> queryByLineIds(List<String> lineIds) {
List<AppLineTopologyDiagramVO> result = new ArrayList<>(); List<AppLineTopologyDiagramVO> result = new ArrayList<>();
if (lineIds != null && lineIds.size() > 0) { if (lineIds != null && !lineIds.isEmpty()) {
result = this.getBaseMapper().queryByLineIds( lineIds); result = this.getBaseMapper().queryByLineIds( lineIds);
} }
return result; return result;
@@ -83,14 +81,13 @@ public class AppLineTopologyDiagramServiceImpl extends ServiceImpl<AppLineTopolo
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void auditList(LinePostionParam linePostionParam) { public void auditList(LinePostionParam linePostionParam) {
linePostionParam.getPointList().forEach(temp->{ linePostionParam.getPointList().forEach(temp->{
csLinePOService.lambdaUpdate().eq(CsLinePO::getLineId,temp.getLineId()).set(CsLinePO::getName,temp.getName()).set(CsLinePO::getPosition,temp.getLinePostion()).update(); csLinePOService.lambdaUpdate().eq(CsLinePO::getLineId,temp.getLineId()).set(CsLinePO::getName,temp.getName()).set(CsLinePO::getPosition,temp.getLinePostion()).update();
this.lambdaUpdate().eq(AppLineTopologyDiagramPO::getId,temp.getId()). this.lambdaUpdate().eq(AppLineTopologyDiagramPO::getId,temp.getId()).
eq(AppLineTopologyDiagramPO::getLineId,temp.getLineId()).set(AppLineTopologyDiagramPO::getLat,temp.getLat()). eq(AppLineTopologyDiagramPO::getLineId,temp.getLineId()).set(AppLineTopologyDiagramPO::getLat,temp.getLat()).
set(AppLineTopologyDiagramPO::getLng,temp.getLng()).set(AppLineTopologyDiagramPO::getId,linePostionParam.getId()).update(); set(AppLineTopologyDiagramPO::getLng,temp.getLng()).set(AppLineTopologyDiagramPO::getId,linePostionParam.getId())
.set(AppLineTopologyDiagramPO::getTarget,temp.getTarget())
.update();
iCsLedgerService.lambdaUpdate().eq(CsLedger::getId,temp.getLineId()).set(CsLedger::getName,temp.getName()).update(); iCsLedgerService.lambdaUpdate().eq(CsLedger::getId,temp.getLineId()).set(CsLedger::getName,temp.getName()).update();
}); });
} }

View File

@@ -1,6 +1,7 @@
package com.njcn.csdevice.service.impl; package com.njcn.csdevice.service.impl;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -177,27 +178,10 @@ public class CsTerminalReplyServiceImpl extends ServiceImpl<CsTerminalReplyMappe
QueryWrapper<CsTerminalReply> queryWrapper = new QueryWrapper<>(); QueryWrapper<CsTerminalReply> queryWrapper = new QueryWrapper<>();
if (StrUtil.isNotBlank(param.getSearchValue())) { if (StrUtil.isNotBlank(param.getSearchValue())) {
queryWrapper.like("cs_terminal_reply.line_id", param.getSearchValue()); queryWrapper.like("cs_terminal_reply.line_id", param.getSearchValue());
// //获取监测点id
// List<CsLinePO> list = csLinePOService.getLineByName(param.getSearchValue());
// if (CollectionUtil.isEmpty(list)) {
// return page;
// } else {
// queryWrapper.and(pr -> {
// // 获取所有 lineId
// List<String> lineIds = list.stream()
// .map(CsLinePO::getLineId)
// .collect(Collectors.toList());
// // 使用 OR 条件连接多个 lineId
// for (int i = 0; i < lineIds.size(); i++) {
// if (i == 0) {
// pr.like("cs_terminal_reply.line_id", lineIds.get(i));
// } else {
// pr.or().like("cs_terminal_reply.line_id", lineIds.get(i));
// }
// }
// });
// }
} }
queryWrapper.between("cs_terminal_reply.Create_Time"
, DateUtil.beginOfDay(DateUtil.parse(param.getSearchBeginTime()))
, DateUtil.endOfDay(DateUtil.parse(param.getSearchEndTime())));
//排序 //排序
queryWrapper.orderBy(true, false, "cs_terminal_reply.create_time"); queryWrapper.orderBy(true, false, "cs_terminal_reply.create_time");
queryWrapper.in("cs_terminal_reply.code", Arrays.asList("allFile", "allEvent", "oneFile")); queryWrapper.in("cs_terminal_reply.code", Arrays.asList("allFile", "allEvent", "oneFile"));

View File

@@ -5,6 +5,7 @@ import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.tocrhz.mqtt.publisher.MqttPublisher; import com.github.tocrhz.mqtt.publisher.MqttPublisher;
import com.njcn.common.pojo.enums.common.DataStateEnum; import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.pojo.exception.BusinessException;
@@ -12,17 +13,13 @@ import com.njcn.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.constant.DataParam; import com.njcn.csdevice.constant.DataParam;
import com.njcn.csdevice.enums.AlgorithmResponseEnum; import com.njcn.csdevice.enums.AlgorithmResponseEnum;
import com.njcn.csdevice.mapper.PortableOfflLogMapper; import com.njcn.csdevice.mapper.PortableOfflLogMapper;
import com.njcn.csdevice.param.UploadDataParam;
import com.njcn.csdevice.pojo.dto.CsEquipmentDeliveryDTO; import com.njcn.csdevice.pojo.dto.CsEquipmentDeliveryDTO;
import com.njcn.csdevice.pojo.po.CsLinePO; import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.pojo.po.PortableOffMainLog; import com.njcn.csdevice.pojo.po.PortableOffMainLog;
import com.njcn.csdevice.pojo.po.PortableOfflLog; import com.njcn.csdevice.pojo.po.PortableOfflLog;
import com.njcn.csdevice.pojo.po.WlRecord; import com.njcn.csdevice.pojo.po.WlRecord;
import com.njcn.csdevice.service.CsLinePOService; import com.njcn.csdevice.service.*;
import com.njcn.csdevice.service.IPortableOfflLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.csdevice.param.UploadDataParam;
import com.njcn.csdevice.service.IWlRecordService;
import com.njcn.csdevice.service.PortableOffMainLogService;
import com.njcn.csdevice.util.InfluxDbParamUtil; import com.njcn.csdevice.util.InfluxDbParamUtil;
import com.njcn.csharmonic.api.EventFeignClient; import com.njcn.csharmonic.api.EventFeignClient;
import com.njcn.csharmonic.api.OfflineDataUploadFeignClient; import com.njcn.csharmonic.api.OfflineDataUploadFeignClient;
@@ -36,8 +33,8 @@ import com.njcn.csharmonic.offline.mincfg.AnalyseComtradeCfg;
import com.njcn.csharmonic.offline.mincfg.vo.CmnModeCfg; import com.njcn.csharmonic.offline.mincfg.vo.CmnModeCfg;
import com.njcn.csharmonic.offline.vo.Response; import com.njcn.csharmonic.offline.vo.Response;
import com.njcn.csharmonic.pojo.po.CsEventPO; import com.njcn.csharmonic.pojo.po.CsEventPO;
import com.njcn.influx.imapper.EvtDataMapper; import com.njcn.influx.imapper.*;
import com.njcn.influx.imapper.PqdDataMapper; import com.njcn.influx.pojo.po.*;
import com.njcn.influx.pojo.po.cs.EntData; import com.njcn.influx.pojo.po.cs.EntData;
import com.njcn.influx.pojo.po.cs.PqdData; import com.njcn.influx.pojo.po.cs.PqdData;
import com.njcn.oss.utils.FileStorageUtil; import com.njcn.oss.utils.FileStorageUtil;
@@ -50,11 +47,11 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.ListUtils; import org.apache.commons.collections4.ListUtils;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.*; import java.io.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.DecimalFormat; import java.text.DecimalFormat;
@@ -81,25 +78,31 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
private final DecimalFormat df = new DecimalFormat("#0.000"); private final DecimalFormat df = new DecimalFormat("#0.000");
private final FileStorageUtil fileStorageUtil; private final FileStorageUtil fileStorageUtil;
private final DicDataFeignClient dicDataFeignClient; private final DicDataFeignClient dicDataFeignClient;
private final OfflineDataUploadFeignClient offlineDataUploadFeignClient; private final OfflineDataUploadFeignClient offlineDataUploadFeignClient;
private final EleEvtFeignClient eleEvtFeignClient; private final EleEvtFeignClient eleEvtFeignClient;
private final EventFeignClient eventFeignClient; private final EventFeignClient eventFeignClient;
private final EquipmentFeignClient equipmentFeignClient; private final EquipmentFeignClient equipmentFeignClient;
private final InfluxDbParamUtil influxDbParamUtil; private final InfluxDbParamUtil influxDbParamUtil;
private final PqdDataMapper pqdDataMapper; private final PqdDataMapper pqdDataMapper;
private final EvtDataMapper evtDataMapper; private final EvtDataMapper evtDataMapper;
private final DataVMapper dataVMapper;
private final DataIMapper dataIMapper;
private final DataHarmRateVMapper dataHarmRateV;
private final DataHarmRateIMapper dataHarmRateI;
private final DataInHarmVMapper dataInHarmV;
private final DataHarmPowerPMapper dataHarmPowerP;
private final DataHarmPowerQMapper dataHarmPowerQ;
private final DataHarmPowerSMapper dataHarmPowerS;
private final DataFlickerMapper dataFlicker;
private final DataFlucMapper dataFluc;
private final DataPltMapper dataPlt;
private final DataHarmPhasicVMapper dataHarmPhasicV;
private final DataHarmPhasicIMapper dataHarmPhasicI;
private final IPqdDataSplitService pqdDataSplitService;
private final MqttPublisher publisher; private final MqttPublisher publisher;
private final PortableOffMainLogService portableOffMainLogService; private final PortableOffMainLogService portableOffMainLogService;
private final IWlRecordService wlRecordService; private final IWlRecordService wlRecordService;
@@ -353,6 +356,8 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
List<List<PqdData>> partition = ListUtils.partition(pqdData, 1500); List<List<PqdData>> partition = ListUtils.partition(pqdData, 1500);
for (List<PqdData> sliceList : partition) { for (List<PqdData> sliceList : partition) {
List<PqdData> sublistAsOriginalListType = new ArrayList<>(sliceList); List<PqdData> sublistAsOriginalListType = new ArrayList<>(sliceList);
// Map<String, Object> map = pqdDataSplitService.splitPqdData(sublistAsOriginalListType);
// insertData(map);
pqdDataMapper.insertBatch(sublistAsOriginalListType); pqdDataMapper.insertBatch(sublistAsOriginalListType);
} }
//min结果集解析入库后就不需要在解析了 //min结果集解析入库后就不需要在解析了
@@ -604,4 +609,61 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
} }
return Objects.isNull(result)?null:result; return Objects.isNull(result)?null:result;
} }
public void insertData(Map<String, Object> map) {
//13张表
Map<String, List<?>> splitData = (Map<String, List<?>>) map.get("splitData");
splitData.forEach((key, value) -> {
switch (key) {
case "data_v":
dataVMapper.insertBatch((List<DataV>) value);
break;
case "data_i":
dataIMapper.insertBatch((List<DataI>) value);
break;
case "data_flicker":
dataFlicker.insertBatch((List<DataFlicker>) value);
break;
case "data_fluc":
dataFluc.insertBatch((List<DataFluc>) value);
break;
case "data_harmphasic_i":
dataHarmPhasicI.insertBatch((List<DataHarmPhasicI>) value);
break;
case "data_harmphasic_v":
dataHarmPhasicV.insertBatch((List<DataHarmPhasicV>) value);
break;
case "data_harmpower_p":
dataHarmPowerP.insertBatch((List<DataHarmPowerP>) value);
break;
case "data_harmpower_q":
dataHarmPowerQ.insertBatch((List<DataHarmPowerQ>) value);
break;
case "data_harmpower_s":
dataHarmPowerS.insertBatch((List<DataHarmPowerS>) value);
break;
case "data_harmrate_v":
dataHarmRateV.insertBatch((List<DataHarmRateV>) value);
break;
case "data_harmrate_i":
dataHarmRateI.insertBatch((List<DataHarmRateI>) value);
break;
case "data_inharm_v":
dataInHarmV.insertBatch((List<DataInHarmV>) value);
break;
case "data_plt":
dataPlt.insertBatch((List<DataPlt>) value);
break;
default:
log.warn("不支持的目标表: {}", key);
break;
}
});
//其余数据
List<PqdData> remainingPqdData = (List<PqdData>) map.get("remainingPqdData");
if (!CollectionUtils.isEmpty(remainingPqdData)) {
pqdDataMapper.insertBatch(remainingPqdData);
}
}
} }

View File

@@ -0,0 +1,425 @@
package com.njcn.csdevice.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.njcn.csdevice.service.IPqdDataSplitService;
import com.njcn.influx.pojo.po.*;
import com.njcn.influx.pojo.po.cs.PqdData;
import com.njcn.redis.pojo.enums.AppRedisKey;
import com.njcn.redis.utils.RedisUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.api.EpdFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.po.DictData;
import com.njcn.system.pojo.po.EleEpdPqd;
import com.njcn.system.pojo.vo.EleEpdPqdListVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* PqdData数据拆分服务实现
*
* @author system
* @since 2026-05-22
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class PqdDataSplitServiceImpl implements IPqdDataSplitService {
private final RedisUtil redisUtil;
private final EpdFeignClient epdFeignClient;
private final DicDataFeignClient dicDataFeignClient;
@Override
public Map<String, Object> splitPqdData(List<PqdData> pqdDataList) {
Map<String, Object> result = new HashMap<>();
if (CollectionUtils.isEmpty(pqdDataList)) {
result.put("splitData", Collections.emptyMap());
result.put("remainingPqdData", Collections.emptyList());
return result;
}
log.info("开始拆分PqdData数据共{}条记录", pqdDataList.size());
Map<String, List<?>> splitDataMap = new HashMap<>();
List<PqdData> remainingPqdData = new ArrayList<>();
//获取表映射关系
Map<String,String> map1 = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD)), Map.class);
//获取字段映射关系
DictData pqd = dicDataFeignClient.getDicDataByCode(DicDataEnum.PQD.getCode()).getData();
List<EleEpdPqdListVO> list = epdFeignClient.selectAll().getData();
List<EleEpdPqd> epdList = list.stream().filter(item -> Objects.equals(item.getDataType(), pqd.getId()))
.findFirst()
.map(EleEpdPqdListVO::getEleEpdPqdVOS)
.orElse(new ArrayList<>());
// 处理 harmStart 和 harmEnd
List<EleEpdPqd> resultList = epdList.stream()
.flatMap(item -> {
if (item.getHarmStart() != null && item.getHarmEnd() != null) {
// 生成从 harmStart 到 harmEnd 的新对象
List<EleEpdPqd> expandedList = new ArrayList<>();
for (int i = item.getHarmStart(); i <= item.getHarmEnd(); i++) {
EleEpdPqd newItem = copyEleEpdPqd(item);
newItem.setName(item.getName() + "_" + i);
expandedList.add(newItem);
}
return expandedList.stream();
} else {
// 保持原对象
return Stream.of(item);
}
})
.collect(Collectors.toList());
Map<String,List<EleEpdPqd>> map2 = resultList.stream().collect(Collectors.groupingBy(EleEpdPqd::getName,LinkedHashMap::new,Collectors.toList()));
try {
for (PqdData pqdData : pqdDataList) {
boolean hasMatchedField = false;
Map<String, Object> fieldValues = extractFieldValues(pqdData);
for (Map.Entry<String, Object> entry : fieldValues.entrySet()) {
String sourceFieldName = StringUtils.capitalize(entry.getKey());
Object value = entry.getValue();
if (value == null || isCommonField(sourceFieldName)) {
continue;
}
String tableName = map1.get(sourceFieldName);
String otherName = sourceFieldName;
List<EleEpdPqd> v = map2.get(sourceFieldName);
if (!CollectionUtils.isEmpty(v)) {
otherName = toCamelCase(v.get(0).getOtherName());
}
if (StrUtil.isBlank(tableName) || StrUtil.isBlank(otherName)) {
continue;
}
hasMatchedField = true;
if (!splitDataMap.containsKey(tableName)) {
splitDataMap.put(tableName, new ArrayList<>());
}
createAndAddTargetData((List<Object>) splitDataMap.get(tableName), tableName, pqdData, otherName, value);
}
if (!hasMatchedField) {
remainingPqdData.add(pqdData);
}
}
result.put("splitData", splitDataMap);
result.put("remainingPqdData", remainingPqdData);
log.info("PqdData数据拆分完成拆分为{}个表,剩余{}条未匹配数据需插入InfluxDB",
splitDataMap.size(), remainingPqdData.size());
} catch (Exception e) {
log.error("PqdData数据拆分失败", e);
throw new RuntimeException("PqdData数据拆分失败", e);
}
return result;
}
private Map<String, Object> extractFieldValues(PqdData pqdData) {
Map<String, Object> fieldValues = new HashMap<>();
Field[] fields = PqdData.class.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
try {
Object value = field.get(pqdData);
if (value != null) {
fieldValues.put(field.getName(), value);
}
} catch (IllegalAccessException e) {
log.warn("获取字段 {} 的值失败", field.getName(), e);
}
}
return fieldValues;
}
private boolean isCommonField(String fieldName) {
Set<String> commonFields = new HashSet<>(Arrays.asList(
"time", "lineId", "phasicType", "valueType", "clDid",
"process", "qualityFlag"
));
return commonFields.contains(fieldName);
}
private void createAndAddTargetData(List<Object> dataList, String tableName,
PqdData pqdData, String targetField, Object value) {
switch (tableName.toLowerCase()) {
case "data_v":
dataList.add(createRStatDataVD(pqdData, targetField, value));
break;
case "data_i":
dataList.add(createRStatDataID(pqdData, targetField, value));
break;
case "data_flicker":
dataList.add(createRStatDataFlicker(pqdData, targetField, value));
break;
case "data_fluc":
dataList.add(createRStatDataFluc(pqdData, targetField, value));
break;
case "data_harmphasic_i":
dataList.add(createRStatDataHarmphasicI(pqdData, targetField, value));
break;
case "data_harmphasic_v":
dataList.add(createRStatDataHarmphasicV(pqdData, targetField, value));
break;
case "data_harmpower_p":
dataList.add(createRStatDataHarmpowerP(pqdData, targetField, value));
break;
case "data_harmpower_q":
dataList.add(createRStatDataHarmpowerQ(pqdData, targetField, value));
break;
case "data_harmpower_s":
dataList.add(createRStatDataHarmpowerS(pqdData, targetField, value));
break;
case "data_harmrate_v":
dataList.add(createRStatDataHarmrateV(pqdData, targetField, value));
break;
case "data_harmrate_i":
dataList.add(createRStatDataHarmrateI(pqdData, targetField, value));
break;
case "data_inharm_v":
dataList.add(createRStatDataInharmV(pqdData, targetField, value));
break;
case "data_plt":
dataList.add(createRStatDataPlt(pqdData, targetField, value));
break;
default:
log.warn("不支持的目标表: {}", tableName);
break;
}
}
private Object createRStatDataVD(PqdData pqdData, String targetField, Object value) {
DataV data = new DataV();
data.setTime(pqdData.getTime());
data.setLineId(pqdData.getLineId());
data.setPhaseType(pqdData.getPhaseType());
data.setValueType(pqdData.getValueType());
data.setClDid(pqdData.getClDid());
data.setProcess(pqdData.getProcess());
data.setQualityFlag("0");
setFieldValue(data, targetField, value);
return data;
}
private Object createRStatDataID(PqdData pqdData, String targetField, Object value) {
DataI data = new DataI();
data.setTime(pqdData.getTime());
data.setLineId(pqdData.getLineId());
data.setValueType(pqdData.getPhaseType());
data.setQualityFlag("0");
setFieldValue(data, targetField, value);
return data;
}
private Object createRStatDataFlicker(PqdData pqdData, String targetField, Object value) {
DataFlicker data = new DataFlicker();
data.setTime(pqdData.getTime());
data.setLineId(pqdData.getLineId());
data.setPhaseType(pqdData.getPhaseType());
data.setValueType(pqdData.getValueType());
data.setClDid(pqdData.getClDid());
data.setProcess(pqdData.getProcess());
data.setQualityFlag("0");
setFieldValue(data, targetField, value);
return data;
}
private Object createRStatDataFluc(PqdData pqdData, String targetField, Object value) {
DataFluc data = new DataFluc();
data.setTime(pqdData.getTime());
data.setLineId(pqdData.getLineId());
data.setPhaseType(pqdData.getPhaseType());
data.setValueType(pqdData.getValueType());
data.setClDid(pqdData.getClDid());
data.setProcess(pqdData.getProcess());
data.setQualityFlag("0");
setFieldValue(data, targetField, value);
return data;
}
private Object createRStatDataHarmphasicI(PqdData pqdData, String targetField, Object value) {
DataHarmPhasicI data = new DataHarmPhasicI();
data.setTime(pqdData.getTime());
data.setLineId(pqdData.getLineId());
data.setPhaseType(pqdData.getPhaseType());
data.setValueType(pqdData.getValueType());
data.setClDid(pqdData.getClDid());
data.setProcess(pqdData.getProcess());
data.setQualityFlag("0");
setFieldValue(data, targetField, value);
return data;
}
private Object createRStatDataHarmphasicV(PqdData pqdData, String targetField, Object value) {
DataHarmPhasicV data = new DataHarmPhasicV();
data.setTime(pqdData.getTime());
data.setLineId(pqdData.getLineId());
data.setPhaseType(pqdData.getPhaseType());
data.setValueType(pqdData.getValueType());
data.setClDid(pqdData.getClDid());
data.setProcess(pqdData.getProcess());
data.setQualityFlag("0");
setFieldValue(data, targetField, value);
return data;
}
private Object createRStatDataHarmpowerP(PqdData pqdData, String targetField, Object value) {
DataHarmPowerP data = new DataHarmPowerP();
data.setTime(pqdData.getTime());
data.setLineId(pqdData.getLineId());
data.setPhaseType(pqdData.getPhaseType());
data.setValueType(pqdData.getValueType());
data.setClDid(pqdData.getClDid());
data.setProcess(pqdData.getProcess());
data.setQualityFlag("0");
setFieldValue(data, targetField, value);
return data;
}
private Object createRStatDataHarmpowerQ(PqdData pqdData, String targetField, Object value) {
DataHarmPowerQ data = new DataHarmPowerQ();
data.setTime(pqdData.getTime());
data.setLineId(pqdData.getLineId());
data.setPhaseType(pqdData.getPhaseType());
data.setValueType(pqdData.getValueType());
data.setClDid(pqdData.getClDid());
data.setProcess(pqdData.getProcess());
data.setQualityFlag("0");
setFieldValue(data, targetField, value);
return data;
}
private Object createRStatDataHarmpowerS(PqdData pqdData, String targetField, Object value) {
DataHarmPowerS data = new DataHarmPowerS();
data.setTime(pqdData.getTime());
data.setLineId(pqdData.getLineId());
data.setPhaseType(pqdData.getPhaseType());
data.setValueType(pqdData.getValueType());
data.setClDid(pqdData.getClDid());
data.setProcess(pqdData.getProcess());
data.setQualityFlag("0");
setFieldValue(data, targetField, value);
return data;
}
private Object createRStatDataHarmrateV(PqdData pqdData, String targetField, Object value) {
DataHarmRateV data = new DataHarmRateV();
data.setTime(pqdData.getTime());
data.setLineId(pqdData.getLineId());
data.setPhaseType(pqdData.getPhaseType());
data.setValueType(pqdData.getValueType());
data.setClDid(pqdData.getClDid());
data.setProcess(pqdData.getProcess());
data.setQualityFlag("0");
setFieldValue(data, targetField, value);
return data;
}
private Object createRStatDataHarmrateI(PqdData pqdData, String targetField, Object value) {
DataHarmRateI data = new DataHarmRateI();
data.setTime(pqdData.getTime());
data.setLineId(pqdData.getLineId());
data.setPhaseType(pqdData.getPhaseType());
data.setValueType(pqdData.getValueType());
data.setClDid(pqdData.getClDid());
data.setProcess(pqdData.getProcess());
data.setQualityFlag("0");
setFieldValue(data, targetField, value);
return data;
}
private Object createRStatDataInharmV(PqdData pqdData, String targetField, Object value) {
DataInHarmV data = new DataInHarmV();
data.setTime(pqdData.getTime());
data.setLineId(pqdData.getLineId());
data.setPhaseType(pqdData.getPhaseType());
data.setValueType(pqdData.getValueType());
data.setClDid(pqdData.getClDid());
data.setProcess(pqdData.getProcess());
data.setQualityFlag("0");
setFieldValue(data, targetField, value);
return data;
}
private Object createRStatDataPlt(PqdData pqdData, String targetField, Object value) {
DataPlt data = new DataPlt();
data.setTime(pqdData.getTime());
data.setLineId(pqdData.getLineId());
data.setPhaseType(pqdData.getPhaseType());
data.setValueType(pqdData.getValueType());
data.setClDid(pqdData.getClDid());
data.setProcess(pqdData.getProcess());
data.setQualityFlag("0");
setFieldValue(data, targetField, value);
return data;
}
private void setFieldValue(Object obj, String fieldName, Object value) {
try {
String camelCaseFieldName = toCamelCase(fieldName);
Field field = obj.getClass().getDeclaredField(camelCaseFieldName);
field.setAccessible(true);
field.set(obj, value);
} catch (NoSuchFieldException | IllegalAccessException e) {
log.warn("设置字段 {} 的值失败", fieldName, e);
}
}
public static String toCamelCase(String input) {
if (input == null || input.isEmpty()) {
return input;
}
StringBuilder result = new StringBuilder();
boolean toUpper = false;
for (char c : input.toCharArray()) {
if (c == '_') {
toUpper = true;
} else {
if (toUpper) {
result.append(Character.toUpperCase(c));
toUpper = false;
} else {
result.append(c);
}
}
}
// 确保首字母小写以匹配Java实体字段命名规范
if (result.length() > 0 && Character.isUpperCase(result.charAt(0))) {
result.setCharAt(0, Character.toLowerCase(result.charAt(0)));
}
return result.toString();
}
private EleEpdPqd copyEleEpdPqd(EleEpdPqd source) {
if (source == null) {
return null;
}
EleEpdPqd target = new EleEpdPqd();
BeanUtils.copyProperties(source, target);
return target;
}
}

View File

@@ -7,7 +7,12 @@ import com.github.tocrhz.mqtt.annotation.MqttSubscribe;
import com.github.tocrhz.mqtt.annotation.NamedValue; import com.github.tocrhz.mqtt.annotation.NamedValue;
import com.github.tocrhz.mqtt.annotation.Payload; import com.github.tocrhz.mqtt.annotation.Payload;
import com.github.tocrhz.mqtt.publisher.MqttPublisher; import com.github.tocrhz.mqtt.publisher.MqttPublisher;
import com.njcn.csdevice.api.CsLineFeignClient;
import com.njcn.csdevice.api.CsLineTopologyFeignClient;
import com.njcn.csdevice.api.DevCapacityFeignClient; import com.njcn.csdevice.api.DevCapacityFeignClient;
import com.njcn.csdevice.api.fallback.CsLineTopologyClientFallbackFactory;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.pojo.vo.AppTopologyDiagramVO;
import com.njcn.csharmonic.param.CommonStatisticalQueryParam; import com.njcn.csharmonic.param.CommonStatisticalQueryParam;
import com.njcn.csharmonic.param.FrequencyStatisticalQueryParam; import com.njcn.csharmonic.param.FrequencyStatisticalQueryParam;
import com.njcn.csharmonic.pojo.dto.RealTimeDataDTO; import com.njcn.csharmonic.pojo.dto.RealTimeDataDTO;
@@ -21,6 +26,10 @@ import com.njcn.csharmonic.service.TemperatureService;
import com.njcn.influx.pojo.dto.StatisticalDataDTO; import com.njcn.influx.pojo.dto.StatisticalDataDTO;
import com.njcn.redis.utils.RedisUtil; import com.njcn.redis.utils.RedisUtil;
import com.njcn.system.api.CsStatisticalSetFeignClient; import com.njcn.system.api.CsStatisticalSetFeignClient;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.enums.DicDataTypeEnum;
import com.njcn.system.pojo.po.DictData;
import com.njcn.system.pojo.po.EleEpdPqd; import com.njcn.system.pojo.po.EleEpdPqd;
import com.njcn.zlevent.api.FileFeignClient; import com.njcn.zlevent.api.FileFeignClient;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@@ -33,6 +42,7 @@ import org.springframework.util.CollectionUtils;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.*; import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@@ -56,6 +66,9 @@ public class MqttMessageHandler {
private final DecimalFormat df = new DecimalFormat("#0.000"); private final DecimalFormat df = new DecimalFormat("#0.000");
private final FileFeignClient fileFeignClient; private final FileFeignClient fileFeignClient;
private final CsEventPOService csEventPOService; private final CsEventPOService csEventPOService;
private final CsLineTopologyFeignClient csLineTopologyClient;
private final CsLineFeignClient csLineFeignClient;
private final DicDataFeignClient dicDataFeignClient;
/** /**
* 实时数据应答 * 实时数据应答
@@ -248,7 +261,7 @@ public class MqttMessageHandler {
}); });
//过滤M //过滤T
List<ThdDataVO> m = tempList.stream().filter(temp -> Objects.equals(temp.getPhase(), "T")).collect(Collectors.toList()); List<ThdDataVO> m = tempList.stream().filter(temp -> Objects.equals(temp.getPhase(), "T")).collect(Collectors.toList());
m.stream().forEach(temp -> { m.stream().forEach(temp -> {
Stream.of("A", "B", "C").forEach(phase -> { Stream.of("A", "B", "C").forEach(phase -> {
@@ -260,41 +273,134 @@ public class MqttMessageHandler {
}); });
//如果是基础数据则添加拓扑图的数据 //如果是基础数据则添加拓扑图的数据
if (Objects.equals("fc8c86dbc3f2d9810f5cd8f53c295415", typeId)) { if (Objects.equals("fc8c86dbc3f2d9810f5cd8f53c295415", typeId)) {
List<ThdDataVO> apfThdI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_ThdA_Load(%)")).collect(Collectors.toList());
Map<String, List<ThdDataVO>> collect3 = apfThdI.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId));
collect3.forEach((k, v) -> {
if (!CollectionUtil.isEmpty(v)) {
double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble();
ThdDataVO thdDataVO = new ThdDataVO();
BeanUtils.copyProperties(v.get(0), thdDataVO);
thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble)));
thdDataVO.setPhase("avg");
result.add(thdDataVO);
}
});
List<ThdDataVO> apfRmsI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_RmsI_TolOut(A)")).collect(Collectors.toList()); List<ThdDataVO> apfRmsI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_RmsI_TolOut(A)")).collect(Collectors.toList());
Map<String, List<ThdDataVO>> collect2 = apfRmsI.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId));
collect2.forEach((k, v) -> {
if (!CollectionUtil.isEmpty(v)) {
double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble();
ThdDataVO thdDataVO = new ThdDataVO();
BeanUtils.copyProperties(v.get(0), thdDataVO);
thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble)));
thdDataVO.setPhase("avg");
result.add(thdDataVO);
}
});
List<ThdDataVO> apfThdISys = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_ThdA_Sys(%)")).collect(Collectors.toList());
Map<String, List<ThdDataVO>> collect4 = apfThdISys.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId));
collect4.forEach((k, v) -> {
if (!CollectionUtil.isEmpty(v)) {
double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble();
ThdDataVO thdDataVO = new ThdDataVO();
BeanUtils.copyProperties(v.get(0), thdDataVO);
thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble)));
thdDataVO.setPhase("avg");
result.add(thdDataVO);
List<DictData> dictData = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.LINE_POSITION.getCode()).getData();
Map<String, DictData> codeToDictData = dictData.stream().collect(Collectors.toMap(DictData::getId, Function.identity()));
//添加拓扑图上自定义的指标
//根据设备id查询拓扑图
AppTopologyDiagramVO vo = csLineTopologyClient.queryTopologyDiagram(devId).getData();
vo.getAppsLineTopologyDiagramPO().forEach(item -> {
String linePositionCode = codeToDictData.get(item.getLinePostion()).getCode();
if (Objects.equals(linePositionCode, DicDataEnum.OUTPUT_SIDE.getCode())) {
//输出侧
if (item.getTarget() != null && !item.getTarget().isEmpty()) {
List<ThdDataVO> l1 = new ArrayList<>();
//根据指标查询
List<EleEpdPqd> data1 = csStatisticalSetFeignClient.queryStatisticalSelect(item.getTarget()).getData();
data1.forEach(temp -> {
CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam();
commonStatisticalQueryParam.setDevId(devId);
commonStatisticalQueryParam.setStatisticalId(temp.getId());
commonStatisticalQueryParam.setValueType("avg");
List<ThdDataVO> listFuture = stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam);
l1.addAll(listFuture);
});
Map<String, List<ThdDataVO>> collect3 = l1.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId));
collect3.forEach((k, v) -> {
if (!CollectionUtil.isEmpty(v)) {
double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble();
ThdDataVO thdDataVO = new ThdDataVO();
BeanUtils.copyProperties(v.get(0), thdDataVO);
thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble)));
thdDataVO.setPhase("avg");
result.add(thdDataVO);
}
});
} else {
Map<String, List<ThdDataVO>> collect2 = apfRmsI.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId));
collect2.forEach((k, v) -> {
if (!CollectionUtil.isEmpty(v)) {
double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble();
ThdDataVO thdDataVO = new ThdDataVO();
BeanUtils.copyProperties(v.get(0), thdDataVO);
thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble)));
thdDataVO.setPhase("avg");
result.add(thdDataVO);
}
});
}
} else if (Objects.equals(linePositionCode, DicDataEnum.GRID_SIDE.getCode())) {
//电网侧
if (item.getTarget() != null && !item.getTarget().isEmpty()) {
//根据指标查询
List<ThdDataVO> l1 = new ArrayList<>();
//根据指标查询
List<EleEpdPqd> data1 = csStatisticalSetFeignClient.queryStatisticalSelect(item.getTarget()).getData();
data1.forEach(temp -> {
CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam();
commonStatisticalQueryParam.setDevId(devId);
commonStatisticalQueryParam.setStatisticalId(temp.getId());
commonStatisticalQueryParam.setValueType("avg");
List<ThdDataVO> listFuture = stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam);
l1.addAll(listFuture);
});
Map<String, List<ThdDataVO>> collect3 = l1.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId));
collect3.forEach((k, v) -> {
if (!CollectionUtil.isEmpty(v)) {
double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble();
ThdDataVO thdDataVO = new ThdDataVO();
BeanUtils.copyProperties(v.get(0), thdDataVO);
thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble)));
thdDataVO.setPhase("avg");
result.add(thdDataVO);
}
});
} else {
List<ThdDataVO> apfThdISys = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_ThdA_Sys(%)")).collect(Collectors.toList());
Map<String, List<ThdDataVO>> collect4 = apfThdISys.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId));
collect4.forEach((k, v) -> {
if (!CollectionUtil.isEmpty(v)) {
double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble();
ThdDataVO thdDataVO = new ThdDataVO();
BeanUtils.copyProperties(v.get(0), thdDataVO);
thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble)));
thdDataVO.setPhase("avg");
result.add(thdDataVO);
}
});
}
} else if (Objects.equals(linePositionCode, DicDataEnum.LOAD_SIDE.getCode())) {
//负载侧
if (item.getTarget() != null && !item.getTarget().isEmpty()) {
//根据指标查询
List<ThdDataVO> l1 = new ArrayList<>();
//根据指标查询
List<EleEpdPqd> data1 = csStatisticalSetFeignClient.queryStatisticalSelect(item.getTarget()).getData();
data1.forEach(temp -> {
CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam();
commonStatisticalQueryParam.setDevId(devId);
commonStatisticalQueryParam.setStatisticalId(temp.getId());
commonStatisticalQueryParam.setValueType("avg");
List<ThdDataVO> listFuture = stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam);
l1.addAll(listFuture);
});
Map<String, List<ThdDataVO>> collect3 = l1.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId));
collect3.forEach((k, v) -> {
if (!CollectionUtil.isEmpty(v)) {
double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble();
ThdDataVO thdDataVO = new ThdDataVO();
BeanUtils.copyProperties(v.get(0), thdDataVO);
thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble)));
thdDataVO.setPhase("avg");
result.add(thdDataVO);
}
});
} else {
List<ThdDataVO> apfThdI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_ThdA_Load(%)")).collect(Collectors.toList());
Map<String, List<ThdDataVO>> collect3 = apfThdI.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId));
collect3.forEach((k, v) -> {
if (!CollectionUtil.isEmpty(v)) {
double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble();
ThdDataVO thdDataVO = new ThdDataVO();
BeanUtils.copyProperties(v.get(0), thdDataVO);
thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble)));
thdDataVO.setPhase("avg");
result.add(thdDataVO);
}
});
}
} }
}); });
Double capacity = devCapacityFeignClient.getDevCapacity(devId).getData(); Double capacity = devCapacityFeignClient.getDevCapacity(devId).getData();
@@ -323,7 +429,6 @@ public class MqttMessageHandler {
publisher.send("/zl/devData/" + devId + "/" + typeId, topoDataJson, 1, false); publisher.send("/zl/devData/" + devId + "/" + typeId, topoDataJson, 1, false);
} }
public String getCldidName(String cldid) { public String getCldidName(String cldid) {
switch (cldid) { switch (cldid) {

View File

@@ -125,7 +125,7 @@ public class TestController {
collect.forEach((tempPhase,byNameMap)->{ collect.forEach((tempPhase,byNameMap)->{
//最小值 //最小值
InfluxQueryWrapper influxQueryWrapperMin = new InfluxQueryWrapper(PqdData.class, clazz); InfluxQueryWrapper influxQueryWrapperMin = new InfluxQueryWrapper(PqdData.class, clazz);
influxQueryWrapperMin.regular(PqdData::getLineId, lineIndex).eq(InfluxDBTableConstant.VALUE_TYPE, "min") influxQueryWrapperMin.regular(PqdData::getLineId, lineIndex).eq(InfluxDBTableConstant.VALUE_TYPE, "MIN")
.eq(InfluxDBTableConstant.PHASIC_TYPE,tempPhase); .eq(InfluxDBTableConstant.PHASIC_TYPE,tempPhase);
// .eq(InfluxDBTableConstant.IS_ABNORMAL, 0); // .eq(InfluxDBTableConstant.IS_ABNORMAL, 0);
@@ -156,7 +156,7 @@ public class TestController {
//最大值 //最大值
InfluxQueryWrapper influxQueryWrapperMax = new InfluxQueryWrapper(PqdData.class, clazz); InfluxQueryWrapper influxQueryWrapperMax = new InfluxQueryWrapper(PqdData.class, clazz);
influxQueryWrapperMax.regular(PqdData::getLineId, lineIndex).eq(InfluxDBTableConstant.VALUE_TYPE, "max") influxQueryWrapperMax.regular(PqdData::getLineId, lineIndex).eq(InfluxDBTableConstant.VALUE_TYPE, "MAX")
.eq(InfluxDBTableConstant.PHASIC_TYPE,tempPhase); .eq(InfluxDBTableConstant.PHASIC_TYPE,tempPhase);
// .eq(InfluxDBTableConstant.IS_ABNORMAL, 0); // .eq(InfluxDBTableConstant.IS_ABNORMAL, 0);
@@ -186,7 +186,7 @@ public class TestController {
//平均值 //平均值
InfluxQueryWrapper influxQueryWrapperAvg = new InfluxQueryWrapper(PqdData.class, clazz); InfluxQueryWrapper influxQueryWrapperAvg = new InfluxQueryWrapper(PqdData.class, clazz);
influxQueryWrapperAvg.regular(PqdData::getLineId, lineIndex).eq(InfluxDBTableConstant.VALUE_TYPE, "avg") influxQueryWrapperAvg.regular(PqdData::getLineId, lineIndex).eq(InfluxDBTableConstant.VALUE_TYPE, "AVG")
.eq(InfluxDBTableConstant.PHASIC_TYPE,tempPhase); .eq(InfluxDBTableConstant.PHASIC_TYPE,tempPhase);
// .eq(InfluxDBTableConstant.IS_ABNORMAL, 0); // .eq(InfluxDBTableConstant.IS_ABNORMAL, 0);
@@ -216,7 +216,7 @@ public class TestController {
//CP95 //CP95
InfluxQueryWrapper influxQueryWrapperCp95 = new InfluxQueryWrapper(PqdData.class, clazz); InfluxQueryWrapper influxQueryWrapperCp95 = new InfluxQueryWrapper(PqdData.class, clazz);
influxQueryWrapperCp95.regular(PqdData::getLineId, lineIndex).eq(InfluxDBTableConstant.VALUE_TYPE, "avg") influxQueryWrapperCp95.regular(PqdData::getLineId, lineIndex).eq(InfluxDBTableConstant.VALUE_TYPE, "AVG")
.eq(InfluxDBTableConstant.PHASIC_TYPE,tempPhase); .eq(InfluxDBTableConstant.PHASIC_TYPE,tempPhase);
// .eq(InfluxDBTableConstant.IS_ABNORMAL, 0); // .eq(InfluxDBTableConstant.IS_ABNORMAL, 0);

View File

@@ -1,348 +1,348 @@
package com.njcn.csreport.job; //package com.njcn.csreport.job;
//
import cn.hutool.extra.spring.SpringUtil; //import cn.hutool.extra.spring.SpringUtil;
import com.github.jeffreyning.mybatisplus.service.IMppService; //import com.github.jeffreyning.mybatisplus.service.IMppService;
import com.njcn.common.pojo.enums.response.CommonResponseEnum; //import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.utils.HarmonicTimesUtil; //import com.njcn.common.utils.HarmonicTimesUtil;
import com.njcn.common.utils.HttpResultUtil; //import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.api.CsLedgerFeignClient; //import com.njcn.csdevice.api.CsLedgerFeignClient;
import com.njcn.csdevice.pojo.dto.LineParamDTO; //import com.njcn.csdevice.pojo.dto.LineParamDTO;
import com.njcn.csdevice.pojo.po.CsLedger; //import com.njcn.csdevice.pojo.po.CsLedger;
//
import com.njcn.csreport.enums.ReportTableEnum; //import com.njcn.csreport.enums.ReportTableEnum;
import com.njcn.csreport.service.RStatDataVDService; //import com.njcn.csreport.service.RStatDataVDService;
import com.njcn.influx.constant.InfluxDbSqlConstant; //import com.njcn.influx.constant.InfluxDbSqlConstant;
import com.njcn.influx.imapper.CommonMapper; //import com.njcn.influx.imapper.CommonMapper;
import com.njcn.influx.imapper.PqdDataMapper; //import com.njcn.influx.imapper.PqdDataMapper;
import com.njcn.influx.imapper.day.GovernReportMapper; //import com.njcn.influx.imapper.day.GovernReportMapper;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant; //import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
import com.njcn.influx.pojo.po.DataV; //import com.njcn.influx.pojo.po.DataV;
import com.njcn.influx.pojo.po.cs.PqdData; //import com.njcn.influx.pojo.po.cs.PqdData;
import com.njcn.influx.query.InfluxQueryWrapper; //import com.njcn.influx.query.InfluxQueryWrapper;
import com.njcn.system.api.CsStatisticalSetFeignClient; //import com.njcn.system.api.CsStatisticalSetFeignClient;
import com.njcn.system.api.DicDataFeignClient; //import com.njcn.system.api.DicDataFeignClient;
//
import com.njcn.system.api.EpdFeignClient; //import com.njcn.system.api.EpdFeignClient;
import com.njcn.system.enums.DicDataEnum; //import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.po.DictData; //import com.njcn.system.pojo.po.DictData;
import com.njcn.system.pojo.po.EleEpdPqd; //import com.njcn.system.pojo.po.EleEpdPqd;
import com.njcn.system.pojo.vo.EleEpdPqdListVO; //import com.njcn.system.pojo.vo.EleEpdPqdListVO;
import lombok.RequiredArgsConstructor; //import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; //import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.annotation.EnableScheduling; //import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; //import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
//
import java.lang.reflect.Field; //import java.lang.reflect.Field;
import java.time.LocalDate; //import java.time.LocalDate;
import java.time.LocalDateTime; //import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; //import java.time.format.DateTimeFormatter;
import java.util.ArrayList; //import java.util.ArrayList;
import java.util.List; //import java.util.List;
import java.util.Map; //import java.util.Map;
import java.util.Objects; //import java.util.Objects;
import java.util.stream.Collectors; //import java.util.stream.Collectors;
//
/** ///**
* Description: // * Description:
* Date: 2024/1/18 10:15【需求编号】 // * Date: 2024/1/18 10:15【需求编号】
* // *
* @author clam // * @author clam
* @version V1.0.0 // * @version V1.0.0
*/ // */
@Component //@Component
@EnableScheduling //@EnableScheduling
@RequiredArgsConstructor //@RequiredArgsConstructor
@Slf4j //@Slf4j
public class ReportCovertJob { //public class ReportCovertJob {
//
private final CsLedgerFeignClient csLedgerFeignClient; // private final CsLedgerFeignClient csLedgerFeignClient;
private final DicDataFeignClient dicDataFeignClient; // private final DicDataFeignClient dicDataFeignClient;
private final EpdFeignClient epdFeignClient; // private final EpdFeignClient epdFeignClient;
private final GovernReportMapper reportMapper; // private final GovernReportMapper reportMapper;
private final RStatDataVDService rStatDataVDService; // private final RStatDataVDService rStatDataVDService;
//
private final static String SERVICE_PACKAGE_PREFIX = "com.njcn.csreport.service."; // private final static String SERVICE_PACKAGE_PREFIX = "com.njcn.csreport.service.";
private final static String ENTITY_PACKAGE_PREFIX = "com.njcn.csreport.pojo.po."; // private final static String ENTITY_PACKAGE_PREFIX = "com.njcn.csreport.pojo.po.";
private final static String SERVICE_SUFFIX = "Service"; // private final static String SERVICE_SUFFIX = "Service";
//
//
/** // /**
* 每天同步influxdb数据到mysql // * 每天同步influxdb数据到mysql
* // *
* @date 2024/3/5 // * @date 2024/3/5
*/ // */
@Scheduled(cron = "0 0 1 * * ? ") // @Scheduled(cron = "0 0 1 * * ? ")
public void executeEvent() throws ClassNotFoundException { // public void executeEvent() throws ClassNotFoundException {
DateTimeFormatter formatter1 = DateTimeFormatter.ISO_DATE; // DateTimeFormatter formatter1 = DateTimeFormatter.ISO_DATE;
// 获取当前日期 // // 获取当前日期
LocalDate today = LocalDate.now(); // LocalDate today = LocalDate.now();
//
//
// 计算前一天的日期 // // 计算前一天的日期
LocalDate yesterday = today.minusDays(1); // LocalDate yesterday = today.minusDays(1);
// 获取前一天的开始时间00:00:00 // // 获取前一天的开始时间00:00:00
LocalDateTime startOfYesterday = yesterday.atStartOfDay(); // LocalDateTime startOfYesterday = yesterday.atStartOfDay();
// 获取前一天的结束时间23:59:59 // // 获取前一天的结束时间23:59:59
LocalDateTime endOfYesterday = yesterday.plusDays(1).atStartOfDay().minusSeconds(1); // LocalDateTime endOfYesterday = yesterday.plusDays(1).atStartOfDay().minusSeconds(1);
//
// 定义时间格式 // // 定义时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//
// 格式化时间为字符串 // // 格式化时间为字符串
String startTime = startOfYesterday.format(formatter); // String startTime = startOfYesterday.format(formatter);
String endTime = endOfYesterday.format(formatter); // String endTime = endOfYesterday.format(formatter);
// String startTime ="2024-07-31 00:00:00"; //// String startTime ="2024-07-31 00:00:00";
// String endTime ="2024-09-20 23:00:00"; //// String endTime ="2024-09-20 23:00:00";
List<CsLedger> data = csLedgerFeignClient.queryLine(new LineParamDTO()).getData(); // List<CsLedger> data = csLedgerFeignClient.queryLine(new LineParamDTO()).getData();
List<String> lineIndex = data.stream().map(CsLedger::getId).collect(Collectors.toList()); // List<String> lineIndex = data.stream().map(CsLedger::getId).collect(Collectors.toList());
// List<String> lineIndex = Stream.of("00B78D016AB32","00B78D016AB51").collect(Collectors.toList()); //// List<String> lineIndex = Stream.of("00B78D016AB32","00B78D016AB51").collect(Collectors.toList());
//
//查询电能质量数据指标 // //查询电能质量数据指标
DictData pqd = dicDataFeignClient.getDicDataByCode(DicDataEnum.PQD.getCode()).getData(); // DictData pqd = dicDataFeignClient.getDicDataByCode(DicDataEnum.PQD.getCode()).getData();
List<DictData> tableNameList = dicDataFeignClient.getDicDataByTypeCode("Data_Day").getData(); // List<DictData> tableNameList = dicDataFeignClient.getDicDataByTypeCode("Data_Day").getData();
Map<String, String> tableMap = tableNameList.stream().collect(Collectors.toMap(DictData::getId, DictData::getCode, (code, code2) -> code)); // Map<String, String> tableMap = tableNameList.stream().collect(Collectors.toMap(DictData::getId, DictData::getCode, (code, code2) -> code));
//
//
List<EleEpdPqdListVO> eleEpdPqdListVOList = epdFeignClient.selectAll().getData(); // List<EleEpdPqdListVO> eleEpdPqdListVOList = epdFeignClient.selectAll().getData();
EleEpdPqdListVO eleEpdPqdListVO = eleEpdPqdListVOList.stream().filter(temp -> Objects.equals(temp.getDataType(), pqd.getId())).collect(Collectors.toList()).get(0); // EleEpdPqdListVO eleEpdPqdListVO = eleEpdPqdListVOList.stream().filter(temp -> Objects.equals(temp.getDataType(), pqd.getId())).collect(Collectors.toList()).get(0);
//
//
Map<String, List<EleEpdPqd>> eleEpdMap = eleEpdPqdListVO.getEleEpdPqdVOS().stream().filter(temp -> StringUtils.isNotEmpty(temp.getOtherName()) // Map<String, List<EleEpdPqd>> eleEpdMap = eleEpdPqdListVO.getEleEpdPqdVOS().stream().filter(temp -> StringUtils.isNotEmpty(temp.getOtherName())
&& StringUtils.isNotEmpty(temp.getResourcesId())) // && StringUtils.isNotEmpty(temp.getResourcesId()))
.collect(Collectors.groupingBy(EleEpdPqd::getResourcesId));//不能全表表分组查,根据映射的 // .collect(Collectors.groupingBy(EleEpdPqd::getResourcesId));//不能全表表分组查,根据映射的
//
for (Map.Entry<String, List<EleEpdPqd>> entry : eleEpdMap.entrySet()) { // for (Map.Entry<String, List<EleEpdPqd>> entry : eleEpdMap.entrySet()) {
String k = entry.getKey(); // String k = entry.getKey();
List<EleEpdPqd> v = entry.getValue(); // List<EleEpdPqd> v = entry.getValue();
String tableName = tableMap.get(k); // String tableName = tableMap.get(k);
List result = new ArrayList<>(); // List result = new ArrayList<>();
Class clazz = Class.forName(ENTITY_PACKAGE_PREFIX + ReportTableEnum.getEntityName(tableName)); // Class clazz = Class.forName(ENTITY_PACKAGE_PREFIX + ReportTableEnum.getEntityName(tableName));
IMppService bean = (IMppService) SpringUtil.getBean(Class.forName(SERVICE_PACKAGE_PREFIX+ReportTableEnum.getEntityName(tableName)+SERVICE_SUFFIX)); // IMppService bean = (IMppService) SpringUtil.getBean(Class.forName(SERVICE_PACKAGE_PREFIX+ReportTableEnum.getEntityName(tableName)+SERVICE_SUFFIX));
//
//由于epd配置表ABC三项对应指标一样这里做去重处理由于功率表功率和三项总功率都对应P只是项别不一一样因此M相要和,A,B,C相分开计算 // //由于epd配置表ABC三项对应指标一样这里做去重处理由于功率表功率和三项总功率都对应P只是项别不一一样因此M相要和,A,B,C相分开计算
Map<String, Map<String, List<EleEpdPqd>>> collect = v.stream().collect(Collectors.groupingBy(EleEpdPqd::getPhase, Collectors.groupingBy(EleEpdPqd::getName))); // Map<String, Map<String, List<EleEpdPqd>>> collect = v.stream().collect(Collectors.groupingBy(EleEpdPqd::getPhase, Collectors.groupingBy(EleEpdPqd::getName)));
//
collect.forEach((tempPhase,byNameMap)->{ // collect.forEach((tempPhase,byNameMap)->{
//最小值 // //最小值
InfluxQueryWrapper influxQueryWrapperMin = new InfluxQueryWrapper(PqdData.class, clazz); // InfluxQueryWrapper influxQueryWrapperMin = new InfluxQueryWrapper(PqdData.class, clazz);
influxQueryWrapperMin.regular(PqdData::getLineId, lineIndex).eq(InfluxDBTableConstant.VALUE_TYPE, "min") // influxQueryWrapperMin.regular(PqdData::getLineId, lineIndex).eq(InfluxDBTableConstant.VALUE_TYPE, "min")
.eq(InfluxDBTableConstant.PHASIC_TYPE,tempPhase); // .eq(InfluxDBTableConstant.PHASIC_TYPE,tempPhase);
// .eq(InfluxDBTableConstant.IS_ABNORMAL, 0); //// .eq(InfluxDBTableConstant.IS_ABNORMAL, 0);
//
//
byNameMap.forEach((name, eleEpdPqdList) -> { // byNameMap.forEach((name, eleEpdPqdList) -> {
EleEpdPqd tempEleEpdPqd = eleEpdPqdList.get(0); // EleEpdPqd tempEleEpdPqd = eleEpdPqdList.get(0);
if (Objects.nonNull(tempEleEpdPqd.getHarmStart()) && Objects.nonNull(tempEleEpdPqd.getHarmEnd())) { // if (Objects.nonNull(tempEleEpdPqd.getHarmStart()) && Objects.nonNull(tempEleEpdPqd.getHarmEnd())) {
//0-49转成1-50 // //0-49转成1-50
if(tempEleEpdPqd.getHarmStart()==0){ // if(tempEleEpdPqd.getHarmStart()==0){
tempEleEpdPqd.setHarmStart(tempEleEpdPqd.getHarmStart()+1); // tempEleEpdPqd.setHarmStart(tempEleEpdPqd.getHarmStart()+1);
tempEleEpdPqd.setHarmEnd(tempEleEpdPqd.getHarmEnd()+1); // tempEleEpdPqd.setHarmEnd(tempEleEpdPqd.getHarmEnd()+1);
} // }
for (int i = tempEleEpdPqd.getHarmStart(); i < tempEleEpdPqd.getHarmEnd() + 1; i++) { // for (int i = tempEleEpdPqd.getHarmStart(); i < tempEleEpdPqd.getHarmEnd() + 1; i++) {
influxQueryWrapperMin.min(tempEleEpdPqd.getName() + "_" + i, tempEleEpdPqd.getOtherName() + "_" + i); // influxQueryWrapperMin.min(tempEleEpdPqd.getName() + "_" + i, tempEleEpdPqd.getOtherName() + "_" + i);
} // }
} else { // } else {
influxQueryWrapperMin.min(tempEleEpdPqd.getName(), tempEleEpdPqd.getOtherName()); // influxQueryWrapperMin.min(tempEleEpdPqd.getName(), tempEleEpdPqd.getOtherName());
} // }
//
}); // });
//
influxQueryWrapperMin.groupBy(InfluxDBTableConstant.LINE_ID) // influxQueryWrapperMin.groupBy(InfluxDBTableConstant.LINE_ID)
.groupBy(InfluxDBTableConstant.PHASIC_TYPE) // .groupBy(InfluxDBTableConstant.PHASIC_TYPE)
.groupBy(InfluxDBTableConstant.VALUE_TYPE) // .groupBy(InfluxDBTableConstant.VALUE_TYPE)
.between(InfluxDBTableConstant.TIME, startTime, endTime); // .between(InfluxDBTableConstant.TIME, startTime, endTime);
List list1 = reportMapper.selectByQueryWrapper(influxQueryWrapperMin); // List list1 = reportMapper.selectByQueryWrapper(influxQueryWrapperMin);
//
//
//最大值 // //最大值
InfluxQueryWrapper influxQueryWrapperMax = new InfluxQueryWrapper(PqdData.class, clazz); // InfluxQueryWrapper influxQueryWrapperMax = new InfluxQueryWrapper(PqdData.class, clazz);
influxQueryWrapperMax.regular(PqdData::getLineId, lineIndex).eq(InfluxDBTableConstant.VALUE_TYPE, "max") // influxQueryWrapperMax.regular(PqdData::getLineId, lineIndex).eq(InfluxDBTableConstant.VALUE_TYPE, "max")
.eq(InfluxDBTableConstant.PHASIC_TYPE,tempPhase); // .eq(InfluxDBTableConstant.PHASIC_TYPE,tempPhase);
// .eq(InfluxDBTableConstant.IS_ABNORMAL, 0); //// .eq(InfluxDBTableConstant.IS_ABNORMAL, 0);
//
//
byNameMap.forEach((name, eleEpdPqdList) -> { // byNameMap.forEach((name, eleEpdPqdList) -> {
EleEpdPqd tempEleEpdPqd = eleEpdPqdList.get(0); // EleEpdPqd tempEleEpdPqd = eleEpdPqdList.get(0);
if (Objects.nonNull(tempEleEpdPqd.getHarmStart()) && Objects.nonNull(tempEleEpdPqd.getHarmEnd())) { // if (Objects.nonNull(tempEleEpdPqd.getHarmStart()) && Objects.nonNull(tempEleEpdPqd.getHarmEnd())) {
//0-49转成1-50 // //0-49转成1-50
if(tempEleEpdPqd.getHarmStart()==0){ // if(tempEleEpdPqd.getHarmStart()==0){
tempEleEpdPqd.setHarmStart(tempEleEpdPqd.getHarmStart()+1); // tempEleEpdPqd.setHarmStart(tempEleEpdPqd.getHarmStart()+1);
tempEleEpdPqd.setHarmEnd(tempEleEpdPqd.getHarmEnd()+1); // tempEleEpdPqd.setHarmEnd(tempEleEpdPqd.getHarmEnd()+1);
} // }
for (int i = tempEleEpdPqd.getHarmStart(); i < tempEleEpdPqd.getHarmEnd() + 1; i++) { // for (int i = tempEleEpdPqd.getHarmStart(); i < tempEleEpdPqd.getHarmEnd() + 1; i++) {
influxQueryWrapperMax.max(tempEleEpdPqd.getName() + "_" + i, tempEleEpdPqd.getOtherName() + "_" + i); // influxQueryWrapperMax.max(tempEleEpdPqd.getName() + "_" + i, tempEleEpdPqd.getOtherName() + "_" + i);
} // }
} else { // } else {
influxQueryWrapperMax.max(tempEleEpdPqd.getName(), tempEleEpdPqd.getOtherName()); // influxQueryWrapperMax.max(tempEleEpdPqd.getName(), tempEleEpdPqd.getOtherName());
} // }
//
}); // });
//
influxQueryWrapperMax.groupBy(InfluxDBTableConstant.LINE_ID) // influxQueryWrapperMax.groupBy(InfluxDBTableConstant.LINE_ID)
.groupBy(InfluxDBTableConstant.PHASIC_TYPE) // .groupBy(InfluxDBTableConstant.PHASIC_TYPE)
.groupBy(InfluxDBTableConstant.VALUE_TYPE) // .groupBy(InfluxDBTableConstant.VALUE_TYPE)
.between(InfluxDBTableConstant.TIME, startTime, endTime); // .between(InfluxDBTableConstant.TIME, startTime, endTime);
List list2 = reportMapper.selectByQueryWrapper(influxQueryWrapperMax); // List list2 = reportMapper.selectByQueryWrapper(influxQueryWrapperMax);
//
//平均值 // //平均值
InfluxQueryWrapper influxQueryWrapperAvg = new InfluxQueryWrapper(PqdData.class, clazz); // InfluxQueryWrapper influxQueryWrapperAvg = new InfluxQueryWrapper(PqdData.class, clazz);
influxQueryWrapperAvg.regular(PqdData::getLineId, lineIndex).eq(InfluxDBTableConstant.VALUE_TYPE, "avg") // influxQueryWrapperAvg.regular(PqdData::getLineId, lineIndex).eq(InfluxDBTableConstant.VALUE_TYPE, "avg")
.eq(InfluxDBTableConstant.PHASIC_TYPE,tempPhase); // .eq(InfluxDBTableConstant.PHASIC_TYPE,tempPhase);
// .eq(InfluxDBTableConstant.IS_ABNORMAL, 0); //// .eq(InfluxDBTableConstant.IS_ABNORMAL, 0);
//
byNameMap.forEach((name, eleEpdPqdList) -> { // byNameMap.forEach((name, eleEpdPqdList) -> {
EleEpdPqd tempEleEpdPqd = eleEpdPqdList.get(0); // EleEpdPqd tempEleEpdPqd = eleEpdPqdList.get(0);
if (Objects.nonNull(tempEleEpdPqd.getHarmStart()) && Objects.nonNull(tempEleEpdPqd.getHarmEnd())) { // if (Objects.nonNull(tempEleEpdPqd.getHarmStart()) && Objects.nonNull(tempEleEpdPqd.getHarmEnd())) {
//0-49转成1-50 // //0-49转成1-50
if(tempEleEpdPqd.getHarmStart()==0){ // if(tempEleEpdPqd.getHarmStart()==0){
tempEleEpdPqd.setHarmStart(tempEleEpdPqd.getHarmStart()+1); // tempEleEpdPqd.setHarmStart(tempEleEpdPqd.getHarmStart()+1);
tempEleEpdPqd.setHarmEnd(tempEleEpdPqd.getHarmEnd()+1); // tempEleEpdPqd.setHarmEnd(tempEleEpdPqd.getHarmEnd()+1);
} // }
for (int i = tempEleEpdPqd.getHarmStart(); i < tempEleEpdPqd.getHarmEnd() + 1; i++) { // for (int i = tempEleEpdPqd.getHarmStart(); i < tempEleEpdPqd.getHarmEnd() + 1; i++) {
influxQueryWrapperAvg.mean(tempEleEpdPqd.getName() + "_" + i, tempEleEpdPqd.getOtherName() + "_" + i); // influxQueryWrapperAvg.mean(tempEleEpdPqd.getName() + "_" + i, tempEleEpdPqd.getOtherName() + "_" + i);
} // }
} else { // } else {
influxQueryWrapperAvg.mean(tempEleEpdPqd.getName(), tempEleEpdPqd.getOtherName()); // influxQueryWrapperAvg.mean(tempEleEpdPqd.getName(), tempEleEpdPqd.getOtherName());
} // }
//
}); // });
//
influxQueryWrapperAvg.groupBy(InfluxDBTableConstant.LINE_ID) // influxQueryWrapperAvg.groupBy(InfluxDBTableConstant.LINE_ID)
.groupBy(InfluxDBTableConstant.PHASIC_TYPE) // .groupBy(InfluxDBTableConstant.PHASIC_TYPE)
.groupBy(InfluxDBTableConstant.VALUE_TYPE) // .groupBy(InfluxDBTableConstant.VALUE_TYPE)
.between(InfluxDBTableConstant.TIME, startTime, endTime); // .between(InfluxDBTableConstant.TIME, startTime, endTime);
List list3 = reportMapper.selectByQueryWrapper(influxQueryWrapperAvg); // List list3 = reportMapper.selectByQueryWrapper(influxQueryWrapperAvg);
//
//
//CP95 // //CP95
InfluxQueryWrapper influxQueryWrapperCp95 = new InfluxQueryWrapper(PqdData.class, clazz); // InfluxQueryWrapper influxQueryWrapperCp95 = new InfluxQueryWrapper(PqdData.class, clazz);
influxQueryWrapperCp95.regular(PqdData::getLineId, lineIndex).eq(InfluxDBTableConstant.VALUE_TYPE, "avg") // influxQueryWrapperCp95.regular(PqdData::getLineId, lineIndex).eq(InfluxDBTableConstant.VALUE_TYPE, "avg")
.eq(InfluxDBTableConstant.PHASIC_TYPE,tempPhase); // .eq(InfluxDBTableConstant.PHASIC_TYPE,tempPhase);
// .eq(InfluxDBTableConstant.IS_ABNORMAL, 0); //// .eq(InfluxDBTableConstant.IS_ABNORMAL, 0);
//
byNameMap.forEach((name, eleEpdPqdList) -> { // byNameMap.forEach((name, eleEpdPqdList) -> {
EleEpdPqd tempEleEpdPqd = eleEpdPqdList.get(0); // EleEpdPqd tempEleEpdPqd = eleEpdPqdList.get(0);
if (Objects.nonNull(tempEleEpdPqd.getHarmStart()) && Objects.nonNull(tempEleEpdPqd.getHarmEnd())) { // if (Objects.nonNull(tempEleEpdPqd.getHarmStart()) && Objects.nonNull(tempEleEpdPqd.getHarmEnd())) {
//0-49转成1-50 // //0-49转成1-50
if(tempEleEpdPqd.getHarmStart()==0){ // if(tempEleEpdPqd.getHarmStart()==0){
tempEleEpdPqd.setHarmStart(tempEleEpdPqd.getHarmStart()+1); // tempEleEpdPqd.setHarmStart(tempEleEpdPqd.getHarmStart()+1);
tempEleEpdPqd.setHarmEnd(tempEleEpdPqd.getHarmEnd()+1); // tempEleEpdPqd.setHarmEnd(tempEleEpdPqd.getHarmEnd()+1);
} // }
for (int i = tempEleEpdPqd.getHarmStart(); i < tempEleEpdPqd.getHarmEnd() + 1; i++) { // for (int i = tempEleEpdPqd.getHarmStart(); i < tempEleEpdPqd.getHarmEnd() + 1; i++) {
influxQueryWrapperCp95.percentile(tempEleEpdPqd.getName() + "_" + i, tempEleEpdPqd.getOtherName() + "_" + i, 95); // influxQueryWrapperCp95.percentile(tempEleEpdPqd.getName() + "_" + i, tempEleEpdPqd.getOtherName() + "_" + i, 95);
} // }
} else { // } else {
influxQueryWrapperCp95.percentile(tempEleEpdPqd.getName(), tempEleEpdPqd.getOtherName(),95); // influxQueryWrapperCp95.percentile(tempEleEpdPqd.getName(), tempEleEpdPqd.getOtherName(),95);
} // }
//
}); // });
//
influxQueryWrapperCp95.groupBy(InfluxDBTableConstant.LINE_ID) // influxQueryWrapperCp95.groupBy(InfluxDBTableConstant.LINE_ID)
.groupBy(InfluxDBTableConstant.PHASIC_TYPE) // .groupBy(InfluxDBTableConstant.PHASIC_TYPE)
.groupBy(InfluxDBTableConstant.VALUE_TYPE) // .groupBy(InfluxDBTableConstant.VALUE_TYPE)
.between(InfluxDBTableConstant.TIME, startTime, endTime); // .between(InfluxDBTableConstant.TIME, startTime, endTime);
List list4 = reportMapper.selectByQueryWrapper(influxQueryWrapperCp95); // List list4 = reportMapper.selectByQueryWrapper(influxQueryWrapperCp95);
//为ValueType转成cp95 // //为ValueType转成cp95
list4.forEach(temp -> { // list4.forEach(temp -> {
//获取 // //获取
Field vauleField = null; // Field vauleField = null;
try { // try {
vauleField = temp.getClass().getDeclaredField("valueType"); // vauleField = temp.getClass().getDeclaredField("valueType");
//
vauleField.setAccessible(true); //暴力访问id // vauleField.setAccessible(true); //暴力访问id
vauleField.set(temp, "CP95"); // vauleField.set(temp, "CP95");
//
} catch (NoSuchFieldException e) { // } catch (NoSuchFieldException e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} catch (IllegalAccessException e) { // } catch (IllegalAccessException e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} // }
//
//
}); // });
//
//
result.addAll(list1); // result.addAll(list1);
result.addAll(list2); // result.addAll(list2);
result.addAll(list3); // result.addAll(list3);
result.addAll(list4); // result.addAll(list4);
//
//
} ); // } );
//1.为time赋值2.映射 // //1.为time赋值2.映射
result.forEach(temp -> { // result.forEach(temp -> {
//获取 // //获取
Field phasicTypeeField = null; // Field phasicTypeeField = null;
Field timeField = null; // Field timeField = null;
Field vauleTypeField = null; // Field vauleTypeField = null;
Field qualityFlagField = null; // Field qualityFlagField = null;
//
try { // try {
//
timeField = temp.getClass().getDeclaredField("time"); // timeField = temp.getClass().getDeclaredField("time");
//
timeField.setAccessible(true); // timeField.setAccessible(true);
timeField.set(temp, yesterday); // timeField.set(temp, yesterday);
phasicTypeeField = temp.getClass().getDeclaredField("phasicType"); // phasicTypeeField = temp.getClass().getDeclaredField("phasicType");
phasicTypeeField.setAccessible(true); // phasicTypeeField.setAccessible(true);
String phase = phasicTypeeField.get(temp).toString(); // String phase = phasicTypeeField.get(temp).toString();
phasicTypeeField.set(temp, getPhase(phase)); // phasicTypeeField.set(temp, getPhase(phase));
//
//
vauleTypeField = temp.getClass().getDeclaredField("valueType"); // vauleTypeField = temp.getClass().getDeclaredField("valueType");
vauleTypeField.setAccessible(true); // vauleTypeField.setAccessible(true);
String valueType = vauleTypeField.get(temp).toString(); // String valueType = vauleTypeField.get(temp).toString();
vauleTypeField.set(temp, valueType.toUpperCase()); // vauleTypeField.set(temp, valueType.toUpperCase());
//
qualityFlagField = temp.getClass().getDeclaredField("qualityFlag"); // qualityFlagField = temp.getClass().getDeclaredField("qualityFlag");
//
qualityFlagField.setAccessible(true); // qualityFlagField.setAccessible(true);
qualityFlagField.set(temp, 0); // qualityFlagField.set(temp, 0);
//
} catch (NoSuchFieldException e) { // } catch (NoSuchFieldException e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} catch (IllegalAccessException e) { // } catch (IllegalAccessException e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} // }
//
//
}); // });
log.info("插入数据"); // log.info("插入数据");
//由于ABA对应的都是A不能批量插入会爆主键冲突 // //由于ABA对应的都是A不能批量插入会爆主键冲突
result.forEach(temp->{ // result.forEach(temp->{
bean.saveOrUpdateByMultiId(temp); // bean.saveOrUpdateByMultiId(temp);
}); // });
//
//
} // }
//
//
} // }
//
public String getPhase( String phase) { // public String getPhase( String phase) {
//
switch (phase) { // switch (phase) {
case "A": // case "A":
return "A"; // return "A";
case "B": // case "B":
return "B"; // return "B";
case "C": // case "C":
return "C"; // return "C";
case "M": // case "M":
return "T"; // return "T";
case "AB": // case "AB":
return "A"; // return "A";
case "BC": // case "BC":
return "B"; // return "B";
case "CA": // case "CA":
return "C"; // return "C";
default: // default:
break; // break;
} // }
return ""; // return "";
} // }
//
//
} //}