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 |   16 ++++++--
 ard-inspection/src/main/java/com/ard/inspection/domain/ArdInspectionGroup.java                  |   34 +++++++++++++++++
 ard-inspection/src/main/java/com/ard/inspection/mapper/ArdInspectionGroupMapper.java            |   12 +++++
 ard-inspection/src/main/resources/mapper/ArdInspectionGroupMapper.xml                           |   50 ++++++++++++++++---------
 4 files changed, 89 insertions(+), 23 deletions(-)

diff --git a/ard-inspection/src/main/java/com/ard/inspection/domain/ArdInspectionGroup.java b/ard-inspection/src/main/java/com/ard/inspection/domain/ArdInspectionGroup.java
index bf9a137..cad7f82 100644
--- a/ard-inspection/src/main/java/com/ard/inspection/domain/ArdInspectionGroup.java
+++ b/ard-inspection/src/main/java/com/ard/inspection/domain/ArdInspectionGroup.java
@@ -1,6 +1,9 @@
 package com.ard.inspection.domain;
 
 import com.ard.common.core.domain.BaseEntity;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
 import javax.validation.constraints.NotBlank;
 import javax.validation.constraints.Size;
 import java.util.ArrayList;
@@ -30,6 +33,9 @@
 
     /** 显示顺序 */
     private Integer orderNum;
+
+    /** 删除标志(0代表存在 2代表删除) */
+    private String delFlag;
 
     /** 父部门名称 */
     private String parentName;
@@ -95,4 +101,32 @@
         this.children = children;
     }
 
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public String getDelFlag() {
+        return delFlag;
+    }
+
+    public void setDelFlag(String delFlag) {
+        this.delFlag = delFlag;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+            .append("groupId", getGroupId())
+            .append("groupParentId", getGroupParentId())
+            .append("ancestors", getAncestors())
+            .append("groupName", getGroupName())
+            .append("orderNum", getOrderNum())
+            .append("status", getStatus())
+            .append("delFlag", getDelFlag())
+            .toString();
+    }
 }
diff --git a/ard-inspection/src/main/java/com/ard/inspection/mapper/ArdInspectionGroupMapper.java b/ard-inspection/src/main/java/com/ard/inspection/mapper/ArdInspectionGroupMapper.java
index c076a4c..e902b9b 100644
--- a/ard-inspection/src/main/java/com/ard/inspection/mapper/ArdInspectionGroupMapper.java
+++ b/ard-inspection/src/main/java/com/ard/inspection/mapper/ArdInspectionGroupMapper.java
@@ -69,8 +69,10 @@
      * @param groupParentId 分组父部门ID
      * @return 结果
      */
-    public ArdInspectionGroup checkInspectionGroupNameUnique(@Param("groupName") String groupName,
+    public ArdInspectionGroup checkInspectionGroupNameUniqueA(@Param("groupName") String groupName,
                                                              @Param("groupParentId") Long groupParentId);
+
+    public ArdInspectionGroup checkInspectionGroupNameUniqueB(@Param("groupName") String groupName);
 
     /**
      * 根据ID查询所有子分组
@@ -103,4 +105,12 @@
      * @return 结果 true 存在 false 不存在
      */
     public int checkInspectionGroupExistUser(Long groupId);
+
+    /**
+     * 查询groupId最大值
+     *
+     * @return 结果 true 存在 false 不存在
+     */
+    public int selectMaxGroupId();
+
 }
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 57ce7f7..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
@@ -61,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);
     }
 
@@ -124,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;
         }
diff --git a/ard-inspection/src/main/resources/mapper/ArdInspectionGroupMapper.xml b/ard-inspection/src/main/resources/mapper/ArdInspectionGroupMapper.xml
index a2b0da0..fca3437 100644
--- a/ard-inspection/src/main/resources/mapper/ArdInspectionGroupMapper.xml
+++ b/ard-inspection/src/main/resources/mapper/ArdInspectionGroupMapper.xml
@@ -5,16 +5,17 @@
 <mapper namespace="com.ard.inspection.mapper.ArdInspectionGroupMapper">
     
     <resultMap type="ArdInspectionGroup" id="ArdInspectionGroupResult">
