7-29 修改用户查询的Mapper层查询SQL语句,去除岗位和角色的重复显示

This commit is contained in:
郝彬 2025-07-30 11:15:41 +08:00
parent 7dbadc7378
commit 35fdcf14f6
2 changed files with 33 additions and 13 deletions

View File

@ -197,6 +197,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> impleme
if(CollUtil.isNotEmpty(req.getPostIds())){
userPostService.bindUserPost(userId, req.getPostIds());
}
if(CollUtil.isNotEmpty(req.getRoleIds())){
userRoleService.bindUserRole(new UserRoleReq().setUserId(userId).setRoleIds(req.getRoleIds()));
}
this.updateById(entity);
}

View File

@ -8,38 +8,55 @@
</sql>
<select id="queryBySelective" resultType="com.dite.znpt.domain.vo.UserListResp">
SELECT u.user_id, u.account, u.status, u.name, u.user_code, u.user_type, u.user_status, d.dept_name, u.mobile, u.create_time,
GROUP_CONCAT(r.role_name) AS role_name,GROUP_CONCAT(p.post_name) AS post_name
SELECT
u.user_id,
u.account,
u.status,
u.name,
u.user_code,
u.user_type,
u.user_status,
d.dept_name,
u.mobile,
u.create_time,
(
SELECT GROUP_CONCAT(DISTINCT r.role_name)
FROM user_role ur
JOIN role r ON ur.role_id = r.role_id
WHERE ur.user_id = u.user_id
) AS role_name,
(
SELECT GROUP_CONCAT(DISTINCT p.post_name)
FROM user_post up
JOIN post p ON up.post_id = p.post_id
WHERE up.user_id = u.user_id
) AS post_name
FROM user u
LEFT JOIN dept d ON u.dept_id = d.dept_id
LEFT JOIN user_role ur ON u.user_id = ur.user_id
LEFT JOIN role r ON ur.role_id = r.role_id
LEFT JOIN user_post up ON up.user_id = u.user_id
LEFT JOIN post p ON p.post_id = up.post_id
<where>
<if test="userCode != null and userCode != ''">
AND u.user_code LIKE concat ('%', #{userCode}, '%')
AND u.user_code LIKE CONCAT('%', #{userCode}, '%')
</if>
<if test="account != null and account != ''">
AND u.account LIKE concat ('%', #{account}, '%')
AND u.account LIKE CONCAT('%', #{account}, '%')
</if>
<if test="name != null and name != ''">
AND u.name LIKE concat ('%', #{name}, '%')
AND u.name LIKE CONCAT('%', #{name}, '%')
</if>
<if test="mobile != null and mobile != ''">
AND u.mobile LIKE concat ('%', #{mobile}, '%')
AND u.mobile LIKE CONCAT('%', #{mobile}, '%')
</if>
<if test="deptId != null and deptId != ''">
AND d.dept_id = #{deptId}
</if>
<if test="userStatus != null and userStatus!=''">
<if test="userStatus != null and userStatus != ''">
AND u.user_status = #{userStatus}
</if>
<if test="userType != null and userType!=''">
<if test="userType != null and userType != ''">
AND u.user_Type = #{userType}
</if>
</where>
GROUP BY u.user_id, u.account, u.status, u.name, u.user_code, u.user_type, u.user_status, d.dept_name, u.mobile, u.create_time
<!-- 移除了 GROUP BY -->
</select>
</mapper>