Browse Source

Merge branch 'master' of https://git.oschina.net/songyue123456/ExamCloud-service-exam-work

# Conflicts:
#	exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/service/ExamStudentService.java
chenken 7 years ago
parent
commit
41df47669a

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

@@ -1,7 +1,5 @@
 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;
@@ -11,8 +9,12 @@ import java.util.Map;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import javax.servlet.http.HttpServletRequest;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.domain.Sort.Direction;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.DeleteMapping;
@@ -25,12 +27,12 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
+import cn.com.qmth.examcloud.common.util.ErrorMsg;
 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;
 
-import javax.servlet.http.HttpServletRequest;
-
 /**
  * 考试服务API
  * Created by songyue on 17/1/13.
@@ -57,7 +59,7 @@ public class ExamApi {
         }else{
             return new ResponseEntity(HttpStatus.NOT_FOUND);
         }
-    	return new ResponseEntity(examService.getAllExam(examCriteria,new PageRequest(curPage,pageSize)), HttpStatus.OK);
+    	return new ResponseEntity(examService.getAllExam(examCriteria,new PageRequest(curPage,pageSize, new Sort(Direction.DESC,"id"))), HttpStatus.OK);
     }
 
     @ApiOperation(value="查询所有考试批次(包含有效)",notes = "不分页带查询")

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

@@ -28,6 +28,8 @@ import javax.servlet.http.HttpServletResponse;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.domain.Sort.Direction;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -109,7 +111,7 @@ public class ExamStudentApi {
             return new ResponseEntity(HttpStatus.NOT_FOUND);
         }
         return new ResponseEntity(examStudentService.getAllExamStudent(examStudent,
-                new PageRequest(curPage, pageSize)), HttpStatus.OK);
+                new PageRequest(curPage, pageSize,new Sort(Direction.DESC,"id"))), HttpStatus.OK);
     }
 
     @ApiOperation(value = "查询所有考试学生带条件", notes = "带条件不分页")
@@ -334,7 +336,7 @@ public class ExamStudentApi {
     }
     @ApiOperation(value = "学习中心考试进度信息", notes = "学习中心考试进度信息")
     @GetMapping("/findOrgExamInfos")
-    public ResponseEntity<Object> findOrgExamInfos(@RequestParam String examId,@RequestParam String orgCode){
+    public ResponseEntity<Object> findOrgExamInfos(String examId,String orgCode){
     	try{
     		List<OrgExamInfo> orgExamInfos = examStudentService.findOrgExamInfos(examId, orgCode);
     		return new ResponseEntity<Object>(orgExamInfos,HttpStatus.OK);

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

@@ -10,6 +10,8 @@ import org.springframework.data.domain.Example;
 import org.springframework.data.domain.ExampleMatcher;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.domain.Sort.Direction;
 import org.springframework.stereotype.Service;
 
 import cn.com.qmth.examcloud.service.examwork.dao.ExamRepo;
@@ -50,7 +52,7 @@ public class ExamService {
     	ExampleMatcher exampleMatcher = ExampleMatcher.matching()
                 .withMatcher("name",contains());
         Example<Exam> examExample = Example.of(examCriteria,exampleMatcher);
-        return examRepo.findAll(examExample);
+        return examRepo.findAll(examExample, new Sort(Direction.DESC,"id"));
     }
 
     /**

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

@@ -16,6 +16,8 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.domain.Sort.Direction;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.RowMapper;
@@ -40,6 +42,7 @@ import cn.com.qmth.examcloud.service.examwork.entity.Exam;
 import cn.com.qmth.examcloud.service.examwork.entity.ExamStudent;
 import cn.com.qmth.examcloud.service.examwork.service.rpc.CourseService;
 import cn.com.qmth.examcloud.service.examwork.service.rpc.OrgService;
+import cn.com.qmth.examcloud.service.examwork.service.rpc.SpecialtyService;
 import cn.com.qmth.examcloud.service.examwork.service.rpc.StudentService;
 
 /**
@@ -72,6 +75,10 @@ public class ExamStudentService {
     @Autowired
 	private JdbcTemplate jdbcTemplate;
 
+	@Autowired
+	SpecialtyService specialtyService;
+
+
 //    @Value("${app.em.photo.path}")
 //    private String PHOTO_PATH ;
 //    @Value("${app.em.facepp.key}")
@@ -95,7 +102,7 @@ public class ExamStudentService {
 //        Example<ExamStudent> examExamStudentple = Example.of(examStudentSearch, exampleMatcher);
 //		Page<ExamStudent> examStudents = examStudentRepo.findAll(examExamStudentple,pageable);
 //        return examStudents;
-    	Specification<ExamStudent> specification = getSpecification(examCriteria);
+    	Specification<ExamStudent> specification = getPageSpecification(examCriteria);
 		Page<ExamStudent> examStudents = examStudentRepo.findAll(specification,pageable);
         return examStudents;
     }
@@ -108,7 +115,7 @@ public class ExamStudentService {
      */
     public  List<ExamStudent> getAllExamStudent(ExamStudentDTO examCriteria){
     	Specification<ExamStudent> specification = getSpecification(examCriteria);
-        return examStudentRepo.findAll(specification);
+        return examStudentRepo.findAll(specification,new Sort(Direction.DESC,"id"));
     }
 
     /**
@@ -256,6 +263,16 @@ public class ExamStudentService {
 		if(StringUtils.isEmpty(dto.getOrgCode())){
 			return new ExcelError("学习中心代码不能为空");
 		}
+//		if(StringUtils.isEmpty(dto.getSpecialtyCode())){
+//			return new ExcelError("专业代码不能为空");
+//		}
+//
+//		Specialty specialty = specialtyService.findByOrgIdAndCode(dto.getOrgId(),dto.getSpecialtyCode());
+//		if(specialty == null || !specialty.getEnable()){
+//			return new ExcelError("专业代码不存在/被禁用");
+//		}
+//		dto.setSpecialtyName(specialty.getName());
+
 		Course course = courseService.findByOrgIdAndCode(dto.getRootOrgId(), dto.getCourseCode());
 		if(course == null || !course.getEnable()){
 			return new ExcelError("课程不存在/被禁用");
@@ -319,7 +336,6 @@ public class ExamStudentService {
 	private Specification<ExamStudent> getSpecification(ExamStudentDTO examCriteria) {
 		Specification<ExamStudent> specification = (root, query, cb) -> {
 		    List<Predicate> predicates = new ArrayList<>();
-//			predicates.add(cb.equal(root.get("exam").get("enable"),true));
 			if(!StringUtils.isEmpty(examCriteria.getStudentId())){
 				predicates.add(cb.equal(root.get("studentId"),examCriteria.getStudentId()));
 			}
@@ -353,7 +369,6 @@ public class ExamStudentService {
 		    if(!StringUtils.isEmpty(examCriteria.getFinished())){
 		    	predicates.add(cb.equal(root.get("finished"),examCriteria.getFinished()));
 		    }
-
 			if(!StringUtils.isEmpty(examCriteria.getExamSite())){
 				predicates.add(cb.like(root.get("examSite"),"%"+examCriteria.getExamSite()+"%"));
 			}
@@ -389,6 +404,83 @@ public class ExamStudentService {
 		return specification;
 	}
 
+	/**
+	 * 生成查询条件
+	 * @param examCriteria
+	 * @return
+	 */
+	private Specification<ExamStudent> getPageSpecification(ExamStudentDTO examCriteria) {
+		Specification<ExamStudent> specification = (root, query, cb) -> {
+			List<Predicate> predicates = new ArrayList<>();
+			if(!StringUtils.isEmpty(examCriteria.getStudentId())){
+				predicates.add(cb.equal(root.get("studentId"),examCriteria.getStudentId()));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getRootOrgId())){
+				predicates.add(cb.equal(root.get("rootOrgId"),examCriteria.getRootOrgId()));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getOrgId())){
+				predicates.add(cb.equal(root.get("orgId"),examCriteria.getOrgId()));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getOrgName())){
+				predicates.add(cb.like(root.get("orgName"),"%"+examCriteria.getOrgName()+"%"));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getExamId())){
+				predicates.add(cb.equal(root.get("exam").get("id"),examCriteria.getExamId()));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getName())){
+				predicates.add(cb.like(root.get("name"),"%"+examCriteria.getName()+"%"));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getStudentCode())){
+				predicates.add(cb.like(root.get("studentCode"),"%"+examCriteria.getStudentCode()+"%"));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getCourseCode())){
+				predicates.add(cb.equal(root.get("courseCode"),examCriteria.getCourseCode()));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getCourseLevel())){
+				predicates.add(cb.equal(root.get("courseLevel"),examCriteria.getCourseLevel()));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getCourseName())){
+				predicates.add(cb.like(root.get("courseName"),"%"+examCriteria.getCourseName()+"%"));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getFinished())){
+				predicates.add(cb.equal(root.get("finished"),examCriteria.getFinished()));
+			}
+
+			if(!StringUtils.isEmpty(examCriteria.getExamSite())){
+				predicates.add(cb.like(root.get("examSite"),"%"+examCriteria.getExamSite()+"%"));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getIdentityNumber())){
+				predicates.add(cb.like(root.get("identityNumber"),"%"+examCriteria.getIdentityNumber()+"%"));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getSpecialtyName())){
+				predicates.add(cb.like(root.get("specialtyName"),"%"+examCriteria.getSpecialtyName()+"%"));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getPaperType())){
+				predicates.add(cb.equal(root.get("paperType"),examCriteria.getPaperType()));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getDegree())){
+				predicates.add(cb.equal(root.get("degree"),examCriteria.getDegree()));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getRepair())){
+				predicates.add(cb.equal(root.get("repair"),examCriteria.getRepair()));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getGraduated())){
+				predicates.add(cb.equal(root.get("graduated"),examCriteria.getGraduated()));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getGrade())){
+				predicates.add(cb.like(root.get("grade"),"%"+examCriteria.getGrade()+"%"));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getExamNumber())){
+				predicates.add(cb.like(root.get("examNumber"),"%"+examCriteria.getExamNumber()+"%"));
+			}
+			if(!StringUtils.isEmpty(examCriteria.getInfoCollector())){
+				predicates.add(cb.like(root.get("infoCollector"),"%"+examCriteria.getInfoCollector()+"%"));
+			}
+			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+		return specification;
+	}
+
 	/**
 	 * 复制考生
 	 * @param sourceExamId
@@ -469,9 +561,13 @@ public class ExamStudentService {
 				orgExamInfo.setOrgName(rs.getString("orgname"));
 				orgExamInfo.setAllNum(rs.getInt("allNum"));
 				orgExamInfo.setCompletedNum(rs.getInt("completedNum"));
-				DecimalFormat df = new DecimalFormat("#.00");
-				double proportion = orgExamInfo.getCompletedNum()/orgExamInfo.getAllNum();
-				orgExamInfo.setProportion(df.format(proportion));
+				if(orgExamInfo.getCompletedNum()==0){
+					orgExamInfo.setProportion("0");
+				}else{
+					DecimalFormat df = new DecimalFormat("#.00");
+					double proportion = (double)orgExamInfo.getCompletedNum()/orgExamInfo.getAllNum();
+					orgExamInfo.setProportion(df.format(proportion*100));
+				}
 				return orgExamInfo;
 			}
 		});

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

@@ -0,0 +1,29 @@
+package cn.com.qmth.examcloud.service.examwork.service.rpc;
+
+import cn.com.qmth.examcloud.common.dto.core.Course;
+import cn.com.qmth.examcloud.common.dto.core.Specialty;
+import cn.com.qmth.examcloud.common.util.GsonUtil;
+import cn.com.qmth.examcloud.service.examwork.service.rpc.client.CourseClient;
+import cn.com.qmth.examcloud.service.examwork.service.rpc.client.SpecialtyClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 专业服务类
+ * Created by songyue on 17/1/14.
+ */
+@Service
+public class SpecialtyService {
+
+	@Autowired
+	SpecialtyClient specialtyClient;
+
+	public Specialty findByOrgIdAndCode(Long orgId, String code) {
+		String json = specialtyClient.findByOrgIdAndCode(orgId,code);
+		Specialty domain = GsonUtil.getInstanceByJson(json, Specialty.class);
+		return domain;
+	}
+
+}

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

