router.go 11 KB

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