SysUserMapper.xml 11.3 KB
Newer Older
fangxinjiang's avatar
fangxinjiang committed
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
<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 2020 yifu4cloud Authors. All Rights Reserved.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yifu.cloud.plus.v1.yifu.admin.mapper.SysUserMapper">
	<!-- 通用查询映射结果 -->
	<resultMap id="baseResultMap" type="com.yifu.cloud.plus.v1.yifu.admin.api.vo.UserVO">
		<id column="user_id" property="userId"/>
		<result column="username" property="username"/>
		<result column="password" property="password"/>
		<result column="salt" property="salt"/>
		<result column="phone" property="phone"/>
		<result column="avatar" property="avatar"/>
		<result column="ucreate_time" property="createTime"/>
		<result column="uupdate_time" property="updateTime"/>
		<result column="lock_flag" property="lockFlag"/>
		<result column="udel_flag" property="delFlag"/>
		<result column="deptId" property="deptId"/>
		<result column="deptName" property="deptName"/>
fangxinjiang's avatar
fangxinjiang committed
34
		<result column="nickname" property="nickname"/>
35 36 37
		<result column="user_group" property="userGroup"/>
		<result column="post" property="post"/>
		<result column="email" property="email"/>
38
		<result column="system_flag" property="systemFlag"/>
fangxinjiang's avatar
fangxinjiang committed
39
		<result column="type" property="type"/>
fangxinjiang's avatar
fangxinjiang committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
		<collection property="roleList" ofType="com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysRole"
					select="com.yifu.cloud.plus.v1.yifu.admin.mapper.SysRoleMapper.listRolesByUserId" column="user_id">
		</collection>
	</resultMap>

	<!-- userVo结果集 -->
	<resultMap id="userVoResultMap" type="com.yifu.cloud.plus.v1.yifu.admin.api.vo.UserVO">
		<id column="user_id" property="userId"/>
		<result column="username" property="username"/>
		<result column="password" property="password"/>
		<result column="salt" property="salt"/>
		<result column="phone" property="phone"/>
		<result column="avatar" property="avatar"/>
		<result column="ucreate_time" property="createTime"/>
		<result column="uupdate_time" property="updateTime"/>
		<result column="lock_flag" property="lockFlag"/>
		<result column="udel_flag" property="delFlag"/>
		<result column="deptId" property="deptId"/>
		<result column="deptName" property="deptName"/>
fangxinjiang's avatar
fangxinjiang committed
59
		<result column="nickname" property="nickname"/>
60 61 62
		<result column="user_group" property="userGroup"/>
		<result column="post" property="post"/>
		<result column="email" property="email"/>
63
		<result column="system_flag" property="systemFlag"/>
fangxinjiang's avatar
fangxinjiang committed
64
		<result column="type" property="type"/>
fangxinjiang's avatar
fangxinjiang committed
65 66 67 68 69 70 71 72 73 74 75 76 77
		<collection property="roleList" ofType="com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysRole">
			<id column="role_id" property="roleId"/>
			<result column="role_name" property="roleName"/>
			<result column="role_code" property="roleCode"/>
			<result column="role_desc" property="roleDesc"/>
			<result column="rcreate_time" property="createTime"/>
			<result column="rupdate_time" property="updateTime"/>
		</collection>
	</resultMap>

	<sql id="userRoleSql">
		sys_user.user_id,
		sys_user.username,
fangxinjiang's avatar
fangxinjiang committed
78
		sys_user.nickname,
fangxinjiang's avatar
fangxinjiang committed
79 80 81 82 83 84 85 86 87 88
		sys_user.`password`,
		sys_user.salt,
		sys_user.phone,
		sys_user.avatar,
		sys_user.dept_id,
		sys_user.create_time AS ucreate_time,
		sys_user.update_time AS uupdate_time,
		sys_user.del_flag    AS udel_flag,
		sys_user.lock_flag   AS lock_flag,
		sys_user.dept_id     AS deptId,
89
		sys_user.user_group,
90 91
		sys_user.post,
		sys_user.email,
92
		sys_user.system_flag,
fangxinjiang's avatar
fangxinjiang committed
93 94 95 96 97 98 99 100 101 102 103
		r.role_id,
		r.role_name,
		r.role_code,
		r.role_desc,
		r.create_time        AS rcreate_time,
		r.update_time        AS rupdate_time
	</sql>

	<sql id="userRoleDeptSql">
		sys_user.user_id,
		sys_user.username,
fangxinjiang's avatar
fangxinjiang committed
104
		sys_user.nickname,
fangxinjiang's avatar
fangxinjiang committed
105 106 107 108 109 110 111 112
		sys_user.`password`,
		sys_user.salt,
		sys_user.phone,
		sys_user.avatar,
		sys_user.create_time AS ucreate_time,
		sys_user.update_time AS uupdate_time,
		sys_user.del_flag    AS udel_flag,
		sys_user.lock_flag   AS lock_flag,
113
		sys_user.user_group,
114 115
		sys_user.post,
		sys_user.email,
116
		sys_user.system_flag,
