项目背景
在SAAS管理端,前端使用Vue3,后端采用Java相关技术栈,以下所展示的数据结构仅作为参考,具体在项目实践中还需根据实际情况进行优化使用。以下数据结构已对后期的Client Site权限分配做了扩展准备,针对SAAS客户端,可做功能以及Api功能的权限隔离。
数据结构-表结构
设计数据结构的念想:允许冗余,扩展查询。
在用户、角色数据结构中冗余组织/部门数据字段,是为了快速关联关系,同时减少了组织/部门的映射关系表。
- 功能/菜单
public class FunctionDO {
@TableId(value = "id", type = IdType.AUTO)
private Int id;
@ApiModelProperty(value = "菜单名称")
private String name;
@ApiModelProperty(value = "类型 1-一级菜单 2-菜单子项 3-按钮 4-接口权限")
private Int type;
@ApiModelProperty(value = "前端-路由路径")
private String path;
@ApiModelProperty(value = "接口地址")
private String apiPath;
@ApiModelProperty(value = "前端-组件地址")
private String component;
@ApiModelProperty(value = "图标")
private String icon;
@ApiModelProperty(value = "权限标识")
private String permission;
@ApiModelProperty(value = "排序")
private Int sort;
@ApiModelProperty(value = "显示状态 1-启用 false 2-隐藏 true")
private Int hidden;
@ApiModelProperty(value = "1-开启缓存 true 2-关闭 false")
private Int keepAlive;
@ApiModelProperty(value = "父级id")
private Int parentId;
@ApiModelProperty(value = "默认为0,若此字段为0,则属于全局功能/菜单,否则为部门/机构独有功能")
private Int deptId;
private LocalDateTime createTime;
private LocalDateTime updateTime;
}
- 系统用户表
public class UserDO {
@TableId(value = "id", type = IdType.AUTO)
private Int id;
@ApiModelProperty(value = "登录账号name")
private String loginName;
@ApiModelProperty(value = "登录密码")
private String password;
@ApiModelProperty(value = "用户昵称")
private String nickName;
//该字段是为了快速实现系统功能,后期允许一个用户关联多个部门/组织,使用String替换,"1003,3001"
@ApiModelProperty(value = "所属组织/部门id")
private Int deptId;
@ApiModelProperty(value = "完整的部门id,deptId|deptId|...")
private String entireDeptId;
private LocalDateTime createTime;
private LocalDateTime updateTime;
}
- 角色
public class RoleDO {
@TableId(value = "id", type = IdType.AUTO)
private Int id;
@ApiModelProperty(value = "角色名称")
private String name;
@ApiModelProperty(value = "角色编码")
private String code;
@ApiModelProperty(value = "排序")
private Int sort;
@ApiModelProperty(value = "启用状态 1-启用 2-禁用 3-逻辑删除")
private Int status;
//存在部门/组织专属的角色
@ApiModelProperty(value = "所属组织/部门id")
private Int deptId;
private LocalDateTime createTime;
private LocalDateTime updateTime;
}
- 组织/部门
public class DeptDO {
@TableId(value = "id", type = IdType.AUTO)
private Int id;
@ApiModelProperty(value = "组织/部门名称")
private String name;
@ApiModelProperty(value = "父级组织/部门id")
private Int parentId;
@ApiModelProperty(value = "排序")
private Int sort;
@ApiModelProperty(value = "组织/部门状态 1-正常 2-禁用")
private Int status;
private LocalDateTime createTime;
private LocalDateTime updateTime;
}
- 功能-角色关系表
public class RolesFunctionsDO {
@TableId(value = "id", type = IdType.AUTO)
private Int id;
private Int roleId;
private Int functionId;
private LocalDateTime createTime;
private LocalDateTime updateTime;
}
- 用户-角色关系表
public class UsersRolesDO {
@TableId(value = "id", type = IdType.AUTO)
private Int id;
private Int userId;
private Int roleId;
private LocalDateTime createTime;
private LocalDateTime updateTime;
}
关联关系
DeptDO与FunctionDO:
FunctionDO中的deptId与DeptDO的id相关联,表示功能所属的部门。
RoleDO与FunctionDO:
通过RolesFunctionsDO建立多对多关系,一个角色可以拥有多个功能,一个功能也可以被多个角色拥有。
UserDO与RoleDO:
通过UsersRolesDO建立多对多关系,一个用户可以拥有多个角色,一个角色也可以被多个用户拥有。