package com.casic.missiles.modular.system.model;

import java.io.Serializable;

import com.baomidou.mybatisplus.annotations.TableLogic;
import com.baomidou.mybatisplus.enums.IdType;

import java.util.Date;

import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableName;
import lombok.Data;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Pattern;

/**
 * <p>
 * 设备表
 * </p>
 *
 * @author lwh123
 * @since 2019-05-23
 */
@TableName("bus_device")
@Data
public class Device extends Model<Device> {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @TableId(value = "ID", type = IdType.ID_WORKER)
    private Long id;
    /**
     * 设备编号
     */
    @Pattern(regexp = "[A-Za-z0-9]{7,20}",message = "设备编号必须为7-20位字母或数字组合")
    @TableField("DEVCODE")
    private String devcode;
    /**
     * 设备名称
     */
    @TableField("DEVICE_NAME")
    private String deviceName;
    /**
     * 在线状态
     */
    @TableField("ONLINE_STATE")
    private String onlineState;
    /**
     * 设备类型
     */
    @TableField("DEVICE_TYPE")
    private Long deviceType;

    /**
     * 是否有效
     */
    @TableLogic
    @TableField("VALID")
    private String valid;
    /**
     * 安装时间
     */
    @TableField("INSTALL_DATE")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date installDate;
    /**
     * 最新状态时间
     */
    @TableField("LOGTIME")
    private Date logtime;
    /**
     * 设备型号（关联型号表）
     */
    @TableField("VERSION")
    private Long modelId;

    @TableField(exist = false)
    private String modelName;
    @TableField(exist = false)
    private String deviceTypeName;
    @TableField(exist = false)
    private String wellCode;
    @TableField(exist = false)
    private String concenCode;//集中器编号
    @TableField(exist = false)
    private Long wellId;//闸井ID
    @TableField(exist = false)
    private Long concenId;//集中器ID
    @TableField(exist = false)
    private String installDateFmt;

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    @Override
    public String toString() {
        return "Device{" +
                "id=" + id +
                ", devcode=" + devcode +
                ", deviceName=" + deviceName +
                ", onlineState=" + onlineState +
                ", deviceType=" + deviceType +
                ", valid=" + valid +
                ", installDate=" + installDate +
                ", logtime=" + logtime +
                "}";
    }
}
