RoleMapper.xml
7.27 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
<?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.com.glsx.dj.system.mapper.RoleMapper" >
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.system.model.Role" >
<!--
WARNING - @mbg.generated
-->
<id column="id" property="id" jdbcType="INTEGER" />
<result column="created_user_id" property="createdUserId"/>
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="description" property="description" jdbcType="VARCHAR" />
<result column="status" property="status" jdbcType="TINYINT" />
<result column="is_super" property="isSuper" jdbcType="BIT"/>
<result column="created_by" property="createdBy" jdbcType="VARCHAR" />
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP" />
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
<result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP" />
<result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" />
</resultMap>
<resultMap id="DTOResultMap" type="cn.com.glsx.dj.system.dto.RoleDTO" extends="BaseResultMap">
<result column="merchant_id" property="merchantId"/>
<result column="merchant_name" property="merchantName"/>
</resultMap>
<sql id="Base_Column_List" >
<!--
WARNING - @mbg.generated
-->
id, created_user_id,name, description, status,is_super, created_by, created_date, updated_by, updated_date,
deleted_flag
</sql>
<select id="listBase" parameterType="cn.com.glsx.dj.system.model.Role" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/> from dj_system_role
<where>
deleted_flag = 'N'
<if test="createdUserId != null">
and created_user_id = #{createdUserId}
</if>
<if test="id != null">
and id = #{id}
</if>
</where>
order by updated_date desc,id desc
</select>
<select id="list" parameterType="cn.com.glsx.dj.system.dto.RoleDTO" resultMap="DTOResultMap">
select
a.id, a.created_user_id,a.name, a.description, a.status,a.is_super, a.created_date, a.updated_date,
c.merchant_id,c.merchant_name
from dj_system_role a
left join dj_system_user b on b.id=a.created_user_id and b.deleted_flag='N'
left join dj_system_merchant c on c.merchant_id=b.merchant_id and c.deleted_flag='N'
<where>
a.deleted_flag = 'N'
<if test="id != null">
and a.id = #{id}
</if>
<if test="createdUserId != null">
and a.created_user_id = #{createdUserId}
</if>
<if test="status != null">
and a.status = #{status}
</if>
<if test="name != null and name !=''">
and a.name like CONCAT('%',#{name},'%')
</if>
<if test="merchantName != null and merchantName !=''">
and c.merchant_name like CONCAT('%',#{merchantName},'%')
</if>
<if test="merchantId != null">
and c.merchant_id = #{merchantId}
</if>
<if test="startTime != null">
<![CDATA[
and a.created_date >= #{startTime}
]]>
</if>
<if test="endTime != null">
<![CDATA[
and a.created_date <= #{endTime}
]]>
</if>
<if test="isSuper != null">
and a.is_super = #{isSuper}
</if>
<if test="ids != null">
and a.id in
<foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="userId != null">
and a.id in (
select ur.role_id from dj_system_user_role ur where ur.deleted_flag='N' and ur.user_id=#{userId}
)
</if>
</where>
order by a.updated_date desc,a.id desc
</select>
<update id="updateAllChildRoleMenu" parameterType="cn.com.glsx.dj.system.dto.RoleDTO">
update dj_system_role_menu a set a.deleted_flag='D',updated_by=#{updatedBy},updated_date=#{updatedDate}
<where>
and a.deleted_flag ='N'
and menu_code in
<foreach collection="deleteMenuCodes" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
and role_id in (
select b.id
from dj_system_role b
join dj_system_user c on c.id=b.created_user_id and c.deleted_flag='N'
where b.deleted_flag='N'
and ( 1=2
<!-- 商户及商户员工 -->
<if test="merchantIds != null and merchantIds.size() > 0">
or c.merchant_id in
<foreach collection="merchantIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<!-- 用户 -->
<if test="userIds != null and userIds.size() > 0 ">
or b.created_user_id in
<foreach collection="userIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
)
)
</where>
</update>
<!-- 删除角色下功能点 -->
<update id="updateAllChildRoleFunction" parameterType="cn.com.glsx.dj.system.dto.RoleDTO">
update dj_system_role_function a set a.deleted_flag='D',updated_by=#{updatedBy},updated_date=#{updatedDate}
<where>
and a.deleted_flag ='N'
and function_id in
<foreach collection="deleteFunctionIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
and role_id in (
select b.id
from dj_system_role b
join dj_system_user c on c.id=b.created_user_id and c.deleted_flag='N'
where b.deleted_flag='N'
and ( 1=2
<!-- 商户及商户员工 -->
<if test="merchantIds != null and merchantIds.size() > 0">
or c.merchant_id in
<foreach collection="merchantIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<!-- 用户 -->
<if test="userIds != null and userIds.size() > 0 ">
or b.created_user_id in
<foreach collection="userIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
)
)
</where>
</update>
<!-- 删除角色下功能值 -->
<update id="updateAllChildRoleFunctionValue" parameterType="cn.com.glsx.dj.system.dto.RoleDTO">
update dj_system_role_function_value a set a.deleted_flag='D',updated_by=#{updatedBy},updated_date=#{updatedDate}
<where>
and a.deleted_flag ='N'
and function_value_id in
<foreach collection="deleteFunctionValueIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
and role_id in (
select b.id
from dj_system_role b
join dj_system_user c on c.id=b.created_user_id and c.deleted_flag='N'
where b.deleted_flag='N'
and ( 1=2
<!-- 商户及商户员工 -->
<if test="merchantIds != null and merchantIds.size() > 0">
or c.merchant_id in
<foreach collection="merchantIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<!-- 用户 -->
<if test="userIds != null and userIds.size() > 0 ">
or b.created_user_id in
<foreach collection="userIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
)
)
</where>
</update>
</mapper>