router.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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.GET("/GetServerTime", common.GetServerTime)
  97. // 通知公告系统消息查询
  98. commonR.Use(token.Auth()).GET("/QueryNotice", common.QueryNotice)
  99. // 通知公告设置已读请求
  100. commonR.Use(token.Auth()).POST("/NoticeReaded", common.NoticeReaded)
  101. }
  102. // ************************ 通用单据 ************************
  103. orderR := apiR.Group("Order")
  104. orderR.Use(token.Auth())
  105. {
  106. // 持仓汇总查询(合约市场)
  107. orderR.GET("/QueryTradePosition", order.QueryTradePosition)
  108. // 委托单查询请求(合约市场)
  109. orderR.GET("/QueryTradeOrderDetail", order.QueryTradeOrderDetail)
  110. // 历史委托单查询请求(合约市场)
  111. orderR.GET("/QueryHisTradeOrderDetail", order.QueryHisTradeOrderDetail)
  112. // 成交单查询(合约市场)
  113. orderR.GET("/QueryTradeDetail", order.QueryTradeDetail)
  114. // 历史成交单查询(合约市场)
  115. orderR.GET("/QueryHisTradeDetail", order.QueryHisTradeDetail)
  116. }
  117. // ************************ 通用交易 ************************
  118. tradeR := apiR.Group("Trade")
  119. tradeR.Use(token.Auth())
  120. {
  121. // 点选挂牌委托单据查询(保证金摘牌大厅)
  122. tradeR.GET("/QueryRecieptOrder", trade.QueryRecieptOrder)
  123. }
  124. // ************************ 行情服务 ************************
  125. quoteR := apiR.Group("Quote")
  126. quoteR.Use(token.Auth())
  127. {
  128. // 查询行情历史数据
  129. quoteR.GET("/QueryHistoryDatas", quote.QueryHistoryDatas)
  130. }
  131. // ************************ 检索服务 ************************
  132. searchR := apiR.Group("Search")
  133. searchR.Use()
  134. {
  135. // 检索商品信息
  136. searchR.GET("/SearchGoodses", search.Goodses)
  137. }
  138. // ************************ 仓单贸易 ************************
  139. wrTradeR := apiR.Group("WRTrade")
  140. wrTradeR.Use(token.Auth())
  141. {
  142. wrTradeR.GET("/GetAllDeliveryGoods", wrtrade.GetAllDeliveryGoods)
  143. }
  144. // ************************ 产能预售 ************************
  145. cpTradeR := apiR.Group("CPTrade")
  146. cpTradeR.Use(token.Auth())
  147. {
  148. // 查询产能预售申请表
  149. cpTradeR.GET("/QueryPreasleApply", cptrade.QueryPreasleApply)
  150. // 查询远期订单信息
  151. cpTradeR.GET("/QueryUserGoodsData", cptrade.QueryUserGoodsData)
  152. // 查询远期订单注销申请信息
  153. cpTradeR.GET("/QueryPositionCancel", cptrade.QueryPositionCancel)
  154. // 查询产能预售商品扩展信息
  155. cpTradeR.GET("/QueryPresaleGoodsEx", cptrade.QueryPresaleGoodsEx)
  156. // 查询产能预售我的出价信息
  157. cpTradeR.GET("/QueryCPTradeMyBidInfos", cptrade.QueryCPTradeMyBidInfos)
  158. // 查询我的预售信息
  159. cpTradeR.GET("/QueryMyCPTradeGoods", cptrade.QueryMyCPTradeGoods)
  160. // 查询产能预售委托单信息
  161. cpTradeR.GET("/QueryCPTradeOrderDetail", cptrade.QueryCPTradeOrderDetail)
  162. }
  163. // ************************ 交割服务 ************************
  164. deliveryR := apiR.Group("Delivery")
  165. deliveryR.Use(token.Auth())
  166. {
  167. // 查询商品交割关系表
  168. deliveryR.GET("/QueryDeliveryRelation", delivery.QueryDeliveryRelation)
  169. }
  170. // ************************ 风险管理 ************************
  171. erms2R := apiR.Group("Erms2")
  172. erms2R.Use(token.Auth())
  173. {
  174. // 查询内部成交单信息
  175. erms2R.GET("/QueryInnerTradeDetail", erms2.QueryInnerTradeDetail)
  176. // 查询期现套利策略表信息(指定资金账户、未结束的)
  177. erms2R.GET("/QueryArbitrageStrategy", erms2.QueryArbitrageStrategy)
  178. // 查询现货合同表信息(指定策略ID、未结束的)
  179. erms2R.GET("/QuerySpotContract", erms2.QuerySpotContract)
  180. }
  181. // ************************ 风险管理v3 ************************
  182. erms3R := apiR.Group("Erms3")
  183. erms3R.Use(token.Auth())
  184. {
  185. // 新增现货合同申请
  186. erms3R.POST("/AddSpotContractApply", erms3.AddSpotContractApply)
  187. // 查询合同申请表单数据
  188. erms3R.GET("/QuerySpotContractAppleForm", erms3.QuerySpotContractAppleForm)
  189. // 查询合同详细信息.
  190. erms3R.GET("/QuerySpotContractDetail", erms3.QuerySpotContractDetail)
  191. // 查询待审核合同
  192. erms3R.GET("/QueryPendingAuditContract", erms3.QueryPendingAuditContract)
  193. // 新增客户申请
  194. erms3R.POST("/AddUserInfoApply", erms3.AddUserInfoApply)
  195. // 客户申请信息查询
  196. erms3R.GET("/QueryUserInfoApplies", erms3.QueryUserInfoApplies)
  197. // 待审核业务查询
  198. erms3R.GET("/QueryPendingBusiness", erms3.QueryPendingBusiness)
  199. // 业务信息查询
  200. erms3R.GET("/QueryBusinessInfo", erms3.QueryBusinessInfo)
  201. // 客户信息查询
  202. erms3R.GET("/QueryUserInfos", erms3.QueryUserInfos)
  203. // 新增期现套利业务申请
  204. erms3R.POST("/AddErms2ASApply", erms3.AddErms2ASApply)
  205. // 新增现货贸易业务申请
  206. erms3R.POST("/AddErms2SpotTradeApply", erms3.AddErms2SpotTradeApply)
  207. }
  208. // ************************ 定制【尚志大宗】 ************************
  209. szdzR := apiR.Group("SZDZ")
  210. szdzR.Use(token.Auth())
  211. {
  212. // 点选挂牌委托单据查询(摘牌大厅)
  213. szdzR.GET("/QueryRecieptOrder", szdz.QueryRecieptOrder)
  214. // 商品提货单查询
  215. szdzR.GET("/QueryGoodsPickup", szdz.QueryGoodsPickup)
  216. // 交易系统转换流水查询
  217. szdzR.GET("/QueryConvertLog", szdz.QueryConvertLog)
  218. // 搜索白名单
  219. szdzR.GET("/SearchWhite", szdz.SearchWhite)
  220. // 查询交易系统转换设置
  221. szdzR.GET("/QueryConvertConfig", szdz.QueryConvertConfig)
  222. // 持仓汇总查询(尚志大宗)
  223. szdzR.GET("/QuerySZDZTradePosition", szdz.QuerySZDZTradePosition)
  224. }
  225. // ************************ 定制【海商报业】 ************************
  226. hsbyR := apiR.Group("HSBY")
  227. hsbyR.Use(token.AuthByHsby())
  228. {
  229. // 查询热门商品列表(二级市场,挂牌点选)
  230. hsbyR.GET("/QueryHsbyTopGoodses", hsby.QueryHsbyTopGoodses)
  231. // 查询二级市场(挂牌点选)商品信息详情
  232. hsbyR.GET("/QueryHsbyListingGoodsDetail", hsby.QueryHsbyListingGoodsDetail)
  233. // 查询二级市场(挂牌点选)商品对应的挂牌委托单信息
  234. hsbyR.GET("/QueryHsbyGoodsOrderDetails", hsby.QueryHsbyGoodsOrderDetails)
  235. // 查询“我的订单”信息
  236. hsbyR.GET("/QueryHsbyMyBuyOrderDetails", hsby.QueryHsbyMyBuyOrderDetails)
  237. // 查询“我的商品”信息
  238. hsbyR.GET("/QueryHsbyMyGoods", hsby.QueryHsbyMyGoods)
  239. // 查询新品上市商品列表(一级市场预售)
  240. hsbyR.GET("/QueryHsbyPreGoodses", hsby.QueryHsbyPreGoodses)
  241. // 查询一级市场(预售)商品信息详情
  242. hsbyR.GET("/QueryHsbyPreGoodsDetail", hsby.QueryHsbyPreGoodsDetail)
  243. // 查询"我的闲置"单据信息
  244. hsbyR.GET("/QueryHsbySellMyDetails", hsby.QueryHsbySellMyDetails)
  245. // 查询我的包裹信息
  246. hsbyR.GET("/QueryHsbyMyPackages", hsby.QueryHsbyMyPackages)
  247. // 设置我的包裹已收货状态
  248. hsbyR.POST("/SetHsbyMyPackagesStatus", hsby.SetHsbyMyPackagesStatus)
  249. // 查询省市信息(不包括区)
  250. hsbyR.GET("/QueryProvincesAndCities", hsby.QueryProvincesAndCities)
  251. // 查询"我的订单 - 已完成"单据信息
  252. hsbyR.GET("/QueryHsbyBuyMyTradeDetail", hsby.QueryHsbyBuyMyTradeDetail)
  253. // 获取我的订单与包裹数量
  254. hsbyR.GET("/GetHsbyMyCount", hsby.GetHsbyMyCount)
  255. // 获取我的订单中待付款信息
  256. hsbyR.GET("/QueryMyPayOrders", hsby.QueryMyPayOrders)
  257. // 获取我的闲置中收款信息查询
  258. hsbyR.GET("/QueryMyCollectionOrders", hsby.QueryMyCollectionOrders)
  259. // 查询海商报业相关市场信息
  260. hsbyR.GET("/QueryHsbyMarkets", hsby.QueryHsbyMarkets)
  261. }
  262. return r
  263. }
  264. func ginLoggerMiddleware() gin.HandlerFunc {
  265. return func(c *gin.Context) {
  266. start := time.Now()
  267. c.Next()
  268. end := time.Now()
  269. latency := end.Sub(start)
  270. path := c.Request.URL.RequestURI()
  271. clientip := c.ClientIP()
  272. method := c.Request.Method
  273. statuscode := c.Writer.Status()
  274. logger.GetLogger().Debugf("|%3d|%13v|%15s|%s %s",
  275. statuscode,
  276. latency,
  277. clientip,
  278. method,
  279. path)
  280. }
  281. }
  282. func ginRecoveryMiddleware() gin.HandlerFunc {
  283. return gin.RecoveryWithWriter(logger.GetLogWriter())
  284. }
  285. // CORSMiddleware cors跨域.
  286. func CORSMiddleware() gin.HandlerFunc {
  287. return func(c *gin.Context) {
  288. c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
  289. c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
  290. 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")
  291. c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT")
  292. c.Writer.Header().Set("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type, X-session-Token")
  293. if c.Request.Method == "OPTIONS" {
  294. c.AbortWithStatus(http.StatusNoContent)
  295. return
  296. }
  297. c.Next()
  298. }
  299. }