package com.uas.platform.b2b.manage.model;

import com.uas.platform.b2b.manage.core.util.StringUtils;

import javax.persistence.*;
import java.util.Date;

/**
 * @Author: huj
 * @Date: Created in 16:04 2018/11/27.
 */
@Table(name = "listen$erp", indexes = {@Index(name = "unique_mac_address",
        columnList = "mac_address", unique = true)})
@Entity
public class Listen {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @Column(name = "mac_address")
    private String macAddress;

    @Column(name = "name", length = 2000)
    private String name;

    @Column(name = "date")
    private Date date;

    @Column(name = "description")
    private String description;

    @Transient
    String status;

    public String getDescription() {
        return StringUtils.isEmpty(description) ? "" : description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getMacAddress() {
        return macAddress;
    }

    public void setMacAddress(String macAddress) {
        this.macAddress = macAddress;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getStatus() {
        Date now = new Date();
        int minutes = (int) ((now.getTime() - getDate().getTime()) / (1000 * 60));
        if (minutes > 20) {
            return status = "异常";
        } else {
            return status = "正常";
        }
    }

    public void setStatus(String status) {
        this.status = status;
    }
}
