Beispiel #1
0
 /**
  * 获取数据
  *
  * @return
  */
 @SuppressWarnings("unchecked")
 public String getData() {
   try {
     if (model.getTitleName().equals("undefined")) {
       model.setTitleName("");
     }
     titles = titleService.findTitlePage(currentPage, 10, model.getTitleName());
     List<Title> list = (List<Title>) titles.getRecordList();
     List<TitleVO> titleVOs = new ArrayList<TitleVO>();
     for (Title title : list) {
       titleVOs.add(PO2VO(title));
     }
     titles.setRecordList(titleVOs);
     JSONprint(JSONSupport.json(titles));
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Beispiel #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";
  }