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