diff --git a/buyer-api/src/main/java/cn/lili/controller/goods/GoodsBuyerController.java b/buyer-api/src/main/java/cn/lili/controller/goods/GoodsBuyerController.java index 19caa3e01..087404b41 100644 --- a/buyer-api/src/main/java/cn/lili/controller/goods/GoodsBuyerController.java +++ b/buyer-api/src/main/java/cn/lili/controller/goods/GoodsBuyerController.java @@ -6,6 +6,7 @@ import cn.lili.common.exception.ServiceException; import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; import cn.lili.modules.goods.entity.dos.Goods; +import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.dto.GoodsSearchParams; import cn.lili.modules.goods.entity.vos.GoodsVO; import cn.lili.modules.goods.service.GoodsService; @@ -101,6 +102,12 @@ public class GoodsBuyerController { return ResultUtil.data(goodsService.queryByParams(goodsSearchParams)); } + @ApiOperation(value = "获取商品sku列表") + @GetMapping("/sku") + public ResultMessage> getSkuByPage(GoodsSearchParams goodsSearchParams) { + return ResultUtil.data(goodsSkuService.getGoodsSkuByList(goodsSearchParams)); + } + @ApiOperation(value = "从ES中获取商品信息") @GetMapping("/es") public ResultMessage> getGoodsByPageFromEs(EsGoodsSearchDTO goodsSearchParams, PageVO pageVO) { 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 47b77d6f4..94b50d7a9 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/entity/dto/GoodsSearchParams.java b/framework/src/main/java/cn/lili/modules/goods/entity/dto/GoodsSearchParams.java index 27bb3bb98..2187c484f 100644 --- a/framework/src/main/java/cn/lili/modules/goods/entity/dto/GoodsSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/goods/entity/dto/GoodsSearchParams.java @@ -101,6 +101,9 @@ public class GoodsSearchParams extends PageVO { if (CharSequenceUtil.isNotEmpty(id)) { queryWrapper.in("id", Arrays.asList(id.split(","))); } + if (CollUtil.isNotEmpty(ids)) { + queryWrapper.in("id", ids); + } if (CharSequenceUtil.isNotEmpty(storeId)) { queryWrapper.eq("store_id", storeId); } 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 3447cb4ec..afe5cfc8b 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 95653da50..7a133fc34 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 be816afed..a03abd7a7 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); } /** diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java index 03f36a304..ee4e41d50 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java @@ -1,5 +1,6 @@ package cn.lili.modules.promotion.serviceimpl; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.json.JSONObject; @@ -109,7 +110,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl i.or(j -> j.in(SKU_ID_COLUMN, skuIds)) .or(n -> n.eq("scope_type", PromotionsScopeTypeEnum.ALL.name())) .or(n -> n.and(k -> k.eq("scope_type", PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name()) - .and(l -> l.in("scope_id", categoriesPath))))); + .and(l -> l.in(CollUtil.isNotEmpty(categoriesPath), "scope_id", categoriesPath))))); queryWrapper.and(i -> i.or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)).or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.NEW))); return this.list(queryWrapper); }