/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package vip.xiaonuo.biz.modular.depotWork.param;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import vip.xiaonuo.biz.core.Const.BizStr;
import vip.xiaonuo.biz.modular.depotSampling.entity.DepotSampling;
import vip.xiaonuo.biz.modular.depotTruckBook.entity.DepotTruckBook;
import vip.xiaonuo.biz.modular.depotTruckWeighDouble.entity.DepotTruckWeighDouble;
import vip.xiaonuo.common.util.BigDecimalUtil;

import javax.validation.constraints.NotBlank;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 出入库管理表添加参数
 *
 * @author xiang
 * @date  2023/09/18 10:20
 **/
@Getter
@Setter
public class DepotWorkAddParam {

    /** 项目编码 */
    @ApiModelProperty(value = "项目编码", required = true, position = 2)
    @NotBlank(message = "depotId不能为空")
    private String depotId;

    /** 车辆预约ID */
    @ApiModelProperty(value = "车辆预约ID", position = 3)
    private String truckBookId;

    /** 还款单号 */
    @ApiModelProperty(value = "还款单号", position = 3)
    private String repayOrderNo;

    /** 放款状态:待放款/已放款/放款中 */
    @ApiModelProperty(value = "放款状态", position = 3)
    private String loanState;

    /** 出入库 */
    @ApiModelProperty(value = "出入库", required = true, position = 4)
    @NotBlank(message = "depotBizType不能为空")
    private String depotBizType;

    /** 粮食种类 */
    @ApiModelProperty(value = "粮食种类", position = 5)
    private String grainGroup;

    /** 粮食类型 */
    @ApiModelProperty(value = "粮食类型", position = 5)
    private String grainType;

    /** 单据分类:系统自动/人工补单 */
    @ApiModelProperty(value = "单据分类:系统自动/人工补单", position = 5)
    private String billGroup;

    /** 负责人身份证号 */
    @ApiModelProperty(value = "负责人身份证号", position = 5)
    private String keeperCitizenId;

    /** 入库数量（吨） */
    @ApiModelProperty(value = "数量（吨）", position = 6)
    private BigDecimal depotTonCount;

    /** 入库价格 */
    @ApiModelProperty(value = "入库价格", position = 7)
    private BigDecimal depotPrice;

    /** 总价 */
    @ApiModelProperty(value = "总价", position = 8)
    private BigDecimal orderAmount;

    /** 干粮数量（吨） */
    @ApiModelProperty(value = "干粮数量（吨）", position = 6)
    private BigDecimal dryTonCount;

    /** 干粮价格（元/吨） */
    @ApiModelProperty(value = "干粮价格（元/吨）", position = 7)
    private BigDecimal dryPrice;

    /** 质量 */
    @ApiModelProperty(value = "质量", position = 9)
    private String depotQuality;

    /** 车牌 */
    @ApiModelProperty(value = "车牌", position = 10)
    private String licensePlate;

    /** 车次编码：yyyymmdd**** */
    @ApiModelProperty(value = "车次编码：yyyymmdd****", position = 11)
    private String carNumber;

    /** 过毛时间 */
    @ApiModelProperty(value = "过毛时间", position = 12)
    private Date grossTime;

    /** 过皮时间 */
    @ApiModelProperty(value = "过皮时间", position = 13)
    private Date tareTime;

    /** 毛重(公斤) */
    @ApiModelProperty(value = "毛重(公斤)", position = 15)
    private BigDecimal grossWeight;

    /** 皮重(公斤) */
    @ApiModelProperty(value = "皮重(公斤)", position = 16)
    private BigDecimal tareWeight;

    /** 净重(公斤) */
    @ApiModelProperty(value = "净重(公斤)", position = 17)
    private BigDecimal netWeight;

    /** 潮干比 */
    @ApiModelProperty(value = "潮干比", position = 18)
    private BigDecimal dampRatio;

    /** 干粮水份(%) */
    @ApiModelProperty(value = "干粮水份(%)", position = 18)
    private BigDecimal canonRatio;

    public DepotWorkAddParam() {
    }

    //入库
    public DepotWorkAddParam(DepotTruckBook book, DepotTruckWeighDouble weighDouble, DepotSampling sampling) {
        this.depotId = book.getDepotId();
        this.truckBookId = book.getTruckBookId();
        this.loanState = BizStr.STATE_LOAN_GRANT_N;
        this.depotBizType = book.getDepotBizType();
        this.keeperCitizenId = book.getKeeperCitizenId();
        this.depotTonCount = weighDouble.getNetWeight().movePointLeft(3);
        this.depotPrice = book.getSamplingPrice();
        this.grainGroup = book.getGrainGroup();
        this.grainType = book.getGrainType();
        this.billGroup = weighDouble.getBillGroup();
        this.licensePlate = book.getLicensePlate();
        this.depotQuality = String.format("水份(%s):%s;容重:%s;不完善率:%s;霉变:%s;杂质:%s;", "%"
                , sampling.getSamplingShuiFen() == null ? BigDecimal.ZERO : sampling.getSamplingShuiFen()
                , sampling.getSamplingRongZhong() == null ? " " : sampling.getSamplingRongZhong()
                , sampling.getSamplingQueShao() == null ? " " : sampling.getSamplingQueShao()
                , sampling.getSamplingMeiBian() == null ? " " : sampling.getSamplingMeiBian()
                , sampling.getSamplingZaZhi() == null ? " " : sampling.getSamplingZaZhi());
        this.carNumber = weighDouble.getCarNumber();
        this.grossTime = weighDouble.getGrossTime();
        this.tareTime = weighDouble.getTareTime();
        this.grossWeight = weighDouble.getGrossWeight();
        this.tareWeight = weighDouble.getTareWeight();
        this.netWeight = weighDouble.getNetWeight();
    }

    //出库
    public DepotWorkAddParam(DepotTruckBook book, BigDecimal depotPrice, DepotTruckWeighDouble weighDouble) {
        this.depotId = book.getDepotId();
        this.truckBookId = book.getTruckBookId();
        this.repayOrderNo = book.getRepayOrderNo();
        this.loanState = BizStr.STATE_LOAN_GRANT_N;
        this.depotBizType = book.getDepotBizType();
        this.keeperCitizenId = book.getKeeperCitizenId();
        this.depotTonCount = weighDouble.getNetWeight().movePointLeft(3);
        this.grainGroup = book.getGrainGroup();
        this.billGroup = weighDouble.getBillGroup();
        this.depotPrice = depotPrice;
        this.orderAmount = BigDecimalUtil.multiplyVal(depotPrice, this.depotTonCount).setScale(2);
        this.licensePlate = book.getLicensePlate();
        this.grainType = "干粮";
        this.carNumber = weighDouble.getCarNumber();
        this.grossTime = weighDouble.getGrossTime();
        this.tareTime = weighDouble.getTareTime();
        this.grossWeight = weighDouble.getGrossWeight();
        this.tareWeight = weighDouble.getTareWeight();
        this.netWeight = weighDouble.getNetWeight();
    }

}
