예제 #1
0
  // @RequiresPermissions("sys:user:edit")
  @RequestMapping(value = "begin-{taskId}${urlSuffix}")
  public void beginTask(
      @PathVariable String taskId,
      HttpServletRequest request,
      HttpServletResponse response,
      Model model)
      throws IOException {
    // 需要判断该任务是不是已经接受过了
    PgOfflineTask off = new PgOfflineTask(UserUtils.getUser(), taskId, null);
    List<PgOfflineTask> list = pgOfflineTaskService.findList(off);
    if (null != list && list.size() > 0) { // 任务已经领取
      // 如果已经接受任务,判断任务是否完成
      off = list.get(0);
      if (off.getOfflineStatus().equals("0")) {
        // status =0 表示任务未完成
        response.getWriter().print(off.getId()); // 返回线下任务的ID
      } else {
        response.getWriter().print("exist"); // 返回线下任务的ID
      }

    } else {
      // 点击"接受任务"/"开始任务"时,将任务信息和用户信息关联,并计算开始结束时间,最后返回线下任务的ID
      String status = "0"; // 未完成
      User user = UserUtils.getUser();
      PgOfflineTask offlineTask = new PgOfflineTask(user, taskId, status);
      pgOfflineTaskService.save(offlineTask);
      response.getWriter().print(offlineTask.getId()); // 返回线下任务的ID
    }
  }
예제 #2
0
  /**
   * 完成线下任务
   *
   * @param offTaskId
   * @param request
   * @param response
   * @param model
   * @return
   */
  @RequestMapping(value = "offlinecomplete")
  public String offlinecomplete(
      String offTaskId, HttpServletRequest request, HttpServletResponse response, Model model) {
    model.addAttribute("site", site);
    String feel = request.getParameter("feel");
    PgOfflineTask offlineTask = pgOfflineTaskService.get(offTaskId);
    offlineTask.setOfflineFeel(feel);
    offlineTask.setOfflineStatus("1"); // 状态:1 表示已完成
    // 保存线下任务
    pgOfflineTaskService.save(offlineTask);

    // 完成线下任务给予积分奖励
    PgTaskList taskList = pgTaskListService.get(offlineTask.getTaskId());
    PgOfflineQuestion offlineQuestion = pgOfflineQuestionService.get(taskList.getQuestionId());
    Integer integral = offlineQuestion.getBaseIntegral();
    // 构造方法PgIntegral(String integralDate,String integralType,Integer integral,User user)
    // 积分类型(integralType):0线上任务/1线下任务/2签到/3日记
    PgIntegral pi = new PgIntegral(DateUtils.getDateTime(), "1", integral, UserUtils.getUser());
    pi.setRemarks(offlineQuestion.getOfflineTask());
    // 累计线下任务积分
    pgIntegralService.save(pi);

    return "redirect:" + Global.getFrontPath() + "/task";
  }