// @Author gmy 2024/10/21 9:50:00 package models import ( "errors" "github.com/beego/beego/v2/client/orm" ) type BaseFromRzdData struct { BaseFromRzdDataId int `orm:"column(base_from_rzd_data_id);pk"` BaseFromRzdIndexId int `orm:"column(base_from_rzd_index_id)"` CreateTime string `orm:"column(create_time)"` DataTime string `orm:"column(data_time)"` IndexCode string `orm:"column(index_code)"` ModifyTime string `orm:"column(modify_time)"` Value float64 `orm:"column(value)"` } func init() { orm.RegisterModel(new(BaseFromRzdData)) } // AddRzdDataList 批量插入数据记录列表 func AddRzdDataList(items []BaseFromRzdData) (err error) { o := orm.NewOrm() _, err = o.InsertMulti(len(items), items) return } // GetRzdDataByIndexCodeAndDataTime 根据指标id和数据日期查询数据 func GetRzdDataByIndexCodeAndDataTime(indexCode string, dataTime string) (items BaseFromRzdData, err error) { o := orm.NewOrm() sql := `SELECT * FROM base_from_rzd_data WHERE index_code=? AND data_time=?` err = o.Raw(sql, indexCode, dataTime).QueryRow(&items) // 使用 QueryRow if errors.Is(err, orm.ErrNoRows) { return items, nil } if err != nil { return items, err } return } // UpdateRzdDataById 根据主键id更新数据 func UpdateRzdDataById(dataId int, value float64) (err error) { o := orm.NewOrm() sql := `UPDATE base_from_rzd_data SET value=? WHERE base_from_rzd_data_id=?` _, err = o.Raw(sql, value, dataId).Exec() return } // GetBaseFromRzdDataByCondition 添加查询 func GetBaseFromRzdDataByCondition(condition string, pars []interface{}) (items []BaseFromRzdData, err error) { sql := `SELECT * FROM base_from_rzd_data WHERE 1=1 ` o := orm.NewOrm() if condition != "" { sql += condition } _, err = o.Raw(sql, pars...).QueryRows(&items) if errors.Is(err, orm.ErrNoRows) { return nil, nil } return } // UpdateRzdData 修改睿姿得数据 func UpdateRzdData(item *BaseFromRzdData) (err error) { o := orm.NewOrm() _, err = o.Update(item) return }