Пример #1
0
  @Override
  public ReturnStatus add(Comment comment) {
    CommentExample example = new CommentExample();
    example
        .createCriteria()
        .andUserIdEqualTo(comment.getUserId())
        .andProductIdEqualTo(comment.getProductId())
        .andOrderIdEqualTo(comment.getOrderId());

    int result;

    List<Comment> list = commentMapper.selectByExample(example);
    if (!list.isEmpty()) {
      Comment c = list.get(0);
      c.setCommentText(comment.getCommentText());
      c.setStars(comment.getStars());
      c.setCreateTime(DateTool.getCurrentTimeCN());

      result = commentMapper.updateByPrimaryKeySelective(c);
    } else {
      result = commentMapper.insert(comment);
    }

    if (result > 0) {
      return new ReturnStatus(result, "ÆÀÂ۳ɹ¦!");
    } else {
      return new ReturnStatus(result, "ÆÀÂÛʧ°Ü");
    }
  }
Пример #2
0
  @Override
  public ReturnStatus delete(int id) {
    Comment comment = getById(id);
    if (comment.getCommentId() == null) {
      List<Comment> list = getSubComments(id);
      for (Comment c : list) {
        commentMapper.deleteByPrimaryKey(c.getId());
      }
    }
    int result = commentMapper.deleteByPrimaryKey(id);

    if (result > 0) {
      return new ReturnStatus(result, "ɾ³ýÆÀÂ۳ɹ¦!");
    } else {
      return new ReturnStatus(result, "ɾ³ýÆÀÂÛʧ°Ü");
    }
  }