Bladeren bron

PSSR检修项目阀门导出

wangggziwen 9 maanden geleden
bovenliggende
commit
9f7f729ca6

+ 77 - 2
master/src/main/java/com/ruoyi/project/pssr/controller/TPssrOverhaulValveController.java

@@ -1,18 +1,31 @@
 package com.ruoyi.project.pssr.controller;
 
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.*;
 
+import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.file.ExcelUtils;
 import com.ruoyi.project.pssr.domain.TPssrApprove;
 import com.ruoyi.project.pssr.domain.TPssrOverhaulExchanger;
 import com.ruoyi.project.pssr.domain.TPssrSubcontent;
 import com.ruoyi.project.pssr.service.ITPssrApproveService;
 import com.ruoyi.project.pssr.service.ITPssrOverhaulExchangerService;
 import com.ruoyi.project.pssr.service.ITPssrSubcontentService;
+import com.ruoyi.project.system.domain.SysUser;
+import com.ruoyi.project.system.service.ISysUserService;
 import org.activiti.engine.HistoryService;
 import org.activiti.engine.RuntimeService;
 import org.activiti.engine.impl.identity.Authentication;
 import org.activiti.engine.runtime.ProcessInstance;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+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;
@@ -60,6 +73,8 @@ public class TPssrOverhaulValveController extends BaseController
     @Autowired
     private ITPssrSubcontentService tPssrSubcontentService;
 
+    @Autowired
+    private ISysUserService sysUserService;
 
     @PutMapping("/turnDownValve")
     public AjaxResult turnDownValve(@RequestBody TPssrOverhaulValve tPssrOverhaulValve) {
@@ -156,8 +171,68 @@ public class TPssrOverhaulValveController extends BaseController
     public AjaxResult export(TPssrOverhaulValve tPssrOverhaulValve)
     {
         List<TPssrOverhaulValve> list = tPssrOverhaulValveService.selectTPssrOverhaulValveList(tPssrOverhaulValve);
-        ExcelUtil<TPssrOverhaulValve> util = new ExcelUtil<TPssrOverhaulValve>(TPssrOverhaulValve.class);
-        return util.exportExcel(list, "overhaulValve");
+        return AjaxResult.success(exportTmpl(list));
+    }
+
+    public String exportTmpl(List<TPssrOverhaulValve> list) {
+        OutputStream out = null;
+        String filename = null;
+        try {
+            String tempUrl = "static/word/pssr/jxxmfm.xlsx"; // 模板文件
+            InputStream is = null;
+            is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
+            XSSFWorkbook wb = null;
+            wb = new XSSFWorkbook(is);
+            XSSFSheet sheet = wb.getSheetAt(0);
+
+            //填充数据
+            int rowIndex = 3;
+            int num = 1;
+
+            Row originalRow = sheet.getRow(3);
+            Cell originalcell = originalRow.getCell(0);
+            // 获取单元格样式
+            CellStyle originalStyle = originalcell.getCellStyle();
+
+            for (TPssrOverhaulValve t : list) {
+                Row row = sheet.createRow(rowIndex);
+                row.setHeight((short) 800);
+                row.createCell(0).setCellValue(num);
+                row.createCell(1).setCellValue(t.getChangeType());
+                row.createCell(2).setCellValue(t.getItem());
+                row.createCell(3).setCellValue(t.getPlant());
+                row.createCell(4).setCellValue(t.getValvePosition());
+                row.createCell(5).setCellValue(t.getType());
+                row.createCell(6).setCellValue(t.getPipeSize());
+                row.createCell(7).setCellValue(t.getValveClass());
+                row.createCell(8).setCellValue(t.getPidNo());
+                row.createCell(9).setCellValue(DateUtils.dateTime(t.getDoneDate()));
+                row.createCell(10);
+                try {
+                    SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getIdentifyingPerson()));
+                    String confirm1 =  sysUser.getSignUrl();
+                    ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 10, 1, 1);
+                } catch (NumberFormatException e) {
+                    throw new RuntimeException(e);
+                }
+                row.createCell(11).setCellValue(t.getRemarks());
+
+                //渲染样式
+                for (int i = 0; i < 12; i++) {
+                    row.getCell(i).setCellStyle(originalStyle);
+                }
+                num++;
+                rowIndex++;
+            }
+            filename = ExcelUtil.encodingFilename("OverhaulValve");
+            out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
+            wb.write(out);
+            wb.close();
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return filename;
     }
 
     /**

BIN
master/src/main/resources/static/word/pssr/jxxmfm.xlsx