From 901bab9b8b1c3773a644bdc74f5eafd666591aeb Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 17 九月 2026 13:37:24 +0800
Subject: [PATCH] feat: 1委托单 2下单详情 3检验任务 4检验任务复核 5检验任务详情 6标准维护 7检验单详情 8报告编制

---
 basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardMethodServiceImpl.java |  251 +++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 216 insertions(+), 35 deletions(-)

diff --git a/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardMethodServiceImpl.java b/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardMethodServiceImpl.java
index df3cd31..67128b6 100644
--- a/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardMethodServiceImpl.java
+++ b/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardMethodServiceImpl.java
@@ -12,21 +12,36 @@
 import com.ruoyi.basic.mapper.StandardMethodMapper;
 import com.ruoyi.basic.mapper.StandardProductListMapper;
 import com.ruoyi.basic.mapper.StructureItemParameterMapper;
+import com.ruoyi.basic.mapper.StandardMethodIndustryMapper;
+import com.ruoyi.basic.mapper.StandardMethodAttachmentMapper;
+import com.ruoyi.basic.mapper.LaboratoryMapper;
+import com.ruoyi.basic.mapper.StandardTreeMapper;
+import com.ruoyi.basic.mapper.StandardTreeTemplateBindingMapper;
 import com.ruoyi.basic.pojo.StandardMethod;
+import com.ruoyi.basic.pojo.StandardMethodIndustry;
+import com.ruoyi.basic.pojo.StandardMethodAttachment;
+import com.ruoyi.basic.pojo.Laboratory;
+import com.ruoyi.basic.pojo.StandardTree;
+import com.ruoyi.basic.pojo.StandardTreeTemplateBinding;
 import com.ruoyi.basic.pojo.StandardProductList;
 import com.ruoyi.basic.pojo.StructureItemParameter;
 import com.ruoyi.basic.service.StandardMethodService;
 import com.ruoyi.basic.service.StandardProductListService;
 import com.ruoyi.basic.service.StructureItemParameterService;
-import lombok.AllArgsConstructor;
+import com.ruoyi.basic.utils.StandardTreePath;
+import com.ruoyi.basic.utils.StandardTreePathParser;
+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 com.ruoyi.common.exception.base.BaseException;
 
+import java.io.File;
 import java.io.IOException;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
-import java.util.stream.Collectors;
 
 /**
  * @author Administrator
@@ -34,7 +49,6 @@
  * @createDate 2024-03-03 19:21:41
  */
 @Service
-@AllArgsConstructor
 public class StandardMethodServiceImpl extends ServiceImpl<StandardMethodMapper, StandardMethod>
         implements StandardMethodService {
 
@@ -47,9 +61,51 @@
     private StructureItemParameterMapper structureItemParameterMapper;
     private StructureItemParameterService structureItemParameterService;
 
+    private StandardMethodIndustryMapper standardMethodIndustryMapper;
+    private StandardMethodAttachmentMapper standardMethodAttachmentMapper;
+    private LaboratoryMapper laboratoryMapper;
+    private StandardTreeMapper standardTreeMapper;
+    private StandardTreeTemplateBindingMapper standardTreeTemplateBindingMapper;
+
+    @Value("${file.path}")
+    private String filePath;
+
+    @Value("${wordUrl}")
+    private String wordUrl;
+
+    /**
+     * 涓氬姟渚濊禆鐢辨瀯閫犲櫒娉ㄥ叆锛涙枃浠惰矾寰勭敱 @Value 浠庨厤缃鍙栵紝涓嶈兘鍙備笌 Lombok 鐨勫叏鍙傛瀯閫犲櫒锛�
+     * 鍚﹀垯 Spring 浼氭妸 String 璇涓洪渶瑕佹敞鍏ョ殑 Bean銆�
+     */
+    public StandardMethodServiceImpl(StandardMethodMapper standardMethodMapper,
+                                     StandardProductListMapper standardProductListMapper,
+                                     StandardProductListService standardProductListService,
+                                     StructureItemParameterMapper structureItemParameterMapper,
+                                     StructureItemParameterService structureItemParameterService,
+                                     StandardMethodIndustryMapper standardMethodIndustryMapper,
+                                     StandardMethodAttachmentMapper standardMethodAttachmentMapper,
+                                     LaboratoryMapper laboratoryMapper,
+                                     StandardTreeMapper standardTreeMapper,
+                                     StandardTreeTemplateBindingMapper standardTreeTemplateBindingMapper) {
+        this.standardMethodMapper = standardMethodMapper;
+        this.standardProductListMapper = standardProductListMapper;
+        this.standardProductListService = standardProductListService;
+        this.structureItemParameterMapper = structureItemParameterMapper;
+        this.structureItemParameterService = structureItemParameterService;
+        this.standardMethodIndustryMapper = standardMethodIndustryMapper;
+        this.standardMethodAttachmentMapper = standardMethodAttachmentMapper;
+        this.laboratoryMapper = laboratoryMapper;
+        this.standardTreeMapper = standardTreeMapper;
+        this.standardTreeTemplateBindingMapper = standardTreeTemplateBindingMapper;
+    }
+
     @Override
     public IPage<StandardMethod> selectStandardMethodList(Page page, StandardMethod standardMethod) {
-        return standardMethodMapper.selectStandardMethodList(page, QueryWrappers.queryWrappers(standardMethod));
+        IPage<StandardMethod> result = standardMethodMapper.selectStandardMethodList(page, QueryWrappers.queryWrappers(standardMethod));
+        for (StandardMethod method : result.getRecords()) {
+            method.setIndustryIds(selectIndustryIds(method.getId()));
+        }
+        return result;
     }
 
     @Override
@@ -58,25 +114,167 @@
     }
 
     @Override
