/**
* @Author: zou.yingbin
* @Create  : 2021/1/13 11:15
* @Modify  : 2021/1/13 11:15
 */

package ermcp

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

//查询现货商品请求
type QryWrStandardReq struct {
	UserId int    `form:"userid" binding:"required"` //用户ID
	Status *int32 `form:"status" binding:"required"` //状态
}

//查询现货商品响应
type QryWrStandardRsp models.ErmcpWrstandard

// QueryWrStandard  企业风险管理查询现货商品
func QueryWrStandard(c *gin.Context) {
	appG := app.Gin{C: c}
	var req QryWrStandardReq
	if err := c.ShouldBind(&req); err != nil {
		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
		return
	}
	m := models.ErmcpWrstandard{AREAUSERID: req.UserId, ISVALID: *req.Status}
	if d, err := m.GetData(); err == nil {
		for i := range d {
			d[i].EnumdicName = mtpcache.GetEnumDicitemName(d[i].UNITID)
		}
		appG.Response(http.StatusOK, e.SUCCESS, d)
	} else {
		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
	}
}

///////////////////////////////

//查询现货商品请求
type QryWrStandardDetailReq struct {
	UserId       int `form:"userid" binding:"required"` // 用户ID
	Wrstandardid int `form:"wrstandardid"`              // 现货商品ID
	Goods        int `form:"goods"`                     // 是否查关联交易商品 1-查询
}

//查询现货商品响应
type QryWrStandardDetailRsp models.ErmcpWrstandDetail

// QueryWrStandardDetail 查询现货商品详情(菜单:现货品种/现货品种详情)
func QueryWrStandardDetail(c *gin.Context) {
	appG := app.Gin{C: c}
	var req QryWrStandardDetailReq
	if err := c.ShouldBind(&req); err != nil {
		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
		return
	}
	m := models.ErmcpWrstandDetail{Wrd: models.ErmcpWrstandard{AREAUSERID: req.UserId,
		WRSTANDARDID: int64(req.Wrstandardid)}, QueryGoods: req.Goods == 1}
	if d, err := m.GetData(); err == nil {
		appG.Response(http.StatusOK, e.SUCCESS, d)
	} else {
		//appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
		appG.Response(http.StatusOK, e.SUCCESS, nil)
	}
}
