|
@@ -0,0 +1,55 @@
|
|
|
+package cn.com.qmth.examcloud.service.examwork.api;
|
|
|
+
|
|
|
+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.ExamStudent;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+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;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by yuanpan on 2017/4/12.
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("${app.api.root}/exam_course")
|
|
|
+public class ExamCourseApi {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamStudentRepo examStudentRepo;
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping
|
|
|
+ public Page<ExamCourseDTO> query(@RequestParam("exam_id") Long examId,
|
|
|
+ @RequestParam(value = "course_name", required = false) String courseName,
|
|
|
+ @RequestParam("cur_page") Integer curPage,
|
|
|
+ @RequestParam("page_size") Integer pageSize) {
|
|
|
+
|
|
|
+
|
|
|
+ Page<ExamStudent> examStudentPage;
|
|
|
+ if (StringUtils.isEmpty(courseName)) {
|
|
|
+ examStudentPage = examStudentRepo.findDistinctCourseCode(examId, new PageRequest(curPage, pageSize));
|
|
|
+ } else {
|
|
|
+ examStudentPage = examStudentRepo.findDistinctCourseCode(examId, '%' + courseName + "%", new PageRequest(curPage, pageSize));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Page<ExamCourseDTO> examCourseDTOPage = examStudentPage.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());
|
|
|
+ return examCourseDTO;
|
|
|
+ });
|
|
|
+
|
|
|
+ return examCourseDTOPage;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|