base_from_rzd_index.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Package models
  2. // @Author gmy 2024/8/7 9:38:00
  3. package models
  4. import (
  5. "eta/eta_index_lib/global"
  6. "eta/eta_index_lib/utils"
  7. "time"
  8. )
  9. type BaseFromRzdIndex struct {
  10. BaseFromRzdIndexId int `gorm:"column:base_from_rzd_index_id;type:int(11);primaryKey;not null;"`
  11. CreateTime time.Time `gorm:"column:create_time;type:datetime;comment:创建时间;not null;default:CURRENT_TIMESTAMP;"` // 创建时间
  12. ModifyTime time.Time `gorm:"column:modify_time;type:datetime;comment:修改时间;not null;default:CURRENT_TIMESTAMP;"` // 修改时间
  13. BaseFromRzdClassifyId int `gorm:"column:base_from_rzd_classify_id;type:int(11) UNSIGNED;comment:原始数据指标分类id;not null;default:0;"` // 原始数据指标分类id
  14. IndexCode string `gorm:"column:index_code;type:varchar(255);comment:指标编码;"` // 指标编码
  15. IndexName string `gorm:"column:index_name;type:varchar(255);comment:指标名称;"` // 指标名称
  16. Frequency string `gorm:"column:frequency;type:varchar(20);comment:频度;"` // 频度
  17. Unit string `gorm:"column:unit;type:varchar(30);comment:单位;"` // 单位
  18. StartDate time.Time `gorm:"column:start_date;type:date;comment:数据开始日期;default:NULL;"` // 数据开始日期
  19. EndDate time.Time `gorm:"column:end_date;type:date;comment:数据结束日期;default:NULL;"` // 数据结束日期
  20. LatestValue float64 `gorm:"column:latest_value;type:double;comment:数据最新值;default:NULL;"` // 数据最新值
  21. }
  22. // AddRzdIndexList 批量插入指标记录列表
  23. func AddRzdIndexList(items []*BaseFromRzdIndex) (err error) {
  24. //o := orm.NewOrm()
  25. //_, err = o.InsertMulti(len(items), items)
  26. err = global.DEFAULT_DB.CreateInBatches(items, len(items)).Error
  27. return
  28. }
  29. // AddRzdIndex 添加指标
  30. func AddRzdIndex(item *BaseFromRzdIndex) (int64, error) {
  31. //o := orm.NewOrm()
  32. //id, err := o.Insert(item)
  33. err := global.DEFAULT_DB.Create(&item).Error
  34. if err != nil {
  35. return 0, err
  36. }
  37. id := int64(item.BaseFromRzdIndexId)
  38. return id, nil
  39. }
  40. // GetRzdIndexByCode 查询指标编码是否存在
  41. func GetRzdIndexByCode(indexCode string) (item *BaseFromRzdIndex, err error) {
  42. //o := orm.NewOrm()
  43. sql := `SELECT * FROM base_from_rzd_index WHERE index_code=?`
  44. //err = o.Raw(sql, indexCode).QueryRow(&item)
  45. err = global.DEFAULT_DB.Raw(sql, indexCode).First(&item).Error
  46. if utils.IsErrNoRow(err) {
  47. return nil, nil
  48. }
  49. return
  50. }