获取角色详情,分组角色id过滤
This commit is contained in:
parent
d229937ac0
commit
f4e4c0fdcf
@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -31,7 +32,7 @@ public interface SaasRoleApi {
|
||||
* 根据id查询详情
|
||||
*/
|
||||
@PostMapping("/api/saasRole/getById")
|
||||
ApiResult<SaasRoleVO> getById(@RequestParam(required = true) Long id);
|
||||
ApiResult<SaasRoleVO> getById(@RequestParam(required = true) @NotNull Long id);
|
||||
|
||||
/**
|
||||
* 获取角色列表
|
||||
|
||||
@ -2,8 +2,8 @@ package cn.axzo.tyr.client.feign;
|
||||
|
||||
import cn.axzo.framework.domain.web.result.ApiListResult;
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.tyr.client.model.vo.SaasRoleGroupVO;
|
||||
import cn.axzo.tyr.client.model.req.QuerySaasRoleGroupReq;
|
||||
import cn.axzo.tyr.client.model.vo.SaasRoleGroupVO;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@ -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 PermissionGroupType {
|
||||
COMMON(1, "通用"),
|
||||
Special (0, "例外"),
|
||||
;
|
||||
|
||||
private Integer code;
|
||||
private String desc;
|
||||
|
||||
private static final Map<Integer, PermissionGroupType> MAPPING = new HashMap<>();
|
||||
static {
|
||||
for (PermissionGroupType type : PermissionGroupType.values()) {
|
||||
MAPPING.put(type.code, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static PermissionGroupType 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 RoleGroupScope {
|
||||
ALL(1, "全部"),
|
||||
SPECIFY_ENTERPRISE_TYPE(2, "指定企业类型"),
|
||||
;
|
||||
|
||||
private Integer code;
|
||||
private String desc;
|
||||
|
||||
private static final Map<Integer, RoleGroupScope> MAPPING = new HashMap<>();
|
||||
static {
|
||||
for (RoleGroupScope type : RoleGroupScope.values()) {
|
||||
MAPPING.put(type.code, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static RoleGroupScope apply(Integer code) {
|
||||
return code == null ? null :MAPPING.get(code);
|
||||
}
|
||||
}
|
||||
@ -34,5 +34,8 @@ public class QuerySaasRoleGroupReq {
|
||||
* 单位类型字典code
|
||||
*/
|
||||
private List<String> ouTypeCode;
|
||||
|
||||
/**
|
||||
* 被那些角色使用到的分组
|
||||
*/
|
||||
private List<Long> roleIds;
|
||||
}
|
||||
|
||||
@ -37,4 +37,6 @@ public class QuerySaasRoleReq {
|
||||
* 分组id
|
||||
*/
|
||||
private List<Long> sassRoleGroupIds;
|
||||
|
||||
private Integer isCommon;
|
||||
}
|
||||
|
||||
@ -1,13 +1,17 @@
|
||||
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.SaasRoleApi;
|
||||
import cn.axzo.tyr.client.model.req.QueryByIdentityIdTypeReq;
|
||||
import cn.axzo.tyr.client.model.req.QuerySaasRoleReq;
|
||||
import cn.axzo.tyr.client.model.vo.SaasRoleVO;
|
||||
import cn.axzo.tyr.server.service.RoleService;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@ -36,7 +40,12 @@ public class SaasRoleController implements SaasRoleApi {
|
||||
|
||||
@Override
|
||||
public ApiResult<SaasRoleVO> getById(Long id) {
|
||||
return null;
|
||||
QuerySaasRoleReq query = QuerySaasRoleReq.builder().ids(Lists.newArrayList(id)).build();
|
||||
List<SaasRoleVO> saasRoles = roleService.query(query);
|
||||
if (CollectionUtils.isNotEmpty(saasRoles)) {
|
||||
return ApiResult.ok(saasRoles.get(0));
|
||||
}
|
||||
throw new BizException(BaseCode.BAD_REQUEST, "未查询到角色");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -55,7 +55,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
if (CollectionUtils.isEmpty(roleIds)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return getByIds(roleIds);
|
||||
return getByIds(roleIds, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,7 +63,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<SaasRoleVO> getByIds(List<Long> roleIds) {
|
||||
public List<SaasRoleVO> getByIds(List<Long> roleIds, Integer isCommon) {
|
||||
if (CollectionUtils.isEmpty(roleIds)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@ -78,7 +78,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
// 转map<roleId,relation>
|
||||
pgrouRelationMap = saasPgroupRoleRelations.stream().collect(Collectors.groupingBy(SaasPgroupRoleRelation::getRoleId));
|
||||
// 查询权限集
|
||||
pGroupMap = permissionGroupService.query(QuerySaasPermissionGroupReq.builder()
|
||||
pGroupMap = permissionGroupService.query(QuerySaasPermissionGroupReq.builder().isCommon(isCommon)
|
||||
.ids(saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList()))
|
||||
.build())
|
||||
// 转map<pgroupId>
|
||||
@ -141,7 +141,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()));
|
||||
return getByIds(list.stream().map(BaseEntity::getId).collect(Collectors.toList()), req.getIsCommon());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -30,21 +30,38 @@ public class SaasRoleGroupServiceImpl implements SaasRoleGroupService {
|
||||
|
||||
@Override
|
||||
public List<SaasRoleGroupVO> getList(QuerySaasRoleGroupReq req) {
|
||||
if (CollectionUtils.isNotEmpty(req.getRoleIds())) {
|
||||
List<SaasRoleGroupRelation> saasRoleGroupRelations = saasRoleGroupRelationDao.lambdaQuery()
|
||||
.in(SaasRoleGroupRelation::getRoleId, req.getRoleIds())
|
||||
.eq(SaasRoleGroupRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
|
||||
List<Long> groupIds = saasRoleGroupRelations.stream().map(SaasRoleGroupRelation::getSaasRoleGroupId).distinct().collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(req.getIds())) {
|
||||
req.getIds().retainAll(groupIds);
|
||||
} else {
|
||||
req.setIds(groupIds);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(req.getIds())) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
List<SaasRoleGroup> groups = saasRoleGroupDao.query(req);
|
||||
if (CollectionUtils.isEmpty(groups)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<SaasRoleGroupRelation> saasRoleGroupRelations = saasRoleGroupRelationDao.lambdaQuery().in(SaasRoleGroupRelation::getSaasRoleGroupId, groups.stream().map(SaasRoleGroup::getId))
|
||||
List<SaasRoleGroupRelation> saasRoleGroupRelations = saasRoleGroupRelationDao.lambdaQuery()
|
||||
.in(SaasRoleGroupRelation::getSaasRoleGroupId, groups.stream().map(SaasRoleGroup::getId))
|
||||
.eq(SaasRoleGroupRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
|
||||
Map<Long, List<Long>> groupRoleMap = saasRoleGroupRelations.stream().collect(Collectors.groupingBy(SaasRoleGroupRelation::getSaasRoleGroupId, Collectors.mapping(SaasRoleGroupRelation::getRoleId, Collectors.toList())));
|
||||
List<SaasRoleGroupVO> results = groups.stream().map(e -> {
|
||||
SaasRoleGroupVO target = BeanUtil.copyProperties(e, SaasRoleGroupVO.class);
|
||||
if (StringUtils.isNotBlank(e.getOuTypeCode())) {
|
||||
target.setOuTypeCode(Arrays.stream(e.getOuTypeCode().split(",")).filter(StringUtils::isNotBlank).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList()));
|
||||
}
|
||||
target.setRoleIds(groupRoleMap.get(e.getId()));
|
||||
return target;
|
||||
}).collect(Collectors.toList());
|
||||
List<SaasRoleGroupVO> results = groups.stream()
|
||||
.map(e -> {
|
||||
SaasRoleGroupVO target = BeanUtil.copyProperties(e, SaasRoleGroupVO.class);
|
||||
if (StringUtils.isNotBlank(e.getOuTypeCode())) {
|
||||
target.setOuTypeCode(Arrays.stream(e.getOuTypeCode().split(",")).filter(StringUtils::isNotBlank).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList()));
|
||||
}
|
||||
target.setRoleIds(groupRoleMap.get(e.getId()));
|
||||
return target;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user