base_from_ly_index.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. "time"
  8. )
  9. type BaseFromLyIndex struct {
  10. BaseFromLyIndexId int `orm:"column(base_from_ly_index_id);pk"` // 指标ID
  11. CreateTime string `orm:"column(create_time)"` // 创建时间
  12. ModifyTime string `orm:"column(modify_time)"` // 修改时间
  13. BaseFromLyClassifyId int `orm:"column(base_from_ly_classify_id)"` // 原始数据指标分类id
  14. IndexCode string `orm:"column(index_code)"` // 指标编码
  15. IndexName string `orm:"column(index_name)"` // 指标名称
  16. Frequency string `orm:"column(frequency)"` // 频度
  17. Unit string `orm:"column(unit)"` // 单位
  18. EdbExist int `orm:"column(edb_exist)"` // 指标库是否已添加:0-否;1-是
  19. }
  20. // 在 init 函数中注册模型
  21. func init() {
  22. orm.RegisterModel(new(BaseFromLyIndex))
  23. }
  24. // AddLyIndexList 批量插入指标记录列表
  25. func AddLyIndexList(items []*BaseFromLyIndex) (err error) {
  26. o := orm.NewOrm()
  27. _, err = o.InsertMulti(len(items), items)
  28. return
  29. }
  30. // AddLyIndex 添加指标
  31. func AddLyIndex(item *BaseFromLyIndex) (int64, error) {
  32. item.CreateTime = time.Now().Format("2006-01-02 15:04:05")
  33. o := orm.NewOrm()
  34. id, err := o.Insert(item)
  35. if err != nil {
  36. return 0, err
  37. }
  38. return id, nil
  39. }
  40. // GetLyIndexByCode 查询指标编码是否存在
  41. func GetLyIndexByCode(indexCode string) (item *BaseFromLyIndex, err error) {
  42. o := orm.NewOrm()
  43. sql := `SELECT * FROM base_from_ly_index WHERE index_code=?`
  44. err = o.Raw(sql, indexCode).QueryRow(&item)
  45. if errors.Is(err, orm.ErrNoRows) {
  46. return nil, nil
  47. }
  48. return
  49. }