package com.ag.log.service;

import com.ag.log.pojo.LogForCdc;
import com.alibaba.fastjson.JSONObject;

import java.util.List;
import java.util.Map;

/**
 * Created by yangxh on 2022/5/31.
 */
public class CdcDataDict {

    private static JSONObject tabJson = new JSONObject();

    public static boolean isExistsTab(String tabName){
        return tabJson.containsKey(tabName);
    }

    public static void putTab(LogForCdc log){

    }

    public static List<String> getColumns(LogForCdc log){
        return (List<String>)tabJson.get(log.getTable());
    }

    public static boolean isContainsCols(LogForCdc log){
        List<String> columns = getColumns(log);
        JSONObject data = null;
        if (!log.getData().isEmpty()){
            data = log.getData();
        }else {
            data = log.getBeforedata();
        }
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            String key = entry.getKey();
            if (!columns.contains(key)){
                return false;
            }
        }
        return true;
    }

    public static void putTabCol(LogForCdc log){

    }
}
