1.调整pms国网主配网监测点功能
This commit is contained in:
@@ -16,6 +16,14 @@ import com.njcn.prepare.harmonic.mapper.mysql.upload.RUploadPointStatisticalData
|
||||
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
|
||||
import com.njcn.prepare.harmonic.pojo.dto.UploadPointStatisticalParam;
|
||||
import com.njcn.prepare.harmonic.service.mysql.upload.IRUploadPointStatisticalDataDService;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.enums.DicDataTypeEnum;
|
||||
import com.njcn.system.enums.DicTreeEnum;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||
import com.njcn.system.pojo.vo.DictTreeVO;
|
||||
import com.njcn.user.api.DeptFeignClient;
|
||||
import com.njcn.user.pojo.po.Dept;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -24,6 +32,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -42,6 +51,10 @@ public class RUploadPointStatisticalDataDServiceImpl extends MppServiceImpl<RUpl
|
||||
private final ROperatingIndexDPOMapper rOperatingIndexDPOMapper;
|
||||
private final RStatIntegrityDMapper rStatIntegrityDMapper;
|
||||
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
|
||||
/**
|
||||
* 此算法用于计算底层数据,方便国网数据上送
|
||||
* 1.表中存储所有单位,没有数据的暂时设置为0
|
||||
@@ -56,87 +69,182 @@ public class RUploadPointStatisticalDataDServiceImpl extends MppServiceImpl<RUpl
|
||||
Dept data = deptFeignClient.getRootDept().getData();
|
||||
String provinceId = deptFeignClient.getDepSonIdByDeptId(data.getId()).getData().get(0);
|
||||
Dept dept = deptFeignClient.getDeptById(provinceId).getData();
|
||||
//筛选国网上送监测点
|
||||
List<DeptGetChildrenMoreDTO> l1 = calculatedParam.getIdList();
|
||||
l1.forEach(item->{
|
||||
List<LineDevGetDTO> newList = item.getLineBaseList().stream().filter(o ->Objects.equals(o.getIsUpToGrid(),1)).collect(Collectors.toList());
|
||||
item.setLineBaseList(newList);
|
||||
UploadPointStatisticalParam uploadPointStatisticalParam = new UploadPointStatisticalParam();
|
||||
uploadPointStatisticalParam.setOrgId(item.getUnitId());
|
||||
List<LineDevGetDTO> lineInfo = item.getLineBaseList();
|
||||
uploadPointStatisticalParam.setOnlineMonitorNum(lineInfo.size());
|
||||
uploadPointStatisticalParam.setRunMonitorNum(lineInfo.size());
|
||||
uploadPointStatisticalParam.setRunTerminalNum((int)lineInfo.stream().map(LineDevGetDTO::getDevId).distinct().count());
|
||||
paramList.add(uploadPointStatisticalParam);
|
||||
});
|
||||
Map<String,List<UploadPointStatisticalParam>> devMap = paramList.stream().collect(Collectors.groupingBy(UploadPointStatisticalParam::getOrgId));
|
||||
//获取数据个数
|
||||
List<RStatIntegrityD> dataList = getStatIntegrityData(calculatedParam.getDataDate());
|
||||
|
||||
//查询所有一级树字典
|
||||
List<SysDicTreePO> sysDicTreePOList = dictTreeFeignClient.queryAll().getData();
|
||||
|
||||
|
||||
List<SysDicTreePO> temTreeList = sysDicTreePOList.stream().filter(item -> Objects.equals(item.getCode(), DicTreeEnum.Trans_Sub.getCode())
|
||||
|| Objects.equals(item.getCode(), DicTreeEnum.Converter.getCode()) || Objects.equals(item.getCode(), DicTreeEnum.Ele_Railways.getCode())
|
||||
|| Objects.equals(item.getCode(), DicTreeEnum.Wind_Farms.getCode()) || Objects.equals(item.getCode(), DicTreeEnum.Power_Station.getCode())
|
||||
|| Objects.equals(item.getCode(), DicTreeEnum.Smelting_Load.getCode()) || Objects.equals(item.getCode(), DicTreeEnum.Imp_Users.getCode())
|
||||
).collect(Collectors.toList());
|
||||
|
||||
Map<String,List<String>> mapKey = new HashMap<>();
|
||||
List<String> otherIds = new ArrayList<>();
|
||||
for(SysDicTreePO sysDicTreePO : temTreeList){
|
||||
List<SysDicTreePO> temList = sysDicTreePOList.stream().filter(item->item.getPid().equals(sysDicTreePO.getId())).collect(Collectors.toList());
|
||||
List<String> ids = temList.stream().map(SysDicTreePO::getId).distinct().collect(Collectors.toList());
|
||||
ids.add(sysDicTreePO.getId());
|
||||
mapKey.put(sysDicTreePO.getCode(),ids);
|
||||
otherIds.addAll(ids);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
List<DictData> dictDataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.Station_Type.getCode()).getData();
|
||||
Map<String,DictData> dictDataMap = dictDataList.stream().collect(Collectors.toMap(DictData::getCode,Function.identity()));
|
||||
|
||||
|
||||
//获取所有单位
|
||||
List<Dept> deptList = deptFeignClient.getAllDept().getData();
|
||||
Map<String,List<Dept>> deptMap = deptList.stream().collect(Collectors.groupingBy(Dept::getCode));
|
||||
l1.forEach(item->{
|
||||
if (Objects.equals(Integer.parseInt(UploadEnum.NJCN_DEPT_LEVEL_1.getCode()),item.getDeptLevel())){
|
||||
Map<String, List<Dept>> deptMap = deptList.stream().collect(Collectors.groupingBy(Dept::getCode));
|
||||
//筛选国网上送监测点
|
||||
List<DeptGetChildrenMoreDTO> l1 = calculatedParam.getIdList();
|
||||
|
||||
//获取数据个数
|
||||
List<RStatIntegrityD> dataList = getStatIntegrityData(calculatedParam.getDataDate());
|
||||
l1.forEach(item -> {
|
||||
|
||||
if (Objects.equals(Integer.parseInt(UploadEnum.NJCN_DEPT_LEVEL_1.getCode()), item.getDeptLevel())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
List<LineDevGetDTO> newList = item.getLineBaseList().stream().filter(o -> Objects.equals(o.getIsUpToGrid(), 1)).collect(Collectors.toList());
|
||||
item.setLineBaseList(newList);
|
||||
|
||||
|
||||
List<LineDevGetDTO> otherMonitor = item.getLineBaseList().stream().filter(me->!otherIds.contains(me.getObjType())).collect(Collectors.toList());
|
||||
|
||||
|
||||
mapKey.forEach((key, val) -> {
|
||||
|
||||
List<LineDevGetDTO> keyItem = item.getLineBaseList().stream().filter(o -> val.contains(o.getObjType())).collect(Collectors.toList());
|
||||
RUploadPointStatisticalDataD rUploadPointStatisticalDataD = new RUploadPointStatisticalDataD();
|
||||
switch (key){
|
||||
case "2100":
|
||||
rUploadPointStatisticalDataD.setStationType(dictDataMap.get(DicDataEnum.Trans_Sub.getCode()).getId());
|
||||
break;
|
||||
case "1200":
|
||||
rUploadPointStatisticalDataD.setStationType(dictDataMap.get(DicDataEnum.Converter.getCode()).getId());
|
||||
break;
|
||||
case "1300":
|
||||
rUploadPointStatisticalDataD.setStationType(dictDataMap.get(DicDataEnum.Ele_Railways.getCode()).getId());
|
||||
break;
|
||||
case "1401":
|
||||
rUploadPointStatisticalDataD.setStationType(dictDataMap.get(DicDataEnum.Wind_Farms.getCode()).getId());
|
||||
break;
|
||||
case "1402":
|
||||
rUploadPointStatisticalDataD.setStationType(dictDataMap.get(DicDataEnum.Power_Station.getCode()).getId());
|
||||
break;
|
||||
case "2600":
|
||||
rUploadPointStatisticalDataD.setStationType(dictDataMap.get(DicDataEnum.Smelting_Load.getCode()).getId());
|
||||
break;
|
||||
case "2400":
|
||||
rUploadPointStatisticalDataD.setStationType(dictDataMap.get(DicDataEnum.Imp_Users.getCode()).getId());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
rUploadPointStatisticalDataD.setId(IdUtil.simpleUUID());
|
||||
rUploadPointStatisticalDataD.setProvinceId(dept.getCode());
|
||||
rUploadPointStatisticalDataD.setProvinceName(dept.getName());
|
||||
rUploadPointStatisticalDataD.setStatisticalDate(calculatedParam.getDataDate());
|
||||
rUploadPointStatisticalDataD.setStatisticalType(UploadEnum.STATISTICAL_TYPE_03.getCode());
|
||||
rUploadPointStatisticalDataD.setUploadStatus(Integer.parseInt(UploadEnum.UPLOAD_STATUS_0.getCode()));
|
||||
//fixme 主配网标识文档中没有,先随便定义一个,后期调整
|
||||
rUploadPointStatisticalDataD.setDistributionFlag(UploadEnum.DISTRIBUTION_FLAG_01.getCode());
|
||||
//fixme over
|
||||
judgeLevel(item.getDeptLevel(), rUploadPointStatisticalDataD, item.getUnitId(), item.getUnitName(), deptList, deptMap);
|
||||
|
||||
|
||||
long pointCount = keyItem.stream().map(LineDevGetDTO::getPointId).distinct().count();
|
||||
long devCount = keyItem.stream().map(LineDevGetDTO::getDevId).distinct().count();
|
||||
rUploadPointStatisticalDataD.setRunTerminalNum((int) devCount);
|
||||
rUploadPointStatisticalDataD.setOnlineMonitorNum((int) pointCount);
|
||||
rUploadPointStatisticalDataD.setRunMonitorNum((int) pointCount);
|
||||
rUploadPointStatisticalDataD.setOnlineMonitorRate(pointCount == 0 ? 0d : BigDecimal.valueOf(rUploadPointStatisticalDataD.getOnlineMonitorNum() * 100.0 / rUploadPointStatisticalDataD.getRunMonitorNum()).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
|
||||
|
||||
List<RStatIntegrityD> l3 = dataList.stream().filter(it -> keyItem.stream().map(LineDevGetDTO::getPointId).collect(Collectors.toList()).contains(it.getLineIndex())).collect(Collectors.toList());
|
||||
int due = l3.stream().mapToInt(RStatIntegrityD::getDueTime).sum();
|
||||
int real = l3.stream().mapToInt(RStatIntegrityD::getRealTime).sum();
|
||||
rUploadPointStatisticalDataD.setExpectCollectNum(due);
|
||||
rUploadPointStatisticalDataD.setActualCollectNum(real);
|
||||
|
||||
if (due == 0 || real == 0) {
|
||||
rUploadPointStatisticalDataD.setDataFullRate(BigDecimal.valueOf(0).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
} else {
|
||||
rUploadPointStatisticalDataD.setDataFullRate(BigDecimal.valueOf(real * 100.0 / due).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
rUploadPointStatisticalDataD.setStationMonitorNum(l3.size());
|
||||
|
||||
|
||||
|
||||
result.add(rUploadPointStatisticalDataD);
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
//其他
|
||||
RUploadPointStatisticalDataD rUploadPointStatisticalDataD = new RUploadPointStatisticalDataD();
|
||||
rUploadPointStatisticalDataD.setStationType(dictDataMap.get(DicDataEnum.Station_Other.getCode()).getId());
|
||||
|
||||
rUploadPointStatisticalDataD.setId(IdUtil.simpleUUID());
|
||||
rUploadPointStatisticalDataD.setProvinceId(dept.getCode());
|
||||
rUploadPointStatisticalDataD.setProvinceName(dept.getName());
|
||||
rUploadPointStatisticalDataD.setStatisticalDate(calculatedParam.getDataDate());
|
||||
rUploadPointStatisticalDataD.setStatisticalType(UploadEnum.STATISTICAL_TYPE_03.getCode());
|
||||
rUploadPointStatisticalDataD.setUploadStatus(Integer.parseInt(UploadEnum.UPLOAD_STATUS_0.getCode()));
|
||||
//fixme 主配网标识文档中没有,先随便定义一个,后期调整
|
||||
//fixme 主配网标识文档中没有,先随便定义一个,后期调整
|
||||
rUploadPointStatisticalDataD.setDistributionFlag(UploadEnum.DISTRIBUTION_FLAG_01.getCode());
|
||||
//fixme over
|
||||
judgeLevel(item.getDeptLevel(),rUploadPointStatisticalDataD,item.getUnitId(),item.getUnitName(),deptList,deptMap);
|
||||
List<UploadPointStatisticalParam> l11 = devMap.get(item.getUnitId());
|
||||
if (CollectionUtil.isNotEmpty(l11)){
|
||||
UploadPointStatisticalParam po = l11.get(0);
|
||||
rUploadPointStatisticalDataD.setRunTerminalNum(po.getRunTerminalNum());
|
||||
rUploadPointStatisticalDataD.setOnlineMonitorNum(po.getOnlineMonitorNum());
|
||||
rUploadPointStatisticalDataD.setRunMonitorNum(po.getRunMonitorNum());
|
||||
rUploadPointStatisticalDataD.setOnlineMonitorRate(po.getOnlineMonitorNum()==0?0d:BigDecimal.valueOf(po.getOnlineMonitorNum()*100.0/po.getRunMonitorNum()).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue());
|
||||
}
|
||||
//获取当前单位下所有的监测点,匹配监测点数据
|
||||
List<LineDevGetDTO> l2 = item.getLineBaseList();
|
||||
if (CollectionUtil.isNotEmpty(l2)){
|
||||
List<RStatIntegrityD> l3 = dataList.stream().filter(it -> l2.stream().map(LineDevGetDTO::getPointId).collect(Collectors.toList()).contains(it.getLineIndex())).collect(Collectors.toList());
|
||||
judgeLevel(item.getDeptLevel(), rUploadPointStatisticalDataD, item.getUnitId(), item.getUnitName(), deptList, deptMap);
|
||||
|
||||
|
||||
long pointCount = otherMonitor.stream().map(LineDevGetDTO::getPointId).distinct().count();
|
||||
long devCount = otherMonitor.stream().map(LineDevGetDTO::getDevId).distinct().count();
|
||||
rUploadPointStatisticalDataD.setRunTerminalNum((int) devCount);
|
||||
rUploadPointStatisticalDataD.setOnlineMonitorNum((int) pointCount);
|
||||
rUploadPointStatisticalDataD.setRunMonitorNum((int) pointCount);
|
||||
rUploadPointStatisticalDataD.setOnlineMonitorRate(pointCount == 0 ? 0d : BigDecimal.valueOf(rUploadPointStatisticalDataD.getOnlineMonitorNum() * 100.0 / rUploadPointStatisticalDataD.getRunMonitorNum()).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
|
||||
|
||||
List<RStatIntegrityD> l3 = dataList.stream().filter(it -> otherMonitor.stream().map(LineDevGetDTO::getPointId).collect(Collectors.toList()).contains(it.getLineIndex())).collect(Collectors.toList());
|
||||
int due = l3.stream().mapToInt(RStatIntegrityD::getDueTime).sum();
|
||||
int real = l3.stream().mapToInt(RStatIntegrityD::getRealTime).sum();
|
||||
rUploadPointStatisticalDataD.setExpectCollectNum(due);
|
||||
rUploadPointStatisticalDataD.setActualCollectNum(real);
|
||||
|
||||
if(due == 0 || real == 0){
|
||||
if (due == 0 || real == 0) {
|
||||
rUploadPointStatisticalDataD.setDataFullRate(BigDecimal.valueOf(0).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
}else {
|
||||
rUploadPointStatisticalDataD.setDataFullRate(BigDecimal.valueOf(real*100.0/due).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
} else {
|
||||
rUploadPointStatisticalDataD.setDataFullRate(BigDecimal.valueOf(real * 100.0 / due).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
rUploadPointStatisticalDataD.setStationMonitorNum(l3.size());
|
||||
}
|
||||
|
||||
result.add(rUploadPointStatisticalDataD);
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
if (CollectionUtil.isNotEmpty(result)){
|
||||
|
||||
if (CollectionUtil.isNotEmpty(result)) {
|
||||
//查询数据如果有数据,将data_id置为null,这样就保留之前的唯一id
|
||||
LambdaQueryWrapper<RUploadPointStatisticalDataD> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(RUploadPointStatisticalDataD::getStatisticalDate,calculatedParam.getDataDate());
|
||||
lambdaQueryWrapper.eq(RUploadPointStatisticalDataD::getStatisticalDate, calculatedParam.getDataDate());
|
||||
List<RUploadPointStatisticalDataD> oldData = this.list(lambdaQueryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(oldData)){
|
||||
result.forEach(item->{
|
||||
item.setId(null);
|
||||
});
|
||||
if (CollectionUtil.isNotEmpty(oldData)) {
|
||||
result.forEach(it -> it.setId(null));
|
||||
}
|
||||
this.saveOrUpdateBatchByMultiId(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* r_operating_index_d表中获取终端、监测点个数
|
||||
*/
|
||||
public List<ROperatingIndexDPO> getOperatingIndexData(String time) {
|
||||
LambdaQueryWrapper<ROperatingIndexDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(ROperatingIndexDPO::getDataDate,time);
|
||||
return rOperatingIndexDPOMapper.selectList(lambdaQueryWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,28 +252,29 @@ public class RUploadPointStatisticalDataDServiceImpl extends MppServiceImpl<RUpl
|
||||
*/
|
||||
public List<RStatIntegrityD> getStatIntegrityData(String time) {
|
||||
LambdaQueryWrapper<RStatIntegrityD> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(RStatIntegrityD::getTimeId,time);
|
||||
lambdaQueryWrapper.eq(RStatIntegrityD::getTimeId, time);
|
||||
return rStatIntegrityDMapper.selectList(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断单位层级
|
||||
*/
|
||||
public void judgeLevel(Integer level, RUploadPointStatisticalDataD rUploadPointStatisticalDataD, String id, String name, List<Dept> deptList, Map<String,List<Dept>> map) {
|
||||
public void judgeLevel(Integer level, RUploadPointStatisticalDataD rUploadPointStatisticalDataD, String id, String name, List<Dept> deptList, Map<String, List<Dept>> map) {
|
||||
String result = "";
|
||||
if (Objects.equals(level,Integer.parseInt(UploadEnum.NJCN_DEPT_LEVEL_2.getCode()))){
|
||||
if (Objects.equals(level, Integer.parseInt(UploadEnum.NJCN_DEPT_LEVEL_2.getCode()))) {
|
||||
result = UploadEnum.STATISTICAL_LEVEL_3.getCode();
|
||||
rUploadPointStatisticalDataD.setCityId("");
|
||||
rUploadPointStatisticalDataD.setCountyId("");
|
||||
} else if (Objects.equals(level,Integer.parseInt(UploadEnum.NJCN_DEPT_LEVEL_3.getCode()))) {
|
||||
} else if (Objects.equals(level, Integer.parseInt(UploadEnum.NJCN_DEPT_LEVEL_3.getCode()))) {
|
||||
result = UploadEnum.STATISTICAL_LEVEL_4.getCode();
|
||||
rUploadPointStatisticalDataD.setCityId(id);
|
||||
rUploadPointStatisticalDataD.setCityName(name);
|
||||
rUploadPointStatisticalDataD.setCountyId("");
|
||||
} else if (Objects.equals(level,Integer.parseInt(UploadEnum.NJCN_DEPT_LEVEL_4.getCode()))) {
|
||||
} else if (Objects.equals(level, Integer.parseInt(UploadEnum.NJCN_DEPT_LEVEL_4.getCode()))) {
|
||||
result = UploadEnum.STATISTICAL_LEVEL_5.getCode();
|
||||
List<String> list = Arrays.stream(map.get(id).get(0).getPids().split(",")).map(String::trim).collect(Collectors.toList());
|
||||
String parentCode = deptList.stream().filter(o->Objects.equals(o.getId(),list.get(3))).findFirst().orElse(null).getCode();
|
||||
String parentCode = deptList.stream().filter(o -> Objects.equals(o.getId(), list.get(3))).findFirst().orElse(null).getCode();
|
||||
rUploadPointStatisticalDataD.setCityId(parentCode);
|
||||
rUploadPointStatisticalDataD.setCityName(map.get(parentCode).get(0).getName());
|
||||
rUploadPointStatisticalDataD.setCountyId(id);
|
||||
|
||||
Reference in New Issue
Block a user