predict_edb_rule_data.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package models
  2. import (
  3. "eta_gn/eta_index_lib/global"
  4. "eta_gn/eta_index_lib/utils"
  5. "gorm.io/gorm"
  6. "time"
  7. )
  8. // PredictEdbRuleData 预测指标,动态规则的计算数据
  9. type PredictEdbRuleData struct {
  10. PredictEdbRuleDataId int `gorm:"primaryKey;autoIncrement;column:predict_edb_rule_data_id"`
  11. EdbInfoId int
  12. ConfigId int
  13. DataTime string
  14. Value string
  15. CreateTime time.Time
  16. ModifyTime time.Time
  17. DataTimestamp int64
  18. }
  19. // PredictEdbRuleDataItem 预测指标,动态规则的计算数据
  20. type PredictEdbRuleDataItem struct {
  21. PredictEdbRuleDataId int `gorm:"primaryKey;autoIncrement;column:predict_edb_rule_data_id"`
  22. EdbInfoId int
  23. ConfigId int
  24. DataTime string
  25. Value float64
  26. CreateTime time.Time
  27. ModifyTime time.Time
  28. DataTimestamp int64
  29. }
  30. // GetPredictEdbRuleDataItemList 根据基础预测指标id集合 获取 所有的普通指标列表数据
  31. func GetPredictEdbRuleDataItemList(edbInfoId, configId int, startDate, endDate string) (list []*PredictEdbRuleDataItem, err error) {
  32. var pars []interface{}
  33. sql := ` SELECT * FROM predict_edb_rule_data WHERE edb_info_id = ? AND config_id = ? `
  34. pars = append(pars, edbInfoId, configId)
  35. if startDate != "" {
  36. sql += ` AND data_time>=? `
  37. pars = append(pars, startDate)
  38. }
  39. if endDate != "" {
  40. sql += ` AND data_time<=? `
  41. pars = append(pars, endDate)
  42. }
  43. sql += ` ORDER BY data_time ASC `
  44. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&list).Error
  45. if err != nil {
  46. return
  47. }
  48. for _, v := range list {
  49. v.ConvertDate()
  50. }
  51. return
  52. }
  53. // GetPredictEdbRuleDataByTo
  54. // @Description: 根据配置id获取数据
  55. // @author: Roc
  56. // @datetime 2024-10-31 15:17:38
  57. // @param to *gorm.DB
  58. // @param configId int
  59. // @return list []*PredictEdbRuleData
  60. // @return err error
  61. func GetPredictEdbRuleDataByTo(to *gorm.DB, configId int) (list []*PredictEdbRuleData, err error) {
  62. sql := `SELECT * FROM predict_edb_rule_data WHERE config_id = ?`
  63. err = to.Raw(sql, configId).Find(&list).Error
  64. return
  65. }
  66. // AfterFind 在该模型上设置钩子函数,把日期转成正确的string,所以查询函数只能用Find函数,First或者Scan是不会触发该函数的来获取数据
  67. func (m *PredictEdbRuleData) AfterFind(db *gorm.DB) (err error) {
  68. if m.DataTime == "" {
  69. return
  70. }
  71. dataDateTmp, err := time.ParseInLocation(utils.FormatDateWallWithLoc, m.DataTime, time.Local)
  72. if err != nil {
  73. return
  74. }
  75. m.DataTime = dataDateTmp.Format(utils.FormatDate)
  76. return
  77. }
  78. // ConvertDate
  79. // @Description: 日期转换
  80. // @author: Roc
  81. // @receiver m
  82. // @datetime 2024-10-31 15:26:48
  83. func (m *PredictEdbRuleData) ConvertDate() {
  84. m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
  85. return
  86. }
  87. // ConvertDate
  88. // @Description: 日期转换
  89. // @author: Roc
  90. // @receiver m
  91. // @datetime 2024-10-31 15:26:59
  92. func (m *PredictEdbRuleDataItem) ConvertDate() {
  93. m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
  94. return
  95. }