router.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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/erms3"
  10. "mtp2_if/controllers/hsby"
  11. "mtp2_if/controllers/order"
  12. "mtp2_if/controllers/quote"
  13. "mtp2_if/controllers/search"
  14. "mtp2_if/controllers/szdz"
  15. "mtp2_if/controllers/taaccount"
  16. "mtp2_if/controllers/trade"
  17. "mtp2_if/controllers/user"
  18. "mtp2_if/controllers/wrtrade"
  19. "mtp2_if/logger"
  20. "mtp2_if/token"
  21. "net/http"
  22. "time"
  23. "github.com/gin-gonic/gin"
  24. // Swagger生成的文档
  25. _ "mtp2_if/docs"
  26. ginSwagger "github.com/swaggo/gin-swagger"
  27. "github.com/swaggo/gin-swagger/swaggerFiles"
  28. )
  29. // InitRouter 初始化路由器的方法
  30. func InitRouter() *gin.Engine {
  31. r := gin.New()
  32. // 设置日志中间件
  33. r.Use(ginLoggerMiddleware())
  34. // 设置奔溃中间件
  35. r.Use(ginRecoveryMiddleware())
  36. // 跨域
  37. r.Use(CORSMiddleware())
  38. // Swagger
  39. if config.SerCfg.GetDebugMode() {
  40. r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
  41. }
  42. // 终端配置
  43. r.GET("/cfg", cfg.QueryCfg)
  44. // 主业务路由分组
  45. apiR := r.Group("/api")
  46. // apiR.Use(token.Auth())
  47. // ************************ 账户信息 ************************
  48. userR := apiR.Group("User")
  49. userR.Use()
  50. {
  51. // 获取登录ID
  52. userR.GET("/GetLoginID", user.GetLoginID)
  53. // 获取用户邀请码请求参数
  54. userR.GET("/QueryUserReferNum", user.QueryUserReferNum)
  55. // 获取用户信息请求参数
  56. userR.Use(token.Auth()).GET("/QueryUserInfo", user.QueryUserInfo)
  57. // 获取用户实名认证状态
  58. userR.Use(token.Auth()).GET("/GetUserAuthStatus", user.GetUserAuthStatus)
  59. // 获取用户商品收藏信息
  60. userR.Use(token.Auth()).GET("/QueryUserFavoriteGoodses", user.QueryUserFavoriteGoodses)
  61. // 添加用户商品收藏信息
  62. userR.Use(token.Auth()).POST("/AddUserFavoriteGoods", user.AddUserFavoriteGoods)
  63. // 移除用户商品收藏信息
  64. userR.Use(token.Auth()).POST("/RemoveUserFavoriteGoods", user.RemoveUserFavoriteGoods)
  65. // 获取用户留言板信息
  66. userR.Use(token.Auth()).GET("/QueryMessageBoard", user.QueryMessageBoard)
  67. // 添加用户留言板信息
  68. userR.Use(token.Auth()).POST("/AddMessageBoard", user.AddMessageBoard)
  69. // 获取用户账号信息
  70. userR.Use(token.Auth()).GET("/GetUserAccount", user.GetUserAccount)
  71. }
  72. // ************************ 资金账户 ************************
  73. taAccountR := apiR.Group("TaAccount")
  74. taAccountR.Use(token.Auth())
  75. {
  76. // 资金流水查询(当前)
  77. taAccountR.GET("/QueryAmountLog", taaccount.QueryAmountLog)
  78. // 资金流水查询(历史)
  79. taAccountR.GET("/QueryHisAmountLog", taaccount.QueryHisAmountLog)
  80. }
  81. // ************************ 通用服务 ************************
  82. commonR := apiR.Group("Common")
  83. commonR.Use()
  84. {
  85. // 查询交易端菜单
  86. commonR.GET("/QueryTraderMenu", common.QueryTraderMenu)
  87. // 查询交易端列表头信息
  88. commonR.GET("/QueryTableDefine", common.QueryTableDefine)
  89. // 查询省市信息(不包括区)
  90. commonR.GET("/QueryProvincesAndCities", common.QueryProvincesAndCities)
  91. // 查询轮播图配置信息
  92. commonR.GET("/QueryImageConfigs", common.QueryImageConfigs)
  93. // 获取所有枚举信息
  94. commonR.GET("/GetAllEnums", common.GetAllEnums)
  95. // 通知公告系统消息查询
  96. commonR.Use(token.Auth()).GET("/QueryNotice", common.QueryNotice)
  97. // 通知公告设置已读请求
  98. commonR.Use(token.Auth()).POST("/NoticeReaded", common.NoticeReaded)
  99. }
  100. // ************************ 通用单据 ************************
  101. orderR := apiR.Group("Order")
  102. orderR.Use(token.Auth())
  103. {
  104. // 持仓汇总查询(合约市场)
  105. orderR.GET("/QueryTradePosition", order.QueryTradePosition)
  106. // 委托单查询请求(合约市场)
  107. orderR.GET("/QueryTradeOrderDetail", order.QueryTradeOrderDetail)
  108. // 历史委托单查询请求(合约市场)
  109. orderR.GET("/QueryHisTradeOrderDetail", order.QueryHisTradeOrderDetail)
  110. // 成交单查询(合约市场)
  111. orderR.GET("/QueryTradeDetail", order.QueryTradeDetail)
  112. // 历史成交单查询(合约市场)
  113. orderR.GET("/QueryHisTradeDetail", order.QueryHisTradeDetail)
  114. }
  115. // ************************ 通用交易 ************************
  116. tradeR := apiR.Group("Trade")
  117. tradeR.Use(token.Auth())
  118. {
  119. // 点选挂牌委托单据查询(保证金摘牌大厅)
  120. tradeR.GET("/QueryRecieptOrder", trade.QueryRecieptOrder)
  121. }
  122. // ************************ 行情服务 ************************
  123. quoteR := apiR.Group("Quote")
  124. quoteR.Use(token.Auth())
  125. {
  126. // 查询行情历史数据
  127. quoteR.GET("/QueryHistoryDatas", quote.QueryHistoryDatas)
  128. }
  129. // ************************ 检索服务 ************************
  130. searchR := apiR.Group("Search")
  131. searchR.Use()
  132. {
  133. // 检索商品信息
  134. searchR.GET("/SearchGoodses", search.Goodses)
  135. }
  136. // ************************ 仓单贸易 ************************
  137. wrTradeR := apiR.Group("WRTrade")
  138. wrTradeR.Use(token.Auth())
  139. {
  140. wrTradeR.GET("/GetAllDeliveryGoods", wrtrade.GetAllDeliveryGoods)
  141. }
  142. // ************************ 产能预售 ************************
  143. cpTradeR := apiR.Group("CPTrade")
  144. cpTradeR.Use(token.Auth())
  145. {
  146. // 查询产能预售申请表
  147. cpTradeR.GET("/QueryPreasleApply", cptrade.QueryPreasleApply)
  148. // 查询远期订单信息
  149. cpTradeR.GET("/QueryUserGoodsData", cptrade.QueryUserGoodsData)
  150. // 查询远期订单注销申请信息
  151. cpTradeR.GET("/QueryPositionCancel", cptrade.QueryPositionCancel)
  152. // 查询产能预售商品扩展信息
  153. cpTradeR.GET("/QueryPresaleGoodsEx", cptrade.QueryPresaleGoodsEx)
  154. // 查询产能预售我的出价信息
  155. cpTradeR.GET("/QueryCPTradeMyBidInfos", cptrade.QueryCPTradeMyBidInfos)
  156. // 查询我的预售信息
  157. cpTradeR.GET("/QueryMyCPTradeGoods", cptrade.QueryMyCPTradeGoods)
  158. // 查询产能预售委托单信息
  159. cpTradeR.GET("/QueryCPTradeOrderDetail", cptrade.QueryCPTradeOrderDetail)
  160. }
  161. // ************************ 交割服务 ************************
  162. deliveryR := apiR.Group("Delivery")
  163. deliveryR.Use(token.Auth())
  164. {
  165. // 查询商品交割关系表
  166. deliveryR.GET("/QueryDeliveryRelation", delivery.QueryDeliveryRelation)
  167. }
  168. // ************************ 风险管理 ************************
  169. erms2R := apiR.Group("Erms2")
  170. erms2R.Use(token.Auth())
  171. {
  172. // 查询内部成交单信息
  173. erms2R.GET("/QueryInnerTradeDetail", erms2.QueryInnerTradeDetail)
  174. // 查询期现套利策略表信息(指定资金账户、未结束的)
  175. erms2R.GET("/QueryArbitrageStrategy", erms2.QueryArbitrageStrategy)
  176. // 查询现货合同表信息(指定策略ID、未结束的)
  177. erms2R.GET("/QuerySpotContract", erms2.QuerySpotContract)
  178. }
  179. // ************************ 风险管理v3 ************************
  180. erms3R := apiR.Group("Erms3")
  181. erms3R.Use(token.Auth())
  182. {
  183. // 新增现货合同申请
  184. erms3R.POST("/AddSpotContractApply", erms3.AddSpotContractApply)
  185. // 查询合同申请表单数据
  186. erms3R.GET("/QuerySpotContractAppleForm", erms3.QuerySpotContractAppleForm)
  187. // 查询合同详细信息.
  188. erms3R.GET("/QuerySpotContractDetail", erms3.QuerySpotContractDetail)
  189. // 查询待审核合同
  190. erms3R.GET("/QueryPendingAuditContract", erms3.QueryPendingAuditContract)
  191. // 新增客户申请
  192. erms3R.POST("/AddUserInfoApply", erms3.AddUserInfoApply)
  193. // 客户申请信息查询
  194. erms3R.GET("/QueryUserInfoApplies", erms3.QueryUserInfoApplies)
  195. // 待审核业务查询
  196. erms3R.GET("/QueryPendingBusiness", erms3.QueryPendingBusiness)
  197. // 业务信息查询
  198. erms3R.GET("/QueryBusinessInfo", erms3.QueryBusinessInfo)
  199. // 客户信息查询
  200. erms3R.GET("/QueryUserInfos", erms3.QueryUserInfos)
  201. // 新增期现套利业务申请
  202. erms3R.POST("/AddErms2ASApply", erms3.AddErms2ASApply)
  203. // 新增现货贸易业务申请
  204. erms3R.POST("/AddErms2SpotTradeApply", erms3.AddErms2SpotTradeApply)
  205. }
  206. // ************************ 定制【尚志大宗】 ************************
  207. szdzR := apiR.Group("SZDZ")
  208. szdzR.Use(token.Auth())
  209. {
  210. // 点选挂牌委托单据查询(摘牌大厅)
  211. szdzR.GET("/QueryRecieptOrder", szdz.QueryRecieptOrder)
  212. // 商品提货单查询
  213. szdzR.GET("/QueryGoodsPickup", szdz.QueryGoodsPickup)
  214. // 交易系统转换流水查询
  215. szdzR.GET("/QueryConvertLog", szdz.QueryConvertLog)
  216. // 搜索白名单
  217. szdzR.GET("/SearchWhite", szdz.SearchWhite)
  218. // 查询交易系统转换设置
  219. szdzR.GET("/QueryConvertConfig", szdz.QueryConvertConfig)
  220. // 持仓汇总查询(尚志大宗)
  221. szdzR.GET("/QuerySZDZTradePosition", szdz.QuerySZDZTradePosition)
  222. }
  223. // ************************ 定制【海商报业】 ************************
  224. hsbyR := apiR.Group("HSBY")
  225. hsbyR.Use(token.AuthByHsby())
  226. {
  227. // 查询热门商品列表(二级市场,挂牌点选)
  228. hsbyR.GET("/QueryHsbyTopGoodses", hsby.QueryHsbyTopGoodses)
  229. // 查询二级市场(挂牌点选)商品信息详情
  230. hsbyR.GET("/QueryHsbyListingGoodsDetail", hsby.QueryHsbyListingGoodsDetail)
  231. // 查询二级市场(挂牌点选)商品对应的挂牌委托单信息
  232. hsbyR.GET("/QueryHsbyGoodsOrderDetails", hsby.QueryHsbyGoodsOrderDetails)
  233. // 查询“我的订单”信息
  234. hsbyR.GET("/QueryHsbyMyBuyOrderDetails", hsby.QueryHsbyMyBuyOrderDetails)
  235. // 查询“我的商品”信息
  236. hsbyR.GET("/QueryHsbyMyGoods", hsby.QueryHsbyMyGoods)
  237. // 查询新品上市商品列表(一级市场预售)
  238. hsbyR.GET("/QueryHsbyPreGoodses", hsby.QueryHsbyPreGoodses)
  239. // 查询一级市场(预售)商品信息详情
  240. hsbyR.GET("/QueryHsbyPreGoodsDetail", hsby.QueryHsbyPreGoodsDetail)
  241. // 查询"我的闲置"单据信息
  242. hsbyR.GET("/QueryHsbySellMyDetails", hsby.QueryHsbySellMyDetails)
  243. // 查询我的包裹信息
  244. hsbyR.GET("/QueryHsbyMyPackages", hsby.QueryHsbyMyPackages)
  245. // 设置我的包裹已收货状态
  246. hsbyR.POST("/SetHsbyMyPackagesStatus", hsby.SetHsbyMyPackagesStatus)
  247. // 查询省市信息(不包括区)
  248. hsbyR.GET("/QueryProvincesAndCities", hsby.QueryProvincesAndCities)
  249. // 查询"我的订单 - 已完成"单据信息
  250. hsbyR.GET("/QueryHsbyBuyMyTradeDetail", hsby.QueryHsbyBuyMyTradeDetail)
  251. // 获取我的订单与包裹数量
  252. hsbyR.GET("/GetHsbyMyCount", hsby.GetHsbyMyCount)
  253. // 获取我的订单中待付款信息
  254. hsbyR.GET("/QueryMyPayOrders", hsby.QueryMyPayOrders)
  255. // 获取我的闲置中收款信息查询
  256. hsbyR.GET("/QueryMyCollectionOrders", hsby.QueryMyCollectionOrders)
  257. // 查询海商报业相关市场信息
  258. hsbyR.GET("/QueryHsbyMarkets", hsby.QueryHsbyMarkets)
  259. }
  260. return r
  261. }
  262. func ginLoggerMiddleware() gin.HandlerFunc {
  263. return func(c *gin.Context) {
  264. start := time.Now()
  265. c.Next()
  266. end := time.Now()
  267. latency := end.Sub(start)
  268. path := c.Request.URL.RequestURI()
  269. clientip := c.ClientIP()
  270. method := c.Request.Method
  271. statuscode := c.Writer.Status()
  272. logger.GetLogger().Debugf("|%3d|%13v|%15s|%s %s",
  273. statuscode,
  274. latency,
  275. clientip,
  276. method,
  277. path)
  278. }
  279. }
  280. func ginRecoveryMiddleware() gin.HandlerFunc {
  281. return gin.RecoveryWithWriter(logger.GetLogWriter())
  282. }
  283. // CORSMiddleware cors跨域.
  284. func CORSMiddleware() gin.HandlerFunc {
  285. return func(c *gin.Context) {
  286. c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
  287. c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
  288. 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")
  289. c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT")
  290. c.Writer.Header().Set("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type, X-session-Token")
  291. if c.Request.Method == "OPTIONS" {
  292. c.AbortWithStatus(http.StatusNoContent)
  293. return
  294. }
  295. c.Next()
  296. }
  297. }