|
@@ -1,63 +1,133 @@
|
|
|
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 org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.qmth.themis.business.bean.mobile.MobileAuthorizationBean;
|
|
|
import com.qmth.themis.business.bean.mobile.MobileAuthorizationMonitorBean;
|
|
|
import com.qmth.themis.business.bean.mobile.MobileAuthorizationParamBean;
|
|
|
import com.qmth.themis.business.bean.mobile.MobileAuthorizationUploadBean;
|
|
|
+import com.qmth.themis.business.cache.ExamRecordCacheUtil;
|
|
|
import com.qmth.themis.business.cache.MobileAuthCacheUtil;
|
|
|
+import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
|
|
|
+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.enums.ExamRecordStatusEnum;
|
|
|
import com.qmth.themis.business.enums.MobileModeEnum;
|
|
|
+import com.qmth.themis.business.service.TEExamStudentService;
|
|
|
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.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;
|
|
|
|
|
|
@Service
|
|
|
public class TEMobileServiceImpl implements TEMobileService {
|
|
|
|
|
|
- @Resource
|
|
|
- RedisUtil redisUtil;
|
|
|
-
|
|
|
+ @Resource
|
|
|
+ RedisUtil redisUtil;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TEExamStudentService examStudentService;
|
|
|
+
|
|
|
@Override
|
|
|
- public MobileAuthorizationBean authorization(MobileAuthorizationParamBean param) {
|
|
|
- MobileModeEnum mode=param.getMode();
|
|
|
- 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);
|
|
|
+ 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(new Date().getTime());
|
|
|
+ ret.setMode(mode);
|
|
|
+ //测试
|
|
|
+ String test = SignatureInfo.build(SignatureType.TOKEN, sessionId, token);
|
|
|
+ ret.setAccessToken(test);
|
|
|
return ret;
|
|
|
}
|
|
|
-
|
|
|
- private MobileAuthorizationBean monitorAuthorization(MobileModeEnum mode,String code) {
|
|
|
- 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) {
|
|
|
+
|
|
|
+ private MobileAuthorizationBean monitorAuthorization(MobileModeEnum mode, String code) {
|
|
|
+ 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();
|
|
|
+ MobileAuthorizationMonitorBean ret = new MobileAuthorizationMonitorBean();
|
|
|
ret.setRecordId(recordId);
|
|
|
ret.setMonitorKey(monitorKey);
|
|
|
ret.setMonitorVideoSource(monitorVideoSource);
|
|
|
ret.setMonitorAudioEnable(monitorAudioEnable);
|
|
|
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) {
|
|
|
+
|
|
|
+ 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();
|
|
|
+ MobileAuthorizationUploadBean ret = new MobileAuthorizationUploadBean();
|
|
|
ret.setRecordId(recordId);
|
|
|
ret.setMainNumber(mainNumber);
|
|
|
ret.setSubNumber(subNumber);
|