wangwei пре 7 година
родитељ
комит
6db078705e

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

@@ -1,7 +1,6 @@
 package cn.com.qmth.examcloud.service.examwork.api;
 
 import java.util.Date;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -13,6 +12,7 @@ import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
 import org.springframework.data.domain.Sort.Direction;
 import org.springframework.http.HttpStatus;
@@ -36,11 +36,13 @@ import cn.com.qmth.examcloud.common.support.exception.StatusException;
 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.dao.ExamStudentRepo;
 import cn.com.qmth.examcloud.service.examwork.dao.ExamSetting4CourseRepo;
+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.ExamStudent;
 import cn.com.qmth.examcloud.service.examwork.entity.ExamSetting4Course;
+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;
 import cn.com.qmth.examcloud.service.examwork.service.ExamService;
 import cn.com.qmth.examcloud.service.examwork.service.ExamStudentService;
@@ -68,6 +70,9 @@ public class ExamApi extends ControllerSupport {
 	@Autowired
 	ExamSetting4CourseRepo examSetting4CourseRepo;
 
+	@Autowired
+	ExamSetting4OrgRepo examSetting4OrgRepo;
+
 	@Autowired
 	private JdbcTemplate jdbcTemplate;
 
@@ -81,13 +86,16 @@ public class ExamApi extends ControllerSupport {
 		} else {
 			return new ResponseEntity(HttpStatus.NOT_FOUND);
 		}
-		return new ResponseEntity(examService.getAllExam(examCriteria,
-				new PageRequest(curPage, pageSize, new Sort(Direction.DESC, "id"))), HttpStatus.OK);
+		return new ResponseEntity(
+				examService.getAllExam(examCriteria,
+						new PageRequest(curPage, pageSize, new Sort(Direction.DESC, "id"))),
+				HttpStatus.OK);
 	}
 
 	@ApiOperation(value = "查询所有考试批次(包含有效)", notes = "不分页带查询")
 	@GetMapping("/exam/all")
