|
@@ -333,37 +333,62 @@ func GetSandboxItemsByClassifyId(sandboxClassifyId int) (list []*SandboxClassify
|
|
|
|
|
|
func GetSandboxAllParentByClassifyId(sandboxClassifyId int) (ids string, err error) {
|
|
|
o := global.DbMap[utils.DbNameIndex]
|
|
|
- sql := `SELECT
|
|
|
- GROUP_CONCAT(DISTINCT m.sandbox_classify_id ORDER BY m.level) AS ids
|
|
|
-FROM
|
|
|
- (
|
|
|
- SELECT
|
|
|
- @id AS _id,(
|
|
|
- SELECT
|
|
|
- @id := parent_id
|
|
|
- FROM
|
|
|
- sandbox_classify
|
|
|
- WHERE
|
|
|
- sandbox_classify_id = _id
|
|
|
- )
|
|
|
+ var sql string
|
|
|
+ if utils.DbDriverName == utils.DbDriverByDm {
|
|
|
+ sql = `WITH RECURSIVE parent_tree (ai_summary_classify_id, parent_id, level) AS (
|
|
|
+ -- 获取起始节点的父级
|
|
|
+ SELECT ai_summary_classify_id, parent_id, 1 as level
|
|
|
+ FROM ai_summary_classify
|
|
|
+ WHERE ai_summary_classify_id = (
|
|
|
+ SELECT parent_id
|
|
|
+ FROM ai_summary_classify
|
|
|
+ WHERE ai_summary_classify_id = ?
|
|
|
+ )
|
|
|
+
|
|
|
+ UNION ALL
|
|
|
+
|
|
|
+ -- 递归获取所有上级节点
|
|
|
+ SELECT ac.ai_summary_classify_id, ac.parent_id, pt.level + 1
|
|
|
+ FROM ai_summary_classify ac
|
|
|
+ JOIN parent_tree pt ON ac.ai_summary_classify_id = pt.parent_id
|
|
|
+ WHERE ac.parent_id IS NOT NULL
|
|
|
+)
|
|
|
+SELECT LISTAGG(ai_summary_classify_id, ',') WITHIN GROUP (ORDER BY level DESC) AS ids
|
|
|
+FROM parent_tree`
|
|
|
+ }else{
|
|
|
+ sql = `SELECT
|
|
|
+ GROUP_CONCAT(DISTINCT m.sandbox_classify_id ORDER BY m.level) AS ids
|
|
|
FROM
|
|
|
(
|
|
|
SELECT
|
|
|
- @id :=(
|
|
|
+ @id AS _id,(
|
|
|
SELECT
|
|
|
- parent_id
|
|
|
+ @id := parent_id
|
|
|
FROM
|
|
|
sandbox_classify
|
|
|
WHERE
|
|
|
- sandbox_classify_id = ?
|
|
|
- )) vm,
|
|
|
- sandbox_classify m
|
|
|
+ sandbox_classify_id = _id
|
|
|
+ )
|
|
|
+ FROM
|
|
|
+ (
|
|
|
+ SELECT
|
|
|
+ @id :=(
|
|
|
+ SELECT
|
|
|
+ parent_id
|
|
|
+ FROM
|
|
|
+ sandbox_classify
|
|
|
+ WHERE
|
|
|
+ sandbox_classify_id = ?
|
|
|
+ )) vm,
|
|
|
+ sandbox_classify m
|
|
|
+ WHERE
|
|
|
+ @id IS NOT NULL
|
|
|
+ ) vm
|
|
|
+ INNER JOIN sandbox_classify m
|
|
|
WHERE
|
|
|
- @id IS NOT NULL
|
|
|
- ) vm
|
|
|
- INNER JOIN sandbox_classify m
|
|
|
-WHERE
|
|
|
- sandbox_classify_id = vm._id `
|
|
|
+ sandbox_classify_id = vm._id `
|
|
|
+ }
|
|
|
+
|
|
|
err = o.Raw(sql, sandboxClassifyId).Scan(&ids).Error
|
|
|
return
|
|
|
}
|