UserMapper.xml
7.64 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
<?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.project.system.user.mapper.UserMapper">
<resultMap type="User" id="UserResult">
<id property="userId" column="userId" />
<result property="deptId" column="deptId" />
<result property="loginName" column="loginName" />
<result property="userName" column="userName" />
<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="salt" column="salt" />
<result property="status" column="status" />
<result property="delFlag" column="delFlag" />
<result property="loginIp" column="loginIp" />
<result property="loginDate" column="loginDate" />
<result property="createBy" column="createBy" />
<result property="createTime" column="createTime" />
<result property="updateBy" column="updateBy" />
<result property="updateTime" column="updateTime" />
<result property="remark" column="remark" />
<association property="dept" column="deptId" javaType="Dept" resultMap="deptResult"/>
</resultMap>
<resultMap id="deptResult" type="Dept">
<id property="deptId" column="deptId" />
<result property="parentId" column="parentId" />
<result property="deptName" column="deptName" />
<result property="orderNum" column="orderNum" />
<result property="status" column="dept_status" />
</resultMap>
<sql id="selectUserVo">
select u.userId, u.deptId, u.loginName, u.userName, u.email, u.phoneNumber, u.sex, u.avatar, u.password, u.salt, u.status, u.delFlag, u.loginIp, u.loginDate, u.createTime, u.remark,
d.deptId, d.parentId, d.deptName, d.orderNum, d.status as dept_status
from sys_user u
left join sys_dept d on u.deptId = d.deptId
left join sys_user_role ur on u.userId = ur.userId
</sql>
<select id="selectUserList" parameterType="User" resultMap="UserResult">
select u.userId, u.deptId, u.loginName, u.userName, u.email, u.phoneNumber, u.password, u.sex, u.avatar, u.salt, u.status, u.delFlag, u.loginIp, u.loginDate, u.createBy, u.createTime, u.remark, d.deptName from sys_user u
left join sys_dept d on u.deptId = d.deptId
where u.delFlag = '0'
<if test="loginName != null and loginName != ''">
AND u.loginName like concat('%', #{loginName}, '%')
</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="params != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND date_format(u.createTime,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(u.createTime,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
</if>
<if test="deptId != null and deptId != 0">
AND (u.deptId = #{deptId} OR u.deptId IN ( SELECT t.deptId FROM sys_dept t WHERE FIND_IN_SET (#{deptId},ancestors) ))
</if>
</select>
<select id="selectUserByLoginName" parameterType="String" resultMap="UserResult">
<include refid="selectUserVo"/>
where u.loginName = #{userName}
</select>
<select id="selectUserByPhoneNumber" parameterType="String" resultMap="UserResult">
<include refid="selectUserVo"/>
where u.phoneNumber = #{phoneNumber}
</select>
<select id="selectUserByEmail" parameterType="String" resultMap="UserResult">
<include refid="selectUserVo"/>
where u.email = #{email}
</select>
<select id="checkLoginNameUnique" parameterType="String" resultType="int">
select count(1) from sys_user where loginName=#{loginName}
</select>
<select id="checkPhoneUnique" parameterType="String" resultMap="UserResult">
select userId, phoneNumber from sys_user where phoneNumber=#{phoneNumber}
</select>
<select id="checkEmailUnique" parameterType="String" resultMap="UserResult">
select userId, email from sys_user where email=#{email}
</select>
<select id="selectUserById" parameterType="Long" resultMap="UserResult">
<include refid="selectUserVo"/>
where u.userId = #{userId}
</select>
<delete id="deleteUserById" parameterType="Long">
delete from sys_user where userId = #{userId}
</delete>
<delete id="deleteUserByIds" parameterType="Long">
update sys_user set delFlag = '2' where userId in
<foreach collection="array" item="userId" open="(" separator="," close=")">
#{userId}
</foreach>
</delete>
<update id="updateUser" parameterType="User">
update sys_user
<set>
<if test="deptId != null and deptId != 0">deptId = #{deptId},</if>
<if test="loginName != null and loginName != ''">loginName = #{loginName},</if>
<if test="userName != null and userName != ''">userName = #{userName},</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="salt != null and salt != ''">salt = #{salt},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="loginIp != null and loginIp != ''">loginIp = #{loginIp},</if>
<if test="loginDate != null">loginDate = #{loginDate},</if>
<if test="updateBy != null and updateBy != ''">updateBy = #{updateBy},</if>
<if test="remark != null and remark != ''">remark = #{remark},</if>
updateTime = sysdate()
</set>
where userId = #{userId}
</update>
<insert id="insertUser" parameterType="User" useGeneratedKeys="true" keyProperty="userId">
insert into sys_user(
<if test="userId != null and userId != 0">userId,</if>
<if test="deptId != null and deptId != 0">deptId,</if>
<if test="loginName != null and loginName != ''">loginName,</if>
<if test="userName != null and userName != ''">userName,</if>
<if test="email != null and email != ''">email,</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="salt != null and salt != ''">salt,</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>
createTime
)values(
<if test="userId != null and userId != ''">#{userId},</if>
<if test="deptId != null and deptId != ''">#{deptId},</if>
<if test="loginName != null and loginName != ''">#{loginName},</if>
<if test="userName != null and userName != ''">#{userName},</if>
<if test="email != null and email != ''">#{email},</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="salt != null and salt != ''">#{salt},</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>
</mapper>