Jelajahi Sumber

修改考生与考试批次部分功能

宋悦 8 tahun lalu
induk
melakukan
ee2ac9f6b1

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

@@ -66,6 +66,7 @@ public class ExamApi {
         if(accessUser != null){
             examCriteria.setOrgId(accessUser.getRootOrgId());
         }
+        examCriteria.setEnable(true);
         return new ResponseEntity(examService.getAllExam(examCriteria), HttpStatus.OK);
     }
 
@@ -114,4 +115,30 @@ public class ExamApi {
         examRepo.deleteInBatch(examRepo.findByIdIn(examIds));
         return new ResponseEntity(HttpStatus.OK);
     }
+
+    @ApiOperation(value = "启用考试", notes = "启用考试")
+    @PutMapping("/enable/{ids}")
+    public ResponseEntity enableUser(@PathVariable String ids) {
+        List<Long> examIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
+                .collect(Collectors.toList());
+        for (Long examId : examIds) {
+            Exam exam = examRepo.findOne(examId);
+            exam.setEnable(true);
+            examRepo.save(exam);
+        }
+        return new ResponseEntity(HttpStatus.OK);
+    }
+
+    @ApiOperation(value = "禁用考试", notes = "禁用考试")
+    @PutMapping("/disable/{ids}")
+    public ResponseEntity disableUser(@PathVariable String ids) {
+        List<Long> examIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
+                .collect(Collectors.toList());
+        for (Long examId : examIds) {
+            Exam exam = examRepo.findOne(examId);
+            exam.setEnable(false);
+            examRepo.save(exam);
+        }
+        return new ResponseEntity(HttpStatus.OK);
+    }
 }

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

@@ -195,4 +195,16 @@ public class ExamStudentApi {
         });
         ExportUtils.exportEXCEL("课程列表", ExamStudentDTO.class, list, response);
     }
+
+    @ApiOperation(value = "复制考试学生", notes = "复制")
+    @PostMapping("/copy/{sourceExamId}/{targetExamId}")
+    public ResponseEntity copyExamStudent(@PathVariable Long sourceExamId,@PathVariable Long targetExamId) {
+        try {
+            examStudentService.copyExamStudent(sourceExamId,targetExamId);
+            return new ResponseEntity(HttpStatus.OK);
+        } catch (Exception e){
+            e.printStackTrace();
+            return new ResponseEntity(new ErrorMsg(e.getMessage()),HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
 }

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

@@ -216,11 +216,18 @@ public class ExamStudentService {
 
 	public void checkExamStudent(ExamStudent examStudent){
 		if(examStudent.getId() != null){
-			if(examStudentRepo.checkExamStuById(examStudent.getRootOrgId(),examStudent.getIdentityNumber(),examStudent.getCourseCode(),examStudent.getId()) > 0){
+			if(examStudentRepo.checkExamStuById(examStudent.getExam().getId(),
+												examStudent.getRootOrgId(),
+												examStudent.getIdentityNumber(),
+												examStudent.getCourseCode(),
+												examStudent.getId()) > 0){
 				throw new RuntimeException("该考生已存在");
 			}
 		}else{
-			if(examStudentRepo.checkExamStu(examStudent.getRootOrgId(),examStudent.getIdentityNumber(),examStudent.getCourseCode()) > 0){
+			if(examStudentRepo.checkExamStu(examStudent.getExam().getId(),
+											examStudent.getRootOrgId(),
+											examStudent.getIdentityNumber(),
+											examStudent.getCourseCode()) > 0){
 				throw new RuntimeException("该考生已存在");
 			}
 		}
@@ -375,4 +382,19 @@ public class ExamStudentService {
 		};
 		return specification;
 	}
+
+	/**
+	 * 复制考生
+	 * @param sourceExamId
+	 * @param targetExamId
+     */
+	public void copyExamStudent(Long sourceExamId,Long targetExamId){
+		List<ExamStudent> sourceExamStudents = examStudentRepo.findByExamId(sourceExamId);
+		Exam targetExam = examRepo.findOne(targetExamId);
+		sourceExamStudents.stream().forEach(examStudent -> {
+			examStudent.setId(null);
+			examStudent.setExam(targetExam);
+		});
+		examStudentRepo.save(sourceExamStudents);
+	}
 }

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

@@ -33,9 +33,9 @@ public interface ExamStudentRepo extends JpaRepository<ExamStudent, Long>, Query
     @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);
 
-    @Query("select count(s) from ExamStudent s where s.rootOrgId=?1 and s.identityNumber=?2 and s.courseCode=?3 and s.id <> ?4")
-    int checkExamStuById(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 and s.id <> ?5")
+    int checkExamStuById(Long examId,Long rootOrgId,String identityNumber,String courseCode,Long id);
 
-    @Query("select count(s) from ExamStudent s where s.rootOrgId=?1 and s.identityNumber=?2 and s.courseCode=?3")
-    int checkExamStu(Long rootOrgId,String identityNumber,String courseCode);
+    @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);
 }

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

@@ -74,6 +74,9 @@ public class Exam implements Serializable {
      */
 	private String status;
 
+
+	private Boolean enable;
+
 	/**
 	 * 考试备注
      */
@@ -406,6 +409,14 @@ public class Exam implements Serializable {
 		this.markingType = markingType;
 	}
 
+	public Boolean getEnable() {
+		return enable;
+	}
+
+	public void setEnable(Boolean enable) {
+		this.enable = enable;
+	}
+
 	public Exam() {
 	}
 }