SysUserMapper.xml
11.1 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?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.huaheng.system.mapper.SysUserMapper">
<resultMap type="com.huaheng.system.api.domain.SysUser" id="SysUserResult">
<id property="userId" column="user_id"/>
<result property="deptId" column="dept_id"/>
<result property="userName" column="user_name"/>
<result property="nickName" column="nick_name"/>
<result property="email" column="email"/>
<result property="phonenumber" column="phonenumber"/>
<result property="sex" column="sex"/>
<result property="avatar" column="avatar"/>
<result property="password" column="password"/>
<result property="status" column="status"/>
<result property="delFlag" column="del_flag"/>
<result property="loginIp" column="login_ip"/>
<result property="loginDate" column="login_date"/>
<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="remark" column="remark"/>
<association property="dept" column="dept_id" javaType="com.huaheng.system.api.domain.SysDept"
resultMap="deptResult"/>
<collection property="roles" javaType="java.util.List" resultMap="RoleResult"/>
</resultMap>
<resultMap id="deptResult" type="com.huaheng.system.api.domain.SysDept">
<id property="deptId" column="dept_id"/>
<result property="parentId" column="parent_id"/>
<result property="deptName" column="dept_name"/>
<result property="orderNum" column="order_num"/>
<result property="leader" column="leader"/>
<result property="status" column="dept_status"/>
</resultMap>
<resultMap id="RoleResult" type="com.huaheng.system.api.domain.SysRole">
<id property="roleId" column="role_id"/>
<result property="roleName" column="role_name"/>
<result property="roleKey" column="role_key"/>
<result property="roleSort" column="role_sort"/>
<result property="dataScope" column="data_scope"/>
<result property="status" column="role_status"/>
</resultMap>
<sql id="selectUserVo">
select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex,
u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
d.dept_id, d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status,
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
from sys_user u
left join sys_dept d on u.dept_id = d.dept_id
left join sys_user_role ur on u.user_id = ur.user_id
left join sys_role r on r.role_id = ur.role_id
</sql>
<select id="selectUserList" parameterType="com.huaheng.system.api.domain.SysUser" resultMap="SysUserResult">
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex,
u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from
sys_user u
left join sys_dept d on u.dept_id = d.dept_id
where u.del_flag = '0'
<if test="userName != null and userName != ''">
AND u.user_name like concat('%', #{userName}, '%')
</if>
<if test="status != null and status != ''">
AND u.status = #{status}
</if>
<if test="phonenumber != null and phonenumber != ''">
AND u.phonenumber like concat('%', #{phonenumber}, '%')
</if>
<if test="beginTime != null and beginTime != ''">
<!-- 开始时间检索 -->
AND date_format(u.create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''">
<!-- 结束时间检索 -->
AND date_format(u.create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d')
</if>
<if test="deptId != null and deptId != 0">
AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE FIND_IN_SET
(#{deptId},ancestors) ))
</if>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
<include refid="selectUserVo"/>
where u.user_name = #{userName}
</select>
<select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
<include refid="selectUserVo"/>
where u.user_id = #{userId}
</select>
<select id="checkUserNameUnique" parameterType="String" resultType="int">
select count(1) from sys_user where user_name = #{userName} limit 1
</select>
<select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult">
select user_id, phonenumber from sys_user where phonenumber = #{phonenumber} limit 1
</select>
<select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
select user_id, email from sys_user where email = #{email} limit 1
</select>
<insert id="insertUser" parameterType="com.huaheng.system.api.domain.SysUser" useGeneratedKeys="true"
keyProperty="userId">
insert into sys_user(
<if test="userId != null and userId != 0">
user_id,
</if>
<if test="deptId != null and deptId != 0">
dept_id,
</if>
<if test="userName != null and userName != ''">
user_name,
</if>
<if test="nickName != null and nickName != ''">
nick_name,
</if>
<if test="email != null and email != ''">
email,
</if>
<if test="avatar != null and avatar != ''">
avatar,
</if>
<if test="phonenumber != null and phonenumber != ''">
phonenumber,
</if>
<if test="sex != null and sex != ''">
sex,
</if>
<if test="password != null and password != ''">
password,
</if>
<if test="status != null and status != ''">
status,
</if>
<if test="createBy != null and createBy != ''">
create_by,
</if>
<if test="remark != null and remark != ''">
remark,
</if>
create_time
)values(
<if test="userId != null and userId != ''">
#{userId},
</if>
<if test="deptId != null and deptId != ''">
#{deptId},
</if>
<if test="userName != null and userName != ''">
#{userName},
</if>
<if test="nickName != null and nickName != ''">
#{nickName},
</if>
<if test="email != null and email != ''">
#{email},
</if>
<if test="avatar != null and avatar != ''">
#{avatar},
</if>
<if test="phonenumber != null and phonenumber != ''">
#{phonenumber},
</if>
<if test="sex != null and sex != ''">
#{sex},
</if>
<if test="password != null and password != ''">
#{password},
</if>
<if test="status != null and status != ''">
#{status},
</if>
<if test="createBy != null and createBy != ''">
#{createBy},
</if>
<if test="remark != null and remark != ''">
#{remark},
</if>
sysdate()
)
</insert>
<update id="updateUser" parameterType="com.huaheng.system.api.domain.SysUser">
update sys_user
<set>
<if test="deptId != null and deptId != 0">
dept_id = #{deptId},
</if>
<if test="userName != null and userName != ''">
user_name = #{userName},
</if>
<if test="nickName != null and nickName != ''">
nick_name = #{nickName},
</if>
<if test="email != null and email != ''">
email = #{email},
</if>
<if test="phonenumber != null and phonenumber != ''">
phonenumber = #{phonenumber},
</if>
<if test="sex != null and sex != ''">
sex = #{sex},
</if>
<if test="avatar != null and avatar != ''">
avatar = #{avatar},
</if>
<if test="password != null and password != ''">
password = #{password},
</if>
<if test="status != null and status != ''">
status = #{status},
</if>
<if test="loginIp != null and loginIp != ''">
login_ip = #{loginIp},
</if>
<if test="loginDate != null">
login_date = #{loginDate},
</if>
<if test="updateBy != null and updateBy != ''">
update_by = #{updateBy},
</if>
<if test="remark != null">
remark = #{remark},
</if>
update_time = sysdate()
</set>
where user_id = #{userId}
</update>
<update id="updateUserStatus" parameterType="com.huaheng.system.api.domain.SysUser">
update sys_user set status = #{status} where user_id = #{userId}
</update>
<update id="updateUserAvatar" parameterType="com.huaheng.system.api.domain.SysUser">
update sys_user set avatar = #{avatar} where user_name = #{userName}
</update>
<update id="resetUserPwd" parameterType="com.huaheng.system.api.domain.SysUser">
update sys_user set password = #{password} where user_name = #{userName}
</update>
<delete id="deleteUserById" parameterType="Long">
delete from sys_user where user_id = #{userId}
</delete>
<delete id="deleteUserByIds" parameterType="Long">
update sys_user set del_flag = '2' where user_id in
<foreach collection="array" item="userId" open="(" separator="," close=")">
#{userId}
</foreach>
</delete>
<select id="getWarehouseByUserName" resultType="java.util.HashMap">
SELECT r.`name`, r.code
FROM sys_user u
LEFT JOIN sys_user_warehouse ur ON u.user_id = ur.userId
LEFT JOIN warehouse r ON ur.warehouseCode = r.code
WHERE u.user_name=#{userName,jdbcType=VARCHAR}
</select>
<select id="getWarehouseByUserCode" resultType="java.util.HashMap">
SELECT DISTINCT warehouse.code, warehouse.name
FROM sys_user_role
INNER JOIN sys_user ON sys_user_role.userId = sys_user.user_id AND sys_user.user_name=
#{userName,jdbcType=VARCHAR} AND sys_user.enable=TRUE AND sys_user.DELETED=FALSE
INNER JOIN sys_role ON sys_user_role.roleId = sys_role.id AND sys_user_role.userId = sys_user.Id AND
sys_role.enable = TRUE
INNER JOIN warehouse ON sys_role.warehouseCode = warehouse.code AND warehouse.enable = TRUE
</select>
</mapper>