base_from_ly_data.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // @Author gmy 2024/8/7 9:50:00
  2. package models
  3. import "github.com/beego/beego/v2/client/orm"
  4. type BaseFromLyData struct {
  5. BaseFromLyDataId int `orm:"column(base_from_ly_data_id);pk"` // 数据ID
  6. CreateTime string `orm:"column(create_time)"` // 创建时间
  7. ModifyTime string `orm:"column(modify_time)"` // 修改时间
  8. BaseFromLyIndexId int `orm:"column(base_from_ly_index_id)"` // 指标id
  9. IndexCode string `orm:"column(index_code)"` // 指标编码
  10. DataTime string `orm:"column(data_time)"` // 数据日期
  11. Value float64 `orm:"column(value)"` // 数据值
  12. }
  13. func init() {
  14. orm.RegisterModel(new(BaseFromLyData))
  15. }
  16. // AddLyDataList 批量插入数据记录列表
  17. func AddLyDataList(items []BaseFromLyData) (err error) {
  18. o := orm.NewOrmUsingDB("data")
  19. _, err = o.InsertMulti(len(items), items)
  20. return
  21. }
  22. // GetLyDataByIndexIdAndDataTime 根据指标id和数据日期查询数据
  23. func GetLyDataByIndexIdAndDataTime(indexId int, dataTime string) (items []BaseFromLyData, err error) {
  24. o := orm.NewOrmUsingDB("data")
  25. sql := `SELECT * FROM base_from_ly_data WHERE base_from_ly_index_id=? AND data_time=?`
  26. _, err = o.Raw(sql, indexId, dataTime).QueryRows(&items)
  27. return
  28. }
  29. // GetLyDataByIndexIdAndDataTimeYM 根据指标id和数据日期的年月查询数据
  30. func GetLyDataByIndexIdAndDataTimeYM(indexId int, dataTime string) (items []BaseFromLyData, err error) {
  31. o := orm.NewOrmUsingDB("data")
  32. sql := `SELECT * FROM base_from_ly_data WHERE base_from_ly_index_id=? AND data_time like ?`
  33. _, err = o.Raw(sql, indexId, dataTime+"%").QueryRows(&items)
  34. return
  35. }
  36. // UpdateLyDataById 根据主键id更新数据
  37. func UpdateLyDataById(dataId int, value float64) (err error) {
  38. o := orm.NewOrmUsingDB("data")
  39. sql := `UPDATE base_from_ly_data SET value=? WHERE base_from_ly_data_id=?`
  40. _, err = o.Raw(sql, value, dataId).Exec()
  41. return
  42. }