package com.ag.util;

import cn.hutool.core.convert.Convert;
import com.ag.base.IRedisService;
import com.ag.secp.platform.spring.SpringApplicationContext;
import com.wb.common.KVBuffer;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Administrator on 2017/4/17.
 */
public class CodeUtil {
    public static void setCodeBuffer(HttpServletRequest request, HttpServletResponse response) {
        String tableName = request.getParameter("tableName");
        //String keyname = request.getParameter("keyName");
        if (StringUtils.isEmpty(tableName)) {
            Object obj = request.getAttribute("tableName");
            if (!StrUtil.isEmpty(obj)) {
                tableName = Convert.toStr(obj);
            }
        }
        if (StringUtils.isEmpty(tableName)){
            tableName = request.getParameter("keyName");
        }
        Assert.notNull(tableName, "请求参数错误，请检查！");

        IRedisService service = (IRedisService)SpringApplicationContext.getBean("redisServiceImpl");
        service.refreshByDictName(tableName);

    }


    /**
     * 重新加载全部redis
     * @param request
     * @param response
     */
    public static void reloadAll(HttpServletRequest request, HttpServletResponse response) {
        KVBuffer.loadRedis();
    }


}
