|
@@ -1,5 +1,8 @@
|
|
package com.ruoyi.project.production.service.impl;
|
|
package com.ruoyi.project.production.service.impl;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
@@ -7,13 +10,23 @@ import java.math.RoundingMode;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
|
|
+import com.ruoyi.common.exception.CustomException;
|
|
|
|
+import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
|
+import com.ruoyi.framework.config.RuoYiConfig;
|
|
|
|
+import com.ruoyi.framework.web.domain.AjaxResult;
|
|
import com.ruoyi.project.production.controller.vo.MonthlyAnalysisDataVO;
|
|
import com.ruoyi.project.production.controller.vo.MonthlyAnalysisDataVO;
|
|
import com.ruoyi.project.production.controller.vo.MonthlyAnalysisQueryVO;
|
|
import com.ruoyi.project.production.controller.vo.MonthlyAnalysisQueryVO;
|
|
import com.ruoyi.project.production.controller.vo.MonthlyUpdateVO;
|
|
import com.ruoyi.project.production.controller.vo.MonthlyUpdateVO;
|
|
import com.ruoyi.project.production.mapper.TMonthlyProductionPriceMapper;
|
|
import com.ruoyi.project.production.mapper.TMonthlyProductionPriceMapper;
|
|
import com.ruoyi.project.production.service.impl.thread.SyncAfterMonthlyUpdateThread;
|
|
import com.ruoyi.project.production.service.impl.thread.SyncAfterMonthlyUpdateThread;
|
|
import com.ruoyi.project.production.service.impl.vo.MonthlyProductionReportVO;
|
|
import com.ruoyi.project.production.service.impl.vo.MonthlyProductionReportVO;
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
|
+import org.apache.poi.xssf.usermodel.*;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import com.ruoyi.project.production.mapper.TMonthlyProductionReportMapper;
|
|
import com.ruoyi.project.production.mapper.TMonthlyProductionReportMapper;
|
|
@@ -29,6 +42,8 @@ import com.ruoyi.project.production.service.ITMonthlyProductionReportService;
|
|
@Service
|
|
@Service
|
|
public class TMonthlyProductionReportServiceImpl implements ITMonthlyProductionReportService
|
|
public class TMonthlyProductionReportServiceImpl implements ITMonthlyProductionReportService
|
|
{
|
|
{
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class);
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private TMonthlyProductionPriceMapper tMonthlyProductionPriceMapper;
|
|
private TMonthlyProductionPriceMapper tMonthlyProductionPriceMapper;
|
|
|
|
|
|
@@ -3151,4 +3166,240 @@ public class TMonthlyProductionReportServiceImpl implements ITMonthlyProductionR
|
|
}
|
|
}
|
|
return affectedRows;
|
|
return affectedRows;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public AjaxResult export(Long year) {
|
|
|
|
+ // 根据年份查询月报数据
|
|
|
|
+ List<MonthlyProductionReportVO> crackerRawMaterial = this.selectCrackerRawMaterialByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> crackerOutputProduct = this.selectCrackerOutputProductByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> aromaticsRawMaterial = this.selectAromaticsRawMaterialByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> aromaticsOutputProduct = this.selectAromaticsOutputProductByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> eligibleProductRate = this.selectEligibleProductRateByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> productYield = this.selectProductYieldByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> crackerUtilityConsumption = this.selectCrackerUtilityConsumptionByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> crackerEnergyConsumption = this.selectCrackerEnergyConsumptionByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> aromaticsUtilityConsumption = this.selectAromaticsUtilityConsumptionByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> aromaticsEnergyConsumption = this.selectAromaticsEnergyConsumptionByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> plantLoad = this.selectPlantLoadByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> costFrEthylene = this.selectCostFrEthyleneByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> runingRate = this.selectRuningRateByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> shoudownHour = this.selectShoudownHourByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> otherside = this.selectOthersideByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> chemicalConsume = this.selectChemicalConsumeByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> sctuUtilityConsumption = this.selectSCTUUtilityConsumptionByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> subUtilityConsumption = this.selectSUBUtilityConsumptionByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> sctfUtilityConsumption = this.selectSCTFUtilityConsumptionByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> kbi = this.selectKbiByYear(year);
|
|
|
|
+ List<MonthlyProductionReportVO> summary = this.selectSummaryByYear(year);
|
|
|
|
+ // 创建工作簿
|
|
|
|
+ XSSFWorkbook wb = new XSSFWorkbook();
|
|
|
|
+ // 创建工作表
|
|
|
|
+ XSSFSheet sheet = wb.createSheet(year + "年");
|
|
|
|
+ // 单元格样式
|
|
|
|
+ XSSFCellStyle styleYellow = wb.createCellStyle();
|
|
|
|
+ styleYellow.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
+ styleYellow.setFillForegroundColor(IndexedColors.YELLOW1.getIndex());
|
|
|
|
+ styleYellow.setBorderBottom(BorderStyle.THIN);
|
|
|
|
+ styleYellow.setBorderLeft(BorderStyle.THIN);
|
|
|
|
+ styleYellow.setBorderRight(BorderStyle.THIN);
|
|
|
|
+ styleYellow.setBorderTop(BorderStyle.THIN);
|
|
|
|
+ XSSFCellStyle styleWhite = wb.createCellStyle();
|
|
|
|
+ styleWhite.setBorderBottom(BorderStyle.THIN);
|
|
|
|
+ styleWhite.setBorderLeft(BorderStyle.THIN);
|
|
|
|
+ styleWhite.setBorderRight(BorderStyle.THIN);
|
|
|
|
+ styleWhite.setBorderTop(BorderStyle.THIN);
|
|
|
|
+ // 行数
|
|
|
|
+ int rowNum = 21 * 2 + crackerRawMaterial.size() + crackerOutputProduct.size() + aromaticsRawMaterial.size()
|
|
|
|
+ + aromaticsOutputProduct.size() + eligibleProductRate.size() + productYield.size()
|
|
|
|
+ + crackerUtilityConsumption.size() + crackerEnergyConsumption.size() + aromaticsUtilityConsumption.size()
|
|
|
|
+ + aromaticsEnergyConsumption.size() + plantLoad.size() + costFrEthylene.size()
|
|
|
|
+ + runingRate.size() + shoudownHour.size() + otherside.size()
|
|
|
|
+ + chemicalConsume.size() + sctuUtilityConsumption.size() + subUtilityConsumption.size()
|
|
|
|
+ + sctfUtilityConsumption.size() + kbi.size() + summary.size();
|
|
|
|
+ for (int i = 0; i < rowNum; i++) {
|
|
|
|
+ // 创建行
|
|
|
|
+ Row row = sheet.createRow(i);
|
|
|
|
+ for (int j = 0; j < 17; j++) {
|
|
|
|
+ if (i == 0 || i == 1 || i == 19 || i == 20 || i == 35 || i == 36 || i == 43 || i == 44 || i == 58 || i == 59 ||
|
|
|
|
+ i == 63 || i == 64 || i == 86 || i == 87 || i == 109 || i == 110 || i == 115 || i == 116 ||
|
|
|
|
+ i == 133 || i == 134 || i == 139 || i == 140 || i == 147 || i == 148 || i == 150 || i == 151 ||
|
|
|
|
+ i == 156 || i == 157 || i == 170 || i == 171 || i == 178 || i == 179 || i == 199 || i == 200 ||
|
|
|
|
+ i == 207 || i == 208 || i == 235 || i == 236 || i == 254 || i == 255 || i == 271 || i == 272) { // 表头行
|
|
|
|
+ Cell cell = row.createCell(j);
|
|
|
|
+ cell.setCellStyle(styleYellow);
|
|
|
|
+ } else { // 非表头行
|
|
|
|
+ Cell cell = row.createCell(j);
|
|
|
|
+ cell.setCellStyle(styleWhite);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ int rowCount = 0;
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "Cracker Raw Material", 1);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, crackerRawMaterial, 1);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "Cracker Output Product", 1);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, crackerOutputProduct, 1);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "Aromatics Raw Material", 1);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, aromaticsRawMaterial, 1);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "Aromatics Output Product", 1);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, aromaticsOutputProduct, 1);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "Eligible Product Rate", 2);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, eligibleProductRate, 2);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "Product Yield", 2);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, productYield, 2);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "Cracker Utility Consumption", 1);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, crackerUtilityConsumption, 1);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "Cracker Energy Consumption", 3);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, crackerEnergyConsumption, 3);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "Aromatics Utility Consumption", 1);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, aromaticsUtilityConsumption, 1);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "Aromatics Energy Consumption", 3);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, aromaticsEnergyConsumption, 3);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "Plant Load", 3);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, plantLoad, 3);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "Cost Fr Ethylene", 1);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, costFrEthylene, 1);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "Runing Rate", 3);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, runingRate, 3);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "Shoudown Hour", 1);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, shoudownHour, 1);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "Otherside", 3);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, otherside, 3);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "Chemical Consume", 1);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, chemicalConsume, 1);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "SCTU Utility Consumption", 1);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, sctuUtilityConsumption, 1);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "SUB Utility Consumption", 1);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, subUtilityConsumption, 1);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "SCTF Utility Consumption", 1);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, sctfUtilityConsumption, 1);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "KBI", 2);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, kbi, 2);
|
|
|
|
+ rowCount = this.setTableHearder(sheet, rowCount, "BCC装置主要原材料及公用工程消耗", 1);
|
|
|
|
+ rowCount = this.setTableData(sheet, rowCount, summary, 1);
|
|
|
|
+ // 输出文件
|
|
|
|
+ FileOutputStream out = null;
|
|
|
|
+ try {
|
|
|
|
+ String filename = UUID.randomUUID().toString() + "_BYC乙烯装置生产报表汇总-" + year + ".xlsx";
|
|
|
|
+ String downloadPath = RuoYiConfig.getDownloadPath() + filename;
|
|
|
|
+ File desc = new File(downloadPath);
|
|
|
|
+ if (!desc.getParentFile().exists())
|
|
|
|
+ {
|
|
|
|
+ desc.getParentFile().mkdirs();
|
|
|
|
+ }
|
|
|
|
+ out = new FileOutputStream(downloadPath);
|
|
|
|
+ wb.write(out);
|
|
|
|
+ return AjaxResult.success(filename);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ log.error("导出Excel异常{}", e.getMessage());
|
|
|
|
+ throw new CustomException("导出Excel失败,请联系网站管理员!");
|
|
|
|
+ } finally {
|
|
|
|
+ if (wb != null)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ wb.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e1)
|
|
|
|
+ {
|
|
|
|
+ e1.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (out != null)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ out.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e1)
|
|
|
|
+ {
|
|
|
|
+ e1.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 设置表数据
|
|
|
|
+ *
|
|
|
|
+ * @param sheet 当前工作表
|
|
|
|
+ * @param rowCount 当前行数
|
|
|
|
+ * @param dataList 表数据内容
|
|
|
|
+ * @param dataType 表数据类型,1表示total,2表示avg,3表示total+avg
|
|
|
|
+ * @return 当前行数
|
|
|
|
+ */
|
|
|
|
+ private int setTableData(XSSFSheet sheet, int rowCount, List<MonthlyProductionReportVO> dataList, int dataType) {
|
|
|
|
+ for (int i = 0; i < dataList.size(); i++) {
|
|
|
|
+ MonthlyProductionReportVO monthlyProductionReportVO = dataList.get(i);
|
|
|
|
+ XSSFRow row = sheet.getRow(rowCount);
|
|
|
|
+ row.getCell(0).setCellValue(monthlyProductionReportVO.getTitle());
|
|
|
|
+ row.getCell(1).setCellValue(monthlyProductionReportVO.getUnit());
|
|
|
|
+ row.getCell(2).setCellValue(monthlyProductionReportVO.getCurrently());
|
|
|
|
+ row.getCell(3).setCellValue(monthlyProductionReportVO.getJan());
|
|
|
|
+ row.getCell(4).setCellValue(monthlyProductionReportVO.getFeb());
|
|
|
|
+ row.getCell(5).setCellValue(monthlyProductionReportVO.getMar());
|
|
|
|
+ row.getCell(6).setCellValue(monthlyProductionReportVO.getApr());
|
|
|
|
+ row.getCell(7).setCellValue(monthlyProductionReportVO.getMay());
|
|
|
|
+ row.getCell(8).setCellValue(monthlyProductionReportVO.getJun());
|
|
|
|
+ row.getCell(9).setCellValue(monthlyProductionReportVO.getJul());
|
|
|
|
+ row.getCell(10).setCellValue(monthlyProductionReportVO.getAug());
|
|
|
|
+ row.getCell(11).setCellValue(monthlyProductionReportVO.getSep());
|
|
|
|
+ row.getCell(12).setCellValue(monthlyProductionReportVO.getOct());
|
|
|
|
+ row.getCell(13).setCellValue(monthlyProductionReportVO.getNov());
|
|
|
|
+ row.getCell(14).setCellValue(monthlyProductionReportVO.getDec());
|
|
|
|
+ if (dataType == 1) {
|
|
|
|
+ row.getCell(15).setCellValue(monthlyProductionReportVO.getTotal());
|
|
|
|
+ } else if (dataType == 2) {
|
|
|
|
+ row.getCell(15).setCellValue(monthlyProductionReportVO.getAvg());
|
|
|
|
+ } else if (dataType == 3) {
|
|
|
|
+ row.getCell(15).setCellValue(monthlyProductionReportVO.getTotal());
|
|
|
|
+ row.getCell(16).setCellValue(monthlyProductionReportVO.getAvg());
|
|
|
|
+ }
|
|
|
|
+ rowCount++;
|
|
|
|
+ }
|
|
|
|
+ return rowCount;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 设置表头
|
|
|
|
+ *
|
|
|
|
+ * @param sheet 当前工作表
|
|
|
|
+ * @param rowCount 当前行数
|
|
|
|
+ * @param header 表头内容
|
|
|
|
+ * @param headerType 表头类型,1表示total,2表示avg,3表示total+avg
|
|
|
|
+ * @return 当前行数
|
|
|
|
+ */
|
|
|
|
+ private int setTableHearder(XSSFSheet sheet, int rowCount, String header, int headerType) {
|
|
|
|
+ // 合并单元格
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowCount,rowCount,0,16));
|
|
|
|
+ XSSFRow row0 = sheet.getRow(rowCount);
|
|
|
|
+ row0.getCell(0).setCellValue(header);
|
|
|
|
+ rowCount++;
|
|
|
|
+ XSSFRow row1 = sheet.getRow(rowCount);
|
|
|
|
+ row1.getCell(0).setCellValue("Title");
|
|
|
|
+ row1.getCell(1).setCellValue("Unit");
|
|
|
|
+ row1.getCell(2).setCellValue("Currently");
|
|
|
|
+ row1.getCell(3).setCellValue("Jan");
|
|
|
|
+ row1.getCell(4).setCellValue("Feb");
|
|
|
|
+ row1.getCell(5).setCellValue("Mar");
|
|
|
|
+ row1.getCell(6).setCellValue("Apr");
|
|
|
|
+ row1.getCell(7).setCellValue("May");
|
|
|
|
+ row1.getCell(8).setCellValue("Jun");
|
|
|
|
+ row1.getCell(9).setCellValue("Jul");
|
|
|
|
+ row1.getCell(10).setCellValue("Aug");
|
|
|
|
+ row1.getCell(11).setCellValue("Sep");
|
|
|
|
+ row1.getCell(12).setCellValue("Oct");
|
|
|
|
+ row1.getCell(13).setCellValue("Nov");
|
|
|
|
+ row1.getCell(14).setCellValue("Dec");
|
|
|
|
+ if (headerType == 1) {
|
|
|
|
+ row1.getCell(15).setCellValue("Total");
|
|
|
|
+ } else if (headerType == 2) {
|
|
|
|
+ row1.getCell(15).setCellValue("Avg");
|
|
|
|
+ } else if (headerType == 3) {
|
|
|
|
+ row1.getCell(15).setCellValue("Total");
|
|
|
|
+ row1.getCell(16).setCellValue("Avg");
|
|
|
|
+ }
|
|
|
|
+ rowCount++;
|
|
|
|
+ return rowCount;
|
|
|
|
+ }
|
|
}
|
|
}
|