base_from_sci99.go 5.2 KB

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