Эх сурвалжийг харах

redis序列化取值修改

wangliang 4 жил өмнө
parent
commit
e542d8ce3e

+ 5 - 2
themis-business/src/main/java/com/qmth/themis/business/cache/ExamActivityRecordCacheUtil.java

@@ -4,6 +4,8 @@ import com.qmth.themis.business.cache.bean.ExamActivityRecordCacheBean;
 import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.util.RedisUtil;
 
+import java.util.Objects;
+
 /**
  * 场次-考试记录hash值操作
  *
@@ -23,7 +25,8 @@ public class ExamActivityRecordCacheUtil {
     }
 
     public static ExamActivityRecordCacheBean getExamRecordStatus(Long activityId, Long examRecordId) {
-        return (ExamActivityRecordCacheBean) redisUtil.get(RedisKeyHelper.examActivityRecordCacheKey(activityId),
-                examRecordId.toString());
+        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examActivityRecordCacheKey(activityId),
+                examRecordId.toString())) ? (ExamActivityRecordCacheBean) redisUtil.get(RedisKeyHelper.examActivityRecordCacheKey(activityId),
+                examRecordId.toString()) : null;
     }
 }

+ 4 - 2
themis-business/src/main/java/com/qmth/themis/business/cache/ExamBreakCacheUtil.java

@@ -7,6 +7,8 @@ import com.qmth.themis.business.enums.VerifyExceptionEnum;
 import com.qmth.themis.business.service.TOeExamBreakHistoryService;
 import com.qmth.themis.business.util.RedisUtil;
 
+import java.util.Objects;
+
 /**
  * 断点缓存hash值操作
  *
@@ -48,7 +50,7 @@ public class ExamBreakCacheUtil {
     }
 
     public static ExceptionEnum getBreakReason(Long examBreakId) {
-        return ExceptionEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.break_reason.getCode()));
+        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.break_reason.getCode())) ? ExceptionEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.break_reason.getCode())) : null;
     }
 
     public static void setResumeReason(Long examBreakId, String resumeReason, boolean update) {
@@ -93,7 +95,7 @@ public class ExamBreakCacheUtil {
     }
 
     public static VerifyExceptionEnum getEntryAuthenticationResult(Long examBreakId) {
-        return VerifyExceptionEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.entry_authentication_result.getCode()));
+        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.entry_authentication_result.getCode())) ? VerifyExceptionEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examBreakCacheKey(examBreakId), ExamBreakHistoryFieldEnum.entry_authentication_result.getCode())) : null;
     }
 
     public static void setEntryAuthenticationId(Long examBreakId, Long entryAuthenticationId, boolean update) {

+ 5 - 5
themis-business/src/main/java/com/qmth/themis/business/cache/ExamRecordCacheUtil.java

@@ -95,7 +95,7 @@ public class ExamRecordCacheUtil {
     }
 
     public static FinishTypeEnum getFinishType(Long recordId) {
-        return FinishTypeEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.finish_type.getCode()));
+        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.finish_type.getCode())) ? FinishTypeEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.finish_type.getCode())) : null;
     }
 
     public static Long getClientLastSyncTime(Long recordId) {
@@ -114,7 +114,7 @@ public class ExamRecordCacheUtil {
     }
 
     public static ExamRecordStatusEnum getStatus(Long recordId) {
-        return ExamRecordStatusEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.status.getCode()));
+        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.status.getCode())) ? ExamRecordStatusEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.status.getCode())) : null;
     }
 
     public static Long getLastBreakId(Long recordId) {
@@ -218,7 +218,7 @@ public class ExamRecordCacheUtil {
     }
 
     public static MonitorStatusSourceEnum getMonitorStatus(Long recordId, MonitorVideoSourceEnum source) {
-        return MonitorStatusSourceEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), SystemConstant.MONITOR_STATUS_ + source.name()));
+        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), SystemConstant.MONITOR_STATUS_ + source.name())) ? MonitorStatusSourceEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), SystemConstant.MONITOR_STATUS_ + source.name())) : null;
     }
 
     public static void setMonitorStatus(Long recordId, MonitorVideoSourceEnum source, MonitorStatusSourceEnum statusSourceEnum, boolean update) {
@@ -229,7 +229,7 @@ public class ExamRecordCacheUtil {
     }
 
     public static MonitorCallStatusSourceEnum getMonitorCallStatus(Long recordId, MonitorVideoSourceEnum source) {
-        return MonitorCallStatusSourceEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), SystemConstant.MONITOR_CALL_STATUS_ + source.name()));
+        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), SystemConstant.MONITOR_CALL_STATUS_ + source.name())) ? MonitorCallStatusSourceEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), SystemConstant.MONITOR_CALL_STATUS_ + source.name())) : null;
     }
 
     public static void setMonitorCallStatus(Long recordId, MonitorVideoSourceEnum source, MonitorCallStatusSourceEnum callStatusSourceEnum) {
@@ -237,7 +237,7 @@ public class ExamRecordCacheUtil {
     }
 
     public static WebsocketStatusEnum getClientWebsocketStatus(Long recordId) {
-        return WebsocketStatusEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.client_websocket_status.getCode()));
+        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.client_websocket_status.getCode())) ? WebsocketStatusEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.client_websocket_status.getCode())) : null;
     }
 
     public static String getClientWebsocketId(Long recordId) {

+ 10 - 9
themis-business/src/main/java/com/qmth/themis/business/cache/FaceVerifyCacheUtil.java

@@ -4,22 +4,23 @@ import com.qmth.themis.business.cache.bean.FaceVerifyCacheBean;
 import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.util.RedisUtil;
 
+import java.util.Objects;
+
 /**
  * 人脸缓存
- * 
+ *
  * @Description:
  * @Author: xiatian
  * @Date: 2020-08-11
  */
 public class FaceVerifyCacheUtil {
-	private static RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
-
-	public static void setFaceVerifyCacheBean(Long examRecordId, Long id, FaceVerifyCacheBean bean) {
-		redisUtil.set(RedisKeyHelper.faceVerifyCacheKey(examRecordId), id.toString(), bean);
-	}
+    private static RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
 
-	public static FaceVerifyCacheBean getFaceVerifyCacheBean(Long examRecordId, Long id) {
-		return (FaceVerifyCacheBean) redisUtil.get(RedisKeyHelper.faceVerifyCacheKey(examRecordId), id.toString());
-	}
+    public static void setFaceVerifyCacheBean(Long examRecordId, Long id, FaceVerifyCacheBean bean) {
+        redisUtil.set(RedisKeyHelper.faceVerifyCacheKey(examRecordId), id.toString(), bean);
+    }
 
+    public static FaceVerifyCacheBean getFaceVerifyCacheBean(Long examRecordId, Long id) {
+        return Objects.nonNull(redisUtil.get(RedisKeyHelper.faceVerifyCacheKey(examRecordId), id.toString())) ? (FaceVerifyCacheBean) redisUtil.get(RedisKeyHelper.faceVerifyCacheKey(examRecordId), id.toString()) : null;
+    }
 }

