コード例 #1
0
ファイル: QuestionAction.java プロジェクト: hemoye/doIT
  @SuppressWarnings("unchecked")
  public String show() {
    // test user
    User user = getCurrentUser();
    ActionContext.getContext().put("luser", user);
    // 该问题
    Userpost userpost = userPostService.findById(questionId);
    Integer cnum = userpost.getClickNumber();
    if (cnum == null) cnum = 0;
    userpost.setClickNumber(cnum + 1);
    userPostService.update(userpost);
    ActionContext.getContext().getValueStack().push(userpost);

    // 标签云
    List<Postlabel> postlabels = labelService.findAll();
    ActionContext.getContext().put("postlabels", postlabels);
    // 相关问题
    List<Userpost> userposts = userPostService.findByType(userpost.getPostlabel(), 5);
    userposts.remove(userpost);
    ActionContext.getContext().put("userposts", 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);

    // 采纳
    Reply adoptReply = null;
    Set<Reply> replies = (Set<Reply>) userpost.getReplies();
    for (Reply r : replies) {
      if (r.getStatus() == 2) {
        adoptReply = r;
        continue;
      }
      if (r.getStatus() == 0) {
        r.setStatus(1);
        replyService.update(r);
      }
    }
    // 新提问
    int questionNum = userPostService.getQuestionNum(user.getUserId());
    ActionContext.getContext().put("questionNum", questionNum);
    // 新回复
    int replyNum = userPostService.getReplyNum(user.getUserId());
    ActionContext.getContext().put("replyNum", replyNum);

    ActionContext.getContext().put("adoptReply", adoptReply);
    return "show";
  }
コード例 #2
0
ファイル: QuestionAction.java プロジェクト: hemoye/doIT
 // 回复
 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();
   }
 }
コード例 #3
0
ファイル: QuestionAction.java プロジェクト: hemoye/doIT
  @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";
  }