router.go 13 KB

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