SysUserMapper.xml 9.51 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
		<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
58
		<result column="nickname" property="nickname"/>
59 60 61
		<result column="user_group" property="userGroup"/>
		<result column="post" property="post"/>
		<result column="email" property="email"/>
62
		<result column="system_flag" property="systemFlag"/>
fangxinjiang's avatar
fangxinjiang committed
63 64 65 66 67 68 69 70 71 72 73 74 75
		<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
76
		sys_user.nickname,
fangxinjiang's avatar
fangxinjiang committed
77 78 79 80 81 82 83 84 85 86
		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,
87
		sys_user.user_group,
88 89
		sys_user.post,
		sys_user.email,
90
		sys_user.system_flag,
fangxinjiang's avatar
fangxinjiang committed
91 92 93 94 95 96 97 98 99 100 101
		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
102
		sys_user.nickname,
fangxinjiang's avatar
fangxinjiang committed
103 104 105 106 107 108 109 110
		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,
111
		sys_user.user_group,
112 113
		sys_user.post,
		sys_user.email,
114
		sys_user.system_flag,
fangxinjiang's avatar
fangxinjiang committed
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
		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
147
		       sys_user.nickname,
fangxinjiang's avatar
fangxinjiang committed
148 149 150 151 152 153 154 155 156
			   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,
157
			   sys_user.user_group,
158 159
			   sys_user.post,
			   sys_user.email,
160
			   sys_user.system_flag,
fangxinjiang's avatar
fangxinjiang committed
161 162 163 164 165 166 167 168 169
			   sys_dept.name        AS deptName
		FROM sys_user
					 LEFT JOIN sys_dept ON sys_dept.dept_id = sys_user.dept_id
		<where>
			sys_user.del_flag = '0'
			<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
170 171 172 173
			<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
174 175 176 177 178 179 180
		</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
181
		       u.nickname,
fangxinjiang's avatar
fangxinjiang committed
182 183 184 185 186 187 188 189 190
			   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,
191
			   u.group,
192
			   u.user_group,
193
			   u.email,
194
			   u.system_flag,
fangxinjiang's avatar
fangxinjiang committed
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
			   d.name AS     deptName
		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
210 211 212

	<insert id="batchInsertUser" parameterType="java.util.List">
	insert into sys_user
213
	(user_id,username,phone,email,password,nickname,create_time)
huyuchen's avatar
huyuchen committed
214 215 216 217 218 219 220 221
	VALUES
	<foreach collection="list" item="item" index="index" separator=",">
	(
		REPLACE(UUID(),"-",""),
		#{item.uid,jdbcType=VARCHAR},
		#{item.telephoneNumber,jdbcType=VARCHAR},
		#{item.email,jdbcType=VARCHAR},
		#{item.password,jdbcType=VARCHAR},
222 223
		#{item.personName,jdbcType=VARCHAR},
		now()
huyuchen's avatar
huyuchen committed
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
	)
	</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>
259
			<trim prefix="update_time =case" suffix="end,">
260 261 262 263
				<foreach collection="list" item="i" index="index">
					when username=#{i.uid} then now()
				</foreach>
			</trim>
huyuchen's avatar
huyuchen committed
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
		</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>
281
			<trim prefix="update_time =case" suffix="end,">
282 283 284 285
				<foreach collection="list" item="i" index="index">
					when username=#{i.userId} then now()
				</foreach>
			</trim>
huyuchen's avatar
huyuchen committed
286 287 288 289 290 291
		</trim>
		where
		<foreach collection="list" separator="or" item="i" index="index" >
			username=#{i.userId}
		</foreach>
	</update>
fangxinjiang's avatar
fangxinjiang committed
292
</mapper>