base_from_sci99.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // BaseFromSci99Index 代表卓创资讯-原始指标表的结构
  7. type BaseFromSci99Index struct {
  8. BaseFromSciIndexId int `orm:"column(base_from_sci_index_id);pk"` // 主键,自动递增
  9. IndexCode string // 指标编码
  10. IndexName string // 指标名称
  11. ClassifyId int // 分类Id
  12. Unit string // 单位
  13. Frequency string // 频度
  14. Describe string // 指标描述
  15. CreateTime time.Time // 创建时间
  16. ModifyTime time.Time // 修改时间
  17. }
  18. // BaseFromSci99Data 代表卓创资讯-原始指标数据表的结构
  19. type BaseFromSci99Data struct {
  20. BaseFromSciDataId int `orm:"column(base_from_sci_data_id);pk"` // 主键,自动递增
  21. BaseFromSciIndexId int // 指标id
  22. IndexCode string // 指标编码
  23. DataTime string // 数据日期
  24. Value float64 // 数据值
  25. CreateTime time.Time // 创建时间
  26. ModifyTime time.Time // 修改时间
  27. }
  28. // BaseFromSci99Classify 代表卓创资讯-原始指标分类表的结构
  29. type BaseFromSci99Classify struct {
  30. BaseFromSciClassifyId int `orm:"column(base_from_sci_classify_id);pk"` // 主键,自动递增
  31. ClassifyName string // 分类名称
  32. Sort int // 排序
  33. CreateTime time.Time // 创建时间
  34. ModifyTime time.Time // 修改时间
  35. }
  36. // 添加数据
  37. func AddBaseFromSci99Index(item *BaseFromSci99Index) (lastId int64, err error) {
  38. o := orm.NewOrmUsingDB("data")
  39. lastId, err = o.Insert(item)
  40. return
  41. }
  42. func AddBaseFromSci99Classify(item *BaseFromSci99Classify) (lastId int64, err error) {
  43. o := orm.NewOrmUsingDB("data")
  44. lastId, err = o.Insert(item)
  45. return
  46. }
  47. func AddBaseFromSci99DataMulti(item []*BaseFromSci99Data) (err error) {
  48. o := orm.NewOrmUsingDB("data")
  49. _, err = o.InsertMulti(1000, item)
  50. return
  51. }
  52. func GetBaseFromSci99Index() (list []*BaseFromSci99Index, err error) {
  53. o := orm.NewOrmUsingDB("data")
  54. sql := `SELECT * FROM base_from_sci99_index `
  55. _, err = o.Raw(sql).QueryRows(&list)
  56. return
  57. }
  58. func GetBaseFromSci99Classify() (list []*BaseFromSci99Classify, err error) {
  59. o := orm.NewOrmUsingDB("data")
  60. sql := `SELECT * FROM base_from_sci99_classify `
  61. _, err = o.Raw(sql).QueryRows(&list)
  62. return
  63. }
  64. func GetBaseFromTradeSci99DataAll(dateStr string) (list []*BaseFromSci99Data, err error) {
  65. o := orm.NewOrmUsingDB("data")
  66. sql := `SELECT * FROM base_from_sci99_data where data_time=?`
  67. _, err = o.Raw(sql, dateStr).QueryRows(&list)
  68. return
  69. }
  70. func GetBaseFromTradeSci99IndexAll(indexCode string) (list []*BaseFromSci99Data, err error) {
  71. o := orm.NewOrmUsingDB("data")
  72. sql := `SELECT * FROM base_from_sci99_data where index_code=?`
  73. _, err = o.Raw(sql, indexCode).QueryRows(&list)
  74. return
  75. }
  76. func GetBaseFromTradeSci99LatestData(indexCode string) (date time.Time, err error) {
  77. o := orm.NewOrmUsingDB("data")
  78. sql := `SELECT data_time FROM base_from_sci99_data where index_code=? ORDER BY data_time DESC limit 1 `
  79. err = o.Raw(sql, indexCode).QueryRow(&date)
  80. return
  81. }
  82. // UpdateBaseFromSci99Data
  83. func UpdateBaseFromSci99Data(value float64, indexCode, dataTime string) (err error) {
  84. o := orm.NewOrmUsingDB("data")
  85. sql := `UPDATE base_from_sci99_data SET value=?,modify_time=NOW() WHERE index_code = ? AND data_time = ? `
  86. _, err = o.Raw(sql, value, indexCode, dataTime).Exec()
  87. return
  88. }