CommentServiceImpl.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package com.goafanti.comment.service.impl;
  2. import java.util.Date;
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import java.util.UUID;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Service;
  8. import com.goafanti.comment.bo.CommentDetailResult;
  9. import com.goafanti.comment.bo.CommentInput;
  10. import com.goafanti.comment.service.CommentService;
  11. import com.goafanti.common.dao.JtCommodityCommentMapper;
  12. import com.goafanti.common.dao.JtConsultOrderMapper;
  13. import com.goafanti.common.dao.JtOrderMapper;
  14. import com.goafanti.common.model.JtCommodityComment;
  15. import com.goafanti.common.utils.StringUtils;
  16. import com.goafanti.core.mybatis.BaseMybatisDao;
  17. import com.goafanti.core.mybatis.page.Pagination;
  18. import com.goafanti.core.shiro.token.TokenManager;
  19. @Service
  20. public class CommentServiceImpl extends BaseMybatisDao<JtCommodityCommentMapper> implements CommentService{
  21. @Autowired
  22. JtCommodityCommentMapper jtCommodityCommentMapper;
  23. @Autowired
  24. JtConsultOrderMapper jtConsultOrderMapper;
  25. @Autowired
  26. JtOrderMapper jtOrderMapper;
  27. @Override
  28. public int addNewComment(CommentInput commentInput, String ip) {
  29. // TODO Auto-generated method stub
  30. String id=UUID.randomUUID().toString();
  31. String uid=TokenManager.getUserId();
  32. // String uid="1180fa62-7c42-44be-bc41-5583814d69f4";
  33. //注释掉必须购买才能评价的条件
  34. /*
  35. JtOrder jtOrder= new JtOrder();
  36. if (commentInput.getType()==0){
  37. jtOrder=jtOrderMapper.selectByPrimaryKey(commentInput.getOrderNo());
  38. if(jtOrder==null || jtOrder.getBuyerId()==null || !jtOrder.getBuyerId().equals(uid))return -1;
  39. }
  40. if (commentInput.getType()==1){
  41. JtConsultOrder jtConsultOrder=jtConsultOrderMapper.selectByPrimaryKey(commentInput.getOrderNo());
  42. if(jtConsultOrder==null || jtConsultOrder.getBuyerId()==null || !jtConsultOrder.getBuyerId().equals(uid))return -1;
  43. }*/
  44. JtCommodityComment jtCommodityComment=new JtCommodityComment();
  45. jtCommodityComment.setCommodityId(commentInput.getCommodityId());
  46. jtCommodityComment.setContent(commentInput.getContent());
  47. jtCommodityComment.setCreateTime(new Date());
  48. jtCommodityComment.setId(id);
  49. jtCommodityComment.setIp(ip);
  50. jtCommodityComment.setStar(commentInput.getStar());
  51. jtCommodityComment.setCommodityType(commentInput.getCommodityType());
  52. //用户id或者订单id如果不存在(匿名评论)
  53. if(StringUtils.isBlank(commentInput.getOrderNo())){
  54. commentInput.setOrderNo("");
  55. }
  56. if(StringUtils.isBlank(uid)){
  57. commentInput.setOrderNo("");
  58. //查看当前ip的游客名称和游客最大名称
  59. uid = jtCommodityCommentMapper.getUidByIp(ip);
  60. if(StringUtils.isBlank(uid)){
  61. uid = jtCommodityCommentMapper.getMaxNameUid();
  62. uid = StringUtils.isBlank(uid) ? "0" : uid;//如果是第一个游客
  63. int c = Integer.parseInt(uid) + 1;
  64. uid = "游客" + String.format("%03d", c);
  65. }
  66. }
  67. jtCommodityComment.setUid(uid);
  68. jtCommodityComment.setOrderNo(commentInput.getOrderNo());
  69. jtCommodityCommentMapper.insert(jtCommodityComment);
  70. return 0;
  71. }
  72. /*
  73. * 0-好评 1-中评 2-差评
  74. * */
  75. @Override
  76. public Integer getCommentCount(Integer type,String commodityId) {
  77. // TODO Auto-generated method stub
  78. return jtCommodityCommentMapper.getCommentCount( type, commodityId);
  79. }
  80. @SuppressWarnings("unchecked")
  81. @Override
  82. public Pagination<CommentDetailResult> searchComment(String commodityId,Integer pageNo,Integer pageSize) {
  83. Map<String, Object>params=new HashMap<>();
  84. if(pageNo==null || pageNo<1)pageNo=1;
  85. if(pageSize == null || pageSize <1)pageSize=10;
  86. params.put("commodityId", commodityId);
  87. return (Pagination<CommentDetailResult>) findPage("searchCommentByCommodityId", "searchCommentCountByCommodityId", params, pageNo, pageSize);
  88. }
  89. @SuppressWarnings("unchecked")
  90. @Override
  91. public Pagination<CommentDetailResult> selectExpertsComment(String id,Integer pageNo,Integer pageSize) {
  92. Map<String, Object>params=new HashMap<>();
  93. if(pageNo==null || pageNo<1)pageNo=1;
  94. if(pageSize == null || pageSize <1)pageSize=10;
  95. params.put("id", id);
  96. return (Pagination<CommentDetailResult>) findPage("selectExpertsCommentList", "selectExpertsCommentCount", params, pageNo, pageSize);
  97. }
  98. @SuppressWarnings("unchecked")
  99. @Override
  100. public Pagination<CommentDetailResult> searchUnlandedCommentList(
  101. String commodityId, Integer pageNo, Integer pageSize) {
  102. Map<String, Object>params=new HashMap<>();
  103. params.put("commodityId", commodityId);
  104. return (Pagination<CommentDetailResult>) findPage("searchUnlandedCommentByCommodityId", "searchCommentCountByCommodityId", params, pageNo, pageSize);
  105. }
  106. }