From 7ce6421b66e941b89ae67d4bde3f92ba19ab0e1a Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Fri, 21 May 2021 10:47:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=83=E9=99=90=E7=AE=A1=E7=90=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/20210519-zhangsai.sql | 5 + .../PermissionDistributeController.java | 9 +- .../rtss/controller/user/UserController.java | 7 + .../user/UserPermissionController.java | 49 ++++-- .../joylink/rtss/dao/UserPermissionDAO.java | 5 +- .../rtss/entity/PermissionDistribute.java | 17 +- .../entity/PermissionDistributeExample.java | 62 ++++++- .../joylink/rtss/entity/UserPermission.java | 23 ++- .../rtss/entity/UserPermissionExample.java | 106 +++++++++--- .../IPermissionDistributeService.java | 29 +++- .../rtss/services/IPermissionService.java | 2 + .../rtss/services/ISysUserService.java | 5 + .../rtss/services/IUserPermissionService.java | 32 +++- .../services/PermissionDistributeService.java | 162 +++++++++++------- .../rtss/services/PermissionService.java | 6 +- .../joylink/rtss/services/SysUserService.java | 10 ++ .../rtss/services/UserPermissionService.java | 117 ++++++++++--- .../permission/UserPermissionQueryVO.java | 19 ++ .../permissionDistribute/DistributeVO.java | 17 +- .../PermissionDistributeQueryVO.java | 15 +- .../PermissionDistributeVO.java | 11 +- .../userPermission/UserPermissionVO.java | 15 +- .../mapper/PermissionDistributeDAO.xml | 99 ++++++----- .../mybatis/mapper/UserPermissionDAO.xml | 69 +++++--- 24 files changed, 655 insertions(+), 236 deletions(-) create mode 100644 sql/20210519-zhangsai.sql create mode 100644 src/main/java/club/joylink/rtss/vo/client/permission/UserPermissionQueryVO.java diff --git a/sql/20210519-zhangsai.sql b/sql/20210519-zhangsai.sql new file mode 100644 index 000000000..293568296 --- /dev/null +++ b/sql/20210519-zhangsai.sql @@ -0,0 +1,5 @@ +ALTER TABLE `permission_distribute` +ADD COLUMN `creator_id` bigint NULL AFTER `from_user_permission_id`; + +alter table user_permission + add create_time datetime default current_timestamp not null; diff --git a/src/main/java/club/joylink/rtss/controller/permission/PermissionDistributeController.java b/src/main/java/club/joylink/rtss/controller/permission/PermissionDistributeController.java index 53b11aa3e..16e3fe3b8 100644 --- a/src/main/java/club/joylink/rtss/controller/permission/PermissionDistributeController.java +++ b/src/main/java/club/joylink/rtss/controller/permission/PermissionDistributeController.java @@ -91,7 +91,7 @@ public class PermissionDistributeController { @ApiOperation(value = "回收权限分发到用户权限中") @PutMapping(path = "/{id}/restore") public void restore(@PathVariable Long id) { - this.permissionDistributeService.restoreDistributeToUserPermission(id); + this.permissionDistributeService.return2UserPermission(id); } @ApiOperation(value = "查询权限分发包详情") @@ -108,4 +108,11 @@ public class PermissionDistributeController { return permissionDistributeService.createAllMapDistribute(project, num, user); } + @Role(RoleEnum.SuperAdmin) + @ApiOperation("收回从该权限分发获取的用户权限") + @PutMapping("/{id}/back") + public void takeBack(@PathVariable Long id) { + permissionDistributeService.takeBack(id); + } + } diff --git a/src/main/java/club/joylink/rtss/controller/user/UserController.java b/src/main/java/club/joylink/rtss/controller/user/UserController.java index 29d55079e..def50bce4 100644 --- a/src/main/java/club/joylink/rtss/controller/user/UserController.java +++ b/src/main/java/club/joylink/rtss/controller/user/UserController.java @@ -107,4 +107,11 @@ public class UserController { public List querySellers(){ return iSysUserService.querySellers(); } + + @Role({RoleEnum.Admin, RoleEnum.SuperAdmin}) + @ApiOperation("查询管理和超管") + @GetMapping("/adminAndSuperAdmin") + public List queryAdminsAndSuperAdmins() { + return iSysUserService.queryAdminsAndSuperAdmins(); + } } diff --git a/src/main/java/club/joylink/rtss/controller/user/UserPermissionController.java b/src/main/java/club/joylink/rtss/controller/user/UserPermissionController.java index cfd04c4f6..587f6e65a 100644 --- a/src/main/java/club/joylink/rtss/controller/user/UserPermissionController.java +++ b/src/main/java/club/joylink/rtss/controller/user/UserPermissionController.java @@ -1,14 +1,18 @@ package club.joylink.rtss.controller.user; +import club.joylink.rtss.constants.RoleEnum; +import club.joylink.rtss.controller.advice.Role; import club.joylink.rtss.services.IUserPermissionService; import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.permission.DistributeSelectVO; import club.joylink.rtss.vo.client.permission.PermissionQueryVO; +import club.joylink.rtss.vo.client.permission.UserPermissionQueryVO; import club.joylink.rtss.vo.client.userPermission.UserPermissionVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; @@ -58,19 +62,12 @@ public class UserPermissionController { return iUserPermissionService.userPermissionStatistic(queryVO); } - @ApiOperation(value = "用户权限转增归属") - @GetMapping(path = "/gotUserList") - public PageVO distributeTo(PermissionQueryVO queryVO) { - return iUserPermissionService.distributeTo(queryVO); - } +// @ApiOperation(value = "用户权限转增归属") +// @GetMapping(path = "/gotUserList") +// public PageVO distributeTo(PermissionQueryVO queryVO) { +// return iUserPermissionService.distributeTo(queryVO); +// } - @ApiOperation(value = "回收用户权限到权限分发中") - @PutMapping(path = "/{id}/back") - public void restorePermissionToDistribute(@PathVariable Long id) { - iUserPermissionService.restorePermissionToDistribute(id); - } - - @ApiOperation(value = "") @GetMapping(path = "/personal") public List queryPersonalUserPermission(@RequestAttribute @ApiIgnore UserVO user) { return iUserPermissionService.queryPersonalUserPermission(user); @@ -82,4 +79,32 @@ public class UserPermissionController { iUserPermissionService.getPermissions4Map(mapId, count, user); } + @Role({RoleEnum.Admin, RoleEnum.SuperAdmin}) + @ApiOperation(value = "将用户权限退回到权限分发中") + @PutMapping(path = "/{id}/back") + public void return2Distribute(@PathVariable Long id) { + iUserPermissionService.return2Distribute(id); + } + + @Role({RoleEnum.Admin, RoleEnum.SuperAdmin}) + @ApiOperation("将用户权限(专用)退回到用户权限中") + @PutMapping("/{id}/back/up") + public void return2UserPermission(@PathVariable Long id) { + iUserPermissionService.return2UserPermission(id); + } + + @Role({RoleEnum.Admin, RoleEnum.SuperAdmin}) + @ApiOperation("查询从该用户权限流向的用户权限") + @GetMapping("/ups/fromThisUP") + public PageVO queryUPsFromThisUP(@Validated UserPermissionQueryVO queryVO) { + return iUserPermissionService.queryUPsFromThisUP(queryVO); + } + + @Role({RoleEnum.Admin, RoleEnum.SuperAdmin}) + @ApiOperation("收回从该用户权限流出的所有权限(权限分发及用户权限)") + @PutMapping("/{id}/takeBack/all") + public void takeBackAll(@PathVariable long id) { + iUserPermissionService.takeBack(id); + } + } diff --git a/src/main/java/club/joylink/rtss/dao/UserPermissionDAO.java b/src/main/java/club/joylink/rtss/dao/UserPermissionDAO.java index 5969fa595..c4d0244cd 100644 --- a/src/main/java/club/joylink/rtss/dao/UserPermissionDAO.java +++ b/src/main/java/club/joylink/rtss/dao/UserPermissionDAO.java @@ -33,7 +33,8 @@ public interface UserPermissionDAO extends MyBatisBaseDao", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdGreaterThan(Long value) { + addCriterion("creator_id >", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdGreaterThanOrEqualTo(Long value) { + addCriterion("creator_id >=", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdLessThan(Long value) { + addCriterion("creator_id <", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdLessThanOrEqualTo(Long value) { + addCriterion("creator_id <=", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdIn(List values) { + addCriterion("creator_id in", values, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdNotIn(List values) { + addCriterion("creator_id not in", values, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdBetween(Long value1, Long value2) { + addCriterion("creator_id between", value1, value2, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdNotBetween(Long value1, Long value2) { + addCriterion("creator_id not between", value1, value2, "creatorId"); + return (Criteria) this; + } + public Criteria andCreateTimeIsNull() { addCriterion("create_time is null"); return (Criteria) this; @@ -1330,4 +1390,4 @@ public class PermissionDistributeExample { this(condition, value, secondValue, null); } } -} \ No newline at end of file +} diff --git a/src/main/java/club/joylink/rtss/entity/UserPermission.java b/src/main/java/club/joylink/rtss/entity/UserPermission.java index b1c13d74d..2e306eac6 100644 --- a/src/main/java/club/joylink/rtss/entity/UserPermission.java +++ b/src/main/java/club/joylink/rtss/entity/UserPermission.java @@ -4,8 +4,8 @@ import java.io.Serializable; import java.time.LocalDateTime; /** - * user_permission * @author + * 用户拥有权限 */ public class UserPermission implements Serializable { private Long id; @@ -62,6 +62,8 @@ public class UserPermission implements Serializable { */ private Long ownerId; + private LocalDateTime createTime; + private static final long serialVersionUID = 1L; public Long getId() { @@ -160,6 +162,14 @@ public class UserPermission implements Serializable { this.ownerId = ownerId; } + public LocalDateTime getCreateTime() { + return createTime; + } + + public void setCreateTime(LocalDateTime createTime) { + this.createTime = createTime; + } + @Override public boolean equals(Object that) { if (this == that) { @@ -183,7 +193,8 @@ public class UserPermission implements Serializable { && (this.getEndTime() == null ? other.getEndTime() == null : this.getEndTime().equals(other.getEndTime())) && (this.getDistributeId() == null ? other.getDistributeId() == null : this.getDistributeId().equals(other.getDistributeId())) && (this.getCanDistribute() == null ? other.getCanDistribute() == null : this.getCanDistribute().equals(other.getCanDistribute())) - && (this.getOwnerId() == null ? other.getOwnerId() == null : this.getOwnerId().equals(other.getOwnerId())); + && (this.getOwnerId() == null ? other.getOwnerId() == null : this.getOwnerId().equals(other.getOwnerId())) + && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())); } @Override @@ -202,6 +213,7 @@ public class UserPermission implements Serializable { result = prime * result + ((getDistributeId() == null) ? 0 : getDistributeId().hashCode()); result = prime * result + ((getCanDistribute() == null) ? 0 : getCanDistribute().hashCode()); result = prime * result + ((getOwnerId() == null) ? 0 : getOwnerId().hashCode()); + result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); return result; } @@ -215,16 +227,17 @@ public class UserPermission implements Serializable { sb.append(", permissionId=").append(permissionId); sb.append(", userId=").append(userId); sb.append(", status=").append(status); - sb.append(", goodsAmount=").append(amount); + sb.append(", amount=").append(amount); sb.append(", remains=").append(remains); sb.append(", forever=").append(forever); sb.append(", startTime=").append(startTime); sb.append(", endTime=").append(endTime); sb.append(", distributeId=").append(distributeId); - sb.append(", distribute=").append(canDistribute); + sb.append(", canDistribute=").append(canDistribute); sb.append(", ownerId=").append(ownerId); + sb.append(", createTime=").append(createTime); sb.append(", serialVersionUID=").append(serialVersionUID); sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/src/main/java/club/joylink/rtss/entity/UserPermissionExample.java b/src/main/java/club/joylink/rtss/entity/UserPermissionExample.java index f503f1996..3958bf644 100644 --- a/src/main/java/club/joylink/rtss/entity/UserPermissionExample.java +++ b/src/main/java/club/joylink/rtss/entity/UserPermissionExample.java @@ -376,62 +376,62 @@ public class UserPermissionExample { } public Criteria andAmountIsNull() { - addCriterion("goodsAmount is null"); + addCriterion("amount is null"); return (Criteria) this; } public Criteria andAmountIsNotNull() { - addCriterion("goodsAmount is not null"); + addCriterion("amount is not null"); return (Criteria) this; } public Criteria andAmountEqualTo(Integer value) { - addCriterion("goodsAmount =", value, "goodsAmount"); + addCriterion("amount =", value, "amount"); return (Criteria) this; } public Criteria andAmountNotEqualTo(Integer value) { - addCriterion("goodsAmount <>", value, "goodsAmount"); + addCriterion("amount <>", value, "amount"); return (Criteria) this; } public Criteria andAmountGreaterThan(Integer value) { - addCriterion("goodsAmount >", value, "goodsAmount"); + addCriterion("amount >", value, "amount"); return (Criteria) this; } public Criteria andAmountGreaterThanOrEqualTo(Integer value) { - addCriterion("goodsAmount >=", value, "goodsAmount"); + addCriterion("amount >=", value, "amount"); return (Criteria) this; } public Criteria andAmountLessThan(Integer value) { - addCriterion("goodsAmount <", value, "goodsAmount"); + addCriterion("amount <", value, "amount"); return (Criteria) this; } public Criteria andAmountLessThanOrEqualTo(Integer value) { - addCriterion("goodsAmount <=", value, "goodsAmount"); + addCriterion("amount <=", value, "amount"); return (Criteria) this; } public Criteria andAmountIn(List values) { - addCriterion("goodsAmount in", values, "goodsAmount"); + addCriterion("amount in", values, "amount"); return (Criteria) this; } public Criteria andAmountNotIn(List values) { - addCriterion("goodsAmount not in", values, "goodsAmount"); + addCriterion("amount not in", values, "amount"); return (Criteria) this; } public Criteria andAmountBetween(Integer value1, Integer value2) { - addCriterion("goodsAmount between", value1, value2, "goodsAmount"); + addCriterion("amount between", value1, value2, "amount"); return (Criteria) this; } public Criteria andAmountNotBetween(Integer value1, Integer value2) { - addCriterion("goodsAmount not between", value1, value2, "goodsAmount"); + addCriterion("amount not between", value1, value2, "amount"); return (Criteria) this; } @@ -746,52 +746,52 @@ public class UserPermissionExample { } public Criteria andCanDistributeEqualTo(Boolean value) { - addCriterion("can_distribute =", value, "distribute"); + addCriterion("can_distribute =", value, "canDistribute"); return (Criteria) this; } public Criteria andCanDistributeNotEqualTo(Boolean value) { - addCriterion("can_distribute <>", value, "distribute"); + addCriterion("can_distribute <>", value, "canDistribute"); return (Criteria) this; } public Criteria andCanDistributeGreaterThan(Boolean value) { - addCriterion("can_distribute >", value, "distribute"); + addCriterion("can_distribute >", value, "canDistribute"); return (Criteria) this; } public Criteria andCanDistributeGreaterThanOrEqualTo(Boolean value) { - addCriterion("can_distribute >=", value, "distribute"); + addCriterion("can_distribute >=", value, "canDistribute"); return (Criteria) this; } public Criteria andCanDistributeLessThan(Boolean value) { - addCriterion("can_distribute <", value, "distribute"); + addCriterion("can_distribute <", value, "canDistribute"); return (Criteria) this; } public Criteria andCanDistributeLessThanOrEqualTo(Boolean value) { - addCriterion("can_distribute <=", value, "distribute"); + addCriterion("can_distribute <=", value, "canDistribute"); return (Criteria) this; } public Criteria andCanDistributeIn(List values) { - addCriterion("can_distribute in", values, "distribute"); + addCriterion("can_distribute in", values, "canDistribute"); return (Criteria) this; } public Criteria andCanDistributeNotIn(List values) { - addCriterion("can_distribute not in", values, "distribute"); + addCriterion("can_distribute not in", values, "canDistribute"); return (Criteria) this; } public Criteria andCanDistributeBetween(Boolean value1, Boolean value2) { - addCriterion("can_distribute between", value1, value2, "distribute"); + addCriterion("can_distribute between", value1, value2, "canDistribute"); return (Criteria) this; } public Criteria andCanDistributeNotBetween(Boolean value1, Boolean value2) { - addCriterion("can_distribute not between", value1, value2, "distribute"); + addCriterion("can_distribute not between", value1, value2, "canDistribute"); return (Criteria) this; } @@ -854,6 +854,66 @@ public class UserPermissionExample { addCriterion("owner_id not between", value1, value2, "ownerId"); return (Criteria) this; } + + public Criteria andCreateTimeIsNull() { + addCriterion("create_time is null"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNotNull() { + addCriterion("create_time is not null"); + return (Criteria) this; + } + + public Criteria andCreateTimeEqualTo(LocalDateTime value) { + addCriterion("create_time =", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotEqualTo(LocalDateTime value) { + addCriterion("create_time <>", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThan(LocalDateTime value) { + addCriterion("create_time >", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThanOrEqualTo(LocalDateTime value) { + addCriterion("create_time >=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThan(LocalDateTime value) { + addCriterion("create_time <", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThanOrEqualTo(LocalDateTime value) { + addCriterion("create_time <=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeIn(List values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List values) { + addCriterion("create_time not in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeBetween(LocalDateTime value1, LocalDateTime value2) { + addCriterion("create_time between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotBetween(LocalDateTime value1, LocalDateTime value2) { + addCriterion("create_time not between", value1, value2, "createTime"); + return (Criteria) this; + } } /** @@ -950,4 +1010,4 @@ public class UserPermissionExample { this(condition, value, secondValue, null); } } -} \ No newline at end of file +} diff --git a/src/main/java/club/joylink/rtss/services/IPermissionDistributeService.java b/src/main/java/club/joylink/rtss/services/IPermissionDistributeService.java index 40432c806..649677926 100644 --- a/src/main/java/club/joylink/rtss/services/IPermissionDistributeService.java +++ b/src/main/java/club/joylink/rtss/services/IPermissionDistributeService.java @@ -1,6 +1,8 @@ package club.joylink.rtss.services; import club.joylink.rtss.constants.Project; +import club.joylink.rtss.constants.StatusEnum; +import club.joylink.rtss.entity.PermissionDistribute; import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.order.OrderCreateVO; @@ -59,7 +61,10 @@ public interface IPermissionDistributeService { String distributeFromUserPermission(UserPermissionDistributeVO distributeVO, UserVO user); - void restoreDistributeToUserPermission(Long id); + /** + * 将权限分发中的权限回收到用户权限 + */ + void return2UserPermission(Long id); List queryPersonalDistributeList(UserVO user); @@ -78,7 +83,7 @@ public interface IPermissionDistributeService { DistributeVO getById(Long id); - void recoveryAfterRestoreUserPermission(Long id, Integer amount); + void recoveryAfterTakeBackUserPermission(Long id, Integer amount); DistributeVO getByOrderCode(String orderCode); @@ -88,15 +93,21 @@ public interface IPermissionDistributeService { PageVO queryPackageDetail(Long id, PermissionDistributeQueryVO queryVO); - /** - * 生成赠送的权限分发 - * @param configVO - * @return - */ - DistributeVO generateGiftDistribute(PermissionGenerateConfigVO configVO); - /** * 创建项目下所有地图的权限分发 */ String createAllMapDistribute(Project project, Integer num, UserVO user); + + /** + * 扣除一些权限 + */ + void deductSomePermission(long id, int amount); + + void takeBack(long id); + + List findEntitiesByUPIds(List upIds, StatusEnum status); + + PermissionDistribute getEntity(long id); + + List findEntitiesByUPId(long upId, StatusEnum status); } diff --git a/src/main/java/club/joylink/rtss/services/IPermissionService.java b/src/main/java/club/joylink/rtss/services/IPermissionService.java index db8986d0a..e33bd3fee 100644 --- a/src/main/java/club/joylink/rtss/services/IPermissionService.java +++ b/src/main/java/club/joylink/rtss/services/IPermissionService.java @@ -64,4 +64,6 @@ public interface IPermissionService { List getJointAndTeachEntities(List mapIds); Permission findJointSimulationEntity(Long mapId); + + Permission findEntity(long id); } diff --git a/src/main/java/club/joylink/rtss/services/ISysUserService.java b/src/main/java/club/joylink/rtss/services/ISysUserService.java index 53c445bbf..ab61938e3 100644 --- a/src/main/java/club/joylink/rtss/services/ISysUserService.java +++ b/src/main/java/club/joylink/rtss/services/ISysUserService.java @@ -312,4 +312,9 @@ public interface ISysUserService { void register(UserInfoVO userInfoVO); List queryUsers(List userIds); + + /** + * 查询管理和超管 + */ + List queryAdminsAndSuperAdmins(); } diff --git a/src/main/java/club/joylink/rtss/services/IUserPermissionService.java b/src/main/java/club/joylink/rtss/services/IUserPermissionService.java index 71f1189ea..c390ed3b8 100644 --- a/src/main/java/club/joylink/rtss/services/IUserPermissionService.java +++ b/src/main/java/club/joylink/rtss/services/IUserPermissionService.java @@ -7,6 +7,7 @@ import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.permission.DistributeSelectVO; import club.joylink.rtss.vo.client.permission.PermissionQueryVO; +import club.joylink.rtss.vo.client.permission.UserPermissionQueryVO; import club.joylink.rtss.vo.client.userPermission.UserPermissionVO; import club.joylink.rtss.vo.user.PermissionGenerateConfigVO; @@ -52,9 +53,12 @@ public interface IUserPermissionService { void updateById(UserPermissionVO upVO); - void restorePermissionToDistribute(Long userPermissionId); + /** + * 将用户权限退回权限分发 + */ + void return2Distribute(Long userPermissionId); - List findByDistributeIdAndStatus(Long distributeId, StatusEnum status); + List findEntitiesByDistributeId(Long distributeId, StatusEnum status); /** * 恢复用户权限的数量 @@ -71,13 +75,6 @@ public interface IUserPermissionService { */ List queryPersonalUserPermission(UserVO user); - /** - * 生成用户权限 - * @param userVO - * @param permissionConfigVOList - */ - void generateUserPermissions(UserVO userVO, List permissionConfigVOList); - /** * 查询有效的用户教学权限 */ @@ -94,4 +91,21 @@ public interface IUserPermissionService { * @param monthAmount 要延长的月数 */ void renewal(long id, int monthAmount); + + /** + * 回收用户权限(专用)到用户权限中 + */ + void return2UserPermission(Long id); + + /** + * 使从该权限分发获取的用户权限失效 + */ + void disableUPsFromDistribute(long distributeId); + + PageVO queryUPsFromThisUP(UserPermissionQueryVO queryVO); + + /** + * 将从该用户权限流出的所有权限收回 + */ + void takeBack(long id); } diff --git a/src/main/java/club/joylink/rtss/services/PermissionDistributeService.java b/src/main/java/club/joylink/rtss/services/PermissionDistributeService.java index 94d7beb80..52708fba7 100644 --- a/src/main/java/club/joylink/rtss/services/PermissionDistributeService.java +++ b/src/main/java/club/joylink/rtss/services/PermissionDistributeService.java @@ -26,7 +26,6 @@ import club.joylink.rtss.vo.client.userPermission.UserPermissionAndAmountVO; import club.joylink.rtss.vo.client.userPermission.UserPermissionDistributeVO; import club.joylink.rtss.vo.client.userPermission.UserPermissionVO; import club.joylink.rtss.vo.client.validGroup.ValidList; -import club.joylink.rtss.vo.user.PermissionGenerateConfigVO; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import lombok.extern.slf4j.Slf4j; @@ -36,7 +35,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; -import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -104,6 +102,15 @@ public class PermissionDistributeService implements IPermissionDistributeService List permissionIds = voList.stream().map(PermissionVO::getId).collect(Collectors.toList()); criteria.andPermissionIdIn(permissionIds); } + if (queryVO.getOrganizationId() != null) { + criteria.andOrganizationIdEqualTo(queryVO.getOrganizationId()); + } + if (queryVO.getCreatorId() != null) { + criteria.andCreatorIdEqualTo(queryVO.getCreatorId()); + } + if (queryVO.getFromUserPermissionId() != null) { + criteria.andFromUserPermissionIdEqualTo(queryVO.getFromUserPermissionId()); + } PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); Page page = (Page) permissionDistributeDAO.selectByExample(example); @@ -158,7 +165,7 @@ public class PermissionDistributeService implements IPermissionDistributeService */ @Override public void immediateInvalid(Long id) { - PermissionDistribute permissionDistribute = getEntityById(id); + PermissionDistribute permissionDistribute = getEntity(id); permissionDistribute.setStatus(StatusEnum.Invalid.getCode()); permissionDistributeDAO.updateByPrimaryKeySelective(permissionDistribute); } @@ -196,9 +203,10 @@ public class PermissionDistributeService implements IPermissionDistributeService order.setDetailVOList(iOrderService.findOrderDetailVOListByOrderId(order.getId())); //如果订单有多个商品,创建权限分发包 + LocalDateTime now = LocalDateTime.now(); if (order.getDetailVOList().size() > 1) { //添加权限分发包 - PermissionDistribute distribute = buildPermissionDistributeFromOrder(order); + PermissionDistribute distribute = buildPermissionDistributeFromOrder(order, now); int amount = order.getDetailVOList().stream().mapToInt(OrderDetailVO::getGoodsAmount).sum(); distribute.setAmount(amount); distribute.setRemains(amount); @@ -214,11 +222,12 @@ public class PermissionDistributeService implements IPermissionDistributeService distribute.setPermissionId(iGoodsService.getById(orderDetailVO.getGoodsId()).getPermissionId()); distribute.setAmount(orderDetailVO.getGoodsAmount()); distribute.setRemains(distribute.getAmount()); + distribute.setCreateTime(now); permissionDistributeDAO.insertSelective(distribute); } } else { //如果只有一个商品,创建权限分发 - PermissionDistribute distribute = buildPermissionDistributeFromOrder(order); + PermissionDistribute distribute = buildPermissionDistributeFromOrder(order, now); OrderDetailVO orderDetailVO = order.getDetailVOList().get(0); distribute.setPermissionId(iGoodsService.getById(orderDetailVO.getGoodsId()).getPermissionId()); distribute.setAmount(orderDetailVO.getGoodsAmount()); @@ -239,13 +248,13 @@ public class PermissionDistributeService implements IPermissionDistributeService * 领取权限。 * 如果权限分发不存在,报DBException(数据不存在) * - * @param id 权限分发id - * @param user 要获取权限的用户 + * @param id 权限分发id + * @param user 要获取权限的用户 */ @Override @Transactional public void getUserPermission(Long id, UserVO user) { - PermissionDistribute distribute = getEntityById(id); + PermissionDistribute distribute = getEntity(id); canReceiveValid(distribute, user); if (distribute.getIsPackage()) { List permissionDistributeList = getEntityByParentId(distribute.getId()); @@ -336,6 +345,7 @@ public class PermissionDistributeService implements IPermissionDistributeService userPermissionAndAmountVOList.removeAll(removeList); Long distributeId; + LocalDateTime now = LocalDateTime.now(); if (userPermissionAndAmountVOList.size() == 1) { distribute.setIsPackage(false); UserPermissionAndAmountVO upaaVO = userPermissionAndAmountVOList.get(0); @@ -343,6 +353,7 @@ public class PermissionDistributeService implements IPermissionDistributeService distribute.setAmount(upaaVO.getAmount()); distribute.setRemains(upaaVO.getAmount()); distribute.setFromUserPermissionId(upaaVO.getUserPermissionId()); + distribute.setCreateTime(now); permissionDistributeDAO.insertSelective(distribute); UserPermission userPermission = new UserPermission(); userPermission.setId(upaaVO.getUserPermissionId()); @@ -353,6 +364,7 @@ public class PermissionDistributeService implements IPermissionDistributeService distribute.setIsPackage(true); distribute.setAmount(userPermissionAndAmountVOList.stream().mapToInt(UserPermissionAndAmountVO::getAmount).sum()); distribute.setRemains(distribute.getAmount()); + distribute.setCreateTime(now); permissionDistributeDAO.insertSelective(distribute); distributeId = distribute.getId(); for (UserPermissionAndAmountVO upaaVO : userPermissionAndAmountVOList) { @@ -363,6 +375,7 @@ public class PermissionDistributeService implements IPermissionDistributeService distribute.setFromUserPermissionId(upaaVO.getUserPermissionId()); distribute.setAmount(upaaVO.getAmount()); distribute.setRemains(upaaVO.getAmount()); + distribute.setCreateTime(now); permissionDistributeDAO.insertSelective(distribute); UserPermission userPermission = new UserPermission(); userPermission.setId(upaaVO.getUserPermissionId()); @@ -373,21 +386,14 @@ public class PermissionDistributeService implements IPermissionDistributeService return generateQrCode(distributeId); } - private PermissionDistribute getEntityById(Long id) { - PermissionDistribute distribute = permissionDistributeDAO.selectByPrimaryKey(id); - BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(distribute, - String.format("id为[%s]的权限分发不存在", id)); - return distribute; - } - /** * 将权限分发中的所有权限全部回收到用户权限 */ @Transactional @Override - public void restoreDistributeToUserPermission(Long id) { + public void return2UserPermission(Long id) { //校验 - PermissionDistribute distribute = getEntityById(id); + PermissionDistribute distribute = getEntity(id); BusinessExceptionAssertEnum.DATA_INVALID.assertNotEquals(StatusEnum.Invalid.getCode(), distribute.getStatus(), "该权限分发已失效"); BusinessExceptionAssertEnum.DATA_STATE_INCORRECT.assertEquals(PermissionDistributeSourceEnum.FromUser.getCode(), @@ -415,7 +421,7 @@ public class PermissionDistributeService implements IPermissionDistributeService @Override public void systemRevokePermissionDistribute(Long id) { //校验 - PermissionDistribute distribute = getEntityById(id); + PermissionDistribute distribute = getEntity(id); if (StatusEnum.Invalid.getCode().equals(distribute.getStatus())) { return; } @@ -474,9 +480,10 @@ public class PermissionDistributeService implements IPermissionDistributeService * 从订单构建一个权限分发,这个权限分发对权限分发包与基础权限分发的公共属性进行了赋值 * * @param orderVO + * @param now * @return */ - private PermissionDistribute buildPermissionDistributeFromOrder(OrderVO orderVO) { + private PermissionDistribute buildPermissionDistributeFromOrder(OrderVO orderVO, LocalDateTime now) { //参数校验 Objects.requireNonNull(orderVO, "order不能为null"); if (CollectionUtils.isEmpty(orderVO.getDetailVOList())) { @@ -496,6 +503,8 @@ public class PermissionDistributeService implements IPermissionDistributeService distribute.setStatus(StatusEnum.Valid.getCode()); distribute.setCanDistribute(true); distribute.setSource(PermissionDistributeSourceEnum.FromOrder.getCode()); + distribute.setCreatorId(orderVO.getCreatorId()); + distribute.setCreateTime(now); return distribute; } @@ -607,16 +616,9 @@ public class PermissionDistributeService implements IPermissionDistributeService return voList; } - public List getByFromUserPermissionId(Long userPermissionId) { - List voList = findByFromUserPermissionId(userPermissionId); - BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertCollectionNotEmpty(voList, - String.format("没有从id为[%s]的用户权限创建的权限分发", userPermissionId)); - return voList; - } - @Override public List queryDistributeGetUsers(Long id, UserVO user) { - List voList = iUserPermissionService.findByDistributeIdAndStatus(id, StatusEnum.Valid); + List voList = iUserPermissionService.findEntitiesByDistributeId(id, StatusEnum.Valid); for (UserPermissionVO vo : voList) { UserVO uservo = iSysUserService.getUserById(vo.getUserId()); vo.setUserName(uservo.getName()); @@ -630,37 +632,12 @@ public class PermissionDistributeService implements IPermissionDistributeService PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); Page page = (Page) getEntityByParentId(id); List voList = page.getResult().stream().map(distribute -> { - DistributeVO vo = new DistributeVO(distribute); - if (vo.getOrganizationId() != null) { - vo.setOrganizationName(iOrganizationService.getById(distribute.getOrganizationId()).getName()); - } - return vo; + Permission permission = iPermissionService.findEntity(distribute.getPermissionId()); + return new DistributeVO(distribute, permission); }).collect(Collectors.toList()); return PageVO.convert(page, voList); } - @Override - public DistributeVO generateGiftDistribute(PermissionGenerateConfigVO configVO) { - PermissionVO permission = this.iPermissionService.getById(configVO.getPermissionId()); - log.info(String.format("即将生成权限[%s:%s]的赠送的权限分发数据", permission.getId(), permission.getName())); - PermissionDistribute distribute = new PermissionDistribute(); - distribute.setSource(PermissionDistributeSourceEnum.Gift.getCode()); - distribute.setPermissionId(configVO.getPermissionId()); - distribute.setAmount(configVO.getQuantity()); - distribute.setRemains(configVO.getQuantity()); - distribute.setForever(false); - LocalDateTime startTime = LocalDate.now().atStartOfDay(); - distribute.setStartTime(startTime); - LocalDateTime endTime = startTime.plusMonths(configVO.getMonthNumber()); - distribute.setEndTime(endTime); - distribute.setStatus(StatusEnum.Valid.getCode()); - distribute.setIsPackage(false); - distribute.setCanDistribute(true); - distribute.setCreateTime(LocalDateTime.now()); - this.permissionDistributeDAO.insert(distribute); - return new DistributeVO(distribute); - } - @Override public String createAllMapDistribute(Project project, Integer num, UserVO user) { iSysUserService.confirmAdmin(user); @@ -684,17 +661,77 @@ public class PermissionDistributeService implements IPermissionDistributeService } @Override - public void recoveryAfterRestoreUserPermission(Long id, Integer amount) { - PermissionDistribute distribute = getEntityById(id); + public void deductSomePermission(long id, int amount) { + PermissionDistribute pd = this.getEntity(id); + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue( + pd.getOnlyGetOne() != null && pd.getOnlyGetOne(), "非专用权限权限分发,无法使用此操作"); + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(pd.getFromUserPermissionId(), "权限分发不是从用户权限创建的,无法收回权限"); + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotTrue(pd.getIsPackage(), "权限分发包收回权限逻辑未实现"); + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(pd.getAmount() >= amount, String.format("权限分发中剩余权限数量不足%s", amount)); + pd.setRemains(pd.getRemains() - amount); + pd.setAmount(pd.getAmount() - amount); + permissionDistributeDAO.updateByPrimaryKey(pd); + } + + @Transactional + @Override + public void takeBack(long id) { + PermissionDistribute entity = this.getEntity(id); + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertEquals(entity.getStatus(), StatusEnum.Valid.getCode(), "无效的权限分发"); + iUserPermissionService.disableUPsFromDistribute(id); //使所有从该权限分发出去的用户权限失效 + entity.setRemains(entity.getAmount()); + permissionDistributeDAO.updateByPrimaryKey(entity); + } + + @Override + public List findEntitiesByUPIds(List upIds, StatusEnum status) { + if (CollectionUtils.isEmpty(upIds)) + return new ArrayList<>(); + PermissionDistributeExample example = new PermissionDistributeExample(); + PermissionDistributeExample.Criteria criteria = example.createCriteria().andFromUserPermissionIdIn(upIds); + if (status != null) { + criteria.andStatusEqualTo(status.getCode()); + } + return permissionDistributeDAO.selectByExample(example); + } + + @Override + public PermissionDistribute getEntity(long id) { + PermissionDistribute distribute = permissionDistributeDAO.selectByPrimaryKey(id); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(distribute, + String.format("id为[%s]的权限分发不存在", id)); + return distribute; + } + + @Override + public List findEntitiesByUPId(long upId, StatusEnum status) { + PermissionDistributeExample example = new PermissionDistributeExample(); + PermissionDistributeExample.Criteria criteria = example.createCriteria().andFromUserPermissionIdEqualTo(upId); + if (status != null) + criteria.andStatusEqualTo(status.getCode()); + return permissionDistributeDAO.selectByExample(example); + } + + @Override + public void recoveryAfterTakeBackUserPermission(Long id, Integer amount) { + PermissionDistribute distribute = getEntity(id); distribute.setRemains(distribute.getRemains() + amount); permissionDistributeDAO.updateByPrimaryKeySelective(distribute); if (distribute.getParentId() != 0) { - PermissionDistribute parentDistribute = getEntityById(distribute.getParentId()); + PermissionDistribute parentDistribute = getEntity(distribute.getParentId()); parentDistribute.setRemains(parentDistribute.getRemains() + amount); permissionDistributeDAO.updateByPrimaryKeySelective(parentDistribute); } } + @Override + public DistributeVO getByOrderCode(String orderCode) { + PermissionDistribute distribute = findByOrderCode(orderCode); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(distribute, + String.format("订单编号为[%s]的权限分发不存在", orderCode)); + return new DistributeVO(distribute); + } + private PermissionDistribute findByOrderCode(String orderCode) { PermissionDistributeExample example = new PermissionDistributeExample(); example.createCriteria().andOrderCodeEqualTo(orderCode); @@ -705,11 +742,10 @@ public class PermissionDistributeService implements IPermissionDistributeService return distributeList.get(0); } - @Override - public DistributeVO getByOrderCode(String orderCode) { - PermissionDistribute distribute = findByOrderCode(orderCode); - BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(distribute, - String.format("订单编号为[%s]的权限分发不存在", orderCode)); - return new DistributeVO(distribute); + public List getByFromUserPermissionId(Long userPermissionId) { + List voList = findByFromUserPermissionId(userPermissionId); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertCollectionNotEmpty(voList, + String.format("没有从id为[%s]的用户权限创建的权限分发", userPermissionId)); + return voList; } } diff --git a/src/main/java/club/joylink/rtss/services/PermissionService.java b/src/main/java/club/joylink/rtss/services/PermissionService.java index 0e6897c3d..95709a6c8 100644 --- a/src/main/java/club/joylink/rtss/services/PermissionService.java +++ b/src/main/java/club/joylink/rtss/services/PermissionService.java @@ -215,12 +215,13 @@ public class PermissionService implements IPermissionService { permissionDAO.updateByPrimaryKey(permission); } - private Permission findEntityById(Long id) { + @Override + public Permission findEntity(long id) { return permissionDAO.selectByPrimaryKey(id); } private Permission getEntityById(Long id) { - Permission permission = findEntityById(id); + Permission permission = findEntity(id); BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(permission, String.format("id为[%s]的权限不存在", id)); return permission; } @@ -589,5 +590,4 @@ public class PermissionService implements IPermissionService { return permissions.get(0); return null; } - } diff --git a/src/main/java/club/joylink/rtss/services/SysUserService.java b/src/main/java/club/joylink/rtss/services/SysUserService.java index 1ec2397ba..c61da4330 100644 --- a/src/main/java/club/joylink/rtss/services/SysUserService.java +++ b/src/main/java/club/joylink/rtss/services/SysUserService.java @@ -839,6 +839,16 @@ public class SysUserService implements ISysUserService { return UserVO.convert2BaseInfoVO(users); } + @Override + public List queryAdminsAndSuperAdmins() { + SysUserExample example = new SysUserExample(); + example.setOrderByClause("id"); + example.createCriteria().andRolesLike(String.format("%%%s%%", BusinessConsts.ROLE_04)); + example.or().andRolesLike(String.format("%%%s%%", BusinessConsts.ROLE_05)); + List users = sysUserDAO.selectByExample(example); + return UserVO.convert2BaseInfoVO(users); + } + private boolean isSameEmailExist(String email) { SysUserExample example = new SysUserExample(); example.createCriteria() diff --git a/src/main/java/club/joylink/rtss/services/UserPermissionService.java b/src/main/java/club/joylink/rtss/services/UserPermissionService.java index bfb5b7430..5c326e9ba 100644 --- a/src/main/java/club/joylink/rtss/services/UserPermissionService.java +++ b/src/main/java/club/joylink/rtss/services/UserPermissionService.java @@ -6,6 +6,7 @@ import club.joylink.rtss.dao.SysUserDAO; import club.joylink.rtss.dao.UserPermissionDAO; import club.joylink.rtss.dao.UserPermissionProcessingDAO; import club.joylink.rtss.entity.PermissionDistribute; +import club.joylink.rtss.entity.SysUser; import club.joylink.rtss.entity.UserPermission; import club.joylink.rtss.entity.UserPermissionExample; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; @@ -17,9 +18,9 @@ import club.joylink.rtss.vo.client.order.OrderDetailCreateVO; import club.joylink.rtss.vo.client.permission.DistributeSelectVO; import club.joylink.rtss.vo.client.permission.PermissionQueryVO; import club.joylink.rtss.vo.client.permission.PermissionVO; +import club.joylink.rtss.vo.client.permission.UserPermissionQueryVO; import club.joylink.rtss.vo.client.permissionDistribute.DistributeVO; import club.joylink.rtss.vo.client.userPermission.UserPermissionVO; -import club.joylink.rtss.vo.user.PermissionGenerateConfigVO; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import org.springframework.beans.factory.annotation.Autowired; @@ -29,6 +30,7 @@ import org.springframework.util.CollectionUtils; import java.time.LocalDateTime; import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; @Service @@ -87,12 +89,11 @@ public class UserPermissionService implements IUserPermissionService { /** * 将用户权限设为失效。 - * 如果用户权限不存在,报DBException(数据不存在) - * - * @param id */ + @Transactional @Override public void setInvalid(Long id) { + takeBack(id); //回收所有权限 UserPermission userPermission = getEntityById(id); userPermission.setStatus(UserPermissionStatusEnum.Invalid.getCode()); userPermissionDAO.updateByPrimaryKeySelective(userPermission); @@ -362,13 +363,14 @@ public class UserPermissionService implements IUserPermissionService { userPermission.setAmount(1); userPermission.setRemains(1); } + userPermission.setCreateTime(LocalDateTime.now()); userPermissionDAO.insertSelective(userPermission); } public void updateById(UserPermissionVO upVO) { Objects.requireNonNull(upVO, "UserPermissionVO不能为null"); Objects.requireNonNull(upVO.getId(), "UserPermissionVO的id不能为null"); - UserPermission userPermission = upVO.conver2DB(); + UserPermission userPermission = upVO.convert2DB(); userPermissionDAO.updateByPrimaryKeySelective(userPermission); } @@ -404,17 +406,21 @@ public class UserPermissionService implements IUserPermissionService { @Transactional @Override - public void restorePermissionToDistribute(Long userPermissionId) { - UserPermissionVO upVO = getById(userPermissionId); - BusinessExceptionAssertEnum.INVALID_OPERATION.assertTrue(StatusEnum.Valid.getCode().equals(upVO.getStatus())); - upVO.setStatus(StatusEnum.Invalid.getCode()); - updateById(upVO); - iPermissionDistributeService.recoveryAfterRestoreUserPermission(upVO.getDistributeId(), upVO.getAmount()); + public void return2Distribute(Long userPermissionId) { + UserPermission entity = getEntityById(userPermissionId); + return2Distribute(entity); + } + + private void return2Distribute(UserPermission up) { + BusinessExceptionAssertEnum.INVALID_OPERATION.assertTrue(StatusEnum.Valid.getCode().equals(up.getStatus())); + up.setStatus(StatusEnum.Invalid.getCode()); + userPermissionDAO.updateByPrimaryKey(up); + iPermissionDistributeService.recoveryAfterTakeBackUserPermission(up.getDistributeId(), up.getAmount()); } @Override - public List findByDistributeIdAndStatus(Long distributeId, StatusEnum status) { - DistributeVO distribute = iPermissionDistributeService.getById(distributeId); + public List findEntitiesByDistributeId(Long distributeId, StatusEnum status) { + PermissionDistribute distribute = iPermissionDistributeService.getEntity(distributeId); List disIdList; if (distribute.getIsPackage()) { List distributeList = iPermissionDistributeService.getByParentId(distributeId); @@ -453,15 +459,6 @@ public class UserPermissionService implements IUserPermissionService { return voList; } - @Override - @Transactional - public void generateUserPermissions(UserVO userVO, List permissionConfigVOList) { - for (PermissionGenerateConfigVO configVO : permissionConfigVOList) { - DistributeVO distributeVO = this.iPermissionDistributeService.generateGiftDistribute(configVO); - this.iPermissionDistributeService.getUserPermission(distributeVO.getId(), userVO); - } - } - @Override public List findEntity(List userIds, Boolean valid) { StatusEnum status = null; @@ -510,6 +507,76 @@ public class UserPermissionService implements IUserPermissionService { userPermissionDAO.updateByPrimaryKey(entity); } + @Transactional + @Override + public void return2UserPermission(Long id) { + UserPermission entity = getEntityById(id); + return2Distribute(entity); //回收用户权限到权限分发中 + iPermissionDistributeService.deductSomePermission(entity.getDistributeId(), 1); + PermissionDistribute distribute = iPermissionDistributeService.getEntity(entity.getDistributeId()); + UserPermission parentUP = getEntityById(distribute.getFromUserPermissionId()); + parentUP.setRemains(parentUP.getRemains() + 1); + userPermissionDAO.updateByPrimaryKey(parentUP); + } + + @Override + public void disableUPsFromDistribute(long distributeId) { + List entities = findEntitiesByDistributeId(distributeId); + if (CollectionUtils.isEmpty(entities)) + return; + userPermissionDAO.updateInvalidByDistributeId(distributeId); + List upIds = entities.stream().map(UserPermission::getId).collect(Collectors.toList()); + iPermissionDistributeService.findEntitiesByUPIds(upIds, StatusEnum.Valid) + .forEach(distribute -> userPermissionDAO.updateInvalidByDistributeId(distribute.getId())); + } + + @Override + public PageVO queryUPsFromThisUP(UserPermissionQueryVO queryVO) { + UserPermission entity = getEntityById(queryVO.getId()); + List distributes = iPermissionDistributeService.findEntitiesByUPId(entity.getId(), StatusEnum.Valid); + Page page = PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); + if (CollectionUtils.isEmpty(distributes)) + PageVO.convert(page, new ArrayList<>()); + List distributeIds = distributes.stream().map(PermissionDistribute::getId).collect(Collectors.toList()); + List ups = findEntitiesByDistributeIds(distributeIds, StatusEnum.Valid); + if (CollectionUtils.isEmpty(ups)) + PageVO.convert(page, new ArrayList<>()); + List userIds = ups.stream().map(UserPermission::getUserId).distinct().collect(Collectors.toList()); + Map userMap = iSysUserService.findEntities(userIds, null).stream() + .collect(Collectors.toMap(SysUser::getId, Function.identity())); + List vos = ups.stream() + .map(up -> { + SysUser sysUser = userMap.get(up.getUserId()); + return new UserPermissionVO(up, sysUser); + }) + .collect(Collectors.toList()); + return PageVO.convert(page, vos); + } + + @Transactional + @Override + public void takeBack(long id) { + UserPermission entity = getEntityById(id); + List distributes = iPermissionDistributeService.findEntitiesByUPId(entity.getId(), StatusEnum.Valid); + if (CollectionUtils.isEmpty(distributes)) + return; + distributes.stream() + .map(PermissionDistribute::getId) + .distinct() + .forEach(distributeId -> { + iPermissionDistributeService.takeBack(distributeId); + iPermissionDistributeService.return2UserPermission(distributeId); + }); + } + + private List findEntitiesByDistributeIds(List distributeIds, StatusEnum status) { + UserPermissionExample example = new UserPermissionExample(); + UserPermissionExample.Criteria criteria = example.createCriteria().andDistributeIdIn(distributeIds); + if (status != null) + criteria.andStatusEqualTo(status.getCode()); + return userPermissionDAO.selectByExample(example); + } + private List findByUserId(Long userId) { UserPermissionExample example = new UserPermissionExample(); example.createCriteria().andUserIdEqualTo(userId); @@ -517,4 +584,10 @@ public class UserPermissionService implements IUserPermissionService { return upList.stream().map(UserPermissionVO::new).collect(Collectors.toList()); } + private List findEntitiesByDistributeId(long distributeId) { + UserPermissionExample example = new UserPermissionExample(); + example.createCriteria().andDistributeIdEqualTo(distributeId); + return userPermissionDAO.selectByExample(example); + } + } diff --git a/src/main/java/club/joylink/rtss/vo/client/permission/UserPermissionQueryVO.java b/src/main/java/club/joylink/rtss/vo/client/permission/UserPermissionQueryVO.java new file mode 100644 index 000000000..2865abdd6 --- /dev/null +++ b/src/main/java/club/joylink/rtss/vo/client/permission/UserPermissionQueryVO.java @@ -0,0 +1,19 @@ +package club.joylink.rtss.vo.client.permission; + +import club.joylink.rtss.constants.StatusEnum; +import club.joylink.rtss.vo.client.PageQueryVO; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import javax.validation.constraints.NotNull; + +@Getter +@Setter +@NoArgsConstructor +public class UserPermissionQueryVO extends PageQueryVO { + @NotNull(message = "id不能为null") + private Long id; + + private StatusEnum status; +} diff --git a/src/main/java/club/joylink/rtss/vo/client/permissionDistribute/DistributeVO.java b/src/main/java/club/joylink/rtss/vo/client/permissionDistribute/DistributeVO.java index d207290ae..5200dc7e8 100644 --- a/src/main/java/club/joylink/rtss/vo/client/permissionDistribute/DistributeVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/permissionDistribute/DistributeVO.java @@ -1,5 +1,6 @@ package club.joylink.rtss.vo.client.permissionDistribute; +import club.joylink.rtss.entity.Permission; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import club.joylink.rtss.constants.PermissionDistributeSourceEnum; @@ -93,11 +94,10 @@ public class DistributeVO { */ private Boolean canRestore; - public static List convert2VOList(List list) { - if (!CollectionUtils.isEmpty(list)) { - return list.stream().map(DistributeVO::new).collect(Collectors.toList()); - } - return null; + public DistributeVO(PermissionDistribute distribute, Permission permission) { + this(distribute); + this.permissionName = permission.getName(); + this.permissionType = permission.getType(); } public DistributeVO(PermissionDistribute pd) { @@ -126,4 +126,11 @@ public class DistributeVO { this.canRestore = false; } } + + public static List convert2VOList(List list) { + if (!CollectionUtils.isEmpty(list)) { + return list.stream().map(DistributeVO::new).collect(Collectors.toList()); + } + return null; + } } diff --git a/src/main/java/club/joylink/rtss/vo/client/permissionDistribute/PermissionDistributeQueryVO.java b/src/main/java/club/joylink/rtss/vo/client/permissionDistribute/PermissionDistributeQueryVO.java index de7ff09af..d16d8be48 100644 --- a/src/main/java/club/joylink/rtss/vo/client/permissionDistribute/PermissionDistributeQueryVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/permissionDistribute/PermissionDistributeQueryVO.java @@ -11,12 +11,6 @@ import lombok.Setter; @Setter public class PermissionDistributeQueryVO extends PageQueryVO { - /** - * 用户名 - */ - @ApiModelProperty(value="用户名") - private String userName; - /** * 手机号 */ @@ -72,4 +66,13 @@ public class PermissionDistributeQueryVO extends PageQueryVO { @ApiModelProperty(value = "权限id") private Long permissionId; + + /** 组织/企业id */ + private Long organizationId; + + /** 创建人id */ + private Long creatorId; + + /** 创建自该用户权限 */ + private Long fromUserPermissionId; } diff --git a/src/main/java/club/joylink/rtss/vo/client/permissionDistribute/PermissionDistributeVO.java b/src/main/java/club/joylink/rtss/vo/client/permissionDistribute/PermissionDistributeVO.java index 2f3828844..19e9828fa 100644 --- a/src/main/java/club/joylink/rtss/vo/client/permissionDistribute/PermissionDistributeVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/permissionDistribute/PermissionDistributeVO.java @@ -127,6 +127,10 @@ public class PermissionDistributeVO { */ private Boolean onlyGetOne; + private Long creatorId; + + private LocalDateTime createTime; + public PermissionDistributeVO(PermissionDistribute distribute) { this.id = distribute.getId(); this.permissionId = distribute.getPermissionId(); @@ -142,11 +146,8 @@ public class PermissionDistributeVO { this.source = distribute.getSource(); this.onlyGetOne = distribute.getOnlyGetOne(); this.isPackage=distribute.getIsPackage(); - } - - @JsonIgnore - public boolean isOnlyGetOne() { - return !this.getCanDistribute() && Objects.nonNull(this.onlyGetOne) && this.onlyGetOne; + this.creatorId = distribute.getCreatorId(); + this.createTime = distribute.getCreateTime(); } public static List convert2VOList(List list) { diff --git a/src/main/java/club/joylink/rtss/vo/client/userPermission/UserPermissionVO.java b/src/main/java/club/joylink/rtss/vo/client/userPermission/UserPermissionVO.java index fed3da67d..5da7b5faa 100644 --- a/src/main/java/club/joylink/rtss/vo/client/userPermission/UserPermissionVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/userPermission/UserPermissionVO.java @@ -1,5 +1,6 @@ package club.joylink.rtss.vo.client.userPermission; +import club.joylink.rtss.entity.SysUser; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; @@ -73,6 +74,8 @@ public class UserPermissionVO { private String ownerName; + private LocalDateTime createTime; + public UserPermissionVO(UserPermission userPermission) { id = userPermission.getId(); permissionId = userPermission.getPermissionId(); @@ -86,9 +89,18 @@ public class UserPermissionVO { status = userPermission.getStatus(); distributeId = userPermission.getDistributeId(); ownerId = userPermission.getOwnerId(); + this.createTime = userPermission.getCreateTime(); } - public UserPermission conver2DB() { + public UserPermissionVO(UserPermission up, SysUser sysUser) { + this(up); + if (sysUser != null) { + this.userName = sysUser.getName(); + this.userNickname = sysUser.getNickname(); + } + } + + public UserPermission convert2DB() { UserPermission userPermission = new UserPermission(); userPermission.setId(this.id); userPermission.setPermissionId(this.permissionId); @@ -102,6 +114,7 @@ public class UserPermissionVO { userPermission.setDistributeId(this.distributeId); userPermission.setCanDistribute(this.canDistribute); userPermission.setOwnerId(this.ownerId); + userPermission.setCreateTime(this.createTime); return userPermission; } diff --git a/src/main/resources/mybatis/mapper/PermissionDistributeDAO.xml b/src/main/resources/mybatis/mapper/PermissionDistributeDAO.xml index 936287473..30917e72e 100644 --- a/src/main/resources/mybatis/mapper/PermissionDistributeDAO.xml +++ b/src/main/resources/mybatis/mapper/PermissionDistributeDAO.xml @@ -9,16 +9,17 @@ - + - - + + - + + @@ -80,9 +81,9 @@ - id, permission_id, order_code, organization_id, user_id, amount, remains, forever, - start_time, end_time, `status`, can_distribute, is_package, parent_id, `source`, - only_get_one, from_user_permission_id, create_time + id, permission_id, order_code, organization_id, user_id, amount, remains, forever, + start_time, end_time, `status`, can_distribute, is_package, parent_id, `source`, + only_get_one, from_user_permission_id, creator_id, create_time select @@ -100,7 +101,7 @@ @@ -226,7 +235,7 @@ remains = #{record.remains,jdbcType=INTEGER}, - forever = #{record.forever,jdbcType=BIT}, + forever = #{record.forever,jdbcType=TINYINT}, start_time = #{record.startTime,jdbcType=TIMESTAMP}, @@ -238,11 +247,14 @@ distribute_id = #{record.distributeId,jdbcType=BIGINT}, - can_distribute = #{record.canDistribute,jdbcType=BIT}, + can_distribute = #{record.canDistribute,jdbcType=TINYINT}, owner_id = #{record.ownerId,jdbcType=BIGINT}, + + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + @@ -256,12 +268,13 @@ `status` = #{record.status,jdbcType=VARCHAR}, amount = #{record.amount,jdbcType=INTEGER}, remains = #{record.remains,jdbcType=INTEGER}, - forever = #{record.forever,jdbcType=BIT}, + forever = #{record.forever,jdbcType=TINYINT}, start_time = #{record.startTime,jdbcType=TIMESTAMP}, end_time = #{record.endTime,jdbcType=TIMESTAMP}, distribute_id = #{record.distributeId,jdbcType=BIGINT}, - can_distribute = #{record.canDistribute,jdbcType=BIT}, - owner_id = #{record.ownerId,jdbcType=BIGINT} + can_distribute = #{record.canDistribute,jdbcType=TINYINT}, + owner_id = #{record.ownerId,jdbcType=BIGINT}, + create_time = #{record.createTime,jdbcType=TIMESTAMP} @@ -285,7 +298,7 @@ remains = #{remains,jdbcType=INTEGER}, - forever = #{forever,jdbcType=BIT}, + forever = #{forever,jdbcType=TINYINT}, start_time = #{startTime,jdbcType=TIMESTAMP}, @@ -297,11 +310,14 @@ distribute_id = #{distributeId,jdbcType=BIGINT}, - can_distribute = #{canDistribute,jdbcType=BIT}, + can_distribute = #{canDistribute,jdbcType=TINYINT}, owner_id = #{ownerId,jdbcType=BIGINT}, + + create_time = #{createTime,jdbcType=TIMESTAMP}, + where id = #{id,jdbcType=BIGINT} @@ -312,12 +328,13 @@ `status` = #{status,jdbcType=VARCHAR}, amount = #{amount,jdbcType=INTEGER}, remains = #{remains,jdbcType=INTEGER}, - forever = #{forever,jdbcType=BIT}, + forever = #{forever,jdbcType=TINYINT}, start_time = #{startTime,jdbcType=TIMESTAMP}, end_time = #{endTime,jdbcType=TIMESTAMP}, distribute_id = #{distributeId,jdbcType=BIGINT}, - can_distribute = #{canDistribute,jdbcType=BIT}, - owner_id = #{ownerId,jdbcType=BIGINT} + can_distribute = #{canDistribute,jdbcType=TINYINT}, + owner_id = #{ownerId,jdbcType=BIGINT}, + create_time = #{createTime,jdbcType=TIMESTAMP} where id = #{id,jdbcType=BIGINT} - \ No newline at end of file +