router.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. package routers
  2. import (
  3. "mtp2_if/config"
  4. "mtp2_if/controllers/cfg"
  5. "mtp2_if/controllers/common"
  6. "mtp2_if/controllers/cptrade"
  7. "mtp2_if/controllers/delivery"
  8. "mtp2_if/controllers/erms2"
  9. "mtp2_if/controllers/hsby"
  10. "mtp2_if/controllers/order"
  11. "mtp2_if/controllers/szdz"
  12. "mtp2_if/controllers/taaccount"
  13. "mtp2_if/controllers/user"
  14. "mtp2_if/controllers/wrtrade"
  15. "mtp2_if/logger"
  16. "mtp2_if/token"
  17. "net/http"
  18. "time"
  19. "github.com/gin-gonic/gin"
  20. // Swagger生成的文档
  21. _ "mtp2_if/docs"
  22. ginSwagger "github.com/swaggo/gin-swagger"
  23. "github.com/swaggo/gin-swagger/swaggerFiles"
  24. )
  25. // InitRouter 初始化路由器的方法
  26. func InitRouter() *gin.Engine {
  27. r := gin.New()
  28. // 设置日志中间件
  29. r.Use(ginLoggerMiddleware())
  30. // 设置奔溃中间件
  31. r.Use(ginRecoveryMiddleware())
  32. // 跨域
  33. r.Use(CORSMiddleware())
  34. // Swagger
  35. if config.SerCfg.GetDebugMode() {
  36. r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
  37. }
  38. // 终端配置
  39. r.GET("/cfg", cfg.QueryCfg)
  40. // 主业务路由分组
  41. apiR := r.Group("/api")
  42. // apiR.Use(token.Auth())
  43. // ************************ 账户信息 ************************
  44. userR := apiR.Group("User")
  45. userR.Use()
  46. {
  47. // 获取登录ID
  48. userR.GET("/GetLoginID", user.GetLoginID)
  49. // 获取用户邀请码请求参数
  50. userR.GET("/QueryUserReferNum", user.QueryUserReferNum)
  51. // 获取用户信息请求参数
  52. userR.Use(token.Auth()).GET("/QueryUserInfo", user.QueryUserInfo)
  53. // 获取用户实名认证状态
  54. userR.Use(token.Auth()).GET("/GetUserAuthStatus", user.GetUserAuthStatus)
  55. }
  56. // ************************ 资金账户 ************************
  57. taAccountR := apiR.Group("TaAccount")
  58. taAccountR.Use(token.Auth())
  59. {
  60. // 资金流水查询(当前)
  61. taAccountR.GET("/QueryAmountLog", taaccount.QueryAmountLog)
  62. // 资金流水查询(历史)
  63. taAccountR.GET("/QueryHisAmountLog", taaccount.QueryHisAmountLog)
  64. }
  65. // ************************ 通用服务 ************************
  66. commonR := apiR.Group("Common")
  67. commonR.Use()
  68. {
  69. // 查询交易端菜单
  70. commonR.GET("/QueryTraderMenu", common.QueryTraderMenu)
  71. // 查询交易端列表头信息
  72. commonR.GET("/QueryTableDefine", common.QueryTableDefine)
  73. // 通知公告系统消息查询
  74. commonR.Use(token.Auth()).GET("/QueryNotice", common.QueryNotice)
  75. // 通知公告设置已读请求
  76. commonR.Use(token.Auth()).POST("/NoticeReaded", common.NoticeReaded)
  77. }
  78. // ************************ 通用单据 ************************
  79. orderR := apiR.Group("Order")
  80. orderR.Use(token.Auth())
  81. {
  82. // 持仓汇总查询(合约市场)
  83. orderR.GET("/QueryTradePosition", order.QueryTradePosition)
  84. // 委托单查询请求(合约市场)
  85. orderR.GET("/QueryTradeOrderDetail", order.QueryTradeOrderDetail)
  86. // 历史委托单查询请求(合约市场)
  87. orderR.GET("/QueryHisTradeOrderDetail", order.QueryHisTradeOrderDetail)
  88. // 成交单查询(合约市场)
  89. orderR.GET("/QueryTradeDetail", order.QueryTradeDetail)
  90. // 历史成交单查询(合约市场)
  91. orderR.GET("/QueryHisTradeDetail", order.QueryHisTradeDetail)
  92. }
  93. // ************************ 仓单贸易 ************************
  94. wrTradeR := apiR.Group("WRTrade")
  95. wrTradeR.Use(token.Auth())
  96. {
  97. wrTradeR.GET("/GetAllDeliveryGoods", wrtrade.GetAllDeliveryGoods)
  98. }
  99. // ************************ 产能预售 ************************
  100. cpTradeR := apiR.Group("CPTrade")
  101. cpTradeR.Use(token.Auth())
  102. {
  103. // 查询产能预售申请表
  104. cpTradeR.GET("/QueryPreasleApply", cptrade.QueryPreasleApply)
  105. // 查询远期订单信息
  106. cpTradeR.GET("/QueryUserGoodsData", cptrade.QueryUserGoodsData)
  107. // 查询远期订单注销申请信息
  108. cpTradeR.GET("/QueryPositionCancel", cptrade.QueryPositionCancel)
  109. // 查询产能预售商品扩展信息
  110. cpTradeR.GET("/QueryPresaleGoodsEx", cptrade.QueryPresaleGoodsEx)
  111. // 查询产能预售我的出价信息
  112. cpTradeR.GET("/QueryCPTradeMyBidInfos", cptrade.QueryCPTradeMyBidInfos)
  113. // 查询我的预售信息
  114. cpTradeR.GET("/QueryMyCPTradeGoods", cptrade.QueryMyCPTradeGoods)
  115. // 查询产能预售委托单信息
  116. cpTradeR.GET("/QueryCPTradeOrderDetail", cptrade.QueryCPTradeOrderDetail)
  117. }
  118. // ************************ 交割服务 ************************
  119. deliveryR := apiR.Group("Delivery")
  120. deliveryR.Use(token.Auth())
  121. {
  122. // 查询商品交割关系表
  123. deliveryR.GET("/QueryDeliveryRelation", delivery.QueryDeliveryRelation)
  124. }
  125. // ************************ 风险管理 ************************
  126. erms2R := apiR.Group("Erms2")
  127. erms2R.Use(token.Auth())
  128. {
  129. // 查询内部成交单信息
  130. erms2R.GET("/QueryInnerTradeDetail", erms2.QueryInnerTradeDetail)
  131. // 查询期现套利策略表信息(指定资金账户、未结束的)
  132. erms2R.GET("/QueryArbitrageStrategy", erms2.QueryArbitrageStrategy)
  133. // 查询现货合同表信息(指定策略ID、未结束的)
  134. erms2R.GET("/QuerySpotContract", erms2.QuerySpotContract)
  135. }
  136. // ************************ 定制【尚志大宗】 ************************
  137. szdzR := apiR.Group("SZDZ")
  138. szdzR.Use(token.Auth())
  139. {
  140. // 点选挂牌委托单据查询(摘牌大厅)
  141. szdzR.GET("/QueryRecieptOrder", szdz.QueryRecieptOrder)
  142. // 商品提货单查询
  143. szdzR.GET("/QueryGoodsPickup", szdz.QueryGoodsPickup)
  144. // 交易系统转换流水查询
  145. szdzR.GET("/QueryConvertLog", szdz.QueryConvertLog)
  146. // 搜索白名单
  147. szdzR.GET("/SearchWhite", szdz.SearchWhite)
  148. // 查询交易系统转换设置
  149. szdzR.GET("/QueryConvertConfig", szdz.QueryConvertConfig)
  150. // 持仓汇总查询(尚志大宗)
  151. szdzR.GET("/QuerySZDZTradePosition", szdz.QuerySZDZTradePosition)
  152. }
  153. // ************************ 定制【海商报业】 ************************
  154. hsbyR := apiR.Group("HSBY")
  155. hsbyR.Use(token.Auth())
  156. {
  157. // 查询热门商品列表(二级市场,挂牌点选)
  158. hsbyR.GET("/QueryTopGoods", hsby.QueryTopGoods)
  159. // 查询二级市场(挂牌点选)商品信息详情
  160. hsbyR.GET("/QueryHsbyListingGoodsDetail", hsby.QueryHsbyListingGoodsDetail)
  161. // 查询二级市场(挂牌点选)商品对应的挂牌委托单信息
  162. hsbyR.GET("/QueryHsbyGoodsOrderDetails", hsby.QueryHsbyGoodsOrderDetails)
  163. }
  164. return r
  165. }
  166. func ginLoggerMiddleware() gin.HandlerFunc {
  167. return func(c *gin.Context) {
  168. start := time.Now()
  169. c.Next()
  170. end := time.Now()
  171. latency := end.Sub(start)
  172. path := c.Request.URL.RequestURI()
  173. clientip := c.ClientIP()
  174. method := c.Request.Method
  175. statuscode := c.Writer.Status()
  176. logger.GetLogger().Debugln("|%3d|%13v|%15s|%s %s",
  177. statuscode,
  178. latency,
  179. clientip,
  180. method,
  181. path)
  182. }
  183. }
  184. func ginRecoveryMiddleware() gin.HandlerFunc {
  185. return gin.RecoveryWithWriter(logger.GetLogWriter())
  186. }
  187. // CORSMiddleware cors跨域.
  188. func CORSMiddleware() gin.HandlerFunc {
  189. return func(c *gin.Context) {
  190. c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
  191. c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
  192. c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With, X-session-Token")
  193. c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT")
  194. c.Writer.Header().Set("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type, X-session-Token")
  195. if c.Request.Method == "OPTIONS" {
  196. c.AbortWithStatus(http.StatusNoContent)
  197. return
  198. }
  199. c.Next()
  200. }
  201. }