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

import java.io.Serializable;

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 com.casic.missiles.modular.system.dto.BusConfigDTO;
import lombok.Data;

/**
 * <p>
 * 设备配置表
 * </p>
 *
 * @author stylefeng123
 * @since 2019-05-16
 */
@TableName("bus_config")
@Data
public class BusConfig extends Model<BusConfig> {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @TableId(value = "ID", type = IdType.AUTO)
    private Long id;
    /**
     * 设备主键
     */
    @TableField("DEVICE_ID")
    private Long deviceId;
    /**
     * 配置信息
     */
    @TableField("FRAMECONTENT")
    private String framecontent;
    /**
     * 传感器设备编号
     */
    @TableField("SENSORID")
    private String sensorid;
    /**
     * 传感器编号
     */
    @TableField("SENSORCODE")
    private String sensorcode;
    /**
     * 状态（0:下发中，1：已下发）
     */
    @TableField("STATUS")
    private String status;
    /**
     * 最大尝试次数
     */
    @TableField("ATTEMPTSMAX")
    private Integer attemptsmax;
    /**
     * 当前尝试次数
     */
    @TableField("ATTEMPTSCURRENT")
    private Integer attemptscurrent;
    /**
     * 下发时间
     */
    @TableField("SENDTIME")
    private Date sendtime;
    /**
     * 界面配置时间
     */
    @TableField("WRITETIME")
    private Date writetime;


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

    @Override
    public String toString() {
        return "BusConfig{" +
                "id=" + id +
                ", deviceId=" + deviceId +
                ", framecontent=" + framecontent +
                ", sensorid=" + sensorid +
                ", sensorcode=" + sensorcode +
                ", status=" + status +
                ", attemptsmax=" + attemptsmax +
                ", attemptscurrent=" + attemptscurrent +
                ", sendtime=" + sendtime +
                ", writetime=" + writetime +
                "}";
    }

    public BusConfig() {
    }

    public BusConfig(BusConfigDTO busConfigDTO) {
        this.deviceId = Long.valueOf(busConfigDTO.getDeviceId());
        this.framecontent = busConfigDTO.getThreshold() + "," + busConfigDTO.getInstallHeight() + ","
                + busConfigDTO.getRetryTimes() + "," + busConfigDTO.getPercent() + "," + busConfigDTO.getIp() + ","
                + busConfigDTO.getPort();
        this.status = "0";
        this.attemptsmax = Integer.valueOf(busConfigDTO.getAttemptsMax());
        this.writetime = new Date();
    }
}