-    public int addStandardMethod(StandardMethod standardMethod) {
-        int insert = standardMethodMapper.insert(standardMethod);
-        return insert;
+    @Transactional(rollbackFor = Exception.class)
+    public Integer addStandardMethod(StandardMethod standardMethod) {
+        standardMethod.setStructureTestObjectId(null);
+        standardMethodMapper.insert(standardMethod);
+        syncIndustries(standardMethod, Collections.<Integer>emptySet());
+        return standardMethod.getId();
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public int delStandardMethod(Integer id) {
-        int i = standardMethodMapper.deleteById(id);
-        return i;
+        StandardMethod method = standardMethodMapper.selectById(id);
+        if (method == null) {
+            throw new BaseException("鏍囧噯涓嶅瓨鍦�");
+        }
+        for (Integer industryId : selectIndustryIds(id)) {
+            removeIndustryTree(method, industryId);
+        }
+        standardMethodIndustryMapper.delete(Wrappers.<StandardMethodIndustry>lambdaQuery()
+                .eq(StandardMethodIndustry::getStandardMethodId, id));
+        standardMethodAttachmentMapper.delete(Wrappers.<StandardMethodAttachment>lambdaQuery()
+                .eq(StandardMethodAttachment::getStandardMethodId, id));
+        return standardMethodMapper.deleteById(id);
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public int upStandardMethod(StandardMethod standardMethod) {
         StandardMethod oldStandardMethod = standardMethodMapper.selectById(standardMethod.getId());
+        if (oldStandardMethod == null) {
+            throw new BaseException("鏍囧噯涓嶅瓨鍦�");
+        }
         if (!oldStandardMethod.getCode().equals(standardMethod.getCode())) {
             CompletableFuture.supplyAsync(() -> replaceMethod(oldStandardMethod.getCode(), standardMethod.getCode()));
         }
         int i = standardMethodMapper.updateById(standardMethod);
+        syncIndustries(standardMethod, new LinkedHashSet<>(selectIndustryIds(oldStandardMethod.getId())));
         return i;
+    }
+
+    private List<Integer> selectIndustryIds(Integer methodId) {
+        List<StandardMethodIndustry> list = standardMethodIndustryMapper.selectList(
+                Wrappers.<StandardMethodIndustry>lambdaQuery()
+                        .eq(StandardMethodIndustry::getStandardMethodId, methodId));
+        List<Integer> ids = new ArrayList<>();
+        for (StandardMethodIndustry item : list) {
+            ids.add(item.getIndustryId());
+        }
+        return ids;
+    }
+
+    private void syncIndustries(StandardMethod method, Set<Integer> oldIds) {
+        Set<Integer> newIds = method.getIndustryIds() == null ? new LinkedHashSet<Integer>()
+                : new LinkedHashSet<>(method.getIndustryIds());
+        for (Integer industryId : newIds) {
+            if (industryId == null || laboratoryMapper.selectById(industryId) == null) {
+                throw new BaseException("琛屼笟涓嶅瓨鍦�");
+            }
+        }
+        for (Integer oldId : oldIds) {
+            if (!newIds.contains(oldId)) {
+                removeIndustryTree(method, oldId);
+                standardMethodIndustryMapper.delete(Wrappers.<StandardMethodIndustry>lambdaQuery()
+                        .eq(StandardMethodIndustry::getStandardMethodId, method.getId())
+                        .eq(StandardMethodIndustry::getIndustryId, oldId));
+            }
+        }
+        for (Integer industryId : newIds) {
+            Laboratory lab = laboratoryMapper.selectById(industryId);
+            Long count = standardMethodIndustryMapper.selectCount(Wrappers.<StandardMethodIndustry>lambdaQuery()
+                    .eq(StandardMethodIndustry::getStandardMethodId, method.getId())
+                    .eq(StandardMethodIndustry::getIndustryId, industryId));
+            if (count == 0) {
+                StandardMethodIndustry relation = new StandardMethodIndustry();
+                relation.setStandardMethodId(method.getId());
+                relation.setIndustryId(industryId);
+                standardMethodIndustryMapper.insert(relation);
+            }
+            StandardTree tree = standardTreeMapper.selectOne(Wrappers.<StandardTree>lambdaQuery()
+                    .eq(StandardTree::getLaboratory, lab.getLaboratoryName())
+                    .eq(StandardTree::getStandardMethodId, method.getId())
+                    .isNull(StandardTree::getSampleType).isNull(StandardTree::getModel));
+            if (tree == null) {
+                tree = new StandardTree();
+                tree.setLaboratory(lab.getLaboratoryName());
+                tree.setSample(buildLabel(method));
+                tree.setStandardMethodId(method.getId());
+                tree.setSort(0);
+                standardTreeMapper.insert(tree);
+            } else if (!buildLabel(method).equals(tree.getSample())) {
+                StandardTree update = new StandardTree();
+                update.setId(tree.getId());
+                update.setSample(buildLabel(method));
+                standardTreeMapper.updateById(update);
+            }
+        }
+    }
+
+    private void removeIndustryTree(StandardMethod method, Integer industryId) {
+        Laboratory lab = laboratoryMapper.selectById(industryId);
+        if (lab == null) return;
+        StandardTree tree = standardTreeMapper.selectOne(Wrappers.<StandardTree>lambdaQuery()
+                .eq(StandardTree::getLaboratory, lab.getLaboratoryName())
+                .eq(StandardTree::getStandardMethodId, method.getId())
+                .isNull(StandardTree::getSampleType).isNull(StandardTree::getModel));
+        if (tree != null) {
+            standardTreeTemplateBindingMapper.delete(Wrappers.<StandardTreeTemplateBinding>lambdaQuery()
+                    .eq(StandardTreeTemplateBinding::getStandardTreeId, tree.getId()));
+            standardProductListMapper.delete(Wrappers.<StandardProductList>lambdaQuery()
+                    .eq(StandardProductList::getLaboratory, lab.getLaboratoryName())
+                    .eq(StandardProductList::getSample, tree.getSample())
+                    .isNull(StandardProductList::getSampleType).isNull(StandardProductList::getModel));
+            standardTreeMapper.deleteById(tree.getId());
+        }
+    }
+
+    private String buildLabel(StandardMethod method) {
+        return method.getCode().trim();
+    }
+
+    @Override
+    public List<StandardMethodAttachment> selectAttachments(Integer standardMethodId) {
+        return standardMethodAttachmentMapper.selectList(Wrappers.<StandardMethodAttachment>lambdaQuery()
+                .eq(StandardMethodAttachment::getStandardMethodId, standardMethodId)
+                .orderByAsc(StandardMethodAttachment::getSort, StandardMethodAttachment::getId));
+    }
+
+    @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");
+        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("涓嶆敮鎸佺殑闄勪欢鏍煎紡");
+        try {
+            boolean image = originalName.matches("(?i).+\\.(jpg|jpeg|png|gif)$");
+            File directory = new File(image ? filePath : wordUrl);
+            if (!directory.exists()) directory.mkdirs();
+            String fileUrl = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmssSSS")) + "-" + originalName;
+            file.transferTo(new File(directory, fileUrl));
+            StandardMethodAttachment attachment = new StandardMethodAttachment();
+            attachment.setStandardMethodId(standardMethodId);
+            attachment.setFileName(originalName);
+            attachment.setFileUrl(fileUrl);
+            attachment.setSort(selectAttachments(standardMethodId).size());
+            standardMethodAttachmentMapper.insert(attachment);
+            return attachment;
+        } catch (IOException e) {
+            throw new BaseException("闄勪欢涓婁紶澶辫触");
+        }
+    }
+
+    @Override
+    public boolean deleteAttachment(Long id) {
+        return standardMethodAttachmentMapper.deleteById(id) > 0;
+    }
+
+    @Override
+    public List<Laboratory> selectIndustryOptions() {
+        return laboratoryMapper.selectList(Wrappers.<Laboratory>lambdaQuery()
+                .select(Laboratory::getId, Laboratory::getLaboratoryName, Laboratory::getSort)
+                .orderByAsc(Laboratory::getSort, Laboratory::getId));
     }
 
     //缂栬緫method鍚庡叏閮ㄦ浛鎹�
@@ -172,33 +370,16 @@
         if (tree == null || tree.trim().isEmpty()) {
             return Collections.emptyMap();
         }
-        String[] trees = tree.split(" - ");
-        Map<String, List<?>> map = new HashMap<>();
-        String str = "";
-        List<StandardMethodList> standardMethodLists = new ArrayList<>();
-        switch (trees.length){
-            case 5:
-                str += "\"" + trees[2] + "\",\"" + trees[3] + "\",\"" + trees[4] + "\"";
-                standardMethodLists.addAll(standardMethodMapper.selectStandardMethodLists(str));
-                standardMethodLists.addAll(standardMethodMapper.selectStandardMethodLists("\"" + trees[2] + "\",\"" + trees[3] + "\""));
-                standardMethodLists.addAll(standardMethodMapper.selectStandardMethodLists("\"" + trees[2] + "\""));
-                break;
-            case 4:
-                str += "\"" + trees[2] + "\",\"" + trees[3] + "\"";
-                standardMethodLists.addAll(standardMethodMapper.selectStandardMethodLists(str));
-                standardMethodLists.addAll(standardMethodMapper.selectStandardMethodLists("\"" + trees[2] + "\""));
-                break;
-            case 3:
-                str += "\"" + trees[2] + "\"";
-                standardMethodLists.addAll(standardMethodMapper.selectStandardMethodLists3(str));
-                break;
-            default:
-                map.put("standardMethodList", null);
-                return map;
+        StandardTreePath path = StandardTreePathParser.parse(tree);
+        String industry = path.getIndustry();
+        List<StandardMethodList> standardMethodLists = new ArrayList<>(standardMethodMapper.selectStandardMethodListsByIndustry(industry));
+        // 鎸� ID 鍘婚噸锛屼繚鎸佺ǔ瀹氭帓搴�
+        Map<Integer, StandardMethodList> byId = new LinkedHashMap<>();
+        for (StandardMethodList m : standardMethodLists) {
+            byId.putIfAbsent(m.getId(), m);
         }
-        standardMethodLists.addAll(standardMethodMapper.selectStandardMethodListsByNull(str));
-        List<StandardMethodList> collect = standardMethodLists.stream().distinct().collect(Collectors.toList());
-        map.put("standardMethodList", collect);
+        Map<String, List<?>> map = new HashMap<>();
+        map.put("standardMethodList", new ArrayList<>(byId.values()));
         return map;
     }
 

--
Gitblit v1.9.3