!96 优化更新索引促销方式,以更新部分字段的方式更新。不在以刷新索引的方式更新。
Merge pull request !96 from OceansDeep/feature/pg
This commit is contained in:
commit
68d03196af
@ -259,6 +259,7 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
|
||||
searchParams.setCategoryPath(promotions.getScopeId());
|
||||
List<GoodsSku> goodsSkuByList = this.goodsSkuService.getGoodsSkuByList(searchParams);
|
||||
List<String> skuIds = goodsSkuByList.stream().map(GoodsSku::getId).collect(Collectors.toList());
|
||||
this.goodsIndexService.deleteEsGoodsPromotionByPromotionId(skuIds, promotions.getId());
|
||||
this.goodsIndexService.updateEsGoodsIndexPromotions(skuIds, promotions, esPromotionKey);
|
||||
} else if (PromotionsScopeTypeEnum.ALL.name().equals(promotions.getScopeType())) {
|
||||
this.goodsIndexService.updateEsGoodsIndexAllByList(promotions, esPromotionKey);
|
||||
|
@ -7,6 +7,9 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springframework.data.elasticsearch.annotations.DateFormat;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.util.Date;
|
||||
@ -35,10 +38,12 @@ public class BasePromotions extends BaseEntity {
|
||||
|
||||
@ApiModelProperty(value = "活动开始时间", required = true)
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || yyyy/MM/dd HH:mm:ss|| yyyy/MM/dd ||epoch_millis")
|
||||
private Date startTime;
|
||||
|
||||
@ApiModelProperty(value = "活动结束时间", required = true)
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || yyyy/MM/dd HH:mm:ss|| yyyy/MM/dd ||epoch_millis")
|
||||
private Date endTime;
|
||||
|
||||
/**
|
||||
|
@ -425,6 +425,8 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
// 查询出全部商品
|
||||
goodsIndices = new ArrayList<>(IterableUtil.toCollection(all));
|
||||
}
|
||||
List<String> skuIds = goodsIndices.stream().map(EsGoodsIndex::getId).collect(Collectors.toList());
|
||||
this.deleteEsGoodsPromotionByPromotionId(skuIds, promotion.getId());
|
||||
//更新商品索引
|
||||
for (EsGoodsIndex goodsIndex : goodsIndices) {
|
||||
this.updateGoodsIndexPromotion(goodsIndex, key, promotion);
|
||||
@ -481,11 +483,11 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
private void removePromotionByPromotionId(EsGoodsIndex goodsIndex, String promotionId) {
|
||||
Map<String, Object> promotionMap = goodsIndex.getPromotionMap();
|
||||
if (promotionMap != null && !promotionMap.isEmpty()) {
|
||||
//如果存在同类型促销活动删除
|
||||
//如果存在同促销ID的活动删除
|
||||
List<String> collect = promotionMap.keySet().stream().filter(i -> i.split("-")[1].equals(promotionId)).collect(Collectors.toList());
|
||||
collect.forEach(promotionMap::remove);
|
||||
goodsIndex.setPromotionMap(promotionMap);
|
||||
updateIndex(goodsIndex);
|
||||
this.updatePromotionsByScript(goodsIndex.getId(), promotionMap);
|
||||
}
|
||||
}
|
||||
|
||||
@ -611,8 +613,25 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
} else {
|
||||
promotionMap.put(key, promotion);
|
||||
}
|
||||
goodsIndex.setPromotionMap(promotionMap);
|
||||
updateIndex(goodsIndex);
|
||||
this.updatePromotionsByScript(goodsIndex.getId(), promotionMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 以更新部分字段的方式更新索引促销信息
|
||||
*
|
||||
* @param id 索引id
|
||||
* @param promotionMap 促销信息
|
||||
*/
|
||||
private void updatePromotionsByScript(String id, Map<String, Object> promotionMap) {
|
||||
JSONObject jsonObject = JSONUtil.parseObj(promotionMap);
|
||||
jsonObject.setDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String s = jsonObject.toString();
|
||||
String promotionsStr = s.replace("{", "[").replace("}", "]");
|
||||
|
||||
UpdateByQueryRequest update = new UpdateByQueryRequest(getIndexName());
|
||||
update.setQuery(QueryBuilders.boolQuery().filter(QueryBuilders.termsQuery("id", id)));
|
||||
update.setScript(new Script("ctx._source." + "promotionMap" + "=" + promotionsStr + ";"));
|
||||
client.updateByQueryAsync(update, RequestOptions.DEFAULT, this.actionListener());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,9 @@ import org.springframework.data.annotation.CreatedBy;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedBy;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.elasticsearch.annotations.DateFormat;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
@ -50,6 +53,7 @@ public abstract class BaseEntity implements Serializable {
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@ApiModelProperty(value = "创建时间", hidden = true)
|
||||
@Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || yyyy/MM/dd HH:mm:ss|| yyyy/MM/dd ||epoch_millis")
|
||||
private Date createTime;
|
||||
|
||||
@LastModifiedBy
|
||||
@ -62,6 +66,7 @@ public abstract class BaseEntity implements Serializable {
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
@ApiModelProperty(value = "更新时间", hidden = true)
|
||||
@Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || yyyy/MM/dd HH:mm:ss|| yyyy/MM/dd ||epoch_millis")
|
||||
private Date updateTime;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
|
Loading…
x
Reference in New Issue
Block a user