qryExposure.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. // QueryRealtimeExposure 查询实时敞口
  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. // QueryExposureDetail 查询敞口现货明细
  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. // ExposureSpotRsp 敞口/现货头寸应答
  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. // QueryHisExposure 查询历史敞口
  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. // RealtimeExposurePositionReq 实时敞口/期货明细 请求
  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. // QueryRealtimeExposurePosition
  174. // @Summary 查询实时敞口期货头寸明细(菜单:实时敞口/期货明细)
  175. // @Produce json
  176. // @Security ApiKeyAuth
  177. // @Param userid query int true "用户id"
  178. // @Param middleGoodsId query int true "套保商品ID"
  179. // @Success 200 {array} RealtimeExposurePositionRsp
  180. // @Failure 500 {object} app.Response
  181. // @Router /Ermcp/QueryRealtimeExposurePosition [get]
  182. // @Tags 企业风险管理(app)
  183. func QueryRealtimeExposurePosition(c *gin.Context) {
  184. appG := app.GinUtils{Gin: app.Gin{C: c}}
  185. var req RealtimeExposurePositionReq
  186. appG.DoBindReq(&req)
  187. m := models.ErmcpExposurePostion{AREAUSERID: req.AreaUserId, MIDDLEGOODSID: req.MiddleGoodsId}
  188. appG.DoGetDataEx(&m)
  189. }
  190. // 敞口/期货头寸 请求
  191. type ExposureHedgePositionReq struct {
  192. AreaUserId int64 `form:"userid" json:"areaUserId"` // 用户ID
  193. }
  194. // 敞口/期货头寸 应答
  195. type ExposureHedgePositionRsp models.ErmcpHedgePosition
  196. // QueryExposureHedgePosition
  197. // @Summary 查询敞口期货头寸(菜单:敞口/期货头寸)
  198. // @Produce json
  199. // @Security ApiKeyAuth
  200. // @Param userid query int true "用户id"
  201. // @Success 200 {array} ExposureHedgePositionRsp
  202. // @Failure 500 {object} app.Response
  203. // @Router /Ermcp/QueryExposureHedgePosition [get]
  204. // @Tags 企业风险管理(app)
  205. func QueryExposureHedgePosition(c *gin.Context) {
  206. appG := app.Gin{C: c}
  207. var req ExposureHedgePositionReq
  208. if err := c.ShouldBind(&req); err != nil {
  209. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  210. return
  211. }
  212. if mtpcache.IsAreaUserId(req.AreaUserId) {
  213. var m = models.ErmcpHedgePosition{RELATEDUSERID: req.AreaUserId}
  214. if d, err := m.GetData(); err == nil {
  215. appG.Response(http.StatusOK, e.SUCCESS, d)
  216. } else {
  217. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  218. }
  219. } else {
  220. var m = models.ErmcpTradePosition{USERID: req.AreaUserId}
  221. if d, err := m.GetData(); err == nil {
  222. sData := make([]models.ErmcpHedgePosition, 0)
  223. for _, v := range d {
  224. hedgePos := models.ErmcpHedgePosition{
  225. RELATEDUSERID: v.USERID,
  226. YDBUYPOSITION: int32(v.BUYPOSITIONQTY),
  227. CURBUYPOSITION: int32(v.BUYCURPOSITIONQTY),
  228. YDSELLPOSITION: int32(v.SELLPOSITIONQTY),
  229. CURSELLPOSITION: int32(v.SELLCURPOSITIONQTY),
  230. HEDGEGOODSID: v.GOODSID,
  231. GOODSID: v.GOODSID,
  232. GOODSCODE: v.GOODSCODE,
  233. GOODSNAME: v.GOODSNAME,
  234. }
  235. hedgePos.Calc()
  236. sData = append(sData, hedgePos)
  237. }
  238. appG.Response(http.StatusOK, e.SUCCESS, sData)
  239. } else {
  240. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  241. }
  242. }
  243. }
  244. // 期货明细请求
  245. type ExposureHedgePosDetailReq struct {
  246. AreaUserId int32 `form:"userid" json:"areaUserId"` // 所属机构ID
  247. GoodsId int32 `form:"goodsId" json:"goodsId"` // 套保商品
  248. }
  249. // ExposureHedgePosDetailRsp 期货明细应答
  250. type ExposureHedgePosDetailRsp models.ErmcpHedgePositionDetail
  251. // QueryExposureHedgePositionDetail 查询敞口期货头寸期货明细
  252. // @Summary 查询敞口期货头寸期货明细(菜单:敞口/期货头寸/期货明细)
  253. // @Produce json
  254. // @Security ApiKeyAuth
  255. // @Param userid query int true "所属机构ID"
  256. // @Param goodsId query int true "商品id"
  257. // @Success 200 {array} ExposureHedgePosDetailRsp
  258. // @Failure 500 {object} app.Response
  259. // @Router /Ermcp/QueryExposureHedgePositionDetail [get]
  260. // @Tags 企业风险管理(app)
  261. func QueryExposureHedgePositionDetail(c *gin.Context) {
  262. appG := app.GinUtils{Gin: app.Gin{C: c}}
  263. var req ExposureHedgePosDetailReq
  264. appG.DoBindReq(&req)
  265. m := models.ErmcpHedgePositionDetail{AREAUSERID: req.AreaUserId, HEDGEGOODSID: req.GoodsId}
  266. appG.DoGetDataEx(&m)
  267. }
  268. // QueryExposureGoods
  269. // @Summary 查询敞口主力合约
  270. // @Produce json
  271. // @Security ApiKeyAuth
  272. // @Param middlegoodsid query int true "套保商品id"
  273. // @Success 200 {array} models.ErmcpMiddlegoodsRelateGoods
  274. // @Failure 500 {object} app.Response
  275. // @Router /Ermcp/QueryExposureGoods [get]
  276. // @Tags 企业风险管理(app)
  277. func QueryExposureGoods(c *gin.Context) {
  278. a := app.GinUtils{Gin: app.Gin{C: c}}
  279. req := struct {
  280. MIDDLEGOODSID int32 `form:"middlegoodsid" binding:"required"` // 用户id
  281. }{}
  282. a.DoBindReq(&req)
  283. m := models.ErmcpMiddlegoodsRelateGoods{MIDDLEGOODSID: req.MIDDLEGOODSID}
  284. a.DoGetDataI(&m)
  285. }