feat(inspect): 完善检验报告功能与数据处理
- 添加重新生成报告的功能接口
- 优化管理员权限判断逻辑,允许管理员查看全部待复核任务
- 改进Excel数据解析逻辑,支持合并单元格的坐标计算
- 完善直绑模板订单的检验结果处理机制
- 优化报告下载接口,支持按报告类型选择
- 提升附件上传大小限制至200MB
已添加1个文件
已修改10个文件
458 ■■■■ 文件已修改
basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardMethodServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/ruoyi/inspect/controller/InsReportController.java 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/ruoyi/inspect/pojo/InsReport.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/ruoyi/inspect/service/InsOrderPlanService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/ruoyi/inspect/service/InsReportService.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java 320 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java 87 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/resources/mapper/InsReportMapper.xml 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/resources/static/inspection-report-template-v2.docx 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/CustomController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/Custom.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardMethodServiceImpl.java
@@ -244,8 +244,8 @@
    @Override
    public StandardMethodAttachment uploadAttachment(Integer standardMethodId, MultipartFile file) {
        if (standardMethodMapper.selectById(standardMethodId) == null) throw new BaseException("标准不存在");
        if (file == null || file.isEmpty() || file.getSize() > 10 * 1024 * 1024)
            throw new BaseException("附件不能为空且不能超过10MB");
        if (file == null || file.isEmpty() || file.getSize() > 200L * 1024 * 1024)
            throw new BaseException("附件不能为空且不能超过200MB");
        String originalName = file.getOriginalFilename();
        if (originalName == null || !originalName.matches("(?i).+\\.(jpg|jpeg|png|gif|doc|docx|xls|xlsx|ppt|pptx|pdf|zip|rar)$"))
            throw new BaseException("不支持的附件格式");
@@ -391,7 +391,6 @@
    }
}
inspect-server/src/main/java/com/ruoyi/inspect/controller/InsReportController.java
@@ -10,6 +10,7 @@
import com.ruoyi.common.core.domain.Result;
import com.ruoyi.framework.exception.ErrorException;
import com.ruoyi.inspect.dto.ReportPageDto;
import com.ruoyi.inspect.service.InsOrderPlanService;
import com.ruoyi.inspect.service.InsReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -37,6 +38,9 @@
    @Resource
    private InsReportService insReportService;
    @Resource
    private InsOrderPlanService insOrderPlanService;
    @Value("${wordUrl}")
    private String wordUrl;
