From bf2026a38d4d36371060673d4651b6e05ca90632 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期二, 01 九月 2026 17:07:30 +0800
Subject: [PATCH] feat(device): 1.更新设备导入验证逻辑和检验任务功能 2.报告编制

---
 cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceServiceImpl.java           |   50 ++++++++++++++-----------
 inspect-server/src/main/java/com/ruoyi/inspect/controller/InsOrderPlanController.java    |    4 +-
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java    |    3 +
 inspect-server/src/main/resources/static/small-wg-detection-template.docx                |    0 
 inspect-server/src/main/java/com/ruoyi/inspect/service/InsOrderPlanService.java          |    2 
 inspect-server/src/main/resources/static/small-detection-template.docx                   |    0 
 inspect-server/src/main/resources/static/detection-report-template.docx                  |    0 
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java |   27 ++++++++++---
 8 files changed, 54 insertions(+), 32 deletions(-)

diff --git a/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceServiceImpl.java b/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceServiceImpl.java
index 570a0f8..a58e4be 100644
--- a/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceServiceImpl.java
+++ b/cnas-device/src/main/java/com/ruoyi/device/service/impl/DeviceServiceImpl.java
@@ -547,17 +547,18 @@
             throw new RuntimeException("瀵煎叆鏂囦欢娌℃湁璁惧鏁版嵁");
         }
 
