From 9b71c96e61c55bf60c0fb555d5038d541f7a0f29 Mon Sep 17 00:00:00 2001 From: what-00 Date: Thu, 13 Apr 2023 10:03:21 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20=E6=96=B0=E5=A2=9E=20GetJoinResDepende?= =?UTF-8?q?ncies,=20=E8=8E=B7=E5=8F=96=20join=20=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/res_relation.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/base/res_relation.go b/base/res_relation.go index 1369398..b656ea1 100644 --- a/base/res_relation.go +++ b/base/res_relation.go @@ -15,3 +15,28 @@ type ResRelation struct { } type GetResRelations func(categoryUuid string) []ResRelation + +// 资源关联依赖 +func GetJoinResDependencies(code string, items []ResRelation) (dependencies []string) { + dependencies = []string{code} + + for { + done := true + for _, item := range items { + if item.Type != "inner" && item.Type != "left" && item.Type != "right" { + continue + } + + if dependencies[len(dependencies)-1] == item.Code && item.RelationResource != "" { + done = false + dependencies = append(dependencies, item.RelationResource) + } + } + + if done { + break + } + } + + return dependencies +}