mirror of https://gitee.com/stylefeng/roses
【SysRoleDataScope】优化
parent
5130d2503c
commit
f5f5f177cb
|
@ -0,0 +1,22 @@
|
||||||
|
package cn.stylefeng.roses.kernel.system;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统角色数据范围service接口实现类
|
||||||
|
*
|
||||||
|
* @author chenjinlong
|
||||||
|
* @date 2021/2/4 16:01
|
||||||
|
*/
|
||||||
|
public interface RoleDataScopeServiceApi {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据机构id集合删除
|
||||||
|
*
|
||||||
|
* @param orgIds 结构id集合
|
||||||
|
* @return
|
||||||
|
* @author chenjinlong
|
||||||
|
* @date 2021/2/4 15:56
|
||||||
|
*/
|
||||||
|
void delByOrgIds(Set<Long> orgIds);
|
||||||
|
}
|
|
@ -16,15 +16,6 @@ import java.util.Set;
|
||||||
*/
|
*/
|
||||||
public interface RoleServiceApi {
|
public interface RoleServiceApi {
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除角色关联的组织架构数据范围
|
|
||||||
*
|
|
||||||
* @param organizationIds 组织架构id集合
|
|
||||||
* @author fengshuonan
|
|
||||||
* @date 2020/11/5 19:17
|
|
||||||
*/
|
|
||||||
void deleteRoleDataScopeListByOrgIdList(Set<Long> organizationIds);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取角色,通过传递角色id列表
|
* 获取角色,通过传递角色id列表
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package cn.stylefeng.roses.kernel.system.pojo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色数据范围
|
||||||
|
*
|
||||||
|
* @author chenjinlong
|
||||||
|
* @date 2021/2/4 15:17
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class SysRoleDataScopeRequest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
private Long roleDataScopeId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色id
|
||||||
|
*/
|
||||||
|
private Long roleId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 机构id
|
||||||
|
*/
|
||||||
|
private Long organizationId;
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||||
import cn.stylefeng.roses.kernel.rule.factory.DefaultTreeBuildFactory;
|
import cn.stylefeng.roses.kernel.rule.factory.DefaultTreeBuildFactory;
|
||||||
import cn.stylefeng.roses.kernel.rule.pojo.tree.DefaultTreeNode;
|
import cn.stylefeng.roses.kernel.rule.pojo.tree.DefaultTreeNode;
|
||||||
import cn.stylefeng.roses.kernel.rule.pojo.ztree.ZTreeNode;
|
import cn.stylefeng.roses.kernel.rule.pojo.ztree.ZTreeNode;
|
||||||
|
import cn.stylefeng.roses.kernel.system.RoleDataScopeServiceApi;
|
||||||
import cn.stylefeng.roses.kernel.system.RoleServiceApi;
|
import cn.stylefeng.roses.kernel.system.RoleServiceApi;
|
||||||
import cn.stylefeng.roses.kernel.system.UserOrgServiceApi;
|
import cn.stylefeng.roses.kernel.system.UserOrgServiceApi;
|
||||||
import cn.stylefeng.roses.kernel.system.UserServiceApi;
|
import cn.stylefeng.roses.kernel.system.UserServiceApi;
|
||||||
|
@ -62,6 +63,9 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
||||||
@Resource
|
@Resource
|
||||||
private UserServiceApi userServiceApi;
|
private UserServiceApi userServiceApi;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RoleDataScopeServiceApi roleDataScopeServiceApi;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(HrOrganizationRequest hrOrganizationRequest) {
|
public void add(HrOrganizationRequest hrOrganizationRequest) {
|
||||||
|
|
||||||
|
@ -129,7 +133,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
||||||
this.update(updateWrapper);
|
this.update(updateWrapper);
|
||||||
|
|
||||||
// 删除角色对应的组织架构数据范围
|
// 删除角色对应的组织架构数据范围
|
||||||
roleServiceApi.deleteRoleDataScopeListByOrgIdList(childIdList);
|
roleDataScopeServiceApi.delByOrgIds(childIdList);
|
||||||
|
|
||||||
// 删除用户对应的组织架构数据范围
|
// 删除用户对应的组织架构数据范围
|
||||||
userServiceApi.deleteUserDataScopeListByOrgIdList(childIdList);
|
userServiceApi.deleteUserDataScopeListByOrgIdList(childIdList);
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package cn.stylefeng.roses.kernel.role.modular.service;
|
package cn.stylefeng.roses.kernel.role.modular.service;
|
||||||
|
|
||||||
import cn.stylefeng.roses.kernel.role.modular.entity.SysRoleDataScope;
|
import cn.stylefeng.roses.kernel.role.modular.entity.SysRoleDataScope;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import cn.stylefeng.roses.kernel.system.pojo.SysRoleDataScopeRequest;
|
||||||
import cn.stylefeng.roses.kernel.system.pojo.role.request.SysRoleRequest;
|
import cn.stylefeng.roses.kernel.system.pojo.role.request.SysRoleRequest;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统角色数据范围service接口
|
* 系统角色数据范围service接口
|
||||||
|
@ -34,22 +34,61 @@ public interface SysRoleDataScopeService extends IService<SysRoleDataScope> {
|
||||||
*/
|
*/
|
||||||
List<Long> getRoleDataScopeIdList(List<Long> roleIdList);
|
List<Long> getRoleDataScopeIdList(List<Long> roleIdList);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据机构id集合删除对应的角色-数据范围关联信息
|
|
||||||
*
|
|
||||||
* @param orgIdList 机构id集合
|
|
||||||
* @author majianguo
|
|
||||||
* @date 2020/11/5 上午11:21
|
|
||||||
*/
|
|
||||||
void deleteRoleDataScopeListByOrgIdList(Set<Long> orgIdList);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色id删除对应的角色-数据范围关联信息
|
* 新增
|
||||||
|
*
|
||||||
|
* @param sysRoleDataScopeRequest 参数对象
|
||||||
|
* @author chenjinlong
|
||||||
|
* @date 2021/1/26 12:52
|
||||||
|
*/
|
||||||
|
void add(SysRoleDataScopeRequest sysRoleDataScopeRequest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*
|
||||||
|
* @param sysRoleDataScopeRequest 参数对象
|
||||||
|
* @author chenjinlong
|
||||||
|
* @date 2021/1/26 12:52
|
||||||
|
*/
|
||||||
|
void del(SysRoleDataScopeRequest sysRoleDataScopeRequest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据角色id 删除角色数据范围
|
||||||
*
|
*
|
||||||
* @param roleId 角色id
|
* @param roleId 角色id
|
||||||
* @author majianguo
|
* @author chenjinlong
|
||||||
* @date 2020/11/5 上午11:21
|
* @date 2021/1/26 12:52
|
||||||
*/
|
*/
|
||||||
void deleteRoleDataScopeListByRoleId(Long roleId);
|
void delByRoleId(Long roleId);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*
|
||||||
|
* @param sysRoleDataScopeRequest 参数对象
|
||||||
|
* @author chenjinlong
|
||||||
|
* @date 2021/1/26 12:52
|
||||||
|
*/
|
||||||
|
void edit(SysRoleDataScopeRequest sysRoleDataScopeRequest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询-详情
|
||||||
|
*
|
||||||
|
* @param sysRoleDataScopeRequest 参数对象
|
||||||
|
* @author chenjinlong
|
||||||
|
* @date 2021/1/26 12:52
|
||||||
|
*/
|
||||||
|
SysRoleDataScope detail(SysRoleDataScopeRequest sysRoleDataScopeRequest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询-列表
|
||||||
|
*
|
||||||
|
* @param sysRoleDataScopeRequest 参数对象
|
||||||
|
* @author chenjinlong
|
||||||
|
* @date 2021/1/26 12:52
|
||||||
|
*/
|
||||||
|
List<SysRoleDataScope> findList(SysRoleDataScopeRequest sysRoleDataScopeRequest);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,19 +24,22 @@ Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意
|
||||||
*/
|
*/
|
||||||
package cn.stylefeng.roses.kernel.role.modular.service.impl;
|
package cn.stylefeng.roses.kernel.role.modular.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.stylefeng.roses.kernel.role.modular.entity.SysRoleDataScope;
|
import cn.stylefeng.roses.kernel.role.modular.entity.SysRoleDataScope;
|
||||||
import cn.stylefeng.roses.kernel.role.modular.mapper.SysRoleDataScopeMapper;
|
import cn.stylefeng.roses.kernel.role.modular.mapper.SysRoleDataScopeMapper;
|
||||||
import cn.stylefeng.roses.kernel.role.modular.service.SysRoleDataScopeService;
|
import cn.stylefeng.roses.kernel.role.modular.service.SysRoleDataScopeService;
|
||||||
|
import cn.stylefeng.roses.kernel.system.RoleDataScopeServiceApi;
|
||||||
|
import cn.stylefeng.roses.kernel.system.pojo.SysRoleDataScopeRequest;
|
||||||
import cn.stylefeng.roses.kernel.system.pojo.role.request.SysRoleRequest;
|
import cn.stylefeng.roses.kernel.system.pojo.role.request.SysRoleRequest;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统角色数据范围service接口实现类
|
* 系统角色数据范围service接口实现类
|
||||||
|
@ -45,53 +48,106 @@ import java.util.Set;
|
||||||
* @date 2020/11/5 下午4:32
|
* @date 2020/11/5 下午4:32
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class SysRoleDataScopeServiceImpl extends ServiceImpl<SysRoleDataScopeMapper, SysRoleDataScope> implements SysRoleDataScopeService {
|
public class SysRoleDataScopeServiceImpl extends ServiceImpl<SysRoleDataScopeMapper, SysRoleDataScope> implements SysRoleDataScopeService, RoleDataScopeServiceApi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void grantDataScope(SysRoleRequest sysRoleParam) {
|
public void grantDataScope(SysRoleRequest sysRoleParam) {
|
||||||
Long roleId = sysRoleParam.getRoleId();
|
Long roleId = sysRoleParam.getRoleId();
|
||||||
|
|
||||||
LambdaQueryWrapper<SysRoleDataScope> queryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
queryWrapper.eq(SysRoleDataScope::getRoleId, roleId);
|
|
||||||
|
|
||||||
// 删除所拥该角色已绑定的范围
|
// 删除所拥该角色已绑定的范围
|
||||||
this.remove(queryWrapper);
|
this.delByRoleId(roleId);
|
||||||
|
|
||||||
// 授权该角色数据范围
|
// 批量新增-授权该角色数据范围
|
||||||
if (ObjectUtil.isNotEmpty(sysRoleParam.getGrantOrgIdList())) {
|
if (ObjectUtil.isNotEmpty(sysRoleParam.getGrantOrgIdList())) {
|
||||||
|
List<SysRoleDataScope> sysRoleDataScopeList = CollUtil.newArrayList();
|
||||||
sysRoleParam.getGrantOrgIdList().forEach(orgId -> {
|
sysRoleParam.getGrantOrgIdList().forEach(orgId -> {
|
||||||
SysRoleDataScope sysRoleDataScope = new SysRoleDataScope();
|
SysRoleDataScope sysRoleDataScope = new SysRoleDataScope();
|
||||||
sysRoleDataScope.setRoleId(roleId);
|
sysRoleDataScope.setRoleId(roleId);
|
||||||
sysRoleDataScope.setOrganizationId(orgId);
|
sysRoleDataScope.setOrganizationId(orgId);
|
||||||
this.save(sysRoleDataScope);
|
sysRoleDataScopeList.add(sysRoleDataScope);
|
||||||
});
|
});
|
||||||
|
this.saveBatch(sysRoleDataScopeList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Long> getRoleDataScopeIdList(List<Long> roleIdList) {
|
public List<Long> getRoleDataScopeIdList(List<Long> roleIdList) {
|
||||||
List<Long> resultList = CollectionUtil.newArrayList();
|
LambdaQueryWrapper<SysRoleDataScope> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
if (ObjectUtil.isNotEmpty(roleIdList)) {
|
queryWrapper.in(SysRoleDataScope::getRoleId, roleIdList);
|
||||||
LambdaQueryWrapper<SysRoleDataScope> queryWrapper = new LambdaQueryWrapper<>();
|
return this.list(queryWrapper).stream().map(SysRoleDataScope::getOrganizationId).collect(Collectors.toList());
|
||||||
queryWrapper.in(SysRoleDataScope::getRoleId, roleIdList);
|
}
|
||||||
this.list(queryWrapper).forEach(sysRoleDataScope -> resultList.add(sysRoleDataScope.getOrganizationId()));
|
|
||||||
}
|
|
||||||
return resultList;
|
@Override
|
||||||
|
public void add(SysRoleDataScopeRequest sysRoleDataScopeRequest) {
|
||||||
|
SysRoleDataScope sysRoleDataScope = new SysRoleDataScope();
|
||||||
|
BeanUtil.copyProperties(sysRoleDataScopeRequest, sysRoleDataScope);
|
||||||
|
this.save(sysRoleDataScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
public void del(SysRoleDataScopeRequest sysRoleDataScopeRequest) {
|
||||||
public void deleteRoleDataScopeListByOrgIdList(Set<Long> orgIdList) {
|
SysRoleDataScope sysRoleDataScope = this.querySysRoleDataScopeById(sysRoleDataScopeRequest);
|
||||||
|
this.removeById(sysRoleDataScope.getRoleDataScopeId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delByRoleId(Long roleId) {
|
||||||
|
SysRoleDataScopeRequest sysRoleDataScopeRequest = new SysRoleDataScopeRequest();
|
||||||
|
sysRoleDataScopeRequest.setRoleId(roleId);
|
||||||
|
this.remove(this.createQueryWrapper(sysRoleDataScopeRequest));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delByOrgIds(Set<Long> orgIds) {
|
||||||
LambdaQueryWrapper<SysRoleDataScope> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysRoleDataScope> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.in(SysRoleDataScope::getOrganizationId, orgIdList);
|
queryWrapper.in(SysRoleDataScope::getOrganizationId, orgIds);
|
||||||
this.remove(queryWrapper);
|
this.remove(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
public void edit(SysRoleDataScopeRequest sysRoleDataScopeRequest) {
|
||||||
public void deleteRoleDataScopeListByRoleId(Long roleId) {
|
SysRoleDataScope sysRoleDataScope = this.querySysRoleDataScopeById(sysRoleDataScopeRequest);
|
||||||
|
BeanUtil.copyProperties(sysRoleDataScopeRequest, sysRoleDataScope);
|
||||||
|
this.updateById(sysRoleDataScope);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysRoleDataScope detail(SysRoleDataScopeRequest sysRoleDataScopeRequest) {
|
||||||
|
return this.getOne(this.createQueryWrapper(sysRoleDataScopeRequest), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysRoleDataScope> findList(SysRoleDataScopeRequest sysRoleDataScopeRequest) {
|
||||||
|
return this.list(this.createQueryWrapper(sysRoleDataScopeRequest));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据主键查询
|
||||||
|
*
|
||||||
|
* @param sysRoleDataScopeRequest dto实体
|
||||||
|
* @author chenjinlong
|
||||||
|
* @date 2021/2/3 15:02
|
||||||
|
*/
|
||||||
|
private SysRoleDataScope querySysRoleDataScopeById(SysRoleDataScopeRequest sysRoleDataScopeRequest) {
|
||||||
|
return this.getById(sysRoleDataScopeRequest.getRoleDataScopeId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建 QueryWrapper
|
||||||
|
*
|
||||||
|
* @param sysRoleDataScopeRequest dto实体
|
||||||
|
* @author chenjinlong
|
||||||
|
* @date 2021/2/3 14:54
|
||||||
|
*/
|
||||||
|
private LambdaQueryWrapper<SysRoleDataScope> createQueryWrapper(SysRoleDataScopeRequest sysRoleDataScopeRequest) {
|
||||||
LambdaQueryWrapper<SysRoleDataScope> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysRoleDataScope> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(SysRoleDataScope::getRoleId, roleId);
|
// SQL拼接
|
||||||
this.remove(queryWrapper);
|
queryWrapper.eq(ObjectUtil.isNotNull(sysRoleDataScopeRequest.getRoleDataScopeId()), SysRoleDataScope::getRoleDataScopeId, sysRoleDataScopeRequest.getRoleDataScopeId());
|
||||||
|
queryWrapper.eq(ObjectUtil.isNotNull(sysRoleDataScopeRequest.getRoleId()), SysRoleDataScope::getRoleId, sysRoleDataScopeRequest.getRoleId());
|
||||||
|
queryWrapper.eq(ObjectUtil.isNotNull(sysRoleDataScopeRequest.getOrganizationId()), SysRoleDataScope::getOrganizationId, sysRoleDataScopeRequest.getOrganizationId());
|
||||||
|
|
||||||
|
return queryWrapper;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,16 +124,16 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||||
|
|
||||||
this.updateById(sysRole);
|
this.updateById(sysRole);
|
||||||
|
|
||||||
Long id = sysRole.getRoleId();
|
Long roleId = sysRole.getRoleId();
|
||||||
|
|
||||||
// 级联删除该角色对应的角色-数据范围关联信息
|
// 级联删除该角色对应的角色-数据范围关联信息
|
||||||
sysRoleDataScopeService.deleteRoleDataScopeListByRoleId(id);
|
sysRoleDataScopeService.delByRoleId(roleId);
|
||||||
|
|
||||||
// 级联删除该角色对应的用户-角色表关联信息
|
// 级联删除该角色对应的用户-角色表关联信息
|
||||||
userServiceApi.deleteUserRoleListByRoleId(id);
|
userServiceApi.deleteUserRoleListByRoleId(roleId);
|
||||||
|
|
||||||
// 级联删除该角色对应的角色-菜单表关联信息
|
// 级联删除该角色对应的角色-菜单表关联信息
|
||||||
sysRoleResourceService.deleteRoleResourceListByRoleId(id);
|
sysRoleResourceService.deleteRoleResourceListByRoleId(roleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -319,11 +319,6 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteRoleDataScopeListByOrgIdList(Set<Long> organizationIds) {
|
|
||||||
sysRoleDataScopeService.deleteRoleDataScopeListByOrgIdList(organizationIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysRoleResponse> getRolesByIds(List<Long> roleIds) {
|
public List<SysRoleResponse> getRolesByIds(List<Long> roleIds) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue