package com.sw.mes.yb.accessory.entity;

import com.sw.mes.base.factory.init.entity.Equipment;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 辅料更换记录
 */
@Data
@Entity
@Table(name = "zhxx_accessory_order")
@DynamicUpdate
@DynamicInsert
public class AccessoryOrder {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 辅料信息
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "org_id", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private AccessoryMaterial org;

    /**
     * 辅料信息
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "target_id", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private AccessoryMaterial target;

    /**
     * 设备
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "equipment_id", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private Equipment equipment;

    /**
     * 设备编号
     */
    @Column(length = 40)
    private String deviceNo;

    /**
     * 下料使用时间
     */
    @Column(length = 18)
    private Double useTime;

    /**
     * 更换后使用时间
     */
    @Column(length = 18)
    private Double targetUseTime;

    /**
     * 更换人
     */
    @Column(length = 50)
    private String createUser;

    /**
     * 更换前-物料编号
     */
    @Column
    private String orgGoodsCode;

    /**
     * 更换后-物料编号
     */
    @Column(length = 50)
    private String targetGoodsCode;

    /**
     * 更换前-厂家
     */
    @Column
    private String orgFactory;

    /**
     * 更换后-厂家
     */
    @Column(length = 50)
    private String targetFactory;

    @Column
    private Integer createUserId;

    /**
     * 更换原因
     */
    @Lob
    private String remark;

    /**
     * 更换时间
     */
    @Column(length = 19)
    @Temporal(TemporalType.TIMESTAMP)
    private Date createDate;

    /**
     * 备注
     */
    @Column
    private String anomalousCause;

    /**
     * 申请人
     */
    @Column(length = 40)
    private String applyUser;

    /**
     * 申请时间
     */
    @Column(length = 19)
    @Temporal(TemporalType.TIMESTAMP)
    private Date applyDate;

    /**
     * 更换数量
     * 默认1
     */
    @Column
    private Integer changeCount;

    /**
     * 库位ID
     */
    @Column
    private Integer locationId;

    /**
     * 库位名称
     */
    @Column(length = 80)
    private String locationName;

    /**
     * 损坏责任人
     */
    @Column(length = 80)
    private String brokeUser;

    /**
     * 更换前-损耗率
     */
    @Column
    private BigDecimal orgAttritionRate;

    /**
     * 班次
     */
    @Column
    private String userClassNo;

    /**
     * 班组
     */
    @Column
    private String userTeamGroup;

    /**
     * 更换前批次号
     */
    @Column
    private String orgBatchNo;

    /**
     * 更换后批次号
     */
    @Column
    private String targetBatchNo;

    /**
     * 更换前刻码
     */
    @Column
    private String orgEngraving;

    /**
     * 更换前碳毡
     */
    @Column
    private String orgCarbonFelt;

    /**
     * 更换后刻码
     */
    @Column
    private String targetEngraving;

    /**
     * 更换后碳毡
     */
    @Column
    private String targetCarbonFelt;
}
