河北超高压算法-区域电站母线电压类指标超标统计

This commit is contained in:
2024-02-04 14:33:29 +08:00
parent 4d070f93c6
commit c8525f477a
17 changed files with 1110 additions and 3 deletions

View File

@@ -0,0 +1,81 @@
package com.njcn.harmonic.pojo.po;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import com.njcn.db.bo.BaseEntity;
import java.io.Serializable;
import java.time.LocalDate;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
/**
* <p>
*
* </p>
*
* @author xuyang
* @since 2024-01-25
*/
@Data
@TableName("r_stat_org_busbar_voltage_d")
public class RStatOrgBusbarVoltageD {
private static final long serialVersionUID = 1L;
/**
* 单位ID
*/
@MppMultiId
private String orgNo;
/**
* 生成数据的时间,每日统计一次
*/
@MppMultiId
private LocalDate dataDate;
/**
* 母线ID
*/
@MppMultiId
private String busbarId;
/**
* 有效接入监测点总数量
*/
private Integer measurementCount;
/**
* 谐波电压超标点数
*/
private Integer vCount;
/**
* 谐波电压超标占比
*/
private Float vRatio;
/**
* 三相电压不平衡超标点数
*/
private Integer unbalanceCount;
/**
* 三相电压不平衡超标占比
*/
private Float unbalanceRatio;
/**
* 闪变超标点数
*/
private Integer flickerCount;
/**
* 闪变超标占比
*/
private Float flickerRatio;
}

View File

@@ -3,6 +3,7 @@ package com.njcn.harmonic.pojo.po;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -28,13 +29,16 @@ public class RStatOrgBusbarVoltageM implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "单位ID")
@TableId(value = "org_no", type = IdType.ASSIGN_ID)
// @TableId(value = "org_no", type = IdType.ASSIGN_ID)
@MppMultiId(value = "org_no")
private String orgNo;
@ApiModelProperty(value = "生成数据的时间,每日统计一次")
@MppMultiId
private LocalDate dataDate;
@ApiModelProperty(value = "母线ID")
@MppMultiId
private String busbarId;
@ApiModelProperty(value = "有效接入监测点总数量")

View File

@@ -3,6 +3,7 @@ package com.njcn.harmonic.pojo.po;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -28,13 +29,16 @@ public class RStatOrgBusbarVoltageQ implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "单位ID")
@TableId(value = "org_no", type = IdType.ASSIGN_ID)
// @TableId(value = "org_no", type = IdType.ASSIGN_ID)
@MppMultiId
private String orgNo;
@ApiModelProperty(value = "生成数据的时间,每日统计一次")
@MppMultiId
private LocalDate dataDate;
@ApiModelProperty(value = "母线ID")
@MppMultiId
private String busbarId;
@ApiModelProperty(value = "有效接入监测点总数量")

View File

@@ -3,6 +3,7 @@ package com.njcn.harmonic.pojo.po;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -28,13 +29,16 @@ public class RStatOrgBusbarVoltageY implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "单位ID")
@TableId(value = "org_no", type = IdType.ASSIGN_ID)
// @TableId(value = "org_no", type = IdType.ASSIGN_ID)
@MppMultiId
private String orgNo;
@ApiModelProperty(value = "生成数据的时间,每日统计一次")
@MppMultiId
private LocalDate dataDate;
@ApiModelProperty(value = "母线ID")
@MppMultiId
private String busbarId;
@ApiModelProperty(value = "有效接入监测点总数量")

View File

