base_from_ly_index.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 BaseFromLyIndex struct {
  10. BaseFromLyIndexId int `gorm:"column:base_from_ly_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. BaseFromLyClassifyId int `gorm:"column:base_from_ly_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. EdbExist int `gorm:"column:edb_exist;type:tinyint(4) UNSIGNED;comment:指标库是否已添加:0-否;1-是;not null;default:0;"` // 指标库是否已添加:0-否;1-是
  19. StartDate time.Time `gorm:"column:start_date;type:date;comment:数据开始日期;default:NULL;"` // 数据开始日期
  20. EndDate time.Time `gorm:"column:end_date;type:date;comment:数据结束日期;default:NULL;"` // 数据结束日期
  21. LatestValue float64 `gorm:"column:latest_value;type:double;comment:数据最新值;default:NULL;"` // 数据最新值
  22. }
  23. // AddLyIndexList 批量插入指标记录列表
  24. func AddLyIndexList(items []*BaseFromLyIndex) (err error) {
  25. //o := orm.NewOrm()
  26. //_, err = o.InsertMulti(len(items), items)
  27. err = global.DEFAULT_DB.CreateInBatches(items, len(items)).Error
  28. return
  29. }
  30. // AddLyIndex 添加指标
  31. func AddLyIndex(item *BaseFromLyIndex) (int64, error) {
  32. item.CreateTime = time.Now()
  33. //o := orm.NewOrm()
  34. //id, err := o.Insert(item)
  35. err := global.DEFAULT_DB.Create(item).Error
  36. if err != nil {
  37. return 0, err
  38. }
  39. id := int64(item.BaseFromLyIndexId)
  40. return id, nil
  41. }
  42. // GetLyIndexByCode 查询指标编码是否存在
  43. func GetLyIndexByCode(indexCode string) (item *BaseFromLyIndex, err error) {
  44. //o := orm.NewOrm()
  45. sql := `SELECT * FROM base_from_ly_index WHERE index_code=?`
  46. //err = o.Raw(sql, indexCode).QueryRow(&item)
  47. err = global.DEFAULT_DB.Raw(sql, indexCode).First(&item).Error
  48. if utils.IsErrNoRow(err) {
  49. return nil, nil
  50. }
  51. return
  52. }