From f25a536d55da005236e3164d3b611da6727f3300 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Thu, 5 Sep 2024 16:25:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=EF=BC=8C=E8=A7=92=E8=89=B2?= =?UTF-8?q?=EF=BC=8C=E8=A7=92=E8=89=B2=E7=BB=91=E5=AE=9A=E8=B5=84=E6=BA=90?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E6=88=B7=E7=BB=91=E5=AE=9A=E8=A7=92=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/RoleAuthController.java | 82 +++++++++++++++++++ .../xiannccda/controller/UserController.java | 21 ++++- .../dto/auth/AuthApiPathQueryDTO.java | 10 +++ .../xiannccda/dto/auth/AuthRoleDTO.java | 15 ++++ .../xiannccda/dto/auth/AuthRoleQueryDTO.java | 11 +++ .../xiannccda/dto/user/UserDetailDTO.java | 36 ++++++++ .../xiannccda/dto/user/UserEditDTO.java | 13 +++ .../xiannccda/dto/user/UserQueryDTO.java | 12 +++ .../joylink/xiannccda/entity/AuthApiPath.java | 47 +++++++++++ .../joylink/xiannccda/entity/AuthRole.java | 30 +++++++ .../xiannccda/entity/AuthRoleApiPathRef.java | 42 ++++++++++ .../xiannccda/entity/AuthRoleUserRef.java | 36 ++++++++ .../xiannccda/mapper/AuthApiPathMapper.java | 19 +++++ .../mapper/AuthRoleApiRefMapper.java | 19 +++++ .../xiannccda/mapper/AuthRoleMapper.java | 23 ++++++ .../mapper/AuthRoleUserRefMapper.java | 19 +++++ .../joylink/xiannccda/mapper/UserMapper.java | 4 + .../xiannccda/mapper/xml/UserMapper.xml | 19 ----- .../repository/IAuthApiPathRepository.java | 21 +++++ .../repository/IAuthRoleApiRefRepository.java | 18 ++++ .../repository/IAuthRoleRepository.java | 22 +++++ .../IAuthRoleUserRefRepository.java | 18 ++++ .../xiannccda/repository/IUserRepository.java | 4 + .../impl/AuthApiPathRepository.java | 30 +++++++ .../impl/AuthRoleApiRefRepository.java | 23 ++++++ .../repository/impl/AuthRoleRepository.java | 38 +++++++++ .../impl/AuthRoleUserRefRepository.java | 23 ++++++ .../repository/impl/UserRepository.java | 22 +++++ .../xiannccda/service/AuthService.java | 67 +++++++++++++++ .../xiannccda/service/UserService.java | 28 +++++-- .../resources/mybatis/mapper/AuthRole.xml | 21 +++++ .../resources/mybatis/mapper/UserMapper.xml | 29 +++++++ .../xiannccda/protocal/x/BigDataReq.java | 2 +- 33 files changed, 796 insertions(+), 28 deletions(-) create mode 100644 src/main/java/club/joylink/xiannccda/controller/RoleAuthController.java create mode 100644 src/main/java/club/joylink/xiannccda/dto/auth/AuthApiPathQueryDTO.java create mode 100644 src/main/java/club/joylink/xiannccda/dto/auth/AuthRoleDTO.java create mode 100644 src/main/java/club/joylink/xiannccda/dto/auth/AuthRoleQueryDTO.java create mode 100644 src/main/java/club/joylink/xiannccda/dto/user/UserDetailDTO.java create mode 100644 src/main/java/club/joylink/xiannccda/dto/user/UserEditDTO.java create mode 100644 src/main/java/club/joylink/xiannccda/dto/user/UserQueryDTO.java create mode 100644 src/main/java/club/joylink/xiannccda/entity/AuthApiPath.java create mode 100644 src/main/java/club/joylink/xiannccda/entity/AuthRole.java create mode 100644 src/main/java/club/joylink/xiannccda/entity/AuthRoleApiPathRef.java create mode 100644 src/main/java/club/joylink/xiannccda/entity/AuthRoleUserRef.java create mode 100644 src/main/java/club/joylink/xiannccda/mapper/AuthApiPathMapper.java create mode 100644 src/main/java/club/joylink/xiannccda/mapper/AuthRoleApiRefMapper.java create mode 100644 src/main/java/club/joylink/xiannccda/mapper/AuthRoleMapper.java create mode 100644 src/main/java/club/joylink/xiannccda/mapper/AuthRoleUserRefMapper.java delete mode 100644 src/main/java/club/joylink/xiannccda/mapper/xml/UserMapper.xml create mode 100644 src/main/java/club/joylink/xiannccda/repository/IAuthApiPathRepository.java create mode 100644 src/main/java/club/joylink/xiannccda/repository/IAuthRoleApiRefRepository.java create mode 100644 src/main/java/club/joylink/xiannccda/repository/IAuthRoleRepository.java create mode 100644 src/main/java/club/joylink/xiannccda/repository/IAuthRoleUserRefRepository.java create mode 100644 src/main/java/club/joylink/xiannccda/repository/impl/AuthApiPathRepository.java create mode 100644 src/main/java/club/joylink/xiannccda/repository/impl/AuthRoleApiRefRepository.java create mode 100644 src/main/java/club/joylink/xiannccda/repository/impl/AuthRoleRepository.java create mode 100644 src/main/java/club/joylink/xiannccda/repository/impl/AuthRoleUserRefRepository.java create mode 100644 src/main/java/club/joylink/xiannccda/service/AuthService.java create mode 100644 src/main/resources/mybatis/mapper/AuthRole.xml create mode 100644 src/main/resources/mybatis/mapper/UserMapper.xml diff --git a/src/main/java/club/joylink/xiannccda/controller/RoleAuthController.java b/src/main/java/club/joylink/xiannccda/controller/RoleAuthController.java new file mode 100644 index 0000000..bda1310 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/controller/RoleAuthController.java @@ -0,0 +1,82 @@ +package club.joylink.xiannccda.controller; + +import club.joylink.xiannccda.dto.LoginInfoDTO; +import club.joylink.xiannccda.dto.auth.AuthApiPathQueryDTO; +import club.joylink.xiannccda.dto.auth.AuthRoleDTO; +import club.joylink.xiannccda.dto.auth.AuthRoleQueryDTO; +import club.joylink.xiannccda.dto.record.AlertRecordQueryDTO; +import club.joylink.xiannccda.entity.AlertRecord; +import club.joylink.xiannccda.entity.AuthApiPath; +import club.joylink.xiannccda.entity.AuthApiPath.AuthApi; +import club.joylink.xiannccda.entity.AuthRole; +import club.joylink.xiannccda.entity.User; +import club.joylink.xiannccda.entity.User.Register; +import club.joylink.xiannccda.repository.IAuthApiPathRepository; +import club.joylink.xiannccda.repository.IAuthRoleRepository; +import club.joylink.xiannccda.service.AuthService; +import club.joylink.xiannccda.service.UserService; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +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.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 用户管理接口 + * + * @author walker-sheng + * @since 2023-06-01 + */ +@RestController +@RequestMapping("/api/role") +@Tag(name = "角色权限资源") +public class RoleAuthController { + + private IAuthApiPathRepository authPathRepository; + private IAuthRoleRepository authRoleRepository; + private AuthService authService; + + public RoleAuthController(IAuthApiPathRepository authPathRepository, IAuthRoleRepository authRoleRepository, AuthService authService) { + this.authPathRepository = authPathRepository; + this.authRoleRepository = authRoleRepository; + this.authService = authService; + } + + @GetMapping("/res/page") + @SecurityRequirement(name = "jwt") + @Operation(summary = "分页api资源") + @ApiResponse(description = "api资源") + public Page pageQuery(AuthApiPathQueryDTO queryDTO) { + return authPathRepository.page(queryDTO); + } + + @PostMapping("/res/saveOrUpdate") + @Operation(summary = "保存编辑资源") + @ApiResponse(description = "保存编辑资源") + public void saveOrUpdate(@RequestBody @Validated(AuthApi.class) AuthApiPath apiPath) { + this.authPathRepository.saveOrUpdate(apiPath); + } + + @GetMapping("/role/page") + @SecurityRequirement(name = "jwt") + @Operation(summary = "角色分页") + @ApiResponse(description = "角色分页") + public Page rulePage(AuthRoleQueryDTO queryDTO) { + return this.authRoleRepository.roleApiPage(queryDTO); + + } + + @PostMapping("/role/saveOrUpdate") + @Operation(summary = "角色编辑") + @ApiResponse(description = "角色编辑") + public void roleSaveOrUpdate(@RequestBody AuthRoleDTO dto) { + this.authService.saveOrUpdate(dto); + } + +} diff --git a/src/main/java/club/joylink/xiannccda/controller/UserController.java b/src/main/java/club/joylink/xiannccda/controller/UserController.java index c454e8e..1bd310e 100644 --- a/src/main/java/club/joylink/xiannccda/controller/UserController.java +++ b/src/main/java/club/joylink/xiannccda/controller/UserController.java @@ -1,8 +1,12 @@ package club.joylink.xiannccda.controller; import club.joylink.xiannccda.dto.LoginInfoDTO; +import club.joylink.xiannccda.dto.user.UserDetailDTO; +import club.joylink.xiannccda.dto.user.UserEditDTO; +import club.joylink.xiannccda.dto.user.UserQueryDTO; import club.joylink.xiannccda.entity.User; import club.joylink.xiannccda.entity.User.Register; +import club.joylink.xiannccda.repository.IUserRepository; import club.joylink.xiannccda.service.UserService; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.v3.oas.annotations.Operation; @@ -28,9 +32,11 @@ import org.springframework.web.bind.annotation.RestController; public class UserController { private UserService userService; + private IUserRepository userRepository; - public UserController(UserService userService) { + public UserController(UserService userService, IUserRepository userRepository) { this.userService = userService; + this.userRepository = userRepository; } @PostMapping("/register") @@ -47,12 +53,21 @@ public class UserController { return this.userService.login(loginInfo); } + + @PostMapping("/edit") + @Operation(summary = "用户修改") + @ApiResponse(description = "用户修改") + public void editUser(@RequestBody UserEditDTO dto) { + this.userService.editUser(dto); + } + + @GetMapping("/paging") @SecurityRequirement(name = "jwt") @Operation(summary = "分页查询用户") @ApiResponse(description = "用户列表") - public Page pageQuery() { - return this.userService.pageQuery(); + public Page pageQuery(UserQueryDTO dto) { + return this.userRepository.userRolePage(dto); } } diff --git a/src/main/java/club/joylink/xiannccda/dto/auth/AuthApiPathQueryDTO.java b/src/main/java/club/joylink/xiannccda/dto/auth/AuthApiPathQueryDTO.java new file mode 100644 index 0000000..07cbbee --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/dto/auth/AuthApiPathQueryDTO.java @@ -0,0 +1,10 @@ +package club.joylink.xiannccda.dto.auth; + +import club.joylink.xiannccda.entity.AuthApiPath; +import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO; +import lombok.Data; + +@Data +public class AuthApiPathQueryDTO extends PageDTO { + +} diff --git a/src/main/java/club/joylink/xiannccda/dto/auth/AuthRoleDTO.java b/src/main/java/club/joylink/xiannccda/dto/auth/AuthRoleDTO.java new file mode 100644 index 0000000..b005e41 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/dto/auth/AuthRoleDTO.java @@ -0,0 +1,15 @@ +package club.joylink.xiannccda.dto.auth; + +import club.joylink.xiannccda.entity.AuthRole; +import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO; +import java.util.List; +import lombok.Data; + +@Data +public class AuthRoleDTO { + + private Long id; + private String name; + private List resList; + private String apiIds; +} diff --git a/src/main/java/club/joylink/xiannccda/dto/auth/AuthRoleQueryDTO.java b/src/main/java/club/joylink/xiannccda/dto/auth/AuthRoleQueryDTO.java new file mode 100644 index 0000000..1a40300 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/dto/auth/AuthRoleQueryDTO.java @@ -0,0 +1,11 @@ +package club.joylink.xiannccda.dto.auth; + +import club.joylink.xiannccda.entity.AuthApiPath; +import club.joylink.xiannccda.entity.AuthRole; +import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO; +import lombok.Data; + +@Data +public class AuthRoleQueryDTO extends PageDTO { + +} diff --git a/src/main/java/club/joylink/xiannccda/dto/user/UserDetailDTO.java b/src/main/java/club/joylink/xiannccda/dto/user/UserDetailDTO.java new file mode 100644 index 0000000..445308e --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/dto/user/UserDetailDTO.java @@ -0,0 +1,36 @@ +package club.joylink.xiannccda.dto.user; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.time.LocalDateTime; +import java.util.List; +import lombok.Data; +import lombok.experimental.Accessors; + +@Data +public class UserDetailDTO { + + private Long id; + private String name; + private String mobile; + private LocalDateTime registerTime; + private List roleList; + + @JsonIgnore + private String userRoles; + + @Data + public static class UserRoleDetail { + + public UserRoleDetail() { + + } + + public UserRoleDetail(Long roleId, String roleName) { + this.roleId = roleId; + this.roleName = roleName; + } + + private Long roleId; + private String roleName; + } +} diff --git a/src/main/java/club/joylink/xiannccda/dto/user/UserEditDTO.java b/src/main/java/club/joylink/xiannccda/dto/user/UserEditDTO.java new file mode 100644 index 0000000..db34c72 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/dto/user/UserEditDTO.java @@ -0,0 +1,13 @@ +package club.joylink.xiannccda.dto.user; + +import java.time.LocalDateTime; +import java.util.List; +import lombok.Data; + +@Data +public class UserEditDTO { + + private Long id; + + private List roleList; +} diff --git a/src/main/java/club/joylink/xiannccda/dto/user/UserQueryDTO.java b/src/main/java/club/joylink/xiannccda/dto/user/UserQueryDTO.java new file mode 100644 index 0000000..db06a12 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/dto/user/UserQueryDTO.java @@ -0,0 +1,12 @@ +package club.joylink.xiannccda.dto.user; + +import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; +import club.joylink.xiannccda.entity.AlertRecord; +import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO; +import java.time.LocalDateTime; +import lombok.Data; + +@Data +public class UserQueryDTO extends PageDTO { + +} diff --git a/src/main/java/club/joylink/xiannccda/entity/AuthApiPath.java b/src/main/java/club/joylink/xiannccda/entity/AuthApiPath.java new file mode 100644 index 0000000..917f8ee --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/entity/AuthApiPath.java @@ -0,0 +1,47 @@ +package club.joylink.xiannccda.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +@Getter +@Setter +@Accessors(chain = true) +@TableName("auth_api_path") +@Schema(name = "authApiPath", description = "资源api") +public class AuthApiPath { + + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @Schema(description = "名字") + @NotBlank(message = "名字不能为空", groups = {AuthApi.class}) + private String name; + + @Schema(description = "路径") + @NotBlank(message = "路径不能为空", groups = {AuthApi.class}) + private String path; + + @Schema(description = "method模式") + @NotBlank(message = "method模式不能为空", groups = {AuthApi.class}) + private String method; + + + public static final String ID = "id"; + + public static final String NAME = "name"; + + public static final String PATH = "path"; + + public static final String METHOD = "method"; + + + public interface AuthApi { + + } +} diff --git a/src/main/java/club/joylink/xiannccda/entity/AuthRole.java b/src/main/java/club/joylink/xiannccda/entity/AuthRole.java new file mode 100644 index 0000000..6136e9c --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/entity/AuthRole.java @@ -0,0 +1,30 @@ +package club.joylink.xiannccda.entity; + +import club.joylink.xiannccda.entity.AuthApiPath.AuthApi; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +@TableName("auth_role") +@Schema(name = "authRole", description = "用户角色") +public class AuthRole { + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + @Schema(description = "名字") + @NotBlank(message = "名字不能为空", groups = {AuthApi.class}) + private String name; + + public static final String ID = "id"; + + public static final String NAME = "name"; +} diff --git a/src/main/java/club/joylink/xiannccda/entity/AuthRoleApiPathRef.java b/src/main/java/club/joylink/xiannccda/entity/AuthRoleApiPathRef.java new file mode 100644 index 0000000..05d8302 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/entity/AuthRoleApiPathRef.java @@ -0,0 +1,42 @@ +package club.joylink.xiannccda.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +@TableName("auth_role_api_ref") +@Schema(name = "authRoleApiRef", description = "角色资源关联") +public class AuthRoleApiPathRef { + + public AuthRoleApiPathRef(Long id, Long roleId, Long apiId) { + this.id = id; + this.roleId = roleId; + this.apiId = apiId; + } + + public AuthRoleApiPathRef(Long roleId, Long apiId) { + this.roleId = roleId; + this.apiId = apiId; + } + + public AuthRoleApiPathRef() { + + } + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + @Schema(description = "名字") + private Long roleId; + @Schema(description = "名字") + private Long apiId; + + public static final String ID = "id"; + + public static final String ROLEID = "role_id"; + public static final String APIID = "api_id"; +} diff --git a/src/main/java/club/joylink/xiannccda/entity/AuthRoleUserRef.java b/src/main/java/club/joylink/xiannccda/entity/AuthRoleUserRef.java new file mode 100644 index 0000000..bee6c12 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/entity/AuthRoleUserRef.java @@ -0,0 +1,36 @@ +package club.joylink.xiannccda.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +@TableName("auth_role_user_ref") +@Schema(name = "authRoleUserRef", description = "用户角色关联") +public class AuthRoleUserRef { + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + @Schema(description = "角色id") + private Long roleId; + @Schema(description = "用户id") + private Long userId; + + public AuthRoleUserRef(Long roleId, Long userId) { + this.roleId = roleId; + this.userId = userId; + } + + public AuthRoleUserRef() { + + } + + public static final String ID = "id"; + + public static final String ROLEID = "role_id"; + public static final String APIID = "user_id"; +} diff --git a/src/main/java/club/joylink/xiannccda/mapper/AuthApiPathMapper.java b/src/main/java/club/joylink/xiannccda/mapper/AuthApiPathMapper.java new file mode 100644 index 0000000..f34418d --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/mapper/AuthApiPathMapper.java @@ -0,0 +1,19 @@ +package club.joylink.xiannccda.mapper; + +import club.joylink.xiannccda.entity.AuthApiPath; +import club.joylink.xiannccda.entity.RelieveTimeShere; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author walker-sheng + * @since 2023-10-19 + */ +@Mapper +public interface AuthApiPathMapper extends BaseMapper { + +} diff --git a/src/main/java/club/joylink/xiannccda/mapper/AuthRoleApiRefMapper.java b/src/main/java/club/joylink/xiannccda/mapper/AuthRoleApiRefMapper.java new file mode 100644 index 0000000..69e321b --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/mapper/AuthRoleApiRefMapper.java @@ -0,0 +1,19 @@ +package club.joylink.xiannccda.mapper; + +import club.joylink.xiannccda.entity.AuthRole; +import club.joylink.xiannccda.entity.AuthRoleApiPathRef; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author walker-sheng + * @since 2023-10-19 + */ +@Mapper +public interface AuthRoleApiRefMapper extends BaseMapper { + +} diff --git a/src/main/java/club/joylink/xiannccda/mapper/AuthRoleMapper.java b/src/main/java/club/joylink/xiannccda/mapper/AuthRoleMapper.java new file mode 100644 index 0000000..e273cb5 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/mapper/AuthRoleMapper.java @@ -0,0 +1,23 @@ +package club.joylink.xiannccda.mapper; + +import club.joylink.xiannccda.dto.auth.AuthRoleDTO; +import club.joylink.xiannccda.dto.auth.AuthRoleQueryDTO; +import club.joylink.xiannccda.entity.AuthApiPath; +import club.joylink.xiannccda.entity.AuthRole; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author walker-sheng + * @since 2023-10-19 + */ +@Mapper +public interface AuthRoleMapper extends BaseMapper { + + Page queryRole(AuthRoleQueryDTO dto); +} diff --git a/src/main/java/club/joylink/xiannccda/mapper/AuthRoleUserRefMapper.java b/src/main/java/club/joylink/xiannccda/mapper/AuthRoleUserRefMapper.java new file mode 100644 index 0000000..b803fe2 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/mapper/AuthRoleUserRefMapper.java @@ -0,0 +1,19 @@ +package club.joylink.xiannccda.mapper; + +import club.joylink.xiannccda.entity.AuthRoleApiPathRef; +import club.joylink.xiannccda.entity.AuthRoleUserRef; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author walker-sheng + * @since 2023-10-19 + */ +@Mapper +public interface AuthRoleUserRefMapper extends BaseMapper { + +} diff --git a/src/main/java/club/joylink/xiannccda/mapper/UserMapper.java b/src/main/java/club/joylink/xiannccda/mapper/UserMapper.java index 1c67f76..9995186 100644 --- a/src/main/java/club/joylink/xiannccda/mapper/UserMapper.java +++ b/src/main/java/club/joylink/xiannccda/mapper/UserMapper.java @@ -1,7 +1,10 @@ package club.joylink.xiannccda.mapper; +import club.joylink.xiannccda.dto.user.UserDetailDTO; +import club.joylink.xiannccda.dto.user.UserQueryDTO; import club.joylink.xiannccda.entity.User; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.ibatis.annotations.Mapper; /** @@ -15,4 +18,5 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface UserMapper extends BaseMapper { + Page detailQuery(UserQueryDTO dto); } diff --git a/src/main/java/club/joylink/xiannccda/mapper/xml/UserMapper.xml b/src/main/java/club/joylink/xiannccda/mapper/xml/UserMapper.xml deleted file mode 100644 index e9d708e..0000000 --- a/src/main/java/club/joylink/xiannccda/mapper/xml/UserMapper.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - id, name, mobile, password, register_time - - - diff --git a/src/main/java/club/joylink/xiannccda/repository/IAuthApiPathRepository.java b/src/main/java/club/joylink/xiannccda/repository/IAuthApiPathRepository.java new file mode 100644 index 0000000..145c389 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/repository/IAuthApiPathRepository.java @@ -0,0 +1,21 @@ +package club.joylink.xiannccda.repository; + +import club.joylink.xiannccda.dto.auth.AuthApiPathQueryDTO; +import club.joylink.xiannccda.entity.AuthApiPath; +import club.joylink.xiannccda.entity.User; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 用户 服务类 + *

+ * + * @author walker-sheng + * @since 2023-06-01 + */ +public interface IAuthApiPathRepository extends IService { + + Page page(AuthApiPathQueryDTO dto); + +} diff --git a/src/main/java/club/joylink/xiannccda/repository/IAuthRoleApiRefRepository.java b/src/main/java/club/joylink/xiannccda/repository/IAuthRoleApiRefRepository.java new file mode 100644 index 0000000..4147f87 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/repository/IAuthRoleApiRefRepository.java @@ -0,0 +1,18 @@ +package club.joylink.xiannccda.repository; + +import club.joylink.xiannccda.entity.AuthRole; +import club.joylink.xiannccda.entity.AuthRoleApiPathRef; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 用户 服务类 + *

+ * + * @author walker-sheng + * @since 2023-06-01 + */ +public interface IAuthRoleApiRefRepository extends IService { + + +} diff --git a/src/main/java/club/joylink/xiannccda/repository/IAuthRoleRepository.java b/src/main/java/club/joylink/xiannccda/repository/IAuthRoleRepository.java new file mode 100644 index 0000000..87855be --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/repository/IAuthRoleRepository.java @@ -0,0 +1,22 @@ +package club.joylink.xiannccda.repository; + +import club.joylink.xiannccda.dto.auth.AuthApiPathQueryDTO; +import club.joylink.xiannccda.dto.auth.AuthRoleDTO; +import club.joylink.xiannccda.dto.auth.AuthRoleQueryDTO; +import club.joylink.xiannccda.entity.AuthApiPath; +import club.joylink.xiannccda.entity.AuthRole; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 用户 服务类 + *

+ * + * @author walker-sheng + * @since 2023-06-01 + */ +public interface IAuthRoleRepository extends IService { + + Page roleApiPage(AuthRoleQueryDTO role); +} diff --git a/src/main/java/club/joylink/xiannccda/repository/IAuthRoleUserRefRepository.java b/src/main/java/club/joylink/xiannccda/repository/IAuthRoleUserRefRepository.java new file mode 100644 index 0000000..4cc5d47 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/repository/IAuthRoleUserRefRepository.java @@ -0,0 +1,18 @@ +package club.joylink.xiannccda.repository; + +import club.joylink.xiannccda.entity.AuthRoleApiPathRef; +import club.joylink.xiannccda.entity.AuthRoleUserRef; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 用户 服务类 + *

+ * + * @author walker-sheng + * @since 2023-06-01 + */ +public interface IAuthRoleUserRefRepository extends IService { + + +} diff --git a/src/main/java/club/joylink/xiannccda/repository/IUserRepository.java b/src/main/java/club/joylink/xiannccda/repository/IUserRepository.java index c6c79b0..d7c9f73 100644 --- a/src/main/java/club/joylink/xiannccda/repository/IUserRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/IUserRepository.java @@ -1,6 +1,9 @@ package club.joylink.xiannccda.repository; +import club.joylink.xiannccda.dto.user.UserDetailDTO; +import club.joylink.xiannccda.dto.user.UserQueryDTO; import club.joylink.xiannccda.entity.User; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; /** @@ -13,4 +16,5 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface IUserRepository extends IService { + Page userRolePage(UserQueryDTO dto); } diff --git a/src/main/java/club/joylink/xiannccda/repository/impl/AuthApiPathRepository.java b/src/main/java/club/joylink/xiannccda/repository/impl/AuthApiPathRepository.java new file mode 100644 index 0000000..08fd6f4 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/repository/impl/AuthApiPathRepository.java @@ -0,0 +1,30 @@ +package club.joylink.xiannccda.repository.impl; + +import club.joylink.xiannccda.dto.auth.AuthApiPathQueryDTO; +import club.joylink.xiannccda.entity.AlertRecord; +import club.joylink.xiannccda.entity.AuthApiPath; +import club.joylink.xiannccda.mapper.AuthApiPathMapper; +import club.joylink.xiannccda.repository.IAuthApiPathRepository; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 用户 服务类 + *

+ * + * @author walker-sheng + * @since 2023-06-01 + */ +@Service +public class AuthApiPathRepository extends ServiceImpl implements IAuthApiPathRepository { + + @Override + public Page page(AuthApiPathQueryDTO dto) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(AuthApiPath.class); + return this.page(dto, queryWrapper); + } +} diff --git a/src/main/java/club/joylink/xiannccda/repository/impl/AuthRoleApiRefRepository.java b/src/main/java/club/joylink/xiannccda/repository/impl/AuthRoleApiRefRepository.java new file mode 100644 index 0000000..5877a99 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/repository/impl/AuthRoleApiRefRepository.java @@ -0,0 +1,23 @@ +package club.joylink.xiannccda.repository.impl; + +import club.joylink.xiannccda.entity.AuthRole; +import club.joylink.xiannccda.entity.AuthRoleApiPathRef; +import club.joylink.xiannccda.mapper.AuthRoleApiRefMapper; +import club.joylink.xiannccda.mapper.AuthRoleMapper; +import club.joylink.xiannccda.repository.IAuthRoleApiRefRepository; +import club.joylink.xiannccda.repository.IAuthRoleRepository; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 用户 服务类 + *

+ * + * @author walker-sheng + * @since 2023-06-01 + */ +@Service +public class AuthRoleApiRefRepository extends ServiceImpl implements IAuthRoleApiRefRepository { + +} diff --git a/src/main/java/club/joylink/xiannccda/repository/impl/AuthRoleRepository.java b/src/main/java/club/joylink/xiannccda/repository/impl/AuthRoleRepository.java new file mode 100644 index 0000000..a9a0843 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/repository/impl/AuthRoleRepository.java @@ -0,0 +1,38 @@ +package club.joylink.xiannccda.repository.impl; + +import club.joylink.xiannccda.dto.auth.AuthRoleDTO; +import club.joylink.xiannccda.dto.auth.AuthRoleQueryDTO; +import club.joylink.xiannccda.entity.AuthRole; +import club.joylink.xiannccda.mapper.AuthRoleMapper; +import club.joylink.xiannccda.repository.IAuthRoleRepository; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import java.util.Arrays; +import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +/** + *

+ * 用户 服务类 + *

+ * + * @author walker-sheng + * @since 2023-06-01 + */ +@Service +public class AuthRoleRepository extends ServiceImpl implements IAuthRoleRepository { + + @Override + public Page roleApiPage(AuthRoleQueryDTO role) { + Page page = this.baseMapper.queryRole(role); + page.getRecords().forEach(d -> { + if (StringUtils.isNotEmpty(d.getApiIds())) { + List refList = Arrays.stream(d.getApiIds().split(",")).map(Long::valueOf).toList(); + d.setResList(refList); + d.setApiIds(null); + } + }); + return page; + } +} diff --git a/src/main/java/club/joylink/xiannccda/repository/impl/AuthRoleUserRefRepository.java b/src/main/java/club/joylink/xiannccda/repository/impl/AuthRoleUserRefRepository.java new file mode 100644 index 0000000..c663065 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/repository/impl/AuthRoleUserRefRepository.java @@ -0,0 +1,23 @@ +package club.joylink.xiannccda.repository.impl; + +import club.joylink.xiannccda.entity.AuthRoleApiPathRef; +import club.joylink.xiannccda.entity.AuthRoleUserRef; +import club.joylink.xiannccda.mapper.AuthRoleApiRefMapper; +import club.joylink.xiannccda.mapper.AuthRoleUserRefMapper; +import club.joylink.xiannccda.repository.IAuthRoleApiRefRepository; +import club.joylink.xiannccda.repository.IAuthRoleUserRefRepository; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 用户 服务类 + *

+ * + * @author walker-sheng + * @since 2023-06-01 + */ +@Service +public class AuthRoleUserRefRepository extends ServiceImpl implements IAuthRoleUserRefRepository { + +} diff --git a/src/main/java/club/joylink/xiannccda/repository/impl/UserRepository.java b/src/main/java/club/joylink/xiannccda/repository/impl/UserRepository.java index 75aaa7c..2e04f7e 100644 --- a/src/main/java/club/joylink/xiannccda/repository/impl/UserRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/impl/UserRepository.java @@ -1,9 +1,17 @@ package club.joylink.xiannccda.repository.impl; +import club.joylink.xiannccda.dto.user.UserDetailDTO; +import club.joylink.xiannccda.dto.user.UserDetailDTO.UserRoleDetail; +import club.joylink.xiannccda.dto.user.UserQueryDTO; import club.joylink.xiannccda.entity.User; import club.joylink.xiannccda.mapper.UserMapper; import club.joylink.xiannccda.repository.IUserRepository; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.google.common.collect.Lists; +import java.util.Arrays; +import java.util.List; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; /** @@ -17,4 +25,18 @@ import org.springframework.stereotype.Service; @Service public class UserRepository extends ServiceImpl implements IUserRepository { + @Override + public Page userRolePage(UserQueryDTO dto) { + Page page = this.baseMapper.detailQuery(dto); + for (UserDetailDTO record : page.getRecords()) { + List userRoleList = Lists.newArrayList(); + Arrays.stream(StringUtils.split(record.getUserRoles(), ',')).forEach(d -> { + String[] idName = StringUtils.split(d, '|'); + userRoleList.add(new UserRoleDetail(Long.valueOf(idName[0]), idName[1])); + }); + record.setRoleList(userRoleList); + record.setUserRoles(null); + } + return page; + } } diff --git a/src/main/java/club/joylink/xiannccda/service/AuthService.java b/src/main/java/club/joylink/xiannccda/service/AuthService.java new file mode 100644 index 0000000..a74a73f --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/service/AuthService.java @@ -0,0 +1,67 @@ +package club.joylink.xiannccda.service; + +import club.joylink.xiannccda.dto.LoginInfoDTO; +import club.joylink.xiannccda.dto.auth.AuthRoleDTO; +import club.joylink.xiannccda.entity.AuthRole; +import club.joylink.xiannccda.entity.AuthRoleApiPathRef; +import club.joylink.xiannccda.entity.User; +import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum; +import club.joylink.xiannccda.repository.IAuthApiPathRepository; +import club.joylink.xiannccda.repository.IAuthRoleApiRefRepository; +import club.joylink.xiannccda.repository.IAuthRoleRepository; +import club.joylink.xiannccda.repository.IUserRepository; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO; +import java.time.Instant; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import org.springframework.security.oauth2.jwt.JwtClaimsSet; +import org.springframework.security.oauth2.jwt.JwtEncoder; +import org.springframework.security.oauth2.jwt.JwtEncoderParameters; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class AuthService { + + IAuthRoleRepository authRoleRepository; + IAuthRoleApiRefRepository authRoleApiRefRepository; + + public AuthService(IAuthRoleRepository authRoleRepository, IAuthRoleApiRefRepository authRoleApiRefRepository) { + this.authRoleRepository = authRoleRepository; + this.authRoleApiRefRepository = authRoleApiRefRepository; + } + + @Transactional + public void saveOrUpdate(AuthRoleDTO dto) { + if (Objects.isNull(dto.getId())) { + AuthRole r = new AuthRole(); + r.setName(dto.getName()); + this.authRoleRepository.save(r); + this.batchSave(dto.getResList(), dto.getId()); + } else { + AuthRole r = this.authRoleRepository.getById(dto.getId()); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(r)); + r.setName(dto.getName()); + this.authRoleRepository.updateById(r); + this.batchSave(dto.getResList(), dto.getId()); + } + } + + private void batchSave(List apiList, Long roleId) { + if (Objects.nonNull(roleId)) { + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(AuthRoleApiPathRef.class); + wrapper.eq(AuthRoleApiPathRef::getRoleId, roleId); + this.authRoleApiRefRepository.remove(wrapper); + } + if (CollectionUtils.isNotEmpty(apiList)) { + List refList = apiList.stream().map(d -> new AuthRoleApiPathRef(roleId, d)).collect(Collectors.toList()); + this.authRoleApiRefRepository.saveBatch(refList); + } + } +} diff --git a/src/main/java/club/joylink/xiannccda/service/UserService.java b/src/main/java/club/joylink/xiannccda/service/UserService.java index a897094..7a892d2 100644 --- a/src/main/java/club/joylink/xiannccda/service/UserService.java +++ b/src/main/java/club/joylink/xiannccda/service/UserService.java @@ -1,28 +1,39 @@ package club.joylink.xiannccda.service; import club.joylink.xiannccda.dto.LoginInfoDTO; +import club.joylink.xiannccda.dto.user.UserEditDTO; +import club.joylink.xiannccda.dto.user.UserQueryDTO; +import club.joylink.xiannccda.entity.AuthRoleUserRef; import club.joylink.xiannccda.entity.User; import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum; +import club.joylink.xiannccda.repository.IAuthRoleUserRefRepository; import club.joylink.xiannccda.repository.IUserRepository; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO; import java.time.Instant; import java.time.LocalDateTime; +import java.util.List; +import java.util.Objects; import org.springframework.security.oauth2.jwt.JwtClaimsSet; import org.springframework.security.oauth2.jwt.JwtEncoder; import org.springframework.security.oauth2.jwt.JwtEncoderParameters; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service public class UserService { final IUserRepository userRepository; final JwtEncoder jwtEncoder; + final IAuthRoleUserRefRepository authRoleUserRefRepository; - public UserService(IUserRepository userRepository, JwtEncoder jwtEncoder) { + public UserService(IUserRepository userRepository, JwtEncoder jwtEncoder, IAuthRoleUserRefRepository authRoleUserRefRepository) { this.userRepository = userRepository; this.jwtEncoder = jwtEncoder; + this.authRoleUserRefRepository = authRoleUserRefRepository; } public String register(User user) { @@ -55,9 +66,16 @@ public class UserService { return token; } - public Page pageQuery() { - Page page = PageDTO.of(1, 10); - Page userPage = this.userRepository.page(page, Wrappers.lambdaQuery()); - return userPage; + @Transactional + public void editUser(UserEditDTO dto) { + User user = this.userRepository.getById(dto.getId()); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(user)); + LambdaQueryWrapper q = Wrappers.lambdaQuery(AuthRoleUserRef.class); + q.eq(AuthRoleUserRef::getUserId, dto.getId()); + this.authRoleUserRefRepository.remove(q); + if (CollectionUtils.isNotEmpty(dto.getRoleList())) { + List refList = dto.getRoleList().stream().map(d -> new AuthRoleUserRef(d, dto.getId())).toList(); + this.authRoleUserRefRepository.saveBatch(refList); + } } } diff --git a/src/main/resources/mybatis/mapper/AuthRole.xml b/src/main/resources/mybatis/mapper/AuthRole.xml new file mode 100644 index 0000000..b4281e2 --- /dev/null +++ b/src/main/resources/mybatis/mapper/AuthRole.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + id + , name + + + diff --git a/src/main/resources/mybatis/mapper/UserMapper.xml b/src/main/resources/mybatis/mapper/UserMapper.xml new file mode 100644 index 0000000..7ce3f08 --- /dev/null +++ b/src/main/resources/mybatis/mapper/UserMapper.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + id + , name, mobile, password, register_time + + + diff --git a/src/test/java/club/joylink/xiannccda/protocal/x/BigDataReq.java b/src/test/java/club/joylink/xiannccda/protocal/x/BigDataReq.java index f813074..4ec621c 100644 --- a/src/test/java/club/joylink/xiannccda/protocal/x/BigDataReq.java +++ b/src/test/java/club/joylink/xiannccda/protocal/x/BigDataReq.java @@ -48,7 +48,7 @@ public class BigDataReq extends MessageRequest { *

* 实际数据 发送 0 = 开始,1=传输中,2=结束 */ - private ScheduleSubIdType subId = ScheduleSubIdType.RUNING; + private ScheduleSubIdType subId = ScheduleSubIdType.HISTORY_RUN; /** * 表号(9) */