inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
@@ -1035,7 +1035,8 @@
    /**
     * 原始记录保存后,按当前模板选用的设备生成待填写的使用记录。
     * 同一订单、样品、设备只生成一条;已经填写过的记录不会被覆盖。
     * 同一订单、样品、设备只生成一条;温湿度和使用日期取原始记录快照,
     * 时间默认 10:00-19:30;已经手工填写过的记录不会被覆盖。
     */
    private synchronized void syncDeviceRecordsFromTemplate(Integer orderId, Integer sampleId,
                                                            Integer templateId, Integer userId) {
@@ -1052,6 +1053,24 @@
        if (CollectionUtils.isEmpty(deviceIds)) {
            return;
        }
        InsOrderStandardTemplate snapshot = insOrderStandardTemplateService.getOne(
                Wrappers.<InsOrderStandardTemplate>lambdaQuery()
                        .eq(InsOrderStandardTemplate::getInsOrderId, orderId)
                        .eq(InsOrderStandardTemplate::getTemplateId, templateId)
                        .last("limit 1"));
        String temperature = snapshot == null || StringUtils.isBlank(snapshot.getTemperature())
                ? order.getTemperature() : snapshot.getTemperature();
        String humidity = snapshot == null || StringUtils.isBlank(snapshot.getHumidity())
                ? order.getHumidity() : snapshot.getHumidity();
        // 原始记录没有检测日期时留空,不默认当天
        LocalDateTime useStartDate = null;
        LocalDateTime useEndDate = null;
        if (snapshot != null && snapshot.getDetectionTime() != null) {
            useStartDate = snapshot.getDetectionTime().atTime(10, 0);
            LocalDate endDate = snapshot.getDetectionEndTime() != null
                    ? snapshot.getDetectionEndTime() : snapshot.getDetectionTime();
            useEndDate = endDate.atTime(19, 30);
        }
        User user = userMapper.selectById(userId);
        String usePerson = user == null ? "" : user.getName();
        String sampleCode = StringUtils.isNotBlank(sample.getSampleCode())
@@ -1060,19 +1079,46 @@
            if (deviceId == null) {
                continue;
            }
            Long count = insOrderDeviceRecordMapper.selectCount(Wrappers.<InsOrderDeviceRecord>lambdaQuery()
                    .eq(InsOrderDeviceRecord::getInsOrderId, orderId)
                    .eq(InsOrderDeviceRecord::getDeviceId, deviceId)
                    .eq(InsOrderDeviceRecord::getSampleCode, sampleCode));
            if (count != null && count > 0) {
            InsOrderDeviceRecord existing = insOrderDeviceRecordMapper.selectOne(
                    Wrappers.<InsOrderDeviceRecord>lambdaQuery()
                            .eq(InsOrderDeviceRecord::getInsOrderId, orderId)
                            .eq(InsOrderDeviceRecord::getDeviceId, deviceId)
                            .eq(InsOrderDeviceRecord::getSampleCode, sampleCode)
                            .last("limit 1"));
            if (existing != null) {
                // 只补自动生成但尚未填写的记录
                if (existing.getUseStartDate() != null) {
                    continue;
                }
                InsOrderDeviceRecord update = new InsOrderDeviceRecord();
                update.setId(existing.getId());
                if (StringUtils.isBlank(existing.getTemperature())) {
                    update.setTemperature(temperature);
                }
                if (StringUtils.isBlank(existing.getHumidity())) {
                    update.setHumidity(humidity);
                }
                if (useStartDate != null) {
                    update.setUseStartDate(useStartDate);
                    update.setUseEndDate(useEndDate);
                }
                if (existing.getUsePersonId() == null) {
                    update.setUsePersonId(userId);
                }
                if (StringUtils.isBlank(existing.getUsePerson())) {
                    update.setUsePerson(usePerson);
                }
                insOrderDeviceRecordMapper.updateById(update);
                continue;
            }
            InsOrderDeviceRecord record = new InsOrderDeviceRecord();
            record.setInsOrderId(orderId);
            record.setDeviceId(deviceId);
            record.setSampleCode(sampleCode);
            record.setTemperature(order.getTemperature());
            record.setHumidity(order.getHumidity());
            record.setTemperature(temperature);
            record.setHumidity(humidity);
            record.setUseStartDate(useStartDate);
            record.setUseEndDate(useEndDate);
            record.setUseBefore(1);
            record.setUseAfter(1);
            record.setUsePersonId(userId);
@@ -1856,11 +1902,13 @@
            }
            // 检验人员提交复核时不生成报告;全部试验室复核通过后生成报告。
            if (report == null || StringUtils.isBlank(report.getUrl())) {
            boolean returnedFromReport = report != null && Objects.equals(report.getIsPass(), 0);
            if (report == null || StringUtils.isBlank(report.getUrl()) || returnedFromReport) {
                this.generateReport(orderId, DETECTION_REPORT, writeUserId);
            }
            // 直绑模板订单同时生成检验报告,两份文件共用同一条审批记录。
            if (directTemplateOrder && (report == null || StringUtils.isBlank(report.getInspectionUrl()))) {
            if (directTemplateOrder && (report == null || StringUtils.isBlank(report.getInspectionUrl())
                    || returnedFromReport)) {
                this.generateReport(orderId, INSPECTION_REPORT, writeUserId);
            }
            report = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery()