/**
* @Author: zou.yingbin
* @Create  : 2021/1/7 17:58
* @Modify  : 2021/1/7 17:58
 */

package ermcp

import (
	"github.com/gin-gonic/gin"
	"mtp2_if/global/app"
	"mtp2_if/global/e"
	"mtp2_if/logger"
	"mtp2_if/models"
	"net/http"
)

// 查套保计划请求
type QryHedgePlanReq struct {
	UserId          int64  `form:"userId" binding:"required"`          //用户ID
	HedgePlanStatus string `form:"HedgePlanStatus" binding:"required"` // 套保计划状态(允许多个，逗号隔开)
}

// 查套保计划应答
type QryHedgePlanRsp models.ErmcpHedgePlan

// QueryHedgePlan 查询套保计划
func QueryHedgePlan(c *gin.Context) {
	appG := app.Gin{C: c}
	req := QryHedgePlanReq{}
	if err := c.ShouldBind(&req); err != nil {
		logger.GetLogger().Errorf("query hedgeplanReq,%v", err)
		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
		return
	}

	var m = models.ErmcpHedgePlan{Areauserid: req.UserId}
	if d, err := m.GetData(req.HedgePlanStatus); err == nil {
		appG.Response(http.StatusOK, e.SUCCESS, d)
	} else {
		logger.GetLogger().Errorf("query fail, %v", err)
		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
	}
}
