From 56fe897d3e06bfa1e1105980d0044e6e67b2a484 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期五, 23 十月 2026 17:44:20 +0800
Subject: [PATCH] feat(report): 实现浏览器内报告DOCX编辑功能

---
 inspect-server/src/main/java/com/ruoyi/inspect/vo/TemplateConditionVo.java                   |    6 
 inspect-server/src/main/java/com/ruoyi/inspect/dto/WriteInspectionConditionDto.java          |   10 +
 inspect-server/src/main/resources/static/inspection-report-template-v2.docx                  |    0 
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderTemplateServiceImpl.java |   28 +++
 inspect-server/src/main/java/com/ruoyi/inspect/controller/InsReportController.java           |   64 +++----
 inspect-server/src/main/java/com/ruoyi/inspect/pojo/InsReportEditSession.java                |   56 ++++++
 inspect-server/src/main/java/com/ruoyi/inspect/pojo/InsOrderStandardTemplate.java            |    9 
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsProductServiceImpl.java       |   21 ++
 inspect-server/src/main/java/com/ruoyi/inspect/service/InsReportService.java                 |    3 
 basic-server/src/main/java/com/ruoyi/basic/pojo/StandardTemplate.java                        |    4 
 basic-server/src/main/resources/mapper/StandardTemplateMapper.xml                            |    3 
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java        |   42 +++-
 basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardTemplateServiceImpl.java     |    3 
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java         |    4 
 inspect-server/src/main/java/com/ruoyi/inspect/pojo/InsReport.java                           |    5 
 inspect-server/src/main/java/com/ruoyi/inspect/service/InsReportEditingService.java          |  219 ++++++++++++++++++++++++
 inspect-server/src/main/resources/static/detection-report-template-v2.docx                   |    0 
 inspect-server/src/main/java/com/ruoyi/inspect/mapper/InsReportEditSessionMapper.java        |    7 
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java     |   52 +++++
 19 files changed, 478 insertions(+), 58 deletions(-)

diff --git a/basic-server/src/main/java/com/ruoyi/basic/pojo/StandardTemplate.java b/basic-server/src/main/java/com/ruoyi/basic/pojo/StandardTemplate.java
index 64d0c17..832fd7b 100644
--- a/basic-server/src/main/java/com/ruoyi/basic/pojo/StandardTemplate.java
+++ b/basic-server/src/main/java/com/ruoyi/basic/pojo/StandardTemplate.java
@@ -15,6 +15,7 @@
  */
 @TableName(value ="standard_template")
 @Data
+@Schema(description = "鍘熷璁板綍妯℃澘")
 public class StandardTemplate  implements Serializable {
     /**
      *
@@ -75,6 +76,9 @@
     @Schema(description = "妯℃澘缂栧彿")
     private String number;
 
+    @Schema(description = "鏍囧噯瑕佹眰鍊�")
+    private String standardRequirement;
+
     /**
      * 浠锋牸(鍏�)
      */
diff --git a/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardTemplateServiceImpl.java b/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardTemplateServiceImpl.java
index 5b60a04..2e25c0b 100644
--- a/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardTemplateServiceImpl.java
+++ b/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardTemplateServiceImpl.java
@@ -131,6 +131,9 @@
         // 鏌ヨ鏃фā鏉�
         StandardTemplate standardTemplate = baseMapper.selectById(newTemplate.getId());
         newTemplate.setThing(standardTemplate.getThing());
+        if (newTemplate.getStandardRequirement() == null) {
+            newTemplate.setStandardRequirement(standardTemplate.getStandardRequirement());
+        }
         if (newTemplate.getPrice() == null) {
             newTemplate.setPrice(java.math.BigDecimal.ZERO);
         }
diff --git a/basic-server/src/main/resources/mapper/StandardTemplateMapper.xml b/basic-server/src/main/resources/mapper/StandardTemplateMapper.xml
index a3d74b0..871f1a2 100644
--- a/basic-server/src/main/resources/mapper/StandardTemplateMapper.xml
+++ b/basic-server/src/main/resources/mapper/StandardTemplateMapper.xml
@@ -9,6 +9,7 @@
             <result property="name" column="name" jdbcType="VARCHAR"/>
             <result property="remark" column="remark" jdbcType="VARCHAR"/>
             <result property="thing" column="thing" jdbcType="VARCHAR"/>
+            <result property="standardRequirement" column="standard_requirement" jdbcType="VARCHAR"/>
             <result property="createUser" column="create_user" jdbcType="INTEGER"/>
             <result property="updateUser" column="update_user" jdbcType="INTEGER"/>
             <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
@@ -17,7 +18,7 @@
 
     <select id="selectStandardTemplatePageList" resultType="com.ruoyi.basic.pojo.StandardTemplate">
         select * from (
-        select st.id, st.name,st.number, st.price, st.remark, u2.name create_user_name, u3.name update_user_name, st.create_time, st.update_time
+        select st.id, st.name,st.number, st.standard_requirement, st.price, st.remark, u2.name create_user_name, u3.name update_user_name, st.create_time, st.update_time
         from standard_template st
         left join user u2 on u2.id = st.create_user
         left join user u3 on u3.id = st.update_user
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/controller/InsReportController.java b/inspect-server/src/main/java/com/ruoyi/inspect/controller/InsReportController.java
index b2cc44f..f204673 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/controller/InsReportController.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/controller/InsReportController.java
@@ -1,16 +1,13 @@
 package com.ruoyi.inspect.controller;
 
-import cn.hutool.core.io.FileUtil;
-import cn.hutool.http.HttpUtil;
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.basic.dto.IfsInventoryQuantitySupplierDto;
-import com.ruoyi.common.annotation.Anonymous;
 import com.ruoyi.common.annotation.PersonalScope;
 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.InsReportEditingService;
 import com.ruoyi.inspect.service.InsReportService;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import io.swagger.v3.oas.annotations.Operation;
@@ -20,16 +17,12 @@
 import org.springframework.web.multipart.MultipartFile;
 
 import jakarta.annotation.Resource;
-import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.Map;
-import java.util.Objects;
-import java.util.Scanner;
 
 @RestController
 @RequestMapping("/insReport")
@@ -41,6 +34,9 @@
 
     @Resource
     private InsOrderPlanService insOrderPlanService;
+
+    @Resource
+    private InsReportEditingService insReportEditingService;
 
     @Value("${wordUrl}")
     private String wordUrl;
@@ -106,7 +102,11 @@
         Integer isExamine = (Integer) param.get("isExamine");
         String examineTell = (String) param.get("examineTell");
         Integer userId = (Integer) param.get("userId");
-        return Result.success(insReportService.examineReport(id, isExamine, examineTell, userId));
+        Map<String, String> sessions = new java.util.HashMap<>();
+        if (param.get("editSessions") instanceof Map<?, ?> values) {
+            values.forEach((key, value) -> sessions.put(String.valueOf(key), String.valueOf(value)));
+        }
+        return Result.success(insReportEditingService.examineReport(id, isExamine, examineTell, userId, sessions));
     }
 
     @Operation(summary = "鎵瑰噯")
@@ -131,34 +131,26 @@
         return value instanceof Number ? ((Number) value).intValue() : Integer.valueOf(String.valueOf(value));
     }
 
