From ac536f5a1a53e21201e489b97285f76438c4d924 Mon Sep 17 00:00:00 2001 From: whb <17803890193@163.com> Date: Tue, 5 Nov 2024 16:40:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=AF=84=E8=AE=BA=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stu/StuGoodsTradingCenterController.java | 22 +- .../trade/entity/StuGoodsCommentInfo.java | 51 ++++ .../entity/StuGoodsCommentInfoExample.java | 240 ++++++++++++++++++ .../dto/StuEvaluateInfoByGoodsIdDTO.java | 43 ++++ .../trade/entity/dto/StuPurchaseGoodsDTO.java | 1 + .../service/StuGoodsTradingOrderService.java | 9 +- .../StuGoodsTradingCenterServiceImpl.java | 2 - .../impl/StuGoodsTradingOrderServiceImpl.java | 142 +++++++++++ .../mappers/StuGoodsCommentInfoMapper.xml | 81 +++++- 9 files changed, 580 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/sztzjy/trade/entity/dto/StuEvaluateInfoByGoodsIdDTO.java diff --git a/src/main/java/com/sztzjy/trade/controller/stu/StuGoodsTradingCenterController.java b/src/main/java/com/sztzjy/trade/controller/stu/StuGoodsTradingCenterController.java index 1f26064..7848bcd 100644 --- a/src/main/java/com/sztzjy/trade/controller/stu/StuGoodsTradingCenterController.java +++ b/src/main/java/com/sztzjy/trade/controller/stu/StuGoodsTradingCenterController.java @@ -210,7 +210,7 @@ public class StuGoodsTradingCenterController { - @ApiOperation("商品详情页面:单独购买") + @ApiOperation("商品详情页面:下单") @AnonymousAccess @PostMapping("/purchaseGoods") public ResultEntity getpurchaseGoods(StuPurchaseGoodsDTO stuPurchaseGoodsDTO) { @@ -228,20 +228,36 @@ public class StuGoodsTradingCenterController { //拼团购买 tradingCenterService.groupPurchase(stuPurchaseGoodsDTO); + } + return new ResultEntity(HttpStatus.OK,"下单成功"); + } - } - return new ResultEntity(HttpStatus.OK,"下单成功"); + + @ApiOperation("商品详情页面:商品评价") + @AnonymousAccess + @GetMapping("/evaluate") + public ResultEntity getEvaluateByGoodsId(@ApiParam("商品ID") Integer goodsId) { + + return stuGoodsTradingOrderService.getEvaluateByGoodsId(goodsId); } + @ApiOperation("商品详情页面:商品评价分页展示") + @AnonymousAccess + @GetMapping("/evaluate") + public ResultEntity getEvaluateByGoodsIdPage(@ApiParam("商品ID") Integer goodsId, + @ApiParam("当前页") @RequestParam(required = true, defaultValue = "1") Integer index, + @ApiParam("每页条数") @RequestParam(required = true, defaultValue = "20") Integer size) { + return stuGoodsTradingOrderService.getEvaluateByGoodsIdPage(goodsId,index,size); + } } diff --git a/src/main/java/com/sztzjy/trade/entity/StuGoodsCommentInfo.java b/src/main/java/com/sztzjy/trade/entity/StuGoodsCommentInfo.java index bc4e8af..630d182 100644 --- a/src/main/java/com/sztzjy/trade/entity/StuGoodsCommentInfo.java +++ b/src/main/java/com/sztzjy/trade/entity/StuGoodsCommentInfo.java @@ -1,14 +1,19 @@ package com.sztzjy.trade.entity; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + /** * 商品评价表 * * @author whb * stu_goods_comment_info */ +@Data public class StuGoodsCommentInfo { @ApiModelProperty(notes = "id") private Integer id; @@ -37,8 +42,22 @@ public class StuGoodsCommentInfo { @ApiModelProperty(notes = "商品ID") private Integer goodsId; + @ApiModelProperty(notes = "关联评论id") + private Integer commentId; + + @ApiModelProperty(notes = "点赞次数 (默认为0 未点赞)") + private Integer giveTheThumbsUp; + + @ApiModelProperty(notes = "回复次数 (默认为0 未回复)") + private Integer replyFrequency; + + @ApiModelProperty(notes = "举报次数 (默认为0 未举报)") + private Integer reportFrequency; + @ApiModelProperty(notes = "电脑传图 json类型(type,url)") private String imageUpload; + @ApiModelProperty(notes = "评论详情") + private List replies = new ArrayList(); public Integer getId() { return id; @@ -112,6 +131,38 @@ public class StuGoodsCommentInfo { this.goodsId = goodsId; } + public Integer getCommentId() { + return commentId; + } + + public void setCommentId(Integer commentId) { + this.commentId = commentId; + } + + public Integer getGiveTheThumbsUp() { + return giveTheThumbsUp; + } + + public void setGiveTheThumbsUp(Integer giveTheThumbsUp) { + this.giveTheThumbsUp = giveTheThumbsUp; + } + + public Integer getReplyFrequency() { + return replyFrequency; + } + + public void setReplyFrequency(Integer replyFrequency) { + this.replyFrequency = replyFrequency; + } + + public Integer getReportFrequency() { + return reportFrequency; + } + + public void setReportFrequency(Integer reportFrequency) { + this.reportFrequency = reportFrequency; + } + public String getImageUpload() { return imageUpload; } diff --git a/src/main/java/com/sztzjy/trade/entity/StuGoodsCommentInfoExample.java b/src/main/java/com/sztzjy/trade/entity/StuGoodsCommentInfoExample.java index a78c91a..49897db 100644 --- a/src/main/java/com/sztzjy/trade/entity/StuGoodsCommentInfoExample.java +++ b/src/main/java/com/sztzjy/trade/entity/StuGoodsCommentInfoExample.java @@ -674,6 +674,246 @@ public class StuGoodsCommentInfoExample { addCriterion("goods_id not between", value1, value2, "goodsId"); return (Criteria) this; } + + public Criteria andCommentIdIsNull() { + addCriterion("comment_id is null"); + return (Criteria) this; + } + + public Criteria andCommentIdIsNotNull() { + addCriterion("comment_id is not null"); + return (Criteria) this; + } + + public Criteria andCommentIdEqualTo(Integer value) { + addCriterion("comment_id =", value, "commentId"); + return (Criteria) this; + } + + public Criteria andCommentIdNotEqualTo(Integer value) { + addCriterion("comment_id <>", value, "commentId"); + return (Criteria) this; + } + + public Criteria andCommentIdGreaterThan(Integer value) { + addCriterion("comment_id >", value, "commentId"); + return (Criteria) this; + } + + public Criteria andCommentIdGreaterThanOrEqualTo(Integer value) { + addCriterion("comment_id >=", value, "commentId"); + return (Criteria) this; + } + + public Criteria andCommentIdLessThan(Integer value) { + addCriterion("comment_id <", value, "commentId"); + return (Criteria) this; + } + + public Criteria andCommentIdLessThanOrEqualTo(Integer value) { + addCriterion("comment_id <=", value, "commentId"); + return (Criteria) this; + } + + public Criteria andCommentIdIn(List values) { + addCriterion("comment_id in", values, "commentId"); + return (Criteria) this; + } + + public Criteria andCommentIdNotIn(List values) { + addCriterion("comment_id not in", values, "commentId"); + return (Criteria) this; + } + + public Criteria andCommentIdBetween(Integer value1, Integer value2) { + addCriterion("comment_id between", value1, value2, "commentId"); + return (Criteria) this; + } + + public Criteria andCommentIdNotBetween(Integer value1, Integer value2) { + addCriterion("comment_id not between", value1, value2, "commentId"); + return (Criteria) this; + } + + public Criteria andGiveTheThumbsUpIsNull() { + addCriterion("give_the_thumbs_up is null"); + return (Criteria) this; + } + + public Criteria andGiveTheThumbsUpIsNotNull() { + addCriterion("give_the_thumbs_up is not null"); + return (Criteria) this; + } + + public Criteria andGiveTheThumbsUpEqualTo(Integer value) { + addCriterion("give_the_thumbs_up =", value, "giveTheThumbsUp"); + return (Criteria) this; + } + + public Criteria andGiveTheThumbsUpNotEqualTo(Integer value) { + addCriterion("give_the_thumbs_up <>", value, "giveTheThumbsUp"); + return (Criteria) this; + } + + public Criteria andGiveTheThumbsUpGreaterThan(Integer value) { + addCriterion("give_the_thumbs_up >", value, "giveTheThumbsUp"); + return (Criteria) this; + } + + public Criteria andGiveTheThumbsUpGreaterThanOrEqualTo(Integer value) { + addCriterion("give_the_thumbs_up >=", value, "giveTheThumbsUp"); + return (Criteria) this; + } + + public Criteria andGiveTheThumbsUpLessThan(Integer value) { + addCriterion("give_the_thumbs_up <", value, "giveTheThumbsUp"); + return (Criteria) this; + } + + public Criteria andGiveTheThumbsUpLessThanOrEqualTo(Integer value) { + addCriterion("give_the_thumbs_up <=", value, "giveTheThumbsUp"); + return (Criteria) this; + } + + public Criteria andGiveTheThumbsUpIn(List values) { + addCriterion("give_the_thumbs_up in", values, "giveTheThumbsUp"); + return (Criteria) this; + } + + public Criteria andGiveTheThumbsUpNotIn(List values) { + addCriterion("give_the_thumbs_up not in", values, "giveTheThumbsUp"); + return (Criteria) this; + } + + public Criteria andGiveTheThumbsUpBetween(Integer value1, Integer value2) { + addCriterion("give_the_thumbs_up between", value1, value2, "giveTheThumbsUp"); + return (Criteria) this; + } + + public Criteria andGiveTheThumbsUpNotBetween(Integer value1, Integer value2) { + addCriterion("give_the_thumbs_up not between", value1, value2, "giveTheThumbsUp"); + return (Criteria) this; + } + + public Criteria andReplyFrequencyIsNull() { + addCriterion("reply_frequency is null"); + return (Criteria) this; + } + + public Criteria andReplyFrequencyIsNotNull() { + addCriterion("reply_frequency is not null"); + return (Criteria) this; + } + + public Criteria andReplyFrequencyEqualTo(Integer value) { + addCriterion("reply_frequency =", value, "replyFrequency"); + return (Criteria) this; + } + + public Criteria andReplyFrequencyNotEqualTo(Integer value) { + addCriterion("reply_frequency <>", value, "replyFrequency"); + return (Criteria) this; + } + + public Criteria andReplyFrequencyGreaterThan(Integer value) { + addCriterion("reply_frequency >", value, "replyFrequency"); + return (Criteria) this; + } + + public Criteria andReplyFrequencyGreaterThanOrEqualTo(Integer value) { + addCriterion("reply_frequency >=", value, "replyFrequency"); + return (Criteria) this; + } + + public Criteria andReplyFrequencyLessThan(Integer value) { + addCriterion("reply_frequency <", value, "replyFrequency"); + return (Criteria) this; + } + + public Criteria andReplyFrequencyLessThanOrEqualTo(Integer value) { + addCriterion("reply_frequency <=", value, "replyFrequency"); + return (Criteria) this; + } + + public Criteria andReplyFrequencyIn(List values) { + addCriterion("reply_frequency in", values, "replyFrequency"); + return (Criteria) this; + } + + public Criteria andReplyFrequencyNotIn(List values) { + addCriterion("reply_frequency not in", values, "replyFrequency"); + return (Criteria) this; + } + + public Criteria andReplyFrequencyBetween(Integer value1, Integer value2) { + addCriterion("reply_frequency between", value1, value2, "replyFrequency"); + return (Criteria) this; + } + + public Criteria andReplyFrequencyNotBetween(Integer value1, Integer value2) { + addCriterion("reply_frequency not between", value1, value2, "replyFrequency"); + return (Criteria) this; + } + + public Criteria andReportFrequencyIsNull() { + addCriterion("report_frequency is null"); + return (Criteria) this; + } + + public Criteria andReportFrequencyIsNotNull() { + addCriterion("report_frequency is not null"); + return (Criteria) this; + } + + public Criteria andReportFrequencyEqualTo(Integer value) { + addCriterion("report_frequency =", value, "reportFrequency"); + return (Criteria) this; + } + + public Criteria andReportFrequencyNotEqualTo(Integer value) { + addCriterion("report_frequency <>", value, "reportFrequency"); + return (Criteria) this; + } + + public Criteria andReportFrequencyGreaterThan(Integer value) { + addCriterion("report_frequency >", value, "reportFrequency"); + return (Criteria) this; + } + + public Criteria andReportFrequencyGreaterThanOrEqualTo(Integer value) { + addCriterion("report_frequency >=", value, "reportFrequency"); + return (Criteria) this; + } + + public Criteria andReportFrequencyLessThan(Integer value) { + addCriterion("report_frequency <", value, "reportFrequency"); + return (Criteria) this; + } + + public Criteria andReportFrequencyLessThanOrEqualTo(Integer value) { + addCriterion("report_frequency <=", value, "reportFrequency"); + return (Criteria) this; + } + + public Criteria andReportFrequencyIn(List values) { + addCriterion("report_frequency in", values, "reportFrequency"); + return (Criteria) this; + } + + public Criteria andReportFrequencyNotIn(List values) { + addCriterion("report_frequency not in", values, "reportFrequency"); + return (Criteria) this; + } + + public Criteria andReportFrequencyBetween(Integer value1, Integer value2) { + addCriterion("report_frequency between", value1, value2, "reportFrequency"); + return (Criteria) this; + } + + public Criteria andReportFrequencyNotBetween(Integer value1, Integer value2) { + addCriterion("report_frequency not between", value1, value2, "reportFrequency"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/src/main/java/com/sztzjy/trade/entity/dto/StuEvaluateInfoByGoodsIdDTO.java b/src/main/java/com/sztzjy/trade/entity/dto/StuEvaluateInfoByGoodsIdDTO.java new file mode 100644 index 0000000..bd0ab6f --- /dev/null +++ b/src/main/java/com/sztzjy/trade/entity/dto/StuEvaluateInfoByGoodsIdDTO.java @@ -0,0 +1,43 @@ +package com.sztzjy.trade.entity.dto; + +import com.sztzjy.trade.entity.StuGoodsCommentInfo; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author 17803 + * @date 2024-11-05 15:01 + */ +@Data +public class StuEvaluateInfoByGoodsIdDTO { + + + @ApiModelProperty(notes = "好感度") + private Integer likability; + + @ApiModelProperty(notes = "词云") + private List wordCloudList; + + @ApiModelProperty(notes = "全部评价数量") + private Integer evaluateAll; + + + @ApiModelProperty(notes = "晒图数量") + private Integer makeBlueprint; + + + @ApiModelProperty(notes = "追评") + private Integer followUpReview; + + @ApiModelProperty(notes = "好评") + private Integer favorableComment; + + @ApiModelProperty(notes = "中评") + private Integer midEvaluation; + + @ApiModelProperty(notes = "差评") + private Integer badReview; +} diff --git a/src/main/java/com/sztzjy/trade/entity/dto/StuPurchaseGoodsDTO.java b/src/main/java/com/sztzjy/trade/entity/dto/StuPurchaseGoodsDTO.java index 28aa26a..a14c183 100644 --- a/src/main/java/com/sztzjy/trade/entity/dto/StuPurchaseGoodsDTO.java +++ b/src/main/java/com/sztzjy/trade/entity/dto/StuPurchaseGoodsDTO.java @@ -20,6 +20,7 @@ public class StuPurchaseGoodsDTO { @ApiModelProperty(notes = "商品类型") private String goodsType; + @ApiModelProperty(notes = "购买数量") private BigDecimal amount; private String userId; diff --git a/src/main/java/com/sztzjy/trade/service/StuGoodsTradingOrderService.java b/src/main/java/com/sztzjy/trade/service/StuGoodsTradingOrderService.java index f5e7c80..7eea099 100644 --- a/src/main/java/com/sztzjy/trade/service/StuGoodsTradingOrderService.java +++ b/src/main/java/com/sztzjy/trade/service/StuGoodsTradingOrderService.java @@ -1,6 +1,8 @@ package com.sztzjy.trade.service; import com.sztzjy.trade.util.ResultEntity; +import io.swagger.annotations.ApiParam; +import org.springframework.web.bind.annotation.RequestParam; /** * @author 17803 @@ -13,4 +15,9 @@ public interface StuGoodsTradingOrderService { //商品详情页面:看了又看功能 ResultEntity getSeeingYouOnAndOn(String userId, Integer goodsId,Integer index,Integer size,String goodsType); - } + //商品详情页面:商品评价 + ResultEntity getEvaluateByGoodsId(Integer goodsId); + + //商品详情页面:商品评价分页展示 + ResultEntity getEvaluateByGoodsIdPage(Integer goodsId, Integer index, Integer size); +} diff --git a/src/main/java/com/sztzjy/trade/service/impl/StuGoodsTradingCenterServiceImpl.java b/src/main/java/com/sztzjy/trade/service/impl/StuGoodsTradingCenterServiceImpl.java index 59cd9d8..80a63cc 100644 --- a/src/main/java/com/sztzjy/trade/service/impl/StuGoodsTradingCenterServiceImpl.java +++ b/src/main/java/com/sztzjy/trade/service/impl/StuGoodsTradingCenterServiceImpl.java @@ -577,8 +577,6 @@ public class StuGoodsTradingCenterServiceImpl implements StuGoodsTradingCenterSe }else { //添加到拼单数据中 - - List stuGroupOrderInfoDTOList = JSON.parseArray(splicingOrdersInfo.getParticipateInGroupBuying(), StuGroupOrderInfoDTO.class); StuGroupOrderInfoDTO stuGroupOrderInfoDTO = new StuGroupOrderInfoDTO(); stuGroupOrderInfoDTO.setUserId(stuPurchaseGoodsDTO.getUserId()); diff --git a/src/main/java/com/sztzjy/trade/service/impl/StuGoodsTradingOrderServiceImpl.java b/src/main/java/com/sztzjy/trade/service/impl/StuGoodsTradingOrderServiceImpl.java index f86dbdd..beee70e 100644 --- a/src/main/java/com/sztzjy/trade/service/impl/StuGoodsTradingOrderServiceImpl.java +++ b/src/main/java/com/sztzjy/trade/service/impl/StuGoodsTradingOrderServiceImpl.java @@ -2,10 +2,12 @@ package com.sztzjy.trade.service.impl; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.RandomUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.sztzjy.trade.entity.*; +import com.sztzjy.trade.entity.dto.StuEvaluateInfoByGoodsIdDTO; import com.sztzjy.trade.entity.dto.StuGoodsInfoDTO; import com.sztzjy.trade.entity.dto.StuGoodsSalesManageDTO; import com.sztzjy.trade.mapper.*; @@ -204,6 +206,146 @@ public class StuGoodsTradingOrderServiceImpl implements StuGoodsTradingOrderServ } + //商品详情页面:商品评价 + @Override + public ResultEntity getEvaluateByGoodsId(Integer goodsId) { + + StuEvaluateInfoByGoodsIdDTO evaluateInfoByGoodsIdDTO = new StuEvaluateInfoByGoodsIdDTO(); + + //计算好评度 + StuGoodsCommentInfoExample stuGoodsCommentInfoExample = new StuGoodsCommentInfoExample(); + stuGoodsCommentInfoExample.createCriteria().andGoodsIdEqualTo(goodsId).andCommentHierarchyEqualTo(0); + List stuGoodsCommentInfoList = stuGoodsCommentInfoMapper.selectByExampleWithBLOBs(stuGoodsCommentInfoExample); + if (!stuGoodsCommentInfoList.isEmpty()) { + + //获取所有评分 + //在淘宝平台上,好评分数通常被认为是4分及以上。 + List ratingList = stuGoodsCommentInfoList.stream().filter(item -> item.getGoodsRating() >= 4).map(StuGoodsCommentInfo::getGoodsRating).collect(Collectors.toList()); + int sum = ratingList.stream().mapToInt(Integer::intValue).sum(); + + //好评度 + int likability = sum / stuGoodsCommentInfoList.size(); + + evaluateInfoByGoodsIdDTO.setLikability(likability); + + //建立词云,从买家评论中,统计数量前10的词汇显示 + + List goodsCommentList = stuGoodsCommentInfoList.stream().map(StuGoodsCommentInfo::getGoodsComment).collect(Collectors.toList()); + + // 统计每个词的频率 + Map wordCountMap = new HashMap<>(); + + for (String comment : goodsCommentList) { + // 使用正则表达式分割评论为单词 + String[] words = comment.split("\\W+"); // 脱离非单词字符 + for (String word : words) { + word = word.trim(); // 去除多余的空格 + if (!word.isEmpty()) { + wordCountMap.put(word, wordCountMap.getOrDefault(word, 0) + 1); + } + } + } + + // 排序并提取前10个词 + List> topWords = wordCountMap.entrySet() + .stream() + .sorted((entry1, entry2) -> entry2.getValue().compareTo(entry1.getValue())) + .limit(10) + .collect(Collectors.toList()); + evaluateInfoByGoodsIdDTO.setWordCloudList(topWords); + + + //评价详情 1-2 差评 3:中评 4-5好评 + + //好评数量 + int favorableComment = ratingList.size(); + evaluateInfoByGoodsIdDTO.setFavorableComment(favorableComment); + + //中评数量 + int midEvaluation = (int) stuGoodsCommentInfoList.stream().filter(item -> item.getGoodsRating() == 3).map(StuGoodsCommentInfo::getGoodsRating).count(); + evaluateInfoByGoodsIdDTO.setMidEvaluation(midEvaluation); + //差评 + int badEvaluation = (int) stuGoodsCommentInfoList.stream().filter(item -> item.getGoodsRating() <= 2).map(StuGoodsCommentInfo::getGoodsRating).count(); + evaluateInfoByGoodsIdDTO.setBadReview(badEvaluation); + + //追评数量 + StuGoodsCommentInfoExample stuGoodsCommentInfoExampleOne = new StuGoodsCommentInfoExample(); + stuGoodsCommentInfoExampleOne.createCriteria().andGoodsIdEqualTo(goodsId).andCommentHierarchyNotEqualTo(0); + List stuGoodsCommentInfoListOne = stuGoodsCommentInfoMapper.selectByExampleWithBLOBs(stuGoodsCommentInfoExampleOne); + //追评数量 + int followUpReview = stuGoodsCommentInfoListOne.size(); + evaluateInfoByGoodsIdDTO.setFollowUpReview(followUpReview); + //晒图数量 + int count = (int) stuGoodsCommentInfoList.stream().filter(item -> item.getImageUpload() != null).count(); + + evaluateInfoByGoodsIdDTO.setMakeBlueprint(count); + + return new ResultEntity<>(HttpStatus.OK, evaluateInfoByGoodsIdDTO); + + + + }else { + return new ResultEntity<>(HttpStatus.OK); + } + } + + //商品详情页面:商品评价分页展示 + @Override + public ResultEntity getEvaluateByGoodsIdPage(Integer goodsId, Integer index, Integer size) { + + //新接口调用返回全部评价 查询所有包含回复评价 + PageHelper.startPage(1, 20); + StuGoodsCommentInfoExample stuGoodsCommentInfoExample = new StuGoodsCommentInfoExample(); + stuGoodsCommentInfoExample.createCriteria().andGoodsIdEqualTo(goodsId).andCommentHierarchyEqualTo(0); + List stuGoodsCommentInfoList = stuGoodsCommentInfoMapper.selectByExampleWithBLOBs(stuGoodsCommentInfoExample); + + if (!stuGoodsCommentInfoList.isEmpty()) { + + + // 收集所有层级的回复 //递归查询 + List allReplies = new ArrayList<>(); + for (StuGoodsCommentInfo stuGoodsCommentInfo : stuGoodsCommentInfoList) { + StuGoodsCommentInfoExample stuGoodsCommentInfoExampleOne = new StuGoodsCommentInfoExample(); + stuGoodsCommentInfoExampleOne.createCriteria().andGoodsIdEqualTo(goodsId).andCommentHierarchyNotEqualTo(0); + List stuGoodsCommentInfoListOne = stuGoodsCommentInfoMapper.selectByExampleWithBLOBs(stuGoodsCommentInfoExampleOne); + + + if (!stuGoodsCommentInfoListOne.isEmpty()) { + for (StuGoodsCommentInfo goodsCommentInfo : stuGoodsCommentInfoListOne) { + + + // 找到第一层回复 + if (goodsCommentInfo.getCommentId() != null && goodsCommentInfo.getCommentId().equals(stuGoodsCommentInfo.getId())) { + // 找到第一层回复 + System.out.println("Found first level reply: " + goodsCommentInfo.getGoodsComment()); + + // 收集所有回复 + allReplies.add(goodsCommentInfo); + allReplies.addAll(findReplies(goodsCommentInfo)); // 在这里添加递归获取的回复 + + } + } + } + } + PageInfo stuGoodsCommentInfoPageInfo = new PageInfo<>(allReplies); + return new ResultEntity<>(HttpStatus.OK, stuGoodsCommentInfoPageInfo); + } + return new ResultEntity<>(HttpStatus.OK); + + + } + + // 递归查找评论及其回复并返回所有回复的列表 + public static List findReplies(StuGoodsCommentInfo commentInfo) { + List repliesList = new ArrayList<>(); + for (StuGoodsCommentInfo reply : commentInfo.getReplies()) { + repliesList.add(reply); + // 递归查找这个回复下的层级评论 + repliesList.addAll(findReplies(reply)); + } + return repliesList; + } + } diff --git a/src/main/resources/mappers/StuGoodsCommentInfoMapper.xml b/src/main/resources/mappers/StuGoodsCommentInfoMapper.xml index ca84e23..f4155d7 100644 --- a/src/main/resources/mappers/StuGoodsCommentInfoMapper.xml +++ b/src/main/resources/mappers/StuGoodsCommentInfoMapper.xml @@ -11,6 +11,10 @@ + + + + @@ -75,7 +79,8 @@ id, order_number, goods_rating, goods_comment, anonymous_evaluation, create_time, - comment_hierarchy, user_id, goods_id + comment_hierarchy, user_id, goods_id, comment_id, give_the_thumbs_up, reply_frequency, + report_frequency image_upload @@ -132,11 +137,13 @@ insert into stu_goods_comment_info (id, order_number, goods_rating, goods_comment, anonymous_evaluation, create_time, comment_hierarchy, user_id, goods_id, - image_upload) + comment_id, give_the_thumbs_up, reply_frequency, + report_frequency, image_upload) values (#{id,jdbcType=INTEGER}, #{orderNumber,jdbcType=VARCHAR}, #{goodsRating,jdbcType=INTEGER}, #{goodsComment,jdbcType=VARCHAR}, #{anonymousEvaluation,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{commentHierarchy,jdbcType=INTEGER}, #{userId,jdbcType=VARCHAR}, #{goodsId,jdbcType=INTEGER}, - #{imageUpload,jdbcType=LONGVARCHAR}) + #{commentId,jdbcType=INTEGER}, #{giveTheThumbsUp,jdbcType=INTEGER}, #{replyFrequency,jdbcType=INTEGER}, + #{reportFrequency,jdbcType=INTEGER}, #{imageUpload,jdbcType=LONGVARCHAR}) insert into stu_goods_comment_info @@ -168,6 +175,18 @@ goods_id, + + comment_id, + + + give_the_thumbs_up, + + + reply_frequency, + + + report_frequency, + image_upload, @@ -200,6 +219,18 @@ #{goodsId,jdbcType=INTEGER}, + + #{commentId,jdbcType=INTEGER}, + + + #{giveTheThumbsUp,jdbcType=INTEGER}, + + + #{replyFrequency,jdbcType=INTEGER}, + + + #{reportFrequency,jdbcType=INTEGER}, + #{imageUpload,jdbcType=LONGVARCHAR}, @@ -241,6 +272,18 @@ goods_id = #{record.goodsId,jdbcType=INTEGER}, + + comment_id = #{record.commentId,jdbcType=INTEGER}, + + + give_the_thumbs_up = #{record.giveTheThumbsUp,jdbcType=INTEGER}, + + + reply_frequency = #{record.replyFrequency,jdbcType=INTEGER}, + + + report_frequency = #{record.reportFrequency,jdbcType=INTEGER}, + image_upload = #{record.imageUpload,jdbcType=LONGVARCHAR}, @@ -260,6 +303,10 @@ comment_hierarchy = #{record.commentHierarchy,jdbcType=INTEGER}, user_id = #{record.userId,jdbcType=VARCHAR}, goods_id = #{record.goodsId,jdbcType=INTEGER}, + comment_id = #{record.commentId,jdbcType=INTEGER}, + give_the_thumbs_up = #{record.giveTheThumbsUp,jdbcType=INTEGER}, + reply_frequency = #{record.replyFrequency,jdbcType=INTEGER}, + report_frequency = #{record.reportFrequency,jdbcType=INTEGER}, image_upload = #{record.imageUpload,jdbcType=LONGVARCHAR} @@ -275,7 +322,11 @@ create_time = #{record.createTime,jdbcType=TIMESTAMP}, comment_hierarchy = #{record.commentHierarchy,jdbcType=INTEGER}, user_id = #{record.userId,jdbcType=VARCHAR}, - goods_id = #{record.goodsId,jdbcType=INTEGER} + goods_id = #{record.goodsId,jdbcType=INTEGER}, + comment_id = #{record.commentId,jdbcType=INTEGER}, + give_the_thumbs_up = #{record.giveTheThumbsUp,jdbcType=INTEGER}, + reply_frequency = #{record.replyFrequency,jdbcType=INTEGER}, + report_frequency = #{record.reportFrequency,jdbcType=INTEGER} @@ -307,6 +358,18 @@ goods_id = #{goodsId,jdbcType=INTEGER}, + + comment_id = #{commentId,jdbcType=INTEGER}, + + + give_the_thumbs_up = #{giveTheThumbsUp,jdbcType=INTEGER}, + + + reply_frequency = #{replyFrequency,jdbcType=INTEGER}, + + + report_frequency = #{reportFrequency,jdbcType=INTEGER}, + image_upload = #{imageUpload,jdbcType=LONGVARCHAR}, @@ -323,6 +386,10 @@ comment_hierarchy = #{commentHierarchy,jdbcType=INTEGER}, user_id = #{userId,jdbcType=VARCHAR}, goods_id = #{goodsId,jdbcType=INTEGER}, + comment_id = #{commentId,jdbcType=INTEGER}, + give_the_thumbs_up = #{giveTheThumbsUp,jdbcType=INTEGER}, + reply_frequency = #{replyFrequency,jdbcType=INTEGER}, + report_frequency = #{reportFrequency,jdbcType=INTEGER}, image_upload = #{imageUpload,jdbcType=LONGVARCHAR} where id = #{id,jdbcType=INTEGER} @@ -335,7 +402,11 @@ create_time = #{createTime,jdbcType=TIMESTAMP}, comment_hierarchy = #{commentHierarchy,jdbcType=INTEGER}, user_id = #{userId,jdbcType=VARCHAR}, - goods_id = #{goodsId,jdbcType=INTEGER} + goods_id = #{goodsId,jdbcType=INTEGER}, + comment_id = #{commentId,jdbcType=INTEGER}, + give_the_thumbs_up = #{giveTheThumbsUp,jdbcType=INTEGER}, + reply_frequency = #{replyFrequency,jdbcType=INTEGER}, + report_frequency = #{reportFrequency,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER} \ No newline at end of file