bug修改

This commit is contained in:
2023-05-23 16:50:42 +08:00
parent b5a0e4c9e3
commit fd97f5fd78
3 changed files with 40 additions and 53 deletions

View File

@@ -34,6 +34,7 @@ import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -51,38 +52,36 @@ public class THDistortionServiceImpl implements THDistortionService {
private final THDistortionMapper thDistortionMapper;
private final InfluxDbUtils influxDbUtils;
private final RMpVThdMapper rMpVThdMapper;
private final LineFeignClient lineFeignClient;
private final IRStatDataVDService statDataVDService;
@Override
public List<THDistortionVO> getTHDistortionData(DeviceInfoParam.BusinessParam thDistortionParam) {
List<THDistortionVO> thDistortionVOS = new ArrayList<>();
List<String> lineList = new ArrayList<>();
//按照条件获取实际运行终端综合信息
List<GeneralDeviceDTO> deviceList = generalDeviceInfoClient.getPracticalRunDeviceInfo(new DeviceInfoParam(thDistortionParam.getStatisticalType(), thDistortionParam.getDeptIndex(), generalInfo.getMicroServiceName(), thDistortionParam.getScale(), thDistortionParam.getManufacturer(), thDistortionParam.getLoadType())).getData();
//组装监测点Top层集合
for (GeneralDeviceDTO generalDeviceDTO : deviceList) {
if (CollectionUtils.isEmpty(generalDeviceDTO.getDeviceIndexes())) {
List<String> lineIndexes = generalDeviceDTO.getLineIndexes();
if (CollectionUtils.isEmpty(lineIndexes)) {
continue;
}
THDistortionVO thDistortionVO = new THDistortionVO();
thDistortionVO.setId(generalDeviceDTO.getIndex());
thDistortionVO.setName(generalDeviceDTO.getName());
if (!CollectionUtils.isEmpty(generalDeviceDTO.getLineIndexes())) {
List<String> lineIndexes = generalDeviceDTO.getLineIndexes();
//查找畸变率
List<PublicDTO> condition = getCondition(lineIndexes, thDistortionParam.getSearchBeginTime(), thDistortionParam.getSearchEndTime());
thDistortionVO.setDistortion(roundHalfUp(condition.stream().mapToDouble(PublicDTO::getData).average().orElse(3.14159)));
//组装父级数据树
List<THDistortionVO> treeList = getTreeData(lineIndexes, thDistortionParam);
thDistortionVO.setChildren(treeList);
//查找畸变率
List<PublicDTO> condition = getCondition(lineIndexes, thDistortionParam.getSearchBeginTime(), thDistortionParam.getSearchEndTime());
thDistortionVO.setDistortion(roundHalfUp(condition.stream().mapToDouble(PublicDTO::getData).average().orElse(3.14159)));
//组装父级数据树
List<THDistortionVO> treeList = getTreeData(lineIndexes, condition);
thDistortionVO.setChildren(treeList);
}
thDistortionVOS.add(thDistortionVO);
}
@@ -135,10 +134,10 @@ public class THDistortionServiceImpl implements THDistortionService {
/*监测点ID扁平化*/
List<String> collect = deviceList.stream().map(GeneralDeviceDTO::getLineIndexes).flatMap(Collection::stream).distinct().collect(Collectors.toList());
QueryWrapper<RMpVThd> wrapper = new QueryWrapper<>();
wrapper.select ("measurement_point_id","max(v_thd) as v_thd")
wrapper.select("measurement_point_id", "max(v_thd) as v_thd")
.in("measurement_point_id", collect)
.between("data_date", statisticsBizBaseParam.getStartTime(), statisticsBizBaseParam.getEndTime())
.eq("data_type", 0).groupBy ("measurement_point_id")
.eq("data_type", 0).groupBy("measurement_point_id")
.orderByDesc("v_thd");
List<RMpVThd> rMpVThdList = rMpVThdMapper.selectList(wrapper);
rMpVThdVOList = rMpVThdList.stream().limit(topNum).map(rMpVThd -> {
@@ -193,7 +192,7 @@ public class THDistortionServiceImpl implements THDistortionService {
/**
* 获取父级每层数据
*/
private List<THDistortionVO> getTreeData(List<String> lineIndexes, DeviceInfoParam.BusinessParam thDistortionParam) {
private List<THDistortionVO> getTreeData(List<String> lineIndexes,List<PublicDTO> condition) {
//监测点集合
List<THDistortionVO> monitorList = thDistortionMapper.getLineData(lineIndexes);
//母线集合
@@ -205,21 +204,18 @@ public class THDistortionServiceImpl implements THDistortionService {
//供电公司集合
List<THDistortionVO> powerCompanyList = thDistortionMapper.getLineInfoByList(substationList.stream().map(THDistortionVO::getPid).distinct().collect(Collectors.toList()));
//查询监测点谐波畸变率
List<PublicDTO> condition = getCondition(lineIndexes, thDistortionParam.getSearchBeginTime(), thDistortionParam.getSearchEndTime());
if (!CollectionUtils.isEmpty(monitorList)) {
//根据监测点集合组装谐波畸变率
monitorList.stream().map(list1 -> condition.stream().filter(list2 -> Objects.equals(list1.getId(), list2.getId())).findAny().map(m -> {
list1.setDistortion(roundHalfUp(m.getData()));
return list1;
})).collect(Collectors.toList());
// busBarList.stream().peek(item -> item.setChildren(getChildCategoryList(item, monitorList))).collect(Collectors.toList());
// deviceList.stream().peek(item -> item.setChildren(getChildCategoryList(item, busBarList))).collect(Collectors.toList());
// substationList.stream().peek(item -> item.setChildren(getChildesList(item, monitorList))).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(monitorList)) {
Map<String, PublicDTO> map = condition.stream().collect(Collectors.toMap(PublicDTO::getId, Function.identity()));
for(THDistortionVO thDistortionVO:monitorList) {
if (map.containsKey(thDistortionVO.getId())) {
thDistortionVO.setDistortion(map.get(thDistortionVO.getId()).getData());
}
}
setChildesList(substationList, monitorList);
setFatherDistortion(substationList);
powerCompanyList.stream().peek(item -> item.setChildren(getChildCategoryList(item, substationList))).collect(Collectors.toList());
powerCompanyList = powerCompanyList.stream().peek(item -> item.setChildren(getChildCategoryList(item, substationList))).collect(Collectors.toList());
setFatherDistortion(powerCompanyList);
}
@@ -229,7 +225,7 @@ public class THDistortionServiceImpl implements THDistortionService {
/**
* 四舍五入保留两位小数
*/
private Double roundHalfUp (double num) {
private Double roundHalfUp(double num) {
if (num == 3.14159) {
return num;
}
@@ -248,33 +244,22 @@ public class THDistortionServiceImpl implements THDistortionService {
*/
private List<PublicDTO> getCondition(List<String> lineIndexes, String startTime, String endTime) {
List<PublicDTO> publicDTOList = new ArrayList<>();
List<String> phasicType = new ArrayList<>();
phasicType.add(Param.PHASIC_TYPEA);
phasicType.add(Param.PHASIC_TYPEB);
phasicType.add(Param.PHASIC_TYPEC);
//数据库查询
List<RStatDataVD> info = statDataVDService.list(new LambdaQueryWrapper<RStatDataVD>()
.in(RStatDataVD::getLineId, lineIndexes)
.ge(StrUtil.isNotBlank(startTime), RStatDataVD::getTime, DateUtil.beginOfDay(DateUtil.parse(startTime)))
.le(StrUtil.isNotBlank(endTime), RStatDataVD::getTime, DateUtil.endOfDay(DateUtil.parse(endTime)))
QueryWrapper<RMpVThd> queryWrapper = new QueryWrapper<>();
queryWrapper.select("max(v_thd) vThd,measurement_point_id").lambda()
.in(RMpVThd::getMeasurementPointId, lineIndexes)
.ge(StrUtil.isNotBlank(startTime), RMpVThd::getDataDate, DateUtil.beginOfDay(DateUtil.parse(startTime)))
.le(StrUtil.isNotBlank(endTime), RMpVThd::getDataDate, DateUtil.endOfDay(DateUtil.parse(endTime)))
.eq(RMpVThd::getDataType, 0).groupBy(RMpVThd::getMeasurementPointId);
// .eq(RStatDataVD::getQualityFlag, 1)
.eq(RStatDataVD::getQualityFlag, 0)
.in(RStatDataVD::getPhasicType, phasicType)
.eq(RStatDataVD::getValueType, Param.VALUE_TYPEAVG)
);
List<RMpVThd> info = rMpVThdMapper.selectList(queryWrapper);
if (CollUtil.isNotEmpty(info)) {
//根据id分组先乘以100.在取平均值,在四舍五入
Map<String, List<BigDecimal>> collect = info.stream().filter(x -> x.getVThd() != null).collect(Collectors.groupingBy(RStatDataVD::getLineId, Collectors.mapping(RStatDataVD::getVThd, Collectors.toList())));
Map<String, Double> vthdMap = info.stream().filter(x -> x.getVThd() != null).collect(Collectors.groupingBy(RStatDataVD::getLineId,
Collectors.averagingDouble(x -> x.getVThd().setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue())));
PublicDTO publicDTO;
for (Map.Entry<String, Double> entry : vthdMap.entrySet()) {
publicDTO = new PublicDTO();
publicDTO.setId(entry.getKey());
publicDTO.setData(entry.getValue());
info.forEach(item->{
PublicDTO publicDTO = new PublicDTO();
publicDTO.setId(item.getMeasurementPointId());
publicDTO.setData(item.getVThd());
publicDTOList.add(publicDTO);
}
});
}
return publicDTOList;
}