YuanPan 7 anni fa
parent
commit
d7b0bf79f6

+ 21 - 6
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/api/ExamStudentApi.java

@@ -11,7 +11,9 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -97,7 +99,7 @@ public class ExamStudentApi {
             if (accessUser.getRootOrgId().longValue() == accessUser.getOrgId().longValue()
                     || examStudent.getStudentId() != null) {
                 examStudent.setRootOrgId(accessUser.getRootOrgId());
-            }else {
+            } else {
                 examStudent.setOrgId(accessUser.getOrgId());
             }
         } else {
@@ -116,7 +118,7 @@ public class ExamStudentApi {
             if (accessUser.getRootOrgId().longValue() == accessUser.getOrgId().longValue()
                     || examStudent.getStudentId() != null) {
                 examStudent.setRootOrgId(accessUser.getRootOrgId());
-            }else {
+            } else {
                 examStudent.setOrgId(accessUser.getOrgId());
             }
         }
@@ -140,7 +142,7 @@ public class ExamStudentApi {
             }
             Exam exam = examRepo.findOne(examStudent.getExam().getId());
             examStudent.setExam(exam);
-            if(StringUtils.isEmpty(examStudent.getPaperType())){
+            if (StringUtils.isEmpty(examStudent.getPaperType())) {
                 examStudent.setPaperType("O");
             }
             ExamStudent saveExamStu = examStudentService.saveExamStudent(examStudent);
@@ -157,7 +159,7 @@ public class ExamStudentApi {
         try {
             Exam exam = examRepo.findOne(examStudent.getExam().getId());
             examStudent.setExam(exam);
-            if(StringUtils.isEmpty(examStudent.getPaperType())){
+            if (StringUtils.isEmpty(examStudent.getPaperType())) {
                 examStudent.setPaperType("O");
             }
             ExamStudent saveExamStu = examStudentService.saveExamStudent(examStudent);
@@ -179,7 +181,7 @@ public class ExamStudentApi {
     @ApiOperation(value = "按ID删除考试学生", notes = "删除")
     @DeleteMapping("/{id}")
     public ResponseEntity deleteExamStudent(@PathVariable String id) {
-        List<Long> examStuIds = Stream.of(id.split(",")).map(s->Long.parseLong(s.trim()))
+        List<Long> examStuIds = Stream.of(id.split(",")).map(s -> Long.parseLong(s.trim()))
                 .collect(Collectors.toList());
         try {
             examStudentService.deleteExamStudent(examStuIds);
@@ -198,7 +200,7 @@ public class ExamStudentApi {
             return new ResponseEntity(HttpStatus.OK);
         } catch (Exception e) {
             e.printStackTrace();
-            return new ResponseEntity(new ErrorMsg(e.getMessage()),HttpStatus.INTERNAL_SERVER_ERROR);
+            return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
         }
     }
 
@@ -267,4 +269,17 @@ public class ExamStudentApi {
             return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
         }
     }
+
+    @ApiOperation(value = "考生完成数量", notes = "考生完成数量")
+    @PostMapping("/count-by-finished")
+    public Map<String, Integer> countByFinished(@RequestParam Long examId) {
+
+        int finished = examStudentRepo.countByExamIdAndFinished(examId, true);
+        int unFinished = examStudentRepo.countByExamIdAndFinished(examId, false);
+        Map<String, Integer> result = new HashMap<>();
+        result.put("finished", finished);
+        result.put("unFinished", unFinished);
+
+        return result;
+    }
 }

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

@@ -23,35 +23,35 @@ public interface ExamStudentRepo extends JpaRepository<ExamStudent, Long>, Query
     List<ExamStudent> findDistinctCourseCode(Long examId);
 
     @Query("select s from ExamStudent s where s.exam.id=?1 and s.courseCode = ?2 group by s.courseCode order by s.courseCode")
-    List<ExamStudent> findDistinctCourseCode(Long examId,String courseCode);
+    List<ExamStudent> findDistinctCourseCode(Long examId, String courseCode);
 
     @Query("select s from ExamStudent s where s.exam.id=?1 group by s.courseCode order by s.courseCode")
     Page<ExamStudent> findDistinctCourseCode(Long examId, Pageable pageable);
 
     @Query("select s from ExamStudent s where s.exam.id=?1 and s.courseCode = ?2 group by s.courseCode order by s.courseCode")
-    Page<ExamStudent> findDistinctCourseCode(Long examId,String courseCode, Pageable pageable);
+    Page<ExamStudent> findDistinctCourseCode(Long examId, String courseCode, Pageable pageable);
 
     List<ExamStudent> findByIdIn(List<Long> ids);
 
     @Query("select s from ExamStudent s where s.exam.id=?1 and s.courseCode =?2 group by s.paperType")
-    List<ExamStudent> findDistinctPaperType(Long examId,String courseCode);
+    List<ExamStudent> findDistinctPaperType(Long examId, String courseCode);
 
     @Query("select s from ExamStudent s where s.exam.id = ?1 and s.courseCode = ?2 and (s.studentCode = ?3 or s.identityNumber = ?3)")
-    ExamStudent findFirstByExamId(Long examId,String courseCode,String stuNumber);
+    ExamStudent findFirstByExamId(Long examId, String courseCode, String stuNumber);
 
     @Query("select count(s) from ExamStudent s where s.exam.id = ?1 and s.rootOrgId=?2 and s.identityNumber=?3 and s.courseCode=?4 and s.id <> ?5")
-    int checkExamStuById(Long examId,Long rootOrgId,String identityNumber,String courseCode,Long id);
+    int checkExamStuById(Long examId, Long rootOrgId, String identityNumber, String courseCode, Long id);
 
     @Query("select count(s) from ExamStudent s where s.exam.id = ?1 and s.rootOrgId=?2 and s.identityNumber=?3 and s.courseCode=?4")
-    int checkExamStu(Long examId,Long rootOrgId,String identityNumber,String courseCode);
+    int checkExamStu(Long examId, Long rootOrgId, String identityNumber, String courseCode);
 
     @Transactional
     @Modifying
     @Query("update ExamStudent s set s.name = ?2,s.specialtyName  = ?3,s.examSite = ?4  where s.identityNumber = ?1")
-    void updateById(String identityNumber,String name,String specialtyName,String examSite);
+    void updateById(String identityNumber, String name, String specialtyName, String examSite);
 
     @Query("select s from ExamStudent s where s.rootOrgId=?1 and s.courseCode=?2")
-    List<ExamStudent> findByCourseCode(Long rootOrgId,String courseCode);
+    List<ExamStudent> findByCourseCode(Long rootOrgId, String courseCode);
 
     List<ExamStudent> findByOrgId(Long orgId);
 
@@ -59,4 +59,6 @@ public interface ExamStudentRepo extends JpaRepository<ExamStudent, Long>, Query
     @Modifying
     @Query("delete from ExamStudent s where s.exam.id = ?1")
     void deleteByExamId(Long examId);
+
+    int countByExamIdAndFinished(Long examId, Boolean finished);
 }