zouyu
2 天以前 2ea3b36a810adcb639f4d3c72c860f722f601927
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
131
132
133
<?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.ruoyi.inspect.mapper.StaffCompetencyInspectItemConfigMapper">
 
    <resultMap id="BaseResultMap" type="com.ruoyi.inspect.pojo.StaffCompetencyInspectItemConfig">
            <id property="id" column="id" jdbcType="BIGINT"/>
            <result property="parentId" column="parent_id" jdbcType="BIGINT"/>
            <result property="ancestors" column="ancestors" jdbcType="VARCHAR"/>
            <result property="itemName" column="item_name" jdbcType="VARCHAR"/>
            <result property="sort" column="sort" jdbcType="INTEGER"/>
            <result property="isEnable" column="is_enable" jdbcType="BIT"/>
            <result property="createUser" column="create_user" jdbcType="INTEGER"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="updateUser" column="update_user" jdbcType="INTEGER"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>
 
    <sql id="Base_Column_List">
        id,parent_id,ancestors,item_name,
        sort,is_enable,create_user,
        create_time,update_user,update_time
    </sql>
 
    <sql id="selectConfigVo">
        select id,parent_id,ancestors,item_name,
               sort,is_enable,create_user,
               create_time,update_user,update_time
        from staff_competency_inspect_item_config
    </sql>
 
    <insert id="insertConfig">
        insert into staff_competency_inspect_item_config(
        <if test="config.parentId != null and config.parentId != 0">parent_id,</if>
        <if test="config.ancestors != null and config.ancestors != ''">ancestors,</if>
        <if test="config.itemName != null and config.itemName != ''">item_name,</if>
        <if test="config.sort != null">sort,</if>
        <if test="config.isEnable != null">is_enable</if>
        )values(
        <if test="config.parentId != null and config.parentId != 0">#{config.parentId},</if>
        <if test="config.ancestors != null and config.ancestors != ''">#{config.ancestors},</if>
        <if test="config.itemName != null and config.itemName != ''">#{config.itemName},</if>
        <if test="config.sort != null">#{config.sort},</if>
        <if test="config.isEnable != null">#{config.isEnable}</if>
        )
    </insert>
    <update id="updateConfig">
        update staff_competency_inspect_item_config
        <set>
            <if test="config.parentId != null and config.parentId != 0">parent_id = #{config.parentId},</if>
            <if test="config.itemName != null and config.itemName != ''">item_name = #{config.itemName},</if>
            <if test="config.ancestors != null and config.ancestors != ''">ancestors = #{config.ancestors},</if>
            <if test="config.sort != null">sort = #{config.sort},</if>
            <if test="config.isEnable != null">is_enable = #{config.isEnable}</if>
        </set>
        where id = #{config.id}
    </update>
    <update id="updateConfigStatusNormal">
        update staff_competency_inspect_item_config set is_enable = 1 where id in
        <foreach collection="configIds" item="configId" open="(" separator="," close=")">
            #{configId}
        </foreach>
    </update>
    <update id="updateConfigChildren">
        update staff_competency_inspect_item_config set ancestors =
        <foreach collection="children" item="item" index="index"
                 separator=" " open="case dept_id" close="end">
            when #{item.id} then #{item.ancestors}
        </foreach>
        where id in
        <foreach collection="children" item="item" index="index"
                 separator="," open="(" close=")">
            #{item.id}
        </foreach>
    </update>
    <select id="selectConfigList" resultType="com.ruoyi.inspect.pojo.StaffCompetencyInspectItemConfig">
        <include refid="selectConfigVo"/>
        where 1 = 1
        <if test="config.id != null and config.id != 0">
            AND id = #{config.id}
        </if>
        <if test="config.parentId != null and config.parentId != 0">
            AND parent_id = #{config.parentId}
        </if>
        <if test="config.itemName != null and config.itemName != ''">
            AND item_name like concat('%', #{config.itemName}, '%')
        </if>
        <if test="config.isEnable != null">
            AND is_enable = #{config.isEnable}
        </if>
        order by sort
    </select>
    <select id="selectConfigById" resultType="com.ruoyi.inspect.vo.StaffCompetencyInspectItemConfigVO">
        select <include refid="Base_Column_List"/>,
               (select item_name from staff_competency_inspect_item_config where id = parent_id) parent_name
        from staff_competency_inspect_item_config
        where id = #{configId}
    </select>
    <select id="checkDeptNameUnique" resultType="com.ruoyi.inspect.pojo.StaffCompetencyInspectItemConfig">
        <include refid="selectConfigVo"/>
        where item_name=#{itemName}
        <choose>
            <when test="parentId!=null and parentId!=''">
                and parent_id = #{parentId}
            </when>
            <when test="parentId==null or parentId==''">
                and parent_id &lt;= 0
            </when>
        </choose>
        limit 1
    </select>
    <select id="selectChildrenConfigById" resultType="com.ruoyi.inspect.pojo.StaffCompetencyInspectItemConfig">
        select * from staff_competency_inspect_item_config where find_in_set(#{configId}, ancestors)
    </select>
    <select id="hasChildByConfigId" resultType="java.lang.Integer">
        select count(1) from staff_competency_inspect_item_config
        where parent_id = #{configId} limit 1
    </select>
    <select id="selectNormalChildrenConfigById" resultType="java.lang.Integer">
        select count(*) from staff_competency_inspect_item_config where is_enable = 1  and find_in_set(#{configId}, ancestors)
    </select>
    <select id="selectConfigHeader" resultType="com.ruoyi.inspect.vo.StaffConfigHeaderVO">
        select
            c2.item_name AS item_name,
            c1.item_name AS children_item_name,
            c1.id AS children_id
        from staff_competency_inspect_item_config c1 left join staff_competency_inspect_item_config c2 on c1.parent_id=c2.id
        where c1.is_enable=1
          and c2.id is not null
        order by c1.parent_id,c1.sort
    </select>
</mapper>