Merge remote-tracking branch 'origin/feature/REQ-1102' into feature/REQ-1102
This commit is contained in:
commit
ab57db18a2
@ -2,6 +2,8 @@ package cn.axzo.tyr.client.feign;
|
||||
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointDTO;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointListQueryRequest;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointMoveRequest;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointTreeNode;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointTreeQueryReq;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointVO;
|
||||
@ -45,11 +47,11 @@ public interface PermissionPointApi {
|
||||
ApiResult<Void> deletePermissionPoint(@PathVariable Long permissionId);
|
||||
|
||||
|
||||
/** 更新父级节点 - 直接更新不校验 **/
|
||||
@PostMapping(value = "/api/v1/permissionPoint/change/{permissionId}")
|
||||
ApiResult<Void> changeParent(@RequestParam Long updater, @PathVariable Long permissionId, @RequestParam Long newParentId);
|
||||
/** 位置移动 **/
|
||||
@PostMapping(value = "/api/v1/permissionPoint/move")
|
||||
ApiResult<Void> move(@RequestBody PermissionPointMoveRequest request);
|
||||
|
||||
/** 更改排序 **/
|
||||
@PostMapping(value = "/api/v1/permissionPoint/sort/{permissionId}")
|
||||
ApiResult<Void> updateSort(@RequestParam Long updater, @PathVariable Long permissionId, @RequestParam Integer direction);
|
||||
/** 查询权限点列表 - 不组装树形结构 **/
|
||||
@PostMapping(value = "/api/v1/permissionPoint/queryList")
|
||||
ApiResult<List<PermissionPointTreeNode>> queryList(@RequestBody PermissionPointListQueryRequest request);
|
||||
}
|
||||
|
||||
@ -30,6 +30,9 @@ public interface SaasRoleGroupApi {
|
||||
@PostMapping("/api/saasRoleGroup/getList")
|
||||
ApiResult<List<SaasRoleGroupVO>> getList(@RequestBody QuerySaasRoleGroupReq req);
|
||||
|
||||
@PostMapping("/api/saasRoleGroup/getById")
|
||||
ApiResult<SaasRoleGroupVO> getById(@RequestParam("id") Long id);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
package cn.axzo.tyr.client.model.permission;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 权限点列表查询对象
|
||||
* 按需扩展
|
||||
* @version V1.0
|
||||
* @author: ZhanSiHu
|
||||
* @date: 2023/9/12 18:51
|
||||
*/
|
||||
@Data
|
||||
public class PermissionPointListQueryRequest {
|
||||
|
||||
/**
|
||||
* 元素类别 0.模块 1.菜单 2页面 3按钮
|
||||
* 参考FeatureType
|
||||
* **/
|
||||
private Integer featureType;
|
||||
|
||||
/**
|
||||
* 权限点所属工作台
|
||||
* **/
|
||||
private String terminal;
|
||||
|
||||
/**
|
||||
* 父级权限点ID
|
||||
* **/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* path左匹配
|
||||
* **/
|
||||
private String likePath;
|
||||
}
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
package cn.axzo.tyr.client.model.permission;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 权限点移动请求
|
||||
*
|
||||
* @version V1.0
|
||||
* @author: ZhanSiHu
|
||||
* @date: 2023/9/12 15:45
|
||||
*/
|
||||
@Data
|
||||
public class PermissionPointMoveRequest {
|
||||
|
||||
/** 权限点ID **/
|
||||
@NotNull(message = "权限点ID不能为空")
|
||||
private Long permissionId;
|
||||
|
||||
/** 父级节点ID - 可为空-则parent为工作台 **/
|
||||
private Long parentId = 0L;
|
||||
|
||||
/** 排序sort **/
|
||||
@NotNull(message = "权限点排序不能为空")
|
||||
private Integer sort;
|
||||
|
||||
/** 操作人 **/
|
||||
private Long updaterId;
|
||||
}
|
||||
@ -35,6 +35,16 @@ public class QuerySaasPermissionGroupReq extends PageRequest {
|
||||
*/
|
||||
private Integer isCommon;
|
||||
|
||||
/**
|
||||
* 工作台id(过滤权限集作用范围)
|
||||
*/
|
||||
private List<Long> workspaceId;
|
||||
|
||||
/**
|
||||
* 单位id(过滤权限集作用范围)
|
||||
*/
|
||||
private List<Long> ouId;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
|
||||
@ -33,6 +33,16 @@ public class QuerySaasRoleReq {
|
||||
*/
|
||||
private List<String> ouTypeCode;
|
||||
|
||||
/**
|
||||
* 工作台id(过滤权限集作用范围)
|
||||
*/
|
||||
private List<Long> workspaceId;
|
||||
|
||||
/**
|
||||
* 单位id(过滤权限集作用范围)
|
||||
*/
|
||||
private List<Long> ouId;
|
||||
|
||||
/**
|
||||
* 分组id
|
||||
*/
|
||||
|
||||
@ -55,6 +55,7 @@ public class SaasPermissionGroupVO {
|
||||
* 权限
|
||||
*/
|
||||
private List<PermissionPointTreeNode> feature;
|
||||
|
||||
/**
|
||||
* 权限范围
|
||||
*/
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
package cn.axzo.tyr.server.common.util;
|
||||
|
||||
import cn.axzo.framework.core.enums.ErrorLevel;
|
||||
import cn.axzo.framework.core.enums.ErrorType;
|
||||
import cn.axzo.framework.domain.web.BizException;
|
||||
import cn.axzo.framework.domain.web.code.IRespCode;
|
||||
|
||||
/**
|
||||
* 抛异常工具
|
||||
*
|
||||
* @version V1.0
|
||||
* @author: ZhanSiHu
|
||||
* @date: 2023/9/12 11:25
|
||||
*/
|
||||
public class Throws {
|
||||
|
||||
/** 用于抛出请求参数类异常 **/
|
||||
public static BizException paramException(IRespCode code, String message) {
|
||||
throw new BizException(ErrorLevel.P2, ErrorType.ERROR_BUSINESS, code, message);
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,8 @@ package cn.axzo.tyr.server.controller.permission;
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.tyr.client.feign.PermissionPointApi;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointDTO;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointListQueryRequest;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointMoveRequest;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointTreeNode;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointTreeQueryReq;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointVO;
|
||||
@ -57,15 +59,15 @@ public class PermissionPointController implements PermissionPointApi {
|
||||
return ApiResult.ok();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ApiResult<Void> changeParent(Long updater, Long permissionId, Long newParentId) {
|
||||
permissionPointService.changeParent(updater, permissionId, newParentId);
|
||||
public ApiResult<Void> move(PermissionPointMoveRequest request) {
|
||||
permissionPointService.move(request);
|
||||
return ApiResult.ok();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResult<Void> updateSort(Long updater, Long permissionId, Integer direction) {
|
||||
permissionPointService.updateSort(updater, permissionId, direction);
|
||||
return ApiResult.ok();
|
||||
public ApiResult<List<PermissionPointTreeNode>> queryList(PermissionPointListQueryRequest request) {
|
||||
return ApiResult.ok(permissionPointService.queryList(request));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package cn.axzo.tyr.server.controller.role;
|
||||
|
||||
|
||||
import cn.axzo.framework.domain.web.BizException;
|
||||
import cn.axzo.framework.domain.web.code.BaseCode;
|
||||
import cn.axzo.framework.domain.web.result.ApiPageResult;
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.tyr.client.feign.SaasPermissionGroupApi;
|
||||
@ -10,8 +12,10 @@ import cn.axzo.tyr.server.repository.service.SaasPermissionGroupDao;
|
||||
import cn.axzo.tyr.server.repository.service.SaasPermissionGroupScopeDao;
|
||||
import cn.axzo.tyr.server.repository.service.SaasPgroupPermissionRelationDao;
|
||||
import cn.axzo.tyr.server.service.PermissionGroupService;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@ -34,7 +38,11 @@ public class SaasPermissionGroupController implements SaasPermissionGroupApi {
|
||||
|
||||
@Override
|
||||
public ApiResult<SaasPermissionGroupVO> getById(Long id) {
|
||||
return null;
|
||||
List<SaasPermissionGroupVO> pGroups = permissionGroupService.query(QuerySaasPermissionGroupReq.builder().ids(Lists.newArrayList(id)).build());
|
||||
if (CollectionUtils.isEmpty(pGroups)) {
|
||||
throw new BizException(BaseCode.BAD_REQUEST, "未查询到权限组信息");
|
||||
}
|
||||
return ApiResult.ok(pGroups.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
package cn.axzo.tyr.server.controller.role;
|
||||
|
||||
import cn.axzo.framework.domain.web.BizException;
|
||||
import cn.axzo.framework.domain.web.code.BaseCode;
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.tyr.client.feign.SaasRoleGroupApi;
|
||||
import cn.axzo.tyr.client.model.req.QuerySaasRoleGroupReq;
|
||||
import cn.axzo.tyr.client.model.vo.SaasRoleGroupVO;
|
||||
import cn.axzo.tyr.server.service.SaasRoleGroupService;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
@ -29,6 +33,15 @@ public class SaasRoleGroupController implements SaasRoleGroupApi {
|
||||
return ApiResult.ok(saasRoleGroupService.getList(req));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResult<SaasRoleGroupVO> getById(Long id) {
|
||||
List<SaasRoleGroupVO> roleGroups = saasRoleGroupService.getList(QuerySaasRoleGroupReq.builder().ids(Lists.newArrayList(id)).build());
|
||||
if (CollectionUtils.isEmpty(roleGroups)) {
|
||||
throw new BizException(BaseCode.BAD_REQUEST, "未查询到角色分组信息");
|
||||
}
|
||||
return ApiResult.ok(roleGroups.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResult delete(List<Long> id) {
|
||||
|
||||
|
||||
@ -37,13 +37,13 @@ public class SaasPermissionGroup extends BaseEntity<SaasPermissionGroup> {
|
||||
*/
|
||||
private Long createBy;
|
||||
|
||||
private String createName;
|
||||
private String creatorName;
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
private Long updateBy;
|
||||
|
||||
private String updateName;
|
||||
private String updatorName;
|
||||
|
||||
/**
|
||||
* 权限集类型:feature data
|
||||
|
||||
@ -22,4 +22,6 @@ public interface SaasFeatureDao extends IService<SaasFeature> {
|
||||
void updateSort(Long permissionId, int switchIndex);
|
||||
|
||||
List<SaasFeature> listLikePath(String path);
|
||||
|
||||
List<SaasFeature> listByParentIdAndTerminal(Long parentId, String terminal);
|
||||
}
|
||||
|
||||
@ -42,4 +42,11 @@ public class SaasFeatureDaoImpl extends ServiceImpl<SaasFeatureMapper, SaasFeatu
|
||||
public List<SaasFeature> listLikePath(String path) {
|
||||
return this.list(new LambdaQueryWrapper<SaasFeature>().likeRight(SaasFeature::getPath, path));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SaasFeature> listByParentIdAndTerminal(Long parentId, String terminal) {
|
||||
return this.list(new LambdaQueryWrapper<SaasFeature>()
|
||||
.eq(SaasFeature::getParentId, parentId)
|
||||
.eq(SaasFeature::getTerminal, terminal));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
package cn.axzo.tyr.server.service;
|
||||
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointDTO;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointListQueryRequest;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointMoveRequest;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointTreeNode;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointTreeQueryReq;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointVO;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasFeature;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -38,10 +39,8 @@ public interface PermissionPointService {
|
||||
/** 删除权限点 **/
|
||||
void delete(Long permissionId);
|
||||
|
||||
/** 更新父级 **/
|
||||
void changeParent(Long updater, Long permissionId,Long newParentId);
|
||||
|
||||
/** 移动排序 **/
|
||||
void updateSort(Long updater, Long permissionId, Integer direction);
|
||||
/** 位置移动-父级和排序 **/
|
||||
void move(PermissionPointMoveRequest request);
|
||||
|
||||
List<PermissionPointTreeNode> queryList(PermissionPointListQueryRequest request);
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import cn.axzo.basics.common.BeanMapper;
|
||||
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
|
||||
import cn.axzo.framework.domain.page.PageResp;
|
||||
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
|
||||
import cn.axzo.tyr.client.model.enums.PermissionScopeType;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointTreeNode;
|
||||
import cn.axzo.tyr.client.model.req.QuerySaasPermissionGroupReq;
|
||||
import cn.axzo.tyr.client.model.vo.SaasPermissionGroupVO;
|
||||
@ -99,10 +100,28 @@ public class PermissionGroupImpl implements PermissionGroupService {
|
||||
// 查询featureCode
|
||||
feature = featureService.listNodesByIds(permissionList.stream().map(SaasPgroupPermissionRelation::getFeatureId).collect(Collectors.toList()));
|
||||
}
|
||||
List<SaasPermissionGroupScope> saasPermissionGroupScopes = saasPermissionGroupScopeDao.lambdaQuery()
|
||||
List<SaasPermissionGroupScope> saasPermissionGroupScopesSource = saasPermissionGroupScopeDao.lambdaQuery()
|
||||
.in(SaasPermissionGroupScope::getPgroupId, groupIds)
|
||||
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
|
||||
.list();
|
||||
// 过滤权限集作用范围
|
||||
List<SaasPermissionGroupScope> saasPermissionGroupScopes = saasPermissionGroupScopesSource.stream().filter(e -> {
|
||||
// 过滤出选中的工作台
|
||||
if (CollectionUtils.isNotEmpty(req.getWorkspaceId())
|
||||
&& PermissionScopeType.WORKSPACE.getCode().equals(e.getScopeType())
|
||||
&& req.getWorkspaceId().contains(e.getScopeId())) {
|
||||
req.getWorkspaceId().contains(e.getScopeId());
|
||||
return true;
|
||||
}
|
||||
// 过滤出选中的单位
|
||||
if (CollectionUtils.isNotEmpty(req.getOuId())
|
||||
&& PermissionScopeType.OU.getCode().equals(e.getScopeType())
|
||||
&& req.getOuId().contains(e.getScopeId())) {
|
||||
req.getWorkspaceId().contains(e.getScopeId());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}).collect(Collectors.toList());
|
||||
// 组装填充字段
|
||||
List<PermissionPointTreeNode> finalFeature = feature;
|
||||
return groupList.stream().map(group ->
|
||||
@ -110,7 +129,7 @@ public class PermissionGroupImpl implements PermissionGroupService {
|
||||
.id(group.getId())
|
||||
.name(group.getName())
|
||||
.feature(finalFeature)
|
||||
.scopes(saasPermissionGroupScopes.stream().map(e -> BeanMapper.copyBean(e, SaasRolePermissionScopeVO.class)).collect(Collectors.toList()))
|
||||
.scopes(saasPermissionGroupScopes.stream().filter(e -> e.getPgroupId().equals(group.getId())).map(e -> BeanMapper.copyBean(e, SaasRolePermissionScopeVO.class)).collect(Collectors.toList()))
|
||||
.createBy(group.getCreateBy())
|
||||
.updateBy(group.getUpdateBy())
|
||||
.type(group.getType())
|
||||
@ -167,10 +186,28 @@ public class PermissionGroupImpl implements PermissionGroupService {
|
||||
// 查询featureCode
|
||||
feature = featureService.listNodesByIds(permissionList.stream().map(SaasPgroupPermissionRelation::getFeatureId).collect(Collectors.toList()));
|
||||
}
|
||||
List<SaasPermissionGroupScope> saasPermissionGroupScopes = saasPermissionGroupScopeDao.lambdaQuery()
|
||||
List<SaasPermissionGroupScope> saasPermissionGroupScopesSource = saasPermissionGroupScopeDao.lambdaQuery()
|
||||
.in(SaasPermissionGroupScope::getPgroupId, groupIds)
|
||||
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
|
||||
.list();
|
||||
// 过滤权限集作用范围
|
||||
List<SaasPermissionGroupScope> saasPermissionGroupScopes = saasPermissionGroupScopesSource.stream().filter(e -> {
|
||||
// 过滤出选中的工作台
|
||||
if (CollectionUtils.isNotEmpty(req.getWorkspaceId())
|
||||
&& PermissionScopeType.WORKSPACE.getCode().equals(e.getScopeType())
|
||||
&& req.getWorkspaceId().contains(e.getScopeId())) {
|
||||
req.getWorkspaceId().contains(e.getScopeId());
|
||||
return true;
|
||||
}
|
||||
// 过滤出选中的单位
|
||||
if (CollectionUtils.isNotEmpty(req.getOuId())
|
||||
&& PermissionScopeType.OU.getCode().equals(e.getScopeType())
|
||||
&& req.getOuId().contains(e.getScopeId())) {
|
||||
req.getWorkspaceId().contains(e.getScopeId());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}).collect(Collectors.toList());
|
||||
// 组装填充字段
|
||||
List<PermissionPointTreeNode> finalFeature = feature;
|
||||
List<SaasPermissionGroupVO> pageList = groupList.stream().map(group ->
|
||||
@ -178,7 +215,7 @@ public class PermissionGroupImpl implements PermissionGroupService {
|
||||
.id(group.getId())
|
||||
.name(group.getName())
|
||||
.feature(finalFeature)
|
||||
.scopes(saasPermissionGroupScopes.stream().map(e -> BeanMapper.copyBean(e, SaasRolePermissionScopeVO.class)).collect(Collectors.toList()))
|
||||
.scopes(saasPermissionGroupScopes.stream().filter(e -> e.getPgroupId().equals(group.getId())).map(e -> BeanMapper.copyBean(e, SaasRolePermissionScopeVO.class)).collect(Collectors.toList()))
|
||||
.createBy(group.getCreateBy())
|
||||
.updateBy(group.getUpdateBy())
|
||||
.type(group.getType())
|
||||
|
||||
@ -12,6 +12,8 @@ import cn.axzo.tyr.client.model.dict.response.BasicDictNodeResp;
|
||||
import cn.axzo.tyr.client.model.dict.response.BasicDictTreeResp;
|
||||
import cn.axzo.tyr.client.model.enums.FeatureType;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointDTO;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointListQueryRequest;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointMoveRequest;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointTreeNode;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointTreeQueryReq;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointVO;
|
||||
@ -30,6 +32,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -316,67 +319,92 @@ public class PermissionPointServiceImpl implements PermissionPointService {
|
||||
this.saasPgroupPermissionRelationDao.removeByPermissionPointIds(delIds);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Throwable.class)
|
||||
|
||||
@Override
|
||||
public void changeParent(Long updater, Long permissionId, Long newParentId) {
|
||||
SaasFeature feature = this.saasFeatureDao.getById(permissionId);
|
||||
if (Objects.equals(feature.getParentId(), newParentId)) {
|
||||
//父级未变
|
||||
return;
|
||||
}
|
||||
SaasFeature parent = this.saasFeatureDao.getById(newParentId);
|
||||
if (!StrUtil.equals(feature.getTerminal(), parent.getTerminal())) {
|
||||
throw new BizException(BaseCode.BAD_REQUEST, "不允许跨工作台");
|
||||
}
|
||||
if (parent.getPath().contains(String.valueOf(permissionId))) {
|
||||
throw new BizException(BaseCode.BAD_REQUEST, "不允许移到子级");
|
||||
}
|
||||
//当前节点
|
||||
SaasFeature entity = new SaasFeature();
|
||||
entity.setId(feature.getId());
|
||||
entity.setParentId(newParentId);
|
||||
entity.setParentBusinessNo(parent.getBusinessNo());
|
||||
entity.setPath(parent.getPath() + parent.getId() + FEATURE_PATH_DELIMITER);
|
||||
entity.setUpdateBy(updater);
|
||||
this.saasFeatureDao.updateById(entity);
|
||||
//更新子级path
|
||||
this.saasFeatureDao.updateChildrenPath(updater, feature.getPath() + feature.getId() + FEATURE_PATH_DELIMITER,
|
||||
entity.getPath() + entity.getId() + FEATURE_PATH_DELIMITER);
|
||||
public void move(PermissionPointMoveRequest request) {
|
||||
SaasFeature feature = getAndCheck(request.getPermissionId());
|
||||
changeParent(feature, request);
|
||||
changeSort(feature, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSort(Long updater, Long permissionId, Integer direction) {
|
||||
//查询当前节点和所有同级节点
|
||||
SaasFeature feature = this.saasFeatureDao.getById(permissionId);
|
||||
List<SaasFeature> children = this.saasFeatureDao.listByParentId(feature.getParentId());
|
||||
List<SaasFeature> sortedChildren = children.stream()
|
||||
.sorted(Comparator.comparing(SaasFeature::getSort))
|
||||
public List<PermissionPointTreeNode> queryList(PermissionPointListQueryRequest request) {
|
||||
|
||||
LambdaQueryWrapper<SaasFeature> wrapper = new LambdaQueryWrapper<SaasFeature>()
|
||||
.eq(Objects.nonNull(request.getTerminal()), SaasFeature::getTerminal, request.getTerminal())
|
||||
.eq(Objects.nonNull(request.getFeatureType()), SaasFeature::getFeatureType, request.getFeatureType())
|
||||
.eq(Objects.nonNull(request.getParentId()), SaasFeature::getParentId, request.getParentId())
|
||||
.likeRight(Objects.nonNull(request.getLikePath()), SaasFeature::getPath, request.getLikePath());
|
||||
|
||||
return this.saasFeatureDao.list(wrapper)
|
||||
.stream()
|
||||
.map(this::feature2Node)
|
||||
.collect(Collectors.toList());
|
||||
//确认当前节点index
|
||||
Integer index = sortedChildren.stream()
|
||||
.filter(x -> x.getId().equals(permissionId))
|
||||
.map(sortedChildren::indexOf)
|
||||
.findFirst().get();
|
||||
int switchIndex = 0;
|
||||
if (direction > 0) {
|
||||
//向上
|
||||
if (index == 0) {
|
||||
//已经是第一个
|
||||
return;
|
||||
}
|
||||
switchIndex = index - 1;
|
||||
} else {
|
||||
//向下
|
||||
if (index == sortedChildren.size() - 1) {
|
||||
//已经最后一个
|
||||
return;
|
||||
}
|
||||
switchIndex = index + 1;
|
||||
}
|
||||
|
||||
private void changeSort(SaasFeature feature, PermissionPointMoveRequest request) {
|
||||
//原parent下节点排序会有缺失但无影响-不处理
|
||||
//同terminal 同级节点
|
||||
List<SaasFeature> saasFeatures = this.saasFeatureDao.listByParentIdAndTerminal(request.getParentId(),
|
||||
feature.getTerminal());
|
||||
//记录排序
|
||||
Map<Long, Integer> sortMap = new HashMap<>();
|
||||
//插入指定位置
|
||||
sortMap.put(request.getPermissionId(), request.getSort());
|
||||
//找到需要更新排序其他节点
|
||||
AtomicInteger sort = new AtomicInteger(0);
|
||||
Integer targetSort = request.getSort();
|
||||
saasFeatures.stream()
|
||||
.sorted(Comparator.comparing(SaasFeature::getSort))
|
||||
.forEach(x -> {
|
||||
//跳过自己
|
||||
if (!x.getId().equals(request.getPermissionId())) {
|
||||
//记录位置
|
||||
sort.incrementAndGet();
|
||||
if (targetSort.equals(sort.get())) {
|
||||
//找到指定位置,当前节点需要移动到下一位置
|
||||
sort.incrementAndGet();
|
||||
}
|
||||
if (!x.getSort().equals(sort.get())) {
|
||||
// 排序需要修正
|
||||
sortMap.put(x.getId(), sort.get());
|
||||
}
|
||||
}
|
||||
});
|
||||
//执行更新 - 有一定性能问题
|
||||
for (Map.Entry<Long, Integer> entry : sortMap.entrySet()) {
|
||||
this.saasFeatureDao.updateSort(entry.getKey(), entry.getValue());
|
||||
}
|
||||
//更新当前节点
|
||||
this.saasFeatureDao.updateSort(permissionId, switchIndex);
|
||||
//更新交换节点
|
||||
this.saasFeatureDao.updateSort(sortedChildren.get(switchIndex).getId(), index);
|
||||
}
|
||||
|
||||
private void changeParent(SaasFeature feature, PermissionPointMoveRequest request) {
|
||||
Long parentId = request.getParentId();
|
||||
if (Objects.equals(feature.getParentId(), parentId)) {
|
||||
//父级未变
|
||||
return;
|
||||
}
|
||||
SaasFeature parent = null;
|
||||
if (parentId != 0) {
|
||||
parent = this.saasFeatureDao.getById(parentId);
|
||||
if (!StrUtil.equals(feature.getTerminal(), parent.getTerminal())) {
|
||||
throw new BizException(BaseCode.BAD_REQUEST, "不允许跨工作台");
|
||||
}
|
||||
if (parent.getPath().contains(String.valueOf(request.getPermissionId()))) {
|
||||
throw new BizException(BaseCode.BAD_REQUEST, "不允许移到子级");
|
||||
}
|
||||
}
|
||||
|
||||
//当前节点更新
|
||||
SaasFeature entity = new SaasFeature();
|
||||
entity.setId(feature.getId());
|
||||
entity.setParentId(parentId);
|
||||
entity.setParentBusinessNo(parent == null ? "0" : parent.getBusinessNo());
|
||||
entity.setPath(parent == null ? FEATURE_TOP_PATH : parent.getPath() + parent.getId() + FEATURE_PATH_DELIMITER);
|
||||
entity.setUpdateBy(request.getUpdaterId());
|
||||
this.saasFeatureDao.updateById(entity);
|
||||
//更新子级path
|
||||
this.saasFeatureDao.updateChildrenPath(request.getUpdaterId(), feature.getPath() + feature.getId() + FEATURE_PATH_DELIMITER,
|
||||
entity.getPath() + entity.getId() + FEATURE_PATH_DELIMITER);
|
||||
}
|
||||
|
||||
private PermissionPointTreeNode feature2Node(SaasFeature feature) {
|
||||
|
||||
@ -56,7 +56,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
if (CollectionUtils.isEmpty(roleIds)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return getByIds(roleIds, null);
|
||||
return getByIds(roleIds, null, null,null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,7 +64,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<SaasRoleVO> getByIds(List<Long> roleIds, Integer isCommon) {
|
||||
public List<SaasRoleVO> getByIds(List<Long> roleIds, Integer isCommon, List<Long> workspaceId, List<Long> ouId) {
|
||||
if (CollectionUtils.isEmpty(roleIds)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@ -79,9 +79,12 @@ public class RoleServiceImpl implements RoleService {
|
||||
// 转map<roleId,relation>
|
||||
pgrouRelationMap = saasPgroupRoleRelations.stream().collect(Collectors.groupingBy(SaasPgroupRoleRelation::getRoleId));
|
||||
// 查询权限集
|
||||
pGroupMap = permissionGroupService.query(QuerySaasPermissionGroupReq.builder().isCommon(isCommon)
|
||||
.ids(saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList()))
|
||||
.build())
|
||||
pGroupMap = permissionGroupService.query(QuerySaasPermissionGroupReq.builder()
|
||||
.isCommon(isCommon)
|
||||
.ids(saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList()))
|
||||
.workspaceId(workspaceId)
|
||||
.ouId(ouId)
|
||||
.build())
|
||||
// 转map<pgroupId>
|
||||
.stream().collect(Collectors.groupingBy(SaasPermissionGroupVO::getId));
|
||||
}
|
||||
@ -142,7 +145,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
.eq(StringUtils.isNotBlank(req.getRoleType()), SaasRole::getRoleType, req.getRoleType())
|
||||
.orderByDesc(BaseEntity::getId)
|
||||
.list();
|
||||
return getByIds(list.stream().map(BaseEntity::getId).collect(Collectors.toList()), req.getIsCommon());
|
||||
return getByIds(list.stream().map(BaseEntity::getId).collect(Collectors.toList()), req.getIsCommon(),req.getWorkspaceId(),req.getOuId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package cn.axzo.tyr.server.permission;
|
||||
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.tyr.client.model.enums.FeatureType;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointDTO;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointListQueryRequest;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointMoveRequest;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointTreeNode;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointTreeQueryReq;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointVO;
|
||||
@ -99,27 +102,30 @@ public class PermissionPointTest {
|
||||
controller.savePermissionPoint(permissionPoint);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSort() {
|
||||
//老数据可能会导致位置不对
|
||||
Long updater = 111L;
|
||||
Long permissionId = 3478L;
|
||||
Integer direction = 1;
|
||||
controller.updateSort(updater, permissionId, direction);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChangeParent() {
|
||||
Long updater = 111L;
|
||||
Long permissionId = 360L;
|
||||
Long newParentId = 354L;
|
||||
controller.changeParent(updater, permissionId, newParentId);
|
||||
public void testMove() {
|
||||
PermissionPointMoveRequest request = new PermissionPointMoveRequest();
|
||||
request.setPermissionId(360L);
|
||||
request.setParentId(354L);
|
||||
request.setSort(1);
|
||||
ApiResult<Void> result = controller.move(request);
|
||||
System.out.println(JSON.toJSONString(result));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDelete() {
|
||||
Long permissionId = 360L;
|
||||
controller.deletePermissionPoint(permissionId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryList() {
|
||||
PermissionPointListQueryRequest request = new PermissionPointListQueryRequest();
|
||||
request.setFeatureType(FeatureType.BUTTON.getCode());
|
||||
ApiResult<List<PermissionPointTreeNode>> result = controller.queryList(request);
|
||||
System.out.println(JSON.toJSONString(result));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user