|
@@ -11,6 +11,7 @@ import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.core.print.common.Constants;
|
|
|
import cn.com.qmth.examcloud.core.print.common.jpa.SearchBuilder;
|
|
|
import cn.com.qmth.examcloud.core.print.common.jpa.SpecUtils;
|
|
|
+import cn.com.qmth.examcloud.core.print.common.upyun.UpYunClient;
|
|
|
import cn.com.qmth.examcloud.core.print.common.utils.Check;
|
|
|
import cn.com.qmth.examcloud.core.print.common.utils.ExcelUtils;
|
|
|
import cn.com.qmth.examcloud.core.print.common.utils.FileUtils;
|
|
@@ -24,6 +25,7 @@ import cn.com.qmth.examcloud.core.print.repository.CourseStatisticRepository;
|
|
|
import cn.com.qmth.examcloud.core.print.service.CoursePaperService;
|
|
|
import cn.com.qmth.examcloud.core.print.service.QuestionStructureService;
|
|
|
import cn.com.qmth.examcloud.core.print.service.bean.coursepaper.*;
|
|
|
+import com.itextpdf.text.pdf.PdfReader;
|
|
|
import javafx.util.Pair;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
@@ -35,6 +37,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -48,6 +51,8 @@ import static cn.com.qmth.examcloud.core.print.common.Constants.*;
|
|
|
public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
private static final Logger log = LoggerFactory.getLogger(CoursePaperServiceImpl.class);
|
|
|
@Autowired
|
|
|
+ private UpYunClient upYunClient;
|
|
|
+ @Autowired
|
|
|
private CoursePaperRepository coursePaperRepository;
|
|
|
@Autowired
|
|
|
private CourseStatisticRepository courseStatisticRepository;
|
|
@@ -96,28 +101,48 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
// Check.isBlank(coursePaper.getAnswerHtmlUrl(), "答案页面地址不能为空!");
|
|
|
// Check.isNull(coursePaper.getPaperP(), "试卷页数不能为空!");
|
|
|
|
|
|
- //试卷预览和答案预览地址
|
|
|
+ //试卷地址和答案地址
|
|
|
String paperHtmlUrl = QUESTION_URL_PREFIX.concat("/api/ecs_ques/paper/pdf/").concat(coursePaper.getPaperId());
|
|
|
String answerHtmlUrl = QUESTION_URL_PREFIX.concat("/api/ecs_ques/paper/answer/pdf/").concat(coursePaper.getPaperId());
|
|
|
|
|
|
+ //转换PDF文件
|
|
|
+ String rootDir = Constants.rootFileDir();
|
|
|
+ FileUtils.makeDirs(rootDir);
|
|
|
+ String paperPdfPath = rootDir + "/" + FileUtils.randomUUID() + SUFFIX_PDF;
|
|
|
+ String answerPdfPath = rootDir + "/" + FileUtils.randomUUID() + SUFFIX_PDF;
|
|
|
+ String paperPdfUrl = upYunClient.upload(new File(paperPdfPath));
|
|
|
+ String answerPdfUrl = upYunClient.upload(new File(answerPdfPath));
|
|
|
+
|
|
|
+ //获取PDF页数
|
|
|
+ int paperP = 0;
|
|
|
+ try (FileInputStream fis = new FileInputStream(paperPdfPath);) {
|
|
|
+ PdfReader pdfReader = new PdfReader(fis);
|
|
|
+ paperP = pdfReader.getNumberOfPages();
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
CoursePaper oldCoursePaper = coursePaperRepository.findByExamIdAndPaperId(coursePaper.getExamId(), coursePaper.getPaperId());
|
|
|
if (oldCoursePaper != null) {
|
|
|
//存在则修改
|
|
|
oldCoursePaper.setPaperName(coursePaper.getPaperName());
|
|
|
oldCoursePaper.setPaperHtmlUrl(paperHtmlUrl);
|
|
|
oldCoursePaper.setAnswerHtmlUrl(answerHtmlUrl);
|
|
|
- oldCoursePaper.setPaperPdfUrl(coursePaper.getPaperPdfUrl());//todo
|
|
|
- oldCoursePaper.setAnswerPdfUrl(coursePaper.getAnswerPdfUrl());//todo
|
|
|
- oldCoursePaper.setPaperP(coursePaper.getPaperP());//todo
|
|
|
+ oldCoursePaper.setPaperPdfUrl(paperPdfUrl);
|
|
|
+ oldCoursePaper.setAnswerPdfUrl(answerPdfUrl);
|
|
|
+ oldCoursePaper.setPaperP(paperP);
|
|
|
coursePaperRepository.save(oldCoursePaper);
|
|
|
-
|
|
|
- //更新试卷试题结构
|
|
|
- questionStructureService.savePaperQuestionStructure(coursePaper.getExamId(), coursePaper.getPaperId());
|
|
|
- return;
|
|
|
+ } else {
|
|
|
+ //否则新增
|
|
|
+ coursePaper.setPaperHtmlUrl(paperHtmlUrl);
|
|
|
+ coursePaper.setAnswerHtmlUrl(answerHtmlUrl);
|
|
|
+ coursePaper.setPaperPdfUrl(paperPdfUrl);
|
|
|
+ coursePaper.setAnswerPdfUrl(answerPdfUrl);
|
|
|
+ coursePaper.setPaperP(paperP);
|
|
|
+ coursePaperRepository.save(coursePaper);
|
|
|
}
|
|
|
- //否则新增
|
|
|
- coursePaperRepository.save(coursePaper);
|
|
|
- //保存试卷试题结构
|
|
|
+
|
|
|
+ //保存或更新试卷试题结构
|
|
|
questionStructureService.savePaperQuestionStructure(coursePaper.getExamId(), coursePaper.getPaperId());
|
|
|
|
|
|
//如果当前考试课程"只有一种试卷类型"且"未分配试卷",则默认分配该试卷
|
|
@@ -130,6 +155,7 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
if (statistics == null || statistics.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
for (CourseStatistic statistic : statistics) {
|
|
|
if (PaperStatus.已有.getIndex() == statistic.getPaperStatus()) {
|
|
|
//跳过已分配的
|