소스 검색

徐明浩
压力容器年检报告批量导出
压力管道年检报告批量导出

徐明浩 3 년 전
부모
커밋
738772a320

+ 41 - 9
master/src/main/java/com/ruoyi/common/utils/document/PDFTemplateUtil.java

@@ -9,9 +9,7 @@ import org.xhtmlrenderer.pdf.ITextRenderer;
 
 
 import javax.servlet.http.HttpServletResponse;
-import java.io.ByteArrayOutputStream;
-import java.io.OutputStream;
-import java.io.StringWriter;
+import java.io.*;
 import java.net.URLEncoder;
 import java.util.Locale;
 import java.util.Map;
@@ -26,11 +24,11 @@ public class PDFTemplateUtil {
     /**
      * 通过模板导出pdf文件
      *
-     * @param map             数据
+     * @param map              数据
      * @param templateFileName 模板文件名
      * @throws Exception
      */
-    private static ByteArrayOutputStream createPDF(Map<String, Object> map, String templateFileName , String filePath) throws Exception {
+    private static ByteArrayOutputStream createPDF(Map<String, Object> map, String templateFileName, String filePath) throws Exception {
         // 创建一个FreeMarker实例, 负责管理FreeMarker模板的Configuration实例
         Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
         // 指定FreeMarker模板文件的位置
@@ -79,16 +77,15 @@ public class PDFTemplateUtil {
      *
      * @param templateName 模板文件名(模板文件名+后缀)
      * @param pdfName      pdf文件名(pdf文件名+后缀)
-     * @param map         数据
+     * @param map          数据
      * @param response     HttpServletResponse
      * @throws Exception
      */
-    public static void exportPdf(String templateName, String pdfName,String filePath, Map<String, Object> map, HttpServletResponse response) throws Exception {
+    public static void exportPdf(String templateName, String pdfName, String filePath, Map<String, Object> map, HttpServletResponse response) throws Exception {
         ByteArrayOutputStream baos = null;
         OutputStream out = null;
         try {
-            baos = createPDF(map, templateName ,filePath);
-            ;
+            baos = createPDF(map, templateName, filePath);
             // 设置响应消息头,告诉浏览器当前响应是一个下载文件
             response.setContentType("application/x-msdownload");
             // 告诉浏览器,当前响应数据要求用户干预保存到文件中,以及文件名是什么 如果文件名有中文,必须URL编码
@@ -110,4 +107,39 @@ public class PDFTemplateUtil {
         }
     }
 
+    /**
+     * 通过模板导出pdf文件
+     *
+     * @param templateName 模板文件名(模板文件名+后缀)
+     * @param pdfName      pdf文件名(pdf文件名+后缀)
+     * @param map          数据
+     * @param response     HttpServletResponse
+     * @throws Exception
+     */
+    public static void createPdf(String templateName, String pdfName, String filePath, Map<String, Object> map, HttpServletResponse response) throws Exception {
+        ByteArrayOutputStream baos = null;
+        FileOutputStream fileOutputStream = null;
+        try {
+            File file = new File(filePath);
+            if (!file.isDirectory()) {
+                file.mkdir();
+            }
+            baos = createPDF(map, templateName, filePath);
+            fileOutputStream = new FileOutputStream(filePath + "\\" + pdfName);
+            fileOutputStream.write(baos.toByteArray());
+            baos.close();
+            fileOutputStream.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new Exception("导出失败:" + e.getMessage());
+        } finally {
+            if (baos != null) {
+                baos.close();
+            }
+            if (fileOutputStream != null) {
+                fileOutputStream.close();
+            }
+        }
+    }
+
 }

+ 2 - 0
master/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@@ -122,6 +122,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 .antMatchers("/pdf/**").anonymous()
                 .antMatchers("/**/exportPDF").anonymous()
                 .antMatchers("/ehs/approvedanger/processImg/**").anonymous()
+                .antMatchers("/sems/historyYlrq/exportPDFForYear").anonymous()
+                .antMatchers("/sems/historyYlgd/exportPDFForYear").anonymous()
                 // 除上面外的所有请求全部需要鉴权认证
                 .anyRequest().authenticated()
                 .and()

+ 96 - 3
master/src/main/java/com/ruoyi/project/sems/controller/TReportHiYlgdController.java

@@ -3,15 +3,16 @@ package com.ruoyi.project.sems.controller;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 
 import com.alibaba.fastjson.JSON;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.document.PDFTemplateUtil;
+import com.ruoyi.common.utils.document.ZipUtil;
 import com.ruoyi.framework.config.RuoYiConfig;
-import com.ruoyi.project.sems.domain.TReportYlgd;
-import com.ruoyi.project.sems.domain.TSpecdevYlgd;
+import com.ruoyi.project.sems.domain.*;
 import com.ruoyi.project.sems.service.ITReportYlgdService;
 import com.ruoyi.project.sems.service.ITSpecdevYlgdService;
 import com.ruoyi.project.system.domain.SysDept;
@@ -27,7 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import com.ruoyi.framework.aspectj.lang.annotation.Log;
 import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
-import com.ruoyi.project.sems.domain.TReportHiYlgd;
 import com.ruoyi.project.sems.service.ITReportHiYlgdService;
 import com.ruoyi.framework.web.controller.BaseController;
 import com.ruoyi.framework.web.domain.AjaxResult;
@@ -206,4 +206,97 @@ public class TReportHiYlgdController extends BaseController
         }
         return null;
     }
+
+    @RequestMapping("/exportPDFForYear")
+    public String exportPDFForYear(@RequestParam String year, HttpServletRequest request, HttpServletResponse response) {
+        OutputStream out = null;
+        try {
+            out = response.getOutputStream();
+            //获取信息,就是上面的结构
+            HashMap<String, Object> map = new HashMap<>();
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            List<TReportHiYlgd> tReportHiYlgds = this.tReportHiYlgdService.selectTReportHiYlgdForYear(year);
+            List<SysDictData> con = iSysDictTypeService.selectDictDataByType("REPORT_CON");
+            //使用当前时间作为文件夹,所有文件保存在当中
+            long now = System.currentTimeMillis();
+            //存放所有pdf文件路径
+            List<String> list = new ArrayList<>();
+            for (TReportHiYlgd tReportHiYlgd : tReportHiYlgds) {
+                if (StringUtils.isNotEmpty(tReportHiYlgd.getCon())) {
+                    for (SysDictData c : con) {
+                        if (tReportHiYlgd.getCon().equals(c.getDictValue())) {
+                            tReportHiYlgd.setCon(c.getDictLabel());
+                        }
+                    }
+                }
+                if (StringUtils.isNotEmpty(tReportHiYlgd.getPlantCode())) {
+                    SysUser sysUser = this.iSysUserService.selectSafeManagerUserByPlantCode(tReportHiYlgd.getPlantCode());
+                    if (sysUser != null) {
+                        map.put("safeUserName", sysUser.getNickName());
+                        map.put("safePhonenumber", sysUser.getPhonenumber());
+                    } else {
+                        map.put("safeUserName", "");
+                        map.put("safePhonenumber", "");
+                    }
+                }
+                map.put("reportHiYlgd", tReportHiYlgd);
+                TReportYlgd reportYlgd = tReportYlgdService.selectTReportYlgdById(tReportHiYlgd.getReportId());
+                TSpecdevYlgd devYlgd = tSpecdevYlgdService.selectTSpecdevYlgdById(reportYlgd.getDevId());
+                map.put("devYlgd", devYlgd);
+                if (tReportHiYlgd.getCheckDate() != null) {
+                    map.put("checkDate", sdf.format(tReportHiYlgd.getCheckDate()));
+                }
+                if (tReportHiYlgd.getNextWarnDate() != null) {
+                    String[] nextWarnDateGD = sdf.format(tReportHiYlgd.getNextWarnDate()).split("-");
+                    map.put("nextWarnDateYear", nextWarnDateGD[0]);
+                    map.put("nextWarnDateMonth", nextWarnDateGD[1]);
+                }
+                if (tReportHiYlgd.getNextCheckDate() != null) {
+                    String[] nextCheckDateGD = sdf.format(tReportHiYlgd.getNextCheckDate()).split("-");
+                    map.put("nextCheckDateYear", nextCheckDateGD[0]);
+                    map.put("nextCheckDateMonth", nextCheckDateGD[1]);
+                }
+                HistoricTaskInstanceQuery htiq = historyService.createHistoricTaskInstanceQuery();
+                List<HistoricTaskInstance> htiLists = htiq.processInstanceId(tReportHiYlgd.getApproveId()).finished().orderByHistoricTaskInstanceEndTime().asc().list();
+                logger.info("报告数据:" + JSON.toJSONString(htiLists));
+                if (htiLists != null) {
+                    SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                    map.put("inspectorOne", htiLists.get(0).getName());
+                    map.put("inspectorOneEndTime", sdf2.format(htiLists.get(0).getEndTime()));
+                    map.put("inspectorTwo", htiLists.get(1).getName());
+                    map.put("inspectorTwoEndTime", sdf2.format(htiLists.get(1).getEndTime()));
+                    map.put("inspectorThree", htiLists.get(2).getName());
+                    map.put("inspectorThreeEndTime", sdf2.format(htiLists.get(2).getEndTime()));
+                    map.put("auditor", htiLists.get(3).getName());
+                    map.put("auditorEndTime", sdf2.format(htiLists.get(3).getEndTime()));
+                    map.put("approveUser", htiLists.get(4).getName());
+                    map.put("approveEndTime", sdf2.format(htiLists.get(4).getEndTime()));
+                }
+                //多个文件区分文件名
+                String pdfName = tReportHiYlgd.getPlantCode()
+                        + "-" + tReportHiYlgd.getUnit()
+                        + "-" + tReportHiYlgd.getDevno()
+                        + "-" + tReportHiYlgd.getDevname()
+                        + "-" + sdf.format(tReportHiYlgd.getCheckDate())
+                        + "-压力容器年度检查报告.pdf"
+                        .replace(" ", "")
+                        .replace("\\s", "")
+                        .replace("\n", "");
+                // 生成PDF文件
+                PDFTemplateUtil.createPdf("yearYlgdFMaker.ftl", pdfName, RuoYiConfig.getProfile() + "/" + now, map, response);
+                list.add(pdfName);
+            }
+            ZipUtil.createZip(RuoYiConfig.getProfile(), now + "", year + "年压力管道年度检查历史报告.zip", list, response);
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (out != null)
+                try {
+                    out.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+        }
+        return null;
+    }
 }

+ 131 - 41
master/src/main/java/com/ruoyi/project/sems/controller/TReportHiYlrqController.java

@@ -1,14 +1,17 @@
 package com.ruoyi.project.sems.controller;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 
 import com.alibaba.fastjson.JSON;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.document.PDFTemplateUtil;
+import com.ruoyi.common.utils.document.ZipUtil;
 import com.ruoyi.framework.config.RuoYiConfig;
 import com.ruoyi.project.sems.domain.*;
 import com.ruoyi.project.sems.service.ITReportYlgdService;
@@ -43,8 +46,7 @@ import javax.servlet.http.HttpServletResponse;
  */
 @RestController
 @RequestMapping("/sems/historyYlrq")
-public class TReportHiYlrqController extends BaseController
-{
+public class TReportHiYlrqController extends BaseController {
     @Autowired
     private ITReportHiYlrqService tReportHiYlrqService;
 
@@ -68,8 +70,7 @@ public class TReportHiYlrqController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('sems:historyYlrq:list')")
     @GetMapping("/list")
-    public TableDataInfo list(TReportHiYlrq tReportHiYlrq)
-    {
+    public TableDataInfo list(TReportHiYlrq tReportHiYlrq) {
         startPage();
         List<TReportHiYlrq> list = tReportHiYlrqService.selectTReportHiYlrqList(tReportHiYlrq);
         return getDataTable(list);
@@ -81,8 +82,7 @@ public class TReportHiYlrqController extends BaseController
     @PreAuthorize("@ss.hasPermi('sems:historyYlrq:export')")
     @Log(title = "压力容器报告历史", businessType = BusinessType.EXPORT)
     @GetMapping("/export")
-    public AjaxResult export(TReportHiYlrq tReportHiYlrq)
-    {
+    public AjaxResult export(TReportHiYlrq tReportHiYlrq) {
         List<TReportHiYlrq> list = tReportHiYlrqService.selectTReportHiYlrqList(tReportHiYlrq);
         ExcelUtil<TReportHiYlrq> util = new ExcelUtil<TReportHiYlrq>(TReportHiYlrq.class);
         return util.exportExcel(list, "historyYlrq");
@@ -93,8 +93,7 @@ public class TReportHiYlrqController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('sems:historyYlrq:query')")
     @GetMapping(value = "/{id}")
-    public AjaxResult getInfo(@PathVariable("id") Long id)
-    {
+    public AjaxResult getInfo(@PathVariable("id") Long id) {
         return AjaxResult.success(tReportHiYlrqService.selectTReportHiYlrqById(id));
     }
 
@@ -104,8 +103,7 @@ public class TReportHiYlrqController extends BaseController
     @PreAuthorize("@ss.hasPermi('sems:historyYlrq:add')")
     @Log(title = "压力容器报告历史", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody TReportHiYlrq tReportHiYlrq)
-    {
+    public AjaxResult add(@RequestBody TReportHiYlrq tReportHiYlrq) {
         return toAjax(tReportHiYlrqService.insertTReportHiYlrq(tReportHiYlrq));
     }
 
@@ -115,8 +113,7 @@ public class TReportHiYlrqController extends BaseController
     @PreAuthorize("@ss.hasPermi('sems:historyYlrq:edit')")
     @Log(title = "压力容器报告历史", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody TReportHiYlrq tReportHiYlrq)
-    {
+    public AjaxResult edit(@RequestBody TReportHiYlrq tReportHiYlrq) {
         return toAjax(tReportHiYlrqService.updateTReportHiYlrq(tReportHiYlrq));
     }
 
@@ -125,15 +122,14 @@ public class TReportHiYlrqController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('sems:historyYlrq:remove')")
     @Log(title = "压力容器报告历史", businessType = BusinessType.DELETE)
-	@DeleteMapping("/{ids}")
-    public AjaxResult remove(@PathVariable Long[] ids)
-    {
+    @DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable Long[] ids) {
         return toAjax(tReportHiYlrqService.deleteTReportHiYlrqByIds(ids));
     }
 
     @RequestMapping("/exportPDF")
     public String exportPDF(@RequestParam String id, HttpServletRequest request, HttpServletResponse response) {
-        OutputStream out= null;
+        OutputStream out = null;
         try {
             out = response.getOutputStream();
             //获取信息,就是上面的结构
@@ -141,36 +137,36 @@ public class TReportHiYlrqController extends BaseController
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
             TReportHiYlrq tReportHiYlrq = this.tReportHiYlrqService.selectTReportHiYlrqById(Long.parseLong(id));
             List<SysDictData> con = iSysDictTypeService.selectDictDataByType("REPORT_CON");
-            if(StringUtils.isNotEmpty(tReportHiYlrq.getCon())){
+            if (StringUtils.isNotEmpty(tReportHiYlrq.getCon())) {
                 for (SysDictData c : con) {
                     if (tReportHiYlrq.getCon().equals(c.getDictValue())) {
                         tReportHiYlrq.setCon(c.getDictLabel());
                     }
                 }
             }
-            if(StringUtils.isNotEmpty(tReportHiYlrq.getPlantCode())){
+            if (StringUtils.isNotEmpty(tReportHiYlrq.getPlantCode())) {
                 SysUser sysUser = this.iSysUserService.selectSafeManagerUserByPlantCode(tReportHiYlrq.getPlantCode());
-                if(sysUser != null){
-                    map.put("safeUserName",sysUser.getNickName());
-                    map.put("safePhonenumber",sysUser.getPhonenumber());
-                }else{
-                    map.put("safeUserName","");
-                    map.put("safePhonenumber","");
+                if (sysUser != null) {
+                    map.put("safeUserName", sysUser.getNickName());
+                    map.put("safePhonenumber", sysUser.getPhonenumber());
+                } else {
+                    map.put("safeUserName", "");
+                    map.put("safePhonenumber", "");
                 }
             }
             map.put("reportHiYlrq", tReportHiYlrq);
             TReportYlrq reportYlrq = tReportYlrqService.selectTReportYlrqById(tReportHiYlrq.getReportId());
             TSpecdevYlrq devYlrq = tSpecdevYlrqService.selectTSpecdevYlrqById(reportYlrq.getDevId());
             map.put("devYlrq", devYlrq);
-            if(tReportHiYlrq.getCheckDate() != null){
+            if (tReportHiYlrq.getCheckDate() != null) {
                 map.put("checkDate", sdf.format(tReportHiYlrq.getCheckDate()));
             }
-            if(tReportHiYlrq.getNextWarnDate() != null){
+            if (tReportHiYlrq.getNextWarnDate() != null) {
                 String[] nextWarnDateGD = sdf.format(tReportHiYlrq.getNextWarnDate()).split("-");
                 map.put("nextWarnDateYear", nextWarnDateGD[0]);
                 map.put("nextWarnDateMonth", nextWarnDateGD[1]);
             }
-            if(tReportHiYlrq.getNextCheckDate() != null){
+            if (tReportHiYlrq.getNextCheckDate() != null) {
                 String[] nextCheckDateGD = sdf.format(tReportHiYlrq.getNextCheckDate()).split("-");
                 map.put("nextCheckDateYear", nextCheckDateGD[0]);
                 map.put("nextCheckDateMonth", nextCheckDateGD[1]);
@@ -178,24 +174,118 @@ public class TReportHiYlrqController extends BaseController
             HistoricTaskInstanceQuery htiq = historyService.createHistoricTaskInstanceQuery();
             List<HistoricTaskInstance> htiLists = htiq.processInstanceId(tReportHiYlrq.getApproveId()).finished().orderByHistoricTaskInstanceEndTime().asc().list();
             logger.info("历史任务:" + JSON.toJSONString(htiLists));
-            if( htiLists != null ){
+            if (htiLists != null) {
                 SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-                map.put("inspectorOne",htiLists.get(0).getName());
-                map.put("inspectorOneEndTime",sdf2.format(htiLists.get(0).getEndTime()));
-                map.put("inspectorTwo",htiLists.get(1).getName());
-                map.put("inspectorTwoEndTime",sdf2.format(htiLists.get(1).getEndTime()));
-                map.put("inspectorThree",htiLists.get(2).getName());
-                map.put("inspectorThreeEndTime",sdf2.format(htiLists.get(2).getEndTime()));
-                map.put("auditor",htiLists.get(3).getName());
-                map.put("auditorEndTime",sdf2.format(htiLists.get(3).getEndTime()));
-                map.put("approveUser",htiLists.get(4).getName());
-                map.put("approveEndTime",sdf2.format(htiLists.get(4).getEndTime()));
+                map.put("inspectorOne", htiLists.get(0).getName());
+                map.put("inspectorOneEndTime", sdf2.format(htiLists.get(0).getEndTime()));
+                map.put("inspectorTwo", htiLists.get(1).getName());
+                map.put("inspectorTwoEndTime", sdf2.format(htiLists.get(1).getEndTime()));
+                map.put("inspectorThree", htiLists.get(2).getName());
+                map.put("inspectorThreeEndTime", sdf2.format(htiLists.get(2).getEndTime()));
+                map.put("auditor", htiLists.get(3).getName());
+                map.put("auditorEndTime", sdf2.format(htiLists.get(3).getEndTime()));
+                map.put("approveUser", htiLists.get(4).getName());
+                map.put("approveEndTime", sdf2.format(htiLists.get(4).getEndTime()));
             }
-            PDFTemplateUtil.exportPdf("yearYlrqFMaker.ftl", "压力容器年度检查报告.pdf","file:/"+ RuoYiConfig.getProfile(), map, response);
+            PDFTemplateUtil.exportPdf("yearYlrqFMaker.ftl", "压力容器年度检查报告.pdf", "file:/" + RuoYiConfig.getProfile(), map, response);
         } catch (Exception e) {
             e.printStackTrace();
-        }finally {
-            if(out!=null)
+        } finally {
+            if (out != null)
+                try {
+                    out.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+        }
+        return null;
+    }
+
+    @RequestMapping("/exportPDFForYear")
+    public String exportPDFForYear(@RequestParam String year, HttpServletRequest request, HttpServletResponse response) {
+        OutputStream out = null;
+        try {
+            out = response.getOutputStream();
+            //获取信息,就是上面的结构
+            HashMap<String, Object> map = new HashMap<>();
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            List<TReportHiYlrq> tReportHiYlrqs = this.tReportHiYlrqService.selectTReportHiYlrqForYear(year);
+            List<SysDictData> con = iSysDictTypeService.selectDictDataByType("REPORT_CON");
+            //使用当前时间作为文件夹,所有文件保存在当中
+            long now = System.currentTimeMillis();
+            //存放所有pdf文件路径
+            List<String> list = new ArrayList<>();
+            for (TReportHiYlrq tReportHiYlrq : tReportHiYlrqs) {
+                if (StringUtils.isNotEmpty(tReportHiYlrq.getCon())) {
+                    for (SysDictData c : con) {
+                        if (tReportHiYlrq.getCon().equals(c.getDictValue())) {
+                            tReportHiYlrq.setCon(c.getDictLabel());
+                        }
+                    }
+                }
+                if (StringUtils.isNotEmpty(tReportHiYlrq.getPlantCode())) {
+                    SysUser sysUser = this.iSysUserService.selectSafeManagerUserByPlantCode(tReportHiYlrq.getPlantCode());
+                    if (sysUser != null) {
+                        map.put("safeUserName", sysUser.getNickName());
+                        map.put("safePhonenumber", sysUser.getPhonenumber());
+                    } else {
+                        map.put("safeUserName", "");
+                        map.put("safePhonenumber", "");
+                    }
+                }
+                map.put("reportHiYlrq", tReportHiYlrq);
+                TReportYlrq reportYlrq = tReportYlrqService.selectTReportYlrqById(tReportHiYlrq.getReportId());
+                TSpecdevYlrq devYlrq = tSpecdevYlrqService.selectTSpecdevYlrqById(reportYlrq.getDevId());
+                map.put("devYlrq", devYlrq);
+                if (tReportHiYlrq.getCheckDate() != null) {
+                    map.put("checkDate", sdf.format(tReportHiYlrq.getCheckDate()));
+                }
+                if (tReportHiYlrq.getNextWarnDate() != null) {
+                    String[] nextWarnDateGD = sdf.format(tReportHiYlrq.getNextWarnDate()).split("-");
+                    map.put("nextWarnDateYear", nextWarnDateGD[0]);
+                    map.put("nextWarnDateMonth", nextWarnDateGD[1]);
+                }
+                if (tReportHiYlrq.getNextCheckDate() != null) {
+                    String[] nextCheckDateGD = sdf.format(tReportHiYlrq.getNextCheckDate()).split("-");
+                    map.put("nextCheckDateYear", nextCheckDateGD[0]);
+                    map.put("nextCheckDateMonth", nextCheckDateGD[1]);
+                }
+                HistoricTaskInstanceQuery htiq = historyService.createHistoricTaskInstanceQuery();
+                List<HistoricTaskInstance> htiLists = htiq.processInstanceId(tReportHiYlrq.getApproveId()).finished().orderByHistoricTaskInstanceEndTime().asc().list();
+                logger.info("报告数据:" + JSON.toJSONString(htiLists));
+                if (htiLists != null) {
+                    SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                    map.put("inspectorOne", htiLists.get(0).getName());
+                    map.put("inspectorOneEndTime", sdf2.format(htiLists.get(0).getEndTime()));
+                    map.put("inspectorTwo", htiLists.get(1).getName());
+                    map.put("inspectorTwoEndTime", sdf2.format(htiLists.get(1).getEndTime()));
+                    map.put("inspectorThree", htiLists.get(2).getName());
+                    map.put("inspectorThreeEndTime", sdf2.format(htiLists.get(2).getEndTime()));
+                    map.put("auditor", htiLists.get(3).getName());
+                    map.put("auditorEndTime", sdf2.format(htiLists.get(3).getEndTime()));
+                    map.put("approveUser", htiLists.get(4).getName());
+                    map.put("approveEndTime", sdf2.format(htiLists.get(4).getEndTime()));
+                }
+                //多个文件区分文件名
+                String pdfName = tReportHiYlrq.getPlantCode()
+                        + "-" + tReportHiYlrq.getUnit()
+                        + "-" + tReportHiYlrq.getDevno()
+                        + "-" + tReportHiYlrq.getDevname()
+                        + "-" + sdf.format(tReportHiYlrq.getCheckDate())
+                        + "-压力容器年度检查报告.pdf"
+                        .replace(" ", "")
+                        .replace("\\s", "")
+                        .replace("\n", "");
+                // 生成PDF文件
+                PDFTemplateUtil.createPdf("yearYlrqFMaker.ftl", pdfName, RuoYiConfig.getProfile() + "/" + now, map, response);
+                list.add(pdfName);
+                //PDFTemplateUtil.exportPdf("yearYlrqFMaker.ftl", pdfName, "file:/" + RuoYiConfig.getProfile(), map, response);
+            }
+            ZipUtil.createZip(RuoYiConfig.getProfile(), now + "", year + "年压力容器年度检查历史报告.zip", list, response);
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (out != null)
                 try {
                     out.close();
                 } catch (IOException e) {

+ 16 - 8
master/src/main/java/com/ruoyi/project/sems/mapper/TReportHiYlgdMapper.java

@@ -6,23 +6,31 @@ import com.ruoyi.project.sems.domain.TReportHiYlgd;
 
 /**
  * 压力管道报告历史Mapper接口
- * 
+ *
  * @author ruoyi
  * @date 2021-09-02
  */
-public interface TReportHiYlgdMapper 
+public interface TReportHiYlgdMapper
 {
     /**
      * 查询压力管道报告历史
-     * 
+     *
      * @param id 压力管道报告历史ID
      * @return 压力管道报告历史
      */
     public TReportHiYlgd selectTReportHiYlgdById(Long id);
 
+    /**
+     * 根据年份获取压力管道报告历史
+     *
+     * @param year 年份
+     * @return
+     */
+    public List<TReportHiYlgd> selectTReportHiYlgdForYear(String year);
+
     /**
      * 查询压力管道报告历史列表
-     * 
+     *
      * @param tReportHiYlgd 压力管道报告历史
      * @return 压力管道报告历史集合
      */
@@ -31,7 +39,7 @@ public interface TReportHiYlgdMapper
 
     /**
      * 新增压力管道报告历史
-     * 
+     *
      * @param tReportHiYlgd 压力管道报告历史
      * @return 结果
      */
@@ -39,7 +47,7 @@ public interface TReportHiYlgdMapper
 
     /**
      * 修改压力管道报告历史
-     * 
+     *
      * @param tReportHiYlgd 压力管道报告历史
      * @return 结果
      */
@@ -47,7 +55,7 @@ public interface TReportHiYlgdMapper
 
     /**
      * 删除压力管道报告历史
-     * 
+     *
      * @param id 压力管道报告历史ID
      * @return 结果
      */
@@ -55,7 +63,7 @@ public interface TReportHiYlgdMapper
 
     /**
      * 批量删除压力管道报告历史
-     * 
+     *
      * @param ids 需要删除的数据ID
      * @return 结果
      */

+ 16 - 8
master/src/main/java/com/ruoyi/project/sems/mapper/TReportHiYlrqMapper.java

@@ -6,23 +6,31 @@ import com.ruoyi.project.sems.domain.TReportHiYlrq;
 
 /**
  * 压力容器报告历史Mapper接口
- * 
+ *
  * @author ruoyi
  * @date 2021-09-02
  */
-public interface TReportHiYlrqMapper 
+public interface TReportHiYlrqMapper
 {
     /**
      * 查询压力容器报告历史
-     * 
+     *
      * @param id 压力容器报告历史ID
      * @return 压力容器报告历史
      */
     public TReportHiYlrq selectTReportHiYlrqById(Long id);
 
+    /**
+     * 根据年份获取压力容器报告历史
+     *
+     * @param year 年份
+     * @return
+     */
+    public List<TReportHiYlrq> selectTReportHiYlrqForYear(String year);
+
     /**
      * 查询压力容器报告历史列表
-     * 
+     *
      * @param tReportHiYlrq 压力容器报告历史
      * @return 压力容器报告历史集合
      */
@@ -31,7 +39,7 @@ public interface TReportHiYlrqMapper
 
     /**
      * 新增压力容器报告历史
-     * 
+     *
      * @param tReportHiYlrq 压力容器报告历史
      * @return 结果
      */
@@ -39,7 +47,7 @@ public interface TReportHiYlrqMapper
 
     /**
      * 修改压力容器报告历史
-     * 
+     *
      * @param tReportHiYlrq 压力容器报告历史
      * @return 结果
      */
@@ -47,7 +55,7 @@ public interface TReportHiYlrqMapper
 
     /**
      * 删除压力容器报告历史
-     * 
+     *
      * @param id 压力容器报告历史ID
      * @return 结果
      */
@@ -55,7 +63,7 @@ public interface TReportHiYlrqMapper
 
     /**
      * 批量删除压力容器报告历史
-     * 
+     *
      * @param ids 需要删除的数据ID
      * @return 结果
      */

+ 17 - 8
master/src/main/java/com/ruoyi/project/sems/service/ITReportHiYlgdService.java

@@ -2,18 +2,19 @@ package com.ruoyi.project.sems.service;
 
 import java.util.List;
 import com.ruoyi.project.sems.domain.TReportHiYlgd;
+import com.ruoyi.project.sems.domain.TReportHiYlrq;
 
 /**
  * 压力管道报告历史Service接口
- * 
+ *
  * @author ruoyi
  * @date 2021-09-02
  */
-public interface ITReportHiYlgdService 
+public interface ITReportHiYlgdService
 {
     /**
      * 查询压力管道报告历史
-     * 
+     *
      * @param id 压力管道报告历史ID
      * @return 压力管道报告历史
      */
@@ -21,15 +22,23 @@ public interface ITReportHiYlgdService
 
     /**
      * 查询压力管道报告历史列表
-     * 
+     *
      * @param tReportHiYlgd 压力管道报告历史
      * @return 压力管道报告历史集合
      */
     public List<TReportHiYlgd> selectTReportHiYlgdList(TReportHiYlgd tReportHiYlgd);
 
+    /**
+     * 根据年份获取压力管道报告历史
+     *
+     * @param year 年份
+     * @return
+     */
+    public List<TReportHiYlgd> selectTReportHiYlgdForYear(String year);
+
     /**
      * 新增压力管道报告历史
-     * 
+     *
      * @param tReportHiYlgd 压力管道报告历史
      * @return 结果
      */
@@ -37,7 +46,7 @@ public interface ITReportHiYlgdService
 
     /**
      * 修改压力管道报告历史
-     * 
+     *
      * @param tReportHiYlgd 压力管道报告历史
      * @return 结果
      */
@@ -45,7 +54,7 @@ public interface ITReportHiYlgdService
 
     /**
      * 批量删除压力管道报告历史
-     * 
+     *
      * @param ids 需要删除的压力管道报告历史ID
      * @return 结果
      */
@@ -53,7 +62,7 @@ public interface ITReportHiYlgdService
 
     /**
      * 删除压力管道报告历史信息
-     * 
+     *
      * @param id 压力管道报告历史ID
      * @return 结果
      */

+ 16 - 8
master/src/main/java/com/ruoyi/project/sems/service/ITReportHiYlrqService.java

@@ -6,23 +6,31 @@ import com.ruoyi.project.sems.domain.TReportYlrq;
 
 /**
  * 压力容器报告历史Service接口
- * 
+ *
  * @author ruoyi
  * @date 2021-09-02
  */
-public interface ITReportHiYlrqService 
+public interface ITReportHiYlrqService
 {
     /**
      * 查询压力容器报告历史
-     * 
+     *
      * @param id 压力容器报告历史ID
      * @return 压力容器报告历史
      */
     public TReportHiYlrq selectTReportHiYlrqById(Long id);
 
+    /**
+     * 根据年份获取压力容器报告历史
+     *
+     * @param year 年份
+     * @return
+     */
+    public List<TReportHiYlrq> selectTReportHiYlrqForYear(String year);
+
     /**
      * 查询压力容器报告历史列表
-     * 
+     *
      * @param tReportHiYlrq 压力容器报告历史
      * @return 压力容器报告历史集合
      */
@@ -30,14 +38,14 @@ public interface ITReportHiYlrqService
 
     /**
      * 新增压力容器报告历史
-     * 
+     *
      * @param tReportHiYlrq 压力容器报告历史
      * @return 结果
      */
     public int insertTReportHiYlrq(TReportHiYlrq tReportHiYlrq);
     /**
      * 修改压力容器报告历史
-     * 
+     *
      * @param tReportHiYlrq 压力容器报告历史
      * @return 结果
      */
@@ -45,7 +53,7 @@ public interface ITReportHiYlrqService
 
     /**
      * 批量删除压力容器报告历史
-     * 
+     *
      * @param ids 需要删除的压力容器报告历史ID
      * @return 结果
      */
@@ -53,7 +61,7 @@ public interface ITReportHiYlrqService
 
     /**
      * 删除压力容器报告历史信息
-     * 
+     *
      * @param id 压力容器报告历史ID
      * @return 结果
      */

+ 5 - 0
master/src/main/java/com/ruoyi/project/sems/service/impl/TReportHiYlgdServiceImpl.java

@@ -45,6 +45,11 @@ public class TReportHiYlgdServiceImpl implements ITReportHiYlgdService
         return tReportHiYlgdMapper.selectTReportHiYlgdList(tReportHiYlgd);
     }
 
+    @Override
+    public List<TReportHiYlgd> selectTReportHiYlgdForYear(String year) {
+        return this.tReportHiYlgdMapper.selectTReportHiYlgdForYear(year);
+    }
+
     /**
      * 新增压力管道报告历史
      *

+ 5 - 0
master/src/main/java/com/ruoyi/project/sems/service/impl/TReportHiYlrqServiceImpl.java

@@ -33,6 +33,11 @@ public class TReportHiYlrqServiceImpl implements ITReportHiYlrqService
         return tReportHiYlrqMapper.selectTReportHiYlrqById(id);
     }
 
+    @Override
+    public List<TReportHiYlrq> selectTReportHiYlrqForYear(String year) {
+        return this.tReportHiYlrqMapper.selectTReportHiYlrqForYear(year);
+    }
+
     /**
      * 查询压力容器报告历史列表
      *

+ 12 - 6
master/src/main/resources/mybatis/sems/TReportHiYlgdMapper.xml

@@ -3,7 +3,7 @@
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.project.sems.mapper.TReportHiYlgdMapper">
-    
+
     <resultMap type="TReportHiYlgd" id="TReportHiYlgdResult">
         <result property="id"    column="id"    />
         <result property="reportId"    column="report_id"    />
@@ -55,21 +55,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select d.id, d.report_id, d.plant_code, d.unit, d.devname, d.devno, d.grade, d.medium, d.des_pressure, d.des_temp, d.opt_pressure, d.safe_class, d.next_warn_date, d.opt_temp, d.year_report_no, d.pj1, d.pj2, d.pj3, d.pj4, d.pj5, d.pj6, d.pj7, d.pj8, d.pj9, d.pj10, d.pj11, d.pj12, d.pj13, d.pj14, d.pj15, d.pj16, d.pj17, d.remarks, d.check_date, d.next_check_date, d.problem, d.con, d.build_date, d.approve_id, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate from t_report_hi_ylgd d
     </sql>
 
+    <select id="selectTReportHiYlgdForYear" parameterType="String" resultMap="TReportHiYlgdResult">
+        <include refid="selectTReportHiYlgdVo"/>
+        where TO_CHAR(check_date,'yyyy') = #{year}
+        and d.del_flag = 0
+    </select>
+
     <select id="selectTReportHiYlgdList" parameterType="TReportHiYlgd" resultMap="TReportHiYlgdResult">
         <include refid="selectTReportHiYlgdVo"/>
-        <where>  
+        <where>
             <if test="reportId != null "> and report_id = #{reportId}</if>
             and d.del_flag = 0
         </where>
         <!-- 数据范围过滤 -->
         ${params.dataScope}
     </select>
-    
+
     <select id="selectTReportHiYlgdById" parameterType="Long" resultMap="TReportHiYlgdResult">
         <include refid="selectTReportHiYlgdVo"/>
         where id = #{id}
     </select>
-        
+
     <insert id="insertTReportHiYlgd" parameterType="TReportHiYlgd">
         <selectKey keyProperty="id" resultType="long" order="BEFORE">
             SELECT seq_t_report_hi_ylgd.NEXTVAL as id FROM DUAL
@@ -229,5 +235,5 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </update>
-    
-</mapper>
+
+</mapper>

+ 12 - 6
master/src/main/resources/mybatis/sems/TReportHiYlrqMapper.xml

@@ -3,7 +3,7 @@
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.project.sems.mapper.TReportHiYlrqMapper">
-    
+
     <resultMap type="TReportHiYlrq" id="TReportHiYlrqResult">
         <result property="id"    column="id"    />
         <result property="reportId"    column="report_id"    />
@@ -73,19 +73,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectTReportHiYlrqList" parameterType="TReportHiYlrq" resultMap="TReportHiYlrqResult">
         <include refid="selectTReportHiYlrqVo"/>
-        <where>  
+        <where>
             <if test="reportId != null "> and report_id = #{reportId}</if>
             and d.del_flag = 0
         </where>
         <!-- 数据范围过滤 -->
         ${params.dataScope}
     </select>
-    
+
     <select id="selectTReportHiYlrqById" parameterType="Long" resultMap="TReportHiYlrqResult">
         <include refid="selectTReportHiYlrqVo"/>
         where id = #{id}
     </select>
-        
+
+    <select id="selectTReportHiYlrqForYear" parameterType="String" resultMap="TReportHiYlrqResult">
+        <include refid="selectTReportHiYlrqVo"/>
+        where TO_CHAR(check_date,'yyyy') = #{year}
+        and d.del_flag = 0
+    </select>
+
     <insert id="insertTReportHiYlrq" parameterType="TReportHiYlrq">
         <selectKey keyProperty="id" resultType="long" order="BEFORE">
             SELECT seq_t_report_hi_ylrq.NEXTVAL as id FROM DUAL
@@ -293,5 +299,5 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </update>
-    
-</mapper>
+
+</mapper>

+ 35 - 0
ui/src/views/sems/reportYlgd/index.vue

@@ -29,6 +29,13 @@
           />
         </el-select>
       </el-form-item>
+      <el-form-item :label="$t('检查年份')" prop="checkYear">
+        <el-date-picker
+          v-model="queryParams.checkYear"
+          type="year"
+          placeholder="选择年">
+        </el-date-picker>
+      </el-form-item>
       <el-form-item>
         <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('搜索') }}</el-button>
         <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
@@ -53,6 +60,14 @@
         >{{ $t('同步数据') }}
         </el-button>
       </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="warning"
+          size="mini"
+          @click="exportDataForYear"
+        >{{ $t('批量下载历史报告') }}
+        </el-button>
+      </el-col>
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
 
@@ -508,6 +523,9 @@
       </form>
     </el-dialog>
     <year-approve v-if="approveVisible" ref="yearApprove" @refreshDataList="getList"></year-approve>
+    <form ref="downloadForm2" :action="downloadAction2" target="FORMSUBMIT">
+      <input name="year" v-model="downloadForm2.year" hidden/>
+    </form>
   </div>
 </template>
 
@@ -598,6 +616,7 @@ export default {
       approveStatusOptions: [],
       // 查询参数
       queryParams: {
+        checkYear:null,
         plantCode:null,
         unit:null,
         approveStatus:null,
@@ -616,7 +635,11 @@ export default {
       downloadForm: {
         id: ''
       },
+      downloadForm2: {
+        year: '',
+      },
       downloadAction: process.env.VUE_APP_BASE_API + '/sems/historyYlgd/exportPDF',
+      downloadAction2: process.env.VUE_APP_BASE_API + '/sems/historyYlgd/exportPDFForYear',
       // 表单校验
       rules: {
         devId: [
@@ -999,6 +1022,18 @@ export default {
       this.$nextTick(() => {
         this.$refs['downloadForm'].submit()
       })
+    },
+    //批量下载某年份的历史报告
+    exportDataForYear() {
+      //将控件时间转为年,如果未选中年份,默认当前年
+      if (this.queryParams.checkYear == null) {
+        this.queryParams.checkYear = Date.now();
+      }
+      var date = new Date(this.queryParams.checkYear)
+      this.downloadForm2.year = date.getFullYear();
+      this.$nextTick(() => {
+        this.$refs['downloadForm2'].submit()
+      })
     }
   }
 };

+ 44 - 7
ui/src/views/sems/reportYlrq/index.vue

@@ -38,6 +38,13 @@
           />
         </el-select>
       </el-form-item>
+      <el-form-item :label="$t('检查年份')" prop="checkYear">
+        <el-date-picker
+          v-model="queryParams.checkYear"
+          type="year"
+          placeholder="选择年">
+        </el-date-picker>
+      </el-form-item>
       <el-form-item>
         <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('搜索') }}</el-button>
         <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
@@ -57,10 +64,18 @@
         <el-button
           type="danger"
           size="mini"
-          @click="syncData"
+          @click="exportData"
         >{{ $t('同步数据') }}
         </el-button>
       </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="warning"
+          size="mini"
+          @click="exportDataForYear"
+        >{{ $t('批量下载历史报告') }}
+        </el-button>
+      </el-col>
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
 
@@ -725,6 +740,9 @@
       </form>
     </el-dialog>
     <year-approve v-if="approveVisible" ref="yearApprove" @refreshDataList="getList"></year-approve>
+    <form ref="downloadForm2" :action="downloadAction2" target="FORMSUBMIT">
+      <input name="year" v-model="downloadForm2.year" hidden/>
+    </form>
   </div>
 </template>
 
@@ -747,6 +765,7 @@ import YearApprove from './yearapprove'
 import {syncReportYlgd} from "@/api/sems/reportYlgd";
 
 export default {
+  year: '',
   name: "ReportYlrq",
   components: {Treeselect, YearApprove},
   data() {
@@ -845,10 +864,11 @@ export default {
       conOptions: [],
       // 查询参数
       queryParams: {
-        plantCode:null,
-        unit:null,
-        approveStatus:null,
-        devno:null,
+        checkYear: null,
+        plantCode: null,
+        unit: null,
+        approveStatus: null,
+        devno: null,
         pageNum: 1,
         pageSize: 20,
       },
@@ -862,9 +882,13 @@ export default {
       form: {},
       //下载参数
       downloadForm: {
-        id: ''
+        id: '',
+      },
+      downloadForm2: {
+        year: '',
       },
       downloadAction: process.env.VUE_APP_BASE_API + '/sems/historyYlrq/exportPDF',
+      downloadAction2: process.env.VUE_APP_BASE_API + '/sems/historyYlrq/exportPDFForYear',
       // 表单校验
       rules: {
         devId: [
@@ -1230,7 +1254,7 @@ export default {
       listHistoryYlrq(this.queryHistoryParams).then(response => {
         this.historyYlrqList = response.rows;
         this.open = true;
-        this.title = row.devno+ this.$t('空格') + this.$t('历史报告');
+        this.title = row.devno + this.$t('空格') + this.$t('历史报告');
       });
     },
     /** 修改按钮操作 */
@@ -1399,6 +1423,19 @@ export default {
       this.$nextTick(() => {
         this.$refs['downloadForm'].submit()
       })
+    },
+
+    //批量下载某年份的历史报告
+    exportDataForYear() {
+      //将控件时间转为年,如果未选中年份,默认当前年
+      if (this.queryParams.checkYear == null) {
+        this.queryParams.checkYear = Date.now();
+      }
+      var date = new Date(this.queryParams.checkYear)
+      this.downloadForm2.year = date.getFullYear();
+      this.$nextTick(() => {
+        this.$refs['downloadForm2'].submit()
+      })
     }
   }
 };