左侧树:获取主题域的树结构
This commit is contained in:
parent
ab56d1ae9b
commit
6c80c006d2
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import iet.ustb.sf.common.R;
|
||||
import iet.ustb.sf.domain.Category;
|
||||
import iet.ustb.sf.service.CategoryService;
|
||||
import iet.ustb.sf.vo.CategoryVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
@ -61,10 +62,23 @@ public class CategoryController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 聚合列表查询
|
||||
*/
|
||||
@Operation(summary = "聚合列表查询")
|
||||
@PostMapping("/getTogethList")
|
||||
public R<List<Map<String, String>>> getTogethList(@RequestBody JSONObject params) {
|
||||
List<Map<String, String>> result = categoryService.getTogethList(params);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主题域的树结构
|
||||
*/
|
||||
@Operation(summary = "获取主题域的树结构")
|
||||
@PostMapping("/getAllTopicTree")
|
||||
public R<Map<String,List<CategoryVo>>> getAllTopicTree(@RequestBody JSONObject params) {
|
||||
Map<String,List<CategoryVo>> map = categoryService.getAllTopicTree(params);
|
||||
return R.ok(map);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ public class HealthController {
|
||||
|
||||
/**
|
||||
* 健康检测
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/")
|
||||
public R<String> healthCheck() {
|
||||
|
@ -3,6 +3,7 @@ package iet.ustb.sf.service;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import iet.ustb.sf.domain.Category;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import iet.ustb.sf.vo.CategoryVo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -21,4 +22,6 @@ public interface CategoryService extends IService<Category> {
|
||||
void delCategory(JSONObject params);
|
||||
|
||||
List<Map<String, String>> getTogethList(JSONObject params);
|
||||
|
||||
Map<String, List<CategoryVo>> getAllTopicTree(JSONObject params);
|
||||
}
|
||||
|
@ -3,14 +3,17 @@ package iet.ustb.sf.service.impl;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import iet.ustb.sf.domain.Analysis;
|
||||
import iet.ustb.sf.domain.Category;
|
||||
import iet.ustb.sf.domain.Target;
|
||||
import iet.ustb.sf.exception.ErrorCode;
|
||||
import iet.ustb.sf.exception.ThrowUtils;
|
||||
import iet.ustb.sf.mapper.AnalysisMapper;
|
||||
import iet.ustb.sf.mapper.TargetMapper;
|
||||
import iet.ustb.sf.service.CategoryService;
|
||||
import iet.ustb.sf.mapper.CategoryMapper;
|
||||
import iet.ustb.sf.util.CheckUtils;
|
||||
import iet.ustb.sf.vo.CategoryVo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -33,6 +36,9 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
|
||||
@Resource
|
||||
private TargetMapper targetMapper;
|
||||
|
||||
@Resource
|
||||
private AnalysisMapper analysisMapper;
|
||||
|
||||
@Override
|
||||
public List<Category> showCategory(Category category) {
|
||||
boolean bl = StringUtils.isEmpty(category.getTopic()) && StringUtils.isEmpty(category.getOrganization());
|
||||
@ -171,6 +177,88 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<CategoryVo>> getAllTopicTree(JSONObject params) {
|
||||
Map<String, List<CategoryVo>> map = new LinkedHashMap<>();
|
||||
|
||||
List<String> topicList = Arrays.asList("生产", "质量", "能源", "运维", "成本", "测试");
|
||||
for (String topic : topicList) {
|
||||
map.put(topic, new ArrayList<>());
|
||||
}
|
||||
|
||||
Map<String, CategoryVo> tmpMap = new HashMap<>();
|
||||
List<Category> categoryList = categoryMapper.selectList(new QueryWrapper<>());
|
||||
for (Category category : categoryList) {
|
||||
CategoryVo categoryVo = CategoryVo.builder()
|
||||
.topic(category.getTopic())
|
||||
.name(category.getNameCn())
|
||||
.show("1")
|
||||
.key("0")
|
||||
.children(new ArrayList<>())
|
||||
.categoryId(category.getId())
|
||||
.build();
|
||||
map.computeIfAbsent(category.getTopic(), k -> new ArrayList<>()).add(categoryVo);
|
||||
tmpMap.put("category:" + category.getId(), categoryVo);
|
||||
}
|
||||
|
||||
String key = params.getString("key");
|
||||
if (key == null) {
|
||||
key = "";
|
||||
}
|
||||
List<String> ids;
|
||||
if ("chat".equals(key)) {
|
||||
List<Analysis> results = analysisMapper.selectList(new QueryWrapper<>());
|
||||
ids = results == null ? Collections.emptyList() :
|
||||
results.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(Analysis::getTargetId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
} else {
|
||||
ids = Collections.emptyList();
|
||||
}
|
||||
|
||||
List<Target> targetList = targetMapper.selectList(new QueryWrapper<>());
|
||||
for (Target target : targetList) {
|
||||
CategoryVo categoryVo = CategoryVo.builder()
|
||||
.topic(target.getTopic())
|
||||
.targetId(target.getId())
|
||||
.name(target.getName())
|
||||
.show("0")
|
||||
.key(String.valueOf(target.getIsKey()))
|
||||
.hasDog(ids.contains(target.getId()))
|
||||
.children(new ArrayList<>())
|
||||
.cycle(target.getCycle())
|
||||
.build();
|
||||
if (target.getParent() == null) {
|
||||
List<CategoryVo> children;
|
||||
if (StringUtils.isEmpty(target.getCategoryId())) {
|
||||
children = map.get(target.getTopic());
|
||||
} else {
|
||||
children = tmpMap.get("category:" + target.getCategoryId()).getChildren();
|
||||
}
|
||||
int index = ids.contains(target.getId()) ? 0 : children.size();
|
||||
children.add(index, categoryVo);
|
||||
} else {
|
||||
CategoryVo mbgkCategoryVo = tmpMap.getOrDefault("target:" + target.getParent(), new CategoryVo());
|
||||
if (mbgkCategoryVo.getChildren() == null) {
|
||||
mbgkCategoryVo.setChildren(new ArrayList<>());
|
||||
}
|
||||
int index = ids.contains(target.getId()) ? 0 : mbgkCategoryVo.getChildren().size();
|
||||
mbgkCategoryVo.getChildren().add(index, categoryVo);
|
||||
tmpMap.put("target:" + target.getParent(), mbgkCategoryVo);
|
||||
}
|
||||
|
||||
if (tmpMap.containsKey("target:" + target.getId())) {
|
||||
CategoryVo mbgkCategoryVo = tmpMap.get("target:" + target.getId());
|
||||
categoryVo.setChildren(mbgkCategoryVo.getChildren());
|
||||
}
|
||||
tmpMap.put("target:" + target.getId(), categoryVo);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
71
src/main/java/iet/ustb/sf/vo/CategoryVo.java
Normal file
71
src/main/java/iet/ustb/sf/vo/CategoryVo.java
Normal file
@ -0,0 +1,71 @@
|
||||
package iet.ustb.sf.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* CategoryVo
|
||||
*
|
||||
* @author huangge1199
|
||||
* @since 2025/8/6 14:08:07
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CategoryVo {
|
||||
|
||||
/**
|
||||
* 主题
|
||||
*/
|
||||
private String topic;
|
||||
|
||||
/**
|
||||
* 组织
|
||||
*/
|
||||
private String organization;
|
||||
|
||||
/**
|
||||
* 指标ID
|
||||
*/
|
||||
private String targetId;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 是否分类,1:是、0:不是
|
||||
*/
|
||||
private String show;
|
||||
|
||||
/**
|
||||
* 是否启用,1:启用、0:不启用
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 是否加点和排序
|
||||
*/
|
||||
private boolean hasDog;
|
||||
|
||||
/**
|
||||
* 子树
|
||||
*/
|
||||
private List<CategoryVo> children;
|
||||
|
||||
/**
|
||||
* 分类ID
|
||||
*/
|
||||
private String categoryId;
|
||||
|
||||
/**
|
||||
* 指标周期
|
||||
*/
|
||||
private String cycle;
|
||||
}
|
Loading…
Reference in New Issue
Block a user