完善iam中角色以及角色与权限关联关系的新增与更新

This commit is contained in:
Zhaoyang 2020-02-03 16:53:50 +08:00
parent 52e6b9bdf8
commit 3fe859f2c4
4 changed files with 54 additions and 1 deletions

View File

@ -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<Long> permissionIdList;
}

View File

@ -37,6 +37,14 @@ public interface IamRolePermissionService extends BaseIamService<IamRolePermissi
*/ */
boolean createRolePermissionRelations(Long roleId, List<Long> permissionIdList); boolean createRolePermissionRelations(Long roleId, List<Long> permissionIdList);
/***
* 批量更新角色与权限集的关系
* @param roleId
* @param permissionIdList
* @return
*/
boolean updateRolePermissionRelations(Long roleId, List<Long> permissionIdList);
/** /**
* 获取RoleService实例 * 获取RoleService实例
* @return * @return

View File

@ -1,5 +1,6 @@
package com.diboot.iam.service.impl; package com.diboot.iam.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.diboot.core.util.BeanUtils; import com.diboot.core.util.BeanUtils;
import com.diboot.iam.entity.IamPermission; import com.diboot.iam.entity.IamPermission;
import com.diboot.iam.entity.IamRolePermission; import com.diboot.iam.entity.IamRolePermission;
@ -61,6 +62,23 @@ public class IamRolePermissionServiceImpl extends BaseIamServiceImpl<IamRolePerm
return createEntities(rolePermissionList); return createEntities(rolePermissionList);
} }
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateRolePermissionRelations(Long roleId, List<Long> permissionIdList) {
// 删除新列表中不存在的关联记录
this.deleteEntities(
Wrappers.<IamRolePermission>lambdaQuery()
.eq(IamRolePermission::getRoleId, roleId)
);
// 批量新增
List<IamRolePermission> rolePermissionList = new ArrayList<>();
for(Long permissionId : permissionIdList){
IamRolePermission rolePermission = new IamRolePermission(roleId, permissionId);
rolePermissionList.add(rolePermission);
}
return createEntities(rolePermissionList);
}
@Override @Override
public IamRoleService getRoleService() { public IamRoleService getRoleService() {
return iamRoleService; return iamRoleService;

View File

@ -18,7 +18,7 @@ public class IamRoleVO extends IamRole {
private static final long serialVersionUID = -6778550575399070076L; private static final long serialVersionUID = -6778550575399070076L;
// 字段关联this.id=iam_role_permission.role_id AND iam_role_permission.permission_id=id // 字段关联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<IamPermission> permissionList; private List<IamPermission> permissionList;
} }