@@ -2,6 +2,10 @@ package com.njcn.prepare.executor;
import com.njcn.device.biz.pojo.dto.DeptGetBusBarDTO;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
import com.njcn.prepare.harmonic.service.mysql.IRStatOrgBusbarVoltageDService;
import com.njcn.prepare.harmonic.service.mysql.IRStatOrgBusbarVoltageMService;
import com.njcn.prepare.harmonic.service.mysql.IRStatOrgBusbarVoltageQService;
import com.njcn.prepare.harmonic.service.mysql.IRStatOrgBusbarVoltageYService;
import com.njcn.prepare.harmonic.service.mysql.busbar.IStationBusBarReportService;
import com.njcn.prepare.harmonic.service.mysql.dim.IRDimVoltageDService;
import com.njcn.prepare.harmonic.service.mysql.dim.IRDimVoltageMService;
@@ -26,6 +30,11 @@ public class BusBarExecutor extends BaseExecutor{
private final IRDimVoltageMService irDimVoltageMService;
private final IRDimVoltageYService irDimVoltageYService;
private final IRStatOrgBusbarVoltageDService rStatOrgBusbarVoltageDService;
private final IRStatOrgBusbarVoltageMService rStatOrgBusbarVoltageMService;
private final IRStatOrgBusbarVoltageQService rStatOrgBusbarVoltageQService;
private final IRStatOrgBusbarVoltageYService rStatOrgBusbarVoltageYService;
private final IStationBusBarReportService iStationBusBarReportService;
@LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "rBusbarVoltage", nodeType = NodeTypeEnum.COMMON)
@@ -54,6 +63,42 @@ public class BusBarExecutor extends BaseExecutor{
}
}
/**
* 区域电站母线电压类指标超标统计
* @param bindCmp
* @return
*/
@LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "rStatOrgBusBarVoltage", nodeType = NodeTypeEnum.COMMON)
public boolean rStatOrgBusBarVoltageAccess(NodeComponent bindCmp) {
return isAccess(bindCmp);
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "rStatOrgBusBarVoltage", nodeType = NodeTypeEnum.COMMON)
public void rStatOrgBusBarVoltageProcess(NodeComponent bindCmp) {
String tag = bindCmp.getTag();
CalculatedParam<DeptGetBusBarDTO> calculatedParam = bindCmp.getRequestData();
if (tag.equalsIgnoreCase("r_stat_org_busbar_voltage_d")) {
//日表
rStatOrgBusbarVoltageDService.busBarHarmonicD(calculatedParam);
} else if (tag.equalsIgnoreCase("r_stat_org_busbar_voltage_m")) {
//数据补招不执行非日表算法
if (!calculatedParam.isRepair()) {
//月表
rStatOrgBusbarVoltageMService.busBarHarmonicM(calculatedParam);
}
} else if (tag.equalsIgnoreCase("r_stat_org_busbar_voltage_q")) {
//数据补招不执行非日表算法
if (!calculatedParam.isRepair()) {
//季表
rStatOrgBusbarVoltageQService.busBarHarmonicQ(calculatedParam);
}
} else if (tag.equalsIgnoreCase("r_stat_org_busbar_voltage_y")) {
//数据补招不执行非日表算法
if (!calculatedParam.isRepair()) {
//年表
rStatOrgBusbarVoltageYService.busBarHarmonicY(calculatedParam);
}
}
}
@LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "rStatBusbarHarmonicY", nodeType = NodeTypeEnum.COMMON)
public boolean rStatBusbarHarmonicYAccess(NodeComponent bindCmp) {

View File

@@ -0,0 +1,16 @@
package com.njcn.prepare.harmonic.mapper.mysql;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.harmonic.pojo.po.RStatOrgBusbarVoltageD;
/**
* <p>
* Mapper 接口
* </p>
*
* @author xuyang
* @since 2024-01-25
*/
public interface RStatOrgBusbarVoltageDMapper extends MppBaseMapper<RStatOrgBusbarVoltageD> {
}

View File

@@ -0,0 +1,16 @@
package com.njcn.prepare.harmonic.mapper.mysql;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.harmonic.pojo.po.RStatOrgBusbarVoltageM;
/**
* <p>
* Mapper 接口
* </p>
*
* @author xuyang
* @since 2024-01-25
*/
public interface RStatOrgBusbarVoltageMMapper extends MppBaseMapper<RStatOrgBusbarVoltageM> {
}

View File

@@ -0,0 +1,16 @@
package com.njcn.prepare.harmonic.mapper.mysql;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.harmonic.pojo.po.RStatOrgBusbarVoltageQ;
/**
* <p>
* Mapper 接口
* </p>
*
* @author xuyang
* @since 2024-01-25
*/
public interface RStatOrgBusbarVoltageQMapper extends MppBaseMapper<RStatOrgBusbarVoltageQ> {
}

View File

@@ -0,0 +1,17 @@
package com.njcn.prepare.harmonic.mapper.mysql;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.harmonic.pojo.po.RStatOrgBusbarVoltageY;
/**
* <p>
* Mapper 接口
* </p>
*
* @author xuyang
* @since 2024-01-25
*/
public interface RStatOrgBusbarVoltageYMapper extends MppBaseMapper<RStatOrgBusbarVoltageY> {
}

View File

@@ -0,0 +1,23 @@
package com.njcn.prepare.harmonic.service.mysql;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.device.biz.pojo.dto.DeptGetBusBarDTO;
import com.njcn.harmonic.pojo.po.RStatOrgBusbarVoltageD;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
/**
* <p>
* 服务类
* </p>
*
* @author xuyang
* @since 2024-01-25
*/
public interface IRStatOrgBusbarVoltageDService extends IService<RStatOrgBusbarVoltageD> {
/**
* 区域电站母线电压类指标超标统计-日表
*/
void busBarHarmonicD(CalculatedParam<DeptGetBusBarDTO> calculatedParam);
}

View File

@@ -0,0 +1,22 @@
package com.njcn.prepare.harmonic.service.mysql;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.device.biz.pojo.dto.DeptGetBusBarDTO;
import com.njcn.harmonic.pojo.po.RStatOrgBusbarVoltageM;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
/**
* <p>
* 服务类
* </p>
*
* @author xuyang
* @since 2024-01-25
*/
public interface IRStatOrgBusbarVoltageMService extends IService<RStatOrgBusbarVoltageM> {
/**
* 区域电站母线电压类指标超标统计-月表
*/
void busBarHarmonicM(CalculatedParam<DeptGetBusBarDTO> calculatedParam);
}

View File

@@ -0,0 +1,22 @@
package com.njcn.prepare.harmonic.service.mysql;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.device.biz.pojo.dto.DeptGetBusBarDTO;
import com.njcn.harmonic.pojo.po.RStatOrgBusbarVoltageQ;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
/**
* <p>
* 服务类
* </p>
*
* @author xuyang
* @since 2024-01-25
*/
public interface IRStatOrgBusbarVoltageQService extends IService<RStatOrgBusbarVoltageQ> {
/**
* 区域电站母线电压类指标超标统计-季表
*/
void busBarHarmonicQ(CalculatedParam<DeptGetBusBarDTO> calculatedParam);
}

View File

@@ -0,0 +1,22 @@
package com.njcn.prepare.harmonic.service.mysql;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.device.biz.pojo.dto.DeptGetBusBarDTO;
import com.njcn.harmonic.pojo.po.RStatOrgBusbarVoltageY;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
/**
* <p>
* 服务类
* </p>
*
* @author xuyang
* @since 2024-01-25
*/
public interface IRStatOrgBusbarVoltageYService extends IService<RStatOrgBusbarVoltageY> {
/**
* 区域电站母线电压类指标超标统计-年表
*/
void busBarHarmonicY(CalculatedParam<DeptGetBusBarDTO> calculatedParam);
}

View File

@@ -0,0 +1,181 @@
package com.njcn.prepare.harmonic.service.mysql.Impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.device.biz.pojo.dto.DeptGetBusBarDTO;
import com.njcn.device.pms.pojo.po.Monitor;
import com.njcn.harmonic.pojo.po.RStatOrgBusbarVoltageD;
import com.njcn.harmonic.pojo.po.day.RStatLimitTargetDPO;
import com.njcn.prepare.harmonic.mapper.mysql.RStatOrgBusbarVoltageDMapper;
import com.njcn.prepare.harmonic.mapper.mysql.day.RStatLimitTargetDMapper;
import com.njcn.prepare.harmonic.mapper.mysql.line.PmsMonitorMapper;
import com.njcn.prepare.harmonic.mapper.mysql.line.RMpMonitorEvaluateDMapper;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
import com.njcn.prepare.harmonic.pojo.mysql.RMpMonitorEvaluateDPO;
import com.njcn.prepare.harmonic.service.mysql.IRStatOrgBusbarVoltageDService;
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 lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
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 2024-01-25
*/
@Service
@RequiredArgsConstructor
public class RStatOrgBusbarVoltageDServiceImpl extends MppServiceImpl<RStatOrgBusbarVoltageDMapper, RStatOrgBusbarVoltageD> implements IRStatOrgBusbarVoltageDService {
private final PmsMonitorMapper pmsMonitorMapper;
private final DicDataFeignClient dicDataFeignClient;
private final RStatLimitTargetDMapper limitTargetMapper;
private final RMpMonitorEvaluateDMapper mpMonitorEvaluateDMapper;
/**
* 1.获取单位下母线数量
* 2.获取母线下监测点个数
* 3.获取监测点的超标情况
* @param calculatedParam
*/
@Override
@Transactional(rollbackFor = {Exception.class})
public void busBarHarmonicD(CalculatedParam<DeptGetBusBarDTO> calculatedParam) {
List<RStatOrgBusbarVoltageD> result = new ArrayList<>();
//fixme 这边calculatedParam参数传入有问题应该只传递母线id集合而不是对象这边后续调整
//获取基础数据
Map<String,List<Monitor>> orgMap = this.getPmsMonitor();
orgMap.forEach((k,v)->{
//根据母线分组
Map<String,List<Monitor>> lineMap = v.stream().collect(Collectors.groupingBy(Monitor::getLineId));
lineMap.forEach((k1,v1)->{
RStatOrgBusbarVoltageD busBarD = new RStatOrgBusbarVoltageD();
busBarD.setOrgNo(k);
busBarD.setDataDate(LocalDateTimeUtil.parseDate(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN));
busBarD.setBusbarId(k1);
List<String> monitorList = v1.stream().map(Monitor::getId).collect(Collectors.toList());
busBarD.setMeasurementCount(this.getEffectiveNum(monitorList,calculatedParam.getDataDate()));
busBarD.setVCount(this.getOverHarmonicV(monitorList,calculatedParam.getDataDate()));
busBarD.setUnbalanceCount(this.getOverThree(monitorList,calculatedParam.getDataDate()));
busBarD.setFlickerCount(this.getOverFlicker(monitorList,calculatedParam.getDataDate()));
busBarD.setVRatio(busBarD.getMeasurementCount()==0?0.0f: Math.min(busBarD.getVCount() * 100.0f / busBarD.getMeasurementCount(), 100.0f));
busBarD.setUnbalanceRatio(busBarD.getMeasurementCount()==0?0.0f: Math.min(busBarD.getUnbalanceCount() * 100.0f / busBarD.getMeasurementCount(), 100.0f));
busBarD.setFlickerRatio(busBarD.getMeasurementCount()==0?0.0f: Math.min(busBarD.getFlickerCount()*100.0f/busBarD.getMeasurementCount(), 100.0f));
result.add(busBarD);
});
});
if (CollectionUtil.isNotEmpty(result)){
this.saveOrUpdateBatchByMultiId(result,1000);
}
}
/**
* 获取 在运 && 正常 的监测点信息
* 根据单位分组
*/
public Map<String,List<Monitor>> getPmsMonitor() {
List<DictData> dicDataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.LINE_STATE.getCode()).getData();
DictData dictData = dicDataList.stream().filter(o-> Objects.equals(o.getCode(), DicDataEnum.RUN.getCode())).findFirst().orElse(null);
LambdaQueryWrapper<Monitor> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(Monitor::getStatus, DataStateEnum.ENABLE.getCode())
.eq(Monitor::getMonitorState,dictData.getId());
List<Monitor> list = pmsMonitorMapper.selectList(lambdaQueryWrapper);
return list.stream().collect(Collectors.groupingBy(Monitor::getOrgId));
}
/**
* 获取有效接入监测点个数
*/
public Integer getEffectiveNum(List<String> lineList, String time) {
LambdaQueryWrapper<RMpMonitorEvaluateDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(RMpMonitorEvaluateDPO::getMeasurementPointId)
.eq(RMpMonitorEvaluateDPO::getDataDate, time)
.in(RMpMonitorEvaluateDPO::getMeasurementPointId, lineList)
.gt(RMpMonitorEvaluateDPO::getEffectiveMinuteCount, 0);
List<RMpMonitorEvaluateDPO> list = mpMonitorEvaluateDMapper.selectList(lambdaQueryWrapper);
return CollUtil.isEmpty(list)?0: list.stream().distinct().map(RMpMonitorEvaluateDPO::getMeasurementPointId).collect(Collectors.toList()).size();
}
/**
* 获取谐波电压超标点数
* 电压总谐波畸变率+2-25次谐波电压
*/
public Integer getOverHarmonicV(List<String> lineList, String time) {
LambdaQueryWrapper<RStatLimitTargetDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(RStatLimitTargetDPO::getLineId)
.eq(RStatLimitTargetDPO::getTime, time)
.in(RStatLimitTargetDPO::getLineId, lineList);
lambdaQueryWrapper.and((wrapper)->{
wrapper.gt(RStatLimitTargetDPO::getUbalanceOvertime, 0)
.or().gt(RStatLimitTargetDPO::getUharm2Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm3Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm4Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm5Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm6Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm7Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm8Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm9Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm10Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm11Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm12Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm13Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm14Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm15Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm16Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm17Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm18Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm19Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm20Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm21Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm22Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm23Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm24Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm25Overtime,0);
});
List<RStatLimitTargetDPO> list = limitTargetMapper.selectList(lambdaQueryWrapper);
return CollUtil.isEmpty(list)?0: list.stream().distinct().map(RStatLimitTargetDPO::getLineId).collect(Collectors.toList()).size();
}
/**
* 三相电压不平衡超标点数
*/
public Integer getOverThree(List<String> lineList, String time) {
LambdaQueryWrapper<RStatLimitTargetDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(RStatLimitTargetDPO::getLineId)
.eq(RStatLimitTargetDPO::getTime, time)
.in(RStatLimitTargetDPO::getLineId, lineList)
.gt(RStatLimitTargetDPO::getUaberranceOvertime, 0);
List<RStatLimitTargetDPO> list = limitTargetMapper.selectList(lambdaQueryWrapper);
return CollUtil.isEmpty(list)?0: list.stream().distinct().map(RStatLimitTargetDPO::getLineId).collect(Collectors.toList()).size();
}
/**
* 闪变超标点数
*/
public Integer getOverFlicker(List<String> lineList,String time) {
LambdaQueryWrapper<RStatLimitTargetDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(RStatLimitTargetDPO::getLineId)
.eq(RStatLimitTargetDPO::getTime, time)
.in(RStatLimitTargetDPO::getLineId, lineList)
.gt(RStatLimitTargetDPO::getFlickerOvertime, 0);
List<RStatLimitTargetDPO> list = limitTargetMapper.selectList(lambdaQueryWrapper);
return CollUtil.isEmpty(list)?0: list.stream().distinct().map(RStatLimitTargetDPO::getLineId).collect(Collectors.toList()).size();
}
}

