base_from_yongyi.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package data_manage
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. type BaseFromYongyiIndex struct {
  9. YongyiIndexId int `orm:"column(yongyi_index_id);pk" gorm:"primaryKey" `
  10. ClassifyId int
  11. IndexCode string
  12. IndexName string
  13. Frequency string
  14. Unit string
  15. Sort int
  16. CreateTime time.Time
  17. ModifyTime time.Time
  18. }
  19. type BaseFromYongyiIndexList struct {
  20. YongyiIndexId int `orm:"column(yongyi_index_id);pk" gorm:"primaryKey" `
  21. ClassifyId int
  22. Interface string
  23. IndexCode string
  24. IndexName string
  25. Frequency string
  26. Unit string
  27. Sort int
  28. CreateTime string
  29. ModifyTime string
  30. DataList []*BaseFromYongyiData
  31. Paging *paging.PagingItem `description:"分页数据"`
  32. }
  33. type YongyiSingleDataResp struct {
  34. YongyiIndexId int
  35. ClassifyId int
  36. IndexCode string
  37. IndexName string
  38. Frequency string
  39. Unit string
  40. StartTime string
  41. CreateTime string
  42. ModifyTime string
  43. Data []*YongyiSingleData
  44. }
  45. type YongyiSingleData struct {
  46. Value string `orm:"column(value)" description:"日期"`
  47. DataTime string `orm:"column(data_time)" description:"值"`
  48. }
  49. func GetYongyiIndex(condition string, pars interface{}) (items []*BaseFromYongyiIndexList, err error) {
  50. sql := ` SELECT * FROM base_from_yongyi_index WHERE 1=1 `
  51. if condition != "" {
  52. sql += condition
  53. }
  54. sql += ` ORDER BY sort ASC, yongyi_index_id asc`
  55. err = global.DmSQL["data"].Raw(sql, pars).Scan(&items).Error
  56. return
  57. }
  58. func GetYongyiIndexDataCount(indexCode string) (count int, err error) {
  59. o := global.DmSQL["data"]
  60. sql := ` SELECT COUNT(1) AS count FROM base_from_yongyi_data WHERE index_code=? `
  61. err = o.Raw(sql, indexCode).Scan(&count).Error
  62. return
  63. }
  64. func GetYongyiIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromYongyiData, err error) {
  65. o := global.DmSQL["data"]
  66. sql := ` SELECT * FROM base_from_yongyi_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  67. err = o.Raw(sql, indexCode, startSize, pageSize).Scan(&items).Error
  68. return
  69. }
  70. func GetYongyiIndexDataByCodes(indexCode []string) (items []*BaseFromYongyiData, err error) {
  71. o := global.DmSQL["data"]
  72. sql := ` SELECT * FROM base_from_yongyi_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCode)) + `) ORDER BY data_time DESC `
  73. err = o.Raw(sql, indexCode).Scan(&items).Error
  74. return
  75. }
  76. type BaseFromYongyiData struct {
  77. YongyiDataId int `orm:"column(yongyi_data_id);pk" gorm:"primaryKey" `
  78. YongyiIndexId int
  79. IndexCode string
  80. DataTime string
  81. Value string
  82. CreateTime string
  83. ModifyTime string
  84. DataTimestamp int64
  85. }
  86. type BaseFromYongyiIndexSearchItem struct {
  87. YongyiIndexId int `orm:"column(yongyi_index_id);pk" gorm:"primaryKey" `
  88. ClassifyId int
  89. IndexCode string
  90. IndexName string
  91. }
  92. // GetYongyiItemList 模糊查询Yongyi数据库指标列表
  93. func GetYongyiItemList(condition string) (items []*BaseFromYongyiIndexSearchItem, err error) {
  94. o := global.DmSQL["data"]
  95. sql := "SELECT * FROM base_from_yongyi_index WHERE 1=1"
  96. if condition != "" {
  97. sql += condition
  98. }
  99. err = o.Raw(sql).Scan(&items).Error
  100. return
  101. }
  102. func GetYongyiIndexDataByCode(indexCode string) (list []*BaseFromYongyiData, err error) {
  103. o := global.DmSQL["data"]
  104. sql := `SELECT * FROM base_from_yongyi_data WHERE index_code=? `
  105. err = o.Raw(sql, indexCode).Scan(&list).Error
  106. return
  107. }
  108. func GetBaseFromYongyiIndexByIndexCode(indexCode string) (list *BaseFromYongyiIndex, err error) {
  109. o := global.DmSQL["data"]
  110. sql := ` SELECT * FROM base_from_yongyi_index WHERE index_code=? `
  111. err = o.Raw(sql, indexCode).First(&list).Error
  112. return
  113. }
  114. type BaseFromYongyiIndexType struct {
  115. Type2 string `orm:"column(type_2)"`
  116. Type3 string `orm:"column(type_3)"`
  117. }
  118. // Update 更新Yongyi指标基础信息
  119. func (item *BaseFromYongyiIndex) Update(cols []string) (err error) {
  120. err = global.DmSQL["data"].Select(cols).Updates(item).Error
  121. return
  122. }
  123. // EditYongyiIndexInfoResp 新增指标的返回
  124. type EditYongyiIndexInfoResp struct {
  125. YongyiIndexId int `description:"指标ID"`
  126. IndexCode string `description:"指标code"`
  127. }