-        Set<String> managementNumbers = new HashSet<>();
+        Set<String> fileKeys = new HashSet<>();
         for (int i = 0; i < rows.size(); i++) {
             String managementNumber = required(rows.get(i).getManagementNumber(), i + 2, "绠$悊缂栧彿");
-            if (!managementNumbers.add(managementNumber)) {
-                throw new RuntimeException("绗�" + (i + 2) + "琛岋細绠$悊缂栧彿" + managementNumber + "鍦ㄦ枃浠朵腑閲嶅");
+            String deviceName = required(rows.get(i).getDeviceName(), i + 2, "浠櫒鍚嶇О");
+            String specificationModel = required(rows.get(i).getSpecificationModel(), i + 2, "瑙勬牸鍨嬪彿");
+            if (!fileKeys.add(deviceKey(deviceName, specificationModel, managementNumber))) {
+                throw new RuntimeException("绗�" + (i + 2) + "琛岋細浠櫒鍚嶇О+瑙勬牸鍨嬪彿+绠$悊缂栧彿鍦ㄦ枃浠朵腑閲嶅");
             }
         }
-        Set<String> existingNumbers = baseMapper.selectList(Wrappers.<Device>lambdaQuery()
-                        .in(Device::getManagementNumber, managementNumbers)
-                        .select(Device::getManagementNumber))
-                .stream().map(Device::getManagementNumber).collect(Collectors.toSet());
+        Set<String> existingKeys = baseMapper.selectList(Wrappers.<Device>lambdaQuery()
+                        .select(Device::getDeviceName, Device::getSpecificationModel, Device::getManagementNumber))
+                .stream().map(d -> deviceKey(d.getDeviceName(), d.getSpecificationModel(), d.getManagementNumber())).collect(Collectors.toSet());
 
         Map<String, List<SysDept>> departmentMap = sysDeptMapper.selectDeptList(new SysDept()).stream()
                 .filter(item -> StringUtils.isNotBlank(item.getDeptName()))
@@ -573,8 +574,10 @@
             int rowNumber = i + 2;
             DeviceImport row = rows.get(i);
             String managementNumber = required(row.getManagementNumber(), rowNumber, "绠$悊缂栧彿");
-            if (existingNumbers.contains(managementNumber)) {
-                throw new RuntimeException("绗�" + rowNumber + "琛岋細绠$悊缂栧彿" + managementNumber + "宸插瓨鍦�");
+            String deviceName = required(row.getDeviceName(), rowNumber, "浠櫒鍚嶇О");
+            String specificationModel = required(row.getSpecificationModel(), rowNumber, "瑙勬牸鍨嬪彿");
+            if (existingKeys.contains(deviceKey(deviceName, specificationModel, managementNumber))) {
+                throw new RuntimeException("绗�" + rowNumber + "琛岋細浠櫒鍚嶇О鈥�" + deviceName + "鈥�+瑙勬牸鍨嬪彿鈥�" + specificationModel + "鈥�+绠$悊缂栧彿鈥�" + managementNumber + "鈥濆凡瀛樺湪");
             }
 
             String laboratoryName = required(row.getLaboratoryName(), rowNumber, "鎵�灞為儴闂�");
@@ -584,10 +587,10 @@
             }
 
             Device device = new Device();
-            device.setDeviceName(required(row.getDeviceName(), rowNumber, "浠櫒鍚嶇О"));
-            device.setSpecificationModel(required(row.getSpecificationModel(), rowNumber, "瑙勬牸鍨嬪彿"));
+            device.setDeviceName(deviceName);
+            device.setSpecificationModel(specificationModel);
             device.setManagementNumber(managementNumber);
-            device.setActivationDate(parseDate(row.getActivationDate(), rowNumber, "鏍″噯鏈夋晥鏈�", true));
+            device.setActivationDate(parseDate(row.getActivationDate()));
             device.setSubordinateDepartmentsId(departments.get(0).getDeptId().intValue());
             device.setDeviceStatus(Integer.valueOf(dictValue(statusMap, row.getDeviceStatus(), rowNumber, "褰撳墠鐘舵��", true)));
             device.setCalibrationDate(required(row.getCalibrationDate(), rowNumber, "鏍″噯鍛ㄦ湡(鏈�)"));
@@ -596,12 +599,12 @@
             device.setFactoryNo(trim(row.getFactoryNo()));
             device.setAssetCode(trim(row.getAssetCode()));
             device.setOrigin(trim(row.getOrigin()));
-            device.setAcquisitionDate(parseDate(row.getAcquisitionDate(), rowNumber, "璐疆鏃ユ湡", false));
+            device.setAcquisitionDate(parseDate(row.getAcquisitionDate()));
             device.setStoragePoint(trim(row.getStoragePoint()));
             device.setTechnicalIndicators(trim(row.getTechnicalIndicators()));
             device.setCalibrationServices(trim(row.getCalibrationServices()));
-            device.setLastCalibrationDate(parseDate(row.getLastCalibrationDate(), rowNumber, "鏈�杩戞牎鍑嗘棩鏈�", false));
-            device.setNextCalibrationDate(parseDate(row.getNextCalibrationDate(), rowNumber, "涓嬫鏍″噯鏃ユ湡", false));
+            device.setLastCalibrationDate(parseDate(row.getLastCalibrationDate()));
+            device.setNextCalibrationDate(parseDate(row.getNextCalibrationDate()));
             device.setLargeCategory(dictValue(typeMap, row.getLargeCategory(), rowNumber, "璁惧绫诲瀷", false));
             device.setUnitPrice(parseDecimal(row.getUnitPrice(), rowNumber, "鍗曚环(涓囧厓)"));
 
@@ -642,19 +645,16 @@
         return value;
     }
 
-    private LocalDateTime parseDate(String input, int rowNumber, String column, boolean required) {
+    private LocalDateTime parseDate(String input) {
         String text = trim(input);
         if (StringUtils.isBlank(text)) {
-            if (required) {
-                throw new RuntimeException("绗�" + rowNumber + "琛岋細" + column + "涓嶈兘涓虹┖");
-            }
             return null;
         }
+        String datePart = text.replace('/', '-').split("\\s+")[0];
         try {
-            return LocalDate.parse(text.substring(0, Math.min(text.length(), 10)).replace('/', '-'), DateTimeFormatter.ofPattern("yyyy-M-d"))
-                    .atStartOfDay();
+            return LocalDate.parse(datePart, DateTimeFormatter.ofPattern("yyyy-M-d")).atStartOfDay();
         } catch (Exception e) {
-            throw new RuntimeException("绗�" + rowNumber + "琛岋細" + column + "鏍煎紡搴斾负yyyy-MM-dd", e);
+            return null;
         }
     }
 
@@ -678,6 +678,12 @@
         return value;
     }
 
