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, "ÆÀÂÛʧ°Ü");
    }
  }