diff --git a/mallinkService/src/main/java/com/iformall/utils/RedisCacheUtils.java b/mallinkService/src/main/java/com/iformall/utils/RedisCacheUtils.java index 1b41943c3..8c0cbab4b 100644 --- a/mallinkService/src/main/java/com/iformall/utils/RedisCacheUtils.java +++ b/mallinkService/src/main/java/com/iformall/utils/RedisCacheUtils.java @@ -11,8 +11,7 @@ import org.springframework.data.redis.core.ValueOperations; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; -import com.iformall.domain.po.WxCUser; -import com.iformall.domain.po.base.BaseCUserEntity; +import com.iformall.domain.po.WxLevelConfig; public class RedisCacheUtils { @@ -21,11 +20,11 @@ public class RedisCacheUtils { } private static List parseListJson(String json,Class clazz) { - return JSON.parseObject(json,new TypeReference>() {}); + return JSON.parseObject(json,new TypeReference>(clazz) {}); } private static Set parseSetJson(String json,Class clazz) { - return JSON.parseObject(json,new TypeReference>() {}); + return JSON.parseObject(json,new TypeReference>(clazz) {}); } public static void cache(RedisTemplate template,String key, Object value,long seconds) { @@ -41,7 +40,12 @@ public class RedisCacheUtils { if (template.hasKey(key)) { ValueOperations operations = template.opsForValue(); Object o = operations.get(key); - return parseJson(JSON.toJSONString(o), clazz); + if (o instanceof String) { + return parseJson((String)o, clazz); + }else { + return parseJson(JSON.toJSONString(o), clazz); + } + } return null; } @@ -50,7 +54,11 @@ public class RedisCacheUtils { if (template.hasKey(key)) { ValueOperations operations = template.opsForValue(); Object o = operations.get(key); - return parseListJson(JSON.toJSONString(o), clazz); + if (o instanceof String) { + return parseListJson((String)o, clazz); + }else { + return parseListJson(JSON.toJSONString(o), clazz); + } } return null; } @@ -59,7 +67,11 @@ public class RedisCacheUtils { if (template.hasKey(key)) { ValueOperations operations = template.opsForValue(); Object o = operations.get(key); - return parseSetJson(JSON.toJSONString(o), clazz); + if (o instanceof String) { + return parseSetJson((String)o, clazz); + }else { + return parseSetJson(JSON.toJSONString(o), clazz); + } } return null; } @@ -72,6 +84,9 @@ public class RedisCacheUtils { if (template.hasKey(key)) { ValueOperations operations = template.opsForValue(); Object o = operations.get(key); + if( o instanceof String) { + return (String) o; + } return JSON.toJSONString(o); } return null; @@ -81,6 +96,9 @@ public class RedisCacheUtils { if (template.hasKey(key)) { ValueOperations operations = template.opsForValue(); Object o = operations.get(key); + if (o instanceof String) { + Long.parseLong((String)o); + } return Long.parseLong(o.toString()); } return null; @@ -90,6 +108,9 @@ public class RedisCacheUtils { if (template.hasKey(key)) { ValueOperations operations = template.opsForValue(); Object o = operations.get(key); + if (o instanceof String) { + return new Integer((String)o); + } return new Integer(o.toString()); } return null; @@ -100,32 +121,41 @@ public class RedisCacheUtils { JSONObject jsonObject = JSON.parseObject(json); Object p = jsonObject.get(property); if (null != p ) { + if (p instanceof String) { + return parseJson((String)p, clazz); + } return parseJson(JSON.toJSONString(p), clazz); } return null; } - public static List getListFieldObject(Object o,String property,Class clazz) { + public static List getFieldListObject(Object o,String property,Class clazz) { String json = JSON.toJSONString(o); JSONObject jsonObject = JSON.parseObject(json); Object p = jsonObject.get(property); if (null != p ) { + if (p instanceof String) { + return parseListJson((String)p, clazz); + } return parseListJson(JSON.toJSONString(p), clazz); } return null; } - public static Set getSetFieldObject(Object o,String property,Class clazz) { + public static Set getFieldSetObject(Object o,String property,Class clazz) { String json = JSON.toJSONString(o); JSONObject jsonObject = JSON.parseObject(json); Object p = jsonObject.get(property); if (null != p ) { + if (p instanceof String) { + return parseSetJson((String)p, clazz); + } return parseSetJson(JSON.toJSONString(p), clazz); } return null; } - public static Map getMapFieldObject(Object o,String property) { + public static Map getFieldMapObject(Object o,String property) { return getFieldObject(o,property,Map.class); }