|
@@ -7,18 +7,105 @@
|
|
|
|
|
|
package cn.com.qmth.examcloud.core.print.service.impl;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+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.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.ExamStructure;
|
|
|
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.ExamStructureConvert;
|
|
|
+import cn.com.qmth.examcloud.core.print.service.bean.ExamStructureInfo;
|
|
|
+import cn.com.qmth.examcloud.core.print.service.bean.ExamStructureQuery;
|
|
|
+
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
/**
|
|
|
* @author: fengdesheng
|
|
|
* @since: 2018/10/17
|
|
|
+ * @update: weiwenhai
|
|
|
+ * @date: 2018.10.30
|
|
|
*/
|
|
|
@Service
|
|
|
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(), "学校机构不能为空");
|
|
|
+ //查询条件
|
|
|
+ SearchBuilder searches = new SearchBuilder();
|
|
|
+ searches.eq("orgId", query.getOrgId());
|
|
|
+ if(query.getExamId() != null){
|
|
|
+ searches.eq("examId", query.getExamId());
|
|
|
+ }
|
|
|
+ Specification<ExamStructure> spec = SpecUtils.buildSearchers(ExamStructure.class, searches.build());
|
|
|
+ //排序条件
|
|
|
+ OrderBuilder orders = new OrderBuilder().desc("id");
|
|
|
+ //分页条件
|
|
|
+ Pageable pageable = SpecUtils.buildPageable(query.getPageNo(), query.getPageSize(), orders.build());
|
|
|
+ Page<ExamStructure> page = examStructureRepository.findAll(spec, pageable);
|
|
|
+ return ExamStructureConvert.ofPage(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveExamStructure(ExamStructureInfo info) {
|
|
|
+ ExamStructure entity = ExamStructureConvert.of(info);
|
|
|
+ examStructureRepository.save(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteExamStructure(List<Long> ids) {
|
|
|
+ if(ids != null && ids.size()>0){
|
|
|
+ for(Long id:ids){
|
|
|
+ examStructureRepository.delete(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @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, "复用导出结构不存在");
|
|
|
+ }
|
|
|
+ ExamStructure newExamStructure = examStructureRepository.findByExamIdAndOrgId(info.getNewExamId(), info.getNewOrgId());
|
|
|
+ if(newExamStructure != null){
|
|
|
+ throw new StatusException(Constants.PRT_CODE_500, "该场考试的导出结构已经存在,不能复用");
|
|
|
+ }
|
|
|
+ examStructure.setId(null);
|
|
|
+ examStructure.setExamId(info.getNewExamId());
|
|
|
+ examStructure.setExamName(info.getNewExamName());
|
|
|
+ examStructure.setId(info.getNewOrgId());
|
|
|
+ examStructure.setOrgName(info.getNewOrgName());
|
|
|
+ examStructureRepository.save(examStructure);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void syncExamStructureExamName(Long examId, String examName) {
|
|
|
+ String updateSql = String.format("UPDATE ec_prt_exam_structure SET exam_name = '%s' WHERE exam_id = %s", examName,examId);
|
|
|
+ jdbcTemplate.update(updateSql);
|
|
|
+ }
|
|
|
|
|
|
}
|