|
|
|
|
@@ -0,0 +1,318 @@
|
|
|
|
|
package com.njcn.prepare.harmonic.service.mysql.upload.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
|
|
|
|
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
|
|
|
|
|
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
|
|
|
|
import com.njcn.common.pojo.exception.BusinessException;
|
|
|
|
|
import com.njcn.device.biz.commApi.CommLineClient;
|
|
|
|
|
import com.njcn.device.biz.commApi.CommTerminalGeneralClient;
|
|
|
|
|
import com.njcn.device.pms.api.MonitorClient;
|
|
|
|
|
import com.njcn.device.pms.pojo.param.MonitorParam;
|
|
|
|
|
import com.njcn.device.pms.pojo.po.GeneratrixWire;
|
|
|
|
|
import com.njcn.device.pms.pojo.po.Monitor;
|
|
|
|
|
import com.njcn.device.pms.pojo.po.PmsMidLedger;
|
|
|
|
|
import com.njcn.device.pms.pojo.po.StatationStat;
|
|
|
|
|
import com.njcn.device.pq.pojo.po.RStatIntegrityD;
|
|
|
|
|
import com.njcn.harmonic.annotaion.HarVoltage;
|
|
|
|
|
import com.njcn.harmonic.pojo.po.RStatDataVD;
|
|
|
|
|
import com.njcn.harmonic.pojo.po.day.RStatDataVDPO;
|
|
|
|
|
import com.njcn.harmonic.pojo.po.day.RStatLimitRateDPO;
|
|
|
|
|
import com.njcn.harmonic.pojo.po.upload.RUploadCommPointBus;
|
|
|
|
|
|
|
|
|
|
import com.njcn.prepare.harmonic.mapper.mysql.day.RStatDataFlickerDMapper;
|
|
|
|
|
import com.njcn.prepare.harmonic.mapper.mysql.day.RStatDataVDMapper;
|
|
|
|
|
import com.njcn.prepare.harmonic.mapper.mysql.day.RStatIntegrityDMapper;
|
|
|
|
|
import com.njcn.prepare.harmonic.mapper.mysql.day.RStatLimitRateDMapper;
|
|
|
|
|
import com.njcn.prepare.harmonic.mapper.mysql.dim.GeneratrixWireMapper;
|
|
|
|
|
import com.njcn.prepare.harmonic.mapper.mysql.dim.PmsMidLedgerMapper;
|
|
|
|
|
import com.njcn.prepare.harmonic.mapper.mysql.upload.PmsStatationStatMapper;
|
|
|
|
|
import com.njcn.prepare.harmonic.mapper.mysql.upload.RUploadCommPointBusMapper;
|
|
|
|
|
import com.njcn.prepare.harmonic.service.mysql.upload.IRUploadCommPointBusService;
|
|
|
|
|
import com.njcn.system.api.DicDataFeignClient;
|
|
|
|
|
import com.njcn.system.enums.DicDataEnum;
|
|
|
|
|
import com.njcn.system.enums.DicDataTypeEnum;
|
|
|
|
|
import com.njcn.system.pojo.po.DictData;
|
|
|
|
|
import com.njcn.user.api.DeptFeignClient;
|
|
|
|
|
import com.njcn.user.pojo.po.Dept;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>
|
|
|
|
|
* 公共连接点母线电能质量统计 服务实现类
|
|
|
|
|
* </p>
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class RUploadCommPointBusServiceImpl extends MppServiceImpl<RUploadCommPointBusMapper, RUploadCommPointBus> implements IRUploadCommPointBusService {
|
|
|
|
|
|
|
|
|
|
private final MonitorClient monitorClient;
|
|
|
|
|
|
|
|
|
|
private final DicDataFeignClient dicDataFeignClient;
|
|
|
|
|
|
|
|
|
|
private final DeptFeignClient deptFeignClient;
|
|
|
|
|
|
|
|
|
|
private final RStatIntegrityDMapper rStatIntegrityDMapper;
|
|
|
|
|
|
|
|
|
|
private final GeneratrixWireMapper generatrixWireMapper;
|
|
|
|
|
|
|
|
|
|
private final PmsMidLedgerMapper pmsMidLedgerMapper;
|
|
|
|
|
|
|
|
|
|
private final PmsStatationStatMapper pmsStatationStatMapper;
|
|
|
|
|
|
|
|
|
|
private final RStatDataVDMapper rStatDataVDMapper;
|
|
|
|
|
|
|
|
|
|
private final RStatDataFlickerDMapper rStatDataFlickerDMapper;
|
|
|
|
|
|
|
|
|
|
private final RStatLimitRateDMapper rStatLimitRateDMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Async("asyncExecutor")
|
|
|
|
|
public void handlerDay(String date){
|
|
|
|
|
List<RUploadCommPointBus> poLIst = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
DictData dictDataStatus = dicDataFeignClient.getDicDataByCodeAndType(DicDataEnum.RUN.getCode(), DicDataTypeEnum.LINE_STATE.getCode()).getData();
|
|
|
|
|
DictData dictDataType = dicDataFeignClient.getDicDataByCodeAndType(DicDataEnum.Pub_Connect_Point.getCode(), DicDataTypeEnum.LINE_TYPE.getCode()).getData();
|
|
|
|
|
|
|
|
|
|
//电压
|
|
|
|
|
List<DictData> dictDataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.DEV_VOLTAGE.getCode()).getData();
|
|
|
|
|
Map<String,DictData> voltageMap = dictDataList.stream().collect(Collectors.toMap(DictData::getId,Function.identity()));
|
|
|
|
|
|
|
|
|
|
String rootDeptId = deptFeignClient.getRootDept().getData().getId();
|
|
|
|
|
List<Dept> deptList = deptFeignClient.getDirectSonSelf(rootDeptId).getData();
|
|
|
|
|
Optional<Dept> optional = deptList.stream().filter(item->!item.getId().equals(rootDeptId)).findFirst();
|
|
|
|
|
Dept provinceOrg;
|
|
|
|
|
if(optional.isPresent()){
|
|
|
|
|
provinceOrg = optional.get();
|
|
|
|
|
}else {
|
|
|
|
|
log.error("公共连接点算法执行异常,获取部门异常,请联系管理员排查");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Dept> deptL = deptFeignClient.getAllDept().getData();
|
|
|
|
|
Map<String,Dept> deptIdMap = deptL.stream().collect(Collectors.toMap(Dept::getId,Function.identity()));
|
|
|
|
|
Map<String,Dept> deptCodeMap = deptL.stream().collect(Collectors.toMap(Dept::getCode,Function.identity()));
|
|
|
|
|
|
|
|
|
|
MonitorParam monitorParam = new MonitorParam();
|
|
|
|
|
monitorParam.setIsUpToGrid(DataStateEnum.ENABLE.getCode());
|
|
|
|
|
monitorParam.setMonitorState(dictDataStatus.getId());
|
|
|
|
|
monitorParam.setMonitorType(dictDataType.getId());
|
|
|
|
|
List<Monitor> monitorList = monitorClient.getMonitorListByParam(monitorParam).getData();
|
|
|
|
|
if(CollUtil.isNotEmpty(monitorList)){
|
|
|
|
|
//筛选所有测点
|
|
|
|
|
List<String> monitorIds = monitorList.stream().map(Monitor::getId).distinct().collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
//获取灿能母线
|
|
|
|
|
List<String> lineIds = monitorList.stream().map(Monitor::getLineId).distinct().collect(Collectors.toList());
|
|
|
|
|
List<GeneratrixWire> generatrixWireList = generatrixWireMapper.selectBatchIds(lineIds);
|
|
|
|
|
Map<String,GeneratrixWire> cnBusMap = generatrixWireList.stream().collect(Collectors.toMap(GeneratrixWire::getId,Function.identity()));
|
|
|
|
|
|
|
|
|
|
//获取同源母线
|
|
|
|
|
List<String> midBusIds = generatrixWireList.stream().map(GeneratrixWire::getMidBusId).distinct().collect(Collectors.toList());
|
|
|
|
|
Map<String,PmsMidLedger> midMap = pmsMidLedgerMapper.selectBatchIds(midBusIds).stream().collect(Collectors.toMap(PmsMidLedger::getId,Function.identity()));
|
|
|
|
|
|
|
|
|
|
//灿能电站
|
|
|
|
|
List<String> stationIds = monitorList.stream().map(Monitor::getPowerrId).distinct().collect(Collectors.toList());
|
|
|
|
|
List<StatationStat> stationList = pmsStatationStatMapper.selectBatchIds(stationIds);
|
|
|
|
|
Map<String,StatationStat> cnStatMap = stationList.stream().collect(Collectors.toMap(StatationStat::getPowerId,Function.identity()));
|
|
|
|
|
List<String> midStationIds = stationList.stream().map(StatationStat::getMidStationId).distinct().collect(Collectors.toList());
|
|
|
|
|
Map<String,PmsMidLedger> midStationMap = pmsMidLedgerMapper.selectBatchIds(midStationIds).stream().collect(Collectors.toMap(PmsMidLedger::getId,Function.identity()));
|
|
|
|
|
|
|
|
|
|
//监测点完整率
|
|
|
|
|
List<RStatIntegrityD> rStatIntegrityDList = rStatIntegrityDMapper.selectList(new LambdaQueryWrapper<RStatIntegrityD>().eq(RStatIntegrityD::getTimeId,date).in(RStatIntegrityD::getLineIndex,monitorIds));
|
|
|
|
|
Map<String,RStatIntegrityD> inteMap = rStatIntegrityDList.stream().collect(Collectors.toMap(RStatIntegrityD::getLineIndex, Function.identity()));
|
|
|
|
|
|
|
|
|
|
//循环母线
|
|
|
|
|
Map<String,List<Monitor>> mapMonitor = monitorList.stream().collect(Collectors.groupingBy(Monitor::getLineId));
|
|
|
|
|
|
|
|
|
|
mapMonitor.forEach((busId,pointList)->{
|
|
|
|
|
RUploadCommPointBus rUploadCommPointBus = new RUploadCommPointBus();
|
|
|
|
|
GeneratrixWire generatrixWire = cnBusMap.get(busId);
|
|
|
|
|
rUploadCommPointBus.setBusId(generatrixWire.getMidBusId());
|
|
|
|
|
PmsMidLedger busMid = midMap.get(generatrixWire.getMidBusId());
|
|
|
|
|
rUploadCommPointBus.setBusName(busMid.getName());
|
|
|
|
|
rUploadCommPointBus.setBusVoltageLevel(String.format("%02d",voltageMap.get(busMid.getVoltageLevel()).getAlgoDescribe()));
|
|
|
|
|
rUploadCommPointBus.setStatisticalType(DicDataEnum.STATISTICAL_TYPE_D.getCode());
|
|
|
|
|
rUploadCommPointBus.setStatisticalDate(date);
|
|
|
|
|
|
|
|
|
|
Monitor point;
|
|
|
|
|
//rUploadCommPointBus.setCityOrg();
|
|
|
|
|
if(pointList.size()>1){
|
|
|
|
|
//筛选最优测点进行数据统计
|
|
|
|
|
point = goodMonitor(pointList,inteMap);
|
|
|
|
|
}else {
|
|
|
|
|
point = pointList.get(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rUploadCommPointBus.setProvinceOrg(provinceOrg.getCode());
|
|
|
|
|
rUploadCommPointBus.setProvinceOrgName(provinceOrg.getName());
|
|
|
|
|
|
|
|
|
|
Dept deptTem = deptIdMap.get(deptCodeMap.get(point.getOrgId()).getPid());
|
|
|
|
|
rUploadCommPointBus.setCityOrg(deptTem.getCode());
|
|
|
|
|
rUploadCommPointBus.setCityOrgName(deptTem.getName());
|
|
|
|
|
|
|
|
|
|
rUploadCommPointBus.setMaintOrg(point.getOperationId());
|
|
|
|
|
rUploadCommPointBus.setMaintOrgName(point.getOperationName());
|
|
|
|
|
rUploadCommPointBus.setStationType("zf01");
|
|
|
|
|
rUploadCommPointBus.setStationId(cnStatMap.get(point.getPowerrId()).getMidStationId());
|
|
|
|
|
PmsMidLedger midStation = midStationMap.get(cnStatMap.get(point.getPowerrId()).getMidStationId());
|
|
|
|
|
rUploadCommPointBus.setStationName(midStation.getName());
|
|
|
|
|
rUploadCommPointBus.setStationVoltageLevel(String.format("%02d",voltageMap.get(midStation.getVoltageLevel()).getAlgoDescribe()));
|
|
|
|
|
rUploadCommPointBus.setMonitorId(point.getMonitorId());
|
|
|
|
|
rUploadCommPointBus.setDataSource("01");
|
|
|
|
|
rUploadCommPointBus.setCnMonitorId(point.getId());
|
|
|
|
|
poLIst.add(rUploadCommPointBus);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
List<String> cnIds = poLIst.stream().map(RUploadCommPointBus::getCnMonitorId).distinct().collect(Collectors.toList());
|
|
|
|
|
QueryWrapper<RStatDataVDPO> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
queryWrapper.select("avg(rms) as rms,line_id").eq("time",date).in("line_id",cnIds).eq("value_type","AVG").groupBy("line_id");
|
|
|
|
|
List<RStatDataVDPO> rStatDataVDList = rStatDataVDMapper.selectList(queryWrapper);
|
|
|
|
|
Map<String,RStatDataVDPO> avgMap = rStatDataVDList.stream().collect(Collectors.toMap(RStatDataVDPO::getLineId,Function.identity()));
|
|
|
|
|
|
|
|
|
|
queryWrapper.clear();
|
|
|
|
|
queryWrapper.select("max(rms) as rms,line_id").eq("time",date).in("line_id",cnIds).eq("value_type","CP95").groupBy("line_id");
|
|
|
|
|
List<RStatDataVDPO> cpList = rStatDataVDMapper.selectList(queryWrapper);
|
|
|
|
|
Map<String,RStatDataVDPO> cpMap = cpList.stream().collect(Collectors.toMap(RStatDataVDPO::getLineId,Function.identity()));
|
|
|
|
|
|
|
|
|
|
List<RStatLimitRateDPO> rStatLimitRateDPOS = rStatLimitRateDMapper.selectList(new LambdaQueryWrapper<RStatLimitRateDPO>().in(RStatLimitRateDPO::getLineId,cnIds).eq(RStatLimitRateDPO::getTime,date).eq(RStatLimitRateDPO::getPhasicType,"T"));
|
|
|
|
|
Map<String,RStatLimitRateDPO> rStatLimitRateDPOMap = rStatLimitRateDPOS.stream().collect(Collectors.toMap(RStatLimitRateDPO::getLineId,Function.identity()));
|
|
|
|
|
|
|
|
|
|
for(RUploadCommPointBus item: poLIst){
|
|
|
|
|
item.setObjId(IdUtil.simpleUUID());
|
|
|
|
|
if(avgMap.containsKey(item.getCnMonitorId())){
|
|
|
|
|
RStatDataVDPO rStatDataVDPO = avgMap.get(item.getCnMonitorId());
|
|
|
|
|
item.setAvgVrms(rStatDataVDPO.getRms());
|
|
|
|
|
}
|
|
|
|
|
if(cpMap.containsKey(item.getCnMonitorId())){
|
|
|
|
|
RStatDataVDPO rStatDataVDPO = cpMap.get(item.getCnMonitorId());
|
|
|
|
|
item.setGVrms(rStatDataVDPO.getRms());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Integer limitDay = 0;
|
|
|
|
|
if(rStatLimitRateDPOMap.containsKey(item.getCnMonitorId())){
|
|
|
|
|
RStatLimitRateDPO r = rStatLimitRateDPOMap.get(item.getCnMonitorId());
|
|
|
|
|
int limit = maxOverTime(r, HarVoltage.class);
|
|
|
|
|
if(r.getAllTime()>0){
|
|
|
|
|
int i= 1440/r.getAllTime();
|
|
|
|
|
if(limit>0){
|
|
|
|
|
item.setHarmVOvDuration(limit*i);
|
|
|
|
|
item.setHarmVOvDays(1);
|
|
|
|
|
limitDay = 1;
|
|
|
|
|
}else {
|
|
|
|
|
item.setHarmVOvDuration(0);
|
|
|
|
|
item.setHarmVOvDays(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//三相不平衡
|
|
|
|
|
if(r.getUbalanceOvertime()>0){
|
|
|
|
|
item.setVunbanOvDuration(r.getUbalanceOvertime()*i);
|
|
|
|
|
item.setVunbanOvDays(1);
|
|
|
|
|
limitDay = 1;
|
|
|
|
|
}else {
|
|
|
|
|
item.setVunbanOvDuration(0);
|
|
|
|
|
item.setVunbanOvDays(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(r.getFlickerAllTime() > 0){
|
|
|
|
|
int i= 1440/r.getFlickerAllTime();
|
|
|
|
|
//
|
|
|
|
|
if(r.getFlickerOvertime()>0){
|
|
|
|
|
item.setPltOvDuration(r.getFlickerOvertime()*i);
|
|
|
|
|
item.setPltOvDays(1);
|
|
|
|
|
limitDay = 1;
|
|
|
|
|
}else {
|
|
|
|
|
item.setPltOvDuration(0);
|
|
|
|
|
item.setPltOvDays(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
item.setOvDays(limitDay);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(CollUtil.isNotEmpty(poLIst)){
|
|
|
|
|
this.saveOrUpdateBatchByMultiId(poLIst);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
* 获取越限最大值
|
|
|
|
|
* @param object
|
|
|
|
|
* @param annotation
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Integer maxOverTime(Object object, Class annotation) {
|
|
|
|
|
Integer maxValue = 0;
|
|
|
|
|
try {
|
|
|
|
|
Class objClass = object.getClass();
|
|
|
|
|
Field[] fields = objClass.getDeclaredFields();
|
|
|
|
|
for (Field field : fields) {
|
|
|
|
|
field.setAccessible(true);
|
|
|
|
|
boolean isAnon = field.isAnnotationPresent(annotation);
|
|
|
|
|
if (isAnon) {
|
|
|
|
|
Object objValue = field.get(object);
|
|
|
|
|
if (objValue instanceof Integer) {
|
|
|
|
|
if ((Integer) objValue > maxValue) {
|
|
|
|
|
maxValue = (Integer) objValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("获取越限最大值异常:{}", e.toString());
|
|
|
|
|
}
|
|
|
|
|
return maxValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 选择最优测点,数据完整性最高
|
|
|
|
|
* @param monitorList
|
|
|
|
|
* @param inteMap
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Monitor goodMonitor(List<Monitor> monitorList,Map<String,RStatIntegrityD> inteMap){
|
|
|
|
|
Float val = 0.00f;
|
|
|
|
|
Monitor monitorRes = monitorList.get(0);
|
|
|
|
|
for(Monitor monitor:monitorList){
|
|
|
|
|
if(inteMap.containsKey(monitor.getId())){
|
|
|
|
|
RStatIntegrityD rStatIntegrityD = inteMap.get(monitor.getId());
|
|
|
|
|
float tem = (float)rStatIntegrityD.getRealTime()/rStatIntegrityD.getDueTime();
|
|
|
|
|
if(tem>val){
|
|
|
|
|
val = tem;
|
|
|
|
|
monitorRes = monitor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return monitorRes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void handlerMonth(String date){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void handlerYear(String date){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|