package com.steerinfo.ems.mesemsdieseloil.model;

import com.alibaba.fastjson.JSONObject;
import com.steerinfo.framework.model.IBasePO;
import io.swagger.annotations.ApiModelProperty;

import java.math.BigDecimal;
import java.util.Date;

public class MesEmsDieseloil implements IBasePO<String> {
    /**
     * 主键(ID,VARCHAR,40)
     */
    @ApiModelProperty(value="主键",required=true)
    private String id;

    /**
     * 状态 0已创建 1已读取(STATE,VARCHAR,1)
     */
    @ApiModelProperty(value="状态 0已创建 1已读取",required=false)
    private String state;

    /**
     * 业务时间(BUSINESS_DATE,VARCHAR,20)
     */
    @ApiModelProperty(value="业务时间",required=false)
    private String businessDate;

    /**
     * 物料编码(MATERIALCODE,VARCHAR,30)
     */
    @ApiModelProperty(value="物料编码",required=false)
    private String materialcode;

    /**
     * 物料名称(MATERIALNAME,VARCHAR,50)
     */
    @ApiModelProperty(value="物料名称",required=false)
    private String materialname;

    /**
     * 数量(VOLUME,DECIMAL,0)
     */
    @ApiModelProperty(value="数量",required=false)
    private BigDecimal volume;

    /**
     * 工厂编码(FACTORY_CODE,VARCHAR,30)
     */
    @ApiModelProperty(value="工厂编码",required=false)
    private String factoryCode;

    /**
     * 工厂名称(FACTORY_NAME,VARCHAR,50)
     */
    @ApiModelProperty(value="工厂名称",required=false)
    private String factoryName;

    /**
     * 单位(UNIT,VARCHAR,20)
     */
    @ApiModelProperty(value="单位",required=false)
    private String unit;

    /**
     * 物料型号(MATERIALSPEC,VARCHAR,20)
     */
    @ApiModelProperty(value="物料型号",required=false)
    private String materialspec;

    /**
     * 读取时间(SENDTIME,TIMESTAMP,7)
     */
    @ApiModelProperty(value="读取时间",required=false)
    private Date sendtime;
    
    /**
     * 重量（吨）(WEIGHT,DECIMAL,20)
     */
    @ApiModelProperty(value="重量（吨）",required=false)
    private BigDecimal weight;

    private static final long serialVersionUID = 1L;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id == null ? null : id.trim();
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state == null ? null : state.trim();
    }

    public String getBusinessDate() {
        return businessDate;
    }

    public void setBusinessDate(String businessDate) {
        this.businessDate = businessDate;
    }

    public String getMaterialcode() {
        return materialcode;
    }

    public void setMaterialcode(String materialcode) {
        this.materialcode = materialcode == null ? null : materialcode.trim();
    }

    public String getMaterialname() {
        return materialname;
    }

    public void setMaterialname(String materialname) {
        this.materialname = materialname == null ? null : materialname.trim();
    }

    public String getFactoryCode() {
        return factoryCode;
    }

    public void setFactoryCode(String factoryCode) {
        this.factoryCode = factoryCode == null ? null : factoryCode.trim();
    }

    public String getFactoryName() {
        return factoryName;
    }

    public void setFactoryName(String factoryName) {
        this.factoryName = factoryName == null ? null : factoryName.trim();
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit == null ? null : unit.trim();
    }

    public String getMaterialspec() {
        return materialspec;
    }

    public void setMaterialspec(String materialspec) {
        this.materialspec = materialspec == null ? null : materialspec.trim();
    }

    public Date getSendtime() {
        return sendtime;
    }

    public void setSendtime(Date sendtime) {
        this.sendtime = sendtime;
    }

    public BigDecimal getWeight() {
		return weight;
	}

	public void setWeight(BigDecimal weight) {
		this.weight = weight;
	}

	public BigDecimal getVolume() {
		return volume;
	}

	public void setVolume(BigDecimal volume) {
		this.volume = volume;
	}

	@Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", state=").append(state);
        sb.append(", businessDate=").append(businessDate);
        sb.append(", materialcode=").append(materialcode);
        sb.append(", materialname=").append(materialname);
        sb.append(", volume=").append(volume);
        sb.append(", factoryCode=").append(factoryCode);
        sb.append(", factoryName=").append(factoryName);
        sb.append(", unit=").append(unit);
        sb.append(", materialspec=").append(materialspec);
        sb.append(", sendtime=").append(sendtime);
        sb.append(", weight=").append(weight);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
    
    /**
	 * JSONObject对象转IfMesEmsSwapfile对象
	 * 
	 * @param jo   JSONObject对象
	 * @return
	 */
	public void jsonobjectToMesEmsDieseloil(JSONObject jo){
		try {
            this.id = jo.getString("id");
            this.state = jo.getString("state");
            this.businessDate = jo.getString("businessDate");
            this.materialcode = jo.getString("materialcode");
            this.materialname = jo.getString("materialname");
            this.volume = new BigDecimal(jo.getString("volume"));
            this.factoryCode = jo.getString("factoryCode");
            this.factoryName = jo.getString("factoryName");
            this.unit = jo.getString("meteringName"); // 单位
            this.weight = new BigDecimal(jo.getString("volume")).multiply(new BigDecimal("0.00084"));
            if(jo.getString("materialspec")==null || jo.getString("materialspec").isEmpty()){
            	// 默认值
            	this.materialspec = "0#";
            } else {
            	this.materialspec = jo.getString("materialspec");
            }
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}