|
@@ -1,6 +1,5 @@
|
|
package cn.com.qmth.examcloud.exchange.outer.api.provider.sydx;
|
|
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.security.bean.User;
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
import cn.com.qmth.examcloud.exchange.base.exception.NoSuchCourseLevelException;
|
|
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.IBaseResponse;
|
|
import cn.com.qmth.examcloud.exchange.base.response.SuccessBaseResponse;
|
|
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.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 cn.com.qmth.examcloud.exchange.outer.service.ExamStudentImportService;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
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.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
import javax.servlet.http.HttpServletRequest;
|
|
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
|
|
* @description StudentExamInfoController.java
|
|
*/
|
|
*/
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("${$rmp.cloud.exchange.outer}/sydx/import_exam_student_info")
|
|
@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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|