提交
@@ -1,5 +1,4 @@
|
||||
package com.tashow.cloud.controller;
|
||||
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.oauth2.config.SaOAuth2ServerConfig;
|
||||
import cn.dev33.satoken.oauth2.consts.GrantType;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
package com.tashow.cloud.controller;
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.sso.config.SaSsoServerConfig;
|
||||
import cn.dev33.satoken.sso.processor.SaSsoServerProcessor;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.tashow.cloud.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.tashow.cloud.model.SystemRole;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 系统角色Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemRoleMapper extends BaseMapper<SystemRole> {
|
||||
|
||||
}
|
||||
@@ -3,9 +3,6 @@ package com.tashow.cloud.mapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.tashow.cloud.model.SystemUser;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统用户Mapper接口
|
||||
@@ -13,34 +10,4 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface SystemUserMapper extends BaseMapper<SystemUser> {
|
||||
|
||||
/**
|
||||
* 获取用户角色ID列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 角色ID列表
|
||||
*/
|
||||
@Select("SELECT role_id FROM system_user_role WHERE user_id = #{userId} AND deleted = 0")
|
||||
List<Long> selectUserRoleIds(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户角色名称列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 角色名称列表
|
||||
*/
|
||||
@Select("SELECT r.name FROM system_role r " +
|
||||
"JOIN system_user_role ur ON r.id = ur.role_id " +
|
||||
"WHERE ur.user_id = #{userId} AND r.deleted = 0 AND ur.deleted = 0 AND r.status = 0")
|
||||
List<String> selectUserRoleNames(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户角色编码列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 角色编码列表
|
||||
*/
|
||||
@Select("SELECT r.code FROM system_role r " +
|
||||
"JOIN system_user_role ur ON r.id = ur.role_id " +
|
||||
"WHERE ur.user_id = #{userId} AND r.deleted = 0 AND ur.deleted = 0 AND r.status = 0")
|
||||
List<String> selectUserRoleCodes(@Param("userId") Long userId);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.tashow.cloud.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.tashow.cloud.model.SystemUserRole;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 系统用户角色关联Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemUserRoleMapper extends BaseMapper<SystemUserRole> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.tashow.cloud.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 系统角色实体类
|
||||
*/
|
||||
@Data
|
||||
@TableName("system_role")
|
||||
public class SystemRole {
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 角色权限字符串
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 显示顺序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)
|
||||
*/
|
||||
private Integer dataScope;
|
||||
|
||||
/**
|
||||
* 数据范围(指定部门数组)
|
||||
*/
|
||||
private String dataScopeDeptIds;
|
||||
|
||||
/**
|
||||
* 角色状态(0正常 1停用)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 角色类型
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private String creator;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
private String updater;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
@TableLogic
|
||||
private Boolean deleted;
|
||||
|
||||
/**
|
||||
* 租户编号
|
||||
*/
|
||||
private Long tenantId;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.tashow.cloud.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 用户角色关联实体类
|
||||
*/
|
||||
@Data
|
||||
@TableName("system_user_role")
|
||||
public class SystemUserRole {
|
||||
/**
|
||||
* 自增编号
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private String creator;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
private String updater;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
@TableLogic
|
||||
private Boolean deleted;
|
||||
|
||||
/**
|
||||
* 租户编号
|
||||
*/
|
||||
private Long tenantId;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.tashow.cloud.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.tashow.cloud.model.SystemRole;
|
||||
|
||||
/**
|
||||
* 系统角色服务接口
|
||||
*/
|
||||
public interface SystemRoleService extends IService<SystemRole> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.tashow.cloud.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.tashow.cloud.model.SystemUserRole;
|
||||
|
||||
/**
|
||||
* 系统用户角色关联服务接口
|
||||
*/
|
||||
public interface SystemUserRoleService extends IService<SystemUserRole> {
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.tashow.cloud.service;
|
||||
|
||||
import com.tashow.cloud.model.SystemUser;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统用户服务接口
|
||||
@@ -55,4 +56,28 @@ public interface SystemUserService {
|
||||
* @return 加密后的密码
|
||||
*/
|
||||
String encodePassword(String rawPassword);
|
||||
|
||||
/**
|
||||
* 获取用户角色ID列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 角色ID列表
|
||||
*/
|
||||
List<Long> getUserRoleIds(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户角色名称列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 角色名称列表
|
||||
*/
|
||||
List<String> getUserRoleNames(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户角色编码列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 角色编码列表
|
||||
*/
|
||||
List<String> getUserRoleCodes(Long userId);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.tashow.cloud.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.tashow.cloud.mapper.SystemRoleMapper;
|
||||
import com.tashow.cloud.model.SystemRole;
|
||||
import com.tashow.cloud.service.SystemRoleService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 系统角色服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class SystemRoleServiceImpl extends ServiceImpl<SystemRoleMapper, SystemRole> implements SystemRoleService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.tashow.cloud.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.tashow.cloud.mapper.SystemUserRoleMapper;
|
||||
import com.tashow.cloud.model.SystemUserRole;
|
||||
import com.tashow.cloud.service.SystemUserRoleService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 系统用户角色关联服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class SystemUserRoleServiceImpl extends ServiceImpl<SystemUserRoleMapper, SystemUserRole> implements SystemUserRoleService {
|
||||
|
||||
}
|
||||
@@ -3,12 +3,19 @@ package com.tashow.cloud.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.tashow.cloud.mapper.SystemUserMapper;
|
||||
import com.tashow.cloud.model.SystemRole;
|
||||
import com.tashow.cloud.model.SystemUser;
|
||||
import com.tashow.cloud.model.SystemUserRole;
|
||||
import com.tashow.cloud.service.SystemRoleService;
|
||||
import com.tashow.cloud.service.SystemUserRoleService;
|
||||
import com.tashow.cloud.service.SystemUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 系统用户服务实现类
|
||||
@@ -18,6 +25,12 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
|
||||
|
||||
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
|
||||
@Autowired
|
||||
private SystemRoleService systemRoleService;
|
||||
|
||||
@Autowired
|
||||
private SystemUserRoleService systemUserRoleService;
|
||||
|
||||
@Override
|
||||
public SystemUser getUserByUsername(String username) {
|
||||
return getOne(new LambdaQueryWrapper<SystemUser>()
|
||||
@@ -33,7 +46,9 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
|
||||
|
||||
@Override
|
||||
public SystemUser getUserById(Long userId) {
|
||||
return getById(userId);
|
||||
return getOne(new LambdaQueryWrapper<SystemUser>()
|
||||
.eq(SystemUser::getId, userId)
|
||||
.eq(SystemUser::getDeleted, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,8 +93,15 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
|
||||
* @param userId 用户ID
|
||||
* @return 角色ID列表
|
||||
*/
|
||||
@Override
|
||||
public List<Long> getUserRoleIds(Long userId) {
|
||||
return baseMapper.selectUserRoleIds(userId);
|
||||
List<SystemUserRole> userRoles = systemUserRoleService.list(new LambdaQueryWrapper<SystemUserRole>()
|
||||
.eq(SystemUserRole::getUserId, userId)
|
||||
.eq(SystemUserRole::getDeleted, false));
|
||||
|
||||
return userRoles.stream()
|
||||
.map(SystemUserRole::getRoleId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,8 +110,23 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
|
||||
* @param userId 用户ID
|
||||
* @return 角色名称列表
|
||||
*/
|
||||
@Override
|
||||
public List<String> getUserRoleNames(Long userId) {
|
||||
return baseMapper.selectUserRoleNames(userId);
|
||||
// 先获取用户角色ID列表
|
||||
List<Long> roleIds = getUserRoleIds(userId);
|
||||
if (roleIds.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 再查询角色名称
|
||||
List<SystemRole> roles = systemRoleService.list(new LambdaQueryWrapper<SystemRole>()
|
||||
.in(SystemRole::getId, roleIds)
|
||||
.eq(SystemRole::getStatus, 0)
|
||||
.eq(SystemRole::getDeleted, false));
|
||||
|
||||
return roles.stream()
|
||||
.map(SystemRole::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +135,22 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
|
||||
* @param userId 用户ID
|
||||
* @return 角色编码列表
|
||||
*/
|
||||
@Override
|
||||
public List<String> getUserRoleCodes(Long userId) {
|
||||
return baseMapper.selectUserRoleCodes(userId);
|
||||
// 先获取用户角色ID列表
|
||||
List<Long> roleIds = getUserRoleIds(userId);
|
||||
if (roleIds.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 再查询角色编码
|
||||
List<SystemRole> roles = systemRoleService.list(new LambdaQueryWrapper<SystemRole>()
|
||||
.in(SystemRole::getId, roleIds)
|
||||
.eq(SystemRole::getStatus, 0)
|
||||
.eq(SystemRole::getDeleted, false));
|
||||
|
||||
return roles.stream()
|
||||
.map(SystemRole::getCode)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
server:
|
||||
port: 48082
|
||||
port: 48083
|
||||
spring:
|
||||
application:
|
||||
name: sso-server
|
||||
|
||||
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 0 B |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 0 B |
@@ -6,6 +6,7 @@ import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.util.SaResult;
|
||||
import com.tashow.cloud.model.SystemRole;
|
||||
import com.tashow.cloud.service.SystemRoleService;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
@@ -159,10 +160,10 @@ public class RoleController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取启用状态的角色列表(可用于下拉选择)
|
||||
* 获取启用状态的角色列表
|
||||
*/
|
||||
@GetMapping("/options")
|
||||
@SaIgnore
|
||||
@PermitAll
|
||||
public SaResult getRoleOptions() {
|
||||
try {
|
||||
List<SystemRole> roles = roleService.getRolesByStatus(0); // 0表示正常状态
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.tashow.cloud.tashowmoduleuserbiz.security.config;
|
||||
|
||||
import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||
import cn.dev33.satoken.router.SaRouter;
|
||||
import cn.dev33.satoken.sso.SaSsoProcessor;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
@@ -11,34 +9,15 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
/**
|
||||
* Sa-Token 配置类
|
||||
*/
|
||||
@Configuration
|
||||
//@Configuration
|
||||
public class SaTokenConfigure implements WebMvcConfigurer {
|
||||
|
||||
/**
|
||||
/* *//**
|
||||
* 注册Sa-Token拦截器,打开注解式鉴权功能
|
||||
*/
|
||||
*//*
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
// 注册路由拦截器,自定义认证规则
|
||||
registry.addInterceptor(new SaInterceptor(handler -> {
|
||||
// 登录认证 -- 排除登录接口外,其他接口需要登录才能访问
|
||||
SaRouter.match("/**")
|
||||
.notMatch("/user/doLogin")
|
||||
.notMatch("/sso/*")
|
||||
.notMatch("/oauth2/*")
|
||||
.check(r -> StpUtil.checkLogin());
|
||||
})).addPathPatterns("/**");
|
||||
}
|
||||
|
||||
/**
|
||||
* SSO-Client端:处理所有SSO相关请求
|
||||
* 配置此函数后,可在客户端端通过以下方式完成单点登录功能:
|
||||
* http://{host}:{port}/sso/login —— Client端登录地址,接受参数:back=登录后的跳转地址
|
||||
* http://{host}:{port}/sso/logout —— Client端单点注销地址(isSlo=true时打开),接受参数:back=注销后的跳转地址
|
||||
* http://{host}:{port}/sso/logoutCall —— Client端单点注销回调地址(isSlo=true时打开),此接口为框架回调,开发者无需关心
|
||||
*/
|
||||
public void ssoClientDister() {
|
||||
// 处理SSO相关请求
|
||||
SaSsoProcessor.instance.clientDister();
|
||||
}
|
||||
// 注册 Sa-Token 拦截器,打开注解式鉴权功能
|
||||
registry.addInterceptor(new SaInterceptor()).addPathPatterns("/**");
|
||||
}*/
|
||||
}
|
||||
@@ -25,7 +25,7 @@ public class SecurityConfiguration {
|
||||
.requestMatchers("/webjars/**").permitAll()
|
||||
.requestMatchers("/swagger-ui").permitAll()
|
||||
.requestMatchers("/swagger-ui/**").permitAll()
|
||||
;
|
||||
.requestMatchers("/test").permitAll() ;
|
||||
// Druid 监控
|
||||
registry.requestMatchers("/druid/**").permitAll();
|
||||
// Spring Boot Actuator 的安全配置
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
package com.tashow.cloud.user.convert;
|
||||
|
||||
import com.tashow.cloud.user.model.Role;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 角色对象转换器
|
||||
*/
|
||||
@Mapper
|
||||
public interface RoleConvert {
|
||||
|
||||
RoleConvert INSTANCE = Mappers.getMapper(RoleConvert.class);
|
||||
|
||||
/**
|
||||
* 将角色列表转换为角色ID列表
|
||||
*
|
||||
* @param roles 角色列表
|
||||
* @return 角色ID列表
|
||||
*/
|
||||
default List<Long> convertToRoleIds(List<Role> roles) {
|
||||
if (roles == null || roles.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return roles.stream()
|
||||
.map(Role::getId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将角色列表转换为角色名称列表
|
||||
*
|
||||
* @param roles 角色列表
|
||||
* @return 角色名称列表
|
||||
*/
|
||||
default List<String> convertToRoleNames(List<Role> roles) {
|
||||
if (roles == null || roles.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return roles.stream()
|
||||
.map(Role::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将角色列表转换为角色编码列表
|
||||
*
|
||||
* @param roles 角色列表
|
||||
* @return 角色编码列表
|
||||
*/
|
||||
default List<String> convertToRoleCodes(List<Role> roles) {
|
||||
if (roles == null || roles.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return roles.stream()
|
||||
.map(Role::getCode)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
package com.tashow.cloud.user.convert;
|
||||
|
||||
import com.tashow.cloud.user.dto.UserCreateReqDTO;
|
||||
import com.tashow.cloud.user.dto.UserRegisterReqDTO;
|
||||
import com.tashow.cloud.user.dto.UserRespDTO;
|
||||
import com.tashow.cloud.user.dto.UserUpdateReqDTO;
|
||||
import com.tashow.cloud.user.model.User;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户对象转换器
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserConvert {
|
||||
|
||||
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
|
||||
|
||||
/**
|
||||
* 用户创建请求DTO转实体
|
||||
*/
|
||||
@Mapping(target = "roles", ignore = true)
|
||||
@Mapping(target = "createTime", ignore = true)
|
||||
@Mapping(target = "updateTime", ignore = true)
|
||||
@Mapping(target = "loginDate", ignore = true)
|
||||
@Mapping(target = "deleted", ignore = true)
|
||||
@Mapping(target = "loginIp", ignore = true)
|
||||
@Mapping(target = "postIds", expression = "java(postIdsToString(bean.getPostIds()))")
|
||||
User convert(UserCreateReqDTO bean);
|
||||
|
||||
/**
|
||||
* 用户更新请求DTO转实体
|
||||
*/
|
||||
@Mapping(target = "roles", ignore = true)
|
||||
@Mapping(target = "username", ignore = true)
|
||||
@Mapping(target = "password", ignore = true)
|
||||
@Mapping(target = "createTime", ignore = true)
|
||||
@Mapping(target = "updateTime", ignore = true)
|
||||
@Mapping(target = "loginDate", ignore = true)
|
||||
@Mapping(target = "deleted", ignore = true)
|
||||
@Mapping(target = "loginIp", ignore = true)
|
||||
@Mapping(target = "postIds", expression = "java(postIdsToString(bean.getPostIds()))")
|
||||
User convert(UserUpdateReqDTO bean);
|
||||
|
||||
/**
|
||||
* 用户注册请求DTO转实体
|
||||
*/
|
||||
@Mapping(target = "roles", ignore = true)
|
||||
@Mapping(target = "id", ignore = true)
|
||||
@Mapping(target = "createTime", ignore = true)
|
||||
@Mapping(target = "updateTime", ignore = true)
|
||||
@Mapping(target = "loginDate", ignore = true)
|
||||
@Mapping(target = "deleted", ignore = true)
|
||||
@Mapping(target = "deptId", ignore = true)
|
||||
@Mapping(target = "postIds", ignore = true)
|
||||
@Mapping(target = "sex", ignore = true)
|
||||
@Mapping(target = "creator", ignore = true)
|
||||
@Mapping(target = "updater", ignore = true)
|
||||
@Mapping(target = "tenantId", ignore = true)
|
||||
@Mapping(target = "remark", ignore = true)
|
||||
@Mapping(target = "status", constant = "0")
|
||||
User convert(UserRegisterReqDTO bean);
|
||||
|
||||
/**
|
||||
* 用户实体转响应DTO
|
||||
*/
|
||||
@Mapping(target = "sexName", expression = "java(getSexName(bean.getSex()))")
|
||||
@Mapping(target = "statusName", expression = "java(getStatusName(bean.getStatus()))")
|
||||
@Mapping(target = "roleIds", ignore = true)
|
||||
@Mapping(target = "roleNames", ignore = true)
|
||||
@Mapping(target = "roleCodes", ignore = true)
|
||||
@Mapping(target = "postIds", expression = "java(stringToPostIds(bean.getPostIds()))")
|
||||
@Mapping(target = "postNames", ignore = true)
|
||||
@Mapping(target = "deptName", ignore = true)
|
||||
UserRespDTO convert(User bean);
|
||||
|
||||
/**
|
||||
* 用户实体列表转响应DTO列表
|
||||
*/
|
||||
List<UserRespDTO> convertList(List<User> list);
|
||||
|
||||
/**
|
||||
* 岗位ID列表转字符串
|
||||
*/
|
||||
default String postIdsToString(List<Long> postIds) {
|
||||
if (postIds == null || postIds.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return postIds.stream()
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转岗位ID列表
|
||||
*/
|
||||
default List<Long> stringToPostIds(String postIds) {
|
||||
if (postIds == null || postIds.isEmpty()) {
|
||||
return java.util.Collections.emptyList();
|
||||
}
|
||||
return java.util.Arrays.stream(postIds.split(","))
|
||||
.map(Long::valueOf)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取性别名称
|
||||
*/
|
||||
default String getSexName(Integer sex) {
|
||||
if (sex == null) {
|
||||
return null;
|
||||
}
|
||||
return switch (sex) {
|
||||
case 1 -> "男";
|
||||
case 2 -> "女";
|
||||
default -> "未知";
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态名称
|
||||
*/
|
||||
default String getStatusName(Integer status) {
|
||||
if (status == null) {
|
||||
return null;
|
||||
}
|
||||
return switch (status) {
|
||||
case 0 -> "正常";
|
||||
case 1 -> "停用";
|
||||
default -> "未知";
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
/**
|
||||
* 用户中心模块业务层实现
|
||||
*
|
||||
* <p>此模块包含以下主要组件:
|
||||
* <ul>
|
||||
* <li>controller - 控制器层,负责接收和响应HTTP请求</li>
|
||||
* <li>service - 服务实现层,实现业务逻辑</li>
|
||||
* <li>mapper - 数据访问层,与数据库交互</li>
|
||||
* <li>convert - 对象转换层,负责DTO和实体间的转换</li>
|
||||
* <li>config - 配置类</li>
|
||||
* </ul>
|
||||
*/
|
||||
package com.tashow.cloud.user;
|
||||
@@ -1,33 +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="com.tashow.cloud.tashowmoduleuserbiz.mapper.SystemRoleMenuMapper">
|
||||
|
||||
<!-- 根据角色ID列表获取菜单ID列表 -->
|
||||
<select id="selectMenuIdsByRoleIds" resultType="java.lang.Long">
|
||||
SELECT DISTINCT menu_id
|
||||
FROM system_role_menu
|
||||
WHERE role_id IN
|
||||
<foreach collection="roleIds" item="roleId" open="(" separator="," close=")">
|
||||
#{roleId}
|
||||
</foreach>
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- 根据角色ID删除角色菜单关联 -->
|
||||
<update id="deleteByRoleId">
|
||||
UPDATE system_role_menu
|
||||
SET deleted = 1,
|
||||
update_time = NOW()
|
||||
WHERE role_id = #{roleId}
|
||||
AND deleted = 0
|
||||
</update>
|
||||
|
||||
<insert id="batchInsert">
|
||||
INSERT INTO system_role_menu (role_id, menu_id, creator, create_time, updater, update_time, deleted, tenant_id)
|
||||
VALUES
|
||||
<foreach collection="menuIds" item="menuId" separator=",">
|
||||
(#{roleId}, #{menuId}, #{creator}, NOW(), #{creator}, NOW(), 0, 0)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
@@ -1,23 +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="com.tashow.cloud.tashowmoduleuserbiz.mapper.SystemUserPostMapper">
|
||||
|
||||
<!-- 根据用户ID删除用户岗位关联 -->
|
||||
<update id="deleteByUserId">
|
||||
UPDATE system_user_post
|
||||
SET deleted = 1,
|
||||
update_time = NOW()
|
||||
WHERE user_id = #{userId}
|
||||
AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- 批量插入用户岗位关联 -->
|
||||
<insert id="batchInsert">
|
||||
INSERT INTO system_user_post (user_id, post_id, creator, create_time, updater, update_time, deleted, tenant_id)
|
||||
VALUES
|
||||
<foreach collection="postIds" item="postId" separator=",">
|
||||
(#{userId}, #{postId}, #{creator}, NOW(), #{creator}, NOW(), 0, 0)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
@@ -1,23 +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="com.tashow.cloud.tashowmoduleuserbiz.mapper.SystemUserRoleMapper">
|
||||
|
||||
<!-- 根据用户ID删除用户角色关联 -->
|
||||
<update id="deleteByUserId">
|
||||
UPDATE system_user_role
|
||||
SET deleted = 1,
|
||||
update_time = NOW()
|
||||
WHERE user_id = #{userId}
|
||||
AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- 批量插入用户角色关联 -->
|
||||
<insert id="batchInsert">
|
||||
INSERT INTO system_user_role (user_id, role_id, creator, create_time, updater, update_time, deleted, tenant_id)
|
||||
VALUES
|
||||
<foreach collection="roleIds" item="roleId" separator=",">
|
||||
(#{userId}, #{roleId}, #{creator}, NOW(), #{creator}, NOW(), 0, 0)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||