From 1422b6fdbc55d2763f9c7a2555cf190a7fadf8aa Mon Sep 17 00:00:00 2001 From: misworga831 Date: Tue, 24 Oct 2023 14:41:41 +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=E4=BB=B7=E4=B8=BA=E6=89=80=E6=9C=89?= =?UTF-8?q?Sku=E7=9A=84=E8=AF=84=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/lili/event/impl/GoodsSkuExecute.java | 6 +++- .../goods/service/GoodsSkuService.java | 10 ++---- .../goods/serviceimpl/GoodsServiceImpl.java | 24 +++++++++++--- .../serviceimpl/GoodsSkuServiceImpl.java | 32 ++----------------- 4 files changed, 29 insertions(+), 43 deletions(-) diff --git a/consumer/src/main/java/cn/lili/event/impl/GoodsSkuExecute.java b/consumer/src/main/java/cn/lili/event/impl/GoodsSkuExecute.java index 47b77d6f..94b50d7a 100644 --- a/consumer/src/main/java/cn/lili/event/impl/GoodsSkuExecute.java +++ b/consumer/src/main/java/cn/lili/event/impl/GoodsSkuExecute.java @@ -7,6 +7,7 @@ import cn.lili.event.GoodsCommentCompleteEvent; import cn.lili.event.StoreSettingChangeEvent; import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.dto.GoodsSearchParams; +import cn.lili.modules.goods.service.GoodsService; import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.member.entity.dos.MemberEvaluation; import cn.lili.modules.store.entity.dos.Store; @@ -31,12 +32,15 @@ public class GoodsSkuExecute implements GoodsCommentCompleteEvent, StoreSettingC @Autowired private GoodsSkuService goodsSkuService; + @Autowired + private GoodsService goodsService; + @Autowired private Cache cache; @Override public void goodsComment(MemberEvaluation memberEvaluation) { - goodsSkuService.updateGoodsSkuCommentNum(memberEvaluation.getSkuId()); + goodsService.updateGoodsCommentNum(memberEvaluation.getGoodsId(), memberEvaluation.getSkuId()); } @Override diff --git a/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java b/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java index 3447cb4e..afe5cfc8 100644 --- a/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java +++ b/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java @@ -211,13 +211,6 @@ public interface GoodsSkuService extends IService { */ void updateGoodsStock(List goodsSkus); - /** - * 更新SKU评价数量 - * - * @param skuId SKUId - */ - void updateGoodsSkuCommentNum(String skuId); - /** * 根据商品id获取全部skuId的集合 * @@ -261,9 +254,10 @@ public interface GoodsSkuService extends IService { /** * 更新商品sku评分 * + * @param goodsId goodsId * @param skuId skuId * @param grade 评分 * @param commentNum 评论数量 */ - void updateGoodsSkuGrade(String skuId, double grade,int commentNum); + void updateGoodsSkuGrade(String goodsId, String skuId, double grade,int commentNum); } \ No newline at end of file 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 95653da5..7a133fc3 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 @@ -14,10 +14,7 @@ import cn.lili.common.properties.RocketmqCustomProperties; import cn.lili.common.security.AuthUser; import cn.lili.common.security.context.UserContext; import cn.lili.common.security.enums.UserEnums; -import cn.lili.modules.goods.entity.dos.Category; -import cn.lili.modules.goods.entity.dos.Goods; -import cn.lili.modules.goods.entity.dos.GoodsGallery; -import cn.lili.modules.goods.entity.dos.Wholesale; +import cn.lili.modules.goods.entity.dos.*; import cn.lili.modules.goods.entity.dto.GoodsOperationDTO; import cn.lili.modules.goods.entity.dto.GoodsParamsDTO; import cn.lili.modules.goods.entity.dto.GoodsSearchParams; @@ -444,11 +441,20 @@ public class GoodsServiceImpl extends ServiceImpl implements } @Override + @Transactional(rollbackFor = Exception.class) public void updateGoodsCommentNum(String goodsId, String skuId) { + GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(skuId); + if (goodsSku == null) { + return; + } //获取商品信息 Goods goods = this.getById(goodsId); + if (goods == null) { + return; + } + //修改商品评价数量 long commentNum = memberEvaluationService.getEvaluationCount(EvaluationQueryParams.builder().goodsId(goodsId).status("OPEN").build()); goods.setCommentNum((int) (commentNum)); @@ -458,10 +464,18 @@ public class GoodsServiceImpl extends ServiceImpl implements //好评率 double grade = NumberUtil.mul(NumberUtil.div(highPraiseNum, goods.getCommentNum().doubleValue(), 2), 100); goods.setGrade(grade); - this.updateById(goods); + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(Goods::getId, goodsId); + updateWrapper.set(Goods::getCommentNum, goods.getCommentNum()); + updateWrapper.set(Goods::getGrade, goods.getGrade()); + this.update(updateWrapper); cache.remove(CachePrefix.GOODS.getPrefix() + goodsId); + + // 修改商品sku评价数量 + this.goodsSkuService.updateGoodsSkuGrade(goodsId, skuId, grade, goods.getCommentNum()); + Map updateIndexFieldsMap = EsIndexUtil.getUpdateIndexFieldsMap(MapUtil.builder(new HashMap()).put("id", skuId).build(), MapUtil.builder(new HashMap()).put("commentNum", goods.getCommentNum()).put("highPraiseNum", highPraiseNum).put("grade", grade).build()); applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("更新商品索引信息", rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.UPDATE_GOODS_INDEX_FIELD.name(), JSONUtil.toJsonStr(updateIndexFieldsMap))); } 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 be816afe..a03abd7a 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 @@ -1,7 +1,6 @@ package cn.lili.modules.goods.serviceimpl; import cn.hutool.core.text.CharSequenceUtil; -import cn.hutool.core.util.NumberUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import cn.lili.cache.Cache; @@ -36,8 +35,6 @@ import cn.lili.modules.goods.service.WholesaleService; import cn.lili.modules.goods.sku.GoodsSkuBuilder; import cn.lili.modules.goods.sku.render.SalesModelRender; import cn.lili.modules.member.entity.dos.FootPrint; -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.promotion.entity.dos.Coupon; import cn.lili.modules.promotion.entity.dos.PromotionGoods; @@ -604,30 +601,6 @@ public class GoodsSkuServiceImpl extends ServiceImpl i } - @Override - @Transactional(rollbackFor = Exception.class) - public void updateGoodsSkuCommentNum(String skuId) { - //获取商品信息 - GoodsSku goodsSku = this.getGoodsSkuByIdFromCache(skuId); - - //好评数量 - long highPraiseNum = memberEvaluationService.getEvaluationCount(EvaluationQueryParams.builder().status("OPEN").grade(EvaluationGradeEnum.GOOD.name()).skuId(skuId).build()); - - //更新商品评价数量 - long commentNum = memberEvaluationService.getEvaluationCount(EvaluationQueryParams.builder().status("OPEN").skuId(skuId).build()); - goodsSku.setCommentNum((int) commentNum); - - //好评率 - double grade = NumberUtil.mul(NumberUtil.div(highPraiseNum, goodsSku.getCommentNum().doubleValue(), 2), 100); - goodsSku.setGrade(grade); - //修改规格 - this.updateGoodsSkuGrade(skuId, grade, goodsSku.getCommentNum()); - - //修改商品的评价数量 - goodsService.updateGoodsCommentNum(goodsSku.getGoodsId(), skuId); - clearCache(skuId); - } - /** * 根据商品id获取全部skuId的集合 * @@ -686,12 +659,13 @@ public class GoodsSkuServiceImpl extends ServiceImpl i } @Override - public void updateGoodsSkuGrade(String skuId, double grade, int commentNum) { + public void updateGoodsSkuGrade(String goodsId, String skuId, double grade, int commentNum) { LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); - updateWrapper.eq(GoodsSku::getId, skuId); + updateWrapper.eq(GoodsSku::getGoodsId, goodsId); updateWrapper.set(GoodsSku::getGrade, grade); updateWrapper.set(GoodsSku::getCommentNum, commentNum); this.update(updateWrapper); + clearCache(skuId); } /**