Browse Source

修改bug

宋悦 8 years ago
parent
commit
a7f4eb0fd6

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

@@ -1,6 +1,7 @@
 package cn.com.qmth.examcloud.service.examwork.api;
 
 import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
+import cn.com.qmth.examcloud.common.util.ErrorMsg;
 import io.swagger.annotations.ApiOperation;
 
 import java.util.Date;
@@ -85,6 +86,7 @@ public class ExamApi {
             exam.setOrgId(accessUser.getOrgId());
             exam.setRootOrgId(accessUser.getRootOrgId());
             exam.setCreateTime(new Date());
+            exam.setCanStuDel(true);
             if(!examService.checkExamName(exam)){
                 errorMap.put("errorMsg","考试名称已存在,请重新填写");
                 return new ResponseEntity(errorMap,HttpStatus.INTERNAL_SERVER_ERROR);
@@ -110,10 +112,15 @@ public class ExamApi {
     @ApiOperation(value="按ID删除考试批次",notes = "删除")
     @DeleteMapping("/exam/{id}")
     public ResponseEntity deleteExam(@PathVariable String id){
-        List<Long> examIds = Stream.of(id.split(",")).map(s->Long.parseLong(s.trim()))
-                .collect(Collectors.toList());
-        examRepo.deleteInBatch(examRepo.findByIdIn(examIds));
-        return new ResponseEntity(HttpStatus.OK);
+        try{
+            List<Long> examIds = Stream.of(id.split(",")).map(s->Long.parseLong(s.trim()))
+                    .collect(Collectors.toList());
+            examService.deleteExam(examIds);
+            return new ResponseEntity(HttpStatus.OK);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseEntity(new ErrorMsg(e.getMessage()),HttpStatus.INTERNAL_SERVER_ERROR);
+        }
     }
 
     @ApiOperation(value = "启用考试", notes = "启用考试")

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

@@ -161,6 +161,18 @@ public class ExamStudentApi {
         }
     }
 
+    @ApiOperation(value = "按考试删除考试学生", notes = "按考试删除")
+    @DeleteMapping("/exam/{examId}")
+    public ResponseEntity deleteExamStudents(@PathVariable Long examId) {
+        try {
+            examStudentService.deleteExamStudents(examId);
+            return new ResponseEntity(HttpStatus.OK);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity(new ErrorMsg(e.getMessage()),HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
     @ApiOperation(value = "导入考试学生", notes = "导入")
     @PostMapping("/import")
     public ResponseEntity importExamStudent(@RequestParam Long examId, @RequestParam CommonsMultipartFile file) {

+ 10 - 18
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/service/ExamService.java

@@ -50,14 +50,6 @@ public class ExamService {
         return examRepo.findAll(examExample);
     }
 
-    /**
-     * 获取所有考试批次
-     * @return
-     */
-    public List<Exam> getAllExam(){
-        return examRepo.findAll();
-    }
-
     /**
      * 按ID获取考试批次
      * @param examId
@@ -78,20 +70,20 @@ public class ExamService {
 
     /**
      * 删除考试批次
-     * @param examId
+     * @param ids
      * @return
      */
-    public void deleteExam(Long examId){
-        examRepo.delete(examId);
+    public void deleteExam(List<Long> ids){
+        List<Exam> exams = examRepo.findByIdIn(ids);
+        for(Exam exam:exams){
+            if(exam.getCanStuDel()){
+                examRepo.delete(exam);
+            }else{
+                throw new RuntimeException(exam.getName()+"批次已经开始,不能删除");
+            }
+        }
     }
 
-    /**
-     * 删除所有考试批次
-     * @return
-     */
-    public void deleteAllExam(){
-        examRepo.deleteAll();
-    }
 
     public boolean checkExamName(Exam exam){
         if(exam.getId()!=null){

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

@@ -63,9 +63,7 @@ public class ExamStudentService {
     @Autowired
     OrgService orgService;
 
-	@Autowired
-	OeService oeService;
-    
+
 //    @Value("${app.em.photo.path}")
 //    private String PHOTO_PATH ;
 //    @Value("${app.em.facepp.key}")
@@ -197,10 +195,6 @@ public class ExamStudentService {
 			student.setRootOrgId(examStudent.getRootOrgId());
 			student.setStudentCode(examStudent.getStudentCode());
 			student.setIdentityNumber(examStudent.getIdentityNumber());
-			examStudentRepo.updateById(examStudent.getIdentityNumber(),
-					examStudent.getName(),
-					examStudent.getSpecialtyName(),
-					examStudent.getExamSite());
 			studentService.updateStudent(student);
 		}
 		examStudent.setFinished(false);
@@ -390,21 +384,38 @@ public class ExamStudentService {
 		List<ExamStudent> targetExamStudents = new ArrayList<ExamStudent>();
 		Exam targetExam = examRepo.findOne(targetExamId);
 		sourceExamStudents.stream().forEach(examStudent -> {
-			ExamStudent tempStudent = BeanCopierUtil.copyProperties(examStudent,ExamStudent.class);
-			tempStudent.setId(null);
-			tempStudent.setExam(targetExam);
-			targetExamStudents.add(tempStudent);
+			if(examStudentRepo.checkExamStuById(examStudent.getExam().getId(),
+					examStudent.getRootOrgId(),
+					examStudent.getIdentityNumber(),
+					examStudent.getCourseCode(),
+					examStudent.getId()) == 0){
+				ExamStudent tempStudent = BeanCopierUtil.copyProperties(examStudent,ExamStudent.class);
+				tempStudent.setId(null);
+				tempStudent.setExam(targetExam);
+				targetExamStudents.add(tempStudent);
+			}
 		});
 		examStudentRepo.save(targetExamStudents);
+		sourceExamStudents.clear();
+		targetExamStudents.clear();
 	}
 
 	public void deleteExamStudent(Long id)throws Exception{
 		ExamStudent examStudent = examStudentRepo.findOne(id);
-		int examRecordCount = oeService.checkExamRecord(examStudent.getExam().getId(), examStudent.getIdentityNumber());
-		if(examRecordCount > 0){
-			throw new RuntimeException("该考生已有考试记录,不能删除");
-		}else{
+		if(examStudent.getExam().getCanStuDel()){
 			examStudentRepo.delete(id);
+		}else{
+			throw new RuntimeException("该考试已开始,不能删除");
+		}
+	}
+
+	public void deleteExamStudents(Long examId)throws Exception{
+		Exam exam = examRepo.findOne(examId);
+		if(exam.getCanStuDel()){
+			List<ExamStudent> examStudents = examStudentRepo.findByExamId(examId);
+			examStudentRepo.deleteInBatch(examStudents);
+		}else{
+			throw new RuntimeException("该考试已开始,不能删除");
 		}
 	}
 }

+ 4 - 0
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/service/rpc/StudentService.java

@@ -42,4 +42,8 @@ public class StudentService {
 		return domain;
 	}
 
+	public void deleteStudent(Long id) {
+		studentClient.deleteStudent(id);
+	}
+
 }

+ 3 - 0
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/service/rpc/client/StudentClient.java

@@ -25,4 +25,7 @@ public interface StudentClient {
 	@RequestMapping(method = RequestMethod.PUT, value = "${app.api.core}/student")
 	String updateStudent(@RequestBody Student student);
 
+	@RequestMapping(method = RequestMethod.DELETE, value = "${app.api.core}/student/{id}")
+	void deleteStudent(@PathVariable("id") Long id);
+
 }

+ 13 - 0
exam-work-domain/src/main/java/cn/com/qmth/examcloud/service/examwork/entity/Exam.java

@@ -196,6 +196,11 @@ public class Exam implements Serializable {
 	@Enumerated(EnumType.STRING)
 	private MarkingType markingType;
 
+	/**
+	 * 学生是否可以删除
+     */
+	private Boolean canStuDel;
+
 
 	public Long getId() {
 		return id;
@@ -469,6 +474,14 @@ public class Exam implements Serializable {
 		this.fillBlankEdit = fillBlankEdit;
 	}
 
+	public Boolean getCanStuDel() {
+		return canStuDel;
+	}
+
+	public void setCanStuDel(Boolean canStuDel) {
+		this.canStuDel = canStuDel;
+	}
+
 	public Exam() {
 	}
 }