package com.sunwin.metro.process;

import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.functions.ProcessFunction;
import org.apache.flink.util.Collector;
import org.apache.flink.util.OutputTag;

/**
 * @program: sunwin_metro
 * @description: 过滤异常仪表号 （DI属性值异常）
 * @author: xuYJ
 * @create: 2021-04-25 15:43
 **/
public class ErrorMetersProcess extends ProcessFunction<Tuple2<String, String>, Tuple2<String, String>> {
    private final OutputTag<Tuple2<String, String>> errorMeter;

    public ErrorMetersProcess(OutputTag<Tuple2<String, String>> errorMeter) {
        this.errorMeter = errorMeter;
    }

    @Override
    public void processElement(Tuple2<String, String> tuple4, Context context, Collector<Tuple2<String, String>> collector) throws Exception {
        try {
            if (tuple4.f1.contains("true")) {
                context.output(errorMeter, tuple4);
            } else {
                String[] s = tuple4.f0.split("_");
                String[] split = s[s.length - 2].split("-");
                collector.collect(new Tuple2<>(split[0],tuple4.f1));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    }
