wangwei 7 yıl önce
ebeveyn
işleme
15f32472f5

+ 22 - 20
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/ExamStudentController.java

@@ -353,32 +353,34 @@ public class ExamStudentController extends ControllerSupport {
 		return new ResponseEntity<ExamStudent>(examStudentRepo.save(examStudent), HttpStatus.OK);
 	}
 
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param ids
+	 * @return
+	 */
 	@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()))
+	@DeleteMapping("/{ids}")
+	public List<Long> deleteExamStudent(@PathVariable String ids) {
+		List<Long> examStuIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
 				.collect(Collectors.toList());
-		try {
-			examStudentService.deleteExamStudent(examStuIds);
-			return new ResponseEntity(HttpStatus.OK);
-		} catch (Exception e) {
-			log.error("删除失败:", e);
-			return new ResponseEntity(new ErrorMsg(e.getMessage()),
-					HttpStatus.INTERNAL_SERVER_ERROR);
-		}
+		examStudentService.deleteExamStudent(examStuIds);
+		return examStuIds;
 	}
 
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param examId
+	 * @return
+	 */
 	@ApiOperation(value = "按考试删除考试学生", notes = "按考试删除")
 	@DeleteMapping("/exam/{examId}")
-	public ResponseEntity deleteExamStudents(@PathVariable Long examId) {
-		try {
-			examStudentService.deleteExamStudents(examId);
-			return new ResponseEntity(HttpStatus.OK);
-		} catch (Exception e) {
-			log.error("删除失败:", e);
-			return new ResponseEntity(new ErrorMsg(e.getMessage()),
-					HttpStatus.INTERNAL_SERVER_ERROR);
-		}
+	public Long deleteExamStudents(@PathVariable Long examId) {
+		examStudentService.deleteExamStudents(examId);
+		return examId;
 	}
 
 	@ApiOperation(value = "导入考试学生", notes = "导入")

+ 17 - 4
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/ExamStudentService.java

@@ -30,6 +30,7 @@ import cn.com.qmth.examcloud.common.dto.core.Student;
 import cn.com.qmth.examcloud.common.dto.core.User;
 import cn.com.qmth.examcloud.common.dto.core.enums.UserType;
 import cn.com.qmth.examcloud.common.dto.examwork.CommonExamStudent;
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.commons.base.util.BeanCopierUtil;
 import cn.com.qmth.examcloud.commons.base.util.ErrorMsg;
 import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
@@ -690,23 +691,35 @@ public class ExamStudentService {
 		targetExamStudents.clear();
 	}
 
-	public void deleteExamStudent(List<Long> ids) throws Exception {
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param ids
+	 */
+	public void deleteExamStudent(List<Long> ids) {
 		List<ExamStudent> examStudents = examStudentRepo.findByIdIn(ids);
 		for (ExamStudent examStudent : examStudents) {
 			if (examStudent.getExam().getCanStuDel()) {
 				examStudentRepo.delete(examStudent);
 			} else {
-				throw new RuntimeException(examStudent.getName() + "已开始考试,不能删除");
+				throw new StatusException("E-150112", examStudent.getName() + "已开始考试,不能删除");
 			}
 		}
 	}
 
-	public void deleteExamStudents(Long examId) throws Exception {
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param examId
+	 */
+	public void deleteExamStudents(Long examId) {
 		Exam exam = examRepo.findOne(examId);
 		if (exam.getCanStuDel()) {
 			examStudentRepo.deleteByExamId(examId);
 		} else {
-			throw new RuntimeException("该考试已开始,不能删除");
+			throw new StatusException("E-150113", "该考试已开始,不能删除");
 		}
 	}