-    @Anonymous
-    @RequestMapping("/onlyOffice/save")
-    public void saveFile(@RequestParam String fileName, HttpServletRequest request, HttpServletResponse response) {
-        PrintWriter writer = null;
-        try {
-            writer = response.getWriter();
-            // 鑾峰彇浼犺緭鐨刯son鏁版嵁
-            Scanner scanner = new Scanner(request.getInputStream()).useDelimiter("\\A");
-            String body = scanner.hasNext() ? scanner.next() : "";
-            JSONObject jsonObject = JSONObject.parseObject(body);
+    @Operation(summary = "鑾峰彇娴忚鍣ㄧ鎶ュ憡缂栬緫浼氳瘽")
+    @GetMapping("/editor/config")
+    public Result editConfig(Integer id, Integer reportType) {
+        return Result.success(insReportEditingService.createEditConfig(id, reportType));
+    }
 
-            if (jsonObject.containsKey("url")) {
-                String jsonArray = jsonObject.get("lastsave").toString(); // 鏇存柊鏃堕棿
-                String fileUrl = jsonObject.get("url").toString(); // 鏇存柊鏂囦欢url
-                HttpUtil.downloadFile(fileUrl, FileUtil.file(wordUrl + "/" + fileName));
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-            writer.write("{\"error\":-1}");
-            return;
-        }
-        /*
-         * status = 1锛屾垜浠粰onlyOffice鐨勬湇鍔¤繑鍥瀧"error":"0"}鐨勪俊鎭��
-         * 杩欐牱onlyOffice浼氳涓哄洖璋冩帴鍙f槸娌¢棶棰樼殑锛岃繖鏍峰氨鍙互鍦ㄧ嚎缂栬緫鏂囨。浜嗭紝鍚﹀垯鐨勮瘽浼氬脊鍑虹獥鍙h鏄�
-         */
-        if (Objects.nonNull(writer)) {
-            writer.write("{\"error\":0}");
-        }
+    @Operation(summary = "璇诲彇瀹℃牳 DOCX 鍐呭")
+    @GetMapping("/editor/document")
+    public org.springframework.http.ResponseEntity<byte[]> editDocument(@RequestParam String token) {
+        return org.springframework.http.ResponseEntity.ok().header("Cache-Control", "no-store")
+                .contentType(org.springframework.http.MediaType.parseMediaType(
+                        "application/vnd.openxmlformats-officedocument.wordprocessingml.document"))
+                .body(insReportEditingService.readDocument(token));
+    }
+
+    @Operation(summary = "淇濆瓨娴忚鍣ㄥ唴缂栬緫鐨� DOCX")
+    @PostMapping(value = "/editor/document", consumes = "multipart/form-data")
+    public Result saveEditDocument(@RequestParam String token, @RequestParam String version,
+                                   @RequestPart MultipartFile file) {
+        return Result.success(insReportEditingService.saveDocument(token, version, file));
     }
 
     @Operation(summary = "鎶ュ憡鎵归噺涓嬭浇")
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/dto/WriteInspectionConditionDto.java b/inspect-server/src/main/java/com/ruoyi/inspect/dto/WriteInspectionConditionDto.java
index 6fedaa7..0f3912b 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/dto/WriteInspectionConditionDto.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/dto/WriteInspectionConditionDto.java
@@ -19,6 +19,9 @@
     @JsonFormat(pattern = "yyyy-MM-dd")
     private LocalDate detectionTime;
 
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private LocalDate detectionEndTime;
+
     private String detectionPlace;
     private List<Integer> deviceIds;
     private Integer insResult;
@@ -27,6 +30,8 @@
     private boolean temperaturePresent;
     @JsonIgnore
     private boolean detectionTimePresent;
+    @JsonIgnore
+    private boolean detectionEndTimePresent;
     @JsonIgnore
     private boolean detectionPlacePresent;
     @JsonIgnore
@@ -44,6 +49,11 @@
         this.detectionTimePresent = true;
     }
 
+    public void setDetectionEndTime(LocalDate detectionEndTime) {
+        this.detectionEndTime = detectionEndTime;
+        this.detectionEndTimePresent = true;
+    }
+
     public void setDetectionPlace(String detectionPlace) {
         this.detectionPlace = detectionPlace;
         this.detectionPlacePresent = true;
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/mapper/InsReportEditSessionMapper.java b/inspect-server/src/main/java/com/ruoyi/inspect/mapper/InsReportEditSessionMapper.java
new file mode 100644
index 0000000..018576d
--- /dev/null
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/mapper/InsReportEditSessionMapper.java
@@ -0,0 +1,7 @@
+package com.ruoyi.inspect.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.inspect.pojo.InsReportEditSession;
+
+public interface InsReportEditSessionMapper extends BaseMapper<InsReportEditSession> {
+}
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/pojo/InsOrderStandardTemplate.java b/inspect-server/src/main/java/com/ruoyi/inspect/pojo/InsOrderStandardTemplate.java
index cf12774..73ae795 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/pojo/InsOrderStandardTemplate.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/pojo/InsOrderStandardTemplate.java
@@ -58,6 +58,9 @@
     @Schema(description = "妯℃澘缂栧彿")
     private String number;
 
+    @Schema(description = "涓嬪崟鏃跺師濮嬭褰曟ā鏉跨殑鏍囧噯瑕佹眰鍊�")
+    private String standardRequirement;
+
     @Schema(description = "妯℃澘灞曠ず鍙婄敓鎴愰『搴�")
     private Integer sort;
 
@@ -73,10 +76,14 @@
     @Schema(description = "璇ユā鏉挎楠屾椂鐨勬箍搴�")
     private String humidity;
 
-    @Schema(description = "妫�娴嬫棩鏈�")
+    @Schema(description = "妫�娴嬪紑濮嬫棩鏈�")
     @JsonFormat(pattern = "yyyy-MM-dd")
     private LocalDate detectionTime;
 
+    @Schema(description = "妫�娴嬬粨鏉熸棩鏈燂紝鍘嗗彶绌哄�兼寜寮�濮嬫棩鏈熷鐞�")
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private LocalDate detectionEndTime;
+
     @Schema(description = "妫�娴嬪湴鐐�")
     private String detectionPlace;
 
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/pojo/InsReport.java b/inspect-server/src/main/java/com/ruoyi/inspect/pojo/InsReport.java
index 4a3eb89..91c3e88 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/pojo/InsReport.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/pojo/InsReport.java
@@ -14,6 +14,7 @@
  */
 @TableName(value ="ins_report")
 @Data
+@Schema(description = "妫�楠屾姤鍛�")
 public class InsReport implements Serializable {
     /**
      *
@@ -59,6 +60,10 @@
     @Schema(description = "涓存椂鎶ュ憡鍦板潃")
     private String tempUrlPdf;
 
+    /** 妫�楠屾姤鍛婁复鏃堕瑙堝湴鍧�銆� */
+    @Schema(description = "妫�楠屾姤鍛婁复鏃堕瑙堝湴鍧�")
+    private String inspectionTempUrlPdf;
+
     /**
      * 1锛氭壒鍑� 0锛氫笉鎵瑰噯
      */
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/pojo/InsReportEditSession.java b/inspect-server/src/main/java/com/ruoyi/inspect/pojo/InsReportEditSession.java
new file mode 100644
index 0000000..fd785f3
--- /dev/null
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/pojo/InsReportEditSession.java
@@ -0,0 +1,56 @@
+package com.ruoyi.inspect.pojo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/** 娴忚鍣ㄧ DOCX 瀹℃牳缂栬緫浼氳瘽锛沝ocumentKey 淇濆瓨鏂囦欢鍐呭 SHA-256銆� */
+@Data
+@TableName("ins_report_edit_session")
+@Schema(description = "鎶ュ憡瀹℃牳鍦ㄧ嚎缂栬緫浼氳瘽")
+public class InsReportEditSession implements Serializable {
+    @Schema(description = "浼氳瘽ID")
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    @Schema(description = "缂栬緫浼氳瘽浠ょ墝")
+    private String token;
+
+    @Schema(description = "鎶ュ憡ID")
+    private Integer reportId;
+
+    @Schema(description = "鎶ュ憡绫诲瀷锛�0妫�娴嬫姤鍛婏紝1妫�楠屾姤鍛�")
+    private Integer reportType;
+
+    @Schema(description = "DOCX鏂囦欢鍐呭鐨凷HA-256鐗堟湰")
+    private String documentKey;
+
+    @Schema(description = "瀹℃牳浜篒D")
+    private Integer userId;
+
+    @Schema(description = "浼氳瘽鐘舵��")
+    private String status;
+
+    @Schema(description = "淇濆瓨璇锋眰ID")
+    private String saveRequestId;
+
+    @Schema(description = "淇濆瓨缁撴灉璇存槑")
+    private String message;
+
+    @Schema(description = "浼氳瘽杩囨湡鏃堕棿")
+    private LocalDateTime expiresAt;
+
+    @Schema(description = "鏈�杩戜繚瀛樺畬鎴愭椂闂�")
+    private LocalDateTime savedAt;
+
+    @Schema(description = "鍒涘缓鏃堕棿")
+    private LocalDateTime createTime;
+
+    @Schema(description = "鏇存柊鏃堕棿")
+    private LocalDateTime updateTime;
+}
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/InsReportEditingService.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/InsReportEditingService.java
new file mode 100644
index 0000000..84f4646
--- /dev/null
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/InsReportEditingService.java
@@ -0,0 +1,219 @@
+package com.ruoyi.inspect.service;
+
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.framework.exception.ErrorException;
+import com.ruoyi.inspect.mapper.InsReportEditSessionMapper;
+import com.ruoyi.inspect.mapper.InsReportMapper;
+import com.ruoyi.inspect.pojo.InsReport;
+import com.ruoyi.inspect.pojo.InsReportEditSession;
+import jakarta.annotation.Resource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+import java.io.InputStream;
+import java.nio.file.*;
+import java.security.MessageDigest;
+import java.time.LocalDateTime;
+import java.util.*;
+
+/** 娴忚鍣ㄥ唴 DOCX 缂栬緫锛氱櫥褰曢壌鏉冦�佺増鏈牎楠岋紝鏃犲尶鍚嶅洖璋冨強鏂囨。鏈嶅姟鍣ㄤ緷璧栥�� */
+@Service
+public class InsReportEditingService {
+    private static final long MAX_BYTES = 100L * 1024 * 1024;
+    @Resource private InsReportMapper reportMapper;
+    @Resource private InsReportEditSessionMapper sessionMapper;
+    @Resource private InsReportService reportService;
+    @Value("${wordUrl}") private String wordUrl;
+
+    @Transactional(rollbackFor = Exception.class)
+    public Map<String, Object> createEditConfig(Integer id, Integer type) {
+        if (!Objects.equals(type, 0) && !Objects.equals(type, 1)) throw new ErrorException("鎶ュ憡绫诲瀷涓嶆纭�");
+        InsReport report = lockEditable(id);
+        Path file = resolveFile(report, type);
+        LocalDateTime now = LocalDateTime.now();
+        sessionMapper.update(null, Wrappers.<InsReportEditSession>lambdaUpdate()
+                .eq(InsReportEditSession::getReportId, id).eq(InsReportEditSession::getReportType, type)
+                .in(InsReportEditSession::getStatus, "EDITING", "SAVED", "FAILED", "SAVE_REQUESTED")
+                .set(InsReportEditSession::getStatus, "EXPIRED"));
+        InsReportEditSession session = new InsReportEditSession();
+        session.setReportId(id);
+        session.setReportType(type);
+        session.setToken(UUID.randomUUID().toString());
+        session.setDocumentKey(version(file));
+        session.setUserId(SecurityUtils.getUserId().intValue());
+        // 鏈墦寮�缂栬緫鐨勭浜屼唤鎶ュ憡纭浣跨敤褰撳墠鎸佷箙鍖栫増鏈紱褰撳墠缂栬緫鍣ㄧ敱鍓嶇淇濆瓨灞忛殰鎻愪氦銆�
+        session.setStatus("SAVED");
+        session.setSavedAt(now);
+        session.setExpiresAt(now.plusHours(8));
+        session.setCreateTime(now);
+        session.setUpdateTime(now);
+        sessionMapper.insert(session);
+        return Map.of("sessionToken", session.getToken(), "version", session.getDocumentKey(),
+                "title", file.getFileName().toString(), "reportType", type);
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    public byte[] readDocument(String token) {
+        InsReportEditSession session = findSession(token);
+        InsReport report = lockEditable(session.getReportId());
+        requireUsable(session);
+        Path file = resolveFile(report, session.getReportType());
+        requireVersion(session, file);
+        try { return Files.readAllBytes(file); }
+        catch (Exception e) { throw new ErrorException("璇诲彇鎶ュ憡澶辫触"); }
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    public Map<String, Object> saveDocument(String token, String expectedVersion, MultipartFile file) {
+        InsReportEditSession session = findSession(token);
+        InsReport report = lockEditable(session.getReportId());
+        requireUsable(session);
+        if (!Objects.equals(expectedVersion, session.getDocumentKey())) {
+            throw new ErrorException("鎶ュ憡鐗堟湰宸插彉鍖栵紝璇烽噸鏂版墦寮�鍚庣紪杈�");
+        }
+        requireVersion(session, resolveFile(report, session.getReportType()));
+        if (file == null || file.isEmpty() || file.getSize() > MAX_BYTES) {
+            throw new ErrorException("鎶ュ憡涓嶈兘涓虹┖锛屼笖涓嶈兘瓒呰繃 100MB");
+        }
+        try {
+            // 鏍¢獙 OOXML 缁撴瀯锛屾嫆缁� ZIP銆丠TML 鎴栭敊璇搷搴斿啋鍏� DOCX銆�
+            try (InputStream input = file.getInputStream(); XWPFDocument doc = new XWPFDocument(input)) {
+                if (doc.getDocument().getBody() == null) throw new IllegalArgumentException();
+            }
+            Path root = Paths.get(wordUrl).toAbsolutePath().normalize();
+            Files.createDirectories(root);
+            Path staged = root.resolve("edited-" + UUID.randomUUID() + ".docx");
+            file.transferTo(staged);
+            // 鏂� Word銆丳DF 鍏ㄩ儴鐢熸垚鎴愬姛鍚庡彂甯冩暟鎹簱鎸囬拡锛涗换浣曞け璐ラ兘涓嶈鐩栨棫鏂囦欢銆�
+            String pdfUrl = reportService.prepareEditedReportPreview(staged.toString());
+            String documentUrl = "/word/" + staged.getFileName();
+            var update = Wrappers.<InsReport>lambdaUpdate().eq(InsReport::getId, report.getId());
+            if (session.getReportType() == 1) {
+                update.set(InsReport::getInspectionUrl, documentUrl).set(InsReport::getInspectionTempUrlPdf, pdfUrl);
+            } else {
+                update.set(InsReport::getUrlS, documentUrl).set(InsReport::getTempUrlPdf, pdfUrl);
+            }
+            reportMapper.update(null, update);
+            session.setDocumentKey(version(staged));
+            session.setStatus("SAVED");
+            session.setSavedAt(LocalDateTime.now());
+            session.setUpdateTime(LocalDateTime.now());
+            session.setMessage("淇濆瓨鎴愬姛");
+            sessionMapper.updateById(session);
+            return Map.of("version", session.getDocumentKey(), "completed", true, "pdfUrl", pdfUrl);
+        } catch (Exception e) {
+            throw e instanceof ErrorException error ? error : new ErrorException("淇濆瓨 Word 澶辫触锛岃閲嶈瘯锛�" + e.getMessage());
+        }
+    }
+
+    /** 淇濆瓨鐗堟湰鏍稿銆佸鏍哥鍚嶅強浼氳瘽澶辨晥浣跨敤鍚屼竴涓姤鍛婅閿佷笌鏁版嵁搴撲簨鍔°�� */
+    @Transactional(rollbackFor = Exception.class)
+    public int examineReport(Integer id, Integer passed, String reason, Integer approver, Map<String, String> tokens) {
+        InsReport report = lockEditable(id);
+        if (!Objects.equals(passed, 0) && !Objects.equals(passed, 1)) throw new ErrorException("瀹℃牳缁撴灉涓嶆纭�");
+        if (Objects.equals(passed, 1)) {
+            checkSaved(report, 0, tokens);
+            if (StringUtils.isNotBlank(report.getInspectionUrl())) checkSaved(report, 1, tokens);
+            // 绛惧悕娴佺▼浼氭敼鍐欐枃浠讹紱鍏堝鍒跺啀鍦ㄤ簨鍔′腑鍒囨崲鎸囬拡锛屽け璐ユ椂鏃х殑宸蹭繚瀛樼涓嶅彈褰卞搷銆�
+            stageForSignature(report);
+        }
+        int result = reportService.examineReport(id, passed, reason, approver);
+        sessionMapper.update(null, Wrappers.<InsReportEditSession>lambdaUpdate()
+                .eq(InsReportEditSession::getReportId, id)
+                .in(InsReportEditSession::getStatus, "EDITING", "SAVED", "FAILED", "SAVE_REQUESTED")
+                .set(InsReportEditSession::getStatus, "FINALIZED")
+                .set(InsReportEditSession::getUpdateTime, LocalDateTime.now()));
+        return result;
+    }
+
+    private void stageForSignature(InsReport report) {
+        try {
+            Path root = Paths.get(wordUrl).toAbsolutePath().normalize();
+            var update = Wrappers.<InsReport>lambdaUpdate().eq(InsReport::getId, report.getId());
+            for (int type : StringUtils.isNotBlank(report.getInspectionUrl()) ? new int[]{0, 1} : new int[]{0}) {
+                Path copy = root.resolve("reviewed-" + UUID.randomUUID() + ".docx");
+                Files.copy(resolveFile(report, type), copy);
+                String url = "/word/" + copy.getFileName();
+                if (type == 0) update.set(InsReport::getUrlS, url);
+                else update.set(InsReport::getInspectionUrl, url);
+            }
+            reportMapper.update(null, update);
+        } catch (Exception e) { throw new ErrorException("鍑嗗瀹℃牳绛惧悕鏂囦欢澶辫触锛岃閲嶈瘯"); }
+    }
+
+    private void checkSaved(InsReport report, int type, Map<String, String> tokens) {
+        if (tokens == null || StringUtils.isBlank(tokens.get(String.valueOf(type)))) {
+            throw new ErrorException("璇峰厛鎵撳紑瀹℃牳缂栬緫椤甸潰骞朵繚瀛樻姤鍛�");
+        }
+        InsReportEditSession session = findSession(tokens.get(String.valueOf(type)));
+        requireUsable(session);
+        if (!Objects.equals(session.getReportId(), report.getId()) || session.getReportType() != type) {
+            throw new ErrorException("鎶ュ憡缂栬緫浼氳瘽涓嶅尮閰�");
+        }
+        requireVersion(session, resolveFile(report, type));
+    }
+
+    private InsReport lockEditable(Integer id) {
+        InsReport report = reportMapper.selectOne(Wrappers.<InsReport>lambdaQuery()
+                .eq(InsReport::getId, id).last("FOR UPDATE"));
+        if (report == null) throw new ErrorException("鎶ュ憡涓嶅瓨鍦�");
+        if (!Objects.equals(report.getState(), 1) || Objects.equals(report.getIsExamine(), 1)
+                || Objects.equals(report.getIsRatify(), 1)) throw new ErrorException("鎶ュ憡宸蹭笉鍦ㄥ緟瀹℃牳鐘舵��");
+        if (!Objects.equals(report.getExamineUserId(), SecurityUtils.getUserId().intValue())) {
+            throw new ErrorException("鍙湁鎸囧畾瀹℃牳浜哄彲浠ョ紪杈戝拰瀹℃牳鎶ュ憡");
+        }
+        return report;
+    }
+
+    private InsReportEditSession findSession(String token) {
+        if (StringUtils.isBlank(token)) throw new ErrorException("缂哄皯缂栬緫浼氳瘽");
+        InsReportEditSession session = sessionMapper.selectOne(Wrappers.<InsReportEditSession>lambdaQuery()
+                .eq(InsReportEditSession::getToken, token));
+        if (session == null || !Objects.equals(session.getUserId(), SecurityUtils.getUserId().intValue())) {
+            throw new ErrorException("缂栬緫浼氳瘽涓嶅瓨鍦ㄦ垨鏃犳潈璁块棶");
+        }
+        return session;
+    }
+
+    private void requireUsable(InsReportEditSession session) {
+        // 绛夊緟鎶ュ憡閿佹湡闂村彲鑳藉凡琚彟涓�绐楀彛澶辨晥锛屾晠姝ゅ杩涜閿佸畾璇汇��
+        InsReportEditSession current = sessionMapper.selectOne(Wrappers.<InsReportEditSession>lambdaQuery()
+                .eq(InsReportEditSession::getId, session.getId()).last("FOR UPDATE"));
+        if (current.getExpiresAt().isBefore(LocalDateTime.now()) || !"SAVED".equals(current.getStatus())) {
+            throw new ErrorException("缂栬緫浼氳瘽宸插け鏁堬紝璇烽噸鏂版墦寮�鎶ュ憡");
+        }
+        session.setDocumentKey(current.getDocumentKey());
+        session.setStatus(current.getStatus());
+    }
+
+    private Path resolveFile(InsReport report, int type) {
+        String url = type == 1 ? report.getInspectionUrl() : StringUtils.defaultIfBlank(report.getUrlS(), report.getUrl());
+        if (StringUtils.isBlank(url) || !url.startsWith("/word/") || !url.toLowerCase().endsWith(".docx")) {
+            throw new ErrorException("瀵瑰簲鐨� DOCX 鎶ュ憡涓嶅瓨鍦�");
+        }
+        try {
+            Path root = Paths.get(wordUrl).toRealPath();
+            Path file = root.resolve(url.substring(6)).normalize().toRealPath();
+            if (!file.startsWith(root) || !Files.isRegularFile(file) || Files.size(file) > MAX_BYTES) throw new IllegalArgumentException();
+            return file;
+        } catch (Exception e) { throw new ErrorException("鎶ュ憡鏂囦欢涓嶅瓨鍦ㄦ垨璺緞涓嶅悎娉�"); }
+    }
+
+    private void requireVersion(InsReportEditSession session, Path file) {
+        if (!Objects.equals(session.getDocumentKey(), version(file))) throw new ErrorException("鎶ュ憡宸茶鏇挎崲锛岃閲嶆柊鎵撳紑鍚庣紪杈�");
+    }
+
+    private String version(Path file) {
+        try (InputStream input = Files.newInputStream(file)) {
+            MessageDigest digest = MessageDigest.getInstance("SHA-256");
+            byte[] buffer = new byte[8192];
+            int length;
+            while ((length = input.read(buffer)) != -1) digest.update(buffer, 0, length);
+            return HexFormat.of().formatHex(digest.digest());
+        } catch (Exception e) { throw new ErrorException("鏃犳硶璇诲彇鎶ュ憡鐗堟湰"); }
+    }
+}
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/InsReportService.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/InsReportService.java
index 8ec79c9..13a6cd9 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/service/InsReportService.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/InsReportService.java
@@ -40,6 +40,9 @@
 
     int wordInsertUrl(Map<String, Object> map, String url);
 
+    /** 鍦ㄧ嚎缂栬緫淇濆瓨鍚庨噸鏂扮敓鎴愬搴旀姤鍛婄殑涓存椂 PDF銆� */
+    String prepareEditedReportPreview(String absoluteDocxPath);
+
     String downAll(String ids);
 
     /**
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
index dcd6d1e..797cc86 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
@@ -359,6 +359,9 @@
                         "妯℃澘ID " + snapshot.getTemplateId());
                 if (snapshot.getDetectionTime() == null) {
                     collect.add("璇烽�夋嫨鈥�" + templateName + "鈥濈殑妫�娴嬫椂闂�");
+                } else if (snapshot.getDetectionEndTime() != null
+                        && snapshot.getDetectionEndTime().isBefore(snapshot.getDetectionTime())) {
+                    collect.add("鈥�" + templateName + "鈥濈殑妫�娴嬬粨鏉熸棩鏈熶笉鑳芥棭浜庡紑濮嬫棩鏈�");
                 }
                 if (StringUtils.isBlank(snapshot.getDetectionPlace())) {
                     collect.add("璇峰~鍐欌��" + templateName + "鈥濈殑妫�娴嬪湴鐐�");
@@ -1655,6 +1658,8 @@
             refreshed.setInsOrderId(orderId);
             refreshed.setTemplateId(templateId);
             refreshed.setNumber(standardTemplate == null ? oldSnapshot.getNumber() : standardTemplate.getNumber());
+            refreshed.setStandardRequirement(oldSnapshot == null
+                    ? standardTemplate.getStandardRequirement() : oldSnapshot.getStandardRequirement());
             refreshed.setName(standardTemplate == null ? oldSnapshot.getName() : standardTemplate.getName());
             refreshed.setRemark(standardTemplate == null ? oldSnapshot.getRemark() : standardTemplate.getRemark());
             refreshed.setThing(standardTemplate == null ? oldSnapshot.getThing() : standardTemplate.getThing());
@@ -1665,6 +1670,7 @@
             refreshed.setHumidity(templateHumidityMap.get(templateId));
             // 鍒锋柊妯℃澘缁撴瀯鏃跺繀椤讳繚鐣欐楠岄樁娈靛~鍐欑殑涓氬姟鏁版嵁锛岄伩鍏嶈繘鍏ュ鏍稿悗鍥炴樉涓虹┖銆�
             refreshed.setDetectionTime(oldSnapshot == null ? null : oldSnapshot.getDetectionTime());
+            refreshed.setDetectionEndTime(oldSnapshot == null ? null : oldSnapshot.getDetectionEndTime());
             refreshed.setDetectionPlace(oldSnapshot == null ? null : oldSnapshot.getDetectionPlace());
             refreshed.setInsResult(oldSnapshot == null ? null : oldSnapshot.getInsResult());
             Integer templateSort = templateSortMap.get(templateId);
@@ -2004,7 +2010,8 @@
         if (Objects.equals(report.getIsRatify(), 1)) {
             throw new ErrorException("宸叉壒鍑嗘姤鍛婁笉鑳介噸鏂扮敓鎴�");
         }
-        if (StringUtils.isNotBlank(report.getUrlS())) {
+        // urlS 鍚屾椂鐢ㄤ簬浜哄伐涓婁紶鍜屽鏍搁〉闈繚瀛樼殑 Word锛涘彧鏈変汉宸ヤ笂浼犻渶瑕佸厛鎵嬪姩鍒囧洖绯荤粺鎶ュ憡銆�
+        if (StringUtils.isNotBlank(report.getUrlS()) && !isBrowserEditedReportUrl(report.getUrlS())) {
             throw new ErrorException("褰撳墠鎶ュ憡宸叉墜鍔ㄤ笂浼狅紝璇峰厛杩樺師涓虹郴缁熸姤鍛婂悗鍐嶉噸鏂扮敓鎴�");
         }
         if (report.getInsOrderId() == null) {
@@ -2048,7 +2055,12 @@
                 .eq(InsReport::getId, reportId)
                 .set(InsReport::getWriteTime, report.getWriteTime())
                 .set(InsReport::getIsPass, report.getIsPass())
+                .set(InsReport::getUrlS, null)
                 .set(InsReport::getTempUrlPdf, "/word/" + tempPdfName));
+    }
+
+    private static boolean isBrowserEditedReportUrl(String url) {
+        return url != null && url.matches("(?i)^/word/(?:edited|reviewed)-[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}\\.docx$");
     }
 
     private Map<String, Object> buildExistingReportMarks(InsReport report) {
@@ -3613,7 +3625,8 @@
                         .eq(InsOrderStandardTemplate::getInsOrderId, orderId)
                         .orderByAsc(InsOrderStandardTemplate::getSort, InsOrderStandardTemplate::getId));
         List<LocalDate> detectionDates = templateSnapshots.stream()
-                .map(InsOrderStandardTemplate::getDetectionTime)
+                .flatMap(snapshot -> java.util.stream.Stream.of(
+                        snapshot.getDetectionTime(), snapshot.getDetectionEndTime()))
                 .filter(Objects::nonNull)
                 .collect(Collectors.toList());
         String insTime = formatReportTestDate(detectionDates);
@@ -3629,7 +3642,7 @@
         List<Map<String, String>> finalDeviceList = deviceList;
         String finalModelStr = modelStr;
 
-        // 鐩寸粦妯℃澘璁㈠崟娌℃湁 ins_product锛屾娴嬮」鐩�佸崟浣嶅拰缁撴灉鍧囦粠璁㈠崟妯℃澘蹇収涓幏鍙栥��
+        // 鐩寸粦妯℃澘璁㈠崟娌℃湁 ins_product锛屾娴嬮」鐩�佹爣鍑嗚姹傚�煎拰缁撴灉鍧囦粠璁㈠崟妯℃澘蹇収涓幏鍙栥��
         List<Map<String, String>> detectionResultRows = directTemplateOrder
                 ? buildTemplateDetectionResultRows(orderId)
                 : buildDetectionResultRows(samples);
@@ -3811,7 +3824,7 @@
     }
 
     /**
-     * 鏂扮増妫�娴嬫姤鍛婄殑缁撴灉琛ㄥ浐瀹氫负鍥涘垪锛氬簭鍙枫�佹娴嬮」鐩�佸崟浣嶃�佹娴嬬粨鏋溿��
+     * 鏂扮増妫�娴嬨�佹楠屾姤鍛婂叡鐢ㄧ粨鏋滄暟鎹紱鏍囧噯瑕佹眰鍊煎彇鑷師濮嬭褰曟ā鏉块厤缃��
      */
     private List<Map<String, String>> buildDetectionResultRows(List<SampleProductDto> samples) {
         List<Map<String, String>> rows = new ArrayList<>();
@@ -3820,6 +3833,7 @@
         }
 
         boolean multipleSamples = samples.size() > 1;
+        Map<Integer, String> requirementsByTemplate = new HashMap<>();
         int sequence = 1;
         for (SampleProductDto sample : samples) {
             if (CollectionUtils.isEmpty(sample.getInsProduct())) {
@@ -3840,8 +3854,15 @@
 
                 Map<String, String> row = new LinkedHashMap<>();
                 row.put("seq", String.valueOf(sequence++));
-                row.put("itemName", itemName);
+                row.put("itemName", formatReportItemWithUnit(itemName, product.getUnit()));
                 row.put("unit", defaultReportText(product.getUnit(), "/"));
+                String requirement = product.getTemplateId() == null ? null
+                        : requirementsByTemplate.computeIfAbsent(product.getTemplateId(), templateId -> {
+                            StandardTemplate sourceTemplate = standardTemplateService.getById(templateId);
+                            return defaultReportText(sourceTemplate == null ? null
+                                    : sourceTemplate.getStandardRequirement(), "/");
+                        });
+                row.put("standardRequirement", defaultReportText(requirement, "/"));
                 row.put("result", defaultReportText(product.getLastValue(), "/"));
                 row.put("inspectionConclusion", formatInspectionConclusion(product.getInsResult()));
                 rows.add(row);
@@ -3867,7 +3888,8 @@
                 Wrappers.<InsOrderStandardTemplate>lambdaQuery()
                         .eq(InsOrderStandardTemplate::getInsOrderId, orderId)
                         .orderByAsc(InsOrderStandardTemplate::getSort, InsOrderStandardTemplate::getId));
-        context.setDetectionDates(snapshots.stream().map(InsOrderStandardTemplate::getDetectionTime)
+        context.setDetectionDates(snapshots.stream().flatMap(snapshot -> java.util.stream.Stream.of(
+                        snapshot.getDetectionTime(), snapshot.getDetectionEndTime()))
                 .filter(Objects::nonNull).distinct().sorted().collect(Collectors.toList()));
         List<Integer> deviceIds = insOrderTemplateDeviceMapper.selectDeviceIdsByOrderId(orderId);
         if (CollectionUtils.isNotEmpty(deviceIds)) {
@@ -3895,6 +3917,12 @@
         List<Map<String, String>> rows = new ArrayList<>();
         int sequence = 1;
         for (InsOrderStandardTemplate snapshot : snapshots) {
+            String standardRequirement = snapshot.getStandardRequirement();
+            // 鍏煎鏂板璇ュ瓧娈靛墠涓嬪崟鐨勬棫璁板綍锛涙湁蹇収鏃跺缁堜互璁㈠崟淇濆瓨鐨勫�间负鍑嗐��
+            if (StringUtils.isBlank(standardRequirement) && snapshot.getTemplateId() != null) {
+                StandardTemplate sourceTemplate = standardTemplateService.getById(snapshot.getTemplateId());
+                standardRequirement = sourceTemplate == null ? null : sourceTemplate.getStandardRequirement();
+            }
             List<TemplateExportCell> exportCells = getTemplateExportCells(snapshot.getThing());
             JSONObject recordValues = StrUtil.isBlank(snapshot.getRecordValues())
                     ? new JSONObject() : JSON.parseObject(snapshot.getRecordValues());
@@ -3913,8 +3941,10 @@
                 row.put("seq", String.valueOf(sequence++));
                 String reportItemName = defaultReportText(itemName,
                         defaultReportText(snapshot.getName(), "妯℃澘ID " + snapshot.getTemplateId()));
-                row.put("itemName", formatExportItemName(reportItemName));
+                row.put("itemName", formatReportItemWithUnit(
+                        formatExportItemName(reportItemName), unit));
                 row.put("unit", defaultReportText(unit, "/"));
+                row.put("standardRequirement", defaultReportText(standardRequirement, "/"));
                 row.put("result", result);
                 row.put("inspectionConclusion", formatInspectionConclusion(snapshot.getInsResult()));
                 rows.add(row);
@@ -4090,6 +4120,14 @@
         return itemName.replaceAll("骞冲潎鍊糪\s*[锛�,]?\\s*", "");
     }
 
+    private static String formatReportItemWithUnit(String itemName, String unit) {
+        if (StringUtils.isBlank(unit) || "/".equals(unit.trim())
+                || itemName.contains(unit.trim())) {
+            return itemName;
+        }
+        return itemName + "锛�" + unit.trim();
+    }
+
     private static String getMapText(Map<String, String> map, String... keys) {
         if (map == null) {
             return null;
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java
index 2820bd8..c8e2581 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java
@@ -846,6 +846,7 @@
             snapshot.setTemplateId(template.getId());
             snapshot.setName(template.getName());
             snapshot.setNumber(template.getNumber());
+            snapshot.setStandardRequirement(template.getStandardRequirement());
             snapshot.setRemark(template.getRemark());
             snapshot.setThing(template.getThing());
             snapshot.setSort(selection.getSort());
@@ -1091,6 +1092,7 @@
                                 .select(InsOrderStandardTemplate::getTemplateId,
                                         InsOrderStandardTemplate::getTemperature,
                                         InsOrderStandardTemplate::getDetectionTime,
+                                        InsOrderStandardTemplate::getDetectionEndTime,
                                         InsOrderStandardTemplate::getDetectionPlace,
                                         InsOrderStandardTemplate::getInsResult)
                                 .orderByAsc(InsOrderStandardTemplate::getSort,
@@ -1100,6 +1102,8 @@
                     condition.setTemplateId(snapshot.getTemplateId());
                     condition.setTemperature(snapshot.getTemperature());
                     condition.setDetectionTime(snapshot.getDetectionTime());
+                    condition.setDetectionEndTime(snapshot.getDetectionEndTime() == null
+                            ? snapshot.getDetectionTime() : snapshot.getDetectionEndTime());
                     condition.setDetectionPlace(snapshot.getDetectionPlace());
                     condition.setInsResult(snapshot.getInsResult());
                     condition.setDeviceIds(templateDeviceIds.getOrDefault(
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderTemplateServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderTemplateServiceImpl.java
index 0de8550..0c4fb27 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderTemplateServiceImpl.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderTemplateServiceImpl.java
@@ -2,6 +2,7 @@
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -17,6 +18,9 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 /**
  * @author Administrator
@@ -67,7 +71,29 @@
         vo.setStandardTreeId(standardTreeId);
         if (standardTreeId != null) {
             List<StandardTreeTemplateBindingVo> bindings = standardTreeService.selectTemplateBindings(standardTreeId);
-            vo.setTemplateBindings(bindings == null ? new ArrayList<>() : bindings);
+            // 鏂颁繚瀛樼殑涓嬪崟妯℃澘璁板綍浜嗗疄闄呬繚鐣欑殑鍘熷璁板綍妯℃澘锛涙棫妯℃澘娌℃湁璇ュ瓧娈碉紝娌跨敤鏍囧噯搴撶粦瀹氬垪琛ㄣ��
+            JSONObject content = StringUtils.isBlank(template.getThing())
+                    ? null : JSON.parseObject(template.getThing());
+            JSONArray savedSelections = content == null ? null : content.getJSONArray("templateList");
+            if (savedSelections == null) {
+                vo.setTemplateBindings(bindings == null ? new ArrayList<>() : bindings);
+            } else {
+                Map<Integer, StandardTreeTemplateBindingVo> currentBindings = (bindings == null
+                        ? new ArrayList<StandardTreeTemplateBindingVo>() : bindings).stream()
+                        .collect(Collectors.toMap(StandardTreeTemplateBindingVo::getTemplateId,
+                                Function.identity(), (first, ignored) -> first));
+                List<StandardTreeTemplateBindingVo> selected = new ArrayList<>();
+                for (int index = 0; index < savedSelections.size(); index++) {
+                    JSONObject selection = savedSelections.getJSONObject(index);
+                    if (selection == null) continue;
+                    StandardTreeTemplateBindingVo binding = currentBindings.get(selection.getInteger("templateId"));
+                    if (binding != null) {
+                        binding.setSort(index);
+                        selected.add(binding);
+                    }
+                }
+                vo.setTemplateBindings(selected);
+            }
         } else {
             vo.setTemplateBindings(new ArrayList<>());
         }
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsProductServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsProductServiceImpl.java
index ed0e8e7..b59afae 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsProductServiceImpl.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsProductServiceImpl.java
@@ -77,7 +77,24 @@
             if (snapshot == null) {
                 throw new ErrorException("鏈壘鍒板綋鍓嶆ā鏉跨殑鍘熷璁板綍蹇収");
             }
-            boolean hasSnapshotField = dto.isTemperaturePresent() || dto.isDetectionTimePresent()
+            boolean hasDetectionRange = dto.isDetectionTimePresent() || dto.isDetectionEndTimePresent();
+            if (hasDetectionRange) {
+                if (!dto.isDetectionTimePresent()) {
+                    throw new ErrorException("璇烽�夋嫨瀹屾暣鐨勬娴嬫椂闂磋寖鍥�");
+                }
+                // 鍏煎鏃у鎴风鍙彁浜ゅ崟涓棩鏈燂紱鏂板鎴风蹇呴』鍚屾椂鎻愪氦璧锋鏃ユ湡鎴栧悓鏃舵竻绌恒��
+                if (!dto.isDetectionEndTimePresent()) {
+                    dto.setDetectionEndTime(dto.getDetectionTime());
+                }
+                if ((dto.getDetectionTime() == null) != (dto.getDetectionEndTime() == null)) {
+                    throw new ErrorException("璇烽�夋嫨瀹屾暣鐨勬娴嬫椂闂磋寖鍥�");
+                }
+                if (dto.getDetectionTime() != null
+                        && dto.getDetectionEndTime().isBefore(dto.getDetectionTime())) {
+                    throw new ErrorException("妫�娴嬬粨鏉熸棩鏈熶笉鑳芥棭浜庡紑濮嬫棩鏈�");
+                }
+            }
+            boolean hasSnapshotField = dto.isTemperaturePresent() || hasDetectionRange
                     || dto.isDetectionPlacePresent()
                     || dto.isInsResultPresent();
             if (hasSnapshotField) {
@@ -88,6 +105,8 @@
                                         InsOrderStandardTemplate::getTemperature, dto.getTemperature())
                                 .set(dto.isDetectionTimePresent(),
                                         InsOrderStandardTemplate::getDetectionTime, dto.getDetectionTime())
+                                .set(hasDetectionRange,
+                                        InsOrderStandardTemplate::getDetectionEndTime, dto.getDetectionEndTime())
                                 .set(dto.isDetectionPlacePresent(),
                                         InsOrderStandardTemplate::getDetectionPlace, dto.getDetectionPlace())
                                 .set(dto.isInsResultPresent(),
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java
index f8e1376..8401156 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java
@@ -231,8 +231,6 @@
         info.setViewStatus(false);
         info.setJumpPath(MenuJumpPathConstants.REPORT_PREPARATION);
         informationNotificationService.addInformationNotification(info);
-        String primaryReportUrl = getPrimaryReportUrl(insReport);
-
         // 鍒ゆ柇鏄惁鏄師鏉愭枡  闇�瑕佹浛鎹�****鎴愪緵搴斿晢
         IfsInventoryQuantity one = ifsInventoryQuantityMapper.selectOne(new LambdaQueryWrapper<IfsInventoryQuantity>()
                 .eq(IfsInventoryQuantity::getId, order.getIfsInventoryId()));
@@ -253,9 +251,7 @@
         }};
         writeMarksToReportFiles(insReport, writeMarks);
 
-        // 淇敼涓存椂pdf
-        String tempUrlPdf = wordToPdfTemp(primaryReportUrl.replace("/word", wordUrl));
-        insReport.setTempUrlPdf("/word/" + tempUrlPdf);
+        refreshTemporaryPreviews(insReport);
 
         insReportMapper.updateById(insReport);
 
@@ -383,16 +379,13 @@
         info.setViewStatus(false);
         info.setJumpPath(MenuJumpPathConstants.REPORT_PREPARATION);
         informationNotificationService.addInformationNotification(info);
-        String primaryReportUrl = getPrimaryReportUrl(insReport);
         Map<String, Object> examineMarks = new HashMap<String, Object>() {{
             put("examineUrl", ReportSignaturePictureUtils.create(imgUrl, signatureUrl));
             put("examineDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(null)).create());
         }};
         writeMarksToReportFiles(insReport, examineMarks);
 
-        // 淇敼涓存椂pdf
-        String tempUrlPdf = wordToPdfTemp(primaryReportUrl.replace("/word", wordUrl));
-        insReport.setTempUrlPdf("/word/" + tempUrlPdf);
+        refreshTemporaryPreviews(insReport);
 
         // 鍙戦�佷紒涓氬井淇¢�氱煡(閫氱煡鎵瑰噯浜哄鎵�)
         threadPoolTaskExecutor.execute(() -> {
@@ -728,6 +721,30 @@
                 .collect(Collectors.toList());
     }
 
+    private void refreshTemporaryPreviews(InsReport report) {
+        String primaryPdf = wordToPdfTemp(getPrimaryReportUrl(report).replace("/word", wordUrl));
+        if (StringUtils.isBlank(primaryPdf)) {
+            throw new ErrorException("妫�娴嬫姤鍛婇瑙堢敓鎴愬け璐�");
+        }
+        report.setTempUrlPdf("/word/" + primaryPdf);
+        if (StringUtils.isNotBlank(report.getInspectionUrl())) {
+            String inspectionPdf = wordToPdfTemp(report.getInspectionUrl().replace("/word", wordUrl));
+            if (StringUtils.isBlank(inspectionPdf)) {
+                throw new ErrorException("妫�楠屾姤鍛婇瑙堢敓鎴愬け璐�");
+            }
+            report.setInspectionTempUrlPdf("/word/" + inspectionPdf);
+        }
+    }
+
+    @Override
+    public String prepareEditedReportPreview(String absoluteDocxPath) {
+        String pdfName = wordToPdfTemp(absoluteDocxPath);
+        if (StringUtils.isBlank(pdfName)) {
+            throw new ErrorException("鎶ュ憡棰勮鐢熸垚澶辫触");
+        }
+        return "/word/" + pdfName;
+    }
+
     private void writeMarksToReportFiles(InsReport report, Map<String, Object> marks) {
         for (String reportUrl : getApprovalReportUrls(report)) {
             wordInsertUrl(marks, reportUrl.replace("/word", wordUrl));
@@ -804,7 +821,12 @@
             throw new ErrorException("鎶ュ憡鏂囦欢涓嶅瓨鍦紝璇疯仈绯荤鐞嗗憳");
         }
         try {
-            String filename = file.getFileName().toString();
+            // 鐗╃悊鏂囦欢鍙兘鏄� reviewed/edited UUID锛涘鐢ㄦ埛濮嬬粓浣跨敤涓氬姟鎶ュ憡缂栧彿銆�
+            String reportNumber = StringUtils.isBlank(report.getCode()) ? "鎶ュ憡" : report.getCode();
+            reportNumber = reportNumber.replaceAll("[\\\\/:*?\"<>|\\p{Cntrl}]", "-").trim();
+            String suffix = StringUtils.isNotBlank(report.getInspectionUrl())
+                    ? (Objects.equals(reportType, INSPECTION_REPORT) ? "-妫�楠屾姤鍛�" : "-妫�娴嬫姤鍛�") : "";
+            String filename = reportNumber + suffix + ".docx";
             String encodedName = URLEncoder.encode(filename, "UTF-8").replace("+", "%20");
             response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
             response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedName);
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/vo/TemplateConditionVo.java b/inspect-server/src/main/java/com/ruoyi/inspect/vo/TemplateConditionVo.java
index 7cb2540..54d253d 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/vo/TemplateConditionVo.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/vo/TemplateConditionVo.java
@@ -18,10 +18,14 @@
     @Schema(description = "娓╁害")
     private String temperature;
 
-    @Schema(description = "妫�娴嬫棩鏈�")
+    @Schema(description = "妫�娴嬪紑濮嬫棩鏈�")
     @JsonFormat(pattern = "yyyy-MM-dd")
     private LocalDate detectionTime;
 
+    @Schema(description = "妫�娴嬬粨鏉熸棩鏈�")
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private LocalDate detectionEndTime;
+
     @Schema(description = "妫�娴嬪湴鐐�")
     private String detectionPlace;
 
diff --git a/inspect-server/src/main/resources/static/detection-report-template-v2.docx b/inspect-server/src/main/resources/static/detection-report-template-v2.docx
index c646665..d3d398b 100644
--- a/inspect-server/src/main/resources/static/detection-report-template-v2.docx
+++ b/inspect-server/src/main/resources/static/detection-report-template-v2.docx
Binary files differ
diff --git a/inspect-server/src/main/resources/static/inspection-report-template-v2.docx b/inspect-server/src/main/resources/static/inspection-report-template-v2.docx
index f343020..9f14e59 100644
--- a/inspect-server/src/main/resources/static/inspection-report-template-v2.docx
+++ b/inspect-server/src/main/resources/static/inspection-report-template-v2.docx
Binary files differ

--
Gitblit v1.9.3