Sfoglia il codice sorgente

缓存+streamId优化

wangliang 4 anni fa
parent
commit
3b48622191
31 ha cambiato i file con 654 aggiunte e 430 eliminazioni
  1. 9 30
      themis-admin/src/main/java/com/qmth/themis/admin/api/SysController.java
  2. 9 16
      themis-admin/src/main/java/com/qmth/themis/admin/api/TBOrgController.java
  3. 21 28
      themis-admin/src/main/java/com/qmth/themis/admin/api/TBUserController.java
  4. 19 11
      themis-admin/src/main/java/com/qmth/themis/admin/api/TEExamController.java
  5. 4 2
      themis-admin/src/main/java/com/qmth/themis/admin/api/TEExamPaperController.java
  6. 4 1
      themis-admin/src/main/java/com/qmth/themis/admin/api/TEExamReexamController.java
  7. 3 2
      themis-admin/src/main/java/com/qmth/themis/admin/api/TEExamStudentController.java
  8. 5 13
      themis-admin/src/main/java/com/qmth/themis/admin/api/TEStudentController.java
  9. 9 10
      themis-admin/src/main/java/com/qmth/themis/admin/api/TIeInvigilateCallMobileController.java
  10. 15 11
      themis-admin/src/main/java/com/qmth/themis/admin/api/TIeInvigilateController.java
  11. 9 8
      themis-admin/src/main/java/com/qmth/themis/admin/api/TIeInvigilateWarnInfoController.java
  12. 0 3
      themis-admin/src/main/java/com/qmth/themis/admin/api/TIeReportController.java
  13. 15 3
      themis-business/src/main/java/com/qmth/themis/business/config/RedisConfig.java
  14. 21 9
      themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java
  15. 2 1
      themis-business/src/main/java/com/qmth/themis/business/dto/response/TEExamActivityDto.java
  16. 99 4
      themis-business/src/main/java/com/qmth/themis/business/service/CacheService.java
  17. 7 2
      themis-business/src/main/java/com/qmth/themis/business/service/TEExamService.java
  18. 168 18
      themis-business/src/main/java/com/qmth/themis/business/service/impl/CacheServiceImpl.java
  19. 2 1
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TEConfigServiceImpl.java
  20. 4 2
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamActivityServiceImpl.java
  21. 17 4
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamServiceImpl.java
  22. 4 4
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TEMobileServiceImpl.java
  23. 3 1
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TEOpenServiceImpl.java
  24. 4 8
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TEStudentServiceImpl.java
  25. 13 13
      themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskExamPaperImportTemplete.java
  26. 19 41
      themis-business/src/main/java/com/qmth/themis/business/util/AuthUtil.java
  27. 146 146
      themis-business/src/main/java/com/qmth/themis/business/util/RedisUtil.java
  28. 5 12
      themis-exam/src/main/java/com/qmth/themis/exam/api/SysController.java
  29. 11 20
      themis-exam/src/main/java/com/qmth/themis/exam/api/TEStudentController.java
  30. 3 3
      themis-exam/src/main/java/com/qmth/themis/exam/api/TIeInvigilateCallMobileController.java
  31. 4 3
      themis-exam/src/main/java/com/qmth/themis/exam/api/TIeInvigilateCallOeController.java

+ 9 - 30
themis-admin/src/main/java/com/qmth/themis/admin/api/SysController.java

@@ -16,13 +16,13 @@ import com.qmth.themis.business.enums.RoleEnum;
 import com.qmth.themis.business.enums.UploadFileEnum;
 import com.qmth.themis.business.service.*;
 import com.qmth.themis.business.util.OssUtil;