View File

@@ -0,0 +1,211 @@
package com.njcn.prepare.harmonic.service.mysql.Impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.device.biz.pojo.dto.DeptGetBusBarDTO;
import com.njcn.device.pms.pojo.po.Monitor;
import com.njcn.harmonic.pojo.po.RStatOrgBusbarVoltageD;
import com.njcn.harmonic.pojo.po.RStatOrgBusbarVoltageM;
import com.njcn.harmonic.pojo.po.day.RStatLimitTargetDPO;
import com.njcn.prepare.harmonic.mapper.mysql.RStatOrgBusbarVoltageDMapper;
import com.njcn.prepare.harmonic.mapper.mysql.RStatOrgBusbarVoltageMMapper;
import com.njcn.prepare.harmonic.mapper.mysql.day.RStatLimitTargetDMapper;
import com.njcn.prepare.harmonic.mapper.mysql.line.PmsMonitorMapper;
import com.njcn.prepare.harmonic.mapper.mysql.line.RMpMonitorEvaluateDMapper;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
import com.njcn.prepare.harmonic.pojo.mysql.RMpMonitorEvaluateDPO;
import com.njcn.prepare.harmonic.service.mysql.IRStatOrgBusbarVoltageMService;
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 org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
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 2024-01-25
*/
@Service
@RequiredArgsConstructor
public class RStatOrgBusbarVoltageMServiceImpl extends MppServiceImpl<RStatOrgBusbarVoltageMMapper, RStatOrgBusbarVoltageM> implements IRStatOrgBusbarVoltageMService {
private final RStatOrgBusbarVoltageDMapper statOrgBusbarVoltageDMapper;
private final RMpMonitorEvaluateDMapper mpMonitorEvaluateDMapper;
private final RStatLimitTargetDMapper limitTargetMapper;
private final PmsMonitorMapper pmsMonitorMapper;
private final DicDataFeignClient dicDataFeignClient;
private final DeptFeignClient deptFeignClient;
@Override
@Transactional(rollbackFor = {Exception.class})
public void busBarHarmonicM(CalculatedParam<DeptGetBusBarDTO> calculatedParam) {
List<RStatOrgBusbarVoltageM> result = new ArrayList<>();
String beginMonth = DateUtil.beginOfMonth(DateUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN)).toString(DatePattern.NORM_DATE_PATTERN);
String endMonth = DateUtil.endOfMonth(DateUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN)).toString(DatePattern.NORM_DATE_PATTERN);
//获取基础数据
Map<String,List<Monitor>> orgMap = this.getPmsMonitor();
orgMap.forEach((k,v)->{
//根据母线分组
Map<String,List<Monitor>> lineMap = v.stream().collect(Collectors.groupingBy(Monitor::getLineId));
lineMap.forEach((k1,v1)->{
RStatOrgBusbarVoltageM busBarM = new RStatOrgBusbarVoltageM();
busBarM.setOrgNo(k);
busBarM.setDataDate(LocalDateTimeUtil.parseDate(beginMonth, DatePattern.NORM_DATE_PATTERN));
busBarM.setBusbarId(k1);
List<String> monitorList = v1.stream().map(Monitor::getId).collect(Collectors.toList());
busBarM.setMeasurementCount(this.getEffectiveNum(monitorList,beginMonth,endMonth));
//获取日表数据
List<RStatOrgBusbarVoltageD> dayList = getDayData(k1,beginMonth,endMonth);
busBarM.setVAverage(Math.min(new Double(dayList.stream().mapToDouble(RStatOrgBusbarVoltageD::getVRatio).average().orElse(0.0f)).floatValue(),100.0f));
busBarM.setVAccrued(busBarM.getMeasurementCount()==0?0.0f:Math.min(this.getOverHarmonicV(monitorList,beginMonth,endMonth)*100.0f/busBarM.getMeasurementCount(),100.0f));
busBarM.setUnbalanceAverage(Math.min(new Double(dayList.stream().mapToDouble(RStatOrgBusbarVoltageD::getUnbalanceRatio).average().orElse(0.0f)).floatValue(),100.0f));
busBarM.setUnbalanceAccrued(busBarM.getMeasurementCount()==0?0.0f:Math.min(this.getOverThree(monitorList,beginMonth,endMonth)*100.0f/busBarM.getMeasurementCount(),100.0f));
busBarM.setFlickerAverage(Math.min(new Double(dayList.stream().mapToDouble(RStatOrgBusbarVoltageD::getFlickerRatio).average().orElse(0.0f)).floatValue(),100.0f));
busBarM.setFlickerAccrued(busBarM.getMeasurementCount()==0?0.0f:Math.min(this.getOverFlicker(monitorList,beginMonth,endMonth)*100.0f/busBarM.getMeasurementCount(),100.0f));
result.add(busBarM);
});
});
if (CollectionUtil.isNotEmpty(result)){
//获取省级部门ids
Dept dept = deptFeignClient.getRootDept().getData();
String code = deptFeignClient.getDepSonDetailByDeptId(dept.getId()).getData().get(0).getCode();
//添加省级数据
List<RStatOrgBusbarVoltageM> provinceData = result .stream().map(object -> {
RStatOrgBusbarVoltageM objectNew = new RStatOrgBusbarVoltageM();
BeanUtils.copyProperties(object, objectNew);
objectNew.setOrgNo(code);
return objectNew;
}).collect(Collectors.toList());
result.addAll(provinceData);
this.saveOrUpdateBatchByMultiId(result,1000);
}
}
/**
* 获取 在运 && 正常 的监测点信息
* 根据单位分组
*/
public Map<String,List<Monitor>> getPmsMonitor() {
List<DictData> dicDataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.LINE_STATE.getCode()).getData();
DictData dictData = dicDataList.stream().filter(o-> Objects.equals(o.getCode(), DicDataEnum.RUN.getCode())).findFirst().orElse(null);
LambdaQueryWrapper<Monitor> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(Monitor::getStatus, DataStateEnum.ENABLE.getCode())
.eq(Monitor::getMonitorState,dictData.getId());
List<Monitor> list = pmsMonitorMapper.selectList(lambdaQueryWrapper);
return list.stream().collect(Collectors.groupingBy(Monitor::getOrgId));
}
/**
* 获取日表数据
*/
public List<RStatOrgBusbarVoltageD> getDayData(String busBar, String startTime, String endTime){
LambdaQueryWrapper<RStatOrgBusbarVoltageD> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.between(RStatOrgBusbarVoltageD::getDataDate,startTime,endTime)
.eq(RStatOrgBusbarVoltageD::getBusbarId, busBar);
return statOrgBusbarVoltageDMapper.selectList(lambdaQueryWrapper);
}
/**
* 获取有效接入监测点个数
*/
public Integer getEffectiveNum(List<String> lineList, String startTime, String endTime) {
LambdaQueryWrapper<RMpMonitorEvaluateDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(RMpMonitorEvaluateDPO::getMeasurementPointId)
.between(RMpMonitorEvaluateDPO::getDataDate, startTime, endTime)
.in(RMpMonitorEvaluateDPO::getMeasurementPointId, lineList)
.gt(RMpMonitorEvaluateDPO::getEffectiveMinuteCount, 0);
List<RMpMonitorEvaluateDPO> list = mpMonitorEvaluateDMapper.selectList(lambdaQueryWrapper);
return CollUtil.isEmpty(list)?0: list.stream().distinct().map(RMpMonitorEvaluateDPO::getMeasurementPointId).collect(Collectors.toList()).size();
}
/**
* 获取谐波电压超标点数
* 电压总谐波畸变率+2-25次谐波电压
*/
public Integer getOverHarmonicV(List<String> lineList, String startTime, String endTime) {
LambdaQueryWrapper<RStatLimitTargetDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(RStatLimitTargetDPO::getLineId)
.between(RStatLimitTargetDPO::getTime, startTime, endTime)
.in(RStatLimitTargetDPO::getLineId, lineList);
lambdaQueryWrapper.and((wrapper)->{
wrapper.gt(RStatLimitTargetDPO::getUbalanceOvertime, 0)
.or().gt(RStatLimitTargetDPO::getUharm2Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm3Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm4Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm5Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm6Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm7Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm8Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm9Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm10Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm11Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm12Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm13Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm14Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm15Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm16Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm17Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm18Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm19Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm20Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm21Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm22Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm23Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm24Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm25Overtime,0);
});
List<RStatLimitTargetDPO> list = limitTargetMapper.selectList(lambdaQueryWrapper);
return CollUtil.isEmpty(list)?0: list.stream().distinct().map(RStatLimitTargetDPO::getLineId).collect(Collectors.toList()).size();
}
/**
* 三相电压不平衡超标点数
*/
public Integer getOverThree(List<String> lineList, String startTime, String endTime) {
LambdaQueryWrapper<RStatLimitTargetDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(RStatLimitTargetDPO::getLineId)
.between(RStatLimitTargetDPO::getTime, startTime, endTime)
.in(RStatLimitTargetDPO::getLineId, lineList)
.gt(RStatLimitTargetDPO::getUaberranceOvertime, 0);
List<RStatLimitTargetDPO> list = limitTargetMapper.selectList(lambdaQueryWrapper);
return CollUtil.isEmpty(list)?0: list.stream().distinct().map(RStatLimitTargetDPO::getLineId).collect(Collectors.toList()).size();
}
/**
* 闪变超标点数
*/
public Integer getOverFlicker(List<String> lineList, String startTime, String endTime) {
LambdaQueryWrapper<RStatLimitTargetDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(RStatLimitTargetDPO::getLineId)
.between(RStatLimitTargetDPO::getTime, startTime, endTime)
.in(RStatLimitTargetDPO::getLineId, lineList)
.gt(RStatLimitTargetDPO::getFlickerOvertime, 0);
List<RStatLimitTargetDPO> list = limitTargetMapper.selectList(lambdaQueryWrapper);
return CollUtil.isEmpty(list)?0: list.stream().distinct().map(RStatLimitTargetDPO::getLineId).collect(Collectors.toList()).size();
}
}

