wangwei 7 éve
szülő
commit
5d8b9f0781

+ 106 - 65
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/service/examwork/api/ExamApi.java

@@ -36,11 +36,14 @@ import cn.com.qmth.examcloud.commons.base.util.ErrorMsg;
 import cn.com.qmth.examcloud.commons.web.security.entity.AccessUser;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.service.examwork.dao.ExamRepo;
-import cn.com.qmth.examcloud.service.examwork.dao.ExamSetting4CourseRepo;
+import cn.com.qmth.examcloud.service.examwork.api.bean.CourseGroupBean;
+import cn.com.qmth.examcloud.service.examwork.dao.CourseGroupRelationRepo;
+import cn.com.qmth.examcloud.service.examwork.dao.CourseGroupRepo;
 import cn.com.qmth.examcloud.service.examwork.dao.ExamSetting4OrgRepo;
 import cn.com.qmth.examcloud.service.examwork.dao.ExamStudentRepo;
 import cn.com.qmth.examcloud.service.examwork.entity.Exam;
-import cn.com.qmth.examcloud.service.examwork.entity.ExamSetting4Course;
+import cn.com.qmth.examcloud.service.examwork.entity.CourseGroup;
+import cn.com.qmth.examcloud.service.examwork.entity.CourseGroupRelation;
 import cn.com.qmth.examcloud.service.examwork.entity.ExamSetting4Org;
 import cn.com.qmth.examcloud.service.examwork.entity.ExamStudent;
 import cn.com.qmth.examcloud.service.examwork.enums.ExamType;
