CommentServiceImpl.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. //用户id或者订单id如果不存在(匿名评论)
  52. if(StringUtils.isBlank(commentInput.getOrderNo())){
  53. commentInput.setOrderNo("");
  54. }
  55. if(StringUtils.isBlank(uid)){
  56. commentInput.setOrderNo("");
  57. //查看当前ip的游客名称和游客最大名称
  58. uid = jtCommodityCommentMapper.getUidByIp(ip);
  59. if(StringUtils.isBlank(uid)){
  60. int c = Integer.parseInt(jtCommodityCommentMapper.getMaxNameUid()) + 1;
  61. uid = "游客" + String.format("%03d", c);
  62. }
  63. }
  64. jtCommodityComment.setUid(uid);
  65. jtCommodityComment.setOrderNo(commentInput.getOrderNo());
  66. jtCommodityCommentMapper.insert(jtCommodityComment);
  67. return 0;
  68. }
  69. /*
  70. * 0-好评 1-中评 2-差评
  71. * */
  72. @Override
  73. public Integer getCommentCount(Integer type,String commodityId) {
  74. // TODO Auto-generated method stub
  75. return jtCommodityCommentMapper.getCommentCount( type, commodityId);
  76. }
  77. @SuppressWarnings("unchecked")
  78. @Override
  79. public Pagination<CommentDetailResult> searchComment(String commodityId,Integer pageNo,Integer pageSize) {
  80. Map<String, Object>params=new HashMap<>();
  81. if(pageNo==null || pageNo<1)pageNo=1;
  82. if(pageSize == null || pageSize <1)pageSize=10;
  83. params.put("commodityId", commodityId);
  84. return (Pagination<CommentDetailResult>) findPage("searchCommentByCommodityId", "searchCommentCountByCommodityId", params, pageNo, pageSize);
  85. }
  86. @SuppressWarnings("unchecked")
  87. @Override
  88. public Pagination<CommentDetailResult> selectExpertsComment(String id,Integer pageNo,Integer pageSize) {
  89. Map<String, Object>params=new HashMap<>();
  90. if(pageNo==null || pageNo<1)pageNo=1;
  91. if(pageSize == null || pageSize <1)pageSize=10;
  92. params.put("id", id);
  93. return (Pagination<CommentDetailResult>) findPage("selectExpertsCommentList", "selectExpertsCommentCount", params, pageNo, pageSize);
  94. }
  95. @SuppressWarnings("unchecked")
  96. @Override
  97. public Pagination<CommentDetailResult> searchUnlandedCommentList(
  98. String commodityId, Integer pageNo, Integer pageSize) {
  99. Map<String, Object>params=new HashMap<>();
  100. params.put("commodityId", commodityId);
  101. return (Pagination<CommentDetailResult>) findPage("searchUnlandedCommentByCommodityId", "searchCommentCountByCommodityId", params, pageNo, pageSize);
  102. }
  103. }