fix(qc-material): 修复父节点路径构建及查询逻辑
- 修改fullPath构建逻辑,避免重复拼接父节点路径 - 调整查询条件,使用ltree类型转换为text进行匹配 - 优化级联查询自身及子孙节点的条件表达式 - 保证查询兼容性与准确性,提高查询性能
This commit is contained in:
parent
66f732bf66
commit
a43523da36
|
|
@ -113,13 +113,14 @@ public class QmsQcMaterialControllerService {
|
|||
// 构建当前节点完整路径:parentTree.id(若 parentTree 为空则直接取 id)
|
||||
String fullPath = StrUtil.isBlank(category.getParentTree())
|
||||
? String.valueOf(category.getId())
|
||||
: category.getParentTree() + "." + category.getId();
|
||||
: category.getParentTree();
|
||||
|
||||
// 一次查询:自身 + 直接子节点(parentTree=fullPath)+ 孙级及更深(parentTree LIKE 'fullPath.%')
|
||||
// parent_tree 为 ltree 类型,需显式转为 text 才能与 varchar 比较
|
||||
return qcMaterialCategoryService.lambdaQuery()
|
||||
.eq(QmsQcMaterialCategory::getCategoryCode, categoryCode)
|
||||
.or().eq(QmsQcMaterialCategory::getParentTree, fullPath)
|
||||
.or().likeRight(QmsQcMaterialCategory::getParentTree, fullPath + ".")
|
||||
.or().apply("parent_tree::text = {0}", fullPath)
|
||||
.or().apply("parent_tree::text LIKE {0}", fullPath + ".%")
|
||||
.list()
|
||||
.stream()
|
||||
.map(QmsQcMaterialCategory::getCategoryCode)
|
||||
|
|
|
|||
Loading…
Reference in New Issue