package com.gzlh.bus; import cn.hutool.cache.CacheUtil; import cn.hutool.cache.impl.TimedCache; import cn.hutool.core.util.ReflectUtil; import cn.hutool.json.JSONUtil; import cn.hutool.log.StaticLog; import com.gzlh.config.SystemObject; import com.gzlh.entity.ReqBO; public class EventDataManager { private static final TimedCache CACHE_MAP= CacheUtil.newTimedCache(20*60*1000); private static final String KEY="event_key"; /** * 缓存 * @param field * @param value */ public static void cacheData(String field,Object value){ ReqBO reqBO= CACHE_MAP.get(KEY); if (reqBO==null){ reqBO=new ReqBO(); reqBO.setDirection(1); } reqBO.setChannelCode(SystemObject.applicationConfig.getChannelCode()); ReflectUtil.setFieldValue(reqBO,field,value); CACHE_MAP.put(KEY,reqBO); StaticLog.info("cache bo:{}", JSONUtil.toJsonStr(reqBO)); } /** * 获取数据中心数据 * @return */ public static ReqBO getCacheData(){ return CACHE_MAP.get(KEY); } /** * 清除掉缓存 */ public static void cleanData(){ CACHE_MAP.clear(); } }