qryErmcp.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/1/6 10:12
  4. * @Modify : 2021/1/6 10:12
  5. */
  6. package ermcp
  7. import (
  8. "github.com/gin-gonic/gin"
  9. "mtp2_if/global/app"
  10. "mtp2_if/global/e"
  11. "mtp2_if/logger"
  12. "mtp2_if/models"
  13. "net/http"
  14. )
  15. // 查询现货合同
  16. type QrySpotContractReq struct {
  17. UserId int64 `form:"userId" binding:"required"` //用户ID
  18. QueryType int32 `form:"QueryType" binding:"required"` // 查询类型 1-未提交 2-待审核 3-履约中 4-已完成
  19. }
  20. // 查询现货合同应答
  21. type QrySpotContractRsp models.ErmcpSpotContractModel
  22. // QuerySpotContract 企业风险管理合同查询
  23. // @Summary 查询现货合同(对应现货合同菜单)
  24. // @Produce json
  25. // @Security ApiKeyAuth
  26. // @Param userId query int true "用户ID"
  27. // @Param QueryType query int true "查询类型 1-未提交 2-待审核 3-履约中 4-已完成"
  28. // @Success 200 {array} QrySpotContractRsp
  29. // @Failure 500 {object} app.Response
  30. // @Router /Ermcp/QuerySpotContract [get]
  31. // @Tags 企业风险管理(app)
  32. func QuerySpotContract(c *gin.Context) {
  33. appG := app.Gin{C: c}
  34. var req QrySpotContractReq
  35. if err := c.ShouldBind(&req); err != nil {
  36. logger.GetLogger().Errorf("parse query req: %v", err)
  37. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  38. return
  39. }
  40. var m = models.ErmcpSpotContractModel{USERID: req.UserId}
  41. if d, err := m.GetData(req.QueryType); 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. type QryErmcpReq struct {
  49. UserId int64 `form:"userId" binding:"required"` //用户ID
  50. ContractType int32 `form:"contracttype" binding:"required"` // 合同类型
  51. QueryType int32 `form:"querytype" binding:"required"` // 查询类型 1-全部 2-待点价 3-履约结算
  52. ContractId string `form:"contractid"` // 合同id(SpotContractId)
  53. }
  54. // 查询合同应答
  55. type QryErmcpRsp models.ErmcpModel
  56. // QueryContract 企业风险管理合同查询
  57. // @Summary 查询合同(采购和销售)
  58. // @Produce json
  59. // @Security ApiKeyAuth
  60. // @Param userId query int true "用户ID"
  61. // @Param contracttype query int true "合同类型 1-采购, -1-销售"
  62. // @Param querytype query int true "查询类型 1-全部 2-待点价 3-履约结算"
  63. // @Param contractid query string false "合同ID(SpotContractId)"
  64. // @Success 200 {array} QryErmcpRsp
  65. // @Failure 500 {object} app.Response
  66. // @Router /Ermcp/QueryContract [get]
  67. // @Tags 企业风险管理(app)
  68. func QueryContract(c *gin.Context) {
  69. appG := app.Gin{C: c}
  70. var req QryErmcpReq
  71. if err := c.ShouldBind(&req); err != nil {
  72. logger.GetLogger().Errorf("parse query req: %v", err)
  73. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  74. return
  75. }
  76. // 参数检查
  77. if req.ContractType != 1 && req.ContractType != -1 {
  78. logger.GetLogger().Errorf("ContractType should in(1, -1)")
  79. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  80. return
  81. }
  82. if req.QueryType != 1 && req.QueryType != 2 && req.QueryType != 3 {
  83. logger.GetLogger().Errorf("QueryType should in(1, 2, 3)")
  84. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  85. return
  86. }
  87. var m = models.ErmcpModel{UserID: req.UserId, SpotContractId: req.ContractId}
  88. if d, err := m.GetData(req.ContractType, req.QueryType); err == nil {
  89. appG.Response(http.StatusOK, e.SUCCESS, d)
  90. } else {
  91. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  92. }
  93. }