|
@@ -1,57 +1,90 @@
|
|
package cn.com.qmth.examcloud.exchange.outer.api.provider.swufe;
|
|
package cn.com.qmth.examcloud.exchange.outer.api.provider.swufe;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.http.HttpStatus;
|
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
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 com.google.common.collect.Maps;
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.DateUtil;
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.DateUtil.DatePatterns;
|
|
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.SaveExamException;
|
|
|
|
-import cn.com.qmth.examcloud.exchange.base.response.FailureBaseResponse;
|
|
|
|
-import cn.com.qmth.examcloud.exchange.base.response.SuccessBaseResponse;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.examwork.api.ExamCloudService;
|
|
|
|
+import cn.com.qmth.examcloud.examwork.api.request.GetExamReq;
|
|
|
|
+import cn.com.qmth.examcloud.examwork.api.request.SaveExamReq;
|
|
|
|
+import cn.com.qmth.examcloud.examwork.api.response.GetExamResp;
|
|
import cn.com.qmth.examcloud.exchange.dao.bean.ExamReq;
|
|
import cn.com.qmth.examcloud.exchange.dao.bean.ExamReq;
|
|
-import cn.com.qmth.examcloud.exchange.dao.bean.OutletExam;
|
|
|
|
-import cn.com.qmth.examcloud.exchange.outer.service.ExamService;
|
|
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @author chenken
|
|
|
|
- * @date 2018年5月7日 下午3:20:33
|
|
|
|
- * @company QMTH
|
|
|
|
|
|
+ * @author chenken
|
|
|
|
+ * @date 2018年5月7日 下午3:20:33
|
|
|
|
+ * @company QMTH
|
|
* @description ExamController.java
|
|
* @description ExamController.java
|
|
*/
|
|
*/
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("${$rmp.cloud.exchange.outer}/exam")
|
|
@RequestMapping("${$rmp.cloud.exchange.outer}/exam")
|
|
-public class ExamController extends ControllerSupport{
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private ExamService examService;
|
|
|
|
-
|
|
|
|
|
|
+public class ExamController extends ControllerSupport {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ ExamCloudService examCloudService;
|
|
|
|
+
|
|
@ApiOperation(value = "创建考试")
|
|
@ApiOperation(value = "创建考试")
|
|
@PostMapping
|
|
@PostMapping
|
|
- public ResponseEntity<?> createExam(@RequestBody ExamReq examReq,HttpServletRequest request){
|
|
|
|
|
|
+ public Map<String, Object> createExam(@RequestBody ExamReq examReq,
|
|
|
|
+ HttpServletRequest request) {
|
|
|
|
+ tranTimes(examReq);
|
|
User accessUser = getAccessUser();
|
|
User accessUser = getAccessUser();
|
|
- if(accessUser == null){
|
|
|
|
- return new ResponseEntity<FailureBaseResponse>(new FailureBaseResponse("请先登录"), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
+ Long rootOrgId = accessUser.getRootOrgId();
|
|
|
|
+
|
|
|
|
+ SaveExamReq saveExamReq = new SaveExamReq();
|
|
|
|
+ saveExamReq.setBeginTime(DateUtil.parse(examReq.getBeginTime(), DatePatterns.ISO));
|
|
|
|
+ saveExamReq.setDuration(examReq.getDuration());
|
|
|
|
+ saveExamReq.setEndTime(DateUtil.parse(examReq.getEndTime(), DatePatterns.ISO));
|
|
|
|
+ saveExamReq.setExamType(examReq.getExamType());
|
|
|
|
+ saveExamReq.setName(examReq.getName());
|
|
|
|
+ saveExamReq.setRootOrgId(rootOrgId);
|
|
|
|
+ examCloudService.saveExam(saveExamReq);
|
|
|
|
+
|
|
|
|
+ GetExamReq req = new GetExamReq();
|
|
|
|
+ req.setName(examReq.getName());
|
|
|
|
+ req.setRootOrgId(rootOrgId);
|
|
|
|
+ GetExamResp resp = examCloudService.getExam(req);
|
|
|
|
+
|
|
|
|
+ Map<String, Object> map = Maps.newHashMap();
|
|
|
|
+ map.put("examId", resp.getId());
|
|
|
|
+ return map;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 方法注释
|
|
|
|
+ *
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ * @param examStudentImportDTO
|
|
|
|
+ */
|
|
|
|
+ private void tranTimes(ExamReq exam) {
|
|
|
|
+ String beginTime = exam.getBeginTime();
|
|
|
|
+ if (StringUtils.isNotBlank(beginTime)) {
|
|
|
|
+ beginTime = StringUtils.replace(beginTime, ".000Z", "");
|
|
|
|
+ beginTime = StringUtils.replace(beginTime, "T", " ");
|
|
|
|
+ exam.setBeginTime(beginTime);
|
|
}
|
|
}
|
|
- try {
|
|
|
|
- OutletExam exam = examService.createExam(examReq, accessUser.getUserToken(), accessUser.getRootOrgId());
|
|
|
|
- return new ResponseEntity<SuccessBaseResponse>(new SuccessBaseResponse("执行成功",exam), HttpStatus.OK);
|
|
|
|
- }catch(SaveExamException e){
|
|
|
|
- e.printStackTrace();
|
|
|
|
- return new ResponseEntity<FailureBaseResponse>(new FailureBaseResponse(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- return new ResponseEntity<FailureBaseResponse>(new FailureBaseResponse("创建失败"), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
+
|
|
|
|
+ String endTime = exam.getEndTime();
|
|
|
|
+ if (StringUtils.isNotBlank(endTime)) {
|
|
|
|
+ endTime = StringUtils.replace(endTime, ".000Z", "");
|
|
|
|
+ endTime = StringUtils.replace(endTime, "T", " ");
|
|
|
|
+ exam.setEndTime(endTime);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
+}
|