package stl import ( "eta/eta_api/global" "eta/eta_api/utils" "time" ) type EdbDataCalculateStl struct { EdbDataId int `orm:"pk" gorm:"primaryKey"` 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:"数据时间戳" gorm:"column:data_timestamp"` } func GetEdbDataCalculateStlByEdbCode(edbCode string) (items []*EdbDataCalculateStl, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT * FROM edb_data_calculate_stl WHERE edb_code =? ORDER BY data_time` err = o.Raw(sql, edbCode).Find(&items).Error return } func DeleteAndInsertEdbDataCalculateStl(edbCode string, dataList []*EdbDataCalculateStl) (err error) { to := global.DbMap[utils.DbNameIndex].Begin() defer func() { if err != nil { _ = to.Rollback() } else { _ = to.Commit() } }() sql := `DELETE FROM edb_data_calculate_stl WHERE edb_code =?` err = to.Exec(sql, edbCode).Error if err != nil { return } err = to.CreateInBatches(dataList, len(dataList)).Error return } func (m *EdbDataCalculateStl) GetMaxId() (maxId int, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT max(edb_data_id) id FROM edb_data_calculate_stl limit 1` err = o.Raw(sql).Scan(&maxId).Error return } func (m *EdbDataCalculateStl) BatchInsert(dataList []*EdbDataCalculateStl) (err error) { o := global.DbMap[utils.DbNameIndex] err = o.CreateInBatches(dataList, utils.MultiAddNum).Error return }