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. 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. if len(indexCode) == 0 {
  84. return
  85. }
  86. o := orm.NewOrmUsingDB("data")
  87. sql := ` SELECT * FROM base_from_yongyi_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCode)) + `) ORDER BY data_time DESC `
  88. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  89. return
  90. }
  91. // GetYongyiByConditionAndFrequency 根据条件获取涌益咨询指标列表
  92. func GetYongyiByConditionAndFrequency(condition, frequency string, pars []interface{}) (items []*BaseFromYongyiIndex, err error) {
  93. o := orm.NewOrmUsingDB("data")
  94. sql := ` SELECT * FROM base_from_yongyi_index WHERE 1=1 `
  95. if condition != "" {
  96. sql += condition
  97. }
  98. sql += ` AND frequency=?`
  99. sql += ` ORDER BY sort ASC, yongyi_index_id ASC`
  100. _, err = o.Raw(sql, pars, frequency).QueryRows(&items)
  101. return
  102. }
  103. func GetYongyiFrequencyByCondition(condition string, pars []interface{}) (items []string, err error) {
  104. sql := `SELECT DISTINCT frequency FROM base_from_yongyi_index WHERE 1=1 `
  105. if condition != "" {
  106. sql += condition
  107. }
  108. sql += ` ORDER BY FIELD(frequency,'日度','周度','旬度','月度','季度','半年度','年度') `
  109. o := orm.NewOrmUsingDB("data")
  110. _, err = o.Raw(sql, pars...).QueryRows(&items)
  111. return
  112. }
  113. // GetYongyiDataDataTimeByIndexId 根据指标id获取指标数据的日期列表
  114. func GetYongyiDataDataTimeByIndexId(indexIdList []int) (items []string, err error) {
  115. if len(indexIdList) == 0 {
  116. return
  117. }
  118. o := orm.NewOrmUsingDB("data")
  119. sql := ` SELECT DISTINCT data_time FROM base_from_yongyi_data WHERE yongyi_index_id IN (` + utils.GetOrmInReplace(len(indexIdList)) + `) ORDER BY data_time DESC`
  120. _, err = o.Raw(sql, indexIdList).QueryRows(&items)
  121. return
  122. }
  123. type BaseFromYongyiData struct {
  124. YongyiDataId int `orm:"column(yongyi_data_id);pk"`
  125. YongyiIndexId int
  126. IndexCode string
  127. DataTime string
  128. Value string
  129. CreateTime string
  130. ModifyTime string
  131. DataTimestamp int64
  132. }
  133. type BaseFromYongyiIndexSearchItem struct {
  134. YongyiIndexId int `orm:"column(yongyi_index_id);pk"`
  135. ClassifyId 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. }