-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: 用户权限、身份、组关系重构 #129
base: refactor
Are you sure you want to change the base?
Conversation
* @param uid | ||
* @return | ||
*/ | ||
@GetMapping("/user/permission") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加个统一前缀“/api/v2”
* @return | ||
*/ | ||
@GetMapping("/user/permission") | ||
public List<String> getPermissions(@RequestAttribute int uid){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
写一个通用返回类CommonResult,所有返回值都用这个类包裹
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private int id; | ||
|
||
private String name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加个描述字段description
/** | ||
* 用户权限id(代替authority) | ||
*/ | ||
private int permissionId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一个用户可以属于多个权限组,一个权限组有多个权限,用户应该有所属组的所有权限。这里应该是list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
另:设置一层直接对应数据库表的对象,比如UserPo,PermissionPo,mapper层负责直接增删改查这些对象,repo层调用mapper层读取Po对象,将Po对象转换组装成Entity,提供给service使用,或者将Entity拆散成Po,调用mapper层写入。
|
||
@Override | ||
public int hashCode(){ | ||
return userId+permissionId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
- 两边加空格
- userId * 10000 + permissionId是不是好一点
private int teamId; | ||
|
||
@Override | ||
public boolean equals(Object obj){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码相似,可以考虑
- 抽取代码,使用设计模式设计一下(模版方法啥的)
- 我不知道JPA里有联合主键这个概念,有的话可以考虑单独新建一个包,专门放这种类,增加代码可读性
* @param userId | ||
* @return 所有权限名 | ||
*/ | ||
public List<String> getPermissionNames(int userId){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
像上面说的,可以分离PO对象和Entity对象,Repository层使用Po组装Entity时,就可以把权限对象转换成枚举,放到Entity里去,不用写这些混乱的东西。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用枚举代替String,String缺少语意,且含混不清,到底是用名字,还是用id?不如从repo中出来的时候就统一转换成枚举
|
||
#-------------------- 用户模块新增的表 -----------------------# | ||
drop table if exists team; | ||
create table `team` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用create table if not esists team
可能好一点,这个会把原有数据删掉
重构了部分用户权限,用户所在科研组的代码