有功功率趋势指标列表详细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

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