diff --git a/tyr-api/src/main/java/cn/axzo/tyr/client/feign/SaasRoleGoupApi.java b/tyr-api/src/main/java/cn/axzo/tyr/client/feign/SaasRoleGroupApi.java similarity index 96% rename from tyr-api/src/main/java/cn/axzo/tyr/client/feign/SaasRoleGoupApi.java rename to tyr-api/src/main/java/cn/axzo/tyr/client/feign/SaasRoleGroupApi.java index ba7c016e..457819a3 100644 --- a/tyr-api/src/main/java/cn/axzo/tyr/client/feign/SaasRoleGoupApi.java +++ b/tyr-api/src/main/java/cn/axzo/tyr/client/feign/SaasRoleGroupApi.java @@ -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 { /** * 保存/更新 diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/controller/role/SaasRoleGroupController.java b/tyr-server/src/main/java/cn/axzo/tyr/server/controller/role/SaasRoleGroupController.java new file mode 100644 index 00000000..e25896c0 --- /dev/null +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/controller/role/SaasRoleGroupController.java @@ -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 saveOrUpdate(SaasRoleGroupVO req) { + return null; + } + + @Override + public ApiListResult getList(QuerySaasRoleGroupReq req) { + return ApiListResult.ok(saasRoleGroupService.getList(req)); + } + + @Override + public ApiResult delete(Long id) { + return null; + } +} diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/service/SaasRoleGroupService.java b/tyr-server/src/main/java/cn/axzo/tyr/server/service/SaasRoleGroupService.java new file mode 100644 index 00000000..d50e03d2 --- /dev/null +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/service/SaasRoleGroupService.java @@ -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 getList(QuerySaasRoleGroupReq req); +} diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/RoleServiceImpl.java b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/RoleServiceImpl.java index bd5548cd..51ed81bb 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/RoleServiceImpl.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/RoleServiceImpl.java @@ -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 list = saasRoleDao.lambdaQuery() diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasRoleGroupServiceImpl.java b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasRoleGroupServiceImpl.java new file mode 100644 index 00000000..7a76af4f --- /dev/null +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasRoleGroupServiceImpl.java @@ -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 getList(QuerySaasRoleGroupReq req) { + List groups = saasRoleGroupDao.query(req); + if (CollectionUtils.isEmpty(groups)) { + return new ArrayList<>(); + } + List saasRoleGroupRelations = saasRoleGroupRelationDao.lambdaQuery().in(SaasRoleGroupRelation::getSaasRoleGroupId, groups.stream().map(SaasRoleGroup::getId)) + .eq(SaasRoleGroupRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list(); + Map> groupRoleMap = saasRoleGroupRelations.stream().collect(Collectors.groupingBy(SaasRoleGroupRelation::getSaasRoleGroupId, Collectors.mapping(SaasRoleGroupRelation::getRoleId, Collectors.toList()))); + List 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; + } +}