WANG 6 年 前
コミット
ad98dc9d18

+ 21 - 4
src/main/java/cn/com/qmth/examcloud/web/helpers/SequenceLockHelper.java

@@ -1,8 +1,12 @@
 package cn.com.qmth.examcloud.web.helpers;
 
+import java.util.List;
+
 import org.apache.commons.lang.StringUtils;
 import org.assertj.core.util.Arrays;
 
+import com.google.common.collect.Lists;
+
 import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
 import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
 import cn.com.qmth.examcloud.commons.util.ThreadLocalUtil;
@@ -50,8 +54,15 @@ public class SequenceLockHelper {
 			if (LOG.isDebugEnabled()) {
 				LOG.debug("locked");
 			}
-			ServletUtil.getRequest()
-					.setAttribute(HttpServletRequestAttribute.$_CUSTOM_SEQUENCE_LOCK.name(), key);
+			@SuppressWarnings("unchecked")
+			List<String> keyList = (List<String>) ServletUtil.getRequest()
+					.getAttribute(HttpServletRequestAttribute.$_CUSTOM_SEQUENCE_LOCK.name());
+			if (null == keyList) {
+				keyList = Lists.newArrayList();
+			}
+			keyList.add(key);
+			ServletUtil.getRequest().setAttribute(
+					HttpServletRequestAttribute.$_CUSTOM_SEQUENCE_LOCK.name(), keyList);
 		} else {
 			throw new SequenceLockException("请求等待,请稍后重试!");
 		}
@@ -66,8 +77,14 @@ public class SequenceLockHelper {
 	public static void releaseLock(Object... args) {
 		String key = LOCK_PREFIX + StringUtils.join(Arrays.asList(args), "_");
 		getRedisClient().delete(key);
-		ServletUtil.getRequest()
-				.removeAttribute(HttpServletRequestAttribute.$_CUSTOM_SEQUENCE_LOCK.name());
+		@SuppressWarnings("unchecked")
+		List<String> keyList = (List<String>) ServletUtil.getRequest()
+				.getAttribute(HttpServletRequestAttribute.$_CUSTOM_SEQUENCE_LOCK.name());
+		if (null != keyList) {
+			if (keyList.contains(key)) {
+				keyList.remove(key);
+			}
+		}
 	}
 
 }

+ 8 - 3
src/main/java/cn/com/qmth/examcloud/web/support/ControllerAspect.java

@@ -1,11 +1,13 @@
 package cn.com.qmth.examcloud.web.support;
 
 import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.collections.CollectionUtils;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Aspect;
@@ -149,10 +151,13 @@ public class ControllerAspect {
 			throw new RuntimeException(e);
 		} finally {
 			if (null != redisClient && redisClient.isEnable()) {
-				Object customSequenceLock = request
+				@SuppressWarnings("unchecked")
+				List<String> keyList = (List<String>) ServletUtil.getRequest()
 						.getAttribute(HttpServletRequestAttribute.$_CUSTOM_SEQUENCE_LOCK.name());
-				if (null != customSequenceLock) {
-					redisClient.delete((String) customSequenceLock);
+				if (CollectionUtils.isNotEmpty(keyList)) {
+					for (String key : keyList) {
+						redisClient.delete(key);
+					}
 				}
 			}
 		}