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

package models

import (
	"fmt"
	"mtp2_if/db"
	"mtp2_if/logger"
)

// 现货商品表
type ErmcpWrstandard struct {
	WRSTANDARDID    int64  `json:"wrstandardid"  xorm:"'WRSTANDARDID'"`       //现货商品ID(SEQ_WRSTANDARD)
	WRSTANDARDCODE  string `json:"wrstandardcode"  xorm:"'WRSTANDARDCODE'"`   //现货商品代码
	DELIVERYGOODSID int32  `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'"` //品种ID
	UNITID          int32  `json:"unitid"  xorm:"'UNITID'"`                   //单位ID
	MINIVALUE       int32  `json:"minivalue"  xorm:"'MINIVALUE'"`             //最小变动值
	MINIVALUEDP     int32  `json:"minivaluedp"  xorm:"'MINIVALUEDP'"`         //最小变动值小数位
	REALMINIVALUE   int32  `json:"realminivalue"  xorm:"'REALMINIVALUE'"`     //实际最小变动值
	REALMINIVALUEDP int32  `json:"realminivaluedp"  xorm:"'REALMINIVALUEDP'"` //实际最小变动值小数位
	CREATORID       int64  `json:"creatorid"  xorm:"'CREATORID'"`             //创建人
	CREATETIME      string `json:"createtime"  xorm:"'CREATETIME'"`           //创建时间
	WRSTANDARDNAME  string `json:"wrstandardname"  xorm:"'WRSTANDARDNAME'"`   //现货商品名称
	AREAUSERID      int    `json:"areauserid"  xorm:"'AREAUSERID'"`           //所属机构
	EnumdicName     string `json:"enumdicname"`                               //单位名称
}

// 查询现货商品
func (r *ErmcpWrstandard) GetData() ([]ErmcpWrstandard, error) {
	str := "select WRSTANDARDID," +
		"       WRSTANDARDCODE," +
		"       DELIVERYGOODSID," +
		"       UNITID," +
		"       MINIVALUE," +
		"       MINIVALUEDP," +
		"       REALMINIVALUE," +
		"       REALMINIVALUEDP," +
		"       CREATORID," +
		"       CREATETIME," +
		"       WRSTANDARDNAME," +
		"       AREAUSERID" +
		"  from wrstandard t" +
		" where t.isvalid = 1 and t.AREAUSERID=%v"

	sqlId := fmt.Sprintf(str, r.AREAUSERID)
	sData := make([]ErmcpWrstandard, 0)
	e := db.GetEngine()
	if err := e.SQL(sqlId).Find(&sData); err != nil {
		logger.GetLogger().Errorf("query wrstardard fail, %v", err)
		return sData, err
	}
	return sData, nil
}
