YuanPan 8 vuotta sitten
vanhempi
commit
1e3e9ec996

+ 55 - 0
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/api/ExamCourseApi.java

@@ -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;
+
+    }
+
+}

+ 9 - 2
exam-work-domain/src/main/java/cn/com/qmth/examcloud/service/examwork/dao/ExamStudentRepo.java

@@ -6,12 +6,19 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 
 import cn.com.qmth.examcloud.service.examwork.entity.ExamStudent;
 
-public interface ExamStudentRepo extends JpaRepository<ExamStudent, Long>,QueryByExampleExecutor<ExamStudent>,JpaSpecificationExecutor<ExamStudent> {
+public interface ExamStudentRepo extends JpaRepository<ExamStudent, Long>, QueryByExampleExecutor<ExamStudent>, JpaSpecificationExecutor<ExamStudent> {
     Page<ExamStudent> findByExamId(Long examId, Pageable pageable);
 
-	List<ExamStudent> findByExamId(Long examId);
+    List<ExamStudent> findByExamId(Long examId);
+
+    @Query("select s from ExamStudent s where s.exam.id=?1 group by s.courseCode")
+    Page<ExamStudent> findDistinctCourseCode(Long examId, Pageable pageable);
+
+    @Query("select s from ExamStudent s where s.exam.id=?1 and s.courseName like ?2 group by s.courseCode")
+    Page<ExamStudent> findDistinctCourseCode(Long examId,String courseName, Pageable pageable);
 }

+ 55 - 0
exam-work-domain/src/main/java/cn/com/qmth/examcloud/service/examwork/dto/ExamCourseDTO.java

@@ -0,0 +1,55 @@
+package cn.com.qmth.examcloud.service.examwork.dto;
+
+import cn.com.qmth.examcloud.service.examwork.enums.ExamType;
+
+/**
+ * Created by yuanpan on 2017/4/12.
+ */
+public class ExamCourseDTO {
+
+    private Long examId;
+    private String examName;
+    private ExamType examType;
+    private String courseName;
+    private String courseCode;
+
+    public Long getExamId() {
+        return examId;
+    }
+
+    public void setExamId(Long examId) {
+        this.examId = examId;
+    }
+
+    public String getExamName() {
+        return examName;
+    }
+
+    public void setExamName(String examName) {
+        this.examName = examName;
+    }
+
+    public ExamType getExamType() {
+        return examType;
+    }
+
+    public void setExamType(ExamType examType) {
+        this.examType = examType;
+    }
+
+    public String getCourseName() {
+        return courseName;
+    }
+
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
+    }
+
+    public String getCourseCode() {
+        return courseCode;
+    }
+
+    public void setCourseCode(String courseCode) {
+        this.courseCode = courseCode;
+    }
+}

+ 2 - 2
exam-work-main/src/main/resources/application.properties

@@ -1,6 +1,6 @@
 spring.datasource.url=jdbc:mysql://localhost:3306/exam_cloud?useUnicode=true&characterEncoding=UTF-8
 spring.datasource.username=root
-spring.datasource.password=123456
+spring.datasource.password=1234
 spring.datasource.validation-query=SELECT 1 FROM DUAL
 spring.datasource.test-on-borrow=true
 spring.datasource.driver-class-name=com.mysql.jdbc.Driver
@@ -24,7 +24,7 @@ spring.http.multipart.max-file-size=10Mb
 
 spring.application.name=ExamCloud-service-exam-work
 server.port=8001
-eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
+eureka.client.serviceUrl.defaultZone=http://192.168.1.88:1111/eureka/
 hystrix.command.default.execution.timeout.enabled=false
 
 app.api.root=/api/ecs_exam_work