From c0932613690cf9dd19c6b5bfb13a1ccb12692c6d Mon Sep 17 00:00:00 2001 From: paulGao Date: Wed, 30 Mar 2022 17:17:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9B=B4=E6=96=B0=E5=95=86?= =?UTF-8?q?=E5=93=81=E7=B4=A2=E5=BC=95=E4=BF=83=E9=94=80=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9A=84=E4=BF=83=E9=94=80=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=B8=8D=E6=AD=A3=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lili/listener/GoodsMessageListener.java | 2 +- .../search/entity/dos/EsGoodsIndex.java | 16 +++++--- .../search/service/EsGoodsIndexService.java | 8 ---- .../serviceimpl/EsGoodsIndexServiceImpl.java | 39 ++++--------------- 4 files changed, 19 insertions(+), 46 deletions(-) diff --git a/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java b/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java index 5cc77b322..558b7c308 100644 --- a/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java +++ b/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java @@ -394,7 +394,7 @@ public class GoodsMessageListener implements RocketMQListener { } } - if (goodsIndex.getPromotionMap() == null || goodsIndex.getPromotionMap().isEmpty()) { + if (goodsIndex.getOriginPromotionMap() == null || goodsIndex.getOriginPromotionMap().isEmpty()) { Map goodsCurrentPromotionMap = promotionService.getGoodsSkuPromotionMap(goodsIndex.getStoreId(), goodsIndex.getId()); goodsIndex.setPromotionMapJson(JSONUtil.toJsonStr(goodsCurrentPromotionMap)); } diff --git a/framework/src/main/java/cn/lili/modules/search/entity/dos/EsGoodsIndex.java b/framework/src/main/java/cn/lili/modules/search/entity/dos/EsGoodsIndex.java index 813249b3b..b4cdf3fdc 100644 --- a/framework/src/main/java/cn/lili/modules/search/entity/dos/EsGoodsIndex.java +++ b/framework/src/main/java/cn/lili/modules/search/entity/dos/EsGoodsIndex.java @@ -97,42 +97,42 @@ public class EsGoodsIndex implements Serializable { /** * 品牌id */ - @Field(type = FieldType.Integer, fielddata = true) + @Field(type = FieldType.Text, fielddata = true) @ApiModelProperty("品牌id") private String brandId; /** * 品牌名称 */ - @Field(type = FieldType.Keyword, fielddata = true) + @Field(type = FieldType.Text, fielddata = true) @ApiModelProperty("品牌名称") private String brandName; /** * 品牌图片地址 */ - @Field(type = FieldType.Keyword, fielddata = true) + @Field(type = FieldType.Text, fielddata = true) @ApiModelProperty("品牌图片地址") private String brandUrl; /** * 分类path */ - @Field(type = FieldType.Keyword) + @Field(type = FieldType.Text, fielddata = true) @ApiModelProperty("分类path") private String categoryPath; /** * 分类名称path */ - @Field(type = FieldType.Keyword) + @Field(type = FieldType.Text, fielddata = true) @ApiModelProperty("分类名称path") private String categoryNamePath; /** * 店铺分类id */ - @Field(type = FieldType.Keyword) + @Field(type = FieldType.Text, fielddata = true) @ApiModelProperty("店铺分类id") private String storeCategoryPath; @@ -375,6 +375,10 @@ public class EsGoodsIndex implements Serializable { } } + public Map getOriginPromotionMap() { + return JSONUtil.parseObj(this.promotionMapJson); + } + public Map getPromotionMap() { return PromotionTools.filterInvalidPromotionsMap(JSONUtil.parseObj(this.promotionMapJson)); } diff --git a/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java b/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java index ffe12d042..3adff571e 100644 --- a/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java +++ b/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java @@ -131,14 +131,6 @@ public interface EsGoodsIndexService { */ void updateEsGoodsIndexAllByList(BasePromotions promotion, String key); - /** - * 删除指定商品的促销信息 - * - * @param skuIds skuId列表 - * @param promotionType 促销类型 - */ - void deleteEsGoodsPromotionIndexByList(List skuIds, PromotionTypeEnum promotionType); - /** * 删除索引中指定的促销活动id的促销活动 * diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java index ce342996a..b249984e8 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java @@ -451,27 +451,6 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements this.updateEsGoodsIndexPromotions(skuIds, promotion, key); } - @Override - public void deleteEsGoodsPromotionIndexByList(List skuIds, PromotionTypeEnum promotionType) { - //批量删除活动索引 - for (String skuId : skuIds) { - EsGoodsIndex goodsIndex = findById(skuId); - //商品索引不为空 - if (goodsIndex != null) { - Map promotionMap = goodsIndex.getPromotionMap(); - if (promotionMap != null && !promotionMap.isEmpty()) { - //如果存在同类型促销活动删除 - List collect = promotionMap.keySet().stream().filter(i -> i.contains(promotionType.name())).collect(Collectors.toList()); - collect.forEach(promotionMap::remove); - goodsIndex.setPromotionMapJson(JSONUtil.toJsonStr(promotionMap)); - updateIndex(goodsIndex); - } - } else { - log.error("更新索引商品促销信息失败!skuId 为 【{}】的索引不存在!", skuId); - } - } - } - @Override public void deleteEsGoodsPromotionByPromotionKey(List skuIds, String promotionsKey) { BulkRequest bulkRequest = new BulkRequest(); @@ -520,13 +499,11 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements * @param promotionsKey 促销活动key */ private UpdateRequest removePromotionByPromotionKey(EsGoodsIndex goodsIndex, String promotionsKey) { - Map promotionMap = goodsIndex.getPromotionMap(); + Map promotionMap = goodsIndex.getOriginPromotionMap(); if (promotionMap != null && !promotionMap.isEmpty()) { //如果存在同促销ID的活动删除 - List collect = promotionMap.keySet().stream().filter(i -> i.equals(promotionsKey)).collect(Collectors.toList()); - collect.forEach(promotionMap::remove); - goodsIndex.setPromotionMapJson(JSONUtil.toJsonStr(promotionMap)); - return this.getGoodsIndexPromotionUpdateRequest(goodsIndex.getId(), promotionMap); + Map filterPromotionMap = promotionMap.entrySet().stream().filter(i -> !i.getKey().equals(promotionsKey)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + return this.getGoodsIndexPromotionUpdateRequest(goodsIndex.getId(), filterPromotionMap); } return null; } @@ -538,7 +515,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements public void cleanInvalidPromotion() { Iterable all = goodsIndexRepository.findAll(); for (EsGoodsIndex goodsIndex : all) { - Map promotionMap = goodsIndex.getPromotionMap(); + Map promotionMap = goodsIndex.getOriginPromotionMap(); //获取商品索引 if (promotionMap != null && !promotionMap.isEmpty()) { //促销不为空则进行清洗 @@ -574,7 +551,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements //如果商品索引不为空,返回促销信息,否则返回空 if (goodsIndex != null) { - Map promotionMap = goodsIndex.getPromotionMap(); + Map promotionMap = goodsIndex.getOriginPromotionMap(); if (promotionMap == null || promotionMap.isEmpty()) { return new HashMap<>(16); } @@ -639,10 +616,10 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements private UpdateRequest updateGoodsIndexPromotion(EsGoodsIndex goodsIndex, String key, BasePromotions promotion) { Map promotionMap; //数据非空处理,如果空给一个新的信息 - if (goodsIndex.getPromotionMap() == null || goodsIndex.getPromotionMap().isEmpty()) { + if (goodsIndex.getOriginPromotionMap() == null || goodsIndex.getOriginPromotionMap().isEmpty()) { promotionMap = new HashMap<>(1); } else { - promotionMap = goodsIndex.getPromotionMap(); + promotionMap = goodsIndex.getOriginPromotionMap(); } log.info("ES修改商品活动索引-活动信息:{}", promotion); @@ -670,7 +647,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements UpdateRequest updateRequest = new UpdateRequest(); updateRequest.index(getIndexName()); updateRequest.id(id); -// updateRequest.retryOnConflict(5); + updateRequest.retryOnConflict(3); // updateRequest.version(promotionMap.size()); Map params = new HashMap<>(); params.put("promotionMap", JSONUtil.toJsonStr(promotionMap));