router.go 10 KB

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