|
@@ -1,16 +1,5 @@
|
|
|
package com.qmth.themis.business.service.impl;
|
|
|
|
|
|
-import java.security.NoSuchAlgorithmException;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-
|
|
|
-import com.qmth.themis.business.util.TencentYunUtil;
|
|
|
-import org.apache.commons.lang3.RandomStringUtils;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
import com.qmth.themis.business.bean.exam.MobileAnswerSubmitReponseBean;
|
|
|
import com.qmth.themis.business.bean.mobile.MobileAuthorizationBean;
|
|
|
import com.qmth.themis.business.bean.mobile.MobileAuthorizationMonitorBean;
|
|
@@ -32,122 +21,133 @@ import com.qmth.themis.business.service.TEMobileService;
|
|
|
import com.qmth.themis.business.util.RedisUtil;
|
|
|
import com.qmth.themis.business.util.ServletUtil;
|
|
|
import com.qmth.themis.business.util.SessionUtil;
|
|
|
+import com.qmth.themis.business.util.TencentYunUtil;
|
|
|
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 org.apache.commons.lang3.RandomStringUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@Service
|
|
|
public class TEMobileServiceImpl implements TEMobileService {
|
|
|
|
|
|
- @Resource
|
|
|
- RedisUtil redisUtil;
|
|
|
+ @Resource
|
|
|
+ RedisUtil redisUtil;
|
|
|
|
|
|
- @Resource
|
|
|
- TEExamStudentService examStudentService;
|
|
|
+ @Resource
|
|
|
+ TEExamStudentService examStudentService;
|
|
|
|
|
|
- @Resource
|
|
|
- TencentYunUtil tencentYunUtil;
|
|
|
+ @Resource
|
|
|
+ TencentYunUtil tencentYunUtil;
|
|
|
|
|
|
- @Override
|
|
|
- public MobileAuthorizationBean authorization(MobileAuthorizationParamBean param) throws NoSuchAlgorithmException {
|
|
|
- MobileModeEnum mode = MobileModeEnum.valueOf(param.getMode().toUpperCase());
|
|
|
- String code = param.getCode();
|
|
|
- MobileAuthorizationBean ret = null;
|
|
|
- if (MobileModeEnum.MOBILE_MONITOR.equals(mode)) {
|
|
|
- ret = monitorAuthorization(mode, code);
|
|
|
- } else if (MobileModeEnum.PHOTO_UPLOAD.equals(mode) || MobileModeEnum.AUDIO_UPLOAD.equals(mode)) {
|
|
|
- ret = answerUploadAuthorization(mode, code);
|
|
|
- }
|
|
|
- if(ExamRecordCacheUtil.getId(ret.getRecordId())==null) {
|
|
|
- throw new BusinessException("考试记录不存在");
|
|
|
- }
|
|
|
- ExamStudentCacheBean es = examStudentService
|
|
|
- .getExamStudentCacheBean(ExamRecordCacheUtil.getExamStudentId(ret.getRecordId()));
|
|
|
- if(es==null) {
|
|
|
- throw new BusinessException("未找到考生");
|
|
|
- }
|
|
|
- ExamRecordStatusEnum sta=ExamRecordCacheUtil.getStatus(ret.getRecordId());
|
|
|
- if(ExamRecordStatusEnum.FIRST_PREPARE.equals(sta)) {
|
|
|
- throw new BusinessException("该考试未开始答题");
|
|
|
- }
|
|
|
- if(ExamRecordStatusEnum.FINISHED.equals(sta)||ExamRecordStatusEnum.PERSISTED.equals(sta)) {
|
|
|
- throw new BusinessException("该考试已结束");
|
|
|
- }
|
|
|
- Platform platform = Platform.valueOf(ServletUtil.getRequestPlatform());
|
|
|
- String deviceId = ServletUtil.getRequestDeviceId();
|
|
|
- AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.studentOauth + "::" + es.getStudentId());
|
|
|
- // 生成token
|
|
|
- String token = RandomStringUtils.randomAlphanumeric(32);
|
|
|
- TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) redisUtil.getStudent(es.getStudentId());
|
|
|
- String source = null;
|
|
|
- if (Objects.equals(platform.name(), Platform.WIN.name())
|
|
|
- || Objects.equals(platform.name(), Platform.MAC.name())) {
|
|
|
- source = platform.getSource().split(",")[1];
|
|
|
- } else if (Objects.equals(platform.name(), Platform.WXAPP.name())
|
|
|
- || Objects.equals(platform.name(), Platform.WEB.name())) {
|
|
|
- source = platform.getSource();
|
|
|
- } else if (Objects.equals(platform.name(), Platform.IOS.name())
|
|
|
- || Objects.equals(platform.name(), Platform.ANDROID.name())) {
|
|
|
- source = platform.getSource().split(",")[2];
|
|
|
- }
|
|
|
- String sessionId = SessionUtil.digest(teStudentCacheDto.getIdentity(),
|
|
|
- Math.abs(authDto.getRoleCodes().toString().hashCode()), source);
|
|
|
- Map<String, Object> expireMap = SystemConstant.getExpireTime(platform);
|
|
|
- Date expire = (Date) expireMap.get("date");
|
|
|
- Long redisExpire = Long.parseLong(String.valueOf(expireMap.get("redisExpire")));
|
|
|
- TBSession tbSession = new TBSession(sessionId, String.valueOf(es.getStudentId()),
|
|
|
- authDto.getRoleCodes().toString(), source, platform.name(), deviceId,
|
|
|
- ServletUtil.getRequest().getLocalAddr(), token, expire);
|
|
|
- redisUtil.setUserSession(sessionId, tbSession, redisExpire);
|
|
|
- ret.setSessionId(sessionId);
|
|
|
- ret.setTime(System.currentTimeMillis());
|
|
|
- ret.setMode(mode);
|
|
|
- //测试
|
|
|
+ @Override
|
|
|
+ public MobileAuthorizationBean authorization(MobileAuthorizationParamBean param) throws NoSuchAlgorithmException {
|
|
|
+ MobileModeEnum mode = MobileModeEnum.valueOf(param.getMode().toUpperCase());
|
|
|
+ String code = param.getCode();
|
|
|
+ MobileAuthorizationBean ret = null;
|
|
|
+ if (MobileModeEnum.MOBILE_MONITOR.equals(mode)) {
|
|
|
+ ret = monitorAuthorization(mode, code);
|
|
|
+ } else if (MobileModeEnum.PHOTO_UPLOAD.equals(mode) || MobileModeEnum.AUDIO_UPLOAD.equals(mode)) {
|
|
|
+ ret = answerUploadAuthorization(mode, code);
|
|
|
+ }
|
|
|
+ if (ExamRecordCacheUtil.getId(ret.getRecordId()) == null) {
|
|
|
+ throw new BusinessException("考试记录不存在");
|
|
|
+ }
|
|
|
+ ExamStudentCacheBean es = examStudentService
|
|
|
+ .getExamStudentCacheBean(ExamRecordCacheUtil.getExamStudentId(ret.getRecordId()));
|
|
|
+ if (es == null) {
|
|
|
+ throw new BusinessException("未找到考生");
|
|
|
+ }
|
|
|
+ ExamRecordStatusEnum sta = ExamRecordCacheUtil.getStatus(ret.getRecordId());
|
|
|
+ if (ExamRecordStatusEnum.FIRST_PREPARE.equals(sta)) {
|
|
|
+ throw new BusinessException("该考试未开始答题");
|
|
|
+ }
|
|
|
+ if (ExamRecordStatusEnum.FINISHED.equals(sta) || ExamRecordStatusEnum.PERSISTED.equals(sta)) {
|
|
|
+ throw new BusinessException("该考试已结束");
|
|
|
+ }
|
|
|
+ Platform platform = Platform.valueOf(ServletUtil.getRequestPlatform());
|
|
|
+ String deviceId = ServletUtil.getRequestDeviceId();
|
|
|
+ AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.studentOauth + "::" + es.getStudentId());
|
|
|
+ // 生成token
|
|
|
+ String token = RandomStringUtils.randomAlphanumeric(32);
|
|
|
+ TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) redisUtil.getStudent(es.getStudentId());
|
|
|
+ String source = null;
|
|
|
+ if (Objects.equals(platform.name(), Platform.WIN.name())
|
|
|
+ || Objects.equals(platform.name(), Platform.MAC.name())) {
|
|
|
+ source = platform.getSource().split(",")[1];
|
|
|
+ } else if (Objects.equals(platform.name(), Platform.WXAPP.name())
|
|
|
+ || Objects.equals(platform.name(), Platform.WEB.name())) {
|
|
|
+ source = platform.getSource();
|
|
|
+ } else if (Objects.equals(platform.name(), Platform.IOS.name())
|
|
|
+ || Objects.equals(platform.name(), Platform.ANDROID.name())) {
|
|
|
+ source = platform.getSource().split(",")[2];
|
|
|
+ }
|
|
|
+ String sessionId = SessionUtil.digest(teStudentCacheDto.getIdentity(),
|
|
|
+ Math.abs(authDto.getRoleCodes().toString().hashCode()), source);
|
|
|
+ Map<String, Object> expireMap = SystemConstant.getExpireTime(platform);
|
|
|
+ Date expire = (Date) expireMap.get("date");
|
|
|
+ Long redisExpire = Long.parseLong(String.valueOf(expireMap.get("redisExpire")));
|
|
|
+ TBSession tbSession = new TBSession(sessionId, String.valueOf(es.getStudentId()),
|
|
|
+ authDto.getRoleCodes().toString(), source, platform.name(), deviceId,
|
|
|
+ ServletUtil.getRequest().getLocalAddr(), token, expire);
|
|
|
+ redisUtil.setUserSession(sessionId, tbSession, redisExpire);
|
|
|
+ ret.setSessionId(sessionId);
|
|
|
+ ret.setTime(System.currentTimeMillis());
|
|
|
+ ret.setMode(mode);
|
|
|
+ //测试
|
|
|
String test = SignatureInfo.build(SignatureType.TOKEN, sessionId, token);
|
|
|
ret.setAccessToken(test);
|
|
|
- return ret;
|
|
|
- }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
|
|
|
- private MobileAuthorizationBean monitorAuthorization(MobileModeEnum mode, String code) {
|
|
|
- TBSession tbSession = (TBSession) ServletUtil.getRequestSession();
|
|
|
- Long recordId = MobileAuthCacheUtil.getRecordId(mode, code);
|
|
|
- String monitorKey = MobileAuthCacheUtil.getMonitorKey(mode, code);
|
|
|
- Source monitorVideoSource = MobileAuthCacheUtil.getMonitorVideoSource(mode, code);
|
|
|
- Boolean monitorAudioEnable = MobileAuthCacheUtil.getMonitorAudioEnable(mode, code);
|
|
|
- if (MobileAuthCacheUtil.getMode(mode, code) == null) {
|
|
|
- throw new BusinessException("二维码已过期");
|
|
|
- }
|
|
|
- MobileAuthorizationMonitorBean ret = new MobileAuthorizationMonitorBean();
|
|
|
- ret.setRecordId(recordId);
|
|
|
- ret.setMonitorKey(monitorKey);
|
|
|
- ret.setMonitorVideoSource(monitorVideoSource);
|
|
|
- ret.setMonitorAudioEnable(monitorAudioEnable);
|
|
|
- ret.setMonitorUserId("s_" + tbSession.getId());
|
|
|
- ret.setMonitorUserSig(tencentYunUtil.getSign(ret.getMonitorUserId(), SystemConstant.TENCENT_EXPIRE_TIME));
|
|
|
- return ret;
|
|
|
- }
|
|
|
+ private MobileAuthorizationBean monitorAuthorization(MobileModeEnum mode, String code) {
|
|
|
+ TBSession tbSession = (TBSession) ServletUtil.getRequestSession();
|
|
|
+ Long recordId = MobileAuthCacheUtil.getRecordId(mode, code);
|
|
|
+ String monitorKey = MobileAuthCacheUtil.getMonitorKey(mode, code);
|
|
|
+ Source monitorVideoSource = MobileAuthCacheUtil.getMonitorVideoSource(mode, code);
|
|
|
+ Boolean monitorAudioEnable = MobileAuthCacheUtil.getMonitorAudioEnable(mode, code);
|
|
|
+ if (MobileAuthCacheUtil.getMode(mode, code) == null) {
|
|
|
+ throw new BusinessException("二维码已过期");
|
|
|
+ }
|
|
|
+ MobileAuthorizationMonitorBean ret = new MobileAuthorizationMonitorBean();
|
|
|
+ ret.setRecordId(recordId);
|
|
|
+ ret.setMonitorKey(monitorKey);
|
|
|
+ ret.setMonitorVideoSource(monitorVideoSource);
|
|
|
+ ret.setMonitorAudioEnable(monitorAudioEnable);
|
|
|
+ if (monitorAudioEnable) {
|
|
|
+ ret.setMonitorUserId("s_" + tbSession.getId());
|
|
|
+ ret.setMonitorUserSig(tencentYunUtil.getSign(ret.getMonitorUserId(), SystemConstant.TENCENT_EXPIRE_TIME));
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
|
|
|
- private MobileAuthorizationBean answerUploadAuthorization(MobileModeEnum mode, String code) {
|
|
|
- Long recordId = MobileAuthCacheUtil.getRecordId(mode, code);
|
|
|
- Integer mainNumber = MobileAuthCacheUtil.getMainNumber(mode, code);
|
|
|
- Integer subNumber = MobileAuthCacheUtil.getSubNumber(mode, code);
|
|
|
- Integer subIndex = MobileAuthCacheUtil.getSubIndex(mode, code);
|
|
|
- if (MobileAuthCacheUtil.getMode(mode, code) == null) {
|
|
|
- throw new BusinessException("二维码已过期");
|
|
|
- }
|
|
|
- MobileAuthorizationUploadBean ret = new MobileAuthorizationUploadBean();
|
|
|
- ret.setRecordId(recordId);
|
|
|
- ret.setMainNumber(mainNumber);
|
|
|
- ret.setSubNumber(subNumber);
|
|
|
- ret.setSubIndex(subIndex);
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
+ private MobileAuthorizationBean answerUploadAuthorization(MobileModeEnum mode, String code) {
|
|
|
+ Long recordId = MobileAuthCacheUtil.getRecordId(mode, code);
|
|
|
+ Integer mainNumber = MobileAuthCacheUtil.getMainNumber(mode, code);
|
|
|
+ Integer subNumber = MobileAuthCacheUtil.getSubNumber(mode, code);
|
|
|
+ Integer subIndex = MobileAuthCacheUtil.getSubIndex(mode, code);
|
|
|
+ if (MobileAuthCacheUtil.getMode(mode, code) == null) {
|
|
|
+ throw new BusinessException("二维码已过期");
|
|
|
+ }
|
|
|
+ MobileAuthorizationUploadBean ret = new MobileAuthorizationUploadBean();
|
|
|
+ ret.setRecordId(recordId);
|
|
|
+ ret.setMainNumber(mainNumber);
|
|
|
+ ret.setSubNumber(subNumber);
|
|
|
+ ret.setSubIndex(subIndex);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public MobileAnswerSubmitReponseBean answerSubmit(Long studentId, Long recordId, Integer mainNumber, Integer subNumber, Integer subIndex,
|
|
|
- String answer) {
|
|
|
+ String answer) {
|
|
|
|
|
|
// 校验当前登录用户和参数一致性
|
|
|
if (ExamRecordCacheUtil.getId(recordId) == null) {
|
|
@@ -162,10 +162,10 @@ public class TEMobileServiceImpl implements TEMobileService {
|
|
|
if (!studentId.equals(es.getStudentId())) {
|
|
|
throw new BusinessException("考试记录的学生Id和当前登录用户不一致");
|
|
|
}
|
|
|
- ExamRecordStatusEnum sta=ExamRecordCacheUtil.getStatus(recordId);
|
|
|
- if(ExamRecordStatusEnum.FINISHED.equals(sta)||ExamRecordStatusEnum.PERSISTED.equals(sta)) {
|
|
|
- throw new BusinessException("该考试已结束");
|
|
|
- }
|
|
|
+ ExamRecordStatusEnum sta = ExamRecordCacheUtil.getStatus(recordId);
|
|
|
+ if (ExamRecordStatusEnum.FINISHED.equals(sta) || ExamRecordStatusEnum.PERSISTED.equals(sta)) {
|
|
|
+ throw new BusinessException("该考试已结束");
|
|
|
+ }
|
|
|
ExamStudentAnswerCacheBean answerCache = (ExamStudentAnswerCacheBean) redisUtil.get(
|
|
|
RedisKeyHelper.examAnswerKey(recordId),
|
|
|
RedisKeyHelper.examAnswerHashKey(mainNumber, subNumber, subIndex));
|