瀏覽代碼

PSSR安全设施泄放阀导出

wangggziwen 6 月之前
父節點
當前提交
ae2d4f6adb

+ 86 - 2
master/src/main/java/com/ruoyi/project/pssr/controller/TPssrSafetyBleedController.java

@@ -1,17 +1,32 @@
 package com.ruoyi.project.pssr.controller;
 
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.file.ExcelUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.framework.aspectj.lang.annotation.Excel;
 import com.ruoyi.framework.aspectj.lang.annotation.Log;
 import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
 import com.ruoyi.framework.web.controller.BaseController;
 import com.ruoyi.framework.web.domain.AjaxResult;
 import com.ruoyi.framework.web.page.TableDataInfo;
 import com.ruoyi.project.pssr.domain.TPssrSafetyBleed;
+import com.ruoyi.project.pssr.domain.TPssrSafetyBleed;
 import com.ruoyi.project.pssr.service.ITPssrSafetyBleedService;
+import com.ruoyi.project.system.domain.SysUser;
+import com.ruoyi.project.system.service.ISysUserService;
+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.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.List;
 
 /**
@@ -26,6 +41,9 @@ public class TPssrSafetyBleedController extends BaseController {
     @Autowired
     private ITPssrSafetyBleedService tPssrSafetyBleedService;
 
+    @Autowired
+    private ISysUserService sysUserService;
+
     /**
      * 查询安全设施-紧急泄放阀列表
      */
@@ -45,8 +63,74 @@ public class TPssrSafetyBleedController extends BaseController {
     @GetMapping("/export")
     public AjaxResult export(TPssrSafetyBleed tPssrSafetyBleed) {
         List<TPssrSafetyBleed> list = tPssrSafetyBleedService.selectTPssrSafetyBleedList(tPssrSafetyBleed);
-        ExcelUtil<TPssrSafetyBleed> util = new ExcelUtil<TPssrSafetyBleed>(TPssrSafetyBleed.class);
-        return util.exportExcel(list, "safetyBleed");
+        return AjaxResult.success(exportTmpl(list));
+    }
+
+    public String exportTmpl(List<TPssrSafetyBleed> list) {
+        OutputStream out = null;
+        String filename = null;
+        try {
+            String tempUrl = "static/word/pssr/aqssxff.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 (TPssrSafetyBleed t : list) {
+                Row row = sheet.createRow(rowIndex);
+                row.setHeight((short) 800);
+                row.createCell(0).setCellValue(num);
+                row.createCell(1).setCellValue(t.getUnit());
+                row.createCell(2).setCellValue(t.getPidNo());
+                row.createCell(3).setCellValue(t.getDevNo());
+                row.createCell(4).setCellValue(t.getVerify());
+                row.createCell(5).setCellValue(t.getInValidity());
+                row.createCell(6).setCellValue(t.getInstallLocation());
+                row.createCell(7).setCellValue(t.getInstallAccuracy());
+                row.createCell(8).setCellValue(t.getPutUse());
+                row.createCell(9).setCellValue(t.getSetPressure());
+                row.createCell(10).setCellValue(t.getUniformPressure());
+                row.createCell(11);
+                row.createCell(12);
+                try {
+                    SysUser sysUser1 = sysUserService.selectUserById(Long.valueOf(t.getConfirmer1()));
+                    SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirmer2()));
+                    String confirm1 =  sysUser1.getSignUrl();
+                    String confirm2 =  sysUser2.getSignUrl();
+                    ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 11, 1, 1);
+                    ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 12, 1, 1);
+                } catch (NumberFormatException e) {
+                    throw new RuntimeException(e);
+                }
+                row.createCell(13).setCellValue(DateUtils.dateTime(t.getConfirmationTime()));
+                row.createCell(14).setCellValue(t.getRemarks());
+
+                //渲染样式
+                for (int i = 0; i < 15; i++) {
+                    row.getCell(i).setCellStyle(originalStyle);
+                }
+                num++;
+                rowIndex++;
+            }
+            filename = ExcelUtil.encodingFilename("SafetyBleed");
+            out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
+            wb.write(out);
+            wb.close();
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return filename;
     }
 
     /**

二進制
master/src/main/resources/static/word/pssr/aqssxff.xlsx