fangxinjiang's avatar
fangxinjiang committed
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
		r.role_id,
		r.role_name,
		r.role_code,
		r.role_desc,
		r.create_time        AS rcreate_time,
		r.update_time        AS rupdate_time,
		d.name               AS deptName,
		d.dept_id            AS deptId
	</sql>

	<select id="getUserVoByUsername" resultMap="userVoResultMap">
		SELECT
		<include refid="userRoleSql"/>
		FROM sys_user AS sys_user
					 LEFT JOIN sys_user_role AS ur ON ur.user_id = sys_user.user_id
					 LEFT JOIN sys_role AS r ON r.role_id = ur.role_id
		WHERE sys_user.username = #{username}
	</select>

	<select id="getUserVoById" resultMap="userVoResultMap">
		SELECT
		<include refid="userRoleDeptSql"/>
		FROM sys_user AS sys_user
					 LEFT JOIN sys_user_role AS ur ON ur.user_id = sys_user.user_id
					 LEFT JOIN sys_role AS r ON r.role_id = ur.role_id
					 LEFT JOIN sys_dept AS d ON d.dept_id = sys_user.dept_id
		WHERE sys_user.user_id = #{id}
	</select>

	<select id="getUserVosPage" resultMap="baseResultMap">
		SELECT sys_user.user_id,
			   sys_user.username,
fangxinjiang's avatar
fangxinjiang committed
149
		       sys_user.nickname,
fangxinjiang's avatar
fangxinjiang committed
150 151 152 153 154 155 156 157 158
			   sys_user.salt,
			   sys_user.phone,
			   sys_user.avatar,
			   sys_user.dept_id,
			   sys_user.create_time AS ucreate_time,
			   sys_user.update_time AS uupdate_time,
			   sys_user.del_flag    AS udel_flag,
			   sys_user.lock_flag   AS lock_flag,
			   sys_user.dept_id     AS deptId,
159
			   sys_user.user_group,
160 161
			   sys_user.post,
			   sys_user.email,
162
			   sys_user.system_flag,
fangxinjiang's avatar
fangxinjiang committed
163
			   sys_user.type,
fangxinjiang's avatar
fangxinjiang committed
164 165 166 167
			   sys_dept.name        AS deptName
		FROM sys_user
					 LEFT JOIN sys_dept ON sys_dept.dept_id = sys_user.dept_id
		<where>
168
			sys_user.del_flag = '0' and (sys_user.type = '0' or sys_user.type = '1')
fangxinjiang's avatar
fangxinjiang committed
169 170 171 172
			<if test="query.username != null and query.username != ''">
				<bind name="usernameLike" value="'%' + query.username + '%'" />
				and sys_user.username LIKE  #{usernameLike}
			</if>
fangxinjiang's avatar
fangxinjiang committed
173 174 175 176
			<if test="query.nickname != null and query.nickname != ''">
				<bind name="nicknameLike" value="'%' + query.nickname + '%'" />
				and sys_user.nickname LIKE  #{nicknameLike}
			</if>
fangxinjiang's avatar
fangxinjiang committed
177 178 179 180 181 182 183
		</where>
		ORDER BY sys_user.create_time DESC
	</select>

	<select id="selectVoList" resultMap="baseResultMap">
		SELECT u.user_id,
			   u.username,
fangxinjiang's avatar
fangxinjiang committed
184
		       u.nickname,
fangxinjiang's avatar
fangxinjiang committed
185 186 187 188 189 190 191 192 193
			   u.password,
			   u.salt,
			   u.phone,
			   u.avatar,
			   u.dept_id,
			   u.create_time ucreate_time,
			   u.update_time uupdate_time,
			   u.del_flag,
			   u.lock_flag,
194
			   u.group,
195
			   u.user_group,
196
			   u.email,
197
			   u.system_flag,
fangxinjiang's avatar
fangxinjiang committed
198
		       u.type
199
			   d.name AS     deptName
fangxinjiang's avatar
fangxinjiang committed
200 201 202 203 204 205 206 207 208 209 210 211 212 213
		FROM sys_user u
					 LEFT JOIN sys_dept d ON d.dept_id = u.dept_id
		<where>
			u.del_flag = '0'
			<if test="query.username != null and query.username != ''">
				<bind name="usernameLike" value="'%' + query.username + '%'" />
				AND u.username LIKE #{usernameLike}
			</if>
			<if test="query.deptId != null and query.deptId != ''">
				AND u.dept_id = #{query.deptId}
			</if>
		</where>
		ORDER BY u.create_time DESC
	</select>
huyuchen's avatar
huyuchen committed
214 215 216

	<insert id="batchInsertUser" parameterType="java.util.List">
	insert into sys_user
huyuchen's avatar
huyuchen committed
217
	(user_id,username,password,phone,email,nickname,create_time,dept_id,dept_name)