@@ -0,0 +1,19 @@
+package cn.com.qmth.examcloud.service.examwork.service.rpc.client;
+
+import org.springframework.cloud.netflix.feign.FeignClient;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+
+
+/**
+ * Created by songyue on 17/7/20.
+ */
+@FeignClient(value = "ExamCloud-service-core")
+public interface SpecialtyClient {
+
+	@RequestMapping(method = RequestMethod.GET, value = "${app.api.core}/specialty")
+	String findByOrgIdAndCode(@RequestParam("orgId") Long orgId, @RequestParam("code") String code);
+
+}

+ 4 - 0
exam-work-domain/src/main/java/cn/com/qmth/examcloud/service/examwork/assembler/ExamStudentAssembler.java

@@ -18,6 +18,7 @@ public class ExamStudentAssembler {
 			dto.setDegree(examStudent.getDegree());
 			dto.setExam(examStudent.getExam());
 			dto.setExamNumber(examStudent.getExamNumber());
+			dto.setExamSite(examStudent.getExamSite());
 			dto.setFinished(examStudent.getFinished());
 			dto.setGrade(examStudent.getGrade());
 			dto.setGraduated(examStudent.getGraduated());
@@ -30,6 +31,7 @@ public class ExamStudentAssembler {
 			dto.setPaperType(examStudent.getPaperType());
 			dto.setRepair(examStudent.getRepair());
 			dto.setRootOrgId(examStudent.getRootOrgId());
+			dto.setSpecialtyCode(examStudent.getSpecialtyCode());
 			dto.setSpecialtyName(examStudent.getSpecialtyName());
 			dto.setStudentCode(examStudent.getStudentCode());
 		}
@@ -46,6 +48,7 @@ public class ExamStudentAssembler {
 			domain.setDegree(dto.getDegree());
 			domain.setExam(dto.getExam());
 			domain.setExamNumber(dto.getExamNumber());
+			domain.setExamSite(dto.getExamSite());
 			domain.setFinished(dto.getFinished());
 			domain.setGrade(dto.getGrade());
 			domain.setGraduated(dto.getGraduated());
@@ -59,6 +62,7 @@ public class ExamStudentAssembler {
 			domain.setRemark(dto.getRemark());
 			domain.setRepair(dto.getRepair());
 			domain.setRootOrgId(dto.getRootOrgId());
+			domain.setSpecialtyCode(dto.getSpecialtyCode());
 			domain.setSpecialtyName(dto.getSpecialtyName());
 			domain.setStudentCode(dto.getStudentCode());
 			domain.setInfoCollector(dto.getInfoCollector());

+ 18 - 5
exam-work-domain/src/main/java/cn/com/qmth/examcloud/service/examwork/dto/ExamStudentDTO.java

@@ -51,6 +51,11 @@ public class ExamStudentDTO {
 	 * 学位
 	 */
 	private Boolean degree;
+
+
+
+	private String specialtyCode;
+
 	@ExcelProperty(index = 6,name = "专业")
 	private String specialtyName;
 	
@@ -89,7 +94,7 @@ public class ExamStudentDTO {
 	/**
 	 * 年级
 	 */
-	@ExcelProperty(index = 10,name = "年")
+	@ExcelProperty(index = 10,name = "年")
 	private String grade;
 	
 	public Long getId() {
@@ -156,12 +161,12 @@ public class ExamStudentDTO {
 		this.courseName = courseName;
 	}
 
-	public String getSpecialtyName() {
-		return specialtyName;
+	public String getSpecialtyCode() {
+		return specialtyCode;
 	}
 
-	public void setSpecialtyName(String specialtyName) {
-		this.specialtyName = specialtyName;
+	public void setSpecialtyCode(String specialtyCode) {
+		this.specialtyCode = specialtyCode;
 	}
 
 	public String getRemark() {
@@ -300,6 +305,14 @@ public class ExamStudentDTO {
 		this.phone = phone;
 	}
 
+	public String getSpecialtyName() {
+		return specialtyName;
+	}
+
+	public void setSpecialtyName(String specialtyName) {
+		this.specialtyName = specialtyName;
+	}
+
 	public ExamStudentDTO() {
 	}
 }

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

@@ -37,21 +37,32 @@ public class ExamStudent implements Serializable {
 	 * 学习中心code
 	 */
     private String orgCode;
-
+    /**
+     * 学习中心名称
+     */
 	private String orgName;
-
+	/**
+	 * 学号
+	 */
 	private String studentCode;
-
+	/**
+	 * 身份证号
+	 */
 	private String identityNumber;
 
 	private String examNumber;
-
+	/**
+	 * 课程code
+	 */
 	private String courseCode;
-
+	/**
+	 * 课程名称
+	 */
 	private String courseName;
-	
+	/**
+	 * 课程等级
+	 */
 	private String courseLevel;
-	
 	/**
 	 * 试卷类型
 	 */
@@ -60,14 +71,18 @@ public class ExamStudent implements Serializable {
 	 * 学位
 	 */
 	private Boolean degree;
-
+	/**
+	 * 专业名称
+	 */
 	private String specialtyName;
-	
+	/**
+	 * 专业code
+	 */
+	private String specialtyCode;
 	/**
 	 * 是否重修
 	 */
 	private Boolean repair;
-	
 	/**
 	 * 年级
 	 */
@@ -78,27 +93,22 @@ public class ExamStudent implements Serializable {
 	private Boolean graduated;
 
 	private String remark;
-	
 	/**
 	 * 是否缺考 
 	 */
 	private Boolean finished;
-	
 	/**
 	 * 学生用户id
 	 */
     private Long studentId;
-
 	/**
 	 * 考点
 	 */
 	private String examSite;
-	
 	/**
 	 * 信息采集人
 	 */
 	private String infoCollector;
-	
 	/**
 	 * 学生电话
 	 */
@@ -313,6 +323,14 @@ public class ExamStudent implements Serializable {
 		this.phone = phone;
 	}
 
+	public String getSpecialtyCode() {
+		return specialtyCode;
+	}
+
+	public void setSpecialtyCode(String specialtyCode) {
+		this.specialtyCode = specialtyCode;
+	}
+
 	public ExamStudent() {
 	}
 }

+ 2 - 1
exam-work-domain/src/main/java/cn/com/qmth/examcloud/service/examwork/enums/PracticeType.java

@@ -6,7 +6,8 @@ package cn.com.qmth.examcloud.service.examwork.enums;
 public enum PracticeType {
 
     AFTER_PRACTICE("结束统一显示答案"),
-    IN_PRACTICE("边答边显示答案");
+    IN_PRACTICE("边答边显示答案"),
+    NO_ANSWER("不显示答案");
 
     private String name;