12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- // @Author gmy 2024/8/7 9:50:00
- package models
- import "github.com/beego/beego/v2/client/orm"
- type BaseFromLyData struct {
- BaseFromLyDataId int `orm:"column(base_from_ly_data_id);pk"` // 数据ID
- CreateTime string `orm:"column(create_time)"` // 创建时间
- ModifyTime string `orm:"column(modify_time)"` // 修改时间
- BaseFromLyIndexId int `orm:"column(base_from_ly_index_id)"` // 指标id
- IndexCode string `orm:"column(index_code)"` // 指标编码
- DataTime string `orm:"column(data_time)"` // 数据日期
- Value float64 `orm:"column(value)"` // 数据值
- }
- func init() {
- orm.RegisterModel(new(BaseFromLyData))
- }
- // AddLyDataList 批量插入数据记录列表
- func AddLyDataList(items []BaseFromLyData) (err error) {
- o := orm.NewOrmUsingDB("data")
- _, err = o.InsertMulti(len(items), items)
- return
- }
- // GetLyDataByIndexIdAndDataTime 根据指标id和数据日期查询数据
- func GetLyDataByIndexIdAndDataTime(indexId int, dataTime string) (items []BaseFromLyData, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM base_from_ly_data WHERE base_from_ly_index_id=? AND data_time=?`
- _, err = o.Raw(sql, indexId, dataTime).QueryRows(&items)
- return
- }
- // GetLyDataByIndexIdAndDataTimeYM 根据指标id和数据日期的年月查询数据
- func GetLyDataByIndexIdAndDataTimeYM(indexId int, dataTime string) (items []BaseFromLyData, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM base_from_ly_data WHERE base_from_ly_index_id=? AND data_time like ?`
- _, err = o.Raw(sql, indexId, dataTime+"%").QueryRows(&items)
- return
- }
- // UpdateLyDataById 根据主键id更新数据
- func UpdateLyDataById(dataId int, value float64) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `UPDATE base_from_ly_data SET value=? WHERE base_from_ly_data_id=?`
- _, err = o.Raw(sql, value, dataId).Exec()
- return
- }
|