Ejemplo n.º 1
0
  @Transactional
  @Override
  public QuestionVote vote(QuestionVote bean) {
    QuestionVote vote = new QuestionVote();
    vote.setId(-1l);
    if (bean.getQuestion() == null || bean.getUser() == null) {
      return vote;
    }
    Finder finder = Finder.create();
    finder.append("from QuestionVote q where q.user.id = :uid ");
    finder.setParam("uid", bean.getUser().getId());
    finder.append(" and q.question.id = :aid");
    finder.setParam("aid", bean.getQuestion().getId());
    List<QuestionVote> vs = dao.find(finder);
    if (vs != null && vs.size() > 0) {

    } else {
      vote = dao.save(bean);
    }
    Finder coutfinder = Finder.create();
    coutfinder.append("from QuestionVote q where q.question.id=:aid");
    coutfinder.setParam("aid", bean.getQuestion().getId());
    int size = dao.countQueryResult(coutfinder);
    QuestionAnswer answer = answerDao.findById(bean.getQuestion().getId());
    if (answer != null) {
      answer.setUps(size);
    }
    return vote;
  }
Ejemplo n.º 2
0
 @Transactional(readOnly = true)
 public UserMessagePage getPage(int pageNo, int pageSize) {
   UserMessagePage result = null;
   Finder finder = Finder.create();
   finder.append("from UserMessage f ");
   finder.append(" order by f.id desc  ");
   Pagination<UserMessage> page = dao.find(finder, pageNo, pageSize);
   result = new UserMessagePage(page);
   return result;
 }