优化初始化商品索引,增加编辑商品时,保留原商品的销量、好评率和评价量
This commit is contained in:
parent
d14763d52c
commit
4316fa8953
@ -14,6 +14,7 @@ import cn.lili.common.properties.RocketmqCustomProperties;
|
|||||||
import cn.lili.common.security.context.UserContext;
|
import cn.lili.common.security.context.UserContext;
|
||||||
import cn.lili.common.utils.SnowFlake;
|
import cn.lili.common.utils.SnowFlake;
|
||||||
import cn.lili.modules.goods.entity.dos.Goods;
|
import cn.lili.modules.goods.entity.dos.Goods;
|
||||||
|
import cn.lili.modules.goods.entity.dos.GoodsGallery;
|
||||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||||
import cn.lili.modules.goods.entity.dto.GoodsOperationDTO;
|
import cn.lili.modules.goods.entity.dto.GoodsOperationDTO;
|
||||||
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
||||||
@ -166,8 +167,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
} else {
|
} else {
|
||||||
skuList = new ArrayList<>();
|
skuList = new ArrayList<>();
|
||||||
for (Map<String, Object> map : goodsOperationDTO.getSkuList()) {
|
for (Map<String, Object> map : goodsOperationDTO.getSkuList()) {
|
||||||
GoodsSku sku = null;
|
GoodsSku sku = GoodsSkuBuilder.build(goods, map, goodsOperationDTO);
|
||||||
sku = GoodsSkuBuilder.build(goods, map, goodsOperationDTO);
|
|
||||||
renderGoodsSku(sku, goodsOperationDTO);
|
renderGoodsSku(sku, goodsOperationDTO);
|
||||||
skuList.add(sku);
|
skuList.add(sku);
|
||||||
//如果商品状态值不对,则es索引移除
|
//如果商品状态值不对,则es索引移除
|
||||||
@ -636,6 +636,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
// 商品销售模式渲染器
|
// 商品销售模式渲染器
|
||||||
salesModelRenders.stream().filter(i -> i.getSalesMode().equals(goodsOperationDTO.getSalesModel())).findFirst().ifPresent(i -> i.renderBatch(goodsSkuList, goodsOperationDTO));
|
salesModelRenders.stream().filter(i -> i.getSalesMode().equals(goodsOperationDTO.getSalesModel())).findFirst().ifPresent(i -> i.renderBatch(goodsSkuList, goodsOperationDTO));
|
||||||
for (GoodsSku goodsSku : goodsSkuList) {
|
for (GoodsSku goodsSku : goodsSkuList) {
|
||||||
|
extendOldSkuValue(goodsSku);
|
||||||
this.renderImages(goodsSku);
|
this.renderImages(goodsSku);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -647,22 +648,43 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
* @param goodsOperationDTO 商品操作DTO
|
* @param goodsOperationDTO 商品操作DTO
|
||||||
*/
|
*/
|
||||||
void renderGoodsSku(GoodsSku goodsSku, GoodsOperationDTO goodsOperationDTO) {
|
void renderGoodsSku(GoodsSku goodsSku, GoodsOperationDTO goodsOperationDTO) {
|
||||||
|
extendOldSkuValue(goodsSku);
|
||||||
// 商品销售模式渲染器
|
// 商品销售模式渲染器
|
||||||
salesModelRenders.stream().filter(i -> i.getSalesMode().equals(goodsOperationDTO.getSalesModel())).findFirst().ifPresent(i -> i.renderSingle(goodsSku, goodsOperationDTO));
|
salesModelRenders.stream().filter(i -> i.getSalesMode().equals(goodsOperationDTO.getSalesModel())).findFirst().ifPresent(i -> i.renderSingle(goodsSku, goodsOperationDTO));
|
||||||
this.renderImages(goodsSku);
|
this.renderImages(goodsSku);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将原sku的一些不会直接传递的值放到新的sku中
|
||||||
|
*
|
||||||
|
* @param goodsSku 商品sku
|
||||||
|
*/
|
||||||
|
private void extendOldSkuValue(GoodsSku goodsSku) {
|
||||||
|
if (CharSequenceUtil.isNotEmpty(goodsSku.getGoodsId())) {
|
||||||
|
GoodsSku oldSku = this.getGoodsSkuByIdFromCache(goodsSku.getId());
|
||||||
|
if (oldSku != null) {
|
||||||
|
goodsSku.setCommentNum(oldSku.getCommentNum());
|
||||||
|
goodsSku.setViewCount(oldSku.getViewCount());
|
||||||
|
goodsSku.setBuyCount(oldSku.getBuyCount());
|
||||||
|
goodsSku.setGrade(oldSku.getGrade());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 渲染sku图片
|
* 渲染sku图片
|
||||||
*
|
*
|
||||||
* @param goodsSku
|
* @param goodsSku sku
|
||||||
*/
|
*/
|
||||||
void renderImages(GoodsSku goodsSku) {
|
void renderImages(GoodsSku goodsSku) {
|
||||||
JSONObject jsonObject = JSONUtil.parseObj(goodsSku.getSpecs());
|
JSONObject jsonObject = JSONUtil.parseObj(goodsSku.getSpecs());
|
||||||
List<Map<String, String>> images = jsonObject.get("images", List.class);
|
List<Map<String, String>> images = jsonObject.get("images", List.class);
|
||||||
if (images != null && !images.isEmpty()) {
|
if (images != null && !images.isEmpty()) {
|
||||||
goodsSku.setThumbnail(goodsGalleryService.getGoodsGallery(images.get(0).get("url")).getThumbnail());
|
GoodsGallery goodsGallery = goodsGalleryService.getGoodsGallery(images.get(0).get("url"));
|
||||||
goodsSku.setSmall(goodsGalleryService.getGoodsGallery(images.get(0).get("url")).getSmall());
|
goodsSku.setBig(goodsGallery.getOriginal());
|
||||||
|
goodsSku.setOriginal(goodsGallery.getOriginal());
|
||||||
|
goodsSku.setThumbnail(goodsGallery.getThumbnail());
|
||||||
|
goodsSku.setSmall(goodsGallery.getSmall());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ import java.util.Map;
|
|||||||
* @author paulG
|
* @author paulG
|
||||||
**/
|
**/
|
||||||
@Data
|
@Data
|
||||||
@Document(indexName = "#{@elasticsearchProperties.indexPrefix}_" + EsSuffix.GOODS_INDEX_NAME)
|
@Document(indexName = "#{@elasticsearchProperties.indexPrefix}_" + EsSuffix.GOODS_INDEX_NAME, createIndex = false)
|
||||||
@ToString
|
@ToString
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@ -215,6 +215,7 @@ public class EsGoodsIndex implements Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 销售模式
|
* 销售模式
|
||||||
|
*
|
||||||
* @see cn.lili.modules.goods.entity.enums.GoodsSalesModeEnum
|
* @see cn.lili.modules.goods.entity.enums.GoodsSalesModeEnum
|
||||||
*/
|
*/
|
||||||
@Field(type = FieldType.Text)
|
@Field(type = FieldType.Text)
|
||||||
|
@ -66,6 +66,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,7 +128,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
|||||||
Boolean flag = (Boolean) cache.get(CachePrefix.INIT_INDEX_FLAG.getPrefix());
|
Boolean flag = (Boolean) cache.get(CachePrefix.INIT_INDEX_FLAG.getPrefix());
|
||||||
//为空则默认写入没有任务
|
//为空则默认写入没有任务
|
||||||
if (flag == null) {
|
if (flag == null) {
|
||||||
cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false);
|
cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false, 10L, TimeUnit.MINUTES);
|
||||||
}
|
}
|
||||||
//有正在初始化的任务,则提示异常
|
//有正在初始化的任务,则提示异常
|
||||||
if (Boolean.TRUE.equals(flag)) {
|
if (Boolean.TRUE.equals(flag)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user