package cn.estsh.i3plus.pojo.mes.bean;

import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * @Description:
 * @Reference:
 * @Author: Crish
 * @CreateDate:2019-04-16-17:36
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "MES_DEFECT_RECORD", indexes = {
        @Index(columnList = "SERIAL_NUMBER"),
        @Index(columnList = "CREATE_DATE_TIME")
})
@Api("不良信息记录表")
public class MesDefectRecord extends BaseBean implements Serializable {
    private static final long serialVersionUID = -6672562641463628050L;

    @Column(name = "SERIAL_NUMBER")
    @ApiParam("产品条码")
    private String serialNumber;

    @Column(name = "WORK_ORDER_NO")
    @ApiParam("生产工单号")
    private String workOrderNo;

    @Column(name = "PART_NO")
    @ApiParam("物料号")
    private String partNo;

    @Column(name = "PART_NAME")
    @ApiParam("物料名称")
    private String partName;

    @Column(name = "DEFECT_CODE")
    @ApiParam("缺陷代码")
    private String defectCode;

    @Column(name = "DEFECT_NAME")
    @ApiParam("缺陷名称")
    private String defectName;

    @Column(name = "DEFECT_LOCATION")
    @ApiParam("缺陷位置")
    private String defectLocation;

    @Column(name = "SIDE_LOCATION")
    @ApiParam("面位")
    private String sideLocation;

    @Column(name = "REPAIR_STATUS")
    @ApiParam("维修状态")
    private Integer repairStatus;

    @Column(name = "WORK_CENTER_CODE")
    @ApiParam("工作中心代码")
    private String workCenterCode;

    @Column(name = "WORK_CELL_CODE")
    @ApiParam("工作单元代码")
    private String workCellCode;

    @Column(name = "MEMO")
    @ApiParam("备注")
    private String memo;

    @Column(name = "DEFECT_ACTION_TYPE")
    @ApiParam("不良处理类型")
    private String defectActionType;

    @Column(name = "QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam("数量")
    private Double qty;

    @Transient
    private List<MesDefect> mesDefectList;

    @Transient
    @ApiParam("后移数量")
    private Integer backwardNum;

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

    @Transient
    @ApiParam("缺陷类型名称")
    private String defectActionTypeName;

    @Transient
    @ApiParam("缺陷数量")
    private Integer defectQty;

    @ApiParam("维修状态名称")
    private String repairStatusName;

    public int getRepairStatusVal() {
        return this.repairStatus == null ? 0 : this.repairStatus;
    }

    public MesDefectRecord() {

    }

    public MesDefectRecord(String partNo, String partName, String workOrderNo, String defectActionType,
                           String defectCode, String defectName, Integer defectQty) {
        this.partNo = partNo;
        this.partName = partName;
        this.workOrderNo = workOrderNo;
        this.defectActionType = defectActionType;
        this.defectCode = defectCode;
        this.defectName = defectName;
        this.defectQty = defectQty;
    }

    public MesDefectRecord(String partNo, String workOrderNo, String partName, String workCenterCode,
                           String workCellCode, String serialNumber, String modifyUser, String modifyDatetime) {
        this.partNo = partNo;
        this.workOrderNo = workOrderNo;
        this.partName = partName;
        this.workCenterCode = workCenterCode;
        this.workCellCode = workCellCode;
        this.serialNumber = serialNumber;
        this.modifyUser = modifyUser;
        this.modifyDatetime = modifyDatetime;
    }
}
