base_from_yongyi.go 6.0 KB

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