Files
pj_service_cloud/pjcloud-upms/pjcloud-upms-biz/src/main/resources/mapper/SysUserMapper.xml
T
2025-06-24 15:17:38 +08:00

315 lines
11 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ Copyright (c) 2018-2025, pjcloud All rights reserved.
~
~ Redistribution and use in source and binary forms, with or without
~ modification, are permitted provided that the following conditions are met:
~
~ Redistributions of source code must retain the above copyright notice,
~ this list of conditions and the following disclaimer.
~ Redistributions in binary form must reproduce the above copyright
~ notice, this list of conditions and the following disclaimer in the
~ documentation and/or other materials provided with the distribution.
~ Neither the name of the pig4cloud.com developer nor the names of its
~ contributors may be used to endorse or promote products derived from
~ this software without specific prior written permission.
~ Author: pjcloud
~
-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bsd.pjcloud.admin.mapper.SysUserMapper">
<!-- 通用查询映射结果 -->
<resultMap id="baseResultMap" type="com.bsd.pjcloud.admin.api.vo.UserVO">
<id column="user_id" property="userId"/>
<result column="process_id" property="processId"/>
<result column="process_status" property="processStatus"/>
<result column="process_time" property="processTime"/>
<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="wx_openid" property="wxOpenid"/>
<result column="qq_openid" property="qqOpenid"/>
<result column="gitee_login" property="giteeOpenId"/>
<result column="osc_id" property="oscOpenId"/>
<result column="wx_cp_userid" property="wxCpUserid"/>
<result column="wx_ding_userid" property="wxDingUserid"/>
<result column="ucreate_time" property="createTime"/>
<result column="uupdate_time" property="updateTime"/>
<result column="lock_flag" property="lockFlag"/>
<result column="password_expire_flag" property="passwordExpireFlag"/>
<result column="password_modify_time" property="passwordModifyTime"/>
<result column="del_flag" property="delFlag"/>
<result column="dept_id" property="deptId"/>
<result column="tenant_id" property="tenantId"/>
<result column="dept_name" property="deptName"/>
<result column="nickname" property="nickname"/>
<result column="name" property="name"/>
<result column="email" property="email"/>
<result column="is_global_face" property="isGlobalFace"/>
<result column="dingtalk_employee_code" property="dingtalkEmployeeCode"/>
<collection property="roleList" ofType="com.bsd.pjcloud.admin.api.entity.SysRole"
select="com.bsd.pjcloud.admin.mapper.SysRoleMapper.listRolesByUserId" column="user_id">
</collection>
<collection property="postList" ofType="com.bsd.pjcloud.admin.api.entity.SysPost"
select="com.bsd.pjcloud.admin.mapper.SysPostMapper.listPostsByUserId" column="user_id">
</collection>
</resultMap>
<sql id="userRoleSql">
u.user_id,
u.process_id,
u.process_status,
u.process_time,
u.username,
u.password,
u.salt,
u.phone,
u.avatar,
u.wx_openid,
u.qq_openid,
u.gitee_login,
u.osc_id,
u.wx_cp_userid,
u.wx_ding_userid,
u.dept_id,
u.del_flag,
u.lock_flag,
u.password_expire_flag,
u.password_modify_time,
u.tenant_id,
u.create_by,
u.create_time ucreate_time,
u.update_time uupdate_time,
r.role_id,
r.role_name,
r.role_code,
r.role_desc,
r.create_time rcreate_time,
r.update_time rupdate_time
</sql>
<sql id="userRoleDeptSql">
u.user_id,
u.username,
u.password,
u.salt,
u.phone,
u.avatar,
u.wx_openid,
u.qq_openid,
u.gitee_login,
u.osc_id,
u.wx_cp_userid,
u.wx_ding_userid,
u.del_flag,
u.lock_flag,
u.password_expire_flag,
u.password_modify_time,
u.tenant_id,
u.nickname,
u.name,
u.email,
u.create_by,
u.create_time ucreate_time,
u.update_time uupdate_time,
d.name dept_name,
d.dept_id
</sql>
<select id="getUserVoByUsername" resultMap="baseResultMap">
SELECT
<include refid="userRoleSql"/>
FROM
sys_user u
LEFT JOIN sys_user_role urole ON urole.user_id = u.user_id
LEFT JOIN sys_role r ON r.role_id = urole.role_id and r.del_flag = '0'
WHERE u.username = #{username} and u.del_flag = '0'
</select>
<select id="getUserVoById" resultMap="baseResultMap">
SELECT
<include refid="userRoleDeptSql"/>
FROM
sys_user u
LEFT JOIN sys_dept d ON d.dept_id = u.dept_id and d.del_flag = '0'
WHERE
u.user_id = #{id} and u.del_flag = '0'
</select>
<select id="getUserVosPage" resultMap="baseResultMap">
SELECT
u.user_id,
u.process_id,
u.process_status,
u.process_time,
u.username,
u.password,
u.salt,
u.phone,
u.avatar,
u.wx_openid,
u.qq_openid,
u.gitee_login,
u.osc_id,
u.wx_cp_userid,
u.wx_ding_userid,
u.dept_id,
u.create_by,
u.create_time ucreate_time,
u.update_time uupdate_time,
u.del_flag,
u.lock_flag,
u.password_expire_flag,
u.password_modify_time,
u.tenant_id,
u.nickname,
u.name,
u.email,
u.is_global_face,
d.name dept_name
FROM
sys_user u
LEFT JOIN sys_dept d ON d.dept_id = u.dept_id
LEFT JOIN sys_user_role urole ON urole.user_id = u.user_id
<where>
u.del_flag = '0'
<if test="query.userId != null">
AND u.user_id = #{query.userId}
</if>
<if test="query.processStatus != null and query.processStatus != '' ">
AND u.process_status = #{query.processStatus}
</if>
<if test="query.username != null and query.username != ''">
<bind name="usernameLike" value="'%'+query.username+'%'"/>
AND u.username LIKE #{usernameLike}
</if>
<if test="query.name != null and query.name != ''">
<bind name="nameLike" value="'%'+query.name+'%'"/>
AND u.name LIKE #{nameLike}
</if>
<if test="query.deptId != null">
AND u.dept_id = #{query.deptId}
</if>
<if test="query.role != null and query.role.size() != 0">
and urole.role_id IN
<foreach collection="query.role" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="query.deptIds != null and query.deptIds.size() != 0">
<choose>
<when test="query.isInclude != null and query.isInclude == true">
and u.dept_id IN
</when>
<when test="query.isInclude != null and query.isInclude == false">
and u.dept_id NOT IN
</when>
<otherwise>
and u.dept_id IN
</otherwise>
</choose>
<foreach collection="query.deptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="query.phone != null and query.phone != ''">
<bind name="phoneLike" value="'%'+query.phone+'%'"/>
AND u.phone LIKE #{phoneLike}
</if>
<if test="query.nameOrPhone != null and query.nameOrPhone != ''">
<bind name="nameOrPhone" value="'%'+query.nameOrPhone+'%'"/>
AND (u.phone LIKE #{nameOrPhone} OR u.name LIKE #{nameOrPhone} )
</if>
<if test="query.userIds != null and query.userIds.size() != 0">
and u.user_id IN
<foreach collection="query.userIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
group by u.user_id
<if test="_databaseId != 'mssql'">
ORDER BY u.create_time DESC, u.user_id DESC
</if>
</select>
<select id="selectVoListByScope" resultMap="baseResultMap">
SELECT
u.user_id,
u.username,
u.password,
u.salt,
u.phone,
u.avatar,
u.wx_openid,
u.qq_openid,
u.gitee_login,
u.osc_id,
u.wx_cp_userid,
u.wx_ding_userid,
u.dept_id,
u.create_by,
u.create_time ucreate_time,
u.update_time uupdate_time,
u.del_flag,
u.lock_flag,
u.password_expire_flag,
u.password_modify_time,
u.tenant_id,
u.nickname,
u.name,
u.email,
d.name dept_name
FROM
sys_user u
LEFT JOIN sys_dept d ON d.dept_id = u.dept_id
LEFT JOIN sys_user_role urole ON urole.user_id = u.user_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>
<if test="query.role != null and query.role.size() != 0">
and urole.role_id IN
<foreach collection="query.role" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="query.deptIds != null and query.deptIds.size() != 0">
<choose>
<when test="query.isInclude != null and query.isInclude == true">
and u.dept_id IN
</when>
<when test="query.isInclude != null and query.isInclude == false">
and u.dept_id NOT IN
</when>
<otherwise>
and u.dept_id IN
</otherwise>
</choose>
<foreach collection="query.deptIds" index="index" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
<if test="ids != null">
AND u.user_id in
<foreach collection="ids" index="index" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</where>
group by u.user_id
<if test="_databaseId != 'mssql'">
ORDER BY u.create_time DESC
</if>
</select>
</mapper>