|
@@ -16,7 +16,9 @@ import com.qmth.jkserver.service.ExamPaperTempService;
|
|
|
import com.qmth.jkserver.service.ExamStudentService;
|
|
|
import com.qmth.jkserver.service.KWService;
|
|
|
import com.qmth.jkserver.util.FileStoreUtil;
|
|
|
+import com.qmth.jkserver.util.JacksonUtil;
|
|
|
import net.lingala.zip4j.core.ZipFile;
|
|
|
+import org.apache.commons.io.FilenameUtils;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -24,6 +26,7 @@ import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.context.annotation.Scope;
|
|
|
import org.springframework.context.annotation.ScopedProxyMode;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -114,6 +117,22 @@ public class ExamPaperTempServiceImpl extends ServiceImpl<ExamPaperTempDao, Exam
|
|
|
UnZipUtils.doUnZip(paperAnswerTarget, answerDir, paperAnswerTarget.getParent());
|
|
|
deletePaths.add(answerDir.getAbsolutePath());
|
|
|
|
|
|
+ Map<String, Object> map = new LinkedHashMap<>();
|
|
|
+ map = SystemConstant.getFileDirectoryCount(answerDir, map);
|
|
|
+
|
|
|
+ File finalAnswerDir = null;
|
|
|
+ if (!CollectionUtils.isEmpty(map)) {
|
|
|
+ log.info("fileDirectoryCount:{}", JacksonUtil.parseJson(map));
|
|
|
+ int fileDirectoryCount = (int) map.get("fileDirectoryCount");
|
|
|
+ if (fileDirectoryCount == 3) {
|
|
|
+ finalAnswerDir = new File((String) map.get("1"));
|
|
|
+ } else if (fileDirectoryCount == 4) {
|
|
|
+ finalAnswerDir = new File((String) map.get("2"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ finalAnswerDir = answerDir;
|
|
|
+ }
|
|
|
+
|
|
|
//获取开卷密码
|
|
|
List<ExamPaperUncoiling> examPaperUncoilingList = kwService.queryExamPaperUncoiling(new ExamPaperUncoilingParams(examCode));
|
|
|
Map<String, File> mapFile = new HashMap<>();
|
|
@@ -126,8 +145,9 @@ public class ExamPaperTempServiceImpl extends ServiceImpl<ExamPaperTempDao, Exam
|
|
|
Map<String, File> finalMapFile = mapFile;
|
|
|
paperAnswerFile = Objects.isNull(paperAnswerFile) ? new ArrayList<>() : paperAnswerFile;
|
|
|
List<File> finalPaperAnswerFile = paperAnswerFile;
|
|
|
+ File finalAnswerDir1 = finalAnswerDir;
|
|
|
paperCourseCodeTempMap.forEach((k, v) -> {
|
|
|
- finalPaperAnswerFile.add(createPaperAnswerFile(k, finalMapFile, answerDir));
|
|
|
+ finalPaperAnswerFile.add(createPaperAnswerFile(k, finalMapFile, finalAnswerDir1));
|
|
|
});
|
|
|
}
|
|
|
FileDto fileDto = new FileDto(paperAnswerFile);
|
|
@@ -265,11 +285,12 @@ public class ExamPaperTempServiceImpl extends ServiceImpl<ExamPaperTempDao, Exam
|
|
|
*
|
|
|
* @param examCode
|
|
|
* @param examStudentAnswerList
|
|
|
+ * @param attachmentMap
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
@Override
|
|
|
- public FileDto getExamStudentAnswerJsonFile(String examCode, List<ExamStudentAnswer> examStudentAnswerList) throws IOException {
|
|
|
+ public FileDto getExamStudentAnswerJsonFile(String examCode, List<ExamStudentAnswer> examStudentAnswerList,Map<Long, Attachment> attachmentMap) throws IOException {
|
|
|
FileStoreUtil fileStoreConfig = SpringContextHolder.getBean(FileStoreUtil.class);
|
|
|
// Query jkExamStudentAnswerQuery = new Query();
|
|
|
// jkExamStudentAnswerQuery.addCriteria(Criteria.where("examCode").is(examCode));
|
|
@@ -280,43 +301,57 @@ public class ExamPaperTempServiceImpl extends ServiceImpl<ExamPaperTempDao, Exam
|
|
|
// throw new JkServerException("考生考试记录为空");
|
|
|
// }
|
|
|
//Map<String, ExamStudentAnswer> examStudentAnswerMap = examStudentAnswerList.stream().collect(Collectors.toMap(e -> e.getDecodeFile().getAccessUri(), Function.identity(), (dto1, dto2) -> dto1));
|
|
|
- Map<String, ExamStudentAnswer> examStudentAnswerMap = new LinkedHashMap<>();
|
|
|
+ Map<String, List<ExamStudentAnswer>> examStudentAnswerMap = new LinkedHashMap<>();
|
|
|
for (ExamStudentAnswer examStudentAnswer : examStudentAnswerList) {
|
|
|
Attachment attachment = attachmentService.getById(examStudentAnswer.getDecodeFileId());
|
|
|
- examStudentAnswerMap.put(attachment.getAccessUri(), examStudentAnswer);
|
|
|
+ if (!examStudentAnswerMap.containsKey(attachment.getAccessUri())) {
|
|
|
+ examStudentAnswerMap.put(attachment.getAccessUri(), new ArrayList<>(Arrays.asList(examStudentAnswer)));
|
|
|
+ } else {
|
|
|
+ List<ExamStudentAnswer> examStudentAnswers = examStudentAnswerMap.get(attachment.getAccessUri());
|
|
|
+ examStudentAnswers.add(examStudentAnswer);
|
|
|
+ examStudentAnswerMap.put(attachment.getAccessUri(), examStudentAnswers);
|
|
|
+ }
|
|
|
}
|
|
|
List<String> deletePaths = new ArrayList<>();
|
|
|
List<LinkedMultiValueMap<String, File[]>> linkedMultiValueMapList = new ArrayList<>();
|
|
|
examStudentAnswerMap.forEach((k, v) -> {
|
|
|
LinkedMultiValueMap<String, File[]> linkedMultiValueMap = new LinkedMultiValueMap<>();
|
|
|
- Attachment attachment = attachmentService.getById(v.getDecodeFileId());
|
|
|
-// File target = SystemConstant.getAttachmentFile(v.getDecodeFile());
|
|
|
- File target = null;
|
|
|
- try {
|
|
|
- target = SystemConstant.getAttachmentFile(attachment);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- if (fileStoreConfig.workIsOss()) {
|
|
|
- deletePaths.add(target.getParentFile().getAbsolutePath());
|
|
|
- }
|
|
|
- File explodeTempDir = new File(target.getParentFile() + File.separator + SystemConstant.getNanoId());
|
|
|
- try {
|
|
|
- UnZipUtils.doUnZip(target, explodeTempDir, target.getParent());
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ for (ExamStudentAnswer es : v) {
|
|
|
+ Attachment attachment = null;
|
|
|
+ if (!attachmentMap.containsKey(es.getDecodeFileId())) {
|
|
|
+ attachment = attachmentService.getById(es.getDecodeFileId());
|
|
|
+ File target = null;
|
|
|
+ try {
|
|
|
+ target = SystemConstant.getAttachmentFile(attachment);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (fileStoreConfig.workIsOss()) {
|
|
|
+ deletePaths.add(target.getParentFile().getAbsolutePath());
|
|
|
+ }
|
|
|
+ File explodeTempDir = new File(target.getParentFile() + File.separator + SystemConstant.getNanoId());
|
|
|
+ try {
|
|
|
+ UnZipUtils.doUnZip(target, explodeTempDir, target.getParent());
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
|
|
|
- File fileJson = new File(explodeTempDir.getAbsolutePath() + File.separator + "json");
|
|
|
- if (!fileJson.exists()) {
|
|
|
- throw new JkServerException(JkServerException.SYSTEM_EXCEPTION.getCode(), "考生作答文件在服务器上不存在");
|
|
|
+ File fileJson = new File(explodeTempDir.getAbsolutePath() + File.separator + "json");
|
|
|
+ if (!fileJson.exists()) {
|
|
|
+ throw new JkServerException(JkServerException.SYSTEM_EXCEPTION.getCode(), "考生作答文件在服务器上不存在");
|
|
|
+ }
|
|
|
+ attachment.setFileJson(fileJson);
|
|
|
+ attachmentMap.put(es.getDecodeFileId(), attachment);
|
|
|
+ } else {
|
|
|
+ attachment = attachmentMap.get(es.getDecodeFileId());
|
|
|
+ }
|
|
|
+ ExamStudent examStudent = examStudentService.getById(es.getStudentId());
|
|
|
+ if (!linkedMultiValueMap.containsKey(examStudent.getBatchId())) {
|
|
|
+ linkedMultiValueMap.add(examStudent.getBatchId(), attachment.getFileJson().listFiles());
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- ExamStudent examStudent = examStudentService.getById(v.getStudentId());
|
|
|
-// linkedMultiValueMap.add(v.getStudent().getBatchId(), fileJson.listFiles());
|
|
|
- linkedMultiValueMap.add(examStudent.getBatchId(), fileJson.listFiles());
|
|
|
linkedMultiValueMapList.add(linkedMultiValueMap);
|
|
|
});
|
|
|
return new FileDto(linkedMultiValueMapList, deletePaths);
|
|
@@ -360,6 +395,7 @@ public class ExamPaperTempServiceImpl extends ServiceImpl<ExamPaperTempDao, Exam
|
|
|
in = new FileInputStream(answerFiles[0]);
|
|
|
ou = new ByteArrayOutputStream();
|
|
|
IOUtils.copy(in, ou);
|
|
|
+ log.info("ext:{},path{}", FilenameUtils.getExtension(file.getPath()), file.getAbsolutePath());
|
|
|
JSONObject answerJson = JSONObject.parseObject(new String(ou.toByteArray(), StandardCharsets.UTF_8));
|
|
|
// log.info("answerJson:{}", answerJson.toJSONString());
|
|
|
JSONArray answerDetails = answerJson.getJSONArray("details");
|