package models

import (
	"github.com/beego/beego/v2/client/orm"
)

type EdbClassifySimplify struct {
	ClassifyId   int    `description:"分类id"`
	ClassifyName string `description:"分类名称"`
	ParentId     int
}

//递归获取所有目录
func GetClassifyAllByClassifyId(classifyId int) (resultList []*EdbClassifySimplify, err error) {
	o := orm.NewOrm()
	for {
		sql := ` SELECT * FROM edb_classify AS a WHERE a.classify_id=? order by sort asc,classify_id asc`
		item := new(EdbClassifySimplify)
		err = o.Raw(sql, classifyId).QueryRow(&item)
		if err != nil {
			break
		}
		if item.ClassifyId > 0 {
			resultList = append(resultList, item)
			classifyId = item.ParentId
		} else {
			break
		}
	}
	return resultList, err
}