|
@@ -31,6 +31,7 @@ import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
import com.qmth.teachcloud.common.enums.CardCreateMethodEnum;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.teachcloud.common.enums.PageSizeEnum;
|
|
|
+import com.qmth.teachcloud.common.enums.SyncFileTypeEnum;
|
|
|
import com.qmth.teachcloud.common.service.BasicAttachmentService;
|
|
|
import com.qmth.teachcloud.common.service.BasicCourseService;
|
|
|
import com.qmth.teachcloud.common.service.BasicRoleDataPermissionService;
|
|
@@ -41,6 +42,7 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.FileCopyUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -64,6 +66,9 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
|
@Resource
|
|
|
private BasicExamRuleService basicExamRuleService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private BasicCardRuleService basicCardRuleService;
|
|
|
+
|
|
|
@Resource
|
|
|
private ExamCardDetailService examCardDetailService;
|
|
|
|
|
@@ -577,35 +582,44 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
|
|
|
|
@Override
|
|
|
public void cardDownload(HttpServletResponse response, String id) {
|
|
|
- File tempFile = null;
|
|
|
String rootPath = null;
|
|
|
try {
|
|
|
-
|
|
|
- // 题卡
|
|
|
- ExamCard examCard = this.getById(id);
|
|
|
// 本地保存目录
|
|
|
- tempFile = SystemConstant.getFileTempDirVar(String.valueOf(System.currentTimeMillis()) + File.separator + SystemConstant.getNanoId(), SystemConstant.TEMP_PREFIX);
|
|
|
+ File tempFile = SystemConstant.getFileTempDirVar(System.currentTimeMillis() + File.separator + SystemConstant.getNanoId(), SystemConstant.TEMP_PREFIX);
|
|
|
rootPath = tempFile.getParent();
|
|
|
- StringJoiner dirPath = new StringJoiner("");
|
|
|
- dirPath = dirPath.add(rootPath).add(File.separator)
|
|
|
- .add(id).add(File.separator).add(SystemConstant.HYPHEN)
|
|
|
- .add(examCard.getTitle()).add(File.separator);
|
|
|
- List<File> fileList = new ArrayList<>();
|
|
|
|
|
|
- String cardHtmlPath = dirPath + examCard.getTitle() + SystemConstant.HTML_PREFIX;
|
|
|
- String cardPdfPath = dirPath + examCard.getTitle() + SystemConstant.PDF_PREFIX;
|
|
|
+ // 删除临时目录中创建的临时文件
|
|
|
+ if (Objects.nonNull(tempFile)) {
|
|
|
+ tempFile.delete();
|
|
|
+ }
|
|
|
|
|
|
+ // 题卡详细信息
|
|
|
+ ExamCard examCard = this.getById(id);
|
|
|
ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCard.getId());
|
|
|
+
|
|
|
+ StringJoiner dirPath = new StringJoiner("");
|
|
|
+ dirPath = dirPath.add(rootPath).add(File.separator).add(examCard.getTitle()).add(File.separator);
|
|
|
+
|
|
|
String htmlContent;
|
|
|
// 通用模板
|
|
|
- if (MakeMethodEnum.SELECT.equals(examCard.getMakeMethod())) {
|
|
|
- htmlContent = createPdfUtil.resetHtmlTemplateBar(examCardDetail.getHtmlContent());
|
|
|
+ if (CardTypeEnum.GENERIC.equals(examCard.getType())) {
|
|
|
+ if (CardCreateMethodEnum.UPLOAD.equals(examCard.getCreateMethod())) {
|
|
|
+ htmlContent = createPdfUtil.resetHtmlTemplateBar(examCardDetail.getHtmlContent());
|
|
|
+ } else {
|
|
|
+ BasicCardRule basicCardRule = basicCardRuleService.getById(examCard.getCardRuleId());
|
|
|
+ htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
|
|
|
+ }
|
|
|
} else {
|
|
|
-// BasicCardRule basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
|
|
|
- htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, null);
|
|
|
+ List<ExamTask> examTasks = examCardDetailService.getExamTaskByCourseCodeAndCardId(examCard.getSchoolId(), examCard.getCourseCode(), id);
|
|
|
+ BasicCardRule basicCardRule = null;
|
|
|
+ if (!CollectionUtils.isEmpty(examTasks)) {
|
|
|
+ basicCardRule = basicCardRuleService.getById(examTasks.get(0).getCardRuleId());
|
|
|
+ }
|
|
|
+ htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
|
|
|
}
|
|
|
|
|
|
- // html
|
|
|
+ // html文件
|
|
|
+ String cardHtmlPath = dirPath + examCard.getTitle() + SystemConstant.HTML_PREFIX;
|
|
|
File htmlFile = new File(cardHtmlPath);
|
|
|
if (!htmlFile.exists()) {
|
|
|
htmlFile.getParentFile().mkdirs();
|
|
@@ -613,29 +627,45 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
|
}
|
|
|
// 生成html文件
|
|
|
FileCopyUtils.copy(htmlContent.getBytes(StandardCharsets.UTF_8), htmlFile);
|
|
|
- fileList.add(htmlFile);
|
|
|
- // 转pdf文件
|
|
|
+
|
|
|
+ // pdf文件
|
|
|
+ String cardPdfPath = dirPath + examCard.getTitle() + SystemConstant.PDF_PREFIX;
|
|
|
File pdfFile = new File(cardPdfPath);
|
|
|
if (!pdfFile.exists()) {
|
|
|
pdfFile.getParentFile().mkdirs();
|
|
|
pdfFile.createNewFile();
|
|
|
}
|
|
|
HtmlToPdfUtil.convert(cardHtmlPath, cardPdfPath, PageSizeEnum.A3);
|
|
|
- fileList.add(pdfFile);
|
|
|
|
|
|
- if (fileList.size() == 0) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("没有可导出文件");
|
|
|
+ // jpg文件
|
|
|
+ String jpgAttachmentIds = examCardDetail.getJpgAttachmentInfo();
|
|
|
+ if (StringUtils.isNotBlank(jpgAttachmentIds)) {
|
|
|
+ List<JSONObject> jsonObjectList = JSONObject.parseArray(jpgAttachmentIds, JSONObject.class);
|
|
|
+ for (JSONObject jsonObject : jsonObjectList) {
|
|
|
+ String jpgAttachmentId = jsonObject.get("attachmentId").toString();
|
|
|
+ String index = jsonObject.get("index").toString();
|
|
|
+ if (StringUtils.isNotBlank(jpgAttachmentId)) {
|
|
|
+ BasicAttachment attachment = basicAttachmentService.getById(jpgAttachmentId);
|
|
|
+ if (attachment != null) {
|
|
|
+ String fileName = examCard.getTitle() + SystemConstant.HYPHEN + index + attachment.getType();
|
|
|
+ teachcloudCommonService.copyFile(dirPath.toString(), fileName, attachment);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- if (Objects.nonNull(tempFile)) {
|
|
|
- tempFile.delete();
|
|
|
+
|
|
|
+ // json文件
|
|
|
+ String content = examCardDetail.getContent();
|
|
|
+ if (StringUtils.isNotBlank(content)) {
|
|
|
+ String jsonPath = dirPath + examCard.getTitle() + SystemConstant.JSON_PREFIX;
|
|
|
+ SystemConstant.createJsonFile(jsonPath, content);
|
|
|
}
|
|
|
- teachcloudCommonService.downloadFileAndZip(response, rootPath, rootPath);
|
|
|
+
|
|
|
+ String zipFileName = id + SystemConstant.ZIP_PREFIX;
|
|
|
+ teachcloudCommonService.downloadFileAndZip(response, rootPath, rootPath, zipFileName);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
- if (Objects.nonNull(tempFile)) {
|
|
|
- tempFile.delete();
|
|
|
- }
|
|
|
if (Objects.nonNull(rootPath)) {
|
|
|
ConvertUtil.delFolder(rootPath);
|
|
|
}
|