【7.1.1】【role】更新角色绑定接口,优化

pull/22/head
fengshuonan 2021-08-10 18:50:48 +08:00
parent 730d831596
commit cb6f3e9aa0
4 changed files with 68 additions and 2 deletions

View File

@ -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 {
}
/**
*
*/

View File

@ -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();
}
/**
*
*

View File

@ -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
*

View File

@ -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) {