qryErmcp.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. }
  53. // 查询合同应答
  54. type QryErmcpRsp models.ErmcpModel
  55. // QueryContract 企业风险管理合同查询
  56. // @Summary 查询合同(采购和销售)
  57. // @Produce json
  58. // @Security ApiKeyAuth
  59. // @Param userId query int true "用户ID"
  60. // @Param contracttype query int true "合同类型 1-采购, -1-销售"
  61. // @Param querytype query int true "查询类型 1-全部 2-待点价 3-履约结算"
  62. // @Success 200 {array} QryErmcpRsp
  63. // @Failure 500 {object} app.Response
  64. // @Router /Ermcp/QueryContract [get]
  65. // @Tags 企业风险管理(app)
  66. func QueryContract(c *gin.Context) {
  67. appG := app.Gin{C: c}
  68. var req QryErmcpReq
  69. if err := c.ShouldBind(&req); err != nil {
  70. logger.GetLogger().Errorf("parse query req: %v", err)
  71. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  72. return
  73. }
  74. // 参数检查
  75. if req.ContractType != 1 && req.ContractType != -1 {
  76. logger.GetLogger().Errorf("ContractType should in(1, -1)")
  77. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  78. return
  79. }
  80. if req.QueryType != 0 && req.QueryType != 1 && req.QueryType != 2 {
  81. logger.GetLogger().Errorf("QueryType should in(0, 1, 2)")
  82. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  83. return
  84. }
  85. var m = models.ErmcpModel{UserID: req.UserId}
  86. if d, err := m.GetData(req.ContractType, req.QueryType); err == nil {
  87. appG.Response(http.StatusOK, e.SUCCESS, d)
  88. } else {
  89. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  90. }
  91. }