123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- package models
- import (
- "eta_gn/eta_index_lib/global"
- "eta_gn/eta_index_lib/utils"
- "gorm.io/gorm"
- "time"
- )
- // PredictEdbRuleData 预测指标,动态规则的计算数据
- 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
- }
- // PredictEdbRuleDataItem 预测指标,动态规则的计算数据
- 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
- }
- // GetPredictEdbRuleDataItemList 根据基础预测指标id集合 获取 所有的普通指标列表数据
- 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_DmSQL.Raw(sql, pars...).Scan(&list).Error
- if err != nil {
- return
- }
- for _, v := range list {
- v.ConvertDate()
- }
- return
- }
- // GetPredictEdbRuleDataByTo
- // @Description: 根据配置id获取数据
- // @author: Roc
- // @datetime 2024-10-31 15:17:38
- // @param to *gorm.DB
- // @param configId int
- // @return list []*PredictEdbRuleData
- // @return err error
- 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
- }
- // AfterFind 在该模型上设置钩子函数,把日期转成正确的string,所以查询函数只能用Find函数,First或者Scan是不会触发该函数的来获取数据
- func (m *PredictEdbRuleData) AfterFind(db *gorm.DB) (err error) {
- if m.DataTime == "" {
- return
- }
- dataDateTmp, err := time.ParseInLocation(utils.FormatDateWallWithLoc, m.DataTime, time.Local)
- if err != nil {
- return
- }
- m.DataTime = dataDateTmp.Format(utils.FormatDate)
- return
- }
- // ConvertDate
- // @Description: 日期转换
- // @author: Roc
- // @receiver m
- // @datetime 2024-10-31 15:26:48
- func (m *PredictEdbRuleData) ConvertDate() {
- m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
- return
- }
- // ConvertDate
- // @Description: 日期转换
- // @author: Roc
- // @receiver m
- // @datetime 2024-10-31 15:26:59
- func (m *PredictEdbRuleDataItem) ConvertDate() {
- m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
- return
- }
|