-        <result property="groupId"    column="group_id"    />
+        <result property="groupId"          column="group_id"           />
         <result property="groupParentId"    column="group_parent_id"    />
-        <result property="ancestors"    column="ancestors"    />
-        <result property="groupName"    column="group_name"    />
-        <result property="orderNum"    column="order_num"    />
-        <result property="createBy"    column="create_by"    />
-        <result property="createTime"    column="create_time"    />
-        <result property="updateBy"    column="update_by"    />
-        <result property="updateTime"    column="update_time"    />
-        <result property="parentName" column="parent_name" />
+        <result property="ancestors"        column="ancestors"          />
+        <result property="groupName"        column="group_name"         />
+        <result property="orderNum"         column="order_num"          />
+        <result property="createBy"         column="create_by"          />
+        <result property="createTime"       column="create_time"        />
+        <result property="updateBy"         column="update_by"          />
+        <result property="updateTime"       column="update_time"        />
+        <result property="delFlag"          column="del_flag"           />
+        <result property="parentName"       column="parent_name"        />
     </resultMap>
 
     <sql id="selectArdInspectionGroupVo">
@@ -26,13 +27,15 @@
                create_by,
                create_time,
                update_by,
-               update_time
+               update_time,
+               del_flag
         from ard_inspection_group
     </sql>
 
     <select id="selectArdInspectionGroupList" parameterType="ArdInspectionGroup" resultMap="ArdInspectionGroupResult">
         <include refid="selectArdInspectionGroupVo"/>
         <where>
+            del_flag = '0'
             <if test="groupId != null ">
                 and group_id = #{groupId}
             </if>
@@ -107,21 +110,26 @@
         where group_id = #{groupId}
     </update>
 
-    <delete id="deleteArdInspectionGroupByGroupId" parameterType="Long">
-        delete from ard_inspection_group where group_id = #{groupId}
-    </delete>
+    <update id="deleteArdInspectionGroupByGroupId" parameterType="Long">
+        update ard_inspection_group set del_flag = '2' where group_id = #{groupId}
+    </update>
 
-    <delete id="deleteArdInspectionGroupByGroupIds" parameterType="String">
-        delete from ard_inspection_group where group_id in 
+    <update id="deleteArdInspectionGroupByGroupIds" parameterType="String">
+        update ard_inspection_group set del_flag = '2' where group_id in
         <foreach item="groupId" collection="array" open="(" separator="," close=")">
             #{groupId}
         </foreach>
-    </delete>
+    </update>
 
-    <select id="checkInspectionGroupNameUnique" resultMap="ArdInspectionGroupResult">
+    <select id="checkInspectionGroupNameUniqueA" resultMap="ArdInspectionGroupResult">
         <include refid="selectArdInspectionGroupVo"/>
         where group_name=#{groupName}
         and group_parent_id = #{groupParentId} limit 1
+    </select>
+
+    <select id="checkInspectionGroupNameUniqueB" resultMap="ArdInspectionGroupResult">
+        <include refid="selectArdInspectionGroupVo"/>
+        where group_name=#{groupName} limit 1
     </select>
 
     <select id="selectChildrenInspectionGroupById" parameterType="Long" resultMap="ArdInspectionGroupResult">
@@ -143,11 +151,17 @@
 
     <select id="hasChildByInspectionGroupId" parameterType="Long" resultType="int">
         select count(1) from ard_inspection_group
-        where group_parent_id = #{groupId} limit 1
+        where del_flag = '0' and group_parent_id = #{groupId} limit 1
     </select>
 
     <select id="checkInspectionGroupExistUser" parameterType="Long" resultType="int">
         select count(1) from sys_user where group_id = #{groupId} and del_flag = '0'
     </select>
 
+    <select id="selectMaxGroupId" resultType="int">
+        SELECT group_id FROM ard_inspection_group
+        WHERE group_parent_id = 0 AND ancestors = 0
+        ORDER BY group_id DESC LIMIT 1
+    </select>
+
 </mapper>
\ No newline at end of file

--
Gitblit v1.9.3