package com.gyee.alarm.model.vo;

import com.gyee.common.model.PointData;
import lombok.Data;

@Data
public class AlarmTag {

    /**
     * 表名
     */
    private String id;

    /**
     * 时间戳
     */
    private Long ts;

    /**
     * 当前值
     */
    private Double val;

    /**
     * 报警类别，0触发，1触发，-1变化触发，大于等于3ai点触发
     */
    private Integer triggerType=0;

    /**
     * 测点
     */
    private String tagId;

    /**
     * 过去值
     */
    private Double oval=0.0;

    /**
     * 报警级别
     */
    private Integer rank;

    /**
     * 更新并检测是否触发报警
     */
    public Boolean updateAndCheck(PointData pointData) {

        if (pointData.getPointValueInDouble() == oval) {
            return false;
        }
        ts = pointData.getPointTime();
        oval = pointData.getPointValueInDouble();


        if(triggerType==-1)
        {
            val=1.0;
        }else  if(triggerType==0)
        {
            if (oval == 0)
            {
                val=1.0;
            }else
            {
                val=0.0;
                return false;
            }
        }else  if(triggerType==1)
        {
            if (oval == 1)
            {
                val=1.0;
            }else
            {
                val=0.0;
                return false;
            }
        }else {
            if (oval.intValue() == triggerType) {
                val=1.0;
            } else if (oval == 0) {
                val=0.0;
                return false;
            }
        }

        return true;
    }
}
