base_from_ly_index.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Package models
  2. // @Author gmy 2024/8/7 9:38:00
  3. package models
  4. import (
  5. "errors"
  6. "eta_gn/eta_index_lib/global"
  7. "github.com/beego/beego/v2/client/orm"
  8. "time"
  9. )
  10. //type BaseFromLyIndex struct {
  11. // BaseFromLyIndexId int `orm:"column(base_from_ly_index_id);pk"` // 指标ID
  12. // CreateTime string `orm:"column(create_time)"` // 创建时间
  13. // ModifyTime string `orm:"column(modify_time)"` // 修改时间
  14. // BaseFromLyClassifyId int `orm:"column(base_from_ly_classify_id)"` // 原始数据指标分类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. // EdbExist int `orm:"column(edb_exist)"` // 指标库是否已添加:0-否;1-是
  20. //}
  21. type BaseFromLyIndex struct {
  22. BaseFromLyIndexId int `gorm:"column:base_from_ly_index_id;primaryKey"` // 指标ID
  23. CreateTime string `gorm:"column:create_time"` // 创建时间
  24. ModifyTime string `gorm:"column:modify_time"` // 修改时间
  25. BaseFromLyClassifyId int `gorm:"column:base_from_ly_classify_id"` // 原始数据指标分类id
  26. IndexCode string `gorm:"column:index_code"` // 指标编码
  27. IndexName string `gorm:"column:index_name"` // 指标名称
  28. Frequency string `gorm:"column:frequency"` // 频度
  29. Unit string `gorm:"column:unit"` // 单位
  30. EdbExist int `gorm:"column:edb_exist"` // 指标库是否已添加:0-否;1-是
  31. }
  32. func (m *BaseFromLyIndex) TableName() string {
  33. return "base_from_ly_index"
  34. }
  35. // 在 init 函数中注册模型
  36. func init() {
  37. orm.RegisterModel(new(BaseFromLyIndex))
  38. }
  39. // AddLyIndexList 批量插入指标记录列表
  40. func AddLyIndexList(items []*BaseFromLyIndex) (err error) {
  41. //o := orm.NewOrm()
  42. //_, err = o.InsertMulti(len(items), items)
  43. err = global.DEFAULT_DmSQL.CreateInBatches(items, 500).Error
  44. return
  45. }
  46. // AddLyIndex 添加指标
  47. func AddLyIndex(item *BaseFromLyIndex) (int64, error) {
  48. item.CreateTime = time.Now().Format("2006-01-02 15:04:05")
  49. //o := orm.NewOrm()
  50. //id, err := o.Insert(item)
  51. err := global.DEFAULT_DmSQL.Create(item).Error
  52. if err != nil {
  53. return 0, err
  54. }
  55. return int64(item.BaseFromLyIndexId), nil
  56. }
  57. // GetLyIndexByCode 查询指标编码是否存在
  58. func GetLyIndexByCode(indexCode string) (item *BaseFromLyIndex, err error) {
  59. //o := orm.NewOrm()
  60. sql := `SELECT * FROM base_from_ly_index WHERE index_code=?`
  61. //err = o.Raw(sql, indexCode).QueryRow(&item)
  62. err = global.DEFAULT_DmSQL.Raw(sql, indexCode).First(&item).Error
  63. if errors.Is(err, orm.ErrNoRows) {
  64. return nil, nil
  65. }
  66. return
  67. }