qryExposure.go 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/1/18 9:26
  4. * @Modify : 2021/1/18 9:26
  5. */
  6. package ermcp
  7. import (
  8. "mtp2_if/global/app"
  9. "mtp2_if/global/e"
  10. "mtp2_if/logger"
  11. "mtp2_if/models"
  12. "net/http"
  13. "github.com/gin-gonic/gin"
  14. )
  15. //敞口相关查询
  16. //实时敞口查询请求
  17. type RealtimeExposureReq struct {
  18. AreaUserID uint32 `form:"userid" binding:"required"` // 用户id
  19. }
  20. //实时敞口查询应答
  21. type RealtimeExposureRsp models.ErmcpRealExposureModel
  22. // QueryUserInfo 查询实时敞口
  23. // @Summary 查询实时敞口
  24. // @Produce json
  25. // @Security ApiKeyAuth
  26. // @Param userid query int true "所属机构ID"
  27. // @Success 200 {array} RealtimeExposureRsp
  28. // @Failure 500 {object} app.Response
  29. // @Router /Ermcp/QueryRealtimeExposure [get]
  30. // @Tags 企业风险管理(app)
  31. func QueryRealtimeExposure(c *gin.Context) {
  32. appG := app.Gin{C: c}
  33. var req RealtimeExposureReq
  34. if err := c.ShouldBind(&req); err != nil {
  35. logger.GetLogger().Errorf("QueryRealtimeExposure fail, %v", err)
  36. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  37. return
  38. }
  39. m := models.ErmcpRealExposureModel{AreaUserID: req.AreaUserID}
  40. if d, err := m.GetDataEx(); err == nil {
  41. appG.Response(http.StatusOK, e.SUCCESS, d)
  42. } else {
  43. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  44. }
  45. }
  46. /***********************敞口明细*************************/
  47. //敞口现货明细请求
  48. type ExposureDetailReq struct {
  49. AreaUserId uint32 `form:"areaUserId" json:"areaUserId"` // 所属机构ID
  50. MiddleGoodsId int32 `form:"middleGoodsId" json:"middlegoodsid"` // 套保商品
  51. }
  52. //敞口现货明细响应
  53. type ExposureDetailRsp models.ErmcpExposureDetailModel
  54. // 查询敞口现货明细
  55. // @Summary 查询敞口现货明细
  56. // @Produce json
  57. // @Security ApiKeyAuth
  58. // @Param areaUserId query int true "所属机构ID"
  59. // @Param middleGoodsId query int true "套保商品"
  60. // @Success 200 {array} ExposureDetailRsp
  61. // @Failure 500 {object} app.Response
  62. // @Router /Ermcp/QueryExposureDetail [get]
  63. // @Tags 企业风险管理(app)
  64. func QueryExposureDetail(c *gin.Context) {
  65. appG := app.Gin{C: c}
  66. var req ExposureDetailReq
  67. if err := c.ShouldBind(&req); err != nil {
  68. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  69. return
  70. }
  71. var m = models.ErmcpExposureDetailModel{Areauserid: req.AreaUserId, MiddlegoodsId: req.MiddleGoodsId}
  72. if d, err := m.GetData(); err == nil {
  73. appG.Response(http.StatusOK, e.SUCCESS, d)
  74. } else {
  75. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  76. }
  77. }
  78. //////////////////////////////////////////////
  79. // 敞口/现货头寸请求
  80. type ExposureSpotReq struct {
  81. AreaUserID int32 `form:"areaUserId" binding:"required"` //所属机构ID
  82. }
  83. // 敞口/现货头寸应答
  84. type ExposureSpotRsp models.AreaSpotModel
  85. // QueryExposureSpot 查询敞口现货头寸
  86. // @Summary 查询敞口现货头寸(敞口/现货头寸)
  87. // @Produce json
  88. // @Security ApiKeyAuth
  89. // @Param areaUserId query int true "所属机构ID"
  90. // @Success 200 {array} ExposureSpotRsp
  91. // @Failure 500 {object} app.Response
  92. // @Router /Ermcp/QueryExposureSpot [get]
  93. // @Tags 企业风险管理(app)
  94. func QueryExposureSpot(c *gin.Context) {
  95. appG := app.Gin{C: c}
  96. var req ExposureSpotReq
  97. if err := c.ShouldBind(&req); err != nil {
  98. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  99. return
  100. }
  101. var m = models.AreaSpotModel{AREAUSERID: req.AreaUserID}
  102. if d, err := m.GetData(); err == nil {
  103. appG.Response(http.StatusOK, e.SUCCESS, d)
  104. } else {
  105. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  106. }
  107. }
  108. ////////////////////////////////////////////
  109. // 敞口/现货头寸/现货明细请求
  110. type ExposureSpotDetailReq struct {
  111. AreaUserID int `form:"areaUserId" binding:"required"` //所属机构ID
  112. WrstandardId int32 `form:"wrstandardId" binding:"required"` // 现货商品ID
  113. }
  114. // 敞口/现货头寸/现货明细应答
  115. type ExposureSpotDetailRsp models.ErmcpAreaSpotDetailModel
  116. // @Summary 查询敞口现货头寸明细(敞口/现货头寸/现货明细)
  117. // @Produce json
  118. // @Security ApiKeyAuth
  119. // @Param areaUserId query int true "所属机构ID"
  120. // @Param wrstandardId query int true "现货品种ID"
  121. // @Success 200 {array} ExposureSpotDetailRsp
  122. // @Failure 500 {object} app.Response
  123. // @Router /Ermcp/QueryExposureSpotDetail [get]
  124. // @Tags 企业风险管理(app)
  125. func QueryExposureSpotDetail(c *gin.Context) {
  126. appG := app.GinUtils{Gin: app.Gin{C: c}}
  127. var req ExposureSpotDetailReq
  128. appG.DoBindReq(&req)
  129. m := models.ErmcpAreaSpotDetailModel{UserId: req.AreaUserID, WrstandardId: req.WrstandardId}
  130. // m必须传指针类型,否则无法进行类型转换
  131. appG.DoGetData(&m)
  132. }
  133. ///////////////////////////////////////////
  134. // 敞口/历史敞口请求
  135. type HisExposureReq struct {
  136. AreaUserID int32 `form:"userid" binding:"required"` //所属机构ID
  137. LastNum int32 `form:"lastNum" binding:"required"` //查询最近多少条记录
  138. }
  139. // 敞口/历史敞口应答
  140. type HisExposureRsp models.ErmcpHisExposureS
  141. // QueryUserInfo 查询历史敞口
  142. // @Summary 查询历史敞口(菜单:敞口/历史敞口)
  143. // @Produce json
  144. // @Security ApiKeyAuth
  145. // @Param userid query int true "用户id"
  146. // @Param lastNum query int true "每个品种记录数"
  147. // @Success 200 {array} HisExposureRsp
  148. // @Failure 500 {object} app.Response
  149. // @Router /Ermcp/QueryHisExposure [get]
  150. // @Tags 企业风险管理(app)
  151. func QueryHisExposure(c *gin.Context) {
  152. appG := app.Gin{C: c}
  153. var req HisExposureReq
  154. if err := c.ShouldBind(&req); err != nil {
  155. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  156. return
  157. }
  158. var m = models.ErmcpHisExposure{AREAUSERID: req.AreaUserID, LastNum: req.LastNum}
  159. if d, err := m.GetData(); err == nil {
  160. appG.Response(http.StatusOK, e.SUCCESS, d)
  161. } else {
  162. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  163. }
  164. }
  165. // 实时敞口/期货明细 请求
  166. type RealtimeExposurePositionReq struct {
  167. AreaUserId int32 `form:"userid" json:"areaUserId"` // 所属机构ID
  168. MiddleGoodsId int32 `form:"middleGoodsId" json:"middlegoodsid"` // 套保商品
  169. }
  170. // 实时敞口/期货明细 应答
  171. type RealtimeExposurePositionRsp models.ErmcpExposurePostion
  172. // @Summary 查询实时敞口期货头寸明细(菜单:实时敞口/期货明细)
  173. // @Produce json
  174. // @Security ApiKeyAuth
  175. // @Param userid query int true "用户id"
  176. // @Param middleGoodsId query int true "套保商品ID"
  177. // @Success 200 {array} RealtimeExposurePositionRsp
  178. // @Failure 500 {object} app.Response
  179. // @Router /Ermcp/QueryRealtimeExposurePosition [get]
  180. // @Tags 企业风险管理(app)
  181. func QueryRealtimeExposurePosition(c *gin.Context) {
  182. appG := app.GinUtils{Gin: app.Gin{C: c}}
  183. var req RealtimeExposurePositionReq
  184. appG.DoBindReq(&req)
  185. m := models.ErmcpExposurePostion{AREAUSERID: req.AreaUserId, MIDDLEGOODSID: req.MiddleGoodsId}
  186. appG.DoGetDataEx(&m)
  187. }
  188. // 敞口/期货头寸 请求
  189. type ExposureHedgePositionReq struct {
  190. AreaUserId int32 `form:"userid" json:"areaUserId"` // 用户ID
  191. }
  192. // 敞口/期货头寸 应答
  193. type ExposureHedgePositionRsp models.ErmcpHedgePosition
  194. // @Summary 查询敞口期货头寸(菜单:敞口/期货头寸)
  195. // @Produce json
  196. // @Security ApiKeyAuth
  197. // @Param userid query int true "用户id"
  198. // @Success 200 {array} ExposureHedgePositionRsp
  199. // @Failure 500 {object} app.Response
  200. // @Router /Ermcp/QueryExposureHedgePosition [get]
  201. // @Tags 企业风险管理(app)
  202. func QueryExposureHedgePosition(c *gin.Context) {
  203. appG := app.Gin{C: c}
  204. var req ExposureHedgePositionReq
  205. if err := c.ShouldBind(&req); err != nil {
  206. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  207. return
  208. }
  209. var m = models.ErmcpHedgePosition{RELATEDUSERID: req.AreaUserId}
  210. if d, err := m.GetData(); err == nil {
  211. appG.Response(http.StatusOK, e.SUCCESS, d)
  212. } else {
  213. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  214. }
  215. }
  216. // 期货明细请求
  217. type ExposureHedgePosDetailReq struct {
  218. AreaUserId int32 `form:"userid" json:"areaUserId"` // 所属机构ID
  219. GoodsId int32 `form:"goodsId" json:"goodsId"` // 套保商品
  220. }
  221. // 期货明细应答
  222. type ExposureHedgePosDetailRsp models.ErmcpHedgePositionDetail
  223. // QueryExposureHedgePositionDetail 查询敞口期货头寸期货明细
  224. // @Summary 查询敞口期货头寸期货明细(菜单:敞口/期货头寸/期货明细)
  225. // @Produce json
  226. // @Security ApiKeyAuth
  227. // @Param userid query int true "所属机构ID"
  228. // @Param goodsId query int true "商品id"
  229. // @Success 200 {array} ExposureHedgePosDetailRsp
  230. // @Failure 500 {object} app.Response
  231. // @Router /Ermcp/QueryExposureHedgePositionDetail [get]
  232. // @Tags 企业风险管理(app)
  233. func QueryExposureHedgePositionDetail(c *gin.Context) {
  234. appG := app.GinUtils{Gin: app.Gin{C: c}}
  235. var req ExposureHedgePosDetailReq
  236. appG.DoBindReq(&req)
  237. m := models.ErmcpHedgePositionDetail{AREAUSERID: req.AreaUserId, HEDGEGOODSID: req.GoodsId}
  238. appG.DoGetDataEx(&m)
  239. }