报错处理
This commit is contained in:
parent
045c1f8db6
commit
d1c7059e6d
@ -10,7 +10,7 @@ import java.util.Map;
|
||||
@AllArgsConstructor
|
||||
public enum PermissionGroupType {
|
||||
COMMON(1, "通用"),
|
||||
Special (0, "例外"),
|
||||
SPECIAL(0, "例外"),
|
||||
;
|
||||
|
||||
private Integer code;
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
package cn.axzo.tyr.client.model.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum PermissionScope {
|
||||
INCLUDE(1, "正选"),
|
||||
EXCLUDE (2, "反选"),
|
||||
;
|
||||
|
||||
private Integer code;
|
||||
private String desc;
|
||||
|
||||
private static final Map<Integer, PermissionScope> MAPPING = new HashMap<>();
|
||||
static {
|
||||
for (PermissionScope type : PermissionScope.values()) {
|
||||
MAPPING.put(type.code, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static PermissionScope apply(Integer code) {
|
||||
return code == null ? null :MAPPING.get(code);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package cn.axzo.tyr.client.model.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum PermissionScopeType {
|
||||
WORKSPACE("workspace", "项目部"),
|
||||
OU ("ou", "单位"),
|
||||
;
|
||||
|
||||
private String code;
|
||||
private String desc;
|
||||
|
||||
private static final Map<String, PermissionScopeType> MAPPING = new HashMap<>();
|
||||
static {
|
||||
for (PermissionScopeType type : PermissionScopeType.values()) {
|
||||
MAPPING.put(type.code, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static PermissionScopeType apply(Integer code) {
|
||||
return code == null ? null :MAPPING.get(code);
|
||||
}
|
||||
}
|
||||
@ -46,9 +46,18 @@ public class SaasPermissionGroupVO {
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 是否为通用权限集 1:是 0:否
|
||||
*/
|
||||
private Integer isCommon;
|
||||
|
||||
/**
|
||||
* 权限
|
||||
*/
|
||||
private List<PermissionPointTreeNode> feature;
|
||||
/**
|
||||
* 权限范围
|
||||
*/
|
||||
private List<SaasRolePermissionScopeVO> scopes;
|
||||
|
||||
}
|
||||
|
||||
@ -14,6 +14,8 @@ public class SaasRolePermissionScopeVO {
|
||||
|
||||
private Long id;
|
||||
|
||||
private Long pgroupId;
|
||||
|
||||
/**
|
||||
* 选择类型: 1.正选 2.反选
|
||||
*/
|
||||
|
||||
@ -36,11 +36,15 @@ public class SaasPermissionGroup extends BaseEntity<SaasPermissionGroup> {
|
||||
* 创建者
|
||||
*/
|
||||
private Long createBy;
|
||||
|
||||
private String createName;
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
private Long updateBy;
|
||||
|
||||
private String updateName;
|
||||
|
||||
/**
|
||||
* 权限集类型:feature data
|
||||
*/
|
||||
|
||||
@ -27,7 +27,7 @@ public class SaasPermissionGroupScope extends BaseEntity<SaasPermissionGroupScop
|
||||
* 权限组id
|
||||
*/
|
||||
@TableField("pgroup_id")
|
||||
private Integer pgroupId;
|
||||
private Long pgroupId;
|
||||
|
||||
/**
|
||||
* 选择类型: 1.正选 2.反选
|
||||
|
||||
@ -1,15 +1,19 @@
|
||||
package cn.axzo.tyr.server.service.impl;
|
||||
|
||||
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.permission.PermissionPointTreeNode;
|
||||
import cn.axzo.tyr.client.model.req.QuerySaasPermissionGroupReq;
|
||||
import cn.axzo.tyr.client.model.vo.SaasPermissionGroupVO;
|
||||
import cn.axzo.tyr.client.model.vo.SaasRolePermissionScopeVO;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasPermissionGroup;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasPermissionGroupScope;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasPgroupPermissionRelation;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasPgroupRoleRelation;
|
||||
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.repository.service.SaasPgroupRoleRelationDao;
|
||||
import cn.axzo.tyr.server.service.PermissionGroupService;
|
||||
@ -46,6 +50,8 @@ public class PermissionGroupImpl implements PermissionGroupService {
|
||||
SaasPgroupPermissionRelationDao permissionRelationDao;
|
||||
@Autowired
|
||||
PermissionPointService featureService;
|
||||
@Autowired
|
||||
SaasPermissionGroupScopeDao saasPermissionGroupScopeDao;
|
||||
|
||||
@Override
|
||||
public List<SaasPermissionGroupVO> query(QuerySaasPermissionGroupReq req) {
|
||||
@ -56,6 +62,12 @@ public class PermissionGroupImpl implements PermissionGroupService {
|
||||
.in(SaasPgroupRoleRelation::getRoleId, req.getRoleIds())
|
||||
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
|
||||
.list();
|
||||
List<Long> hitIds = relationList.stream().map(SaasPgroupRoleRelation::getGroupId).distinct().collect(Collectors.toList());
|
||||
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(req.getIds())) {
|
||||
req.getIds().retainAll(hitIds);
|
||||
} else {
|
||||
req.setIds(hitIds);
|
||||
}
|
||||
// 如果没查询到关联关系则直接返回
|
||||
if (CollectionUtils.isEmpty(relationList)) {
|
||||
return new ArrayList<>();
|
||||
@ -68,6 +80,7 @@ public class PermissionGroupImpl implements PermissionGroupService {
|
||||
.eq(req.getCreateBy() != null, SaasPermissionGroup::getCreateBy, req.getCreateBy())
|
||||
.eq(req.getUpdateBy() != null, SaasPermissionGroup::getUpdateBy, req.getUpdateBy())
|
||||
.eq(StringUtils.isNotBlank(req.getType()), SaasPermissionGroup::getType, req.getType())
|
||||
.like(StringUtils.isNotBlank(req.getName()), SaasPermissionGroup::getName, req.getName())
|
||||
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
|
||||
.orderByDesc(BaseEntity::getId)
|
||||
.list();
|
||||
@ -75,9 +88,10 @@ public class PermissionGroupImpl implements PermissionGroupService {
|
||||
if (CollectionUtils.isEmpty(groupList)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<Long> groupIds = groupList.stream().map(BaseEntity::getId).collect(Collectors.toList());
|
||||
// 查询权限集关联的权限
|
||||
List<SaasPgroupPermissionRelation> permissionList = permissionRelationDao.lambdaQuery()
|
||||
.in(SaasPgroupPermissionRelation::getGroupId, groupList.stream().map(BaseEntity::getId).collect(Collectors.toList()))
|
||||
.in(SaasPgroupPermissionRelation::getGroupId, groupIds)
|
||||
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
|
||||
.list();
|
||||
List<PermissionPointTreeNode> feature = null;
|
||||
@ -85,6 +99,10 @@ public class PermissionGroupImpl implements PermissionGroupService {
|
||||
// 查询featureCode
|
||||
feature = featureService.listNodesByIds(permissionList.stream().map(SaasPgroupPermissionRelation::getFeatureId).collect(Collectors.toList()));
|
||||
}
|
||||
List<SaasPermissionGroupScope> saasPermissionGroupScopes = saasPermissionGroupScopeDao.lambdaQuery()
|
||||
.in(SaasPermissionGroupScope::getPgroupId, groupIds)
|
||||
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
|
||||
.list();
|
||||
// 组装填充字段
|
||||
List<PermissionPointTreeNode> finalFeature = feature;
|
||||
return groupList.stream().map(group ->
|
||||
@ -92,9 +110,11 @@ 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()))
|
||||
.createBy(group.getCreateBy())
|
||||
.updateBy(group.getUpdateBy())
|
||||
.type(group.getType())
|
||||
.isCommon(group.getIsCommon())
|
||||
.build()
|
||||
).collect(Collectors.toList());
|
||||
|
||||
@ -129,16 +149,17 @@ public class PermissionGroupImpl implements PermissionGroupService {
|
||||
.eq(StringUtils.isNotBlank(req.getType()), SaasPermissionGroup::getType, req.getType())
|
||||
.like(StringUtils.isNotBlank(req.getName()), SaasPermissionGroup::getName, req.getName())
|
||||
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
|
||||
.orderByDesc(BaseEntity::getId)
|
||||
.orderByAsc(BaseEntity::getCreateAt).orderByAsc(BaseEntity::getId)
|
||||
.page(iPage);
|
||||
List<SaasPermissionGroup> groupList = iPage.getRecords();
|
||||
// 如果权限集为空则直接返回
|
||||
if (CollectionUtils.isEmpty(groupList)) {
|
||||
return PageResp.zero(iPage.getCurrent(), iPage.getSize());
|
||||
}
|
||||
List<Long> groupIds = groupList.stream().map(BaseEntity::getId).collect(Collectors.toList());
|
||||
// 查询权限集关联的权限
|
||||
List<SaasPgroupPermissionRelation> permissionList = permissionRelationDao.lambdaQuery()
|
||||
.in(SaasPgroupPermissionRelation::getGroupId, groupList.stream().map(BaseEntity::getId).collect(Collectors.toList()))
|
||||
.in(SaasPgroupPermissionRelation::getGroupId, groupIds)
|
||||
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
|
||||
.list();
|
||||
List<PermissionPointTreeNode> feature = null;
|
||||
@ -146,6 +167,10 @@ public class PermissionGroupImpl implements PermissionGroupService {
|
||||
// 查询featureCode
|
||||
feature = featureService.listNodesByIds(permissionList.stream().map(SaasPgroupPermissionRelation::getFeatureId).collect(Collectors.toList()));
|
||||
}
|
||||
List<SaasPermissionGroupScope> saasPermissionGroupScopes = saasPermissionGroupScopeDao.lambdaQuery()
|
||||
.in(SaasPermissionGroupScope::getPgroupId, groupIds)
|
||||
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
|
||||
.list();
|
||||
// 组装填充字段
|
||||
List<PermissionPointTreeNode> finalFeature = feature;
|
||||
List<SaasPermissionGroupVO> pageList = groupList.stream().map(group ->
|
||||
@ -153,12 +178,13 @@ 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()))
|
||||
.createBy(group.getCreateBy())
|
||||
.updateBy(group.getUpdateBy())
|
||||
.type(group.getType())
|
||||
.isCommon(group.getIsCommon())
|
||||
.build()
|
||||
).collect(Collectors.toList());
|
||||
return PageResp.list(iPage.getCurrent(), iPage.getSize(), iPage.getTotal(), pageList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user