mirror of https://gitee.com/stylefeng/roses
【7.1.1】【role】更新角色绑定接口,优化
parent
730d831596
commit
cb6f3e9aa0
|
@ -49,7 +49,7 @@ public class SysRoleRequest extends BaseRequest {
|
|||
/**
|
||||
* 主键
|
||||
*/
|
||||
@NotNull(message = "roleId不能为空", groups = {edit.class, delete.class, detail.class, updateStatus.class, grantResource.class, grantDataScope.class, grantMenuButton.class})
|
||||
@NotNull(message = "roleId不能为空", groups = {edit.class, delete.class, detail.class, updateStatus.class, grantResource.class, grantResourceV2.class, grantDataScope.class, grantMenuButton.class})
|
||||
@ChineseDescription("主键")
|
||||
private Long roleId;
|
||||
|
||||
|
@ -120,6 +120,18 @@ public class SysRoleRequest extends BaseRequest {
|
|||
@ChineseDescription("授权资源")
|
||||
private List<String> grantResourceList;
|
||||
|
||||
/**
|
||||
* 授权资源,模块组包含的所有资源
|
||||
*/
|
||||
@ChineseDescription("授权资源,模块组包含的所有资源")
|
||||
private List<String> modularTotalResource;
|
||||
|
||||
/**
|
||||
* 授权资源,模块组选中的资源
|
||||
*/
|
||||
@ChineseDescription("授权资源,模块组选中的资源")
|
||||
private List<String> selectedResource;
|
||||
|
||||
/**
|
||||
* 授权数据
|
||||
*/
|
||||
|
@ -154,6 +166,13 @@ public class SysRoleRequest extends BaseRequest {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数校验分组:授权资源
|
||||
*/
|
||||
public @interface grantResourceV2 {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数校验分组:授权数据
|
||||
*/
|
||||
|
|
|
@ -128,6 +128,18 @@ public class SysRoleController {
|
|||
return new SuccessResponseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色绑定接口数据
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/8/10 18:23
|
||||
*/
|
||||
@PostResource(name = "角色绑定接口数据V2", path = "/sysRole/grantResourceV2")
|
||||
public ResponseData grantResourceV2(@RequestBody @Validated(SysRoleRequest.grantResourceV2.class) SysRoleRequest sysRoleRequest) {
|
||||
sysRoleResourceService.grantResourceV2(sysRoleRequest);
|
||||
return new SuccessResponseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色授权菜单和按钮
|
||||
*
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.system.modular.role.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRoleResource;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.role.request.SysRoleRequest;
|
||||
import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRoleResource;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -47,6 +47,14 @@ public interface SysRoleResourceService extends IService<SysRoleResource> {
|
|||
*/
|
||||
void grantResource(SysRoleRequest sysRoleRequest);
|
||||
|
||||
/**
|
||||
* 角色授权接口资源
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/8/10 18:28
|
||||
*/
|
||||
void grantResourceV2(SysRoleRequest sysRoleRequest);
|
||||
|
||||
/**
|
||||
* 根据资源id集合删除角色关联的资源
|
||||
*
|
||||
|
|
|
@ -24,12 +24,14 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.system.modular.role.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.role.request.SysRoleRequest;
|
||||
import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRoleResource;
|
||||
import cn.stylefeng.roses.kernel.system.modular.role.mapper.SysRoleResourceMapper;
|
||||
import cn.stylefeng.roses.kernel.system.modular.role.service.SysRoleResourceService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -79,6 +81,31 @@ public class SysRoleResourceServiceImpl extends ServiceImpl<SysRoleResourceMappe
|
|||
this.saveBatch(sysRoleResources);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void grantResourceV2(SysRoleRequest sysRoleRequest) {
|
||||
// 先将该业务下,模块下的所有资源删除掉
|
||||
List<String> modularTotalResource = sysRoleRequest.getModularTotalResource();
|
||||
if (ObjectUtil.isNotEmpty(modularTotalResource)) {
|
||||
LambdaUpdateWrapper<SysRoleResource> wrapper = new LambdaUpdateWrapper<>();
|
||||
wrapper.in(SysRoleResource::getResourceCode, modularTotalResource);
|
||||
wrapper.eq(SysRoleResource::getRoleId, sysRoleRequest.getRoleId());
|
||||
this.remove(wrapper);
|
||||
}
|
||||
|
||||
// 再将该业务下,需要绑定的资源添加上
|
||||
List<String> selectedResource = sysRoleRequest.getSelectedResource();
|
||||
if (ObjectUtil.isNotEmpty(selectedResource)) {
|
||||
ArrayList<SysRoleResource> menuResources = new ArrayList<>();
|
||||
for (String resourceCode : selectedResource) {
|
||||
SysRoleResource sysRoleResource = new SysRoleResource();
|
||||
sysRoleResource.setRoleId(sysRoleRequest.getRoleId());
|
||||
sysRoleResource.setResourceCode(resourceCode);
|
||||
menuResources.add(sysRoleResource);
|
||||
}
|
||||
this.saveBatch(menuResources, menuResources.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteRoleResourceListByResourceIds(List<Long> resourceIds) {
|
||||
|
|
Loading…
Reference in New Issue