@RequestMapping("/submitAnswer.do") public RestResult submitAnswer( HttpServletRequest request, HttpServletResponse response, Model model, @RequestParam(value = "id") int id, @RequestParam(value = "answer") String answer, @RequestParam(value = "type", required = false, defaultValue = "simulate") String type) { try { // TODO per type to choose session uuid String examSessionUUID = request.getSession().getAttribute(ExamPageAction.SESSION_SIMULATE_EXAM_ID).toString(); // TODO the openid of student,should get it from weixin api if (examService.getRemainingTime(examSessionUUID) <= 0) { return new RestResult("timeout"); } String openid = "aaa"; Student student = studentService.getByOpenid(openid); Exam exam = examService.getById(id); if (examSessionUUID == null || student == null || exam == null) { throw new RuntimeException("Invalid submitAnswer request"); } Answer a = new Answer(id, student.getId(), openid, answer, new Date()); examService.saveAnswer(examSessionUUID, a); Map<String, String> map = new HashMap<String, String>(); map.put("answer", exam.getAnswer()); return new RestResult("ok", map); } catch (Exception e) { logger.error("", e); return new RestResult("internal_error"); } }
@RequestMapping("/get.do") public RestResult get( HttpServletRequest request, HttpServletResponse response, Model model, @RequestParam(value = "id") int id) { try { Exam exam = examService.getById(id); return new RestResult("ok", exam); } catch (Exception e) { logger.error("", e); return new RestResult("internal_error"); } }