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

import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.AndonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
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;
import java.io.Serializable;

/**
 * @Description : ANDON_PLC控制
 * @Reference :
 * @Author : hansen.ke
 * @CreateDate : 2019-05-10 17:32
 * @Modify:
 **/
@Data
@Entity
@Table(name="ANDON_PLC")
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Api("安灯PLC控制")
public class AndonPLC extends BaseBean implements Serializable {

    private static final long serialVersionUID = -611094238158756163L;

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

    @Column(name = "WORK_CELL_CODE")
    @ApiParam(value = "工位代码")
    private String workCellCode;

    @Column(name = "NODE_CODE")
    @ApiParam(value = "控制节点编码")
    private String nodeCode;

    @Column(name = "NODE_IP")
    @ApiParam(value = "IP地址")
    private String nodeIP;

    @Column(name = "CHANNEL")
    @ApiParam("通道")
    private String channel;

    @Column(name = "DEVICE")
    @ApiParam("终端")
    private String device;

    @Column(name = "OPC_URL")
    @ApiParam("OPCUA路径")
    private String opcUrl;

    @Column(name = "NAME_SPACE_INDEX")
    @ApiParam("空间索引")
    private Integer nameSpaceIndex = 2;

    @Column(name = "CHANNEL_NAME")
    @ApiParam(value = "通道名称")
    private String channelName;

    @Column(name = "TAG_NAME")
    @ApiParam(value = "标签名字")
    private String tagName;

    @Column(name = "TAG_ADDRESS")
    @ApiParam(value = "标签地址")
    private String tagAddress;

    @Column(name = "TAG_TYPE")
    @ApiParam(value = "标签类型")
    private String tagType;

    @Column(name = "DATA_TYPE")
    @ApiParam("标签数据类型")
    private String dataType;

    @Column(name = "GROUP_NO")
    @ApiParam(value = "分组号")
    private String groupNo;

    @AnnoOutputColumn(refClass = AndonEnumUtil.ALARM_TYPE.class,refForeignKey = "value",value = "description")
    @Column(name = "ALARM_CODE")
    @ApiParam(value = "安灯类型")
    private String alarmCode;

    @AnnoOutputColumn(refClass = AndonEnumUtil.ALARM_BUSI_FLAG.class,refForeignKey = "value",value = "description")
    @Column(name = "TAG_BUSINESS_TYPE")
    @ApiParam(value = "标签业务类型")
    private String tagBusinessType;

    @AnnoOutputColumn(refClass = AndonEnumUtil.IS_ALARM_STATUS.class,refForeignKey = "value",value = "description")
    @Column(name = "IS_ALARM_STATUS")
    @ApiParam(value = "是否安灯")
    private Integer isAlarmStatus;

    @Transient
    @ApiParam(value = "安灯类型名称")
    private String alarmCodeName;

    @Transient
    @ApiParam(value = "生产线名称")
    private String workCenterName;

    @Transient
    @ApiParam(value = "标签业务类型名称")
    private String tagBusinessTypeName;

    @Transient
    @ApiParam(value = "是否安灯名称")
    private String isAlarmStatusName;

    public int getIsAlarmStatusVal(){
        if(isAlarmStatus == null){
            return 0;
        }
        return isAlarmStatus.intValue();
    }
}
