base_from_yongyi.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. type BaseFromYongyiIndex struct {
  9. YongyiIndexId int `orm:"column(yongyi_index_id);pk"`
  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"`
  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 EsBaseFromYongyiIndex struct {
  34. YongyiIndexId int64
  35. IndexCode string
  36. IndexName string
  37. Frequency string
  38. Unit string
  39. ClassifyId int64
  40. StartDate string
  41. EndDate string
  42. TerminalCode string
  43. CreateTime string
  44. ModifyTime string
  45. }
  46. type YongyiSingleDataResp struct {
  47. YongyiIndexId int
  48. ClassifyId int
  49. IndexCode string
  50. IndexName string
  51. Frequency string
  52. Unit string
  53. StartTime string
  54. CreateTime string
  55. ModifyTime string
  56. Data []*YongyiSingleData
  57. }
  58. type YongyiSingleData struct {
  59. Value string `orm:"column(value)" description:"日期"`
  60. DataTime string `orm:"column(data_time)" description:"值"`
  61. }
  62. func GetYongyiIndex(condition string, pars interface{}) (items []*BaseFromYongyiIndexList, err error) {
  63. o := orm.NewOrmUsingDB("data")
  64. sql := ` SELECT * FROM base_from_yongyi_index WHERE 1=1 `
  65. if condition != "" {
  66. sql += condition
  67. }
  68. sql += ` ORDER BY sort ASC, yongyi_index_id asc`
  69. _, err = o.Raw(sql, pars).QueryRows(&items)
  70. return
  71. }
  72. func GetYongyiIndexDataCount(indexCode string) (count int, err error) {
  73. o := orm.NewOrmUsingDB("data")
  74. sql := ` SELECT COUNT(1) AS count FROM base_from_yongyi_data WHERE index_code=? `
  75. err = o.Raw(sql, indexCode).QueryRow(&count)
  76. return
  77. }
  78. func GetYongyiIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromYongyiData, err error) {
  79. o := orm.NewOrmUsingDB("data")
  80. sql := ` SELECT * FROM base_from_yongyi_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  81. _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
  82. return
  83. }
  84. func GetYongyiIndexDataByCodes(indexCode []string) (items []*BaseFromYongyiData, err error) {
  85. o := orm.NewOrmUsingDB("data")
  86. sql := ` SELECT * FROM base_from_yongyi_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCode)) + `) ORDER BY data_time DESC `
  87. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  88. return
  89. }
  90. type BaseFromYongyiData struct {
  91. YongyiDataId int `orm:"column(yongyi_data_id);pk"`
  92. YongyiIndexId int
  93. IndexCode string
  94. DataTime string
  95. Value string
  96. CreateTime string
  97. ModifyTime string
  98. DataTimestamp int64
  99. }
  100. type BaseFromYongyiIndexSearchItem struct {
  101. YongyiIndexId int `orm:"column(yongyi_index_id);pk"`
  102. ClassifyId int
  103. IndexCode string
  104. IndexName string
  105. }
  106. // GetYongyiItemList 模糊查询Yongyi数据库指标列表
  107. func GetYongyiItemList(condition string) (items []*BaseFromYongyiIndexSearchItem, err error) {
  108. o := orm.NewOrmUsingDB("data")
  109. sql := "SELECT * FROM base_from_yongyi_index WHERE 1=1"
  110. if condition != "" {
  111. sql += condition
  112. }
  113. _, err = o.Raw(sql).QueryRows(&items)
  114. return
  115. }
  116. func GetYongyiIndexDataByCode(indexCode string) (list []*BaseFromYongyiData, err error) {
  117. o := orm.NewOrmUsingDB("data")
  118. sql := `SELECT * FROM base_from_yongyi_data WHERE index_code=? `
  119. _, err = o.Raw(sql, indexCode).QueryRows(&list)
  120. return
  121. }
  122. func GetBaseFromYongyiIndexByIndexCode(indexCode string) (list *BaseFromYongyiIndex, err error) {
  123. o := orm.NewOrmUsingDB("data")
  124. sql := ` SELECT * FROM base_from_yongyi_index WHERE index_code=? `
  125. err = o.Raw(sql, indexCode).QueryRow(&list)
  126. return
  127. }
  128. type BaseFromYongyiIndexType struct {
  129. Type2 string `orm:"column(type_2)"`
  130. Type3 string `orm:"column(type_3)"`
  131. }
  132. // Update 更新Yongyi指标基础信息
  133. func (item *BaseFromYongyiIndex) Update(cols []string) (err error) {
  134. o := orm.NewOrmUsingDB("data")
  135. _, err = o.Update(item, cols...)
  136. return
  137. }
  138. // EditYongyiIndexInfoResp 新增指标的返回
  139. type EditYongyiIndexInfoResp struct {
  140. YongyiIndexId int `description:"指标ID"`
  141. IndexCode string `description:"指标code"`
  142. }