base_from_rzd_index.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Package models
  2. // @Author gmy 2024/8/7 9:38:00
  3. package models
  4. import (
  5. "errors"
  6. "github.com/beego/beego/v2/client/orm"
  7. )
  8. type BaseFromRzdIndex struct {
  9. BaseFromRzdIndexId int `orm:"column(base_from_rzd_index_id);pk"`
  10. CreateTime string `orm:"column(create_time)"`
  11. ModifyTime string `orm:"column(modify_time)"`
  12. BaseFromLyClassifyId int `orm:"column(base_from_rzd_classify_id)"`
  13. IndexCode string `orm:"column(index_code)"`
  14. IndexName string `orm:"column(index_name)"`
  15. Frequency string `orm:"column(frequency)"`
  16. Unit string `orm:"column(unit)"`
  17. }
  18. // 在 init 函数中注册模型
  19. func init() {
  20. orm.RegisterModel(new(BaseFromRzdIndex))
  21. }
  22. // AddRzdIndexList 批量插入指标记录列表
  23. func AddRzdIndexList(items []*BaseFromRzdIndex) (err error) {
  24. o := orm.NewOrm()
  25. _, err = o.InsertMulti(len(items), items)
  26. return
  27. }
  28. // AddRzdIndex 添加指标
  29. func AddRzdIndex(item *BaseFromRzdIndex) (int64, error) {
  30. o := orm.NewOrm()
  31. id, err := o.Insert(item)
  32. if err != nil {
  33. return 0, err
  34. }
  35. return id, nil
  36. }
  37. // GetRzdIndexByCode 查询指标编码是否存在
  38. func GetRzdIndexByCode(indexCode string) (item *BaseFromRzdIndex, err error) {
  39. o := orm.NewOrm()
  40. sql := `SELECT * FROM base_from_rzd_index WHERE index_code=?`
  41. err = o.Raw(sql, indexCode).QueryRow(&item)
  42. if errors.Is(err, orm.ErrNoRows) {
  43. return nil, nil
  44. }
  45. return
  46. }