chart_classify.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. // ChartClassify 图表分类表
  10. type ChartClassify struct {
  11. ChartClassifyId int `orm:"column(chart_classify_id);pk"`
  12. ChartClassifyName string `description:"分类名称"`
  13. ParentId int `description:"父级id"`
  14. HasData int `description:"是否含有指标数据"`
  15. SysUserId int `description:"创建人id"`
  16. SysUserRealName string `description:"创建人姓名"`
  17. Level int `description:"层级"`
  18. UniqueCode string `description:"唯一编码"`
  19. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  20. Source int `description:"1:ETA图库;2:商品价格曲线"`
  21. CreateTime time.Time `description:"创建时间"`
  22. ModifyTime time.Time `description:"修改时间"`
  23. }
  24. func (m *ChartClassify) GetItemsByCondition(cond string, pars []interface{}, fieldArr []string, orderRule string) (items []*ChartClassify, err error) {
  25. o := orm.NewOrmUsingDB("data")
  26. fields := strings.Join(fieldArr, ",")
  27. if len(fieldArr) == 0 {
  28. fields = `*`
  29. }
  30. order := `ORDER BY create_time DESC`
  31. if orderRule != "" {
  32. order = ` ORDER BY ` + orderRule
  33. }
  34. sql := fmt.Sprintf(`SELECT %s FROM chart_classify WHERE 1=1 %s %s`, fields, cond, order)
  35. _, err = o.Raw(sql, pars).QueryRows(&items)
  36. return
  37. }
  38. // ChartClassifyItem 指标分类信息
  39. type ChartClassifyItem struct {
  40. ClassifyId int `description:"分类ID"`
  41. ClassifyName string `description:"分类名称"`
  42. UniqueCode string `description:"唯一编码"`
  43. ParentId int `description:"父级ID"`
  44. Level int `description:"层级"`
  45. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  46. //Source int `description:"1-ETA图库; 2-商品价格曲线"`
  47. CreateTime string `description:"创建时间"`
  48. UpdateTime string `description:"修改时间"`
  49. Child []*ChartClassifyItem `description:"子分类"`
  50. }
  51. func FormatChartClassify2Item(origin *ChartClassify) (item *ChartClassifyItem) {
  52. if origin == nil {
  53. return
  54. }
  55. item = new(ChartClassifyItem)
  56. item.ClassifyId = origin.ChartClassifyId
  57. item.ClassifyName = origin.ChartClassifyName
  58. item.UniqueCode = origin.UniqueCode
  59. item.ParentId = origin.ParentId
  60. item.Level = origin.Level
  61. item.Sort = origin.Sort
  62. //item.Source = origin.Source
  63. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  64. item.UpdateTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  65. item.Child = make([]*ChartClassifyItem, 0)
  66. return
  67. }
  68. type ChartClassifyView struct {
  69. ChartClassifyId int `description:"图表分类"`
  70. ChartClassifyName string `description:"分类名称"`
  71. ParentId int `description:"父级ID"`
  72. }
  73. func GetChartClassifyViewById(classifyId int) (item *ChartClassifyView, err error) {
  74. o := orm.NewOrmUsingDB("data")
  75. sql := `SELECT * FROM chart_classify WHERE chart_classify_id=? `
  76. err = o.Raw(sql, classifyId).QueryRow(&item)
  77. return
  78. }