+ 13 - 10
themis-business/src/main/java/com/qmth/themis/business/cache/LivenessVerifyCacheUtil.java

@@ -4,20 +4,23 @@ import com.qmth.themis.business.cache.bean.LivenessVerifyCacheBean;
 import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.util.RedisUtil;
 
-/**活检缓存
- * @Description: 
+import java.util.Objects;
+
+/**
+ * 活检缓存
+ *
+ * @Description:
  * @Author: xiatian
  * @Date: 2020-08-11
  */
 public class LivenessVerifyCacheUtil {
-	private static RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
-
-	public static void setLivenessVerifyCacheBean(Long examRecordId, Long id, LivenessVerifyCacheBean bean) {
-		redisUtil.set(RedisKeyHelper.livenessVerifyCacheKey(examRecordId), id.toString(), bean);
-	}
+    private static RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
 
-	public static LivenessVerifyCacheBean getLivenessVerifyCacheBean(Long examRecordId, Long id) {
-		return (LivenessVerifyCacheBean) redisUtil.get(RedisKeyHelper.livenessVerifyCacheKey(examRecordId), id.toString());
-	}
+    public static void setLivenessVerifyCacheBean(Long examRecordId, Long id, LivenessVerifyCacheBean bean) {
+        redisUtil.set(RedisKeyHelper.livenessVerifyCacheKey(examRecordId), id.toString(), bean);
+    }
 
+    public static LivenessVerifyCacheBean getLivenessVerifyCacheBean(Long examRecordId, Long id) {
+        return Objects.nonNull(redisUtil.get(RedisKeyHelper.livenessVerifyCacheKey(examRecordId), id.toString())) ? (LivenessVerifyCacheBean) redisUtil.get(RedisKeyHelper.livenessVerifyCacheKey(examRecordId), id.toString()) : null;
+    }
 }

+ 7 - 4
themis-business/src/main/java/com/qmth/themis/business/cache/MobileAuthCacheUtil.java

@@ -5,6 +5,8 @@ import com.qmth.themis.business.enums.MobileModeEnum;
 import com.qmth.themis.business.enums.MonitorVideoSourceEnum;
 import com.qmth.themis.business.util.RedisUtil;
 
+import java.util.Objects;
+
 /**
  * 移动端临时认证
  *
@@ -25,7 +27,7 @@ public class MobileAuthCacheUtil {
     }
 
     public static MobileModeEnum getMode(MobileModeEnum mode, String code) {
-        return MobileModeEnum.valueOf((String) redisUtil.get(RedisKeyHelper.mobileAuthCacheKey(mode, code), "mode"));
+        return Objects.nonNull(redisUtil.get(RedisKeyHelper.mobileAuthCacheKey(mode, code), "mode")) ? MobileModeEnum.valueOf((String) redisUtil.get(RedisKeyHelper.mobileAuthCacheKey(mode, code), "mode")) : null;
     }
 
     public static void setCode(MobileModeEnum mode, String code) {
@@ -69,13 +71,14 @@ public class MobileAuthCacheUtil {
     }
 
     public static void setMonitorVideoSource(MobileModeEnum mode, String code,
-            MonitorVideoSourceEnum monitorVideoSource) {
+                                             MonitorVideoSourceEnum monitorVideoSource) {
         redisUtil.set(RedisKeyHelper.mobileAuthCacheKey(mode, code), "monitorVideoSource", monitorVideoSource);
     }
 
     public static MonitorVideoSourceEnum getMonitorVideoSource(MobileModeEnum mode, String code) {
-        return MonitorVideoSourceEnum.valueOf((String) redisUtil
-                .get(RedisKeyHelper.mobileAuthCacheKey(mode, code), "monitorVideoSource"));
+        return Objects.nonNull(redisUtil
+                .get(RedisKeyHelper.mobileAuthCacheKey(mode, code), "monitorVideoSource")) ? MonitorVideoSourceEnum.valueOf((String) redisUtil
+                .get(RedisKeyHelper.mobileAuthCacheKey(mode, code), "monitorVideoSource")) : null;
     }
 
     public static String getUserType(MobileModeEnum mode, String code) {