角色分组spi service

This commit is contained in:
yangsong 2023-09-11 11:10:13 +08:00
parent 5c49333198
commit 77bf00fadb
5 changed files with 102 additions and 2 deletions

View File

@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RequestParam;
* 角色分组
*/
@FeignClient(name = "tyr", url = "${axzo.service.maokai:http://tyr:8080/api/saasRoleGroup}")
public interface SaasRoleGoupApi {
public interface SaasRoleGroupApi {
/**
* 保存/更新

View File

@ -0,0 +1,33 @@
package cn.axzo.tyr.server.controller.role;
import cn.axzo.framework.domain.web.result.ApiListResult;
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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequiredArgsConstructor
public class SaasRoleGroupController implements SaasRoleGroupApi {
private final SaasRoleGroupService saasRoleGroupService;
@Override
public ApiResult<Void> saveOrUpdate(SaasRoleGroupVO req) {
return null;
}
@Override
public ApiListResult<SaasRoleGroupVO> getList(QuerySaasRoleGroupReq req) {
return ApiListResult.ok(saasRoleGroupService.getList(req));
}
@Override
public ApiResult<Void> delete(Long id) {
return null;
}
}

View File

@ -0,0 +1,10 @@
package cn.axzo.tyr.server.service;
import cn.axzo.tyr.client.model.req.QuerySaasRoleGroupReq;
import cn.axzo.tyr.client.model.vo.SaasRoleGroupVO;
import java.util.List;
public interface SaasRoleGroupService {
List<SaasRoleGroupVO> getList(QuerySaasRoleGroupReq req);
}

View File

@ -19,7 +19,10 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
@ -128,6 +131,9 @@ public class RoleServiceImpl implements RoleService {
groupRelation = roleGroupRelationDao.lambdaQuery()
.in(SaasRoleGroupRelation::getSaasRoleGroupId, roleGroup.stream().map(BaseEntity::getId).collect(Collectors.toList()))
.list();
if (CollectionUtils.isEmpty(groupRelation)) {
return new ArrayList<>();
}
}
// 查询角色
List<SaasRole> list = saasRoleDao.lambdaQuery()

View File

@ -0,0 +1,51 @@
package cn.axzo.tyr.server.service.impl;
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
import cn.axzo.tyr.client.model.req.QuerySaasRoleGroupReq;
import cn.axzo.tyr.client.model.vo.SaasRoleGroupVO;
import cn.axzo.tyr.server.repository.entity.SaasRoleGroup;
import cn.axzo.tyr.server.repository.entity.SaasRoleGroupRelation;
import cn.axzo.tyr.server.repository.service.SaasRoleGroupDao;
import cn.axzo.tyr.server.repository.service.SaasRoleGroupRelationDao;
import cn.axzo.tyr.server.service.SaasRoleGroupService;
import cn.hutool.core.bean.BeanUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@RequiredArgsConstructor
@Service
public class SaasRoleGroupServiceImpl implements SaasRoleGroupService {
private final SaasRoleGroupDao saasRoleGroupDao;
private final SaasRoleGroupRelationDao saasRoleGroupRelationDao;
@Override
public List<SaasRoleGroupVO> getList(QuerySaasRoleGroupReq req) {
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))
.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());
return results;
}
}