wangwei 6 years ago
parent
commit
70d680ab38

+ 49 - 1
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/provider/ExamCloudServiceProvider.java

@@ -30,9 +30,11 @@ import cn.com.qmth.examcloud.commons.base.helpers.DynamicEnum;
 import cn.com.qmth.examcloud.commons.base.helpers.DynamicEnumManager;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.core.examwork.base.enums.ExamProperty;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamCourseRelationRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgSettingsRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamPropertyRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamCourseRelationEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgSettingsEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPropertyEntity;
@@ -41,6 +43,7 @@ import cn.com.qmth.examcloud.core.examwork.service.bean.ExamInfo;
 import cn.com.qmth.examcloud.core.examwork.service.impl.ExamServiceImpl;
 import cn.com.qmth.examcloud.examwork.api.ExamCloudService;
 import cn.com.qmth.examcloud.examwork.api.bean.ExamBean;
+import cn.com.qmth.examcloud.examwork.api.bean.ExamCourseRelationBean;
 import cn.com.qmth.examcloud.examwork.api.request.GetExamCourseListReq;
 import cn.com.qmth.examcloud.examwork.api.request.GetExamListReq;
 import cn.com.qmth.examcloud.examwork.api.request.GetExamPropertyReq;
@@ -86,6 +89,9 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 	@Autowired
 	ExamPropertyRepo examPropertyRepo;
 
+	@Autowired
+	ExamCourseRelationRepo examCourseRelationRepo;
+
 	@ApiOperation(value = "新增考试批次", notes = "新增")
 	@PostMapping("saveExam")
 	@Override
@@ -407,7 +413,49 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 	@PostMapping("getExamCourseList")
 	@Override
 	public GetExamCourseListResp getExamCourseList(@RequestBody GetExamCourseListReq req) {
-		return null;
+		Long examId = req.getExamId();
+
+		final long start = null == req.getStart() ? 1 : req.getStart();
+
+		Pageable pageable = new PageRequest(0, 100, Sort.Direction.ASC, "courseId");
+
+		Specification<ExamCourseRelationEntity> specification = (root, query, cb) -> {
+			List<Predicate> predicates = new ArrayList<>();
+			predicates.add(cb.equal(root.get("examId"), examId));
+
+			predicates.add(cb.greaterThanOrEqualTo(root.get("courseId"), start));
+
+			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+
+		Page<ExamCourseRelationEntity> page = examCourseRelationRepo.findAll(specification,
+				pageable);
+
+		Iterator<ExamCourseRelationEntity> iterator = page.iterator();
+
+		List<ExamCourseRelationBean> list = Lists.newArrayList();
+		long next = start;
+		while (iterator.hasNext()) {
+			ExamCourseRelationEntity e = iterator.next();
+			ExamCourseRelationBean b = new ExamCourseRelationBean();
+			b.setCourseCode(e.getCourseCode());
+			b.setCourseId(e.getCourseId());
+			b.setCourseLevel(e.getCourseLevel());
+			b.setCourseName(e.getCourseName());
+			b.setExamId(examId);
+
+			next = e.getCourseId();
+			list.add(b);
+		}
+
+		GetExamCourseListResp resp = new GetExamCourseListResp();
+		if (next != start) {
+			next++;
+		}
+		resp.setNext(next);
+		resp.setRelationList(list);
+
+		return resp;
 	}
 
 }