View File

@@ -0,0 +1,211 @@
package com.njcn.prepare.harmonic.service.mysql.Impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.device.biz.pojo.dto.DeptGetBusBarDTO;
import com.njcn.device.pms.pojo.po.Monitor;
import com.njcn.harmonic.pojo.po.RStatOrgBusbarVoltageD;
import com.njcn.harmonic.pojo.po.RStatOrgBusbarVoltageQ;
import com.njcn.harmonic.pojo.po.day.RStatLimitTargetDPO;
import com.njcn.prepare.harmonic.mapper.mysql.RStatOrgBusbarVoltageDMapper;
import com.njcn.prepare.harmonic.mapper.mysql.RStatOrgBusbarVoltageQMapper;
import com.njcn.prepare.harmonic.mapper.mysql.day.RStatLimitTargetDMapper;
import com.njcn.prepare.harmonic.mapper.mysql.line.PmsMonitorMapper;
import com.njcn.prepare.harmonic.mapper.mysql.line.RMpMonitorEvaluateDMapper;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
import com.njcn.prepare.harmonic.pojo.mysql.RMpMonitorEvaluateDPO;
import com.njcn.prepare.harmonic.service.mysql.IRStatOrgBusbarVoltageQService;
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 org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
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 2024-01-25
*/
@Service
@RequiredArgsConstructor
public class RStatOrgBusbarVoltageQServiceImpl extends MppServiceImpl<RStatOrgBusbarVoltageQMapper, RStatOrgBusbarVoltageQ> implements IRStatOrgBusbarVoltageQService {
private final RStatOrgBusbarVoltageDMapper statOrgBusbarVoltageDMapper;
private final RMpMonitorEvaluateDMapper mpMonitorEvaluateDMapper;
private final RStatLimitTargetDMapper limitTargetMapper;
private final PmsMonitorMapper pmsMonitorMapper;
private final DicDataFeignClient dicDataFeignClient;
private final DeptFeignClient deptFeignClient;
@Override
@Transactional(rollbackFor = {Exception.class})
public void busBarHarmonicQ(CalculatedParam<DeptGetBusBarDTO> calculatedParam) {
List<RStatOrgBusbarVoltageQ> result = new ArrayList<>();
String begin = DateUtil.beginOfQuarter(DateUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN)).toString(DatePattern.NORM_DATE_PATTERN);
String end = DateUtil.endOfQuarter(DateUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN)).toString(DatePattern.NORM_DATE_PATTERN);
//获取基础数据
Map<String,List<Monitor>> orgMap = this.getPmsMonitor();
orgMap.forEach((k,v)->{
//根据母线分组
Map<String,List<Monitor>> lineMap = v.stream().collect(Collectors.groupingBy(Monitor::getLineId));
lineMap.forEach((k1,v1)->{
RStatOrgBusbarVoltageQ busBarQ = new RStatOrgBusbarVoltageQ();
busBarQ.setOrgNo(k);
busBarQ.setDataDate(LocalDateTimeUtil.parseDate(begin, DatePattern.NORM_DATE_PATTERN));
busBarQ.setBusbarId(k1);
List<String> monitorList = v1.stream().map(Monitor::getId).collect(Collectors.toList());
busBarQ.setMeasurementCount(this.getEffectiveNum(monitorList,begin,end));
//获取日表数据
List<RStatOrgBusbarVoltageD> dayList = getDayData(k1,begin,end);
busBarQ.setVAverage(Math.min(new Double(dayList.stream().mapToDouble(RStatOrgBusbarVoltageD::getVRatio).average().orElse(0.0f)).floatValue(),100.0f));
busBarQ.setVAccrued(busBarQ.getMeasurementCount()==0?0.0f:Math.min(this.getOverHarmonicV(monitorList,begin,end)*100.0f/busBarQ.getMeasurementCount(),100.0f));
busBarQ.setUnbalanceAverage(Math.min(new Double(dayList.stream().mapToDouble(RStatOrgBusbarVoltageD::getUnbalanceRatio).average().orElse(0.0f)).floatValue(),100.0f));
busBarQ.setUnbalanceAccrued(busBarQ.getMeasurementCount()==0?0.0f:Math.min(this.getOverThree(monitorList,begin,end)*100.0f/busBarQ.getMeasurementCount(),100.0f));
busBarQ.setFlickerAverage(Math.min(new Double(dayList.stream().mapToDouble(RStatOrgBusbarVoltageD::getFlickerRatio).average().orElse(0.0f)).floatValue(),100.0f));
busBarQ.setFlickerAccrued(busBarQ.getMeasurementCount()==0?0.0f:Math.min(this.getOverFlicker(monitorList,begin,end)*100.0f/busBarQ.getMeasurementCount(),100.0f));
result.add(busBarQ);
});
});
if (CollectionUtil.isNotEmpty(result)){
//获取省级部门ids
Dept dept = deptFeignClient.getRootDept().getData();
String code = deptFeignClient.getDepSonDetailByDeptId(dept.getId()).getData().get(0).getCode();
//添加省级数据
List<RStatOrgBusbarVoltageQ> provinceData = result .stream().map(object -> {
RStatOrgBusbarVoltageQ objectNew = new RStatOrgBusbarVoltageQ();
BeanUtils.copyProperties(object, objectNew);
objectNew.setOrgNo(code);
return objectNew;
}).collect(Collectors.toList());
result.addAll(provinceData);
this.saveOrUpdateBatchByMultiId(result,1000);
}
}
/**
* 获取 在运 && 正常 的监测点信息
* 根据单位分组
*/
public Map<String,List<Monitor>> getPmsMonitor() {
List<DictData> dicDataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.LINE_STATE.getCode()).getData();
DictData dictData = dicDataList.stream().filter(o-> Objects.equals(o.getCode(), DicDataEnum.RUN.getCode())).findFirst().orElse(null);
LambdaQueryWrapper<Monitor> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(Monitor::getStatus, DataStateEnum.ENABLE.getCode())
.eq(Monitor::getMonitorState,dictData.getId());
List<Monitor> list = pmsMonitorMapper.selectList(lambdaQueryWrapper);
return list.stream().collect(Collectors.groupingBy(Monitor::getOrgId));
}
/**
* 获取日表数据
*/
public List<RStatOrgBusbarVoltageD> getDayData(String busBar, String startTime, String endTime){
LambdaQueryWrapper<RStatOrgBusbarVoltageD> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.between(RStatOrgBusbarVoltageD::getDataDate,startTime,endTime)
.eq(RStatOrgBusbarVoltageD::getBusbarId, busBar);
return statOrgBusbarVoltageDMapper.selectList(lambdaQueryWrapper);
}
/**
* 获取有效接入监测点个数
*/
public Integer getEffectiveNum(List<String> lineList, String startTime, String endTime) {
LambdaQueryWrapper<RMpMonitorEvaluateDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(RMpMonitorEvaluateDPO::getMeasurementPointId)
.between(RMpMonitorEvaluateDPO::getDataDate, startTime, endTime)
.in(RMpMonitorEvaluateDPO::getMeasurementPointId, lineList)
.gt(RMpMonitorEvaluateDPO::getEffectiveMinuteCount, 0);
List<RMpMonitorEvaluateDPO> list = mpMonitorEvaluateDMapper.selectList(lambdaQueryWrapper);
return CollUtil.isEmpty(list)?0: list.stream().distinct().map(RMpMonitorEvaluateDPO::getMeasurementPointId).collect(Collectors.toList()).size();
}
/**
* 获取谐波电压超标点数
* 电压总谐波畸变率+2-25次谐波电压
*/
public Integer getOverHarmonicV(List<String> lineList, String startTime, String endTime) {
LambdaQueryWrapper<RStatLimitTargetDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(RStatLimitTargetDPO::getLineId)
.between(RStatLimitTargetDPO::getTime, startTime, endTime)
.in(RStatLimitTargetDPO::getLineId, lineList);
lambdaQueryWrapper.and((wrapper)->{
wrapper.gt(RStatLimitTargetDPO::getUbalanceOvertime, 0)
.or().gt(RStatLimitTargetDPO::getUharm2Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm3Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm4Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm5Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm6Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm7Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm8Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm9Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm10Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm11Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm12Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm13Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm14Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm15Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm16Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm17Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm18Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm19Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm20Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm21Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm22Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm23Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm24Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm25Overtime,0);
});
List<RStatLimitTargetDPO> list = limitTargetMapper.selectList(lambdaQueryWrapper);
return CollUtil.isEmpty(list)?0: list.stream().distinct().map(RStatLimitTargetDPO::getLineId).collect(Collectors.toList()).size();
}
/**
* 三相电压不平衡超标点数
*/
public Integer getOverThree(List<String> lineList, String startTime, String endTime) {
LambdaQueryWrapper<RStatLimitTargetDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(RStatLimitTargetDPO::getLineId)
.between(RStatLimitTargetDPO::getTime, startTime, endTime)
.in(RStatLimitTargetDPO::getLineId, lineList)
.gt(RStatLimitTargetDPO::getUaberranceOvertime, 0);
List<RStatLimitTargetDPO> list = limitTargetMapper.selectList(lambdaQueryWrapper);
return CollUtil.isEmpty(list)?0: list.stream().distinct().map(RStatLimitTargetDPO::getLineId).collect(Collectors.toList()).size();
}
/**
* 闪变超标点数
*/
public Integer getOverFlicker(List<String> lineList, String startTime, String endTime) {
LambdaQueryWrapper<RStatLimitTargetDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(RStatLimitTargetDPO::getLineId)
.between(RStatLimitTargetDPO::getTime, startTime, endTime)
.in(RStatLimitTargetDPO::getLineId, lineList)
.gt(RStatLimitTargetDPO::getFlickerOvertime, 0);
List<RStatLimitTargetDPO> list = limitTargetMapper.selectList(lambdaQueryWrapper);
return CollUtil.isEmpty(list)?0: list.stream().distinct().map(RStatLimitTargetDPO::getLineId).collect(Collectors.toList()).size();
}
}

