/**
  * 获取热门文档
  *
  * @return
  */
 private List<Document> getHotDoc() {
   List<Want> wantList = wantService.getByGroup();
   List<Document> hotDocList = new ArrayList<Document>();
   for (Want want : wantList) {
     hotDocList.add(documentService.getById(want.getDocid()));
   }
   return hotDocList;
 }
 /**
  * 修改页面转发
  *
  * @param session
  * @param model
  * @param docid
  * @return
  */
 @RequestMapping(params = "method=modify", method = RequestMethod.GET)
 public String modify(HttpSession session, Model model, Integer docid) {
   User user = (User) session.getAttribute("user");
   if (user != null) {
     Document document = documentService.getById(docid);
     model.addAttribute("document", document);
     model.addAttribute("user", user);
     return "document/modify";
   } else return "error";
 }
  /**
   * 删除Controller
   *
   * @param session
   * @param model
   * @param docid
   * @return
   */
  @RequestMapping(params = "method=delete", method = RequestMethod.GET)
  public String delete(HttpSession session, Model model, Integer docid) {
    User user = (User) session.getAttribute("user");
    if (user != null) {
      Document document = documentService.getById(docid);

      documentService.delete(docid);
      // 回滚积分
      retPoint(user, document);

      model.addAttribute("user", user);
      return "redirect:document?method=list";
    } else return "error";
  }
  /**
   * 显示详细内容
   *
   * @param session
   * @param model
   * @param docid
   * @return
   */
  @RequestMapping(params = "method=show", method = RequestMethod.GET)
  public String show(HttpSession session, Model model, int docid, Pager<Comment> paraPage) {
    User user = (User) session.getAttribute("user");
    if (user != null) {
      Document document = documentService.getById(docid);
      if (document != null) {
        if (paraPage == null) paraPage = new Pager<Comment>();
        int totleCount = commentService.getAllCount(docid);

        Pager<Comment> page =
            new Pager<Comment>(totleCount, paraPage.getCurPage(), paraPage.getCountPerPage());
        List<Comment> commentList =
            commentService.getByPage(page.getStartCount(), page.getCountPerPage(), docid);
        if (commentList.isEmpty()) model.addAttribute("msg", "当前还没人翻译,译一下");
        else {
          // 为comment设置User字段
          for (Comment comment : commentList) {
            comment.setUser(userService.getByKey(comment.getUserid()));
            comment.setLikeTime(loveService.CountByComment(comment.getComid()));
            // 如果当前session与该评论的user相同,则可以删除
            if (comment.getUserid().equals(user.getUserid())) comment.setCanDel("1");
          }

          Comment comment = commentService.getByDocAndAc(document.getDocid());
          // 还没接受则可以接受
          if (comment == null) {
            // 如果当前session与此篇文档的用户相同,则可以进行接受操作
            if (document.getUserid().equals(user.getUserid())) model.addAttribute("canAcc", "1");
          } else {
            comment.setUser(userService.getByKey(comment.getUserid()));
            comment.setLikeTime(loveService.CountByComment(comment.getComid()));
            if (comment.getUserid().equals(user.getUserid())) comment.setCanDel("1");
            model.addAttribute("accComment", comment);
          }

          page.settList(commentList);
          model.addAttribute("msg", "已有翻译");
        }
        model.addAttribute("page", page);
        User author = userService.getByKey(document.getUserid());
        model.addAttribute("user", user);
        model.addAttribute("document", document);
        model.addAttribute("author", author);
        model.addAttribute("wantCount", wantService.countByDoc(docid));
        return "document/show";
      }
    }
    return "error";
  }