From c072682530bb797bf7a5eaffc87e1e2b394d3b60 Mon Sep 17 00:00:00 2001
From: deslrey <deslre0381@gmail.com>
Date: 星期二, 13 一月 2026 09:08:26 +0800
Subject: [PATCH] 新增取消拖拽功能造成的删除和插入操作接口

---
 basic-server/src/main/java/com/ruoyi/basic/controller/StandardTreeController.java           |    6 +
 basic-server/src/main/java/com/ruoyi/basic/service/StandardProductListService.java          |    7 +
 basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardProductListServiceImpl.java |  240 +++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 242 insertions(+), 11 deletions(-)

diff --git a/basic-server/src/main/java/com/ruoyi/basic/controller/StandardTreeController.java b/basic-server/src/main/java/com/ruoyi/basic/controller/StandardTreeController.java
index 499d73b..5a7a552 100644
--- a/basic-server/src/main/java/com/ruoyi/basic/controller/StandardTreeController.java
+++ b/basic-server/src/main/java/com/ruoyi/basic/controller/StandardTreeController.java
@@ -94,6 +94,12 @@
         return Result.success(standardProductListService.selectStandardProductListByMethodId(id, tree));
     }
 
+    @ApiOperation(value = "閫氳繃妫�楠屾爣鍑嗘煡璇㈡楠岄」鐩�")
+    @GetMapping("/buildStandardProductListNoDrag")
+    public Result selectStandardProductListByMethodId1(Integer id, String tree) {
+        return Result.success(standardProductListService.buildStandardProductListNoDrag(id, tree));
+    }
+
     @ApiOperation(value = "鎵归噺鏌ヨ妫�楠岄」鐩�")
     @GetMapping("/selectStandardProductByMethodId")
     public Result selectStandardProductByMethodId(Integer id, String tree, Integer page, String laboratory, String item, String items) {
diff --git a/basic-server/src/main/java/com/ruoyi/basic/service/StandardProductListService.java b/basic-server/src/main/java/com/ruoyi/basic/service/StandardProductListService.java
index f2eff64..47d8f70 100644
--- a/basic-server/src/main/java/com/ruoyi/basic/service/StandardProductListService.java
+++ b/basic-server/src/main/java/com/ruoyi/basic/service/StandardProductListService.java
@@ -24,6 +24,8 @@
 
     Map<String, Object> selectStandardProductListByMethodId(Integer id, String tree);
 
+    Map<String, Object> buildStandardProductListNoDrag(Integer id, String tree);
+
     IPage<StandardProductList> selectStandardProductByMethodId(Integer id, String tree, Integer page, String laboratory, String item, String items);
 
     Map<String, List<?>> selectStandardProductEnumByMethodId(Integer id, String tree, String item);
@@ -32,18 +34,21 @@
 
     /**
      * 鏍囧噯搴撴嫋鎷�
+     *
      * @param resetTreeDragDTO
      */
     void resetTreeDrag(ResetTreeDragDTO resetTreeDragDTO);
 
     /**
      * 鏍囧噯搴撴嫋鎷�
+     *
      * @param standardProductLists
      */
     void resetTreeDragBatch(List<StandardProductList> standardProductLists);
 
     /**
      * 妫�楠岄」瑕佹眰鍊煎姣�
+     *
      * @param copyStandardProductListDto
      * @return
      */
@@ -51,6 +56,7 @@
 
     /**
      * 妫�楠岄」瑕佹眰鍊煎姣斾竴涓�
+     *
      * @param copyStandardProductListDto
      * @return
      */
@@ -58,6 +64,7 @@
 
     /**
      * 妫�楠岄」澶嶅埗鎺掑簭
+     *
      * @param copyStandardProductListDto
      * @return
      */
diff --git a/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardProductListServiceImpl.java b/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardProductListServiceImpl.java
index 06567df..51dd916 100644
--- a/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardProductListServiceImpl.java
+++ b/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardProductListServiceImpl.java
@@ -189,16 +189,15 @@
     }
 
     /**
-     *
-     * @param str                 鍒ゅ畾鍏紡
-     * @param model               鍨嬪彿
-     * @param standardCores       鑺暟
-     * @param conductorMaterial   瀵间綋鏉愯川
-     * @param conductorType       瀵间綋绫诲瀷
+     * @param str               鍒ゅ畾鍏紡
+     * @param model             鍨嬪彿
+     * @param standardCores     鑺暟
+     * @param conductorMaterial 瀵间綋鏉愯川
+     * @param conductorType     瀵间綋绫诲瀷
      * @param insSample
      * @return
      */
