package com.engine.salary.service.impl;

import com.cloudstore.dev.api.util.Util_DataCache;
import com.engine.core.impl.Service;
import com.engine.salary.service.SalaryCacheService;
import com.engine.salary.util.JsonUtil;
import org.apache.commons.lang3.StringUtils;
import weaver.general.Util;

public class SalaryCacheServiceImpl extends Service implements SalaryCacheService {


    @Override
    public <T> void set(String key, T value) {
        Util_DataCache.setObjVal(key, value);
    }

    @Override
    public <T> void set(String key, T value, int time) {
        Util_DataCache.setObjVal(key, value, time);
    }

    @Override
    public <T> void setJson(String key, T value) {
        Util_DataCache.setObjVal(key, JsonUtil.toJsonString(value));
    }

    @Override
    public <T> void setJson(String key, T value, int time) {
        Util_DataCache.setObjVal(key, JsonUtil.toJsonString(value), time);
    }

    @Override
    public <T> T get(String key) {
        return (T) Util_DataCache.getObjVal(key);
    }

    @Override
    public <T> T getJson(String key, Class<T> clazz) {
        String value = Util.null2String(Util_DataCache.getObjVal(key));
        if (StringUtils.isEmpty(value)) {
            return null;
        }
        return JsonUtil.parseObject(value, clazz);
    }

    @Override
    public void remove(String key) {
        Util_DataCache.clearVal(key);
    }
}
