Skip to content
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

Open
wants to merge 1 commit into
base: refactor
Choose a base branch
from

Conversation

GLaxky
Copy link

@GLaxky GLaxky commented Feb 7, 2023

重构了部分用户权限,用户所在科研组的代码

@GLaxky GLaxky requested a review from lilingj February 7, 2023 07:02
* @param uid
* @return
*/
@GetMapping("/user/permission")
Copy link
Member

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){
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一个用户可以属于多个权限组,一个权限组有多个权限,用户应该有所属组的所有权限。这里应该是list

Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    • 两边加空格
  1. userId * 10000 + permissionId是不是好一点

private int teamId;

@Override
public boolean equals(Object obj){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码相似,可以考虑

  1. 抽取代码,使用设计模式设计一下(模版方法啥的)
  2. 我不知道JPA里有联合主键这个概念,有的话可以考虑单独新建一个包,专门放这种类,增加代码可读性

* @param userId
* @return 所有权限名
*/
public List<String> getPermissionNames(int userId){
Copy link
Member

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里去,不用写这些混乱的东西。

Copy link
Member

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`
Copy link
Member

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可能好一点,这个会把原有数据删掉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants