base_from_ly_index.go 1.7 KB

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