wangwei 7 år sedan
förälder
incheckning
8559cf9556

+ 108 - 44
examcloud-exchange-outer-api-provider/src/main/java/cn/com/qmth/examcloud/exchange/outer/api/provider/sydx/StudentExamInfoController.java

@@ -1,6 +1,5 @@
 package cn.com.qmth.examcloud.exchange.outer.api.provider.sydx;
 
-
 import cn.com.qmth.examcloud.commons.web.security.bean.User;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.exchange.base.exception.NoSuchCourseLevelException;
@@ -11,12 +10,16 @@ import cn.com.qmth.examcloud.exchange.base.response.FailureBaseResponse;
 import cn.com.qmth.examcloud.exchange.base.response.IBaseResponse;
 import cn.com.qmth.examcloud.exchange.base.response.SuccessBaseResponse;
 import cn.com.qmth.examcloud.exchange.dao.bean.ExamStudentImportDTO;
+import cn.com.qmth.examcloud.exchange.dao.bean.OutletExam;
+import cn.com.qmth.examcloud.exchange.dao.bean.OutletExamStudent;
 import cn.com.qmth.examcloud.exchange.outer.service.ExamStudentImportService;
 
 import com.alibaba.fastjson.JSON;
 
 import io.swagger.annotations.ApiOperation;
 
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -27,55 +30,116 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+
 import javax.servlet.http.HttpServletRequest;
 
 /**
  * 石油大学专用-接收考生数据接口
- * @author  	chenken
- * @date    	2018年4月3日 下午3:57:42
- * @company 	QMTH
+ * 
+ * @author chenken
+ * @date 2018年4月3日 下午3:57:42
+ * @company QMTH
  * @description StudentExamInfoController.java
  */
 @RestController
 @RequestMapping("${$rmp.cloud.exchange.outer}/sydx/import_exam_student_info")