@@ -68,10 +71,13 @@ public class ExamApi extends ControllerSupport {
 	ExamStudentService examStudentService;
 
 	@Autowired
-	ExamSetting4CourseRepo examSetting4CourseRepo;
+	CourseGroupRepo courseGroupRepo;
 
 	@Autowired
 	ExamSetting4OrgRepo examSetting4OrgRepo;
+	
+	@Autowired
+	CourseGroupRelationRepo courseGroupRelationRepo;
 
 	@Autowired
 	private JdbcTemplate jdbcTemplate;
@@ -268,89 +274,124 @@ public class ExamApi extends ControllerSupport {
 		return new ResponseEntity(HttpStatus.OK);
 	}
 
-	@ApiOperation(value = "查询特殊考试设置", notes = "查询特殊考试设置")
-	@GetMapping("/exam/querySpecificExamList/{examId}/{curPage}/{pageSize}")
-	public ResponseEntity<?> querySpecificExamList(@PathVariable Long examId,
+	@ApiOperation(value = "查询课程组集合", notes = "")
+	@GetMapping("/exam/queryCourseGroupList/{examId}/{curPage}/{pageSize}")
+	public List<CourseGroupBean> queryCourseGroupList(@PathVariable Long examId,
 			@PathVariable Integer curPage, @PathVariable Integer pageSize) {
 
-		List<ExamSetting4Course> groupList = examSetting4CourseRepo.findByExamId(examId,
-				(curPage - 1) * pageSize, pageSize);
+		Pageable pageable = new PageRequest(curPage-1, pageSize, Sort.Direction.DESC, "updateTime");
+		List<CourseGroup> groupList = courseGroupRepo.findAllByExamId(examId, pageable);
+
+		List<CourseGroupBean> ret = Lists.newArrayList();
+
+		for (CourseGroup curCourseGroup : groupList) {
+			CourseGroupBean bean = new CourseGroupBean();
+			bean.setBeginTime(curCourseGroup.getBeginTime());
+			bean.setCreationTime(curCourseGroup.getCreationTime());
+			bean.setDescription(curCourseGroup.getDescription());
+			bean.setEndTime(curCourseGroup.getEndTime());
+			bean.setExamId(curCourseGroup.getExamId());
+			bean.setId(curCourseGroup.getId());
+			bean.setName(curCourseGroup.getName());
+			bean.setUpdateTime(curCourseGroup.getUpdateTime());
 
-		for (ExamSetting4Course specificExam : groupList) {
 			List<Long> courseIdList = Lists.newArrayList();
-			specificExam.setCourseIdList(courseIdList);
-
-			List<Map<String, Object>> queryList = jdbcTemplate.queryForList(
-					"select t.course_id from ecs_e_exam_course_relation t where t.specific_exam_id=?",
-					specificExam.getId());
-			if (CollectionUtils.isNotEmpty(queryList)) {
-				for (Map<String, Object> map : queryList) {
-					Long courseId = Long.valueOf(map.get("COURSE_ID").toString());
-					courseIdList.add(courseId);
-				}
+			bean.setCourseIdList(courseIdList);
+
+			List<CourseGroupRelation> relationList = courseGroupRelationRepo
+					.findAllByGroupId(bean.getId());
+
+			for (CourseGroupRelation cur : relationList) {
+				courseIdList.add(cur.getCourseId());
 			}
+			
+			ret.add(bean);
 		}
 
-		return new ResponseEntity<List<ExamSetting4Course>>(groupList, HttpStatus.OK);
+		return ret;
 	}
 
-	@ApiOperation(value = "通过课程ID查询特殊考试设置", notes = "通过课程ID查询特殊考试设置")
-	@GetMapping("/exam/querySpecificExamByCourseId/{courseId}")
-	public ResponseEntity<?> querySpecificExamByCourseId(@PathVariable Long courseId) {
-		List<ExamSetting4Course> groupList = examSetting4CourseRepo
-				.queryCourseGroupsByCourseId(courseId);
+	@ApiOperation(value = "通过课程ID查询课程组集合", notes = "")
+	@GetMapping("/exam/queryCourseGroupList/{examId}/{courseId}")
+	public List<CourseGroupBean> queryCourseGroupList(@PathVariable Long examId,
+			@PathVariable Long courseId) {
+
+		List<CourseGroupRelation> relationList = courseGroupRelationRepo
+				.findAllByCourseIdAndExamId(courseId, examId);
+
+		List<Long> groupIdList = Lists.newArrayList();
+		for (CourseGroupRelation cur : relationList) {
+			Long groupId = cur.getGroupId();
+			groupIdList.add(groupId);
+		}
+
+		List<CourseGroup> groupList = courseGroupRepo
+				.findAllByIdInOrderByUpdateTimeDesc(groupIdList);
+
+		List<CourseGroupBean> ret = Lists.newArrayList();
+
+		for (CourseGroup curCourseGroup : groupList) {
+			CourseGroupBean bean = new CourseGroupBean();
+			bean.setBeginTime(curCourseGroup.getBeginTime());
+			bean.setCreationTime(curCourseGroup.getCreationTime());
+			bean.setDescription(curCourseGroup.getDescription());
+			bean.setEndTime(curCourseGroup.getEndTime());
+			bean.setExamId(curCourseGroup.getExamId());
+			bean.setId(curCourseGroup.getId());
+			bean.setName(curCourseGroup.getName());
+			bean.setUpdateTime(curCourseGroup.getUpdateTime());
 
-		for (ExamSetting4Course specificExam : groupList) {
 			List<Long> courseIdList = Lists.newArrayList();
-			specificExam.setCourseIdList(courseIdList);
-
-			List<Map<String, Object>> queryList = jdbcTemplate.queryForList(
-					"select t.course_id from ecs_e_exam_course_relation t where t.specific_exam_id=?",
-					specificExam.getId());
-			if (CollectionUtils.isNotEmpty(queryList)) {
-				for (Map<String, Object> map : queryList) {
-					Long curCourseId = Long.valueOf(map.get("COURSE_ID").toString());
-					courseIdList.add(curCourseId);
-				}
+			bean.setCourseIdList(courseIdList);
+
+			List<CourseGroupRelation> curRelationList = courseGroupRelationRepo
+					.findAllByGroupId(bean.getId());
+
+			for (CourseGroupRelation cur : curRelationList) {
+				courseIdList.add(cur.getCourseId());
 			}
 		}
 
-		return new ResponseEntity<Object>(groupList, HttpStatus.OK);
+		return ret;
 	}
 
-	@ApiOperation(value = "更新特殊考试设置", notes = "更新特殊考试设置")
-	@PutMapping("/exam/specificExam")
-	public ResponseEntity<?> updateSpecificExam(@RequestBody ExamSetting4Course specificExam,
+	@ApiOperation(value = "更新课程组", notes = "")
+	@PutMapping("/exam/courseGroup")
+	public void updateCourseGroup(@RequestBody CourseGroupBean courseGroupBean,
 			HttpServletRequest request) {
 
-		examSetting4CourseRepo.save(specificExam);
-		Long specificExamId = specificExam.getId();
-		Long examId = specificExam.getExamId();
-
-		List<Long> courseIdList = specificExam.getCourseIdList();
-		jdbcTemplate.update("delete from ecs_e_exam_course_relation  where specific_exam_id=?",
-				specificExamId);
-
-		if (CollectionUtils.isNotEmpty(courseIdList)) {
-			for (Long courseId : courseIdList) {
-				jdbcTemplate.update(
-						"delete from ecs_e_exam_course_relation  where exam_id=? and course_id=?",
-						specificExamId, courseId);
-				jdbcTemplate.update(
-						"insert into ecs_e_exam_course_relation(specific_exam_id,course_id,exam_id) values(?,?,?)",
-						specificExamId, courseId, examId);
-			}
+		CourseGroup courseGroup = new CourseGroup();
+		courseGroup.setBeginTime(courseGroupBean.getBeginTime());
+		courseGroup.setCreationTime(courseGroupBean.getCreationTime());
+		courseGroup.setDescription(courseGroupBean.getDescription());
+		courseGroup.setEndTime(courseGroupBean.getEndTime());
+		courseGroup.setExamId(courseGroupBean.getExamId());
+		courseGroup.setId(courseGroupBean.getId());
+		courseGroup.setName(courseGroupBean.getName());
+		courseGroup.setUpdateTime(courseGroupBean.getUpdateTime());
+
+		courseGroupRepo.save(courseGroup);
+		List<Long> courseIdList = courseGroupBean.getCourseIdList();
+
+		List<CourseGroupRelation> relationList = Lists.newArrayList();
+
+		courseGroupRelationRepo.deleteByGroupId(courseGroup.getId());
+		
+		for (Long cur : courseIdList) {
+			CourseGroupRelation relation = new CourseGroupRelation();
+			relation.setCourseId(cur);
+			relation.setExamId(courseGroupBean.getExamId());
+			relation.setGroupId(courseGroup.getId());
+			relationList.add(relation);
 		}
-
-		return new ResponseEntity<Object>(HttpStatus.OK);
+		courseGroupRelationRepo.save(relationList);
 	}
 
-	@ApiOperation(value = "删除特殊考试设置", notes = "删除特殊考试设置")
-	@DeleteMapping("/exam/specificExam/{id}")
-	public ResponseEntity<?> deleteSpecificExam(@PathVariable Long id, HttpServletRequest request) {
-		examSetting4CourseRepo.delete(id);
-		jdbcTemplate.update("delete from ecs_e_exam_course_relation  where group_id=?", id);
-		return new ResponseEntity<Object>(HttpStatus.OK);
+	@ApiOperation(value = "删除课程组", notes = "删除特殊考试设置")
+	@DeleteMapping("/exam/courseGroup/{id}")
+	public void deleteSpecificExam(@PathVariable Long id, HttpServletRequest request) {
+		courseGroupRepo.delete(id);
+		courseGroupRelationRepo.deleteByGroupId(id);
 	}
 
 	@ApiOperation(value = "查询考试相关的学习中心设置", notes = "查询考试相关的学习中心设置")

+ 129 - 0
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/service/examwork/api/bean/CourseGroupBean.java

@@ -0,0 +1,129 @@
+package cn.com.qmth.examcloud.service.examwork.api.bean;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.springframework.format.annotation.DateTimeFormat;
+
+import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
+
+/**
+ * 课程组
+ * 
+ * @author WANG
+ *
+ */
+public class CourseGroupBean implements JsonSerializable {
+
+	private static final long serialVersionUID = -3335725218626631530L;
+
+	@Id
+	@GeneratedValue
+	private Long id;
+
+	private Long examId;
+
+	private String name;
+
+	private String description;
+
+	List<Long> courseIdList;
+
+	/**
+	 * 考试批次开始时间
+	 */
+	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+	private Date beginTime;
+
+	/**
+	 * 考试批次结束时间
+	 */
+	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+	private Date endTime;
+
+	/**
+	 * 更新时间
+	 */
+	private Date updateTime;
+
+	/**
+	 * 创建时间
+	 */
+	private Date creationTime;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Long getExamId() {
+		return examId;
+	}
+
+	public void setExamId(Long examId) {
+		this.examId = examId;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getDescription() {
+		return description;
+	}
+
+	public void setDescription(String description) {
+		this.description = description;
+	}
+
+	public List<Long> getCourseIdList() {
+		return courseIdList;
+	}
+
+	public void setCourseIdList(List<Long> courseIdList) {
+		this.courseIdList = courseIdList;
+	}
+
+	public Date getBeginTime() {
+		return beginTime;
+	}
+
+	public void setBeginTime(Date beginTime) {
+		this.beginTime = beginTime;
+	}
+
+	public Date getEndTime() {
+		return endTime;
+	}
+
+	public void setEndTime(Date endTime) {
+		this.endTime = endTime;
+	}
+
+	public Date getUpdateTime() {
+		return updateTime;
+	}
+
+	public void setUpdateTime(Date updateTime) {
+		this.updateTime = updateTime;
+	}
+
+	public Date getCreationTime() {
+		return creationTime;
+	}
+
+	public void setCreationTime(Date creationTime) {
+		this.creationTime = creationTime;
+	}
+
+}

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

@@ -0,0 +1,29 @@
+package cn.com.qmth.examcloud.service.examwork.dao;
+
+import java.util.List;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.repository.query.QueryByExampleExecutor;
+
+import cn.com.qmth.examcloud.service.examwork.entity.CourseGroupRelation;
+import cn.com.qmth.examcloud.service.examwork.entity.CourseGroupRelationPK;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年6月7日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public interface CourseGroupRelationRepo
+		extends
+			JpaRepository<CourseGroupRelation, CourseGroupRelationPK>,
+			QueryByExampleExecutor<CourseGroupRelation> {
+
+	List<CourseGroupRelation> findAllByGroupId(Long groupId);
+
+	List<CourseGroupRelation> findAllByCourseIdAndExamId(Long courseId, Long examId);
+
+	void deleteByGroupId(Long groupId);
+
+}

+ 27 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/service/examwork/dao/CourseGroupRepo.java

@@ -0,0 +1,27 @@
+package cn.com.qmth.examcloud.service.examwork.dao;
+
+import java.util.List;
+
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.repository.query.QueryByExampleExecutor;
+
+import cn.com.qmth.examcloud.service.examwork.entity.CourseGroup;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年6月7日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public interface CourseGroupRepo
+		extends
+			JpaRepository<CourseGroup, Long>,
+			QueryByExampleExecutor<CourseGroup> {
+
+	List<CourseGroup> findAllByExamId(Long examId, Pageable pageable);
+
+	List<CourseGroup> findAllByIdInOrderByUpdateTimeDesc(List<Long> idList);
+
+}

+ 0 - 22
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/service/examwork/dao/ExamSetting4CourseRepo.java

@@ -1,22 +0,0 @@
-package cn.com.qmth.examcloud.service.examwork.dao;
-
-import java.util.List;
-
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.query.Param;
-import org.springframework.data.repository.query.QueryByExampleExecutor;
-
-import cn.com.qmth.examcloud.service.examwork.entity.ExamSetting4Course;
-
-public interface ExamSetting4CourseRepo
-		extends JpaRepository<ExamSetting4Course, Long>, QueryByExampleExecutor<ExamSetting4Course> {
-
-	@Query(value = "select * from ecs_e_exam_4_course t where t.exam_id=?1 order by id desc limit ?2,?3", nativeQuery = true)
-	List<ExamSetting4Course> findByExamId(@Param("examId") Long examId, @Param("curPage") Integer curPage,
-			@Param("pageSize") Integer pageSize);
-
-	@Query(value = "select x.* from ecs_e_exam_4_course x,ecs_e_exam_course_relation  y where x.id=y.specific_exam_id and y.course_id=?1", nativeQuery = true)
-	List<ExamSetting4Course> queryCourseGroupsByCourseId(@Param("courseId") Long courseId);
-
-}

+ 0 - 12
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/service/examwork/dao/ExamSettingCourseRelationRepo.java

@@ -1,12 +0,0 @@
-package cn.com.qmth.examcloud.service.examwork.dao;
-
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.repository.query.QueryByExampleExecutor;
-
-import cn.com.qmth.examcloud.service.examwork.entity.ExamSettingCourseRelation;
-import cn.com.qmth.examcloud.service.examwork.entity.ExamSettingCourseRelationPK;
-
-public interface ExamSettingCourseRelationRepo
-		extends JpaRepository<ExamSettingCourseRelation, ExamSettingCourseRelationPK>, QueryByExampleExecutor<ExamSettingCourseRelation> {
-
-}

+ 5 - 17
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/service/examwork/entity/ExamSetting4Course.java → examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/service/examwork/entity/CourseGroup.java

@@ -1,26 +1,25 @@
 package cn.com.qmth.examcloud.service.examwork.entity;
 
-import java.io.Serializable;
 import java.util.Date;
-import java.util.List;
 
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
 import javax.persistence.Table;
-import javax.persistence.Transient;
 
 import org.springframework.format.annotation.DateTimeFormat;
 
+import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
+
 /**
- * 考试-课程
+ * 课程
  * 
  * @author WANG
  *
  */
 @Entity
-@Table(name = "ecs_e_exam_4_course")
-public class ExamSetting4Course implements Serializable {
+@Table(name = "ecs_e_course_group")
+public class CourseGroup extends JpaEntity {
 
 	private static final long serialVersionUID = -3335725218626631530L;
 
@@ -34,9 +33,6 @@ public class ExamSetting4Course implements Serializable {
 
 	private String description;
 
-	@Transient
-	private List<Long> courseIdList;
-
 	/**
 	 * 考试批次开始时间
 	 */
@@ -81,14 +77,6 @@ public class ExamSetting4Course implements Serializable {
 		this.description = description;
 	}
 
-	public List<Long> getCourseIdList() {
-		return courseIdList;
-	}
-
-	public void setCourseIdList(List<Long> courseIdList) {
-		this.courseIdList = courseIdList;
-	}
-
 	public Date getBeginTime() {
 		return beginTime;
 	}

+ 14 - 14
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/service/examwork/entity/ExamSettingCourseRelation.java → examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/service/examwork/entity/CourseGroupRelation.java

@@ -8,40 +8,40 @@ import javax.persistence.IdClass;
 import javax.persistence.Table;
 
 /**
- * 考试课程关联
+ * 课程关联课程
  * 
  * @author WANG
  *
  */
 @Entity
-@Table(name = "ecs_e_exam_course_relation")
-@IdClass(ExamSettingCourseRelationPK.class)
-public class ExamSettingCourseRelation implements Serializable {
+@Table(name = "ecs_e_course_group_relation")
+@IdClass(CourseGroupRelationPK.class)
+public class CourseGroupRelation implements Serializable {
 
 	private static final long serialVersionUID = -3335725218626631530L;
 
 	@Id
-	private String specificExamId;
+	private Long courseId;
 
 	@Id
-	private String courseId;
+	private Long groupId;
 
 	private Long examId;
 
-	public String getSpecificExamId() {
-		return specificExamId;
+	public Long getCourseId() {
+		return courseId;
 	}
 
-	public void setSpecificExamId(String specificExamId) {
-		this.specificExamId = specificExamId;
+	public void setCourseId(Long courseId) {
+		this.courseId = courseId;
 	}
 
-	public String getCourseId() {
-		return courseId;
+	public Long getGroupId() {
+		return groupId;
 	}
 
-	public void setCourseId(String courseId) {
-		this.courseId = courseId;
+	public void setGroupId(Long groupId) {
+		this.groupId = groupId;
 	}
 
 	public Long getExamId() {

+ 35 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/service/examwork/entity/CourseGroupRelationPK.java

@@ -0,0 +1,35 @@
+package cn.com.qmth.examcloud.service.examwork.entity;
+
+import java.io.Serializable;
+
+/**
+ * 课程组关联课程 主键
+ * 
+ * @author WANG
+ *
+ */
+public class CourseGroupRelationPK implements Serializable {
+
+	private static final long serialVersionUID = 2741694459442340816L;
+
+	private Long courseId;
+
+	private Long groupId;
+
+	public Long getCourseId() {
+		return courseId;
+	}
+
+	public void setCourseId(Long courseId) {
+		this.courseId = courseId;
+	}
+
+	public Long getGroupId() {
+		return groupId;
+	}
+
+	public void setGroupId(Long groupId) {
+		this.groupId = groupId;
+	}
+
+}

+ 0 - 35
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/service/examwork/entity/ExamSettingCourseRelationPK.java

@@ -1,35 +0,0 @@
-package cn.com.qmth.examcloud.service.examwork.entity;
-
-import java.io.Serializable;
-
-/**
- * 考试课程关联 主键
- * 
- * @author WANG
- *
- */
-public class ExamSettingCourseRelationPK implements Serializable {
-
-	private static final long serialVersionUID = 2741694459442340816L;
-
-	private String specificExamId;
-
-	private String courseId;
-
-	public String getSpecificExamId() {
-		return specificExamId;
-	}
-
-	public void setSpecificExamId(String specificExamId) {
-		this.specificExamId = specificExamId;
-	}
-
-	public String getCourseId() {
-		return courseId;
-	}
-
-	public void setCourseId(String courseId) {
-		this.courseId = courseId;
-	}
-
-}