소스 검색

徐明浩
压力容器年检报告批量导出盖章图片处理
压力管道年检报告批量导出盖章图片处理

徐明浩 3 년 전
부모
커밋
d6b919b9e0

+ 5 - 3
master/src/main/java/com/ruoyi/common/utils/document/PDFTemplateUtil.java

@@ -112,19 +112,21 @@ public class PDFTemplateUtil {
      *
      * @param templateName 模板文件名(模板文件名+后缀)
      * @param pdfName      pdf文件名(pdf文件名+后缀)
+     * @param filePath     文件路径
+     * @param filePath2    图片路径
      * @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 {
+    public static void createPdf(String templateName, String pdfName, String filePath, String filePath2, 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();
+                file.mkdirs();
             }
-            baos = createPDF(map, templateName, filePath);
+            baos = createPDF(map, templateName, filePath2);
             fileOutputStream = new FileOutputStream(filePath + "\\" + pdfName);
             fileOutputStream.write(baos.toByteArray());
             baos.close();

+ 11 - 1
master/src/main/java/com/ruoyi/common/utils/document/ZipUtil.java

@@ -13,6 +13,16 @@ import java.util.zip.ZipOutputStream;
  */
 public class ZipUtil {
 
+    /**
+     * 创建zip文件并用流方式返回浏览器下载
+     *
+     * @param filePath  需压缩的文件路径
+     * @param folder    文件上层目录,用于区分多次下载
+     * @param zipName   zip压缩包文件名
+     * @param fileNames 目录下文件绝对路径集合
+     * @param response
+     * @throws Exception
+     */
     public static void createZip(String filePath, String folder, String zipName, List<String> fileNames, HttpServletResponse response) throws Exception {
         OutputStream out = null;
         ByteArrayOutputStream baos = new ByteArrayOutputStream(1000);
@@ -21,7 +31,7 @@ public class ZipUtil {
             File file = new File(filePath + "\\" + folder + "\\" + fileName);
             fileList.add(file);
         }
-        String zip = filePath + "/" + folder + "/" + zipName;
+        String zip = filePath + folder + "/" + zipName;
         try {
             File file = new File(filePath + "/" + folder);
             if (!file.isDirectory()) {

+ 38 - 43
master/src/main/java/com/ruoyi/project/sems/controller/TReportHiYlgdController.java

@@ -45,8 +45,7 @@ import javax.servlet.http.HttpServletResponse;
  */
 @RestController
 @RequestMapping("/sems/historyYlgd")
-public class TReportHiYlgdController extends BaseController
-{
+public class TReportHiYlgdController extends BaseController {
     @Autowired
     private ITReportHiYlgdService tReportHiYlgdService;
 
@@ -70,8 +69,7 @@ public class TReportHiYlgdController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('sems:historyYlgd:list')")
     @GetMapping("/list")
-    public TableDataInfo list(TReportHiYlgd tReportHiYlgd)
-    {
+    public TableDataInfo list(TReportHiYlgd tReportHiYlgd) {
         startPage();
         List<TReportHiYlgd> list = tReportHiYlgdService.selectTReportHiYlgdList(tReportHiYlgd);
         return getDataTable(list);
@@ -83,8 +81,7 @@ public class TReportHiYlgdController extends BaseController
     @PreAuthorize("@ss.hasPermi('sems:historyYlgd:export')")
     @Log(title = "压力管道报告历史", businessType = BusinessType.EXPORT)
     @GetMapping("/export")
-    public AjaxResult export(TReportHiYlgd tReportHiYlgd)
-    {
+    public AjaxResult export(TReportHiYlgd tReportHiYlgd) {
         List<TReportHiYlgd> list = tReportHiYlgdService.selectTReportHiYlgdList(tReportHiYlgd);
         ExcelUtil<TReportHiYlgd> util = new ExcelUtil<TReportHiYlgd>(TReportHiYlgd.class);
         return util.exportExcel(list, "historyYlgd");
@@ -95,8 +92,7 @@ public class TReportHiYlgdController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('sems:historyYlgd:query')")
     @GetMapping(value = "/{id}")
-    public AjaxResult getInfo(@PathVariable("id") Long id)
-    {
+    public AjaxResult getInfo(@PathVariable("id") Long id) {
         return AjaxResult.success(tReportHiYlgdService.selectTReportHiYlgdById(id));
     }
 
@@ -106,8 +102,7 @@ public class TReportHiYlgdController extends BaseController
     @PreAuthorize("@ss.hasPermi('sems:historyYlgd:add')")
     @Log(title = "压力管道报告历史", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody TReportHiYlgd tReportHiYlgd)
-    {
+    public AjaxResult add(@RequestBody TReportHiYlgd tReportHiYlgd) {
         return toAjax(tReportHiYlgdService.insertTReportHiYlgd(tReportHiYlgd));
     }
 
@@ -117,8 +112,7 @@ public class TReportHiYlgdController extends BaseController
     @PreAuthorize("@ss.hasPermi('sems:historyYlgd:edit')")
     @Log(title = "压力管道报告历史", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody TReportHiYlgd tReportHiYlgd)
-    {
+    public AjaxResult edit(@RequestBody TReportHiYlgd tReportHiYlgd) {
         return toAjax(tReportHiYlgdService.updateTReportHiYlgd(tReportHiYlgd));
     }
 
@@ -127,22 +121,21 @@ public class TReportHiYlgdController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('sems:historyYlgd:remove')")
     @Log(title = "压力管道报告历史", businessType = BusinessType.DELETE)
-	@DeleteMapping("/{ids}")
-    public AjaxResult remove(@PathVariable Long[] ids)
-    {
+    @DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable Long[] ids) {
         return toAjax(tReportHiYlgdService.deleteTReportHiYlgdByIds(ids));
     }
 
     @RequestMapping("/exportPDF")
     public String exportPDF(@RequestParam String id, HttpServletRequest request, HttpServletResponse response) {
-        OutputStream out= null;
+        OutputStream out = null;
         try {
             out = response.getOutputStream();
             //获取信息,就是上面的结构
             HashMap<String, Object> map = new HashMap<>();
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
             TReportHiYlgd reportHiYlgd = tReportHiYlgdService.selectTReportHiYlgdById(Long.parseLong(id));
-            if(StringUtils.isNotEmpty(reportHiYlgd.getCon())){
+            if (StringUtils.isNotEmpty(reportHiYlgd.getCon())) {
                 List<SysDictData> con = iSysDictTypeService.selectDictDataByType("REPORT_CON");
                 for (SysDictData c : con) {
                     if (reportHiYlgd.getCon().equals(c.getDictValue())) {
@@ -150,29 +143,29 @@ public class TReportHiYlgdController extends BaseController
                     }
                 }
             }
-            if(StringUtils.isNotEmpty(reportHiYlgd.getPlantCode())){
+            if (StringUtils.isNotEmpty(reportHiYlgd.getPlantCode())) {
                 SysUser sysUser = this.iSysUserService.selectSafeManagerUserByPlantCode(reportHiYlgd.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("reportHiYlgd", reportHiYlgd);
             TReportYlgd reportYlgd = tReportYlgdService.selectTReportYlgdById(reportHiYlgd.getReportId());
             TSpecdevYlgd devYlgd = tSpecdevYlgdService.selectTSpecdevYlgdById(reportYlgd.getDevId());
             map.put("devYlgd", devYlgd);
-            if(reportHiYlgd.getCheckDate() != null){
+            if (reportHiYlgd.getCheckDate() != null) {
                 map.put("checkDate", sdf.format(reportHiYlgd.getCheckDate()));
             }
-            if(reportYlgd.getNextWarnDate() != null){
+            if (reportYlgd.getNextWarnDate() != null) {
                 String[] nextWarnDateGD = sdf.format(reportYlgd.getNextWarnDate()).split("-");
                 map.put("nextWarnDateYear", nextWarnDateGD[0]);
                 map.put("nextWarnDateMonth", nextWarnDateGD[1]);
             }
-            if(reportHiYlgd.getNextCheckDate() != null){
+            if (reportHiYlgd.getNextCheckDate() != null) {
                 String[] nextCheckDateGD = sdf.format(reportHiYlgd.getNextCheckDate()).split("-");
                 map.put("nextCheckDateYear", nextCheckDateGD[0]);
                 map.put("nextCheckDateMonth", nextCheckDateGD[1]);
@@ -180,24 +173,24 @@ public class TReportHiYlgdController extends BaseController
             HistoricTaskInstanceQuery htiq = historyService.createHistoricTaskInstanceQuery();
             List<HistoricTaskInstance> htiLists = htiq.processInstanceId(reportHiYlgd.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("inspectorOneName",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("inspectorOneName", 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("yearYlgdFMaker.ftl", "压力管道年度检查报告.pdf","file:/"+ RuoYiConfig.getProfile(), map, response);
+            PDFTemplateUtil.exportPdf("yearYlgdFMaker.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) {
@@ -283,10 +276,12 @@ public class TReportHiYlgdController extends BaseController
                         .replace("\\s", "")
                         .replace("\n", "");
                 // 生成PDF文件
-                PDFTemplateUtil.createPdf("yearYlgdFMaker.ftl", pdfName, RuoYiConfig.getProfile() + "/" + now, map, response);
+                PDFTemplateUtil.createPdf("yearYlgdFMaker.ftl", pdfName,
+                        RuoYiConfig.getProfile() + "/reportHi/" + now,
+                        "file:/" + RuoYiConfig.getProfile(), map, response);
                 list.add(pdfName);
             }
-            ZipUtil.createZip(RuoYiConfig.getProfile(), now + "", year + "年压力管道年度检查历史报告.zip", list, response);
+            ZipUtil.createZip(RuoYiConfig.getProfile() + "/reportHi/", now + "", year + "年压力管道年度检查历史报告.zip", list, response);
         } catch (Exception e) {
             e.printStackTrace();
         } finally {

+ 4 - 2
master/src/main/java/com/ruoyi/project/sems/controller/TReportHiYlrqController.java

@@ -277,11 +277,13 @@ public class TReportHiYlrqController extends BaseController {
                         .replace("\\s", "")
                         .replace("\n", "");
                 // 生成PDF文件
-                PDFTemplateUtil.createPdf("yearYlrqFMaker.ftl", pdfName, RuoYiConfig.getProfile() + "/" + now, map, response);
+                PDFTemplateUtil.createPdf("yearYlrqFMaker.ftl", pdfName,
+                        RuoYiConfig.getProfile() + "/reportHi/" + now,
+                        "file:/" + RuoYiConfig.getProfile(), map, response);
                 list.add(pdfName);
                 //PDFTemplateUtil.exportPdf("yearYlrqFMaker.ftl", pdfName, "file:/" + RuoYiConfig.getProfile(), map, response);
             }
-            ZipUtil.createZip(RuoYiConfig.getProfile(), now + "", year + "年压力容器年度检查历史报告.zip", list, response);
+            ZipUtil.createZip(RuoYiConfig.getProfile() + "/reportHi/", now + "", year + "年压力容器年度检查历史报告.zip", list, response);
         } catch (Exception e) {
             e.printStackTrace();
         } finally {