Sfoglia il codice sorgente

增加考生条件分页查询

ting.yin 8 anni fa
parent
commit
4665168713

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

@@ -4,8 +4,6 @@ import io.swagger.annotations.ApiOperation;
 
 import java.util.Date;
 
-import javax.servlet.http.HttpServletRequest;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.http.HttpStatus;
@@ -18,9 +16,9 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
 import cn.com.qmth.examcloud.service.examwork.dao.ExamRepo;
 import cn.com.qmth.examcloud.service.examwork.entity.Exam;
 import cn.com.qmth.examcloud.service.examwork.service.ExamService;
@@ -39,23 +37,22 @@ public class ExamApi {
     @Autowired
     ExamService examService;
 
-    @ApiOperation(value="查询所有考试批次",notes = "分页带查询")
-    @GetMapping("/exam/all/{curPage}/{pageSize}")
-    public ResponseEntity getAllExam(@ModelAttribute Exam examCriteria, @PathVariable Integer curPage,@PathVariable Integer pageSize){
-    	return new ResponseEntity(examService.getAllExam(examCriteria,new PageRequest(curPage - 1,pageSize)), HttpStatus.OK);
-    }
-
-    @ApiOperation(value="查询所有考试批次",notes = "不分页带查询")
-    @GetMapping("/exam/all")
-    public ResponseEntity getAllExam(@ModelAttribute Exam examCriteria){
-        return new ResponseEntity(examService.getAllExam(examCriteria), HttpStatus.OK);
-    }
+//    @ApiOperation(value="查询所有考试批次",notes = "分页带查询")
+//    @GetMapping("/exam/all/{curPage}/{pageSize}")
+//    public ResponseEntity getAllExam(@ModelAttribute Exam examCriteria, @PathVariable Integer curPage,@PathVariable Integer pageSize){
+//    	return new ResponseEntity(examService.getAllExam(examCriteria,new PageRequest(curPage - 1,pageSize)), HttpStatus.OK);
+//    }
+//
+//    @ApiOperation(value="查询所有考试批次",notes = "不分页带查询")
+//    @GetMapping("/exam/all")
+//    public ResponseEntity getAllExam(@ModelAttribute Exam examCriteria){
+//        return new ResponseEntity(examService.getAllExam(examCriteria), HttpStatus.OK);
+//    }
 
     @ApiOperation(value="查询所有考试批次(orgId)",notes = "不分页不带查询")
     @GetMapping("/exam")
-    public ResponseEntity getAllExam(HttpServletRequest request){
-    	AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
-        return new ResponseEntity(examRepo.findByOrgId(accessUser.getRootOrgId()), HttpStatus.OK);
+    public ResponseEntity getAllExam(@RequestParam Long orgId){
+        return new ResponseEntity(examRepo.findByOrgId(orgId), HttpStatus.OK);
     }
 
     @ApiOperation(value="按ID查询考试批次",notes = "ID查询")

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

@@ -32,7 +32,7 @@ import cn.com.qmth.examcloud.service.examwork.service.ExamStudentService;
  * Created by songyue on 17/1/13.
  */
 @RestController
-@RequestMapping("${app.api.root}")
+@RequestMapping("${app.api.root}/exam_student")
 public class ExamStudentApi {
 
     @Autowired
@@ -41,51 +41,45 @@ public class ExamStudentApi {
     @Autowired
     ExamStudentService examStudentService;
 
-    @ApiOperation(value="查询所有考试学生",notes = "分页")
-    @GetMapping("/exam_student/all/{curPage}/{pageSize}")
+    @ApiOperation(value="查询考试学生带条件和分页",notes = "带条件带分页")
+    @GetMapping("/all/{curPage}/{pageSize}")
     public ResponseEntity getAllExamStudent(@ModelAttribute ExamStudent examCriteria, @PathVariable Integer curPage, @PathVariable Integer pageSize){
         return new ResponseEntity(examStudentService.getAllExamStudent(examCriteria,new PageRequest(curPage - 1,pageSize)),HttpStatus.OK);
     }
 
-    @ApiOperation(value="查询所有考试学生",notes = "不分页")
+    @ApiOperation(value="查询所有考试学生带条件",notes = "带条件不分页")
     @GetMapping("/exam_student/all")
     public ResponseEntity getAllExamStudent(@ModelAttribute ExamStudent examCriteria){
         return new ResponseEntity(examStudentService.getAllExamStudent(examCriteria), HttpStatus.OK);
     }
 
-    @ApiOperation(value="查询所有考试学生",notes = "不分页不带查询条件")
-    @GetMapping("/exam_student")
-    public ResponseEntity getAllExamStudent(){
-        return new ResponseEntity(examStudentRepo.findAll(), HttpStatus.OK);
-    }
-
     @ApiOperation(value="按ID查询考试学生",notes = "ID查询")
-    @GetMapping("/exam_student/{id}")
+    @GetMapping("/{id}")
     public ResponseEntity<ExamStudent> getExamStudentById(@PathVariable Long id){
         return new ResponseEntity<ExamStudent>(examStudentService.getExamStudentById(id),HttpStatus.OK);
     }
 
     @ApiOperation(value="新增考试学生",notes = "新增")
-    @PostMapping("/exam_student")
+    @PostMapping()
     public ResponseEntity addExamStudent(@RequestBody ExamStudent examStudent){
         return new ResponseEntity<ExamStudent>(examStudentService.saveExamStudent(examStudent),HttpStatus.OK);
     }
 
     @ApiOperation(value="更新考试学生",notes = "更新")
-    @PutMapping("/exam_student")
+    @PutMapping()
     public ResponseEntity updateExamStudent(@RequestBody ExamStudent examStudent){
         return new ResponseEntity(examStudentService.saveExamStudent(examStudent),HttpStatus.OK);
     }
 
     @ApiOperation(value="按ID删除考试学生",notes = "删除")
-    @DeleteMapping("/exam_student/{id}")
+    @DeleteMapping("/{id}")
     public ResponseEntity deleteExamStudent(@PathVariable Long id){
     	examStudentService.deleteExamStudent(id);
         return new ResponseEntity(HttpStatus.OK);
     }
     
     @ApiOperation(value="导入考试学生",notes = "导入")
-    @PostMapping("/exam_student/import")
+    @PostMapping("/import")
     public ResponseEntity importExamStudent(@RequestParam Long examId,@RequestParam MultipartFile file){
     	try {
     		List<ExcelError> excelErrors = examStudentService.importExamStudent(examId,file.getInputStream());
@@ -109,7 +103,7 @@ public class ExamStudentApi {
 //    }
     
     @ApiOperation(value="照片检验",notes = "检验")
-    @PostMapping("/exam_student/photo_check")
+    @PostMapping("/photo_check")
     public ResponseEntity photoCheck(@RequestParam Long examId){
     	try {
     		List<ErrorMsg> errorMsgs = examStudentService.photoCheck(examId);
@@ -119,4 +113,14 @@ public class ExamStudentApi {
 			return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
 		}
     }
+    
+//    @ApiOperation(value="导出考试学生带条件",notes = "导出")
+//    @GetMapping("/export")
+//    public void exportExamStudent(@ModelAttribute ExamStudent examCriteria,HttpServletResponse response){
+//    	List<CourseDTO> list = new ArrayList<CourseDTO>();
+//    	courseRepo.findByOrgId(orgId).forEach(c -> {
+//    		list.add(courseAssembler.toDTO(c));
+//        });
+//    	ExportUtils.exportEXCEL("课程列表", CourseDTO.class, list, response);
+//    }
 }

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

@@ -51,17 +51,12 @@ public class ExamStudentService {
      * @return 
      * @return
      */
-    public  Page<ExamStudent> getAllExamStudent(ExamStudent examCriteria, Pageable pageable){
+    public Page<ExamStudent> getAllExamStudent(ExamStudent examCriteria, Pageable pageable){
 //        ExampleMatcher exampleMatcher = ExampleMatcher.matching()
 //                .withMatcher("name",startsWith());
 //        Example<ExamStudent> examExamStudentple = Example.of(examCriteria, exampleMatcher);
 //        return examStudentRepo.findAll(examExamStudentple,pageable);
-    	Specification<ExamStudent> specification = (root, query, cb) -> {
-            List<Predicate> predicates = new ArrayList<>();
-            predicates.add(cb.like(root.get("name"),examCriteria.getName()));
-            predicates.add(cb.like(root.get("studentCode"),examCriteria.getStudentCode()));
-            return cb.and(predicates.toArray(new Predicate[predicates.size()]));
-        };
+    	Specification<ExamStudent> specification = getStudentSpecification(examCriteria);
         return examStudentRepo.findAll(specification,pageable);
     }
 
@@ -72,10 +67,8 @@ public class ExamStudentService {
      * @return
      */
     public  List<ExamStudent> getAllExamStudent(ExamStudent examCriteria){
-        ExampleMatcher exampleMatcher = ExampleMatcher.matching()
-                .withMatcher("name",startsWith());
-        Example<ExamStudent> examExamStudentple = Example.of(examCriteria, exampleMatcher);
-        return examStudentRepo.findAll(examExamStudentple);
+    	Specification<ExamStudent> specification = getStudentSpecification(examCriteria);
+        return examStudentRepo.findAll(specification);
     }
 
     /**
@@ -181,5 +174,31 @@ public class ExamStudentService {
 		}
 		return msgs;
 	}
-
+	
+	/**
+	 * 生成查询条件
+	 * @param examCriteria
+	 * @return
+	 */
+	private Specification<ExamStudent> getStudentSpecification(ExamStudent examCriteria) {
+		Specification<ExamStudent> specification = (root, query, cb) -> {
+		    List<Predicate> predicates = new ArrayList<>();
+		    predicates.add(cb.equal(root.get("rootOrgId"),examCriteria.getRootOrgId()));
+		    if(null!=examCriteria.getOrgId()){
+		    	predicates.add(cb.equal(root.get("orgId"),examCriteria.getOrgId()));
+		    }
+		    if(null!=examCriteria.getExam()){
+		    	predicates.add(cb.equal(root.get("exam").get("id"),examCriteria.getExam().getId()));
+		    }
+		    if(null!=examCriteria.getName()){
+		    	predicates.add(cb.like(root.get("name"),examCriteria.getName()));
+		    }
+		    if(null!=examCriteria.getStudentCode()){
+		    	predicates.add(cb.like(root.get("studentCode"),examCriteria.getStudentCode()));
+		    }
+		    predicates.add(cb.equal(root.get("finished"),examCriteria.isFinished()));
+		    return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+		return specification;
+	}
 }

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

@@ -26,12 +26,10 @@ public class Exam implements Serializable {
 	@NotNull
 	private Long orgId;
 
-	@Temporal(value = TemporalType.DATE)
-	@DateTimeFormat(pattern="yyyy-MM-dd")
+	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
 	private Date beginTime;
 
-	@Temporal(value = TemporalType.DATE)
-	@DateTimeFormat(pattern="yyyy-MM-dd")
+	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
 	private Date endTime;
 
 	@NotNull
@@ -43,7 +41,9 @@ public class Exam implements Serializable {
 	 * 考试时长
 	 */
 	private Integer duration;
-
+	/**
+	 * 冻结时间
+	 */
 	private Integer freezeTime;
 
 	private String status;
@@ -51,8 +51,7 @@ public class Exam implements Serializable {
 	private String remark;
 
 	@CreatedDate
-	@Temporal(value = TemporalType.DATE)
-	@DateTimeFormat(pattern="yyyy-MM-dd")
+	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
 	private Date createTime;
 
 	public long getId() {