qryExposure.go 9.5 KB

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