|
@@ -1,27 +1,13 @@
|
|
package cn.com.qmth.examcloud.service.examwork.api;
|
|
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.criteria.ExamCourseCriteria;
|
|
import cn.com.qmth.examcloud.service.examwork.dto.ExamCourseDTO;
|
|
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 cn.com.qmth.examcloud.service.examwork.service.ExamCourseService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Page;
|
|
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 org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
-import java.util.Map;
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* Created by yuanpan on 2017/4/12.
|
|
* Created by yuanpan on 2017/4/12.
|
|
@@ -31,91 +17,24 @@ import java.util.stream.Collectors;
|
|
public class ExamCourseApi {
|
|
public class ExamCourseApi {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- ExamStudentRepo examStudentRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- CourseService courseService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- ExamRepo examRepo;
|
|
|
|
|
|
+ private ExamCourseService examCourseService;
|
|
|
|
|
|
|
|
|
|
@GetMapping
|
|
@GetMapping
|
|
- public Page<ExamCourseDTO> findCourse(@RequestParam("exam_id") Long examId,
|
|
|
|
- @RequestParam(value = "course_code", required = false) String courseCode,
|
|
|
|
- @RequestParam(value = "course_level", required = false) String courseLevel,
|
|
|
|
- @RequestParam("cur_page") Integer curPage,
|
|
|
|
- @RequestParam("page_size") Integer pageSize) {
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- List<ExamStudent> examStudents;
|
|
|
|
- if (!StringUtils.isEmpty(courseCode)) {
|
|
|
|
- examStudents = examStudentRepo.findDistinctCourseCode(examId, courseCode);
|
|
|
|
- } else {
|
|
|
|
- examStudents = examStudentRepo.findDistinctCourseCode(examId);
|
|
|
|
- }
|
|
|
|
- Map<String, Course> courseMap = getCourseMap(examId);
|
|
|
|
-
|
|
|
|
- List<ExamCourseDTO> examCourseDTOs = examStudents.stream().map(examStudent -> {
|
|
|
|
- ExamCourseDTO examCourseDTO = new ExamCourseDTO();
|
|
|
|
- examCourseDTO.setExamId(examId);
|
|
|
|
- examCourseDTO.setExamName(examStudent.getExam().getName());
|
|
|
|
- examCourseDTO.setExamType(examStudent.getExam().getExamType());
|
|
|
|
- examCourseDTO.setCourseName(examStudent.getCourseName());
|
|
|
|
- examCourseDTO.setCourseCode(examStudent.getCourseCode());
|
|
|
|
- examCourseDTO.setOrgId(examStudent.getRootOrgId());
|
|
|
|
- return examCourseDTO;
|
|
|
|
- }).filter(examCourseDTO -> {
|
|
|
|
- Course course = courseMap.get(examCourseDTO.getCourseCode());
|
|
|
|
- return course.getEnable() != null ? course.getEnable() : false;
|
|
|
|
- }).filter(examCourseDTO -> {
|
|
|
|
- if(!StringUtils.isEmpty(courseLevel)){
|
|
|
|
- Course course = courseMap.get(examCourseDTO.getCourseCode());
|
|
|
|
- return courseLevel.equals(course.getLevel().name());
|
|
|
|
- }else{
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
- int total = examCourseDTOs.size();
|
|
|
|
- examCourseDTOs = examCourseDTOs.stream().skip(curPage * pageSize).limit(pageSize).collect(Collectors.toList());
|
|
|
|
- return new PageImpl<ExamCourseDTO>(examCourseDTOs, new PageRequest(curPage, pageSize), total);
|
|
|
|
-
|
|
|
|
|
|
+ public Page<ExamCourseDTO> findAllPage(@RequestParam("exam_id") Long examId,
|
|
|
|
+ @RequestParam(value = "course_code",required = false) String courseCode,
|
|
|
|
+ @RequestParam(value = "course_level",required = false) String courseLevel,
|
|
|
|
+ @RequestParam("cur_page") Integer curPage,
|
|
|
|
+ @RequestParam("page_size") Integer pageSize) {
|
|
|
|
+ ExamCourseCriteria courseCriteria = new ExamCourseCriteria(examId,courseCode,courseLevel,curPage,pageSize);
|
|
|
|
+ Page<ExamCourseDTO> examCourseDTOs = examCourseService.findAllPage(courseCriteria);
|
|
|
|
+ return examCourseDTOs;
|
|
}
|
|
}
|
|
|
|
|
|
@GetMapping("/marking")
|
|
@GetMapping("/marking")
|
|
- public List<ExamCourseDTO> findCourse(@RequestParam(value = "exam_id", required = true) Long examId) {
|
|
|
|
-
|
|
|
|
- List<ExamStudent> examStudents = examStudentRepo.findDistinctCourseCode(examId);
|
|
|
|
-
|
|
|
|
- Map<String, Course> courseMap = getCourseMap(examId);
|
|
|
|
-
|
|
|
|
- List<ExamCourseDTO> examCourseDTOs = examStudents.stream().map(examStudent -> {
|
|
|
|
- ExamCourseDTO examCourseDTO = new ExamCourseDTO();
|
|
|
|
- examCourseDTO.setExamId(examId);
|
|
|
|
- examCourseDTO.setExamName(examStudent.getExam().getName());
|
|
|
|
- examCourseDTO.setExamType(examStudent.getExam().getExamType());
|
|
|
|
- examCourseDTO.setCourseName(examStudent.getCourseName());
|
|
|
|
- examCourseDTO.setCourseCode(examStudent.getCourseCode());
|
|
|
|
- examCourseDTO.setOrgId(examStudent.getRootOrgId());
|
|
|
|
- return examCourseDTO;
|
|
|
|
- }).filter(examCourseDTO -> {
|
|
|
|
- Course course = courseMap.get(examCourseDTO.getCourseCode());
|
|
|
|
- return course.getEnable() != null ? course.getEnable() : false;
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
|
|
+ public List<ExamCourseDTO> findAll(@RequestParam("exam_id") Long examId) {
|
|
|
|
+ ExamCourseCriteria courseCriteria = new ExamCourseCriteria(examId);
|
|
|
|
+ List<ExamCourseDTO> examCourseDTOs = examCourseService.findAll(courseCriteria);
|
|
return examCourseDTOs;
|
|
return examCourseDTOs;
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private Map<String, Course> getCourseMap(Long examId) {
|
|
|
|
- Map<String, Course> 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);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return courseMap;
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|