Browse Source

修改重考逻辑

chenken 7 years ago
parent
commit
b022937dc4

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

@@ -1,6 +1,7 @@
 package cn.com.qmth.examcloud.service.examwork.api;
 
 import cn.com.qmth.examcloud.common.dto.core.Course;
+import cn.com.qmth.examcloud.common.dto.examwork.CommonExamStudent;
 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;
@@ -28,6 +29,7 @@ import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Sort;
 import org.springframework.data.domain.Sort.Direction;
@@ -114,6 +116,24 @@ public class ExamStudentApi {
         return new ResponseEntity(examStudentService.getAllExamStudent(examStudent,
                 new PageRequest(curPage, pageSize,new Sort(Direction.DESC,"id"))), HttpStatus.OK);
     }
+    /**
+     * 
+     * @return
+     */
+    @ApiOperation(value = "查询重考考生", notes = "查询重考考生")
+    @PostMapping("/reexamineStudents/{curPage}/{pageSize}")
+    public ResponseEntity getReexamineStudents(@RequestBody CommonExamStudent examStudentSpecification,@PathVariable Integer curPage,@PathVariable Integer pageSize){
+    	try{
+    		Page<ExamStudent> pageExamStudents = examStudentService.getReexamineStudent(examStudentSpecification, curPage, pageSize);
+    		if(pageExamStudents==null||pageExamStudents.getContent()==null||pageExamStudents.getContent().size()==0){
+    			return new ResponseEntity(new ErrorMsg("无数据",null), HttpStatus.OK);
+    		}
+    		return new ResponseEntity(pageExamStudents,HttpStatus.OK);
+    	}catch(Exception e){
+    		e.printStackTrace();
+    		return new ResponseEntity(new ErrorMsg("调用失败"),HttpStatus.INTERNAL_SERVER_ERROR);
+    	}
+    }
 
     @ApiOperation(value = "查询所有考试学生带条件", notes = "带条件不分页")
     @GetMapping("/all")
@@ -181,6 +201,11 @@ public class ExamStudentApi {
     public ResponseEntity<ExamStudent> getExamStudentById(@PathVariable Long id, @RequestParam boolean finished) {
         ExamStudent examStudent = examStudentRepo.findOne(id);
         examStudent.setFinished(finished);
+        //进入考试时,判断考试次数是否小于考试信息(ecs_exam)中的考试次数,如果是,考试次数加一
+        long examTimes = examStudent.getExam().getExamTimes();
+        if(examTimes > examStudent.getNormalExamTimes()){
+        	examStudent.setNormalExamTimes(examStudent.getNormalExamTimes()+1);
+        }
         return new ResponseEntity<ExamStudent>(examStudentRepo.save(examStudent), HttpStatus.OK);
     }
 
@@ -358,4 +383,14 @@ public class ExamStudentApi {
             return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
         }
     }
+    
+    @ApiOperation(value = "设置考生为重考状态", notes = "设置考生为重考状态")
+    @PostMapping("/setExamStudentReexamine")
+    public ResponseEntity<Object> setExamStudentIsReexamine(@RequestBody CommonExamStudent commonExamStudent){
+    	if(commonExamStudent.getId() == null){
+    		return new ResponseEntity<Object>(new ErrorMsg("考生ID不能为空"), HttpStatus.INTERNAL_SERVER_ERROR);
+    	}
+    	examStudentService.setExamStudentIsReexamine(commonExamStudent);
+    	return new ResponseEntity<Object>(HttpStatus.OK);
+    }
 }

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

@@ -15,6 +15,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
 import org.springframework.data.domain.Sort.Direction;
@@ -23,12 +24,14 @@ import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.RequestBody;
 
 import cn.com.qmth.examcloud.common.dto.core.Course;
 import cn.com.qmth.examcloud.common.dto.core.Org;
 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.common.util.ErrorMsg;
 import cn.com.qmth.examcloud.common.util.excel.ExcelError;
 import cn.com.qmth.examcloud.common.util.excel.ExcelReader;
@@ -329,6 +332,92 @@ public class ExamStudentService {
 		return msgs;
 	}
 	
