宋悦 8 yıl önce
ebeveyn
işleme
a80a7c7727

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

@@ -178,12 +178,11 @@ public class ExamStudentApi {
 
     @ApiOperation(value = "按ID删除考试学生", notes = "删除")
     @DeleteMapping("/{id}")
-    public ResponseEntity deleteExamStudent(@PathVariable Long id) {
-//        List<Long> examStuIds = Stream.of(id.split(",")).map(s->Long.parseLong(s.trim()))
-//                .collect(Collectors.toList());
-//        examStudentRepo.deleteInBatch(examStudentRepo.findByIdIn(examStuIds));
+    public ResponseEntity deleteExamStudent(@PathVariable String id) {
+        List<Long> examStuIds = Stream.of(id.split(",")).map(s->Long.parseLong(s.trim()))
+                .collect(Collectors.toList());
         try {
-            examStudentService.deleteExamStudent(id);
+            examStudentService.deleteExamStudent(examStuIds);
             return new ResponseEntity(HttpStatus.OK);
         } catch (Exception e) {
             e.printStackTrace();

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

@@ -398,12 +398,14 @@ public class ExamStudentService {
 		targetExamStudents.clear();
 	}
 
-	public void deleteExamStudent(Long id)throws Exception{
-		ExamStudent examStudent = examStudentRepo.findOne(id);
-		if(examStudent.getExam().getCanStuDel()){
-			examStudentRepo.delete(id);
-		}else{
-			throw new RuntimeException("该考试已开始,不能删除");
+	public void deleteExamStudent(List<Long> ids)throws Exception{
+		List<ExamStudent> examStudents = examStudentRepo.findByIdIn(ids);
+		for(ExamStudent examStudent : examStudents){
+			if(examStudent.getExam().getCanStuDel()){
+				examStudentRepo.delete(examStudent);
+			}else{
+				throw new RuntimeException(examStudent.getName()+"已开始考试,不能删除");
+			}
 		}
 	}