Exemplo n.º 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
    }
  }
Exemplo n.º 2
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";
  }
Exemplo n.º 3
0
 /**
  * 签收任务
  *
  * @param taskId 任务ID
  */
 @RequestMapping(value = "claim")
 @ResponseBody
 public String claim(Act act) {
   String userId =
       UserUtils.getUser().getLoginName(); // ObjectUtils.toString(UserUtils.getUser().getId());
   actTaskService.claim(act.getTaskId(), userId);
   return "true"; // adminPath + "/act/task";
 }
Exemplo n.º 4
0
 @Transactional(readOnly = false)
 public void saveRole(Role role) {
   if (role.getId() == null) {
     role.setUser(UserUtils.getUser());
   }
   roleDao.save(role);
   systemRealm.clearAllCachedAuthorizationInfo();
 }
Exemplo n.º 5
0
 public List<Role> findAllRole() {
   User currentUser = UserUtils.getUser();
   if (!currentUser.isAdmin()) {
     return roleDao.findByUserId(currentUser.getId());
   } else {
     return roleDao.findAllList();
   }
 }
Exemplo n.º 6
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
    }
  }
Exemplo n.º 7
0
 @Transactional(readOnly = false)
 public Page<Link> find(Page<Link> page, Link link, boolean isDataScopeFilter) {
   // 更新过期的权重,间隔为“6”个小时
   Date updateExpiredWeightDate = (Date) CacheUtils.get("updateExpiredWeightDateByLink");
   if (updateExpiredWeightDate == null
       || (updateExpiredWeightDate != null
           && updateExpiredWeightDate.getTime() < new Date().getTime())) {
     linkDao.updateExpiredWeight();
     CacheUtils.put("updateExpiredWeightDateByLink", DateUtils.addHours(new Date(), 6));
   }
   DetachedCriteria dc = linkDao.createDetachedCriteria();
   dc.createAlias("category", "category");
   dc.createAlias("category.site", "category.site");
   if (link.getCategory() != null
       && StringUtils.isNotBlank(link.getCategory().getId())
       && !Category.isRoot(link.getCategory().getId())) {
     Category category = categoryDao.get(link.getCategory().getId());
     if (category != null) {
       dc.add(
           Restrictions.or(
               Restrictions.eq("category.id", category.getId()),
               Restrictions.like("category.parentIds", "%," + category.getId() + ",%")));
       dc.add(Restrictions.eq("category.site.id", category.getSite().getId()));
       link.setCategory(category);
     } else {
       dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId()));
     }
   } else {
     dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId()));
   }
   if (StringUtils.isNotEmpty(link.getTitle())) {
     dc.add(Restrictions.like("title", "%" + link.getTitle() + "%"));
   }
   if (link.getCreateBy() != null && StringUtils.isNotBlank(link.getCreateBy().getId())) {
     dc.add(Restrictions.eq("createBy.id", link.getCreateBy().getId()));
   }
   if (isDataScopeFilter) {
     dc.createAlias("category.office", "categoryOffice").createAlias("createBy", "createBy");
     dc.add(dataScopeFilter(UserUtils.getUser(), "categoryOffice", "createBy"));
   }
   dc.add(Restrictions.eq(Link.FIELD_DEL_FLAG, link.getDelFlag()));
   dc.addOrder(Order.desc("weight"));
   dc.addOrder(Order.desc("updateDate"));
   return linkDao.find(page, dc);
 }
Exemplo n.º 8
0
 @Transactional(readOnly = false)
 public void saveMenu(Menu menu) {
   menu.setParent(this.getMenu(menu.getParent().getId()));
   String oldParentIds = menu.getParentIds(); // 获取修改前的parentIds,用于更新子节点的parentIds
   menu.setParentIds(menu.getParent().getParentIds() + menu.getParent().getId() + ",");
   if (menu.getId() == null) {
     menu.setUser(UserUtils.getUser());
   }
   menuDao.clear();
   menuDao.save(menu);
   // 更新子节点 parentIds
   List<Menu> list = menuDao.findByParentIdsLike("%," + menu.getId() + ",%");
   for (Menu e : list) {
     e.setParentIds(e.getParentIds().replace(oldParentIds, menu.getParentIds()));
   }
   menuDao.save(list);
   systemRealm.clearAllCachedAuthorizationInfo();
 }
Exemplo n.º 9
0
 public Page<User> findUser(Page<User> page, User user) {
   DetachedCriteria dc = userDao.createDetachedCriteria();
   User currentUser = UserUtils.getUser();
   if (!currentUser.isAdmin()) {
     if (user.getArea() == null || user.getArea().getId() == null) {
       user.setArea(currentUser.getArea());
     }
     if (user.getOffice() == null || user.getOffice().getId() == null) {
       user.setOffice(currentUser.getOffice());
     }
   }
   dc.createAlias("area", "area");
   if (user.getArea() != null && user.getArea().getId() != null) {
     dc.add(
         Restrictions.or(
             Restrictions.eq("area.id", user.getArea().getId()),
             Restrictions.eq("area.parent.id", user.getArea().getId()),
             Restrictions.like("area.parentIds", "%," + user.getArea().getId() + ",%")));
   }
   dc.createAlias("office", "office");
   if (user.getOffice() != null && user.getOffice().getId() != null) {
     dc.add(
         Restrictions.or(
             Restrictions.eq("office.id", user.getOffice().getId()),
             Restrictions.eq("office.parent.id", user.getOffice().getId()),
             Restrictions.like("office.parentIds", "%," + user.getOffice().getId() + ",%")));
   }
   if (StringUtils.isNotEmpty(user.getLoginName())) {
     dc.add(Restrictions.like("loginName", "%" + user.getLoginName() + "%"));
   }
   if (StringUtils.isNotEmpty(user.getName())) {
     dc.add(Restrictions.like("name", "%" + user.getName() + "%"));
   }
   dc.add(Restrictions.eq("delFlag", User.DEL_FLAG_NORMAL));
   if (!StringUtils.isNotEmpty(page.getOrderBy())) {
     dc.addOrder(Order.asc("area.code")).addOrder(Order.asc("office.code"));
   }
   return userDao.find(page, dc);
 }
Exemplo n.º 10
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";
  }
Exemplo n.º 11
0
  /**
   * 我接受的任务列表
   *
   * @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";
  }