123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- package models
- import (
- "eta/eta_index_lib/global"
- "eta/eta_index_lib/utils"
- "gorm.io/gorm"
- "time"
- )
- type PredictEdbRuleData struct {
- PredictEdbRuleDataId int `gorm:"primaryKey;autoIncrement;column:predict_edb_rule_data_id"`
- EdbInfoId int
- ConfigId int
- DataTime string
- Value string
- CreateTime time.Time
- ModifyTime time.Time
- DataTimestamp int64
- }
- func (m *PredictEdbRuleData) AfterFind(db *gorm.DB) (err error) {
- m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
- return
- }
- type PredictEdbRuleDataItem struct {
- PredictEdbRuleDataId int `gorm:"primaryKey;autoIncrement;column:predict_edb_rule_data_id"`
- EdbInfoId int
- ConfigId int
- DataTime string
- Value float64
- CreateTime time.Time
- ModifyTime time.Time
- DataTimestamp int64
- }
- func (m *PredictEdbRuleDataItem) AfterFind(db *gorm.DB) (err error) {
- m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
- return
- }
- func GetPredictEdbRuleDataItemList(edbInfoId, configId int, startDate, endDate string) (list []*PredictEdbRuleDataItem, err error) {
- var pars []interface{}
- sql := ` SELECT * FROM predict_edb_rule_data WHERE edb_info_id = ? AND config_id = ? `
- pars = append(pars, edbInfoId, configId)
- if startDate != "" {
- sql += ` AND data_time>=? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- sql += ` AND data_time<=? `
- pars = append(pars, endDate)
- }
- sql += ` ORDER BY data_time ASC `
- err = global.DEFAULT_DB.Raw(sql, pars...).Find(&list).Error
- if err != nil {
- return
- }
- for _, v := range list {
- v.ConvertDate()
- }
- return
- }
- func GetPredictEdbRuleDataByTo(to *gorm.DB, configId int) (list []*PredictEdbRuleData, err error) {
- sql := `SELECT * FROM predict_edb_rule_data WHERE config_id = ?`
- err = to.Raw(sql, configId).Find(&list).Error
- return
- }
- func (m *PredictEdbRuleData) ConvertDate() {
- m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
- return
- }
- func (m *PredictEdbRuleDataItem) ConvertDate() {
- m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
- return
- }
|