From fa696e6c1126a77f85ca556e904677187e3293e7 Mon Sep 17 00:00:00 2001 From: misworga831 Date: Mon, 16 Oct 2023 16:40:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=95=86=E5=93=81=E8=AF=84=E8=AE=BA,=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E7=BB=9F=E8=AE=A1=E8=AF=84=E8=AE=BA=E6=80=BB?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goods/serviceimpl/GoodsServiceImpl.java | 16 ++++++++-------- .../goods/serviceimpl/GoodsSkuServiceImpl.java | 9 ++++----- .../member/entity/dto/EvaluationQueryParams.java | 8 ++++++-- .../serviceimpl/MemberEvaluationServiceImpl.java | 16 +++++++--------- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java index 6029998aa..bab43739b 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java @@ -26,7 +26,7 @@ import cn.lili.modules.goods.entity.vos.GoodsSkuVO; import cn.lili.modules.goods.entity.vos.GoodsVO; import cn.lili.modules.goods.mapper.GoodsMapper; import cn.lili.modules.goods.service.*; -import cn.lili.modules.member.entity.dos.MemberEvaluation; +import cn.lili.modules.member.entity.dto.EvaluationQueryParams; import cn.lili.modules.member.entity.enums.EvaluationGradeEnum; import cn.lili.modules.member.service.MemberEvaluationService; import cn.lili.modules.store.entity.dos.FreightTemplate; @@ -446,19 +446,19 @@ public class GoodsServiceImpl extends ServiceImpl implements //获取商品信息 Goods goods = this.getById(goodsId); - //修改商品评价数量 - goods.setCommentNum(goods.getCommentNum() + 1); - //修改商品好评率 - LambdaQueryWrapper goodEvaluationQueryWrapper = new LambdaQueryWrapper<>(); - goodEvaluationQueryWrapper.eq(MemberEvaluation::getId, goodsId); - goodEvaluationQueryWrapper.eq(MemberEvaluation::getGrade, EvaluationGradeEnum.GOOD.name()); + //修改商品评价数量 + long commentNum = memberEvaluationService.getEvaluationCount(EvaluationQueryParams.builder().goodsId(goodsId).build()); + goods.setCommentNum((int) (commentNum)); + //好评数量 - long highPraiseNum = memberEvaluationService.count(goodEvaluationQueryWrapper); + long highPraiseNum = memberEvaluationService.getEvaluationCount(EvaluationQueryParams.builder().goodsId(goodsId).grade(EvaluationGradeEnum.GOOD.name()).build()); //好评率 double grade = NumberUtil.mul(NumberUtil.div(highPraiseNum, goods.getCommentNum().doubleValue(), 2), 100); goods.setGrade(grade); this.updateById(goods); + + cache.remove(CachePrefix.GOODS.getPrefix() + goodsId); } /** diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java index 17aa75460..6ace49da8 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java @@ -612,14 +612,12 @@ public class GoodsSkuServiceImpl extends ServiceImpl i //获取商品信息 GoodsSku goodsSku = this.getGoodsSkuByIdFromCache(skuId); - EvaluationQueryParams queryParams = new EvaluationQueryParams(); - queryParams.setGrade(EvaluationGradeEnum.GOOD.name()); - queryParams.setSkuId(goodsSku.getId()); //好评数量 - long highPraiseNum = memberEvaluationService.getEvaluationCount(queryParams); + long highPraiseNum = memberEvaluationService.getEvaluationCount(EvaluationQueryParams.builder().grade(EvaluationGradeEnum.GOOD.name()).skuId(skuId).build()); //更新商品评价数量 - goodsSku.setCommentNum(goodsSku.getCommentNum() != null ? goodsSku.getCommentNum() + 1 : 1); + long commentNum = memberEvaluationService.getEvaluationCount(EvaluationQueryParams.builder().skuId(skuId).build()); + goodsSku.setCommentNum((int) commentNum); //好评率 double grade = NumberUtil.mul(NumberUtil.div(highPraiseNum, goodsSku.getCommentNum().doubleValue(), 2), 100); @@ -640,6 +638,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i //修改商品的评价数量 goodsService.updateGoodsCommentNum(goodsSku.getGoodsId()); + clearCache(skuId); } /** diff --git a/framework/src/main/java/cn/lili/modules/member/entity/dto/EvaluationQueryParams.java b/framework/src/main/java/cn/lili/modules/member/entity/dto/EvaluationQueryParams.java index 90cbbdf77..80e0cde34 100644 --- a/framework/src/main/java/cn/lili/modules/member/entity/dto/EvaluationQueryParams.java +++ b/framework/src/main/java/cn/lili/modules/member/entity/dto/EvaluationQueryParams.java @@ -4,8 +4,7 @@ import cn.hutool.core.text.CharSequenceUtil; import cn.lili.common.vo.PageVO; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.EqualsAndHashCode; +import lombok.*; /** * 评价查询条件 @@ -15,8 +14,13 @@ import lombok.EqualsAndHashCode; */ @EqualsAndHashCode(callSuper = true) @Data +@NoArgsConstructor +@AllArgsConstructor +@Builder public class EvaluationQueryParams extends PageVO { + private static final long serialVersionUID = 2038158669175297129L; + @ApiModelProperty(value = "ID") private String id; diff --git a/framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberEvaluationServiceImpl.java b/framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberEvaluationServiceImpl.java index 2e137778a..b0127cb0a 100644 --- a/framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberEvaluationServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberEvaluationServiceImpl.java @@ -6,6 +6,7 @@ import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.json.JSONUtil; import cn.lili.common.enums.ResultCode; import cn.lili.common.enums.SwitchEnum; +import cn.lili.common.event.TransactionCommitSendMQEvent; import cn.lili.common.exception.ServiceException; import cn.lili.common.properties.RocketmqCustomProperties; import cn.lili.common.security.context.UserContext; @@ -31,7 +32,6 @@ import cn.lili.modules.order.order.entity.enums.CommentStatusEnum; import cn.lili.modules.order.order.service.OrderItemService; import cn.lili.modules.order.order.service.OrderService; import cn.lili.mybatis.util.PageUtil; -import cn.lili.rocketmq.RocketmqSendCallbackBuilder; import cn.lili.rocketmq.tags.GoodsTagsEnum; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -40,8 +40,8 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -77,17 +77,15 @@ public class MemberEvaluationServiceImpl extends ServiceImpl managerQuery(EvaluationQueryParams queryParams) { //获取评价分页 @@ -133,8 +131,8 @@ public class MemberEvaluationServiceImpl extends ServiceImpl