base_from_yongyi.go 6.1 KB

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