-import com.qmth.themis.business.util.RedisUtil;
 import com.qmth.themis.business.util.ServletUtil;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
 import io.swagger.annotations.*;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -83,7 +83,7 @@ public class SysController {
     TEExamStudentService teExamStudentService;
 
     @Resource
-    RedisUtil redisUtil;
+    CacheService cacheService;
 
     @ApiOperation(value = "菜单查询接口")
     @RequestMapping(value = "/getMenu", method = RequestMethod.POST)
@@ -103,10 +103,6 @@ public class SysController {
         if (Objects.isNull(orgId) || Objects.equals(orgId, "")) {
             throw new BusinessException(ExceptionResultEnum.ORG_ID_IS_NULL);
         }
-        //        SchoolDto schoolDto = (SchoolDto) redisTemplate.opsForValue().get(SystemConstant.SCHOOL_CACHE + orgId);
-        //        Map map = new HashMap();
-        //        map.put(SystemConstant.ENV_FILEHOST, schoolDto.getFileHost());
-        //        return ResultUtil.ok(map);
         return ResultUtil.ok(true);
     }
 
@@ -216,15 +212,7 @@ public class SysController {
             throw new BusinessException(ExceptionResultEnum.ORG_CODE_IS_NULL);
         }
         if (!Objects.equals(code.toUpperCase(), SystemConstant.ADMIN)) {
-            TBOrg tbOrg = (TBOrg) redisUtil.getOrgCode(code);
-            if (Objects.isNull(tbOrg)) {
-                QueryWrapper<TBOrg> tbOrgQueryWrapper = new QueryWrapper<>();
-                tbOrgQueryWrapper.lambda().eq(TBOrg::getCode, code);
-                tbOrg = tbOrgService.getOne(tbOrgQueryWrapper);
-                if (Objects.nonNull(tbOrg)) {
-                    redisUtil.setOrgCode(code, tbOrg);
-                }
-            }
+            TBOrg tbOrg = cacheService.addOrgCodeCache(code);
             if (Objects.isNull(tbOrg)) {
                 throw new BusinessException(ExceptionResultEnum.ORG_NO);
             }
@@ -260,20 +248,11 @@ public class SysController {
     @ApiOperation(value = "角色查询接口")
     @RequestMapping(value = "/role/query", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "角色信息", response = TBRole.class)})
+    @Cacheable(value = SystemConstant.roleCache, key = "methodName")
     public Result roleList() {
-        List<TBRole> tbRoleList = (List<TBRole>) redisUtil.getRole();
-        if (Objects.nonNull(tbRoleList) && tbRoleList.size() > 0) {
-            tbRoleList = (List<TBRole>) tbRoleList.get(0);
-        } else {
-            QueryWrapper<TBRole> tbRoleQueryWrapper = new QueryWrapper<>();
-            tbRoleQueryWrapper.lambda()
-                    .notIn(TBRole::getRoleCode, RoleEnum.SUPER_ADMIN.name(), RoleEnum.STUDENT.name());
-            tbRoleList = tbRoleService.list(tbRoleQueryWrapper);
-            if (Objects.nonNull(tbRoleList)) {
-                redisUtil.setRole(tbRoleList);
-            }
-        }
-        return ResultUtil.ok(tbRoleList);
+        QueryWrapper<TBRole> tbRoleQueryWrapper = new QueryWrapper<>();
+        tbRoleQueryWrapper.lambda().notIn(TBRole::getRoleCode, RoleEnum.SUPER_ADMIN.name(), RoleEnum.STUDENT.name());
+        return ResultUtil.ok(tbRoleService.list(tbRoleQueryWrapper));
     }
 
     @ApiOperation(value = "考试场次查询接口")
@@ -290,7 +269,7 @@ public class SysController {
                             @ApiParam(value = "批次名称", required = false) @RequestParam(required = false) String name,
                             @ApiParam(value = "类型(区分实时监考台和考务)", required = false) @RequestParam(required = false) String type) {
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         List<TEExam> teExamList = null;
         if (authDto.getRoleCodes().toString().contains(RoleEnum.ADMIN.name()) || authDto.getRoleCodes().toString()
                 .contains(RoleEnum.SUPER_ADMIN.name())) {//管理员
@@ -350,7 +329,7 @@ public class SysController {
         }
         //首先查询当前用户所要监控的roomCode
         QueryWrapper<TBExamInvigilateUser> examInvigilateUserQueryWrapper = new QueryWrapper<>();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         examInvigilateUserQueryWrapper.lambda().eq(TBExamInvigilateUser::getOrgId, tbUser.getOrgId())
                 .eq(TBExamInvigilateUser::getExamId, examId);
         if (authDto.getRoleCodes().toString().contains(RoleEnum.INVIGILATE.name())) {

+ 9 - 16
themis-admin/src/main/java/com/qmth/themis/admin/api/TBOrgController.java

@@ -8,8 +8,8 @@ import com.qmth.themis.business.dto.response.TBOrgDto;
 import com.qmth.themis.business.entity.TBOrg;
 import com.qmth.themis.business.entity.TBUser;
 import com.qmth.themis.business.enums.FieldUniqueEnum;
+import com.qmth.themis.business.service.CacheService;
 import com.qmth.themis.business.service.TBOrgService;
-import com.qmth.themis.business.util.RedisUtil;
 import com.qmth.themis.business.util.ServletUtil;
 import com.qmth.themis.business.util.UidUtil;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
@@ -24,7 +24,6 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
-import java.util.Collections;
 import java.util.Map;
 import java.util.Objects;
 
@@ -46,13 +45,11 @@ public class TBOrgController {
     TBOrgService tbOrgService;
 
     @Resource
-    RedisUtil redisUtil;
+    UidUtil uidUtil;
 
     @Resource
-    UidUtil uidUtil;
+    CacheService cacheService;
 
-    //    @CachePut(value = "org_cache", key = "'orgCacheQuery'")
-    //    @Cacheable(value = "org_cache", key = "#p0")
     @ApiOperation(value = "机构查询分页接口")
     @RequestMapping(value = "/query", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "机构信息", response = TBOrgDto.class)})
@@ -64,7 +61,6 @@ public class TBOrgController {
         return ResultUtil.ok(tbOrgService.queryByPage(new Page<>(pageNumber, pageSize), code, name, enable));
     }
 
-    //    @CacheEvict(value = "org_cache", key = "'orgCacheQuery'")
     @ApiOperation(value = "机构新增/编辑接口")
     @RequestMapping(value = "/save", method = RequestMethod.POST)
     @Transactional
@@ -91,8 +87,8 @@ public class TBOrgController {
                 tbOrg.setUpdateId(tbUser.getId());
             }
             tbOrgService.saveOrUpdate(tbOrg);
-            redisUtil.setOrg(tbOrg.getId(), tbOrg);
-            redisUtil.setOrgCode(tbOrg.getCode(), tbOrg);
+            cacheService.addOrgCache(tbOrg.getId());
+            cacheService.addOrgCodeCache(tbOrg.getCode());
         } catch (Exception e) {
             log.error("请求出错", e);
             if (e instanceof DuplicateKeyException) {
@@ -124,18 +120,15 @@ public class TBOrgController {
             throw new BusinessException(ExceptionResultEnum.ENABLE_IS_NULL);
         }
         Integer enable = Integer.parseInt(String.valueOf(user.get("enable")));
-        TBOrg tbOrg = (TBOrg) redisUtil.getOrg(orgId);
-        if (Objects.isNull(tbOrg)) {
-            tbOrg = tbOrgService.getById(orgId);
-        }
+        TBOrg tbOrg = cacheService.addOrgCache(orgId);
         if (Objects.isNull(tbOrg)) {
-            throw new BusinessException(ExceptionResultEnum.USER_NO);
+            throw new BusinessException(ExceptionResultEnum.ORG_NO);
         }
         //保存机构
         tbOrg.setEnable(enable);
         tbOrgService.updateById(tbOrg);
-        redisUtil.setOrg(orgId, tbOrg);
-        redisUtil.setOrgCode(tbOrg.getCode(), tbOrg);
+        cacheService.updateOrgCache(orgId);
+        cacheService.updateOrgCodeCache(tbOrg.getCode());
         return ResultUtil.ok(true);
     }
 }

+ 21 - 28
themis-admin/src/main/java/com/qmth/themis/admin/api/TBUserController.java

@@ -18,7 +18,10 @@ import com.qmth.themis.business.entity.TBUserRole;
 import com.qmth.themis.business.enums.FieldUniqueEnum;
 import com.qmth.themis.business.enums.MqTagEnum;
 import com.qmth.themis.business.enums.SystemOperationEnum;
-import com.qmth.themis.business.service.*;
+import com.qmth.themis.business.service.CacheService;
+import com.qmth.themis.business.service.MqDtoService;
+import com.qmth.themis.business.service.TBUserRoleService;
+import com.qmth.themis.business.service.TBUserService;
 import com.qmth.themis.business.util.*;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.enums.Platform;
@@ -68,9 +71,6 @@ public class TBUserController {
     @Resource
     TBUserRoleService tbUserRoleService;
 
-    @Resource
-    TBOrgService tbOrgService;
-
     @Resource
     UidUtil uidUtil;
 
@@ -102,15 +102,7 @@ public class TBUserController {
         String orgCode = String.valueOf(mapParameter.get("code"));
         TBOrg tbOrg = null;
         if (!Objects.equals(orgCode.toUpperCase(), SystemConstant.ADMIN)) {
-            tbOrg = (TBOrg) redisUtil.getOrgCode(orgCode);
-            if (Objects.isNull(tbOrg)) {
-                QueryWrapper<TBOrg> tbOrgQueryWrapper = new QueryWrapper<>();
-                tbOrgQueryWrapper.lambda().eq(TBOrg::getCode, orgCode);
-                tbOrg = tbOrgService.getOne(tbOrgQueryWrapper);
-                if (Objects.nonNull(tbOrg)) {
-                    redisUtil.setOrgCode(orgCode, tbOrg);
-                }
-            }
+            tbOrg = cacheService.addOrgCodeCache(orgCode);
             if (Objects.isNull(tbOrg)) {
                 throw new BusinessException(ExceptionResultEnum.ORG_NO);
             }
@@ -191,11 +183,10 @@ public class TBUserController {
         Platform platform = ServletUtil.getRequestPlatform();
         String deviceId = ServletUtil.getRequestDeviceId();
         //添加用户鉴权缓存
-        AuthDto authDto = cacheService.addAccountCache(user.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(user.getId());
         //生成token
         String token = RandomStringUtils.randomAlphanumeric(32);
-        //添加用户缓存
-        redisUtil.setUser(user.getId(), user);
+        cacheService.addAccountCache(user.getId());
         Source source = null;
         if (Platform.WIN == platform || Platform.MAC == platform) {
             source = Source.ADMIN_CLIENT;
@@ -234,7 +225,7 @@ public class TBUserController {
             orgMap.put("logo", authDto.getTbOrg().getLogo());
             orgMap.put("enableMonitorRecord", authDto.getTbOrg().getEnableMonitorRecord());
             map.put(SystemConstant.ORG_INFO, orgMap);
-            redisUtil.setOrg(authDto.getTbOrg().getId(), authDto.getTbOrg());
+            cacheService.addOrgCache(authDto.getTbOrg().getId());
         }
         return ResultUtil.ok(map);
     }
@@ -539,7 +530,7 @@ public class TBUserController {
     public Result logout() throws NoSuchAlgorithmException {
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
         TBSession tbSession = (TBSession) ServletUtil.getRequestSession();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         if (Objects.isNull(tbSession)) {
             throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
         }
@@ -555,8 +546,8 @@ public class TBUserController {
             }
         }
         if (delete) {
-            redisUtil.deleteUser(tbUser.getId());
             cacheService.removeAccountCache(tbUser.getId());
+            cacheService.removeAccountAuthCache(tbUser.getId());
         }
         //mq发送消息start
         MqDto mqDto = new MqDto(mqUtil.getMqGroupDomain().getTopic(), MqTagEnum.USER.name(), SystemOperationEnum.LOGOUT,
@@ -616,8 +607,8 @@ public class TBUserController {
         TBUser dbUser = null;
         AuthDto authDto = null;
         if (Objects.nonNull(mapParameter.get("id"))) {
-            dbUser = tbUserService.getById(Long.parseLong(String.valueOf(mapParameter.get("id"))));
-            authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + dbUser.getId());
+            dbUser = cacheService.addAccountCache(Long.parseLong(String.valueOf(mapParameter.get("id"))));
+            authDto = cacheService.addAccountAuthCache(dbUser.getId());
         }
         Gson gson = new Gson();
         TBUser tbUser = gson.fromJson(gson.toJson(mapParameter), TBUser.class);
@@ -671,8 +662,10 @@ public class TBUserController {
                                     s.name());
                     redisUtil.deleteUserSession(sessionId);
                 }
-                redisUtil.deleteUser(tbUser.getId());
                 cacheService.removeAccountCache(tbUser.getId());
+                cacheService.removeAccountAuthCache(tbUser.getId());
+            } else {
+                cacheService.updateAccountCache(tbUser.getId());
             }
         } catch (Exception e) {
             log.error("请求出错", e);
@@ -733,7 +726,7 @@ public class TBUserController {
             throw new BusinessException(ExceptionResultEnum.ENABLE_IS_NULL);
         }
         Integer enable = Integer.parseInt(String.valueOf(user.get("enable")));
-        TBUser tbUser = tbUserService.getById(userId);
+        TBUser tbUser = cacheService.addAccountCache(userId);
         if (Objects.isNull(tbUser)) {
             throw new BusinessException(ExceptionResultEnum.USER_NO);
         }
@@ -741,7 +734,7 @@ public class TBUserController {
         tbUser.setEnable(enable);
         tbUserService.updateById(tbUser);
         if (enable == 0) {
-            AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+            AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
             if (Objects.nonNull(authDto)) {
                 for (Source s : Source.values()) {
                     String sessionId = SessionUtil
@@ -750,10 +743,10 @@ public class TBUserController {
                     redisUtil.deleteUserSession(sessionId);
                 }
             }
-            redisUtil.deleteUser(tbUser.getId());
             cacheService.removeAccountCache(tbUser.getId());
+            cacheService.removeAccountAuthCache(tbUser.getId());
         } else {
-            redisUtil.setUser(tbUser.getId(), tbUser);
+            cacheService.updateAccountCache(tbUser.getId());
         }
         return ResultUtil.ok(true);
     }
@@ -773,7 +766,7 @@ public class TBUserController {
             throw new BusinessException(ExceptionResultEnum.PASSWORD_IS_NULL);
         }
         String password = String.valueOf(mapParameter.get("password"));
-        TBUser tbUser = tbUserService.getById(id);
+        TBUser tbUser = cacheService.addAccountCache(id);
         if (Objects.isNull(tbUser)) {
             throw new BusinessException(ExceptionResultEnum.USER_NO);
         }
@@ -781,7 +774,7 @@ public class TBUserController {
         tbUser.setPassword(password);
         tbUser.setUpdateId(currentUser.getId());
         tbUserService.updateById(tbUser);
-        redisUtil.deleteUser(tbUser.getId());
+        cacheService.removeAccountCache(tbUser.getId());
         return ResultUtil.ok(true);
     }
 }

+ 19 - 11
themis-admin/src/main/java/com/qmth/themis/admin/api/TEExamController.java

@@ -7,6 +7,7 @@ import com.qmth.themis.business.annotation.ApiJsonProperty;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
 import com.qmth.themis.business.cache.RedisKeyHelper;
 import com.qmth.themis.business.cache.bean.ExamActivityRecordCacheBean;
+import com.qmth.themis.business.cache.bean.ExamCacheBean;
 import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.AuthDto;
@@ -81,6 +82,9 @@ public class TEExamController {
     @Resource
     private TEExamPaperService examPaperService;
 
+    @Resource
+    CacheService cacheService;
+
     @ApiOperation(value = "考试批次修改/新增接口")
     @RequestMapping(value = "/save", method = RequestMethod.POST)
     @Transactional
@@ -112,7 +116,8 @@ public class TEExamController {
             TEExam oldTeExam = null;
             if (Objects.nonNull(oldId)) {
                 teExamDto.setUpdateId(tbUser.getId());
-                oldTeExam = teExamService.getById(oldId);
+                ExamCacheBean examCacheBean = teExamService.getExamCacheBean(oldId);
+                oldTeExam = teExamService.cacheConvert(examCacheBean);
                 if (Objects.equals(oldTeExam.getMonitorStatus(), InvigilateMonitorStatusEnum.FINISHED)) {
                     throw new BusinessException("监考结束的考试批次不可以修改");
                 }
@@ -271,7 +276,7 @@ public class TEExamController {
                         @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber,
                         @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         if (authDto.getRoleCodes().toString().contains(RoleEnum.INSPECTION.name())) {
             userId = null;
         }
@@ -295,10 +300,11 @@ public class TEExamController {
             throw new BusinessException(ExceptionResultEnum.ENABLE_IS_NULL);
         }
         Integer enable = Integer.parseInt(String.valueOf(mapParameter.get("enable")));
-        TEExam teExam = teExamService.getById(examId);
-        if (Objects.isNull(teExam)) {
+        ExamCacheBean examCacheBean = teExamService.getExamCacheBean(examId);
+        if (Objects.isNull(examCacheBean)) {
             throw new BusinessException(ExceptionResultEnum.EXAM_NO);
         }
+        TEExam teExam = teExamService.cacheConvert(examCacheBean);
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
         teExam.setEnable(enable);
         teExam.setUpdateId(tbUser.getId());
@@ -314,11 +320,11 @@ public class TEExamController {
         if (Objects.isNull(id) || Objects.equals(id, "")) {
             throw new BusinessException(ExceptionResultEnum.EXAM_ID_IS_NULL);
         }
-        TEExam teExam = teExamService.getById(id);
-        if (Objects.isNull(teExam)) {
+        ExamCacheBean examCacheBean = teExamService.getExamCacheBean(id);
+        if (Objects.isNull(examCacheBean)) {
             throw new BusinessException(ExceptionResultEnum.EXAM_NO);
         }
-        return ResultUtil.ok(new TEExamDto(teExam));
+        return ResultUtil.ok(new TEExamDto(teExamService.cacheConvert(examCacheBean)));
     }
 
     @ApiOperation(value = "考试批次复制接口")
@@ -341,10 +347,11 @@ public class TEExamController {
             throw new BusinessException(ExceptionResultEnum.EXAM_NAME_IS_NULL);
         }
         String name = String.valueOf(mapParameter.get("name"));
-        TEExam teExam = teExamService.getById(examId);
-        if (Objects.isNull(teExam)) {
+        ExamCacheBean examCacheBean = teExamService.getExamCacheBean(examId);
+        if (Objects.isNull(examCacheBean)) {
             throw new BusinessException(ExceptionResultEnum.EXAM_NO);
         }
+        TEExam teExam = teExamService.cacheConvert(examCacheBean);
         List<TEExamActivity> teExamActivityList = null;
         try {
             teExam.setId(null);
@@ -418,7 +425,7 @@ public class TEExamController {
         }
         //首先查询当前用户所要监控的roomCode
         QueryWrapper<TBExamInvigilateUser> examInvigilateUserQueryWrapper = new QueryWrapper<>();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         //如果有监考员角色,只能查看自己所监考的考场,巡考员和管理员则可以查看全部考场
         examInvigilateUserQueryWrapper.lambda().eq(TBExamInvigilateUser::getOrgId, tbUser.getOrgId())
                 .eq(TBExamInvigilateUser::getExamId, examId);
@@ -538,7 +545,8 @@ public class TEExamController {
     @ApiResponses({@ApiResponse(code = 200, message = "{\"taskId\":0}", response = Result.class)})
     public Result scoreCalculate(@ApiParam(value = "批次ID", required = true) @RequestParam Long id) {
         //先查询考试相关信息
-        TEExam teExam = teExamService.getById(id);
+        ExamCacheBean examCacheBean = teExamService.getExamCacheBean(id);
+        TEExam teExam = teExamService.cacheConvert(examCacheBean);
         if (Objects.isNull(teExam)) {
             throw new BusinessException(ExceptionResultEnum.EXAM_NO);
         }

+ 4 - 2
themis-admin/src/main/java/com/qmth/themis/admin/api/TEExamPaperController.java

@@ -1,6 +1,7 @@
 package com.qmth.themis.admin.api;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.qmth.themis.business.cache.bean.ExamCacheBean;
 import com.qmth.themis.business.cache.bean.ExamPaperCacheBean;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.MqDto;
@@ -157,10 +158,11 @@ public class TEExamPaperController {
             transMap.put("createId", tbUser.getId());
             transMap.put("orgId", tbUser.getOrgId());
             //先查询考试相关信息
-            TEExam teExam = teExamService.getById(examId);
-            if (Objects.isNull(teExam)) {
+            ExamCacheBean examCacheBean = teExamService.getExamCacheBean(examId);
+            if (Objects.isNull(examCacheBean)) {
                 throw new BusinessException(ExceptionResultEnum.EXAM_NO);
             }
+            TEExam teExam = teExamService.cacheConvert(examCacheBean);
             transMap.put("objectiveShuffle", objectiveShuffle);
             transMap.put("optionShuffle", optionShuffle);
             transMap.put("audioPlayCount", audioPlayCount);

+ 4 - 1
themis-admin/src/main/java/com/qmth/themis/admin/api/TEExamReexamController.java

@@ -62,6 +62,9 @@ public class TEExamReexamController {
     @Resource
     TEExamStudentService teExamStudentService;
 
+    @Resource
+    CacheService cacheService;
+
     @ApiOperation(value = "重考申请接口")
     @RequestMapping(value = "/apply", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
@@ -252,7 +255,7 @@ public class TEExamReexamController {
                        @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber,
                        @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         //如果有监考员角色,只能查看自己所监考的考场,巡考员和管理员则可以查看全部考场
         Long userId = null;
         if (authDto.getRoleCodes().toString().contains(RoleEnum.INVIGILATE.name())) {

+ 3 - 2
themis-admin/src/main/java/com/qmth/themis/admin/api/TEExamStudentController.java

@@ -308,10 +308,11 @@ public class TEExamStudentController {
             transMap.put("createId", tbUser.getId());
 
             // 先查询考试相关信息
-            TEExam teExam = teExamService.getById(examId);
-            if (Objects.isNull(teExam)) {
+            ExamCacheBean examCacheBean = teExamService.getExamCacheBean(examId);
+            if (Objects.isNull(examCacheBean)) {
                 throw new BusinessException(ExceptionResultEnum.EXAM_NO);
             }
+            TEExam teExam = teExamService.cacheConvert(examCacheBean);
             transMap.put("mode", teExam.getMode());
             transMap.put("orgId", teExam.getOrgId());
             transMap.put("examCount", teExam.getExamCount());

+ 5 - 13
themis-admin/src/main/java/com/qmth/themis/admin/api/TEStudentController.java

@@ -2,18 +2,15 @@ package com.qmth.themis.admin.api;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.google.gson.Gson;
 import com.qmth.themis.business.annotation.ApiJsonObject;
 import com.qmth.themis.business.annotation.ApiJsonProperty;
-import com.qmth.themis.business.constant.SystemConstant;
-import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
 import com.qmth.themis.business.dto.response.TEStudentDto;
 import com.qmth.themis.business.entity.TBUser;
 import com.qmth.themis.business.entity.TEStudent;
 import com.qmth.themis.business.entity.TOeExamRecord;
+import com.qmth.themis.business.service.CacheService;
 import com.qmth.themis.business.service.TEStudentService;
 import com.qmth.themis.business.util.OssUtil;
-import com.qmth.themis.business.util.RedisUtil;
 import com.qmth.themis.business.util.ServletUtil;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
@@ -26,7 +23,6 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
-import java.util.Collections;
 import java.util.Map;
 import java.util.Objects;
 
@@ -46,10 +42,10 @@ public class TEStudentController {
     TEStudentService teStudentService;
 
     @Resource
-    RedisUtil redisUtil;
+    OssUtil ossUtil;
 
     @Resource
-    OssUtil ossUtil;
+    CacheService cacheService;
 
     @ApiOperation(value = "学生查询接口")
     @RequestMapping(value = "/query", method = RequestMethod.POST)
@@ -91,9 +87,7 @@ public class TEStudentController {
         teStudent.setEnable(enable);
         teStudent.setUpdateId(tbUser.getId());
         teStudentService.updateById(teStudent);
-        Gson gson = new Gson();
-        TEStudentCacheDto teStudentCacheDto = gson.fromJson(gson.toJson(teStudent), TEStudentCacheDto.class);
-        redisUtil.setStudent(teStudent.getId(), teStudentCacheDto);
+        cacheService.updateStudentAccountCache(teStudent.getId());
         return ResultUtil.ok(true);
     }
 
@@ -121,9 +115,7 @@ public class TEStudentController {
         teStudent.setPassword(password);
         teStudent.setUpdateId(tbUser.getId());
         teStudentService.updateById(teStudent);
-        Gson gson = new Gson();
-        TEStudentCacheDto teStudentCacheDto = gson.fromJson(gson.toJson(teStudent), TEStudentCacheDto.class);
-        redisUtil.setStudent(teStudent.getId(), teStudentCacheDto);
+        cacheService.updateStudentAccountCache(teStudent.getId());
         return ResultUtil.ok(true);
     }
 

+ 9 - 10
themis-admin/src/main/java/com/qmth/themis/admin/api/TIeInvigilateCallMobileController.java

@@ -16,10 +16,7 @@ import com.qmth.themis.business.dto.MqDto;
 import com.qmth.themis.business.dto.response.TIeExamInvigilateCallDto;
 import com.qmth.themis.business.entity.*;
 import com.qmth.themis.business.enums.*;
-import com.qmth.themis.business.service.MqDtoService;
-import com.qmth.themis.business.service.TEExamStudentService;
-import com.qmth.themis.business.service.TIeExamInvigilateCallService;
-import com.qmth.themis.business.service.TOeExamRecordService;
+import com.qmth.themis.business.service.*;
 import com.qmth.themis.business.util.*;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.enums.Source;
@@ -48,7 +45,6 @@ import java.util.*;
 @RestController
 @RequestMapping("/${prefix.url.admin}/monitor")
 public class TIeInvigilateCallMobileController {
-
     private final static Logger log = LoggerFactory.getLogger(TIeInvigilateCallMobileController.class);
 
     @Resource
@@ -78,6 +74,9 @@ public class TIeInvigilateCallMobileController {
     @Resource
     MqUtil mqUtil;
 
+    @Resource
+    CacheService cacheService;
+
     @ApiOperation(value = "监考监控通话查询接口")
     @RequestMapping(value = "/call/list", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "监考监控信息", response = TIeExamInvigilateCallDto.class)})
@@ -93,7 +92,7 @@ public class TIeInvigilateCallMobileController {
             callStatus = callStatusEnum.name();
         }
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         //如果有监考员角色,只能查看自己所监考的考场,巡考员和管理员则可以查看全部考场
         Long userId = null;
         if (authDto.getRoleCodes().toString().contains(RoleEnum.INVIGILATE.name())) {
@@ -127,7 +126,7 @@ public class TIeInvigilateCallMobileController {
             callStatus = callStatusEnum.name();
         }
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         //如果有监考员角色,只能查看自己所监考的考场,巡考员和管理员则可以查看全部考场
         Long userId = null;
         if (authDto.getRoleCodes().toString().contains(RoleEnum.INVIGILATE.name())) {
@@ -164,13 +163,13 @@ public class TIeInvigilateCallMobileController {
         }
         MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf(String.valueOf(mapParameter.get("source")));
         //获取考试记录缓存
-        String liveUrl = dictionaryConfig.monitorDomain().getPrefix() + "_" + recordId + "_" + source.name().toLowerCase();
+        String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         if (Objects.isNull(ExamRecordCacheUtil.getMonitorStatus(recordId, source))) {
             throw new BusinessException("推流状态为空");
         }
         Long timestamp = System.currentTimeMillis();
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.CALLING, timestamp);
-        tOeExamRecordService.sendExamRecordDataSaveMq(recordId,timestamp);
+        tOeExamRecordService.sendExamRecordDataSaveMq(recordId, timestamp);
         String monitorKey = ExamRecordCacheUtil.getMonitorKey(recordId);
         MonitorStatusSourceEnum status = ExamRecordCacheUtil.getMonitorStatus(recordId, source);
         TIeExamInvigilateCallLog tIeExamInvigilateCallLog = new TIeExamInvigilateCallLog(recordId, source, liveUrl,
@@ -200,7 +199,7 @@ public class TIeInvigilateCallMobileController {
         }
         MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf(String.valueOf(mapParameter.get("source")));
         //获取考试记录缓存
-        String liveUrl = dictionaryConfig.monitorDomain().getPrefix() + "_" + recordId + "_" + source.name().toLowerCase();
+        String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         ExamRecordStatusEnum statusEnum = ExamRecordCacheUtil.getStatus(recordId);
         if (Objects.isNull(statusEnum) || Objects.equals(statusEnum, ExamRecordStatusEnum.FINISHED) || Objects
                 .equals(statusEnum, ExamRecordStatusEnum.PERSISTED)) {

+ 15 - 11
themis-admin/src/main/java/com/qmth/themis/admin/api/TIeInvigilateController.java

@@ -18,6 +18,7 @@ import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.AuthDto;
 import com.qmth.themis.business.dto.ExamPropCountDto;
 import com.qmth.themis.business.dto.MqDto;
+import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
 import com.qmth.themis.business.entity.*;
 import com.qmth.themis.business.enums.*;
 import com.qmth.themis.business.excel.ExportUtils;
@@ -100,6 +101,9 @@ public class TIeInvigilateController {
     @Resource
     DictionaryConfig dictionaryConfig;
 
+    @Resource
+    CacheService cacheService;
+
     @ApiOperation(value = "实时监控台视频列表接口")
     @RequestMapping(value = "/list/video", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "监考监控信息", response = InvigilateListVideoBean.class)})
@@ -117,7 +121,7 @@ public class TIeInvigilateController {
                             @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber,
                             @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         //如果有监考员角色,只能查看自己所监考的考场,巡考员和管理员则可以查看全部考场
         Long userId = null;
         if (authDto.getRoleCodes().toString().contains(RoleEnum.INVIGILATE.name())) {
@@ -161,7 +165,7 @@ public class TIeInvigilateController {
                     if (Objects.nonNull(monitorVideoSource)) {
                         source = MonitorVideoSourceEnum.valueOf(monitorVideoSource);
                     }
-                    String monitorLiveUrl = dictionaryConfig.monitorDomain().getPrefix() + "_" + s.getExamRecordId() + "_" + source.name().toLowerCase();
+                    String monitorLiveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), s.getExamRecordId(), source);
                     s.setMonitorLiveUrl(monitorLiveUrl);
                     WebsocketStatusEnum websocketStatusEnum = ExamRecordCacheUtil.getClientWebsocketStatus(s.getExamRecordId());
                     if (Objects.nonNull(websocketStatusEnum)) {
@@ -189,7 +193,7 @@ public class TIeInvigilateController {
             throw new BusinessException("随机数不能为空");
         }
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         //如果有监考员角色,只能查看自己所监考的考场,巡考员和管理员则可以查看全部考场
         Long userId = null;
         if (authDto.getRoleCodes().toString().contains(RoleEnum.INVIGILATE.name())) {
@@ -203,7 +207,7 @@ public class TIeInvigilateController {
             }
             ExamCacheBean finalExamCacheBean = examCacheBean;
             invigilateListVideoBeanList.forEach(s -> {
-                String monitorLiveUrl = dictionaryConfig.monitorDomain().getPrefix() + "_" + s.getExamRecordId() + "_" + MonitorVideoSourceEnum.CLIENT_CAMERA.name().toLowerCase();
+                String monitorLiveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), s.getExamRecordId(), MonitorVideoSourceEnum.CLIENT_CAMERA);
                 if (Objects.nonNull(monitorLiveUrl)) {
                     s.setMonitorLiveUrl(monitorLiveUrl);
                 }
@@ -245,7 +249,7 @@ public class TIeInvigilateController {
                               @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber,
                               @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         //如果有监考员角色,只能查看自己所监考的考场,巡考员和管理员则可以查看全部考场
         Long userId = null;
         if (authDto.getRoleCodes().toString().contains(RoleEnum.INVIGILATE.name())) {
@@ -282,7 +286,7 @@ public class TIeInvigilateController {
             breachStatus = Objects.isNull(ExamRecordCacheUtil.getBreachStatus(examRecordId)) ? 1 : ExamRecordCacheUtil.getBreachStatus(examRecordId);
         }
         ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(examStudentId);
-        TEStudent teStudent = teStudentService.getById(examStudentCacheBean.getStudentId());
+        TEStudentCacheDto teStudent = cacheService.addStudentAccountCache(examStudentCacheBean.getStudentId());
         String basePhotoPath = ossUtil.getAliYunOssPublicDomain().getPublicUrl() + File.separator + teStudent.getBasePhotoPath();
         String identity = examStudentCacheBean.getIdentity();
         String examStudentName = examStudentCacheBean.getName();
@@ -326,7 +330,7 @@ public class TIeInvigilateController {
 
         //2020/11/24新增管理员不清除预警状态
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         if (!authDto.getRoleCodes().toString().contains(RoleEnum.ADMIN.name())) {
             //清除预警未阅状态
             UpdateWrapper<TIeInvigilateWarnInfo> tIeExamInvigilateNoticeUpdateWrapper = new UpdateWrapper<>();
@@ -396,7 +400,7 @@ public class TIeInvigilateController {
                              @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber,
                              @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         //如果有监考员角色,只能查看自己所监考的考场,巡考员和管理员则可以查看全部考场
         Long userId = null;
         if (authDto.getRoleCodes().toString().contains(RoleEnum.INVIGILATE.name())) {
@@ -438,7 +442,7 @@ public class TIeInvigilateController {
                                @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber,
                                @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         //如果有监考员角色,只能查看自己所监考的考场,巡考员和管理员则可以查看全部考场
         Long userId = null;
         if (authDto.getRoleCodes().toString().contains(RoleEnum.INVIGILATE.name())) {
@@ -457,7 +461,7 @@ public class TIeInvigilateController {
                                    @ApiParam(value = "姓名", required = false) @RequestParam(required = false) String name,
                                    @ApiParam(value = "证件号", required = false) @RequestParam(required = false) String identity) throws Exception {
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         //如果有监考员角色,只能查看自己所监考的考场,巡考员和管理员则可以查看全部考场
         Long userId = null;
         if (authDto.getRoleCodes().toString().contains(RoleEnum.INVIGILATE.name())) {
@@ -566,7 +570,7 @@ public class TIeInvigilateController {
         }
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
         //发送mq给客户端监考消息start
-        mapParameter.put("formUserId",tbUser.getId());
+        mapParameter.put("formUserId", tbUser.getId());
         MqDto mqDto = new MqDto(mqUtil.getMqGroupDomain().getTopic(), MqTagEnum.OE_IM_CLUSTERING.name(), recordId, MqTagEnum.OE_IM_CLUSTERING, String.valueOf(recordId), mapParameter, tbUser.getName());
         mqDtoService.assembleSendOneOrderMsg(mqDto);
         //发送mq给客户端监考消息end

+ 9 - 8
themis-admin/src/main/java/com/qmth/themis/admin/api/TIeInvigilateWarnInfoController.java

@@ -11,6 +11,7 @@ import com.qmth.themis.business.dto.response.TIeWarningNotifyDto;
 import com.qmth.themis.business.entity.TBUser;
 import com.qmth.themis.business.entity.TIeInvigilateWarnInfo;
 import com.qmth.themis.business.enums.RoleEnum;
+import com.qmth.themis.business.service.CacheService;
 import com.qmth.themis.business.service.TIeInvigilateWarnInfoService;
 import com.qmth.themis.business.service.TOeExamRecordService;
 import com.qmth.themis.business.util.RedisUtil;
@@ -37,15 +38,15 @@ import java.util.*;
 @RequestMapping("/${prefix.url.admin}/invigilate/warn")
 public class TIeInvigilateWarnInfoController {
 
-    @Resource
-    RedisUtil redisUtil;
-
     @Resource
     TIeInvigilateWarnInfoService tIeInvigilateWarnInfoService;
 
     @Resource
     TOeExamRecordService tOeExamRecordService;
 
+    @Resource
+    CacheService cacheService;
+
     @ApiOperation(value = "预警提醒接口")
     @RequestMapping(value = "/notify", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "{\"count\":1}", response = Result.class)})
@@ -53,7 +54,7 @@ public class TIeInvigilateWarnInfoController {
                          @ApiParam(value = "考试场次id", required = false) @RequestParam(required = false) Long examActivityId,
                          @ApiParam(value = "虚拟考场代码", required = false) @RequestParam(required = false) String roomCode) {
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         //如果有监考员角色,只能查看自己所监考的考场,巡考员和管理员则可以查看全部考场
         Long userId = null;
         if (authDto.getRoleCodes().toString().contains(RoleEnum.INVIGILATE.name())) {
@@ -81,7 +82,7 @@ public class TIeInvigilateWarnInfoController {
                        @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber,
                        @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         //如果有监考员角色,只能查看自己所监考的考场,巡考员和管理员则可以查看全部考场
         Long userId = null;
         if (authDto.getRoleCodes().toString().contains(RoleEnum.INVIGILATE.name())) {
@@ -95,7 +96,7 @@ public class TIeInvigilateWarnInfoController {
     @ApiResponses({@ApiResponse(code = 200, message = "预警通知信息", response = TIeWarningNotifyDto.class)})
     public Result warningMessage(@ApiParam(value = "考试批次id", required = false) @RequestParam(required = false) Long examId) {
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         //如果有监考员角色,只能查看自己所监考的考场,巡考员和管理员则可以查看全部考场
         Long userId = null;
         if (authDto.getRoleCodes().toString().contains(RoleEnum.INVIGILATE.name())) {
@@ -117,7 +118,7 @@ public class TIeInvigilateWarnInfoController {
         }
         //2020/11/24新增管理员不清除预警状态
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         if (!authDto.getRoleCodes().toString().contains(RoleEnum.ADMIN.name())) {
             List<String> warningIds = (List<String>) mapParameter.get("warningIds");
             if (warningIds.size() > 0) {
@@ -154,7 +155,7 @@ public class TIeInvigilateWarnInfoController {
                                           @ApiParam(value = "预警量min", required = false) @RequestParam(required = false) Integer minWarningCount,
                                           @ApiParam(value = "预警量max", required = false) @RequestParam(required = false) Integer maxWarningCount) {
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.userOauth + tbUser.getId());
+        AuthDto authDto = cacheService.addAccountAuthCache(tbUser.getId());
         //如果有监考员角色,只能查看自己所监考的考场,巡考员和管理员则可以查看全部考场
         Long userId = null;
         if (authDto.getRoleCodes().toString().contains(RoleEnum.INVIGILATE.name())) {

+ 0 - 3
themis-admin/src/main/java/com/qmth/themis/admin/api/TIeReportController.java

@@ -34,9 +34,6 @@ public class TIeReportController {
     @Resource
     private TIeReportService reportService;
 
-    @Resource
-    RedisUtil redisUtil;
-
     @ApiOperation(value = "考试概览")
     @RequestMapping(value = "/exam_view", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})

+ 15 - 3
themis-business/src/main/java/com/qmth/themis/business/config/RedisConfig.java

@@ -43,9 +43,19 @@ public class RedisConfig {
     private Map<String, RedisCacheConfiguration> getRedisCacheConfigurationMap() {
         Map<String, RedisCacheConfiguration> redisCacheConfigurationMap = new HashMap<>();
         redisCacheConfigurationMap.put(SystemConstant.userOauth,
-                this.getRedisCacheConfigurationWithTtl(SystemConstant.REDIS_OAUTH_EXPIRE_TIME));
+                this.getRedisCacheConfigurationWithTtl(SystemConstant.REDIS_EXPIRE_TIME));
         redisCacheConfigurationMap.put(SystemConstant.studentOauth,
-                this.getRedisCacheConfigurationWithTtl(SystemConstant.REDIS_OAUTH_EXPIRE_TIME));
+                this.getRedisCacheConfigurationWithTtl(SystemConstant.REDIS_EXPIRE_TIME));
+        redisCacheConfigurationMap.put(SystemConstant.userAccount,
+                this.getRedisCacheConfigurationWithTtl(SystemConstant.REDIS_EXPIRE_TIME));
+        redisCacheConfigurationMap.put(SystemConstant.studentAccount,
+                this.getRedisCacheConfigurationWithTtl(SystemConstant.REDIS_EXPIRE_TIME));
+        redisCacheConfigurationMap.put(SystemConstant.orgCache,
+                this.getRedisCacheConfigurationWithTtl(SystemConstant.REDIS_EXPIRE_TIME));
+        redisCacheConfigurationMap.put(SystemConstant.orgCodeCache,
+                this.getRedisCacheConfigurationWithTtl(SystemConstant.REDIS_EXPIRE_TIME));
+        redisCacheConfigurationMap.put(SystemConstant.roleCache,
+                this.getRedisCacheConfigurationWithTtl(SystemConstant.REDIS_EXPIRE_TIME));
         redisCacheConfigurationMap.put(SystemConstant.configCache,
                 this.getRedisCacheConfigurationWithTtl(SystemConstant.REDIS_EXPIRE_TIME));
         return redisCacheConfigurationMap;
@@ -66,7 +76,9 @@ public class RedisConfig {
                 RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
                 .serializeValuesWith(
                         RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer))
-                .entryTtl(Duration.ofSeconds(seconds));
+                .entryTtl(Duration.ofSeconds(seconds))
+                .disableCachingNullValues()
+                .computePrefixWith(cacheName -> cacheName + ":");
         return redisCacheConfiguration;
     }
 

+ 21 - 9
themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java

@@ -1,6 +1,7 @@
 package com.qmth.themis.business.constant;
 
 import com.qmth.themis.business.dto.ExpireTimeDTO;
+import com.qmth.themis.business.enums.MonitorVideoSourceEnum;
 import com.qmth.themis.common.contanst.Constants;
 import com.qmth.themis.common.enums.Platform;
 import com.qmth.themis.common.enums.Source;
@@ -231,9 +232,7 @@ public class SystemConstant {
 
     public static final long REDIS_PHONE_EXPIRE_TIME = 60L * 43200L;//过期时间30天
 
-    public static final long REDIS_OAUTH_EXPIRE_TIME = 2 * 60L * 60L;
-
-    public static final long REDIS_DEFAULT_EXPIRE_TIME = 1 * 60L * 60L;
+    public static final long REDIS_DEFAULT_EXPIRE_TIME = 12 * 60L * 60L;
 
     /**
      * rocket mq
@@ -296,13 +295,15 @@ public class SystemConstant {
     /**
      * 缓存配置
      */
-    public static final String userOauth = "user:oauth:cache::";
-
-    public static final String studentOauth = "student:oauth:cache::";
+    public static final String userOauth = "user:oauth:cache";
+    public static final String studentOauth = "student:oauth:cache";
+    public static final String userAccount = "user:account:cache";
+    public static final String studentAccount = "student:account:cache";
+    public static final String orgCache = "org:cache";
+    public static final String orgCodeCache = "org:code:cache";
+    public static final String roleCache = "role:cache";
+    public static final String configCache = "config:cache";
 
-    public static final String configCache = "config:cache::";
-
-//    public static final String SQL_UNIQUE_ERROR = "#23000";
     //    /**
     //     * ehcache配置
     //     */
@@ -424,4 +425,15 @@ public class SystemConstant {
         return String.format("%02d", hour) + ":" + String.format("%02d", min) + ":" + String.format("%02d", sec);
     }
 
+    /**
+     * 设置streamId
+     *
+     * @param prefix
+     * @param recordId
+     * @param monitorVideoSource
+     * @return
+     */
+    public static String setStreamId(String prefix, Long recordId, MonitorVideoSourceEnum monitorVideoSource) {
+        return prefix + "_" + recordId + "_" + monitorVideoSource.name().toLowerCase();
+    }
 }

+ 2 - 1
themis-business/src/main/java/com/qmth/themis/business/dto/response/TEExamActivityDto.java

@@ -7,6 +7,7 @@ import com.qmth.themis.business.cache.bean.ExamActivityCacheBean;
 import com.qmth.themis.business.cache.bean.ExamCacheBean;
 import com.qmth.themis.business.cache.bean.ExamCourseCacheBean;
 import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
+import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.enums.EntryAuthenticationPolicyEnum;
 import com.qmth.themis.business.enums.ExamModeEnum;
 import com.qmth.themis.business.enums.HardwareTestEnum;
@@ -223,7 +224,7 @@ public class TEExamActivityDto implements Serializable {
             List<String> videoSources = Arrays.asList(monitorVideoSource.trim().toUpperCase().split(","));
             List<MonitorStreamDto> monitorStreamDtoList = new ArrayList<>();
             videoSources.forEach(s -> {
-                monitorStreamDtoList.add(new MonitorStreamDto(MonitorVideoSourceEnum.valueOf(s), prefix + "_" + recordId + "_" + MonitorVideoSourceEnum.valueOf(s).name().toLowerCase()));
+                monitorStreamDtoList.add(new MonitorStreamDto(MonitorVideoSourceEnum.valueOf(s), SystemConstant.setStreamId(prefix, recordId, MonitorVideoSourceEnum.valueOf(s))));
             });
             this.setMonitorVideoSource(monitorStreamDtoList);
             //加入monitorAudioEnable逻辑

+ 99 - 4
themis-business/src/main/java/com/qmth/themis/business/service/CacheService.java

@@ -1,6 +1,9 @@
 package com.qmth.themis.business.service;
 
 import com.qmth.themis.business.dto.AuthDto;
+import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
+import com.qmth.themis.business.entity.TBOrg;
+import com.qmth.themis.business.entity.TBUser;
 
 /**
  * @Description: 缓存 服务类
@@ -11,13 +14,82 @@ import com.qmth.themis.business.dto.AuthDto;
  */
 public interface CacheService {
 
+    /**
+     * 添加机构缓存
+     *
+     * @param orgId
+     * @return
+     */
+    public TBOrg addOrgCache(Long orgId);
+
+    /**
+     * 更新机构缓存
+     *
+     * @param orgId
+     * @return
+     */
+    public TBOrg updateOrgCache(Long orgId);
+
+    /**
+     * 添加机构编码缓存
+     *
+     * @param code
+     * @return
+     */
+    public TBOrg addOrgCodeCache(String code);
+
+    /**
+     * 更新机构编码缓存
+     *
+     * @param code
+     * @return
+     */
+    public TBOrg updateOrgCodeCache(String code);
+
+    /**
+     * 删除机构缓存
+     *
+     * @param orgId
+     */
+    public void removeOrgCache(Long orgId);
+
+    /**
+     * 删除机构编码缓存
+     *
+     * @param code
+     */
+    public void removeOrgCodeCache(String code);
+
+    /**
+     * 添加用户鉴权缓存
+     *
+     * @param userId
+     * @return
+     */
+    public AuthDto addAccountAuthCache(Long userId);
+
+    /**
+     * 删除用户鉴权缓存
+     *
+     * @param userId
+     */
+    public void removeAccountAuthCache(Long userId);
+
     /**
      * 添加用户缓存
      *
      * @param userId
      * @return
      */
-    public AuthDto addAccountCache(Long userId);
+    public TBUser addAccountCache(Long userId);
+
+    /**
+     * 更新用户缓存
+     *
+     * @param userId
+     * @return
+     */
+    public TBUser updateAccountCache(Long userId);
 
     /**
      * 删除用户缓存
@@ -26,18 +98,41 @@ public interface CacheService {
      */
     public void removeAccountCache(Long userId);
 
+    /**
+     * 添加学生鉴权缓存
+     *
+     * @param studentId
+     * @return
+     */
+    public AuthDto addStudentAuthCache(Long studentId);
+
+    /**
+     * 删除学生鉴权缓存
+     *
+     * @param studentId
+     */
+    public void removeStudentAuthCache(Long studentId);
+
     /**
      * 添加学生缓存
      *
      * @param studentId
      * @return
      */
-    public AuthDto addStudentCache(Long studentId);
+    public TEStudentCacheDto addStudentAccountCache(Long studentId);
+
+    /**
+     * 更新学生缓存
+     *
+     * @param studentId
+     * @return
+     */
+    public TEStudentCacheDto updateStudentAccountCache(Long studentId);
 
     /**
      * 删除学生缓存
      *
-     * @param userId
+     * @param studentId
      */
-    public void removeStudentCache(Long userId);
+    public void removeStudentAccountCache(Long studentId);
 }

+ 7 - 2
themis-business/src/main/java/com/qmth/themis/business/service/TEExamService.java

@@ -15,7 +15,6 @@ import com.qmth.themis.business.enums.ScoreStatusEnum;
 import com.qmth.themis.business.enums.SystemOperationEnum;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 
@@ -218,5 +217,11 @@ public interface TEExamService extends IService<TEExam> {
 
     public IPage<OpenExamBean> examQueryForOpen(Page<OpenExamBean> ipage, Long examId, String examCode);
 
-
+    /**
+     * 缓存转换
+     *
+     * @param examCacheBean
+     * @return
+     */
+    public TEExam cacheConvert(ExamCacheBean examCacheBean);
 }

+ 168 - 18
themis-business/src/main/java/com/qmth/themis/business/service/impl/CacheServiceImpl.java

@@ -1,17 +1,20 @@
 package com.qmth.themis.business.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.google.gson.Gson;
+import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.AuthDto;
+import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
 import com.qmth.themis.business.entity.*;
 import com.qmth.themis.business.enums.RoleEnum;
 import com.qmth.themis.business.service.*;
-import com.qmth.themis.business.util.RedisUtil;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.CachePut;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
@@ -51,8 +54,79 @@ public class CacheServiceImpl implements CacheService {
     @Resource
     TEStudentService teStudentService;
 
-    @Resource
-    RedisUtil redisUtil;
+    /**
+     * 添加机构缓存
+     *
+     * @param orgId
+     * @return
+     */
+    @Override
+    @Cacheable(value = SystemConstant.orgCache, key = "#p0")
+    public TBOrg addOrgCache(Long orgId) {
+        return tbOrgService.getById(orgId);
+    }
+
+    /**
+     * 更新机构缓存
+     *
+     * @param orgId
+     * @return
+     */
+    @Override
+    @CachePut(value = SystemConstant.orgCache, key = "#p0", condition = "#result != null")
+    public TBOrg updateOrgCache(Long orgId) {
+        return tbOrgService.getById(orgId);
+    }
+
+    /**
+     * 添加机构编码缓存
+     *
+     * @param code
+     * @return
+     */
+    @Override
+    @Cacheable(value = SystemConstant.orgCodeCache, key = "#p0")
+    public TBOrg addOrgCodeCache(String code) {
+        QueryWrapper<TBOrg> tbOrgQueryWrapper = new QueryWrapper<>();
+        tbOrgQueryWrapper.lambda().eq(TBOrg::getCode, code);
+        return tbOrgService.getOne(tbOrgQueryWrapper);
+    }
+
+    /**
+     * 更新机构编码缓存
+     *
+     * @param code
+     * @return
+     */
+    @Override
+    @CachePut(value = SystemConstant.orgCodeCache, key = "#p0", condition = "#result != null")
+    public TBOrg updateOrgCodeCache(String code) {
+        QueryWrapper<TBOrg> tbOrgQueryWrapper = new QueryWrapper<>();
+        tbOrgQueryWrapper.lambda().eq(TBOrg::getCode, code);
+        return tbOrgService.getOne(tbOrgQueryWrapper);
+    }
+
+    /**
+     * 删除机构缓存
+     *
+     * @param orgId
+     */
+    @Override
+    @CacheEvict(value = SystemConstant.orgCache, key = "#p0")
+    public void removeOrgCache(Long orgId) {
+
+    }
+
+    /**
+     * 删除机构编码缓存
+     *
+     * @param code
+     */
+    @Override
+    @CacheEvict(value = SystemConstant.orgCodeCache, key = "#p0")
+    public void removeOrgCodeCache(String code) {
+
+    }
 
     /**
      * 添加用户缓存
@@ -61,11 +135,12 @@ public class CacheServiceImpl implements CacheService {
      * @return
      */
     @Override
-    @Cacheable(value = "user:oauth:cache", key = "#p0")
-    public AuthDto addAccountCache(Long userId) {
+    @Cacheable(value = SystemConstant.userOauth, key = "#p0")
+    public AuthDto addAccountAuthCache(Long userId) {
         AuthDto authDto = null;
         try {
-            TBUser user = tbUserService.getById(userId);
+            CacheService cacheService = SpringContextHolder.getBean(CacheService.class);
+            TBUser user = cacheService.addAccountCache(userId);
             if (Objects.isNull(user)) {
                 throw new BusinessException(ExceptionResultEnum.USER_NO);
             }
@@ -74,7 +149,7 @@ public class CacheServiceImpl implements CacheService {
             uWrapper.lambda().eq(TBUserRole::getUserId, user.getId());
             List<TBUserRole> tbUserRoleList = tbUserRoleService.list(uWrapper);
             if (Objects.nonNull(tbUserRoleList)) {
-                TBOrg tbOrg = Objects.isNull(redisUtil.getOrg(user.getOrgId())) ? tbOrgService.getById(user.getOrgId()) : (TBOrg) redisUtil.getOrg(user.getOrgId());
+                TBOrg tbOrg = this.addOrgCache(user.getOrgId());
                 //根据角色名查权限
                 Set<String> roleCodes = tbUserRoleList.stream().map(s -> s.getRoleCode()).collect(Collectors.toSet());
                 QueryWrapper<TBRolePrivilege> rpWrapper = new QueryWrapper<>();
@@ -88,38 +163,74 @@ public class CacheServiceImpl implements CacheService {
             }
         } catch (Exception e) {
             log.error("请求出错", e);
-            throw new BusinessException("添加用户缓存失败");
+            throw new BusinessException("添加用户鉴权缓存失败");
         }
         return authDto;
     }
 
+    /**
+     * 删除用户鉴权缓存
+     *
+     * @param userId
+     */
+    @Override
+    @CacheEvict(value = SystemConstant.userOauth, key = "#p0")
+    public void removeAccountAuthCache(Long userId) {
+
+    }
+
+    /**
+     * 添加用户缓存
+     *
+     * @param userId
+     * @return
+     */
+    @Override
+    @Cacheable(value = SystemConstant.userAccount, key = "#p0")
+    public TBUser addAccountCache(Long userId) {
+        return tbUserService.getById(userId);
+    }
+
+    /**
+     * 更新用户缓存
+     *
+     * @param userId
+     * @return
+     */
+    @Override
+    @CachePut(value = SystemConstant.userAccount, key = "#p0", condition = "#result != null")
+    public TBUser updateAccountCache(Long userId) {
+        return tbUserService.getById(userId);
+    }
+
     /**
      * 删除用户缓存
      *
      * @param userId
      */
     @Override
-    @CacheEvict(value = "user:oauth:cache", key = "#p0")
+    @CacheEvict(value = SystemConstant.userAccount, key = "#p0")
     public void removeAccountCache(Long userId) {
 
     }
 
     /**
-     * 添加学生缓存
+     * 添加学生鉴权缓存
      *
      * @param studentId
      * @return
      */
     @Override
-    @Cacheable(value = "student:oauth:cache", key = "#p0")
-    public AuthDto addStudentCache(Long studentId) {
+    @Cacheable(value = SystemConstant.studentOauth, key = "#p0")
+    public AuthDto addStudentAuthCache(Long studentId) {
         AuthDto authDto = null;
         try {
-            TEStudent teStudent = teStudentService.getById(studentId);
-            if (Objects.isNull(teStudent)) {
+            CacheService cacheService = SpringContextHolder.getBean(CacheService.class);
+            TEStudentCacheDto teStudentCacheDto = cacheService.addStudentAccountCache(studentId);
+            if (Objects.isNull(teStudentCacheDto)) {
                 throw new BusinessException(ExceptionResultEnum.STUDENT_NO);
             }
-            TBOrg tbOrg = tbOrgService.getById(teStudent.getOrgId());
+            TBOrg tbOrg = cacheService.addOrgCache(teStudentCacheDto.getOrgId());
             //根据学生角色查权限
             QueryWrapper<TBRolePrivilege> rpWrapper = new QueryWrapper<>();
             rpWrapper.lambda().eq(TBRolePrivilege::getRoleCode, RoleEnum.STUDENT.name());
@@ -133,19 +244,58 @@ public class CacheServiceImpl implements CacheService {
             authDto = new AuthDto(roleCodes, tbPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()), tbOrg);
         } catch (Exception e) {
             log.error("请求出错", e);
-            throw new BusinessException("添加学生缓存失败");
+            throw new BusinessException("添加学生鉴权缓存失败");
         }
         return authDto;
     }
 
+    /**
+     * 删除学生鉴权缓存
+     *
+     * @param studentId
+     */
+    @Override
+    @CacheEvict(value = SystemConstant.studentOauth, key = "#p0")
+    public void removeStudentAuthCache(Long studentId) {
+
+    }
+
+    /**
+     * 添加学生缓存
+     *
+     * @param studentId
+     * @return
+     */
+    @Override
+    @Cacheable(value = SystemConstant.studentAccount, key = "#p0")
+    public TEStudentCacheDto addStudentAccountCache(Long studentId) {
+        TEStudent teStudent = teStudentService.getById(studentId);
+        Gson gson = new Gson();
+        return gson.fromJson(gson.toJson(teStudent), TEStudentCacheDto.class);
+    }
+
+    /**
+     * 更新学生缓存
+     *
+     * @param studentId
+     * @return
+     */
+    @Override
+    @CachePut(value = SystemConstant.studentAccount, key = "#p0", condition = "#result != null")
+    public TEStudentCacheDto updateStudentAccountCache(Long studentId) {
+        TEStudent teStudent = teStudentService.getById(studentId);
+        Gson gson = new Gson();
+        return gson.fromJson(gson.toJson(teStudent), TEStudentCacheDto.class);
+    }
+
     /**
      * 删除学生缓存
      *
      * @param studentId
      */
     @Override
-    @CacheEvict(value = "student:oauth:cache", key = "#p0")
-    public void removeStudentCache(Long studentId) {
+    @CacheEvict(value = SystemConstant.studentAccount, key = "#p0")
+    public void removeStudentAccountCache(Long studentId) {
 
     }
 }

+ 2 - 1
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEConfigServiceImpl.java

@@ -1,6 +1,7 @@
 package com.qmth.themis.business.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dao.TEConfigMapper;
 import com.qmth.themis.business.entity.TEConfig;
 import com.qmth.themis.business.service.TEConfigService;
@@ -26,7 +27,7 @@ public class TEConfigServiceImpl extends ServiceImpl<TEConfigMapper, TEConfig> i
      * @return
      */
     @Override
-    @Cacheable(value = "config:cache", key = "methodName")
+    @Cacheable(value = SystemConstant.configCache, key = "methodName")
     public TEConfig getGlobalConfig() {
         List<TEConfig> teConfigList = this.list();
         return Objects.isNull(teConfigList) || teConfigList.size() == 0 ? null : teConfigList.get(0);

+ 4 - 2
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamActivityServiceImpl.java

@@ -6,6 +6,7 @@ import com.qmth.themis.business.cache.bean.ExamActivityCacheBean;
 import com.qmth.themis.business.cache.bean.ExamCacheBean;
 import com.qmth.themis.business.cache.bean.ExamCourseCacheBean;
 import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
+import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dao.TEExamActivityMapper;
 import com.qmth.themis.business.dto.MqDto;
 import com.qmth.themis.business.dto.response.MonitorStreamDto;
@@ -188,7 +189,7 @@ public class TEExamActivityServiceImpl extends ServiceImpl<TEExamActivityMapper,
             List<String> videoSources = Arrays.asList(teExamActivityDto.getMonitorVideoSourceStr().trim().toUpperCase().replaceAll(" ", "").split(","));
             List<MonitorStreamDto> monitorStreamDtoList = new ArrayList<>();
             videoSources.forEach(s -> {
-                monitorStreamDtoList.add(new MonitorStreamDto(MonitorVideoSourceEnum.valueOf(s), prefix + "_" + recordId + "_" + MonitorVideoSourceEnum.valueOf(s).name().toLowerCase()));
+                monitorStreamDtoList.add(new MonitorStreamDto(MonitorVideoSourceEnum.valueOf(s), SystemConstant.setStreamId(prefix, recordId, MonitorVideoSourceEnum.valueOf(s))));
             });
             teExamActivityDto.setMonitorVideoSource(monitorStreamDtoList);
             teExamActivityDto.setMonitorAudioEnable(examCache.getMonitorAudioEnable());
@@ -292,7 +293,8 @@ public class TEExamActivityServiceImpl extends ServiceImpl<TEExamActivityMapper,
         try {
             TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
             examId = teExamActivityList.get(0).getExamId();
-            TEExam teExam = teExamService.getById(teExamActivityList.get(0).getExamId());
+            ExamCacheBean examCacheBean = teExamService.getExamCacheBean(teExamActivityList.get(0).getExamId());
+            TEExam teExam = teExamService.cacheConvert(examCacheBean);
             if (Objects.nonNull(teExam.getMonitorStatus()) && Objects
                     .equals(teExam.getMonitorStatus(), InvigilateMonitorStatusEnum.FINISHED)) {
                 throw new BusinessException("监考结束的考试场次不可以修改");

+ 17 - 4
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamServiceImpl.java

@@ -6,6 +6,7 @@ import com.aliyun.oss.common.utils.BinaryUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.gson.Gson;
 import com.qmth.themis.business.bean.admin.OpenExamBean;
 import com.qmth.themis.business.bean.exam.*;
 import com.qmth.themis.business.cache.*;
@@ -110,6 +111,9 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
     @Resource
     MonitorUtil monitorUtil;
 
+    @Resource
+    CacheService cacheService;
+
     /**
      * 查询考试批次
      *
@@ -1153,10 +1157,7 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
             throw new BusinessException(ExceptionResultEnum.EXAM_STATUS_UPDATE_ERROR);
         }
         //更新未完成考试记录id
-        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) redisUtil.getStudent(es.getStudentId());
-        ExamingDataCacheUtil.deleteUnFinishedRecordId(studentId);
-        redisUtil.setStudent(teStudentCacheDto.getId(), teStudentCacheDto);
-
+        TEStudentCacheDto teStudentCacheDto = cacheService.updateStudentAccountCache(es.getStudentId());
         MqDto mobileMqDto = new MqDto(mqUtil.getMqGroupDomain().getTopic(), MqTagEnum.EXAM_STOP.name(), recordId, MqTagEnum.EXAM_STOP, String.valueOf(recordId), Collections.singletonMap(SystemConstant.RECORD_ID, recordId), String.valueOf(recordId));
         mqDtoService.assembleSendOneOrderMsg(mobileMqDto);
         //异步持久化
@@ -1502,4 +1503,16 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
     public IPage<OpenExamBean> examQueryForOpen(Page<OpenExamBean> ipage, Long examId, String examCode) {
         return teExamMapper.examQueryForOpen(ipage, examId, examCode);
     }
+
+    /**
+     * 缓存转换
+     *
+     * @param examCacheBean
+     * @return
+     */
+    @Override
+    public TEExam cacheConvert(ExamCacheBean examCacheBean) {
+        Gson gson = new Gson();
+        return gson.fromJson(gson.toJson(examCacheBean), TEExam.class);
+    }
 }

+ 4 - 4
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEMobileServiceImpl.java

@@ -96,7 +96,7 @@ public class TEMobileServiceImpl implements TEMobileService {
             throw new BusinessException(ExceptionResultEnum.EXAM_ALREADY_FINISHED);
         }
         String deviceId = ServletUtil.getRequestDeviceId();
-        AuthDto authDto = cacheService.addStudentCache(es.getStudentId());
+        AuthDto authDto = cacheService.addStudentAuthCache(es.getStudentId());
         // 生成token
         String token = RandomStringUtils.randomAlphanumeric(32);
         String sessionId = ret.getSessionId();
@@ -133,12 +133,12 @@ public class TEMobileServiceImpl implements TEMobileService {
         ret.setMonitorKey(ExamRecordCacheUtil.getMonitorKey(recordId));
         ret.setMonitorVideoSource(monitorVideoSource);
         ret.setMonitorAudioEnable(getMonitorAudioEnable(recordId, monitorVideoSource));
-        ret.setMonitorStreamId(monitorUtil.getMonitorDomain().getPrefix() + "_" + recordId + "_" + monitorVideoSource.name().toLowerCase());
+        ret.setMonitorStreamId(SystemConstant.setStreamId(monitorUtil.getMonitorDomain().getPrefix(), recordId, monitorVideoSource));
         Source sourceEnum = monitorVideoSource.getSessionSource();
         ExamStudentCacheBean es = examStudentService
                 .getExamStudentCacheBean(ExamRecordCacheUtil.getExamStudentId(ret.getRecordId()));
         String userType = MobileAuthCacheUtil.getUserType(mode, code);
-        AuthDto authDto = cacheService.addStudentCache(es.getStudentId());
+        AuthDto authDto = cacheService.addStudentAuthCache(es.getStudentId());
         String sessionId = SessionUtil
                 .digest(es.getStudentId(), Math.abs(authDto.getRoleCodes().toString().hashCode()), sourceEnum);
         if (Objects.nonNull(userType) && userType.contains(RoleEnum.STUDENT.name())) {
@@ -164,7 +164,7 @@ public class TEMobileServiceImpl implements TEMobileService {
         ExamStudentCacheBean es = examStudentService
                 .getExamStudentCacheBean(ExamRecordCacheUtil.getExamStudentId(recordId));
         Source sourceEnum = Source.OE_ANSWER;
-        AuthDto authDto = cacheService.addStudentCache(es.getStudentId());
+        AuthDto authDto = cacheService.addStudentAuthCache(es.getStudentId());
         String sessionId = SessionUtil
                 .digest(es.getStudentId(), Math.abs(authDto.getRoleCodes().toString().hashCode()), sourceEnum);
         ret.setRecordId(recordId);

+ 3 - 1
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEOpenServiceImpl.java

@@ -10,6 +10,7 @@ import com.qmth.themis.business.bean.admin.OpenExamCourseBean;
 import com.qmth.themis.business.bean.admin.OpenRecordAnswerBean;
 import com.qmth.themis.business.bean.admin.OpenRecordNeedMarkBean;
 import com.qmth.themis.business.cache.RedisKeyHelper;
+import com.qmth.themis.business.cache.bean.ExamCacheBean;
 import com.qmth.themis.business.cache.bean.ExamPaperCacheBean;
 import com.qmth.themis.business.dto.response.TEExamStudentDto;
 import com.qmth.themis.business.entity.TEExam;
@@ -181,7 +182,8 @@ public class TEOpenServiceImpl implements TEOpenService {
     }
 
     private TEExam checkExam(Long examId) {
-        TEExam exam = examService.getById(examId);
+        ExamCacheBean examCacheBean = examService.getExamCacheBean(examId);
+        TEExam exam = examService.cacheConvert(examCacheBean);
         if (exam == null) {
             throw new BusinessException("未找到考试信息");
         }

+ 4 - 8
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEStudentServiceImpl.java

@@ -4,16 +4,14 @@ import com.aliyun.oss.common.utils.BinaryUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.google.gson.Gson;
 import com.qmth.themis.business.bean.admin.StudentPhotoUploadResponseBean;
 import com.qmth.themis.business.dao.TEStudentMapper;
-import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
 import com.qmth.themis.business.dto.response.TEStudentDto;
 import com.qmth.themis.business.dto.response.TEStudentExamRecordDto;
 import com.qmth.themis.business.entity.TEStudent;
+import com.qmth.themis.business.service.CacheService;
 import com.qmth.themis.business.service.TEStudentService;
 import com.qmth.themis.business.util.OssUtil;
-import com.qmth.themis.business.util.RedisUtil;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.HexUtils;
 import org.springframework.stereotype.Service;
@@ -43,7 +41,7 @@ public class TEStudentServiceImpl extends ServiceImpl<TEStudentMapper, TEStudent
     OssUtil ossUtil;
 
     @Resource
-    RedisUtil redisUtil;
+    CacheService cacheService;
 
     /**
      * 学生档案查询
@@ -57,7 +55,7 @@ public class TEStudentServiceImpl extends ServiceImpl<TEStudentMapper, TEStudent
      */
     @Override
     public IPage<TEStudentDto> studentQuery(IPage<Map> iPage, String identity, String name, Integer enable,
-            Long orgId) {
+                                            Long orgId) {
         return teStudentMapper.studentQuery(iPage, identity, name, enable, orgId);
     }
 
@@ -91,9 +89,7 @@ public class TEStudentServiceImpl extends ServiceImpl<TEStudentMapper, TEStudent
         try {
             student.setBasePhotoPath(filePath);
             this.saveOrUpdate(student);
-            Gson gson = new Gson();
-            TEStudentCacheDto teStudentCacheDto = gson.fromJson(gson.toJson(student), TEStudentCacheDto.class);
-            redisUtil.setStudent(student.getId(), teStudentCacheDto);
+            cacheService.updateStudentAccountCache(student.getId());
             in = file.getInputStream();
             ossUtil.upload(true, filePath, in, BinaryUtil.toBase64String(HexUtils.decodeHex(md5)));
             String url = ossUtil.getAliYunOssPublicDomain().getPublicUrl() + File.separator + filePath;

+ 13 - 13
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskExamPaperImportTemplete.java

@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.aliyun.oss.common.utils.BinaryUtil;
+import com.qmth.themis.business.cache.bean.ExamCacheBean;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.entity.TEExam;
 import com.qmth.themis.business.entity.TEExamCourse;
@@ -111,12 +112,11 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
     public void dispose(File file, Map<String, Object> map, StringBuilder result) throws IOException {
 
         Long examId = (Long) map.get("examId");
-
-        TEExam teExam = teExamService.getById(examId);
-        if (Objects.isNull(teExam)) {
+        ExamCacheBean examCacheBean = teExamService.getExamCacheBean(examId);
+        if (Objects.isNull(examCacheBean)) {
             throw new BusinessException(ExceptionResultEnum.EXAM_NO);
         }
-
+        TEExam teExam = teExamService.cacheConvert(examCacheBean);
         String tempDir = SystemConstant.TEMP_FILES_DIR;
         String dir = tempDir + "/" + uuid() + "/";
         File dfile = new File(dir);
@@ -168,11 +168,11 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
         if (course == null) {
             throw new BusinessException("科目编码不存在 " + courseCode);
         }
-        List<Long> paperIds=new ArrayList<Long>();
+        List<Long> paperIds = new ArrayList<Long>();
         File[] childs = courseDir.listFiles();
         for (File paperDir : childs) {
             if (paperDir.isDirectory()) {
-                disposePaperDir(rootDir, teExam, course, paperDir, map,paperIds);
+                disposePaperDir(rootDir, teExam, course, paperDir, map, paperIds);
             }
         }
         Boolean objectiveShuffle = (Boolean) map.get("objectiveShuffle");
@@ -208,9 +208,9 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
         teExamCourseService.saveOrUpdate(course);
         // 设置调卷比例
         teExamPaperService.savePaperWeight(paperWeight(list));
-        
+
         //处理试卷缓存
-        teExamPaperService.disposePaperCacheOnPaperImport(teExam.getId(),paperIds);
+        teExamPaperService.disposePaperCacheOnPaperImport(teExam.getId(), paperIds);
 
         //清除考试科目缓存
         teExamCourseService.deleteExamCourseCacheBean(teExam.getId(), courseCode);
@@ -234,7 +234,7 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
     }
 
     private void disposePaperDir(String rootDir, TEExam teExam, TEExamCourse course, File paperDir,
-                                 Map<String, Object> map,List<Long> paperIds) throws IOException {
+                                 Map<String, Object> map, List<Long> paperIds) throws IOException {
         String paperCode = paperDir.getName();
         File[] childs = paperDir.listFiles();
 
@@ -485,10 +485,10 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
             for (int j = 0; j < answerdetailquestions.size(); j++) {
                 JSONObject answerquestion = answerdetailquestions.getJSONObject(j);
                 JSONObject structquestion = structdetailquestions.getJSONObject(j);
-                int structType=structquestion.getInteger("structType").intValue();
+                int structType = structquestion.getInteger("structType").intValue();
                 answerquestion.put("structType", structType);
                 answerquestion.put("score", structquestion.getDouble("score"));
-                if (structType != 1&& structType != 2&& structType != 3&& structType != 6) {
+                if (structType != 1 && structType != 2 && structType != 3 && structType != 6) {
                     JSONArray answer = answerquestion.getJSONArray("answer");
                     disposeAnswerUrl(rootDir, answer, paper.getId(), attachmentDir);
                 }
@@ -498,10 +498,10 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
                     for (int k = 0; k < answersubQuestions.size(); k++) {
                         JSONObject answersubquestion = answersubQuestions.getJSONObject(k);
                         JSONObject structsubquestion = structsubQuestions.getJSONObject(k);
-                        int subStructType=structsubquestion.getInteger("structType").intValue();
+                        int subStructType = structsubquestion.getInteger("structType").intValue();
                         answersubquestion.put("structType", subStructType);
                         answersubquestion.put("score", structsubquestion.getDouble("score"));
-                        if (subStructType != 1&& subStructType != 2&& subStructType != 3) {
+                        if (subStructType != 1 && subStructType != 2 && subStructType != 3) {
                             JSONArray answer = answersubquestion.getJSONArray("answer");
                             disposeAnswerUrl(rootDir, answer, paper.getId(), attachmentDir);
                         }

+ 19 - 41
themis-business/src/main/java/com/qmth/themis/business/util/AuthUtil.java

@@ -1,16 +1,12 @@
 package com.qmth.themis.business.util;
 
-import com.google.gson.Gson;
 import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.AuthDto;
 import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
 import com.qmth.themis.business.entity.TBSession;
 import com.qmth.themis.business.entity.TBUser;
-import com.qmth.themis.business.entity.TEStudent;
 import com.qmth.themis.business.service.CacheService;
-import com.qmth.themis.business.service.TBUserService;
-import com.qmth.themis.business.service.TEStudentService;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.enums.Platform;
 import com.qmth.themis.common.exception.BusinessException;
@@ -54,20 +50,15 @@ public class AuthUtil {
                                                List<String> sysUrls,
                                                HttpServletRequest request,
                                                HttpServletResponse response) {
-        RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
-        TBUserService tbUserService = SpringContextHolder.getBean(TBUserService.class);
+        CacheService cacheService = SpringContextHolder.getBean(CacheService.class);
         String url = request.getServletPath();
         String method = request.getMethod();
-        TBSession tbSession = authHeadCommon(redisUtil, platform, deviceId, authorization, time, method, url);
-        long userId = Long.parseLong(tbSession.getIdentity());
-        TBUser tbUser = (TBUser) redisUtil.getUser(userId);
-        if (Objects.isNull(tbUser)) {
-            tbUser = tbUserService.getById(userId);
-            redisUtil.setUser(tbUser.getId(), tbUser);
-        }
+        TBSession tbSession = authHeadCommon(platform, deviceId, authorization, time, method, url);
+        Long userId = Long.parseLong(tbSession.getIdentity());
+        TBUser tbUser = cacheService.addAccountCache(userId);
         request.setAttribute(SystemConstant.SESSION, tbSession);
         request.setAttribute(SystemConstant.ACCOUNT, tbUser);
-        return authFootCommon(redisUtil, userId, SystemConstant.userOauth, sysUrls, request, response);
+        return authFootCommon(userId, SystemConstant.userOauth, sysUrls, request, response);
     }
 
     /**
@@ -89,22 +80,15 @@ public class AuthUtil {
                                               List<String> sysUrls,
                                               HttpServletRequest request,
                                               HttpServletResponse response) {
-        RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
-        TEStudentService teStudentService = SpringContextHolder.getBean(TEStudentService.class);
+        CacheService cacheService = SpringContextHolder.getBean(CacheService.class);
         String url = request.getServletPath();
         String method = request.getMethod();
-        TBSession tbSession = authHeadCommon(redisUtil, platform, deviceId, authorization, time, method, url);
-        long userId = Long.parseLong(tbSession.getIdentity());
-        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) redisUtil.getStudent(userId);
-        if (Objects.isNull(teStudentCacheDto)) {
-            TEStudent teStudent = teStudentService.getById(userId);
-            Gson gson = new Gson();
-            teStudentCacheDto = gson.fromJson(gson.toJson(teStudent), TEStudentCacheDto.class);
-            redisUtil.setStudent(teStudent.getId(), teStudentCacheDto);
-        }
+        TBSession tbSession = authHeadCommon(platform, deviceId, authorization, time, method, url);
+        Long studentId = Long.parseLong(tbSession.getIdentity());
+        TEStudentCacheDto teStudentCacheDto = cacheService.addStudentAccountCache(studentId);
         request.setAttribute(SystemConstant.SESSION, tbSession);
         request.setAttribute(SystemConstant.STUDENT_ACCOUNT, teStudentCacheDto);
-        return authFootCommon(redisUtil, userId, SystemConstant.studentOauth, sysUrls, request, response);
+        return authFootCommon(studentId, SystemConstant.studentOauth, sysUrls, request, response);
     }
 
     /**
@@ -124,27 +108,25 @@ public class AuthUtil {
                                                      long time,
                                                      String method,
                                                      String url) {
-        RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
-        return authHeadCommon(redisUtil, platform, deviceId, authorization, time, method, url);
+        return authHeadCommon(platform, deviceId, authorization, time, method, url);
     }
 
     /**
      * 鉴权头公用
      *
-     * @param redisUtil
      * @param platform
      * @param deviceId
      * @param authorization
      * @param time
      * @return
      */
-    static TBSession authHeadCommon(RedisUtil redisUtil,
-                                    Platform platform,
+    static TBSession authHeadCommon(Platform platform,
                                     String deviceId,
                                     String authorization,
                                     long time,
                                     String method,
                                     String url) {
+        RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
         if (SystemConstant.expire(time)) {
             log.warn("Authorization faile: time expired, server time=" + System.currentTimeMillis());
             throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
@@ -190,7 +172,6 @@ public class AuthUtil {
     /**
      * 鉴权尾公用
      *
-     * @param redisUtil
      * @param userId
      * @param type
      * @param sysUrls
@@ -198,22 +179,19 @@ public class AuthUtil {
      * @param response
      * @return
      */
-    static boolean authFootCommon(RedisUtil redisUtil,
-                                  long userId,
+    static boolean authFootCommon(long userId,
                                   String type,
                                   List<String> sysUrls,
                                   HttpServletRequest request,
                                   HttpServletResponse response) {
         String url = request.getServletPath();
         CacheService cacheService = SpringContextHolder.getBean(CacheService.class);
-        AuthDto authDto = (AuthDto) redisUtil.get(type + userId);
         //验证权限
-        if (Objects.isNull(authDto)) {
-            if (type.contains(SystemConstant.userOauth)) {
-                authDto = cacheService.addAccountCache(userId);
-            } else if (type.contains(SystemConstant.studentOauth)) {
-                authDto = cacheService.addStudentCache(userId);
-            }
+        AuthDto authDto = null;
+        if (type.contains(SystemConstant.userOauth)) {
+            authDto = cacheService.addAccountAuthCache(userId);
+        } else if (type.contains(SystemConstant.studentOauth)) {
+            authDto = cacheService.addStudentAuthCache(userId);
         }
         request.setAttribute(SystemConstant.ORG, authDto.getTbOrg());
 

+ 146 - 146
themis-business/src/main/java/com/qmth/themis/business/util/RedisUtil.java

@@ -24,92 +24,92 @@ public class RedisUtil {
     @Resource
     RedisTemplate<String, Object> redisTemplate;
 
-    /**
-     * 获取机构信息
-     *
-     * @param orgId
-     * @return
-     */
-    public Object getOrg(Long orgId) {
-        return redisTemplate.opsForValue().get(SystemConstant.ORG + orgId);
-    }
-
-    /**
-     * 设置机构信息
-     *
-     * @param orgId
-     * @param o
-     */
-    public void setOrg(Long orgId, Object o) {
-        redisTemplate.opsForValue().set(SystemConstant.ORG + orgId, o, SystemConstant.REDIS_EXPIRE_TIME, TimeUnit.SECONDS);
-    }
-
-    /**
-     * 获取机构信息
-     *
-     * @param orgCode
-     * @return
-     */
-    public Object getOrgCode(String orgCode) {
-        return redisTemplate.opsForValue().get(SystemConstant.ORG + orgCode);
-    }
-
-    /**
-     * 设置机构信息
-     *
-     * @param o
-     */
-    public void setRole(Object o) {
-        redisTemplate.opsForList().leftPushAll(SystemConstant.ROLE, o);
-        redisTemplate.expire(SystemConstant.ROLE, SystemConstant.REDIS_EXPIRE_TIME, TimeUnit.SECONDS);
-    }
-
-    /**
-     * 获取机构信息
-     *
-     * @return
-     */
-    public Object getRole() {
-        return redisTemplate.opsForList().range(SystemConstant.ROLE, 0, -1);
-    }
-
-    /**
-     * 设置机构信息
-     *
-     * @param orgCode
-     * @param o
-     */
-    public void setOrgCode(String orgCode, Object o) {
-        redisTemplate.opsForValue().set(SystemConstant.ORG + orgCode, o, SystemConstant.REDIS_EXPIRE_TIME, TimeUnit.SECONDS);
-    }
-
-    /**
-     * 删除机构缓存
-     *
-     * @param orgId
-     */
-    public void deleteOrg(Long orgId) {
-        redisTemplate.delete(SystemConstant.ORG + orgId);
-    }
-
-    /**
-     * 删除机构缓存
-     *
-     * @param orgId
-     */
-    public void deleteOrgCode(String orgCode) {
-        redisTemplate.delete(SystemConstant.ORG + orgCode);
-    }
-
-    /**
-     * 获取用户信息
-     *
-     * @param userId
-     * @return
-     */
-    public Object getUser(Long userId) {
-        return redisTemplate.opsForValue().get(SystemConstant.USER + userId);
-    }
+//    /**
+//     * 获取机构信息
+//     *
+//     * @param orgId
+//     * @return
+//     */
+//    public Object getOrg(Long orgId) {
+//        return redisTemplate.opsForValue().get(SystemConstant.ORG + orgId);
+//    }
+//
+//    /**
+//     * 设置机构信息
+//     *
+//     * @param orgId
+//     * @param o
+//     */
+//    public void setOrg(Long orgId, Object o) {
+//        redisTemplate.opsForValue().set(SystemConstant.ORG + orgId, o, SystemConstant.REDIS_EXPIRE_TIME, TimeUnit.SECONDS);
+//    }
+
+//    /**
+//     * 获取机构信息
+//     *
+//     * @param orgCode
+//     * @return
+//     */
+//    public Object getOrgCode(String orgCode) {
+//        return redisTemplate.opsForValue().get(SystemConstant.ORG + orgCode);
+//    }
+//
+//    /**
+//     * 设置机构信息
+//     *
+//     * @param o
+//     */
+//    public void setRole(Object o) {
+//        redisTemplate.opsForList().leftPushAll(SystemConstant.ROLE, o);
+//        redisTemplate.expire(SystemConstant.ROLE, SystemConstant.REDIS_EXPIRE_TIME, TimeUnit.SECONDS);
+//    }
+
+//    /**
+//     * 获取机构信息
+//     *
+//     * @return
+//     */
+//    public Object getRole() {
+//        return redisTemplate.opsForList().range(SystemConstant.ROLE, 0, -1);
+//    }
+
+//    /**
+//     * 设置机构信息
+//     *
+//     * @param orgCode
+//     * @param o
+//     */
+//    public void setOrgCode(String orgCode, Object o) {
+//        redisTemplate.opsForValue().set(SystemConstant.ORG + orgCode, o, SystemConstant.REDIS_EXPIRE_TIME, TimeUnit.SECONDS);
+//    }
+//
+//    /**
+//     * 删除机构缓存
+//     *
+//     * @param orgId
+//     */
+//    public void deleteOrg(Long orgId) {
+//        redisTemplate.delete(SystemConstant.ORG + orgId);
+//    }
+//
+//    /**
+//     * 删除机构缓存
+//     *
+//     * @param orgCode
+//     */
+//    public void deleteOrgCode(String orgCode) {
+//        redisTemplate.delete(SystemConstant.ORG + orgCode);
+//    }
+
+//    /**
+//     * 获取用户信息
+//     *
+//     * @param userId
+//     * @return
+//     */
+//    public Object getUser(Long userId) {
+//        return redisTemplate.opsForValue().get(SystemConstant.USER + userId);
+//    }
 
     /**
      * 获取用户会话信息
@@ -121,15 +121,15 @@ public class RedisUtil {
         return redisTemplate.opsForValue().get(SystemConstant.SESSION + sessionId);
     }
 
-    /**
-     * 删除用户缓存
-     *
-     * @param userId
-     */
-    public void deleteUser(Long userId) {
-        redisTemplate.delete(SystemConstant.USER + userId);
-    }
-
+//    /**
+//     * 删除用户缓存
+//     *
+//     * @param userId
+//     */
+//    public void deleteUser(Long userId) {
+//        redisTemplate.delete(SystemConstant.USER + userId);
+//    }
+//
     /**
      * 删除用户会话缓存
      *
@@ -138,57 +138,57 @@ public class RedisUtil {
     public void deleteUserSession(String sessionId) {
         redisTemplate.delete(SystemConstant.SESSION + sessionId);
     }
-
-    /**
-     * 设置用户信息
-     *
-     * @param userId
-     * @param o
-     */
-    public void setUser(Long userId, Object o) {
-        redisTemplate.opsForValue().set(SystemConstant.USER + userId, o, SystemConstant.REDIS_EXPIRE_TIME, TimeUnit.SECONDS);
-    }
-
-    /**
-     * 设置学生信息
-     *
-     * @param studentId
-     * @param o
-     * @param time
-     * @param timeUnit
-     */
-    public void setStudent(Long studentId, Object o, Long time, TimeUnit timeUnit) {
-        redisTemplate.opsForValue().set(SystemConstant.STUDENT + studentId, o, time, timeUnit);
-    }
-
-    /**
-     * 设置学生信息
-     *
-     * @param studentId
-     * @param o
-     */
-    public void setStudent(Long studentId, Object o) {
-        redisTemplate.opsForValue().set(SystemConstant.STUDENT + studentId, o);
-    }
-
-    /**
-     * 删除学生缓存
-     *
-     * @param studentId
-     */
-    public void deleteStudent(Long studentId) {
-        redisTemplate.delete(SystemConstant.STUDENT + studentId);
-    }
-
-    /**
-     * 获取学生信息
-     *
-     * @param studentId
-     * @return
-     */
-    public Object getStudent(Long studentId) {
-        return redisTemplate.opsForValue().get(SystemConstant.STUDENT + studentId);
-    }
+//
+//    /**
+//     * 设置用户信息
+//     *
+//     * @param userId
+//     * @param o
+//     */
+//    public void setUser(Long userId, Object o) {
+//        redisTemplate.opsForValue().set(SystemConstant.USER + userId, o, SystemConstant.REDIS_EXPIRE_TIME, TimeUnit.SECONDS);
+//    }
+
+//    /**
+//     * 设置学生信息
+//     *
+//     * @param studentId
+//     * @param o
+//     * @param time
+//     * @param timeUnit
+//     */
+//    public void setStudent(Long studentId, Object o, Long time, TimeUnit timeUnit) {
+//        redisTemplate.opsForValue().set(SystemConstant.STUDENT + studentId, o, time, timeUnit);
+//    }
+//
+//    /**
+//     * 设置学生信息
+//     *
+//     * @param studentId
+//     * @param o
+//     */
+//    public void setStudent(Long studentId, Object o) {
+//        redisTemplate.opsForValue().set(SystemConstant.STUDENT + studentId, o);
+//    }
+
+//    /**
+//     * 删除学生缓存
+//     *
+//     * @param studentId
+//     */
+//    public void deleteStudent(Long studentId) {
+//        redisTemplate.delete(SystemConstant.STUDENT + studentId);
+//    }
+//
+//    /**
+//     * 获取学生信息
+//     *
+//     * @param studentId
+//     * @return
+//     */
+//    public Object getStudent(Long studentId) {
+//        return redisTemplate.opsForValue().get(SystemConstant.STUDENT + studentId);
+//    }
 
     /**
      * 设置用户session信息

+ 5 - 12
themis-exam/src/main/java/com/qmth/themis/exam/api/SysController.java

@@ -8,9 +8,8 @@ import com.qmth.themis.business.bean.exam.VersionBean;
 import com.qmth.themis.business.entity.TBClientVersion;
 import com.qmth.themis.business.entity.TBOrg;
 import com.qmth.themis.business.enums.UploadFileEnum;
+import com.qmth.themis.business.service.CacheService;
 import com.qmth.themis.business.service.TBClientVersionService;
-import com.qmth.themis.business.service.TBOrgService;
-import com.qmth.themis.business.util.RedisUtil;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
 import com.qmth.themis.exam.config.DictionaryConfig;
@@ -30,18 +29,15 @@ import java.util.Objects;
 @RequestMapping("/${prefix.url.exam}/sys")
 public class SysController {
 
-    @Resource
-    private TBOrgService orgService;
-
-    @Resource
-    RedisUtil redisUtil;
-
     @Resource
     DictionaryConfig dictionaryConfig;
 
     @Resource
     TBClientVersionService tbClientVersionService;
 
+    @Resource
+    CacheService cacheService;
+
     @ApiOperation(value = "获取环境接口")
     @RequestMapping(value = "/env", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "环境信息", response = Result.class)})
@@ -51,10 +47,7 @@ public class SysController {
         EnvBean env = new EnvBean();
         if (Objects.nonNull(mapParameter.get("orgId"))) {
             Long orgId = Long.parseLong(String.valueOf(mapParameter.get("orgId")));
-            TBOrg org = (TBOrg) redisUtil.getOrg(orgId);
-            if (Objects.isNull(org)) {
-                org = orgService.getById(orgId);
-            }
+            TBOrg org = cacheService.addOrgCache(orgId);
             if (Objects.nonNull(org)) {
                 OrgInfoBean orgInfo = new OrgInfoBean(org.getName(), org.getLogo(), (org.getUpdateTime() == null ? null : org.getUpdateTime()));
                 env.setOrgInfo(orgInfo);

+ 11 - 20
themis-exam/src/main/java/com/qmth/themis/exam/api/TEStudentController.java

@@ -34,8 +34,6 @@ import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.enums.Platform;
 import com.qmth.themis.common.enums.Source;
 import com.qmth.themis.common.exception.BusinessException;
-import com.qmth.themis.common.signature.SignatureInfo;
-import com.qmth.themis.common.signature.SignatureType;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
 import com.qmth.themis.exam.config.ExamConstant;
@@ -50,7 +48,10 @@ import org.springframework.web.bind.annotation.RestController;
 import javax.annotation.Resource;
 import java.io.File;
 import java.security.NoSuchAlgorithmException;
-import java.util.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
 
 /**
  * @Description: 考生 前端控制器
@@ -130,17 +131,13 @@ public class TEStudentController {
         if (Objects.nonNull(mapParameter.get("examId"))) {
             examId = Long.parseLong(String.valueOf(mapParameter.get("examId")));
             ExamCacheBean ec = teExamService.getExamCacheBean(examId);
-            tbOrg = Objects.isNull(redisUtil.getOrg(ec.getOrgId())) ?
-                    tbOrgService.getById(ec.getOrgId()) :
-                    (TBOrg) redisUtil.getOrg(ec.getOrgId());
+            tbOrg = cacheService.addOrgCache(ec.getOrgId());
         }
         if (Objects.isNull(orgId) && Objects.isNull(examId)) {
             throw new BusinessException(ExceptionResultEnum.ORG_ID_OR_EXAM_ID_NOT_CHOOSE);
         }
         if (Objects.nonNull(orgId)) {
-            tbOrg = Objects.isNull(redisUtil.getOrg(orgId)) ?
-                    tbOrgService.getById(orgId) :
-                    (TBOrg) redisUtil.getOrg(orgId);
+            tbOrg = cacheService.addOrgCache(orgId);
         }
         if (Objects.isNull(tbOrg)) {
             throw new BusinessException(ExceptionResultEnum.ORG_NO);
@@ -198,16 +195,10 @@ public class TEStudentController {
         Platform platform = ServletUtil.getRequestPlatform();
         String deviceId = ServletUtil.getRequestDeviceId();
         //添加用户鉴权缓存
-        AuthDto authDto = cacheService.addStudentCache(teStudent.getId());
+        AuthDto authDto = cacheService.addStudentAuthCache(teStudent.getId());
         //生成token
         String token = RandomStringUtils.randomAlphanumeric(32);
-        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) redisUtil.getStudent(teStudent.getId());
-        if (Objects.isNull(teStudentCacheDto)) {
-            Gson gson = new Gson();
-            teStudentCacheDto = gson.fromJson(gson.toJson(teStudent), TEStudentCacheDto.class);
-        }
-        //添加用户缓存
-        redisUtil.setStudent(teStudent.getId(), teStudentCacheDto);
+        cacheService.addStudentAccountCache(teStudent.getId());
         //判断会话来源
         Source source = null;
         if (Platform.WIN == platform || Platform.MAC == platform) {
@@ -296,7 +287,7 @@ public class TEStudentController {
         if (Objects.isNull(tbSession)) {
             throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
         }
-        AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.studentOauth + teStudent.getId());
+        AuthDto authDto = cacheService.addStudentAuthCache(teStudent.getId());
         redisUtil.deleteUserSession(tbSession.getId());
         //循环检查该用户下其他平台是否存在session,不存在则删除用户缓存和鉴权缓存
         boolean delete = true;
@@ -309,8 +300,8 @@ public class TEStudentController {
             }
         }
         if (delete) {
-            redisUtil.deleteStudent(teStudent.getId());
-            cacheService.removeStudentCache(teStudent.getId());
+            cacheService.removeStudentAuthCache(teStudent.getId());
+            cacheService.removeStudentAccountCache(teStudent.getId());
         }
         //mq发送消息start
         MqDto mqDto = new MqDto(mqUtil.getMqGroupDomain().getTopic(), MqTagEnum.STUDENT.name(),

+ 3 - 3
themis-exam/src/main/java/com/qmth/themis/exam/api/TIeInvigilateCallMobileController.java

@@ -132,7 +132,7 @@ public class TIeInvigilateCallMobileController {
         if (!Objects.equals(status, MonitorStatusSourceEnum.START)) {
             throw new BusinessException("推流状态不正常");
         }
-        String liveUrl = dictionaryConfig.monitorDomain().getPrefix() + "_" + recordId + "_" + source.name().toLowerCase();
+        String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         Long timestamp = System.currentTimeMillis();
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.START, timestamp);
         tOeExamRecordService.sendExamRecordDataSaveMq(recordId, timestamp);
@@ -172,7 +172,7 @@ public class TIeInvigilateCallMobileController {
             throw new BusinessException("异常类型不能为空");
         }
         //获取考试记录缓存
-        String liveUrl = dictionaryConfig.monitorDomain().getPrefix() + "_" + recordId + "_" + source.name().toLowerCase();
+        String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         MonitorCallStatusSourceEnum callStatus = Objects.nonNull(ExamRecordCacheUtil.getMonitorCallStatus(recordId, source)) ? ExamRecordCacheUtil.getMonitorCallStatus(recordId, source) : null;
         Long timestamp = System.currentTimeMillis();
         ExamRecordCacheUtil.setMonitorStatus(recordId, source, status, timestamp);
@@ -230,7 +230,7 @@ public class TIeInvigilateCallMobileController {
         } else if (Objects.isNull(ExamRecordCacheUtil.getMonitorStatus(recordId, source))) {
             throw new BusinessException("推流状态为空");
         }
-        String liveUrl = dictionaryConfig.monitorDomain().getPrefix() + "_" + recordId + "_" + source.name().toLowerCase();
+        String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         Long timestamp = System.currentTimeMillis();
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.STOP, timestamp);
         tOeExamRecordService.sendExamRecordDataSaveMq(recordId, timestamp);

+ 4 - 3
themis-exam/src/main/java/com/qmth/themis/exam/api/TIeInvigilateCallOeController.java

@@ -3,6 +3,7 @@ package com.qmth.themis.exam.api;
 import com.qmth.themis.business.annotation.ApiJsonObject;
 import com.qmth.themis.business.annotation.ApiJsonProperty;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
+import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.MqDto;
 import com.qmth.themis.business.entity.TIeExamInvigilateCallLog;
 import com.qmth.themis.business.enums.*;
@@ -132,7 +133,7 @@ public class TIeInvigilateCallOeController {
             throw new BusinessException("异常类型不能为空");
         }
         //获取考试记录缓存
-        String liveUrl = dictionaryConfig.monitorDomain().getPrefix() + "_" + recordId + "_" + source.name().toLowerCase();
+        String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         MonitorCallStatusSourceEnum callStatus = Objects.nonNull(ExamRecordCacheUtil.getMonitorCallStatus(recordId, source)) ? ExamRecordCacheUtil.getMonitorCallStatus(recordId, source) : null;
         Long timestamp = System.currentTimeMillis();
         ExamRecordCacheUtil.setMonitorStatus(recordId, source, status, timestamp);
@@ -167,7 +168,7 @@ public class TIeInvigilateCallOeController {
         Long recordId = Long.parseLong(String.valueOf(mapParameter.get("recordId")));
         //获取考试记录缓存
         MonitorVideoSourceEnum source = MonitorVideoSourceEnum.CLIENT_CAMERA;
-        String liveUrl = dictionaryConfig.monitorDomain().getPrefix() + "_" + recordId + "_" + source.name().toLowerCase();
+        String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         if (Objects.isNull(source) || Objects.isNull(ExamRecordCacheUtil.getMonitorStatus(recordId, source))) {
             throw new BusinessException("推流状态为空");
         }
@@ -201,7 +202,7 @@ public class TIeInvigilateCallOeController {
         Long recordId = Long.parseLong(String.valueOf(mapParameter.get("recordId")));
         //获取考试记录缓存
         MonitorVideoSourceEnum source = MonitorVideoSourceEnum.CLIENT_CAMERA;
-        String liveUrl = dictionaryConfig.monitorDomain().getPrefix() + "_" + recordId + "_" + source.name().toLowerCase();
+        String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         ExamRecordStatusEnum statusEnum = ExamRecordCacheUtil.getStatus(recordId);
         if (Objects.isNull(statusEnum) || Objects.equals(statusEnum, ExamRecordStatusEnum.FINISHED) || Objects.equals(statusEnum, ExamRecordStatusEnum.PERSISTED)) {
             return ResultUtil.ok(Collections.singletonMap("updateTime", System.currentTimeMillis()));