feat: 角色权限模块
This commit is contained in:
@@ -32,24 +32,7 @@
|
||||
<artifactId>jc-club-auth-domain</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- Sa-Token 权限认证,在线文档:https://sa-token.cc -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-spring-boot-starter</artifactId>
|
||||
<version>1.37.0</version>
|
||||
</dependency>
|
||||
<!-- Sa-Token 整合 Redis (使用 jackson 序列化方式) -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-redis-jackson</artifactId>
|
||||
<version>1.37.0</version>
|
||||
</dependency>
|
||||
<!-- 提供Redis连接池 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
<version>2.9.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@@ -0,0 +1,102 @@
|
||||
package com.landaiqing.auth.application.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.landaiqing.auth.application.convert.AuthPermissionDTOConverter;
|
||||
import com.landaiqing.auth.application.dto.AuthPermissionDTO;
|
||||
import com.landaiqing.auth.domain.entity.AuthPermissionBO;
|
||||
import com.landaiqing.auth.domain.service.AuthPermissionDomainService;
|
||||
import com.landaiqing.auth.common.entity.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 权限controller
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2024/2/19
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/permission/")
|
||||
@Slf4j
|
||||
public class PermissionController {
|
||||
|
||||
@Resource
|
||||
private AuthPermissionDomainService authPermissionDomainService;
|
||||
|
||||
/**
|
||||
* 新增权限
|
||||
*/
|
||||
@RequestMapping("add")
|
||||
public Result<Boolean> add(@RequestBody AuthPermissionDTO authPermissionDTO) {
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("PermissionController.add.dto:{}", JSON.toJSONString(authPermissionDTO));
|
||||
}
|
||||
Preconditions.checkArgument(!StringUtils.isBlank(authPermissionDTO.getName()), "权限名称不能为空");
|
||||
Preconditions.checkNotNull(authPermissionDTO.getParentId(), "权限父id不能为空");
|
||||
AuthPermissionBO permissionBO = AuthPermissionDTOConverter.INSTANCE.convertDTOToBO(authPermissionDTO);
|
||||
return Result.ok(authPermissionDomainService.add(permissionBO));
|
||||
} catch (Exception e) {
|
||||
log.error("PermissionController.add.error:{}", e.getMessage(), e);
|
||||
return Result.fail("新增权限失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改权限
|
||||
*/
|
||||
@RequestMapping("update")
|
||||
public Result<Boolean> update(@RequestBody AuthPermissionDTO authPermissionDTO) {
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("PermissionController.update.dto:{}", JSON.toJSONString(authPermissionDTO));
|
||||
}
|
||||
Preconditions.checkNotNull(authPermissionDTO.getId(), "权限id不能为空");
|
||||
AuthPermissionBO permissionBO = AuthPermissionDTOConverter.INSTANCE.convertDTOToBO(authPermissionDTO);
|
||||
return Result.ok(authPermissionDomainService.update(permissionBO));
|
||||
} catch (Exception e) {
|
||||
log.error("PermissionController.update.error:{}", e.getMessage(), e);
|
||||
return Result.fail("更新权限信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除权限
|
||||
*/
|
||||
@RequestMapping("delete")
|
||||
public Result<Boolean> delete(@RequestBody AuthPermissionDTO authPermissionDTO) {
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("PermissionController.delete.dto:{}", JSON.toJSONString(authPermissionDTO));
|
||||
}
|
||||
Preconditions.checkNotNull(authPermissionDTO.getId(), "权限id不能为空");
|
||||
AuthPermissionBO permissionBO = AuthPermissionDTOConverter.INSTANCE.convertDTOToBO(authPermissionDTO);
|
||||
return Result.ok(authPermissionDomainService.delete(permissionBO));
|
||||
} catch (Exception e) {
|
||||
log.error("PermissionController.delete.error:{}", e.getMessage(), e);
|
||||
return Result.fail("删除权限信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户权限
|
||||
*/
|
||||
@RequestMapping("getPermission")
|
||||
public Result<Boolean> getPermission(String userName) {
|
||||
try {
|
||||
log.info("PermissionController.getPermission.userName:{}",userName);
|
||||
Preconditions.checkArgument(!StringUtils.isBlank(userName), "用户id不能为空");
|
||||
return Result.ok(authPermissionDomainService.getPermission(userName));
|
||||
} catch (Exception e) {
|
||||
log.error("PermissionController.getPermission.error:{}", e.getMessage(), e);
|
||||
return Result.fail("查询用户权限信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
package com.landaiqing.auth.application.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.landaiqing.auth.application.convert.AuthRoleDTOConverter;
|
||||
import com.landaiqing.auth.application.dto.AuthRoleDTO;
|
||||
import com.landaiqing.auth.common.entity.Result;
|
||||
import com.landaiqing.auth.domain.entity.AuthRoleBO;
|
||||
import com.landaiqing.auth.domain.service.AuthRoleDomainService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @Classname RoleController
|
||||
* @BelongsProject: jc-club
|
||||
* @BelongsPackage: com.landaiqing.auth.application.controller
|
||||
* @Author: landaiqing
|
||||
* @CreateTime: 2024-02-19 15:34
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/role/")
|
||||
@Slf4j
|
||||
public class RoleController {
|
||||
@Resource
|
||||
private AuthRoleDomainService authRoleDomainService;
|
||||
/**
|
||||
* @description: 新增角色
|
||||
* @param: [authRoleDTO]
|
||||
* @return: com.landaiqing.auth.common.entity.Result<java.lang.Boolean>
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/19 15:36
|
||||
*/
|
||||
@PostMapping("add")
|
||||
public Result<Boolean> add(@RequestBody AuthRoleDTO authRoleDTO){
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("RoleController.add.dto:{}", JSON.toJSONString(authRoleDTO));
|
||||
}
|
||||
Preconditions.checkNotNull(authRoleDTO.getRoleName(),"角色名称不能为空");
|
||||
Preconditions.checkNotNull(authRoleDTO.getRoleKey(),"角色Key不能为空");
|
||||
AuthRoleBO authRoleBO = AuthRoleDTOConverter.INSTANCE.convertDTOToBO(authRoleDTO);
|
||||
return Result.ok(authRoleDomainService.add(authRoleBO));
|
||||
} catch (Exception e) {
|
||||
log.error("RoleController.add.error:{}", e.getMessage(), e);
|
||||
return Result.fail("新增角色失败");
|
||||
}
|
||||
}
|
||||
@PostMapping("update")
|
||||
public Result<Boolean> update(@RequestBody AuthRoleDTO authRoleDTO){
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("RoleController.update.dto:{}", JSON.toJSONString(authRoleDTO));
|
||||
}
|
||||
Preconditions.checkNotNull(authRoleDTO.getId(),"角色id不能为空");
|
||||
|
||||
AuthRoleBO authRoleBO = AuthRoleDTOConverter.INSTANCE.convertDTOToBO(authRoleDTO);
|
||||
return Result.ok(authRoleDomainService.update(authRoleBO));
|
||||
} catch (Exception e) {
|
||||
log.error("RoleController.update.error:{}", e.getMessage(), e);
|
||||
return Result.fail("更新角色信息失败");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @description: 删除角色
|
||||
* @param: [authRoleDTO]
|
||||
* @return: com.landaiqing.auth.common.entity.Result<java.lang.Boolean>
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/19 15:53
|
||||
*/
|
||||
@PostMapping("delete")
|
||||
public Result<Boolean> delete(@RequestBody AuthRoleDTO authRoleDTO){
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("RoleController.delete.dto:{}", JSON.toJSONString(authRoleDTO));
|
||||
}
|
||||
AuthRoleBO authRoleBO = AuthRoleDTOConverter.INSTANCE.convertDTOToBO(authRoleDTO);
|
||||
return Result.ok(authRoleDomainService.delete(authRoleBO));
|
||||
} catch (Exception e) {
|
||||
log.error("RoleController.delete.error:{}", e.getMessage(), e);
|
||||
return Result.fail("删除角色信息失败");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
package com.landaiqing.auth.application.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.landaiqing.auth.application.convert.AuthRolePermissionDTOConverter;
|
||||
import com.landaiqing.auth.application.dto.AuthRolePermissionDTO;
|
||||
import com.landaiqing.auth.common.entity.Result;
|
||||
import com.landaiqing.auth.domain.entity.AuthRolePermissionBO;
|
||||
import com.landaiqing.auth.domain.service.AuthRolePermissionDomainService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 角色权限controller
|
||||
*
|
||||
* @author: landaiqing
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/rolePermission/")
|
||||
@Slf4j
|
||||
public class RolePermissionController {
|
||||
|
||||
@Resource
|
||||
private AuthRolePermissionDomainService authRolePermissionDomainService;
|
||||
|
||||
/**
|
||||
* 新增角色权限关联关系
|
||||
*/
|
||||
@RequestMapping("add")
|
||||
public Result<Boolean> add(@RequestBody AuthRolePermissionDTO authRolePermissionDTO) {
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("RolePermissionController.add.dto:{}", JSON.toJSONString(authRolePermissionDTO));
|
||||
}
|
||||
Preconditions.checkArgument(!CollectionUtils.isEmpty(authRolePermissionDTO.getPermissionIdList()),"权限关联不能为空");
|
||||
Preconditions.checkNotNull(authRolePermissionDTO.getRoleId(),"角色不能为空!");
|
||||
AuthRolePermissionBO rolePermissionBO = AuthRolePermissionDTOConverter.INSTANCE.convertDTOToBO(authRolePermissionDTO);
|
||||
return Result.ok(authRolePermissionDomainService.add(rolePermissionBO));
|
||||
} catch (Exception e) {
|
||||
log.error("PermissionController.add.error:{}", e.getMessage(), e);
|
||||
return Result.fail("新增角色权限失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -45,10 +45,7 @@ public class UserController {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("UserController.register.dto:{}", JSON.toJSONString(authUserDTO));
|
||||
}
|
||||
Preconditions.checkArgument(!StringUtils.isBlank(authUserDTO.getUserName()),"用户名不能为空");
|
||||
Preconditions.checkArgument(!StringUtils.isBlank(authUserDTO.getEmail()),"邮箱不能为空");
|
||||
Preconditions.checkArgument(!StringUtils.isBlank(authUserDTO.getPassword()),"密码不能为空");
|
||||
|
||||
checkUserInfo(authUserDTO);
|
||||
AuthUserBO authUserBO = AuthUserDTOConverter.INSTANCE.convertDTOToBO(authUserDTO);
|
||||
return Result.ok(authUserDomainService.register(authUserBO));
|
||||
} catch (Exception e) {
|
||||
@@ -56,4 +53,74 @@ public class UserController {
|
||||
return Result.fail("注册用户失败");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @description: 修改用户信息
|
||||
* @param: [authUserDTO]
|
||||
* @return: com.landaiqing.auth.common.entity.Result<java.lang.Boolean>
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/19 14:38
|
||||
*/
|
||||
@PostMapping("update")
|
||||
public Result<Boolean> update(@RequestBody AuthUserDTO authUserDTO){
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("UserController.update.dto:{}", JSON.toJSONString(authUserDTO));
|
||||
}
|
||||
checkUserInfo(authUserDTO);
|
||||
AuthUserBO authUserBO = AuthUserDTOConverter.INSTANCE.convertDTOToBO(authUserDTO);
|
||||
return Result.ok(authUserDomainService.update(authUserBO));
|
||||
} catch (Exception e) {
|
||||
log.error("UserController.update.error:{}", e.getMessage(), e);
|
||||
return Result.fail("更新用户信息失败");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @description: 用户启用/禁用
|
||||
* @param: [authUserDTO]
|
||||
* @return: com.landaiqing.auth.common.entity.Result<java.lang.Boolean>
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/19 14:56
|
||||
*/
|
||||
@PostMapping("changeStatus")
|
||||
public Result<Boolean> changeStatus(@RequestBody AuthUserDTO authUserDTO){
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("UserController.changeStatus.dto:{}", JSON.toJSONString(authUserDTO));
|
||||
}
|
||||
Preconditions.checkNotNull(authUserDTO.getStatus(),"用户名状态不能为空");
|
||||
AuthUserBO authUserBO = AuthUserDTOConverter.INSTANCE.convertDTOToBO(authUserDTO);
|
||||
return Result.ok(authUserDomainService.update(authUserBO));
|
||||
} catch (Exception e) {
|
||||
log.error("UserController.changeStatus.error:{}", e.getMessage(), e);
|
||||
return Result.fail("启用/禁用用户信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description: 删除用户
|
||||
* @param: [authUserDTO]
|
||||
* @return: com.landaiqing.auth.common.entity.Result<java.lang.Boolean>
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/19 14:50
|
||||
*/
|
||||
@PostMapping("delete")
|
||||
public Result<Boolean> delete(@RequestBody AuthUserDTO authUserDTO){
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("UserController.update.dto:{}", JSON.toJSONString(authUserDTO));
|
||||
}
|
||||
AuthUserBO authUserBO = AuthUserDTOConverter.INSTANCE.convertDTOToBO(authUserDTO);
|
||||
return Result.ok(authUserDomainService.delete(authUserBO));
|
||||
} catch (Exception e) {
|
||||
log.error("UserController.update.error:{}", e.getMessage(), e);
|
||||
return Result.fail("删除用户信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
private void checkUserInfo(@RequestBody AuthUserDTO authUserDTO) {
|
||||
Preconditions.checkArgument(!StringUtils.isBlank(authUserDTO.getUserName()),"用户名不能为空");
|
||||
Preconditions.checkArgument(!StringUtils.isBlank(authUserDTO.getEmail()),"邮箱不能为空");
|
||||
Preconditions.checkArgument(!StringUtils.isBlank(authUserDTO.getPassword()),"密码不能为空");
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,21 @@
|
||||
package com.landaiqing.auth.application.convert;
|
||||
|
||||
import com.landaiqing.auth.application.dto.AuthPermissionDTO;
|
||||
import com.landaiqing.auth.domain.entity.AuthPermissionBO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 权限dto转换器
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2024/2/19
|
||||
*/
|
||||
@Mapper
|
||||
public interface AuthPermissionDTOConverter {
|
||||
|
||||
AuthPermissionDTOConverter INSTANCE = Mappers.getMapper(AuthPermissionDTOConverter.class);
|
||||
|
||||
AuthPermissionBO convertDTOToBO(AuthPermissionDTO authPermissionDTO);
|
||||
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package com.landaiqing.auth.application.convert;
|
||||
|
||||
import com.landaiqing.auth.application.dto.AuthRoleDTO;
|
||||
import com.landaiqing.auth.domain.entity.AuthRoleBO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 角色dto转换器
|
||||
*
|
||||
* @author: landaiqing
|
||||
*/
|
||||
@Mapper
|
||||
public interface AuthRoleDTOConverter {
|
||||
|
||||
AuthRoleDTOConverter INSTANCE = Mappers.getMapper(AuthRoleDTOConverter.class);
|
||||
|
||||
AuthRoleBO convertDTOToBO(AuthRoleDTO authRoleDTO);
|
||||
|
||||
AuthRoleDTO convertBOToDTO(AuthRoleBO authRoleBO);
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.landaiqing.auth.application.convert;
|
||||
|
||||
import com.landaiqing.auth.application.dto.AuthRolePermissionDTO;
|
||||
import com.landaiqing.auth.domain.entity.AuthRolePermissionBO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 权限dto转换器
|
||||
*
|
||||
* @author: landaiqing
|
||||
*/
|
||||
@Mapper
|
||||
public interface AuthRolePermissionDTOConverter {
|
||||
|
||||
AuthRolePermissionDTOConverter INSTANCE = Mappers.getMapper(AuthRolePermissionDTOConverter.class);
|
||||
|
||||
AuthRolePermissionBO convertDTOToBO(AuthRolePermissionDTO authRolePermissionDTO);
|
||||
|
||||
}
|
@@ -9,7 +9,6 @@ import org.mapstruct.factory.Mappers;
|
||||
* 用户dto转换器
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2023/10/8
|
||||
*/
|
||||
@Mapper
|
||||
public interface AuthUserDTOConverter {
|
||||
|
@@ -8,7 +8,7 @@ import java.io.Serializable;
|
||||
* 权限dto
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2023/11/3
|
||||
* @date: 2024/2/19
|
||||
*/
|
||||
@Data
|
||||
public class AuthPermissionDTO implements Serializable {
|
||||
|
@@ -8,7 +8,7 @@ import java.io.Serializable;
|
||||
* 角色dto
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2023/11/2
|
||||
* @date: 2024/2/19
|
||||
*/
|
||||
@Data
|
||||
public class AuthRoleDTO implements Serializable {
|
||||
|
@@ -9,7 +9,6 @@ import java.util.List;
|
||||
* (AuthRolePermission)实体类
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2023-11-04 22:16:00
|
||||
*/
|
||||
@Data
|
||||
public class AuthRolePermissionDTO implements Serializable {
|
||||
|
Reference in New Issue
Block a user