wangwei 7 tahun lalu
induk
melakukan
456abb296c

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

@@ -2,11 +2,12 @@ package cn.com.qmth.examcloud.core.examwork.api.controller;
 
 import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
 
-import java.util.Date;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import javax.persistence.criteria.Predicate;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.lang3.StringUtils;
@@ -17,6 +18,7 @@ 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.data.jpa.domain.Specification;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -112,6 +114,35 @@ public class ExamController extends ControllerSupport {
 		return new ResponseEntity(examService.getAllExam(examCriteria), HttpStatus.OK);
 	}
 
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param name
+	 * @return
+	 */
+	@ApiOperation(value = "查询考试批次(包含有效、无效)")
+	@GetMapping("queryByName")
+	public List<Exam> queryByName(@RequestParam(required = false) String name) {
+
+		if (StringUtils.isBlank(name)) {
+			List<Exam> list = Lists.newArrayList();
+			return list;
+		}
+
+		Specification<Exam> specification = (root, query, cb) -> {
+			List<Predicate> predicates = new ArrayList<>();
+			predicates.add(cb.equal(root.get("rootOrgId"), getRootOrgId()));
+			predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
+
+			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+		Sort sort = new Sort(Direction.DESC, "updateTime");
+		List<Exam> page = examRepo.findAll(specification, sort);
+
+		return page;
+	}
+
 	@ApiOperation(value = "根据机构ID和考试类型查询所有有效考试批次", notes = "根据机构ID和考试类型查询所有有效考试批次")
 	@GetMapping("rootOrgId/{orgId}/{examType}")
 	public ResponseEntity getEnableExamByRootOrgId(@PathVariable Long orgId,
@@ -174,7 +205,6 @@ public class ExamController extends ControllerSupport {
 
 		exam.setOrgId(accessUser.getOrgId());
 		exam.setRootOrgId(accessUser.getRootOrgId());
-		exam.setCreateTime(new Date());
 		exam.setCanStuDel(true);
 		if (!examService.checkExamName(exam)) {
 			throw new StatusException("E-001001", "考试名称已存在,请重新填写");

+ 0 - 3
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/provider/ExamCloudServiceProvider.java

@@ -1,7 +1,5 @@
 package cn.com.qmth.examcloud.core.examwork.api.provider;
 
-import java.util.Date;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -48,7 +46,6 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 		// exam.setOrgId(accessUser.getOrgId());
 		exam.setOrgId(109L);
 		// exam.setRootOrgId(accessUser.getRootOrgId());
-		exam.setCreateTime(new Date());
 		exam.setCanStuDel(true);
 		if (!examService.checkExamName(exam)) {
 			throw new StatusException("EXAMWORK-EXAMEXSTED", "考试名称已存在,请重新填写");

+ 11 - 8
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/ExamRepo.java

@@ -3,6 +3,7 @@ package cn.com.qmth.examcloud.core.examwork.dao;
 import java.util.List;
 
 import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
@@ -10,23 +11,25 @@ import org.springframework.transaction.annotation.Transactional;
 
 import cn.com.qmth.examcloud.core.examwork.dao.entity.Exam;
 
-public interface ExamRepo extends JpaRepository<Exam, Long>,QueryByExampleExecutor<Exam>{
+public interface ExamRepo
+		extends
+			JpaRepository<Exam, Long>,
+			QueryByExampleExecutor<Exam>,
+			JpaSpecificationExecutor<Exam> {
 
 	List<Exam> findByOrgId(Long orgId);
 
-//	void deleteByIdIn(List<Long> ids);
-
 	List<Exam> findByIdIn(List<Long> ids);
 
-	List<Exam> findByNameAndRootOrgId(String name,Long rootOrgId);
-	
+	List<Exam> findByNameAndRootOrgId(String name, Long rootOrgId);
+
 	Long countByName(String name);
 
-	Long countByNameAndRootOrgId(String name,Long rootOrgId);
+	Long countByNameAndRootOrgId(String name, Long rootOrgId);
 
-	Long countByNameAndIdNot(String name,Long id);
+	Long countByNameAndIdNot(String name, Long id);
 
-	Long countByNameAndRootOrgIdAndIdNot(String name,Long rootOrgId,Long id);
+	Long countByNameAndRootOrgIdAndIdNot(String name, Long rootOrgId, Long id);
 
 	@Transactional
 	@Modifying

+ 38 - 52
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/entity/Exam.java

@@ -11,10 +11,9 @@ import javax.persistence.Lob;
 import javax.persistence.Table;
 import javax.validation.constraints.NotNull;
 
-import org.springframework.data.annotation.CreatedDate;
 import org.springframework.format.annotation.DateTimeFormat;
 
-import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
+import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.enums.ExamType;
 import cn.com.qmth.examcloud.core.examwork.dao.enums.MarkingType;
 import cn.com.qmth.examcloud.core.examwork.dao.enums.PracticeType;
@@ -24,7 +23,7 @@ import cn.com.qmth.examcloud.core.examwork.dao.enums.PracticeType;
  */
 @Entity
 @Table(name = "ecs_exam")
-public class Exam implements JsonSerializable {
+public class Exam extends JpaEntity {
 
 	private static final long serialVersionUID = 4009839764353162256L;
 
@@ -45,37 +44,38 @@ public class Exam implements JsonSerializable {
 
 	/**
 	 * 考试批次开始时间
-     */
-	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+	 */
+	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
 	private Date beginTime;
 
 	/**
 	 * 考试批次结束时间
-     */
-	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+	 */
+	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
 	private Date endTime;
 
 	/**
 	 * 考试名称
-     */
+	 */
 	@NotNull
 	private String name;
 
 	/**
 	 * 考试类型
-     */
+	 */
 	@Enumerated(EnumType.STRING)
 	private ExamType examType;
 
 	/**
 	 * 是否入学考试
-     */
+	 */
 	private Boolean isEntranceExam;
 
 	/**
 	 * 考试时长
 	 */
 	private Integer duration;
+
 	/**
 	 * 冻结时间
 	 */
@@ -83,52 +83,44 @@ public class Exam implements JsonSerializable {
 
 	/**
 	 * 考试状态
-     */
+	 */
 	private String status;
 
-
 	private Boolean enable;
 
 	/**
 	 * 考试备注
-     */
+	 */
 	private String remark;
 
-	/**
-	 * 创建时间
-     */
-	@CreatedDate
-	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
-	private Date createTime;
-
 	/**
 	 * 考试次数
-     */
+	 */
 	private Long examTimes;
 
 	/**
 	 * 断点续考时间(秒)
-     */
+	 */
 	private Long examReconnectTime;
 
 	/**
 	 * 考前说明
-     */
-	@Lob 
+	 */
+	@Lob
 	private String beforeExamRemark;
 
 	/**
 	 * 考后说明
-     */
-	@Lob 
+	 */
+	@Lob
 	private String afterExamRemark;
-	
+
 	/**
 	 * 作弊说明
 	 */
-	@Lob 
+	@Lob
 	private String cheatingRemark;
-	
+
 	/**
 	 * 是否展示作弊
 	 */
@@ -136,12 +128,12 @@ public class Exam implements JsonSerializable {
 
 	/**
 	 * 是否显示成绩
-     */
+	 */
 	private String isObjScoreView;
 
 	/**
 	 * 练习模式
-     */
+	 */
 	@Enumerated(EnumType.STRING)
 	private PracticeType practiceType;
 
@@ -167,27 +159,27 @@ public class Exam implements JsonSerializable {
 
 	/**
 	 * 单选题补充说明
-     */
+	 */
 	private String singleAnswerRemark;
 
 	/**
 	 * 多选题补充说明
-     */
+	 */
 	private String mutipleAnswerRemark;
 
 	/**
 	 * 判断题补充说明
-     */
+	 */
 	private String boolAnswerRemark;
 
 	/**
 	 * 填空题补充说明
-     */
+	 */
 	private String fillBlankRemark;
 
 	/**
 	 * 问答题补充说明
-     */
+	 */
 	private String textAnswerRemark;
 
 	/**
@@ -197,44 +189,46 @@ public class Exam implements JsonSerializable {
 
 	/**
 	 * 是否启用人脸识别
-     */
+	 */
 	private String isFaceEnable;
 
 	/**
 	 * 进入考试是否验证人脸识别(强制、非强制)
-     */
+	 */
 	private String isFaceCheck;
 
 	/**
 	 * 抓拍间隔
-     */
+	 */
 	private Double snapshotInterval;
 
 	/**
 	 * 预警阈值
-     */
+	 */
 	private Double warnThreshold;
 
 	/**
 	 * 阅卷方式
-     */
+	 */
 	@Enumerated(EnumType.STRING)
 	private MarkingType markingType;
 
 	/**
 	 * 学生是否可以删除
-     */
+	 */
 	@NotNull
 	private Boolean canStuDel;
-	
+
 	/**
 	 * 是否开启人脸活体检测
 	 */
 	private Boolean isFaceVerify;
+
 	/**
 	 * 活体检测开始分钟数
 	 */
 	private Integer faceVerifyStartMinute;
+
 	/**
 	 * 活体检测结束分钟数
 	 */
@@ -328,14 +322,6 @@ public class Exam implements JsonSerializable {
 		this.remark = remark;
 	}
 
-	public Date getCreateTime() {
-		return createTime;
-	}
-
-	public void setCreateTime(Date createTime) {
-		this.createTime = createTime;
-	}
-
 	public Long getExamTimes() {
 		return examTimes;
 	}
@@ -527,7 +513,7 @@ public class Exam implements JsonSerializable {
 	public void setEntranceExam(Boolean entranceExam) {
 		isEntranceExam = entranceExam;
 	}
-	
+
 	public Boolean getIsEntranceExam() {
 		return isEntranceExam;
 	}