算法提交
This commit is contained in:
@@ -19,6 +19,6 @@ public interface IRUploadSubstationStatisticalDataDService extends IService<RUpl
|
||||
* 变电站监测统计数据
|
||||
* @param calculatedParam
|
||||
*/
|
||||
void insertSubStatisticalDataDay(CalculatedParam<DeptGetChildrenMoreDTO> calculatedParam);
|
||||
void insertSubStatisticalDataDay(CalculatedParam<String> calculatedParam);
|
||||
|
||||
}
|
||||
|
||||
@@ -21,10 +21,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -55,13 +52,15 @@ public class RUploadPointStatisticalDataDServiceImpl extends MppServiceImpl<RUpl
|
||||
//获取省级单位id
|
||||
Dept data = deptFeignClient.getRootDept().getData();
|
||||
String provinceId = deptFeignClient.getDepSonIdByDeptId(data.getId()).getData().get(0);
|
||||
String code = deptFeignClient.getDeptById(provinceId).getData().getCode();
|
||||
Dept dept = deptFeignClient.getDeptById(provinceId).getData();
|
||||
//获取监测点、终端个数
|
||||
List<ROperatingIndexDPO> devList = getOperatingIndexData(calculatedParam.getDataDate());
|
||||
Map<String,List<ROperatingIndexDPO>> devMap = devList.stream().collect(Collectors.groupingBy(ROperatingIndexDPO::getOrgNo));
|
||||
//获取数据个数
|
||||
List<RStatIntegrityD> dataList = getStatIntegrityData(calculatedParam.getDataDate());
|
||||
//获取所有单位
|
||||
List<Dept> deptList = deptFeignClient.getAllDept().getData();
|
||||
Map<String,List<Dept>> deptMap = deptList.stream().collect(Collectors.groupingBy(Dept::getCode));
|
||||
List<DeptGetChildrenMoreDTO> list = calculatedParam.getIdList();
|
||||
list.forEach(item->{
|
||||
if (Objects.equals(Integer.parseInt(UploadEnum.NJCN_DEPT_LEVEL_1.getCode()),item.getDeptLevel())){
|
||||
@@ -69,30 +68,21 @@ public class RUploadPointStatisticalDataDServiceImpl extends MppServiceImpl<RUpl
|
||||
}
|
||||
RUploadPointStatisticalDataD rUploadPointStatisticalDataD = new RUploadPointStatisticalDataD();
|
||||
rUploadPointStatisticalDataD.setId(IdUtil.simpleUUID());
|
||||
rUploadPointStatisticalDataD.setProvinceId(code);
|
||||
rUploadPointStatisticalDataD.setProvinceId(dept.getCode());
|
||||
rUploadPointStatisticalDataD.setProvinceName(dept.getName());
|
||||
rUploadPointStatisticalDataD.setStatisticalDate(calculatedParam.getDataDate());
|
||||
rUploadPointStatisticalDataD.setStatisticalLevel(judgeLevel(item.getDeptLevel()));
|
||||
rUploadPointStatisticalDataD.setStatisticalType(UploadEnum.STATISTICAL_TYPE_03.getCode());
|
||||
//fixme 主配网标识文档中没有,先随便定义一个,后期调整
|
||||
rUploadPointStatisticalDataD.setDistributionFlag(UploadEnum.DISTRIBUTION_FLAG_01.getCode());
|
||||
//fixme over
|
||||
if (Objects.equals(item.getDeptLevel(),Integer.parseInt(UploadEnum.NJCN_DEPT_LEVEL_2.getCode()))) {
|
||||
rUploadPointStatisticalDataD.setCityId("");
|
||||
rUploadPointStatisticalDataD.setCountyId("");
|
||||
} else if (Objects.equals(item.getDeptLevel(),Integer.parseInt(UploadEnum.NJCN_DEPT_LEVEL_3.getCode()))) {
|
||||
rUploadPointStatisticalDataD.setCityId(item.getUnitId());
|
||||
rUploadPointStatisticalDataD.setCountyId("");
|
||||
} else if (Objects.equals(item.getDeptLevel(),Integer.parseInt(UploadEnum.NJCN_DEPT_LEVEL_4.getCode()))) {
|
||||
rUploadPointStatisticalDataD.setCityId("");
|
||||
rUploadPointStatisticalDataD.setCountyId(item.getUnitId());
|
||||
}
|
||||
judgeLevel(item.getDeptLevel(),rUploadPointStatisticalDataD,item.getUnitId(),item.getUnitName(),deptList,deptMap);
|
||||
List<ROperatingIndexDPO> l1 = devMap.get(item.getUnitId());
|
||||
if (CollectionUtil.isNotEmpty(l1)){
|
||||
ROperatingIndexDPO po = l1.get(0);
|
||||
rUploadPointStatisticalDataD.setRunTerminalNum(po.getOnlineMeasurementPoints());
|
||||
rUploadPointStatisticalDataD.setOnlineMonitorNum(po.getTransitMeasurementPoints());
|
||||
rUploadPointStatisticalDataD.setRunMonitorNum(po.getMeasurementRunPoints());
|
||||
rUploadPointStatisticalDataD.setOnlineMonitorRate(BigDecimal.valueOf(po.getMeasurementRunPoints()*100.0/po.getTransitMeasurementPoints()).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue());
|
||||
rUploadPointStatisticalDataD.setOnlineMonitorRate(po.getMeasurementRunPoints()==0?0d:BigDecimal.valueOf(po.getTransitMeasurementPoints()*100.0/po.getMeasurementRunPoints()).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue());
|
||||
}
|
||||
//获取当前单位下所有的监测点,匹配监测点数据
|
||||
List<LineDevGetDTO> l2 = item.getLineBaseList();
|
||||
@@ -142,16 +132,27 @@ public class RUploadPointStatisticalDataDServiceImpl extends MppServiceImpl<RUpl
|
||||
/**
|
||||
* 判断单位层级
|
||||
*/
|
||||
public String judgeLevel(Integer level) {
|
||||
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()))){
|
||||
result = UploadEnum.STATISTICAL_LEVEL_3.getCode();
|
||||
rUploadPointStatisticalDataD.setCityId("");
|
||||
rUploadPointStatisticalDataD.setCountyId("");
|
||||
} 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()))) {
|
||||
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();
|
||||
rUploadPointStatisticalDataD.setCityId(parentCode);
|
||||
rUploadPointStatisticalDataD.setCityName(map.get(parentCode).get(0).getName());
|
||||
rUploadPointStatisticalDataD.setCountyId(id);
|
||||
rUploadPointStatisticalDataD.setCountyName(name);
|
||||
}
|
||||
return result;
|
||||
rUploadPointStatisticalDataD.setStatisticalLevel(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
package com.njcn.prepare.harmonic.service.mysql.upload.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
|
||||
import com.njcn.device.biz.commApi.CommTerminalGeneralClient;
|
||||
import com.njcn.device.biz.pojo.dto.DeptGetChildrenMoreDTO;
|
||||
import com.njcn.device.biz.pojo.dto.DeptGetSubStationDTO;
|
||||
import com.njcn.device.biz.pojo.param.DeptGetLineParam;
|
||||
import com.njcn.device.pms.api.StatationStatClient;
|
||||
import com.njcn.device.pms.pojo.param.PmsStatationStatInfoParam;
|
||||
import com.njcn.device.pms.pojo.po.StatationStat;
|
||||
import com.njcn.harmonic.pojo.po.upload.RUploadPointStatisticalDataD;
|
||||
import com.njcn.harmonic.pojo.po.upload.RUploadSubstationStatisticalDataD;
|
||||
import com.njcn.prepare.harmonic.enums.UploadEnum;
|
||||
import com.njcn.prepare.harmonic.mapper.mysql.upload.RUploadSubstationStatisticalDataDMapper;
|
||||
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
|
||||
import com.njcn.prepare.harmonic.service.mysql.upload.IRUploadSubstationStatisticalDataDService;
|
||||
@@ -15,7 +24,8 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -28,23 +38,105 @@ import java.util.List;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class RUploadSubstationStatisticalDataDServiceImpl extends ServiceImpl<RUploadSubstationStatisticalDataDMapper, RUploadSubstationStatisticalDataD> implements IRUploadSubstationStatisticalDataDService {
|
||||
public class RUploadSubstationStatisticalDataDServiceImpl extends MppServiceImpl<RUploadSubstationStatisticalDataDMapper, RUploadSubstationStatisticalDataD> implements IRUploadSubstationStatisticalDataDService {
|
||||
|
||||
private final CommTerminalGeneralClient commTerminalGeneralClient;
|
||||
private final DeptFeignClient deptFeignClient;
|
||||
private final StatationStatClient statationStatClient;
|
||||
@Override
|
||||
public void insertSubStatisticalDataDay(CalculatedParam<DeptGetChildrenMoreDTO> calculatedParam) {
|
||||
DeptGetLineParam deptGetLineParam = new DeptGetLineParam();
|
||||
public void insertSubStatisticalDataDay(CalculatedParam<String> calculatedParam) {
|
||||
List<RUploadSubstationStatisticalDataD> result = new ArrayList<>();
|
||||
//获取省级单位id
|
||||
Dept data = deptFeignClient.getRootDept().getData();
|
||||
deptGetLineParam.setDeptId(data.getId());
|
||||
List<DeptGetSubStationDTO> data1 = commTerminalGeneralClient.deptSubStation(deptGetLineParam).getData();
|
||||
data1.forEach(item->{
|
||||
System.out.println("id==:" + item.getUnitId());
|
||||
System.out.println("level==:" + item.getDeptLevel());
|
||||
System.out.println("");
|
||||
String provinceId = deptFeignClient.getDepSonIdByDeptId(data.getId()).getData().get(0);
|
||||
Dept dept = deptFeignClient.getDeptById(provinceId).getData();
|
||||
//变电站id
|
||||
List<String> subList = calculatedParam.getIdList();
|
||||
//获取变电站信息
|
||||
List<StatationStat> subInfo = getSubstationInfo(subList);
|
||||
Map<String,List<StatationStat>> subMap = subInfo.stream().collect(Collectors.groupingBy(StatationStat::getOrgId));
|
||||
//获取所有部门单位信息
|
||||
List<Dept> deptList = deptFeignClient.getAllDept().getData();
|
||||
Map<String,List<Dept>> deptMap = deptList.stream().collect(Collectors.groupingBy(Dept::getCode));
|
||||
deptMap.forEach((k,v)->{
|
||||
List<String> list = Arrays.stream(v.get(0).getPids().split(",")).map(String::trim).collect(Collectors.toList());
|
||||
if (list.size() > 2){
|
||||
RUploadSubstationStatisticalDataD rUploadSubstationStatisticalDataD = new RUploadSubstationStatisticalDataD();
|
||||
rUploadSubstationStatisticalDataD.setId(IdUtil.simpleUUID());
|
||||
rUploadSubstationStatisticalDataD.setStatisticalDate(calculatedParam.getDataDate());
|
||||
rUploadSubstationStatisticalDataD.setStatisticalType(UploadEnum.STATISTICAL_TYPE_03.getCode());
|
||||
rUploadSubstationStatisticalDataD.setProvinceId(dept.getCode());
|
||||
rUploadSubstationStatisticalDataD.setProvinceName(dept.getName());
|
||||
//处理层级关系 && 处理基础数据
|
||||
getDeptLevel(list,rUploadSubstationStatisticalDataD,deptList,deptMap,k,subMap);
|
||||
result.add(rUploadSubstationStatisticalDataD);
|
||||
}
|
||||
});
|
||||
if (CollectionUtil.isNotEmpty(result)){
|
||||
//查询数据如果有数据,将data_id置为null,这样就保留之前的唯一id
|
||||
LambdaQueryWrapper<RUploadSubstationStatisticalDataD> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(RUploadSubstationStatisticalDataD::getStatisticalDate,calculatedParam.getDataDate());
|
||||
List<RUploadSubstationStatisticalDataD> oldData = this.list(lambdaQueryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(oldData)){
|
||||
result.forEach(item->{
|
||||
item.setId(null);
|
||||
});
|
||||
}
|
||||
//存储数据
|
||||
this.saveOrUpdateBatchByMultiId(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取变电站信息
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
public List<StatationStat> getSubstationInfo(List<String> list) {
|
||||
PmsStatationStatInfoParam param = new PmsStatationStatInfoParam();
|
||||
param.setPowerIds(list);
|
||||
return statationStatClient.getPowerInfo(param).getData();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断当前部门的层级
|
||||
* @return
|
||||
*/
|
||||
public void getDeptLevel(List<String> list, RUploadSubstationStatisticalDataD rUploadSubstationStatisticalDataD, List<Dept> deptList, Map<String,List<Dept>> map, String code, Map<String,List<StatationStat>> subMap) {
|
||||
switch (list.size()) {
|
||||
//市级
|
||||
case 3:
|
||||
int count = 0;
|
||||
//处理层级
|
||||
rUploadSubstationStatisticalDataD.setCityId(code);
|
||||
rUploadSubstationStatisticalDataD.setCityName(map.get(code).get(0).getName());
|
||||
rUploadSubstationStatisticalDataD.setCountyId("");
|
||||
//处理基础数据
|
||||
String id = deptList.stream().filter(o->Objects.equals(o.getCode(),code)).findAny().orElse(null).getId();
|
||||
List<String> codeList = deptList.stream().filter(o->Objects.equals(o.getPid(),id)).map(Dept::getCode).collect(Collectors.toList());
|
||||
for (String item : codeList) {
|
||||
List<StatationStat> l = subMap.get(item);
|
||||
if (CollectionUtil.isNotEmpty(l)){
|
||||
count = count + l.size();
|
||||
}
|
||||
}
|
||||
rUploadSubstationStatisticalDataD.setSubstationCount(count == 0 ? null:count);
|
||||
break;
|
||||
//县级
|
||||
case 4:
|
||||
//处理层级
|
||||
String parentCode = deptList.stream().filter(o->Objects.equals(o.getId(),list.get(3))).findFirst().orElse(null).getCode();
|
||||
rUploadSubstationStatisticalDataD.setCityId(parentCode);
|
||||
rUploadSubstationStatisticalDataD.setCityName(map.get(parentCode).get(0).getName());
|
||||
rUploadSubstationStatisticalDataD.setCountyId(code);
|
||||
rUploadSubstationStatisticalDataD.setCountyName(map.get(code).get(0).getName());
|
||||
//处理基础数据
|
||||
List<StatationStat> l = subMap.get(code);
|
||||
if (CollectionUtil.isNotEmpty(l)){
|
||||
rUploadSubstationStatisticalDataD.setSubstationCount(l.size());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user