@@ -150,12 +154,21 @@
        return Result.success(insReportService.downAll(ids));
    }
    @ApiOperation(value = "报告下载")
    @ApiOperation(value = "报告下载(reportType:0检测报告,1检验报告)")
    @GetMapping("/download")
    @PreAuthorize("@ss.hasPermi('business:reportPreparation')")
    @PersonalScope(permsName = "business:reportPreparation", objectName = ReportPageDto.class, paramName = "createOrderUser")
    public void download(Integer id, ReportPageDto reportPageDto, HttpServletResponse response) {
        insReportService.download(id, reportPageDto.getCreateOrderUser(), response);
    public void download(Integer id, Integer reportType, ReportPageDto reportPageDto, HttpServletResponse response) {
        insReportService.download(id, reportType, reportPageDto.getCreateOrderUser(), response);
    }
    @ApiOperation(value = "重新生成报告")
    @PostMapping("/regenerate")
//    @PreAuthorize("@ss.hasPermi('business:reportPreparation')")
    @PersonalScope(permsName = "business:reportPreparation", objectName = ReportPageDto.class, paramName = "createOrderUser")
    public Result regenerate(@RequestBody ReportPageDto reportPageDto) {
        insOrderPlanService.regenerateReport(reportPageDto.getId(), reportPageDto.getCreateOrderUser());
        return Result.success();
    }
    @ApiOperation(value = "报告批量上传")
inspect-server/src/main/java/com/ruoyi/inspect/pojo/InsReport.java
@@ -41,6 +41,12 @@
    private String url;
    /**
     * 系统生成的检验报告地址;与 url 对应的检测报告共用同一条审批记录。
     */
    @ApiModelProperty("检验报告地址")
    private String inspectionUrl;
    /**
     * 手动上传报告地址
     */
    @ApiModelProperty("创建时间")
inspect-server/src/main/java/com/ruoyi/inspect/service/InsOrderPlanService.java
@@ -59,6 +59,11 @@
    int rawMaterialVerifyPlan(VerifyPlanDto verifyPlanDto);
    /**
     * 按当前检验数据重新生成尚未批准的系统报告。
     */
    void regenerateReport(Integer reportId, Integer createOrderUser);
    /**
     * 电缆配置. 查看标识
     * @param id
     * @param laboratory
inspect-server/src/main/java/com/ruoyi/inspect/service/InsReportService.java
@@ -41,8 +41,10 @@
    String downAll(String ids);
    /** 单份报告 Word 下载,createOrderUser 用于复用报告编制的数据范围。 */
    void download(Integer id, Integer createOrderUser, HttpServletResponse response);
    /**
     * 单份报告 Word 下载,reportType:0检测报告,1检验报告;createOrderUser 用于复用报告编制的数据范围。
     */
    void download(Integer id, Integer reportType, Integer createOrderUser, HttpServletResponse response);
    int upAll(MultipartFile file) throws IOException;
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
@@ -178,8 +178,12 @@
        String userName = null;
        Integer userId = null;
        if (ObjectUtil.isNotEmpty(insOrderPlanDTO.getUserId())) {
            userId = SecurityUtils.getUserId().intValue();
            userName = userMapper.selectById(userId).getName();
            Integer currentUserId = SecurityUtils.getUserId().intValue();
            // 管理员可以查看并复核全部待复核任务,普通用户仍只查看分配给自己的任务。
            if (!SecurityUtils.isAdmin(currentUserId.longValue())) {
                userId = currentUserId;
                userName = userMapper.selectById(userId).getName();
            }
            insOrderPlanDTO.setUserId(null);
        }
        Integer isCheck = insOrderPlanDTO.getIsCheck();
@@ -745,18 +749,9 @@
        } catch (Exception ignored) {
            thing = compressedThing;
        }
        JSONArray cellData = JSON.parseObject(thing).getJSONArray("data").getJSONObject(0).getJSONArray("celldata");
        JSONObject sheet = JSON.parseObject(thing).getJSONArray("data").getJSONObject(0);
        JSONArray cellData = sheet.getJSONArray("celldata");
        NavigableMap<Integer, List<String>> result = new TreeMap<>();
        Integer inspectionResultColumn = null;
        for (Object item : cellData) {
            JSONObject cell = JSON.parseObject(JSON.toJSONString(item));
            Integer column = cell.getInteger("c");
            JSONObject value = cell.getJSONObject("v");
            String displayValue = value == null ? null : value.getString("v");
            if (inspectionResultColumn == null && "检验结果".equals(StringUtils.trim(displayValue))) {
                inspectionResultColumn = column;
            }
        }
        for (Object item : cellData) {
            JSONObject cell = JSON.parseObject(JSON.toJSONString(item));
            JSONObject value = cell.getJSONObject("v");
@@ -767,16 +762,119 @@
            Integer row = cell.getInteger("r");
            Integer column = cell.getInteger("c");
            if (row != null && column != null) {
                // “导出值”标在检测项目标题单元格时,真正导出的值是同一行“检验结果”列的单元格。
                String coordinate = row + "-" + column;
                String resultCoordinate = row + "-" + inspectionResultColumn;
                if (inspectionResultColumn != null && !Objects.equals(column, inspectionResultColumn)) {
                    coordinate = resultCoordinate;
                }
                // 批注单元格可能横向合并,右侧结果单元格也可能纵向合并;最终读取结果区域的左上角存储坐标。
                String coordinate = getRightAdjacentCoordinate(sheet, row, column);
                result.computeIfAbsent(row, ignored -> new ArrayList<>()).add(coordinate);
            }
        }
        return result;
    }
    /**
     * 返回指定单元格(或其所在合并区域)右侧紧邻列的下标。
     * Luckysheet 的合并信息通常保存在 config.merge;部分历史模板只在单元格 v.mc 中保留,
     * 因此两种结构都要兼容。
     */
    private int getRightAdjacentColumn(JSONObject sheet, int row, int column) {
        int rightEdge = column;
        JSONObject config = sheet == null ? null : sheet.getJSONObject("config");
        JSONObject merges = config == null ? null : config.getJSONObject("merge");
        if (merges != null) {
            for (Object rawMerge : merges.values()) {
                rightEdge = extendMergedRightEdge(rightEdge, row, column, rawMerge);
            }
        }
        JSONArray cellData = sheet == null ? null : sheet.getJSONArray("celldata");
        if (cellData != null) {
            for (Object rawCell : cellData) {
                JSONObject cell = JSON.parseObject(JSON.toJSONString(rawCell));
                JSONObject value = cell == null ? null : cell.getJSONObject("v");
                JSONObject merge = value == null ? null : value.getJSONObject("mc");
                rightEdge = extendMergedRightEdge(rightEdge, row, column, merge);
            }
        }
        return rightEdge + 1;
    }
    private String getRightAdjacentCoordinate(JSONObject sheet, int row, int column) {
        int adjacentColumn = getRightAdjacentColumn(sheet, row, column);
        int[] anchor = findMergedAnchor(sheet, row, adjacentColumn);
        return anchor[0] + "-" + anchor[1];
    }
    /**
     * Luckysheet 只在合并区域左上角保存实际值。若目标单元格位于合并区域内部,
     * 将其转换为该区域的左上角坐标;未合并则返回原坐标。
     */
    private int[] findMergedAnchor(JSONObject sheet, int row, int column) {
        JSONObject config = sheet == null ? null : sheet.getJSONObject("config");
        JSONObject merges = config == null ? null : config.getJSONObject("merge");
        if (merges != null) {
            for (Object rawMerge : merges.values()) {
                int[] anchor = findMergedAnchor(row, column, rawMerge);
                if (anchor != null) {
                    return anchor;
                }
            }
        }
        JSONArray cellData = sheet == null ? null : sheet.getJSONArray("celldata");
        if (cellData != null) {
            for (Object rawCell : cellData) {
                JSONObject cell = JSON.parseObject(JSON.toJSONString(rawCell));
                JSONObject value = cell == null ? null : cell.getJSONObject("v");
                int[] anchor = findMergedAnchor(row, column,
                        value == null ? null : value.getJSONObject("mc"));
                if (anchor != null) {
                    return anchor;
                }
            }
        }
        return new int[]{row, column};
    }
    private int[] findMergedAnchor(int row, int column, Object rawMerge) {
        if (rawMerge == null) {
            return null;
        }
        JSONObject merge = rawMerge instanceof JSONObject
                ? (JSONObject) rawMerge : JSON.parseObject(JSON.toJSONString(rawMerge));
        Integer startRow = merge.getInteger("r");
        Integer startColumn = merge.getInteger("c");
        Integer rowSpan = merge.getInteger("rs");
        Integer columnSpan = merge.getInteger("cs");
        if (startRow == null || startColumn == null || rowSpan == null || columnSpan == null
                || rowSpan < 1 || columnSpan < 1) {
            return null;
        }
        if (row >= startRow && row < startRow + rowSpan
                && column >= startColumn && column < startColumn + columnSpan) {
            return new int[]{startRow, startColumn};
        }
        return null;
    }
    private int extendMergedRightEdge(int currentRightEdge, int row, int column, Object rawMerge) {
        if (rawMerge == null) {
            return currentRightEdge;
        }
        JSONObject merge = rawMerge instanceof JSONObject
                ? (JSONObject) rawMerge : JSON.parseObject(JSON.toJSONString(rawMerge));
        Integer startRow = merge.getInteger("r");
        Integer startColumn = merge.getInteger("c");
        Integer rowSpan = merge.getInteger("rs");
        Integer columnSpan = merge.getInteger("cs");
        if (startRow == null || startColumn == null || rowSpan == null || columnSpan == null
                || rowSpan < 1 || columnSpan < 1) {
            return currentRightEdge;
        }
        int endRow = startRow + rowSpan - 1;
        int endColumn = startColumn + columnSpan - 1;
        if (row >= startRow && row <= endRow && column >= startColumn && column <= endColumn) {
            return Math.max(currentRightEdge, endColumn);
        }
        return currentRightEdge;
    }
    /**
@@ -794,7 +892,7 @@
    }
    /**
     * 直绑模板订单只校验模板中标记为“导出值”的单元格,不使用检验项状态或 last_value 判定。
     * 直绑模板订单只校验每个“导出值”批注所在区域右侧紧邻单元格,不使用检验项状态或 last_value 判定。
     */
    private List<String> getMissingTemplateExportValues(Integer orderId) {
        List<InsOrderStandardTemplate> snapshots = insOrderStandardTemplateService.list(
@@ -1532,6 +1630,10 @@
            refreshed.setRecordValues(templateRecordValuesMap.get(templateId));
            refreshed.setTemperature(templateTemperatureMap.get(templateId));
            refreshed.setHumidity(templateHumidityMap.get(templateId));
            // 刷新模板结构时必须保留检验阶段填写的业务数据,避免进入复核后回显为空。
            refreshed.setDetectionTime(oldSnapshot == null ? null : oldSnapshot.getDetectionTime());
            refreshed.setDetectionPlace(oldSnapshot == null ? null : oldSnapshot.getDetectionPlace());
            refreshed.setInsResult(oldSnapshot == null ? null : oldSnapshot.getInsResult());
            Integer templateSort = templateSortMap.get(templateId);
            refreshed.setSort(templateSort == null ? nextTemplateSort++ : templateSort);
            refreshedSnapshots.add(refreshed);
@@ -1586,12 +1688,13 @@
        InsReport existingReport = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery()
                .eq(InsReport::getInsOrderId, orderId)
                .last("limit 1"));
        boolean directTemplateOrder = isDirectTemplateOrder(orderId);
        if (currentState != null && Objects.equals(currentState.getInsState(), 5)
                && existingReport != null && StringUtils.isNotBlank(existingReport.getUrl())) {
                && existingReport != null && StringUtils.isNotBlank(existingReport.getUrl())
                && (!directTemplateOrder || StringUtils.isNotBlank(existingReport.getInspectionUrl()))) {
            // 防止复核页面重复点击或网络重试重复生成报告、重复发起报告审批。
            return 1;
        }
        boolean directTemplateOrder = isDirectTemplateOrder(orderId);
        if (directTemplateOrder && Objects.equals(type, 1)
                && !Objects.equals(dto.getInsResult(), 0) && !Objects.equals(dto.getInsResult(), 1)) {
            throw new ErrorException("请选择检验单结论");
@@ -1640,15 +1743,22 @@
                    .eq(InsOrder::getId, orderId)
                    .set(InsOrder::getInsState, 5));
            // 检验人员提交复核时不再生成报告;仅在全部试验室复核通过后生成检测报告。
            // 检验人员提交复核时不生成报告;全部试验室复核通过后生成报告。
            if (report == null || StringUtils.isBlank(report.getUrl())) {
                this.generateReport(orderId, DETECTION_REPORT, writeUserId);
                report = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery()
                        .eq(InsReport::getInsOrderId, orderId)
                        .last("limit 1"));
            }
            // 直绑模板订单同时生成检验报告,两份文件共用同一条审批记录。
            if (directTemplateOrder && (report == null || StringUtils.isBlank(report.getInspectionUrl()))) {
                this.generateReport(orderId, INSPECTION_REPORT, writeUserId);
            }
            report = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery()
                    .eq(InsReport::getInsOrderId, orderId)
                    .last("limit 1"));
            if (report == null || StringUtils.isBlank(report.getUrl())) {
                throw new ErrorException("检测报告生成失败");
            }
            if (directTemplateOrder && StringUtils.isBlank(report.getInspectionUrl())) {
                throw new ErrorException("检验报告生成失败");
            }
            if (report.getTempUrlPdf() == null) {
                String tempUrlPdf = this.wordToPdfTemp(report.getUrl().replace("/word", wordUrl));
@@ -1798,6 +1908,101 @@
            throw new ErrorException("找不到当前检验任务的检验人,无法生成检测报告");
        }
        return inspector.getUserId();
    }
    /**
     * 重新生成尚未批准的系统报告,并恢复已存在的编制、审核签名。
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void regenerateReport(Integer reportId, Integer createOrderUser) {
        if (reportId == null) {
            throw new ErrorException("报告不能为空");
        }
        InsReport accessibleReport = insReportMapper.selectDownloadableReport(reportId, createOrderUser);
        if (accessibleReport == null) {
            throw new ErrorException("报告不存在、尚未生成或无权操作");
        }
        // 数据库行锁避免同一报告被多人同时重新生成并覆盖。
        InsReport report = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery()
                .eq(InsReport::getId, reportId)
                .last("FOR UPDATE"));
        if (report == null) {
            throw new ErrorException("报告不存在");
        }
        if (Objects.equals(report.getIsRatify(), 1)) {
            throw new ErrorException("已批准报告不能重新生成");
        }
        if (StringUtils.isNotBlank(report.getUrlS())) {
            throw new ErrorException("当前报告已手动上传,请先还原为系统报告后再重新生成");
        }
        if (report.getInsOrderId() == null) {
            throw new ErrorException("报告未关联检验单,无法重新生成");
        }
        Integer reportType = report.getReportType() == null ? DETECTION_REPORT : report.getReportType();
        Integer writeUserId = report.getWriteUserId() == null
                ? SecurityUtils.getUserId().intValue() : report.getWriteUserId();
        boolean directTemplateOrder = isDirectTemplateOrder(report.getInsOrderId());
        if (directTemplateOrder) {
            generateReport(report.getInsOrderId(), DETECTION_REPORT, writeUserId);
            generateReport(report.getInsOrderId(), INSPECTION_REPORT, writeUserId);
        } else {
            generateReport(report.getInsOrderId(), reportType, writeUserId);
        }
        InsReport regenerated = insReportMapper.selectById(reportId);
        if (regenerated == null || StringUtils.isBlank(regenerated.getUrl())) {
            throw new ErrorException("报告重新生成失败");
        }
        if (directTemplateOrder && StringUtils.isBlank(regenerated.getInspectionUrl())) {
            throw new ErrorException("检验报告重新生成失败");
        }
        String reportPath = regenerated.getUrl().replace("/word", wordUrl);
        Map<String, Object> marks = buildExistingReportMarks(report);
        if (!marks.isEmpty()) {
            insReportService.wordInsertUrl(marks, reportPath);
            if (StringUtils.isNotBlank(regenerated.getInspectionUrl())) {
                insReportService.wordInsertUrl(marks,
                        regenerated.getInspectionUrl().replace("/word", wordUrl));
            }
        }
        String tempPdfName = wordToPdfTemp(reportPath);
        if (StringUtils.isBlank(tempPdfName)) {
            throw new ErrorException("报告预览文件生成失败");
        }
        // generateReport 会写入当前时间;重新生成不应改变原审批记录时间。
        insReportMapper.update(null, Wrappers.<InsReport>lambdaUpdate()
                .eq(InsReport::getId, reportId)
                .set(InsReport::getWriteTime, report.getWriteTime())
                .set(InsReport::getTempUrlPdf, "/word/" + tempPdfName));
    }
    private Map<String, Object> buildExistingReportMarks(InsReport report) {
        Map<String, Object> marks = new HashMap<>();
        boolean submitted = Objects.equals(report.getState(), 1)
                || report.getIsExamine() != null
                || report.getExamineTime() != null;
        if (submitted) {
            User writer = getReportSigner(report.getWriteUserId(), "编制人");
            marks.put("writeUrl", Pictures.ofLocal(imgUrl + "/" + writer.getSignatureUrl()).create());
            marks.put("writeDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(report.getWriteTime())).create());
            marks.put("insUrl", Pictures.ofLocal(imgUrl + "/" + writer.getSignatureUrl()).create());
        }
        if (Objects.equals(report.getIsExamine(), 1)) {
            User examiner = getReportSigner(report.getExamineUserId(), "审核人");
            marks.put("examineUrl", Pictures.ofLocal(imgUrl + "/" + examiner.getSignatureUrl()).create());
            marks.put("examineDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(report.getExamineTime())).create());
        }
        return marks;
    }
    private User getReportSigner(Integer userId, String roleName) {
        User user = userId == null ? null : userMapper.selectById(userId);
        if (user == null || StringUtils.isBlank(user.getSignatureUrl())) {
            throw new ErrorException("找不到" + roleName + "的签名");
        }
        return user;
    }
    /**
@@ -3038,9 +3243,9 @@
                    }
                }
            }
            // 新版检测报告直接使用固定四列结果行,不再构造旧版可变列 TableRenderData。
            // 检验报告仍沿用下方原有的大表格逻辑。
            if (!showResult) {
            // 直绑模板的检测报告、检验报告都使用新版固定结果行,不再进入旧版检验项表格逻辑。
            // 直绑模板中的承载记录没有旧检验项字段,进入旧逻辑会在格式化时产生空指针。
            if (!showResult || directTemplateOrder) {
                return;
            }
            // 收样日期
@@ -3445,8 +3650,9 @@
                ? "微库仑法,有机氯含量小于0.005%时,以未检出报出。"
                : defaultReportText(insOrder.getRemark(), "/");
        // 检测报告和检验报告统一使用新版报告模板
        String templateName = "/static/detection-report-template-v2.docx";
        String templateName = showResult
                ? "/static/inspection-report-template-v2.docx"
                : "/static/detection-report-template-v2.docx";
        InputStream inputStream = this.getClass().getResourceAsStream(templateName);
        if (inputStream == null) {
            throw new RuntimeException("找不到报告模板: " + templateName);
@@ -3533,7 +3739,7 @@
                    put("resultNote", finalResultRemark);
                }});
        try {
            String name = insReport.getCode().replace("/", "") + (showResult ? ".docx" : "-C.docx");
            String name = insReport.getCode().replace("/", "") + (showResult ? "-J.docx" : "-C.docx");
            Files.createDirectories(Paths.get(wordUrl));
            template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl, name)));
            insReport.setUrl("/word/" + name);
@@ -3550,6 +3756,22 @@
        InsReport existing = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery()
                .eq(InsReport::getInsOrderId, report.getInsOrderId())
                .last("limit 1"));
        if (Objects.equals(report.getReportType(), INSPECTION_REPORT)) {
            String inspectionUrl = report.getUrl();
            if (existing == null) {
                report.setReportType(DETECTION_REPORT);
                report.setUrl(null);
                report.setInspectionUrl(inspectionUrl);
                insReportMapper.insert(report);
            } else {
                insReportMapper.update(null, Wrappers.<InsReport>lambdaUpdate()
                        .eq(InsReport::getId, existing.getId())
                        .set(InsReport::getInspectionUrl, inspectionUrl)
                        .set(InsReport::getWriteUserId, report.getWriteUserId())
                        .set(InsReport::getWriteTime, report.getWriteTime()));
            }
            return;
        }
        if (existing == null) {
            insReportMapper.insert(report);
            return;
@@ -3591,6 +3813,7 @@
                row.put("itemName", itemName);
                row.put("unit", defaultReportText(product.getUnit(), "/"));
                row.put("result", defaultReportText(product.getLastValue(), "/"));
                row.put("inspectionConclusion", formatInspectionConclusion(product.getInsResult()));
                rows.add(row);
            }
        }
@@ -3629,6 +3852,7 @@
                row.put("itemName", formatExportItemName(reportItemName));
                row.put("unit", defaultReportText(unit, "/"));
                row.put("result", result);
                row.put("inspectionConclusion", formatInspectionConclusion(snapshot.getInsResult()));
                rows.add(row);
            }
        }
@@ -3636,6 +3860,16 @@
            throw new ErrorException("当前订单未找到可生成报告的原始记录模板");
        }
        return rows;
    }
    private static String formatInspectionConclusion(Integer insResult) {
        if (Objects.equals(insResult, 1)) {
            return "合格";
        }
        if (Objects.equals(insResult, 0)) {
            return "不合格";
        }
        return "/";
    }
    private List<TemplateExportCell> getTemplateExportCells(String compressedThing) {
@@ -3648,9 +3882,8 @@
        } catch (Exception ignored) {
            thing = compressedThing;
        }
        JSONArray cellData = JSON.parseObject(thing).getJSONArray("data").getJSONObject(0).getJSONArray("celldata");
        Integer resultColumn = null;
        Integer itemColumn = null;
        JSONObject sheet = JSON.parseObject(thing).getJSONArray("data").getJSONObject(0);
        JSONArray cellData = sheet.getJSONArray("celldata");
        Integer unitColumn = null;
        List<int[]> exportCells = new ArrayList<>();
        Map<String, String> templateValues = new HashMap<>();
@@ -3664,13 +3897,6 @@
            }
            String displayValue = value.get("v") == null ? null : String.valueOf(value.get("v"));
            templateValues.put(row + "-" + column, displayValue);
            if (resultColumn == null && "检验结果".equals(StringUtils.trim(displayValue))) {
                resultColumn = column;
            }
            if (itemColumn == null && ("检测项目".equals(StringUtils.trim(displayValue))
                    || "检验项目".equals(StringUtils.trim(displayValue)))) {
                itemColumn = column;
            }
            if (unitColumn == null && "单位".equals(StringUtils.trim(displayValue))) {
                unitColumn = column;
            }
@@ -3685,13 +3911,9 @@
        exportCells.sort(Comparator.comparingInt((int[] cell) -> cell[0]).thenComparingInt(cell -> cell[1]));
        List<TemplateExportCell> results = new ArrayList<>();
        for (int[] exportCell : exportCells) {
            int resultColumnForRow = resultColumn == null ? exportCell[1] : resultColumn;
            // 通常“导出值”批注配置在项目名称单元格;若配置在结果单元格,则回到“检测项目”列取名称。
            Integer itemColumnForRow = !Objects.equals(exportCell[1], resultColumnForRow)
                    ? exportCell[1] : itemColumn;
            TemplateExportCell result = new TemplateExportCell();
            result.resultCoordinate = exportCell[0] + "-" + resultColumnForRow;
            result.itemCoordinate = itemColumnForRow == null ? null : exportCell[0] + "-" + itemColumnForRow;
            result.resultCoordinate = getRightAdjacentCoordinate(sheet, exportCell[0], exportCell[1]);
            result.itemCoordinate = exportCell[0] + "-" + exportCell[1];
            result.unitCoordinate = unitColumn == null ? null : exportCell[0] + "-" + unitColumn;
            result.templateValues = templateValues;
            results.add(result);
@@ -5139,7 +5361,7 @@
                }
            }
            // 判断是否是数字类型
            if (sampleProductDto2.getInspectionValueType().equals("1")) {
            if ("1".equals(sampleProductDto2.getInspectionValueType())) {
                // 把检验内容如果正硫化点和焦烧时间把  .  切割成  :
                String lastValue = sampleProductDto2.getLastValue();
                if (sampleProductDto2.getInspectionItem().contains("正硫化点") || sampleProductDto2.getInspectionItem().contains("焦烧时间")) {
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java
@@ -86,6 +86,9 @@
@Slf4j
public class InsReportServiceImpl extends ServiceImpl<InsReportMapper, InsReport>
        implements InsReportService {
    private static final int DETECTION_REPORT = 0;
    private static final int INSPECTION_REPORT = 1;
    @Resource
    private UserMapper userMapper;
    @Resource
@@ -209,30 +212,30 @@
        info.setViewStatus(false);
        info.setJumpPath(MenuJumpPathConstants.REPORT_PREPARATION);
        informationNotificationService.addInformationNotification(info);
        //系统生成报告地址
        String url = insReport.getUrl();
        //手动上传报告地址
        String urlS = insReport.getUrlS();
        String primaryReportUrl = getPrimaryReportUrl(insReport);
        // 判断是否是原材料  需要替换****成供应商
        IfsInventoryQuantity one = ifsInventoryQuantityMapper.selectOne(new LambdaQueryWrapper<IfsInventoryQuantity>()
                .eq(IfsInventoryQuantity::getId, order.getIfsInventoryId()));
        if (one != null) {
            if (isRawMater && order.getOrderType().equals(InsOrderTypeConstants.ENTER_THE_FACTORY)) {
                changeText(new HashMap<String, String>() {{
                    put("**********", one.getSupplierName());
                }}, (StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl));
                for (String reportUrl : getApprovalReportUrls(insReport)) {
                    changeText(new HashMap<String, String>() {{
                        put("**********", one.getSupplierName());
                    }}, reportUrl.replace("/word", wordUrl));
                }
            }
        }
        wordInsertUrl(new HashMap<String, Object>() {{
        Map<String, Object> writeMarks = new HashMap<String, Object>() {{
            put("writeUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create());
            put("writeDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(null)).create());
            put("insUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create());
        }}, (StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl));
        }};
        writeMarksToReportFiles(insReport, writeMarks);
        // 修改临时pdf
        String tempUrlPdf = wordToPdfTemp((StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl));
        String tempUrlPdf = wordToPdfTemp(primaryReportUrl.replace("/word", wordUrl));
        insReport.setTempUrlPdf("/word/" + tempUrlPdf);
        insReportMapper.updateById(insReport);
@@ -330,17 +333,15 @@
        info.setViewStatus(false);
        info.setJumpPath(MenuJumpPathConstants.REPORT_PREPARATION);
        informationNotificationService.addInformationNotification(info);
        //系统生成报告地址
        String url = insReport.getUrl();
        //手动上传报告地址
        String urlS = insReport.getUrlS();
        wordInsertUrl(new HashMap<String, Object>() {{
        String primaryReportUrl = getPrimaryReportUrl(insReport);
        Map<String, Object> examineMarks = new HashMap<String, Object>() {{
            put("examineUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create());
            put("examineDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(null)).create());
        }}, (StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl));
        }};
        writeMarksToReportFiles(insReport, examineMarks);
        // 修改临时pdf
        String tempUrlPdf = wordToPdfTemp((StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl));
        String tempUrlPdf = wordToPdfTemp(primaryReportUrl.replace("/word", wordUrl));
        insReport.setTempUrlPdf("/word/" + tempUrlPdf);
        // 发送企业微信通知(通知批准人审批)
@@ -473,28 +474,29 @@
        if (StringUtils.isBlank(sealUrl)) {
            throw new ErrorException(laboratory + "找不到报告专用章");
        }
        //系统生成报告地址
        String url = insReport.getUrl();
        //手动上传报告地址
        String urlS = insReport.getUrlS();
        String finalUrl = (StrUtil.isBlank(urlS) ? url : urlS).replace("/word", wordUrl);
        String primaryReportUrl = getPrimaryReportUrl(insReport);
        String finalUrl = primaryReportUrl.replace("/word", wordUrl);
        wordInsertUrl(new HashMap<String, Object>() {{
        Map<String, Object> ratifyMarks = new HashMap<String, Object>() {{
            put("ratifyUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create());
            put("ratifyDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(null)).create());
            put("seal1", Pictures.ofLocal(imgUrl + "/" + sealUrl).create());
            put("seal2", Pictures.ofLocal(imgUrl + "/" + sealUrl).create());
        }}, finalUrl);
        }};
        writeMarksToReportFiles(insReport, ratifyMarks);
        // 修改临时pdf
        insReport.setTempUrlPdf((StrUtil.isBlank(urlS) ? url : urlS).replace(".docx", ".pdf"));
        insReport.setTempUrlPdf(primaryReportUrl.replace(".docx", ".pdf"));
        InsOrder insOrder = new InsOrder();
        insOrder.setId(insOrderId);
        insOrder.setState(4);
        insOrderMapper.updateById(insOrder);
        wordToPdf(finalUrl, sealUrl, isRawMater && order.getOrderType().equals(InsOrderTypeConstants.ENTER_THE_FACTORY));
        for (String reportUrl : getApprovalReportUrls(insReport)) {
            wordToPdf(reportUrl.replace("/word", wordUrl), sealUrl,
                    isRawMater && order.getOrderType().equals(InsOrderTypeConstants.ENTER_THE_FACTORY));
        }
        // 判断是否为原材料
        if (isRawMater) {
@@ -537,6 +539,27 @@
        return 1;
    }
    private String getPrimaryReportUrl(InsReport report) {
        String reportUrl = StringUtils.isNotBlank(report.getUrlS()) ? report.getUrlS() : report.getUrl();
        if (StringUtils.isBlank(reportUrl)) {
            throw new ErrorException("检测报告文件不存在");
        }
        return reportUrl;
    }
    private List<String> getApprovalReportUrls(InsReport report) {
        return Arrays.asList(getPrimaryReportUrl(report), report.getInspectionUrl()).stream()
                .filter(StringUtils::isNotBlank)
                .distinct()
                .collect(Collectors.toList());
    }
    private void writeMarksToReportFiles(InsReport report, Map<String, Object> marks) {
        for (String reportUrl : getApprovalReportUrls(report)) {
            wordInsertUrl(marks, reportUrl.replace("/word", wordUrl));
        }
    }
    //报告批量下载
    @Override
@@ -577,17 +600,23 @@
    }
    @Override
    public void download(Integer id, Integer createOrderUser, HttpServletResponse response) {
    public void download(Integer id, Integer reportType, Integer createOrderUser, HttpServletResponse response) {
        if (id == null) {
            throw new ErrorException("报告不能为空");
        }
        reportType = reportType == null ? DETECTION_REPORT : reportType;
        if (!Objects.equals(reportType, DETECTION_REPORT) && !Objects.equals(reportType, INSPECTION_REPORT)) {
            throw new ErrorException("报告类型不正确");
        }
        InsReport report = insReportMapper.selectDownloadableReport(id, createOrderUser);
        if (report == null) {
            throw new ErrorException("报告不存在、尚未生成或无权下载");
        }
        String reportUrl = StringUtils.isNotBlank(report.getUrlS()) ? report.getUrlS() : report.getUrl();
        String reportUrl = Objects.equals(reportType, INSPECTION_REPORT)
                ? report.getInspectionUrl() : getPrimaryReportUrl(report);
        if (StringUtils.isBlank(reportUrl) || !reportUrl.replace('\\', '/').startsWith("/word/")) {
            throw new ErrorException("报告文件不存在,请联系管理员");
            throw new ErrorException((Objects.equals(reportType, INSPECTION_REPORT) ? "检验报告" : "检测报告")
                    + "文件不存在,请联系管理员");
        }
        Path root = Paths.get(wordUrl).toAbsolutePath().normalize();
        Path file = root.resolve(reportUrl.replace('\\', '/').substring("/word/".length())).normalize();
inspect-server/src/main/resources/mapper/InsReportMapper.xml
@@ -82,7 +82,10 @@
    <!-- 报告报表导出 -->
    <select id="reportAllExport" resultType="com.ruoyi.inspect.dto.InsReportExport">
        select code,
        case when report_type = 0 then '检测报告' else '检验报告' end                         report_type_name,
        case
        when inspection_url is not null and inspection_url != '' then '检测报告、检验报告'
        when report_type = 0 then '检测报告'
        else '检验报告' end                                                               report_type_name,
        case when type_source = 0 then '成品下单' else '原材料下单' end                    type_source,
        case
        when order_type = '抽检' then '抽检'
inspect-server/src/main/resources/static/inspection-report-template-v2.docx
Binary files differ
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/CustomController.java
@@ -35,7 +35,7 @@
    }
    @ApiOperation(value = "删除客户信息")
    @DeleteMapping("/delCustomById")
    public Result delCustomById(Long id) {
    public Result delCustomById(@RequestParam("id") Long id) {
        return Result.success(customService.delCustomById(id));
    }
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/Custom.java
@@ -28,6 +28,9 @@
    @ApiModelProperty(value = "单位地址")
    private String address;
    @ApiModelProperty(value = "联系人")
    private String contact;
    @ApiModelProperty(value = "工厂域")
    private String code;