From 82ce59218139d9fefeae7b9e5fbc88b499ff023f Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 08 十月 2026 13:35:06 +0800
Subject: [PATCH] feat(inspect): 新增新聚检验订单编辑功能并优化报告生成流程 - 新增 updateNewJuInsOrder 接口支持新聚检验订单修改 - 增加文件上传大小限制至200MB,请求大小限制至400MB - 在设备信息中新增出厂编号字段显示 - 优化温湿度处理逻辑,报告中仅显示温度信息 - 新增印章管理功能,支持MA标志章、报告章和骑缝章配置 - 完善检验报告生成流程,增加多种报告类型常量定义 - 优化附件上传功能,增加空值检查和返回值处理 - 调整委托编号生成逻辑,完善新聚订单可编辑性判断 - 更新CNAS流程中报告编号使用正式报告编号替代委托编号

---
 cnas-process/src/main/java/com/ruoyi/process/service/impl/ProcessReportServiceImpl.java |  200 +++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 172 insertions(+), 28 deletions(-)

diff --git a/cnas-process/src/main/java/com/ruoyi/process/service/impl/ProcessReportServiceImpl.java b/cnas-process/src/main/java/com/ruoyi/process/service/impl/ProcessReportServiceImpl.java
index a92b478..42c93eb 100644
--- a/cnas-process/src/main/java/com/ruoyi/process/service/impl/ProcessReportServiceImpl.java
+++ b/cnas-process/src/main/java/com/ruoyi/process/service/impl/ProcessReportServiceImpl.java
@@ -3,6 +3,7 @@
 import cn.hutool.core.lang.UUID;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.deepoove.poi.XWPFTemplate;
@@ -13,14 +14,20 @@
 import com.ruoyi.common.core.domain.entity.User;
 import com.ruoyi.common.utils.QueryWrappers;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.SignatureImageUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ruoyi.framework.exception.ErrorException;
+import com.ruoyi.inspect.mapper.InsOrderMapper;
+import com.ruoyi.inspect.mapper.InsReportMapper;
+import com.ruoyi.inspect.pojo.InsOrder;
+import com.ruoyi.inspect.pojo.InsReport;
 import com.ruoyi.inspect.util.HackLoopTableRenderPolicy;
