有功功率趋势指标列表详细excel导出

This commit is contained in:
guofeihu
2024-09-10 15:04:54 +08:00
parent bf67652055
commit 024bba337a
9 changed files with 618 additions and 257 deletions

View File

@@ -1,6 +1,5 @@
package com.njcn.harmonic.constant;
/**
* @author 徐扬
*/
@@ -71,4 +70,20 @@ public interface Param {
String DECIMAL_FORMATSTR = "#0.0000";
String DECIMAL_FORMATTWOSTR = "#.##";
String voltageOffset = "电压偏差";
String vTimes = "谐波电压";
String iTimes = "谐波电流";
String ubalance = "三相电压不平衡度";
String voltageFluctuation = "电压波动";
String flicker = "闪变";
String interHarmonic = "间谐波电压含有率";
String sequenceCurrentUnbalance = "电流不平衡度";
}

View File

@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;
/**
@@ -27,33 +28,33 @@ public class PowerStatisticsParam extends BaseParam {
private String field;
@ApiModelProperty("区间1时间集合")
private List<String> time0;
private List<String> time0 = new ArrayList<>();
@ApiModelProperty("区间2时间集合")
private List<String> time1;
private List<String> time1 = new ArrayList<>();
@ApiModelProperty("区间3时间集合")
private List<String> time2;
private List<String> time2 = new ArrayList<>();
@ApiModelProperty("区间4时间集合")
private List<String> time3;
private List<String> time3 = new ArrayList<>();
@ApiModelProperty("区间5时间集合")
private List<String> time4;
private List<String> time4 = new ArrayList<>();
@ApiModelProperty("区间6时间集合")
private List<String> time5;
private List<String> time5 = new ArrayList<>();
@ApiModelProperty("区间7时间集合")
private List<String> time6;
private List<String> time6 = new ArrayList<>();
@ApiModelProperty("区间8时间集合")
private List<String> time7;
private List<String> time7 = new ArrayList<>();
@ApiModelProperty("区间9时间集合")
private List<String> time8;
private List<String> time8 = new ArrayList<>();
@ApiModelProperty("区间10时间集合")
private List<String> time9;
private List<String> time9 = new ArrayList<>();
}

View File

@@ -1,5 +1,6 @@
package com.njcn.harmonic.pojo.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -19,12 +20,15 @@ public class PowerStatisticsTargetVO {
private String time;
@ApiModelProperty("电压偏差")
@ExcelProperty(index =2,value = {"电压","B"})
private Integer voltageOffset = 0;
@ApiModelProperty("谐波电压")
@ExcelProperty(index =3,value = {"电压","C"})
private Integer vTimes = 0;
@ApiModelProperty("谐波电流")
@ExcelProperty(index =4,value = {"电流","A"})
private Integer iTimes = 0;
@ApiModelProperty("三相电压不平衡度")
@@ -69,34 +73,58 @@ public class PowerStatisticsTargetVO {
@ApiModelProperty("电流不平衡度详情")
private List<ThdDataVO> sequenceCurrentUnbalanceList = new ArrayList<>();
@ApiModelProperty("越限相别(用于后端辅助计算)")
@ApiModelProperty("相别(用于后端辅助计算)")
private String phasicType;
@ApiModelProperty("越限统计方式(用于后端辅助计算)")
@ApiModelProperty("统计方式(用于后端辅助计算)")
private String valueType;;
@ApiModelProperty("电压偏差国标限(用于后端辅助计算)")
@ApiModelProperty("电压偏差国标限(用于后端辅助计算)")
private Float voltageOffsetLimit;
@ApiModelProperty("谐波电压国标限(用于后端辅助计算)")
private Float vTimesLimit;
@ApiModelProperty("谐波电压国标限(用于后端辅助计算)")
private List<Float> vTimesLimit = new ArrayList<>();;
@ApiModelProperty("谐波电流国标限(用于后端辅助计算)")
private Float iTimesLimit;
@ApiModelProperty("谐波电流国标限(用于后端辅助计算)")
private List<Float> iTimesLimit = new ArrayList<>();;
@ApiModelProperty("三相电压不平衡度国标限(用于后端辅助计算)")
@ApiModelProperty("三相电压不平衡度国标限(用于后端辅助计算)")
private Float ubalanceLimit;
@ApiModelProperty("电压波动国标限(用于后端辅助计算)")
@ApiModelProperty("电压波动国标限(用于后端辅助计算)")
private Float voltageFluctuationLimit;
@ApiModelProperty("闪变国标限(用于后端辅助计算)")
@ApiModelProperty("闪变国标限(用于后端辅助计算)")
private Float flickerLimit;
@ApiModelProperty("间谐波电压含有率国标限(用于后端辅助计算)")
private Float interHarmonicLimit;
@ApiModelProperty("间谐波电压含有率国标限(用于后端辅助计算)")
private List<Float> interHarmonicLimit = new ArrayList<>();;
@ApiModelProperty("电流不平衡度国标限(用于后端辅助计算)")
@ApiModelProperty("电流不平衡度国标限(用于后端辅助计算)")
private Float sequenceCurrentUnbalanceLimit;
@ApiModelProperty("电压偏差具体值(用于后端辅助计算)")
private Double voltageOffsetData;
@ApiModelProperty("谐波电压具体值(用于后端辅助计算)")
private List<Double> vTimesData = new ArrayList<>();;
@ApiModelProperty("谐波电流具体值(用于后端辅助计算)")
private List<Double> iTimesData = new ArrayList<>();;
@ApiModelProperty("三相电压不平衡度具体值(用于后端辅助计算)")
private Double ubalanceData;
@ApiModelProperty("电压波动具体值(用于后端辅助计算)")
private Double voltageFluctuationData;
@ApiModelProperty("闪变具体值(用于后端辅助计算)")
private Double flickerData;
@ApiModelProperty("间谐波电压含有率具体值(用于后端辅助计算)")
private List<Double> interHarmonicData = new ArrayList<>();
@ApiModelProperty("电流不平衡度具体值(用于后端辅助计算)")
private Double sequenceCurrentUnbalanceData;
}

View File

@@ -17,24 +17,6 @@ public class ThdDataVO {
@ApiModelProperty("单位")
private String unit;
@ApiModelProperty("平均值A相")
private String AVGPhaseA;
@ApiModelProperty("平均值B相")
private String AVGPhaseB;
@ApiModelProperty("平均值C相")
private String AVGPhaseC;
@ApiModelProperty("CP95A相")
private String CP95PhaseA;
@ApiModelProperty("CP95B相")
private String CP95PhaseB;
@ApiModelProperty("CP95C相")
private String CP95PhaseC;
@ApiModelProperty("最小值A相")
private String MINPhaseA;
@@ -53,22 +35,28 @@ public class ThdDataVO {
@ApiModelProperty("最大值C相")
private String MAXPhaseC;
@ApiModelProperty("平均值A相")
private String AVGPhaseA;
@ApiModelProperty("平均值B相")
private String AVGPhaseB;
@ApiModelProperty("平均值C相")
private String AVGPhaseC;
@ApiModelProperty("CP95A相")
private String CP95PhaseA;
@ApiModelProperty("CP95B相")
private String CP95PhaseB;
@ApiModelProperty("CP95C相")
private String CP95PhaseC;
@ApiModelProperty("国标限值")
private Float limit;
public void init(){
this.AVGPhaseA = "0";
this.AVGPhaseB = "0";
this.AVGPhaseC = "0";
this.CP95PhaseA = "0";
this.CP95PhaseB = "0";
this.CP95PhaseC = "0";
this.MINPhaseA = "0";
this.MINPhaseB = "0";
this.MINPhaseC = "0";
this.MAXPhaseA = "0";
this.MAXPhaseB = "0";
this.MAXPhaseC = "0";
}
@ApiModelProperty("时间")
private String time;
}

View File

@@ -0,0 +1,75 @@
package com.njcn.harmonic.pojo.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 指标详情数据Excel实体类
* @author guofeihu
* @since 2024-08-20
*/
@Data
public class ThdDataVOExcel {
@ApiModelProperty("时间")
@ExcelProperty(index =0,value = "时间")
private String time;
@ApiModelProperty("名称")
@ExcelProperty(index =1,value = "指标")
private String anotherName;
@ApiModelProperty("单位")
@ExcelProperty(index =2,value = "单位")
private String unit;
@ApiModelProperty("最小值A相")
@ExcelProperty(index =3,value = {"最小值","A"})
private String MINPhaseA;
@ApiModelProperty("最小值B相")
@ExcelProperty(index =4,value = {"最小值","B"})
private String MINPhaseB;
@ApiModelProperty("最小值C相")
@ExcelProperty(index =5,value = {"最小值","C"})
private String MINPhaseC;
@ApiModelProperty("最大值A相")
@ExcelProperty(index =6,value = {"最大值","A"})
private String MAXPhaseA;
@ApiModelProperty("最大值B相")
@ExcelProperty(index =7,value = {"最大值","B"})
private String MAXPhaseB;
@ApiModelProperty("最大值C相")
@ExcelProperty(index =8,value = {"最大值","C"})
private String MAXPhaseC;
@ApiModelProperty("平均值A相")
@ExcelProperty(index =9,value = {"平均值","A"})
private String AVGPhaseA;
@ApiModelProperty("平均值B相")
@ExcelProperty(index =10,value = {"平均值","B"})
private String AVGPhaseB;
@ApiModelProperty("平均值C相")
@ExcelProperty(index =11,value = {"平均值","C"})
private String AVGPhaseC;
@ApiModelProperty("CP95A相")
@ExcelProperty(index =12,value = {"cp95","A"})
private String CP95PhaseA;
@ApiModelProperty("CP95B相")
@ExcelProperty(index =13,value = {"cp95","B"})
private String CP95PhaseB;
@ApiModelProperty("CP95C相")
@ExcelProperty(index =14,value = {"cp95","C"})
private String CP95PhaseC;
}

