|
@@ -2,7 +2,7 @@ package cn.com.qmth.examcloud.core.oe.student.api.controller;
|
|
|
|
|
|
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.OeConstants;
|
|
|
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.client.CourseInfo;
|
|
@@ -13,19 +13,14 @@ import cn.com.qmth.examcloud.support.Constants;
|
|
|
import cn.com.qmth.examcloud.support.enums.FileAnswerAcknowledgeStatus;
|
|
|
import cn.com.qmth.examcloud.support.examing.ExamFileAnswer;
|
|
|
import cn.com.qmth.examcloud.support.examing.ExamRecordData;
|
|
|
-import cn.com.qmth.examcloud.support.filestorage.FileStorageUtil;
|
|
|
+import cn.com.qmth.examcloud.support.fss.FssFactory;
|
|
|
+import cn.com.qmth.examcloud.support.fss.FssHelper;
|
|
|
+import cn.com.qmth.examcloud.support.fss.model.FssSignInfo;
|
|
|
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 com.google.common.collect.Maps;
|
|
|
import com.mysql.cj.util.StringUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -39,10 +34,6 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.validation.Valid;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@Api(tags = "在线考试控制")
|
|
|
@RestController
|
|
@@ -64,9 +55,6 @@ public class ExamControlController extends ControllerSupport {
|
|
|
@Autowired
|
|
|
private ExamFileAnswerService examFileAnswerService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private UpyunService upyunService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private RedisClient redisClient;
|
|
|
|
|
@@ -212,87 +200,60 @@ public class ExamControlController extends ControllerSupport {
|
|
|
return examControlService.getEndExamInfo(examRecordDataId);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取又拍云文件上传签名(微信小程序调用)
|
|
|
- */
|
|
|
@Deprecated
|
|
|
- @ApiOperation(value = "获取又拍云文件上传签名(微信小程序调用,废弃)")
|
|
|
+ @ApiOperation(value = "获取作答文件上传签名-又拍云(微信小程序调用,废弃)")
|
|
|
@PostMapping("/upyunSignature")
|
|
|
- public UpyunSignatureInfo getUpyunSignature(@ModelAttribute @Valid GetYunSignatureReq req) {
|
|
|
- return examControlService.getUpyunSignature(req);
|
|
|
+ public FssSignInfo getUpyunSignature(@ModelAttribute @Valid GetYunSignatureReq req) {
|
|
|
+ return getAnswerUploadSign(req);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取云存储上传签名(微信小程序调用)
|
|
|
- */
|
|
|
- @ApiOperation(value = "获取文件上传签名(微信小程序调用)")
|
|
|
+ @ApiOperation(value = "获取作答文件上传签名(微信小程序调用)")
|
|
|
@PostMapping("/yunSignature")
|
|
|
- public GetYunSignDomain getYunSignature(@ModelAttribute @Valid GetYunSignatureReq req) {
|
|
|
- FileStorageType fileStorageType = FileStorageUtil.getFileStorageType();
|
|
|
-
|
|
|
- // 是否为环境监测场景
|
|
|
- boolean isTestDev = Constants.OE_ENV_CHECK_EXAM_RECORD_DATA_ID.equals(req.getExamRecordDataId());
|
|
|
+ public FssSignInfo getYunSignature(@ModelAttribute @Valid GetYunSignatureReq req) {
|
|
|
+ return getAnswerUploadSign(req);
|
|
|
+ }
|
|
|
|
|
|
- if (FileStorageType.UPYUN.equals(fileStorageType)) {
|
|
|
- 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;
|
|
|
+ private FssSignInfo getAnswerUploadSign(GetYunSignatureReq req) {
|
|
|
+ String fileSuffix = req.getFileSuffix();
|
|
|
+ if (StringUtils.isNullOrEmpty(fileSuffix)) {
|
|
|
+ throw new StatusException("5002", "文件后缀名不允许为空");
|
|
|
}
|
|
|
+ fileSuffix = !fileSuffix.contains(".") ? "." + fileSuffix : fileSuffix;
|
|
|
|
|
|
- if (FileStorageType.ALIYUN.equals(fileStorageType)) {
|
|
|
- String fileSuffix = req.getFileSuffix();
|
|
|
- if (StringUtils.isNullOrEmpty(fileSuffix)) {
|
|
|
- throw new StatusException("5002", "文件后缀名不允许为空");
|
|
|
+ Long examStudentId;
|
|
|
+ // 是否为环境监测场景
|
|
|
+ boolean isTestDev = Constants.OE_ENV_CHECK_EXAM_RECORD_DATA_ID.equals(req.getExamRecordDataId());
|
|
|
+ if (isTestDev) {
|
|
|
+ examStudentId = Constants.OE_ENV_CHECK_EXAM_STUDENT_ID;
|
|
|
+ } else {
|
|
|
+ ExamRecordData examRecordData = examRecordDataService.getExamRecordDataCache(req.getExamRecordDataId());
|
|
|
+ if (examRecordData == null) {
|
|
|
+ log.warn("ExamRecordDataCache not exist! examRecordDataId = {}", req.getExamRecordDataId());
|
|
|
+ throw new StatusException("5002", "请求参数值有误!");
|
|
|
}
|
|
|
- fileSuffix = !fileSuffix.contains(".") ? "." + fileSuffix : fileSuffix;
|
|
|
+ examStudentId = examRecordData.getExamStudentId();
|
|
|
+ }
|
|
|
|
|
|
- Long examStudentId;
|
|
|
- if (isTestDev) {
|
|
|
- examStudentId = Constants.OE_ENV_CHECK_EXAM_STUDENT_ID;
|
|
|
- } else {
|
|
|
- ExamRecordData examRecordData = examRecordDataService.getExamRecordDataCache(req.getExamRecordDataId());
|
|
|
- if (examRecordData == null) {
|
|
|
- log.warn("ExamRecordDataCache not exist! examRecordDataId = {}", req.getExamRecordDataId());
|
|
|
- throw new StatusException("5002", "请求参数值有误!");
|
|
|
- }
|
|
|
- examStudentId = examRecordData.getExamStudentId();
|
|
|
- }
|
|
|
+ // 路径:/oe-answer-file/{examStudentId}/{examRecordDataId}/{order}/{examStudentId}_{examRecordDataId}_{order}_{timeMillis}{randomNum}.jpg",
|
|
|
+ StringBuilder filePath = new StringBuilder();
|
|
|
+ filePath.append(OE_ANSWER_FILE_PATH).append(SEPARATOR)
|
|
|
+ .append(examStudentId).append(SEPARATOR).append(req.getExamRecordDataId())
|
|
|
+ .append(SEPARATOR).append(req.getOrder()).append(SEPARATOR)
|
|
|
+ .append(examStudentId).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(fileSuffix);
|
|
|
|
|
|
- StringBuffer filePath = new StringBuffer();
|
|
|
- filePath.append(OE_ANSWER_FILE_PATH).append(SEPARATOR)
|
|
|
- .append(examStudentId).append(SEPARATOR).append(req.getExamRecordDataId())
|
|
|
- .append(SEPARATOR).append(req.getOrder()).append(SEPARATOR)
|
|
|
- .append(examStudentId).append(UNDERLINE).append(req.getExamRecordDataId())
|
|
|
- .append(UNDERLINE).append(req.getOrder()).append(UNDERLINE).append(System.currentTimeMillis())
|
|
|
- .append(RandomUtils.nextInt(8999) + 1000);
|
|
|
+ FssSignInfo result = FssFactory.getInstance(false).buildSign(filePath.toString());
|
|
|
|
|
|
- if (!StringUtils.isNullOrEmpty(req.getExt())) {
|
|
|
- filePath.append(UNDERLINE).append(req.getExt());
|
|
|
- }
|
|
|
- filePath.append(fileSuffix);
|
|
|
-
|
|
|
- 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;
|
|
|
- }
|
|
|
+ String signIdentifier = String.valueOf(System.currentTimeMillis());
|
|
|
+ result.setSignIdentifier(signIdentifier);
|
|
|
|
|
|
- throw new StatusException("5002", "未配置正确云存储类型");
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -326,11 +287,11 @@ public class ExamControlController extends ControllerSupport {
|
|
|
String fileUrl = "";
|
|
|
if (req.getFilePath().indexOf(",") > -1) {
|
|
|
for (String url : req.getFilePath().split(",")) {
|
|
|
- fileUrl += FileStorageUtil.realPath(url) + ",";
|
|
|
+ fileUrl += FssHelper.finalFileUrl(url) + ",";
|
|
|
}
|
|
|
fileUrl = fileUrl.substring(0, fileUrl.length() - 1);
|
|
|
} else {
|
|
|
- fileUrl = FileStorageUtil.realPath(req.getFilePath());
|
|
|
+ fileUrl = FssHelper.finalFileUrl(req.getFilePath());
|
|
|
}
|
|
|
examControlService.sendFileAnswerToWebSocket(req.getExamRecordDataId(), req.getOrder(),
|
|
|
fileUrl, req.getTransferFileType(), user.getUserId(), user.getRootOrgId());
|
|
@@ -373,115 +334,35 @@ public class ExamControlController extends ControllerSupport {
|
|
|
}
|
|
|
|
|
|
@Deprecated
|
|
|
- @ApiOperation(value = "获取抓拍照片的又拍云签名(废弃)")
|
|
|
+ @ApiOperation(value = "获取抓拍照片文件上传签名信息-又拍云(废弃)")
|
|
|
@GetMapping("/getCapturePhotoUpYunSign")
|
|
|
- public GetUpyunSignDomain getCapturePhotoUpYunSign(GetYunSignDomainQuery query) {
|
|
|
- return getUpYunSign(query);
|
|
|
+ public FssSignInfo getCapturePhotoUpYunSign(GetYunSignDomainQuery query) {
|
|
|
+ return getCaptureUploadSign(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 = CacheConstants.CACHE_OE_UPYUN_IMAGE_SIGN
|
|
|
- + 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 = "获取抓拍照片的云存储签名")
|
|
|
+ @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", "未配置正确云存储类型");
|
|
|
+ public FssSignInfo getCapturePhotoYunSign(GetYunSignDomainQuery query) {
|
|
|
+ return getCaptureUploadSign(query);
|
|
|
}
|
|
|
|
|
|
- //阿里云签名
|
|
|
- private GetAliyunSignDomain getAliYunSign(GetYunSignDomainQuery query) {
|
|
|
- String fileSuffix = query.getFileSuffix();
|
|
|
- if (StringUtils.isNullOrEmpty(fileSuffix)) {
|
|
|
+ private FssSignInfo getCaptureUploadSign(GetYunSignDomainQuery query) {
|
|
|
+ User accessUser = this.getAccessUser();
|
|
|
+ if (StringUtils.isNullOrEmpty(query.getFileSuffix())) {
|
|
|
throw new StatusException("4001", "文件后缀名不允许为空");
|
|
|
}
|
|
|
- fileSuffix = fileSuffix.indexOf(".") == -1 ? "." + fileSuffix : fileSuffix;
|
|
|
|
|
|
- GetAliyunSignDomain result = new GetAliyunSignDomain();
|
|
|
- User accessUser = this.getAccessUser();
|
|
|
+ String fileSuffix = query.getFileSuffix().startsWith(".") ? query.getFileSuffix() : "." + query.getFileSuffix();
|
|
|
+
|
|
|
+ // 路径:/capture_photo/{rootOrgId}/{userId}/{timeMillis}{fileSuffix}
|
|
|
+ String filePath = String.format(OeConstants.CAPTURE_PHOTO_PATH, accessUser.getRootOrgId(), accessUser.getUserId(), System.currentTimeMillis(), fileSuffix);
|
|
|
+ FssSignInfo result = FssFactory.getInstance(false).buildSign(filePath);
|
|
|
+
|
|
|
String signIdentifier = String.valueOf(System.currentTimeMillis());
|
|
|
- String aliyunSignRedisKey = CacheConstants.CACHE_OE_UPYUN_IMAGE_SIGN
|
|
|
- + 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());
|
|
|
+ String signRedisKey = CacheConstants.CACHE_OE_UPYUN_IMAGE_SIGN + accessUser.getUserId() + "_" + signIdentifier;
|
|
|
+ redisClient.set(signRedisKey, result, 60);
|
|
|
result.setSignIdentifier(signIdentifier);
|
|
|
- return result;
|
|
|
- }
|
|
|
|
|
|
- @Deprecated
|
|
|
- @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 = CacheConstants.CACHE_OE_UPYUN_IMAGE_SIGN
|
|
|
- + 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;
|
|
|
}
|
|
|
|