base_from_ccf.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 BaseFromCCFIndex struct {
  9. BaseFromCcfIndexId int `orm:"column(base_from_ccf_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 BaseFromCCFIndexList struct {
  20. BaseFromCcfIndexId int `orm:"column(base_from_ccf_index_id);pk"`
  21. EdbInfoId int
  22. ClassifyId int
  23. IndexCode string
  24. IndexName string
  25. Frequency string
  26. Unit string
  27. Sort int
  28. CreateTime string
  29. ModifyTime string
  30. EndDate string
  31. EndValue string
  32. EdbExist int `description:"指标库是否已添加:0-否;1-是"`
  33. DataList []*BaseFromCCFData
  34. Paging *paging.PagingItem `description:"分页数据"`
  35. }
  36. type CCFSingleDataResp struct {
  37. BaseFromCcfIndexId int
  38. ClassifyId int
  39. IndexCode string
  40. IndexName string
  41. Frequency string
  42. Unit string
  43. CreateTime string
  44. ModifyTime string
  45. Data []*CCFSingleData
  46. }
  47. type CCFSingleData struct {
  48. Value string `orm:"column(value)" description:"日期"`
  49. DataTime string `orm:"column(data_time)" description:"值"`
  50. }
  51. func GetCCFIndex(condition string, pars interface{}) (items []*BaseFromCCFIndexList, err error) {
  52. o := orm.NewOrmUsingDB("data")
  53. sql := ` SELECT * FROM base_from_ccf_index WHERE 1=1 `
  54. if condition != "" {
  55. sql += condition
  56. }
  57. sql += ` ORDER BY sort ASC, base_from_ccf_index_id asc`
  58. _, err = o.Raw(sql, pars).QueryRows(&items)
  59. return
  60. }
  61. func GetCCFIndexDataCount(indexCode string) (count int, err error) {
  62. o := orm.NewOrmUsingDB("data")
  63. sql := ` SELECT COUNT(1) AS count FROM base_from_ccf_data WHERE index_code=? `
  64. err = o.Raw(sql, indexCode).QueryRow(&count)
  65. return
  66. }
  67. type CCFIndexDataCountGroup struct {
  68. IndexCode string
  69. Count int
  70. }
  71. func GetCCFIndexDataCountGroup(indexCodes []string) (items []*CCFIndexDataCountGroup, err error) {
  72. if len(indexCodes) <= 0 {
  73. return
  74. }
  75. o := orm.NewOrmUsingDB("data")
  76. sql := ` SELECT COUNT(1) AS count, index_code FROM base_from_ccf_data WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodes)) + `) GROUP BY index_code`
  77. _, err = o.Raw(sql, indexCodes).QueryRows(&items)
  78. return
  79. }
  80. func GetCCFIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromCCFData, err error) {
  81. o := orm.NewOrmUsingDB("data")
  82. sql := ` SELECT * FROM base_from_ccf_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  83. _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
  84. return
  85. }
  86. func GetCCFIndexDataByCodes(indexCode []string) (items []*BaseFromCCFData, err error) {
  87. if len(indexCode) <= 0 {
  88. return
  89. }
  90. o := orm.NewOrmUsingDB("data")
  91. sql := ` SELECT * FROM base_from_ccf_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCode)) + `) ORDER BY data_time DESC `
  92. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  93. return
  94. }
  95. type BaseFromCCFData struct {
  96. BaseFromCcfDataId int `orm:"column(base_from_ccf_data_id);pk"`
  97. BaseFromCcfIndexId int
  98. IndexCode string
  99. DataTime string
  100. Value string
  101. CreateTime string
  102. ModifyTime string
  103. DataTimestamp int64
  104. }
  105. type BaseFromCCFIndexSearchItem struct {
  106. BaseFromCcfIndexId int `orm:"column(base_from_ccf_index_id);pk"`
  107. ClassifyId int
  108. IndexCode string
  109. IndexName string
  110. }
  111. // GetCCFItemList 模糊查询CCF数据库指标列表
  112. func GetCCFItemList(condition string) (items []*BaseFromCCFIndexSearchItem, err error) {
  113. o := orm.NewOrmUsingDB("data")
  114. sql := "SELECT * FROM base_from_ccf_index WHERE 1=1"
  115. if condition != "" {
  116. sql += condition
  117. }
  118. _, err = o.Raw(sql).QueryRows(&items)
  119. return
  120. }
  121. func GetCCFIndexDataByCode(indexCode string) (list []*BaseFromCCFData, err error) {
  122. o := orm.NewOrmUsingDB("data")
  123. sql := `SELECT * FROM base_from_ccf_data WHERE index_code=? `
  124. _, err = o.Raw(sql, indexCode).QueryRows(&list)
  125. return
  126. }
  127. func GetBaseFromCCFIndexByIndexCode(indexCode string) (list *BaseFromCCFIndex, err error) {
  128. o := orm.NewOrmUsingDB("data")
  129. sql := ` SELECT * FROM base_from_ccf_index WHERE index_code=? `
  130. err = o.Raw(sql, indexCode).QueryRow(&list)
  131. return
  132. }
  133. func GetCCFIndexPage(condition string, pars interface{}, startSize, pageSize int) (items []*BaseFromCCFIndexList, err error) {
  134. o := orm.NewOrmUsingDB("data")
  135. sql := ` SELECT * FROM base_from_ccf_index WHERE 1=1 `
  136. if condition != "" {
  137. sql += condition
  138. }
  139. sql += ` ORDER BY sort ASC, base_from_ccf_index_id asc LIMIT ?,?`
  140. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  141. return
  142. }
  143. func GetCCFIndexPageCount(condition string, pars interface{}) (count int, err error) {
  144. o := orm.NewOrmUsingDB("data")
  145. sql := ` SELECT COUNT(1) AS count FROM base_from_ccf_index WHERE 1=1 `
  146. if condition != "" {
  147. sql += condition
  148. }
  149. err = o.Raw(sql, pars).QueryRow(&count)
  150. return
  151. }
  152. type BaseFromCCFIndexSearchList struct {
  153. List []*BaseFromCCFIndexList
  154. Paging *paging.PagingItem `description:"分页数据"`
  155. }
  156. type CCFIndexSource2EdbReq struct {
  157. EdbCode string
  158. EdbName string
  159. Frequency string
  160. Unit string
  161. ClassifyId int
  162. AdminId int
  163. AdminRealName string
  164. }
  165. // BatchCheckCCFEdbReq 指标数据结构体
  166. type BatchCheckCCFEdbReq struct {
  167. //IsJoinEdb int `form:"IsJoinEdb" description:"是否加到指标库,0:未加到指标库"`
  168. Frequencies string `description:"频度;枚举值:日度、周度、月度、季度、半年度、年度"`
  169. Keyword string `description:"关键字"`
  170. ClassifyIds string `description:"所选品种id列表"`
  171. ListAll bool `form:"ListAll" json:"ListAll" description:"列表全选"`
  172. TradeCodeList string `form:"TradeCodeList" json:"TradeCodeList" description:"全选为false时, 该数组为选中; 全选为true时, 该数组为不选的指标"`
  173. }
  174. func GetCCFFrequencyByClassifyId(classifyId int) (items []*GlFrequency, err error) {
  175. o := orm.NewOrmUsingDB("data")
  176. sql := ` SELECT frequency FROM base_from_ccf_index WHERE classify_id = ? `
  177. sql += ` GROUP BY frequency ORDER BY frequency ASC `
  178. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  179. return
  180. }
  181. func GetCCFIndexDataByDataTime(indexCodes []string, startDate, endDate string) (items []*BaseFromCCFData, err error) {
  182. o := orm.NewOrmUsingDB("data")
  183. sql := ` SELECT * FROM base_from_ccf_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `) and data_time >=? and data_time <? ORDER BY data_time DESC `
  184. _, err = o.Raw(sql, indexCodes, startDate, endDate).QueryRows(&items)
  185. return
  186. }
  187. func GetCCFIndexDataTimePageByCodes(indexCodes []string, startSize, pageSize int) (dataTimes []string, err error) {
  188. o := orm.NewOrmUsingDB("data")
  189. sql := ` SELECT data_time FROM base_from_ccf_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `) GROUP BY data_time ORDER BY data_time DESC LIMIT ?,? `
  190. _, err = o.Raw(sql, indexCodes, startSize, pageSize).QueryRows(&dataTimes)
  191. return
  192. }
  193. func GetCCFIndexDataTimePageCount(indexCodes []string) (count int, err error) {
  194. o := orm.NewOrmUsingDB("data")
  195. sql := ` SELECT COUNT(DISTINCT data_time) AS count FROM base_from_ccf_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `)`
  196. err = o.Raw(sql, indexCodes).QueryRow(&count)
  197. return
  198. }
  199. // GetCCFDataDataTimeByIndexId 根据指标id获取指标数据的日期列表
  200. func GetCCFDataDataTimeByIndexId(indexIdList []int) (items []string, err error) {
  201. if len(indexIdList) == 0 {
  202. return
  203. }
  204. o := orm.NewOrmUsingDB("data")
  205. sql := ` SELECT DISTINCT data_time FROM base_from_ccf_data WHERE base_from_ccf_index_id IN (` + utils.GetOrmInReplace(len(indexIdList)) + `) ORDER BY data_time DESC`
  206. _, err = o.Raw(sql, indexIdList).QueryRows(&items)
  207. return
  208. }
  209. func GetCCFIndexDataByIndexIdAndDataTime(indexId []int, dataTimeList []string) (items []*BaseFromCCFData, err error) {
  210. o := orm.NewOrmUsingDB("data")
  211. sql := ` SELECT * FROM base_from_ccf_data WHERE base_from_ccf_index_id in (` + utils.GetOrmInReplace(len(indexId)) + `) and data_time in (` + utils.GetOrmInReplace(len(dataTimeList)) + `) `
  212. _, err = o.Raw(sql, indexId, dataTimeList).QueryRows(&items)
  213. return
  214. }