This commit is contained in:
ls
2024-10-16 15:30:27 +08:00
parent 35e48104b9
commit 7bb433234f
5 changed files with 827 additions and 786 deletions

View File

@@ -76,7 +76,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
* @param username 用户登录账户 * @param username 用户登录账户
* @return * @return
*/ */
IPage<SysUser> getUserByRoleId(Page page, @Param("roleId") String roleId, @Param("username") String username); IPage<SysUser> getUserByRoleId(Page page, @Param("roleId") String roleId, @Param("username") String username, @Param("roleCode") String roleCode);
/** /**
* 根据用户名设置部门ID * 根据用户名设置部门ID

View File

@@ -2,300 +2,311 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.system.mapper.SysUserMapper"> <mapper namespace="org.jeecg.modules.system.mapper.SysUserMapper">
<!-- 根据用户名查询 --> <!-- 根据用户名查询 -->
<select id="getUserByName" resultType="org.jeecg.modules.system.entity.SysUser"> <select id="getUserByName" resultType="org.jeecg.modules.system.entity.SysUser">
select * from sys_user where username = #{username} and del_flag = 0 select * from sys_user where username = #{username} and del_flag = 0
</select> </select>
<!-- 根据用户名查询用户ID -->
<select id="getUserIdByName" resultType="String">
select id from sys_user where username = #{username} and del_flag = 0
</select>
<!-- 根据部门Id查询 --> <!-- 根据用户名查询用户ID -->
<select id="getUserByDepId" resultType="org.jeecg.modules.system.entity.SysUser"> <select id="getUserIdByName" resultType="String">
select * from sys_user where del_flag = 0 and id in (select user_id from sys_user_depart where dep_id=#{departId}) select id from sys_user where username = #{username} and del_flag = 0
<if test="username!=null and username!=''"> </select>
and username = #{username}
</if>
</select>
<!-- 查询部门和子部门下的所有用户账号 --> <!-- 根据部门Id查询 -->
<select id="getUserAccountsByDepCode" resultType="String"> <select id="getUserByDepId" resultType="org.jeecg.modules.system.entity.SysUser">
<if test="orgCode != null"> select * from sys_user where del_flag = 0 and id in (select user_id from sys_user_depart where
<bind name="bindOrgCode" value="orgCode+'%'"/> dep_id=#{departId})
</if> <if test="username!=null and username!=''">
select username from sys_user where del_flag = 0 and id in (select user_id from sys_user_depart where dep_id in (select id from sys_depart where org_code LIKE #{bindOrgCode})) and username = #{username}
</select> </if>
</select>
<!-- 查询用户的所属部门名称信息 --> <!-- 查询部门和子部门下的所有用户账号 -->
<select id="getDepNamesByUserIds" resultType="org.jeecg.modules.system.vo.SysUserDepVo"> <select id="getUserAccountsByDepCode" resultType="String">
select d.depart_name,ud.user_id from sys_user_depart ud,sys_depart d where d.id = ud.dep_id and ud.user_id in <if test="orgCode != null">
<foreach collection="userIds" index="index" item="id" open="(" separator="," close=")"> <bind name="bindOrgCode" value="orgCode+'%'"/>
#{id} </if>
</foreach> select username from sys_user where del_flag = 0 and id in (select user_id from sys_user_depart where dep_id in
</select> (select id from sys_depart where org_code LIKE #{bindOrgCode}))
</select>
<!-- 通过多个部门IDS查询部门下的用户信息 --> <!-- 查询用户的所属部门名称信息 -->
<select id="getUserByDepIds" resultType="org.jeecg.modules.system.entity.SysUser"> <select id="getDepNamesByUserIds" resultType="org.jeecg.modules.system.vo.SysUserDepVo">
select * from sys_user where del_flag = 0 select d.depart_name,ud.user_id from sys_user_depart ud,sys_depart d where d.id = ud.dep_id and ud.user_id in
<if test="departIds!=null and departIds.size()>0"> <foreach collection="userIds" index="index" item="id" open="(" separator="," close=")">
and id in (select user_id from sys_user_depart where dep_id in #{id}
<foreach collection="departIds" index="index" item="id" open="(" separator="," close=")"> </foreach>
#{id} </select>
</foreach>
)
</if>
<if test="username!=null and username!=''">
and username = #{username}
</if>
</select>
<!-- 根据角色Id查询 --> <!-- 通过多个部门IDS查询部门下的用户信息 -->
<select id="getUserByRoleId" resultType="org.jeecg.modules.system.entity.SysUser"> <select id="getUserByDepIds" resultType="org.jeecg.modules.system.entity.SysUser">
select * from sys_user where del_flag = 0 and id in (select user_id from sys_user_role where role_id=#{roleId}) select * from sys_user where del_flag = 0
<if test="username!=null and username!=''"> <if test="departIds!=null and departIds.size()>0">
and username = #{username} and id in (select user_id from sys_user_depart where dep_id in
</if> <foreach collection="departIds" index="index" item="id" open="(" separator="," close=")">
</select> #{id}
</foreach>
<!-- 修改用户部门code --> )
<update id="updateUserDepart"> </if>
UPDATE sys_user SET <if test="username!=null and username!=''">
<if test="orgCode!=null and loginTenantId!=null"> and username = #{username}
org_code = #{orgCode} </if>
,login_tenant_id = #{loginTenantId} </select>
</if>
<if test="orgCode==null and loginTenantId!=null">
login_tenant_id = #{loginTenantId}
</if>
<if test="orgCode!=null and loginTenantId==null">
org_code = #{orgCode}
</if>
where username = #{username}
</update>
<!-- 根据手机号查询 --> <!-- 根据角色Id查询 -->
<select id="getUserByPhone" resultType="org.jeecg.modules.system.entity.SysUser"> <select id="getUserByRoleId" resultType="org.jeecg.modules.system.entity.SysUser">
select * from sys_user where phone = #{phone} and del_flag = 0 select * from sys_user where del_flag = 0 and id in (select user_id from sys_user_role where 1=1
</select> <if test="roleId!=null and roleId!=''">
and role_id = #{roleId}
<!-- 根据邮箱查询用户信息 --> </if>
<select id="getUserByEmail" resultType="org.jeecg.modules.system.entity.SysUser"> <if test="roleCode!=null and roleCode!=''">
select * from sys_user where email = #{email} and del_flag = 0 and role_code = #{roleCode}
</select> </if>
)
<if test="username!=null and username!=''">
and username = #{roleCode}
</if>
<!-- SQL片段getUserByOrgCode 的 FROM 和 WHERE 部分 --> </select>
<sql id="getUserByOrgCodeFromSql">
FROM
sys_depart
INNER JOIN sys_user_depart ON sys_user_depart.dep_id = sys_depart.id
INNER JOIN sys_user ON sys_user.id = sys_user_depart.user_id
WHERE
<if test="orgCode == null">
<bind name="bindOrgCode" value="'%'"/>
</if>
<if test="orgCode != null">
<bind name="bindOrgCode" value="orgCode+'%'"/>
</if>
sys_user.del_flag = 0 AND sys_depart.org_code LIKE #{bindOrgCode}
<if test="userParams != null"> <!-- 修改用户部门code -->
<if test="userParams.realname != null and userParams.realname != ''"> <update id="updateUserDepart">
AND sys_user.realname LIKE concat(concat('%',#{userParams.realname}),'%') UPDATE sys_user SET
</if> <if test="orgCode!=null and loginTenantId!=null">
<if test="userParams.workNo != null and userParams.workNo != ''"> org_code = #{orgCode}
AND sys_user.work_no LIKE concat(concat('%',#{userParams.workNo}),'%') ,login_tenant_id = #{loginTenantId}
</if> </if>
</if> <if test="orgCode==null and loginTenantId!=null">
</sql> login_tenant_id = #{loginTenantId}
</if>
<if test="orgCode!=null and loginTenantId==null">
org_code = #{orgCode}
</if>
where username = #{username}
</update>
<!-- 根据 orgCode 查询用户,包括子部门下的用户 --> <!-- 根据手机号查询 -->
<select id="getUserByOrgCode" resultType="org.jeecg.modules.system.model.SysUserSysDepartModel"> <select id="getUserByPhone" resultType="org.jeecg.modules.system.entity.SysUser">
SELECT select * from sys_user where phone = #{phone} and del_flag = 0
sys_user.id AS id, </select>
sys_user.realname AS realname,
sys_user.avatar AS avatar,
sys_user.sex AS sex,
sys_user.birthday AS birthday,
sys_user.work_no AS workNo,
sys_user.telephone AS telephone,
sys_user.email AS email,
sys_user.phone AS phone,
sys_depart.id AS departId,
sys_depart.depart_name AS departName
<include refid="getUserByOrgCodeFromSql"/>
ORDER BY
sys_depart.org_code ASC
</select>
<!-- 查询 getUserByOrgCode 的总数--> <!-- 根据邮箱查询用户信息 -->
<select id="getUserByOrgCodeTotal" resultType="java.lang.Integer"> <select id="getUserByEmail" resultType="org.jeecg.modules.system.entity.SysUser">
SELECT COUNT(1) <include refid="getUserByOrgCodeFromSql"/> select * from sys_user where email = #{email} and del_flag = 0
</select> </select>
<!-- 批量删除角色的与用户关系--> <!-- SQL片段getUserByOrgCode 的 FROM 和 WHERE 部分 -->
<update id="deleteBathRoleUserRelation"> <sql id="getUserByOrgCodeFromSql">
delete from sys_user_role FROM
where role_id in sys_depart
<foreach item="id" collection="roleIdArray" open="(" separator="," close=")"> INNER JOIN sys_user_depart ON sys_user_depart.dep_id = sys_depart.id
#{id} INNER JOIN sys_user ON sys_user.id = sys_user_depart.user_id
</foreach> WHERE
</update> <if test="orgCode == null">
<!-- 批量删除角色的与权限关系--> <bind name="bindOrgCode" value="'%'"/>
<update id="deleteBathRolePermissionRelation"> </if>
delete from sys_role_permission <if test="orgCode != null">
where role_id in <bind name="bindOrgCode" value="orgCode+'%'"/>
<foreach item="id" collection="roleIdArray" open="(" separator="," close=")"> </if>
#{id} sys_user.del_flag = 0 AND sys_depart.org_code LIKE #{bindOrgCode}
</foreach>
</update>
<!-- 查询被逻辑删除的用户 --> <if test="userParams != null">
<select id="selectLogicDeleted" resultType="org.jeecg.modules.system.entity.SysUser"> <if test="userParams.realname != null and userParams.realname != ''">
SELECT * FROM sys_user ${ew.customSqlSegment} AND sys_user.realname LIKE concat(concat('%',#{userParams.realname}),'%')
</select> </if>
<if test="userParams.workNo != null and userParams.workNo != ''">
AND sys_user.work_no LIKE concat(concat('%',#{userParams.workNo}),'%')
</if>
</if>
</sql>
<!-- 更新被逻辑删除的用户 --> <!-- 根据 orgCode 查询用户,包括子部门下的用户 -->
<update id="revertLogicDeleted"> <select id="getUserByOrgCode" resultType="org.jeecg.modules.system.model.SysUserSysDepartModel">
UPDATE SELECT
sys_user sys_user.id AS id,
SET sys_user.realname AS realname,
del_flag = 0, sys_user.avatar AS avatar,
update_by = #{entity.updateBy}, sys_user.sex AS sex,
update_time = #{entity.updateTime} sys_user.birthday AS birthday,
WHERE sys_user.work_no AS workNo,
del_flag = 1 sys_user.telephone AS telephone,
AND id IN sys_user.email AS email,
<foreach collection="userIds" item="userId" open="(" close=")" separator="," > sys_user.phone AS phone,
#{userId} sys_depart.id AS departId,
</foreach> sys_depart.depart_name AS departName
</update> <include refid="getUserByOrgCodeFromSql"/>
ORDER BY
sys_depart.org_code ASC
</select>
<!-- 彻底删除被逻辑删除的用户 --> <!-- 查询 getUserByOrgCode 的总数-->
<delete id="deleteLogicDeleted"> <select id="getUserByOrgCodeTotal" resultType="java.lang.Integer">
DELETE FROM sys_user WHERE del_flag = 1 AND id IN SELECT COUNT(1)
<foreach collection="userIds" item="userId" open="(" close=")" separator="," > <include refid="getUserByOrgCodeFromSql"/>
#{userId} </select>
</foreach>
</delete>
<!-- 更新空字符串为null --> <!-- 批量删除角色的与用户关系-->
<update id="updateNullByEmptyString"> <update id="deleteBathRoleUserRelation">
UPDATE sys_user delete from sys_user_role
<if test="fieldName == 'email'"> where role_id in
SET email = NULL WHERE email = '' <foreach item="id" collection="roleIdArray" open="(" separator="," close=")">
</if> #{id}
<if test="fieldName == 'phone'"> </foreach>
SET phone = NULL WHERE phone = '' </update>
</if> <!-- 批量删除角色的与权限关系-->
</update> <update id="deleteBathRolePermissionRelation">
delete from sys_role_permission
where role_id in
<foreach item="id" collection="roleIdArray" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<!-- 通过多个部门IDS查询部门下的用户信息 --> <!-- 查询被逻辑删除的用户 -->
<select id="queryByDepIds" resultType="org.jeecg.modules.system.entity.SysUser"> <select id="selectLogicDeleted" resultType="org.jeecg.modules.system.entity.SysUser">
select * from sys_user where del_flag = 0 SELECT * FROM sys_user ${ew.customSqlSegment}
<if test="departIds!=null and departIds.size()>0"> </select>
and id in (select user_id from sys_user_depart where dep_id in
<foreach collection="departIds" index="index" item="id" open="(" separator="," close=")">
#{id}
</foreach>
)
</if>
<if test="username!=null and username!=''">
and username != #{username}
</if>
</select>
<!--根据角色查询用户--> <!-- 更新被逻辑删除的用户 -->
<select id="selectUserListByRoleId" resultType="org.jeecg.modules.system.entity.SysUser"> <update id="revertLogicDeleted">
select DISTINCT a.* from sys_user a UPDATE
left join sys_user_role sur on sur.user_id = a.id sys_user
where SET
a.del_flag = 0 and a.status = 1 del_flag = 0,
and a.username!='_reserve_user_external' update_by = #{entity.updateBy},
and sur.role_id=#{roleId} update_time = #{entity.updateTime}
<if test="keyword!=null and keyword!=''"> WHERE
<bind name="bindKeyword" value="'%'+keyword+'%'"/> del_flag = 1
and (a.username like #{bindKeyword} or a.realname like #{bindKeyword}) AND id IN
</if> <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
</update>
<if test="tenantId!=null"> <!-- 彻底删除被逻辑删除的用户 -->
and a.id in ( <delete id="deleteLogicDeleted">
select user_id from sys_user_tenant where tenant_id = #{tenantId} and status = '1' DELETE FROM sys_user WHERE del_flag = 1 AND id IN
) <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
</if> #{userId}
</foreach>
<!--【QQYUN-8239】用户角色添加用户 返回2页数据实际只显示一页 需要将不符合的用户id排除--> </delete>
<if test="excludeUserIdList!=null and excludeUserIdList.size()>0">
and a.id not in
<foreach collection="excludeUserIdList" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
</if>
</select>
<!--获取租户下的用户离职列表信息--> <!-- 更新空字符串为null -->
<select id="getTenantQuitList" resultType="org.jeecg.modules.system.entity.SysUser"> <update id="updateNullByEmptyString">
select su.id,su.username,su.realname,su.sex,su.avatar,su.create_time,sut.create_by from sys_user su UPDATE sys_user
join sys_user_tenant sut on sut.user_id = su.id and sut.status = '2' <if test="fieldName == 'email'">
where SET email = NULL WHERE email = ''
su.status = 1 </if>
and su.del_flag = 0 <if test="fieldName == 'phone'">
<if test="tenantId != 0"> SET phone = NULL WHERE phone = ''
and sut.tenant_id = #{tenantId} </if>
</if> </update>
</select>
<!--获取租户下的有效用户ids信息--> <!-- 通过多个部门IDS查询部门下的用户信息 -->
<select id="getTenantUserIdList" resultType="java.lang.String" parameterType="java.lang.Integer"> <select id="queryByDepIds" resultType="org.jeecg.modules.system.entity.SysUser">
SELECT DISTINCT( su.id ) id select * from sys_user where del_flag = 0
FROM sys_user su <if test="departIds!=null and departIds.size()>0">
<choose> and id in (select user_id from sys_user_depart where dep_id in
<when test="tenantId!=null and tenantId != 0"> <foreach collection="departIds" index="index" item="id" open="(" separator="," close=")">
JOIN sys_user_tenant sut ON sut.user_id = su.id #{id}
AND sut.STATUS = '1' </foreach>
AND sut.tenant_id = #{tenantId} )
AND su.STATUS = 1 </if>
AND su.del_flag = 0 <if test="username!=null and username!=''">
</when> and username != #{username}
<otherwise> </if>
WHERE su.STATUS = 1 </select>
AND su.del_flag = 0
</otherwise>
</choose>
</select>
<!--更新刪除状态和离职状态-->
<update id="updateStatusAndFlag">
UPDATE
sys_user
SET
del_flag = 0,
update_by = #{sysUser.updateBy},
update_time = #{sysUser.updateTime},
status = 1
WHERE
del_flag = 1
AND id IN
<foreach collection="userIds" item="userId" open="(" close=")" separator="," >
#{userId}
</foreach>
</update>
<!--根据部门id获取用户数据--> <!--根据角色查询用户-->
<select id="getUserByDepartsTenantId" resultType="org.jeecg.modules.system.entity.SysUser"> <select id="selectUserListByRoleId" resultType="org.jeecg.modules.system.entity.SysUser">
select su.* from sys_user su select DISTINCT a.* from sys_user a
join sys_user_tenant sut on su.id = sut.user_id left join sys_user_role sur on sur.user_id = a.id
where su.del_flag = 0 where
<if test="departIds!=null and departIds.size()>0"> a.del_flag = 0 and a.status = 1
and su.id in (select user_id from sys_user_depart and a.username!='_reserve_user_external'
where dep_id in and sur.role_id=#{roleId}
<foreach collection="departIds" index="index" item="id" open="(" separator="," close=")"> <if test="keyword!=null and keyword!=''">
#{id} <bind name="bindKeyword" value="'%'+keyword+'%'"/>
</foreach> and (a.username like #{bindKeyword} or a.realname like #{bindKeyword})
) </if>
</if>
and sut.tenant_id=#{tenantId} <if test="tenantId!=null">
and a.id in (
select user_id from sys_user_tenant where tenant_id = #{tenantId} and status = '1'
)
</if>
<!--【QQYUN-8239】用户角色添加用户 返回2页数据实际只显示一页 需要将不符合的用户id排除-->
<if test="excludeUserIdList!=null and excludeUserIdList.size()>0">
and a.id not in
<foreach collection="excludeUserIdList" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
</if>
</select>
<!--获取租户下的用户离职列表信息-->
<select id="getTenantQuitList" resultType="org.jeecg.modules.system.entity.SysUser">
select su.id,su.username,su.realname,su.sex,su.avatar,su.create_time,sut.create_by from sys_user su
join sys_user_tenant sut on sut.user_id = su.id and sut.status = '2'
where
su.status = 1
and su.del_flag = 0
<if test="tenantId != 0">
and sut.tenant_id = #{tenantId}
</if>
</select>
<!--获取租户下的有效用户ids信息-->
<select id="getTenantUserIdList" resultType="java.lang.String" parameterType="java.lang.Integer">
SELECT DISTINCT( su.id ) id
FROM sys_user su
<choose>
<when test="tenantId!=null and tenantId != 0">
JOIN sys_user_tenant sut ON sut.user_id = su.id
AND sut.STATUS = '1'
AND sut.tenant_id = #{tenantId}
AND su.STATUS = 1
AND su.del_flag = 0
</when>
<otherwise>
WHERE su.STATUS = 1
AND su.del_flag = 0
</otherwise>
</choose>
</select>
<!--更新刪除状态和离职状态-->
<update id="updateStatusAndFlag">
UPDATE
sys_user
SET
del_flag = 0,
update_by = #{sysUser.updateBy},
update_time = #{sysUser.updateTime},
status = 1
WHERE
del_flag = 1
AND id IN
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
</update>
<!--根据部门id获取用户数据-->
<select id="getUserByDepartsTenantId" resultType="org.jeecg.modules.system.entity.SysUser">
select su.* from sys_user su
join sys_user_tenant sut on su.id = sut.user_id
where su.del_flag = 0
<if test="departIds!=null and departIds.size()>0">
and su.id in (select user_id from sys_user_depart
where dep_id in
<foreach collection="departIds" index="index" item="id" open="(" separator="," close=")">
#{id}
</foreach>
)
</if>
and sut.tenant_id=#{tenantId}
and sut.status = '1' and sut.status = '1'
</select> </select>
</mapper> </mapper>

View File

@@ -177,7 +177,7 @@ public interface ISysUserService extends IService<SysUser> {
* @param username 用户账户名称 * @param username 用户账户名称
* @return * @return
*/ */
public IPage<SysUser> getUserByRoleId(Page<SysUser> page, String roleId, String username); public IPage<SysUser> getUserByRoleId(Page<SysUser> page, String roleId, String username,String roleCode);
/** /**
* 通过用户名获取用户角色集合 * 通过用户名获取用户角色集合

View File

@@ -551,9 +551,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
* @return * @return
*/ */
@Override @Override
public IPage<SysUser> getUserByRoleId(Page<SysUser> page, String roleId, String username) { public IPage<SysUser> getUserByRoleId(Page<SysUser> page, String roleId, String username,String roleCode) {
//update-begin---author:wangshuai ---date:20230220 for[QQYUN-3980]组织管理中 职位功能 职位表加租户id 加职位-用户关联表------------ //update-begin---author:wangshuai ---date:20230220 for[QQYUN-3980]组织管理中 职位功能 职位表加租户id 加职位-用户关联表------------
IPage<SysUser> userRoleList = userMapper.getUserByRoleId(page, roleId, username); IPage<SysUser> userRoleList = userMapper.getUserByRoleId(page, roleId, username,roleCode);
List<SysUser> records = userRoleList.getRecords(); List<SysUser> records = userRoleList.getRecords();
if (null != records && records.size() > 0) { if (null != records && records.size() > 0) {
List<String> userIds = records.stream().map(SysUser::getId).collect(Collectors.toList()); List<String> userIds = records.stream().map(SysUser::getId).collect(Collectors.toList());