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

import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.WmsEnumUtil;
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 : jimmy.zeng
 * @CreateDate : 2018-11-01 11:57
 * @Modify:
 **/
@Data
@Entity
@Table(name = "WMS_TRANS_TYPE")
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Api(value = "交易类型表", description = "交易类型表")
public class WmsTransType extends BaseBean {

    private static final long serialVersionUID = -4309264918740295355L;
    @Column(name = "TRANS_TYPE_CODE")
    @ApiParam(value = "类型编号")
    private String transTypeCode;

    @Column(name = "TRANS_TYPE_NAME")
    @ApiParam(value = "类型名称")
    private String transTypeName;

    @Column(name = "SEQ")
    @ApiParam(value = "序号")
    private Integer seq;

    @Column(name = "AG_ID")
    @ApiParam(value = "作业流程")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long agId;

    @Transient
    @ApiParam("中文流程名称")
    private String agNameC;

    @Column(name = "TRANS_TYPE_DESC")
    @ApiParam(value = "类型说明")
    private String transTypeDesc;

    @Column(name = "TM_ID")
    @ApiParam(value = "交易处理组件")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long tmId;

    @Column(name = "PDA_ICON")
    @ApiParam(value = "PDA图标")
    private String pdaIcon;

    @Column(name = "IS_SEND_ERROR_EMAIL", columnDefinition = "int default 2")
    @ApiParam(value = "是否发送异常邮件")
    private Integer isSendErrorEmail;

    @Column(name = "ORDER_BACK_TYPE")
    @ApiParam(value = "单据回退类型")
    @AnnoOutputColumn(refClass = WmsEnumUtil.ORDER_BACK_TYPE.class, refForeignKey = "value", value = "description")
    private Integer orderBackType;

    @Column(name = "TM_NAME")
    @ApiParam(value = "交易处理组件名称")
    private String tmName;

    @Column(name = "DIRECT")
    @ApiParam(value = "交易的方向：IN,OUT,MOVE")
    private String direct;

    @Transient
    @ApiParam("菜单URL")
    private String menuUrl;

    @Transient
    @ApiParam("交易处理组件调用类")
    private String callClass;

    public String getMenuUrl() {
        return "/handle?transTypeCode=" + this.transTypeCode;
    }

    public long getTmIdVal() {
        return this.tmId == null ? 0 : this.tmId;
    }

    public WmsTransType(String transTypeCode) {
        this.transTypeCode = transTypeCode;
    }

    public WmsTransType() {

    }

    public WmsTransType(String transTypeCode, String transTypeName) {
        this.transTypeCode = transTypeCode;
        this.transTypeName = transTypeName;
    }
}
