主配网监测点统计数据算法
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.njcn.prepare.harmonic.mapper.mysql.upload;
|
||||
|
||||
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
|
||||
import com.njcn.harmonic.pojo.po.upload.RUploadPointStatisticalDataD;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 主配网监测点统计数据-日表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-12-07
|
||||
*/
|
||||
public interface RUploadPointStatisticalDataDMapper extends MppBaseMapper<RUploadPointStatisticalDataD> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.njcn.prepare.harmonic.service.mysql.upload;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.device.biz.pojo.dto.DeptGetChildrenMoreDTO;
|
||||
import com.njcn.harmonic.pojo.po.upload.RUploadPointStatisticalDataD;
|
||||
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 主配网监测点统计数据-日表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-12-07
|
||||
*/
|
||||
public interface IRUploadPointStatisticalDataDService extends IService<RUploadPointStatisticalDataD> {
|
||||
|
||||
/**
|
||||
* 插入日表数据
|
||||
* @param calculatedParam
|
||||
*/
|
||||
void insertPointStatisticalDataDay(CalculatedParam<DeptGetChildrenMoreDTO> calculatedParam);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
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.github.jeffreyning.mybatisplus.service.MppServiceImpl;
|
||||
import com.njcn.device.biz.pojo.dto.DeptGetChildrenMoreDTO;
|
||||
import com.njcn.device.biz.pojo.dto.LineDevGetDTO;
|
||||
import com.njcn.device.pq.pojo.po.RStatIntegrityD;
|
||||
import com.njcn.harmonic.pojo.po.ROperatingIndexDPO;
|
||||
import com.njcn.harmonic.pojo.po.upload.RUploadPointStatisticalDataD;
|
||||
import com.njcn.prepare.harmonic.enums.UploadEnum;
|
||||
import com.njcn.prepare.harmonic.mapper.mysql.area.ROperatingIndexDPOMapper;
|
||||
import com.njcn.prepare.harmonic.mapper.mysql.day.RStatIntegrityDMapper;
|
||||
import com.njcn.prepare.harmonic.mapper.mysql.upload.RUploadPointStatisticalDataDMapper;
|
||||
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
|
||||
import com.njcn.prepare.harmonic.service.mysql.upload.IRUploadPointStatisticalDataDService;
|
||||
import com.njcn.user.api.DeptFeignClient;
|
||||
import com.njcn.user.pojo.po.Dept;
|
||||
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.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 主配网监测点统计数据-日表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-12-07
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class RUploadPointStatisticalDataDServiceImpl extends MppServiceImpl<RUploadPointStatisticalDataDMapper, RUploadPointStatisticalDataD> implements IRUploadPointStatisticalDataDService {
|
||||
|
||||
private final DeptFeignClient deptFeignClient;
|
||||
private final ROperatingIndexDPOMapper rOperatingIndexDPOMapper;
|
||||
private final RStatIntegrityDMapper rStatIntegrityDMapper;
|
||||
|
||||
/**
|
||||
* 此算法用于计算底层数据,方便国网数据上送
|
||||
* 1.表中存储所有单位,没有数据的暂时设置为0
|
||||
* 2.r_operating_index_d表中获取终端、监测点个数
|
||||
* 3.r_stat_integrity_d表中获取数据应收数、实收数
|
||||
*/
|
||||
@Override
|
||||
public void insertPointStatisticalDataDay(CalculatedParam<DeptGetChildrenMoreDTO> calculatedParam) {
|
||||
List<RUploadPointStatisticalDataD> result = new ArrayList<>();
|
||||
//获取省级单位id
|
||||
Dept data = deptFeignClient.getRootDept().getData();
|
||||
String provinceId = deptFeignClient.getDepSonIdByDeptId(data.getId()).getData().get(0);
|
||||
String code = deptFeignClient.getDeptById(provinceId).getData().getCode();
|
||||
//获取监测点、终端个数
|
||||
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<DeptGetChildrenMoreDTO> list = calculatedParam.getIdList();
|
||||
list.forEach(item->{
|
||||
if (Objects.equals(Integer.parseInt(UploadEnum.NJCN_DEPT_LEVEL_1.getCode()),item.getDeptLevel())){
|
||||
return;
|
||||
}
|
||||
RUploadPointStatisticalDataD rUploadPointStatisticalDataD = new RUploadPointStatisticalDataD();
|
||||
rUploadPointStatisticalDataD.setDataId(IdUtil.simpleUUID());
|
||||
rUploadPointStatisticalDataD.setProvinceId(code);
|
||||
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());
|
||||
}
|
||||
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());
|
||||
}
|
||||
//获取当前单位下所有的监测点,匹配监测点数据
|
||||
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());
|
||||
int due = l3.stream().mapToInt(RStatIntegrityD::getDueTime).sum();
|
||||
int real = l3.stream().mapToInt(RStatIntegrityD::getRealTime).sum();
|
||||
rUploadPointStatisticalDataD.setExpectCollectNum(due);
|
||||
rUploadPointStatisticalDataD.setActualCollectNum(real);
|
||||
rUploadPointStatisticalDataD.setDataFullRate(BigDecimal.valueOf(real*100.0/due).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue());
|
||||
rUploadPointStatisticalDataD.setStationMonitorNum(l3.size());
|
||||
}
|
||||
result.add(rUploadPointStatisticalDataD);
|
||||
});
|
||||
if (CollectionUtil.isNotEmpty(result)){
|
||||
//查询数据如果有数据,将data_id置为null,这样就保留之前的唯一id
|
||||
LambdaQueryWrapper<RUploadPointStatisticalDataD> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(RUploadPointStatisticalDataD::getStatisticalDate,calculatedParam.getDataDate());
|
||||
List<RUploadPointStatisticalDataD> oldData = this.list(lambdaQueryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(oldData)){
|
||||
result.forEach(item->{
|
||||
item.setDataId(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);
|
||||
}
|
||||
|
||||
/**
|
||||
* r_stat_integrity_d表中获取数据应收数、实收数
|
||||
*/
|
||||
public List<RStatIntegrityD> getStatIntegrityData(String time) {
|
||||
LambdaQueryWrapper<RStatIntegrityD> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(RStatIntegrityD::getTimeId,time);
|
||||
return rStatIntegrityDMapper.selectList(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断单位层级
|
||||
*/
|
||||
public String judgeLevel(Integer level) {
|
||||
String result = "";
|
||||
if (Objects.equals(level,Integer.parseInt(UploadEnum.NJCN_DEPT_LEVEL_2.getCode()))){
|
||||
result = UploadEnum.STATISTICAL_LEVEL_3.getCode();
|
||||
} else if (Objects.equals(level,Integer.parseInt(UploadEnum.NJCN_DEPT_LEVEL_3.getCode()))) {
|
||||
result = UploadEnum.STATISTICAL_LEVEL_4.getCode();
|
||||
} else if (Objects.equals(level,Integer.parseInt(UploadEnum.NJCN_DEPT_LEVEL_4.getCode()))) {
|
||||
result = UploadEnum.STATISTICAL_LEVEL_5.getCode();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user