huyuchen's avatar
huyuchen committed
218 219 220 221
	VALUES
	<foreach collection="list" item="item" index="index" separator=",">
	(
		REPLACE(UUID(),"-",""),
huyuchen's avatar
huyuchen committed
222
		#{item.uid},
huyuchen's avatar
huyuchen committed
223
		#{item.password},
huyuchen's avatar
huyuchen committed
224 225 226
		#{item.telephoneNumber},
		#{item.email},
		#{item.personName},
huyuchen's avatar
huyuchen committed
227 228 229
		now(),
		#{item.deptId},
		#{item.deptName}
huyuchen's avatar
huyuchen committed
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
	)
	</foreach>
	</insert>

	<update id="batchUpdateUser" parameterType="java.util.List">
		update sys_user
		<trim prefix="set" suffixOverrides=",">
			<trim prefix="phone =case" suffix="end,">
				<foreach collection="list" item="i" index="index">
					<if test="i.telephoneNumber!=null">
						when username=#{i.uid} then #{i.telephoneNumber}
					</if>
				</foreach>
			</trim>
			<trim prefix="email =case" suffix="end,">
				<foreach collection="list" item="i" index="index">
					<if test="i.email!=null">
						when username=#{i.uid} then #{i.email}
					</if>
				</foreach>
			</trim>
			<trim prefix="nickname =case" suffix="end," >
				<foreach collection="list" item="i" index="index">
					<if test="i.personName!=null">
						when username=#{i.uid} then #{i.personName}
					</if>
				</foreach>
			</trim>
			<trim prefix="password =case" suffix="end," >
				<foreach collection="list" item="i" index="index">
					<if test="i.password!=null">
						when username=#{i.uid} then #{i.password}
					</if>
				</foreach>
			</trim>
265
			<trim prefix="update_time =case" suffix="end,">
266 267 268 269
				<foreach collection="list" item="i" index="index">
					when username=#{i.uid} then now()
				</foreach>
			</trim>
huyuchen's avatar
huyuchen committed
270 271 272
			<trim prefix="dept_id =case" suffix="end,">
				<foreach collection="list" item="i" index="index">
					<if test="i.deptId!=null">
huyuchen's avatar
huyuchen committed
273
						when username=#{i.uid} then #{i.deptId}
huyuchen's avatar
huyuchen committed
274 275 276 277 278 279
					</if>
				</foreach>
			</trim>
			<trim prefix="dept_name =case" suffix="end,">
				<foreach collection="list" item="i" index="index">
					<if test="i.deptName!=null">
huyuchen's avatar
huyuchen committed
280
						when username=#{i.uid} then #{i.deptName}
huyuchen's avatar
huyuchen committed
281 282 283
					</if>
				</foreach>
			</trim>
huyuchen's avatar
huyuchen committed
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
		</trim>
		where
		<foreach collection="list" separator="or" item="i" index="index" >
			username=#{i.uid}
		</foreach>
	</update>

	<update id="updateUser" parameterType="java.util.List">
		update sys_user
		<trim prefix="set" suffixOverrides=",">
			<trim prefix="dept_id =case" suffix="end,">
				<foreach collection="list" item="i" index="index">
					<if test="i.deptId!=null">
						when username=#{i.userId} then #{i.deptId}
					</if>
				</foreach>
			</trim>
301
			<trim prefix="update_time =case" suffix="end,">
302 303 304 305
				<foreach collection="list" item="i" index="index">
					when username=#{i.userId} then now()
				</foreach>
			</trim>
306 307 308 309 310 311 312
			<trim prefix="dept_name =case" suffix="end,">
				<foreach collection="list" item="i" index="index">
					<if test="i.deptName!=null">
						when username=#{i.userId} then #{i.deptName}
					</if>
				</foreach>
			</trim>
huyuchen's avatar
huyuchen committed
313 314 315 316 317 318
		</trim>
		where
		<foreach collection="list" separator="or" item="i" index="index" >
			username=#{i.userId}
		</foreach>
	</update>
fangxinjiang's avatar
fangxinjiang committed
319 320 321 322 323
	<!-- 获取b端用户分页 fxj 2022-12-27 -->
	<select id="getBusinessUserVoPage" resultType="com.yifu.cloud.plus.v1.yifu.admin.api.vo.BusinessUserVo">
		select *
		from sys_user AS `user`
		<where> `user`.del_flag = '0'
fangxinjiang's avatar
fangxinjiang committed
324 325
			<if test="query.deptId != null and query.deptId != ''">
				and `user`.dept_id = #{query.deptId}
fangxinjiang's avatar
fangxinjiang committed
326
			</if>
fangxinjiang's avatar
fangxinjiang committed
327 328 329
			<if test="query.type != null and query.type != ''">
				and `user`.type = #{query.type}
			</if>
fangxinjiang's avatar
fangxinjiang committed
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
			<if test="query.nickname != null and query.nickname != ''">
				and `user`.nickname LIKE CONCAT('%',#{query.nickname},'%')
			</if>
			<if test="query.username != null and query.username != ''">
				and `user`.username LIKE CONCAT('%',#{query.username},'%')
			</if>
			<if test="null != query.userIdsB and query.userIdsB.size > 0">
				where  b.user_id in
				<foreach collection="query.userIdsB" item="item" index="index" open="(" close=")" separator=",">
					#{item}
				</foreach>
			</if>
		</where>
		ORDER BY `user`.create_time DESC
	</select>
fangxinjiang's avatar
fangxinjiang committed
345
</mapper>