-    private boolean getIsIf(String str, String model, String standardCores, String conductorMaterial, String conductorType,InsSampleReceiveDto insSample) {
+    private boolean getIsIf(String str, String model, String standardCores, String conductorMaterial, String conductorType, InsSampleReceiveDto insSample) {
         Matcher matcher = Pattern.compile("\\d+(\\.\\d+)?").matcher(model);
         String model2 = "";
         while (matcher.find()) {
@@ -452,11 +451,225 @@
                 return Integer.compare(num1, num2);
             }
         });
-          // 鎸夌収绱㈠紩鎺掑簭
+        // 鎸夌収绱㈠紩鎺掑簭
         if (isDrag) {
-            list.sort((o1, o2) -> (o1.getSort() == null ? 0 : o1.getSort())
-                    - (o2.getSort() == null ? 0 : o2.getSort()));
+            list.sort(Comparator.comparingInt(o -> (o.getSort() == null ? 0 : o.getSort())));
         }
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("productList", list);
+        map.put("total", list.size());
+        return map;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Map<String, Object> buildStandardProductListNoDrag(Integer id, String tree) {
+
+        String[] trees = tree.split(" - ");
+        List<StandardProductList> list = new ArrayList<>();
+        if (trees.length == 3) {
+            List<StandardTree> treeList = new ArrayList<>();
+            StandardTree standardTree = new StandardTree();
+            standardTree.setFactory(trees[0]);
+            standardTree.setLaboratory(trees[1]);
+            standardTree.setSampleType(trees[2]);
+
+            List<ProductDto> pList = standardTreeMapper.selectPList(trees[2]);
+            if (CollectionUtils.isEmpty(pList) || pList.get(0) == null) {
+                List<StandardTree> treeList1 =
+                        standardTreeMapper.selectList(
+                                Wrappers.<StandardTree>lambdaQuery()
+                                        .eq(StandardTree::getLaboratory, trees[1])
+                                        .eq(StandardTree::getSampleType, trees[2])
+                        );
+                if (CollectionUtils.isEmpty(treeList1)) {
+                    treeList.add(standardTree);
+                } else {
+                    treeList.addAll(treeList1);
+                }
+            } else {
+                for (ProductDto p : pList) {
+                    standardTree.setSample(p.getName());
+                    List<StandardTree> treeList1 =
+                            standardTreeMapper.selectList(
+                                    Wrappers.<StandardTree>lambdaQuery()
+                                            .eq(StandardTree::getLaboratory, trees[1])
+                                            .eq(StandardTree::getSampleType, trees[2])
+                                            .eq(StandardTree::getSample, p.getName())
+                            );
+                    if (CollectionUtils.isEmpty(treeList1)) {
+                        treeList.add(JSON.parseObject(
+                                JSON.toJSONString(standardTree),
+                                StandardTree.class
+                        ));
+                    } else {
+                        treeList.addAll(treeList1);
+                    }
+                }
+            }
+
+            for (StandardTree st : treeList) {
+                String tree2 = trees[0] + " - " + trees[1] + " - " + trees[2]
+                        + " - " + st.getSample() + " - " + st.getModel();
+
+                list.addAll(
+                        standardTreeMapper.selectStandardProductListByTree(
+                                "\"" + trees[2] + "\"",
+                                st.getSample(),
+                                st.getModel(),
+                                tree2,
+                                trees[1]
+                        )
+                );
+                list.addAll(
+                        standardTreeMapper.selectStandardProductListByTree2(
+                                "\"" + trees[2] + "\",\"" + st.getSample() + "\"",
+                                st.getSample(),
+                                st.getModel(),
+                                tree2,
+                                trees[1]
+                        )
+                );
+            }
+
+        } else if (trees.length == 4) {
+
+            List<StandardTree> treeList =
+                    standardTreeMapper.selectList(
+                            Wrappers.<StandardTree>lambdaQuery()
+                                    .eq(StandardTree::getLaboratory, trees[1])
+                                    .eq(StandardTree::getSampleType, trees[2])
+                                    .eq(StandardTree::getSample, trees[3])
+                    );
+
+            if (CollectionUtils.isEmpty(treeList)) {
+                StandardTree st = new StandardTree();
+                st.setFactory(trees[0]);
+                st.setLaboratory(trees[1]);
+                st.setSampleType(trees[2]);
+                st.setSample(trees[3]);
+                treeList.add(st);
+            }
+
+            for (StandardTree st : treeList) {
+                String str = tree + " - " + st.getModel();
+                list.addAll(
+                        standardTreeMapper.selectStandardProductListByTree(
+                                "\"" + trees[2] + "\"",
+                                st.getSample(),
+                                st.getModel(),
+                                str,
+                                trees[1]
+                        )
+                );
+                list.addAll(
+                        standardTreeMapper.selectStandardProductListByTree2(
+                                "\"" + trees[2] + "\",\"" + trees[3] + "\"",
+                                st.getSample(),
+                                st.getModel(),
+                                str,
+                                trees[1]
+                        )
+                );
+            }
+
+        } else {
+            list.addAll(
+                    standardTreeMapper.selectStandardProductListByTree(
+                            "\"" + trees[2] + "\"",
+                            "null".equals(trees[3]) ? null : trees[3],
+                            trees[4],
+                            tree,
+                            trees[1]
+                    )
+            );
+            list.addAll(
+                    standardTreeMapper.selectStandardProductListByTree2(
+                            "\"" + trees[2] + "\",\"" + trees[3] + "\"",
+                            "null".equals(trees[3]) ? null : trees[3],
+                            trees[4],
+                            tree,
+                            trees[1]
+                    )
+            );
+        }
+
+        for (StandardProductList p : list) {
+            p.setId(IdWorker.getId());
+        }
+        List<StandardProductList> oldList =
+                standardProductListMapper.selectList(
+                        Wrappers.<StandardProductList>lambdaQuery()
+                                .eq(StandardProductList::getStandardMethodListId, id)
+                                .like(StandardProductList::getTree, tree)
+                );
+
+        for (StandardProductList old : oldList) {
+            for (StandardProductList cur : list) {
+
+                // 鍗婂緞鍙湁涓�涓�硷紝鑷姩璧嬪��
+                String radiusList = cur.getRadiusList();
+                if (StringUtils.isNotBlank(radiusList)
+                        && !"null".equals(radiusList)
+                        && !"\"\"".equals(radiusList)) {
+                    JSONArray jsonArray = JSON.parseArray(radiusList);
+                    List<String> radius = jsonArray.toJavaList(String.class);
+                    if (CollectionUtils.isNotEmpty(radius) && radius.size() == 1) {
+                        cur.setRadius(radius.get(0));
+                    }
+                }
+
+                if (Objects.equals(old.getInspectionItem(), cur.getInspectionItem())
+                        && Objects.equals(
+                        Objects.toString(old.getInspectionItemSubclass(), ""),
+                        Objects.toString(cur.getInspectionItemSubclass(), "")
+                )
+                        && Objects.equals(old.getModel(), cur.getModel())
+                        && old.getTree().contains(
+                        cur.getSample() == null ? "null" : cur.getSample()
+                )
+                        && Objects.equals(
+                        old.getStructureItemParameterId(),
+                        cur.getStructureItemParameterId()
+                )) {
+
+                    cur.setId(old.getId());
+                    cur.setSort(old.getSort());
+                    cur.setState(old.getState());
+                    cur.setMethod(old.getMethodS());
+                    cur.setRadius(old.getRadius());
+                    cur.setRates(old.getRates());
+                    cur.setAsk(old.getAsk());
+                    cur.setTell(old.getTell());
+                    cur.setPrice(old.getPrice());
+                    cur.setManHour(old.getManHour());
+                    cur.setSection(old.getSection());
+                    cur.setCores(old.getCores());
+                    cur.setConductorMaterial(old.getConductorMaterial());
+                    cur.setConductorType(old.getConductorType());
+                    cur.setTemplateId(old.getTemplateId());
+                    break;
+                }
+            }
+        }
+
+        list.sort((o1, o2) -> {
+            String f1 = o1.getManHourGroup();
+            String f2 = o2.getManHourGroup();
+
+            boolean e1 = StringUtils.isBlank(f1);
+            boolean e2 = StringUtils.isBlank(f2);
+
+            if (e1 && e2) return 0;
+            if (e1) return 1;
+            if (e2) return -1;
+
+            return Integer.compare(
+                    extractNumber(f1),
+                    extractNumber(f2)
+            );
+        });
 
         Map<String, Object> map = new HashMap<>();
         map.put("productList", list);
@@ -508,6 +721,7 @@
 
     /**
      * 淇敼鏍囧噯搴撳尯闂�
+     *
      * @param list
      * @return
      */
@@ -520,6 +734,7 @@
 
     /**
      * 鏍囧噯搴撴嫋鎷�
+     *
      * @param resetTreeDragDTO
      */
     @Override
@@ -538,7 +753,7 @@
                     resetTreeDragDTO.getTree());
 
             // 浠庝笅寰�涓�
-        } else if (beginIndex > endIndex){
+        } else if (beginIndex > endIndex) {
             standardProductListMapper.updateSortDown(beginIndex,
                     endIndex,
                     methodId,
@@ -559,6 +774,7 @@
 
     /**
      * 妫�楠岄」瑕佹眰鍊煎姣�
+     *
      * @param copyDto
      * @return
      */
@@ -602,6 +818,7 @@
 
     /**
      * 妫�楠岄」澶嶅埗瀵规瘮涓�涓�
+     *
      * @param dto
      * @return
      */
@@ -636,6 +853,7 @@
 
     /**
      * 妫�楠岄」澶嶅埗鎺掑簭
+     *
      * @param copyDto
      * @return
      */

--
Gitblit v1.9.3