From 7a8fe33d905a74e9cd092d9e9cc3d446c79b9c7e Mon Sep 17 00:00:00 2001
From: Xiajijian <1176061145@qq.com>
Date: Tue, 03 Mar 2026 08:58:19 +0800
Subject: [PATCH] 1. 修改分组无添加父级目录问题。

---
 ard-inspection/src/main/java/com/ard/inspection/service/impl/ArdInspectionGroupServiceImpl.java |  115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 110 insertions(+), 5 deletions(-)

diff --git a/ard-inspection/src/main/java/com/ard/inspection/service/impl/ArdInspectionGroupServiceImpl.java b/ard-inspection/src/main/java/com/ard/inspection/service/impl/ArdInspectionGroupServiceImpl.java
index bd73c0c..ce455a3 100644
--- a/ard-inspection/src/main/java/com/ard/inspection/service/impl/ArdInspectionGroupServiceImpl.java
+++ b/ard-inspection/src/main/java/com/ard/inspection/service/impl/ArdInspectionGroupServiceImpl.java
@@ -1,8 +1,10 @@
 package com.ard.inspection.service.impl;
 
+import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
+import java.util.stream.Collectors;
 
-import com.ard.common.annotation.DataScope;
 import com.ard.common.constant.UserConstants;
 import com.ard.common.core.domain.entity.SysUser;
 import com.ard.common.exception.ServiceException;
@@ -11,6 +13,7 @@
 import com.ard.common.utils.StringUtils;
 import com.ard.common.utils.spring.SpringUtils;
 import com.ard.inspection.domain.ArdInspectionGroup;
+import com.ard.inspection.domain.GroupTreeSelect;
 import com.ard.inspection.mapper.ArdInspectionGroupMapper;
 import com.ard.inspection.service.IArdInspectionGroupService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -58,9 +61,16 @@
      */
     @Override
     public int insertArdInspectionGroup(ArdInspectionGroup ardInspectionGroup) {
-        ArdInspectionGroup inspectionGroup = ardInspectionGroupMapper.selectArdInspectionGroupByGroupId(ardInspectionGroup.getGroupParentId());
-        ardInspectionGroup.setAncestors(inspectionGroup.getAncestors() + "," + ardInspectionGroup.getGroupParentId());
+        if (ardInspectionGroup.getGroupId() == null){
+            ardInspectionGroup.setGroupId((long) (ardInspectionGroupMapper.selectMaxGroupId() + 100));
+            ardInspectionGroup.setGroupParentId(0L);
+            ardInspectionGroup.setAncestors("0");
+        }else {
+            ArdInspectionGroup inspectionGroup = ardInspectionGroupMapper.selectArdInspectionGroupByGroupId(ardInspectionGroup.getGroupParentId());
+            ardInspectionGroup.setAncestors(inspectionGroup.getAncestors() + "," + ardInspectionGroup.getGroupParentId());
+        }
         ardInspectionGroup.setCreateTime(DateUtils.getNowDate());
+        ardInspectionGroup.setDelFlag("0");
         return ardInspectionGroupMapper.insertArdInspectionGroup(ardInspectionGroup);
     }
 
@@ -121,8 +131,9 @@
     @Override
     public boolean checkInspectionGroupNameUnique(ArdInspectionGroup ardInspectionGroup) {
         Long groupId = StringUtils.isNull(ardInspectionGroup.getGroupId()) ? -1L : ardInspectionGroup.getGroupId();
-        ArdInspectionGroup info = ardInspectionGroupMapper.checkInspectionGroupNameUnique(ardInspectionGroup.getGroupName(),ardInspectionGroup.getGroupParentId());
-        if (StringUtils.isNotNull(info) && info.getGroupId().longValue() != groupId.longValue())
+        ArdInspectionGroup infoA = ardInspectionGroupMapper.checkInspectionGroupNameUniqueA(ardInspectionGroup.getGroupName(),ardInspectionGroup.getGroupParentId());
+        ArdInspectionGroup infoB = ardInspectionGroupMapper.checkInspectionGroupNameUniqueB(ardInspectionGroup.getGroupName());
+        if (StringUtils.isNotNull(infoB) && infoB.getGroupId().longValue() != groupId.longValue())
         {
             return UserConstants.NOT_UNIQUE;
         }
@@ -170,4 +181,98 @@
         return result > 0;
     }
 
+    /**
+     * 查询分组树结构信息
+     *
+     * @param ardInspectionGroup 精细化巡检分组
+     * @return 分组树信息集合
+     */
+    @Override
+    public List<GroupTreeSelect> selectGroupTreeList(ArdInspectionGroup ardInspectionGroup)
+    {
+        List<ArdInspectionGroup> groups = selectArdInspectionGroupList(ardInspectionGroup);
+        return buildGroupTreeSelect(groups);
+    }
+
+    /**
+     * 构建前端所需要下拉树结构
+     *
+     * @param groups 分组列表
+     * @return 下拉树结构列表
+     */
+    @Override
+    public List<GroupTreeSelect> buildGroupTreeSelect(List<ArdInspectionGroup> groups){
+        List<ArdInspectionGroup> groupTrees = buildGroupTree(groups);
+        return groupTrees.stream().map(GroupTreeSelect::new).collect(Collectors.toList());
+    }
+
+    /**
+     * 构建前端所需要树结构
+     *
+     * @param groups 分组列表
+     * @return 树结构列表
+     */
+    @Override
+    public List<ArdInspectionGroup> buildGroupTree(List<ArdInspectionGroup> groups){
+        List<ArdInspectionGroup> returnList = new ArrayList<ArdInspectionGroup>();
+        List<Long> tempList = groups.stream().map(ArdInspectionGroup::getGroupId).collect(Collectors.toList());
+        for (ArdInspectionGroup group : groups)
+        {
+            // 如果是顶级节点, 遍历该父节点的所有子节点
+            if (!tempList.contains(group.getGroupParentId()))
+            {
+                recursionFn(groups, group);
+                returnList.add(group);
+            }
+        }
+        if (returnList.isEmpty())
+        {
+            returnList = groups;
+        }
+        return returnList;
+    }
+
+    /**
+     * 递归列表
+     */
+    private void recursionFn(List<ArdInspectionGroup> list, ArdInspectionGroup t)
+    {
+        // 得到子节点列表
+        List<ArdInspectionGroup> childList = getChildList(list, t);
+        t.setChildren(childList);
+        for (ArdInspectionGroup tChild : childList)
+        {
+            if (hasChild(list, tChild))
+            {
+                recursionFn(list, tChild);
+            }
+        }
+    }
+
+    /**
+     * 得到子节点列表
+     */
+    private List<ArdInspectionGroup> getChildList(List<ArdInspectionGroup> list, ArdInspectionGroup t)
+    {
+        List<ArdInspectionGroup> tlist = new ArrayList<ArdInspectionGroup>();
+        Iterator<ArdInspectionGroup> it = list.iterator();
+        while (it.hasNext())
+        {
+            ArdInspectionGroup n = (ArdInspectionGroup) it.next();
+            if (StringUtils.isNotNull(n.getGroupParentId()) && n.getGroupParentId().longValue() == t.getGroupId().longValue())
+            {
+                tlist.add(n);
+            }
+        }
+        return tlist;
+    }
+
+    /**
+     * 判断是否有子节点
+     */
+    private boolean hasChild(List<ArdInspectionGroup> list, ArdInspectionGroup t)
+    {
+        return getChildList(list, t).size() > 0;
+    }
+
 }

--
Gitblit v1.9.3