|
@@ -7,6 +7,7 @@
|
|
|
|
|
|
package cn.com.qmth.examcloud.core.print.service.impl;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
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.utils.Check;
|
|
@@ -31,6 +32,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.io.File;
|
|
|
import java.util.*;
|
|
|
|
|
|
+import static cn.com.qmth.examcloud.core.print.common.Constants.PRT_CODE_500;
|
|
|
+
|
|
|
/**
|
|
|
* @author: fengdesheng
|
|
|
* @since: 2018/10/17
|
|
@@ -46,9 +49,9 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
@Override
|
|
|
public List<CoursePaperInfo> getCoursePaperList(CoursePaperQuery query) {
|
|
|
Check.isNull(query, "查询参数不能为空!");
|
|
|
- Check.isEmpty(query.getOrgId(), "学校ID不能为空!");
|
|
|
- Check.isEmpty(query.getExamId(), "考试ID不能为空!");
|
|
|
- Check.isEmpty(query.getCourseId(), "课程ID不能为空!");
|
|
|
+ Check.isNull(query.getOrgId(), "学校ID不能为空!");
|
|
|
+ Check.isNull(query.getExamId(), "考试ID不能为空!");
|
|
|
+ Check.isNull(query.getCourseId(), "课程ID不能为空!");
|
|
|
|
|
|
//查询条件
|
|
|
SearchBuilder searches = new SearchBuilder();
|
|
@@ -71,9 +74,31 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void syncCoursePaper(CoursePaper coursePaper) {
|
|
|
- //todo
|
|
|
- System.out.println(coursePaper.getOrgId());
|
|
|
+ public void syncCoursePaper(CoursePaper info) {
|
|
|
+ Check.isNull(info.getOrgId(), "学校ID不能为空!");
|
|
|
+ Check.isNull(info.getExamId(), "考试ID不能为空!");
|
|
|
+ Check.isNull(info.getCourseId(), "课程ID不能为空!");
|
|
|
+ Check.isEmpty(info.getCourseCode(), "课程代码不能为空!");
|
|
|
+ Check.isEmpty(info.getCourseName(), "课程名称不能为空!");
|
|
|
+ Check.isNull(info.getPaperId(), "试卷ID不能为空!");
|
|
|
+ Check.isEmpty(info.getPaperName(), "试卷名称不能为空!");
|
|
|
+ Check.isNull(info.getPaperP(), "试卷页数不能为空!");
|
|
|
+ Check.isBlank(info.getPaperFileUrl(), "试卷文件地址不能为空!");
|
|
|
+ Check.isBlank(info.getAnswerFileUrl(), "答案文件地址不能为空!");
|
|
|
+
|
|
|
+ CoursePaper coursePaper = coursePaperRepository.findByExamIdAndPaperId(info.getExamId(), info.getPaperId());
|
|
|
+ if (coursePaper != null) {
|
|
|
+ //存在则修改
|
|
|
+ coursePaper.setPaperName(info.getPaperName());
|
|
|
+ coursePaper.setPaperP(info.getPaperP());
|
|
|
+ coursePaper.setPaperFileUrl(info.getPaperFileUrl());
|
|
|
+ coursePaper.setAnswerFileUrl(info.getAnswerFileUrl());
|
|
|
+ coursePaperRepository.save(coursePaper);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //否则新增
|
|
|
+ coursePaperRepository.save(info);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -91,14 +116,13 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
public void allotCoursePaper(Long courseStatisticId, Long coursePaperId) {
|
|
|
Check.isEmpty(courseStatisticId, "课程统计ID不能为空!");
|
|
|
Check.isEmpty(coursePaperId, "课程试卷ID不能为空!");
|
|
|
+
|
|
|
CourseStatistic statistic = courseStatisticRepository.findOne(courseStatisticId);
|
|
|
- if (statistic == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ Check.isNull(statistic, "当前课程统计不存在!");
|
|
|
+
|
|
|
CoursePaper coursePaper = coursePaperRepository.findOne(coursePaperId);
|
|
|
- if (coursePaper == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ Check.isNull(coursePaper, "当前课程试卷不存在!");
|
|
|
+
|
|
|
statistic.setCoursePaper(coursePaper);
|
|
|
statistic.setPaperStatus(PaperStatus.已有.getIndex());
|
|
|
courseStatisticRepository.save(statistic);
|
|
@@ -127,7 +151,7 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
}
|
|
|
|
|
|
//反馈信息
|
|
|
- StringBuffer msg = new StringBuffer();
|
|
|
+ StringBuffer errors = new StringBuffer();
|
|
|
|
|
|
//获取考试课程下的试卷列表
|
|
|
List<CoursePaper> coursePapers = this.getCoursePapers(orgId, examId);
|
|
@@ -148,7 +172,7 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
for (CourseStatistic statistic : statistics) {
|
|
|
List<CoursePaper> papers = maps.get(statistic.getCourseId());
|
|
|
if (papers == null || papers.isEmpty()) {
|
|
|
- msg.append("课程《").append(statistic.getCourseName()).append("(").append(statistic.getCourseCode()).append(")》试卷数不足!").append("\n");
|
|
|
+ errors.append(String.format("《%s(%s)》", statistic.getCourseName(), statistic.getCourseCode()));
|
|
|
continue;
|
|
|
}
|
|
|
Collections.shuffle(papers);
|
|
@@ -161,7 +185,12 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
if (!needUpdateStatistics.isEmpty()) {
|
|
|
courseStatisticRepository.save(needUpdateStatistics);
|
|
|
}
|
|
|
- log.debug(msg.toString());
|
|
|
+
|
|
|
+ //试卷不足时,反馈给前端
|
|
|
+ if (errors.length() > 0) {
|
|
|
+ errors.append("等课程的试卷数不足!");
|
|
|
+ throw new StatusException(PRT_CODE_500, errors.toString());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private List<CoursePaper> getCoursePapers(Long orgId, Long examId) {
|