chart_framework_node.go 4.5 KB

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