Преглед на файлове

王子文 月报 导出

wangggziwen преди 2 години
родител
ревизия
3a94c765f3

+ 16 - 0
master/src/main/java/com/ruoyi/project/production/controller/TMonthlyProductionReportController.java

@@ -1,9 +1,14 @@
 package com.ruoyi.project.production.controller;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import com.ruoyi.project.production.controller.vo.MonthlyAnalysisQueryVO;
 import com.ruoyi.project.production.controller.vo.MonthlyUpdateVO;
+import com.ruoyi.project.production.service.impl.vo.MonthlyProductionReportVO;
+import com.ruoyi.project.training.spec.domain.TStPlan;
+import com.ruoyi.project.training.spec.domain.vo.TStPlanExportVO;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -36,6 +41,17 @@ public class TMonthlyProductionReportController extends BaseController
     @Autowired
     private ITMonthlyProductionReportService tMonthlyProductionReportService;
 
+    /**
+     * 导出每月生产报告
+     */
+    @PreAuthorize("@ss.hasPermi('production:monthly:export')")
+    @Log(title = "每月生产报告", businessType = BusinessType.EXPORT)
+    @GetMapping("/export/{year}")
+    public AjaxResult export(@PathVariable("year") Long year)
+    {
+        return tMonthlyProductionReportService.export(year);
+    }
+
     /**
      * 修改SUB Utility Consumption
      */

+ 3 - 0
master/src/main/java/com/ruoyi/project/production/service/ITMonthlyProductionReportService.java

@@ -2,6 +2,7 @@ package com.ruoyi.project.production.service;
 
 import java.util.List;
 
+import com.ruoyi.framework.web.domain.AjaxResult;
 import com.ruoyi.project.production.controller.vo.MonthlyAnalysisDataVO;
 import com.ruoyi.project.production.controller.vo.MonthlyAnalysisQueryVO;
 import com.ruoyi.project.production.controller.vo.MonthlyUpdateVO;
@@ -226,4 +227,6 @@ public interface ITMonthlyProductionReportService
      * 修改KBI
      */
     public int updateKbi(MonthlyUpdateVO monthlyUpdateVO);
+
+    public AjaxResult export(Long year);
 }

+ 251 - 0
master/src/main/java/com/ruoyi/project/production/service/impl/TMonthlyProductionReportServiceImpl.java

@@ -1,5 +1,8 @@
 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.Method;
 import java.math.BigDecimal;
@@ -7,13 +10,23 @@ import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.Date;
 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.MonthlyAnalysisQueryVO;
 import com.ruoyi.project.production.controller.vo.MonthlyUpdateVO;
 import com.ruoyi.project.production.mapper.TMonthlyProductionPriceMapper;
 import com.ruoyi.project.production.service.impl.thread.SyncAfterMonthlyUpdateThread;
 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.stereotype.Service;
 import com.ruoyi.project.production.mapper.TMonthlyProductionReportMapper;
@@ -29,6 +42,8 @@ import com.ruoyi.project.production.service.ITMonthlyProductionReportService;
 @Service
 public class TMonthlyProductionReportServiceImpl implements ITMonthlyProductionReportService
 {
+    private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class);
+
     @Autowired
     private TMonthlyProductionPriceMapper tMonthlyProductionPriceMapper;
 
@@ -3151,4 +3166,240 @@ public class TMonthlyProductionReportServiceImpl implements ITMonthlyProductionR
         }
         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;
+    }
 }

+ 8 - 0
ui/src/api/production/monthly.js

@@ -1,5 +1,13 @@
 import request from '@/utils/request'
 
+// 导出月报
+export function exportMonthlyReport(year) {
+  return request({
+    url: '/production/monthly/export/' + year,
+    method: 'get'
+  })
+}
+
 // 修改SUB Utility Consumption
 export function updateSUBUtilityConsumption(data) {
   return request({

+ 17 - 1
ui/src/views/production/monthly/index.vue

@@ -19,6 +19,7 @@
           icon="el-icon-download"
           size="mini"
           v-hasPermi="['production:monthly:export']"
+          @click="handleExport"
         >导出</el-button>
       </el-form-item>
       <el-form-item>
@@ -2902,7 +2903,8 @@ import {
   updateCostFrEthylene,
   updateSUBUtilityConsumption,
   updateSctfUtilityConsumption,
-  updateKbi
+  updateKbi,
+  exportMonthlyReport
 } from "@/api/production/monthly";
 import {
   getPriceByYear,
@@ -3004,6 +3006,20 @@ export default {
     this.getMonthlyReport();
   },
   methods: {
+    /** 导出按钮操作 */
+    handleExport() {
+      // 获取选中的年份
+      let year = this.year.getFullYear();
+      this.$confirm("是否确认导出" + year + "年全部月报数据?", "警告", {
+        confirmButtonText: "确定",
+        cancelButtonText: "取消",
+        type: "warning"
+      }).then(function() {
+        return exportMonthlyReport(year);
+      }).then(response => {
+        this.download(response.msg);
+      })
+    },
     /** 点击开工锅炉公用工程单价维护事件处理 */
     handleQueryPrice() {
       let year = this.year.getFullYear();