edb_classify.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package data_manage
  2. import (
  3. "eta/eta_hub/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "strings"
  7. "time"
  8. )
  9. // EdbClassify 指标分类
  10. type EdbClassify struct {
  11. ClassifyId int `orm:"column(classify_id);pk"`
  12. ClassifyType uint8 `description:"分类类型,0:普通指标分类,1:预测指标分类"`
  13. ClassifyName string `description:"分类名称"`
  14. ParentId int `description:"父级id"`
  15. RootId int `description:"顶级id"`
  16. HasData int `description:"是否含有指标数据"`
  17. SysUserId int `description:"创建人id"`
  18. SysUserRealName string `description:"创建人姓名"`
  19. Level int `description:"层级"`
  20. UniqueCode string `description:"唯一编码"`
  21. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  22. CreateTime time.Time `description:"创建时间"`
  23. ModifyTime time.Time `description:"修改时间"`
  24. }
  25. func (m *EdbClassify) GetItemsByCondition(cond string, pars []interface{}, fieldArr []string, orderRule string) (items []*EdbClassify, err error) {
  26. o := orm.NewOrmUsingDB("data")
  27. fields := strings.Join(fieldArr, ",")
  28. if len(fieldArr) == 0 {
  29. fields = `*`
  30. }
  31. order := `ORDER BY create_time DESC`
  32. if orderRule != "" {
  33. order = ` ORDER BY ` + orderRule
  34. }
  35. sql := fmt.Sprintf(`SELECT %s FROM edb_classify WHERE 1=1 %s %s`, fields, cond, order)
  36. _, err = o.Raw(sql, pars).QueryRows(&items)
  37. return
  38. }
  39. // EdbClassifyItem 指标分类信息
  40. type EdbClassifyItem struct {
  41. ClassifyId int `description:"分类ID"`
  42. ClassifyName string `description:"分类名称"`
  43. UniqueCode string `description:"分类唯一编码"`
  44. ParentId int `description:"父级id"`
  45. Level int `description:"层级"`
  46. Sort int `description:"排序"`
  47. CreateTime string `description:"创建时间"`
  48. UpdateTime string `description:"更新时间"`
  49. Child []*EdbClassifyItem `description:"子分类"`
  50. }
  51. func FormatEdbClassify2Item(origin *EdbClassify) (item *EdbClassifyItem) {
  52. if origin == nil {
  53. return
  54. }
  55. item = new(EdbClassifyItem)
  56. item.ClassifyId = origin.ClassifyId
  57. item.ClassifyName = origin.ClassifyName
  58. item.UniqueCode = origin.UniqueCode
  59. item.ParentId = origin.ParentId
  60. item.Level = origin.Level
  61. item.Sort = origin.Sort
  62. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  63. item.UpdateTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  64. item.Child = make([]*EdbClassifyItem, 0)
  65. return
  66. }