base_from_yongyi.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "time"
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  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. EdbInfoId int
  24. IndexCode string
  25. IndexName string
  26. Frequency string
  27. Unit string
  28. Sort int
  29. UniqueCode string
  30. CreateTime string
  31. ModifyTime string
  32. EdbExist int `description:"指标库是否已添加:0-否;1-是"`
  33. DataList []*BaseFromYongyiData
  34. Paging *paging.PagingItem `description:"分页数据"`
  35. }
  36. type YongyiSingleDataResp struct {
  37. YongyiIndexId int
  38. ClassifyId int
  39. EdbInfoId int
  40. IndexCode string
  41. IndexName string
  42. Frequency string
  43. Unit string
  44. StartTime string
  45. CreateTime string
  46. ModifyTime string
  47. EdbExist int `description:"指标库是否已添加:0-否;1-是"`
  48. Data []*YongyiSingleData
  49. }
  50. type YongyiSingleData struct {
  51. Value string `orm:"column(value)" description:"日期"`
  52. DataTime string `orm:"column(data_time)" description:"值"`
  53. }
  54. func GetYongyiIndexByClassifyId(classifyId int) (items []*BaseFromYongyiIndex, err error) {
  55. o := orm.NewOrmUsingDB("data")
  56. sql := ` SELECT yongyi_index_id, classify_id, index_code, index_name FROM base_from_yongyi_index WHERE classify_id=? ORDER BY sort ASC, yongyi_index_id ASC `
  57. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  58. return
  59. }
  60. func GetYongyiIndex(condition string, pars interface{}) (items []*BaseFromYongyiIndexList, err error) {
  61. o := orm.NewOrmUsingDB("data")
  62. sql := ` SELECT * FROM base_from_yongyi_index WHERE 1=1 `
  63. if condition != "" {
  64. sql += condition
  65. }
  66. sql += ` ORDER BY sort ASC, yongyi_index_id asc`
  67. _, err = o.Raw(sql, pars).QueryRows(&items)
  68. return
  69. }
  70. func GetYongyiIndexDataCount(indexCode string) (count int, err error) {
  71. o := orm.NewOrmUsingDB("data")
  72. sql := ` SELECT COUNT(1) AS count FROM base_from_yongyi_data WHERE index_code=? `
  73. err = o.Raw(sql, indexCode).QueryRow(&count)
  74. return
  75. }
  76. func GetYongyiIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromYongyiData, err error) {
  77. o := orm.NewOrmUsingDB("data")
  78. sql := ` SELECT * FROM base_from_yongyi_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  79. _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
  80. return
  81. }
  82. func GetYongyiIndexDataByCodes(indexCode []string) (items []*BaseFromYongyiData, err error) {
  83. o := orm.NewOrmUsingDB("data")
  84. sql := ` SELECT * FROM base_from_yongyi_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCode)) + `) ORDER BY data_time DESC `
  85. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  86. return
  87. }
  88. // GetYongyiByConditionAndFrequency 根据条件获取涌益咨询指标列表
  89. func GetYongyiByConditionAndFrequency(condition, frequency string, pars []interface{}) (items []*BaseFromYongyiIndex, err error) {
  90. o := orm.NewOrmUsingDB("data")
  91. sql := ` SELECT * FROM base_from_yongyi_index WHERE 1=1 `
  92. if condition != "" {
  93. sql += condition
  94. }
  95. sql += ` AND frequency=?`
  96. sql += ` ORDER BY sort ASC, yongyi_index_id ASC`
  97. _, err = o.Raw(sql, pars, frequency).QueryRows(&items)
  98. return
  99. }
  100. func GetYongyiFrequencyByCondition(condition string, pars []interface{}) (items []string, err error) {
  101. sql := `SELECT DISTINCT frequency FROM base_from_yongyi_index WHERE 1=1 `
  102. if condition != "" {
  103. sql += condition
  104. }
  105. sql += ` ORDER BY FIELD(frequency,'日度','周度','旬度','月度','季度','半年度','年度') `
  106. o := orm.NewOrmUsingDB("data")
  107. _, err = o.Raw(sql, pars...).QueryRows(&items)
  108. return
  109. }
  110. // GetYongyiDataDataTimeByIndexId 根据指标id获取指标数据的日期列表
  111. func GetYongyiDataDataTimeByIndexId(indexIdList []int) (items []string, err error) {
  112. if len(indexIdList) == 0 {
  113. return
  114. }
  115. o := orm.NewOrmUsingDB("data")
  116. sql := ` SELECT DISTINCT data_time FROM base_from_yongyi_data WHERE yongyi_index_id IN (` + utils.GetOrmInReplace(len(indexIdList)) + `) ORDER BY data_time DESC`
  117. _, err = o.Raw(sql, indexIdList).QueryRows(&items)
  118. return
  119. }
  120. type BaseFromYongyiData struct {
  121. YongyiDataId int `orm:"column(yongyi_data_id);pk"`
  122. YongyiIndexId int
  123. IndexCode string
  124. DataTime string
  125. Value string
  126. CreateTime string
  127. ModifyTime string
  128. DataTimestamp int64
  129. }
  130. type BaseFromYongyiIndexSearchItem struct {
  131. YongyiIndexId int `orm:"column(yongyi_index_id);pk"`
  132. ClassifyId int
  133. IndexCode string
  134. IndexName string
  135. }
  136. // GetYongyiItemList 模糊查询Yongyi数据库指标列表
  137. func GetYongyiItemList(condition string) (items []*BaseFromYongyiIndexSearchItem, err error) {
  138. o := orm.NewOrmUsingDB("data")
  139. sql := "SELECT * FROM base_from_yongyi_index WHERE 1=1"
  140. if condition != "" {
  141. sql += condition
  142. }
  143. _, err = o.Raw(sql).QueryRows(&items)
  144. return
  145. }
  146. func GetYongyiIndexDataByCode(indexCode string) (list []*BaseFromYongyiData, err error) {
  147. o := orm.NewOrmUsingDB("data")
  148. sql := `SELECT * FROM base_from_yongyi_data WHERE index_code=? `
  149. _, err = o.Raw(sql, indexCode).QueryRows(&list)
  150. return
  151. }
  152. func GetBaseFromYongyiIndexByIndexCode(indexCode string) (list *BaseFromYongyiIndex, err error) {
  153. o := orm.NewOrmUsingDB("data")
  154. sql := ` SELECT * FROM base_from_yongyi_index WHERE index_code=? `
  155. err = o.Raw(sql, indexCode).QueryRow(&list)
  156. return
  157. }
  158. type BaseFromYongyiIndexType struct {
  159. Type2 string `orm:"column(type_2)"`
  160. Type3 string `orm:"column(type_3)"`
  161. }
  162. // Update 更新Yongyi指标基础信息
  163. func (item *BaseFromYongyiIndex) Update(cols []string) (err error) {
  164. o := orm.NewOrmUsingDB("data")
  165. _, err = o.Update(item, cols...)
  166. return
  167. }
  168. // EditYongyiIndexInfoResp 新增指标的返回
  169. type EditYongyiIndexInfoResp struct {
  170. YongyiIndexId int `description:"指标ID"`
  171. IndexCode string `description:"指标code"`
  172. }