Feature: 删除用户权限逻辑优化.

pull/10/head
chen.ma 3 years ago
parent 8c29662372
commit 30ac508f26

@ -1,6 +1,7 @@
package com.github.dynamic.threadpool.auth.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -12,6 +13,11 @@ import com.github.dynamic.threadpool.auth.model.biz.permission.PermissionRespDTO
import com.github.dynamic.threadpool.auth.service.PermissionService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
/**
* Permission service impl.
@ -54,9 +60,9 @@ public class PermissionServiceImpl implements PermissionService {
@Override
public void deletePermission(String role, String resource, String action) {
LambdaUpdateWrapper<PermissionInfo> updateWrapper = Wrappers.lambdaUpdate(PermissionInfo.class)
.eq(PermissionInfo::getRole, role)
.eq(PermissionInfo::getResource, resource)
.eq(PermissionInfo::getAction, action);
.eq(StrUtil.isNotBlank(role), PermissionInfo::getRole, role)
.eq(StrUtil.isNotBlank(resource), PermissionInfo::getResource, resource)
.eq(StrUtil.isNotBlank(action), PermissionInfo::getAction, action);
permissionMapper.delete(updateWrapper);
}

@ -1,18 +1,25 @@
package com.github.dynamic.threadpool.auth.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.github.dynamic.threadpool.auth.mapper.RoleMapper;
import com.github.dynamic.threadpool.auth.model.RoleInfo;
import com.github.dynamic.threadpool.auth.model.biz.role.RoleQueryPageReqDTO;
import com.github.dynamic.threadpool.auth.model.biz.role.RoleRespDTO;
import com.github.dynamic.threadpool.auth.service.PermissionService;
import com.github.dynamic.threadpool.auth.service.RoleService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@ -28,6 +35,8 @@ public class RoleServiceImpl implements RoleService {
private final RoleMapper roleMapper;
private final PermissionService permissionService;
@Override
public IPage<RoleRespDTO> listRole(int pageNo, int pageSize) {
RoleQueryPageReqDTO queryPage = new RoleQueryPageReqDTO(pageNo, pageSize);
@ -53,10 +62,18 @@ public class RoleServiceImpl implements RoleService {
@Override
public void deleteRole(String role, String userName) {
List<String> roleStrList = CollUtil.toList(role);
if (StrUtil.isBlank(role)) {
LambdaQueryWrapper<RoleInfo> queryWrapper = Wrappers.lambdaQuery(RoleInfo.class).eq(RoleInfo::getUserName, userName);
roleStrList = roleMapper.selectList(queryWrapper).stream().map(RoleInfo::getRole).collect(Collectors.toList());
}
LambdaUpdateWrapper<RoleInfo> updateWrapper = Wrappers.lambdaUpdate(RoleInfo.class)
.eq(RoleInfo::getRole, role)
.eq(RoleInfo::getUserName, userName);
.eq(StrUtil.isNotBlank(role), RoleInfo::getRole, role)
.eq(StrUtil.isNotBlank(userName), RoleInfo::getUserName, userName);
roleMapper.delete(updateWrapper);
roleStrList.forEach(each -> permissionService.deletePermission(each, "", ""));
}
@Override

@ -10,6 +10,7 @@ import com.github.dynamic.threadpool.auth.mapper.UserMapper;
import com.github.dynamic.threadpool.auth.model.UserInfo;
import com.github.dynamic.threadpool.auth.model.biz.user.UserQueryPageReqDTO;
import com.github.dynamic.threadpool.auth.model.biz.user.UserRespDTO;
import com.github.dynamic.threadpool.auth.service.RoleService;
import com.github.dynamic.threadpool.auth.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
@ -29,6 +30,8 @@ public class UserServiceImpl implements UserService {
private final UserMapper userMapper;
private final RoleService roleService;
@Override
public IPage<UserRespDTO> listUser(int pageNo, int pageSize) {
UserQueryPageReqDTO queryPage = new UserQueryPageReqDTO(pageNo, pageSize);
@ -69,6 +72,7 @@ public class UserServiceImpl implements UserService {
LambdaUpdateWrapper<UserInfo> updateWrapper = Wrappers.lambdaUpdate(UserInfo.class)
.eq(UserInfo::getUserName, userName);
userMapper.delete(updateWrapper);
roleService.deleteRole("", userName);
}
@Override

Loading…
Cancel
Save