Exemple #1
0
 // 回复
 public void answer() {
   Reply reply = new Reply();
   // test user
   User user = getCurrentUser();
   reply.setUser(user);
   if (questionId != null) {
     Userpost question = userPostService.findById(questionId); // 用户
     question.setReplyNumber(
         question.getReplyNumber() == null ? 1 : question.getReplyNumber() + 1);
     reply.setUserpost(question);
   }
   if (replyContext.matches("回复  .+: ?(.*)")) {
     replyContext = replyContext.replaceAll("回复  .+: ?(.*)", "$1");
   }
   reply.setReplyContext(replyContext);
   reply.setReplyNumber(0);
   // 用户回帖数加1
   Userinfo userinfo = reply.getUser().getUserinfo();
   userinfo.setReplyNumber(userinfo.getReplyNumber() == null ? 1 : userinfo.getReplyNumber() + 1);
   if (replyFatherId != null) {
     reply.setReply(replyService.findById(replyFatherId));
   }
   reply.setReplyTime(new Timestamp(System.currentTimeMillis()));
   reply.setStatus(0); // 有新回复
   replyService.save(reply);
   ReplyVO replyVO = new ReplyVO();
   MyBeanUtils.copy(replyVO, reply);
   if (reply.getReply() != null) {
     replyVO.setUserName(reply.getReply().getUser().getUserName());
   }
   UserVO userVO = new UserVO();
   MyBeanUtils.copy(userVO, reply.getUser());
   replyVO.setUserVO(userVO);
   Json json = new Json();
   json.setSuccess(true);
   json.setObj(replyVO);
   try {
     JSONprint(JSONSupport.json(json));
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemple #2
0
  @SuppressWarnings("unchecked")
  public String index() {
    // test user
    User user = getCurrentUser();
    ActionContext.getContext().put("luser", user);

    ActionContext.getContext().put("questionState", questionState);
    ActionContext.getContext().put("labelId", labelId);

    if (user != null) {
      // 新提问
      int questionNum = userPostService.getQuestionNum(user.getUserId());
      ActionContext.getContext().put("questionNum", questionNum);
      // 新回复
      int replyNum = userPostService.getReplyNum(user.getUserId());
      ActionContext.getContext().put("replyNum", replyNum);
    }

    // 标签云
    List<Postlabel> postlabels = labelService.findAll();
    ActionContext.getContext().put("postlabels", postlabels);
    // 热门问题
    List<Userpost> userposts = userPostService.topPosts(5);
    ActionContext.getContext().put("topposts", userposts);
    // 雷锋榜
    List<User> users = (List<User>) userService.topByReplys(1, 6).getRecordList();
    ActionContext.getContext().put("users", users);
    // 等级称号
    List<Title> titles = titleService.findAll();
    ActionContext.getContext().put("titles", titles);

    // 分页
    Map<String, Object> filterMap = new HashMap<String, Object>();
    if (labelId != 0) {
      filterMap.put("labelId=?", labelId);
    }
    Map<String, Boolean> orderMap = new HashMap<String, Boolean>();
    if (questionState == TOPNEW) {
      orderMap.put("postTime", false);
    } else if (questionState == TOPHOT) {
      orderMap.put("clickNumber", false);
    } else if (questionState == QUESWAIT) {
      orderMap.put("postTime", false);
      filterMap.put("replyNumber is NULL", null);
    }
    PageBean page = userPostService.findPage(pageNum, pageSize, filterMap, orderMap);
    ActionContext.getContext().getValueStack().push(page);

    // replyVO
    List<ReplyVO> replyVOs = new ArrayList<ReplyVO>();
    List<Userpost> questions = (List<Userpost>) page.getRecordList();
    for (int i = 0; i < questions.size(); i++) {
      Userpost question = questions.get(i);
      if (question.getReplyNumber() == null || question.getReplyNumber() == 0) {
        replyVOs.add(null);
      } else {
        List<Reply> replies = new ArrayList<Reply>(question.getReplies());
        int m = -1;
        ReplyVO replyVO = new ReplyVO();
        for (int j = 0; j < replies.size(); j++) {
          Reply reply = replies.get(j);
          if (reply.getStatus() == 2) { // 采纳
            m = j;
            break;
          }
        }
        if (m == -1) {
          m = replies.size() - 1;
        }
        Reply reply = replies.get(m);
        UserVO userVO = new UserVO();
        MyBeanUtils.copy(userVO, reply.getUser());
        MyBeanUtils.copy(replyVO, reply);
        replyVO.setUserHead(reply.getUser().getUserHead());
        replyVO.setUserName(reply.getUser().getUserName());
        replyVO.setUserVO(userVO);
        replyVOs.add(replyVO);
      }
    }
    ActionContext.getContext().put("replyVOs", replyVOs);
    return "index";
  }