improve esGoods parameter selector buckets(not get category and brand from db, add EsGoodsIndex Field BrandName,BrandUrl,CategoryNamePath)

This commit is contained in:
paulGao
2021-09-07 01:55:58 +08:00
parent 8f10b6b2a6
commit 4063c8b063
19 changed files with 650 additions and 195 deletions

View File

@@ -44,7 +44,7 @@ public class ParameterManagerController {
@PutMapping
public ResultMessage<Parameters> update(@Valid Parameters parameters) {
if (parametersService.updateById(parameters)) {
if (parametersService.updateParameter(parameters)) {
return ResultUtil.data(parameters);
}
throw new ServiceException(ResultCode.PARAMETER_UPDATE_ERROR);

View File

@@ -1,32 +1,39 @@
package cn.lili.controller.other;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.json.JSONUtil;
import cn.lili.cache.Cache;
import cn.lili.cache.CachePrefix;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.goods.entity.dos.Brand;
import cn.lili.modules.goods.entity.dos.Category;
import cn.lili.modules.goods.entity.dos.Goods;
import cn.lili.modules.goods.entity.dos.GoodsSku;
import cn.lili.modules.goods.entity.dto.GoodsParamsDTO;
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
import cn.lili.modules.goods.entity.enums.GoodsStatusEnum;
import cn.lili.modules.goods.service.BrandService;
import cn.lili.modules.goods.service.CategoryService;
import cn.lili.modules.goods.service.GoodsService;
import cn.lili.modules.goods.service.GoodsSkuService;
import cn.lili.modules.promotion.service.PromotionService;
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
import cn.lili.modules.search.service.EsGoodsIndexService;
import cn.lili.modules.store.entity.dos.StoreGoodsLabel;
import cn.lili.modules.store.service.StoreGoodsLabelService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -57,6 +64,15 @@ public class ElasticsearchController {
@Autowired
private PromotionService promotionService;
@Autowired
private CategoryService categoryService;
@Autowired
private BrandService brandService;
@Autowired
private StoreGoodsLabelService storeGoodsLabelService;
@Autowired
private Cache cache;
@@ -67,7 +83,6 @@ public class ElasticsearchController {
if (Boolean.TRUE.equals(flag)) {
return ResultUtil.error(100000, "当前有任务在执行");
}
cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false);
ThreadUtil.execAsync(() -> {
//查询商品信息
LambdaQueryWrapper<GoodsSku> queryWrapper = new LambdaQueryWrapper<>();
@@ -84,6 +99,23 @@ public class ElasticsearchController {
List<GoodsParamsDTO> goodsParamDTOS = JSONUtil.toList(goods.getParams(), GoodsParamsDTO.class);
index = new EsGoodsIndex(goodsSku, goodsParamDTOS);
}
if (goods.getCategoryPath() != null) {
List<Category> categories = categoryService.listByIdsOrderByLevel(Arrays.asList(goods.getCategoryPath().split(",")));
if (!categories.isEmpty()) {
index.setCategoryNamePath(ArrayUtil.join(categories.stream().map(Category::getName).toArray(), ","));
}
}
Brand brand = brandService.getById(goods.getBrandId());
if (brand != null) {
index.setBrandName(brand.getName());
index.setBrandUrl(brand.getLogo());
}
if (goods.getStoreCategoryPath() != null && CharSequenceUtil.isNotEmpty(goods.getStoreCategoryPath())) {
List<StoreGoodsLabel> storeGoodsLabels = storeGoodsLabelService.listByStoreIds(Arrays.asList(goods.getStoreCategoryPath().split(",")));
if (!storeGoodsLabels.isEmpty()) {
index.setStoreCategoryNamePath(ArrayUtil.join(storeGoodsLabels.stream().map(StoreGoodsLabel::getLabelName).toArray(), ","));
}
}
Map<String, Object> goodsCurrentPromotionMap = promotionService.getGoodsCurrentPromotionMap(index);
index.setPromotionMap(goodsCurrentPromotionMap);
esGoodsIndices.add(index);

View File

@@ -1,5 +1,6 @@
package cn.lili.test.elasticsearch;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.json.JSONUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.modules.goods.entity.dos.GoodsSku;
@@ -20,12 +21,13 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.elasticsearch.core.SearchPage;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -56,6 +58,50 @@ class EsTest {
private PromotionService promotionService;
public static void main(String[] args) {
EsGoodsIndex goodsIndex = new EsGoodsIndex();
goodsIndex.setGoodsName("1111");
goodsIndex.setBuyCount(99);
goodsIndex.setCommentNum(99);
goodsIndex.setGrade(100D);
goodsIndex.setHighPraiseNum(100);
goodsIndex.setIntro("I'd like a cup of tea, please");
goodsIndex.setIsAuth("1");
goodsIndex.setMarketEnable("1");
goodsIndex.setMobileIntro("I want something cold to drink");
goodsIndex.setPoint(0);
goodsIndex.setSelfOperated(true);
goodsIndex.setThumbnail("picture");
goodsIndex.setStoreCategoryPath("1");
String ignoreField = "serialVersionUID,promotionMap,id,goodsId";
List<EsGoodsIndex> goodsIndices = new ArrayList<>();
Map<String, Field> fieldMap = ReflectUtil.getFieldMap(EsGoodsIndex.class);
for (int i = 0; i < 10; i++) {
EsGoodsIndex a = new EsGoodsIndex();
for (Map.Entry<String, Field> entry : fieldMap.entrySet()) {
Object fieldValue = ReflectUtil.getFieldValue(goodsIndex, entry.getValue());
if (fieldValue != null && !ignoreField.contains(entry.getKey())) {
ReflectUtil.setFieldValue(a, entry.getValue(), fieldValue);
}
}
goodsIndices.add(a);
}
;
// BeanUtil.copyProperties(goodsIndex, a);
System.out.println(cn.hutool.core.date.DateUtil.endOfDay(new Date()));
// ReflectUtil.getFieldValue(goodsIndex, )
// for (Object o : ReflectUtil.getFieldsValue(goodsIndex)) {
// if (o != null) {
// System.out.println(o);
// }
// }
}
@Test
void searchGoods() {
EsGoodsSearchDTO goodsSearchDTO = new EsGoodsSearchDTO();

View File

@@ -35,18 +35,19 @@ class SeckillTest {
@Test
void add() {
SeckillVO seckillVO = new SeckillVO();
seckillVO.setId("123456");
seckillVO.setId("10000");
seckillVO.setStoreIds("132");
seckillVO.setSeckillApplyStatus(SeckillApplyStatusEnum.NOT_APPLY.name());
seckillVO.setPromotionStatus(PromotionStatusEnum.NEW.name());
seckillVO.setApplyEndTime(DateUtil.parse("2020-11-13 23:50:00"));
seckillVO.setStartTime(DateUtil.parse("2020-11-14 12:00:00"));
seckillVO.setEndTime(DateUtil.parse("2020-11-14 18:00:00"));
seckillVO.setHours("13,14,15,16,17");
seckillVO.setApplyEndTime(DateUtil.parse("2021-09-06 14:20:00"));
seckillVO.setStartTime(DateUtil.parse("2021-09-06 14:22:00"));
seckillVO.setEndTime(DateUtil.parse("2021-09-06 23:59:00"));
seckillVO.setHours("15,17,19");
seckillVO.setPromotionName("Seckill" + seckillVO.getId());
seckillVO.setSeckillRule("rule" + seckillVO.getId());
seckillVO.setStoreId("0");
seckillVO.setStoreId("1376433565247471616");
seckillVO.setStoreName("platform");
Assertions.assertTrue(seckillService.saveSeckill(seckillVO));
}
@@ -54,32 +55,32 @@ class SeckillTest {
void addApply() {
List<SeckillApplyVO> seckillApplyVOS = new ArrayList<>();
SeckillApplyVO seckillApplyVO = new SeckillApplyVO();
seckillApplyVO.setGoodsName("Apple MacBook Pro 13.3 新款八核M1芯片 8G 256G SSD 深空灰 笔记本电脑 轻薄本 MYD82CH/A");
seckillApplyVO.setSkuId("50111");
seckillApplyVO.setOriginalPrice(20000D);
seckillApplyVO.setPrice(19000D);
seckillApplyVO.setGoodsName("Apple iPhone 12");
seckillApplyVO.setSkuId("1387977574860193792");
seckillApplyVO.setOriginalPrice(4000D);
seckillApplyVO.setPrice(3600D);
seckillApplyVO.setPromotionApplyStatus(PromotionApplyStatusEnum.APPLY.name());
seckillApplyVO.setQuantity(100);
seckillApplyVO.setQuantity(1);
seckillApplyVO.setSalesNum(0);
seckillApplyVO.setSeckillId("123456");
seckillApplyVO.setStoreId("501");
seckillApplyVO.setStoreName("Apple产品自营旗舰");
seckillApplyVO.setTimeLine(17);
seckillApplyVO.setSeckillId("10000");
seckillApplyVO.setStoreId("1376369067769724928");
seckillApplyVO.setStoreName("Lilishop自营");
seckillApplyVO.setTimeLine(15);
seckillApplyVOS.add(seckillApplyVO);
seckillApplyVO = new SeckillApplyVO();
seckillApplyVO.setGoodsName("RedmiBook 16 锐龙版 超轻薄全面屏(6核R5-4500U 16G 512G 100% sRGB高色域)灰 手提 笔记本电脑 小米 红米");
seckillApplyVO.setSkuId("141");
seckillApplyVO.setOriginalPrice(10000D);
seckillApplyVO.setPrice(9000D);
seckillApplyVO.setGoodsName("Apple iPhone 12");
seckillApplyVO.setSkuId("1387977574864388096");
seckillApplyVO.setOriginalPrice(4000D);
seckillApplyVO.setPrice(3600D);
seckillApplyVO.setPromotionApplyStatus(PromotionApplyStatusEnum.APPLY.name());
seckillApplyVO.setQuantity(100);
seckillApplyVO.setQuantity(1);
seckillApplyVO.setSalesNum(0);
seckillApplyVO.setSeckillId("123456");
seckillApplyVO.setStoreId("131");
seckillApplyVO.setStoreName("小米自营旗舰");
seckillApplyVO.setTimeLine(16);
seckillApplyVO.setSeckillId("10000");
seckillApplyVO.setStoreId("1376369067769724928");
seckillApplyVO.setStoreName("Lilishop自营");
seckillApplyVO.setTimeLine(15);
seckillApplyVOS.add(seckillApplyVO);
seckillApplyService.addSeckillApply("123456", "501", seckillApplyVOS);
seckillApplyService.addSeckillApply("10000", "1376369067769724928", seckillApplyVOS);
Assertions.assertTrue(true);
}