|
@@ -1,20 +1,63 @@
|
|
|
package cn.com.qmth.examcloud.core.oe.student.api.controller;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+import javax.validation.Valid;
|
|
|
+
|
|
|
+import org.apache.commons.lang.math.RandomUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import com.mysql.cj.util.StringUtils;
|
|
|
+
|
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.util.Util;
|
|
|
import cn.com.qmth.examcloud.core.oe.student.base.utils.Check;
|
|
|
-import cn.com.qmth.examcloud.core.oe.student.bean.*;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.AliyunSignatureInfo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.BatchGetUpyunSignDomain;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.BatchGetUpyunSignDomainQuery;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.CheckExamInProgressInfo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.CheckQrCodeInfo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.EndExamInfo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.ExamProcessResultInfo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.GetAliyunSignDomain;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.GetQrCodeReq;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.GetUploadedFileAcknowledgeStatusReq;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.GetUpyunSignDomain;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.GetUpyunSignDomainQuery;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.GetYunSignDomain;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.GetYunSignDomainQuery;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.GetYunSignatureReq;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.SaveUploadedFileAcknowledgeStatusReq;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.SaveUploadedFileReq;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.StartExamInfo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.UpyunSignatureInfo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.YunSignatureInfo;
|
|
|
import cn.com.qmth.examcloud.core.oe.student.service.ExamControlService;
|
|
|
import cn.com.qmth.examcloud.core.oe.student.service.ExamFileAnswerService;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.service.ExamRecordDataService;
|
|
|
import cn.com.qmth.examcloud.core.oe.student.service.ExamingSessionService;
|
|
|
import cn.com.qmth.examcloud.support.Constants;
|
|
|
import cn.com.qmth.examcloud.support.enums.FileAnswerAcknowledgeStatus;
|
|
|
import cn.com.qmth.examcloud.support.enums.HandInExamType;
|
|
|
import cn.com.qmth.examcloud.support.examing.ExamFileAnswer;
|
|
|
+import cn.com.qmth.examcloud.support.examing.ExamRecordData;
|
|
|
import cn.com.qmth.examcloud.support.examing.ExamingSession;
|
|
|
import cn.com.qmth.examcloud.support.redis.RedisKeyHelper;
|
|
|
import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
|
|
|
+import cn.com.qmth.examcloud.web.filestorage.FileStoragePathEnvInfo;
|
|
|
+import cn.com.qmth.examcloud.web.filestorage.FileStorageType;
|
|
|
+import cn.com.qmth.examcloud.web.filestorage.FileStorageUtil;
|
|
|
+import cn.com.qmth.examcloud.web.filestorage.YunHttpRequest;
|
|
|
import cn.com.qmth.examcloud.web.helpers.SequenceLockHelper;
|
|
|
import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
@@ -22,22 +65,19 @@ import cn.com.qmth.examcloud.web.support.Naked;
|
|
|
import cn.com.qmth.examcloud.web.upyun.UpYunHttpRequest;
|
|
|
import cn.com.qmth.examcloud.web.upyun.UpyunPathEnvironmentInfo;
|
|
|
import cn.com.qmth.examcloud.web.upyun.UpyunService;
|
|
|
-import com.mysql.cj.util.StringUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-
|
|
|
-import javax.validation.Valid;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@Api(tags = "在线考试控制")
|
|
|
@RestController
|
|
|
@RequestMapping("${app.api.oe.student}/examControl")
|
|
|
public class ExamControlController extends ControllerSupport {
|
|
|
+ private static final String SEPARATOR = "/";
|
|
|
|
|
|
+ private static final String UNDERLINE = "_";
|
|
|
+
|
|
|
+ // 小程序答案上传目录
|
|
|
+ private static final String OE_ANSWER_FILE_PATH = "oe-answer-file";
|
|
|
@Autowired
|
|
|
private ExamControlService examControlService;
|
|
|
@Autowired
|
|
@@ -48,7 +88,9 @@ public class ExamControlController extends ControllerSupport {
|
|
|
private UpyunService upyunService;
|
|
|
@Autowired
|
|
|
private RedisClient redisClient;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private ExamRecordDataService examRecordDataService;
|
|
|
+
|
|
|
/**
|
|
|
* 开始考试
|
|
|
*/
|
|
@@ -148,9 +190,58 @@ public class ExamControlController extends ControllerSupport {
|
|
|
*/
|
|
|
@ApiOperation(value = "获取又拍云文件上传签名(微信小程序调用)")
|
|
|
@PostMapping("/upyunSignature")
|
|
|
- public UpyunSignatureInfo getUpyunSignature(@ModelAttribute @Valid GetUpyunSignatureReq req) {
|
|
|
+ public UpyunSignatureInfo getUpyunSignature(@ModelAttribute @Valid GetYunSignatureReq req) {
|
|
|
return examControlService.getUpyunSignature(req);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 获取云存储上传签名(微信小程序调用)
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "获取文件上传签名(微信小程序调用)")
|
|
|
+ @PostMapping("/yunSignature")
|
|
|
+ public YunSignatureInfo getYunSignature(@ModelAttribute @Valid GetYunSignatureReq req) {
|
|
|
+
|
|
|
+ if(FileStorageUtil.getFileStorageType()==null) {
|
|
|
+ throw new StatusException("5001", "未配置当前云存储类型");
|
|
|
+ }
|
|
|
+ if(FileStorageType.UPYUN.name().equals(FileStorageUtil.getFileStorageType())) {
|
|
|
+ return examControlService.getUpyunSignature(req);
|
|
|
+ }
|
|
|
+ if(FileStorageType.ALIYUN.name().equals(FileStorageUtil.getFileStorageType())) {
|
|
|
+ String fileSuffix = req.getFileSuffix();
|
|
|
+ if (StringUtils.isNullOrEmpty(fileSuffix)) {
|
|
|
+ throw new StatusException("5002", "文件后缀名不允许为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamRecordData examRecordData = examRecordDataService.getExamRecordDataCache(req.getExamRecordDataId());
|
|
|
+ fileSuffix = fileSuffix.indexOf(".") == -1 ? "." + fileSuffix : fileSuffix;
|
|
|
+
|
|
|
+ StringBuffer filePath = new StringBuffer();
|
|
|
+
|
|
|
+ filePath.append(OE_ANSWER_FILE_PATH).append(SEPARATOR)
|
|
|
+ .append(examRecordData.getExamStudentId()).append(SEPARATOR).append(req.getExamRecordDataId())
|
|
|
+ .append(SEPARATOR).append(req.getOrder()).append(SEPARATOR)
|
|
|
+ .append(examRecordData.getExamStudentId()).append(UNDERLINE).append(req.getExamRecordDataId())
|
|
|
+ .append(UNDERLINE).append(req.getOrder()).append(UNDERLINE).append(System.currentTimeMillis())
|
|
|
+ .append(RandomUtils.nextInt(8999) + 1000);
|
|
|
+
|
|
|
+ if (!StringUtils.isNullOrEmpty(req.getExt())) {
|
|
|
+ filePath.append(UNDERLINE).append(req.getExt());
|
|
|
+ }
|
|
|
+ filePath.append(".").append(req.getFileSuffix());
|
|
|
+
|
|
|
+ AliyunSignatureInfo result = new AliyunSignatureInfo();
|
|
|
+ String signIdentifier = String.valueOf(System.currentTimeMillis());
|
|
|
+ FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
|
|
|
+ env.setRelativePath(filePath.toString());
|
|
|
+ YunHttpRequest aliYunHttpRequest = FileStorageUtil.getSignature(FileStorageType.ALIYUN,Constants.MINI_PROGRAM_ANWSER_SITEID, env, req.getFileMd5());
|
|
|
+ result.setAccessUrl(aliYunHttpRequest.getAccessUrl());
|
|
|
+ result.setFormUrl(aliYunHttpRequest.getFormUrl());
|
|
|
+ result.setFormParams(aliYunHttpRequest.getFormParams());
|
|
|
+ result.setSignIdentifier(signIdentifier);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ throw new StatusException("5002", "未配置正确云存储类型");
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 校验二维码(微信小程序调用)
|
|
@@ -230,10 +321,16 @@ public class ExamControlController extends ControllerSupport {
|
|
|
examFileAnswerService.saveFileAnswer(acknowledgeId, fileAnswer);
|
|
|
}
|
|
|
|
|
|
+ //原接口,不作改动
|
|
|
@ApiOperation(value = "获取抓拍照片的又拍云签名")
|
|
|
@GetMapping("/getCapturePhotoUpYunSign")
|
|
|
- public GetUpyunSignDomain getCapturePhotoUpYunSign(GetUpyunSignDomainQuery query) {
|
|
|
- String fileSuffix = query.getFileSuffix();
|
|
|
+ public GetUpyunSignDomain getCapturePhotoUpYunSign(GetYunSignDomainQuery query) {
|
|
|
+ return getUpYunSign(query);
|
|
|
+ }
|
|
|
+
|
|
|
+ //又拍云签名
|
|
|
+ private GetUpyunSignDomain getUpYunSign(GetYunSignDomainQuery query) {
|
|
|
+ String fileSuffix = query.getFileSuffix();
|
|
|
if (StringUtils.isNullOrEmpty(fileSuffix)) {
|
|
|
throw new StatusException("200001", "文件后缀名不允许为空");
|
|
|
}
|
|
@@ -257,12 +354,53 @@ public class ExamControlController extends ControllerSupport {
|
|
|
result.setSignIdentifier(signIdentifier);
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取抓拍照片的云存储签名")
|
|
|
+ @GetMapping("/getCapturePhotoYunSign")
|
|
|
+ public GetYunSignDomain getCapturePhotoYunSign(GetYunSignDomainQuery query) {
|
|
|
+ if(FileStorageUtil.getFileStorageType()==null) {
|
|
|
+ throw new StatusException("3001", "未配置当前云存储类型");
|
|
|
+ }
|
|
|
+ if(FileStorageType.UPYUN.name().equals(FileStorageUtil.getFileStorageType())) {
|
|
|
+ return getUpYunSign(query);
|
|
|
+ }
|
|
|
+ if(FileStorageType.ALIYUN.name().equals(FileStorageUtil.getFileStorageType())) {
|
|
|
+ return getAliYunSign(query);
|
|
|
+ }
|
|
|
+ throw new StatusException("3002", "未配置正确云存储类型");
|
|
|
+ }
|
|
|
+
|
|
|
+ //阿里云签名
|
|
|
+ private GetAliyunSignDomain getAliYunSign(GetYunSignDomainQuery query) {
|
|
|
+ String fileSuffix = query.getFileSuffix();
|
|
|
+ if (StringUtils.isNullOrEmpty(fileSuffix)) {
|
|
|
+ throw new StatusException("4001", "文件后缀名不允许为空");
|
|
|
+ }
|
|
|
+ fileSuffix = fileSuffix.indexOf(".") == -1 ? "." + fileSuffix : fileSuffix;
|
|
|
+
|
|
|
+ GetAliyunSignDomain result = new GetAliyunSignDomain();
|
|
|
+ User accessUser = this.getAccessUser();
|
|
|
+ String signIdentifier = String.valueOf(System.currentTimeMillis());
|
|
|
+ String aliyunSignRedisKey = Constants.EXAM_CAPTURE_PHOTO_UPYUN_SIGN_PREFIX
|
|
|
+ + accessUser.getUserId() + "_" + signIdentifier;
|
|
|
+ FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
|
|
|
+ env.setRootOrgId(accessUser.getRootOrgId().toString());
|
|
|
+ env.setUserId(accessUser.getUserId().toString());
|
|
|
+ env.setFileSuffix(fileSuffix);
|
|
|
+ YunHttpRequest aliYunHttpRequest = FileStorageUtil.getSignature(FileStorageType.ALIYUN,Constants.CAPTURE_PHOTO_UPYUN_SITEID, env, query.getFileMd5());
|
|
|
+ redisClient.set(aliyunSignRedisKey, aliYunHttpRequest, 60);
|
|
|
+ result.setAccessUrl(aliYunHttpRequest.getAccessUrl());
|
|
|
+ result.setFormUrl(aliYunHttpRequest.getFormUrl());
|
|
|
+ result.setFormParams(aliYunHttpRequest.getFormParams());
|
|
|
+ result.setSignIdentifier(signIdentifier);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
@ApiOperation(value = "批量获取抓拍照片的又拍云签名")
|
|
|
@PostMapping("/batchGetCapturePhotoUpYunSign")
|
|
|
public BatchGetUpyunSignDomain batchGetCapturePhotoUpYunSign(@RequestBody BatchGetUpyunSignDomainQuery batchQuery) {
|
|
|
if (batchQuery.getQueryList() == null || batchQuery.getQueryList().isEmpty()) {
|
|
|
- throw new StatusException("200001", "查询条件不允许为空");
|
|
|
+ throw new StatusException("300001", "查询条件不允许为空");
|
|
|
}
|
|
|
|
|
|
List<GetUpyunSignDomain> signDomainList = new ArrayList<>();
|