base_from_rzd_index.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. "github.com/beego/beego/v2/client/orm"
  8. )
  9. type BaseFromRzdIndex struct {
  10. BaseFromRzdIndexId int `gorm:"column:base_from_rzd_index_id;prmaryKey"`
  11. //BaseFromRzdIndexId int `orm:"column(base_from_rzd_index_id);pk"`
  12. CreateTime string `orm:"column(create_time)"`
  13. ModifyTime string `orm:"column(modify_time)"`
  14. BaseFromLyClassifyId int `orm:"column(base_from_rzd_classify_id)"`
  15. IndexCode string `orm:"column(index_code)"`
  16. IndexName string `orm:"column(index_name)"`
  17. Frequency string `orm:"column(frequency)"`
  18. Unit string `orm:"column(unit)"`
  19. }
  20. // 在 init 函数中注册模型
  21. func init() {
  22. orm.RegisterModel(new(BaseFromRzdIndex))
  23. }
  24. // AddRzdIndexList 批量插入指标记录列表
  25. func AddRzdIndexList(items []*BaseFromRzdIndex) (err error) {
  26. //o := orm.NewOrm()
  27. //_, err = o.InsertMulti(len(items), items)
  28. err = global.DEFAULT_DB.CreateInBatches(items, len(items)).Error
  29. return
  30. }
  31. // AddRzdIndex 添加指标
  32. func AddRzdIndex(item *BaseFromRzdIndex) (int64, error) {
  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.BaseFromRzdIndexId)
  40. return id, nil
  41. }
  42. // GetRzdIndexByCode 查询指标编码是否存在
  43. func GetRzdIndexByCode(indexCode string) (item *BaseFromRzdIndex, err error) {
  44. //o := orm.NewOrm()
  45. sql := `SELECT * FROM base_from_rzd_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. }