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 io.swagger.annotations.ApiParam;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.io.Serializable;

/**
 * 生产过程上下文对象-装配件清单信息
 */
@Data
public class MesProductionAssemblyContext implements Serializable {

    private static final long serialVersionUID = 2382117884422723639L;

    @ApiParam("生产工单号")
    public String workOrderNo;

    @ApiParam("装配件零件编码")
    public String assemblyPartNo;

    @ApiParam("装配件零件名称")
    public String assemblyPartName;

    @ApiParam("装配件条码")
    public String assemblySn;

    @ApiParam("生产工单零件号")
    public String partNo;

    @ApiParam("生产工单零件名称")
    public String partName;

    @ApiParam("装配零件状态")
    public Integer assemblyStatus;

    @ApiParam("是否跳过")
    public Integer isSkip = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();

    @ApiParam("装配件条码确认方式")
    public Integer matchType;

    @ApiParam("扫描规则")
    public String matchRule;

    @ApiParam("不可用规则")
    public String prodRuleIgnoreCfg;

    @ApiParam("自制件ID")
    public Long productSnId;

    @ApiParam("数据来源")
    public Integer dataSource;

    @ApiParam("来源ID")
    public Long sourceId;

    @ApiParam(value = "排序/非排序产品加工规则ID")
    public Long pid;

    @ApiParam("最小值")
    public Double minValue;

    @ApiParam("最大值")
    public Double maxValue;

    @ApiParam(value = "装备序号")
    public Integer routeSeq;

    @ApiParam(value = "装配爆炸图FID")
    public Long imageFileId;

    @ApiParam(value = "音频文件")
    public Long audioFileId;

    @ApiParam(value = "装配爆炸图URL")
    public String imageFileUrl;

    @ApiParam(value = "音频文件URL")
    public String audioFileUrl;

    @ApiParam(value = "装配爆炸图URL")
    public Integer fileIsFinished = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();

    @ApiParam("前道工艺代码")
    public String preCraftCode;

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

    @ApiParam("区域代码")
    public String areaCode;

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

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

    @ApiParam("设备代码")
    public String equipmentCode;

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

    @ApiParam("工序名称")
    public String processName;

    @ApiParam("工艺代码")
    public String craftCode;

    @ApiParam("工艺名称")
    public String craftName;

    @ApiParam(name = "数据关联键")
    public Integer foreignKey;

    @ApiParam(value = "是否可复用条码")
    public Integer isRepeat = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();

    @ApiParam(value = "是否可复用条码是否写入上下文进行复用")
    public Integer isRepeat2Cache = CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue();

    @ApiParam("匹配时间")
    public String matchDatetime;

    @ApiParam(value = "工序用量")
    public Double qty;

    @ApiParam("容器匹配信息")
    public String containerSnData;

    @ApiParam("是否已经验证过原料调配")
    public String isCheckedRawMix;

    public String repeatKeyToString() {
        if (StringUtils.isEmpty(this.equipmentCode) || StringUtils.isEmpty(this.matchType) || (StringUtils.isEmpty(this.matchRule) && StringUtils.isEmpty(this.assemblyPartNo))) return null;
        return String.format("%s:%s&%s:%s&%s:%s&%s:%s",
                MesPcnExtConstWords.EQUIPMENT_CODE, this.equipmentCode.toUpperCase(),
                MesPcnExtConstWords.MATCH_TYPE, this.matchType,
                MesPcnExtConstWords.MATCH_RULE, StringUtils.isEmpty(this.matchRule) ? MesPcnExtConstWords.EMPTY : this.matchRule,
                MesPcnExtConstWords.ASSEMBLY_PART_NO, StringUtils.isEmpty(this.assemblyPartNo) ? MesPcnExtConstWords.EMPTY : this.assemblyPartNo.toUpperCase());
    }

}
