|
@@ -13,13 +13,14 @@ import cn.com.qmth.examcloud.core.print.common.jpa.OrderBuilder;
|
|
|
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;
|
|
|
+import cn.com.qmth.examcloud.core.print.entity.ExamQuestionStructure;
|
|
|
import cn.com.qmth.examcloud.core.print.entity.ExamStructure;
|
|
|
+import cn.com.qmth.examcloud.core.print.enums.ExamType;
|
|
|
import cn.com.qmth.examcloud.core.print.repository.ExamStructureRepository;
|
|
|
import cn.com.qmth.examcloud.core.print.service.ExamStructureService;
|
|
|
import cn.com.qmth.examcloud.core.print.service.bean.examstructure.ExamStructureConvert;
|
|
|
import cn.com.qmth.examcloud.core.print.service.bean.examstructure.ExamStructureInfo;
|
|
|
import cn.com.qmth.examcloud.core.print.service.bean.examstructure.ExamStructureQuery;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
@@ -27,8 +28,6 @@ import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
/**
|
|
|
* @author: fengdesheng
|
|
|
* @since: 2018/10/17
|
|
@@ -39,14 +38,13 @@ import java.util.List;
|
|
|
public class ExamStructureServiceImpl implements ExamStructureService {
|
|
|
@Autowired
|
|
|
private ExamStructureRepository examStructureRepository;
|
|
|
-
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
@Override
|
|
|
public Page<ExamStructureInfo> getExamStructureList(ExamStructureQuery query) {
|
|
|
Check.isNull(query, "查询参数不能为空!");
|
|
|
- Check.isEmpty(query.getOrgId(), "机构id不能为空");
|
|
|
+ Check.isEmpty(query.getOrgId(), "学校ID不能为空!");
|
|
|
//查询条件
|
|
|
SearchBuilder searches = new SearchBuilder();
|
|
|
searches.eq("orgId", query.getOrgId());
|
|
@@ -64,24 +62,32 @@ public class ExamStructureServiceImpl implements ExamStructureService {
|
|
|
|
|
|
@Override
|
|
|
public void saveExamStructure(ExamStructureInfo info) {
|
|
|
- Check.isNull(info.getExamId(), "考试id不能为空");
|
|
|
- Check.isNull(info.getOrgId(), "机构id不能为空");
|
|
|
- Check.isBlank(info.getExamName(), "考试名称不能为空");
|
|
|
- Check.isBlank(info.getOrgName(), "机构名称不能为空");
|
|
|
- Check.isBlank(info.getExamType(), "考试类型不能为空");
|
|
|
- Check.isNull(info.getQuestionStructure(), "结构详情设置不能空");
|
|
|
- Check.isNull(info.getQuestionStructure().getSingleChoiceTotal(), "结构详情中,单选题数量不能为空");
|
|
|
- Check.isNull(info.getQuestionStructure().getMultipleChoiceTotal(), "结构详情中,多选题数量不能为空");
|
|
|
- Check.isNull(info.getQuestionStructure().getBoolQuestionTotal(), "结构详情中,判断题数量不能为空");
|
|
|
+ Check.isNull(info.getOrgId(), "学校ID不能为空!");
|
|
|
+ Check.isBlank(info.getOrgName(), "学校名称不能为空!");
|
|
|
+ Check.isNull(info.getExamId(), "考试ID不能为空!");
|
|
|
+ Check.isBlank(info.getExamName(), "考试名称不能为空!");
|
|
|
+
|
|
|
+ ExamQuestionStructure questionStructure = info.getQuestionStructure();
|
|
|
+ Check.isNull(questionStructure, "题数设置信息不能空!");
|
|
|
+ Check.isNull(questionStructure.getSingleChoiceTotal(), "单选题数量不能为空!");
|
|
|
+ Check.isNull(questionStructure.getMultipleChoiceTotal(), "多选题数量不能为空!");
|
|
|
+ Check.isNull(questionStructure.getBoolQuestionTotal(), "判断题数量不能为空!");
|
|
|
+
|
|
|
ExamStructure entity = ExamStructureConvert.of(info);
|
|
|
+ entity.setExamType(ExamType.TRADITION.name());
|
|
|
examStructureRepository.save(entity);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void deleteExamStructure(List<Long> ids) {
|
|
|
- if (ids != null && ids.size() > 0) {
|
|
|
- for (Long id : ids) {
|
|
|
+ public void deleteExamStructure(Long[] ids) {
|
|
|
+ if (ids == null || ids.length == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (Long id : ids) {
|
|
|
+ try {
|
|
|
examStructureRepository.delete(id);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // ignore record not exist
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -89,27 +95,32 @@ public class ExamStructureServiceImpl implements ExamStructureService {
|
|
|
@Override
|
|
|
public void copyExamStructure(ExamStructureInfo info) {
|
|
|
//数据校验
|
|
|
- Check.isNull(info.getOrgId(), "被复用的机构id不能为空");
|
|
|
- Check.isNull(info.getExamId(), "被复用的考试id不能为空");
|
|
|
- Check.isNull(info.getNewOrgId(), "复用后的机构id不能为空");
|
|
|
- Check.isNull(info.getExamId(), "复用后的考试id不能为空");
|
|
|
- //首先查询要复用 导出结构设置信息
|
|
|
- ExamStructure examStructure = examStructureRepository.findByExamIdAndOrgId(info.getExamId(), info.getOrgId());
|
|
|
- if (examStructure == null) {
|
|
|
- throw new StatusException(Constants.PRT_CODE_500, "复用导出结构不存在");
|
|
|
+ Check.isNull(info.getOrgId(), "原学校ID不能为空!");
|
|
|
+ Check.isNull(info.getExamId(), "原考试ID不能为空!");
|
|
|
+ Check.isNull(info.getNewOrgId(), "新学校ID不能为空!");
|
|
|
+ Check.isBlank(info.getNewOrgName(), "新学校名称不能为空!");
|
|
|
+ Check.isNull(info.getExamId(), "新考试ID不能为空!");
|
|
|
+ Check.isBlank(info.getNewExamName(), "新考试名称不能为空!");
|
|
|
+
|
|
|
+ ExamStructure newStructure = examStructureRepository.findByExamIdAndOrgId(info.getNewExamId(), info.getNewOrgId());
|
|
|
+ if (newStructure != null) {
|
|
|
+ throw new StatusException(Constants.PRT_CODE_500, "新学校考试下已有结构信息,不可复用!");
|
|
|
}
|
|
|
- ExamStructure newExamStructure = examStructureRepository.findByExamIdAndOrgId(info.getNewExamId(), info.getNewOrgId());
|
|
|
- if (newExamStructure != null) {
|
|
|
- throw new StatusException(Constants.PRT_CODE_500, "该场考试的导出结构已经存在,不能复用");
|
|
|
+
|
|
|
+ ExamStructure oldStructure = examStructureRepository.findByExamIdAndOrgId(info.getExamId(), info.getOrgId());
|
|
|
+ if (oldStructure == null) {
|
|
|
+ throw new StatusException(Constants.PRT_CODE_500, "原结构信息不存在!");
|
|
|
}
|
|
|
- newExamStructure = new ExamStructure();
|
|
|
- BeanUtils.copyProperties(examStructure, newExamStructure);
|
|
|
- newExamStructure.setId(null);
|
|
|
- newExamStructure.setExamId(info.getNewExamId());
|
|
|
- newExamStructure.setExamName(info.getNewExamName());
|
|
|
- newExamStructure.setOrgId(info.getNewOrgId());
|
|
|
- newExamStructure.setOrgName(info.getNewOrgName());
|
|
|
- examStructureRepository.save(newExamStructure);
|
|
|
+
|
|
|
+ newStructure = new ExamStructure();
|
|
|
+ newStructure.setId(null);
|
|
|
+ newStructure.setOrgId(info.getNewOrgId());
|
|
|
+ newStructure.setOrgName(info.getNewOrgName());
|
|
|
+ newStructure.setExamId(info.getNewExamId());
|
|
|
+ newStructure.setExamName(info.getNewExamName());
|
|
|
+ newStructure.setExamType(oldStructure.getExamType());
|
|
|
+ newStructure.setStruct(oldStructure.getStruct());
|
|
|
+ examStructureRepository.save(newStructure);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -121,14 +132,13 @@ public class ExamStructureServiceImpl implements ExamStructureService {
|
|
|
@Override
|
|
|
public ExamStructureInfo getExamStructure(ExamStructureQuery query) {
|
|
|
Check.isNull(query, "查询参数不能为空!");
|
|
|
- Check.isEmpty(query.getOrgId(), "机构id不能为空");
|
|
|
- Check.isEmpty(query.getExamId(), "考试id不能为空");
|
|
|
+ Check.isEmpty(query.getOrgId(), "学校ID不能为空!");
|
|
|
+ Check.isEmpty(query.getExamId(), "考试ID不能为空!");
|
|
|
ExamStructure entity = examStructureRepository.findByExamIdAndOrgId(query.getExamId(), query.getOrgId());
|
|
|
if (entity == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- ExamStructureInfo info = ExamStructureConvert.of(entity);
|
|
|
- return info;
|
|
|
+ return ExamStructureConvert.of(entity);
|
|
|
}
|
|
|
|
|
|
}
|