View File

@@ -0,0 +1,212 @@
package com.njcn.prepare.harmonic.service.mysql.Impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.device.biz.pojo.dto.DeptGetBusBarDTO;
import com.njcn.device.pms.pojo.po.Monitor;
import com.njcn.harmonic.pojo.po.RStatOrgBusbarVoltageD;
import com.njcn.harmonic.pojo.po.RStatOrgBusbarVoltageY;
import com.njcn.harmonic.pojo.po.day.RStatLimitTargetDPO;
import com.njcn.prepare.harmonic.mapper.mysql.RStatOrgBusbarVoltageDMapper;
import com.njcn.prepare.harmonic.mapper.mysql.RStatOrgBusbarVoltageYMapper;
import com.njcn.prepare.harmonic.mapper.mysql.day.RStatLimitTargetDMapper;
import com.njcn.prepare.harmonic.mapper.mysql.line.PmsMonitorMapper;
import com.njcn.prepare.harmonic.mapper.mysql.line.RMpMonitorEvaluateDMapper;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
import com.njcn.prepare.harmonic.pojo.mysql.RMpMonitorEvaluateDPO;
import com.njcn.prepare.harmonic.service.mysql.IRStatOrgBusbarVoltageYService;
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 org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
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 2024-01-25
*/
@Service
@RequiredArgsConstructor
public class RStatOrgBusbarVoltageYServiceImpl extends MppServiceImpl<RStatOrgBusbarVoltageYMapper, RStatOrgBusbarVoltageY> implements IRStatOrgBusbarVoltageYService {
private final RStatOrgBusbarVoltageDMapper statOrgBusbarVoltageDMapper;
private final RMpMonitorEvaluateDMapper mpMonitorEvaluateDMapper;
private final RStatLimitTargetDMapper limitTargetMapper;
private final PmsMonitorMapper pmsMonitorMapper;
private final DicDataFeignClient dicDataFeignClient;
private final DeptFeignClient deptFeignClient;
@Override
@Transactional(rollbackFor = {Exception.class})
public void busBarHarmonicY(CalculatedParam<DeptGetBusBarDTO> calculatedParam) {
List<RStatOrgBusbarVoltageY> result = new ArrayList<>();
String begin = DateUtil.beginOfYear(DateUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN)).toString(DatePattern.NORM_DATE_PATTERN);
String end = DateUtil.endOfYear(DateUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN)).toString(DatePattern.NORM_DATE_PATTERN);
//获取基础数据
Map<String,List<Monitor>> orgMap = this.getPmsMonitor();
orgMap.forEach((k,v)->{
//根据母线分组
Map<String,List<Monitor>> lineMap = v.stream().collect(Collectors.groupingBy(Monitor::getLineId));
lineMap.forEach((k1,v1)->{
RStatOrgBusbarVoltageY busBarY = new RStatOrgBusbarVoltageY();
busBarY.setOrgNo(k);
busBarY.setDataDate(LocalDateTimeUtil.parseDate(begin, DatePattern.NORM_DATE_PATTERN));
busBarY.setBusbarId(k1);
List<String> monitorList = v1.stream().map(Monitor::getId).collect(Collectors.toList());
busBarY.setMeasurementCount(this.getEffectiveNum(monitorList,begin,end));
//获取日表数据
List<RStatOrgBusbarVoltageD> dayList = getDayData(k1,begin,end);
busBarY.setVAverage(Math.min(new Double(dayList.stream().mapToDouble(RStatOrgBusbarVoltageD::getVRatio).average().orElse(0.0f)).floatValue(),100.0f));
busBarY.setVAccrued(busBarY.getMeasurementCount()==0?0.0f:Math.min(this.getOverHarmonicV(monitorList,begin,end)*100.0f/busBarY.getMeasurementCount(),100.0f));
busBarY.setUnbalanceAverage(Math.min(new Double(dayList.stream().mapToDouble(RStatOrgBusbarVoltageD::getUnbalanceRatio).average().orElse(0.0f)).floatValue(),100.0f));
busBarY.setUnbalanceAccrued(busBarY.getMeasurementCount()==0?0.0f:Math.min(this.getOverThree(monitorList,begin,end)*100.0f/busBarY.getMeasurementCount(),100.0f));
busBarY.setFlickerAverage(Math.min(new Double(dayList.stream().mapToDouble(RStatOrgBusbarVoltageD::getFlickerRatio).average().orElse(0.0f)).floatValue(),100.0f));
busBarY.setFlickerAccrued(busBarY.getMeasurementCount()==0?0.0f:Math.min(this.getOverFlicker(monitorList,begin,end)*100.0f/busBarY.getMeasurementCount(),100.0f));
result.add(busBarY);
});
});
if (CollectionUtil.isNotEmpty(result)){
//获取省级部门ids
Dept dept = deptFeignClient.getRootDept().getData();
String code = deptFeignClient.getDepSonDetailByDeptId(dept.getId()).getData().get(0).getCode();
//添加省级数据
List<RStatOrgBusbarVoltageY> provinceData = result .stream().map(object -> {
RStatOrgBusbarVoltageY objectNew = new RStatOrgBusbarVoltageY();
BeanUtils.copyProperties(object, objectNew);
objectNew.setOrgNo(code);
return objectNew;
}).collect(Collectors.toList());
result.addAll(provinceData);
this.saveOrUpdateBatchByMultiId(result,1000);
}
}
/**
* 获取 在运 && 正常 的监测点信息
* 根据单位分组
*/
public Map<String,List<Monitor>> getPmsMonitor() {
List<DictData> dicDataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.LINE_STATE.getCode()).getData();
DictData dictData = dicDataList.stream().filter(o-> Objects.equals(o.getCode(), DicDataEnum.RUN.getCode())).findFirst().orElse(null);
LambdaQueryWrapper<Monitor> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(Monitor::getStatus, DataStateEnum.ENABLE.getCode())
.eq(Monitor::getMonitorState,dictData.getId());
List<Monitor> list = pmsMonitorMapper.selectList(lambdaQueryWrapper);
return list.stream().collect(Collectors.groupingBy(Monitor::getOrgId));
}
/**
* 获取日表数据
*/
public List<RStatOrgBusbarVoltageD> getDayData(String busBar, String startTime, String endTime){
LambdaQueryWrapper<RStatOrgBusbarVoltageD> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.between(RStatOrgBusbarVoltageD::getDataDate,startTime,endTime)
.eq(RStatOrgBusbarVoltageD::getBusbarId, busBar);
return statOrgBusbarVoltageDMapper.selectList(lambdaQueryWrapper);
}
/**
* 获取有效接入监测点个数
*/
public Integer getEffectiveNum(List<String> lineList, String startTime, String endTime) {
LambdaQueryWrapper<RMpMonitorEvaluateDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(RMpMonitorEvaluateDPO::getMeasurementPointId)
.between(RMpMonitorEvaluateDPO::getDataDate, startTime, endTime)
.in(RMpMonitorEvaluateDPO::getMeasurementPointId, lineList)
.gt(RMpMonitorEvaluateDPO::getEffectiveMinuteCount, 0);
List<RMpMonitorEvaluateDPO> list = mpMonitorEvaluateDMapper.selectList(lambdaQueryWrapper);
return CollUtil.isEmpty(list)?0: list.stream().distinct().map(RMpMonitorEvaluateDPO::getMeasurementPointId).collect(Collectors.toList()).size();
}
/**
* 获取谐波电压超标点数
* 电压总谐波畸变率+2-25次谐波电压
*/
public Integer getOverHarmonicV(List<String> lineList, String startTime, String endTime) {
LambdaQueryWrapper<RStatLimitTargetDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(RStatLimitTargetDPO::getLineId)
.between(RStatLimitTargetDPO::getTime, startTime, endTime)
.in(RStatLimitTargetDPO::getLineId, lineList);
lambdaQueryWrapper.and((wrapper)->{
wrapper.gt(RStatLimitTargetDPO::getUbalanceOvertime, 0)
.or().gt(RStatLimitTargetDPO::getUharm2Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm3Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm4Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm5Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm6Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm7Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm8Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm9Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm10Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm11Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm12Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm13Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm14Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm15Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm16Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm17Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm18Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm19Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm20Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm21Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm22Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm23Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm24Overtime,0)
.or().gt(RStatLimitTargetDPO::getUharm25Overtime,0);
});
List<RStatLimitTargetDPO> list = limitTargetMapper.selectList(lambdaQueryWrapper);
return CollUtil.isEmpty(list)?0: list.stream().distinct().map(RStatLimitTargetDPO::getLineId).collect(Collectors.toList()).size();
}
/**
* 三相电压不平衡超标点数
*/
public Integer getOverThree(List<String> lineList, String startTime, String endTime) {
LambdaQueryWrapper<RStatLimitTargetDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(RStatLimitTargetDPO::getLineId)
.between(RStatLimitTargetDPO::getTime, startTime, endTime)
.in(RStatLimitTargetDPO::getLineId, lineList)
.gt(RStatLimitTargetDPO::getUaberranceOvertime, 0);
List<RStatLimitTargetDPO> list = limitTargetMapper.selectList(lambdaQueryWrapper);
return CollUtil.isEmpty(list)?0: list.stream().distinct().map(RStatLimitTargetDPO::getLineId).collect(Collectors.toList()).size();
}
/**
* 闪变超标点数
*/
public Integer getOverFlicker(List<String> lineList, String startTime, String endTime) {
LambdaQueryWrapper<RStatLimitTargetDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(RStatLimitTargetDPO::getLineId)
.between(RStatLimitTargetDPO::getTime, startTime, endTime)
.in(RStatLimitTargetDPO::getLineId, lineList)
.gt(RStatLimitTargetDPO::getFlickerOvertime, 0);
List<RStatLimitTargetDPO> list = limitTargetMapper.selectList(lambdaQueryWrapper);
return CollUtil.isEmpty(list)?0: list.stream().distinct().map(RStatLimitTargetDPO::getLineId).collect(Collectors.toList()).size();
}
}