-
Notifications
You must be signed in to change notification settings - Fork 40
refactor: 用户权限、身份、组关系重构 #129
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
base: refactor
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,6 @@ public class UserController { | |
| UserService userService; | ||
| @Autowired | ||
| NotifyService notifyService; | ||
|
|
||
| @Autowired | ||
| BaseApi baseApi; | ||
|
|
||
|
|
@@ -131,5 +130,24 @@ public void downloadLeaseContract(@RequestAttribute int uid, HttpServletResponse | |
| userService.downloadContractFile(uid,response); | ||
| } | ||
|
|
||
| /** | ||
| * @author LiXiaoKang | ||
| * @description 新增获取用户权限与所属组信息 | ||
| * @create 1/10/2020 8:38 PM | ||
| */ | ||
|
|
||
| /** | ||
| * 获取用户权限信息 | ||
| * @param uid | ||
| * @return | ||
| */ | ||
| @GetMapping("/user/permission") | ||
| public List<String> getPermissions(@RequestAttribute int uid){ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 写一个通用返回类CommonResult,所有返回值都用这个类包裹 |
||
| return userService.getPermissionNames(uid); | ||
| } | ||
|
|
||
| @GetMapping("/user/team") | ||
| public List<String> getTeams(@RequestAttribute int uid){ | ||
| return userService.getTeams(uid); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.softeng.dingtalk.entity; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import lombok.ToString; | ||
|
|
||
| import javax.persistence.Entity; | ||
| import javax.persistence.GeneratedValue; | ||
| import javax.persistence.GenerationType; | ||
| import javax.persistence.Id; | ||
|
|
||
| /** | ||
| * @author LiXiaoKang | ||
| * @description 用户权限类 | ||
| * @date 02/02/2023 | ||
| */ | ||
| @Getter | ||
| @Setter | ||
| @Entity | ||
| @NoArgsConstructor | ||
| @ToString | ||
| public class Permission { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private int id; | ||
|
|
||
| private String name; | ||
|
|
||
| private String description; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.softeng.dingtalk.entity; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import lombok.ToString; | ||
|
|
||
| import javax.persistence.Entity; | ||
| import javax.persistence.GeneratedValue; | ||
| import javax.persistence.GenerationType; | ||
| import javax.persistence.Id; | ||
|
|
||
| /** | ||
| * @author LiXiaoKang | ||
| * @description 用户组实体类 | ||
| * @date 02/02/2023 | ||
| */ | ||
| @Getter | ||
| @Setter | ||
| @Entity | ||
| @NoArgsConstructor | ||
| @ToString | ||
| public class Team { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private int id; | ||
|
|
||
| private String name; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 加个描述字段description |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,6 +159,17 @@ public class User { | |
| @OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE) | ||
| private List<Prize> allPrizes; | ||
|
|
||
| /** | ||
| * @author LiXiaoKang | ||
| * @description todo-用户权限重构 | ||
| * @date 2/3/2023 | ||
| */ | ||
|
|
||
| /** | ||
| * 用户权限id(代替authority) | ||
| */ | ||
| private int permissionId; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 一个用户可以属于多个权限组,一个权限组有多个权限,用户应该有所属组的所有权限。这里应该是list
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 另:设置一层直接对应数据库表的对象,比如UserPo,PermissionPo,mapper层负责直接增删改查这些对象,repo层调用mapper层读取Po对象,将Po对象转换组装成Entity,提供给service使用,或者将Entity拆散成Po,调用mapper层写入。 |
||
|
|
||
|
|
||
| public User(String userid, String unionid, String name, String avatar, int authority, Position position) { | ||
| this.userid = userid; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.softeng.dingtalk.entity; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import lombok.ToString; | ||
|
|
||
| import javax.persistence.Entity; | ||
| import javax.persistence.Id; | ||
| import javax.persistence.IdClass; | ||
|
|
||
| /** | ||
| * @author LiXiaoKang | ||
| * @description 用户-用户权限实体类 | ||
| * @date 02/02/2023 | ||
| */ | ||
| @Getter | ||
| @Setter | ||
| @Entity | ||
| @NoArgsConstructor | ||
| @ToString | ||
| // 设置联合主键的注解 | ||
| @IdClass(UserPermissionAssociatePK.class) | ||
| public class UserPermission { | ||
|
|
||
| @Id | ||
| private int userId; | ||
|
|
||
| @Id | ||
| private int permissionId; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.softeng.dingtalk.entity; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import lombok.ToString; | ||
|
|
||
| import java.io.Serializable; | ||
|
|
||
| /** | ||
| * @author LiXiaoKang | ||
| * @description 用户-权限实体类的联合主键 | ||
| * @date 02/02/2023 | ||
| */ | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @ToString | ||
| public class UserPermissionAssociatePK implements Serializable { | ||
|
|
||
| private int userId; | ||
|
|
||
| private int permissionId; | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj){ | ||
| if(obj instanceof UserPermissionAssociatePK){ | ||
| return userId == ((UserPermissionAssociatePK) obj).userId && permissionId == ((UserPermissionAssociatePK) obj).getPermissionId(); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode(){ | ||
| return userId+permissionId; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.softeng.dingtalk.entity; | ||
|
|
||
|
|
||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import lombok.ToString; | ||
|
|
||
| import javax.persistence.Entity; | ||
| import javax.persistence.Id; | ||
| import javax.persistence.IdClass; | ||
|
|
||
| /** | ||
| * @author LiXiaoKang | ||
| * @description 用户组实体类 | ||
| * @date 02/02/2023 | ||
| */ | ||
| @Getter | ||
| @Setter | ||
| @Entity | ||
| @NoArgsConstructor | ||
| @ToString | ||
| // 设置联合主键的注解 | ||
| @IdClass(UserTeamAssociatePK.class) | ||
| public class UserTeam { | ||
|
|
||
| @Id | ||
| private int userId; | ||
|
|
||
| @Id | ||
| private int teamId; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.softeng.dingtalk.entity; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import lombok.ToString; | ||
|
|
||
| import java.io.Serializable; | ||
|
|
||
| /** | ||
| * @author LiXiaoKang | ||
| * @description 用户-用户组实体类的联合主键 | ||
| * @date 02/02/2023 | ||
| */ | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @ToString | ||
| public class UserTeamAssociatePK implements Serializable { | ||
|
|
||
| private int userId; | ||
|
|
||
| private int teamId; | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj){ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 代码相似,可以考虑
|
||
| if(obj instanceof UserTeamAssociatePK){ | ||
| return userId == ((UserTeamAssociatePK) obj).userId && teamId == ((UserTeamAssociatePK) obj).getTeamId(); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode(){ | ||
| return userId+teamId; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.softeng.dingtalk.repository; | ||
|
|
||
| import com.softeng.dingtalk.entity.Permission; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| /** | ||
| * @author LiXiaoKang | ||
| * @description 操作Permission实体类的接口 | ||
| * @date 2/5/2023 | ||
| */ | ||
|
|
||
| @Repository | ||
| public interface PermissionRepository extends CustomizedRepository<Permission, Integer>{ | ||
|
|
||
| Permission findById(int id); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.softeng.dingtalk.repository; | ||
|
|
||
| import com.softeng.dingtalk.entity.Team; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| /** | ||
| * @author LiXiaoKang | ||
| * @description 操作Team实体类的接口 | ||
| * @date 2/5/2023 | ||
| */ | ||
|
|
||
| @Repository | ||
| public interface TeamRepository extends CustomizedRepository<Team, Integer>{ | ||
| Team findById(int id); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package com.softeng.dingtalk.repository; | ||
|
|
||
| import com.softeng.dingtalk.entity.UserPermission; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * @author LiXiaoKang | ||
| * @description 操作UserPermission实体类的接口 | ||
| * @date 2/5/2023 | ||
| */ | ||
|
|
||
| @Repository | ||
| public interface UserPermissionRepository extends CustomizedRepository<UserPermission, UserPermissionRepository>{ | ||
|
|
||
| /** | ||
| * 获取用户的所有权限 | ||
| * @param userId 用户id | ||
| * @return 用户所有权限 | ||
| */ | ||
| List<UserPermission> findAllByUserId(int userId); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.softeng.dingtalk.repository; | ||
|
|
||
| import com.softeng.dingtalk.entity.UserTeam; | ||
| import com.softeng.dingtalk.entity.UserTeamAssociatePK; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * @author LiXiaoKang | ||
| * @description 操作UserTeam实体类的接口 | ||
| * @date 2/5/2023 | ||
| */ | ||
|
|
||
| @Repository | ||
| public interface UserTeamRepository extends CustomizedRepository<UserTeam, UserTeamAssociatePK>{ | ||
|
|
||
| /** | ||
| * 获取用户所在的所有用户组 | ||
| * @param userId 用户id | ||
| * @return 用户所在的所有用户组 | ||
| */ | ||
| List<UserTeam> findAllByUserId(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.
加个统一前缀“/api/v2”