package com.sagacloud.broadcast;

import com.sagacloud.cache.cachedObject.pojo.VenderInfoMap;
import com.sagacloud.dict.TypeToInfosMap;
import com.sagacloud.search.AllObjs;
import org.json.JSONObject;

/**
 * Created by wo on 10/22/19.
 */
public interface MsgHandler {
    void init();
    void publish(String msg);
    void consume();
    public static void clearCache(String msg){
        JSONObject jsonMsg = new JSONObject(msg);
        int type = jsonMsg.getInt("type");
        if(type == 7){
            String objId = jsonMsg.getJSONArray("infos").getJSONObject(0).getString("id");
            AllObjs.clearCache(objId.substring(2,12));
        }else if(type == 1 || type == 2){
            String objId = jsonMsg.getString("id");
            AllObjs.clearCache(objId.substring(2,12));
        }else if(type == 8){
            String objId = jsonMsg.getString("projectId");
            AllObjs.clearCache(objId.substring(2,12));
        }else if(type == 12){
            TypeToInfosMap.clearDict2Infos(jsonMsg.getString("dictId"));
        }else if(type == 13){
            TypeToInfosMap.clearPj2Dict(jsonMsg.getString("projectId"));
        }else if(type == 99){
            VenderInfoMap.clearCache();
        }

    }
}