+	/**
+	 * 获取重考考生
+	 * @param examCriteria
+	 * @param pageable
+	 * @return
+	 */
+    public Page<ExamStudent> getReexamineStudent(CommonExamStudent examCriteria,Integer curPage,Integer pageSize){
+    	if(examCriteria.getExamId() == null){
+    		return null;
+    	}
+    	StringBuffer sql = new StringBuffer();
+    	sql.append("select "
+				   + "t1.id 				id,"
+				   + "t1.exam_id 			exam_id,"
+				   + "t1.org_id 			org_id,"
+				   + "t1.org_name 			org_name,"
+				   + "t1.course_code 		course_code,"
+				   + "t1.course_name 		course_name,"
+				   + "t1.course_level 		course_level,"
+				   + "t1.name 				name,"
+				   + "t1.student_code 	 	student_code,"
+				   + "t1.identity_number 	identity_number"
+				+ " from ecs_exam_student t1 "
+				+ " where t1.normal_exam_times = ( "+
+				" 	select t2.exam_times from ecs_exam t2 where t2.id = t1.exam_id "+
+				")");
+    	sql.append(" and t1.exam_id="+examCriteria.getExamId());
+    	sql.append(getSqlSpecification(examCriteria));
+    	sql.append(" limit "+(curPage-1)*pageSize+","+pageSize);
+    	
+    	Exam exam = examRepo.findOne(examCriteria.getExamId());
+    	List<ExamStudent> examStudents = this.jdbcTemplate.query(sql.toString(), new RowMapper<ExamStudent>(){
+			@Override
+			public ExamStudent mapRow(ResultSet rs, int arg)throws SQLException {
+				ExamStudent examStudent = new ExamStudent();
+				examStudent.setId(rs.getLong("id"));
+				examStudent.setExam(exam);
+				examStudent.setOrgId(rs.getLong("org_id"));
+				examStudent.setOrgName(rs.getString("org_name"));
+				examStudent.setCourseCode(rs.getString("course_code"));
+				examStudent.setCourseName(rs.getString("course_name"));
+				examStudent.setCourseLevel(rs.getString("course_level"));
+				examStudent.setName(rs.getString("name"));
+				examStudent.setStudentCode(rs.getString("student_code"));
+				examStudent.setIdentityNumber(rs.getString("identity_number"));
+				return examStudent;
+			}
+    	});
+    	int total = countReexamineStudent(examCriteria);
+    	return new PageImpl<>(examStudents,null,total);
+    }
+	
+	private int countReexamineStudent(CommonExamStudent examCriteria) {
+		StringBuffer sql = new StringBuffer();
+    	sql.append("select count(t1.id) from ecs_exam_student t1 where t1.normal_exam_times = ( "+
+    				" select t2.exam_times from ecs_exam t2 where t2.id = t1.exam_id "+
+    			")");
+    	sql.append(" and t1.exam_id="+examCriteria.getExamId());
+    	sql.append(getSqlSpecification(examCriteria));
+		return this.jdbcTemplate.queryForObject(sql.toString(), Integer.class);
+	}
+
+	private String getSqlSpecification(CommonExamStudent examCriteria){
+		StringBuffer sql = new StringBuffer(""); 
+		if(!StringUtils.isEmpty(examCriteria.getOrgId())){
+			sql.append(" and t1.org_id = "+examCriteria.getOrgId());
+	    }
+		if(!StringUtils.isEmpty(examCriteria.getName())){
+			sql.append(" and t1.name LIKE '%"+examCriteria.getName()+"%'");
+	    }
+		if(!StringUtils.isEmpty(examCriteria.getStudentCode())){
+			sql.append(" and t1.student_code LIKE '%"+examCriteria.getStudentCode()+"%'");
+	    }
+		if(!StringUtils.isEmpty(examCriteria.getCourseCode())){
+			sql.append(" and t1.course_code = "+examCriteria.getCourseCode());
+		}
+		if(!StringUtils.isEmpty(examCriteria.getCourseLevel())){
+			sql.append(" and t1.course_level = "+examCriteria.getCourseLevel());
+		}
+		if(!StringUtils.isEmpty(examCriteria.getIdentityNumber())){
+			sql.append(" and t1.identity_number = "+examCriteria.getIdentityNumber());
+		}
+		sql.append(" order by t1.id ");
+		return sql.toString();
+	}
+	
 	/**
 	 * 生成查询条件
 	 * @param examCriteria
@@ -612,4 +701,20 @@ public class ExamStudentService {
 			}
 		});
 	}
+	/**
+	 * 设置考生重考信息
+	 * @param examStudentId
+	 */
+	public void setExamStudentIsReexamine(CommonExamStudent commonExamStudent){
+		if(commonExamStudent.getId() == null){
+			return;
+		}
+		ExamStudent examStudent = examStudentRepo.findOne(commonExamStudent.getId());
+		if(examStudent!=null){
+			examStudent.setIsReexamine(true);
+			examStudent.setReexamineType(commonExamStudent.getReexamineType());
+			examStudent.setReexamineDetail(commonExamStudent.getReexamineDetail());
+			examStudentRepo.save(examStudent);
+		}
+	}
 }

+ 50 - 2
exam-work-domain/src/main/java/cn/com/qmth/examcloud/service/examwork/entity/ExamStudent.java

@@ -113,10 +113,28 @@ public class ExamStudent implements Serializable {
 	 * 学生电话
 	 */
 	private String phone;
-
+	/**
+	 * 正常考试次数  不含重考
+	 */
+	private Integer normalExamTimes;
+	/**
+	 * 是否为重考
+	 */
+	private Boolean isReexamine;
+	/**
+	 * 重考原因类型
+	 */
+	private String reexamineType;
+	/**
+	 * 重考原因详情
+	 */
+	private String reexamineDetail;
+	
 	public static long getSerialVersionUID() {
 		return serialVersionUID;
 	}
+	
+	public ExamStudent() {}
 
 	public Long getId() {
 		return id;
@@ -331,6 +349,36 @@ public class ExamStudent implements Serializable {
 		this.specialtyCode = specialtyCode;
 	}
 
-	public ExamStudent() {
+	public Integer getNormalExamTimes() {
+		return normalExamTimes;
+	}
+
+	public void setNormalExamTimes(Integer normalExamTimes) {
+		this.normalExamTimes = normalExamTimes;
 	}
+
+	public Boolean getIsReexamine() {
+		return isReexamine;
+	}
+
+	public void setIsReexamine(Boolean isReexamine) {
+		this.isReexamine = isReexamine;
+	}
+
+	public String getReexamineType() {
+		return reexamineType;
+	}
+
+	public void setReexamineType(String reexamineType) {
+		this.reexamineType = reexamineType;
+	}
+
+	public String getReexamineDetail() {
+		return reexamineDetail;
+	}
+
+	public void setReexamineDetail(String reexamineDetail) {
+		this.reexamineDetail = reexamineDetail;
+	}
+	
 }