ard-inspection/src/main/resources/mapper/ArdInspectionGroupMapper.xml
@@ -5,15 +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="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">
@@ -25,28 +27,52 @@
               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>
            <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>
            del_flag = '0'
            <if test="groupId != null ">
                and group_id = #{groupId}
            </if>
            <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>
        order by group_parent_id, order_num
    </select>
    
    <select id="selectArdInspectionGroupByGroupId" parameterType="Long" resultMap="ArdInspectionGroupResult">
        <include refid="selectArdInspectionGroupVo"/>
        where group_id = #{groupId}
        SELECT
            g.group_id,
            g.group_parent_id,
            g.ancestors,
            g.group_name,
            g.order_num,
            ( SELECT group_name FROM ard_inspection_group WHERE group_id = g.group_parent_id) parent_name
        FROM
            ard_inspection_group g
        WHERE
            g.group_id = #{groupId}
    </select>
    <insert id="insertArdInspectionGroup" parameterType="ArdInspectionGroup" useGeneratedKeys="true" keyProperty="groupId">
    <insert id="insertArdInspectionGroup" parameterType="ArdInspectionGroup">
        insert into ard_inspection_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="groupId != null">group_id,</if>
            <if test="groupParentId != null">group_parent_id,</if>
            <if test="ancestors != null">ancestors,</if>
            <if test="groupName != null">group_name,</if>
@@ -57,6 +83,7 @@
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="groupId != null">#{groupId},</if>
            <if test="groupParentId != null">#{groupParentId},</if>
            <if test="ancestors != null">#{ancestors},</if>
            <if test="groupName != null">#{groupName},</if>
@@ -83,22 +110,27 @@
        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}
        and del_flag = '0' limit 1
        and group_parent_id = #{groupParentId} limit 1
    </select>
    <select id="checkInspectionGroupNameUniqueB" resultMap="ArdInspectionGroupResult">
        <include refid="selectArdInspectionGroupVo"/>
        where del_flag = '0'
        and group_name=#{groupName} limit 1
    </select>
    <select id="selectChildrenInspectionGroupById" parameterType="Long" resultMap="ArdInspectionGroupResult">
@@ -120,11 +152,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>