base_from_gpr_risk.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 BaseFromGprRiskIndex struct {
  9. BaseFromGprRiskIndexId int `orm:"column(base_from_gpr_risk_index_id);pk"`
  10. ClassifyId int
  11. IndexCode string
  12. IndexName string
  13. Frequency string
  14. Unit string
  15. Sort int
  16. StartDate string `description:"开始日期"`
  17. EndDate string `description:"结束日期"`
  18. EndValue float64
  19. CreateTime time.Time
  20. ModifyTime time.Time
  21. }
  22. type BaseFromGprRiskIndexList struct {
  23. BaseFromGprRiskIndexId int `orm:"column(base_from_gpr_risk_index_id);pk"`
  24. ClassifyId int
  25. Interface string
  26. EdbInfoId int
  27. EdbUniqueCode string `description:"指标库唯一编码"`
  28. EdbClassifyId int `description:"指标库分类ID"`
  29. StartDate string
  30. EndDate string
  31. EndValue float64
  32. IndexCode string
  33. IndexName string
  34. Frequency string
  35. Unit string
  36. Sort int
  37. CreateTime string
  38. ModifyTime string
  39. EdbExist int `description:"指标库是否已添加:0-否;1-是"`
  40. DataList []*BaseFromGprRiskData
  41. Paging *paging.PagingItem `description:"分页数据"`
  42. }
  43. type BaseFromGprRiskIndexSearchList struct {
  44. List []*BaseFromGprRiskIndexList
  45. Paging *paging.PagingItem `description:"分页数据"`
  46. }
  47. type GprRiskSingleDataResp struct {
  48. BaseFromGprRiskIndexId int
  49. ClassifyId int
  50. EdbInfoId int
  51. IndexCode string
  52. IndexName string
  53. Frequency string
  54. Unit string
  55. StartTime string
  56. CreateTime string
  57. ModifyTime string
  58. EdbExist int `description:"指标库是否已添加:0-否;1-是"`
  59. Data []*GprRiskSingleData
  60. Paging *paging.PagingItem `description:"分页数据"`
  61. }
  62. type GprRiskSingleData struct {
  63. Value string `orm:"column(value)" description:"日期"`
  64. DataTime string `orm:"column(data_time)" description:"值"`
  65. }
  66. func GetGprRiskIndexByClassifyId(classifyId int) (items []*BaseFromGprRiskIndex, err error) {
  67. o := orm.NewOrmUsingDB("data")
  68. sql := ` SELECT base_from_gpr_risk_index_id, classify_id, index_code, index_name FROM base_from_gpr_risk_index WHERE classify_id=? ORDER BY sort ASC, base_from_gpr_risk_index_id ASC `
  69. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  70. return
  71. }
  72. func GetGprRiskIndex(condition string, pars interface{}) (items []*BaseFromGprRiskIndexList, err error) {
  73. o := orm.NewOrmUsingDB("data")
  74. sql := ` SELECT * FROM base_from_gpr_risk_index WHERE 1=1 `
  75. if condition != "" {
  76. sql += condition
  77. }
  78. sql += ` ORDER BY sort ASC, base_from_gpr_risk_index_id asc`
  79. _, err = o.Raw(sql, pars).QueryRows(&items)
  80. return
  81. }
  82. func GetGprRiskIndexPage(condition string, pars interface{}, startSize, pageSize int) (items []*BaseFromGprRiskIndexList, err error) {
  83. o := orm.NewOrmUsingDB("data")
  84. sql := ` SELECT * FROM base_from_gpr_risk_index WHERE 1=1 `
  85. if condition != "" {
  86. sql += condition
  87. }
  88. sql += ` ORDER BY sort ASC, base_from_gpr_risk_index_id asc LIMIT ?,?`
  89. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  90. return
  91. }
  92. func GetGprRiskIndexPageCount(condition string, pars interface{}) (count int, err error) {
  93. o := orm.NewOrmUsingDB("data")
  94. sql := ` SELECT COUNT(1) AS count FROM base_from_gpr_risk_index WHERE 1=1 `
  95. if condition != "" {
  96. sql += condition
  97. }
  98. err = o.Raw(sql, pars).QueryRow(&count)
  99. return
  100. }
  101. func GetGprRiskIndexDataCount(indexCode string) (count int, err error) {
  102. o := orm.NewOrmUsingDB("data")
  103. sql := ` SELECT COUNT(1) AS count FROM base_from_gpr_risk_data WHERE index_code=? `
  104. err = o.Raw(sql, indexCode).QueryRow(&count)
  105. return
  106. }
  107. func GetGprRiskIndexDataByDataTime(indexCodes []string, startDate, endDate string) (items []*BaseFromGprRiskData, err error) {
  108. o := orm.NewOrmUsingDB("data")
  109. sql := ` SELECT * FROM base_from_gpr_risk_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `) and data_time >=? and data_time <? ORDER BY data_time DESC `
  110. _, err = o.Raw(sql, indexCodes, startDate, endDate).QueryRows(&items)
  111. return
  112. }
  113. func GetGprRiskIndexDataTimePageByCodes(indexCodes []string, startSize, pageSize int) (dataTimes []string, err error) {
  114. o := orm.NewOrmUsingDB("data")
  115. sql := ` SELECT data_time FROM base_from_gpr_risk_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `) GROUP BY data_time ORDER BY data_time DESC LIMIT ?,? `
  116. _, err = o.Raw(sql, indexCodes, startSize, pageSize).QueryRows(&dataTimes)
  117. return
  118. }
  119. func GetGprRiskIndexDataTimePageCount(indexCodes []string) (count int, err error) {
  120. o := orm.NewOrmUsingDB("data")
  121. sql := ` SELECT COUNT(DISTINCT data_time) AS count FROM base_from_gpr_risk_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `) `
  122. err = o.Raw(sql, indexCodes).QueryRow(&count)
  123. return
  124. }
  125. func GetGprRiskIndexDataByCodes(indexCode []string) (items []*BaseFromGprRiskData, err error) {
  126. if len(indexCode) == 0 {
  127. return
  128. }
  129. o := orm.NewOrmUsingDB("data")
  130. sql := ` SELECT * FROM base_from_gpr_risk_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCode)) + `) ORDER BY data_time DESC `
  131. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  132. return
  133. }
  134. // GetGprRiskByConditionAndFrequency 根据条件获取涌益咨询指标列表
  135. func GetGprRiskByConditionAndFrequency(condition, frequency string, pars []interface{}) (items []*BaseFromGprRiskIndex, err error) {
  136. o := orm.NewOrmUsingDB("data")
  137. sql := ` SELECT * FROM base_from_gpr_risk_index WHERE 1=1 `
  138. if condition != "" {
  139. sql += condition
  140. }
  141. sql += ` AND frequency=?`
  142. sql += ` ORDER BY sort ASC, base_from_gpr_risk_index_id ASC`
  143. _, err = o.Raw(sql, pars, frequency).QueryRows(&items)
  144. return
  145. }
  146. func GetGprRiskFrequencyByCondition(condition string, pars []interface{}) (items []string, err error) {
  147. sql := `SELECT DISTINCT frequency FROM base_from_gpr_risk_index WHERE 1=1 `
  148. if condition != "" {
  149. sql += condition
  150. }
  151. sql += ` ORDER BY FIELD(frequency,'日度','周度','旬度','月度','季度','半年度','年度') `
  152. o := orm.NewOrmUsingDB("data")
  153. _, err = o.Raw(sql, pars...).QueryRows(&items)
  154. return
  155. }
  156. // GetGprRiskDataDataTimeByIndexId 根据指标id获取指标数据的日期列表
  157. func GetGprRiskDataDataTimeByIndexId(indexIdList []int) (items []string, err error) {
  158. if len(indexIdList) == 0 {
  159. return
  160. }
  161. o := orm.NewOrmUsingDB("data")
  162. sql := ` SELECT DISTINCT data_time FROM base_from_gpr_risk_data WHERE base_from_gpr_risk_index_id IN (` + utils.GetOrmInReplace(len(indexIdList)) + `) ORDER BY data_time DESC`
  163. _, err = o.Raw(sql, indexIdList).QueryRows(&items)
  164. return
  165. }
  166. type BaseFromGprRiskData struct {
  167. BaseFromGprRiskDataId int `orm:"column(base_from_gpr_risk_data_id);pk"`
  168. BaseFromGprRiskIndexId int
  169. IndexCode string
  170. DataTime string
  171. Value string
  172. CreateTime string
  173. ModifyTime string
  174. DataTimestamp int64
  175. }
  176. type BaseFromGprRiskIndexSearchItem struct {
  177. BaseFromGprRiskIndexId int `orm:"column(base_from_gpr_risk_index_id);pk"`
  178. ClassifyId int
  179. ParentClassifyId int
  180. IndexCode string
  181. IndexName string
  182. }
  183. // BatchCheckGprRiskEdbReq 指标数据结构体
  184. type BatchCheckGprRiskEdbReq struct {
  185. //IsJoinEdb int `form:"IsJoinEdb" description:"是否加到指标库,0:未加到指标库"`
  186. Frequencies string `description:"频度;枚举值:日度、周度、月度、季度、半年度、年度"`
  187. Keyword string `description:"关键字"`
  188. ClassifyIds string `description:"所选品种id列表"`
  189. ListAll bool `form:"ListAll" json:"ListAll" description:"列表全选"`
  190. TradeCodeList string `form:"TradeCodeList" json:"TradeCodeList" description:"全选为false时, 该数组为选中; 全选为true时, 该数组为不选的指标"`
  191. }
  192. // GetGprRiskItemList 模糊查询GprRisk数据库指标列表
  193. func GetGprRiskItemList(condition string) (items []*BaseFromGprRiskIndexSearchItem, err error) {
  194. o := orm.NewOrmUsingDB("data")
  195. sql := "SELECT * FROM base_from_gpr_risk_index WHERE 1=1"
  196. if condition != "" {
  197. sql += condition
  198. }
  199. _, err = o.Raw(sql).QueryRows(&items)
  200. return
  201. }
  202. func GetGprRiskIndexDataByCode(indexCode string, pageIndex, pageSize int) (list []*BaseFromGprRiskData, err error) {
  203. o := orm.NewOrmUsingDB("data")
  204. sql := `SELECT * FROM base_from_gpr_risk_data WHERE index_code=? order by data_time desc limit ?,?`
  205. _, err = o.Raw(sql, indexCode, pageIndex, pageSize).QueryRows(&list)
  206. return
  207. }
  208. func GetGprRiskIndexDataTotalByCode(indexCode string) (total int64, err error) {
  209. o := orm.NewOrmUsingDB("data")
  210. sql := `SELECT count(*) FROM base_from_gpr_risk_data WHERE index_code=?`
  211. err = o.Raw(sql, indexCode).QueryRow(&total)
  212. return
  213. }
  214. func GetBaseFromGprRiskIndexByIndexCode(indexCode string) (list *BaseFromGprRiskIndex, err error) {
  215. o := orm.NewOrmUsingDB("data")
  216. sql := ` SELECT * FROM base_from_gpr_risk_index WHERE index_code=? `
  217. err = o.Raw(sql, indexCode).QueryRow(&list)
  218. return
  219. }
  220. type BaseFromGprRiskIndexType struct {
  221. Type2 string `orm:"column(type_2)"`
  222. Type3 string `orm:"column(type_3)"`
  223. }
  224. // Update 更新GprRisk指标基础信息
  225. func (item *BaseFromGprRiskIndex) Update(cols []string) (err error) {
  226. o := orm.NewOrmUsingDB("data")
  227. _, err = o.Update(item, cols...)
  228. return
  229. }
  230. // EditGprRiskIndexInfoResp 新增指标的返回
  231. type EditGprRiskIndexInfoResp struct {
  232. BaseFromGprRiskIndexId int `description:"指标ID"`
  233. IndexCode string `description:"指标code"`
  234. }
  235. type GprRiskIndexSource2EdbReq struct {
  236. EdbCode string
  237. EdbName string
  238. Frequency string
  239. Unit string
  240. ClassifyId int
  241. AdminId int
  242. AdminRealName string
  243. }
  244. func GetGprRiskFrequencyByClassifyId(classifyId int) (items []*GlFrequency, err error) {
  245. o := orm.NewOrmUsingDB("data")
  246. sql := ` SELECT frequency FROM base_from_gpr_risk_index WHERE classify_id = ? `
  247. sql += ` GROUP BY frequency ORDER BY frequency ASC `
  248. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  249. return
  250. }