chart_framework_node.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package data_manage
  2. import (
  3. "eta/eta_mobile/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "strings"
  7. "time"
  8. )
  9. // ChartFrameworkNode 图库框架节点表
  10. type ChartFrameworkNode struct {
  11. ChartFrameworkNodeId int `orm:"column(chart_framework_node_id);pk"`
  12. ChartFrameworkId int `description:"框架ID"`
  13. FrameworkName string `description:"框架名称"`
  14. NodeId string `description:"节点ID"`
  15. NodeName string `description:"节点名称"`
  16. MyChartClassifyId int `description:"我的图表分类ID"`
  17. CreateTime time.Time `description:"创建时间"`
  18. }
  19. func (m *ChartFrameworkNode) TableName() string {
  20. return "chart_framework_node"
  21. }
  22. func (m *ChartFrameworkNode) PrimaryId() string {
  23. return "chart_framework_node_id"
  24. }
  25. func (m *ChartFrameworkNode) Create() (err error) {
  26. o := orm.NewOrmUsingDB("data")
  27. id, err := o.Insert(m)
  28. if err != nil {
  29. return
  30. }
  31. m.ChartFrameworkNodeId = int(id)
  32. return
  33. }
  34. func (m *ChartFrameworkNode) CreateMulti(items []*ChartFrameworkNode) (err error) {
  35. if len(items) == 0 {
  36. return
  37. }
  38. o := orm.NewOrmUsingDB("data")
  39. _, err = o.InsertMulti(len(items), items)
  40. return
  41. }
  42. func (m *ChartFrameworkNode) Update(cols []string) (err error) {
  43. o := orm.NewOrmUsingDB("data")
  44. _, err = o.Update(m, cols...)
  45. return
  46. }
  47. func (m *ChartFrameworkNode) Del() (err error) {
  48. o := orm.NewOrmUsingDB("data")
  49. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  50. _, err = o.Raw(sql, m.ChartFrameworkNodeId).Exec()
  51. return
  52. }
  53. func (m *ChartFrameworkNode) GetItemById(id int) (item *ChartFrameworkNode, err error) {
  54. o := orm.NewOrmUsingDB("data")
  55. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  56. err = o.Raw(sql, id).QueryRow(&item)
  57. return
  58. }
  59. func (m *ChartFrameworkNode) GetItemByCondition(condition string, pars []interface{}) (item *ChartFrameworkNode, err error) {
  60. o := orm.NewOrmUsingDB("data")
  61. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
  62. err = o.Raw(sql, pars).QueryRow(&item)
  63. return
  64. }
  65. func (m *ChartFrameworkNode) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  66. o := orm.NewOrmUsingDB("data")
  67. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  68. err = o.Raw(sql, pars).QueryRow(&count)
  69. return
  70. }
  71. func (m *ChartFrameworkNode) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*ChartFrameworkNode, err error) {
  72. o := orm.NewOrmUsingDB("data")
  73. fields := strings.Join(fieldArr, ",")
  74. if len(fieldArr) == 0 {
  75. fields = `*`
  76. }
  77. order := `ORDER BY create_time DESC`
  78. if orderRule != "" {
  79. order = ` ORDER BY ` + orderRule
  80. }
  81. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  82. _, err = o.Raw(sql, pars).QueryRows(&items)
  83. return
  84. }
  85. func (m *ChartFrameworkNode) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*ChartFrameworkNode, err error) {
  86. o := orm.NewOrmUsingDB("data")
  87. fields := strings.Join(fieldArr, ",")
  88. if len(fieldArr) == 0 {
  89. fields = `*`
  90. }
  91. order := `ORDER BY create_time DESC`
  92. if orderRule != "" {
  93. order = ` ORDER BY ` + orderRule
  94. }
  95. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  96. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  97. return
  98. }
  99. // ChartFrameworkNodeItem 图库框架节点信息
  100. type ChartFrameworkNodeItem struct {
  101. ChartFrameworkNodeId int
  102. ChartFrameworkId int `description:"框架ID"`
  103. FrameworkName string `description:"框架名称"`
  104. NodeId string `description:"节点ID"`
  105. NodeName string `description:"节点名称"`
  106. MyChartClassifyId int `description:"我的图表分类ID"`
  107. ChartNum int `description:"分类下的图表数"`
  108. CreateTime string `description:"创建时间"`
  109. }
  110. // FormatChartFrameworkNode2Item 格式化框架节点信息
  111. func FormatChartFrameworkNode2Item(origin *ChartFrameworkNode, chartNum int) (item *ChartFrameworkNodeItem) {
  112. if origin == nil {
  113. return
  114. }
  115. item = new(ChartFrameworkNodeItem)
  116. item.ChartFrameworkNodeId = origin.ChartFrameworkNodeId
  117. item.ChartFrameworkId = origin.ChartFrameworkId
  118. item.FrameworkName = origin.FrameworkName
  119. item.NodeId = origin.NodeId
  120. item.NodeName = origin.NodeName
  121. item.MyChartClassifyId = origin.MyChartClassifyId
  122. item.ChartNum = chartNum
  123. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  124. return
  125. }