-	public ResponseEntity getEnableExam(HttpServletRequest request, @ModelAttribute Exam examCriteria) {
+	public ResponseEntity getEnableExam(HttpServletRequest request,
+			@ModelAttribute Exam examCriteria) {
 		AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
 		if (accessUser != null) {
 			examCriteria.setOrgId(accessUser.getRootOrgId());
@@ -98,7 +106,8 @@ public class ExamApi extends ControllerSupport {
 
 	@ApiOperation(value = "根据机构ID和考试类型查询所有有效考试批次", notes = "根据机构ID和考试类型查询所有有效考试批次")
 	@GetMapping("/exam/rootOrgId/{orgId}/{examType}")
-	public ResponseEntity getEnableExamByRootOrgId(@PathVariable Long orgId, @PathVariable String examType) {
+	public ResponseEntity getEnableExamByRootOrgId(@PathVariable Long orgId,
+			@PathVariable String examType) {
 		if (orgId == null) {
 			return new ResponseEntity(new ErrorMsg("机构ID不能为空"), HttpStatus.OK);
 		}
@@ -113,23 +122,26 @@ public class ExamApi extends ControllerSupport {
 
 	@ApiOperation(value = "查询所有考试批次(包含有效无效)", notes = "不分页带查询")
 	@GetMapping("/exam/all/both")
-	public ResponseEntity getAllExam(HttpServletRequest request, @ModelAttribute Exam examCriteria) {
+	public ResponseEntity getAllExam(HttpServletRequest request,
+			@ModelAttribute Exam examCriteria) {
 		AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
 		if (accessUser != null) {
 			examCriteria.setOrgId(accessUser.getRootOrgId());
 		}
 		return new ResponseEntity(examService.getAllExam(examCriteria), HttpStatus.OK);
 	}
-	
+
 	@ApiOperation(value = "根据名称查询考试批次(包含有效)", notes = "不分页带查询")
 	@GetMapping("/exam/name")
-	public ResponseEntity getEnableExamByName(HttpServletRequest request, @ModelAttribute Exam examCriteria) {
+	public ResponseEntity getEnableExamByName(HttpServletRequest request,
+			@ModelAttribute Exam examCriteria) {
 		AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
 		if (accessUser != null) {
 			examCriteria.setRootOrgId(accessUser.getRootOrgId());
 		}
 		examCriteria.setEnable(true);
-		return new ResponseEntity(examService.findByNameAndRootOrgId(examCriteria.getName(),examCriteria.getRootOrgId()), HttpStatus.OK);
+		return new ResponseEntity(examService.findByNameAndRootOrgId(examCriteria.getName(),
+				examCriteria.getRootOrgId()), HttpStatus.OK);
 	}
 
 	@ApiOperation(value = "按ID查询考试批次", notes = "ID查询")
@@ -141,7 +153,7 @@ public class ExamApi extends ControllerSupport {
 	@ApiOperation(value = "新增考试批次", notes = "新增")
 	@PostMapping("/exam")
 	public Exam addExam(HttpServletRequest request, @RequestBody Exam exam) {
-		
+
 		if (null != exam.getBeforeExamRemark() && exam.getBeforeExamRemark().length() > 250000) {
 			throw new StatusException("EXAMWORK-001002", "考前说明内容过大");
 		}
@@ -151,7 +163,7 @@ public class ExamApi extends ControllerSupport {
 		if (null != exam.getCheatingRemark() && exam.getCheatingRemark().length() > 250000) {
 			throw new StatusException("EXAMWORK-001002", "作弊说明内容过大");
 		}
-		
+
 		AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
 		if (accessUser != null) {
 			exam.setOrgId(accessUser.getOrgId());
@@ -174,7 +186,7 @@ public class ExamApi extends ControllerSupport {
 		if (!examService.checkExamName(exam)) {
 			throw new StatusException("EXAMWORK-001001", "考试名称已存在,请重新填写");
 		}
-		
+
 		if (null != exam.getBeforeExamRemark() && exam.getBeforeExamRemark().length() > 250000) {
 			throw new StatusException("EXAMWORK-001002", "考前说明内容过大");
 		}
@@ -184,7 +196,7 @@ public class ExamApi extends ControllerSupport {
 		if (null != exam.getCheatingRemark() && exam.getCheatingRemark().length() > 250000) {
 			throw new StatusException("EXAMWORK-001002", "作弊说明内容过大");
 		}
-		
+
 		Exam ret = examService.saveExam(exam);
 		return ret;
 	}
@@ -199,14 +211,16 @@ public class ExamApi extends ControllerSupport {
 			return new ResponseEntity(HttpStatus.OK);
 		} catch (Exception e) {
 			log.error("删除失败:", e);
-			return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
+			return new ResponseEntity(new ErrorMsg(e.getMessage()),
+					HttpStatus.INTERNAL_SERVER_ERROR);
 		}
 	}
 
 	@ApiOperation(value = "启用考试", notes = "启用考试")
 	@PutMapping("/exam/enable/{ids}")
 	public ResponseEntity enableUser(@PathVariable String ids) {
-		List<Long> examIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
+		List<Long> examIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
+				.collect(Collectors.toList());
 		for (Long examId : examIds) {
 			Exam exam = examRepo.findOne(examId);
 			exam.setEnable(true);
@@ -218,7 +232,8 @@ public class ExamApi extends ControllerSupport {
 	@ApiOperation(value = "禁用考试", notes = "禁用考试")
 	@PutMapping("/exam/disable/{ids}")
 	public ResponseEntity disableUser(@PathVariable String ids) {
-		List<Long> examIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
+		List<Long> examIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
+				.collect(Collectors.toList());
 		for (Long examId : examIds) {
 			Exam exam = examRepo.findOne(examId);
 			exam.setEnable(false);
@@ -244,7 +259,8 @@ public class ExamApi extends ControllerSupport {
 
 	@ApiOperation(value = "网考更新考务信息", notes = "网考更新考务信息")
 	@PutMapping("/exam/updateExamStudent")
-	public ResponseEntity updateExamStudent(@RequestParam Long examId, @RequestParam Long examStuId) {
+	public ResponseEntity updateExamStudent(@RequestParam Long examId,
+			@RequestParam Long examStuId) {
 		examRepo.canNotDel(examId);
 		ExamStudent examStudent = examStudentRepo.findOne(examStuId);
 		examStudent.setFinished(true);
@@ -254,17 +270,19 @@ public class ExamApi extends ControllerSupport {
 
 	@ApiOperation(value = "查询特殊考试设置", notes = "查询特殊考试设置")
 	@GetMapping("/exam/querySpecificExamList/{examId}/{curPage}/{pageSize}")
-	public ResponseEntity<?> querySpecificExamList(@PathVariable Long examId, @PathVariable Integer curPage,
-			@PathVariable Integer pageSize) {
+	public ResponseEntity<?> querySpecificExamList(@PathVariable Long examId,
+			@PathVariable Integer curPage, @PathVariable Integer pageSize) {
 
-		List<ExamSetting4Course> groupList = examSetting4CourseRepo.findByExamId(examId, (curPage - 1) * pageSize, pageSize);
+		List<ExamSetting4Course> groupList = examSetting4CourseRepo.findByExamId(examId,
+				(curPage - 1) * pageSize, pageSize);
 
 		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());
+					"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());
@@ -279,14 +297,16 @@ public class ExamApi extends ControllerSupport {
 	@ApiOperation(value = "通过课程ID查询特殊考试设置", notes = "通过课程ID查询特殊考试设置")
 	@GetMapping("/exam/querySpecificExamByCourseId/{courseId}")
 	public ResponseEntity<?> querySpecificExamByCourseId(@PathVariable Long courseId) {
-		List<ExamSetting4Course> groupList = examSetting4CourseRepo.queryCourseGroupsByCourseId(courseId);
+		List<ExamSetting4Course> groupList = examSetting4CourseRepo
+				.queryCourseGroupsByCourseId(courseId);
 
 		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());
+					"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());
@@ -300,22 +320,25 @@ public class ExamApi extends ControllerSupport {
 
 	@ApiOperation(value = "更新特殊考试设置", notes = "更新特殊考试设置")
 	@PutMapping("/exam/specificExam")
-	public ResponseEntity<?> updateSpecificExam(@RequestBody ExamSetting4Course specificExam, HttpServletRequest request) {
+	public ResponseEntity<?> updateSpecificExam(@RequestBody ExamSetting4Course specificExam,
+			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);
+		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=?",
+				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);
+						"insert into ecs_e_exam_course_relation(specific_exam_id,course_id,exam_id) values(?,?,?)",
+						specificExamId, courseId, examId);
 			}
 		}
 
@@ -329,4 +352,20 @@ public class ExamApi extends ControllerSupport {
 		jdbcTemplate.update("delete from ecs_e_exam_course_relation  where group_id=?", id);
 		return new ResponseEntity<Object>(HttpStatus.OK);
 	}
+
+	@ApiOperation(value = "查询考试相关的学习中心设置", notes = "查询考试相关的学习中心设置")
+	@GetMapping("/exam/examSetting4OrgList/{examId}/{curPage}/{pageSize}")
+	public List<?> getExamSetting4OrgList(@PathVariable Long examId, @PathVariable Integer curPage,
+			@PathVariable Integer pageSize) {
+		Pageable pageable = new PageRequest(curPage, pageSize, Sort.Direction.DESC, "updateTime");
+		List<ExamSetting4Org> allByExamId = examSetting4OrgRepo.findAllByExamId(examId, pageable);
+		return allByExamId;
+	}
+
+	@ApiOperation(value = "新增考试相关的学习中心设置", notes = "新增考试相关的学习中心设置")
+	@PostMapping("/exam/examSetting4Org")
+	public ExamSetting4Org addExamSetting4Org(@RequestBody ExamSetting4Org examSetting4Org) {
+		return null;
+	}
+
 }

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

@@ -0,0 +1,20 @@
+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.ExamSetting4Org;
+
+public interface ExamSetting4OrgRepo
+		extends
+			JpaRepository<ExamSetting4Org, Long>,
+			QueryByExampleExecutor<ExamSetting4Org> {
+
+	List<ExamSetting4Org> findAllByExamId(Long examId, Pageable pageable);
+
+	List<ExamSetting4Org> findAllByExamIdAndOrgId(Long examId, Long orgId, Pageable pageable);
+
+}

+ 25 - 44
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/service/examwork/entity/ExamSetting4Org.java

@@ -1,41 +1,38 @@
 package cn.com.qmth.examcloud.service.examwork.entity;
 
-import java.io.Serializable;
 import java.util.Date;
-import java.util.List;
 
+import javax.persistence.Column;
 import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
+import javax.persistence.IdClass;
 import javax.persistence.Table;
-import javax.persistence.Transient;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
 
 import org.springframework.format.annotation.DateTimeFormat;
 
+import cn.com.qmth.examcloud.common.support.JsonSerializable;
+
 /**
- *考试-学习中心
- * 
- * @author WANG
+ * 类注释
  *
+ * @author WANGWEI
+ * @date 2018年5月16日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
  */
 @Entity
 @Table(name = "ecs_e_exam_4_org")
-public class ExamSetting4Org implements Serializable {
+@IdClass(ExamSetting4OrgPK.class)
+public class ExamSetting4Org implements JsonSerializable {
 
 	private static final long serialVersionUID = -3335725218626631530L;
 
 	@Id
-	@GeneratedValue
-	private Long id;
-
 	private Long examId;
 
-	private String name;
-
-	private String description;
-
-	@Transient
-	private List<Long> courseIdList;
+	@Id
+	private String orgId;
 
 	/**
 	 * 考试批次开始时间
@@ -49,13 +46,13 @@ public class ExamSetting4Org implements Serializable {
 	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
 	private Date endTime;
 
-	public Long getId() {
-		return id;
-	}
-
-	public void setId(Long id) {
-		this.id = id;
-	}
+	/**
+	 * 更新时间
+	 */
+	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+	@Column(nullable = false)
+	@Temporal(TemporalType.TIMESTAMP)
+	private Date updateTime;
 
 	public Long getExamId() {
 		return examId;
@@ -65,28 +62,12 @@ public class ExamSetting4Org implements Serializable {
 		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 String getOrgId() {
+		return orgId;
 	}
 
-	public void setCourseIdList(List<Long> courseIdList) {
-		this.courseIdList = courseIdList;
+	public void setOrgId(String orgId) {
+		this.orgId = orgId;
 	}
 
 	public Date getBeginTime() {

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

@@ -0,0 +1,35 @@
+package cn.com.qmth.examcloud.service.examwork.entity;
+
+import java.io.Serializable;
+
+/**
+ * 考试-学习中心 PK
+ * 
+ * @author WANG
+ *
+ */
+public class ExamSetting4OrgPK implements Serializable {
+
+	private static final long serialVersionUID = 3692854300698527252L;
+
+	private Long examId;
+
+	private String orgId;
+
+	public Long getExamId() {
+		return examId;
+	}
+
+	public void setExamId(Long examId) {
+		this.examId = examId;
+	}
+
+	public String getOrgId() {
+		return orgId;
+	}
+
+	public void setOrgId(String orgId) {
+		this.orgId = orgId;
+	}
+
+}