package com.jiayue.ipfcst.common.data.entity;

import com.jiayue.ipfcst.common.data.abst.AbstractBaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.core.annotation.Order;

import javax.persistence.*;

/**
 * 通道断开日志
 *
 * @author xsl
 * @version 3.0
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
public class ChannelDisconLog extends AbstractBaseEntity {
    private static final long serialVersionUID = 1L;

    @Id
    @Order(1)
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "myid")
    @GenericGenerator(name = "myid", strategy = "com.jiayue.ipfcst.common.data.entity.id.CustomIDGenerator")
    private Integer id;

    /**
     * 通道ID
     */
    @Column
    private String channelId;

    /**
     * 通道名称
     */
    @Column
    private String channelName;

    /**
     * 断开时间
     */
    @Column
    private Long disconnectTime;

    /**
     * 重连时间
     */
    @Column
    private Long reconnectTime;

    /**
     * 时长
     */
    @Column
    private String duration;


    /**
     * 计算并配置持续时间
     */
    public void countAndSetDuration(){
        if(this.reconnectTime==null || this.disconnectTime==null || this.reconnectTime <= this.disconnectTime){
            return;
        }
        Long durationL = this.reconnectTime-this.disconnectTime;
        if (durationL/1000>=60){
            setDuration(durationL/(1000*60)+"分");
        }
        else{
           setDuration(durationL/1000+"秒");
        }
    }
}
