farm模块-优化三级树结构
This commit is contained in:
@@ -280,17 +280,32 @@ public class DictController {
|
|||||||
return success(BeanUtils.toBean(res, FarmingTypeRespVO.class));
|
return success(BeanUtils.toBean(res, FarmingTypeRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "字典数据维护-下拉框列表-物种类别")
|
@Operation(summary = "字典数据维护-下拉框列表-三级物种类别")
|
||||||
@GetMapping("/list/species-classify-library")
|
@GetMapping("/list/three-library")
|
||||||
public CommonResult<List<SpeciesClassifyLibraryRespVO>> getSpeciesClassifyLibraryList() {
|
public CommonResult<List<SpeciesClassifyLibraryRespVO>> getTreeLibraryList() {
|
||||||
try {
|
try {
|
||||||
// 获取物种类别字典数据
|
// 获取物种类别字典数据
|
||||||
List<SysDictDO> dictList = sysDictService.getByTypeCode(CommonConstants.DICT_TYPE_CODE_3);
|
List<SysDictDO> dictList = sysDictService.getByTypeCode(CommonConstants.DICT_TYPE_CODE_3);
|
||||||
// 使用工具类构建树结构
|
// 使用工具类构建树结构
|
||||||
List<SpeciesClassifyLibraryRespVO> treeList = TreeStructureUtil.buildSpeciesClassifyTree(dictList);
|
List<SpeciesClassifyLibraryRespVO> threeList = TreeStructureUtil.buildSpeciesClassifyTree(dictList);
|
||||||
return success(treeList);
|
return success(threeList);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("获取物种类别列表失败", e);
|
log.error("获取三级物种类别列表失败", e);
|
||||||
|
return success(new ArrayList<>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "字典数据维护-下拉框列表-二级物种类别")
|
||||||
|
@GetMapping("/list/two-library")
|
||||||
|
public CommonResult<List<SpeciesClassifyLibraryRespVO>> getTwoLibraryList() {
|
||||||
|
try {
|
||||||
|
// 获取物种类别字典数据
|
||||||
|
List<SysDictDO> dictList = sysDictService.getByTypeCode(CommonConstants.DICT_TYPE_CODE_3);
|
||||||
|
// 使用工具类构建二级树结构
|
||||||
|
List<SpeciesClassifyLibraryRespVO> twoList = TreeStructureUtil.buildTwoLevelTree(dictList);
|
||||||
|
return success(twoList);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取二级物种类别列表失败", e);
|
||||||
return success(new ArrayList<>());
|
return success(new ArrayList<>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,12 @@ public class ModelManagementController {
|
|||||||
return success(modelManagementService.createModelManagement(createReqVO));
|
return success(modelManagementService.createModelManagement(createReqVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/copyModel")
|
||||||
|
@Operation(summary = "复制模型管理")
|
||||||
|
public CommonResult<String> copyModelManagement(@Valid @RequestBody ModelManagementSaveReqVO createReqVO) {
|
||||||
|
return success(modelManagementService.copyModelManagement(createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@Operation(summary = "更新模型管理")
|
@Operation(summary = "更新模型管理")
|
||||||
public CommonResult<Boolean> updateModelManagement(@Valid @RequestBody ModelManagementSaveReqVO updateReqVO) {
|
public CommonResult<Boolean> updateModelManagement(@Valid @RequestBody ModelManagementSaveReqVO updateReqVO) {
|
||||||
|
|||||||
@@ -62,4 +62,5 @@ public interface ModelManagementService {
|
|||||||
*/
|
*/
|
||||||
PageResult<ModelManagementDO> getModelManagementPage(ModelManagementPageReqVO pageReqVO);
|
PageResult<ModelManagementDO> getModelManagementPage(ModelManagementPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
String copyModelManagement(@Valid ModelManagementSaveReqVO createReqVO);
|
||||||
}
|
}
|
||||||
@@ -218,4 +218,10 @@ public class ModelManagementServiceImpl implements ModelManagementService {
|
|||||||
return modelManagementMapper.selectPage(pageReqVO);
|
return modelManagementMapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String copyModelManagement(ModelManagementSaveReqVO createReqVO) {
|
||||||
|
// createModelManagementCase(createReqVO.getId());
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -49,6 +49,39 @@ public class TreeStructureUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建物种类别二级树结构
|
||||||
|
*
|
||||||
|
* @param dictList 字典数据列表
|
||||||
|
* @return 二级树形结构列表
|
||||||
|
*/
|
||||||
|
public static List<SpeciesClassifyLibraryRespVO> buildTwoLevelTree(List<SysDictDO> dictList) {
|
||||||
|
if (dictList == null || dictList.isEmpty()) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 按一级分类分组
|
||||||
|
Map<String, List<SysDictDO>> groupedByLevel1 = dictList.stream()
|
||||||
|
.filter(dict -> isValidLevel1Node(dict))
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
SysDictDO::getField1Code,
|
||||||
|
Collectors.toList()
|
||||||
|
));
|
||||||
|
|
||||||
|
// 构建二级树形结构
|
||||||
|
return groupedByLevel1.entrySet().stream()
|
||||||
|
.map(entry -> buildTwoLevelNode(entry.getKey(), entry.getValue()))
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.sorted(Comparator.comparing(SpeciesClassifyLibraryRespVO::getSpeciesClassName))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 记录错误日志,返回空列表
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建通用树结构
|
* 构建通用树结构
|
||||||
*
|
*
|
||||||
@@ -209,4 +242,62 @@ public class TreeStructureUtil {
|
|||||||
level2Node.setChildren(level3Nodes);
|
level2Node.setChildren(level3Nodes);
|
||||||
return level2Node;
|
return level2Node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建二级树节点(只包含一级和二级,不包含三级)
|
||||||
|
*/
|
||||||
|
private static SpeciesClassifyLibraryRespVO buildTwoLevelNode(String level1Code, List<SysDictDO> level1Children) {
|
||||||
|
if (level1Children == null || level1Children.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取一级分类名称
|
||||||
|
String level1Name = level1Children.stream()
|
||||||
|
.filter(TreeStructureUtil::isValidLevel1Node)
|
||||||
|
.map(SysDictDO::getField1Name)
|
||||||
|
.findFirst()
|
||||||
|
.orElse("");
|
||||||
|
|
||||||
|
if (level1Name.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建一级节点
|
||||||
|
SpeciesClassifyLibraryRespVO level1Node = new SpeciesClassifyLibraryRespVO(level1Code, level1Name);
|
||||||
|
|
||||||
|
// 按二级分类分组
|
||||||
|
Map<String, List<SysDictDO>> groupedByLevel2 = level1Children.stream()
|
||||||
|
.filter(dict -> isValidLevel2Node(dict))
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
SysDictDO::getField2Code,
|
||||||
|
Collectors.toList()
|
||||||
|
));
|
||||||
|
|
||||||
|
// 构建二级节点列表(不包含三级)
|
||||||
|
List<SpeciesClassifyLibraryRespVO> level2Nodes = groupedByLevel2.entrySet().stream()
|
||||||
|
.map(entry -> {
|
||||||
|
String level2Code = entry.getKey();
|
||||||
|
List<SysDictDO> level2Children = entry.getValue();
|
||||||
|
|
||||||
|
// 获取二级分类名称
|
||||||
|
String level2Name = level2Children.stream()
|
||||||
|
.filter(TreeStructureUtil::isValidLevel2Node)
|
||||||
|
.map(SysDictDO::getField2Name)
|
||||||
|
.findFirst()
|
||||||
|
.orElse("");
|
||||||
|
|
||||||
|
if (level2Name.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建二级节点(不设置children,即不包含三级分类)
|
||||||
|
return new SpeciesClassifyLibraryRespVO(level2Code, level2Name);
|
||||||
|
})
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.sorted(Comparator.comparing(SpeciesClassifyLibraryRespVO::getSpeciesClassName))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
level1Node.setChildren(level2Nodes);
|
||||||
|
return level1Node;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user