|
@@ -1,7 +1,6 @@
|
|
|
package com.persagy.apm.alarmservice.group.management.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.persagy.apm.alarmservice.group.management.model.equip.dto.QueryEquipDTO;
|
|
@@ -11,12 +10,13 @@ import com.persagy.apm.alarmservice.group.management.model.group.vo.EquipGroupIn
|
|
|
import com.persagy.apm.alarmservice.group.management.model.group.vo.GroupInfoVO;
|
|
|
import com.persagy.apm.alarmservice.group.management.model.group.vo.GroupTreeVO;
|
|
|
import com.persagy.apm.alarmservice.group.management.service.GroupManagementService;
|
|
|
+import com.persagy.apm.alarmservice.group.objgroup.model.ObjGroup;
|
|
|
+import com.persagy.apm.alarmservice.group.objgroup.model.dto.QueryObjGroupDTO;
|
|
|
+import com.persagy.apm.alarmservice.group.objgroup.service.IObjGroupService;
|
|
|
import com.persagy.apm.common.context.poems.PoemsContext;
|
|
|
import com.persagy.apm.common.model.vo.SimpleObjVO;
|
|
|
import com.persagy.apm.common.response.PageList;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.collections4.CollectionUtils;
|
|
|
-import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.elasticsearch.action.get.GetRequest;
|
|
|
import org.elasticsearch.action.get.GetResponse;
|
|
@@ -33,16 +33,13 @@ import org.elasticsearch.rest.RestStatus;
|
|
|
import org.elasticsearch.search.SearchHit;
|
|
|
import org.elasticsearch.search.SearchHits;
|
|
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
|
-import org.elasticsearch.search.sort.SortOrder;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
-import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -63,6 +60,8 @@ public class GroupManagementServiceImpl implements GroupManagementService {
|
|
|
|
|
|
@Autowired
|
|
|
private RestHighLevelClient client;
|
|
|
+ @Autowired
|
|
|
+ private IObjGroupService objGroupService;
|
|
|
|
|
|
@Value("${elasticsearch.maxSearchCount}")
|
|
|
private int maxSearchCount;
|
|
@@ -279,7 +278,7 @@ public class GroupManagementServiceImpl implements GroupManagementService {
|
|
|
return equipGroupInfoVO;
|
|
|
}
|
|
|
|
|
|
- if (CollectionUtils.isNotEmpty(groupTreeVO.getChildren())) {
|
|
|
+ if (!CollectionUtils.isEmpty(groupTreeVO.getChildren())) {
|
|
|
cascadeSearchGroupInfo(groupTreeVO.getChildren(), equipGroupInfoVO, equipFuncMap);
|
|
|
}
|
|
|
}
|
|
@@ -289,22 +288,87 @@ public class GroupManagementServiceImpl implements GroupManagementService {
|
|
|
/**
|
|
|
* 获取分组树
|
|
|
*
|
|
|
- * @return java.util.List<com.persagy.apm.alarmservice.group.management.model.vo.GroupTreeVO>
|
|
|
- * @author 易涛
|
|
|
- * @date 2021/9/8 14:44
|
|
|
+ * @return 分组树节点列表
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/10/19 2:40 下午
|
|
|
*/
|
|
|
- public static List<GroupTreeVO> getGroupTree() {
|
|
|
- InputStream inputStream = GroupManagementServiceImpl.class.getClassLoader()
|
|
|
- .getResourceAsStream("json" + File.separator + "GroupTree.json");
|
|
|
- if (inputStream == null) {
|
|
|
- return null;
|
|
|
+ @Override
|
|
|
+ public List<GroupTreeVO> getGroupTree() {
|
|
|
+ // 不再从配置文件读取分组数据
|
|
|
+ // InputStream inputStream = GroupManagementServiceImpl.class.getClassLoader()
|
|
|
+ // .getResourceAsStream("json" + File.separator + "GroupTree.json");
|
|
|
+ // if (inputStream == null) {
|
|
|
+ // return null;
|
|
|
+ // }
|
|
|
+ // try {
|
|
|
+ // String str = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
|
|
|
+ // return JSONArray.parseArray(str, GroupTreeVO.class);
|
|
|
+ // } catch (IOException ioe) {
|
|
|
+ // throw new RuntimeException("json文件有误", ioe);
|
|
|
+ // }
|
|
|
+ // 从表中查询所有分组
|
|
|
+ QueryObjGroupDTO queryObjGroupDTO = new QueryObjGroupDTO();
|
|
|
+ List<ObjGroup> objGroups = objGroupService.queryObjGroupList(queryObjGroupDTO);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(objGroups)) {
|
|
|
+ return new ArrayList<>();
|
|
|
}
|
|
|
- try {
|
|
|
- String str = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
|
|
|
- return JSONArray.parseArray(str, GroupTreeVO.class);
|
|
|
- } catch (IOException ioe) {
|
|
|
- throw new RuntimeException("json文件有误", ioe);
|
|
|
+ // 将分组列表转换为树形结构,根节点的parentId = 0;
|
|
|
+ Map<String, List<ObjGroup>> objGroupMap = new HashMap<>();
|
|
|
+ for (ObjGroup objGroup : objGroups) {
|
|
|
+ String parentId = objGroup.getParentId();
|
|
|
+ if (!objGroupMap.containsKey(parentId)) {
|
|
|
+ objGroupMap.put(parentId, Lists.newArrayList(objGroup));
|
|
|
+ } else {
|
|
|
+ objGroupMap.get(parentId).add(objGroup);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return objGroupMap2Tree(objGroupMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将分组的map转换为树
|
|
|
+ *
|
|
|
+ * @param objGroupMap 分组的map
|
|
|
+ * @return 分组树节点列表
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/10/19 2:50 下午
|
|
|
+ */
|
|
|
+ private List<GroupTreeVO> objGroupMap2Tree(Map<String, List<ObjGroup>> objGroupMap) {
|
|
|
+ if (CollectionUtils.isEmpty(objGroupMap)) {
|
|
|
+ return new ArrayList<>();
|
|
|
}
|
|
|
+ List<GroupTreeVO> result = new ArrayList<>();
|
|
|
+ // 根节点parentId = 0;
|
|
|
+ List<ObjGroup> rootObjGroups = objGroupMap.get("0");
|
|
|
+ rootObjGroups.forEach(objGroup -> {
|
|
|
+ GroupTreeVO groupTreeVO = ConvertGroupTool.INSTANCE.convert2GroupTreeVO(objGroup);
|
|
|
+ result.add(groupTreeVO);
|
|
|
+ });
|
|
|
+ cascadeSetChildren(objGroupMap, result);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 级联设置子节点
|
|
|
+ *
|
|
|
+ * @param objGroupMap 分组map 分组parentId -> 分组列表
|
|
|
+ * @param groupTreeVOList 要设置子节点的节点列表
|
|
|
+ * @exception
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/10/19 3:16 下午
|
|
|
+ */
|
|
|
+ private void cascadeSetChildren(Map<String, List<ObjGroup>> objGroupMap, List<GroupTreeVO> groupTreeVOList) {
|
|
|
+ groupTreeVOList.forEach(groupTreeVO -> {
|
|
|
+ if (objGroupMap.containsKey(groupTreeVO.getId())) {
|
|
|
+ List<ObjGroup> sonObjGroups = objGroupMap.get(groupTreeVO.getId());
|
|
|
+ List<GroupTreeVO> sonNodes = sonObjGroups.stream().map(
|
|
|
+ ConvertGroupTool.INSTANCE::convert2GroupTreeVO
|
|
|
+ ).collect(Collectors.toList());
|
|
|
+ groupTreeVO.setChildren(sonNodes);
|
|
|
+ cascadeSetChildren(objGroupMap, sonNodes);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -364,7 +428,7 @@ public class GroupManagementServiceImpl implements GroupManagementService {
|
|
|
BeanUtils.copyProperties(groupTreeVO, groupInfoVO);
|
|
|
return groupInfoVO;
|
|
|
}
|
|
|
- if (CollectionUtils.isNotEmpty(groupTreeVO.getChildren())) {
|
|
|
+ if (!CollectionUtils.isEmpty(groupTreeVO.getChildren())) {
|
|
|
queryById(groupTreeVO.getChildren(), groupInfoVO, id);
|
|
|
}
|
|
|
}
|