edb_classify.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type EdbClassify struct {
  7. ClassifyId int `orm:"column(classify_id);pk"`
  8. ClassifyType uint8 `description:"分类类型,0:普通指标分类,1:预测指标分类"`
  9. ClassifyName string `description:"分类名称"`
  10. ParentId int `description:"父级id"`
  11. HasData int `description:"是否含有指标数据"`
  12. CreateTime time.Time `description:"创建时间"`
  13. ModifyTime time.Time `description:"修改时间"`
  14. SysUserId int `description:"创建人id"`
  15. SysUserRealName string `description:"创建人姓名"`
  16. Level int `description:"层级"`
  17. UniqueCode string `description:"唯一编码"`
  18. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  19. }
  20. func GetEdbClassifyById(classifyId int) (item *EdbClassify, err error) {
  21. o := orm.NewOrm()
  22. sql := `SELECT * FROM edb_classify WHERE classify_id=? `
  23. err = o.Raw(sql, classifyId).QueryRow(&item)
  24. return
  25. }
  26. type EdbClassifySimplify struct {
  27. ClassifyId int `description:"分类id"`
  28. ClassifyName string `description:"分类名称"`
  29. ParentId int
  30. }
  31. //递归获取所有目录
  32. func GetClassifyAllByClassifyId(classifyId int) (resultList []*EdbClassifySimplify, err error) {
  33. o := orm.NewOrm()
  34. for {
  35. sql := ` SELECT * FROM edb_classify AS a WHERE a.classify_id=? order by sort asc,classify_id asc`
  36. item := new(EdbClassifySimplify)
  37. err = o.Raw(sql, classifyId).QueryRow(&item)
  38. if err != nil {
  39. break
  40. }
  41. if item.ClassifyId > 0 {
  42. resultList = append(resultList, item)
  43. classifyId = item.ParentId
  44. } else {
  45. break
  46. }
  47. }
  48. return resultList, err
  49. }