router.go 13 KB

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