From 3fe859f2c42891f3cc7ab2b8ec367195be9a4644 Mon Sep 17 00:00:00 2001 From: Zhaoyang Date: Mon, 3 Feb 2020 16:53:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84iam=E4=B8=AD=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E4=BB=A5=E5=8F=8A=E8=A7=92=E8=89=B2=E4=B8=8E=E6=9D=83?= =?UTF-8?q?=E9=99=90=E5=85=B3=E8=81=94=E5=85=B3=E7=B3=BB=E7=9A=84=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E4=B8=8E=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/diboot/iam/dto/IamRoleFormDTO.java | 27 +++++++++++++++++++ .../iam/service/IamRolePermissionService.java | 8 ++++++ .../impl/IamRolePermissionServiceImpl.java | 18 +++++++++++++ .../java/com/diboot/iam/vo/IamRoleVO.java | 2 +- 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 iam-base-starter/src/main/java/com/diboot/iam/dto/IamRoleFormDTO.java diff --git a/iam-base-starter/src/main/java/com/diboot/iam/dto/IamRoleFormDTO.java b/iam-base-starter/src/main/java/com/diboot/iam/dto/IamRoleFormDTO.java new file mode 100644 index 0000000..3d0b618 --- /dev/null +++ b/iam-base-starter/src/main/java/com/diboot/iam/dto/IamRoleFormDTO.java @@ -0,0 +1,27 @@ +package com.diboot.iam.dto; + +import com.diboot.iam.entity.IamRole; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +import java.util.List; + +/** + * 角色表单接收类 + * @author mazc@dibo.ltd + * @version v2.0 + * @date 2019/12/18 + */ +@Getter +@Setter +@Accessors(chain = true) +public class IamRoleFormDTO extends IamRole { + + private static final long serialVersionUID = 1444823850258901617L; + + /*** + * 权限id列表 + */ + private List permissionIdList; +} diff --git a/iam-base-starter/src/main/java/com/diboot/iam/service/IamRolePermissionService.java b/iam-base-starter/src/main/java/com/diboot/iam/service/IamRolePermissionService.java index 5fc045b..9bbb8ad 100644 --- a/iam-base-starter/src/main/java/com/diboot/iam/service/IamRolePermissionService.java +++ b/iam-base-starter/src/main/java/com/diboot/iam/service/IamRolePermissionService.java @@ -37,6 +37,14 @@ public interface IamRolePermissionService extends BaseIamService permissionIdList); + /*** + * 批量更新角色与权限集的关系 + * @param roleId + * @param permissionIdList + * @return + */ + boolean updateRolePermissionRelations(Long roleId, List permissionIdList); + /** * 获取RoleService实例 * @return diff --git a/iam-base-starter/src/main/java/com/diboot/iam/service/impl/IamRolePermissionServiceImpl.java b/iam-base-starter/src/main/java/com/diboot/iam/service/impl/IamRolePermissionServiceImpl.java index 84a8a77..cd9342b 100644 --- a/iam-base-starter/src/main/java/com/diboot/iam/service/impl/IamRolePermissionServiceImpl.java +++ b/iam-base-starter/src/main/java/com/diboot/iam/service/impl/IamRolePermissionServiceImpl.java @@ -1,5 +1,6 @@ package com.diboot.iam.service.impl; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.diboot.core.util.BeanUtils; import com.diboot.iam.entity.IamPermission; import com.diboot.iam.entity.IamRolePermission; @@ -61,6 +62,23 @@ public class IamRolePermissionServiceImpl extends BaseIamServiceImpl permissionIdList) { + // 删除新列表中不存在的关联记录 + this.deleteEntities( + Wrappers.lambdaQuery() + .eq(IamRolePermission::getRoleId, roleId) + ); + // 批量新增 + List rolePermissionList = new ArrayList<>(); + for(Long permissionId : permissionIdList){ + IamRolePermission rolePermission = new IamRolePermission(roleId, permissionId); + rolePermissionList.add(rolePermission); + } + return createEntities(rolePermissionList); + } + @Override public IamRoleService getRoleService() { return iamRoleService; diff --git a/iam-base-starter/src/main/java/com/diboot/iam/vo/IamRoleVO.java b/iam-base-starter/src/main/java/com/diboot/iam/vo/IamRoleVO.java index a0c6c56..2844637 100644 --- a/iam-base-starter/src/main/java/com/diboot/iam/vo/IamRoleVO.java +++ b/iam-base-starter/src/main/java/com/diboot/iam/vo/IamRoleVO.java @@ -18,7 +18,7 @@ public class IamRoleVO extends IamRole { private static final long serialVersionUID = -6778550575399070076L; // 字段关联:this.id=iam_role_permission.role_id AND iam_role_permission.permission_id=id - @BindEntityList(entity = IamPermission.class, condition = "this.id=iam_role_permission.role_id AND iam_role_permission.permission_id=id") + @BindEntityList(entity = IamPermission.class, condition = "this.id=iam_role_permission.role_id AND iam_role_permission.permission_id=id AND iam_role_permission.is_deleted=0") private List permissionList; } \ No newline at end of file