|
@@ -0,0 +1,94 @@
|
|
|
+package com.persagy.apm.controller;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.persagy.apm.common.response.CommonResult;
|
|
|
+import com.persagy.apm.common.utils.ResultHelper;
|
|
|
+import com.persagy.apm.model.vo.GroupTreeDetailVO;
|
|
|
+import com.persagy.apm.model.vo.GroupTreeVO;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author 易涛
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2021/9/7 18:09
|
|
|
+ */
|
|
|
+@Api(tags = "分组管理")
|
|
|
+@RestController
|
|
|
+@RequestMapping("group-management")
|
|
|
+public class GroupManagementController {
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取分组树")
|
|
|
+ @PostMapping("/queryGroupTree")
|
|
|
+ public CommonResult<List<GroupTreeVO>> queryGroupTree(){
|
|
|
+ return ResultHelper.single(getGroupTree());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取分组树
|
|
|
+ * @author 易涛
|
|
|
+ * @date 2021/9/8 14:44
|
|
|
+ * @return java.util.List<com.persagy.apm.model.vo.GroupTreeVO>
|
|
|
+ */
|
|
|
+ private List<GroupTreeVO> getGroupTree(){
|
|
|
+ InputStream inputStream = this.getClass().getClassLoader()
|
|
|
+ .getResourceAsStream(File.separator+"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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "根据id获取分组详情信息")
|
|
|
+ @PostMapping("/queryTreeById")
|
|
|
+ public CommonResult<GroupTreeDetailVO> queryTreeById(@RequestBody String id){
|
|
|
+ List<GroupTreeVO> groupTreeVOList = getGroupTree();
|
|
|
+ GroupTreeDetailVO groupTreeDetailVO = new GroupTreeDetailVO();
|
|
|
+ queryById(groupTreeVOList,groupTreeDetailVO,id);
|
|
|
+ return ResultHelper.single(groupTreeDetailVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 递归匹配符合条件的分组对象
|
|
|
+ * @param groupTreeVOList
|
|
|
+ * @param id
|
|
|
+ * @author 易涛
|
|
|
+ * @date 2021/9/8 14:50
|
|
|
+ * @return com.persagy.apm.model.vo.GroupTreeVO
|
|
|
+ */
|
|
|
+ private GroupTreeDetailVO queryById(List<GroupTreeVO> groupTreeVOList,GroupTreeDetailVO groupTreeDetailVO,String id){
|
|
|
+ for(GroupTreeVO groupTreeVO:groupTreeVOList){
|
|
|
+ if(StringUtils.isNotEmpty(groupTreeDetailVO.getId())){
|
|
|
+ return groupTreeDetailVO;
|
|
|
+ }
|
|
|
+ if(Objects.equals(groupTreeVO.getId(),id)){
|
|
|
+ BeanUtils.copyProperties(groupTreeVO,groupTreeDetailVO);
|
|
|
+ return groupTreeDetailVO;
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isNotEmpty(groupTreeVO.getChildren())){
|
|
|
+ queryById(groupTreeVO.getChildren(),groupTreeDetailVO,id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return groupTreeDetailVO;
|
|
|
+ }
|
|
|
+}
|