fix 用户查询回显角色信息
This commit is contained in:
+45
-1
@@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.jero.common.exception.JeroBootException;
|
import com.jero.common.exception.JeroBootException;
|
||||||
|
import com.jero.modules.system.vo.SysUserVo;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
@@ -100,6 +101,44 @@ public class SysUserController {
|
|||||||
@Resource
|
@Resource
|
||||||
private BaseCommonService baseCommonService;
|
private BaseCommonService baseCommonService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据角色id和部门id获取用户列表数据
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("sys:user:list")
|
||||||
|
@PermissionData(pageComponent = "system/UserList")
|
||||||
|
@RequestMapping(value = "/pageRoleAndDepart", method = RequestMethod.GET)
|
||||||
|
public Result<IPage<SysUserVo>> queryPageListByRoleAndDepart(SysUser user,
|
||||||
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||||
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
||||||
|
HttpServletRequest req) {
|
||||||
|
String roleId = req.getParameter("roleId");
|
||||||
|
String departId = req.getParameter("departId");
|
||||||
|
//TODO 外部模拟登陆临时账号,列表不显示
|
||||||
|
Page<SysUserVo> page = new Page<>(pageNo, pageSize);
|
||||||
|
IPage<SysUserVo> pageList = sysUserService.queryPageListByRoleAndDepart(page, user, roleId, departId);
|
||||||
|
List<SysUserVo> userList = new ArrayList<>();
|
||||||
|
for (SysUserVo record : pageList.getRecords()) {
|
||||||
|
record.setEmail(PasswordUtil.decrypt(record.getEmail()));
|
||||||
|
record.setPhone(PasswordUtil.decrypt(record.getPhone()));
|
||||||
|
userList.add(record);
|
||||||
|
}
|
||||||
|
pageList.setRecords(userList);
|
||||||
|
//批量查询用户的所属部门
|
||||||
|
//step.1 先拿到全部的 useids
|
||||||
|
//step.2 通过 useids,一次性查询用户的所属部门名字
|
||||||
|
List<String> userIds = pageList.getRecords().stream().map(SysUser::getId).collect(Collectors.toList());
|
||||||
|
if (userIds != null && userIds.size() > 0) {
|
||||||
|
Map<String, String> useDepNames = sysUserService.getDepNamesByUserIds(userIds);
|
||||||
|
Map<String, String> roleNames = sysUserService.getRoleNameByUserIds(userIds);
|
||||||
|
pageList.getRecords().forEach(item -> {
|
||||||
|
item.setOrgCodeTxt(useDepNames.get(item.getId()));
|
||||||
|
item.setRoleName(roleNames.get(item.getId()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
log.info(pageList.toString());
|
||||||
|
return Result.OK(pageList);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户列表数据
|
* 获取用户列表数据
|
||||||
* @param user
|
* @param user
|
||||||
@@ -661,11 +700,16 @@ public class SysUserController {
|
|||||||
String sysRoleId = sysUserRoleVO.getRoleId();
|
String sysRoleId = sysUserRoleVO.getRoleId();
|
||||||
for(String sysUserId:sysUserRoleVO.getUserIdList()) {
|
for(String sysUserId:sysUserRoleVO.getUserIdList()) {
|
||||||
SysUserRole sysUserRole = new SysUserRole(sysUserId,sysRoleId);
|
SysUserRole sysUserRole = new SysUserRole(sysUserId,sysRoleId);
|
||||||
QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<SysUserRole>();
|
QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("role_id", sysRoleId).eq("user_id",sysUserId);
|
queryWrapper.eq("role_id", sysRoleId).eq("user_id",sysUserId);
|
||||||
SysUserRole one = sysUserRoleService.getOne(queryWrapper);
|
SysUserRole one = sysUserRoleService.getOne(queryWrapper);
|
||||||
if(one==null){
|
if(one==null){
|
||||||
sysUserRoleService.save(sysUserRole);
|
sysUserRoleService.save(sysUserRole);
|
||||||
|
queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.select("role_id");
|
||||||
|
queryWrapper.eq("user_id",sysUserId);
|
||||||
|
//List<SysUserRole> userRoleList = sysUserRoleService.listObjs(queryWrapper);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-5
@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.jero.modules.system.entity.SysRole;
|
||||||
|
import com.jero.modules.system.vo.SysUserVo;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import com.jero.modules.system.entity.SysUser;
|
import com.jero.modules.system.entity.SysUser;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
@@ -23,6 +25,7 @@ import java.util.List;
|
|||||||
public interface SysUserMapper extends BaseMapper<SysUser> {
|
public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||||
/**
|
/**
|
||||||
* 通过用户账号查询用户信息
|
* 通过用户账号查询用户信息
|
||||||
|
*
|
||||||
* @param username
|
* @param username
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -30,6 +33,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据部门Id查询用户信息
|
* 根据部门Id查询用户信息
|
||||||
|
*
|
||||||
* @param page
|
* @param page
|
||||||
* @param departId
|
* @param departId
|
||||||
* @return
|
* @return
|
||||||
@@ -38,13 +42,15 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户Ids,查询用户所属部门名称信息
|
* 根据用户Ids,查询用户所属部门名称信息
|
||||||
|
*
|
||||||
* @param userIds
|
* @param userIds
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<SysUserDepVo> getDepNamesByUserIds(@Param("userIds")List<String> userIds);
|
List<SysUserDepVo> getDepNamesByUserIds(@Param("userIds") List<String> userIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据部门Ids,查询部门下用户信息
|
* 根据部门Ids,查询部门下用户信息
|
||||||
|
*
|
||||||
* @param page
|
* @param page
|
||||||
* @param departIds
|
* @param departIds
|
||||||
* @return
|
* @return
|
||||||
@@ -53,6 +59,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色Id查询用户信息
|
* 根据角色Id查询用户信息
|
||||||
|
*
|
||||||
* @param page
|
* @param page
|
||||||
* @param
|
* @param
|
||||||
* @return
|
* @return
|
||||||
@@ -61,13 +68,15 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户名设置部门ID
|
* 根据用户名设置部门ID
|
||||||
|
*
|
||||||
* @param username
|
* @param username
|
||||||
* @param departId
|
* @param departId
|
||||||
*/
|
*/
|
||||||
void updateUserDepart(@Param("username") String username,@Param("orgCode") String orgCode);
|
void updateUserDepart(@Param("username") String username, @Param("orgCode") String orgCode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据手机号查询用户信息
|
* 根据手机号查询用户信息
|
||||||
|
*
|
||||||
* @param phone
|
* @param phone
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -76,10 +85,11 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据邮箱查询用户信息
|
* 根据邮箱查询用户信息
|
||||||
|
*
|
||||||
* @param email
|
* @param email
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public SysUser getUserByEmail(@Param("email")String email);
|
public SysUser getUserByEmail(@Param("email") String email);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据 orgCode 查询用户,包括子部门下的用户
|
* 根据 orgCode 查询用户,包括子部门下的用户
|
||||||
@@ -130,13 +140,26 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
|||||||
*/
|
*/
|
||||||
int deleteLogicDeleted(@Param("userIds") String userIds);
|
int deleteLogicDeleted(@Param("userIds") String userIds);
|
||||||
|
|
||||||
/** 更新空字符串为null【此写法有sql注入风险,禁止随便用】 */
|
/**
|
||||||
|
* 更新空字符串为null【此写法有sql注入风险,禁止随便用】
|
||||||
|
*/
|
||||||
int updateNullByEmptyString(@Param("fieldName") String fieldName);
|
int updateNullByEmptyString(@Param("fieldName") String fieldName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据部门Ids,查询部门下用户信息
|
* 根据部门Ids,查询部门下用户信息
|
||||||
|
*
|
||||||
* @param departIds
|
* @param departIds
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<SysUser> queryByDepIds(@Param("departIds")List<String> departIds,@Param("username") String username);
|
List<SysUser> queryByDepIds(@Param("departIds") List<String> departIds, @Param("username") String username);
|
||||||
|
|
||||||
|
IPage<SysUserVo> queryPageListByRoleAndDepart(Page<SysUserVo> page, @Param("user") SysUser user, @Param("roleId") String roleId, @Param("departId") String departId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户Ids,查询用户所属角色名称信息
|
||||||
|
*
|
||||||
|
* @param userIds
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<SysRole> getRoleNameByUserIds(@Param("userIds") List<String> userIds);
|
||||||
}
|
}
|
||||||
|
|||||||
+29
@@ -161,4 +161,33 @@
|
|||||||
and username != #{username}
|
and username != #{username}
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="queryPageListByRoleAndDepart" resultType="com.jero.modules.system.vo.SysUserVo">
|
||||||
|
select a.*
|
||||||
|
from (select su.*, group_concat(sur.role_id) roleIds, group_concat(sud.dep_id) departIds
|
||||||
|
from sys_user su
|
||||||
|
left join sys_user_role sur on su.id = sur.user_id
|
||||||
|
left join sys_user_depart sud ON su.id = sud.user_id
|
||||||
|
where su.del_flag = 0
|
||||||
|
GROUP BY su.id) a
|
||||||
|
<where>
|
||||||
|
<if test="departId != null and departId != ''">
|
||||||
|
a.departIds LIKE CONCAT('%', #{departId},'%')
|
||||||
|
</if>
|
||||||
|
<if test="roleId != null and roleId != ''">
|
||||||
|
and a.roleIds LIKE CONCAT('%', #{roleId},'%')
|
||||||
|
</if>
|
||||||
|
<if test="user.username != null and user.username != ''">
|
||||||
|
and a.username LIKE CONCAT('%', #{user.username},'%')
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getRoleNameByUserIds" resultType="com.jero.modules.system.entity.SysRole">
|
||||||
|
select sr.role_name, sur.user_id id from sys_role sr left join sys_user_role sur on sr.id = sur.role_id where sur.user_id in
|
||||||
|
<foreach collection="userIds" index="index" item="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
+5
@@ -15,6 +15,7 @@ import com.jero.modules.system.entity.SysUser;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.jero.modules.system.model.SysUserSysDepartModel;
|
import com.jero.modules.system.model.SysUserSysDepartModel;
|
||||||
|
import com.jero.modules.system.vo.SysUserVo;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -233,4 +234,8 @@ public interface ISysUserService extends IService<SysUser> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<SysUser> queryByDepIds(List<String> departIds, String username);
|
List<SysUser> queryByDepIds(List<String> departIds, String username);
|
||||||
|
|
||||||
|
IPage<SysUserVo> queryPageListByRoleAndDepart(Page<SysUserVo> page, SysUser user, String roleId, String departId);
|
||||||
|
|
||||||
|
Map<String, String> getRoleNameByUserIds(List<String> userIds);
|
||||||
}
|
}
|
||||||
|
|||||||
+22
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.jero.modules.system.vo.SysUserVo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import com.jero.common.api.vo.Result;
|
import com.jero.common.api.vo.Result;
|
||||||
import com.jero.common.constant.CacheConstant;
|
import com.jero.common.constant.CacheConstant;
|
||||||
@@ -439,4 +440,25 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
return userMapper.queryByDepIds(departIds,username);
|
return userMapper.queryByDepIds(departIds,username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPage<SysUserVo> queryPageListByRoleAndDepart(Page<SysUserVo> page, SysUser user, String roleId, String departId) {
|
||||||
|
|
||||||
|
return userMapper.queryPageListByRoleAndDepart(page, user,roleId,departId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getRoleNameByUserIds(List<String> userIds) {
|
||||||
|
List<SysRole> list = this.baseMapper.getRoleNameByUserIds(userIds);
|
||||||
|
Map<String, String> res = new HashMap<>();
|
||||||
|
list.forEach(item -> {
|
||||||
|
if (res.get(item.getId()) == null) {
|
||||||
|
res.put(item.getId(), item.getRoleName());
|
||||||
|
} else {
|
||||||
|
res.put(item.getId(), res.get(item.getId()) + "," + item.getRoleName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.jero.modules.system.vo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.jero.modules.system.entity.SysUser;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户Vo
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @Author scott
|
||||||
|
* @since 2018-12-20
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class SysUserVo extends SysUser {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "角色")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String roleName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "角色id")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String roleId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色code
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "角色code")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String roleCode;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user