Examples of CmsVoteTopic


Examples of com.jeecms.cms.entity.assist.CmsVoteTopic

  @SuppressWarnings("unchecked")
  public void execute(Environment env, Map params, TemplateModel[] loopVars,
      TemplateDirectiveBody body) throws TemplateException, IOException {
    CmsSite site = FrontUtils.getSite(env);
    CmsVoteTopic vote;
    Integer id = getId(params);
    if (id != null) {
      vote = cmsVoteTopicMng.findById(id);
    } else {
      Integer siteId = getSiteId(params);
View Full Code Here

Examples of com.jeecms.cms.entity.assist.CmsVoteTopic

  @RequestMapping(value = "/vote_result.jspx", method = RequestMethod.GET)
  public String result(Integer voteId, HttpServletRequest request,
      HttpServletResponse response, ModelMap model) {
    CmsSite site = CmsUtils.getSite(request);
    CmsVoteTopic vote = cmsVoteTopicMng.findById(voteId);
    model.addAttribute("vote", vote);
    FrontUtils.frontData(request, model, site);
    return FrontUtils.getTplPath(request, site.getSolutionPath(),
        TPLDIR_SPECIAL, VOTE_RESULT);
  }
View Full Code Here

Examples of com.jeecms.cms.entity.assist.CmsVoteTopic

  @RequestMapping(value = "/vote.jspx", method = RequestMethod.GET)
  public String input(Integer voteId, HttpServletRequest request,
      HttpServletResponse response, ModelMap model) {
    CmsSite site = CmsUtils.getSite(request);
    CmsVoteTopic vote = cmsVoteTopicMng.findById(voteId);
    model.addAttribute("vote", vote);
    FrontUtils.frontData(request, model, site);
    return FrontUtils.getTplPath(request, site.getSolutionPath(),
        TPLDIR_SPECIAL, VOTE_INPUT);
  }
View Full Code Here

Examples of com.jeecms.cms.entity.assist.CmsVoteTopic

            "-");
        // 写cookie
        CookieUtils.addCookie(request, response, cookieName,
            cookieValue, Integer.MAX_VALUE, null);
      }
      CmsVoteTopic vote = cmsVoteTopicMng.vote(voteId, itemIds, user, ip,
          cookieValue);
      model.addAttribute("status", 0);
      model.addAttribute("vote", vote);

      log.info("vote CmsVote id={}, name={}", vote.getId(), vote
          .getTitle());
    }
    FrontUtils.frontData(request, model, site);
    return FrontUtils.getTplPath(request, site.getSolutionPath(),
        TPLDIR_SPECIAL, VOTE_RESULT);
View Full Code Here