View File

@@ -100,6 +100,12 @@
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>advance-api</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

View File

@@ -3,12 +3,12 @@ package com.njcn.harmonic.service.activepowerrange.impl;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.njcn.harmonic.constant.Param;
import com.njcn.harmonic.pojo.param.PowerStatisticsParam;
import com.njcn.harmonic.pojo.vo.PowerStatisticsExcelRangVO;
import com.njcn.harmonic.pojo.vo.PowerStatisticsTargetVO;
import com.njcn.harmonic.pojo.vo.PowerStatisticsVO;
import com.njcn.harmonic.pojo.vo.ThdDataVO;
import com.njcn.harmonic.pojo.vo.*;
import com.njcn.harmonic.service.activepowerrange.PowerStatisticsService;
import com.njcn.influx.pojo.bo.CommonQueryParam;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
@@ -28,6 +28,7 @@ import org.apache.poi.xssf.usermodel.XSSFSimpleShape;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;
@@ -51,12 +52,23 @@ public class PowerStatisticsServiceImpl implements PowerStatisticsService {
private final EpdFeignClient epdFeignClient;
private List<String> METHODS = Arrays.asList("AVG","CP95","MIN","MAX");
private List<String> METHODS = Arrays.asList(InfluxDBTableConstant.AVG,InfluxDBTableConstant.CP95,InfluxDBTableConstant.MIN,InfluxDBTableConstant.MAX);
private List<String> PHASE = Arrays.asList("A","B","C");
private List<String> PHASE = Arrays.asList(InfluxDBTableConstant.PHASE_TYPE_A,InfluxDBTableConstant.PHASE_TYPE_B,InfluxDBTableConstant.PHASE_TYPE_C);
private List<String> times = Arrays.asList("0~10%","10~20%","20~30%","30~40%","40~50%","50~60%","60~70%","70~80%","80~90%","90~100%");
@Override
public PowerStatisticsVO getDataByLineId(PowerStatisticsParam powerStatisticsParam) {
//每次执行区间查询前都走一遍定时任务算法(防止当天没有区间相关数据)
RActivePowerRangeParam rActivePowerRangeParam = new RActivePowerRangeParam();
BeanUtil.copyProperties(powerStatisticsParam, rActivePowerRangeParam);
//设置查询
rActivePowerRangeParam.setSearch(true);
rActivePowerRangeParam.setSearchForAdd(true);
//执行定时任务根据前端点击的时间范围及监测点
rActivePowerRangeFeignClient.record(rActivePowerRangeParam);
//执行完就可以获取到区间数据了
RActivePowerRangePO rActivePowerRangePO = rActivePowerRangeFeignClient.getDataByLineId(powerStatisticsParam.getLineId(),
powerStatisticsParam.getSearchBeginTime(),powerStatisticsParam.getSearchEndTime()).getData();
if(rActivePowerRangePO == null){
@@ -87,11 +99,10 @@ public class PowerStatisticsServiceImpl implements PowerStatisticsService {
@Override
public List<PowerStatisticsTargetVO> getTargetLimitById(PowerStatisticsParam powerStatisticsParam) {
List<PowerStatisticsTargetVO> data = new ArrayList<>();
RActivePowerRangeParam rActivePowerRangeParam = new RActivePowerRangeParam();
BeanUtil.copyProperties(powerStatisticsParam, rActivePowerRangeParam);
rActivePowerRangeParam.setSearch(true);
//重点说明:powerStatisticsTargetVO结构(维度)为:time可能多组相同,取决于功率表data_harmpower_p中的相别及统计方式,标识每个指标是否越限,总之一句话:当前时间中八个指标是否越限及他们的相别和统计方式是什么
//重点说明:powerStatisticsTargetVO结构(维度)为:time可能多组相同,取决于功率表data_harmpower_p中的相别及统计方式,标识每个指标是否越限,总之一句话:每条数据当前时间中八个指标是否越限及他们的相别和统计方式是什么
//基于record结构需要做维度的转换
List<PowerStatisticsTargetVO> record = rActivePowerRangeFeignClient.record(rActivePowerRangeParam).getData();
//根据时间分组:
@@ -99,126 +110,211 @@ public class PowerStatisticsServiceImpl implements PowerStatisticsService {
map.forEach((key, value) ->{
PowerStatisticsTargetVO powerStatisticsTargetVO = new PowerStatisticsTargetVO();
powerStatisticsTargetVO.setTime(key);
ThdDataVO thdDataVO = new ThdDataVO();
thdDataVO.init();
Map<String,String> voltageOffsetPV = new HashMap<>();
Map<String,String> vTimesPV = new HashMap<>();
Map<String,String> iTimesPV = new HashMap<>();
Map<String,String> ubalancePV = new HashMap<>();
Map<String,String> voltageFluctuationPV = new HashMap<>();
Map<String,String> flickerPV = new HashMap<>();
Map<String,String> interHarmonicPV = new HashMap<>();
Map<String,String> sequenceCurrentUnbalancePV = new HashMap<>();
powerStatisticsTargetVO.setField(powerStatisticsParam.getField());
//各指标越限的相别及统计方式集合
List<Map<String,String>> pvs = new ArrayList<>();
//遍历当前时间下的区间指标(注意:可能多组只是说统计方式和相别不同)
for(PowerStatisticsTargetVO vo : value){
if(vo.getVoltageOffset() == 1){
powerStatisticsTargetVO.setVoltageOffset(1);
voltageOffsetPV.put(vo.getPhasicType(),vo.getValueType());
}
if(vo.getVTimes() == 1){
powerStatisticsTargetVO.setVTimes(1);
vTimesPV.put(vo.getPhasicType(),vo.getValueType());
}
if(vo.getITimes() == 1){
powerStatisticsTargetVO.setITimes(1);
iTimesPV.put(vo.getPhasicType(),vo.getValueType());
}
if(vo.getUbalance() == 1){
powerStatisticsTargetVO.setUbalance(1);
ubalancePV.put(vo.getPhasicType(),vo.getValueType());
}
if(vo.getVoltageFluctuation() == 1){
powerStatisticsTargetVO.setVoltageFluctuation(1);
voltageFluctuationPV.put(vo.getPhasicType(),vo.getValueType());
}
if(vo.getFlicker() == 1){
powerStatisticsTargetVO.setFlicker(1);
flickerPV.put(vo.getPhasicType(),vo.getValueType());
}
if(vo.getInterHarmonic() == 1){
powerStatisticsTargetVO.setInterHarmonic(1);
interHarmonicPV.put(vo.getPhasicType(),vo.getValueType());
}
if(vo.getSequenceCurrentUnbalance() == 1){
powerStatisticsTargetVO.setSequenceCurrentUnbalance(1);
sequenceCurrentUnbalancePV.put(vo.getPhasicType(),vo.getValueType());
}
//以下这些判断只要有一个指标越限了(不管是什么统计方式和相别)直接标识该指标越限(这些字段用于前端展示)
if(vo.getVoltageOffset().intValue() == 1) powerStatisticsTargetVO.setVoltageOffset(1);
if(vo.getVTimes().intValue() == 1) powerStatisticsTargetVO.setVTimes(1);
if(vo.getITimes().intValue() == 1) powerStatisticsTargetVO.setITimes(1);
if(vo.getUbalance().intValue() == 1) powerStatisticsTargetVO.setUbalance(1);
if(vo.getVoltageFluctuation().intValue() == 1) powerStatisticsTargetVO.setVoltageFluctuation(1);
if(vo.getFlicker().intValue() == 1) powerStatisticsTargetVO.setFlicker(1);
if(vo.getInterHarmonic().intValue() == 1) powerStatisticsTargetVO.setInterHarmonic(1);
if(vo.getSequenceCurrentUnbalance().intValue() == 1) powerStatisticsTargetVO.setSequenceCurrentUnbalance(1);
//以下逻辑用于前端点击指标时能看到指标具体的越限情况(比方说A相AVG越限了)
Map<String,String> pv = new HashMap<>();
pv.put(vo.getPhasicType(),vo.getValueType());
//除了带有谐波次数的指标需要特殊处理其他正常添加到pvs中
if(vo.getVoltageOffsetData()!=null) pv.put(Param.voltageOffset,df.format(vo.getVoltageOffsetData()));
if(vo.getUbalanceData()!=null) pv.put(Param.ubalance,df.format(vo.getUbalanceData()));
if(vo.getVoltageFluctuationData()!=null) pv.put(Param.voltageFluctuation,df.format(vo.getVoltageFluctuationData()));
if(vo.getFlickerData()!=null) pv.put(Param.flicker,df.format(vo.getFlickerData()));
if(vo.getSequenceCurrentUnbalanceData()!=null) pv.put(Param.sequenceCurrentUnbalance,df.format(vo.getSequenceCurrentUnbalanceData()));
pvs.add(pv);
}
powerStatisticsTargetVO.setVoltageOffsetList(initPV(voltageOffsetPV,"电压偏差",value.get(0).getVoltageOffsetLimit()));
powerStatisticsTargetVO.setVTimesList(initPV(vTimesPV,"谐波电压",value.get(0).getVTimesLimit()));
powerStatisticsTargetVO.setITimestList(initPV(iTimesPV,"谐波电流",value.get(0).getITimesLimit()));
powerStatisticsTargetVO.setUbalanceList(initPV(ubalancePV,"三相电压不平衡度",value.get(0).getUbalanceLimit()));
powerStatisticsTargetVO.setVoltageFluctuationList(initPV(voltageFluctuationPV,"电压波动",value.get(0).getVoltageFluctuationLimit()));
powerStatisticsTargetVO.setFlickerList(initPV(flickerPV,"闪变",value.get(0).getFlickerLimit()));
powerStatisticsTargetVO.setInterHarmonicList(initPV(interHarmonicPV,"间谐波电压含有率",value.get(0).getInterHarmonicLimit()));
powerStatisticsTargetVO.setSequenceCurrentUnbalanceList(initPV(sequenceCurrentUnbalancePV,"电流不平衡度",value.get(0).getSequenceCurrentUnbalanceLimit()));
powerStatisticsTargetVO.setVoltageOffsetList(initPV(pvs,Param.voltageOffset,value.get(0).getVoltageOffsetLimit()));
//谐波电压带有谐波次数需要特殊处理
powerStatisticsTargetVO.setVTimesList(initFrequencyPV(value,Param.vTimes,value.get(0).getVTimesLimit()));
//谐波电流带有谐波次数需要特殊处理
powerStatisticsTargetVO.setITimestList(initFrequencyPV(value,Param.iTimes,value.get(0).getITimesLimit()));
powerStatisticsTargetVO.setUbalanceList(initPV(pvs,Param.ubalance,value.get(0).getUbalanceLimit()));
powerStatisticsTargetVO.setVoltageFluctuationList(initPV(pvs,Param.voltageFluctuation,value.get(0).getVoltageFluctuationLimit()));
powerStatisticsTargetVO.setFlickerList(initPV(pvs,Param.flicker,value.get(0).getFlickerLimit()));
//间谐波电压含有率带有谐波次数需要特殊处理
powerStatisticsTargetVO.setInterHarmonicList(initFrequencyPV(value,Param.interHarmonic,value.get(0).getInterHarmonicLimit()));
powerStatisticsTargetVO.setSequenceCurrentUnbalanceList(initPV(pvs,Param.sequenceCurrentUnbalance,value.get(0).getSequenceCurrentUnbalanceLimit()));
data.add(powerStatisticsTargetVO);
});
return data;
return data.stream().sorted(Comparator.comparing(PowerStatisticsTargetVO::getTime)).collect(Collectors.toList());
}
private List<ThdDataVO> initPV(Map<String,String> pv,String name,Float limit){
private List<ThdDataVO> initPV(List<Map<String,String>> pv, String name, Float limit){
List<ThdDataVO> thdDataVOS = new ArrayList<>();
ThdDataVO tdv = new ThdDataVO();
tdv.setAnotherName(name);
tdv.setLimit(limit);
tdv.init();
pv.forEach((phasicType, valueType) ->{
switch (valueType){
case InfluxDBTableConstant.AVG:
switch (valueType){
case InfluxDBTableConstant.PHASE_TYPE_A:
tdv.setAVGPhaseA("1");
break;
case InfluxDBTableConstant.PHASE_TYPE_B:
tdv.setAVGPhaseB("1");
break;
case InfluxDBTableConstant.PHASE_TYPE_C:
tdv.setAVGPhaseC("1");
break;
}
//便利统计方式和相别集合渲染对应字段
for(Map<String,String> arr :pv){
arr.forEach((phasicType, valueType) ->{
switch (valueType){
case InfluxDBTableConstant.AVG:
switch (phasicType){
case InfluxDBTableConstant.PHASE_TYPE_A:
tdv.setAVGPhaseA(arr.get(name));
break;
case InfluxDBTableConstant.PHASE_TYPE_B:
tdv.setAVGPhaseB(arr.get(name));
break;
case InfluxDBTableConstant.PHASE_TYPE_C:
tdv.setAVGPhaseC(arr.get(name));
break;
}
break;
case InfluxDBTableConstant.CP95:
switch (phasicType){
case InfluxDBTableConstant.PHASE_TYPE_A:
tdv.setCP95PhaseA(arr.get(name));
break;
case InfluxDBTableConstant.PHASE_TYPE_B:
tdv.setCP95PhaseB(arr.get(name));
break;
case InfluxDBTableConstant.PHASE_TYPE_C:
tdv.setCP95PhaseC(arr.get(name));
break;
}
break;
case InfluxDBTableConstant.MIN:
switch (phasicType){
case InfluxDBTableConstant.PHASE_TYPE_A:
tdv.setMINPhaseA(arr.get(name));
break;
case InfluxDBTableConstant.PHASE_TYPE_B:
tdv.setMINPhaseB(arr.get(name));
break;
case InfluxDBTableConstant.PHASE_TYPE_C:
tdv.setMINPhaseC(arr.get(name));
break;
}
break;
case InfluxDBTableConstant.MAX:
switch (phasicType){
case InfluxDBTableConstant.PHASE_TYPE_A:
tdv.setMAXPhaseA(arr.get(name));
break;
case InfluxDBTableConstant.PHASE_TYPE_B:
tdv.setMAXPhaseB(arr.get(name));
break;
case InfluxDBTableConstant.PHASE_TYPE_C:
tdv.setMAXPhaseC(arr.get(name));
break;
}
break;
}
});
}
//如果所有的相别和统计方式都没有值则可直接忽略该条数据
if(tdv.getAVGPhaseA() != null || tdv.getAVGPhaseB() != null
|| tdv.getAVGPhaseC() != null || tdv.getCP95PhaseA() != null
|| tdv.getCP95PhaseB() != null || tdv.getCP95PhaseC() != null
|| tdv.getMINPhaseA() != null || tdv.getMINPhaseB() != null
|| tdv.getMINPhaseC() != null || tdv.getMAXPhaseA() != null
|| tdv.getMAXPhaseB() != null || tdv.getMAXPhaseC() != null){
thdDataVOS.add(tdv);
}
return thdDataVOS;
}
private List<Double> getFrequencyData(List<PowerStatisticsTargetVO> pv,String valueType,String phasicType,String name){
//根据不同的相别及统计方式分别获取该时间组下区间指标集合的具体值
List<PowerStatisticsTargetVO> data = pv.stream().filter(param->phasicType.equals(param.getPhasicType()) && valueType.equals(param.getValueType())).collect(Collectors.toList());
if(!data.isEmpty()){
switch (name){
case Param.vTimes:
return data.get(0).getVTimesData();
case Param.iTimes:
return data.get(0).getITimesData();
case Param.interHarmonic:
return data.get(0).getInterHarmonicData();
}
}
return null;
}
private String frequencyPVList(List<Double> data,int index){
try {
return df.format(data.get(index));
} catch (Exception e) {
return null;
}
}
private List<ThdDataVO> initFrequencyPV(List<PowerStatisticsTargetVO> pv, String name, List<Float> limit){
List<ThdDataVO> thdDataVOS = new ArrayList<>();
if(!limit.isEmpty()){
//根据不同的相别及统计方式分别获取该时间组下区间指标集合的具体值
List<Double> avgA = getFrequencyData(pv,InfluxDBTableConstant.AVG,InfluxDBTableConstant.PHASE_TYPE_A,name);
List<Double> avgB = getFrequencyData(pv,InfluxDBTableConstant.AVG,InfluxDBTableConstant.PHASE_TYPE_B,name);
List<Double> avgC = getFrequencyData(pv,InfluxDBTableConstant.AVG,InfluxDBTableConstant.PHASE_TYPE_C,name);
List<Double> cp94A = getFrequencyData(pv,InfluxDBTableConstant.CP95,InfluxDBTableConstant.PHASE_TYPE_A,name);
List<Double> cp94B = getFrequencyData(pv,InfluxDBTableConstant.CP95,InfluxDBTableConstant.PHASE_TYPE_B,name);
List<Double> cp94C = getFrequencyData(pv,InfluxDBTableConstant.CP95,InfluxDBTableConstant.PHASE_TYPE_C,name);
List<Double> minA = getFrequencyData(pv,InfluxDBTableConstant.MIN,InfluxDBTableConstant.PHASE_TYPE_A,name);
List<Double> minB = getFrequencyData(pv,InfluxDBTableConstant.MIN,InfluxDBTableConstant.PHASE_TYPE_B,name);
List<Double> minC = getFrequencyData(pv,InfluxDBTableConstant.MIN,InfluxDBTableConstant.PHASE_TYPE_C,name);
List<Double> maxA = getFrequencyData(pv,InfluxDBTableConstant.MAX,InfluxDBTableConstant.PHASE_TYPE_A,name);
List<Double> maxB = getFrequencyData(pv,InfluxDBTableConstant.MAX,InfluxDBTableConstant.PHASE_TYPE_B,name);
List<Double> maxC = getFrequencyData(pv,InfluxDBTableConstant.MAX,InfluxDBTableConstant.PHASE_TYPE_C,name);
int k = 0,j = 0;
double c = 0;
switch (name){
//谐波电压和电流默认谐波次数2-25
case Param.vTimes:
case Param.iTimes:
k = 2;
j = 25;
break;
case InfluxDBTableConstant.CP95:
switch (valueType){
case InfluxDBTableConstant.PHASE_TYPE_A:
tdv.setCP95PhaseA("1");
break;
case InfluxDBTableConstant.PHASE_TYPE_B:
tdv.setCP95PhaseB("1");
break;
case InfluxDBTableConstant.PHASE_TYPE_C:
tdv.setCP95PhaseC("1");
break;
}
break;
case InfluxDBTableConstant.MIN:
switch (valueType){
case InfluxDBTableConstant.PHASE_TYPE_A:
tdv.setMINPhaseA("1");
break;
case InfluxDBTableConstant.PHASE_TYPE_B:
tdv.setMINPhaseB("1");
break;
case InfluxDBTableConstant.PHASE_TYPE_C:
tdv.setMINPhaseC("1");
break;
}
break;
case InfluxDBTableConstant.MAX:
switch (valueType){
case InfluxDBTableConstant.PHASE_TYPE_A:
tdv.setMAXPhaseA("1");
break;
case InfluxDBTableConstant.PHASE_TYPE_B:
tdv.setMAXPhaseB("1");
break;
case InfluxDBTableConstant.PHASE_TYPE_C:
tdv.setMAXPhaseC("1");
break;
}
//间谐波电压含有率默认谐波次数1-16
case Param.interHarmonic:
k = 1;
j = 16;
c = 0.5;
break;
}
});
thdDataVOS.add(tdv);
for (int i = k; i <= j; i++) {
ThdDataVO tdv = new ThdDataVO();
tdv.setAnotherName(name +(((i-c)+"").replace(".0",""))+"");
try {
tdv.setLimit(limit.get(i-k));
//frequencyPVList次方法提提高容灾,如果真的出现数组越界只有一种情况:有些有功功率查不到对应的某些指标数据
tdv.setAVGPhaseA(frequencyPVList(avgA,i-k));
tdv.setAVGPhaseB(frequencyPVList(avgB,i-k));
tdv.setAVGPhaseC(frequencyPVList(avgC,i-k));
tdv.setCP95PhaseA(frequencyPVList(cp94A,i-k));
tdv.setCP95PhaseB(frequencyPVList(cp94B,i-k));
tdv.setCP95PhaseC(frequencyPVList(cp94C,i-k));
tdv.setMINPhaseA(frequencyPVList(minA,i-k));
tdv.setMINPhaseA(frequencyPVList(minB,i-k));
tdv.setMINPhaseA(frequencyPVList(minC,i-k));
tdv.setMAXPhaseA(frequencyPVList(maxA,i-k));
tdv.setMAXPhaseA(frequencyPVList(maxB,i-k));
tdv.setMAXPhaseA(frequencyPVList(maxC,i-k));
} catch (Exception e) {
e.printStackTrace();
}
//如果所有的相别和统计方式都没有值则可直接忽略该条数据
if(tdv.getAVGPhaseA() != null || tdv.getAVGPhaseB() != null
|| tdv.getAVGPhaseC() != null || tdv.getCP95PhaseA() != null
|| tdv.getCP95PhaseB() != null || tdv.getCP95PhaseC() != null
|| tdv.getMINPhaseA() != null || tdv.getMINPhaseB() != null
|| tdv.getMINPhaseC() != null || tdv.getMAXPhaseA() != null
|| tdv.getMAXPhaseB() != null || tdv.getMAXPhaseC() != null){
thdDataVOS.add(tdv);
}
}
}
return thdDataVOS;
}
@@ -226,6 +322,7 @@ public class PowerStatisticsServiceImpl implements PowerStatisticsService {
public List<ThdDataVO> getTargetByTime(PowerStatisticsParam powerStatisticsParam) {
List<ThdDataVO> result = new ArrayList();
List<EleEpdPqd> eleEpdPqds = new ArrayList<>();
//获取固定指标具体请看Param.DATABSEMAP
if("1".equals(powerStatisticsParam.getStatisticalId())){
com.njcn.device.pq.constant.Param.DATABSEMAP.forEach((key,value) ->{
List<EleEpdPqd> epdPqds = epdFeignClient.findListByShowName(key).getData();
@@ -277,10 +374,12 @@ public class PowerStatisticsServiceImpl implements PowerStatisticsService {
eleEpdPqds.forEach(epdPqd->{
List<CommonQueryParam> commonQueryParams = new ArrayList<>();
commonQueryParams.clear();
//带有谐波次数的指标
if(epdPqd.getHarmEnd()!=null && epdPqd.getHarmStart()!=null){
for (int i = epdPqd.getHarmStart().intValue(); i <= epdPqd.getHarmEnd().intValue(); i++) {
ThdDataVO thdDataVO = new ThdDataVO();
thdDataVO.setUnit(epdPqd.getUnit());
thdDataVO.setTime(powerStatisticsParam.getSearchBeginTime());
String index = i+"";
if(epdPqd.getShowName().equals("间谐波电压含有率")){
thdDataVO.setAnotherName(Integer.parseInt(index) - 0.5 + "");
@@ -291,9 +390,11 @@ public class PowerStatisticsServiceImpl implements PowerStatisticsService {
result.add(thdDataVO);
}
}else{
//无谐波次数的指标
ThdDataVO thdDataVO = new ThdDataVO();
thdDataVO.setAnotherName(epdPqd.getShowName());
thdDataVO.setUnit(epdPqd.getUnit());
thdDataVO.setTime(powerStatisticsParam.getSearchBeginTime());
getThdDataVO(null,thdDataVO,epdPqd,powerStatisticsParam);
result.add(thdDataVO);
}
@@ -302,14 +403,15 @@ public class PowerStatisticsServiceImpl implements PowerStatisticsService {
}
//将各个指标的所有的相别统计方式以表格的维度进行组装数据
private ThdDataVO getThdDataVO(String columnName,ThdDataVO thdDataVO,EleEpdPqd epdPqd,PowerStatisticsParam powerStatisticsParam){
private ThdDataVO getThdDataVO(String columnName, ThdDataVO thdDataVO, EleEpdPqd epdPqd, PowerStatisticsParam powerStatisticsParam){
List<CommonQueryParam> commonQueryParams = new ArrayList<>();
CommonQueryParam commonQueryParam = new CommonQueryParam();
commonQueryParam.setLineId(powerStatisticsParam.getLineId());
commonQueryParam.setTableName(epdPqd.getClassId());
commonQueryParam.setColumnName(columnName == null ? epdPqd.getOtherName():columnName);
commonQueryParam.setStartTime(powerStatisticsParam.getSearchBeginTime()+Param.START_TIME);
commonQueryParam.setEndTime(powerStatisticsParam.getSearchEndTime()+ Param.END_TIME);
commonQueryParam.setStartTime(powerStatisticsParam.getSearchBeginTime());
commonQueryParam.setEndTime(powerStatisticsParam.getSearchEndTime());
//唯一不同的条件时统计方式和相别,所以这边直接把所有的情况都考虑进去
commonQueryParam.setDataType(METHODS.get(0));
commonQueryParam.setPhasic(PHASE.get(0));
commonQueryParams.add(commonQueryParam);
@@ -499,10 +601,80 @@ public class PowerStatisticsServiceImpl implements PowerStatisticsService {
@Override
public void exportExcelListTemplate(PowerStatisticsParam powerStatisticsParam, HttpServletResponse response) {
ExportParams exportParams = new ExportParams(powerStatisticsParam.getSearchValue(), "指标越限列表数据");
List<PowerStatisticsTargetVO> powerStatisticsTargetVOS = getTargetLimitById(powerStatisticsParam);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, PowerStatisticsTargetVO.class, powerStatisticsTargetVOS);
PoiUtil.exportFileByWorkbook(workbook, powerStatisticsParam.getSearchValue()+".xlsx", response);
//获取各个区间的详细数据(就是调用getTargetByTime方法在进行某些指标的名称的处理)
List<ThdDataVOExcel> time0 = getExcelListRecord(powerStatisticsParam.getTime0(),powerStatisticsParam.getLineId());
List<ThdDataVOExcel> time1 = getExcelListRecord(powerStatisticsParam.getTime1(),powerStatisticsParam.getLineId());
List<ThdDataVOExcel> time2 = getExcelListRecord(powerStatisticsParam.getTime2(),powerStatisticsParam.getLineId());
List<ThdDataVOExcel> time3 = getExcelListRecord(powerStatisticsParam.getTime3(),powerStatisticsParam.getLineId());
List<ThdDataVOExcel> time4 = getExcelListRecord(powerStatisticsParam.getTime4(),powerStatisticsParam.getLineId());
List<ThdDataVOExcel> time5 = getExcelListRecord(powerStatisticsParam.getTime5(),powerStatisticsParam.getLineId());
List<ThdDataVOExcel> time6 = getExcelListRecord(powerStatisticsParam.getTime6(),powerStatisticsParam.getLineId());
List<ThdDataVOExcel> time7 = getExcelListRecord(powerStatisticsParam.getTime7(),powerStatisticsParam.getLineId());
List<ThdDataVOExcel> time8 = getExcelListRecord(powerStatisticsParam.getTime8(),powerStatisticsParam.getLineId());
List<ThdDataVOExcel> time9 = getExcelListRecord(powerStatisticsParam.getTime9(),powerStatisticsParam.getLineId());
try {
//10个区间10个sheet10组数据
ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), ThdDataVOExcel.class).build();
WriteSheet sheet0 = EasyExcel.writerSheet(0, times.get(0) ).head(ThdDataVOExcel.class).build();
excelWriter.write(time0, sheet0);
WriteSheet sheet1 = EasyExcel.writerSheet(1, times.get(1) ).head(ThdDataVOExcel.class).build();
excelWriter.write(time1, sheet1);
WriteSheet sheet2 = EasyExcel.writerSheet(2, times.get(2) ).head(ThdDataVOExcel.class).build();
excelWriter.write(time2, sheet2);
WriteSheet sheet3 = EasyExcel.writerSheet(3, times.get(3) ).head(ThdDataVOExcel.class).build();
excelWriter.write(time3, sheet3);
WriteSheet sheet4 = EasyExcel.writerSheet(4, times.get(4) ).head(ThdDataVOExcel.class).build();
excelWriter.write(time4, sheet4);
WriteSheet sheet5 = EasyExcel.writerSheet(5, times.get(5) ).head(ThdDataVOExcel.class).build();
excelWriter.write(time5, sheet5);
WriteSheet sheet6 = EasyExcel.writerSheet(6, times.get(6) ).head(ThdDataVOExcel.class).build();
excelWriter.write(time6, sheet6);
WriteSheet sheet7 = EasyExcel.writerSheet(7, times.get(7) ).head(ThdDataVOExcel.class).build();
excelWriter.write(time7, sheet7);
WriteSheet sheet8 = EasyExcel.writerSheet(8, times.get(8) ).head(ThdDataVOExcel.class).build();
excelWriter.write(time8, sheet8);
WriteSheet sheet9 = EasyExcel.writerSheet(9, times.get(9) ).head(ThdDataVOExcel.class).build();
excelWriter.write(time9, sheet9);
excelWriter.finish();
} catch (IOException e) {
e.printStackTrace();
}
}
private List<ThdDataVOExcel> getExcelListRecord(List<String> times, String lineId){
List<ThdDataVO> thdDataVOS = new ArrayList<>();
List<ThdDataVOExcel> thdDataVOExcels = new ArrayList<>();
PowerStatisticsParam powerStatisticsParam = new PowerStatisticsParam();
powerStatisticsParam.setLineId(lineId);
for(String time : times){
powerStatisticsParam.setSearchBeginTime(time);
powerStatisticsParam.setSearchEndTime(time);
for (int i = 1; i <= 4; i++) {
powerStatisticsParam.setStatisticalId(i+"");
List<ThdDataVO> thdDataVOList = getTargetByTime(powerStatisticsParam);
if(i != 1){
for(ThdDataVO thdDataVO : thdDataVOList){
switch (i){
case 2:
thdDataVO.setAnotherName("谐波电压"+thdDataVO.getAnotherName());
break;
case 3:
thdDataVO.setAnotherName("谐波电流"+thdDataVO.getAnotherName());
break;
case 4:
thdDataVO.setAnotherName("间谐波电压"+thdDataVO.getAnotherName());
break;
}
}
}
thdDataVOS.addAll(thdDataVOList);
}
}
for(ThdDataVO thdDataVO : thdDataVOS){
ThdDataVOExcel thdDataVOExcel = new ThdDataVOExcel();
BeanUtils.copyProperties(thdDataVO, thdDataVOExcel);
thdDataVOExcels.add(thdDataVOExcel);
}
return thdDataVOExcels;
}
}