wangggziwen 10 сар өмнө
parent
commit
610f8151ad

+ 78 - 2
master/src/main/java/com/ruoyi/project/pssr/controller/TPssrProgrammeController.java

@@ -1,17 +1,29 @@
 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.file.ExcelUtils;
 import com.ruoyi.common.utils.file.FileUploadUtils;
 import com.ruoyi.framework.config.RuoYiConfig;
 import com.ruoyi.project.pssr.domain.*;
 import com.ruoyi.project.pssr.service.ITPssrApproveService;
 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.ProcessEngine;
 import org.activiti.engine.ProcessEngines;
 import org.activiti.engine.TaskService;
 import org.activiti.engine.task.Task;
+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.*;
@@ -44,6 +56,9 @@ public class TPssrProgrammeController extends BaseController
     @Autowired
     private ITPssrSubcontentService tPssrSubcontentService;
 
+    @Autowired
+    private ISysUserService sysUserService;
+
 
     /**
      * 查询开工方案列表
@@ -66,8 +81,69 @@ public class TPssrProgrammeController extends BaseController
     public AjaxResult export(TPssrProgramme tPssrProgramme)
     {
         List<TPssrProgramme> list = tPssrProgrammeService.selectTPssrProgrammeList(tPssrProgramme);
-        ExcelUtil<TPssrProgramme> util = new ExcelUtil<TPssrProgramme>(TPssrProgramme.class);
-        return util.exportExcel(list, "programme");
+        return AjaxResult.success(exportTmpl(list));
+    }
+
+    public String exportTmpl(List<TPssrProgramme> list) {
+        OutputStream out = null;
+        String filename = null;
+        try {
+            String tempUrl = "static/word/pssr/kgfa.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 (TPssrProgramme 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.getFileName());
+                row.createCell(3).setCellValue(t.getWriteDone());
+                row.createCell(4).setCellValue(t.getCheckDone());
+                row.createCell(5).setCellValue(t.getTrainDone());
+                row.createCell(6);
+                row.createCell(7);
+                try {
+                    SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getConfirm1()));
+                    SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirm2()));
+                    String confirm1 =  sysUser.getSignUrl();
+                    String confirm2=  sysUser2.getSignUrl();
+                    ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 6, 1, 1);
+                    ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 7, 1, 1);
+                } catch (NumberFormatException e) {
+                    throw new RuntimeException(e);
+                }
+                row.createCell(8).setCellValue(t.getRemarks());
+
+
+                //渲染样式
+                for (int i = 0; i < 9; i++) {
+                    row.getCell(i).setCellStyle(originalStyle);
+                }
+                num++;
+                rowIndex++;
+            }
+            filename = ExcelUtil.encodingFilename("Programme");
+            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/kgfa.xlsx