UsPermissionMapper.xml
6.32 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?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="cn.runsa.portal.base.dao.UsPermissionMapper" >
<resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.UsPermission" >
<id column="uspId" property="id" jdbcType="INTEGER" />
<result column="usId" property="usid" jdbcType="INTEGER" />
<result column="uspLimit" property="limit" jdbcType="BIT" />
<result column="moId" property="moId" jdbcType="INTEGER" />
<result column="moName" property="moName" jdbcType="VARCHAR" />
<association property="channel" javaType="cn.runsa.portal.base.entity.Channel">
<id column="chId" property="id" />
<result column="chName" property="name"/>
</association>
<association property="organization" javaType="cn.runsa.portal.base.entity.Organization">
<id column="orId" property="id" />
<result column="orName" property="name"/>
</association>
<collection property="brandList" ofType="cn.runsa.portal.base.entity.Brand">
<id column="brId" property="id" />
<result column="brName" property="name"/>
</collection>
<collection property="roleList" ofType="cn.runsa.portal.base.entity.Role">
<id column="roId" property="id" />
<result column="roName" property="name"/>
</collection>
</resultMap>
<sql id="Base_Column_List" >
uspId, usId, chId, uspLimit, moId
</sql>
<select id="findById" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
SELECT
p.usId,
p.uspId,
p.uspLimit
p.chId,
ch.chName,
p.moId,
r.roName,
b.brName
FROM
`smUsPermission` p
LEFT JOIN mtChannel ch ON p.chId = ch.chId
LEFT JOIN smUsPermRole pr ON p.uspId = pr.uspId
LEFT JOIN smRole r ON pr.roId = r.roId
LEFT JOIN smUsPermBrand pb ON p.uspId = pb.uspId
LEFT JOIN mtBrand b ON pb.brId = b.brId
WHERE
p.uspId = #{id,jdbcType=INTEGER}
</select>
<select id="findList" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
SELECT
p.usId,
p.uspId,
ch.chId,
ch.chName,
oz.orId,
oz.orName,
r.roId,
r.roName,
b.brId,
b.brName
FROM
`smUsPermission` p
INNER JOIN mtChannel ch ON p.chId = ch.chId
INNER JOIN smUsPermRole pr ON p.uspId = pr.uspId
INNER JOIN smRole r ON pr.roId = r.roId
INNER JOIN smUsPermBrand pb ON p.uspId = pb.uspId
INNER JOIN mtBrand b ON pb.brId = b.brId
LEFT JOIN mtOrganization oz ON p.moId = oz.orId
WHERE
p.usId = #{id,jdbcType=INTEGER}
</select>
<delete id="delete" parameterType="java.lang.Integer" >
delete from smUsPermission
where uspId = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="cn.runsa.portal.base.entity.UsPermission" >
<selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into smUsPermission (usId, chId, uspLimit,
moId)
values (#{usid,jdbcType=INTEGER}, #{chid,jdbcType=INTEGER}, #{limit,jdbcType=BIT},
#{moid,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="cn.runsa.portal.base.entity.UsPermission" >
<selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into smUsPermission
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="usid != null" >
usId,
</if>
<if test="channel.id != null" >
chId,
</if>
<if test="limit != null" >
uspLimit,
</if>
<if test="moId != null" >
moId,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="usid != null" >
#{usid,jdbcType=INTEGER},
</if>
<if test="channel.id != null" >
#{channel.id,jdbcType=INTEGER},
</if>
<if test="limit != null" >
#{limit,jdbcType=BIT},
</if>
<if test="moId != null" >
#{moId,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateSelective" parameterType="cn.runsa.portal.base.entity.UsPermission" >
update smUsPermission
<set >
<if test="usid != null" >
usId = #{usid,jdbcType=INTEGER},
</if>
<if test="chid != null" >
chId = #{chid,jdbcType=INTEGER},
</if>
<if test="limit != null" >
uspLimit = #{limit,jdbcType=BIT},
</if>
<if test="moid != null" >
moId = #{moid,jdbcType=INTEGER},
</if>
</set>
where uspId = #{id,jdbcType=INTEGER}
</update>
<update id="update" parameterType="cn.runsa.portal.base.entity.UsPermission" >
update smUsPermission
set usId = #{usid,jdbcType=INTEGER},
chId = #{chid,jdbcType=INTEGER},
uspLimit = #{limit,jdbcType=BIT},
moId = #{moid,jdbcType=INTEGER}
where uspId = #{id,jdbcType=INTEGER}
</update>
<insert id="insertPermBrand" parameterType="cn.runsa.portal.base.entity.UsPermission" >
insert into smUsPermBrand (uspId,brId) values
<foreach collection="brandList" item="item" index="index" separator="," >
(
#{id,jdbcType=INTEGER},
#{item.id,jdbcType=INTEGER}
)
</foreach>
</insert>
<insert id="insertUsPermRole" parameterType="cn.runsa.portal.base.entity.UsPermission" >
insert into smUsPermRole (uspId,roId) values
<foreach collection="roleList" item="item" index="index" separator="," >
(
#{id,jdbcType=INTEGER},
#{item.id,jdbcType=INTEGER}
)
</foreach>
</insert>
<delete id="deletePermBrand" parameterType="java.lang.Integer" >
delete from smUsPermBrand
where uspId = #{id,jdbcType=INTEGER}
</delete>
<delete id="deleteUsPermRole" parameterType="java.lang.Integer" >
delete from smUsPermRole
where uspId = #{id,jdbcType=INTEGER}
</delete>
<delete id="deleteByUsid" parameterType="java.lang.Integer" >
delete from smUsPermission
where usId = #{id,jdbcType=INTEGER}
</delete>
<delete id="deletePermRoleByUsid" parameterType="java.lang.Integer" >
DELETE
FROM
smUsPermRole
WHERE
uspId IN (
SELECT
uspid
FROM
smUsPermission
where
usId = #{id,jdbcType=INTEGER}
)
</delete>
<delete id="deletePermBrandByUsid" parameterType="java.lang.Integer" >
DELETE
FROM
smUsPermBrand
WHERE
uspId IN (
SELECT
uspid
FROM
smUsPermission
where
usId = #{id,jdbcType=INTEGER}
)
</delete>
</mapper>