!349 fix & improve

Merge pull request !349 from OceansDeep/pg
This commit is contained in:
OceansDeep 2024-06-17 07:14:46 +00:00 committed by Gitee
commit 763519876e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 8 additions and 25 deletions

View File

@ -4,7 +4,6 @@ import cn.lili.cache.CachePrefix;
import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.PromotionTypeEnum;
import cn.lili.common.vo.PageVO; import cn.lili.common.vo.PageVO;
import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.dos.GoodsSku;
import cn.lili.modules.goods.entity.dto.GoodsSkuDTO;
import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dos.PromotionGoods;
import cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams; import cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -52,7 +51,7 @@ public interface PromotionGoodsService extends IService<PromotionGoods> {
* @param skus 商品skuId * @param skus 商品skuId
* @return 促销商品集合 * @return 促销商品集合
*/ */
List<PromotionGoods> findSkuValidPromotions(List<GoodsSkuDTO> skus); List<PromotionGoods> findSkuValidPromotions(List<String> skus);
/** /**
* 分页获取促销商品信息 * 分页获取促销商品信息

View File

@ -1,15 +1,12 @@
package cn.lili.modules.promotion.serviceimpl; package cn.lili.modules.promotion.serviceimpl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import cn.lili.cache.Cache; import cn.lili.cache.Cache;
import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.PromotionTypeEnum;
import cn.lili.common.vo.PageVO; import cn.lili.common.vo.PageVO;
import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.dos.GoodsSku;
import cn.lili.modules.goods.entity.dto.GoodsSkuDTO;
import cn.lili.modules.goods.entity.vos.GoodsVO; import cn.lili.modules.goods.entity.vos.GoodsVO;
import cn.lili.modules.goods.service.GoodsService; import cn.lili.modules.goods.service.GoodsService;
import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.goods.service.GoodsSkuService;
@ -34,7 +31,6 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -52,11 +48,6 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
private static final String SKU_ID_COLUMN = "sku_id"; private static final String SKU_ID_COLUMN = "sku_id";
/**
* Redis
*/
@Autowired
private StringRedisTemplate stringRedisTemplate;
/** /**
* 秒杀活动申请 * 秒杀活动申请
*/ */
@ -96,22 +87,12 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
} }
@Override @Override
public List<PromotionGoods> findSkuValidPromotions(List<GoodsSkuDTO> skus) { public List<PromotionGoods> findSkuValidPromotions(List<String> skuIds) {
List<String> categories = skus.stream().map(GoodsSku::getCategoryPath).collect(Collectors.toList());
List<String> skuIds = skus.stream().map(GoodsSku::getId).collect(Collectors.toList());
List<String> categoriesPath = new ArrayList<>();
categories.forEach(i -> {
if (CharSequenceUtil.isNotEmpty(i)) {
categoriesPath.addAll(Arrays.asList(i.split(",")));
}
}
);
QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>(); QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>();
queryWrapper.and(i -> i.or(j -> j.in(SKU_ID_COLUMN, skuIds)) queryWrapper.and(i -> i.or(j -> j.in(SKU_ID_COLUMN, skuIds))
.or(n -> n.eq("scope_type", PromotionsScopeTypeEnum.ALL.name())) .or(n -> n.eq("scope_type", PromotionsScopeTypeEnum.ALL.name()))
.or(n -> n.and(k -> k.eq("scope_type", PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name()) .or(n -> n.and(k -> k.eq("scope_type", PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name()))));
.and(l -> l.in(CollUtil.isNotEmpty(categoriesPath), "scope_id", categoriesPath)))));
queryWrapper.and(i -> i.or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)).or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.NEW))); queryWrapper.and(i -> i.or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)).or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.NEW)));
return this.list(queryWrapper); return this.list(queryWrapper);
} }

View File

@ -196,7 +196,8 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
if (skuIPage == null || CollUtil.isEmpty(skuIPage.getRecords())) { if (skuIPage == null || CollUtil.isEmpty(skuIPage.getRecords())) {
break; break;
} }
List<PromotionGoods> skuValidPromotions = promotionGoodsService.findSkuValidPromotions(skuIPage.getRecords()); List<String> skuIds = skuIPage.getRecords().stream().map(GoodsSku::getId).collect(Collectors.toList());
List<PromotionGoods> skuValidPromotions = promotionGoodsService.findSkuValidPromotions(skuIds);
List<String> brandIds = new ArrayList<>(); List<String> brandIds = new ArrayList<>();
@ -248,7 +249,9 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
(CharSequenceUtil.isNotEmpty(j.getSkuId()) && j.getSkuId().equals(goodsSku.getId())) || (CharSequenceUtil.isNotEmpty(j.getSkuId()) && j.getSkuId().equals(goodsSku.getId())) ||
(j.getScopeType().equals(PromotionsScopeTypeEnum.ALL.name()) && j.getStoreId().equals("0")) || (j.getScopeType().equals(PromotionsScopeTypeEnum.ALL.name()) && j.getStoreId().equals("0")) ||
(j.getScopeType().equals(PromotionsScopeTypeEnum.ALL.name()) && j.getStoreId().equals(esGoodsIndex.getStoreId())) || (j.getScopeType().equals(PromotionsScopeTypeEnum.ALL.name()) && j.getStoreId().equals(esGoodsIndex.getStoreId())) ||
(j.getScopeType().equals(PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name()) && j.getScopeId().contains(goodsSku.getCategoryPath()))) (j.getScopeType().equals(PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name()) && j.getStoreId().equals("0") && j.getScopeId().contains(goodsSku.getCategoryPath()))||
(j.getScopeType().equals(PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name()) && j.getStoreId().equals(goodsSku.getStoreId()) && j.getScopeId().contains(goodsSku.getCategoryPath()))
)
.collect(Collectors.toList()); .collect(Collectors.toList());
if (CollUtil.isNotEmpty(promotionGoods)) { if (CollUtil.isNotEmpty(promotionGoods)) {
esGoodsIndex.setPromotionMapJson(JSONUtil.toJsonStr(promotionService.wrapperPromotionMapList(promotionGoods))); esGoodsIndex.setPromotionMapJson(JSONUtil.toJsonStr(promotionService.wrapperPromotionMapList(promotionGoods)));