主配网监测点统计数据算法

This commit is contained in:
2023-12-08 10:56:23 +08:00
parent df070093c5
commit 2f19b720ba
11 changed files with 537 additions and 0 deletions

View File

@@ -138,6 +138,7 @@ public class CommTerminalServiceImpl implements CommTerminalService {
deptGetChildrenMoreDTO.setUnitId(item.getUnitId());
deptGetChildrenMoreDTO.setUnitName(item.getUnitName());
deptGetChildrenMoreDTO.setUnitChildrenList(item.getUnitChildrenList());
deptGetChildrenMoreDTO.setDeptLevel(item.getDeptLevel());
List<String> deptIds = item.getUnitChildrenList();
if (CollectionUtil.isNotEmpty(deptIds)) {
List<LineDevGetDTO> lineList = new ArrayList<>();

View File

@@ -0,0 +1,57 @@
package com.njcn.harmonic.pojo.dto;
import lombok.Data;
import java.math.BigDecimal;
/**
* 类的介绍:上送国网-接收电能质量主配网监测点统计数据接口list实体
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/12/7 8:52
*/
@Data
public class MonitorStatisticalDTO {
private String id;
private String provinceId;
private String provinceName;
private String cityId;
private String cityName;
private String countyId;
private String countyName;
private Integer runTerminalNum;
private Integer onlineMonitorNum;
private Integer runMonitorNum;
private BigDecimal onlineMonitorRate;
private Integer expectCollectNum;
private Integer actualCollectNum;
private BigDecimal dataFullRate;
private String stationType;
private Integer stationMonitorNum;
private String statisticalDate;
private String statisticalLevel;
private String statisticalType;
private String distributionFlag;
}

View File

@@ -0,0 +1,129 @@
package com.njcn.harmonic.pojo.po.upload;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import lombok.Data;
/**
* <p>
* 主配网监测点统计数据-日表
* </p>
*
* @author xuyang
* @since 2023-12-07
*/
@Data
@TableName("r_upload_point_statistical_data_d")
public class RUploadPointStatisticalDataD {
private static final long serialVersionUID = 1L;
/**
* uuid
*/
private String dataId;
/**
* 省级单位id
*/
@MppMultiId
private String provinceId;
/**
* 省级单位名称
*/
private String provinceName;
/**
* 市级单位id
*/
@MppMultiId
private String cityId;
/**
* 市级单位名称
*/
private String cityName;
/**
* 县级单位id
*/
@MppMultiId
private String countyId;
/**
* 县级单位名称
*/
private String countyName;
/**
* 在运监测终端数量
*/
private Integer runTerminalNum;
/**
* 在线监测点个数
*/
private Integer onlineMonitorNum;
/**
* 在运监测点个数
*/
private Integer runMonitorNum;
/**
* 监测点在线率
*/
private Double onlineMonitorRate;
/**
* 数据应收数
*/
private Integer expectCollectNum;
/**
* 数据实收数
*/
private Integer actualCollectNum;
/**
* 完整率
*/
private Double dataFullRate;
/**
* 所属站别
*/
private String stationType;
/**
* 所属站别下的监测点个数
*/
private Integer stationMonitorNum;
/**
* 统计日期
*/
@MppMultiId
private String statisticalDate;
/**
* 统计层级
*/
@MppMultiId
private String statisticalLevel;
/**
* 统计类型
*/
@MppMultiId
private String statisticalType;
/**
* 主配网标识
*/
@MppMultiId
private String distributionFlag;
}

View File

@@ -0,0 +1,51 @@
package com.njcn.harmonic.controller.upload;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.harmonic.service.upload.PointStatisticalDataService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 类的介绍:国网指标数据上送
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/12/7 9:05
*/
@Validated
@Slf4j
@RestController
@RequestMapping("/upload")
@Api(tags = "国网指标数据上送")
@AllArgsConstructor
public class PointStatisticalDataController extends BaseController {
private final PointStatisticalDataService pointStatisticalDataService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/statisticalCreate")
@ApiOperation("主配网监测点统计数据(2.4.1.17)")
@ApiImplicitParam(name = "param", value = "实体参数", required = true)
public HttpResult<Object> statisticalCreate(@RequestBody Object param) {
String methodDescribe = getMethodDescribe("statisticalCreate");
LogUtil.njcnDebug(log, "{},实体参数:{}", methodDescribe, param);
pointStatisticalDataService.getPointStatisticalData(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -0,0 +1,14 @@
package com.njcn.harmonic.service.upload;
/**
* @author xuyang
*/
public interface PointStatisticalDataService {
/**
* 2.4.1.17接收电能质量主配网监测点统计数据接口
* @param param
*/
void getPointStatisticalData(Object param);
}

View File

@@ -0,0 +1,21 @@
package com.njcn.harmonic.service.upload.impl;
import com.njcn.harmonic.service.upload.PointStatisticalDataService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author xuyang
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class PointStatisticalDataServiceImpl implements PointStatisticalDataService {
@Override
public void getPointStatisticalData(Object param) {
}
}

View File

@@ -0,0 +1,52 @@
package com.njcn.prepare.harmonic.enums;
import lombok.Getter;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/12/7 14:32
*/
@Getter
public enum UploadEnum {
/**
* 统计层级
*/
STATISTICAL_LEVEL_3("3",""),
STATISTICAL_LEVEL_4("4",""),
STATISTICAL_LEVEL_5("5",""),
NJCN_DEPT_LEVEL_1("1","全国"),
NJCN_DEPT_LEVEL_2("2","省级"),
NJCN_DEPT_LEVEL_3("3","市级"),
NJCN_DEPT_LEVEL_4("4","县级"),
/**
* 统计类型
*/
STATISTICAL_TYPE_01("01","年数据"),
STATISTICAL_TYPE_02("02","月数据"),
STATISTICAL_TYPE_03("03","日数据"),
/**
* 主配网标识
*/
DISTRIBUTION_FLAG_01("01","主网"),
DISTRIBUTION_FLAG_02("02","配网"),
;
private final String code;
private final String message;
UploadEnum(String code, String message) {
this.code = code;
this.message = message;
}
}

View File

@@ -12,6 +12,7 @@ import com.njcn.prepare.harmonic.service.mysql.area.RStatOrgService;
import com.njcn.prepare.harmonic.service.mysql.dim.*;
import com.njcn.prepare.harmonic.service.mysql.line.PollutionService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.*;
import com.njcn.prepare.harmonic.service.mysql.upload.IRUploadPointStatisticalDataDService;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
@@ -67,6 +68,7 @@ public class OrgPointExecutor extends BaseExecutor{
private final RDimBusStationEventStartisDPOService rDimBusStationEventStartisDPOService;
private final RDimBusStationEventStartisMPOService rDimBusStationEventStartisMPOService;
private final RDimBusStationEventStartisYPOService rDimBusStationEventStartisYPOService;
private final IRUploadPointStatisticalDataDService irUploadPointStatisticalDataDService;
/**
*
* 3.3.2. 单位标数据质量
@@ -599,5 +601,18 @@ public class OrgPointExecutor extends BaseExecutor{
}
}
/**
* 河北国网上送接口
* 2.4.1.17接收电能质量主配网监测点统计数据接口
* xuyang
*/
@LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "rUploadPointStatisticalData", nodeType = NodeTypeEnum.COMMON)
public boolean rUploadPointStatisticalDataAccess(NodeComponent bindCmp) {
return isAccess(bindCmp);
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "rUploadPointStatisticalData", nodeType = NodeTypeEnum.COMMON)
public void rUploadPointStatisticalDataProcess(NodeComponent bindCmp) {
irUploadPointStatisticalDataDService.insertPointStatisticalDataDay(bindCmp.getRequestData());
}
}

View File

@@ -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> {
}

View File

@@ -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);
}

View File

@@ -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;
}
}