update 优化 框架整体提高查询性能
parent
073d5e0243
commit
bb37b3401d
|
|
@ -35,6 +35,11 @@ public interface CacheNames {
|
|||
*/
|
||||
String SYS_TENANT = GlobalConstants.GLOBAL_REDIS_KEY + "sys_tenant#30d";
|
||||
|
||||
/**
|
||||
* 客户端
|
||||
*/
|
||||
String SYS_CLIENT = GlobalConstants.GLOBAL_REDIS_KEY + "sys_client#30d";
|
||||
|
||||
/**
|
||||
* 用户账户
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public class SysClientController extends BaseController {
|
|||
@Log(title = "客户端管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/changeStatus")
|
||||
public R<Void> changeStatus(@RequestBody SysClientBo bo) {
|
||||
return toAjax(sysClientService.updateUserStatus(bo.getId(), bo.getStatus()));
|
||||
return toAjax(sysClientService.updateUserStatus(bo.getClientId(), bo.getStatus()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import org.dromara.system.domain.bo.SysUserProfileBo;
|
|||
import org.dromara.system.domain.vo.AvatarVo;
|
||||
import org.dromara.system.domain.vo.ProfileVo;
|
||||
import org.dromara.system.domain.vo.SysUserVo;
|
||||
import org.dromara.system.service.ISysRoleService;
|
||||
import org.dromara.system.service.ISysUserService;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
|
@ -43,6 +44,7 @@ import java.util.Arrays;
|
|||
public class SysProfileController extends BaseController {
|
||||
|
||||
private final ISysUserService userService;
|
||||
private final ISysRoleService roleService;
|
||||
|
||||
@DubboReference
|
||||
private RemoteFileService remoteFileService;
|
||||
|
|
@ -53,10 +55,11 @@ public class SysProfileController extends BaseController {
|
|||
@GetMapping
|
||||
public R<ProfileVo> profile() {
|
||||
SysUserVo user = userService.selectUserById(LoginHelper.getUserId());
|
||||
user.setRoles(roleService.selectRolesByUserId(user.getUserId()));
|
||||
ProfileVo profileVo = new ProfileVo();
|
||||
profileVo.setUser(user);
|
||||
profileVo.setRoleGroup(userService.selectUserRoleGroup(user.getUserName()));
|
||||
profileVo.setPostGroup(userService.selectUserPostGroup(user.getUserName()));
|
||||
profileVo.setRoleGroup(userService.selectUserRoleGroup(user.getUserId()));
|
||||
profileVo.setPostGroup(userService.selectUserPostGroup(user.getUserId()));
|
||||
return R.ok(profileVo);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ public class SysUserController extends BaseController {
|
|||
if (ObjectUtil.isNull(user)) {
|
||||
return R.fail("没有权限访问用户数据!");
|
||||
}
|
||||
user.setRoles(roleService.selectRolesByUserId(user.getUserId()));
|
||||
userInfoVo.setUser(user);
|
||||
userInfoVo.setPermissions(loginUser.getMenuPermission());
|
||||
userInfoVo.setRoles(loginUser.getRolePermission());
|
||||
|
|
@ -142,7 +143,7 @@ public class SysUserController extends BaseController {
|
|||
if (ObjectUtil.isNotNull(userId)) {
|
||||
SysUserVo sysUser = userService.selectUserById(userId);
|
||||
userInfoVo.setUser(sysUser);
|
||||
userInfoVo.setRoleIds(StreamUtils.toList(sysUser.getRoles(), SysRoleVo::getRoleId));
|
||||
userInfoVo.setRoleIds(roleService.selectRoleListByUserId(userId));
|
||||
userInfoVo.setPostIds(postService.selectPostListByUserId(userId));
|
||||
}
|
||||
return R.ok(userInfoVo);
|
||||
|
|
@ -241,8 +242,9 @@ public class SysUserController extends BaseController {
|
|||
@SaCheckPermission("system:user:query")
|
||||
@GetMapping("/authRole/{userId}")
|
||||
public R<SysUserInfoVo> authRole(@PathVariable Long userId) {
|
||||
userService.checkUserDataScope(userId);
|
||||
SysUserVo user = userService.selectUserById(userId);
|
||||
List<SysRoleVo> roles = roleService.selectRolesByUserId(userId);
|
||||
List<SysRoleVo> roles = roleService.selectRolesAuthByUserId(userId);
|
||||
SysUserInfoVo userInfoVo = new SysUserInfoVo();
|
||||
userInfoVo.setUser(user);
|
||||
userInfoVo.setRoles(LoginHelper.isSuperAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isSuperAdmin()));
|
||||
|
|
|
|||
|
|
@ -19,10 +19,12 @@ import org.dromara.system.api.model.RoleDTO;
|
|||
import org.dromara.system.api.model.XcxLoginUser;
|
||||
import org.dromara.system.domain.SysUser;
|
||||
import org.dromara.system.domain.bo.SysUserBo;
|
||||
import org.dromara.system.domain.vo.SysRoleVo;
|
||||
import org.dromara.system.domain.vo.SysUserVo;
|
||||
import org.dromara.system.mapper.SysUserMapper;
|
||||
import org.dromara.system.service.ISysConfigService;
|
||||
import org.dromara.system.service.ISysPermissionService;
|
||||
import org.dromara.system.service.ISysRoleService;
|
||||
import org.dromara.system.service.ISysUserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -41,14 +43,13 @@ public class RemoteUserServiceImpl implements RemoteUserService {
|
|||
private final ISysUserService userService;
|
||||
private final ISysPermissionService permissionService;
|
||||
private final ISysConfigService configService;
|
||||
private final ISysRoleService roleService;
|
||||
private final SysUserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public LoginUser getUserInfo(String username, String tenantId) throws UserException {
|
||||
return TenantHelper.dynamic(tenantId, () -> {
|
||||
SysUser sysUser = userMapper.selectOne(new LambdaQueryWrapper<SysUser>()
|
||||
.select(SysUser::getUserName, SysUser::getStatus)
|
||||
.eq(SysUser::getUserName, username));
|
||||
SysUserVo sysUser = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, username));
|
||||
if (ObjectUtil.isNull(sysUser)) {
|
||||
throw new UserException("user.not.exists", username);
|
||||
}
|
||||
|
|
@ -57,16 +58,14 @@ public class RemoteUserServiceImpl implements RemoteUserService {
|
|||
}
|
||||
// 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||
return buildLoginUser(userMapper.selectUserByUserName(username));
|
||||
return buildLoginUser(sysUser);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginUser getUserInfo(Long userId, String tenantId) throws UserException {
|
||||
return TenantHelper.dynamic(tenantId, () -> {
|
||||
SysUser sysUser = userMapper.selectOne(new LambdaQueryWrapper<SysUser>()
|
||||
.select(SysUser::getUserName, SysUser::getStatus)
|
||||
.eq(SysUser::getUserId, userId));
|
||||
SysUserVo sysUser = userMapper.selectVoById(userId);
|
||||
if (ObjectUtil.isNull(sysUser)) {
|
||||
throw new UserException("user.not.exists", "");
|
||||
}
|
||||
|
|
@ -75,16 +74,14 @@ public class RemoteUserServiceImpl implements RemoteUserService {
|
|||
}
|
||||
// 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||
return buildLoginUser(userMapper.selectUserByUserName(sysUser.getUserName()));
|
||||
return buildLoginUser(sysUser);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginUser getUserInfoByPhonenumber(String phonenumber, String tenantId) throws UserException {
|
||||
return TenantHelper.dynamic(tenantId, () -> {
|
||||
SysUser sysUser = userMapper.selectOne(new LambdaQueryWrapper<SysUser>()
|
||||
.select(SysUser::getPhonenumber, SysUser::getStatus)
|
||||
.eq(SysUser::getPhonenumber, phonenumber));
|
||||
SysUserVo sysUser = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getPhonenumber, phonenumber));
|
||||
if (ObjectUtil.isNull(sysUser)) {
|
||||
throw new UserException("user.not.exists", phonenumber);
|
||||
}
|
||||
|
|
@ -93,16 +90,14 @@ public class RemoteUserServiceImpl implements RemoteUserService {
|
|||
}
|
||||
// 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||
return buildLoginUser(userMapper.selectUserByPhonenumber(phonenumber));
|
||||
return buildLoginUser(sysUser);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginUser getUserInfoByEmail(String email, String tenantId) throws UserException {
|
||||
return TenantHelper.dynamic(tenantId, () -> {
|
||||
SysUser user = userMapper.selectOne(new LambdaQueryWrapper<SysUser>()
|
||||
.select(SysUser::getEmail, SysUser::getStatus)
|
||||
.eq(SysUser::getEmail, email));
|
||||
SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getEmail, email));
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
throw new UserException("user.not.exists", email);
|
||||
}
|
||||
|
|
@ -111,7 +106,7 @@ public class RemoteUserServiceImpl implements RemoteUserService {
|
|||
}
|
||||
// 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||
return buildLoginUser(userMapper.selectUserByEmail(email));
|
||||
return buildLoginUser(user);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -179,8 +174,10 @@ public class RemoteUserServiceImpl implements RemoteUserService {
|
|||
loginUser.setMenuPermission(permissionService.getMenuPermission(userVo.getUserId()));
|
||||
loginUser.setRolePermission(permissionService.getRolePermission(userVo.getUserId()));
|
||||
loginUser.setDeptName(ObjectUtil.isNull(userVo.getDept()) ? "" : userVo.getDept().getDeptName());
|
||||
List<RoleDTO> roles = BeanUtil.copyToList(userVo.getRoles(), RoleDTO.class);
|
||||
loginUser.setRoles(roles);
|
||||
List<SysRoleVo> roles = DataPermissionHelper.ignore(() -> {
|
||||
return roleService.selectRolesByUserId(userVo.getUserId());
|
||||
});
|
||||
loginUser.setRoles(BeanUtil.copyToList(roles, RoleDTO.class));
|
||||
return loginUser;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public interface SysDeptMapper extends BaseMapperPlus<SysDept, SysDeptVo> {
|
|||
@DataPermission({
|
||||
@DataColumn(key = "deptName", value = "dept_id")
|
||||
})
|
||||
SysDeptVo selectDeptById(Long deptId);
|
||||
long countDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* 根据角色ID查询部门树信息
|
||||
|
|
|
|||
|
|
@ -13,20 +13,12 @@ import java.util.List;
|
|||
*/
|
||||
public interface SysPostMapper extends BaseMapperPlus<SysPost, SysPostVo> {
|
||||
|
||||
/**
|
||||
* 根据用户ID获取岗位选择框列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 选中岗位ID列表
|
||||
*/
|
||||
List<Long> selectPostListByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 查询用户所属岗位组
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
List<SysPostVo> selectPostsByUserName(String userName);
|
||||
List<SysPostVo> selectPostsByUserId(Long userId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ package org.dromara.system.mapper;
|
|||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.dromara.common.mybatis.annotation.DataColumn;
|
||||
import org.dromara.common.mybatis.annotation.DataPermission;
|
||||
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import org.dromara.system.domain.SysRole;
|
||||
import org.dromara.system.domain.vo.SysRoleVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -51,21 +51,12 @@ public interface SysRoleMapper extends BaseMapperPlus<SysRole, SysRoleVo> {
|
|||
*/
|
||||
List<SysRoleVo> selectRolePermissionByUserId(Long userId);
|
||||
|
||||
|
||||
/**
|
||||
* 根据用户ID获取角色选择框列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 选中角色ID列表
|
||||
*/
|
||||
List<Long> selectRoleListByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param userId 用户ID
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRoleVo> selectRolesByUserName(String userName);
|
||||
List<SysRoleVo> selectRolesByUserId(Long userId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,41 +61,11 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo> {
|
|||
})
|
||||
Page<SysUserVo> selectUnallocatedList(@Param("page") Page<SysUser> page, @Param(Constants.WRAPPER) Wrapper<SysUser> queryWrapper);
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
SysUserVo selectUserByUserName(String userName);
|
||||
|
||||
/**
|
||||
* 通过手机号查询用户
|
||||
*
|
||||
* @param phonenumber 手机号
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
SysUserVo selectUserByPhonenumber(String phonenumber);
|
||||
|
||||
/**
|
||||
* 通过邮箱查询用户
|
||||
*
|
||||
* @param email 邮箱
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
SysUserVo selectUserByEmail(String email);
|
||||
|
||||
/**
|
||||
* 通过用户ID查询用户
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
@DataPermission({
|
||||
@DataColumn(key = "deptName", value = "d.dept_id"),
|
||||
@DataColumn(key = "userName", value = "u.user_id")
|
||||
@DataColumn(key = "deptName", value = "dept_id"),
|
||||
@DataColumn(key = "userName", value = "user_id")
|
||||
})
|
||||
SysUserVo selectUserById(Long userId);
|
||||
long countUserById(Long userId);
|
||||
|
||||
@Override
|
||||
@DataPermission({
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public interface ISysClientService {
|
|||
/**
|
||||
* 修改状态
|
||||
*/
|
||||
int updateUserStatus(Long id, String status);
|
||||
int updateUserStatus(String clientId, String status);
|
||||
|
||||
/**
|
||||
* 校验并批量删除客户端管理信息
|
||||
|
|
|
|||
|
|
@ -35,6 +35,14 @@ public interface ISysRoleService {
|
|||
*/
|
||||
List<SysRoleVo> selectRolesByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色列表(包含被授权状态)
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRoleVo> selectRolesAuthByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色权限
|
||||
*
|
||||
|
|
@ -180,4 +188,5 @@ public interface ISysRoleService {
|
|||
int insertAuthUsers(Long roleId, Long[] userIds);
|
||||
|
||||
void cleanOnlineUserByRole(Long roleId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,18 +68,18 @@ public interface ISysUserService {
|
|||
/**
|
||||
* 根据用户ID查询用户所属角色组
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
String selectUserRoleGroup(String userName);
|
||||
String selectUserRoleGroup(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询用户所属岗位组
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
String selectUserPostGroup(String userName);
|
||||
String selectUserPostGroup(Long userId);
|
||||
|
||||
/**
|
||||
* 校验用户名称是否唯一
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.constant.CacheNames;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
|
|
@ -16,6 +17,8 @@ import org.dromara.system.domain.bo.SysClientBo;
|
|||
import org.dromara.system.domain.vo.SysClientVo;
|
||||
import org.dromara.system.mapper.SysClientMapper;
|
||||
import org.dromara.system.service.ISysClientService;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
|
|
@ -47,6 +50,7 @@ public class SysClientServiceImpl implements ISysClientService {
|
|||
/**
|
||||
* 查询客户端管理
|
||||
*/
|
||||
@Cacheable(cacheNames = CacheNames.SYS_CLIENT, key = "#clientId")
|
||||
@Override
|
||||
public SysClientVo queryByClientId(String clientId) {
|
||||
return baseMapper.selectVoOne(new LambdaQueryWrapper<SysClient>().eq(SysClient::getClientId, clientId));
|
||||
|
|
@ -104,6 +108,7 @@ public class SysClientServiceImpl implements ISysClientService {
|
|||
/**
|
||||
* 修改客户端管理
|
||||
*/
|
||||
@CacheEvict(cacheNames = CacheNames.SYS_CLIENT, key = "#bo.clientId")
|
||||
@Override
|
||||
public Boolean updateByBo(SysClientBo bo) {
|
||||
SysClient update = MapstructUtils.convert(bo, SysClient.class);
|
||||
|
|
@ -115,12 +120,13 @@ public class SysClientServiceImpl implements ISysClientService {
|
|||
/**
|
||||
* 修改状态
|
||||
*/
|
||||
@CacheEvict(cacheNames = CacheNames.SYS_CLIENT, key = "#clientId")
|
||||
@Override
|
||||
public int updateUserStatus(Long id, String status) {
|
||||
public int updateUserStatus(String clientId, String status) {
|
||||
return baseMapper.update(null,
|
||||
new LambdaUpdateWrapper<SysClient>()
|
||||
.set(SysClient::getStatus, status)
|
||||
.eq(SysClient::getId, id));
|
||||
.eq(SysClient::getClientId, clientId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -133,6 +139,7 @@ public class SysClientServiceImpl implements ISysClientService {
|
|||
/**
|
||||
* 批量删除客户端管理
|
||||
*/
|
||||
@CacheEvict(cacheNames = CacheNames.SYS_CLIENT, allEntries = true)
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ import java.util.List;
|
|||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class SysDeptServiceImpl implements ISysDeptService{
|
||||
public class SysDeptServiceImpl implements ISysDeptService {
|
||||
|
||||
private final SysDeptMapper baseMapper;
|
||||
private final SysRoleMapper roleMapper;
|
||||
|
|
@ -143,6 +143,7 @@ public class SysDeptServiceImpl implements ISysDeptService{
|
|||
* @param deptIds 部门ID串逗号分隔
|
||||
* @return 部门名称串逗号分隔
|
||||
*/
|
||||
@Override
|
||||
public String selectDeptNameByIds(String deptIds) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Long id : StringUtils.splitTo(deptIds, Convert::toLong)) {
|
||||
|
|
@ -219,8 +220,7 @@ public class SysDeptServiceImpl implements ISysDeptService{
|
|||
if (LoginHelper.isSuperAdmin()) {
|
||||
return;
|
||||
}
|
||||
SysDeptVo dept = baseMapper.selectDeptById(deptId);
|
||||
if (ObjectUtil.isNull(dept)) {
|
||||
if (baseMapper.countDeptById(deptId) == 0) {
|
||||
throw new ServiceException("没有权限访问部门数据!");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,14 +32,6 @@ public class SysLogininforServiceImpl implements ISysLogininforService {
|
|||
|
||||
private final SysLogininforMapper baseMapper;
|
||||
|
||||
|
||||
private String getBlock(Object msg) {
|
||||
if (msg == null) {
|
||||
msg = "";
|
||||
}
|
||||
return "[" + msg.toString() + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo<SysLogininforVo> selectPageLogininforList(SysLogininforBo logininfor, PageQuery pageQuery) {
|
||||
Map<String, Object> params = logininfor.getParams();
|
||||
|
|
|
|||
|
|
@ -4,18 +4,19 @@ import cn.hutool.core.util.ObjectUtil;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.system.domain.SysNotice;
|
||||
import org.dromara.system.domain.SysUser;
|
||||
import org.dromara.system.domain.bo.SysNoticeBo;
|
||||
import org.dromara.system.domain.vo.SysNoticeVo;
|
||||
import org.dromara.system.domain.vo.SysUserVo;
|
||||
import org.dromara.system.mapper.SysNoticeMapper;
|
||||
import org.dromara.system.mapper.SysUserMapper;
|
||||
import org.dromara.system.service.ISysNoticeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
@ -68,7 +69,7 @@ public class SysNoticeServiceImpl implements ISysNoticeService {
|
|||
lqw.like(StringUtils.isNotBlank(bo.getNoticeTitle()), SysNotice::getNoticeTitle, bo.getNoticeTitle());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getNoticeType()), SysNotice::getNoticeType, bo.getNoticeType());
|
||||
if (StringUtils.isNotBlank(bo.getCreateByName())) {
|
||||
SysUserVo sysUser = userMapper.selectUserByUserName(bo.getCreateByName());
|
||||
SysUserVo sysUser = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, bo.getCreateByName()));
|
||||
lqw.eq(SysNotice::getCreateBy, ObjectUtil.isNotNull(sysUser) ? sysUser.getUserId() : null);
|
||||
}
|
||||
lqw.orderByAsc(SysNotice::getNoticeId);
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
|
|
@ -18,6 +18,7 @@ import org.dromara.system.domain.vo.SysPostVo;
|
|||
import org.dromara.system.mapper.SysPostMapper;
|
||||
import org.dromara.system.mapper.SysUserPostMapper;
|
||||
import org.dromara.system.service.ISysPostService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
@ -92,7 +93,8 @@ public class SysPostServiceImpl implements ISysPostService {
|
|||
*/
|
||||
@Override
|
||||
public List<Long> selectPostListByUserId(Long userId) {
|
||||
return baseMapper.selectPostListByUserId(userId);
|
||||
List<SysPostVo> list = baseMapper.selectPostsByUserId(userId);
|
||||
return StreamUtils.toList(list, SysPostVo::getPostId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
|||
.like(StringUtils.isNotBlank(bo.getRoleKey()), "r.role_key", bo.getRoleKey())
|
||||
.between(params.get("beginTime") != null && params.get("endTime") != null,
|
||||
"r.create_time", params.get("beginTime"), params.get("endTime"))
|
||||
.orderByAsc("r.role_sort").orderByAsc("r.create_time");;
|
||||
.orderByAsc("r.role_sort").orderByAsc("r.create_time");
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
|
@ -91,6 +91,17 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
|||
*/
|
||||
@Override
|
||||
public List<SysRoleVo> selectRolesByUserId(Long userId) {
|
||||
return baseMapper.selectRolesByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色列表(包含被授权状态)
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 角色列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysRoleVo> selectRolesAuthByUserId(Long userId) {
|
||||
List<SysRoleVo> userRoles = baseMapper.selectRolePermissionByUserId(userId);
|
||||
List<SysRoleVo> roles = selectRoleAll();
|
||||
for (SysRoleVo role : roles) {
|
||||
|
|
@ -140,7 +151,8 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
|||
*/
|
||||
@Override
|
||||
public List<Long> selectRoleListByUserId(Long userId) {
|
||||
return baseMapper.selectRoleListByUserId(userId);
|
||||
List<SysRoleVo> list = baseMapper.selectRolesByUserId(userId);
|
||||
return StreamUtils.toList(list, SysRoleVo::getRoleId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ import org.springframework.cache.annotation.Cacheable;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -141,7 +140,7 @@ public class SysUserServiceImpl implements ISysUserService {
|
|||
*/
|
||||
@Override
|
||||
public SysUserVo selectUserByUserName(String userName) {
|
||||
return baseMapper.selectUserByUserName(userName);
|
||||
return baseMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, userName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -152,7 +151,7 @@ public class SysUserServiceImpl implements ISysUserService {
|
|||
*/
|
||||
@Override
|
||||
public SysUserVo selectUserByPhonenumber(String phonenumber) {
|
||||
return baseMapper.selectUserByPhonenumber(phonenumber);
|
||||
return baseMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getPhonenumber, phonenumber));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -163,18 +162,18 @@ public class SysUserServiceImpl implements ISysUserService {
|
|||
*/
|
||||
@Override
|
||||
public SysUserVo selectUserById(Long userId) {
|
||||
return baseMapper.selectUserById(userId);
|
||||
return baseMapper.selectVoById(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户所属角色组
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public String selectUserRoleGroup(String userName) {
|
||||
List<SysRoleVo> list = roleMapper.selectRolesByUserName(userName);
|
||||
public String selectUserRoleGroup(Long userId) {
|
||||
List<SysRoleVo> list = roleMapper.selectRolesByUserId(userId);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
|
@ -184,12 +183,12 @@ public class SysUserServiceImpl implements ISysUserService {
|
|||
/**
|
||||
* 查询用户所属岗位组
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public String selectUserPostGroup(String userName) {
|
||||
List<SysPostVo> list = postMapper.selectPostsByUserName(userName);
|
||||
public String selectUserPostGroup(Long userId) {
|
||||
List<SysPostVo> list = postMapper.selectPostsByUserId(userId);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
|
@ -261,7 +260,7 @@ public class SysUserServiceImpl implements ISysUserService {
|
|||
if (LoginHelper.isSuperAdmin()) {
|
||||
return;
|
||||
}
|
||||
if (ObjectUtil.isNull(baseMapper.selectUserById(userId))) {
|
||||
if (baseMapper.countUserById(userId) == 0) {
|
||||
throw new ServiceException("没有权限访问用户数据!");
|
||||
}
|
||||
}
|
||||
|
|
@ -421,7 +420,7 @@ public class SysUserServiceImpl implements ISysUserService {
|
|||
userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getUserId, user.getUserId()));
|
||||
}
|
||||
// 新增用户与岗位管理
|
||||
List<SysUserPost> list = StreamUtils.toList(Arrays.asList(posts), postId -> {
|
||||
List<SysUserPost> list = StreamUtils.toList(List.of(posts), postId -> {
|
||||
SysUserPost up = new SysUserPost();
|
||||
up.setUserId(user.getUserId());
|
||||
up.setPostId(postId);
|
||||
|
|
@ -449,7 +448,7 @@ public class SysUserServiceImpl implements ISysUserService {
|
|||
if (!LoginHelper.isSuperAdmin(userId)) {
|
||||
roleList.remove(UserConstants.SUPER_ADMIN_ID);
|
||||
}
|
||||
List<Long> canDoRoleList = StreamUtils.filter(Arrays.asList(roleIds), roleList::contains);
|
||||
List<Long> canDoRoleList = StreamUtils.filter(List.of(roleIds), roleList::contains);
|
||||
if (CollUtil.isEmpty(canDoRoleList)) {
|
||||
throw new ServiceException("没有权限访问角色的数据");
|
||||
}
|
||||
|
|
@ -502,7 +501,7 @@ public class SysUserServiceImpl implements ISysUserService {
|
|||
checkUserAllowed(userId);
|
||||
checkUserDataScope(userId);
|
||||
}
|
||||
List<Long> ids = Arrays.asList(userIds);
|
||||
List<Long> ids = List.of(userIds);
|
||||
// 删除用户与角色关联
|
||||
userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getUserId, ids));
|
||||
// 删除用户与岗位表
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@
|
|||
select * from sys_dept ${ew.getCustomSqlSegment}
|
||||
</select>
|
||||
|
||||
<select id="selectDeptById" resultMap="SysDeptResult">
|
||||
select * from sys_dept where del_flag = '0' and dept_id = #{deptId}
|
||||
<select id="countDeptById" resultType="Long">
|
||||
select count(*) from sys_dept where del_flag = '0' and dept_id = #{deptId}
|
||||
</select>
|
||||
|
||||
<select id="selectDeptListByRoleId" resultType="Long">
|
||||
|
|
|
|||
|
|
@ -7,20 +7,12 @@
|
|||
<resultMap type="org.dromara.system.domain.vo.SysPostVo" id="SysPostResult">
|
||||
</resultMap>
|
||||
|
||||
<select id="selectPostListByUserId" parameterType="Long" resultType="Long">
|
||||
select p.post_id
|
||||
<select id="selectPostsByUserId" parameterType="Long" resultMap="SysPostResult">
|
||||
select p.post_id, p.post_name, p.post_code
|
||||
from sys_post p
|
||||
left join sys_user_post up on up.post_id = p.post_id
|
||||
left join sys_user u on u.user_id = up.user_id
|
||||
where u.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectPostsByUserName" parameterType="String" resultMap="SysPostResult">
|
||||
select p.post_id, p.post_name, p.post_code
|
||||
from sys_post p
|
||||
left join sys_user_post up on up.post_id = p.post_id
|
||||
left join sys_user u on u.user_id = up.user_id
|
||||
where u.user_name = #{userName}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -40,23 +40,17 @@
|
|||
WHERE r.del_flag = '0' and sur.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectRoleListByUserId" parameterType="Long" resultType="Long">
|
||||
select r.role_id
|
||||
from sys_role r
|
||||
left join sys_user_role sur on sur.role_id = r.role_id
|
||||
left join sys_user u on u.user_id = sur.user_id
|
||||
where u.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectRolesByUserName" parameterType="String" resultMap="SysRoleResult">
|
||||
<select id="selectRolesByUserId" parameterType="Long" resultMap="SysRoleResult">
|
||||
select r.role_id,
|
||||
r.role_name,
|
||||
r.role_key,
|
||||
r.role_sort
|
||||
r.role_sort,
|
||||
r.data_scope,
|
||||
r.status
|
||||
from sys_role r
|
||||
left join sys_user_role sur on sur.role_id = r.role_id
|
||||
left join sys_user u on u.user_id = sur.user_id
|
||||
WHERE r.del_flag = '0' and u.user_name = #{userName}
|
||||
WHERE r.del_flag = '0' and sur.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectRoleById" resultMap="SysRoleResult">
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
<id property="userId" column="user_id"/>
|
||||
<result property="deptId" column="dept_id"/>
|
||||
<association property="dept" column="dept_id" resultMap="deptResult"/>
|
||||
<collection property="roles" javaType="java.util.List" resultMap="RoleResult"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="deptResult" type="org.dromara.system.domain.vo.SysDeptVo">
|
||||
|
|
@ -19,50 +18,6 @@
|
|||
<result property="createTime" column="dept_create_time"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="RoleResult" type="org.dromara.system.domain.vo.SysRoleVo">
|
||||
<id property="roleId" column="role_id"/>
|
||||
<result property="status" column="role_status"/>
|
||||
<result property="createTime" column="role_create_time"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectUserVo">
|
||||
select u.user_id,
|
||||
u.tenant_id,
|
||||
u.dept_id,
|
||||
u.user_name,
|
||||
u.nick_name,
|
||||
u.user_type,
|
||||
u.email,
|
||||
u.avatar,
|
||||
u.phonenumber,
|
||||
u.password,
|
||||
u.sex,
|
||||
u.status,
|
||||
u.del_flag,
|
||||
u.login_ip,
|
||||
u.login_date,
|
||||
u.create_by,
|
||||
u.create_time,
|
||||
u.remark,
|
||||
d.dept_id,
|
||||
d.parent_id,
|
||||
d.ancestors,
|
||||
d.dept_name,
|
||||
d.order_num,
|
||||
d.leader,
|
||||
d.status as dept_status,
|
||||
r.role_id,
|
||||
r.role_name,
|
||||
r.role_key,
|
||||
r.role_sort,
|
||||
r.data_scope,
|
||||
r.status as role_status
|
||||
from sys_user u
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
left join sys_user_role sur on u.user_id = sur.user_id
|
||||
left join sys_role r on r.role_id = sur.role_id
|
||||
</sql>
|
||||
|
||||
<select id="selectPageUserList" resultMap="SysUserResult">
|
||||
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex,
|
||||
u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
|
||||
|
|
@ -101,24 +56,8 @@
|
|||
${ew.getCustomSqlSegment}
|
||||
</select>
|
||||
|
||||
<select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.del_flag = '0' and u.user_name = #{userName}
|
||||
</select>
|
||||
|
||||
<select id="selectUserByPhonenumber" parameterType="String" resultMap="SysUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.del_flag = '0' and u.phonenumber = #{phonenumber}
|
||||
</select>
|
||||
|
||||
<select id="selectUserByEmail" parameterType="String" resultMap="SysUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.del_flag = '0' and u.email = #{email}
|
||||
</select>
|
||||
|
||||
<select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.del_flag = '0' and u.user_id = #{userId}
|
||||
<select id="countUserById" resultType="Long">
|
||||
select count(*) from sys_user where del_flag = '0' and user_id = #{userId}
|
||||
</select>
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue