资源,角色,角色绑定资源,用户绑定角色
Some checks failed
local-test分支构建docker并发布运行 / Docker-Build (push) Has been cancelled

This commit is contained in:
tiger_zhou 2024-09-05 16:25:28 +08:00
parent 8867818832
commit f25a536d55
33 changed files with 796 additions and 28 deletions

View File

@ -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<AuthApiPath> 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<AuthRoleDTO> 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);
}
}

View File

@ -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<User> pageQuery() {
return this.userService.pageQuery();
public Page<UserDetailDTO> pageQuery(UserQueryDTO dto) {
return this.userRepository.userRolePage(dto);
}
}

View File

@ -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<AuthApiPath> {
}

View File

@ -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<Long> resList;
private String apiIds;
}

View File

@ -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<AuthRole> {
}

View File

@ -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<UserRoleDetail> 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;
}
}

View File

@ -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<Long> roleList;
}

View File

@ -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<UserQueryDTO> {
}

View File

@ -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 {
}
}

View File

@ -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";
}

View File

@ -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";
}

View File

@ -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";
}

View File

@ -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;
/**
* <p>
* Mapper 接口
* </p>
*
* @author walker-sheng
* @since 2023-10-19
*/
@Mapper
public interface AuthApiPathMapper extends BaseMapper<AuthApiPath> {
}

View File

@ -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;
/**
* <p>
* Mapper 接口
* </p>
*
* @author walker-sheng
* @since 2023-10-19
*/
@Mapper
public interface AuthRoleApiRefMapper extends BaseMapper<AuthRoleApiPathRef> {
}

View File

@ -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;
/**
* <p>
* Mapper 接口
* </p>
*
* @author walker-sheng
* @since 2023-10-19
*/
@Mapper
public interface AuthRoleMapper extends BaseMapper<AuthRole> {
Page<AuthRoleDTO> queryRole(AuthRoleQueryDTO dto);
}

View File

@ -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;
/**
* <p>
* Mapper 接口
* </p>
*
* @author walker-sheng
* @since 2023-10-19
*/
@Mapper
public interface AuthRoleUserRefMapper extends BaseMapper<AuthRoleUserRef> {
}

View File

@ -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<User> {
Page<UserDetailDTO> detailQuery(UserQueryDTO dto);
}

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="club.joylink.xiannccda.mapper.UserMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="club.joylink.xiannccda.entity.User">
<id column="id" property="id" />
<result column="name" property="name" />
<result column="mobile" property="mobile" />
<result column="password" property="password" />
<result column="register_time" property="registerTime" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, name, mobile, password, register_time
</sql>
</mapper>

View File

@ -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;
/**
* <p>
* 用户 服务类
* </p>
*
* @author walker-sheng
* @since 2023-06-01
*/
public interface IAuthApiPathRepository extends IService<AuthApiPath> {
Page<AuthApiPath> page(AuthApiPathQueryDTO dto);
}

View File

@ -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;
/**
* <p>
* 用户 服务类
* </p>
*
* @author walker-sheng
* @since 2023-06-01
*/
public interface IAuthRoleApiRefRepository extends IService<AuthRoleApiPathRef> {
}

View File

@ -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;
/**
* <p>
* 用户 服务类
* </p>
*
* @author walker-sheng
* @since 2023-06-01
*/
public interface IAuthRoleRepository extends IService<AuthRole> {
Page<AuthRoleDTO> roleApiPage(AuthRoleQueryDTO role);
}

View File

@ -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;
/**
* <p>
* 用户 服务类
* </p>
*
* @author walker-sheng
* @since 2023-06-01
*/
public interface IAuthRoleUserRefRepository extends IService<AuthRoleUserRef> {
}

View File

@ -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<User> {
Page<UserDetailDTO> userRolePage(UserQueryDTO dto);
}

View File

@ -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;
/**
* <p>
* 用户 服务类
* </p>
*
* @author walker-sheng
* @since 2023-06-01
*/
@Service
public class AuthApiPathRepository extends ServiceImpl<AuthApiPathMapper, AuthApiPath> implements IAuthApiPathRepository {
@Override
public Page<AuthApiPath> page(AuthApiPathQueryDTO dto) {
LambdaQueryWrapper<AuthApiPath> queryWrapper = Wrappers.lambdaQuery(AuthApiPath.class);
return this.page(dto, queryWrapper);
}
}

View File

@ -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;
/**
* <p>
* 用户 服务类
* </p>
*
* @author walker-sheng
* @since 2023-06-01
*/
@Service
public class AuthRoleApiRefRepository extends ServiceImpl<AuthRoleApiRefMapper, AuthRoleApiPathRef> implements IAuthRoleApiRefRepository {
}