+import com.ruoyi.process.dto.ProcessReportDto;
 import com.ruoyi.process.mapper.ProcessReportMapper;
 import com.ruoyi.process.pojo.ProcessReport;
 import com.ruoyi.process.service.ProcessReportService;
 import com.ruoyi.system.mapper.UserMapper;
 import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.xwpf.usermodel.*;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -31,11 +38,14 @@
 import java.io.*;
 import java.net.URLEncoder;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 /**
@@ -52,45 +62,177 @@
 
     @Resource
     private ProcessReportMapper processReportMapper;
-
-
+    @Value("${file.path}")
+    private String imgUrl;
     @Value("${wordUrl}")
     private String wordUrl;
 
     @Resource
     private UserMapper userMapper;
 
+    @Resource
+    private InsReportMapper insReportMapper;
+
+    @Resource
+    private InsOrderMapper insOrderMapper;
+
     @Override
-    public IPage<ProcessReport> pageProcessReport(Page page, ProcessReport processReport) {
-        //todo 浠呯湅鎴�
-        IPage<ProcessReport> processReportIPage = processReportMapper.pageProcessReport(page, QueryWrappers.queryWrappers(processReport));
-//        for (ProcessReport record : processReportIPage.getRecords()) {
-//            List<String> name = new ArrayList<>();
-//            for (String s : record.getSignatory().split(",")) {
-//                User user = userMapper.selectById(Integer.parseInt(s));
-//                name.add(user.getName());
-//            }
-//            String signatoryName = name.stream().collect(Collectors.joining(","));
-//            record.setSignatoryName(signatoryName);
-//        }
+    public IPage<ProcessReportDto> pageProcessReport(Page page, ProcessReportDto processReport) {
+        // #21 鎵撳紑鍒楄〃鏃讹紝鑷姩甯﹀嚭宸查�氳繃瀹℃壒锛堟壒鍑嗙姸鎬�=鎵瑰噯锛変絾灏氭湭鐧昏鐨勬楠屽崟
+        autoBringOutApproved();
+        IPage<ProcessReportDto> processReportIPage = processReportMapper.pageProcessReport(page, QueryWrappers.queryWrappers(processReport));
 
         return processReportIPage;
     }
 
+    /**
+     * 鎵弿宸叉壒鍑嗕絾灏氭湭杩涘叆鎶ュ憡缁撴灉鐧昏琛ㄧ殑妫�楠屾姤鍛婏紝鑷姩鐢熸垚寰呯櫥璁拌褰曪紙浠ユ姤鍛婄紪鍙峰幓閲嶏紝骞傜瓑锛夈��
+     */
+    private void autoBringOutApproved() {
+        List<InsReport> approved = insReportMapper.selectList(Wrappers.<InsReport>lambdaQuery()
+                .eq(InsReport::getIsRatify, 1)
+                .eq(InsReport::getIsPass, 1));
+        if (approved.isEmpty()) {
+            return;
+        }
+        Set<String> existing = this.list(Wrappers.<ProcessReport>lambdaQuery()
+                .select(ProcessReport::getInsReportCode)).stream()
+                .map(ProcessReport::getInsReportCode)
+                .filter(StringUtils::isNotBlank)
+                .collect(Collectors.toCollection(HashSet::new));
+        for (InsReport report : approved) {
+            String code = report.getCode();
+            if (StringUtils.isBlank(code) || existing.contains(code)) {
+                continue;
+            }
+            ProcessReport pr = new ProcessReport();
+            pr.setInsReportCode(code);
+            pr.setInspectionOrderId(report.getInsOrderId());
+            if (report.getRatifyTime() != null) {
+                pr.setSendTime(report.getRatifyTime().toLocalDate());
+            }
+            if (report.getInsOrderId() != null) {
+                InsOrder order = insOrderMapper.selectById(report.getInsOrderId());
+                if (order != null) {
+                    pr.setSend(order.getCompany());
+                    pr.setMethod(getReportDeliveryName(order));
+                }
+            }
+            this.save(pr);
+            existing.add(code);
+        }
+    }
+
+    private String getReportDeliveryName(InsOrder order) {
+        if (order.getReportDelivery() != null) {
+            switch (order.getReportDelivery()) {
+                case 1:
+                    return "鑷彇";
+                case 2:
+                    return "蹇��";
+                case 3:
+                    return "鐢靛瓙浼犻��";
+                default:
+                    break;
+            }
+        }
+        // 鍏煎灏氭湭缁存姢 report_delivery 鐨勫巻鍙插鎵樺崟銆�
+        return order.getSend() != null && order.getSend() == 1 ? "鑷彇" : "鍏朵粬";
+    }
+
     @Override
