|
@@ -1,17 +1,26 @@
|
|
|
package cn.com.qmth.examcloud.service.examwork.api;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.common.dto.core.Course;
|
|
|
+import cn.com.qmth.examcloud.service.examwork.dao.ExamRepo;
|
|
|
import cn.com.qmth.examcloud.service.examwork.dao.ExamStudentRepo;
|
|
|
import cn.com.qmth.examcloud.service.examwork.dto.ExamCourseDTO;
|
|
|
+import cn.com.qmth.examcloud.service.examwork.entity.Exam;
|
|
|
import cn.com.qmth.examcloud.service.examwork.entity.ExamStudent;
|
|
|
+import cn.com.qmth.examcloud.service.examwork.service.rpc.CourseService;
|
|
|
+import cn.com.qmth.examcloud.service.examwork.service.rpc.client.CourseClient;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -24,6 +33,12 @@ public class ExamCourseApi {
|
|
|
@Autowired
|
|
|
ExamStudentRepo examStudentRepo;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ CourseService courseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamRepo examRepo;
|
|
|
+
|
|
|
|
|
|
@GetMapping
|
|
|
public Page<ExamCourseDTO> findCourse(@RequestParam("exam_id") Long examId,
|
|
@@ -32,15 +47,15 @@ public class ExamCourseApi {
|
|
|
@RequestParam("page_size") Integer pageSize) {
|
|
|
|
|
|
|
|
|
- Page<ExamStudent> examStudentPage;
|
|
|
+ List<ExamStudent> examStudents;
|
|
|
if (StringUtils.isEmpty(courseCode)) {
|
|
|
- examStudentPage = examStudentRepo.findDistinctCourseCode(examId, new PageRequest(curPage, pageSize));
|
|
|
+ examStudents = examStudentRepo.findDistinctCourseCode(examId);
|
|
|
} else {
|
|
|
- examStudentPage = examStudentRepo.findDistinctCourseCode(examId, courseCode, new PageRequest(curPage, pageSize));
|
|
|
+ examStudents = examStudentRepo.findDistinctCourseCode(examId, courseCode);
|
|
|
}
|
|
|
+ Map<String, Boolean> courseMap = getCourseEnableMap(examId);
|
|
|
|
|
|
-
|
|
|
- Page<ExamCourseDTO> examCourseDTOPage = examStudentPage.map(examStudent -> {
|
|
|
+ List<ExamCourseDTO> examCourseDTOs = examStudents.stream().map(examStudent -> {
|
|
|
ExamCourseDTO examCourseDTO = new ExamCourseDTO();
|
|
|
examCourseDTO.setExamId(examId);
|
|
|
examCourseDTO.setExamName(examStudent.getExam().getName());
|
|
@@ -49,16 +64,21 @@ public class ExamCourseApi {
|
|
|
examCourseDTO.setCourseCode(examStudent.getCourseCode());
|
|
|
examCourseDTO.setOrgId(examStudent.getRootOrgId());
|
|
|
return examCourseDTO;
|
|
|
- });
|
|
|
- return examCourseDTOPage;
|
|
|
+ }).filter(examCourseDTO -> {
|
|
|
+ Boolean enable = courseMap.get(examCourseDTO.getCourseCode());
|
|
|
+ return enable != null ? enable : false;
|
|
|
+ }).skip(curPage * pageSize).limit(pageSize).collect(Collectors.toList());
|
|
|
+ return new PageImpl<ExamCourseDTO>(examCourseDTOs, new PageRequest(curPage, pageSize), examStudents.size());
|
|
|
|
|
|
}
|
|
|
|
|
|
@GetMapping("/marking")
|
|
|
- public List<ExamCourseDTO> findCourse(@RequestParam(value="exam_id",required = true) Long examId) {
|
|
|
+ public List<ExamCourseDTO> findCourse(@RequestParam(value = "exam_id", required = true) Long examId) {
|
|
|
|
|
|
List<ExamStudent> examStudents = examStudentRepo.findDistinctCourseCode(examId);
|
|
|
|
|
|
+ Map<String, Boolean> courseMap = getCourseEnableMap(examId);
|
|
|
+
|
|
|
List<ExamCourseDTO> examCourseDTOs = examStudents.stream().map(examStudent -> {
|
|
|
ExamCourseDTO examCourseDTO = new ExamCourseDTO();
|
|
|
examCourseDTO.setExamId(examId);
|
|
@@ -68,9 +88,24 @@ public class ExamCourseApi {
|
|
|
examCourseDTO.setCourseCode(examStudent.getCourseCode());
|
|
|
examCourseDTO.setOrgId(examStudent.getRootOrgId());
|
|
|
return examCourseDTO;
|
|
|
+ }).filter(examCourseDTO -> {
|
|
|
+ Boolean enable = courseMap.get(examCourseDTO.getCourseCode());
|
|
|
+ return enable != null ? enable : false;
|
|
|
}).collect(Collectors.toList());
|
|
|
return examCourseDTOs;
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private Map<String, Boolean> getCourseEnableMap(Long examId) {
|
|
|
+ Map<String, Boolean> courseMap = new HashMap<>();
|
|
|
+ Exam exam = examRepo.findOne(examId);
|
|
|
+ List<Course> courses = courseService.findByOrgId(exam.getRootOrgId());
|
|
|
+ if(courses != null && courses.size() > 0){
|
|
|
+ for(Course course:courses){
|
|
|
+ courseMap.put(course.getCode(),course.getEnable());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return courseMap;
|
|
|
+ }
|
|
|
+
|
|
|
}
|