View File

@ -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;
/**
* <p>
* 用户 服务类
* </p>
*
* @author walker-sheng
* @since 2023-06-01
*/
@Service
public class AuthRoleRepository extends ServiceImpl<AuthRoleMapper, AuthRole> implements IAuthRoleRepository {
@Override
public Page<AuthRoleDTO> roleApiPage(AuthRoleQueryDTO role) {
Page<AuthRoleDTO> page = this.baseMapper.queryRole(role);
page.getRecords().forEach(d -> {
if (StringUtils.isNotEmpty(d.getApiIds())) {
List<Long> refList = Arrays.stream(d.getApiIds().split(",")).map(Long::valueOf).toList();
d.setResList(refList);
d.setApiIds(null);
}
});
return page;
}
}

View File

@ -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;
/**
* <p>
* 用户 服务类
* </p>
*
* @author walker-sheng
* @since 2023-06-01
*/
@Service
public class AuthRoleUserRefRepository extends ServiceImpl<AuthRoleUserRefMapper, AuthRoleUserRef> implements IAuthRoleUserRefRepository {
}

View File

@ -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<UserMapper, User> implements IUserRepository {
@Override
public Page<UserDetailDTO> userRolePage(UserQueryDTO dto) {
Page<UserDetailDTO> page = this.baseMapper.detailQuery(dto);
for (UserDetailDTO record : page.getRecords()) {
List<UserRoleDetail> 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;
}
}

View File

@ -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<Long> apiList, Long roleId) {
if (Objects.nonNull(roleId)) {
LambdaQueryWrapper<AuthRoleApiPathRef> wrapper = Wrappers.lambdaQuery(AuthRoleApiPathRef.class);
wrapper.eq(AuthRoleApiPathRef::getRoleId, roleId);
this.authRoleApiRefRepository.remove(wrapper);
}
if (CollectionUtils.isNotEmpty(apiList)) {
List<AuthRoleApiPathRef> refList = apiList.stream().map(d -> new AuthRoleApiPathRef(roleId, d)).collect(Collectors.toList());
this.authRoleApiRefRepository.saveBatch(refList);
}
}
}

View File

@ -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<User> pageQuery() {
Page<User> page = PageDTO.of(1, 10);
Page<User> 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<AuthRoleUserRef> q = Wrappers.lambdaQuery(AuthRoleUserRef.class);
q.eq(AuthRoleUserRef::getUserId, dto.getId());
this.authRoleUserRefRepository.remove(q);
if (CollectionUtils.isNotEmpty(dto.getRoleList())) {
List<AuthRoleUserRef> refList = dto.getRoleList().stream().map(d -> new AuthRoleUserRef(d, dto.getId())).toList();
this.authRoleUserRefRepository.saveBatch(refList);
}
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="club.joylink.xiannccda.mapper.AuthRoleMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="club.joylink.xiannccda.entity.AuthRole">
<id column="id" property="id"/>
<result column="name" property="name"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id
, name
</sql>
<select id="queryRole" resultType="club.joylink.xiannccda.dto.auth.AuthRoleDTO">
select a.id, A.name, B.api_ids
from auth_role A
left join (select role_id, group_concat(api_id) as api_ids from auth_role_api_ref GROUP BY role_id) B
on A.id = B.role_id
</select>
</mapper>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="club.joylink.xiannccda.mapper.UserMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="club.joylink.xiannccda.entity.User">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="mobile" property="mobile"/>
<result column="password" property="password"/>
<result column="register_time" property="registerTime"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id
, name, mobile, password, register_time
</sql>
<select id="detailQuery" resultType="club.joylink.xiannccda.dto.user.UserDetailDTO">
select A.id, A.name, A.mobile, A.register_time, B.user_roles
from user A
left join (select A.user_id, GROUP_CONCAT(A.role_id, '|', B.`name`) as user_roles
from auth_role_user_ref A
left join auth_role B on A.role_id = B.id
GROUP BY user_id) B
on A.id = B.user_id
where 1 = 1
</select>
</mapper>

View File

@ -48,7 +48,7 @@ public class BigDataReq extends MessageRequest {
* <p>
* 实际数据 发送 0 = 开始1=传输中2=结束
*/
private ScheduleSubIdType subId = ScheduleSubIdType.RUNING;
private ScheduleSubIdType subId = ScheduleSubIdType.HISTORY_RUN;
/**
* 表号(9)
*/