qryErmcp.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. QueryType int32 `form:"QueryType" binding:"required"` // 查询类型 1-未提交 2-待审核 3-履约中 4-已完成
  18. }
  19. // 查询现货合同应答
  20. type QrySpotContractRsp models.ErmcpSpotContractModel
  21. // QuerySpotContract 企业风险管理合同查询
  22. // @Summary 查询现货合同(对应现货合同菜单)
  23. // @Produce json
  24. // @Security ApiKeyAuth
  25. // @Param QueryType query int true "查询类型 1-未提交 2-待审核 3-履约中 4-已完成"
  26. // @Success 200 {array} QrySpotContractRsp
  27. // @Failure 500 {object} app.Response
  28. // @Router /Ermcp/QuerySpotContract [get]
  29. // @Tags 企业风险管理(app)
  30. func QuerySpotContract(c *gin.Context) {
  31. appG := app.Gin{C: c}
  32. var req QrySpotContractReq
  33. if err := c.ShouldBind(&req); err != nil {
  34. logger.GetLogger().Errorf("parse query req: %v", err)
  35. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  36. return
  37. }
  38. var m models.ErmcpSpotContractModel
  39. if d, err := m.GetData(req.QueryType); err == nil {
  40. appG.Response(http.StatusOK, e.SUCCESS, d)
  41. } else {
  42. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  43. }
  44. }
  45. // 查询合同请求结构
  46. type QryErmcpReq struct {
  47. ContractType int32 `form:"contracttype" binding:"required"` // 合同类型
  48. QueryType int32 `form:"QueryType" binding:"required"` // 查询类型 1-全部 2-待点价 3-履约结算
  49. }
  50. // 查询合同应答
  51. type QryErmcpRsp models.ErmcpModel
  52. // QueryContract 企业风险管理合同查询
  53. // @Summary 查询合同(采购和销售)
  54. // @Produce json
  55. // @Security ApiKeyAuth
  56. // @Param contracttype query int true "合同类型 1-采购, -1-销售"
  57. // @Param QueryType query int true "查询类型 1-全部 2-待点价 3-履约结算"
  58. // @Success 200 {array} QryErmcpRsp
  59. // @Failure 500 {object} app.Response
  60. // @Router /Ermcp/QueryContract [get]
  61. // @Tags 企业风险管理(app)
  62. func QueryContract(c *gin.Context) {
  63. appG := app.Gin{C: c}
  64. var req QryErmcpReq
  65. if err := c.ShouldBind(&req); err != nil {
  66. logger.GetLogger().Errorf("parse query req: %v", err)
  67. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  68. return
  69. }
  70. // 参数检查
  71. if req.ContractType != 1 && req.ContractType != -1 {
  72. logger.GetLogger().Errorf("ContractType should in(1, -1)")
  73. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  74. return
  75. }
  76. if req.QueryType != 0 && req.QueryType != 1 && req.QueryType != 2 {
  77. logger.GetLogger().Errorf("QueryType should in(0, 1, 2)")
  78. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  79. return
  80. }
  81. var m models.ErmcpModel
  82. if d, err := m.GetData(req.ContractType, req.QueryType); err == nil {
  83. appG.Response(http.StatusOK, e.SUCCESS, d)
  84. } else {
  85. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  86. }
  87. }