package cn.estsh.i3plus.ext.mes.pcn.pojo.context;

import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesProduceSn;
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCell;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import java.io.Serializable;

/**
 * 生产过程上下文对象-零件条码(非排序进料零件条码/排序工单号)
 */
@Data
public class MesProductionPsInContext implements Serializable {

    private static final long serialVersionUID = 4337949265011880288L;

    @ApiParam(name = "数据关联键  排序:生产工单号  非排序:snowflakeId")
    private Integer foreignKey;

    @ApiParam("组织代码")
    private String organizeCode;

    @ApiParam("零件条码ID")
    private Long id;

    @ApiParam("未知条码ID/队列ID")
    private Long relateId;

    @ApiParam("工单号")
    private String workOrderNo;

    @ApiParam("零件条码")
    private String productSn;

    @ApiParam("过程条码")
    private String serialNumber;

    @ApiParam("客户条码")
    private String custSn;

    @ApiParam("条码质量状态")
    private Integer qcStatus;

    @ApiParam("零件条码状态【用于发送设备加工参数】")
    private Integer snStatus;

    @ApiParam("打印状态")
    private Integer printStatus;

    @ApiParam("零件号")
    private String partNo;

    @ApiParam("零件名称")
    private String partName;

    @ApiParam("流程代码")
    private String routeCode;

    @ApiParam("工序代码")
    private String processCode;

    @ApiParam(value ="工艺代码")
    private String craftCode;

    @ApiParam("生产线代码")
    private String workCenterCode;

    @ApiParam("工位代码")
    private String workCellCode;

    @ApiParam("工艺强过码")
    private String craftJumpCode;

    @ApiParam("信息来源")
    private Integer messageSource;

    //默认否
    @ApiParam("是否空腔")
    private Integer isFinishCode = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();

    //默认否
    @ApiParam(name = "是否前道工艺防错")
    private Integer isCheckCraft = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();

    //默认未验证
    @ApiParam(name = "前道工艺防错结果")
    private Integer checkCraftResult = MesPcnExtConstWords.ZERO;

    //默认否
    @ApiParam("业务验证之后需要清除的数据标志")
    private Integer busiCheckToDelete = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();

    @ApiParam("裁片方案代码")
    private String cutCode;

    public MesProductionPsInContext() {}

    public MesProductionPsInContext(String organizeCode, String productSn) {
        this.organizeCode = organizeCode;
        this.productSn = productSn;
    }

    public MesProductionPsInContext(MesProduceSn produceSn) {
        BeanUtils.copyProperties(produceSn, this);
        if (!StringUtils.isEmpty(this.productSn)) this.productSn = this.productSn.toUpperCase();
        if (!StringUtils.isEmpty(this.custSn)) this.custSn = this.custSn.toUpperCase();
        if (!StringUtils.isEmpty(this.workOrderNo)) this.workOrderNo = this.workOrderNo.toUpperCase();
        if (!StringUtils.isEmpty(this.partNo)) this.partNo = this.partNo.toUpperCase();
    }

    public MesProductionPsInContext foreignKey(Integer foreignKey) {
        this.foreignKey = foreignKey;
        return this;
    }

    public MesProductionPsInContext isCheck(MesWorkCell workCell) {
        if(!StringUtils.isEmpty(workCell.getIsCheckCraft()) && workCell.getIsCheckCraft().compareTo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) == 0) this.isCheckCraft = workCell.getIsCheckCraft();
        return this;
    }

    public MesProductionPsInContext checkCraftResult(Integer checkCraftResult) {
        this.checkCraftResult = checkCraftResult;
        return this;
    }

    public MesProductionPsInContext isFinishCode() {
        this.isFinishCode = CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue();
        return this;
    }

    public MesProductionPsInContext relateId(Long relateId) {
        if (!StringUtils.isEmpty(relateId)) this.relateId = relateId;
        return this;
    }

    public MesProductionPsInContext messageSource(Integer messageSource) {
        this.messageSource = messageSource;
        return this;
    }

    public MesProductionPsInContext busiCheckToDelete() {
        this.busiCheckToDelete = CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue();
        return this;
    }

    public MesProductionPsInContext cutCode(String cutCode) {
        this.cutCode = cutCode;
        return this;
    }

}
