修改在线率算法
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
package com.njcn.harmonic.service.impl;
|
package com.njcn.harmonic.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.njcn.common.config.GeneralInfo;
|
import com.njcn.common.config.GeneralInfo;
|
||||||
import com.njcn.device.api.GeneralDeviceInfoClient;
|
import com.njcn.device.api.GeneralDeviceInfoClient;
|
||||||
@@ -21,7 +20,6 @@ import org.springframework.util.CollectionUtils;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -100,43 +98,7 @@ public class OnlineRateDataServiceImpl implements OnlineRateDataService {
|
|||||||
onlineRateCensusVO.setSingle(single);
|
onlineRateCensusVO.setSingle(single);
|
||||||
onlineRateCensusVO.setRatio(ratio);
|
onlineRateCensusVO.setRatio(ratio);
|
||||||
|
|
||||||
// List<OnlineRateVO> list = new ArrayList<>();
|
|
||||||
// List<OnlineRateVO> periodList = new ArrayList<>();
|
|
||||||
// OnlineRateCensusVO onlineRateCensusVO = new OnlineRateCensusVO();
|
|
||||||
// OnlineRateParam onlineRateParam = new OnlineRateParam();
|
|
||||||
// BeanUtil.copyProperties(onlineRateCensusParam,onlineRateParam);
|
|
||||||
// List<String> type = new ArrayList<>();
|
|
||||||
// List<Double> single = new ArrayList<>();
|
|
||||||
// List<Double> ratio = new ArrayList<>();
|
|
||||||
// if (Objects.equals(onlineRateCensusParam.getStatisticalType(),0)){
|
|
||||||
// list = getOnlineRateData(onlineRateParam).get(0).getChildren();
|
|
||||||
// } else {
|
|
||||||
// list = getOnlineRateData(onlineRateParam);
|
|
||||||
// }
|
|
||||||
// if (!CollectionUtils.isEmpty(list)){
|
|
||||||
// list.forEach(onlineRateVO -> {
|
|
||||||
// type.add(onlineRateVO.getName());
|
|
||||||
// single.add(onlineRateVO.getOnlineRateData());
|
|
||||||
// onlineRateCensusVO.setType(type);
|
|
||||||
// onlineRateCensusVO.setSingle(single);
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// if (StringUtils.isNotBlank(onlineRateCensusParam.getPeriodBeginTime()) &&
|
|
||||||
// StringUtils.isNotBlank(onlineRateCensusParam.getPeriodEndTime())){
|
|
||||||
// onlineRateParam.setSearchBeginTime(onlineRateCensusParam.getPeriodBeginTime());
|
|
||||||
// onlineRateParam.setSearchEndTime(onlineRateCensusParam.getPeriodEndTime());
|
|
||||||
// if (Objects.equals(onlineRateCensusParam.getStatisticalType(),0)){
|
|
||||||
// periodList = getOnlineRateData(onlineRateParam).get(0).getChildren();
|
|
||||||
// } else {
|
|
||||||
// periodList = getOnlineRateData(onlineRateParam);
|
|
||||||
// }
|
|
||||||
// if (!CollectionUtils.isEmpty(periodList)) {
|
|
||||||
// periodList.forEach(onlineRateVO -> {
|
|
||||||
// ratio.add(onlineRateVO.getOnlineRateData());
|
|
||||||
// onlineRateCensusVO.setRatio(ratio);
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
return onlineRateCensusVO;
|
return onlineRateCensusVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,9 +123,9 @@ public class OnlineRateDataServiceImpl implements OnlineRateDataService {
|
|||||||
})).collect(Collectors.toList());
|
})).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
substationList.stream().peek(item -> item.setChildren(getChildCategoryList(item, deviceList))).collect(Collectors.toList());
|
substationList.stream().peek(item -> item.setChildren(getChildCategoryList(item, deviceList))).collect(Collectors.toList());
|
||||||
|
setSubstationListOnlineRate(substationList);
|
||||||
powerCompanyList.stream().peek(item -> item.setChildren(getChildCategoryList(item, substationList))).collect(Collectors.toList());
|
powerCompanyList.stream().peek(item -> item.setChildren(getChildCategoryList(item, substationList))).collect(Collectors.toList());
|
||||||
setFatherOnlineRate(substationList);
|
setPowerCompanyListOnlineRate(powerCompanyList);
|
||||||
setFatherOnlineRate(powerCompanyList);
|
|
||||||
return powerCompanyList;
|
return powerCompanyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,102 +178,41 @@ public class OnlineRateDataServiceImpl implements OnlineRateDataService {
|
|||||||
return publicDTOList;
|
return publicDTOList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 父级组装
|
|
||||||
*/
|
|
||||||
private void setFatherData(Map<String, List<String>> map, List<OnlineRateVO> list, DeviceInfoParam.BusinessParam onlineRateParam) {
|
|
||||||
for (String key : map.keySet()) {
|
|
||||||
if (!CollectionUtils.isEmpty(map.get(key))) {
|
|
||||||
List<OnlineRateVO> onlineRateVOList = getTreeData(map.get(key), onlineRateParam);
|
|
||||||
//拼接父级
|
|
||||||
OnlineRateVO onlineRateVO = new OnlineRateVO();
|
|
||||||
onlineRateVO.setId("0");
|
|
||||||
onlineRateVO.setName(key);
|
|
||||||
onlineRateVO.setLevel(0);
|
|
||||||
if (CollectionUtil.isNotEmpty(onlineRateVOList)) {
|
|
||||||
onlineRateVO.setChildren(onlineRateVOList);
|
|
||||||
}
|
|
||||||
list.add(onlineRateVO);
|
|
||||||
setTopOnlineRate(list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算父级终端在线率
|
* 计算变电站层级在线率
|
||||||
*/
|
*/
|
||||||
private void setFatherOnlineRate(List<OnlineRateVO> list) {
|
private void setSubstationListOnlineRate(List<OnlineRateVO> list) {
|
||||||
list.forEach(item -> {
|
list.forEach(item -> {
|
||||||
List<OnlineRateVO> children = item.getChildren();
|
List<OnlineRateVO> children = item.getChildren();
|
||||||
List<OnlineRateVO> tempList = children.stream().filter(s -> !Objects.equals(s.getOnlineRateData(), 3.14159)).collect(Collectors.toList());
|
List<OnlineRateVO> tempList = children.stream().filter(s -> !Objects.equals(s.getOnlineRateData(), 3.14159)).collect(Collectors.toList());
|
||||||
if (!CollectionUtils.isEmpty(tempList)) {
|
if (!CollectionUtils.isEmpty(tempList)) {
|
||||||
item.setOnlineRateData(tempList.stream().mapToDouble(OnlineRateVO::getOnlineRateData).sum() / children.size());
|
item.setOnlineRateData(tempList.stream().mapToDouble(OnlineRateVO::getOnlineRateData).sum() / tempList.size());
|
||||||
|
} else {
|
||||||
|
item.setOnlineRateData(3.14159);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 计算供电公司层级在线率
|
||||||
|
*/
|
||||||
|
private void setPowerCompanyListOnlineRate(List<OnlineRateVO> list) {
|
||||||
|
list.forEach(item -> {
|
||||||
|
List<OnlineRateVO> rateVOS = new ArrayList<>();
|
||||||
|
item.getChildren().forEach(item1 -> {
|
||||||
|
item1.getChildren().forEach(item2 -> {
|
||||||
|
rateVOS.add(item2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
List<OnlineRateVO> tempList = rateVOS.stream().filter(s -> !Objects.equals(s.getOnlineRateData(), 3.14159)).collect(Collectors.toList());
|
||||||
|
if (!CollectionUtils.isEmpty(tempList)) {
|
||||||
|
item.setOnlineRateData(tempList.stream().mapToDouble(OnlineRateVO::getOnlineRateData).sum() / tempList.size());
|
||||||
} else {
|
} else {
|
||||||
item.setOnlineRateData(3.14159);
|
item.setOnlineRateData(3.14159);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//变电站
|
|
||||||
private void setSubstationIntegrity(List<OnlineRateVO> list) {
|
|
||||||
list.forEach(item -> {
|
|
||||||
List<OnlineRateVO> children = item.getChildren();
|
|
||||||
List<OnlineRateVO> result = new ArrayList<>(children);
|
|
||||||
double aver = result.stream().mapToDouble(OnlineRateVO::getOnlineRateData).average().orElseThrow(IllegalStateException::new);
|
|
||||||
item.setOnlineRateData(BigDecimal.valueOf(aver).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//供电公司
|
|
||||||
private void setPowerCompanyIntegrity(List<OnlineRateVO> list) {
|
|
||||||
list.forEach(item -> {
|
|
||||||
List<OnlineRateVO> result = new ArrayList<>();
|
|
||||||
List<OnlineRateVO> children = item.getChildren();
|
|
||||||
children.forEach(item2 -> {
|
|
||||||
List<OnlineRateVO> children2 = item2.getChildren();
|
|
||||||
result.addAll(children2);
|
|
||||||
});
|
|
||||||
double aver = result.stream().mapToDouble(OnlineRateVO::getOnlineRateData).average().orElseThrow(IllegalStateException::new);
|
|
||||||
item.setOnlineRateData(BigDecimal.valueOf(aver).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//省级
|
|
||||||
private void setAreaIntegrity(List<OnlineRateVO> list) {
|
|
||||||
list.forEach(item -> {
|
|
||||||
List<OnlineRateVO> result = new ArrayList<>();
|
|
||||||
List<OnlineRateVO> children = item.getChildren();
|
|
||||||
children.forEach(item2 -> {
|
|
||||||
List<OnlineRateVO> children2 = item2.getChildren();
|
|
||||||
children2.forEach(item3 -> {
|
|
||||||
List<OnlineRateVO> children3 = item3.getChildren();
|
|
||||||
result.addAll(children3);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
double aver = result.stream().mapToDouble(OnlineRateVO::getOnlineRateData).average().orElseThrow(IllegalStateException::new);
|
|
||||||
item.setOnlineRateData(BigDecimal.valueOf(aver).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setTopOnlineRate(List<OnlineRateVO> list) {
|
|
||||||
list.forEach(item -> {
|
|
||||||
List<OnlineRateVO> result = new ArrayList<>();
|
|
||||||
List<OnlineRateVO> children = item.getChildren();
|
|
||||||
children.forEach(item2 -> {
|
|
||||||
List<OnlineRateVO> children2 = item2.getChildren();
|
|
||||||
children2.forEach(item3 -> {
|
|
||||||
List<OnlineRateVO> children3 = item3.getChildren();
|
|
||||||
children3.forEach(item4 -> {
|
|
||||||
List<OnlineRateVO> children4 = item4.getChildren();
|
|
||||||
result.addAll(children4);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
double aver = result.stream().mapToDouble(OnlineRateVO::getOnlineRateData).average().orElseThrow(IllegalStateException::new);
|
|
||||||
item.setOnlineRateData(BigDecimal.valueOf(aver).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user