base_from_sci99.go 6.2 KB

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