|
|
|
|
@@ -0,0 +1,223 @@
|
|
|
|
|
package com.njcn.csharmonic.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.date.DatePattern;
|
|
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.njcn.csdevice.api.CsLineFeignClient;
|
|
|
|
|
import com.njcn.csdevice.api.WlRecordFeignClient;
|
|
|
|
|
import com.njcn.csdevice.pojo.param.WlRecordParam;
|
|
|
|
|
import com.njcn.csdevice.pojo.po.CsDataSet;
|
|
|
|
|
import com.njcn.csdevice.pojo.po.CsLinePO;
|
|
|
|
|
import com.njcn.csdevice.pojo.vo.RecordVo;
|
|
|
|
|
import com.njcn.csdevice.utils.DataChangeUtil;
|
|
|
|
|
import com.njcn.csharmonic.constant.HarmonicConstant;
|
|
|
|
|
import com.njcn.csharmonic.mapper.CsDataSetMapper;
|
|
|
|
|
import com.njcn.csharmonic.param.DataParam;
|
|
|
|
|
import com.njcn.csharmonic.pojo.vo.RealTimeDataVo;
|
|
|
|
|
import com.njcn.csharmonic.service.IDataService;
|
|
|
|
|
import com.njcn.csharmonic.util.InfluxDbParamUtil;
|
|
|
|
|
import com.njcn.influx.pojo.dto.StatisticalDataDTO;
|
|
|
|
|
import com.njcn.influx.service.CommonService;
|
|
|
|
|
import com.njcn.system.api.CsStatisticalSetFeignClient;
|
|
|
|
|
import com.njcn.system.api.DictTreeFeignClient;
|
|
|
|
|
import com.njcn.system.pojo.po.EleEpdPqd;
|
|
|
|
|
import com.njcn.system.pojo.vo.DictTreeVO;
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 类的介绍:
|
|
|
|
|
*
|
|
|
|
|
* @author xuyang
|
|
|
|
|
* @version 1.0.0
|
|
|
|
|
* @createTime 2023/6/1 10:11
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
public class DataServiceImpl implements IDataService {
|
|
|
|
|
|
|
|
|
|
private final CommonService commonService;
|
|
|
|
|
private final CsStatisticalSetFeignClient csStatisticalSetFeignClient;
|
|
|
|
|
private final DictTreeFeignClient dictTreeFeignClient;
|
|
|
|
|
private final InfluxDbParamUtil influxDbParamUtil;
|
|
|
|
|
private final CsLineFeignClient csLineFeignClient;
|
|
|
|
|
private final CsDataSetMapper csDataSetMapper;
|
|
|
|
|
private final WlRecordFeignClient wlRecordFeignClient;
|
|
|
|
|
private final DecimalFormat df = new DecimalFormat("#0.00");
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<RealTimeDataVo> getRealTimeData(DataParam param) {
|
|
|
|
|
List<RealTimeDataVo> result = new ArrayList<>();
|
|
|
|
|
//获取监测点使用的数据集
|
|
|
|
|
List<CsLinePO> finalCsLinePOList = csLineFeignClient.queryLineById(Arrays.asList(param.getLineId())).getData();
|
|
|
|
|
CsDataSet csDataSet = csDataSetMapper.selectOne(new LambdaQueryWrapper<CsDataSet>().eq(CsDataSet::getId,finalCsLinePOList.get(0).getDataSetId()));
|
|
|
|
|
Double ct = finalCsLinePOList.get(0).getCtRatio();
|
|
|
|
|
Double pt = finalCsLinePOList.get(0).getPtRatio();
|
|
|
|
|
//根据类型id获取指标分组
|
|
|
|
|
List<DictTreeVO> dictTreeVOList = dictTreeFeignClient.query(param.getTargetType()).getData();
|
|
|
|
|
if (CollUtil.isNotEmpty(dictTreeVOList)) {
|
|
|
|
|
dictTreeVOList = dictTreeVOList.stream().sorted(Comparator.comparing(DictTreeVO::getSort)).collect(Collectors.toList());
|
|
|
|
|
//根据分组获取对应指标
|
|
|
|
|
List<RealTimeDataVo> finalResult = result;
|
|
|
|
|
dictTreeVOList.forEach(item->{
|
|
|
|
|
List<EleEpdPqd> epdPqdList = csStatisticalSetFeignClient.queryStatisticalSelect(item.getId()).getData();
|
|
|
|
|
epdPqdList.forEach(item2->{
|
|
|
|
|
if (Objects.isNull(item2.getHarmStart())) {
|
|
|
|
|
RealTimeDataVo vo = getBaseData(item2,param.getLineId(),param.getDataLevel(),csDataSet.getDataLevel(),pt,ct);
|
|
|
|
|
if (Objects.nonNull(vo)) {
|
|
|
|
|
finalResult.add(vo);
|
|
|
|
|
}
|
|
|
|
|
} else if (Objects.equals(item2.getHarmStart(),2)) {
|
|
|
|
|
List<RealTimeDataVo> harmList = getHarmData(item2,param.getLineId());
|
|
|
|
|
finalResult.addAll(harmList);
|
|
|
|
|
} else if (Objects.equals(item2.getHarmStart(),1)) {
|
|
|
|
|
List<RealTimeDataVo> inuharmList = getInuHarmData(item2,param.getLineId());
|
|
|
|
|
finalResult.addAll(inuharmList);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (CollUtil.isNotEmpty(result)) {
|
|
|
|
|
result = channelData(result);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<RecordVo> getTestData(DataParam param) {
|
|
|
|
|
WlRecordParam.lineRecord record = new WlRecordParam.lineRecord();
|
|
|
|
|
record.setLineId(param.getLineId());
|
|
|
|
|
String beginDay = LocalDateTimeUtil.format(LocalDateTimeUtil.beginOfDay(LocalDateTimeUtil.parse(param.getStartTime(), DatePattern.NORM_DATE_PATTERN)),DatePattern.NORM_DATETIME_PATTERN);
|
|
|
|
|
String endDay = LocalDateTimeUtil.format(LocalDateTimeUtil.endOfDay(LocalDateTimeUtil.parse(param.getEndTime(), DatePattern.NORM_DATE_PATTERN)),DatePattern.NORM_DATETIME_PATTERN);
|
|
|
|
|
record.setItemStartTime(beginDay);
|
|
|
|
|
record.setItemEndTime(endDay);
|
|
|
|
|
return wlRecordFeignClient.findDevBaseDataByLineId(record).getData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//基础数据
|
|
|
|
|
public RealTimeDataVo getBaseData(EleEpdPqd item2, String lineId, String dataLevel, String csDataSetLevel,Double pt, Double ct) {
|
|
|
|
|
RealTimeDataVo vo = new RealTimeDataVo();
|
|
|
|
|
String unit;
|
|
|
|
|
double re;
|
|
|
|
|
vo.setId(item2.getId());
|
|
|
|
|
vo.setName(item2.getName());
|
|
|
|
|
StatisticalDataDTO statisticalDataDTO = commonService.getLineRtData(lineId,influxDbParamUtil.getTableNameByClassId(item2.getClassId()),item2.getName(),item2.getPhase(),"avg",influxDbParamUtil.getClDidByLineId(lineId));
|
|
|
|
|
if (Objects.isNull(statisticalDataDTO)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
vo.setTime(statisticalDataDTO.getTime());
|
|
|
|
|
vo.setAvgValue(statisticalDataDTO.getValue());
|
|
|
|
|
vo.setPhase(item2.getPhase());
|
|
|
|
|
vo.setOtherName(item2.getShowName());
|
|
|
|
|
vo.setSort(item2.getSort());
|
|
|
|
|
if (Objects.equals("Primary",dataLevel)) {
|
|
|
|
|
if (Objects.equals("Primary",csDataSetLevel)) {
|
|
|
|
|
vo.setAvgValue(Double.valueOf(df.format(statisticalDataDTO.getValue())));
|
|
|
|
|
unit = item2.getUnit();
|
|
|
|
|
} else {
|
|
|
|
|
if (HarmonicConstant.POWER_LIST.contains(item2.getShowName())) {
|
|
|
|
|
re = DataChangeUtil.secondaryToPrimary(item2.getPrimaryFormula(), statisticalDataDTO.getValue(), pt, ct) / 1000;
|
|
|
|
|
vo.setAvgValue(Double.valueOf(df.format(re)));
|
|
|
|
|
unit = "k" + item2.getUnit();
|
|
|
|
|
} else {
|
|
|
|
|
vo.setAvgValue(Double.valueOf(df.format(statisticalDataDTO.getValue())));
|
|
|
|
|
unit = item2.getUnit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (Objects.equals("Primary",csDataSetLevel)) {
|
|
|
|
|
if (HarmonicConstant.POWER_LIST.contains(item2.getShowName())) {
|
|
|
|
|
re = DataChangeUtil.primaryToSecondary(item2.getPrimaryFormula(), statisticalDataDTO.getValue(), pt, ct);
|
|
|
|
|
vo.setAvgValue(Double.valueOf(df.format(re)));
|
|
|
|
|
} else {
|
|
|
|
|
vo.setAvgValue(Double.valueOf(df.format(statisticalDataDTO.getValue())));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
vo.setAvgValue(Double.valueOf(df.format(statisticalDataDTO.getValue())));
|
|
|
|
|
}
|
|
|
|
|
unit = item2.getUnit();
|
|
|
|
|
}
|
|
|
|
|
vo.setUnit(unit);
|
|
|
|
|
if (Objects.nonNull(unit)) {
|
|
|
|
|
vo.setOtherName(item2.getShowName() + "(" + unit + ")");
|
|
|
|
|
}
|
|
|
|
|
return vo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//谐波数据
|
|
|
|
|
public List<RealTimeDataVo> getHarmData(EleEpdPqd item2, String lineId) {
|
|
|
|
|
List<RealTimeDataVo> list = new ArrayList<>();
|
|
|
|
|
for (int i = item2.getHarmStart(); i <= item2.getHarmEnd(); i++) {
|
|
|
|
|
RealTimeDataVo vo = new RealTimeDataVo();
|
|
|
|
|
vo.setId(item2.getId());
|
|
|
|
|
vo.setName(item2.getName().concat("_").concat(Integer.toString(i)));
|
|
|
|
|
StatisticalDataDTO statisticalDataDTO = commonService.getLineRtData(lineId,influxDbParamUtil.getTableNameByClassId(item2.getClassId()),item2.getName().concat("_").concat(Integer.toString(i)),item2.getPhase(),"avg",influxDbParamUtil.getClDidByLineId(lineId));
|
|
|
|
|
vo.setTime(statisticalDataDTO.getTime());
|
|
|
|
|
vo.setAvgValue(Double.valueOf(df.format(statisticalDataDTO.getValue())));
|
|
|
|
|
vo.setPhase(item2.getPhase());
|
|
|
|
|
vo.setOtherName(i + "次" + "(" + item2.getUnit() + ")");
|
|
|
|
|
vo.setSort(item2.getSort());
|
|
|
|
|
vo.setUnit(item2.getUnit());
|
|
|
|
|
list.add(vo);
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//间谐波数据
|
|
|
|
|
public List<RealTimeDataVo> getInuHarmData(EleEpdPqd item2, String lineId) {
|
|
|
|
|
List<RealTimeDataVo> list = new ArrayList<>();
|
|
|
|
|
for (int i = item2.getHarmStart(); i <= item2.getHarmEnd(); i++) {
|
|
|
|
|
RealTimeDataVo vo = new RealTimeDataVo();
|
|
|
|
|
vo.setId(item2.getId());
|
|
|
|
|
vo.setName(item2.getName().concat("_").concat(Integer.toString(i)));
|
|
|
|
|
StatisticalDataDTO statisticalDataDTO = commonService.getLineRtData(lineId,influxDbParamUtil.getTableNameByClassId(item2.getClassId()),item2.getName().concat("_").concat(Integer.toString(i)),item2.getPhase(),"avg",influxDbParamUtil.getClDidByLineId(lineId));
|
|
|
|
|
vo.setTime(statisticalDataDTO.getTime());
|
|
|
|
|
vo.setAvgValue(Double.valueOf(df.format(statisticalDataDTO.getValue())));
|
|
|
|
|
vo.setPhase(item2.getPhase());
|
|
|
|
|
vo.setOtherName((i-0.5) + "次" + "(" + item2.getUnit() + ")");
|
|
|
|
|
vo.setSort(item2.getSort());
|
|
|
|
|
vo.setUnit(item2.getUnit());
|
|
|
|
|
list.add(vo);
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//数据格式处理
|
|
|
|
|
public List<RealTimeDataVo> channelData(List<RealTimeDataVo> list) {
|
|
|
|
|
List<RealTimeDataVo> result = new ArrayList<>();
|
|
|
|
|
//将list 排序,并按照排序后的结果进行有序分组
|
|
|
|
|
LinkedHashMap<String, List<RealTimeDataVo>> map = list.stream().sorted(Comparator.comparing(RealTimeDataVo::getSort)).collect(Collectors.groupingBy(RealTimeDataVo::getName, LinkedHashMap::new, Collectors.toList()));
|
|
|
|
|
map.forEach((k,v)->{
|
|
|
|
|
RealTimeDataVo vo = new RealTimeDataVo();
|
|
|
|
|
RealTimeDataVo vo1 = v.get(0);
|
|
|
|
|
BeanUtils.copyProperties(vo1,vo);
|
|
|
|
|
RealTimeDataVo phaseA = v.stream().filter(s->Objects.equals(s.getPhase(),"A") || Objects.equals(s.getPhase(),"AB")).findFirst().orElse(null);
|
|
|
|
|
if (Objects.nonNull(phaseA)) {
|
|
|
|
|
vo.setValueA(phaseA.getAvgValue());
|
|
|
|
|
}
|
|
|
|
|
RealTimeDataVo phaseB = v.stream().filter(s->Objects.equals(s.getPhase(),"B") || Objects.equals(s.getPhase(),"BC")).findFirst().orElse(null);
|
|
|
|
|
if (Objects.nonNull(phaseB)) {
|
|
|
|
|
vo.setValueB(phaseB.getAvgValue());
|
|
|
|
|
}
|
|
|
|
|
RealTimeDataVo phaseC = v.stream().filter(s->Objects.equals(s.getPhase(),"C") || Objects.equals(s.getPhase(),"CA")).findFirst().orElse(null);
|
|
|
|
|
if (Objects.nonNull(phaseC)) {
|
|
|
|
|
vo.setValueC(phaseC.getAvgValue());
|
|
|
|
|
}
|
|
|
|
|
RealTimeDataVo phaseM = v.stream().filter(s->Objects.equals(s.getPhase(),"M")).findFirst().orElse(null);
|
|
|
|
|
if (Objects.nonNull(phaseM)) {
|
|
|
|
|
vo.setValueM(phaseM.getAvgValue());
|
|
|
|
|
}
|
|
|
|
|
vo.setPhase("/");
|
|
|
|
|
vo.setAvgValue(null);
|
|
|
|
|
result.add(vo);
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|