+    private String deviceKey(String deviceName, String specificationModel, String managementNumber) {
+        return (deviceName == null ? "" : deviceName.trim()) + "|"
+                + (specificationModel == null ? "" : specificationModel.trim()) + "|"
+                + (managementNumber == null ? "" : managementNumber.trim());
+    }
+
     private String trim(String value) {
         return value == null ? null : value.trim();
     }
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/controller/InsOrderPlanController.java b/inspect-server/src/main/java/com/ruoyi/inspect/controller/InsOrderPlanController.java
index 3839fc7..814ba70 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/controller/InsOrderPlanController.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/controller/InsOrderPlanController.java
@@ -99,8 +99,8 @@
 
     @ApiOperation(value = "鏍¢獙妫�楠屼换鍔℃彁浜�")
     @PostMapping("/checkSubmitPlan")
-    public Result<?> checkSubmitPlan(Integer orderId, String laboratory) {
-        return Result.success(insOrderPlanService.checkSubmitPlan(orderId, laboratory));
+    public Result<?> checkSubmitPlan(Integer orderId, String laboratory, Integer reportType) {
+        return Result.success(insOrderPlanService.checkSubmitPlan(orderId, laboratory, reportType));
     }
 
 
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/InsOrderPlanService.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/InsOrderPlanService.java
index 5a71f3b..0aa126a 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/service/InsOrderPlanService.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/InsOrderPlanService.java
@@ -36,7 +36,7 @@
 
     List<InsProduct> getInsProduct(InsOrderPlanProductDto insOrderPlanProductDto);
 
-    Map<String,Object> checkSubmitPlan(Integer orderId, String laboratory);
+    Map<String,Object> checkSubmitPlan(Integer orderId, String laboratory, Integer reportType);
 
     IPage<InsOrderFile> getFileList(Page page, InsOrderFile insOrderFile);
 
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 31c71a6..161afd1 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
@@ -277,9 +277,14 @@
     }
 
     @Override
-    public Map<String,Object> checkSubmitPlan(Integer orderId, String laboratory) {
+    public Map<String,Object> checkSubmitPlan(Integer orderId, String laboratory, Integer reportType) {
         Map<String, Object> map = new HashMap<>();
         List<String> collect = new ArrayList<>();
+        if (Objects.equals(DETECTION_REPORT, reportType)) {
+            map.put("errorMsg", collect);
+            map.put("unInsOrderCount", 0L);
+            return map;
+        }
         List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId).select(InsSample::getId));
         List<Integer> ids = insSamples.stream().map(a -> a.getId()).collect(Collectors.toList());
         List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
@@ -773,7 +778,17 @@
         if (!Objects.equals(DETECTION_REPORT, reportType) && !Objects.equals(INSPECTION_REPORT, reportType)) {
             throw new ErrorException("璇烽�夋嫨鎶ュ憡绫诲瀷");
         }
-        InsOrder order = insOrderMapper.selectById(orderId);
+        InsOrder order = insOrderMapper.selectOne(Wrappers.<InsOrder>lambdaQuery()
+                .eq(InsOrder::getId, orderId)
+                .last("FOR UPDATE"));
+        InsReport existingReport = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery()
+                .eq(InsReport::getInsOrderId, orderId));
+        if (existingReport != null && existingReport.getReportType() != null
+                && !Objects.equals(existingReport.getReportType(), reportType)) {
+            throw new ErrorException("鍚屼竴妫�楠岃鍗曞彧鑳戒娇鐢ㄤ竴绉嶆姤鍛婄被鍨�");
+        }
+        boolean isInspectionReport = Objects.equals(INSPECTION_REPORT, reportType);
+        registerInsResults = isInspectionReport && Boolean.TRUE.equals(registerInsResults);
         // 1. 鍒ゆ柇鏄惁鏈夐噸澶嶇紪鍙�, 鏈夐噸澶嶇紪鍙峰仛鎻愰啋
         Long codeCount = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery()
                 .ne(InsOrder::getState, -1)
@@ -887,7 +902,7 @@
 
         // 11.鎴愬搧鎶芥牱娣诲姞鍚堟牸鐘舵��
         // 鍒ゆ柇鏄惁鏈夋娊鏍蜂俊鎭�
