Bläddra i källkod

Merge branch 'master' of http://git.qmth.com.cn/ExamCloud-3/examcloud-web.git

WANG 6 år sedan
förälder
incheckning
57a567b584

+ 22 - 3
src/main/java/cn/com/qmth/examcloud/web/cache/CacheCloudServiceProvider.java

@@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.RestController;
 import com.google.common.collect.Maps;
 
 import cn.com.qmth.examcloud.api.commons.CloudService;
+import cn.com.qmth.examcloud.api.commons.enums.BasicDataType;
+import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
 import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
@@ -38,7 +40,24 @@ public class CacheCloudServiceProvider implements CloudService {
 	public String refresh(@RequestBody RefreshCacheReq req) {
 
 		String className = req.getClassName();
-		Object[] keys = req.getKeys();
+		String[] keys = req.getKeys();
+		BasicDataType[] typeArray = req.getTypeArray();
+
+		Object[] expectedKeys = new Object[keys.length];
+
+		for (int i = 0; i < keys.length; i++) {
+			String key = keys[i];
+			BasicDataType type = typeArray[i];
+			if (type.equals(BasicDataType.LONG)) {
+				expectedKeys[i] = Long.parseLong(key);
+			} else if (type.equals(BasicDataType.STRING)) {
+				expectedKeys[i] = key;
+			} else if (type.equals(BasicDataType.INTEGER)) {
+				expectedKeys[i] = Integer.parseInt(key);
+			} else {
+				throw new ExamCloudRuntimeException("key type is not supported");
+			}
+		}
 
 		ObjectCache<?> objectCache = map.get(className);
 		if (null == objectCache) {
@@ -51,8 +70,8 @@ public class CacheCloudServiceProvider implements CloudService {
 				throw new StatusException("008001", "class not found");
 			}
 		}
-		objectCache.refresh(keys);
-		Object object = objectCache.get(keys);
+		objectCache.refresh(expectedKeys);
+		Object object = objectCache.get(expectedKeys);
 		return JsonUtil.toJson(object);
 	}
 

+ 14 - 0
src/main/java/cn/com/qmth/examcloud/web/cache/ObjectRedisCacheTrigger.java

@@ -6,6 +6,8 @@ import org.springframework.stereotype.Component;
 
 import com.google.common.collect.Maps;
 
+import cn.com.qmth.examcloud.api.commons.enums.BasicDataType;
+import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
 import cn.com.qmth.examcloud.web.cloud.CloudClientSupport;
 import cn.com.qmth.examcloud.web.support.SpringContextHolder;
 
@@ -56,14 +58,26 @@ public class ObjectRedisCacheTrigger extends CloudClientSupport {
 		}
 
 		String[] keyArray = new String[keys.length];
+		BasicDataType[] typeArray = new BasicDataType[keys.length];
 
 		for (int i = 0; i < keys.length; i++) {
 			keyArray[i] = String.valueOf(keys[i]);
+			Class<? extends Object> c = keys[i].getClass();
+			if (c.equals(Long.class)) {
+				typeArray[i] = BasicDataType.LONG;
+			} else if (c.equals(String.class)) {
+				typeArray[i] = BasicDataType.STRING;
+			} else if (c.equals(Integer.class)) {
+				typeArray[i] = BasicDataType.INTEGER;
+			} else {
+				throw new ExamCloudRuntimeException("key type is not supported");
+			}
 		}
 
 		RefreshCacheReq req = new RefreshCacheReq();
 		req.setClassName(className);
 		req.setKeys(keyArray);
+		req.setTypeArray(typeArray);
 		post(appName, "refresh", req);
 
 	}

+ 11 - 3
src/main/java/cn/com/qmth/examcloud/web/cache/RefreshCacheReq.java

@@ -1,5 +1,6 @@
 package cn.com.qmth.examcloud.web.cache;
 
+import cn.com.qmth.examcloud.api.commons.enums.BasicDataType;
 import cn.com.qmth.examcloud.api.commons.exchange.BaseRequest;
 
 /**
@@ -11,15 +12,14 @@ import cn.com.qmth.examcloud.api.commons.exchange.BaseRequest;
  */
 public class RefreshCacheReq extends BaseRequest {
 
-	/**
-	 * 属性注释
-	 */
 	private static final long serialVersionUID = -6516842403328041136L;
 
 	private String className;
 
 	private String[] keys;
 
+	private BasicDataType[] typeArray;
+
 	public String getClassName() {
 		return className;
 	}
@@ -36,4 +36,12 @@ public class RefreshCacheReq extends BaseRequest {
 		this.keys = keys;
 	}
 
+	public BasicDataType[] getTypeArray() {
+		return typeArray;
+	}
+
+	public void setTypeArray(BasicDataType[] typeArray) {
+		this.typeArray = typeArray;
+	}
+
 }