This commit is contained in:
2025-04-22 15:23:13 +08:00
parent e731ef8bcd
commit 01671a3ed2
57 changed files with 326 additions and 362 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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;
/**
* 系统用户服务实现类
@@ -17,6 +24,12 @@ import java.util.List;
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser> implements SystemUserService {
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
@Autowired
private SystemRoleService systemRoleService;
@Autowired
private SystemUserRoleService systemUserRoleService;
@Override
public SystemUser getUserByUsername(String username) {
@@ -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());
}
}

View File

@@ -1,5 +1,5 @@
server:
port: 48082
port: 48083
spring:
application:
name: sso-server

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 0 B