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

import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.mes.model.MesButtonFlagModel;
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_WORK_ORDER", indexes = {
        @Index(columnList = "ORDER_NO"),
        @Index(columnList = "AREA_CODE"),
        @Index(columnList = "WORK_CENTER_CODE"),
        @Index(columnList = "WO_STATUS")
}, uniqueConstraints = {
        @UniqueConstraint(columnNames = {"ORGANIZE_CODE", "ORDER_NO", "PART_NO"})
})
@Api("生产工单")
public class MesWorkOrder extends BaseBean implements Serializable {
    private static final long serialVersionUID = -3566003375267865064L;

    @Column(name = "ORDER_NO", nullable = false)
    @ApiParam("工单号")
    private String orderNo;

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

    @Column(name = "PART_NAME_RDD")
    @ApiParam("物料名称")
    private String partNameRdd;

    @Column(name = "PROD_CFG_CODE")
    @ApiParam("产品配置代码")
    private String prodCfgCode;

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

    @Column(name = "COMPLETE_QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam("完成数量")
    private Double completeQty;

    @Column(name = "REPAIR_QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam("返修数量")
    private Double repairQty;

    @Column(name = "SCRAP_QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam("报废数量")
    private Double scrapQty;

    @Column(name = "SEQ", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam("工单序号")
    private Double seq;

    @Column(name = "WO_STATUS")
    @ApiParam("工单状态")
    private Integer workOrderStatus;

    @Column(name = "IS_PULL")
    @ApiParam("是否投料")
    private Integer isPull = 1;

    @Column(name = "WO_TYPE")
    @ApiParam("工单类型")
    private Integer workOrderType;

    @Column(name = "NEXT_ORDER")
    @ApiParam("下一工单")
    private String nextOrder;

    @Column(name = "PLAN_ORDER_NO")
    @ApiParam("生产计划单号")
    private String planOrderNo;

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

    @Column(name = "AREA_CODE")
    @ApiParam("区域代码")
    private String areaCode;

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

    @Column(name = "SCHEDULE_DATE")
    @ApiParam("排产日期")
    private String scheduleDate;

    @Column(name = "CUST_PROD_LINE_CODE")
    @ApiParam("客户产线代码")
    private String custProdLineCode;

    @Column(name = "SHIFT_CODE")
    @ApiParam("班次")
    private String shiftCode;

    @Column(name = "START_TIME")
    @ApiParam("开始时间")
    private String startTime;

    @Column(name = "END_TIME")
    @ApiParam("结束时间")
    private String endTime;

    @Column(name = "WO_SOURCE")
    @ApiParam("工单来源")
    private String workOrderSource;

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

    @Column(name = "SHIFT_GROUP")
    @ApiParam("班组")
    private String shiftGroup;

    @Column(name = "APPROVAL_STATUS")
    @ApiParam("审批状态")
    private Integer approvalStatus;

    @Column(name = "CUST_CODE")
    @ApiParam("客户代码")
    private String custCode;

    @Column(name = "CUST_ORDER_NO")
    @ApiParam("客户订单号")
    private String custOrderNo;

    @Column(name = "FI_QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam("首检数量")
    private Double fiQty;

    @Column(name = "FI_COMPLETE_QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam("首检完成数量")
    private Double fiCompleteQty;

    @Column(name = "FI_GENERATE_QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam("首检生成数量")
    private Double fiGenerateQty;

    @Lob
    @Column(name = "EXTEND")
    @ApiParam("扩展数据")
    public String extend;

    @Column(name = "RESERVED1")
    @ApiParam("预留字段1")
    private String reserved1;

    @Column(name = "RESERVED2")
    @ApiParam("预留字段2")
    private String reserved2;

    @Column(name = "RESERVED3")
    @ApiParam("预留字段3")
    private String reserved3;

    @Column(name = "RESERVED4")
    @ApiParam("预留字段4")
    private String reserved4;

    @Column(name = "PARENT_PART_NO")
    @ApiParam("父阶物料号")
    private String parentPartNo;

    @Column(name = "PRINT_STATUS")
    @ApiParam("打印状态")
    private Integer printStatus;

    @Version
    @Column(name = "LOCK_VERSION")
    @ApiParam(value = "乐观锁", example = "1")
    public Integer lockVersion;

    /**********************  冗余字段 *********************************/
    @Transient
    @ApiParam(value = "工作中心名称")
    public String workCenterName;

    @Transient
    @ApiParam(value = "工作单元名称")
    public String workCellName;

    @Transient
    @ApiParam(value = "客户产线名称")
    public String custProdLineName;

    @Transient
    @ApiParam(value = "班次名称")
    public String shiftName;

    @Transient
    @ApiParam(value = "班组名称")
    public String shiftGroupName;

    @Transient
    @ApiParam(value = "产品配置名称")
    public String prodCfgName;

    @Transient
    @ApiParam("区域代码名称")
    private String areaCodeName;

    @Transient
    @ApiParam("状态-下达，启动，暂停")
    private List<Integer> statusList;

    @Transient
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiParam(value = "计划开始日期查询用，查询开始日期", example = "2018-12-31 23:59:59")
    public String startTimeStart;


    @Transient
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiParam(value = "计划开始日期查询用，查询截至日期", example = "2018-12-31 23:59:59")
    public String startTimeEnd;

    @Transient
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiParam(value = "计划结束日期查询用，查询结束日期起始", example = "2018-12-31 23:59:59")
    public String endTimeStart;

    @Transient
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiParam(value = "计划结束日期查询用，查询结束日期截至", example = "2018-12-31 23:59:59")
    public String endTimeEnd;

    @Transient
    @ApiParam("mes生产工单页面按钮控制")
    private MesButtonFlagModel mesButtonFlagModel;

    @Transient
    @ApiParam(value = "下达按钮编号")
    public String buttonCode;

    @Transient
    @ApiParam("批量打包开窗页面查询工单=1")
    private String pageType;

    @Transient
    @ApiParam("产品批次")
    private String productBatch;

    @Transient
    @ApiParam("工单类型描述")
    private String workOrderTypeDesc;

    @Transient
    @ApiParam("工单状态描述")
    private String workOrderStatusDesc;

    @Transient
    @ApiParam("计划类型")
    private Integer planType;

    @Transient
    @ApiParam(value = "完成按钮编号")
    public String comButtonCode;

    @Transient
    @ApiParam("工单源序号")
    private Double srcSeq;

    @Transient
    @ApiParam("零件号集合")
    private String partNoList;

    @Transient
    @ApiParam("零件名称集合")
    private String partNameList;

    @Transient
    @ApiParam("客户集合")
    private List<String> custList;

    @Transient
    @ApiParam("工位完成数量")
    private Integer stationCompleteQty = 0;

    @Transient
    @ApiParam("客户物料号")
    private String customerPartNo;

    @Transient
    @ApiParam("客户物料名称")
    private String customerPartName;

    @Transient
    @ApiParam("客户物料颜色")
    private String customerPartColor;

    @Transient
    @ApiParam("项目名称")
    private String prodCfgTypeName;

    @Transient
    @ApiParam("颜色代码")
    private String colorCode;

    @Transient
    @ApiParam("挂架数")
    private Integer shelvesAmount;

    @Transient
    @ApiParam("供漆罐代码")
    private String paintTankCode;

    @Transient
    @ApiParam("计划报表标识")
    private String reportFormCode;

    @Transient
    @ApiParam("一检数量")
    private Integer firstInspectionQty;

    @Transient
    @ApiParam("二检数量")
    private Integer secondInspectionQty;

    @Transient
    @ApiParam("子零件")
    private String itemPartNo;

    @Transient
    @ApiParam(value = "子零件数量", example = "0")
    private Double itemQty = 0d;

    @Transient
    @ApiParam(value = "子零件总数", example = "0")
    private Double itemQtyCount = 0d;

    @Transient
    @ApiParam("是否虚拟件")
    private Integer isFictive = 2;

    @Transient
    @ApiParam("行颜色")
    private String rowColor;

    @Transient
    @ApiParam("一检数量")
    private Integer endCheckQty;

    @Transient
    @ApiParam("打包数量")
    private Integer finalInspectionQty;

    @Transient
    @ApiParam("已报工数量")
    private Integer productOffLineQty;

    @Transient
    @ApiParam("生产节拍")
    private Integer takt;

    /**********************  动态冗余字段（界面维护大写） *********************************/

    @Transient
    @ApiParam("基准时间")
    private String standardDate;

    @Transient
    @ApiParam("圈数")
    private Integer rounds;

    @Transient
    @ApiParam("节拍")
    private String chainSpeed;

    @Transient
    @ApiParam("小车号")
    private String smallCarNo;

    @Transient
    @ApiParam("小车数量")
    private String smallCarAmount;

    @Transient
    @ApiParam("标包")
    private String standardPackage;

    @Transient
    @ApiParam("包规代码")
    private String packageGauge;

    @Transient
    @ApiParam("反喷标识")
    private String reverseSprayMark;

    @Transient
    @ApiParam("模具编号集合")
    private String mouldCodeList;




    public double getQtyVal() {
        return this.qty == null ? 0.0d : this.qty;
    }

    public double getCompleteQtyVal() {
        return this.completeQty == null ? 0.0d : this.completeQty;
    }

    public double getRepairQtyVal() {
        return this.repairQty == null ? 0.0d : this.repairQty;
    }

    public double getScrapQtyVal() {
        return this.scrapQty == null ? 0.0d : this.scrapQty;
    }

    public double getSeqVal() {
        return this.seq == null ? 0.0d : this.seq;
    }

    public int getWorkOrderStatusVal() {
        return this.workOrderStatus == null ? 0 : this.workOrderStatus;
    }

    public int getWorkOrderTypeVal() {
        return this.workOrderType == null ? 0 : this.workOrderType;
    }

    public int getApprovalStatusVal() {
        return this.approvalStatus == null ? 0 : this.approvalStatus;
    }

    public MesWorkOrder() {
    }

    public MesWorkOrder(String orderNo, String startTime, String workCenterCode, Double qty,
                        String partNo, String partNameRdd, String itemPartNo, Double itemQty) {
        this.orderNo = orderNo;
        this.startTime = startTime;
        this.workCenterCode = workCenterCode;
        this.qty = qty;
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.itemPartNo = itemPartNo;
        this.itemQty = itemQty;
    }
}
