package com.jay.monitor.data.server.report.alert.rule.config;

import com.jay.monitor.data.server.enums.MatchRuleEnums;
import com.jay.monitor.data.server.report.alert.rule.MatchValueCondition;
import org.springframework.stereotype.Component;

/**
 * 小于比较器
 *
 * @author liukaixiong
 * @Email liukx@elab-plus.com
 * @date 2021/9/6 - 15:12
 */
@Component
public class LTValueCondition implements MatchValueCondition {

    @Override
    public MatchRuleEnums matchRule() {
        return MatchRuleEnums.lt;
    }

    @Override
    public boolean match(Object value, String matchValue) {
        long left = 0L;
        long right = 0L;
        if (!(value instanceof Long)) {
            try {
                // 如果转换不成数字的直接返回false
                left = Long.parseLong(value.toString());
                right = Long.parseLong(matchValue);
            } catch (Exception e) {
                return false;
            }
        }
        if (left < right) {
            return true;
        }
        return false;
    }
}
