base_from_ccf.go 8.4 KB

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