diff --git a/auth/src/main/java/com/github/dynamic/threadpool/auth/service/impl/PermissionServiceImpl.java b/auth/src/main/java/com/github/dynamic/threadpool/auth/service/impl/PermissionServiceImpl.java index 2a7bd176..e6ca996a 100644 --- a/auth/src/main/java/com/github/dynamic/threadpool/auth/service/impl/PermissionServiceImpl.java +++ b/auth/src/main/java/com/github/dynamic/threadpool/auth/service/impl/PermissionServiceImpl.java @@ -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 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); } diff --git a/auth/src/main/java/com/github/dynamic/threadpool/auth/service/impl/RoleServiceImpl.java b/auth/src/main/java/com/github/dynamic/threadpool/auth/service/impl/RoleServiceImpl.java index 4f15664b..924b66e2 100644 --- a/auth/src/main/java/com/github/dynamic/threadpool/auth/service/impl/RoleServiceImpl.java +++ b/auth/src/main/java/com/github/dynamic/threadpool/auth/service/impl/RoleServiceImpl.java @@ -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 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 roleStrList = CollUtil.toList(role); + if (StrUtil.isBlank(role)) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(RoleInfo.class).eq(RoleInfo::getUserName, userName); + roleStrList = roleMapper.selectList(queryWrapper).stream().map(RoleInfo::getRole).collect(Collectors.toList()); + } + LambdaUpdateWrapper 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 diff --git a/auth/src/main/java/com/github/dynamic/threadpool/auth/service/impl/UserServiceImpl.java b/auth/src/main/java/com/github/dynamic/threadpool/auth/service/impl/UserServiceImpl.java index dd35567a..f4753c3c 100644 --- a/auth/src/main/java/com/github/dynamic/threadpool/auth/service/impl/UserServiceImpl.java +++ b/auth/src/main/java/com/github/dynamic/threadpool/auth/service/impl/UserServiceImpl.java @@ -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 listUser(int pageNo, int pageSize) { UserQueryPageReqDTO queryPage = new UserQueryPageReqDTO(pageNo, pageSize); @@ -69,6 +72,7 @@ public class UserServiceImpl implements UserService { LambdaUpdateWrapper updateWrapper = Wrappers.lambdaUpdate(UserInfo.class) .eq(UserInfo::getUserName, userName); userMapper.delete(updateWrapper); + roleService.deleteRole("", userName); } @Override