liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
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
134
<?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">
<!-- 
    namespace:必须与对应的接口全类名一致
    id:必须与对应接口的某个对应的方法名一致
    
 -->
<mapper namespace="com.basic.x01.securityCheck.mapper.SecurityCheckMapper">
    <resultMap id="TbSecurityType" type="TbSecurityType">
        <id property="typeId" column="type_id" />
        <result property="orgId" column="org_id" />
        <result property="typeName" column="type_name" />
        <result property="createTime" column="create_time" />
        <result property="itemCount" column="item_count" />
    </resultMap>
    
    <resultMap id="TbSecurityCheckItem" type="TbSecurityCheckItem">
        <id property="itemId" column="item_id" />
        <result property="typeId" column="type_id" />
        <result property="orgId" column="org_id" />
        <result property="typeName" column="type_name" />
        <result property="itemName" column="item_name" />
        <result property="itemContent" column="item_content" />
        <result property="createTime" column="create_time" />
        <result property="checkWay" column="check_way" />
    </resultMap>
    
    <delete id="deleteUnusedTbSecurityCheckItem">
        delete from tb_security_check_item
        where org_id=#{orgId} and item_id=#{itemId}
    </delete>
    <update id="updateTbSecurityCheckItem" parameterType="TbSecurityCheckItem">
        update tb_security_check_item
        set type_id=#{typeId}, item_name=#{itemName},
            item_content=#{itemContent}, check_way=#{checkWay}
        where item_id=#{itemId} and org_id=#{orgId}
    </update>
    <select id="getTbSecurityCheckItem" resultMap="TbSecurityCheckItem">
        select i.*, (select type_name from tb_security_type where type_id=i.type_id limit 1)
            as type_name
        from tb_security_check_item i
        where i.item_id=#{0}
    </select>
    <select id="checkSameTbSecurityCheckItem" parameterType="TbSecurityCheckItem" resultType="int">
        select count(0) from tb_security_check_item
        where org_id=#{orgId} and type_id=#{typeId} and item_name=#{itemName}
            <if test="itemId !=null and itemId !=''">
            and item_id !=#{itemId}
            </if>
    </select>
 
    <insert id="insertTbSecurityCheckItem" parameterType="TbSecurityCheckItem">
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="itemId">
            select replace(uuid(), '-', '') as itemId
        </selectKey>
        insert into tb_security_check_item(item_id, type_id, org_id,
            item_name, item_content, create_time, check_way,
            create_user_id)
        values (#{itemId}, #{typeId}, #{orgId}, #{itemName}, #{itemContent},
            date_format(now(),'%Y-%m-%d %H:%i:%S'), #{checkWay},
            #{createUserId}
            )
    </insert>
 
    <select id="checkSameTbSeucrityType" parameterType="TbSecurityType" resultType="int">
        select count(0)    from tb_security_type
        where org_id=#{orgId} and type_name=#{typeName}
            <if test="typeId !=null and typeId !='' ">
            and type_id != #{typeId}
            </if>
    </select>
    
    <insert id="insertTbSecurityType" parameterType="TbSecurityType">
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="typeId">  
            select replace(uuid(), '-', '') as typeId
        </selectKey>  
    
        insert into tb_security_type(type_id, org_id, type_name, create_time,
            create_user_id
            )
        values(#{typeId}, #{orgId}, #{typeName}, date_format(now(),'%Y-%m-%d %H:%i:%S'),
            #{createUserId}
            )
    </insert>
    
    <update id="updateTbSecurityType" parameterType="TbSecurityType">
        update tb_security_type
        set type_name=#{typeName}
        where type_id=#{typeId} and org_id=#{orgId}
    </update>
    
    <delete id="deleteUnusedTbSecurityType">
        delete from tb_security_type
        where org_id=#{orgId} and type_id not in 
            <foreach item="item" index="index" collection="typeList"
                open="(" separator="," close=")">
                #{item.typeId}    
            </foreach>
            and not exists (select 1 from tb_security_check_item i 
                where i.type_id=tb_security_type.type_id
                )
    </delete>
    
    <select id="getSecurityType" resultMap="TbSecurityType">
        select * from tb_security_type
        where org_id=#{0}
        order by create_time
    </select>
    
    <select id="getSecurityType4Edit" resultMap="TbSecurityType">
        select t.*, (select count(0) from tb_security_check_item i 
            where i.org_id=t.org_id and i.type_id=t.type_id
            ) as item_count
        from tb_security_type t
        where org_id=#{0}
        order by create_time
    </select>
    
    <select id="getSecurityCheckItemList" resultMap="TbSecurityCheckItem">
        select i.*, (select type_name from tb_security_type where type_id=i.type_id limit 1)
            as type_name
        from tb_security_check_item i
        where org_id=#{orgId}
            <if test="typeId != null and typeId !=''">
                and type_id=#{typeId}
            </if>
            <if test="itemContent !=null and itemContent !=''">
                and (instr(item_name, #{itemContent})>0 or
                instr(item_content, #{itemContent})>0)
            </if>
        order by create_time
    </select>
</mapper>