Browse Source

#运行月报告导出chart

zhongwei
yang_shj 10 months ago
parent
commit
dfd9271510
  1. 22
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/AttributeVo.java
  2. 26
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/CurveAttrValueVo.java
  3. 22
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/CurveYArrayVo.java
  4. 2
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/EchartVo.java
  5. 3
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/RunDataShowVo.java
  6. 12
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/impl/ReportServiceImpl.java
  7. 364
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java

22
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/AttributeVo.java

@ -0,0 +1,22 @@
package com.hnac.hzims.operational.report.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author ysj
*/
@Data
@ApiModel("曲线对象")
public class AttributeVo {
@ApiModelProperty("设备编码")
private String deviceCode;
@ApiModelProperty("属性")
private String signage;
@ApiModelProperty("属性名称")
private String signageName;
}

26
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/CurveAttrValueVo.java

@ -0,0 +1,26 @@
package com.hnac.hzims.operational.report.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
import lombok.Data;
/**
* @author ysj
*/
@Data
@ApiModel("运行数据对象")
public class CurveAttrValueVo {
@ApiModelProperty("属性")
private String attribute;
@ApiModelProperty("属性名称")
private String attributeName;
@ApiModelProperty("时间")
private Integer time;
@ApiModelProperty("值")
private Double value;
}

22
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/CurveYArrayVo.java

@ -0,0 +1,22 @@
package com.hnac.hzims.operational.report.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author ysj
*/
@Data
@ApiModel("运行数据对象")
public class CurveYArrayVo {
@ApiModelProperty("属性")
private String attribute;
@ApiModelProperty("属性名称")
private String attributeName;
@ApiModelProperty("值:数组")
private Number[] values;
}

2
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/EchartVo.java

