package com.xydl.cac.comparator;


import com.xydl.cac.exception.BusinessException;

import java.util.Date;
import java.util.LinkedHashMap;

public class MissCompare extends Comparator {

    // 一天触发一次
    boolean done = false;

    @Override
    public boolean compare(Object source, String threshold, Date lastDTime) {
        if (!done && source == null && lastDTime != null) {
            long t2 = Long.parseLong(threshold);
            long last = System.currentTimeMillis() - lastDTime.getTime();
            hours = last / 1000 / 60 / 60;
            if (hours >= t2) {
                done = true;
                return true;
            }
        }
        return false;
    }

    @Override
    public LinkedHashMap<String, String> supportedOperator() {
        LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
        map.put("GTR", "超过规定小时无数据");
        return map;
    }

    @Override
    public void valid(String operator, String threshold) throws Exception {
        Integer hours = Integer.parseInt(threshold);
        if (hours <= 1) {
            throw new BusinessException("阈值必须大于1");
        }
    }

}
