|
@@ -13,6 +13,7 @@ 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.ElectronUtils;
|
|
|
import cn.com.qmth.examcloud.core.print.common.utils.ExcelUtils;
|
|
|
import cn.com.qmth.examcloud.core.print.common.utils.FileUtils;
|
|
|
import cn.com.qmth.examcloud.core.print.entity.CoursePaper;
|
|
@@ -97,23 +98,24 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
Check.isEmpty(coursePaper.getCourseName(), "课程名称不能为空!");
|
|
|
Check.isEmpty(coursePaper.getPaperId(), "试卷ID不能为空!");
|
|
|
Check.isEmpty(coursePaper.getPaperName(), "试卷名称不能为空!");
|
|
|
-// Check.isBlank(coursePaper.getPaperHtmlUrl(), "试卷页面地址不能为空!");
|
|
|
-// 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();
|
|
|
+ final String rootDir = Constants.rootFileDir();
|
|
|
+ final String paperPdfPath = rootDir + "/" + FileUtils.randomUUID() + SUFFIX_PDF;
|
|
|
+ final String answerPdfPath = rootDir + "/" + FileUtils.randomUUID() + SUFFIX_PDF;
|
|
|
FileUtils.makeDirs(rootDir);
|
|
|
- String paperPdfPath = rootDir + "/" + FileUtils.randomUUID() + SUFFIX_PDF;
|
|
|
- String answerPdfPath = rootDir + "/" + FileUtils.randomUUID() + SUFFIX_PDF;
|
|
|
+ ElectronUtils.toPdf(paperHtmlUrl, paperPdfPath);
|
|
|
+ ElectronUtils.toPdf(answerHtmlUrl, answerPdfPath);
|
|
|
+
|
|
|
+ //上传PDF至又拍云
|
|
|
String paperPdfUrl = upYunClient.upload(new File(paperPdfPath));
|
|
|
String answerPdfUrl = upYunClient.upload(new File(answerPdfPath));
|
|
|
|
|
|
- //获取PDF页数
|
|
|
+ //获取试卷PDF的页数
|
|
|
int paperP = 0;
|
|
|
try (FileInputStream fis = new FileInputStream(paperPdfPath);) {
|
|
|
PdfReader pdfReader = new PdfReader(fis);
|
|
@@ -121,6 +123,9 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
} catch (IOException e) {
|
|
|
log.error(e.getMessage());
|
|
|
}
|
|
|
+ if (paperP == 0) {
|
|
|
+ throw new StatusException(PRT_CODE_400, "试卷页数不能为空!");
|
|
|
+ }
|
|
|
|
|
|
CoursePaper oldCoursePaper = coursePaperRepository.findByExamIdAndPaperId(coursePaper.getExamId(), coursePaper.getPaperId());
|
|
|
if (oldCoursePaper != null) {
|