@ -14,7 +14,7 @@ import java.util.List;
public class EchartVo {
@ApiModelProperty("时间:day")
private String time;
private Integer time;
@ApiModelProperty("数据值对象")
List<EchartValueVo> values;

3
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/RunDataShowVo.java

@ -31,7 +31,4 @@ public class RunDataShowVo extends RunMonthEntity {
@ApiModelProperty("年计划完成率")
private Double yearRate;
@ApiModelProperty("曲线转换对象")
private List<CurveEchartVo> curveEcharts;
}

12
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/impl/ReportServiceImpl.java

@ -980,11 +980,7 @@ public class ReportServiceImpl implements ReportService {
item.setSignage(data.getSignage());
Date date = DateUtil.parse(item.getTs(), "yyyy-MM-dd HH:mm:ss.s");
day.setTime(date);
if(day.get(Calendar.DAY_OF_MONTH) <= 9){
item.setTs("0" + day.get(Calendar.DAY_OF_MONTH));
}else{
item.setTs(day.get(Calendar.DAY_OF_MONTH) + "");
}
item.setTs(String.valueOf(day.get(Calendar.DAY_OF_MONTH)));
}).collect(Collectors.toList()));
});
if(CollectionUtil.isEmpty(analyseDatas)){
@ -993,7 +989,7 @@ public class ReportServiceImpl implements ReportService {
Map<String,List<AnalyseDataTaosVO>> map = analyseDatas.stream().collect(Collectors.groupingBy(AnalyseDataTaosVO::getTs));
return map.entrySet().stream().map(entry->{
EchartVo echart = new EchartVo();
echart.setTime(entry.getKey());
echart.setTime(Integer.valueOf(entry.getKey()));
echart.setValues(entry.getValue().stream().map(value->{
EchartValueVo echartValue = new EchartValueVo();
echartValue.setAttribute(value.getSignage());
@ -1061,12 +1057,12 @@ public class ReportServiceImpl implements ReportService {
attributes.add(A_tem);
AttributeVo B_tem = new AttributeVo();
B_tem.setSignage(HomePageConstant.A_PHASE_IRON_CORE_TEMP);
B_tem.setSignage(HomePageConstant.B_PHASE_IRON_CORE_TEMP);
B_tem.setSignageName("B相铁芯温度1");
attributes.add(B_tem);
AttributeVo C_tem = new AttributeVo();
C_tem.setSignage(HomePageConstant.A_PHASE_IRON_CORE_TEMP);
C_tem.setSignage(HomePageConstant.C_PHASE_IRON_CORE_TEMP);
C_tem.setSignageName("C相铁芯温度1");
attributes.add(C_tem);
break;

364
hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java

@ -9,18 +9,18 @@ import com.hnac.hzims.operational.report.service.RunMonthService;
import com.hnac.hzims.operational.report.vo.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.charts.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@ -32,7 +32,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
@ -103,7 +103,7 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
// 创建Excel文件
// 表头、sheet页、文件名
String headerName = data.getStationName() + "运行月报(" + mon + ")";
HSSFWorkbook hssWB = this.drawBook(headerName,data);
Workbook hssWB = this.drawBook(headerName,data);
// 设置头信息
response.setCharacterEncoding("UTF-8");
response.setContentType("application/vnd.ms-excel");
@ -127,10 +127,10 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* 手绘运行数据表格
* @return
*/
private HSSFWorkbook drawBook(String headerName,RunMonthEntity entity) {
HSSFWorkbook hssWB = new HSSFWorkbook();
private Workbook drawBook(String headerName,RunMonthEntity entity) {
Workbook hssWB = new XSSFWorkbook();
// 添加sheet页
HSSFSheet sheet = hssWB.createSheet(headerName);
Sheet sheet = hssWB.createSheet(headerName);
// 绘制表格行标
int row = 1;
// 行高
@ -139,6 +139,7 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
sheet.setDefaultColumnWidth(20);
// 首行表头
this.firstHeader(hssWB, sheet , headerName);
// 一、表头格式设置
this.titleHeader(hssWB, sheet,"1、运行数据总汇",row);
row += 1;
@ -146,8 +147,8 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
this.runDataHeader(hssWB,sheet,row);
row += 1;
// 运行数据填充
List<RunDataVo> runData = JSONObject.parseObject(entity.getRunData(),new TypeReference<List<RunDataVo>>(){});
row = this.runDataFill(hssWB,sheet,row,runData);
row = this.runDataFill(hssWB,sheet,row,entity.getRunData());
// 二、表头格式设置
this.titleHeader(hssWB, sheet,"2、告警报表",row);
row += 1;
@ -155,36 +156,217 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
this.alarmHeader(hssWB,sheet,row);
row += 1;
// 告警数据填充
List<RunAlarmVo> runAlarm = JSONObject.parseObject(entity.getAlarmData(),new TypeReference<List<RunAlarmVo>>(){});
row = this.alarmDataFill(hssWB,sheet,row,runAlarm);
row = this.alarmDataFill(hssWB,sheet,row,entity.getAlarmData());
// 三、表头格式设置
this.titleHeader(hssWB, sheet,"3、机组负荷、温度曲线",row);
row += 1;
// 绘制机组曲线
row = this.drawCurves(hssWB,sheet,row,entity.getCurveData());
// 四、表头格式设置
this.titleHeader(hssWB, sheet,"4、运行数据分析",row);
row += 1;
// 运行数据分析填充
row = this.analysisDataFill(hssWB,sheet,row,entity.getAnalysisData());
// 五、表头格式设置
this.titleHeader(hssWB, sheet,"5、运行建议及其他",row);
row += 1;
// 运行建议及其他填充
this.runProposeFill(hssWB,sheet,row,entity.getRunPropose());
return hssWB;
}
/**
* 绘制机组曲线
* @param hssWB
* @param rowNumber
* @param data
* @return
*/
private int drawCurves(Workbook hssWB,Sheet sheet, int rowNumber, String data) {
if(StringUtil.isEmpty(data)){
// 绘制空表格
this.emptyRow(hssWB,sheet,rowNumber);
CellRangeAddress region = new CellRangeAddress(rowNumber, rowNumber, (short) 0, (short) 7);
sheet.addMergedRegion(region);
return rowNumber + 1;
}
List<CurveEchartVo> curves = JSONObject.parseObject(data,new TypeReference<List<CurveEchartVo>>(){});
if(CollectionUtil.isEmpty(curves)){
// 绘制空表格
this.emptyRow(hssWB,sheet,rowNumber);
CellRangeAddress region = new CellRangeAddress(rowNumber, rowNumber, (short) 0, (short) 7);
sheet.addMergedRegion(region);
return rowNumber + 1;
}
// 遍历机组
for(CurveEchartVo device : curves) {
// 负荷曲线
rowNumber = this.drawCurve(hssWB,sheet,rowNumber,device.getLoadCurve(),device.getDeviceName() + "_负荷曲线");
// 轴承温度
rowNumber = this.drawCurve(hssWB,sheet,rowNumber,device.getBearingTempCurve(),device.getDeviceName() + "_轴承温度曲线");
// 定子温度曲线
rowNumber = this.drawCurve(hssWB,sheet,rowNumber,device.getStatorTempCurve(),device.getDeviceName() + "_定子温度曲线");
}
return rowNumber;
}
/**
* 绘制曲线
* @param loadCurve
* @param rowNumber
*/
private int drawCurve(Workbook hssWB,Sheet sheet,int rowNumber,List<EchartVo> loadCurve,String title) {
// 标题
Row row_1 = sheet.createRow(rowNumber);
this.setTitileStyle(hssWB, row_1, 7, false, false, HorizontalAlignment.LEFT);
row_1.getCell(0).setCellValue(title);
CellRangeAddress region1 = new CellRangeAddress(rowNumber, rowNumber, (short) 0, (short) 7);
sheet.addMergedRegion(region1);
rowNumber += 1;
if(CollectionUtil.isEmpty(loadCurve)){
// 绘制空表格
this.emptyRow(hssWB,sheet,rowNumber);
CellRangeAddress region2 = new CellRangeAddress(rowNumber, rowNumber, (short) 0, (short) 7);
sheet.addMergedRegion(region2);
return rowNumber + 1;
}
// 合并chart范围
CellRangeAddress region2 = new CellRangeAddress(rowNumber, rowNumber + 7, (short) 0, (short) 7);
sheet.addMergedRegion(region2);
// 画布
Drawing drawing = sheet.createDrawingPatriarch();
// 固定位置 : 前4个参数偏移位置, col1 : 起始列数 row1 : 起始行数 col2 : 结束行数 row2 : 结束行数
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, rowNumber, 8, rowNumber + 7);
// Chart图表
Chart chart = drawing.createChart(anchor);
// 折线图
ChartLegend chartLegend = chart.getOrCreateLegend();
// 停靠位置 : 右上
chartLegend.setPosition(LegendPosition.TOP_RIGHT);
// 折线图数据存储对象
LineChartData lineChartData = chart.getChartDataFactory().createLineChartData();
// X 轴位置 : 下
ChartAxis xAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
// Y 轴位置 : 左
ValueAxis yAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
// 轴交叉点
yAxis.setCrosses(AxisCrosses.AUTO_ZERO);
// X 轴数据散点
ChartDataSource<Number> xds = DataSources.fromArray(loadCurve.stream().map(EchartVo::getTime).toArray(Number[]::new));
// 曲线条目集合
List<CurveYArrayVo> curveYArray = this.curveToArray(loadCurve);
// Y 轴曲线 : 平滑散点值
for(CurveYArrayVo array : curveYArray){
ChartDataSource<Number> yds = DataSources.fromArray(array.getValues());
LineChartSeries series = lineChartData.addSeries(xds,yds);
// 曲线名称
series.setTitle(array.getAttributeName());
}
chart.plot(lineChartData, xAxis, yAxis);
return rowNumber + 8;
}
/**
* 曲线转数组对象
* @param curves
* @return
*/
private List<CurveYArrayVo> curveToArray(List<EchartVo> curves) {
List<CurveAttrValueVo> attrValues = new ArrayList<>();
curves.forEach(curve->{
attrValues.addAll(curve.getValues().stream().map(value->{
CurveAttrValueVo attrValue = new CurveAttrValueVo();
attrValue.setAttribute(value.getAttribute());
attrValue.setAttributeName(value.getAttributeName());
attrValue.setTime(curve.getTime());
attrValue.setValue(value.getValue());
return attrValue;
}).collect(Collectors.toList()));
});
return attrValues.stream().collect(Collectors.groupingBy(CurveAttrValueVo::getAttribute)).entrySet().stream().map(entry->{
CurveYArrayVo yArray = new CurveYArrayVo();
yArray.setAttribute(entry.getKey());
yArray.setAttributeName(entry.getValue().get(0).getAttributeName());
yArray.setValues(entry.getValue().stream().sorted(Comparator.comparing(CurveAttrValueVo::getTime)).map(CurveAttrValueVo::getValue).toArray(Double[]::new));
return yArray;
}).collect(Collectors.toList());
}
/**
* 运行数据分析填充
* @param hssWB
* @param sheet
* @param rowNumber
* @param analysisData
*/
private int analysisDataFill(Workbook hssWB, Sheet sheet, int rowNumber, String analysisData) {
if(StringUtil.isEmpty(analysisData)){
// 绘制空表格
this.emptyRow(hssWB,sheet,rowNumber);
CellRangeAddress region2 = new CellRangeAddress(rowNumber, rowNumber, (short) 0, (short) 7);
sheet.addMergedRegion(region2);
return rowNumber + 1;
}
for(int i = 0; i < 4;i++){
// 运行数据分析赋值
Row row = sheet.createRow(rowNumber + i);
this.setTitileStyle(hssWB, row, 7, false, false, HorizontalAlignment.LEFT);
if(i == 0){
row.getCell(0).setCellValue(analysisData);
}
}
CellRangeAddress region1 = new CellRangeAddress(rowNumber, rowNumber + 3, (short) 0, (short) 7);
sheet.addMergedRegion(region1);
return rowNumber + 4;
}
/**
* 运行建议及其他填充
* @param hssWB
* @param sheet
* @param rowNumber
* @param runPropose
*/
private void runProposeFill(Workbook hssWB, Sheet sheet, int rowNumber, String runPropose) {
if(StringUtil.isEmpty(runPropose)){
// 绘制空表格
this.emptyRow(hssWB,sheet,rowNumber);
CellRangeAddress region2 = new CellRangeAddress(rowNumber, rowNumber, (short) 0, (short) 7);
sheet.addMergedRegion(region2);
}
for(int i = 0; i < 4;i++){
// 运行数据分析赋值
Row row = sheet.createRow(rowNumber + i);
this.setTitileStyle(hssWB, row, 7, false, false, HorizontalAlignment.LEFT);
if(i == 0){
row.getCell(0).setCellValue(runPropose);
}
}
CellRangeAddress region1 = new CellRangeAddress(rowNumber, rowNumber + 3, (short) 0, (short) 7);
sheet.addMergedRegion(region1);
}
/**
* 设置头部
* @param hssWB
* @param sheet
*/
private void firstHeader(HSSFWorkbook hssWB, HSSFSheet sheet,String headerName) {
private void firstHeader(Workbook hssWB, Sheet sheet,String headerName) {
// 第一行
HSSFRow fisrtRow = sheet.createRow(0);
Row fisrtRow = sheet.createRow(0);
this.setTitileStyle(hssWB, fisrtRow, 7, true,true,HorizontalAlignment.CENTER);
// 第一个单元格
HSSFCell headCell = fisrtRow.getCell(0);
Cell headCell = fisrtRow.getCell(0);
headCell.setCellValue(headerName);
// 首行合并情况
CellRangeAddress region1 = new CellRangeAddress(0, 0, (short) 0, (short) 7);
@ -196,11 +378,11 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* @param hssWB
* @param sheet
*/
private void titleHeader(HSSFWorkbook hssWB, HSSFSheet sheet,String title,int rowNumber) {
private void titleHeader(Workbook hssWB, Sheet sheet,String title,int rowNumber) {
// 创建行
HSSFRow row_1 = sheet.createRow(rowNumber);
Row row_1 = sheet.createRow(rowNumber);
this.setTitileStyle(hssWB, row_1, 7, false,true,HorizontalAlignment.LEFT);
HSSFCell work_header_row_cell_1 = row_1.getCell(0);
Cell work_header_row_cell_1 = row_1.getCell(0);
work_header_row_cell_1.setCellValue(title);
// 行合并情况
CellRangeAddress region1 = new CellRangeAddress(rowNumber, rowNumber, (short) 0, (short) 7);
@ -212,26 +394,26 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* @param hssWB
* @param sheet
*/
private void runDataHeader(HSSFWorkbook hssWB, HSSFSheet sheet,int rowNumber) {
private void runDataHeader(Workbook hssWB, Sheet sheet,int rowNumber) {
// 创建行
HSSFRow row = sheet.createRow(rowNumber);
Row row = sheet.createRow(rowNumber);
this.setTitileStyle(hssWB, row, 7, false,true,HorizontalAlignment.CENTER);
// 第一行
HSSFCell row_cell_1 = row.getCell(0);
Cell row_cell_1 = row.getCell(0);
row_cell_1.setCellValue("组名");
HSSFCell row_cell_2 = row.getCell(1);
Cell row_cell_2 = row.getCell(1);
row_cell_2.setCellValue("本月累计运行时长");
HSSFCell row_cell_3 = row.getCell(2);
Cell row_cell_3 = row.getCell(2);
row_cell_3.setCellValue("机组发电量");
HSSFCell row_cell_4 = row.getCell(3);
Cell row_cell_4 = row.getCell(3);
row_cell_4.setCellValue("计划发电量");
HSSFCell row_cell_5 = row.getCell(4);
Cell row_cell_5 = row.getCell(4);
row_cell_5.setCellValue("实发电量");
HSSFCell row_cell_6 = row.getCell(5);
Cell row_cell_6 = row.getCell(5);
row_cell_6.setCellValue("完成率");
HSSFCell row_cell_7 = row.getCell(6);
Cell row_cell_7 = row.getCell(6);
row_cell_7.setCellValue("年累计发电量");
HSSFCell row_cell_8 = row.getCell(7);
Cell row_cell_8 = row.getCell(7);
row_cell_8.setCellValue("年计划完成率");
}
@ -240,37 +422,49 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* @param hssWB
* @param sheet
* @param rowNumber
* @param data
* @return
*/
private int runDataFill(HSSFWorkbook hssWB, HSSFSheet sheet, int rowNumber,List<RunDataVo> runData) {
private int runDataFill(Workbook hssWB, Sheet sheet, int rowNumber,String data) {
if(StringUtil.isEmpty(data)){
// 绘制空表格
this.emptyRow(hssWB,sheet,rowNumber);
CellRangeAddress region = new CellRangeAddress(rowNumber, rowNumber, (short) 0, (short) 7);
sheet.addMergedRegion(region);
return rowNumber + 1;
}
List<RunDataVo> runData = JSONObject.parseObject(data,new TypeReference<List<RunDataVo>>(){});
if(CollectionUtil.isEmpty(runData)){
// 绘制空表格
this.emptyRow(hssWB,sheet,rowNumber);
CellRangeAddress region = new CellRangeAddress(rowNumber, rowNumber, (short) 0, (short) 7);
sheet.addMergedRegion(region);
return rowNumber + 1;
}
int row = rowNumber;
int endRow = rowNumber + runData.size();
for (;row < endRow; row ++){
// 创建行
HSSFRow frow = sheet.createRow(row);
Row frow = sheet.createRow(row);
this.setTitileStyle(hssWB, frow, 7, false,false,HorizontalAlignment.CENTER);
// 组名
HSSFCell frow_cell_1 = frow.getCell(0);
Cell frow_cell_1 = frow.getCell(0);
frow_cell_1.setCellValue(runData.get(row - rowNumber).getDeviceName());
// 本月累计运行时长
HSSFCell frow_cell_2 = frow.getCell(1);
Cell frow_cell_2 = frow.getCell(1);
frow_cell_2.setCellValue(runData.get(row - rowNumber).getRunHours() + "小时");
// 机组发电量
HSSFCell frow_cell_3 = frow.getCell(2);
Cell frow_cell_3 = frow.getCell(2);
frow_cell_3.setCellValue(runData.get(row - rowNumber).getGenerate());
if(row == rowNumber){
// 计划发电量
HSSFCell frow_cell_4 = frow.getCell(3);
Cell frow_cell_4 = frow.getCell(3);
frow_cell_4.setCellValue(runData.stream().mapToDouble(RunDataVo::getPlan).sum());
// 实发电量
HSSFCell frow_cell_5 = frow.getCell(4);
Cell frow_cell_5 = frow.getCell(4);
frow_cell_5.setCellValue(runData.stream().mapToDouble(RunDataVo::getGenerate).sum());
// 完成率
HSSFCell frow_cell_6 = frow.getCell(5);
Cell frow_cell_6 = frow.getCell(5);
double monSumGenerate = runData.stream().mapToDouble(RunDataVo::getGenerate).sum();
double monSumPlan = runData.stream().mapToDouble(RunDataVo::getPlan).sum();
if(Math.abs(monSumGenerate) > 0 && Math.abs(monSumPlan) > 0){
@ -279,10 +473,10 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
frow_cell_6.setCellValue("0%");
}
// 年累计发电量
HSSFCell frow_cell_7 = frow.getCell(6);
Cell frow_cell_7 = frow.getCell(6);
frow_cell_7.setCellValue(runData.stream().mapToDouble(RunDataVo::getGenerateYear).sum());
// 年计划完成率
HSSFCell frow_cell_8 = frow.getCell(7);
Cell frow_cell_8 = frow.getCell(7);
double yearSumGenerate = runData.stream().mapToDouble(RunDataVo::getGenerateYear).sum();
double yearSumPlan = runData.stream().mapToDouble(RunDataVo::getPlanYear).sum();
if(Math.abs(yearSumGenerate) > 0 && Math.abs(yearSumPlan) > 0){
@ -312,26 +506,26 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* @param sheet
* @param rowNumber
*/
private void emptyRow(HSSFWorkbook hssWB, HSSFSheet sheet, int rowNumber) {
private void emptyRow(Workbook hssWB, Sheet sheet, int rowNumber) {
// 创建行
HSSFRow row = sheet.createRow(rowNumber);
this.setTitileStyle(hssWB, row, 8, false,false,HorizontalAlignment.CENTER);
Row row = sheet.createRow(rowNumber);
this.setTitileStyle(hssWB, row, 7, false,false,HorizontalAlignment.CENTER);
// 第一行
HSSFCell row_cell_1 = row.getCell(0);
Cell row_cell_1 = row.getCell(0);
row_cell_1.setCellValue("");
HSSFCell row_cell_2 = row.getCell(1);
Cell row_cell_2 = row.getCell(1);
row_cell_2.setCellValue("");
HSSFCell row_cell_3 = row.getCell(2);
Cell row_cell_3 = row.getCell(2);
row_cell_3.setCellValue("");
HSSFCell row_cell_4 = row.getCell(3);
Cell row_cell_4 = row.getCell(3);
row_cell_4.setCellValue("");
HSSFCell row_cell_5 = row.getCell(4);
Cell row_cell_5 = row.getCell(4);
row_cell_5.setCellValue("");
HSSFCell row_cell_6 = row.getCell(5);
Cell row_cell_6 = row.getCell(5);
row_cell_6.setCellValue("");
HSSFCell row_cell_7 = row.getCell(6);
Cell row_cell_7 = row.getCell(6);
row_cell_7.setCellValue("");
HSSFCell row_cell_8 = row.getCell(7);
Cell row_cell_8 = row.getCell(7);
row_cell_8.setCellValue("");
}
@ -341,26 +535,26 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* @param hssWB
* @param sheet
*/
private void alarmHeader(HSSFWorkbook hssWB, HSSFSheet sheet,int rowNumber) {
private void alarmHeader(Workbook hssWB, Sheet sheet,int rowNumber) {
// 创建行
HSSFRow row = sheet.createRow(rowNumber);
Row row = sheet.createRow(rowNumber);
this.setTitileStyle(hssWB, row, 7, false,true,HorizontalAlignment.CENTER);
// 第一行
HSSFCell row_cell_1 = row.getCell(0);
Cell row_cell_1 = row.getCell(0);
row_cell_1.setCellValue("组名");
HSSFCell row_cell_2 = row.getCell(1);
Cell row_cell_2 = row.getCell(1);
row_cell_2.setCellValue("首次时间");
HSSFCell row_cell_3 = row.getCell(2);
Cell row_cell_3 = row.getCell(2);
row_cell_3.setCellValue("事件内容");
HSSFCell row_cell_4 = row.getCell(3);
Cell row_cell_4 = row.getCell(3);
row_cell_4.setCellValue("告警类型");
HSSFCell row_cell_5 = row.getCell(4);
Cell row_cell_5 = row.getCell(4);
row_cell_5.setCellValue("次数");
HSSFCell row_cell_6 = row.getCell(5);
Cell row_cell_6 = row.getCell(5);
row_cell_6.setCellValue("原因初步分析");
HSSFCell row_cell_7 = row.getCell(6);
Cell row_cell_7 = row.getCell(6);
row_cell_7.setCellValue("处置");
HSSFCell row_cell_8 = row.getCell(7);
Cell row_cell_8 = row.getCell(7);
row_cell_8.setCellValue("备注");
}
@ -369,44 +563,54 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* @param hssWB
* @param sheet
* @param rowNumber
* @param runAlarm
* @param data
* @return
*/
private int alarmDataFill(HSSFWorkbook hssWB, HSSFSheet sheet, int rowNumber, List<RunAlarmVo> runAlarm) {
private int alarmDataFill(Workbook hssWB, Sheet sheet, int rowNumber, String data) {
if(StringUtil.isEmpty(data)){
// 绘制空表格
this.emptyRow(hssWB,sheet,rowNumber);
CellRangeAddress region = new CellRangeAddress(rowNumber, rowNumber, (short) 0, (short) 7);
sheet.addMergedRegion(region);
return rowNumber + 1;
}
List<RunAlarmVo> runAlarm = JSONObject.parseObject(data,new TypeReference<List<RunAlarmVo>>(){});
if(CollectionUtil.isEmpty(runAlarm)){
// 绘制空表格
this.emptyRow(hssWB,sheet,rowNumber);
CellRangeAddress region = new CellRangeAddress(rowNumber, rowNumber, (short) 0, (short) 7);
sheet.addMergedRegion(region);
return rowNumber + 1;
}
int row = rowNumber;
int endRow = rowNumber + runAlarm.size();
for (;row < endRow ; row ++){
// 创建行
HSSFRow frow = sheet.createRow(row);
Row frow = sheet.createRow(row);
this.setTitileStyle(hssWB, frow, 7, false,false,HorizontalAlignment.CENTER);
// 组名
HSSFCell frow_cell_1 = frow.getCell(0);
Cell frow_cell_1 = frow.getCell(0);
frow_cell_1.setCellValue(runAlarm.get(row - rowNumber).getDeviceName());
// 首次时间
HSSFCell frow_cell_2 = frow.getCell(1);
Cell frow_cell_2 = frow.getCell(1);
frow_cell_2.setCellValue(runAlarm.get(row - rowNumber).getAlarmTime());
// 事件内容
HSSFCell frow_cell_3 = frow.getCell(2);
Cell frow_cell_3 = frow.getCell(2);
frow_cell_3.setCellValue(runAlarm.get(row - rowNumber).getContent());
// 告警类型
HSSFCell frow_cell_4 = frow.getCell(3);
Cell frow_cell_4 = frow.getCell(3);
frow_cell_4.setCellValue(runAlarm.get(row - rowNumber).getTypeName());
// 次数
HSSFCell frow_cell_5 = frow.getCell(4);
Cell frow_cell_5 = frow.getCell(4);
frow_cell_5.setCellValue(runAlarm.get(row - rowNumber).getCount());
// 原因初步分析
HSSFCell frow_cell_6 = frow.getCell(5);
Cell frow_cell_6 = frow.getCell(5);
frow_cell_6.setCellValue(runAlarm.get(row - rowNumber).getReason());
// 处置
HSSFCell frow_cell_7 = frow.getCell(6);
Cell frow_cell_7 = frow.getCell(6);
frow_cell_7.setCellValue(runAlarm.get(row - rowNumber).getDispose());
// 备注
HSSFCell frow_cell_8 = frow.getCell(7);
Cell frow_cell_8 = frow.getCell(7);
frow_cell_8.setCellValue(runAlarm.get(row - rowNumber).getMemo());
}
return endRow;
@ -420,10 +624,10 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* @param row
* @param len
*/
private void setTitileStyle(HSSFWorkbook hssWB, HSSFRow row, int len, boolean isHead,boolean isBold,HorizontalAlignment alignment) {
HSSFCellStyle cellStyle = getHeadStyle(hssWB, alignment,isHead,isBold);
private void setTitileStyle(Workbook hssWB, Row row, int len, boolean isHead,boolean isBold,HorizontalAlignment alignment) {
CellStyle cellStyle = getHeadStyle(hssWB, alignment,isHead,isBold);
for (int i = 0; i <= len; i++) {
HSSFCell hssfcell = row.createCell(i);
Cell hssfcell = row.createCell(i);
hssfcell.setCellStyle(cellStyle);
}
}
@ -434,8 +638,8 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* @param hssWB
* @return
*/
private HSSFCellStyle getHeadStyle(HSSFWorkbook hssWB,HorizontalAlignment alignment ,boolean isHead,boolean isBold) {
HSSFCellStyle headStyle = hssWB.createCellStyle();
private CellStyle getHeadStyle(Workbook hssWB,HorizontalAlignment alignment ,boolean isHead,boolean isBold) {
CellStyle headStyle = hssWB.createCellStyle();
//边框
headStyle.setBorderLeft(BorderStyle.THIN);
headStyle.setBorderRight(BorderStyle.THIN);
@ -445,7 +649,7 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
//格式: 居中、居右、居左.....
headStyle.setAlignment(alignment);
headStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直居中
HSSFFont font = hssWB.createFont();
Font font = hssWB.createFont();
//字体:
font.setFontName("黑体");
if(isBold){

Loading…
Cancel
Save