Examples of com.jeecms.cms.entity.assist.CmsVoteTopic

    if (itemIds == null || itemIds.length <= 0) {
      model.addAttribute("status", 2);
      return true;
    }

    CmsVoteTopic topic = cmsVoteTopicMng.findById(topicId);
    // 投票主题不存在
    if (topic == null) {
      model.addAttribute("status", 100);
      return true;
    }
    // 投票项不合法
    boolean contains;
    for (Integer itemId : itemIds) {
      contains = false;
      for (CmsVoteItem item : topic.getItems()) {
        if (item.getId().equals(itemId)) {
          contains = true;
          break;
        }
      }
      if (!contains) {
        model.addAttribute("status", 101);
        return true;
      }
    }

    // 需要登录才能投票
    if (topic.getRestrictMember() && user == null) {
      model.addAttribute("status", 501);
      return true;
    }

    // 投票主题已经关闭
    if (topic.getDisabled()) {
      model.addAttribute("status", 200);
      return true;
    }
    // 投票的选项个数大于允许的个数
    if (itemIds.length > topic.getMultiSelect()) {
      model.addAttribute("status", 201);
      return true;
    }
    long now = System.currentTimeMillis();
    // 投票还没有开始
    Date start = topic.getStartTime();
    if (start != null && now < start.getTime()) {
      model.addAttribute("status", 202);
      model.addAttribute("startTime", start);
      return true;
    }
    // 投票已经结束
    Date end = topic.getEndTime();
    if (end != null && now > end.getTime()) {
      model.addAttribute("status", 203);
      model.addAttribute("endTime", end);
      return true;
    }
    Integer hour = topic.getRepeateHour();
    if (hour == null || hour > 0) {
      Date vtime;
      // 规定时间内,同一会员不能重复投票
      if (topic.getRestrictMember()) {
        vtime = cmsVoteRecordMng.lastVoteTimeByUserId(user.getId(),
            topicId);
        if (hour == null
            || vtime.getTime() + hour * 60 * 60 * 1000 > now) {
          model.addAttribute("status", 204);
          return true;
        }
      }
      // 规定时间内,同一IP不能重复投票
      if (topic.getRestrictIp()) {
        vtime = cmsVoteRecordMng.lastVoteTimeByIp(ip, topicId);
        if (hour == null
            || vtime.getTime() + hour * 60 * 60 * 1000 > now) {
          model.addAttribute("status", 205);
          return true;
        }
      }
      // 规定时间内,同一COOKIE不能重复投票
      if (topic.getRestrictCookie() && cookie != null) {
        vtime = cmsVoteRecordMng.lastVoteTimeByCookie(cookie, topicId);
        if (hour == null
            || vtime.getTime() + hour * 60 * 60 * 1000 > now) {
          model.addAttribute("status", 206);
          return true;
View Full Code Here

Examples of com.jeecms.cms.entity.assist.CmsVoteTopic

  private boolean vldExist(Integer id, Integer siteId, WebErrors errors) {
    if (errors.ifNull(id, "id")) {
      return true;
    }
    CmsVoteTopic entity = manager.findById(id);
    if (errors.ifNotExist(entity, CmsVoteTopic.class, id)) {
      return true;
    }
    if (!entity.getSite().getId().equals(siteId)) {
      errors.notInSite(CmsVoteTopic.class, id);
      return true;
    }
    return false;
  }
View Full Code Here

Examples of com.jeecms.cms.entity.assist.CmsVoteTopic

    return page;
  }

  @Transactional(readOnly = true)
  public CmsVoteTopic findById(Integer id) {
    CmsVoteTopic entity = dao.findById(id);
    return entity;
  }
View Full Code Here

Examples of com.jeecms.cms.entity.assist.CmsVoteTopic

    return bean;
  }

  public CmsVoteTopic vote(Integer topicId, Integer[] itemIds, CmsUser user,
      String ip, String cookie) {
    CmsVoteTopic topic = findById(topicId);
    Set<CmsVoteItem> items = topic.getItems();
    int totalCount = topic.getTotalCount();
    for (CmsVoteItem item : items) {
      if (ArrayUtils.contains(itemIds, item.getId())) {
        item.setVoteCount(item.getVoteCount() + 1);
        totalCount++;
      }
    }
    topic.setTotalCount(totalCount);
    // 如果需要限制投票,则需保存投票记录。
    if ((topic.getRepeateHour() == null || topic.getRepeateHour() > 0)
        && (topic.getRestrictMember() || topic.getRestrictIp() || topic
            .getRestrictCookie())) {
      cmsVoteRecordMng.save(topic, user, ip, cookie);
    }
    return topic;
  }
View Full Code Here

Examples of com.jeecms.cms.entity.assist.CmsVoteTopic

    }
    return topic;
  }

  public CmsVoteTopic deleteById(Integer id) {
    CmsVoteTopic bean = dao.deleteById(id);
    return bean;
  }
View Full Code Here

Examples of com.jeecms.cms.entity.assist.CmsVoteTopic

    f.setMaxResults(1);
    return (CmsVoteTopic) f.createQuery(getSession()).uniqueResult();
  }

  public CmsVoteTopic findById(Integer id) {
    CmsVoteTopic entity = get(id);
    return entity;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.