package com.elab.core.kafka.monitor;

import com.alibaba.fastjson.JSON;
import com.elab.log.model.CatCrossIdModel;
import com.jay.monitor.data.client.ext.MonitorRuleCallback;
import com.jay.monitor.data.core.model.serializable.base.BaseDTO;
import com.jay.monitor.data.core.model.serializable.base.SearchIndexData;
import com.jay.monitor.data.core.model.serializable.base.TranceLogData;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.function.BiConsumer;

/**
 * @Module TODO
 * @Description TODO
 * @Author liukaixiong
 * @Date 2020/10/30 19:42
 */
@Component
public class TestTopicMonitorRule implements MonitorRuleCallback {

    @Override
    public void registerRule(Map<String, BiConsumer<String, ? super BaseDTO>> ruleMap) {
        ruleMap.put("DEFAULT_ALL", (value, mqData) -> {
            CatCrossIdModel catCrossIdModel = JSON.parseObject(value, CatCrossIdModel.class);
            if (mqData instanceof TranceLogData) {
                TranceLogData tranceLogData = (TranceLogData) mqData;
                tranceLogData.setRootLogId(catCrossIdModel.get_catRootMessageId());
                tranceLogData.setParentLogId(catCrossIdModel.get_catParentMessageId());
                tranceLogData.setLogId(catCrossIdModel.get_catChildMessageId());
            }

        });

        ruleMap.put("uat-mysql-dts", (value, mqData) -> {
            if (mqData instanceof SearchIndexData) {
                SearchIndexData indexData = (SearchIndexData) mqData;
                indexData.setGroupName("aaaa");
                indexData.setGroupKeyName("bbbb");
                indexData.setDataId("cccc");
            }
        });
    }

}
