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

import cn.estsh.i3plus.ext.mes.pojo.util.MesExtEnumUtil;
import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
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 org.springframework.util.StringUtils;

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

/**
 * @author yinxiao
 * @date 2023-2023/2/6 11:20
 * @Description
 */
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "MES_ASSIST_OUT_AND_ENTER", indexes = {
        @Index(columnList = "SYSTEM_SYNC_STATUS"),
        @Index(columnList = "WORK_CENTER_CODE"),
        @Index(columnList = "ASSIST_OUT_AND_ENTER_DETAIL"),
        @Index(columnList = "START_TIME"),
        @Index(columnList = "END_TIME"),
        @Index(columnList = "INFLUENCE_DATE"),
        @Index(columnList = "LIABILITY_ATTRIBUTION")
})
@Api("援入援出明细记录")
public class MesAssistOutAndEnter extends BaseBean implements Serializable {

    private static final long serialVersionUID = 2336733528794801640L;

    @Column(name = "SYSTEM_SYNC_STATUS")
    @ColumnDefault("2")
    @ApiParam(value = "系统同步标志")
    public Integer systemSyncStatus = 2;

    @Column(name = "WORK_CENTER_CODE")
    @ApiParam("生产线代码")
    private String workCenterCode;

    @Column(name = "WORK_CENTER_NAME")
    @ApiParam("生产线名称")
    private String workCenterName;

    @Column(name = "ASSIST_OUT_AND_ENTER_DETAIL")
    @ApiParam("援入援出明细项")
    @AnnoOutputColumn(refClass = MesExtEnumUtil.ASSIST_OUT_AND_ENTER_DETAIL.class)
    private Integer assistOutAndEnterDetail;

    @Column(name = "OWNER_DEPARTMENT")
    @ApiParam(value = "责任部门")
    private String ownerDepartment;

    @Column(name = "WORK_CONTENT")
    @ApiParam("工作内容")
    private String workContent;

    @Column(name = "START_TIME")
    @ApiParam("开始时间(年月日 时分秒)")
    private String startTime;

    @Column(name = "END_TIME")
    @ApiParam("结束时间(年月日 时分秒)")
    private String endTime;

    @Column(name = "INFLUENCE_NUMBER")
    @ApiParam("影响人数")
    private Integer influenceNumber;

    @Column(
            name = "INTERVAL_TIME",
            columnDefinition = "decimal(18,8)"
    )
    @ColumnDefault("0")
    @ApiParam("间隔时间(分钟)")
    private Double intervalTime;

    @Column(
            name = "INFLUENCE_TIME",
            columnDefinition = "decimal(18,8)"
    )
    @ColumnDefault("0")
    @ApiParam("影响时间(分钟)，影响人数*（结束时间-开始时间）")
    private Double influenceTime;

    @Column(name = "INFLUENCE_DATE")
    @ApiParam("影响日期（年月日）")
    private String influenceDate;

    @Column(name = "COOPERATION", columnDefinition = "TEXT")
    @ApiParam("外协（备注）")
    private String cooperation;

    @Column(name = "PERSONNEL_COST")
    @ApiParam("人件费")
    private String personnelCost;

    @Column(
            name = "AMOUNT",
            columnDefinition = "decimal(18,8)"
    )
    @ColumnDefault("0")
    @ApiParam("金额（影响时间*生产线的人件费）")
    private Double amount;

    @Column(name = "CONFIRM_USER")
    @ApiParam("确认人")
    private String confirmUser;

    @Column(name = "CONFIRM_DATE_TIME")
    @ApiParam("确认时间")
    private String confirmDatetime;

    @Column(name = "CATEGORY_CODE")
    @ApiParam("产品别")
    private String categoryCode;

    @Column(name = "CAREER_CODE")
    @ApiParam("事业别")
    private String careerCode;

    @Column(name = "ASSIST_WORK_CENTER_CODE")
    @ApiParam("援入生产线代码")
    private String assistWorkCenterCode;

    @Column(name = "ASSIST_WORK_CENTER_NAME")
    @ApiParam("援入生产线名称")
    private String assistWorkCenterName;
    //----------------bu3 start-----------------------

    @Column(name = "TAKE_ON",columnDefinition="TEXT")
    @ApiParam("担当登录名")
    private String takeOn;

    @Column(name = "TAKE_ON_USER_NAME",columnDefinition="TEXT")
    @ApiParam("担当用户名")
    private String takeOnUserName;

    @Column(name = "TAKE_ON_CONFIRM",columnDefinition="TEXT")
    @ApiParam("担当确认")
    private String takeOnConfirm;

    @Column(name = "TAKE_ON_CONFIRM_TIME")
    @ApiParam("担当确认时间")
    private String takeOnConfirmTime;

    @Column(name = "PERSON_RESPONSIBLE",columnDefinition="TEXT")
    @ApiParam("责任人登录名")
    private String personResponsible;

    @Column(name = "PERSON_RESPONSIBLE_USER_NAME",columnDefinition="TEXT")
    @ApiParam("责任人用户名")
    private String personResponsibleUserName;

    @Column(name = "PERSON_RESPONSIBLE_CONFIRM",columnDefinition="TEXT")
    @ApiParam("责任人确认")
    private String personResponsibleConfirm;

    @Column(name = "PERSON_RESPONSIBLE_CONFIRM_TIME")
    @ApiParam("责任人确认时间")
    private String personResponsibleConfirmTime;

    @Column(name = "RESPONSIBLE_MINISTER",columnDefinition="TEXT")
    @ApiParam("责任部长登录名")
    private String responsibleMinister;

    @Column(name = "RESPONSIBLE_MINISTER_USER_NAME",columnDefinition="TEXT")
    @ApiParam("责任部长用户名")
    private String responsibleMinisterUserName;

    @Column(name = "RESPONSIBLE_MINISTER_CONFIRM",columnDefinition="TEXT")
    @ApiParam("责任部长确认")
    private String responsibleMinisterConfirm;

    @Column(name = "RESPONSIBLE_MINISTER_CONFIRM_TIME")
    @ApiParam("责任部长确认时间")
    private String responsibleMinisterConfirmTime;

    @Column(name = "LIABILITY_ATTRIBUTION")
    @ApiParam("责任归属")
    @AnnoOutputColumn(refClass = MesExtEnumUtil.LIABILITY_ATTRIBUTION.class, refForeignKey = "value", value = "description")
    private Integer liabilityAttribution;
    //----------------bu3 end-----------------------

    @Transient
    @ApiParam("影响日期（年月日）开始")
    private String influenceDateStart;

    @Transient
    @ApiParam("影响日期（年月日）结束")
    private String influenceDateEnd;

    @Transient
    @ApiParam("援入援出明细项描述")
    private String assistOutAndEnterDetailDesc;

    @Transient
    @ApiParam("责任归属Str")
    private String liabilityAttributionStr;

    public String getAssistOutAndEnterDetailDesc() {
        if (StringUtils.isEmpty(this.assistOutAndEnterDetail)) {
            return assistOutAndEnterDetailDesc;
        }
        return MesExtEnumUtil.ASSIST_OUT_AND_ENTER_DETAIL.valueOfDescription(this.assistOutAndEnterDetail);
    }
}
