ziwen 1 year ago
parent
commit
8baa5b0e7c
2 changed files with 53 additions and 3 deletions
  1. 10 1
      controllers/sandbox/sandbox.go
  2. 43 2
      models/sandbox/sandbox.go

+ 10 - 1
controllers/sandbox/sandbox.go

@@ -1405,9 +1405,18 @@ func (this *SandboxController) ListV2() {
 		return
 	}
 
+	for i, v := range list {
+		ids, err := sandbox.GetSandboxAllParentByClassifyId(v.SandboxClassifyId)
+		if err != nil {
+			br.Msg = "获取父级信息错误!"
+			br.ErrMsg = "获取父级信息错误,Err:" + err.Error()
+			return
+		}
+		list[i].ParentIds = ids
+	}
 	resp := new(sandbox.SandboxListResp)
 	if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
-		items := make([]*sandbox.Sandbox, 0)
+		items := make([]*sandbox.SandboxListItems, 0)
 		resp.Paging = page
 		resp.List = items
 		br.Ret = 200

+ 43 - 2
models/sandbox/sandbox.go

@@ -268,7 +268,11 @@ WHERE
 	return
 }
 
-func GetSandboxListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*Sandbox, err error) {
+type SandboxListItems struct {
+	Sandbox
+	ParentIds string
+}
+func GetSandboxListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*SandboxListItems, err error) {
 	o := orm.NewOrmUsingDB("data")
 	sql := ` SELECT * FROM sandbox WHERE 1=1 `
 	if condition != "" {
@@ -291,7 +295,7 @@ func GetSandboxListCountByCondition(condition string, pars []interface{}) (count
 
 type SandboxListResp struct {
 	Paging *paging.PagingItem
-	List   []*Sandbox
+	List   []*SandboxListItems
 }
 
 func AddSandbox(item *Sandbox) (lastId int64, err error) {
@@ -306,4 +310,41 @@ func GetSandboxItemsByClassifyId(sandboxClassifyId int) (list []*SandboxClassify
 		FROM sandbox  WHERE sandbox_classify_id = ? AND is_delete = 0 `
 	_, err = o.Raw(sql,sandboxClassifyId).QueryRows(&list)
 	return
+}
+
+func GetSandboxAllParentByClassifyId(sandboxClassifyId int) (ids string, err error) {
+	o := orm.NewOrmUsingDB("data")
+	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 
+		) 
+	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
+	sandbox_classify_id = vm._id `
+	err = o.Raw(sql,sandboxClassifyId).QueryRow(&ids)
+	return
 }