chart_theme_default_data.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package models
  2. import (
  3. "eta/eta_forum_task/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // ChartThemeDefaultData
  8. // @Description: 图表默认数据
  9. type ChartThemeDefaultData struct {
  10. EdbDataId int `description:"指标数据ID" orm:"column(edb_data_id);pk"`
  11. EdbInfoId int `description:"指标ID"`
  12. EdbCode string `description:"指标编码"`
  13. DataTime string //`json:"-" description:"数据日期"`
  14. DataTimestamp int64 `description:"数据日期"`
  15. Value float64 `description:"数据值"`
  16. ModifyTime time.Time `description:"修改时间"`
  17. CreateTime time.Time `description:"创建时间"`
  18. }
  19. // GetChartThemeDefaultDataList
  20. // @Description: 获取指标的数据(日期正序返回)
  21. // @author: Roc
  22. // @datetime 2023-12-13 16:40:14
  23. // @param endInfoId int
  24. // @return list []*ChartThemeDefaultData
  25. // @return err error
  26. func GetChartThemeDefaultDataList(endInfoId int) (list []*ChartThemeDefaultData, err error) {
  27. sql := `SELECT * FROM chart_theme_default_data WHERE edb_info_id=? `
  28. sql += ` ORDER BY data_time ASC `
  29. o := orm.NewOrmUsingDB("data")
  30. _, err = o.Raw(sql, endInfoId).QueryRows(&list)
  31. return
  32. }
  33. // Update
  34. // @Description: 更新
  35. // @author: Roc
  36. // @receiver m
  37. // @datetime 2023-12-13 16:40:04
  38. // @param cols []string
  39. // @return err error
  40. func (m *ChartThemeDefaultData) Update(cols []string) (err error) {
  41. o := orm.NewOrmUsingDB("data")
  42. _, err = o.Update(m, cols...)
  43. return
  44. }
  45. // GetChartThemeDefaultDataItemList
  46. // @Description: 获取指标的数据(日期正序返回)
  47. // @author: Roc
  48. // @datetime 2023-12-13 16:40:22
  49. // @param endInfoId int
  50. // @return list []*ChartThemeDefaultDataItem
  51. // @return err error
  52. func GetChartThemeDefaultDataItemList(endInfoId int, startDate string) (list []*EdbDataList, err error) {
  53. sql := `SELECT edb_data_id,edb_info_id,data_time,value,data_timestamp FROM chart_theme_default_data WHERE edb_info_id=? `
  54. var pars []interface{}
  55. if startDate != "" {
  56. sql += ` AND data_time>=? `
  57. pars = append(pars, startDate)
  58. }
  59. sql += ` ORDER BY data_time ASC `
  60. o := orm.NewOrmUsingDB("data")
  61. _, err = o.Raw(sql, endInfoId, pars).QueryRows(&list)
  62. return
  63. }
  64. // GetChartEdbMappingListByEdbInfoId
  65. // @Description: 返回模拟的mapping假数据
  66. // @author: Roc
  67. // @datetime 2023-12-14 10:03:20
  68. // @param edbInfoIdList []int
  69. // @return list []*models.ChartEdbInfoMapping
  70. // @return err error
  71. func GetChartEdbMappingListByEdbInfoId(edbInfoIdList []int) (list []*ChartEdbInfoMapping, err error) {
  72. num := len(edbInfoIdList)
  73. if num <= 0 {
  74. return
  75. }
  76. o := orm.NewOrmUsingDB("data")
  77. sql := ` SELECT * FROM chart_theme_default_edb_info WHERE edb_info_id IN(` + utils.GetOrmInReplace(num) + `)
  78. `
  79. _, err = o.Raw(sql, edbInfoIdList).QueryRows(&list)
  80. return
  81. }