wangwei 6 anos atrás
pai
commit
e6c1160efd

+ 49 - 0
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/ExamController.java

@@ -57,6 +57,7 @@ import cn.com.qmth.examcloud.core.examwork.api.controller.bean.ExamOrgSettingsDo
 import cn.com.qmth.examcloud.core.examwork.base.enums.ExamProperty;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamCourseGroupRelationRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamCourseGroupSettingsRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamCourseRelationRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgPropertyRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgSettingsRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamPropertyRepo;
@@ -64,6 +65,7 @@ import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamStudentRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamCourseGroupRelationEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamCourseGroupSettingsEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamCourseRelationEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgPropertyEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgSettingsEntity;
@@ -123,6 +125,53 @@ public class ExamController extends ControllerSupport {
 	@Autowired
 	StudentCloudService studentCloudService;
 
+	@Autowired
+	ExamCourseRelationRepo examCourseRelationRepo;
+
+	@ApiOperation(value = "查询考试的课程集合")
+	@GetMapping("queryExamCourseList")
+	public List<ExamCourseRelationEntity> getExamCourseList(
+			@RequestParam(required = true) Long examId, @RequestParam(required = false) String name,
+			@RequestParam(required = false) String level) {
+
+		ExamEntity one = examRepo.findOne(examId);
+		if (null == one) {
+			throw new StatusException("E-001250", "examId is wrong");
+		}
+		validateRootOrgIsolation(one.getRootOrgId());
+
+		Specification<ExamCourseRelationEntity> specification = (root, query, cb) -> {
+			List<Predicate> predicates = new ArrayList<>();
+
+			Predicate pr1 = cb.like(root.get("name"), toSqlSearchPattern(name));
+			Predicate pr2 = cb.like(root.get("code"), toSqlSearchPattern(name));
+
+			predicates.add(cb.or(pr1, pr2));
+
+			if (StringUtils.isNotBlank(level)) {
+				predicates.add(cb.equal(root.get("level"), toSqlSearchPattern(level)));
+			}
+
+			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+
+		PageRequest pageRequest = new PageRequest(0, 50, new Sort(Direction.DESC, "updateTime"));
+
+		Page<ExamCourseRelationEntity> page = examCourseRelationRepo.findAll(specification,
+				pageRequest);
+
+		Iterator<ExamCourseRelationEntity> iterator = page.iterator();
+		List<ExamCourseRelationEntity> list = Lists.newArrayList();
+
+		while (iterator.hasNext()) {
+			ExamCourseRelationEntity next = iterator.next();
+			list.add(next);
+		}
+
+		return list;
+
+	}
+
 	/**
 	 * 方法注释
 	 *

+ 0 - 45
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/ExamStudentController.java

@@ -6,8 +6,6 @@ import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
 import javax.persistence.criteria.Predicate;
 import javax.servlet.http.HttpServletResponse;
 
@@ -50,7 +48,6 @@ import cn.com.qmth.examcloud.core.basic.api.response.GetCourseResp;
 import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
 import cn.com.qmth.examcloud.core.basic.api.response.GetStudentResp;
 import cn.com.qmth.examcloud.core.basic.api.response.SaveStudentResp;
-import cn.com.qmth.examcloud.core.examwork.api.controller.bean.CourseDomain;
 import cn.com.qmth.examcloud.core.examwork.api.controller.bean.ExamStudentDomain;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamStudentRepo;
@@ -71,9 +68,6 @@ import io.swagger.annotations.ApiOperation;
 @RequestMapping("${$rmp.ctr.examwork}/exam_student")
 public class ExamStudentController extends ControllerSupport {
 
-	@Autowired
-	private EntityManager em;
-
 	@Autowired
 	ExamStudentRepo examStudentRepo;
 
@@ -95,45 +89,6 @@ public class ExamStudentController extends ControllerSupport {
 	@Autowired
 	ExamRecordCloudService examRecordCloudService;
 
-	@ApiOperation(value = "查询考试的课程集合")
-	@GetMapping("queryExamCourseList")
-	public List<CourseDomain> getExamCourseList(@RequestParam(required = true) Long examId) {
-
-		User accessUser = getAccessUser();
-		Long rootOrgId = accessUser.getRootOrgId();
-
-		StringBuilder sql = new StringBuilder(
-				"SELECT t.exam_id from ec_e_exam_student t where t.exam_id=?");
-
-		sql.append(" group by t.exam_id,t.course_id");
-
-		Query query = em.createNativeQuery(sql.toString());
-		query.setParameter(1, examId);
-
-		List<?> resultList = query.getResultList();
-
-		List<CourseDomain> list = Lists.newArrayList();
-		for (Object cur : resultList) {
-			GetCourseReq req = new GetCourseReq();
-			req.setId((Long) cur);
-			req.setRootOrgId(rootOrgId);
-			GetCourseResp getCourseResp = courseCloudService.getCourse(req);
-			CourseBean courseBean = getCourseResp.getCourseBean();
-
-			CourseDomain d = new CourseDomain();
-			d.setCode(courseBean.getCode());
-			d.setLevel(courseBean.getLevel());
-			d.setName(courseBean.getName());
-			d.setId(courseBean.getId());
-
-			list.add(d);
-		}
-
-		em.close();
-
-		return list;
-	}
-
 	/**
 	 * 方法注释
 	 *

+ 23 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/ExamCourseRelationRepo.java

@@ -0,0 +1,23 @@
+package cn.com.qmth.examcloud.core.examwork.dao;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.repository.query.QueryByExampleExecutor;
+
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamCourseRelationEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamCourseRelationPK;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年9月20日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public interface ExamCourseRelationRepo
+		extends
+			JpaRepository<ExamCourseRelationEntity, ExamCourseRelationPK>,
+			QueryByExampleExecutor<ExamCourseRelationEntity>,
+			JpaSpecificationExecutor<ExamCourseRelationEntity> {
+
+}

+ 73 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/entity/ExamCourseRelationEntity.java

@@ -0,0 +1,73 @@
+package cn.com.qmth.examcloud.core.examwork.dao.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.Table;
+
+import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
+
+@Entity
+@Table(name = "EC_E_EXAM_COURSE_RELATION")
+@IdClass(ExamCourseRelationPK.class)
+public class ExamCourseRelationEntity extends JpaEntity {
+
+	private static final long serialVersionUID = 757531976286006550L;
+
+	@Id
+	private Long examId;
+
+	@Id
+	private Long courseId;
+
+	@Column(nullable = false)
+	private String courseName;
+
+	@Column(nullable = false)
+	private String courseCode;
+
+	@Column(nullable = false)
+	private String courseLevel;
+
+	public Long getExamId() {
+		return examId;
+	}
+
+	public void setExamId(Long examId) {
+		this.examId = examId;
+	}
+
+	public Long getCourseId() {
+		return courseId;
+	}
+
+	public void setCourseId(Long courseId) {
+		this.courseId = courseId;
+	}
+
+	public String getCourseName() {
+		return courseName;
+	}
+
+	public void setCourseName(String courseName) {
+		this.courseName = courseName;
+	}
+
+	public String getCourseCode() {
+		return courseCode;
+	}
+
+	public void setCourseCode(String courseCode) {
+		this.courseCode = courseCode;
+	}
+
+	public String getCourseLevel() {
+		return courseLevel;
+	}
+
+	public void setCourseLevel(String courseLevel) {
+		this.courseLevel = courseLevel;
+	}
+
+}

+ 29 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/entity/ExamCourseRelationPK.java

@@ -0,0 +1,29 @@
+package cn.com.qmth.examcloud.core.examwork.dao.entity;
+
+import java.io.Serializable;
+
+public class ExamCourseRelationPK implements Serializable {
+
+	private static final long serialVersionUID = -9214147168423303504L;
+
+	private Long examId;
+
+	private Long courseId;
+
+	public Long getExamId() {
+		return examId;
+	}
+
+	public void setExamId(Long examId) {
+		this.examId = examId;
+	}
+
+	public Long getCourseId() {
+		return courseId;
+	}
+
+	public void setCourseId(Long courseId) {
+		this.courseId = courseId;
+	}
+
+}

+ 11 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/entity/ExamStudentEntity.java

@@ -70,6 +70,9 @@ public class ExamStudentEntity extends JpaEntity {
 	@Column(nullable = false)
 	private Long courseId;
 
+	@Column(nullable = false)
+	private String courseName;
+
 	/**
 	 * 课程ID
 	 */
@@ -259,4 +262,12 @@ public class ExamStudentEntity extends JpaEntity {
 		this.courseCode = courseCode;
 	}
 
+	public String getCourseName() {
+		return courseName;
+	}
+
+	public void setCourseName(String courseName) {
+		this.courseName = courseName;
+	}
+
 }

+ 13 - 0
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/ExamStudentServiceImpl.java

@@ -22,9 +22,11 @@ import cn.com.qmth.examcloud.core.basic.api.request.SaveCourseReq;
 import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
 import cn.com.qmth.examcloud.core.basic.api.response.GetStudentResp;
 import cn.com.qmth.examcloud.core.basic.api.response.SaveCourseResp;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamCourseRelationRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgSettingsRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamStudentRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamCourseRelationEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentEntity;
 import cn.com.qmth.examcloud.core.examwork.service.ExamStudentService;
@@ -59,6 +61,9 @@ public class ExamStudentServiceImpl implements ExamStudentService {
 	@Autowired
 	CourseCloudService courseCloudService;
 
+	@Autowired
+	ExamCourseRelationRepo examCourseRelationRepo;
+
 	/**
 	 * 方法注释
 	 *
@@ -177,6 +182,7 @@ public class ExamStudentServiceImpl implements ExamStudentService {
 		examStudent.setRootOrgId(rootOrgId);
 
 		examStudent.setCourseId(courseBean.getId());
+		examStudent.setCourseName(courseBean.getName());
 		examStudent.setCourseCode(courseBean.getCode());
 		examStudent.setCourseLevel(courseBean.getLevel());
 
@@ -193,6 +199,13 @@ public class ExamStudentServiceImpl implements ExamStudentService {
 
 		ExamStudentEntity saved = examStudentRepo.saveAndFlush(examStudent);
 
+		ExamCourseRelationEntity relation = new ExamCourseRelationEntity();
+		relation.setExamId(saved.getId());
+		relation.setCourseId(saved.getCourseId());
+		relation.setCourseLevel(saved.getCourseLevel());
+		relation.setCourseName(saved.getCourseName());
+		examCourseRelationRepo.save(relation);
+
 		ExamStudentInfo ret = new ExamStudentInfo();
 		ret.setId(saved.getId());
 		ret.setCourseCode(courseBean.getCode());