Example #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();
   }
 }