base_from_sci99.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package data_source
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. // BaseFromSci99Index 代表卓创资讯-原始指标表的结构
  8. type BaseFromSci99Index struct {
  9. BaseFromSciIndexId int `orm:"column(base_from_sci_index_id);pk"` // 主键,自动递增
  10. IndexCode string // 指标编码
  11. IndexName string // 指标名称
  12. ClassifyId int // 分类Id
  13. Unit string // 单位
  14. Frequency string // 频度
  15. Describe string // 指标描述
  16. CreateTime time.Time // 创建时间
  17. ModifyTime time.Time // 修改时间
  18. }
  19. // BaseFromSci99Data 代表卓创资讯-原始指标数据表的结构
  20. type BaseFromSci99Data struct {
  21. BaseFromSciDataId int `orm:"column(base_from_sci_data_id);pk"` // 主键,自动递增
  22. BaseFromSciIndexId int // 指标id
  23. IndexCode string // 指标编码
  24. DataTime string // 数据日期
  25. Value float64 // 数据值
  26. CreateTime time.Time // 创建时间
  27. ModifyTime time.Time // 修改时间
  28. }
  29. // BaseFromSci99Classify 代表卓创资讯-原始指标分类表的结构
  30. type BaseFromSci99Classify struct {
  31. BaseFromSciClassifyId int `orm:"column(base_from_sci_classify_id);pk"` // 主键,自动递增
  32. ClassifyName string // 分类名称
  33. Sort int // 排序
  34. CreateTime time.Time // 创建时间
  35. ModifyTime time.Time // 修改时间
  36. }
  37. type BaseFromSci99DataItem struct {
  38. BaseFromSciDataId int `orm:"column(base_from_sci_data_id);pk"` // 主键,自动递增
  39. BaseFromSciIndexId int // 指标id
  40. IndexCode string // 指标编码
  41. DataTime string // 数据日期
  42. Value float64 // 数据值
  43. CreateTime string // 创建时间
  44. ModifyTime string // 修改时间
  45. }
  46. type BaseFromSci99IndexList struct {
  47. BaseFromSciIndexId int `orm:"column(base_from_sci_index_id);pk"` // 主键,自动递增
  48. IndexCode string // 指标编码
  49. IndexName string // 指标名称
  50. ClassifyId int // 分类Id
  51. Unit string // 单位
  52. Frequency string // 频度
  53. Describe string // 指标描述
  54. CreateTime string // 创建时间
  55. ModifyTime string // 修改时间
  56. DataList []*BaseFromSci99DataItem
  57. Paging *paging.PagingItem `description:"分页数据"`
  58. }
  59. // 添加数据
  60. func AddBaseFromSci99Index(item *BaseFromSci99Index) (lastId int64, err error) {
  61. o := orm.NewOrmUsingDB("data")
  62. lastId, err = o.Insert(item)
  63. return
  64. }
  65. func AddBaseFromSci99Classify(item *BaseFromSci99Classify) (lastId int64, err error) {
  66. o := orm.NewOrmUsingDB("data")
  67. lastId, err = o.Insert(item)
  68. return
  69. }
  70. func AddBaseFromSci99DataMulti(item []*BaseFromSci99Data) (err error) {
  71. o := orm.NewOrmUsingDB("data")
  72. _, err = o.InsertMulti(1000, item)
  73. return
  74. }
  75. func GetBaseFromSci99Classify() (list []*BaseFromSci99Classify, err error) {
  76. o := orm.NewOrmUsingDB("data")
  77. sql := `SELECT * FROM base_from_sci99_classify `
  78. _, err = o.Raw(sql).QueryRows(&list)
  79. return
  80. }
  81. func GetSci99Index(condition string, pars interface{}) (items []*BaseFromSci99IndexList, err error) {
  82. o := orm.NewOrmUsingDB("data")
  83. sql := ` SELECT * FROM base_from_sci99_index WHERE 1=1 `
  84. if condition != "" {
  85. sql += condition
  86. }
  87. sql += `ORDER BY base_from_sci_index_id ASC `
  88. _, err = o.Raw(sql, pars).QueryRows(&items)
  89. return
  90. }
  91. func GetSci99IndexDataCount(indexCode string) (count int, err error) {
  92. o := orm.NewOrmUsingDB("data")
  93. sql := ` SELECT COUNT(1) AS count FROM base_from_sci99_data WHERE index_code=? `
  94. err = o.Raw(sql, indexCode).QueryRow(&count)
  95. return
  96. }
  97. func GetSci99IndexData(indexCode string, startSize, pageSize int) (items []*BaseFromSci99DataItem, err error) {
  98. o := orm.NewOrmUsingDB("data")
  99. sql := ` SELECT * FROM base_from_sci99_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  100. _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
  101. return
  102. }
  103. func GetSci99DataMaxCount(classifyId int) (count int, err error) {
  104. o := orm.NewOrmUsingDB("data")
  105. sql := `SELECT MAX(t.num) AS count FROM (
  106. SELECT COUNT(1) AS num FROM base_from_icpi_index AS a
  107. INNER JOIN base_from_icpi_data AS b ON a.base_from_icpi_index_id=b.base_from_icpi_index_id
  108. WHERE a.base_from_icpi_classify_id=?
  109. GROUP BY a.base_from_icpi_index_id
  110. )AS t `
  111. err = o.Raw(sql, classifyId).QueryRow(&count)
  112. return
  113. }
  114. func GetSci99IndexDataByCode(indexCode string) (items []*BaseFromSci99DataItem, err error) {
  115. o := orm.NewOrmUsingDB("data")
  116. sql := ` SELECT * FROM base_from_sci99_data WHERE index_code=? ORDER BY data_time DESC `
  117. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  118. return
  119. }
  120. func GetSci99IndexLatestDate(indexCode string) (ModifyTime string, err error) {
  121. o := orm.NewOrmUsingDB("data")
  122. sql := ` SELECT modify_time FROM base_from_sci99_data WHERE index_code=? ORDER BY modify_time DESC limit 1 `
  123. err = o.Raw(sql, indexCode).QueryRow(&ModifyTime)
  124. return
  125. }