package com.zg.project.wisdom.domain;

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

import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.zg.framework.aspectj.lang.annotation.Excel;
import com.zg.framework.web.domain.BaseEntity;

/**
 * 供应计划对象 gys_jh
 *
 * 说明：
 * - jhQty    ：计划交货数量
 * - realQty  ：累计已入库数量（落库）
 * - waitQty  ：待入库数量 = jhQty - realQty（仅用于反显，不落库）
 *
 * @author zg
 * @date 2025-05-28
 */
public class GysJh extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 主键ID */
    private Long id;

    /** 行号 */
    @Excel(name = "行号")
    private String xh;

    /** 序号 */
    @Excel(name = "序号")
    private Long indexNo;

    /** 县局 */
    @Excel(name = "县局")
    private String xj;

    /** 项目号 */
    @Excel(name = "项目号")
    private String xmNo;

    /** 项目描述 */
    @Excel(name = "项目描述")
    private String xmMs;

    /** 物料号 */
    @Excel(name = "物料号")
    private String wlNo;

    /** 物料描述 */
    @Excel(name = "物料描述")
    private String wlMs;

    /** 供应商编码 */
    @Excel(name = "供应商编码")
    private String gysNo;

    /** 供应商名称 */
    @Excel(name = "供应商名称")
    private String gysMc;

    /** 计划交货金额 */
    @Excel(name = "计划交货金额")
    private BigDecimal jhAmt;

    /** 合同单价 */
    @Excel(name = "合同单价")
    private BigDecimal htDj;

    /** 合同数量 */
    @Excel(name = "合同数量")
    private BigDecimal htQty;

    /** SAP订单编号 */
    @Excel(name = "SAP订单编号")
    private String sapNo;

    /** 计划交货数量 */
    @Excel(name = "计划交货数量")
    private BigDecimal jhQty;

    /** 已入库数量（累计） */
    @Excel(name = "已入库数量")
    private BigDecimal realQty;

    /**
     * 待入库数量（反显字段，不落库）
     *
     * 计算规则：
     * waitQty = jhQty - realQty
     */
    private BigDecimal waitQty;

    /** 计量单位 */
    @Excel(name = "计量单位")
    private String dw;

    /**
     * 状态
     * 0：未到货
     * 1：部分入库
     * 2：已入库
     */
    private String status;

    /** 身份码 */
    @Excel(name = "身份码")
    private String entityId;

    /** 备注 */
    @Excel(name = "备注")
    private String remark;

    /** 是否删除（0正常 1删除） */
    private String isDelete;

    /** 查询开始时间（yyyy-MM-dd HH:mm:ss） */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date beginTime;

    /** 查询结束时间（yyyy-MM-dd HH:mm:ss） */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date endTime;

    // ======================= getter / setter =======================

    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

    public String getXh() { return xh; }
    public void setXh(String xh) { this.xh = xh; }

    public Long getIndexNo() { return indexNo; }
    public void setIndexNo(Long indexNo) { this.indexNo = indexNo; }

    public String getXj() { return xj; }
    public void setXj(String xj) { this.xj = xj; }

    public String getXmNo() { return xmNo; }
    public void setXmNo(String xmNo) { this.xmNo = xmNo; }

    public String getXmMs() { return xmMs; }
    public void setXmMs(String xmMs) { this.xmMs = xmMs; }

    public String getWlNo() { return wlNo; }
    public void setWlNo(String wlNo) { this.wlNo = wlNo; }

    public String getWlMs() { return wlMs; }
    public void setWlMs(String wlMs) { this.wlMs = wlMs; }

    public String getGysNo() { return gysNo; }
    public void setGysNo(String gysNo) { this.gysNo = gysNo; }

    public String getGysMc() { return gysMc; }
    public void setGysMc(String gysMc) { this.gysMc = gysMc; }

    public BigDecimal getJhAmt() { return jhAmt; }
    public void setJhAmt(BigDecimal jhAmt) { this.jhAmt = jhAmt; }

    public BigDecimal getHtDj() { return htDj; }
    public void setHtDj(BigDecimal htDj) { this.htDj = htDj; }

    public BigDecimal getHtQty() { return htQty; }
    public void setHtQty(BigDecimal htQty) { this.htQty = htQty; }

    public String getSapNo() { return sapNo; }
    public void setSapNo(String sapNo) { this.sapNo = sapNo; }

    public BigDecimal getJhQty() { return jhQty; }
    public void setJhQty(BigDecimal jhQty) { this.jhQty = jhQty; }

    public BigDecimal getRealQty() { return realQty; }
    public void setRealQty(BigDecimal realQty) { this.realQty = realQty; }

    /**
     * 待入库数量（不落库，动态计算）
     */
    public BigDecimal getWaitQty() {
        if (jhQty == null) {
            return BigDecimal.ZERO;
        }
        BigDecimal inQty = realQty == null ? BigDecimal.ZERO : realQty;
        return jhQty.subtract(inQty);
    }
    public void setWaitQty(BigDecimal waitQty) {
        this.waitQty = waitQty;
    }

    public String getDw() { return dw; }
    public void setDw(String dw) { this.dw = dw; }

    public String getStatus() { return status; }
    public void setStatus(String status) { this.status = status; }

    public String getEntityId() { return entityId; }
    public void setEntityId(String entityId) { this.entityId = entityId; }

    public String getRemark() { return remark; }
    public void setRemark(String remark) { this.remark = remark; }

    public String getIsDelete() { return isDelete; }
    public void setIsDelete(String isDelete) { this.isDelete = isDelete; }

    public Date getBeginTime() { return beginTime; }
    public void setBeginTime(Date beginTime) { this.beginTime = beginTime; }

    public Date getEndTime() { return endTime; }
    public void setEndTime(Date endTime) { this.endTime = endTime; }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("id", getId())
                .append("indexNo", getIndexNo())
                .append("xj", getXj())
                .append("xmNo", getXmNo())
                .append("xmMs", getXmMs())
                .append("wlNo", getWlNo())
                .append("wlMs", getWlMs())
                .append("gysNo", getGysNo())
                .append("gysMc", getGysMc())
                .append("jhAmt", getJhAmt())
                .append("htDj", getHtDj())
                .append("sapNo", getSapNo())
                .append("xh", getXh())
                .append("jhQty", getJhQty())
                .append("realQty", getRealQty())
                .append("waitQty", getWaitQty())
                .append("htQty", getHtQty())
                .append("dw", getDw())
                .append("status", getStatus())
                .append("entityId", getEntityId())
                .append("remark", getRemark())
                .append("createBy", getCreateBy())
                .append("createTime", getCreateTime())
                .append("updateBy", getUpdateBy())
                .append("updateTime", getUpdateTime())
                .append("isDelete", getIsDelete())
                .toString();
    }
}
