feat(database): 重构用户角色关联及权限体系
- 新增 BizException 构造函数支持自定义消息 - 优化 SQL 脚本结构,明确表设计最佳实践 - 修改 t_user、t_role 等表字段类型与索引策略 - 引入代理主键 id 到关联表 t_user_role 和 t_role_permission - 更新 UserRole 实体类适配 MyBatis-Plus 主键策略 - 增强 UserRoleService 接口功能,支持分配和撤销角色 - 实现批量操作和事务控制提升数据一致性 - 添加安全注解 @PreAuthorize 控制接口访问权限 - 修正 Mapper 注解并优化参数命名提高可读性 - 扩展 ErrorCode 常量增强错误描述准确性
This commit is contained in:
@@ -32,12 +32,13 @@ public interface UserMapper extends BaseMapper<User> {
|
||||
|
||||
/**
|
||||
* 插入用户角色关系
|
||||
* @param id 用户id
|
||||
* @param i 角色id
|
||||
* 注意:已将注解由 @Select 修正为 @Insert,并优化了参数命名。
|
||||
* 由于 t_user_role 现在有自增主键 id,只需插入 user_id 和 role_id。
|
||||
* @param userId 用户id
|
||||
* @param roleId 角色id
|
||||
*/
|
||||
|
||||
@Select("INSERT INTO t_user_role (user_id, role_id) VALUES (#{userId}, #{roleId})")
|
||||
void insertUserRole(@Param("userId") Long id, @Param("roleId") Long i);
|
||||
@Insert("INSERT INTO t_user_role (user_id, role_id) VALUES (#{userId}, #{roleId})")
|
||||
void insertUserRole(@Param("userId") Long userId, @Param("roleId") Long roleId);
|
||||
|
||||
/**
|
||||
* 根据用户名查询用户信息
|
||||
@@ -97,4 +98,4 @@ public interface UserMapper extends BaseMapper<User> {
|
||||
many = @Many(select = "findRolesByUserId"))
|
||||
})
|
||||
User findUserWithRolesByUsername(String username);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,17 @@ package cn.nopj.chaos_api.mapper;
|
||||
|
||||
import cn.nopj.chaos_api.domain.entity.UserRole;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@Mapper
|
||||
public interface UserRoleMapper extends BaseMapper<UserRole> {
|
||||
/**
|
||||
* 删除用户角色关系
|
||||
* @param userId 用户id
|
||||
* @param roleId 角色id
|
||||
*/
|
||||
@Delete("DELETE FROM t_user_role WHERE user_id = #{userId} AND role_id = #{roleId}")
|
||||
int delete(@Param("userId") Long userId,@Param("roleId") Long roleId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user