|
@@ -3,6 +3,7 @@ package com.qmth.distributed.print.business.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.qmth.boot.core.concurrent.service.ConcurrentService;
|
|
@@ -20,13 +21,15 @@ import com.qmth.distributed.print.business.util.PdfUtil;
|
|
|
import com.qmth.teachcloud.common.bean.dto.DataPermissionRule;
|
|
|
import com.qmth.teachcloud.common.bean.marking.ConvertJpgStorage;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
+import com.qmth.teachcloud.common.entity.BasicAttachment;
|
|
|
import com.qmth.teachcloud.common.entity.BasicCourse;
|
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
-import com.qmth.teachcloud.common.service.BasicCourseService;
|
|
|
-import com.qmth.teachcloud.common.service.BasicRoleDataPermissionService;
|
|
|
-import com.qmth.teachcloud.common.service.TeachcloudCommonService;
|
|
|
+import com.qmth.teachcloud.common.enums.PageSizeEnum;
|
|
|
+import com.qmth.teachcloud.common.service.*;
|
|
|
+import com.qmth.teachcloud.common.util.Base64Util;
|
|
|
import com.qmth.teachcloud.common.util.FileUtil;
|
|
|
+import com.qmth.teachcloud.common.util.HtmlToPdfUtil;
|
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
import com.qmth.teachcloud.mark.enums.LockType;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
@@ -72,6 +75,15 @@ public class ExamCardModelFourServiceImpl extends ServiceImpl<ExamCardModelFourM
|
|
|
@Resource
|
|
|
TeachcloudCommonService teachcloudCommonService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ BasicAttachmentService basicAttachmentService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ FileUploadService fileUploadService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ SysUserService sysUserService;
|
|
|
+
|
|
|
/**
|
|
|
* 新增/修改模式4题卡
|
|
|
*
|
|
@@ -210,4 +222,138 @@ public class ExamCardModelFourServiceImpl extends ServiceImpl<ExamCardModelFourM
|
|
|
}
|
|
|
return cardPageDtoIPage;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id获取模式4题卡
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ExamCardModelFour getOne(Long id) {
|
|
|
+ ExamCardModelFour examCardModelFour = this.getById(id);
|
|
|
+ if (Objects.nonNull(examCardModelFour) && Objects.nonNull(examCardModelFour.getCourseId())) {
|
|
|
+ BasicCourse basicCourse = basicCourseService.getById(examCardModelFour.getCourseId());
|
|
|
+ examCardModelFour.setCourseCode(Objects.nonNull(basicCourse) ? basicCourse.getCode() : null);
|
|
|
+ examCardModelFour.setCourseName(Objects.nonNull(basicCourse) ? basicCourse.getName() : null);
|
|
|
+ }
|
|
|
+ return examCardModelFour;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据题卡id删除
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Boolean deleteGeneric(Long id) {
|
|
|
+ return this.removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据题卡id生成图片
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void convertImage(Long id) {
|
|
|
+ ExamCardModelFour examCardModelFour = this.getById(id);
|
|
|
+ if (!ExamCardStatusEnum.SUBMIT.equals(examCardModelFour.getStatus())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("提交状态题卡才能生成图片");
|
|
|
+ }
|
|
|
+ createJpgImage(examCardModelFour);
|
|
|
+ if (StringUtils.isNotBlank(examCardModelFour.getJpgAttachment())) {
|
|
|
+ UpdateWrapper<ExamCardModelFour> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.lambda().set(ExamCardModelFour::getJpgAttachment, examCardModelFour.getJpgAttachment())
|
|
|
+ .eq(ExamCardModelFour::getId, id);
|
|
|
+ this.update(updateWrapper);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出题卡文件
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void downloadCard(Long id) {
|
|
|
+ String rootPath = null;
|
|
|
+ try {
|
|
|
+ ExamCardModelFour examCardModelFour = this.getById(id);
|
|
|
+ // 去掉题卡名称中的空格,否则创建目录报错
|
|
|
+ String title = StringUtils.deleteWhitespace(examCardModelFour.getTitle());
|
|
|
+ // 本地保存目录
|
|
|
+ rootPath = FileUtil.getFileTempDirPath(true);
|
|
|
+ // 下载文件保存路径(以题卡名称命名)
|
|
|
+ String downloadFilePath = rootPath + File.separator + title;
|
|
|
+ File downloadPathFile = new File(downloadFilePath);
|
|
|
+ if (!downloadPathFile.exists()) {
|
|
|
+ downloadPathFile.mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ // HTML文件
|
|
|
+ String htmlContent = createPdfUtil.replaceBlankHtmlContent(examCardModelFour.getHtmlContent(), examCardModelFour.getCourseId());
|
|
|
+ File htmlFile = new File(downloadFilePath, title + SystemConstant.HTML_PREFIX);
|
|
|
+ if (!htmlFile.exists()) {
|
|
|
+ htmlFile.createNewFile();
|
|
|
+ }
|
|
|
+ FileUtil.writeContent(htmlFile, htmlContent);
|
|
|
+
|
|
|
+ // PDF文件
|
|
|
+ File pdfFile = new File(downloadFilePath, title + SystemConstant.PDF_PREFIX);
|
|
|
+ if (!pdfFile.exists()) {
|
|
|
+ pdfFile.createNewFile();
|
|
|
+ }
|
|
|
+ HtmlToPdfUtil.convert(htmlFile.getPath(), pdfFile.getPath(), "8K".equals(examCardModelFour.getPageSize()) ? PageSizeEnum.K8 : PageSizeEnum.valueOf(examCardModelFour.getPageSize()));
|
|
|
+
|
|
|
+ // JPG文件
|
|
|
+ String jpgAttachmentIds = examCardModelFour.getJpgAttachment();
|
|
|
+ if (StringUtils.isNotBlank(jpgAttachmentIds)) {
|
|
|
+ List<ConvertJpgStorage> jsonObjectList = JSONObject.parseArray(jpgAttachmentIds, ConvertJpgStorage.class);
|
|
|
+ for (ConvertJpgStorage convertJpgStorage : jsonObjectList) {
|
|
|
+ String jpgAttachmentId = convertJpgStorage.getAttachmentId();
|
|
|
+ Integer index = convertJpgStorage.getIndex();
|
|
|
+ if (jpgAttachmentId != null) {
|
|
|
+ BasicAttachment attachment = basicAttachmentService.getById(jpgAttachmentId);
|
|
|
+ if (attachment != null) {
|
|
|
+ String fileName = downloadFilePath + File.separator + title + SystemConstant.HYPHEN + index + attachment.getType();
|
|
|
+ fileUploadService.downloadFile(attachment.getPath(), fileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // json文件
|
|
|
+ String content = examCardModelFour.getContent();
|
|
|
+ if (StringUtils.isNotBlank(content)) {
|
|
|
+ String jsonPath = downloadFilePath + File.separator + title + SystemConstant.JSON_PREFIX;
|
|
|
+ FileUtil.writeContent(new File(jsonPath), content);
|
|
|
+ }
|
|
|
+
|
|
|
+ String zipFileName = title + SystemConstant.ZIP_PREFIX;
|
|
|
+ SysUser sysUser = sysUserService.getById(ServletUtil.getRequestUserId());
|
|
|
+ FileUtil.downloadEncryptZip(ServletUtil.getResponse(), downloadPathFile, zipFileName, new String(Base64Util.decode(sysUser.getPassword())));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if (Objects.nonNull(rootPath)) {
|
|
|
+ FileUtil.deleteDirectory(rootPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量导出题卡文件
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void batchDownloadCard(List<Long> ids) {
|
|
|
+ for (Long l : ids) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|