示例#1
0
  /**
   * 完成线上任务
   *
   * @param onTaskId 线上任务ID
   * @param request
   * @param response POST不要使用@PathVariable
   * @return
   */
  @RequestMapping(value = "onlinecomplete")
  public String onlineComplete(
      String onTaskId, HttpServletRequest request, HttpServletResponse response) {
    PgOnlineTask onlineTask = pgOnlineTaskService.get(onTaskId); // 线上任务

    String onlineCheck = request.getParameter("answerChk"); // 用户选择的答案(ID)
    PgAnswer answer = pgAnswerService.get(onlineCheck); // 答案对象
    if (answer != null && answer.getRightOrNot().equals("1")) {
      onlineTask.setRightOrNot("1"); // 答案是否正确(1:正确;0:错误)
      // 答题正确给予积分奖励
      PgTaskList taskList = pgTaskListService.get(onlineTask.getTaskId());
      PgOnlineQuestion onlineQuestion = pgOnlineQuestionService.get(taskList.getQuestionId());
      Integer integral = onlineQuestion.getBaseIntegral();
      // 构造方法PgIntegral(String integralDate,String integralType,Integer integral,User user)
      // 积分类型(integralType):0线上任务/1线下任务/2签到/3日记
      PgIntegral pi = new PgIntegral(DateUtils.getDateTime(), "0", integral, UserUtils.getUser());
      pi.setRemarks(onlineQuestion.getQuestion());
      pgIntegralService.save(pi);

    } else {
      onlineTask.setRightOrNot("0"); // 答案是否正确(1:正确;0:错误)
    }
    onlineTask.setOnlineTaskStatus("1"); // 状态:1 表示已完成
    onlineTask.setAnswerId(onlineCheck); // 用户选择的答案(ID)
    String answerType =
        ""; // 答题方式
            // 未完成***********************************-------------------------------------------

    // 更新"是否正确"
    pgOnlineTaskService.save(onlineTask); // 更新会员在线任务
    return "redirect:" + Global.getFrontPath() + "/task";
  }
示例#2
0
  /**
   * 开始(接受)线上任务
   *
   * @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
    }
  }