-        if (order.getQuarterItemId() != null) {
+        if (isInspectionReport && order.getQuarterItemId() != null) {
             // 鍒ゆ柇鏄惁鏈変笉鍚堟牸
             this.addProductSpotCheck(insSamples, order);
         }
@@ -942,7 +957,7 @@
         });
 
         // 14.ifs绉诲簱(鍘熸潗鏂欓渶瑕佽繘琛岀Щ搴撴搷浣�) --> 鏈�鍚庢墽琛�,鍥犱负澶辫触鏃犳硶鍥炴粴
-        if (ifsInventoryQuantity != null) {
+        if (ifsInventoryQuantity != null && isInspectionReport) {
             // 鐧昏妫�楠岀粨鏋�
             // 鍒ゆ柇鏄惁鏈変笉鍚堟牸, 鏈変笉鍚堟牸涓嶈兘绉诲簱
             // todo: ifs绉诲簱
@@ -956,7 +971,7 @@
             });
 
 
-        } else {
+        } else if (isInspectionReport) {
             // 淇敼鎴愬搧鐘舵��
             // 鍒ゆ柇鏄惁鏈変笉鍚堟牸
             Long unqualifiedCount = insReportService.getUnqualifiedCount(order);
@@ -983,7 +998,7 @@
     private void addAnalysis(List<InsProduct> productList, IfsInventoryQuantity ifsInventoryQuantity, InsOrder order, String sendUserAccount) {
         for (InsProduct insProduct : productList) {
             // 鍒ゆ柇鏄惁鏄暟鍊肩被鍨�
-            if (insProduct.getInspectionValueType().equals("1") && insProduct.getInsResult().equals(1)) {
+            if ("1".equals(insProduct.getInspectionValueType()) && Objects.equals(insProduct.getInsResult(), 1)) {
                 List<InsProductDeviationWarningDetail> insProductAnalysisDtoList = insProductMapper.selectAnalysis(insProduct, ifsInventoryQuantity.getSupplierName());
 
                 if (CollectionUtils.isEmpty(insProductAnalysisDtoList)) {
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 6d549f7..2354d4d 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
@@ -814,7 +814,8 @@
         // 鍒ゆ柇鏄惁鏈変笉鍚堟牸
         Long unqualifiedCount = getUnqualifiedCount(insOrder);
 
-        if (count.equals(0L) && unqualifiedCount.equals(0L) && one.getIsFinish().equals(0) && one.getIsSource().equals(1) && registerInsResults) {
+        if (count.equals(0L) && unqualifiedCount.equals(0L) && one.getIsFinish().equals(0)
+                && one.getIsSource().equals(1) && Boolean.TRUE.equals(registerInsResults)) {
             // 鍘熸潗鏂欑Щ搴�
             //濡傛灉鏄媶鍒嗙殑璁㈠崟锛屽垯鎶婃媶鍒嗙殑鎵�鏈夋壒娆¢兘绉诲簱
             if(one.getIsSplitOrder()==1 && !hasExemption){
diff --git a/inspect-server/src/main/resources/static/detection-report-template.docx b/inspect-server/src/main/resources/static/detection-report-template.docx
index 674f63a..e748edb 100644
--- a/inspect-server/src/main/resources/static/detection-report-template.docx
+++ b/inspect-server/src/main/resources/static/detection-report-template.docx
Binary files differ
diff --git a/inspect-server/src/main/resources/static/small-detection-template.docx b/inspect-server/src/main/resources/static/small-detection-template.docx
index aa5fc27..8cbfc1f 100644
--- a/inspect-server/src/main/resources/static/small-detection-template.docx
+++ b/inspect-server/src/main/resources/static/small-detection-template.docx
Binary files differ
diff --git a/inspect-server/src/main/resources/static/small-wg-detection-template.docx b/inspect-server/src/main/resources/static/small-wg-detection-template.docx
index 10b5e34..053779f 100644
--- a/inspect-server/src/main/resources/static/small-wg-detection-template.docx
+++ b/inspect-server/src/main/resources/static/small-wg-detection-template.docx
Binary files differ

--
Gitblit v1.9.3