上个版本补漏

This commit is contained in:
guofeihu
2024-09-12 13:47:30 +08:00
parent 1ec3385f2d
commit 00c5f4c710
10 changed files with 274 additions and 34 deletions

View File

@@ -23,6 +23,7 @@ import com.njcn.prepare.harmonic.service.mysql.event.RActivePowerRangeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
@@ -74,6 +75,7 @@ public class RActivePowerRangeServiceImpl extends MppServiceImpl<RActivePowerRan
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public List<PowerStatisticsTargetVO> record(RActivePowerRangeParam rActivePowerRangeParam) {
if(rActivePowerRangeParam == null){
rActivePowerRangeParam = new RActivePowerRangeParam();
@@ -404,13 +406,13 @@ public class RActivePowerRangeServiceImpl extends MppServiceImpl<RActivePowerRan
}
}
//组装公共查询(有谐波次数查询和没有谐波次数查询)
//组装公共查询(有谐波次数指标查询和没有谐波次数指标查询)
private List<StatisticalDataDTO> commonQuery(String tableName,String columnName,StatisticalDataDTO statisticalDataDTO,Integer start,Integer end){
List<CommonQueryParam> commonQueryParams = new ArrayList<>();
//不管哪种时间是固定的
String time = statisticalDataDTO.getTime().atZone(ZoneId.systemDefault()).format(formatter);
CommonQueryParam commonQueryParam = new CommonQueryParam();
//无谐波次数查询
//无谐波次数指标查询
if(start == null){
commonQueryParam.setStartTime(time);
commonQueryParam.setEndTime(time);
@@ -421,7 +423,7 @@ public class RActivePowerRangeServiceImpl extends MppServiceImpl<RActivePowerRan
commonQueryParam.setColumnName(columnName);
commonQueryParams.add(commonQueryParam);
}else{
//有谐波次数查询
//有谐波次数指标查询
for (int i = start; i <= end; i++) {
commonQueryParam = new CommonQueryParam();
commonQueryParam.setStartTime(time);
@@ -472,7 +474,7 @@ public class RActivePowerRangeServiceImpl extends MppServiceImpl<RActivePowerRan
if(!rActivePowerRangePOS.isEmpty()){
RActivePowerRangePO rActivePowerRangePO = new RActivePowerRangePO();
rActivePowerRangePO.setLineId(lineId);
//多条记录则次数累加,是否越限只有一个区间越限则统一视为该区间越限
//多条记录则次数累加,是否越限只有一个区间越限则统一视为该区间越限
for(RActivePowerRangePO rangePO : rActivePowerRangePOS){
rActivePowerRangePO.setMinsNum0(rangePO.getMinsNum0()+rActivePowerRangePO.getMinsNum0());
rActivePowerRangePO.setMinsNum1(rangePO.getMinsNum1()+rActivePowerRangePO.getMinsNum1());

View File

@@ -1,15 +1,18 @@
package com.njcn.prepare.harmonic.service.mysql.Impl.event;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.device.biz.commApi.CommLineClient;
import com.njcn.device.biz.pojo.dto.LineDTO;
import com.njcn.device.pms.pojo.param.MonitorTerminalParam;
import com.njcn.device.pq.api.NewStationClient;
import com.njcn.device.pq.constant.Param;
import com.njcn.device.pq.pojo.po.NewStation;
import com.njcn.event.api.EventDetailFeignClient;
import com.njcn.event.file.component.WaveFileComponent;
import com.njcn.event.api.TransientFeignClient;
import com.njcn.event.file.pojo.dto.WaveDataDTO;
import com.njcn.event.pojo.po.RmpEventDetailPO;
import com.njcn.prepare.harmonic.mapper.mysql.event.SpThroughMapper;
import com.njcn.prepare.harmonic.pojo.param.SpThroughParam;
@@ -18,8 +21,11 @@ import com.njcn.prepare.harmonic.pojo.vo.SpThroughVO;
import com.njcn.prepare.harmonic.service.mysql.event.SpThroughService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.time.LocalDateTime;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -37,46 +43,182 @@ public class SpThroughServiceImpl extends MppServiceImpl<SpThroughMapper, SpThro
private final NewStationClient newStationClient;
private final WaveFileComponent waveFileComponent;
private final TransientFeignClient transientFeignClient;
@Override
@Transactional(rollbackFor = Exception.class)
public void record() {
LocalDateTime currentTime = LocalDateTime.now();
//获取最新的暂态事件信息(截至目前为止)
List<RmpEventDetailPO> evenStDetailPOS = eventDetailFeignClient.getNewEventDetailByTime(getLastTime(),currentTime).getData();
MonitorTerminalParam monitorTerminalParam = new MonitorTerminalParam();
monitorTerminalParam.setSystemType(0);
monitorTerminalParam.setType(0);
for(RmpEventDetailPO rmpEventDetailPO : evenStDetailPOS){
//获取监测点
LineDTO lineDTO = commLineClient.getLineDetail(rmpEventDetailPO.getMeasurementPointId()).getData();
if(lineDTO != null && lineDTO.getNewStationId() != null){
//监测点必须绑定新能源场站
NewStation newStation = newStationClient.selectById(lineDTO.getNewStationId()).getData();
if(newStation != null){
//waveFileComponent.getComtrade();
//暂升事件
if(Param.UPPEREVENT.equals(rmpEventDetailPO.getEventType())){
//风电场
if(Param.WINDFARM.equals(newStation.getStationType())){
}
//光伏电站
if(Param.PHOTOVOLTAICPOWER.equals(newStation.getStationType())){
}
}
//暂降事件
if(Param.LOWEREVENT.equals(rmpEventDetailPO.getEventType())){
//风电场
if(Param.WINDFARM.equals(newStation.getStationType())){
}
//光伏电站
if(Param.PHOTOVOLTAICPOWER.equals(newStation.getStationType())){
//事件不能重复统计(除非事件的暂降类型及变电站类型发生变化)
LambdaQueryWrapper<SpThroughPO> lambdaQueryWrapper = new LambdaQueryWrapper();
lambdaQueryWrapper.eq(SpThroughPO::getEventId,rmpEventDetailPO.getEventId())
.eq(SpThroughPO::getEventType,rmpEventDetailPO.getEventType())
.eq(SpThroughPO::getStationType,newStation.getStationType())
.eq(SpThroughPO::getState,1);
if(this.baseMapper.selectList(lambdaQueryWrapper).isEmpty()){
//准备高低电压穿越实体bean
SpThroughPO spThroughPO = new SpThroughPO();
spThroughPO.setId(IdUtil.simpleUUID());
spThroughPO.setEventId(rmpEventDetailPO.getEventId());
spThroughPO.setEventType(rmpEventDetailPO.getEventType());
spThroughPO.setStationType(newStation.getStationType());
//默认该事件没有穿越
spThroughPO.setIsOrNot(0);
//设置波形查询的条件:事件ID
monitorTerminalParam.setId(rmpEventDetailPO.getEventId());
//获取RMS波形数据(由于WaveDataDTO为复杂对象所以转成byte数组在进行反序列化)
byte[] bytes = transientFeignClient.getTransientAnalyseWaveToByteArray(monitorTerminalParam).getData();
WaveDataDTO waveDataDTO = null;
try {
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bis);
//强转成WaveDataDTO
waveDataDTO = (WaveDataDTO)ois.readObject();
} catch (Exception e) {
e.printStackTrace();
}
//标称电压
if(lineDTO.getVoltageLevel()!=null){
Float voltageLevel = Float.parseFloat(lineDTO.getVoltageLevel());
//格式化数据源
List<List<Float>> newListRmsData = listRmsDataFormat(waveDataDTO);
//暂升事件
if(Param.UPPEREVENT.equals(rmpEventDetailPO.getEventType())){
//风电场
if(Param.WINDFARM.equals(newStation.getStationType())){
if(isThrough(waveDataDTO,125,130,500,voltageLevel.floatValue(),newListRmsData)
&& isThrough(waveDataDTO,120,125,1000,voltageLevel.floatValue(),newListRmsData)
&& isThrough(waveDataDTO,110,120,10000,voltageLevel.floatValue(),newListRmsData)){
spThroughPO.setIsOrNot(1);
}
}
//光伏电站
if(Param.PHOTOVOLTAICPOWER.equals(newStation.getStationType())){
if(isThrough(waveDataDTO,125,130,500,voltageLevel.floatValue(),newListRmsData)
&& isThrough(waveDataDTO,120,125,1000,voltageLevel.floatValue(),newListRmsData)
&& isThrough(waveDataDTO,110,120,10000,voltageLevel.floatValue(),newListRmsData)){
spThroughPO.setIsOrNot(1);
}
}
}
//暂降事件
if(Param.LOWEREVENT.equals(rmpEventDetailPO.getEventType())){
//风电场
if(Param.WINDFARM.equals(newStation.getStationType())){
if(isThrough(waveDataDTO,20,-1,625,voltageLevel.floatValue(),newListRmsData)){
spThroughPO.setIsOrNot(1);
}
}
//光伏电站
if(Param.PHOTOVOLTAICPOWER.equals(newStation.getStationType())){
if(isThrough(waveDataDTO,0,-1,150,voltageLevel.floatValue(),newListRmsData)
&& isThrough(waveDataDTO,20,-1,625,voltageLevel.floatValue(),newListRmsData)
&& isThrough(waveDataDTO,20,90,-1,voltageLevel.floatValue(),newListRmsData)){
spThroughPO.setIsOrNot(1);
}
}
}
spThroughPO.setCreateTime(currentTime);
this.baseMapper.insert(spThroughPO);
};
}
}
}
}
}
private boolean isThrough(WaveDataDTO waveDataDTO,int start,int end,int ms,float voltageLevel,List<List<Float>> newListRmsData){
boolean isThrough = false;
//格式化RMS源数据
float startVoltageLevel = voltageLevel * (start / 100F);
float endVoltageLevel = -1;
if(end!=-1){
endVoltageLevel = voltageLevel * (end / 100F);
}
for (int i = 0; i < newListRmsData.size(); i++) {
for (int j = 1; j < newListRmsData.get(i).size(); j++) {
float curValue = newListRmsData.get(i).get(j);
//当电压达到目标值时
if(endVoltageLevel != -1 && startVoltageLevel < curValue && curValue <= endVoltageLevel){
isContinuity(newListRmsData,i+1,newListRmsData.get(i).get(0).intValue(),ms,j);
isThrough = true;
}else if(startVoltageLevel == curValue){
isContinuity(newListRmsData,i+1,newListRmsData.get(i).get(0).intValue(),ms,j);
isThrough = true;
}
}
}
return isThrough;
}
private boolean isContinuity(List<List<Float>> newListRmsData,int index,int curms,int ms,int p){
boolean isContinuity = false;
//记录电压有效毫秒数
Set<Integer> effectiveMs = new HashSet<>();
for (int k = curms + 1 ; k <= curms + ms; k++) {
effectiveMs.add(k);
}
int count = 0;
for (int i = index; i < newListRmsData.size(); i++) {
for (int j = 0; j < newListRmsData.get(i).size(); j++) {
int curVallue = newListRmsData.get(i).get(0).intValue();
//如果当前相别的电压毫秒数在有效期范围内则记录下数字
if(effectiveMs.contains(curVallue) && checkListIsNull(newListRmsData.get(i),p)!=null){
count ++;
}
}
}
if(count >= effectiveMs.size()){
isContinuity = true;
}
return isContinuity;
}
private Float checkListIsNull(List<Float> list ,int index){
try {
return list.get(index);
} catch (Exception e) {
return null;
}
}
//格式化RMS数据:将listRmsData中的电压数据取出在根据pt变比组成新的RMS数据
private List<List<Float>> listRmsDataFormat(WaveDataDTO waveDataDTO){
List<List<Float>> newListRmsData = new ArrayList<>();
List<Integer> indexs = new ArrayList<>();
//根据channelNames取出电压对应listRmsData数据中的数据索引
for (int i = 0; i < waveDataDTO.getChannelNames().size(); i++) {
if(waveDataDTO.getChannelNames().get(i).indexOf("电压")!=-1){
indexs.add(i);
}
}
//前端展示的波形图数据来源就是这个所以这边也跟前端保持一致
for (int i = 0; i < waveDataDTO.getListRmsData().size(); i++) {
List<Float> cur = waveDataDTO.getListRmsData().get(i);
List<Float> newCur = new ArrayList<>();
//数组第一个为时间
newCur.add(cur.get(0));
//便利电压数据的索引
for(Integer index : indexs){
//根据PT变比算出新的数据(前端取的一次值,也是根据pt变比算出的,所以这边和前端保持一致)新增到新的数组中
newCur.add(cur.get(index) * Float.parseFloat((waveDataDTO.getPt() / 1000F)+""));
}
newListRmsData.add(newCur);
}
return newListRmsData;
}
//拿到最近一次插入高低电压穿越表信息的时间