|
|
@@ -1,5 +1,7 @@
|
|
|
package com.xunmei.core.resumption.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
@@ -8,14 +10,17 @@ import com.xunmei.common.core.vo.IdNameVo;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
import com.xunmei.core.resumption.domain.AppRule;
|
|
|
-import com.xunmei.core.resumption.dto.appRule.AppRuleListForOrgDto;
|
|
|
-import com.xunmei.core.resumption.dto.appRule.AppRulePageDto;
|
|
|
+import com.xunmei.core.resumption.dto.rule.AppRuleListForOrgDto;
|
|
|
+import com.xunmei.core.resumption.dto.rule.AppRulePageDto;
|
|
|
import com.xunmei.core.resumption.mapper.AppRuleMapper;
|
|
|
-import com.xunmei.core.resumption.dto.appRule.AppRuleEditDto;
|
|
|
+import com.xunmei.core.resumption.dto.rule.AppRuleEditDto;
|
|
|
import com.xunmei.core.resumption.service.IAppRuleService;
|
|
|
import com.xunmei.core.resumption.vo.appRule.AppRuleInfoVo;
|
|
|
import com.xunmei.core.resumption.vo.appRule.AppRulePageVo;
|
|
|
+import com.xunmei.core.resumption.vo.appRuleItem.RuleTreeItem;
|
|
|
+import com.xunmei.system.api.Eto.OrgListByTypesConditionEto;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
+import com.xunmei.system.api.domain.SysOrg;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -24,7 +29,9 @@ import com.xunmei.common.core.utils.IDHelper;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -119,4 +126,43 @@ public class AppRuleServiceImpl extends ServiceImpl<AppRuleMapper, AppRule> impl
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<RuleTreeItem> getRuleTree(Long orgId) {
|
|
|
+ List<RuleTreeItem> tree = new ArrayList<>();
|
|
|
+ List<SysOrg> orgs = remoteOrgService
|
|
|
+ .listByTypes(OrgListByTypesConditionEto.builder().orgId(orgId).orgTypes(Arrays.asList("1", "2", "3", "4", "11")).build())
|
|
|
+ .getData();
|
|
|
+ if (ObjectUtil.isEmpty(orgs)) {
|
|
|
+ return tree;
|
|
|
+ }
|
|
|
+ Map<Long, SysOrg> orgMap = orgs.stream().collect(Collectors.toMap(o -> o.getId(), o -> o));
|
|
|
+ List<SysOrg> tops = orgs.stream().filter(o -> !orgMap.containsKey(o.getParentId())).collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isEmpty(tops)) {
|
|
|
+ return tree;
|
|
|
+ }
|
|
|
+ List<Long> orgIds = orgs.stream().map(o -> o.getId()).collect(Collectors.toList());
|
|
|
+ List<AppRule> rules = appRuleMapper.selectList(new LambdaQueryWrapper<AppRule>().in(AppRule::getOrgId, orgIds));
|
|
|
+
|
|
|
+ tree = tops.stream().map(o -> generateTree(o, orgs, rules)).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return tree;
|
|
|
+ }
|
|
|
+
|
|
|
+ private RuleTreeItem generateTree(SysOrg parent, List<SysOrg> allOrg, List<AppRule> allRule) {
|
|
|
+ RuleTreeItem item = RuleTreeItem.builder().isRule(0).id(parent.getId()).label(parent.getName()).children(new ArrayList<>()).build();
|
|
|
+ List<RuleTreeItem> ruleItems = allRule.stream().filter(r -> ObjectUtil.equal(r.getOrgId(), parent.getId()))
|
|
|
+ .map(o -> RuleTreeItem.builder().isRule(1).id(o.getId()).label(o.getName()).orgType(parent.getType().toString()).build())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ item.getChildren().addAll(ruleItems);
|
|
|
+
|
|
|
+ List<SysOrg> children = allOrg.stream()
|
|
|
+ .filter(o -> ObjectUtil.equal(o.getParentId(), parent.getId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (SysOrg child : children) {
|
|
|
+ item.getChildren().add(generateTree(child, allOrg, allRule));
|
|
|
+ }
|
|
|
+
|
|
|
+ return item;
|
|
|
+ }
|
|
|
}
|