Jelajahi Sumber

PSSR实验室导出

wangggziwen 7 bulan lalu
induk
melakukan
6255e99af2

+ 81 - 6
master/src/main/java/com/ruoyi/project/pssr/controller/TPssrLaboratoryController.java

@@ -1,16 +1,27 @@
 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.project.pssr.domain.TPssrApprove;
-import com.ruoyi.project.pssr.domain.TPssrCleaning;
-import com.ruoyi.project.pssr.domain.TPssrSubcontent;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.file.ExcelUtils;
+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.GetMapping;
@@ -23,7 +34,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import com.ruoyi.framework.aspectj.lang.annotation.Log;
 import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
-import com.ruoyi.project.pssr.domain.TPssrLaboratory;
 import com.ruoyi.project.pssr.service.ITPssrLaboratoryService;
 import com.ruoyi.framework.web.controller.BaseController;
 import com.ruoyi.framework.web.domain.AjaxResult;
@@ -49,6 +59,9 @@ public class TPssrLaboratoryController extends BaseController
     @Autowired
     private ITPssrSubcontentService tPssrSubcontentService;
 
+    @Autowired
+    private ISysUserService sysUserService;
+
     /**
      * 查询实验室列表
      */
@@ -70,8 +83,70 @@ public class TPssrLaboratoryController extends BaseController
     public AjaxResult export(TPssrLaboratory tPssrLaboratory)
     {
         List<TPssrLaboratory> list = tPssrLaboratoryService.selectTPssrLaboratoryList(tPssrLaboratory);
-        ExcelUtil<TPssrLaboratory> util = new ExcelUtil<TPssrLaboratory>(TPssrLaboratory.class);
-        return util.exportExcel(list, "laboratory");
+        return AjaxResult.success(exportTmpl(list));
+    }
+
+    public String exportTmpl(List<TPssrLaboratory> list) {
+        OutputStream out = null;
+        String filename = null;
+        try {
+            String tempUrl = "static/word/pssr/sys.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 (TPssrLaboratory t : list) {
+                Row row = sheet.createRow(rowIndex);
+                row.setHeight((short) 800);
+                row.createCell(0).setCellValue(num);
+                row.createCell(1).setCellValue(t.getInstrumentNumber());
+                row.createCell(2).setCellValue(t.getName());
+                row.createCell(3).setCellValue(t.getSerialNumber());
+                row.createCell(4).setCellValue(t.getVisualInspection());
+                row.createCell(5).setCellValue(t.getFunctionalCheck());
+                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(DateUtils.dateTime(t.getConfirmationDate()));
+                row.createCell(9).setCellValue(t.getRemarks());
+
+
+                //渲染样式
+                for (int i = 0; i < 10; i++) {
+                    row.getCell(i).setCellStyle(originalStyle);
+                }
+                num++;
+                rowIndex++;
+            }
+            filename = ExcelUtil.encodingFilename("Laboratory");
+            out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
+            wb.write(out);
+            wb.close();
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return filename;
     }
 
     /**

TEMPAT SAMPAH
master/src/main/resources/static/word/pssr/sys.xlsx


+ 3 - 3
ui/src/views/pssr/laboratory/index.vue

@@ -380,9 +380,9 @@
             placeholder="选择确认时间">
           </el-date-picker>
         </el-form-item>
-        <el-form-item label="删除状态" prop="delFlag">
-          <el-input v-model="form.delFlag" placeholder="请输入删除状态" />
-        </el-form-item>
+        <!--<el-form-item label="删除状态" prop="delFlag">-->
+          <!--<el-input v-model="form.delFlag" placeholder="请输入删除状态" />-->
+        <!--</el-form-item>-->
         <!--<el-form-item label="创建人" prop="createrCode">-->
           <!--<el-input v-model="form.createrCode" placeholder="请输入创建人" />-->
         <!--</el-form-item>-->