-public class StudentExamInfoController  extends ControllerSupport{
-
-    private static final Logger LOG = LoggerFactory.getLogger(StudentExamInfoController.class);
-
-    @Autowired
-    private ExamStudentImportService examStudentImportService;
-
-    @ApiOperation(value = "石油大学使用:创建考试和导入学生")
-    @PostMapping
-    public ResponseEntity<IBaseResponse> post(@RequestBody ExamStudentImportDTO examStudentImportDTO,
-                                              HttpServletRequest request) {
-    	User accessUser = getAccessUser();
-        if(accessUser == null){
-        	return new ResponseEntity<>(new FailureBaseResponse("检测到用户为空,请先登录", null), HttpStatus.INTERNAL_SERVER_ERROR);
-        }
-        try {
-            LOG.info("请求参数是:" + JSON.toJSONString(examStudentImportDTO));
-        } catch (Exception e) {
-        }
-        Long rootOrgId = accessUser.getRootOrgId();
-        if (rootOrgId == null) {
-            return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
-        }
-        try {
-            Long examId = examStudentImportService.save(accessUser.getUserToken(), rootOrgId, examStudentImportDTO);
-            return new ResponseEntity<>(new SuccessBaseResponse("", examId), HttpStatus.OK);
-        } catch (NoSuchCourseLevelException e) {
-            LOG.error("课程级别不存在", e);
-            return new ResponseEntity<>(new FailureBaseResponse("课程级别不存在", null), HttpStatus.INTERNAL_SERVER_ERROR);
-        } catch (NoSuchExamException e) {
-            LOG.error("考试不存在", e);
-            return new ResponseEntity<>(new FailureBaseResponse("考试不存在", null), HttpStatus.INTERNAL_SERVER_ERROR);
-        } catch (SaveExamException e) {
-            LOG.error("创建考试失败", e);
-            return new ResponseEntity<>(new FailureBaseResponse("创建考试失败,可能该考试名称已经存在", null), HttpStatus.INTERNAL_SERVER_ERROR);
-        } catch (SaveExamStudentException e) {
-            LOG.error("创建考生失败", e);
-            return new ResponseEntity<>(new FailureBaseResponse("创建考生失败,可能该考生信息已经存在", null), HttpStatus.INTERNAL_SERVER_ERROR);
-        }
-    }
+public class StudentExamInfoController extends ControllerSupport {
+
+	private static final Logger LOG = LoggerFactory.getLogger(StudentExamInfoController.class);
+
+	@Autowired
+	private ExamStudentImportService examStudentImportService;
+
+	@ApiOperation(value = "石油大学使用:创建考试和导入学生")
+	@PostMapping
+	public ResponseEntity<IBaseResponse> post(
+			@RequestBody ExamStudentImportDTO examStudentImportDTO, HttpServletRequest request) {
+
+		tranTimes(examStudentImportDTO);
+
+		User accessUser = getAccessUser();
+		if (accessUser == null) {
+			return new ResponseEntity<>(new FailureBaseResponse("检测到用户为空,请先登录", null),
+					HttpStatus.INTERNAL_SERVER_ERROR);
+		}
+		try {
+			LOG.info("请求参数是:" + JSON.toJSONString(examStudentImportDTO));
+		} catch (Exception e) {
+		}
+		Long rootOrgId = accessUser.getRootOrgId();
+		if (rootOrgId == null) {
+			return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
+		}
+		try {
+			Long examId = examStudentImportService.save(accessUser.getUserToken(), rootOrgId,
+					examStudentImportDTO);
+			return new ResponseEntity<>(new SuccessBaseResponse("", examId), HttpStatus.OK);
+		} catch (NoSuchCourseLevelException e) {
+			LOG.error("课程级别不存在", e);
+			return new ResponseEntity<>(new FailureBaseResponse("课程级别不存在", null),
+					HttpStatus.INTERNAL_SERVER_ERROR);
+		} catch (NoSuchExamException e) {
+			LOG.error("考试不存在", e);
+			return new ResponseEntity<>(new FailureBaseResponse("考试不存在", null),
+					HttpStatus.INTERNAL_SERVER_ERROR);
+		} catch (SaveExamException e) {
+			LOG.error("创建考试失败", e);
+			return new ResponseEntity<>(new FailureBaseResponse("创建考试失败,可能该考试名称已经存在", null),
+					HttpStatus.INTERNAL_SERVER_ERROR);
+		} catch (SaveExamStudentException e) {
+			LOG.error("创建考生失败", e);
+			return new ResponseEntity<>(new FailureBaseResponse("创建考生失败,可能该考生信息已经存在", null),
+					HttpStatus.INTERNAL_SERVER_ERROR);
+		}
+	}
+
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param examStudentImportDTO
+	 */
+	private void tranTimes(ExamStudentImportDTO examStudentImportDTO) {
+		OutletExam exam = examStudentImportDTO.getExam();
+
+		String beginTime = exam.getBeginTime();
+		if (StringUtils.isNotBlank(beginTime)) {
+			beginTime = StringUtils.replace(beginTime, "Z", "");
+			beginTime = StringUtils.replace(beginTime, "T", " ");
+			exam.setBeginTime(beginTime);
+		}
+
+		String endTime = exam.getEndTime();
+		if (StringUtils.isNotBlank(endTime)) {
+			endTime = StringUtils.replace(endTime, "Z", "");
+			endTime = StringUtils.replace(endTime, "T", " ");
+			exam.setEndTime(endTime);
+		}
+
+		List<OutletExamStudent> examStudentList = examStudentImportDTO.getExamStudentList();
+		if (CollectionUtils.isNotEmpty(examStudentList)) {
+
+			for (OutletExamStudent cur : examStudentList) {
+				OutletExam curExam = cur.getExam();
+				if (null == curExam) {
+					continue;
+				}
+				String b = curExam.getBeginTime();
+				if (StringUtils.isNotBlank(b)) {
+					b = StringUtils.replace(b, "Z", "");
+					b = StringUtils.replace(b, "T", " ");
+					curExam.setBeginTime(b);
+				}
+
+				String e = curExam.getEndTime();
+				if (StringUtils.isNotBlank(e)) {
+					e = StringUtils.replace(e, "Z", "");
+					e = StringUtils.replace(e, "T", " ");
+					curExam.setEndTime(e);
+				}
+			}
+		}
+	}
+
 }

+ 40 - 39
examcloud-exchange-outer-dao/src/main/java/cn/com/qmth/examcloud/exchange/dao/bean/OutletExam.java

@@ -1,15 +1,14 @@
 package cn.com.qmth.examcloud.exchange.dao.bean;
 
-
-import cn.com.qmth.examcloud.common.dto.em.enums.ExamType;
-import cn.com.qmth.examcloud.common.dto.em.enums.MarkingType;
-import cn.com.qmth.examcloud.common.dto.em.enums.PracticeType;
-
 import java.io.Serializable;
 import java.util.Date;
 
 import javax.validation.constraints.NotNull;
 
+import cn.com.qmth.examcloud.common.dto.em.enums.ExamType;
+import cn.com.qmth.examcloud.common.dto.em.enums.MarkingType;
+import cn.com.qmth.examcloud.common.dto.em.enums.PracticeType;
+
 public class OutletExam implements Serializable {
 
 	private static final long serialVersionUID = -1674026406657304645L;
@@ -28,33 +27,34 @@ public class OutletExam implements Serializable {
 
 	/**
 	 * 考试批次开始时间
-     */
-	private Date beginTime;
+	 */
+	private String beginTime;
 
 	/**
 	 * 考试批次结束时间
-     */
-	private Date endTime;
+	 */
+	private String endTime;
 
 	/**
 	 * 考试名称
-     */
+	 */
 	private String name;
 
 	/**
 	 * 考试类型
-     */
+	 */
 	private ExamType examType;
 
 	/**
 	 * 是否入学考试
-     */
+	 */
 	private Boolean isEntranceExam;
 
 	/**
 	 * 考试时长
 	 */
 	private Integer duration;
+
 	/**
 	 * 冻结时间
 	 */
@@ -62,50 +62,49 @@ public class OutletExam implements Serializable {
 
 	/**
 	 * 考试状态
-     */
+	 */
 	private String status;
 
-
 	private Boolean enable;
 
 	/**
 	 * 考试备注
-     */
+	 */
 	private String remark;
 
 	/**
 	 * 创建时间
-     */
+	 */
 	private Date createTime;
 
 	/**
 	 * 考试次数
-     */
+	 */
 	private Long examTimes;
 
 	/**
 	 * 断点续考时间(秒)
-     */
+	 */
 	private Long examReconnectTime;
 
 	/**
 	 * 考前说明
-     */
+	 */
 	private String beforeExamRemark;
 
 	/**
 	 * 考后说明
-     */
+	 */
 	private String afterExamRemark;
 
 	/**
 	 * 是否显示成绩
-     */
+	 */
 	private String isObjScoreView;
 
 	/**
 	 * 练习模式
-     */
+	 */
 	private PracticeType practiceType;
 
 	/**
@@ -130,27 +129,27 @@ public class OutletExam implements Serializable {
 
 	/**
 	 * 单选题补充说明
-     */
+	 */
 	private String singleAnswerRemark;
 
 	/**
 	 * 多选题补充说明
-     */
+	 */
 	private String mutipleAnswerRemark;
 
 	/**
 	 * 判断题补充说明
-     */
+	 */
 	private String boolAnswerRemark;
 
 	/**
 	 * 填空题补充说明
-     */
+	 */
 	private String fillBlankRemark;
 
 	/**
 	 * 问答题补充说明
-     */
+	 */
 	private String textAnswerRemark;
 
 	/**
@@ -160,43 +159,45 @@ public class OutletExam implements Serializable {
 
 	/**
 	 * 是否启用人脸识别
-     */
+	 */
 	private String isFaceEnable;
 
 	/**
 	 * 进入考试是否验证人脸识别(强制、非强制)
-     */
+	 */
 	private String isFaceCheck;
 
 	/**
 	 * 抓拍间隔
-     */
+	 */
 	private Double snapshotInterval;
 
 	/**
 	 * 预警阈值
-     */
+	 */
 	private Double warnThreshold;
 
 	/**
 	 * 阅卷方式
-     */
+	 */
 	private MarkingType markingType;
 
 	/**
 	 * 学生是否可以删除
-     */
+	 */
 	@NotNull
 	private Boolean canStuDel;
-	
+
 	/**
 	 * 是否开启人脸活体检测
 	 */
 	private Boolean isFaceVerify;
+
 	/**
 	 * 活体检测开始分钟数
 	 */
 	private Integer faceVerifyStartMinute;
+
 	/**
 	 * 活体检测结束分钟数
 	 */
@@ -226,19 +227,19 @@ public class OutletExam implements Serializable {
 		this.rootOrgId = rootOrgId;
 	}
 
-	public Date getBeginTime() {
+	public String getBeginTime() {
 		return beginTime;
 	}
 
-	public void setBeginTime(Date beginTime) {
+	public void setBeginTime(String beginTime) {
 		this.beginTime = beginTime;
 	}
 
-	public Date getEndTime() {
+	public String getEndTime() {
 		return endTime;
 	}
 
-	public void setEndTime(Date endTime) {
+	public void setEndTime(String endTime) {
 		this.endTime = endTime;
 	}
 
@@ -489,7 +490,7 @@ public class OutletExam implements Serializable {
 	public void setEntranceExam(Boolean entranceExam) {
 		isEntranceExam = entranceExam;
 	}
-	
+
 	public Boolean getIsEntranceExam() {
 		return isEntranceExam;
 	}

+ 14 - 2
examcloud-exchange-outer-service/src/main/java/cn/com/qmth/examcloud/exchange/outer/service/impl/ExamServiceImpl.java

@@ -1,5 +1,6 @@
 package cn.com.qmth.examcloud.exchange.outer.service.impl;
 
+import java.util.Date;
 import java.util.List;
 
 import org.springframework.beans.factory.annotation.Autowired;
@@ -7,6 +8,8 @@ import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 
 import cn.com.qmth.examcloud.common.dto.em.enums.ExamType;
+import cn.com.qmth.examcloud.commons.base.util.DateUtil;
+import cn.com.qmth.examcloud.commons.base.util.DateUtil.DatePatterns;
 import cn.com.qmth.examcloud.exchange.base.exception.SaveExamException;
 import cn.com.qmth.examcloud.exchange.dao.bean.ExamReq;
 import cn.com.qmth.examcloud.exchange.dao.bean.OutletExam;
@@ -35,8 +38,17 @@ public class ExamServiceImpl implements ExamService {
             exam = examListResp.getBody().get(0);
         } else {
         	exam.setName(examReq.getName());
-        	exam.setBeginTime(examReq.getBeginTime());
-        	exam.setEndTime(examReq.getEndTime());
+        	
+        	Date beginTime = examReq.getBeginTime();
+        	if (null!=beginTime) {
+        		exam.setBeginTime(DateUtil.format(beginTime, DatePatterns.ISO));
+			}
+        	
+        	Date endTime = examReq.getEndTime();
+        	if (null!=endTime) {
+        		exam.setEndTime(DateUtil.format(endTime, DatePatterns.ISO));
+			}
+        	
         	exam.setRemark(examReq.getName());//备注填考试名称
         	exam.setExamType(strToEnum(examReq.getExamType()));
         	exam.setDuration(examReq.getDuration());