base_from_yongyi.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 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. o := orm.NewOrmUsingDB("data")
  51. sql := ` SELECT * FROM base_from_yongyi_index WHERE 1=1 `
  52. if condition != "" {
  53. sql += condition
  54. }
  55. sql += ` ORDER BY sort ASC, yongyi_index_id asc`
  56. _, err = o.Raw(sql, pars).QueryRows(&items)
  57. return
  58. }
  59. func GetYongyiIndexDataCount(indexCode string) (count int, err error) {
  60. o := orm.NewOrmUsingDB("data")
  61. sql := ` SELECT COUNT(1) AS count FROM base_from_yongyi_data WHERE index_code=? `
  62. err = o.Raw(sql, indexCode).QueryRow(&count)
  63. return
  64. }
  65. func GetYongyiIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromYongyiData, err error) {
  66. o := orm.NewOrmUsingDB("data")
  67. sql := ` SELECT * FROM base_from_yongyi_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  68. _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
  69. return
  70. }
  71. func GetYongyiIndexDataByCodes(indexCode []string) (items []*BaseFromYongyiData, err error) {
  72. o := orm.NewOrmUsingDB("data")
  73. sql := ` SELECT * FROM base_from_yongyi_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCode)) + `) ORDER BY data_time DESC `
  74. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  75. return
  76. }
  77. type BaseFromYongyiData struct {
  78. YongyiDataId int `orm:"column(yongyi_data_id);pk"`
  79. YongyiIndexId int
  80. IndexCode string
  81. DataTime string
  82. Value string
  83. CreateTime string
  84. ModifyTime string
  85. DataTimestamp int64
  86. }
  87. type BaseFromYongyiIndexSearchItem struct {
  88. YongyiIndexId int `orm:"column(yongyi_index_id);pk"`
  89. ClassifyId int
  90. IndexCode string
  91. IndexName string
  92. }
  93. // GetYongyiItemList 模糊查询Yongyi数据库指标列表
  94. func GetYongyiItemList(condition string) (items []*BaseFromYongyiIndexSearchItem, err error) {
  95. o := orm.NewOrmUsingDB("data")
  96. sql := "SELECT * FROM base_from_yongyi_index WHERE 1=1"
  97. if condition != "" {
  98. sql += condition
  99. }
  100. _, err = o.Raw(sql).QueryRows(&items)
  101. return
  102. }
  103. func GetYongyiIndexDataByCode(indexCode string) (list []*BaseFromYongyiData, err error) {
  104. o := orm.NewOrmUsingDB("data")
  105. sql := `SELECT * FROM base_from_yongyi_data WHERE index_code=? `
  106. _, err = o.Raw(sql, indexCode).QueryRows(&list)
  107. return
  108. }
  109. func GetBaseFromYongyiIndexByIndexCode(indexCode string) (list *BaseFromYongyiIndex, err error) {
  110. o := orm.NewOrmUsingDB("data")
  111. sql := ` SELECT * FROM base_from_yongyi_index WHERE index_code=? `
  112. err = o.Raw(sql, indexCode).QueryRow(&list)
  113. return
  114. }
  115. type BaseFromYongyiIndexType struct {
  116. Type2 string `orm:"column(type_2)"`
  117. Type3 string `orm:"column(type_3)"`
  118. }
  119. // Update 更新Yongyi指标基础信息
  120. func (item *BaseFromYongyiIndex) Update(cols []string) (err error) {
  121. o := orm.NewOrmUsingDB("data")
  122. _, err = o.Update(item, cols...)
  123. return
  124. }
  125. // EditYongyiIndexInfoResp 新增指标的返回
  126. type EditYongyiIndexInfoResp struct {
  127. YongyiIndexId int `description:"指标ID"`
  128. IndexCode string `description:"指标code"`
  129. }