From 486bebe6d2ade36095ed6c50f96ad9543116ede6 Mon Sep 17 00:00:00 2001 From: xiaochangbai <704566072@qq.com> Date: Wed, 1 Jun 2022 18:03:30 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat:=E6=99=BA=E8=83=BD=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=8E=A8=E8=8D=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../search/entity/dto/EsGoodsSearchDTO.java | 3 ++ .../serviceimpl/EsGoodsSearchServiceImpl.java | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/framework/src/main/java/cn/lili/modules/search/entity/dto/EsGoodsSearchDTO.java b/framework/src/main/java/cn/lili/modules/search/entity/dto/EsGoodsSearchDTO.java index 564d0ecd..2f0759d6 100644 --- a/framework/src/main/java/cn/lili/modules/search/entity/dto/EsGoodsSearchDTO.java +++ b/framework/src/main/java/cn/lili/modules/search/entity/dto/EsGoodsSearchDTO.java @@ -44,4 +44,7 @@ public class EsGoodsSearchDTO { @ApiModelProperty(hidden = true) private Map> notShowCol = new HashMap<>(); + @ApiModelProperty("当前商品skuId,根据当前浏览的商品信息来给用户推荐可能喜欢的商品") + private String currentGoodsId; + } diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java index 620d3bd8..e77d5bce 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java @@ -363,6 +363,9 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService { //对查询条件进行处理 this.commonSearch(filterBuilder, searchDTO); + //智能推荐 + this.recommended(filterBuilder,searchDTO); + //未上架的商品不显示 filterBuilder.must(QueryBuilders.matchQuery("marketEnable", GoodsStatusEnum.UPPER.name())); //待审核和审核不通过的商品不显示 @@ -401,6 +404,36 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService { return nativeSearchQueryBuilder; } + /** + * 商品推荐 + * @param filterBuilder + * @param searchDTO + */ + private void recommended(BoolQueryBuilder filterBuilder, EsGoodsSearchDTO searchDTO) { + EsGoodsIndex currentGoodsIndice = null; + if(CharSequenceUtil.isNotEmpty(searchDTO.getCurrentGoodsId())){ + //查询当前商品的信息 + NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder(); + NativeSearchQuery build = searchQueryBuilder.build(); + build.setIds(Arrays.asList(searchDTO.getCurrentGoodsId())); + List esGoodsIndices = restTemplate.multiGet(build, EsGoodsIndex.class, restTemplate.getIndexCoordinatesFor(EsGoodsIndex.class)); + if(esGoodsIndices==null || esGoodsIndices.size()<1){ + return; + } + currentGoodsIndice = esGoodsIndices.get(0); + } + //推荐相同分类的商品 + String categoryPath = currentGoodsIndice.getCategoryPath(); + if(CharSequenceUtil.isNotEmpty(categoryPath)){ + //匹配二级分类 + String substring = categoryPath.substring(0, categoryPath.lastIndexOf(",")); + filterBuilder.must(QueryBuilders.wildcardQuery("categoryPath",substring+"*")); + } + + //排除当前商品 + filterBuilder.mustNot(QueryBuilders.matchQuery("id",searchDTO.getCurrentGoodsId())); + } + /** * 查询属性处理 * From ccb57411a2f0ae224aafd87daa67bcf8467ea4ac Mon Sep 17 00:00:00 2001 From: xiaochangbai <704566072@qq.com> Date: Wed, 1 Jun 2022 21:27:51 +0800 Subject: [PATCH 2/6] =?UTF-8?q?refactor:=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serviceimpl/EsGoodsSearchServiceImpl.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java index e77d5bce..e91bd477 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java @@ -410,28 +410,28 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService { * @param searchDTO */ private void recommended(BoolQueryBuilder filterBuilder, EsGoodsSearchDTO searchDTO) { - EsGoodsIndex currentGoodsIndice = null; - if(CharSequenceUtil.isNotEmpty(searchDTO.getCurrentGoodsId())){ - //查询当前商品的信息 - NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder(); - NativeSearchQuery build = searchQueryBuilder.build(); - build.setIds(Arrays.asList(searchDTO.getCurrentGoodsId())); - List esGoodsIndices = restTemplate.multiGet(build, EsGoodsIndex.class, restTemplate.getIndexCoordinatesFor(EsGoodsIndex.class)); - if(esGoodsIndices==null || esGoodsIndices.size()<1){ - return; - } - currentGoodsIndice = esGoodsIndices.get(0); + + String currentGoodsId = searchDTO.getCurrentGoodsId(); + if(CharSequenceUtil.isEmpty(currentGoodsId)) { + return; } - //推荐相同分类的商品 - String categoryPath = currentGoodsIndice.getCategoryPath(); + + //排除当前商品 + filterBuilder.mustNot(QueryBuilders.matchQuery("id",currentGoodsId)); + + //查询当前浏览商品的索引信息 + EsGoodsIndex esGoodsIndex = restTemplate.get(currentGoodsId, EsGoodsIndex.class); + if(esGoodsIndex==null) { + return; + } + //推荐与当前浏览商品相同一个二级分类下的商品 + String categoryPath = esGoodsIndex.getCategoryPath(); if(CharSequenceUtil.isNotEmpty(categoryPath)){ //匹配二级分类 String substring = categoryPath.substring(0, categoryPath.lastIndexOf(",")); filterBuilder.must(QueryBuilders.wildcardQuery("categoryPath",substring+"*")); } - //排除当前商品 - filterBuilder.mustNot(QueryBuilders.matchQuery("id",searchDTO.getCurrentGoodsId())); } /** From 234b8ab31c3b942c932ac0375eb7c9a1932fa6f1 Mon Sep 17 00:00:00 2001 From: paulGao Date: Thu, 2 Jun 2022 10:31:24 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BB=93=E7=AE=97?= =?UTF-8?q?=E6=97=B6=E5=BD=93=E5=89=8D=E5=95=86=E5=93=81=E4=BF=83=E9=94=80?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=8A=B6=E6=80=81=E7=9A=84=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=EF=BC=88=E4=BF=AE=E5=A4=8D=E6=89=8B=E5=8A=A8=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=88=96=E4=B8=8B=E6=9E=B6=E4=BF=83=E9=94=80=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E8=B4=AD=E7=89=A9=E8=BD=A6=E5=95=86=E5=93=81?= =?UTF-8?q?=E8=BF=98=E6=98=AF=E4=BF=83=E9=94=80=E4=BB=B7=E6=A0=BC=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/cart/entity/vo/CartSkuVO.java | 4 ++ .../cart/render/impl/CheckDataRender.java | 17 ++++++ .../order/cart/service/CartServiceImpl.java | 38 +----------- .../service/PromotionGoodsService.java | 17 +++++- .../PromotionGoodsServiceImpl.java | 58 +++++++++++++++++-- .../promotion/tools/PromotionCacheKeys.java | 39 ------------- 6 files changed, 88 insertions(+), 85 deletions(-) delete mode 100644 framework/src/main/java/cn/lili/modules/promotion/tools/PromotionCacheKeys.java diff --git a/framework/src/main/java/cn/lili/modules/order/cart/entity/vo/CartSkuVO.java b/framework/src/main/java/cn/lili/modules/order/cart/entity/vo/CartSkuVO.java index 59f2e7ea..30608258 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/entity/vo/CartSkuVO.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/entity/vo/CartSkuVO.java @@ -117,4 +117,8 @@ public class CartSkuVO extends CartBase implements Serializable { public Map getPromotionMap() { return PromotionTools.filterInvalidPromotionsMap(this.promotionMap); } + + public Map getNotFilterPromotionMap() { + return this.promotionMap; + } } diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java index 1430263b..8cb02a48 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java @@ -31,6 +31,7 @@ import cn.lili.modules.promotion.entity.dos.Coupon; import cn.lili.modules.promotion.entity.dos.Pintuan; import cn.lili.modules.promotion.entity.dos.PointsGoods; import cn.lili.modules.promotion.entity.vos.CouponVO; +import cn.lili.modules.promotion.service.PromotionGoodsService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -63,6 +64,11 @@ public class CheckDataRender implements CartRenderStep { @Autowired private WholesaleService wholesaleService; + /** + * 商品索引 + */ + @Autowired + private PromotionGoodsService promotionGoodsService; @Override public RenderStepEnums step() { @@ -127,6 +133,17 @@ public class CheckDataRender implements CartRenderStep { //设置失效消息 cartSkuVO.setErrorMessage("商品库存不足,现有库存数量[" + dataSku.getQuantity() + "]"); } + //如果存在商品促销活动,则判定商品促销状态 + if (CollUtil.isNotEmpty(cartSkuVO.getNotFilterPromotionMap()) || Boolean.TRUE.equals(cartSkuVO.getGoodsSku().getPromotionFlag())) { + //获取当前最新的促销信息 + cartSkuVO.setPromotionMap(this.promotionGoodsService.getCurrentGoodsPromotion(cartSkuVO.getGoodsSku(), tradeDTO.getCartTypeEnum().name())); + //设定商品价格 + Double goodsPrice = cartSkuVO.getGoodsSku().getPromotionFlag() != null && cartSkuVO.getGoodsSku().getPromotionFlag() ? cartSkuVO.getGoodsSku().getPromotionPrice() : cartSkuVO.getGoodsSku().getPrice(); + cartSkuVO.setPurchasePrice(goodsPrice); + cartSkuVO.setUtilPrice(goodsPrice); + cartSkuVO.setSubTotal(CurrencyUtil.mul(cartSkuVO.getPurchasePrice(), cartSkuVO.getNum())); + } + } } diff --git a/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java b/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java index f23459df..0712ddca 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java @@ -16,7 +16,6 @@ import cn.lili.modules.goods.entity.dos.Wholesale; import cn.lili.modules.goods.entity.enums.GoodsAuthEnum; import cn.lili.modules.goods.entity.enums.GoodsSalesModeEnum; import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; -import cn.lili.modules.goods.entity.vos.GoodsVO; import cn.lili.modules.goods.service.GoodsService; import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.goods.service.WholesaleService; @@ -36,10 +35,8 @@ import cn.lili.modules.order.order.entity.dos.Trade; import cn.lili.modules.order.order.entity.vo.ReceiptVO; import cn.lili.modules.promotion.entity.dos.KanjiaActivity; import cn.lili.modules.promotion.entity.dos.MemberCoupon; -import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dto.search.KanjiaActivitySearchParams; import cn.lili.modules.promotion.entity.dto.search.MemberCouponSearchParams; -import cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams; import cn.lili.modules.promotion.entity.enums.KanJiaStatusEnum; import cn.lili.modules.promotion.entity.enums.MemberCouponStatusEnum; import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; @@ -139,7 +136,7 @@ public class CartServiceImpl implements CartService { } CartTypeEnum cartTypeEnum = getCartType(cartType); GoodsSku dataSku = checkGoods(skuId); - Map promotionMap = this.getCurrentGoodsPromotion(dataSku, cartType); + Map promotionMap = promotionGoodsService.getCurrentGoodsPromotion(dataSku, cartType); try { //购物车方式购买需要保存之前的选择,其他方式购买,则直接抹除掉之前的记录 @@ -554,39 +551,6 @@ public class CartServiceImpl implements CartService { return trade; } - private Map getCurrentGoodsPromotion(GoodsSku dataSku, String cartType) { - Map promotionMap; - EsGoodsIndex goodsIndex = goodsIndexService.findById(dataSku.getId()); - if (goodsIndex == null) { - GoodsVO goodsVO = this.goodsService.getGoodsVO(dataSku.getGoodsId()); - goodsIndex = goodsIndexService.getResetEsGoodsIndex(dataSku, goodsVO.getGoodsParamsDTOList()); - } - if (goodsIndex.getPromotionMap() != null && !goodsIndex.getPromotionMap().isEmpty()) { - if (goodsIndex.getPromotionMap().keySet().stream().anyMatch(i -> i.contains(PromotionTypeEnum.SECKILL.name())) || (goodsIndex.getPromotionMap().keySet().stream().anyMatch(i -> i.contains(PromotionTypeEnum.PINTUAN.name())) && CartTypeEnum.PINTUAN.name().equals(cartType))) { - - Optional> containsPromotion = goodsIndex.getPromotionMap().entrySet().stream().filter(i -> i.getKey().contains(PromotionTypeEnum.SECKILL.name()) || i.getKey().contains(PromotionTypeEnum.PINTUAN.name())).findFirst(); - if (containsPromotion.isPresent()) { - JSONObject promotionsObj = JSONUtil.parseObj(containsPromotion.get().getValue()); - PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); - searchParams.setSkuId(dataSku.getId()); - searchParams.setPromotionId(promotionsObj.get("id").toString()); - PromotionGoods promotionsGoods = promotionGoodsService.getPromotionsGoods(searchParams); - if (promotionsGoods != null && promotionsGoods.getPrice() != null) { - dataSku.setPromotionFlag(true); - dataSku.setPromotionPrice(promotionsGoods.getPrice()); - } else { - dataSku.setPromotionFlag(false); - dataSku.setPromotionPrice(null); - } - } - } - promotionMap = goodsIndex.getPromotionMap(); - } else { - promotionMap = null; - } - return promotionMap; - } - /** * 获取购物车类型 diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/PromotionGoodsService.java b/framework/src/main/java/cn/lili/modules/promotion/service/PromotionGoodsService.java index 58a80e00..4aac7c38 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/PromotionGoodsService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/PromotionGoodsService.java @@ -3,6 +3,7 @@ package cn.lili.modules.promotion.service; import cn.lili.cache.CachePrefix; import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.vo.PageVO; +import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -10,6 +11,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import java.util.Date; import java.util.List; +import java.util.Map; /** * 促销商品业务层 @@ -35,7 +37,7 @@ public interface PromotionGoodsService extends IService { /** * 获取某sku所有有效活动 * - * @param skuId 商品skuId + * @param skuId 商品skuId * @param storeIds 店铺id * @return 促销商品集合 */ @@ -70,7 +72,7 @@ public interface PromotionGoodsService extends IService { /** * 获取当前有效时间特定促销类型的促销商品信息 * - * @param skuId skuId + * @param skuId skuId * @param promotionTypes 特定促销类型 * @return 促销商品信息 */ @@ -79,7 +81,7 @@ public interface PromotionGoodsService extends IService { /** * 获取当前有效时间特定促销类型的促销商品价格 * - * @param skuId skuId + * @param skuId skuId * @param promotionTypes 特定促销类型 * @return 促销商品价格 */ @@ -154,4 +156,13 @@ public interface PromotionGoodsService extends IService { */ void deletePromotionGoods(PromotionGoodsSearchParams searchParams); + /** + * 获取当前商品促销信息 + * + * @param dataSku 商品sku信息 + * @param cartType 购物车类型 + * @return 当前商品促销信息 + */ + Map getCurrentGoodsPromotion(GoodsSku dataSku, String cartType); + } \ No newline at end of file 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 cc2a993f..98852a25 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 @@ -2,10 +2,15 @@ package cn.lili.modules.promotion.serviceimpl; import cn.hutool.core.convert.Convert; import cn.hutool.core.text.CharSequenceUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.vo.PageVO; import cn.lili.modules.goods.entity.dos.GoodsSku; +import cn.lili.modules.goods.entity.vos.GoodsVO; +import cn.lili.modules.goods.service.GoodsService; import cn.lili.modules.goods.service.GoodsSkuService; +import cn.lili.modules.order.cart.entity.enums.CartTypeEnum; import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dos.SeckillApply; import cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams; @@ -16,6 +21,8 @@ import cn.lili.modules.promotion.mapper.PromotionGoodsMapper; import cn.lili.modules.promotion.service.PromotionGoodsService; import cn.lili.modules.promotion.service.SeckillApplyService; import cn.lili.modules.promotion.tools.PromotionTools; +import cn.lili.modules.search.entity.dos.EsGoodsIndex; +import cn.lili.modules.search.service.EsGoodsIndexService; import cn.lili.mybatis.util.PageUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -27,10 +34,7 @@ import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; +import java.util.*; /** * 促销商品业务层实现 @@ -59,6 +63,12 @@ public class PromotionGoodsServiceImpl extends ServiceImpl findSkuValidPromotion(String skuId, String storeIds) { @@ -267,8 +277,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl promotionIds) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() - .in(PromotionGoods::getPromotionId, promotionIds); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper().in(PromotionGoods::getPromotionId, promotionIds); this.remove(queryWrapper); } @@ -282,4 +291,41 @@ public class PromotionGoodsServiceImpl extends ServiceImpl getCurrentGoodsPromotion(GoodsSku dataSku, String cartType) { + Map promotionMap; + EsGoodsIndex goodsIndex = goodsIndexService.findById(dataSku.getId()); + if (goodsIndex == null) { + GoodsVO goodsVO = this.goodsService.getGoodsVO(dataSku.getGoodsId()); + goodsIndex = goodsIndexService.getResetEsGoodsIndex(dataSku, goodsVO.getGoodsParamsDTOList()); + } + if (goodsIndex.getPromotionMap() != null && !goodsIndex.getPromotionMap().isEmpty()) { + if (goodsIndex.getPromotionMap().keySet().stream().anyMatch(i -> i.contains(PromotionTypeEnum.SECKILL.name())) || (goodsIndex.getPromotionMap().keySet().stream().anyMatch(i -> i.contains(PromotionTypeEnum.PINTUAN.name())) && CartTypeEnum.PINTUAN.name().equals(cartType))) { + Optional> containsPromotion = goodsIndex.getPromotionMap().entrySet().stream().filter(i -> i.getKey().contains(PromotionTypeEnum.SECKILL.name()) || i.getKey().contains(PromotionTypeEnum.PINTUAN.name())).findFirst(); + containsPromotion.ifPresent(stringObjectEntry -> this.setGoodsPromotionInfo(dataSku, stringObjectEntry)); + } + promotionMap = goodsIndex.getPromotionMap(); + } else { + promotionMap = null; + dataSku.setPromotionFlag(false); + dataSku.setPromotionPrice(null); + } + return promotionMap; + } + + private void setGoodsPromotionInfo(GoodsSku dataSku, Map.Entry promotionInfo) { + JSONObject promotionsObj = JSONUtil.parseObj(promotionInfo); + PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); + searchParams.setSkuId(dataSku.getId()); + searchParams.setPromotionId(promotionsObj.get("id").toString()); + PromotionGoods promotionsGoods = this.getPromotionsGoods(searchParams); + if (promotionsGoods != null && promotionsGoods.getPrice() != null) { + dataSku.setPromotionFlag(true); + dataSku.setPromotionPrice(promotionsGoods.getPrice()); + } else { + dataSku.setPromotionFlag(false); + dataSku.setPromotionPrice(null); + } + } + } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionCacheKeys.java b/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionCacheKeys.java deleted file mode 100644 index 6281f779..00000000 --- a/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionCacheKeys.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.lili.modules.promotion.tools; - -import cn.lili.cache.CachePrefix; - -/** - * 满额活动缓存Key - * @author paulG - * @since 2020/10/12 - **/ -public class PromotionCacheKeys { - - /** - * 读取满优惠redis key - * @param activityId 活动ID - * @return 满优惠redis key - */ - public static String getFullDiscountKey(String activityId){ - return CachePrefix.STORE_ID_FULL_DISCOUNT + "::" + activityId; - } - - /** - * 读取满优惠redis key - * @param id id - * @return 满优惠redis key - */ - public static String getPromotionGoodsKey(String id){ - return CachePrefix.PROMOTION_GOODS + "::" + id; - } - - /** - * 读取秒杀活动redis key - * @param timeStr 时间字符串(格式为 yyyyMMdd) - * @return 满优惠redis key - */ - public static String getSeckillTimelineKey(String timeStr){ - return CachePrefix.STORE_ID_SECKILL + "::" + timeStr; - } - -} From c4d879a0ad37ef4c07b38c4c34e97ebadb384f38 Mon Sep 17 00:00:00 2001 From: paulGao Date: Thu, 2 Jun 2022 16:50:26 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=95=86=E5=93=81=E6=97=B6=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/lili/event/impl/StockUpdateExecute.java | 1 + .../modules/goods/serviceimpl/GoodsSkuServiceImpl.java | 10 +++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/consumer/src/main/java/cn/lili/event/impl/StockUpdateExecute.java b/consumer/src/main/java/cn/lili/event/impl/StockUpdateExecute.java index e03d38c0..ceee4a1a 100644 --- a/consumer/src/main/java/cn/lili/event/impl/StockUpdateExecute.java +++ b/consumer/src/main/java/cn/lili/event/impl/StockUpdateExecute.java @@ -358,6 +358,7 @@ public class StockUpdateExecute implements OrderStatusChangeEvent { skuKeys.add(GoodsSkuService.getStockCacheKey(orderItem.getSkuId())); GoodsSku goodsSku = new GoodsSku(); goodsSku.setId(orderItem.getSkuId()); + goodsSku.setGoodsId(orderItem.getGoodsId()); goodsSkus.add(goodsSku); } //批量获取商品库存 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 72e32930..aa6bc4c4 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 @@ -506,18 +506,14 @@ public class GoodsSkuServiceImpl extends ServiceImpl i @Override @Transactional(rollbackFor = Exception.class) public void updateGoodsStuck(List goodsSkus) { - //商品id集合 hashset 去重复 - Set goodsIds = new HashSet<>(); - for (GoodsSku sku : goodsSkus) { - goodsIds.add(sku.getGoodsId()); - } + Map> groupByGoodsIds = goodsSkus.stream().collect(Collectors.groupingBy(GoodsSku::getGoodsId)); //获取相关的sku集合 LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.in(GoodsSku::getGoodsId, goodsIds); + lambdaQueryWrapper.in(GoodsSku::getGoodsId, groupByGoodsIds.keySet()); List goodsSkuList = this.list(lambdaQueryWrapper); //统计每个商品的库存 - for (String goodsId : goodsIds) { + for (String goodsId : groupByGoodsIds.keySet()) { //库存 Integer quantity = 0; for (GoodsSku goodsSku : goodsSkuList) { From 65a4bb77788149b5c814424ad403af99bcb0097b Mon Sep 17 00:00:00 2001 From: paulGao Date: Mon, 6 Jun 2022 10:12:09 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=8F=91=E7=94=9F=E7=9A=84=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E4=BF=A1=E6=81=AF=E6=97=B6=E5=8F=91=E7=94=9F?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/order/entity/vo/OrderItemVO.java | 34 +++++++++++-- .../order/order/entity/vo/OrderSimpleVO.java | 50 ++++++++++++++----- 2 files changed, 67 insertions(+), 17 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/order/order/entity/vo/OrderItemVO.java b/framework/src/main/java/cn/lili/modules/order/order/entity/vo/OrderItemVO.java index 6d091159..5ab18dcf 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/entity/vo/OrderItemVO.java +++ b/framework/src/main/java/cn/lili/modules/order/order/entity/vo/OrderItemVO.java @@ -5,6 +5,7 @@ import cn.lili.modules.order.order.entity.enums.OrderComplaintStatusEnum; import cn.lili.modules.order.order.entity.enums.OrderItemAfterSaleStatusEnum; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.NoArgsConstructor; /** * 子订单VO @@ -13,6 +14,7 @@ import lombok.Data; * @since 2020-08-17 20:28 */ @Data +@NoArgsConstructor public class OrderItemVO { @ApiModelProperty(value = "编号") @@ -55,17 +57,39 @@ public class OrderItemVO { private String commentStatus; - public OrderItemVO(String sn, String goodsId, String skuId, String num, String image, String name, String afterSaleStatus, String complainStatus, String commentStatus, Double goodsPrice) { + public void setSn(String sn) { this.sn = sn; - this.goodsId = goodsId; + } + + public void setSkuId(String skuId) { this.skuId = skuId; + } + + public void setNum(String num) { this.num = num; + } + + public void setImage(String image) { this.image = image; + } + + public void setName(String name) { this.name = name; - this.afterSaleStatus = afterSaleStatus; - this.complainStatus = complainStatus; - this.commentStatus = commentStatus; + } + + public void setGoodsPrice(Double goodsPrice) { this.goodsPrice = goodsPrice; } + public void setAfterSaleStatus(String afterSaleStatus) { + this.afterSaleStatus = afterSaleStatus; + } + + public void setComplainStatus(String complainStatus) { + this.complainStatus = complainStatus; + } + + public void setCommentStatus(String commentStatus) { + this.commentStatus = commentStatus; + } } diff --git a/framework/src/main/java/cn/lili/modules/order/order/entity/vo/OrderSimpleVO.java b/framework/src/main/java/cn/lili/modules/order/order/entity/vo/OrderSimpleVO.java index f44efa3d..4f58fb0c 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/entity/vo/OrderSimpleVO.java +++ b/framework/src/main/java/cn/lili/modules/order/order/entity/vo/OrderSimpleVO.java @@ -1,7 +1,7 @@ package cn.lili.modules.order.order.entity.vo; +import cn.hutool.core.text.CharSequenceUtil; import cn.lili.common.enums.ClientTypeEnum; -import cn.lili.common.utils.StringUtils; import cn.lili.modules.order.order.entity.enums.*; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; @@ -135,28 +135,54 @@ public class OrderSimpleVO { private String deliverStatus; public List getOrderItems() { - if (StringUtils.isEmpty(groupGoodsId)) { + if (CharSequenceUtil.isEmpty(groupGoodsId)) { return new ArrayList<>(); } List orderItemVOS = new ArrayList<>(); - String[] orderItemsSn = groupOrderItemsSn.split(","); + + String[] goodsId = groupGoodsId.split(","); - String[] skuId = groupSkuId.split(","); - String[] num = groupNum.split(","); - String[] image = groupImages.split(","); - String[] name = groupName.split(","); - String[] afterSaleStatus = groupAfterSaleStatus.split(","); - String[] complainStatus = groupComplainStatus.split(","); - String[] commentStatus = groupCommentStatus.split(","); - String[] goodsPrice = groupGoodsPrice.split(","); for (int i = 0; i < goodsId.length; i++) { - orderItemVOS.add(new OrderItemVO(orderItemsSn[i], goodsId[i], skuId[i], num[i], image[i], name[i], afterSaleStatus[i], complainStatus[i], commentStatus[i], Double.parseDouble(goodsPrice[i]))); + orderItemVOS.add(this.getOrderItemVO(i)); } return orderItemVOS; } + private OrderItemVO getOrderItemVO(int i) { + OrderItemVO orderItemVO = new OrderItemVO(); + orderItemVO.setGoodsId(groupGoodsId.split(",")[i]); + if (CharSequenceUtil.isNotEmpty(groupOrderItemsSn)) { + orderItemVO.setSn(groupOrderItemsSn.split(",")[i]); + } + if (CharSequenceUtil.isNotEmpty(groupSkuId)) { + orderItemVO.setSkuId(groupSkuId.split(",")[i]); + } + if (CharSequenceUtil.isNotEmpty(groupName)) { + orderItemVO.setName(groupName.split(",")[i]); + } + if (CharSequenceUtil.isNotEmpty(groupNum) && groupNum.split(",").length == groupGoodsId.split(",").length) { + orderItemVO.setNum(groupNum.split(",")[i]); + } + if (CharSequenceUtil.isNotEmpty(groupImages) && groupImages.split(",").length == groupGoodsId.split(",").length) { + orderItemVO.setImage(groupImages.split(",")[i]); + } + if (CharSequenceUtil.isNotEmpty(groupAfterSaleStatus) && groupAfterSaleStatus.split(",").length == groupGoodsId.split(",").length) { + orderItemVO.setAfterSaleStatus(groupAfterSaleStatus.split(",")[i]); + } + if (CharSequenceUtil.isNotEmpty(groupComplainStatus) && groupComplainStatus.split(",").length == groupGoodsId.split(",").length) { + orderItemVO.setComplainStatus(groupComplainStatus.split(",")[i]); + } + if (CharSequenceUtil.isNotEmpty(groupCommentStatus) && groupCommentStatus.split(",").length == groupGoodsId.split(",").length) { + orderItemVO.setCommentStatus(groupCommentStatus.split(",")[i]); + } + if (CharSequenceUtil.isNotEmpty(groupGoodsPrice) && groupGoodsPrice.split(",").length == groupGoodsId.split(",").length) { + orderItemVO.setGoodsPrice(Double.parseDouble(groupGoodsPrice.split(",")[i])); + } + return orderItemVO; + } + /** * 初始化自身状态 */ From ee3f8a92616b4e1e16954a59794a90f00728b8ac Mon Sep 17 00:00:00 2001 From: paulGao Date: Mon, 6 Jun 2022 15:24:52 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=B8=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=E8=8E=B7=E5=8F=96=E7=9A=84=E4=BC=98=E6=83=A0=E5=88=B8?= =?UTF-8?q?=E6=9F=90=E4=BA=9B=E6=83=85=E5=86=B5=E4=B8=8D=E8=83=BD=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/lili/modules/order/cart/service/CartServiceImpl.java | 3 +++ .../cn/lili/modules/order/order/entity/vo/OrderSimpleVO.java | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java b/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java index 0712ddca..7b44ed78 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java @@ -604,6 +604,9 @@ public class CartServiceImpl implements CartService { cartPrice = CurrencyUtil.add(cartPrice, CurrencyUtil.mul(cartSkuVO.getGoodsSku().getPrice(), cartSkuVO.getNum())); skuPrice.put(cartSkuVO.getGoodsSku().getId(), CurrencyUtil.mul(cartSkuVO.getGoodsSku().getPrice(), cartSkuVO.getNum())); } + } else { + cartPrice = CurrencyUtil.add(cartPrice, CurrencyUtil.mul(cartSkuVO.getGoodsSku().getPrice(), cartSkuVO.getNum())); + skuPrice.put(cartSkuVO.getGoodsSku().getId(), CurrencyUtil.mul(cartSkuVO.getGoodsSku().getPrice(), cartSkuVO.getNum())); } } diff --git a/framework/src/main/java/cn/lili/modules/order/order/entity/vo/OrderSimpleVO.java b/framework/src/main/java/cn/lili/modules/order/order/entity/vo/OrderSimpleVO.java index 4f58fb0c..711ffd92 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/entity/vo/OrderSimpleVO.java +++ b/framework/src/main/java/cn/lili/modules/order/order/entity/vo/OrderSimpleVO.java @@ -2,7 +2,6 @@ package cn.lili.modules.order.order.entity.vo; import cn.hutool.core.text.CharSequenceUtil; import cn.lili.common.enums.ClientTypeEnum; -import cn.lili.modules.order.order.entity.enums.*; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.Data;