Beispiel #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, "ÆÀÂÛʧ°Ü");
    }
  }
Beispiel #2
0
  @Override
  public List<Comment> getSubComments(int commentId) {
    CommentExample example = new CommentExample();
    example.createCriteria().andCommentIdEqualTo(commentId);

    return commentMapper.selectByExample(example);
  }
Beispiel #3
0
  @Override
  public List<Comment> getByUser(int userId) {
    CommentExample example = new CommentExample();
    example.createCriteria().andUserIdEqualTo(userId);

    return commentMapper.selectByExample(example);
  }
Beispiel #4
0
  @Override
  public List<Comment> getByOrderMain(int orderId) {
    CommentExample example = new CommentExample();
    example.createCriteria().andOrderIdEqualTo(orderId).andCommentIdIsNull();

    return commentMapper.selectByExample(example);
  }
Beispiel #5
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, "ɾ³ýÆÀÂÛʧ°Ü");
    }
  }
Beispiel #6
0
 @Override
 public Comment getById(int id) {
   return commentMapper.selectByPrimaryKey(id);
 }