|
@@ -36,6 +36,7 @@ import com.qmth.teachcloud.common.service.*;
|
|
import com.qmth.teachcloud.common.util.*;
|
|
import com.qmth.teachcloud.common.util.*;
|
|
import com.qmth.teachcloud.common.util.excel.ExcelError;
|
|
import com.qmth.teachcloud.common.util.excel.ExcelError;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
@@ -909,6 +910,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
public Map<String, Object> executeDownloadPdfLogic(Map<String, Object> map) throws Exception {
|
|
public Map<String, Object> executeDownloadPdfLogic(Map<String, Object> map) throws Exception {
|
|
|
|
+ List<File> sourceFileList = null;
|
|
|
|
+ File zipFile = null;
|
|
|
|
+ String zipLocalRootPath = null;
|
|
try {
|
|
try {
|
|
TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
|
|
TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
|
|
JSONArray jsonArray = JSONArray.parseArray(tbTask.getRemark());
|
|
JSONArray jsonArray = JSONArray.parseArray(tbTask.getRemark());
|
|
@@ -918,59 +922,80 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
}
|
|
}
|
|
|
|
|
|
//查询examDetail
|
|
//查询examDetail
|
|
- List<ExamDetail> examDetailList = examDetailService.listByIds(Arrays.asList(arraysParams.getIds()));
|
|
|
|
- if (Objects.nonNull(examDetailList)) {
|
|
|
|
- Set<Long> attachmentIds = new HashSet<>();
|
|
|
|
- Set<Long> allAttachmentIds = examDetailList.stream().map(ExamDetail::getAttachmentId).collect(Collectors.toSet());
|
|
|
|
- if (!CollectionUtils.isEmpty(allAttachmentIds)) {
|
|
|
|
- attachmentIds.addAll(allAttachmentIds);
|
|
|
|
- }
|
|
|
|
- Set<Long> cardAttachmentIds = examDetailList.stream().map(ExamDetail::getCardAttachmentId).collect(Collectors.toSet());
|
|
|
|
- if (!CollectionUtils.isEmpty(cardAttachmentIds)) {
|
|
|
|
- attachmentIds.addAll(cardAttachmentIds);
|
|
|
|
|
|
+// List<ExamDetail> examDetailList = examDetailService.listByIds(Arrays.asList(arraysParams.getIds()));
|
|
|
|
+ List<ExamDetailPdfDownloadDto> examDetailList = examDetailService.findPdfDownload(Arrays.asList(arraysParams.getIds()));
|
|
|
|
+ if (!CollectionUtils.isEmpty(examDetailList)) {
|
|
|
|
+ LocalDateTime nowTime = LocalDateTime.now();
|
|
|
|
+ StringJoiner stringJoiner = new StringJoiner("")
|
|
|
|
+ .add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator);
|
|
|
|
+ StringJoiner dirName = new StringJoiner("")
|
|
|
|
+ .add(UploadFileEnum.FILE.getTitle()).add(File.separator)
|
|
|
|
+ .add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
|
+ .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
|
+ .add(String.format("%02d", nowTime.getDayOfMonth()))
|
|
|
|
+ .add(File.separator).add(SystemConstant.getUuid()).add(SystemConstant.ZIP_PREFIX);
|
|
|
|
+ zipFile = new File(stringJoiner.toString() + dirName.toString());
|
|
|
|
+ if (!zipFile.getParentFile().exists()) {
|
|
|
|
+ zipFile.getParentFile().mkdirs();
|
|
}
|
|
}
|
|
- List<BasicAttachment> basicAttachmentList = basicAttachmentService.listByIds(attachmentIds);
|
|
|
|
-
|
|
|
|
- if (Objects.nonNull(basicAttachmentList) && basicAttachmentList.size() > 0) {
|
|
|
|
- LocalDateTime nowTime = LocalDateTime.now();
|
|
|
|
- StringJoiner stringJoiner = new StringJoiner("")
|
|
|
|
- .add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator);
|
|
|
|
- StringJoiner dirName = new StringJoiner("")
|
|
|
|
- .add(UploadFileEnum.FILE.getTitle()).add(File.separator)
|
|
|
|
- .add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
|
- .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
|
- .add(String.format("%02d", nowTime.getDayOfMonth()))
|
|
|
|
- .add(File.separator).add(SystemConstant.getUuid()).add(SystemConstant.ZIP_PREFIX);
|
|
|
|
-
|
|
|
|
- File zipFile = new File(stringJoiner.toString() + dirName.toString());
|
|
|
|
- if (!zipFile.getParentFile().exists()) {
|
|
|
|
- zipFile.getParentFile().mkdirs();
|
|
|
|
-// zipFile.createNewFile();
|
|
|
|
- }
|
|
|
|
|
|
|
|
- boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
|
|
|
+ Long time = System.currentTimeMillis();
|
|
|
|
+ zipLocalRootPath = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + time;
|
|
|
|
+ sourceFileList = new ArrayList<>(examDetailList.size() * 5);
|
|
|
|
+ for (ExamDetailPdfDownloadDto e : examDetailList) {
|
|
|
|
+ StringJoiner dirPath = new StringJoiner("")
|
|
|
|
+ .add(String.valueOf(time)).add(File.separator)
|
|
|
|
+ .add(e.getSemesterName()).add(File.separator)
|
|
|
|
+ .add(e.getExamName()).add(File.separator)
|
|
|
|
+ .add(e.getCourseNameCode()).add(File.separator)
|
|
|
|
+ .add(e.getPackageCode()).add(File.separator)
|
|
|
|
+ .add(e.getCourseNameCode()).add("-")
|
|
|
|
+ .add(e.getPaperNumber()).add("-");
|
|
|
|
+ //试卷合并文件
|
|
|
|
+ if (Objects.nonNull(e.getAttachmentId())) {
|
|
|
|
+ BasicAttachment attachment = basicAttachmentService.getById(e.getAttachmentId());
|
|
|
|
+ File paperFile = getAttachmentFile(attachment, dirPath.toString() + PdfTypeEnum.PAPER.getTitle() + SystemConstant.PDF_PREFIX);
|
|
|
|
+ if (Objects.nonNull(paperFile)) {
|
|
|
|
+ sourceFileList.add(paperFile);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- List<File> sourceFiles = new ArrayList<>();
|
|
|
|
- for (BasicAttachment basicAttachment : basicAttachmentList) {
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
|
|
|
|
- UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
|
|
|
|
-
|
|
|
|
- StringJoiner stringJoinerPdf = new StringJoiner("")
|
|
|
|
- .add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator)
|
|
|
|
- .add((String) jsonObject.get(SystemConstant.PATH));
|
|
|
|
- File htmlFile = null;
|
|
|
|
- if (oss) {
|
|
|
|
- htmlFile = fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), stringJoinerPdf.toString(), uploadFileEnum.getFssType());
|
|
|
|
- } else {
|
|
|
|
- htmlFile = new File((String) jsonObject.get(SystemConstant.PATH));
|
|
|
|
|
|
+ //题卡合并文件
|
|
|
|
+ if (Objects.nonNull(e.getCardAttachmentId())) {
|
|
|
|
+ BasicAttachment cardAttachment = basicAttachmentService.getById(e.getCardAttachmentId());
|
|
|
|
+ File cardFile = getAttachmentFile(cardAttachment, dirPath.toString() + PdfTypeEnum.CARD_A3.getTitle() + SystemConstant.PDF_PREFIX);
|
|
|
|
+ if (Objects.nonNull(cardFile)) {
|
|
|
|
+ sourceFileList.add(cardFile);
|
|
}
|
|
}
|
|
- sourceFiles.add(htmlFile);
|
|
|
|
}
|
|
}
|
|
-// FileUtil.doZip(zipFile, sourceFiles);
|
|
|
|
|
|
|
|
- Zip4jUtil.zipEncryptFile(zipFile.getPath(), sourceFiles, SystemConstant.ZIP_ENCRYPT_PWD);
|
|
|
|
|
|
+ //卷袋贴/签到表/登记表文件
|
|
|
|
+ if (Objects.nonNull(e.getCardAttachmentId())) {
|
|
|
|
+ JSONObject js = JSONObject.parseObject(e.getAttachmentPath());
|
|
|
|
+ JSONArray jsonArrayTemp = js.getJSONArray(SystemConstant.PATH);
|
|
|
|
+ for (int i = 0; i < jsonArrayTemp.size(); i++) {
|
|
|
|
+ JSONObject object = jsonArrayTemp.getJSONObject(i);
|
|
|
|
+ PdfTypeEnum pdfTypeEnum = PdfTypeEnum.valueOf((String) object.get("printType"));
|
|
|
|
+ switch (pdfTypeEnum) {
|
|
|
|
+ case PACKAGE:
|
|
|
|
+ case SIGN:
|
|
|
|
+ case CHECK_IN:
|
|
|
|
+ File file = getJsonFile(object, dirPath.toString() + pdfTypeEnum.getTitle() + SystemConstant.PDF_PREFIX);
|
|
|
|
+ if (Objects.nonNull(file)) {
|
|
|
|
+ sourceFileList.add(file);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtils.isEmpty(sourceFileList)) {
|
|
|
|
+ Zip4jUtil.zipEncryptFile(zipFile.getPath(), zipLocalRootPath, SystemConstant.ZIP_ENCRYPT_PWD);
|
|
String ossDirName = dirName.toString().replaceAll("\\\\", "/");
|
|
String ossDirName = dirName.toString().replaceAll("\\\\", "/");
|
|
JSONObject jsonObject = new JSONObject();
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
+ boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
if (oss) {//上传至oss
|
|
if (oss) {//上传至oss
|
|
fileStoreUtil.ossUpload(ossDirName, zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))), fileStoreUtil.getUploadEnumByPath(ossDirName).getFssType());
|
|
fileStoreUtil.ossUpload(ossDirName, zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))), fileStoreUtil.getUploadEnumByPath(ossDirName).getFssType());
|
|
jsonObject.put(SystemConstant.PATH, ossDirName);
|
|
jsonObject.put(SystemConstant.PATH, ossDirName);
|
|
@@ -981,15 +1006,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
}
|
|
}
|
|
jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
tbTask.setResultFilePath(jsonObject.toJSONString());
|
|
tbTask.setResultFilePath(jsonObject.toJSONString());
|
|
- if (Objects.nonNull(dictionaryConfig.sysDomain()) && dictionaryConfig.sysDomain().isOss()) {
|
|
|
|
- for (File file : sourceFiles) {
|
|
|
|
- file.delete();
|
|
|
|
- }
|
|
|
|
- zipFile.delete();
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
- map.computeIfAbsent(SystemConstant.SIZE, v -> attachmentIds.size());
|
|
|
|
}
|
|
}
|
|
|
|
+ map.put(SystemConstant.SIZE, Objects.nonNull(sourceFileList) ? sourceFileList.size() : 0);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error(SystemConstant.LOG_ERROR, e);
|
|
log.error(SystemConstant.LOG_ERROR, e);
|
|
if (e instanceof ApiException) {
|
|
if (e instanceof ApiException) {
|
|
@@ -997,10 +1016,77 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
} else {
|
|
} else {
|
|
ResultUtil.error(e.getMessage());
|
|
ResultUtil.error(e.getMessage());
|
|
}
|
|
}
|
|
|
|
+ } finally {
|
|
|
|
+ if (!CollectionUtils.isEmpty(sourceFileList)) {
|
|
|
|
+ for (File file : sourceFileList) {
|
|
|
|
+ file.delete();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (Objects.nonNull(dictionaryConfig.sysDomain()) && dictionaryConfig.sysDomain().isOss() && Objects.nonNull(zipFile)) {
|
|
|
|
+ zipFile.delete();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取附件文件
|
|
|
|
+ *
|
|
|
|
+ * @param jsonObject
|
|
|
|
+ * @param pathName
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ private File getJsonFile(JSONObject jsonObject, String pathName) throws Exception {
|
|
|
|
+ File file = null;
|
|
|
|
+ String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
|
|
|
|
+ StringJoiner stringJoinerPdf = new StringJoiner("")
|
|
|
|
+ .add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator)
|
|
|
|
+ .add(pathName);
|
|
|
|
+ if (Objects.nonNull(attachmentType) && !Objects.equals(attachmentType, SystemConstant.LOCAL)) {
|
|
|
|
+ file = fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PDF_PATH), stringJoinerPdf.toString(), UploadFileEnum.PDF.getFssType());
|
|
|
|
+ } else {
|
|
|
|
+ file = new File(stringJoinerPdf.toString());
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
+ file.getParentFile().mkdirs(); //目标文件目录不存在的话需要创建目录
|
|
|
|
+ file.createNewFile();
|
|
|
|
+ }
|
|
|
|
+ IOUtils.copy(new FileInputStream((String) jsonObject.get(SystemConstant.PDF_PATH)), new FileOutputStream(file));
|
|
|
|
+ }
|
|
|
|
+ return file;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取附件文件
|
|
|
|
+ *
|
|
|
|
+ * @param pathName
|
|
|
|
+ * @param pathName
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ private File getAttachmentFile(BasicAttachment attachment, String pathName) throws Exception {
|
|
|
|
+ File file = null;
|
|
|
|
+ if (Objects.nonNull(attachment) && Objects.nonNull(attachment.getPath())) {
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(attachment.getPath());
|
|
|
|
+ String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
|
|
|
|
+ UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
|
|
|
|
+ StringJoiner stringJoinerPdf = new StringJoiner("")
|
|
|
|
+ .add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator)
|
|
|
|
+ .add(pathName);
|
|
|
|
+ if (Objects.nonNull(attachmentType) && !Objects.equals(attachmentType, SystemConstant.LOCAL)) {
|
|
|
|
+ file = fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), stringJoinerPdf.toString(), uploadFileEnum.getFssType());
|
|
|
|
+ } else {
|
|
|
|
+ file = new File(stringJoinerPdf.toString());
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
+ file.getParentFile().mkdirs(); //目标文件目录不存在的话需要创建目录
|
|
|
|
+ file.createNewFile();
|
|
|
|
+ }
|
|
|
|
+ IOUtils.copy(new FileInputStream((String) jsonObject.get(SystemConstant.PATH)), new FileOutputStream(file));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return file;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
public Map<String, Object> executeExportSampleLogic(Map<String, Object> map) throws Exception {
|
|
public Map<String, Object> executeExportSampleLogic(Map<String, Object> map) throws Exception {
|