zhaowenyu
2026-01-16 226b062ef301b61260efac126e1db373ace85b87
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ard.inspection.mapper.ArdInspectionGroupMapper">
    
    <resultMap type="ArdInspectionGroup" id="ArdInspectionGroupResult">
        <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"    />
    </resultMap>
 
    <sql id="selectArdInspectionGroupVo">
        select group_id,
               group_parent_id,
               ancestors,
               group_name,
               order_num,
               create_by,
               create_time,
               update_by,
               update_time
        from ard_inspection_group
    </sql>
 
    <select id="selectArdInspectionGroupList" parameterType="ArdInspectionGroup" resultMap="ArdInspectionGroupResult">
        <include refid="selectArdInspectionGroupVo"/>
        <where>  
            <if test="groupParentId != null "> and group_parent_id = #{groupParentId}</if>
            <if test="ancestors != null  and ancestors != ''"> and ancestors = #{ancestors}</if>
            <if test="groupName != null  and groupName != ''"> and group_name like concat('%', #{groupName}, '%')</if>
            <if test="orderNum != null "> and order_num = #{orderNum}</if>
        </where>
    </select>
    
    <select id="selectArdInspectionGroupByGroupId" parameterType="Long" resultMap="ArdInspectionGroupResult">
        <include refid="selectArdInspectionGroupVo"/>
        where group_id = #{groupId}
    </select>
 
    <insert id="insertArdInspectionGroup" parameterType="ArdInspectionGroup" useGeneratedKeys="true" keyProperty="groupId">
        insert into ard_inspection_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="groupParentId != null">group_parent_id,</if>
            <if test="ancestors != null">ancestors,</if>
            <if test="groupName != null">group_name,</if>
            <if test="orderNum != null">order_num,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="groupParentId != null">#{groupParentId},</if>
            <if test="ancestors != null">#{ancestors},</if>
            <if test="groupName != null">#{groupName},</if>
            <if test="orderNum != null">#{orderNum},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>
 
    <update id="updateArdInspectionGroup" parameterType="ArdInspectionGroup">
        update ard_inspection_group
        <trim prefix="SET" suffixOverrides=",">
            <if test="groupParentId != null">group_parent_id = #{groupParentId},</if>
            <if test="ancestors != null">ancestors = #{ancestors},</if>
            <if test="groupName != null">group_name = #{groupName},</if>
            <if test="orderNum != null">order_num = #{orderNum},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where group_id = #{groupId}
    </update>
 
    <delete id="deleteArdInspectionGroupByGroupId" parameterType="Long">
        delete from ard_inspection_group where group_id = #{groupId}
    </delete>
 
    <delete id="deleteArdInspectionGroupByGroupIds" parameterType="String">
        delete from ard_inspection_group where group_id in 
        <foreach item="groupId" collection="array" open="(" separator="," close=")">
            #{groupId}
        </foreach>
    </delete>
 
    <select id="checkInspectionGroupNameUnique" resultMap="ArdInspectionGroupResult">
        <include refid="selectArdInspectionGroupVo"/>
        where group_name=#{groupName}
        and group_parent_id = #{groupParentId}
        and del_flag = '0' limit 1
    </select>
 
    <select id="selectChildrenInspectionGroupById" parameterType="Long" resultMap="ArdInspectionGroupResult">
        select * from ard_inspection_group where find_in_set(#{groupId}, ancestors)
    </select>
 
    <update id="updateInspectionGroupChildren" parameterType="java.util.List">
        update ard_inspection_group set ancestors =
        <foreach collection="inspectionGroups" item="item" index="index"
                 separator=" " open="case group_id" close="end">
            when #{item.groupId} then #{item.ancestors}
        </foreach>
        where group_id in
        <foreach collection="inspectionGroups" item="item" index="index"
                 separator="," open="(" close=")">
            #{item.groupId}
        </foreach>
    </update>
 
    <select id="hasChildByInspectionGroupId" parameterType="Long" resultType="int">
        select count(1) from ard_inspection_group
        where 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>
 
</mapper>