|
@@ -0,0 +1,446 @@
|
|
|
|
+package cn.com.qmth.examcloud.core.oe.student.api.controller;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+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.google.common.collect.Maps;
|
|
|
|
+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.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.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.filestorage.FileStorageUtil;
|
|
|
|
+import cn.com.qmth.examcloud.support.redis.RedisKeyHelper;
|
|
|
|
+import cn.com.qmth.examcloud.web.filestorage.FileStorageHelper;
|
|
|
|
+import cn.com.qmth.examcloud.web.filestorage.FileStoragePathEnvInfo;
|
|
|
|
+import cn.com.qmth.examcloud.web.filestorage.FileStorageType;
|
|
|
|
+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;
|
|
|
|
+import cn.com.qmth.examcloud.web.support.Naked;
|
|
|
|
+import cn.com.qmth.examcloud.web.upyun.UpyunPathEnvironmentInfo;
|
|
|
|
+import cn.com.qmth.examcloud.web.upyun.UpyunService;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+
|
|
|
|
+@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
|
|
|
|
+ private ExamingSessionService examingSessionService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExamFileAnswerService examFileAnswerService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private UpyunService upyunService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisClient redisClient;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExamRecordDataService examRecordDataService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 开始考试
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "开始考试")
|
|
|
|
+ @GetMapping("/startExam")
|
|
|
|
+ public StartExamInfo startExam(@RequestParam Long examStudentId) {
|
|
|
|
+ User user = getAccessUser();
|
|
|
|
+ String sequenceLockKey = Constants.EXAM_CONTROL_LOCK_PREFIX + user.getUserId();
|
|
|
|
+ StartExamInfo startExamInfo;
|
|
|
|
+ // 开始考试上锁,分布式锁,系统在请求结束后会,自动释放锁,无需手动解锁
|
|
|
|
+ SequenceLockHelper.getLock(sequenceLockKey);
|
|
|
|
+ Check.isNull(examStudentId, "examStudentId不能为空");
|
|
|
|
+
|
|
|
|
+ startExamInfo = examControlService.startExam(examStudentId, user);
|
|
|
|
+ return startExamInfo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 断点续考:检查正在进行中的考试
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "断点续考:检查正在进行中的考试")
|
|
|
|
+ @GetMapping("/checkExamInProgress")
|
|
|
|
+ public ExamProcessResultInfo checkExamInProgress() {
|
|
|
|
+ User user = getAccessUser();
|
|
|
|
+ String sequenceLockKey = Constants.EXAM_CONTROL_LOCK_PREFIX + user.getUserId();
|
|
|
|
+ // 系统在请求结束后会,自动释放锁,无需手动解锁
|
|
|
|
+ SequenceLockHelper.getLock(sequenceLockKey);
|
|
|
|
+ ExamProcessResultInfo res = new ExamProcessResultInfo();
|
|
|
|
+ try {
|
|
|
|
+ CheckExamInProgressInfo info = examControlService.checkExamInProgress(user.getUserId());
|
|
|
|
+ res.setCode(Constants.COMMON_SUCCESS_CODE);
|
|
|
|
+ res.setData(info);
|
|
|
|
+ return res;
|
|
|
|
+ } catch (StatusException e) {
|
|
|
|
+ if (e.getCode().equals(Constants.EXAM_RECORD_NOT_END_STATUS_CODE)) {
|
|
|
|
+ res.setCode(Constants.PROCESSING_EXAM_RECORD_CODE);
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+ throw e;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 考试心跳
|
|
|
|
+ *
|
|
|
|
+ * @return 剩余时间
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "考试心跳")
|
|
|
|
+ @GetMapping("/examHeartbeat")
|
|
|
|
+ public Long examHeartbeat() {
|
|
|
|
+ User user = getAccessUser();
|
|
|
|
+ return examControlService.examHeartbeat(user);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 结束考试:交卷..
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "结束考试:交卷")
|
|
|
|
+ @GetMapping("/endExam")
|
|
|
|
+ public void endExam() {
|
|
|
|
+ User user = getAccessUser();
|
|
|
|
+ Long studentId = user.getUserId();
|
|
|
|
+ String sequenceLockKey = Constants.EXAM_CONTROL_LOCK_PREFIX + user.getUserId();
|
|
|
|
+ //系统在请求结束后会,自动释放锁,无需手动解锁
|
|
|
|
+ SequenceLockHelper.getLock(sequenceLockKey);
|
|
|
|
+
|
|
|
|
+ long st = System.currentTimeMillis();
|
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
|
+
|
|
|
|
+ ExamingSession examingSession = examingSessionService.getExamingSession(studentId);
|
|
|
|
+
|
|
|
|
+ if (log.isDebugEnabled()) {
|
|
|
|
+ log.debug("0 [END_EXAM] 交卷前处理耗时:" + (System.currentTimeMillis() - startTime) + " ms");
|
|
|
|
+ }
|
|
|
|
+ examControlService.handInExam(examingSession.getExamRecordDataId(), HandInExamType.MANUAL);
|
|
|
|
+ if (log.isDebugEnabled()) {
|
|
|
|
+ log.debug("1 [END_EXAM]合计 耗时:" + (System.currentTimeMillis() - st) + " ms");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取考试记录信息
|
|
|
|
+ *
|
|
|
|
+ * @param examRecordDataId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "获取考试记录信息")
|
|
|
|
+ @GetMapping("/getEndExamInfo")
|
|
|
|
+ public EndExamInfo getEndExamInfo(@RequestParam Long examRecordDataId) {
|
|
|
|
+ return examControlService.getEndExamInfo(examRecordDataId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取又拍云文件上传签名(微信小程序调用)
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "获取又拍云文件上传签名(微信小程序调用)")
|
|
|
|
+ @PostMapping("/upyunSignature")
|
|
|
|
+ public UpyunSignatureInfo getUpyunSignature(@ModelAttribute @Valid GetYunSignatureReq req) {
|
|
|
|
+ return examControlService.getUpyunSignature(req);
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 获取云存储上传签名(微信小程序调用)
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "获取文件上传签名(微信小程序调用)")
|
|
|
|
+ @PostMapping("/yunSignature")
|
|
|
|
+ public GetYunSignDomain getYunSignature(@ModelAttribute @Valid GetYunSignatureReq req) {
|
|
|
|
+
|
|
|
|
+ if(FileStorageType.UPYUN.equals(FileStorageUtil.getFileStorageType())) {
|
|
|
|
+ GetUpyunSignDomain result = new GetUpyunSignDomain();
|
|
|
|
+ Map<String, String> params = Maps.newHashMap();
|
|
|
|
+ UpyunSignatureInfo info=examControlService.getUpyunSignature(req);
|
|
|
|
+ String signIdentifier = String.valueOf(System.currentTimeMillis());
|
|
|
|
+ params.put("authorization", info.getSignature());
|
|
|
|
+ params.put("policy", info.getPolicy());
|
|
|
|
+ result.setAccessUrl(FileStorageHelper.getUrl(info.getUpyunFileDomain(), info.getFilePath()));
|
|
|
|
+ result.setFormUrl(info.getUploadUrl());
|
|
|
|
+ result.setFormParams(params);
|
|
|
|
+ result.setSignIdentifier(signIdentifier);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ if(FileStorageType.ALIYUN.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());
|
|
|
|
+
|
|
|
|
+ GetAliyunSignDomain result = new GetAliyunSignDomain();
|
|
|
|
+ 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", "未配置正确云存储类型");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 校验二维码(微信小程序调用)
|
|
|
|
+ */
|
|
|
|
+ @Naked
|
|
|
|
+ @ApiOperation(value = "校验二维码(微信小程序调用)")
|
|
|
|
+ @PostMapping("/checkQrCode")
|
|
|
|
+ public CheckQrCodeInfo checkQrCode(@RequestParam(required = true) String qrCode) {
|
|
|
|
+ return examControlService.checkQrCode(qrCode);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存上传的文件(微信小程序调用)
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "保存上传的文件(微信小程序调用)")
|
|
|
|
+ @PostMapping("/saveUploadedFile")
|
|
|
|
+ public String saveUploadedFile(@ModelAttribute @Valid SaveUploadedFileReq req) {
|
|
|
|
+ User user = getAccessUser();
|
|
|
|
+ ExamFileAnswer examFileAnswer = new ExamFileAnswer();
|
|
|
|
+ examFileAnswer.setExamRecordDataId(req.getExamRecordDataId());
|
|
|
|
+ examFileAnswer.setExamStudentId(req.getExamStudentId());
|
|
|
|
+ examFileAnswer.setQuestionOrder(req.getOrder());
|
|
|
|
+ examFileAnswer.setFilePath(req.getFilePath());
|
|
|
|
+ examFileAnswer.setStatus(FileAnswerAcknowledgeStatus.UNCONFIRMED);
|
|
|
|
+ examFileAnswer.setTransferFileType(req.getTransferFileType());
|
|
|
|
+ String fileAnswerId = RedisKeyHelper.getBuilder().studentFileAnswerKey(req.getExamRecordDataId(), req.getOrder());
|
|
|
|
+ examFileAnswerService.saveFileAnswer(fileAnswerId, examFileAnswer);
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ String fileUrl = "";
|
|
|
|
+ if (req.getFilePath().indexOf(",") > -1) {
|
|
|
|
+ for (String url : req.getFilePath().split(",")) {
|
|
|
|
+ fileUrl += FileStorageUtil.realPath(url)+ ",";
|
|
|
|
+ }
|
|
|
|
+ fileUrl = fileUrl.substring(0, fileUrl.length() - 1);
|
|
|
|
+ } else {
|
|
|
|
+ fileUrl = FileStorageUtil.realPath(req.getFilePath());
|
|
|
|
+ }
|
|
|
|
+ examControlService.sendFileAnswerToWebSocket(req.getExamRecordDataId(), req.getOrder(),
|
|
|
|
+ fileUrl, req.getTransferFileType(), user.getUserId(), user.getRootOrgId());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ examFileAnswerService.deleteFileAnswer(fileAnswerId);
|
|
|
|
+ throw new StatusException("100009", "消息通知失败", e);
|
|
|
|
+ }
|
|
|
|
+ return fileAnswerId;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //TODO 此方法有修改,微信需要修改代码
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询客户端对上传的文件的响应状态(微信小程序调用)
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "查询客户端对上传的文件的响应状态(微信小程序调用)")
|
|
|
|
+ @PostMapping("/getUploadedFileAcknowledgeStatus")
|
|
|
|
+ public String getUploadedFileAcknowledgeStatus(@ModelAttribute @Valid GetUploadedFileAcknowledgeStatusReq req) {
|
|
|
|
+ ExamFileAnswer fileAnswer = examFileAnswerService.getFileAnswer(req.getAcknowledgeId());
|
|
|
|
+ if (null != fileAnswer) {
|
|
|
|
+ return fileAnswer.getStatus().toString();
|
|
|
|
+ }
|
|
|
|
+ return FileAnswerAcknowledgeStatus.UNCONFIRMED.toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改上传音频结果推送状态
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "修改上传音频结果推送状态")
|
|
|
|
+ @PostMapping("/saveUploadedFileAcknowledgeStatus")
|
|
|
|
+ public void saveUploadedFileAcknowledgeStatus(@RequestBody @Valid SaveUploadedFileAcknowledgeStatusReq req) {
|
|
|
|
+ String acknowledgeId = RedisKeyHelper.getBuilder().studentFileAnswerKey(req.getExamRecordDataId(), req.getOrder());
|
|
|
|
+ ExamFileAnswer fileAnswer = examFileAnswerService.getFileAnswer(acknowledgeId);
|
|
|
|
+ if (null == fileAnswer) {
|
|
|
|
+ throw new StatusException("100010", "无效的数据");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fileAnswer.setStatus(FileAnswerAcknowledgeStatus.valueOf(req.getAcknowledgeStatus()));
|
|
|
|
+ examFileAnswerService.saveFileAnswer(acknowledgeId, fileAnswer);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //原接口,不作改动
|
|
|
|
+ @ApiOperation(value = "获取抓拍照片的又拍云签名")
|
|
|
|
+ @GetMapping("/getCapturePhotoUpYunSign")
|
|
|
|
+ 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", "文件后缀名不允许为空");
|
|
|
|
+ }
|
|
|
|
+ fileSuffix = fileSuffix.indexOf(".") == -1 ? "." + fileSuffix : fileSuffix;
|
|
|
|
+
|
|
|
|
+ GetUpyunSignDomain result = new GetUpyunSignDomain();
|
|
|
|
+ User accessUser = this.getAccessUser();
|
|
|
|
+ String signIdentifier = String.valueOf(System.currentTimeMillis());
|
|
|
|
+ String upyunSignRedisKey = Constants.EXAM_CAPTURE_PHOTO_UPYUN_SIGN_PREFIX
|
|
|
|
+ + accessUser.getUserId() + "_" + signIdentifier;
|
|
|
|
+
|
|
|
|
+ UpyunPathEnvironmentInfo env = new UpyunPathEnvironmentInfo();
|
|
|
|
+ env.setRootOrgId(accessUser.getRootOrgId().toString());
|
|
|
|
+ env.setUserId(accessUser.getUserId().toString());
|
|
|
|
+ env.setFileSuffix(fileSuffix);
|
|
|
|
+ YunHttpRequest upYunHttpRequest = upyunService.buildUpYunHttpRequest(Constants.CAPTURE_PHOTO_UPYUN_SITEID, env, query.getFileMd5());
|
|
|
|
+ redisClient.set(upyunSignRedisKey, upYunHttpRequest, 60);
|
|
|
|
+ result.setAccessUrl(upYunHttpRequest.getAccessUrl());
|
|
|
|
+ result.setFormUrl(upYunHttpRequest.getFormUrl());
|
|
|
|
+ result.setFormParams(upYunHttpRequest.getFormParams());
|
|
|
|
+ result.setSignIdentifier(signIdentifier);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "获取抓拍照片的云存储签名")
|
|
|
|
+ @GetMapping("/getCapturePhotoYunSign")
|
|
|
|
+ public GetYunSignDomain getCapturePhotoYunSign(GetYunSignDomainQuery query) {
|
|
|
|
+ if(FileStorageType.UPYUN.equals(FileStorageUtil.getFileStorageType())) {
|
|
|
|
+ return getUpYunSign(query);
|
|
|
|
+ }
|
|
|
|
+ if(FileStorageType.ALIYUN.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("300001", "查询条件不允许为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<GetUpyunSignDomain> signDomainList = new ArrayList<>();
|
|
|
|
+ for (GetUpyunSignDomainQuery query : batchQuery.getQueryList()) {
|
|
|
|
+ String fileSuffix = query.getFileSuffix();
|
|
|
|
+ if (StringUtils.isNullOrEmpty(fileSuffix)) {
|
|
|
|
+ throw new StatusException("", "文件后缀名不允许为空");
|
|
|
|
+ }
|
|
|
|
+ fileSuffix = fileSuffix.indexOf(".") == -1 ? "." + fileSuffix : fileSuffix;
|
|
|
|
+
|
|
|
|
+ GetUpyunSignDomain upyunSignDomain = new GetUpyunSignDomain();
|
|
|
|
+ User accessUser = this.getAccessUser();
|
|
|
|
+ String signIdentifier = String.valueOf(System.currentTimeMillis());
|
|
|
|
+ String upyunSignRedisKey = Constants.EXAM_CAPTURE_PHOTO_UPYUN_SIGN_PREFIX
|
|
|
|
+ + accessUser.getUserId() + "_" + signIdentifier;
|
|
|
|
+
|
|
|
|
+ UpyunPathEnvironmentInfo env = new UpyunPathEnvironmentInfo();
|
|
|
|
+ env.setRootOrgId(accessUser.getRootOrgId().toString());
|
|
|
|
+ env.setUserId(accessUser.getUserId().toString());
|
|
|
|
+ env.setFileSuffix(fileSuffix);
|
|
|
|
+ YunHttpRequest upYunHttpRequest = upyunService.buildUpYunHttpRequest(Constants.CAPTURE_PHOTO_UPYUN_SITEID, env, query.getFileMd5());
|
|
|
|
+ redisClient.set(upyunSignRedisKey, upYunHttpRequest, 60);
|
|
|
|
+ upyunSignDomain.setAccessUrl(upYunHttpRequest.getAccessUrl());
|
|
|
|
+ upyunSignDomain.setFormUrl(upYunHttpRequest.getFormUrl());
|
|
|
|
+ upyunSignDomain.setFormParams(upYunHttpRequest.getFormParams());
|
|
|
|
+ upyunSignDomain.setSignIdentifier(signIdentifier);
|
|
|
|
+
|
|
|
|
+ signDomainList.add(upyunSignDomain);
|
|
|
|
+ Util.sleep(TimeUnit.MILLISECONDS, 1);
|
|
|
|
+ }
|
|
|
|
+ BatchGetUpyunSignDomain result = new BatchGetUpyunSignDomain();
|
|
|
|
+ result.setList(signDomainList);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "获取二维码")
|
|
|
|
+ @PostMapping("/getQrCode")
|
|
|
|
+ public String getQrCode(@RequestBody GetQrCodeReq req) {
|
|
|
|
+ return examControlService.getQrCode(req, getAccessUser());
|
|
|
|
+ }
|
|
|
|
+}
|