/** * 开始(接受)线上任务 * * @param taskId * @param request * @param response * @param model * @return */ @RequestMapping(value = "onlineBegin-{taskId}${urlSuffix}") public void onlineBegin( @PathVariable String taskId, HttpServletRequest request, HttpServletResponse response, Model model) throws IOException { // 点击"接受任务"/"开始任务"时,将任务信息和用户信息关联,并计算开始结束时间,最后返回线下任务的ID // 需要判断该任务是不是已经接受过了 PgOnlineTask pot = new PgOnlineTask(taskId, UserUtils.getUser()); List<PgOnlineTask> list = pgOnlineTaskService.findList(pot); if (null != list && list.size() > 0) { // 任务已经领取 // 如果已经接受任务,判断任务是否完成 pot = list.get(0); if (pot.getOnlineTaskStatus().equals("0")) { // status =0 表示任务未完成 response.getWriter().print(pot.getId()); // 返回线上任务的ID } else { response.getWriter().print("exist"); // 返回线上任务的ID } } else { PgTaskList taskList = pgTaskListService.get(taskId); PgOnlineQuestion onlineQuestion = pgOnlineQuestionService.get(taskList.getQuestionId()); Integer timeLength = onlineQuestion.getTimeLength(); String status = "0"; // 未完成 User user = UserUtils.getUser(); // user:用户,taskId:任务ID,status:任务状态 answerBeginDate:任务开始时间, // answerEndDate:任务结束时间,answerId:答案ID,answerType:答题方式,rightOrNot:是否正确 Date answerBeginDate = new Date(); Date answerEndDate = new Date(answerBeginDate.getTime() + timeLength * 60 * 1000); // 任务结束时间 PgOnlineTask onlineTask = new PgOnlineTask(user, taskId, status, answerBeginDate, answerEndDate, null, null, null); pgOnlineTaskService.save(onlineTask); response.getWriter().print(onlineTask.getId()); // 返回线上任务的ID } }
/** * 我接受的任务列表 * * @param taskType * @param request * @param response * @param model * @return */ @RequestMapping(value = "list-{taskType}${urlSuffix}") public String taskList( @PathVariable String taskType, PgOnlineTask pgOnlineTask, PgOfflineTask pgOfflineTask, HttpServletRequest request, HttpServletResponse response, Model model) { model.addAttribute("site", site); // 0:线上任务,1:线下任务 Page p = null; Task task = null; List<Task> taskList = new ArrayList<Task>(); // 0:线上任务 if (taskType.equals("0") || taskType.equals("all")) { pgOnlineTask.setUser(UserUtils.getUser()); p = pgOnlineTaskService.findPage(new Page<PgOnlineTask>(request, response), pgOnlineTask); List<PgOnlineTask> list = p.getList(); if (null != list && list.size() > 0) { for (PgOnlineTask on : list) { PgOnlineQuestion onlineQuestion = pgOnlineQuestionService.get(pgTaskListService.get(on.getTaskId()).getQuestionId()); String id = on.getTaskId(); // 任务ID String questionId = onlineQuestion.getId(); String name = onlineQuestion.getQuestion(); String type = "0"; String status = on.getOnlineTaskStatus(); String time = DateUtils.formatDateTime(on.getCreateDate()); String userName = UserUtils.getUser().getName(); task = new Task(id, questionId, name, type, status, time, userName); taskList.add(task); } } } // 1:线下任务 if (taskType.equals("1") || taskType.equals("all")) { pgOfflineTask.setUser(UserUtils.getUser()); p = pgOfflineTaskService.findPage(new Page<PgOfflineTask>(request, response), pgOfflineTask); List<PgOfflineTask> list = p.getList(); if (null != list && list.size() > 0) { for (PgOfflineTask off : list) { PgOfflineQuestion offlineQuestion = pgOfflineQuestionService.get(pgTaskListService.get(off.getTaskId()).getQuestionId()); // public Task(String questionId,String name,String type,String time) String id = off.getTaskId(); String questionId = offlineQuestion.getId(); String name = offlineQuestion.getOfflineTask(); String type = "1"; String status = off.getOfflineStatus(); String time = DateUtils.formatDateTime(off.getCreateDate()); String userName = UserUtils.getUser().getName(); task = new Task(id, questionId, name, type, status, time, userName); taskList.add(task); } } } if (taskList.size() != 0) { Page<Task> page = pgTaskListService.findPage(new Page<Task>(request, response), task, taskList); model.addAttribute("page", page); } return "modules/cms/front/themes/" + site.getTheme() + "/myTaskList"; }