/** * 查询站点前n条评论和评论总数 * * @param sortKey 排序关键字 * @param desc 排序方式 * @param docId 文档ID * @param HttpServletRequest request * @return String * @throws Exception Exception */ public @ResponseBody(datatype = "jsonp") NComentList getSiteCommentNList( String site, int n, HttpServletRequest request, HttpServletResponse response) { try { Container container = new ContainerImpl(); // NComentList docCommentList = docCommentManager.getSiteCommnetList(n); container.init(site, request, request.getSession(), response); if (!CollectionUtils.isEmpty(docCommentList.getComments())) { for (DocComment docComment : docCommentList.getComments()) { String documentUrl = container.getPublishedDocumentUrl(new Integer(docComment.getDocId()).toString()); docComment.setDocUrl(documentUrl); } } return docCommentList; } catch (Exception e) { return null; } }
/** * 添加新评论 * * @param docId 文档ID * @param commentUser 评论用户名 * @param isGuest 是否是匿名用户 * @param docComment 评论内容 * @param status 评论状态 * @param request HttpServletRequest * @return String * @throws Exception */ public @ResponseBody(datatype = "jsonp") CommentResult addNewComment( long channelId, int docId, String commentUser, String isGuest, String docComment, HttpServletRequest request) throws Exception { DocComment docCommentBean = new DocComment(); if (StringUtil.isEmpty(commentUser)) { if (Boolean.parseBoolean(isGuest)) docCommentBean.setUserName("__quest"); } else { docCommentBean.setUserName(URLDecoder.decode(commentUser, "UTF-8")); } docCommentBean.setDocId(docId); if (!StringUtil.isEmpty(docComment)) { docCommentBean.setDocComment(URLDecoder.decode(docComment, "UTF-8")); } docCommentBean.setUserIP(com.frameworkset.util.StringUtil.getClientIP(request)); // 默认即可发布 int status = 1; // 获取频道的评论审核开关 Integer aduitSwitchFlag = docCommentManager.getChannelCommentAduitSwitch((int) channelId); if (aduitSwitchFlag != null) { // 如果评论为开通状态,则评论的状态为待审核,否则为即可发布状态 status = aduitSwitchFlag == 0 ? 2 : 1; } docCommentBean.setStatus(status); CommentResult result = new CommentResult(); result.setAduitSwitchFlag(aduitSwitchFlag + ""); try { docCommentManager.addOneComment(docCommentBean); result.setMsg("success"); } catch (DocCommentManagerException e) { result.setMsg("failed"); result.setError(StringUtil.exceptionToString(e)); } return result; }