package models import ( "time" "github.com/beego/beego/v2/client/orm" ) type EdbDataCalculateStl struct { EdbDataId int `orm:"pk"` EdbInfoId int `description:"指标id"` EdbCode string `description:"指标编码"` DataTime time.Time `description:"数据时间"` Value float64 `description:"数据值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` DataTimestamp int64 `description:"数据时间戳"` } type CalculateStlConfigMapping struct { Id int `orm:"pk" description:"主键"` CalculateStlConfigId int `description:"stl配置id"` EdbInfoId int `description:"edb信息id"` StlEdbType int `description:"stl指标类型: 1-Trend, 2-Seasonal, 3-Residual"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` } type CalculateStlConfig struct { CalculateStlConfigId int `orm:"column(calculate_stl_config_id);pk"` Config string `description:"STL计算配置"` SysUserId int `description:"系统用户ID"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func GetRelationCalculateStlConfigMappingByEdbInfoId(edbInfoId int) (items []*CalculateStlConfigMapping, err error) { o := orm.NewOrm() sql := `SELECT calculate_stl_config_id FROM calculate_stl_config_mapping WHERE edb_info_id =? LIMIT 1` var confId int err = o.Raw(sql, edbInfoId).QueryRow(&confId) if err != nil { return } sql = `SELECT * FROM calculate_stl_config_mapping WHERE calculate_stl_config_id =?` _, err = o.Raw(sql, confId).QueryRows(&items) return } // GetCalculateStlConfigMappingByConfigId 根据配置文件id获取配置文件映射信息 func GetCalculateStlConfigMappingByConfigId(configId int) (items []*CalculateStlConfigMapping, err error) { o := orm.NewOrm() sql := `SELECT * FROM calculate_stl_config_mapping WHERE calculate_stl_config_id=?` _, err = o.Raw(sql, configId).QueryRows(&items) return } // GetCalculateStlConfigMappingIdByEdbInfoId 获取配置文件id func GetCalculateStlConfigMappingIdByEdbInfoId(edbInfoId int) (configId int, err error) { o := orm.NewOrm() sql := `SELECT calculate_stl_config_id FROM calculate_stl_config_mapping WHERE edb_info_id=? LIMIT 1` err = o.Raw(sql, edbInfoId).QueryRow(&configId) return } func DeleteAndInsertEdbDataCalculateStl(edbCode string, dataList []*EdbDataCalculateStl) (err error) { tx, err := orm.NewOrm().Begin() if err != nil { return } defer func() { if err != nil { tx.Rollback() } else { tx.Commit() } }() sql := `DELETE FROM edb_data_calculate_stl WHERE edb_code =?` _, err = tx.Raw(sql, edbCode).Exec() if err != nil { return } _, err = tx.InsertMulti(500, dataList) return } func (c *CalculateStlConfig) Update(cols []string) (err error) { o := orm.NewOrm() _, err = o.Update(c, cols...) return } func GetCalculateStlConfigById(id int) (item *CalculateStlConfig, err error) { o := orm.NewOrm() sql := "SELECT * FROM calculate_stl_config WHERE calculate_stl_config_id =?" err = o.Raw(sql, id).QueryRow(&item) return }