-    public void exportProcessReport(List<Integer> ids, HttpServletResponse response) {
-        List<ProcessReport> processReports = processReportMapper.getIds(ids);
-//        for (ProcessReport record : processReports) {
-//            List<String> name = new ArrayList<>();
-//            if(StringUtils.isNotBlank(record.getSignatory())){
-//                for (String s : record.getSignatory().split(",")) {
-//                    User user = userMapper.selectById(Integer.parseInt(s));
-//                    name.add(user.getName());
-//                }
-//                String signatoryName = name.stream().collect(Collectors.joining(","));
-//                record.setSignatoryName(signatoryName);
-//            }
-//        }
+    public void downloadStampedReport(Integer id, String format, HttpServletResponse response) {
+        if (id == null) {
+            throw new ErrorException("鎶ュ憡缁撴灉涓嶈兘涓虹┖");
+        }
+        ProcessReport processReport = getById(id);
+        if (processReport == null) {
+            throw new ErrorException("鎶ュ憡缁撴灉涓嶅瓨鍦�");
+        }
+        if (StringUtils.isBlank(processReport.getInsReportCode())
+                && processReport.getInspectionOrderId() == null) {
+            throw new ErrorException("璇ヨ褰曟湭鍏宠仈妫�楠屾姤鍛婏紝鏃犳硶涓嬭浇");
+        }
+
+        String downloadFormat = StringUtils.isBlank(format) ? "pdf" : format.trim().toLowerCase();
+        if (!"pdf".equals(downloadFormat) && !"word".equals(downloadFormat)) {
+            throw new ErrorException("涓嬭浇鏍煎紡涓嶆纭�");
+        }
+
+        com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<InsReport> query =
+                Wrappers.<InsReport>lambdaQuery()
+                        .eq(InsReport::getIsRatify, 1)
+                        .eq(StringUtils.isNotBlank(processReport.getInsReportCode()),
+                                InsReport::getCode, processReport.getInsReportCode())
+                        .eq(processReport.getInspectionOrderId() != null,
+                                InsReport::getInsOrderId, processReport.getInspectionOrderId())
+                        .orderByDesc(InsReport::getId)
+                        .last("limit 1");
+        InsReport report = insReportMapper.selectOne(query);
+        if (report == null) {
+            throw new ErrorException("鏈壘鍒板凡鎵瑰噯鐨勬姤鍛婏紝鏃犳硶涓嬭浇鏈夌珷鎶ュ憡");
+        }
+
+        String fileUrl;
+        String extension;
+        String contentType;
+        if ("word".equals(downloadFormat)) {
+            fileUrl = StringUtils.isNotBlank(report.getUrlS()) ? report.getUrlS() : report.getUrl();
+            extension = ".docx";
+            contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
+        } else {
+            fileUrl = report.getTempUrlPdf();
+            extension = ".pdf";
+            contentType = "application/pdf";
+        }
+        if ("pdf".equals(downloadFormat) && StringUtils.isBlank(fileUrl)) {
+            String reportUrl = StringUtils.isNotBlank(report.getUrlS()) ? report.getUrlS() : report.getUrl();
+            if (StringUtils.isNotBlank(reportUrl) && reportUrl.toLowerCase().endsWith(".docx")) {
+                fileUrl = reportUrl.substring(0, reportUrl.length() - 5) + ".pdf";
+            }
+        }
+        if (StringUtils.isBlank(fileUrl) || !fileUrl.replace('\\', '/').startsWith("/word/")) {
+            throw new ErrorException("鏈夌珷鎶ュ憡灏氭湭鐢熸垚锛岃鍏堝畬鎴愭姤鍛婃壒鍑�");
+        }
+
+        Path root = Paths.get(wordUrl).toAbsolutePath().normalize();
+        Path file = root.resolve(fileUrl.replace('\\', '/').substring("/word/".length())).normalize();
+        if (!file.startsWith(root) || !Files.isRegularFile(file)) {
+            throw new ErrorException("鏈夌珷鎶ュ憡鏂囦欢涓嶅瓨鍦紝璇烽噸鏂版壒鍑嗙敓鎴�");
+        }
+
+        try {
+            String filename = StringUtils.isNotBlank(processReport.getInsReportCode())
+                    ? processReport.getInsReportCode() + extension : file.getFileName().toString();
+            String encodedName = URLEncoder.encode(filename, "UTF-8").replace("+", "%20");
+            response.setContentType(contentType);
+            response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedName);
+            response.setHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename");
+            response.setHeader("download-filename", encodedName);
+            response.setContentLengthLong(Files.size(file));
+            try (InputStream inputStream = Files.newInputStream(file);
+                 OutputStream outputStream = response.getOutputStream()) {
+                IOUtils.copy(inputStream, outputStream);
+                outputStream.flush();
+            }
+        } catch (IOException e) {
+            throw new ErrorException("鏈夌珷鎶ュ憡涓嬭浇澶辫触");
+        }
+    }
+
+    @Override
+    public void exportProcessReport(ProcessReportDto dto, HttpServletResponse response) {
+        List<ProcessReportDto> processReports = processReportMapper.exportProcessReport();
+        for (ProcessReportDto processReport : processReports) {
+            // 鍙戦�佷汉鐢熸垚绛惧悕鍥剧墖
+            processReport.setSendUserRender(StringUtils.isNotBlank(processReport.getSendUserUrl())
+                    ? Pictures.ofLocal(imgUrl + "/" + processReport.getSendUserUrl()).create() : null);
+
+            // 绛炬敹浜虹敓鎴愬浘鐗�
+            processReport.setSignatoryRender(StringUtils.isNotBlank(processReport.getSignatory())
+                    ? Pictures.ofStream(SignatureImageUtil.saveImageToFile(processReport.getSignatory())).create() : null);
+        }
+
         // 鑾峰彇璺緞
         InputStream inputStream = this.getClass().getResourceAsStream("/static/report-deal.docx");
         Configure configure = Configure.builder()
@@ -110,6 +252,8 @@
             template.write(os);
             os.flush();
             os.close();
+            inputStream.close();
+            inputStream.close();
         } catch (Exception e) {
             e.printStackTrace();
             throw new RuntimeException("瀵煎嚭澶辫触");

--
Gitblit v1.9.3