فهرست منبع

离线考试增加允许上传字段

宋悦 7 سال پیش
والد
کامیت
a449c243be

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

@@ -3,6 +3,7 @@ package cn.com.qmth.examcloud.service.examwork.api;
 import cn.com.qmth.examcloud.common.util.ErrorMsg;
 import cn.com.qmth.examcloud.service.examwork.dao.ExamOrgTimeRepo;
 import cn.com.qmth.examcloud.service.examwork.entity.ExamOrgTime;
+import cn.com.qmth.examcloud.service.examwork.service.ExamOrgTimeService;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
@@ -24,13 +25,16 @@ public class ExamOrgTimeApi {
     @Autowired
     ExamOrgTimeRepo examOrgTimeRepo;
 
+    @Autowired
+    ExamOrgTimeService examOrgTimeService;
+
     @ApiOperation(value="查询学习中心考试时间",notes = "分页")
-    @GetMapping("/examOrgTime/{examId}/{curPage}/{pageSize}")
-    public ResponseEntity findByExamId(@PathVariable Long examId,
+    @GetMapping("/examOrgTime/{curPage}/{pageSize}")
+    public ResponseEntity findByExamId(@ModelAttribute ExamOrgTime examOrgTime,
                                        @PathVariable Integer curPage,
                                        @PathVariable Integer pageSize){
         PageRequest pageRequest = new PageRequest(curPage,pageSize);
-        Page<ExamOrgTime> orgTimePage = examOrgTimeRepo.findByExamId(examId,pageRequest);
+        Page<ExamOrgTime> orgTimePage = examOrgTimeService.getAllOrgTime(examOrgTime,pageRequest);
     	return new ResponseEntity(orgTimePage, HttpStatus.OK);
     }
 

+ 60 - 0
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/service/ExamOrgTimeService.java

@@ -0,0 +1,60 @@
+package cn.com.qmth.examcloud.service.examwork.service;
+
+import cn.com.qmth.examcloud.service.examwork.dao.ExamOrgTimeRepo;
+import cn.com.qmth.examcloud.service.examwork.entity.ExamOrgTime;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import javax.persistence.criteria.Predicate;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by songyue on 18/3/1.
+ */
+@Service
+public class ExamOrgTimeService {
+
+
+    @Autowired
+    private ExamOrgTimeRepo examOrgTimeRepo;
+
+    /**
+     * 获取所有学习中心考试时间(分页)
+     * @param examOrgTime
+     * @param pageable
+     * @return
+     * @return
+     */
+    public Page<ExamOrgTime> getAllOrgTime(ExamOrgTime examOrgTime, Pageable pageable){
+        Specification<ExamOrgTime> specification = getPageSpecification(examOrgTime);
+        Page<ExamOrgTime> examOrgTimes = examOrgTimeRepo.findAll(specification,pageable);
+        return examOrgTimes;
+    }
+
+    /**
+     * 生成查询条件
+     * @param examOrgTime
+     * @return
+     */
+    private Specification<ExamOrgTime> getPageSpecification(ExamOrgTime examOrgTime) {
+        Specification<ExamOrgTime> specification = (root, query, cb) -> {
+            List<Predicate> predicates = new ArrayList<>();
+            if(!StringUtils.isEmpty(examOrgTime.getExamId())){
+                predicates.add(cb.equal(root.get("examId"),examOrgTime.getExamId()));
+            }
+            if(!StringUtils.isEmpty(examOrgTime.getOrgCode())){
+                predicates.add(cb.like(root.get("orgCode"),"%"+examOrgTime.getOrgCode()+"%"));
+            }
+            if(!StringUtils.isEmpty(examOrgTime.getOrgName())){
+                predicates.add(cb.like(root.get("orgName"),"%"+examOrgTime.getOrgName()+"%"));
+            }
+            return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+        };
+        return specification;
+    }
+}

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

@@ -113,8 +113,10 @@ public class ExamService {
         List<ExamOrgTime> examOrgTimes = new ArrayList<>();
         for(Org org:orgList){
             Long orgId = org.getId();
+            String orgCode = org.getCode();
             String orgName = org.getName();
-            ExamOrgTime examOrgTime = new ExamOrgTime(examId,orgId,orgName,beginTime,endTime);
+            ExamOrgTime examOrgTime = new ExamOrgTime(examId, orgId, orgCode,
+                                                      orgName, beginTime, endTime);
             examOrgTimes.add(examOrgTime);
         }
         examOrgTimeRepo.save(examOrgTimes);

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

@@ -5,6 +5,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.text.DecimalFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 import javax.persistence.criteria.Predicate;
@@ -143,6 +144,7 @@ public class ExamStudentService {
 					String examEndTime = String.valueOf(examOrgTime.getEndTime().getTime());
 					examStudent.setExamBeginTime(examBeginTime);
 					examStudent.setExamEndTime(examEndTime);
+					examStudent.setCanUpload(getCanUpload(examOrgTime));
 				}
 			}else{
 				String examBeginTime = String.valueOf(exam.getBeginTime().getTime());
@@ -153,6 +155,19 @@ public class ExamStudentService {
 		}
 	}
 
+	private Boolean getCanUpload(ExamOrgTime examOrgTime){
+		if(examOrgTime.getCanUpload() == null){
+			Date now = new Date();
+			if(now.after(examOrgTime.getEndTime())){
+				return false;
+			}else{
+				return true;
+			}
+		}else{
+			return examOrgTime.getCanUpload();
+		}
+	}
+
 	public ExamStudent findById(Long id){
 		ExamStudent examStudent = examStudentRepo.findOne(id);
 		setExamOrgTime(examStudent);

+ 30 - 2
exam-work-domain/src/main/java/cn/com/qmth/examcloud/service/examwork/entity/ExamOrgTime.java

@@ -28,7 +28,8 @@ public class ExamOrgTime implements Serializable{
     @NotNull
     private Long orgId;
 
-    @NotNull
+    private String orgCode;
+
     private String orgName;
 
     /**
@@ -41,6 +42,11 @@ public class ExamOrgTime implements Serializable{
      */
     private Date endTime;
 
+    /**
+     * 是否可上传
+     */
+    private Boolean canUpload;
+
     public Long getId() {
         return id;
     }
@@ -89,9 +95,31 @@ public class ExamOrgTime implements Serializable{
         this.orgName = orgName;
     }
 
-    public ExamOrgTime(Long examId, Long orgId, String orgName,Date beginTime, Date endTime) {
+    public Boolean getCanUpload() {
+        return canUpload;
+    }
+
+    public void setCanUpload(Boolean canUpload) {
+        this.canUpload = canUpload;
+    }
+
+    public String getOrgCode() {
+        return orgCode;
+    }
+
+    public void setOrgCode(String orgCode) {
+        this.orgCode = orgCode;
+    }
+
+    public ExamOrgTime(Long examId,
+                       Long orgId,
+                       String orgCode,
+                       String orgName,
+                       Date beginTime,
+                       Date endTime) {
         this.examId = examId;
         this.orgId = orgId;
+        this.orgCode = orgCode;
         this.orgName = orgName;
         this.beginTime = beginTime;
         this.endTime = endTime;

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

@@ -147,6 +147,11 @@ public class ExamStudent implements Serializable {
 	 */
 	@Transient
 	private String examEndTime;
+
+	/**
+	 * 是否可上传
+     */
+	private Boolean canUpload;
 	
 	public static long getSerialVersionUID() {
 		return serialVersionUID;
@@ -433,4 +438,12 @@ public class ExamStudent implements Serializable {
 	public void setExamEndTime(String examEndTime) {
 		this.examEndTime = examEndTime;
 	}
+
+	public Boolean getCanUpload() {
+		return canUpload;
+	}
+
+	public void setCanUpload(Boolean canUpload) {
+		this.canUpload = canUpload;
+	}
 }