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

import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @Description : 作业记录表
 * @Reference :
 * @Author : hansen.ke
 * @CreateDate : 2018-11-23 11:10
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "WMS_ACTION_LOG")
@Api(value = "作业记录表")
public class WmsActionLog extends BaseBean {

    private static final long serialVersionUID = 8664373854844368861L;
    @Column(name = "TASK_NO")
    @ApiParam(value = "作业任务编号", example = "1")
    @JsonSerialize(using = ToStringSerializer.class)
    public String taskNo;

    @Column(name = "TRANS_TYPE_CODE")
    @ApiParam(value = "交易类型编号")
    public String transTypeCode;

    @Transient
    @Column(name = "MOVE_NO")
    @ApiParam(value = "移动单单号")
    public String moveNo;

    @Column(name = "AG_ID")
    @ApiParam(value = "作业流程编号", example = "1")
    @JsonSerialize(using = ToStringSerializer.class)
    public Long agId;

    //get单独处理
    public long getAgIdVal() {
        return agId == null ? 0 : agId.longValue();
    }

    @Column(name = "AL_NAME_RDD")
    @ApiParam(value = "流程名称")
    public String agNameRdd;

    @Column(name = "ACTION_USER_NAME")
    @ApiParam(value = "作业人员")
    public String actionUserName;

    @Column(name = "FIX_NO")
    @ApiParam(value = "设备编号")
    public String fixNo;

    @Column(name = "START_TIME")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiParam(value = "开始作业时间")
    public String startTime;

    @Column(name = "END_TIME")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiParam(value = "结束作业时间")
    public String endTime;

    @Transient
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiParam(value = "开始作业时间查询用，查询起始日期", example = "2018-01-01 01:00:00")
    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-01-01 01:00:00")
    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;

    // 状态:1=创建,10=处理中,20=已完成
    @Column(name = "ACTION_STATUS")
    @ApiParam(value = "作业状态", example = "1")
    public Integer actionStatus;

    @Column(name = "TOTAL_STEP")
    @ApiParam(value = "总步数", example = "1")
    public Integer totalStep;

    @Column(name = "CURRENT_STEP")
    @ApiParam(value = "当前步骤", example = "1")
    public Integer currentStep;

    @Column(name = "INIT_AM_ID")
    @ApiParam(value = "初始化组件编号", example = "0")
    public Long initAmId;

    @Column(name = "DETAILS_AM_ID")
    @ApiParam(value = "明细处理组件编号", example = "0")
    public Long detailsAmId;

    @Column(name = "END_AM_ID")
    @ApiParam(value = "结束组件编号", example = "0")
    public Long endAmId;

    @Column(name = "DURATION")
    @ApiParam(value = "执行耗时，单位：毫秒", example = "0")
    public Integer duration = 0;

    public Long getInitAmId() {
        if (initAmId != null) {
            return initAmId.longValue();
        } else {
            return initAmId;
        }
    }

    public Long getDetailsAmId() {
        if (detailsAmId != null) {
            return detailsAmId.longValue();
        } else {
            return detailsAmId;
        }
    }

    public Long getEndAmId() {
        if (endAmId != null) {
            return endAmId.longValue();
        } else {
            return endAmId;
        }
    }
}
