UserMapper.xml
8.93 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
<?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.pc.system.user.mapper.UserMapper">
<resultMap type="com.huaheng.pc.system.user.domain.User" id="UserResult">
<id property="id" column="id" />
<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="enable" column="enable" />
<result property="deleted" column="deleted" />
<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" resultMap="deptResult" javaType="com.huaheng.pc.system.dept.domain.Dept"/>
</resultMap>
<resultMap id="deptResult" type="com.huaheng.pc.system.dept.domain.Dept">
<id property="id" column="deptId" />
<result property="parentId" column="parentId" />
<result property="deptName" column="deptName" />
<result property="orderNum" column="orderNum" />
<result property="enable" column="dept_enable" />
</resultMap>
<sql id="selectUserVo">
select u.id, u.deptId, u.loginName, u.userName, u.email, u.phoneNumber, u.sex, u.avatar, u.password, u.salt, u.enable, u.deleted, u.loginIp, u.loginDate, u.createTime, u.remark,
d.id AS deptId, d.parentId, d.deptName, d.orderNum, d.enable as dept_enable
from sys_user u
left join sys_dept d on u.deptId = d.id
left join sys_user_role ur on u.id = ur.userId
</sql>
<select id="selectUserList" resultMap="UserResult">
select u.id, u.deptId, u.loginName, u.userName, u.email, u.phoneNumber, u.password, u.sex, u.avatar, u.salt, u.enable, u.deleted, 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.id
WHERE u.deleted = false
<if test="loginName != null and loginName != ''">
AND u.loginName like concat('%', #{loginName}, '%')
</if>
<if test="enable != null">
AND u.enable = #{enable}
</if>
<if test="phoneNumber != null and phoneNumber != ''">
AND u.phoneNumber like concat('%', #{phoneNumber}, '%')
</if>
<if test="params != null and params.beginTime != 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 != 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.id FROM sys_dept t WHERE FIND_IN_SET (#{deptId},ancestors) ))
</if>
</select>
<select id="selectUserByLoginName" resultMap="UserResult">
<include refid="selectUserVo"/>
where u.loginName = #{userName}
</select>
<select id="selectUserByPhoneNumber" resultMap="UserResult">
<include refid="selectUserVo"/>
where u.phoneNumber = #{phoneNumber}
</select>
<select id="selectUserByEmail" resultMap="UserResult">
<include refid="selectUserVo"/>
where u.email = #{email}
</select>
<select id="checkLoginNameUnique" resultType="java.lang.Integer">
select count(1) from sys_user where loginName=#{loginName}
</select>
<select id="checkPhoneUnique" resultMap="UserResult">
select id, phoneNumber from sys_user where phoneNumber=#{phoneNumber}
</select>
<select id="checkEmailUnique" resultMap="UserResult">
select id, email from sys_user where email=#{email}
</select>
<select id="selectUserById" resultMap="UserResult">
<include refid="selectUserVo"/>
where u.id = #{id}
</select>
<select id="selectmen" resultType="com.huaheng.pc.system.user.domain.User">
select * from sys_user where loginName = #{loginName}
</select>
<delete id="deleteUserById">
delete from sys_user where id = #{id}
</delete>
<delete id="deleteUserByIds">
update sys_user set deleted = true where id in
<foreach collection="array" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<update id="updateUser">
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="enable != null ">enable = #{enable},</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>
<if test="id != null">
AND id = #{id}
</if>
<if test="loginName != null">
AND loginName = #{loginName}
</if>
</where>
</update>
<!--where id = #{id}-->
<insert id="insertUser" useGeneratedKeys="true" keyProperty="id">
insert into sys_user(
<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="enable != null ">enable,</if>
<if test="createBy != null and createBy != ''">createBy,</if>
<if test="remark != null and remark != ''">remark,</if>
createTime
)values(
<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="enable != null ">#{enable},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if>
sysdate()
)
</insert>
<select id="getWarehouseByUserId" resultType="java.util.HashMap">
SELECT DISTINCT warehouse.id, warehouse.code, warehouse.name
FROM sys_user_role
INNER JOIN sys_role ON sys_user_role.roleId = sys_role.id AND sys_user_role.userId = #{userId, jdbcType=INTEGER} AND sys_role.enable = TRUE AND sys_role.deleted = FALSE
INNER JOIN warehouse ON sys_role.warehouseId = warehouse.id AND warehouse.enable = TRUE AND warehouse.deleted = FALSE
</select>
<select id="getWarehouseByUserCode" resultType="java.util.HashMap">
SELECT DISTINCT warehouse.id, warehouse.code, warehouse.name
FROM sys_user_role
INNER JOIN sys_user ON sys_user_role.userId = sys_user.id AND sys_user.loginName= #{loginName,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.warehouseId = warehouse.id AND warehouse.enable = TRUE AND warehouse.deleted = FALSE ;
</select>
<update id="insertupdateTime" >
update sys_user set updateTime = #{date} where loginName = #{cPersonCode}
</update>
</mapper>