@@ -7,7 +7,6 @@ import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.CorsConfigurationSource;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
@@ -35,7 +34,6 @@ public class SecurityBean {
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
config.setAllowCredentials(true);
|
||||
// config.addAllowedOrigin(CorsConfiguration.ALL);
|
||||
config.setAllowedOriginPatterns(Collections.singletonList(CorsConfiguration.ALL));
|
||||
config.addAllowedHeader(CorsConfiguration.ALL);
|
||||
config.addAllowedMethod(CorsConfiguration.ALL);
|
||||
|
||||
@@ -140,6 +140,26 @@ public abstract class BaseElasticsearchService {
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"brandName\": {\n" +
|
||||
" \"type\": \"text\",\n" +
|
||||
" \"fielddata\": true,\n" +
|
||||
" \"fields\": {\n" +
|
||||
" \"keyword\": {\n" +
|
||||
" \"type\": \"keyword\",\n" +
|
||||
" \"ignore_above\": 256\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"brandUrl\": {\n" +
|
||||
" \"type\": \"text\",\n" +
|
||||
" \"fielddata\": true,\n" +
|
||||
" \"fields\": {\n" +
|
||||
" \"keyword\": {\n" +
|
||||
" \"type\": \"keyword\",\n" +
|
||||
" \"ignore_above\": 256\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"buyCount\": {\n" +
|
||||
" \"type\": \"long\"\n" +
|
||||
" },\n" +
|
||||
@@ -163,6 +183,16 @@ public abstract class BaseElasticsearchService {
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"categoryNamePath\": {\n" +
|
||||
" \"type\": \"text\",\n" +
|
||||
" \"fielddata\": true,\n" +
|
||||
" \"fields\": {\n" +
|
||||
" \"keyword\": {\n" +
|
||||
" \"type\": \"keyword\",\n" +
|
||||
" \"ignore_above\": 256\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"commentNum\": {\n" +
|
||||
" \"type\": \"long\"\n" +
|
||||
" },\n" +
|
||||
|
||||
@@ -25,6 +25,14 @@ public interface CategoryService extends IService<Category> {
|
||||
*/
|
||||
List<Category> dbList(String parentId);
|
||||
|
||||
/**
|
||||
* 根据分类id集合获取所有分类根据层级排序
|
||||
*
|
||||
* @param ids 分类ID集合
|
||||
* @return 商品分类列表
|
||||
*/
|
||||
List<Category> listByIdsOrderByLevel(List<String> ids);
|
||||
|
||||
/**
|
||||
* 获取分类树
|
||||
*
|
||||
|
||||
@@ -11,4 +11,14 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
*/
|
||||
public interface ParametersService extends IService<Parameters> {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 更新参数组信息
|
||||
*
|
||||
* @param parameters 参数组信息
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
boolean updateParameter(Parameters parameters);
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.lili.modules.goods.serviceimpl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.lili.cache.Cache;
|
||||
import cn.lili.cache.CachePrefix;
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
@@ -48,6 +48,17 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
||||
return this.list(new LambdaQueryWrapper<Category>().eq(Category::getParentId, parentId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类id集合获取所有分类根据层级排序
|
||||
*
|
||||
* @param ids 分类ID集合
|
||||
* @return 商品分类列表
|
||||
*/
|
||||
@Override
|
||||
public List<Category> listByIdsOrderByLevel(List<String> ids) {
|
||||
return this.list(new LambdaQueryWrapper<Category>().in(Category::getId, ids).orderByAsc(Category::getLevel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CategoryVO> categoryTree() {
|
||||
List<CategoryVO> categoryVOList = (List<CategoryVO>) cache.get(CachePrefix.CATEGORY.getPrefix());
|
||||
@@ -69,13 +80,8 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
||||
categoryVOList.add(categoryVO);
|
||||
}
|
||||
}
|
||||
categoryVOList.sort(new Comparator<CategoryVO>() {
|
||||
@Override
|
||||
public int compare(CategoryVO o1, CategoryVO o2) {
|
||||
return o1.getSortOrder().compareTo(o2.getSortOrder());
|
||||
}
|
||||
});
|
||||
if (categoryVOList.size() != 0) {
|
||||
categoryVOList.sort(Comparator.comparing(Category::getSortOrder));
|
||||
if (!categoryVOList.isEmpty()) {
|
||||
cache.put(CachePrefix.CATEGORY.getPrefix(), categoryVOList);
|
||||
cache.put(CachePrefix.CATEGORY_ARRAY.getPrefix(), list);
|
||||
}
|
||||
@@ -85,15 +91,13 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
||||
@Override
|
||||
public List<CategoryVO> getStoreCategory(String[] categories) {
|
||||
List<String> arr = Arrays.asList(categories.clone());
|
||||
List<CategoryVO> categoryVOList = categoryTree().stream()
|
||||
return categoryTree().stream()
|
||||
.filter(item -> arr.contains(item.getId())).collect(Collectors.toList());
|
||||
return categoryVOList;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Category> firstCategory() {
|
||||
QueryWrapper queryWrapper = Wrappers.query();
|
||||
QueryWrapper<Category> queryWrapper = Wrappers.query();
|
||||
queryWrapper.eq("level", 0);
|
||||
return list(queryWrapper);
|
||||
}
|
||||
@@ -108,8 +112,9 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
||||
for (CategoryVO item : topCatList) {
|
||||
if (item.getId().equals(parentId)) {
|
||||
return item.getChildren();
|
||||
} else {
|
||||
return getChildren(parentId, item.getChildren());
|
||||
}
|
||||
return getChildren(parentId, item.getChildren());
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@@ -129,12 +134,7 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
||||
categoryVOList.add(categoryVO);
|
||||
}
|
||||
}
|
||||
categoryVOList.sort(new Comparator<CategoryVO>() {
|
||||
@Override
|
||||
public int compare(CategoryVO o1, CategoryVO o2) {
|
||||
return o1.getSortOrder().compareTo(o2.getSortOrder());
|
||||
}
|
||||
});
|
||||
categoryVOList.sort(Comparator.comparing(Category::getSortOrder));
|
||||
return categoryVOList;
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
||||
}
|
||||
//还为空的话,直接返回
|
||||
if (categoryVOList == null) {
|
||||
return null;
|
||||
return new ArrayList<>();
|
||||
}
|
||||
//循环顶级分类
|
||||
for (Category category : categoryVOList) {
|
||||
@@ -174,7 +174,7 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
||||
public List<Category> findByAllBySortOrder(Category category) {
|
||||
QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq(category.getLevel() != null, "level", category.getLevel())
|
||||
.eq(StrUtil.isNotBlank(category.getName()), "name", category.getName())
|
||||
.eq(CharSequenceUtil.isNotBlank(category.getName()), "name", category.getName())
|
||||
.eq(category.getParentId() != null, "parent_id", category.getParentId())
|
||||
.ne(category.getId() != null, "id", category.getId())
|
||||
.eq(DELETE_FLAG_COLUMN, false)
|
||||
@@ -329,7 +329,7 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
||||
/**
|
||||
* 递归自身,找到id等于parentId的对象,获取他的children 返回
|
||||
*
|
||||
* @param parentId 父ID
|
||||
* @param parentId 父ID
|
||||
* @param categoryVOList 分类VO
|
||||
* @return 子分类列表VO
|
||||
*/
|
||||
@@ -338,11 +338,11 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
||||
if (item.getId().equals(parentId)) {
|
||||
return item.getChildren();
|
||||
}
|
||||
if (item.getChildren() != null && item.getChildren().size() > 0) {
|
||||
if (item.getChildren() != null && !item.getChildren().isEmpty()) {
|
||||
return getChildren(parentId, categoryVOList);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return categoryVOList;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -117,7 +117,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
}
|
||||
|
||||
this.updateStock(newSkuList);
|
||||
generateEsCheck(goods);
|
||||
generateEs(goods);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -164,7 +164,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
this.updateBatchById(newSkuList);
|
||||
}
|
||||
this.updateStock(newSkuList);
|
||||
generateEsCheck(goods);
|
||||
generateEs(goods);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,6 +248,10 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
EsGoodsIndex goodsIndex = goodsIndexService.findById(skuId);
|
||||
if (goodsIndex == null) {
|
||||
goodsIndex = goodsIndexService.resetEsGoodsIndex(goodsSku, goodsVO.getGoodsParamsDTOList());
|
||||
|
||||
//发送mq消息
|
||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.RESET_GOODS_INDEX.name();
|
||||
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(Collections.singletonList(goodsIndex)), RocketmqSendCallbackBuilder.commonCallback());
|
||||
}
|
||||
|
||||
//商品规格
|
||||
@@ -300,7 +304,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
cache.remove(GoodsSkuService.getCacheKeys(sku.getId()));
|
||||
cache.put(GoodsSkuService.getCacheKeys(sku.getId()), sku);
|
||||
}
|
||||
generateEsCheck(goods);
|
||||
generateEs(goods);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,18 +477,18 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
//修改规格
|
||||
this.update(goodsSku);
|
||||
//修改规格索引
|
||||
goodsIndexService.updateIndexCommentNum(goodsSku.getId(), goodsSku.getCommentNum(), highPraiseNum, grade);
|
||||
goodsIndexService.updateIndex(goodsSku.getId(), new EsGoodsIndex().setCommentNum(goodsSku.getCommentNum()).setHighPraiseNum(highPraiseNum).setGrade(grade));
|
||||
|
||||
//修改商品的评价数量
|
||||
goodsService.updateGoodsCommentNum(goodsSku.getGoodsId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成ES商品索引
|
||||
* 发送生成ES商品索引
|
||||
*
|
||||
* @param goods 商品信息
|
||||
*/
|
||||
private void generateEsCheck(Goods goods) {
|
||||
private void generateEs(Goods goods) {
|
||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GENERATOR_GOODS_INDEX.name();
|
||||
//发送mq消息
|
||||
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goods), RocketmqSendCallbackBuilder.commonCallback());
|
||||
|
||||
@@ -1,13 +1,30 @@
|
||||
package cn.lili.modules.goods.serviceimpl;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.properties.RocketmqCustomProperties;
|
||||
import cn.lili.modules.goods.entity.dos.Goods;
|
||||
import cn.lili.modules.goods.entity.dos.Parameters;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsParamsDTO;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsParamsItemDTO;
|
||||
import cn.lili.modules.goods.mapper.ParametersMapper;
|
||||
import cn.lili.modules.goods.service.GoodsService;
|
||||
import cn.lili.modules.goods.service.ParametersService;
|
||||
import cn.lili.rocketmq.RocketmqSendCallbackBuilder;
|
||||
import cn.lili.rocketmq.tags.GoodsTagsEnum;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 商品参数业务层实现
|
||||
@@ -17,4 +34,92 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*/
|
||||
@Service
|
||||
public class ParametersServiceImpl extends ServiceImpl<ParametersMapper, Parameters> implements ParametersService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private GoodsService goodsService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private RocketmqCustomProperties rocketmqCustomProperties;
|
||||
|
||||
@Autowired
|
||||
private RocketMQTemplate rocketMQTemplate;
|
||||
|
||||
/**
|
||||
* 更新参数组信息
|
||||
*
|
||||
* @param parameters 参数组信息
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
@Override
|
||||
public boolean updateParameter(Parameters parameters) {
|
||||
Parameters origin = this.getById(parameters.getId());
|
||||
if (origin == null) {
|
||||
throw new ServiceException(ResultCode.CATEGORY_NOT_EXIST);
|
||||
}
|
||||
|
||||
List<String> goodsIds = new ArrayList<>();
|
||||
LambdaQueryWrapper<Goods> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.select(Goods::getId, Goods::getParams);
|
||||
queryWrapper.like(Goods::getParams, parameters.getGroupId());
|
||||
List<Map<String, Object>> goodsList = this.goodsService.listMaps(queryWrapper);
|
||||
|
||||
for (Map<String, Object> goods : goodsList) {
|
||||
String params = (String) goods.get("params");
|
||||
List<GoodsParamsDTO> goodsParamsDTOS = JSONUtil.toList(params, GoodsParamsDTO.class);
|
||||
List<GoodsParamsDTO> goodsParamsDTOList = goodsParamsDTOS.stream().filter(i -> i.getGroupId() != null && i.getGroupId().equals(parameters.getGroupId())).collect(Collectors.toList());
|
||||
this.setGoodsItemDTOList(goodsParamsDTOList, parameters);
|
||||
LambdaUpdateWrapper<Goods> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(Goods::getId, goods.get("id"));
|
||||
updateWrapper.set(Goods::getParams, JSONUtil.toJsonStr(goodsParamsDTOS));
|
||||
this.goodsService.update(updateWrapper);
|
||||
goodsIds.add(goods.get("id").toString());
|
||||
}
|
||||
|
||||
|
||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX.name();
|
||||
//发送mq消息
|
||||
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goodsIds), RocketmqSendCallbackBuilder.commonCallback());
|
||||
return this.updateById(parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品参数信息
|
||||
*
|
||||
* @param goodsParamsDTOList 商品参数项列表
|
||||
* @param parameters 参数信息
|
||||
*/
|
||||
private void setGoodsItemDTOList(List<GoodsParamsDTO> goodsParamsDTOList, Parameters parameters) {
|
||||
for (GoodsParamsDTO goodsParamsDTO : goodsParamsDTOList) {
|
||||
List<GoodsParamsItemDTO> goodsParamsItemDTOList = goodsParamsDTO.getGoodsParamsItemDTOList().stream().filter(i -> i.getParamId() != null && i.getParamId().equals(parameters.getId())).collect(Collectors.toList());
|
||||
for (GoodsParamsItemDTO goodsParamsItemDTO : goodsParamsItemDTOList) {
|
||||
this.setGoodsItemDTO(goodsParamsItemDTO, parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品参数详细信息
|
||||
*
|
||||
* @param goodsParamsItemDTO 商品参数项信息
|
||||
* @param parameters 参数信息
|
||||
*/
|
||||
private void setGoodsItemDTO(GoodsParamsItemDTO goodsParamsItemDTO, Parameters parameters) {
|
||||
if (goodsParamsItemDTO.getParamId().equals(parameters.getId())) {
|
||||
goodsParamsItemDTO.setParamId(parameters.getId());
|
||||
goodsParamsItemDTO.setParamName(parameters.getParamName());
|
||||
goodsParamsItemDTO.setRequired(parameters.getRequired());
|
||||
goodsParamsItemDTO.setIsIndex(parameters.getIsIndex());
|
||||
goodsParamsItemDTO.setSort(parameters.getSort());
|
||||
if (CharSequenceUtil.isNotEmpty(parameters.getOptions()) && !parameters.getOptions().contains(goodsParamsItemDTO.getParamValue())) {
|
||||
if (parameters.getOptions().contains(",")) {
|
||||
goodsParamsItemDTO.setParamValue(parameters.getOptions().substring(0, parameters.getOptions().indexOf(",")));
|
||||
} else {
|
||||
goodsParamsItemDTO.setParamValue(parameters.getOptions());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -59,13 +59,11 @@ public class SkuPromotionRender implements CartRenderStep {
|
||||
*/
|
||||
private void renderBasePrice(TradeDTO tradeDTO) {
|
||||
tradeDTO.getCartList().forEach(
|
||||
cartVO -> {
|
||||
cartVO.getSkuList().forEach(cartSkuVO -> {
|
||||
PriceDetailDTO priceDetailDTO = cartSkuVO.getPriceDetailDTO();
|
||||
priceDetailDTO.setGoodsPrice(cartSkuVO.getSubTotal());
|
||||
priceDetailDTO.setDiscountPrice(CurrencyUtil.sub(priceDetailDTO.getOriginalPrice(), cartSkuVO.getSubTotal()));
|
||||
});
|
||||
}
|
||||
cartVO -> cartVO.getSkuList().forEach(cartSkuVO -> {
|
||||
PriceDetailDTO priceDetailDTO = cartSkuVO.getPriceDetailDTO();
|
||||
priceDetailDTO.setGoodsPrice(cartSkuVO.getSubTotal());
|
||||
priceDetailDTO.setDiscountPrice(CurrencyUtil.sub(priceDetailDTO.getOriginalPrice(), cartSkuVO.getSubTotal()));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ public class CartServiceImpl implements CartService {
|
||||
if (cartSkuVO != null && dataSku.getUpdateTime().equals(cartSkuVO.getGoodsSku().getUpdateTime())) {
|
||||
|
||||
//如果覆盖购物车中商品数量
|
||||
if (cover) {
|
||||
if (Boolean.TRUE.equals(cover)) {
|
||||
cartSkuVO.setNum(num);
|
||||
this.checkSetGoodsQuantity(cartSkuVO, skuId, num);
|
||||
} else {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.lili.modules.order.order.entity.vo;
|
||||
|
||||
import cn.lili.common.utils.StringUtils;
|
||||
import cn.lili.common.enums.ClientTypeEnum;
|
||||
import cn.lili.common.utils.StringUtils;
|
||||
import cn.lili.modules.order.order.entity.enums.*;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@@ -149,7 +149,7 @@ public class OrderSimpleVO {
|
||||
String[] complainStatus = groupComplainStatus.split(",");
|
||||
String[] commentStatus = groupCommentStatus.split(",");
|
||||
String[] goodsPrice = groupGoodsPrice.split(",");
|
||||
// String goodsId, String skuId, Integer num, String image, String name, String afterSaleStatus
|
||||
|
||||
for (int i = 0; i < goodsId.length; i++) {
|
||||
orderItemVOS.add(new OrderItemVO(orderItemsSn[i], goodsId[i], skuId[i], num[i], image[i], name[i], afterSaleStatus[i], complainStatus[i], commentStatus[i], Double.parseDouble(goodsPrice[i])));
|
||||
}
|
||||
|
||||
@@ -91,12 +91,12 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
||||
|
||||
GoodsSku sku = goodsSkuService.getGoodsSkuByIdFromCache(skuId);
|
||||
if (sku == null) {
|
||||
return null;
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<PromotionGoods> promotionGoods = new ArrayList<>();
|
||||
promotionGoods.addAll(this.list(new LambdaQueryWrapper<PromotionGoods>()
|
||||
List<PromotionGoods> promotionGoods = new ArrayList<>(this.list(new LambdaQueryWrapper<PromotionGoods>()
|
||||
.eq(PromotionGoods::getSkuId, skuId)
|
||||
.le(PromotionGoods::getStartTime, System.currentTimeMillis())
|
||||
.eq(PromotionGoods::getPromotionStatus, PromotionStatusEnum.START.name())));
|
||||
|
||||
|
||||
@@ -170,8 +170,8 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
||||
promotionGoodsPage.setSize(page.getSize());
|
||||
promotionGoodsPage.setTotal(page.getTotal());
|
||||
promotionGoodsPage.setPages(page.getPages());
|
||||
for (PromotionGoods record : page.getRecords()) {
|
||||
PromotionGoodsDTO promotionGoodsDTO = this.wrapperPromotionGoodsDTO(record);
|
||||
for (PromotionGoods promotionGoods : page.getRecords()) {
|
||||
PromotionGoodsDTO promotionGoodsDTO = this.wrapperPromotionGoodsDTO(promotionGoods);
|
||||
promotionGoodsList.add(promotionGoodsDTO);
|
||||
}
|
||||
promotionGoodsPage.setRecords(promotionGoodsList);
|
||||
@@ -380,8 +380,8 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
||||
promotionGoodsPage.setTotal(page.getTotal());
|
||||
promotionGoodsPage.setPages(page.getPages());
|
||||
List<PromotionGoods> records = page.getRecords();
|
||||
for (PromotionGoods record : records) {
|
||||
PromotionGoodsDTO promotionGoodsDTO = this.wrapperPromotionGoodsDTO(record);
|
||||
for (PromotionGoods promotionGoods : records) {
|
||||
PromotionGoodsDTO promotionGoodsDTO = this.wrapperPromotionGoodsDTO(promotionGoods);
|
||||
promotionGoodsList.add(promotionGoodsDTO);
|
||||
}
|
||||
promotionGoodsPage.setRecords(promotionGoodsList);
|
||||
@@ -414,9 +414,9 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
||||
searchParams.setOrder(pageVo.getOrder());
|
||||
IPage<GoodsSku> goodsSkuByPage = goodsSkuService.getGoodsSkuByPage(searchParams);
|
||||
//将查询到的商品sku转换为促销商品
|
||||
for (GoodsSku record : goodsSkuByPage.getRecords()) {
|
||||
PromotionGoodsDTO promotionGoods = new PromotionGoodsDTO(record);
|
||||
promotionGoods.setGoodsImage(record.getThumbnail());
|
||||
for (GoodsSku goodsSku : goodsSkuByPage.getRecords()) {
|
||||
PromotionGoodsDTO promotionGoods = new PromotionGoodsDTO(goodsSku);
|
||||
promotionGoods.setGoodsImage(goodsSku.getThumbnail());
|
||||
promotionGoods.setStartTime(promotion.getStartTime());
|
||||
promotionGoods.setEndTime(promotion.getEndTime());
|
||||
promotionGoods.setTitle(promotion.getPromotionName());
|
||||
|
||||
@@ -4,10 +4,9 @@ import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.lili.common.enums.PromotionTypeEnum;
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.enums.PromotionTypeEnum;
|
||||
import cn.lili.trigger.message.PromotionMessage;
|
||||
import cn.lili.modules.order.cart.entity.vo.FullDiscountVO;
|
||||
import cn.lili.modules.promotion.entity.dos.*;
|
||||
import cn.lili.modules.promotion.entity.dto.KanjiaActivityGoodsDTO;
|
||||
@@ -19,6 +18,7 @@ import cn.lili.modules.promotion.entity.vos.SeckillVO;
|
||||
import cn.lili.modules.promotion.service.*;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||
import cn.lili.modules.search.service.EsGoodsIndexService;
|
||||
import cn.lili.trigger.message.PromotionMessage;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
@@ -115,7 +115,7 @@ public class PromotionServiceImpl implements PromotionService {
|
||||
break;
|
||||
//秒杀
|
||||
case SECKILL:
|
||||
result = this.updateSeckill(promotionMessage, esPromotionKey, promotionTypeEnum);
|
||||
result = this.updateSeckill(promotionMessage, promotionTypeEnum);
|
||||
break;
|
||||
//拼团
|
||||
case PINTUAN:
|
||||
@@ -381,11 +381,10 @@ public class PromotionServiceImpl implements PromotionService {
|
||||
* 修改秒杀状态
|
||||
*
|
||||
* @param promotionMessage 信息队列传输促销信息实体
|
||||
* @param esPromotionKey es Key
|
||||
* @param promotionTypeEnum 促销分类枚举
|
||||
* @return 修改结果
|
||||
*/
|
||||
private boolean updateSeckill(PromotionMessage promotionMessage, String esPromotionKey, PromotionTypeEnum promotionTypeEnum) {
|
||||
private boolean updateSeckill(PromotionMessage promotionMessage, PromotionTypeEnum promotionTypeEnum) {
|
||||
boolean result;
|
||||
SeckillVO seckill = this.mongoTemplate.findById(promotionMessage.getPromotionId(), SeckillVO.class);
|
||||
if (seckill == null) {
|
||||
|
||||
@@ -1,24 +1,17 @@
|
||||
package cn.lili.modules.promotion.serviceimpl;
|
||||
|
||||
import cn.lili.common.enums.PromotionTypeEnum;
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.trigger.util.DelayQueueTools;
|
||||
import cn.lili.trigger.enums.DelayTypeEnums;
|
||||
import cn.lili.trigger.message.PromotionMessage;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.trigger.interfaces.TimeTrigger;
|
||||
import cn.lili.trigger.model.TimeExecuteConstant;
|
||||
import cn.lili.trigger.model.TimeTriggerMsg;
|
||||
import cn.lili.common.properties.RocketmqCustomProperties;
|
||||
import cn.lili.common.utils.BeanUtil;
|
||||
import cn.lili.common.utils.DateUtil;
|
||||
import cn.lili.mybatis.util.PageUtil;
|
||||
import cn.lili.common.utils.StringUtils;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.common.properties.RocketmqCustomProperties;
|
||||
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
|
||||
import cn.lili.modules.promotion.entity.dos.Seckill;
|
||||
import cn.lili.modules.promotion.entity.dos.SeckillApply;
|
||||
import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum;
|
||||
import cn.lili.common.enums.PromotionTypeEnum;
|
||||
import cn.lili.modules.promotion.entity.enums.SeckillApplyStatusEnum;
|
||||
import cn.lili.modules.promotion.entity.vos.SeckillSearchParams;
|
||||
import cn.lili.modules.promotion.entity.vos.SeckillVO;
|
||||
@@ -32,6 +25,13 @@ import cn.lili.modules.system.entity.dos.Setting;
|
||||
import cn.lili.modules.system.entity.dto.SeckillSetting;
|
||||
import cn.lili.modules.system.entity.enums.SettingEnum;
|
||||
import cn.lili.modules.system.service.SettingService;
|
||||
import cn.lili.mybatis.util.PageUtil;
|
||||
import cn.lili.trigger.enums.DelayTypeEnums;
|
||||
import cn.lili.trigger.interfaces.TimeTrigger;
|
||||
import cn.lili.trigger.message.PromotionMessage;
|
||||
import cn.lili.trigger.model.TimeExecuteConstant;
|
||||
import cn.lili.trigger.model.TimeTriggerMsg;
|
||||
import cn.lili.trigger.util.DelayQueueTools;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
@@ -47,6 +47,7 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -193,6 +194,9 @@ public class SeckillServiceImpl extends ServiceImpl<SeckillMapper, Seckill> impl
|
||||
this.mongoTemplate.save(seckillVO);
|
||||
//如果编辑后活动时间不一致,则编辑延时任务
|
||||
if (seckill.getStartTime().getTime() != seckillVO.getStartTime().getTime()) {
|
||||
if (seckillVO.getEndTime() == null) {
|
||||
seckillVO.setEndTime(cn.hutool.core.date.DateUtil.endOfDay(new Date()));
|
||||
}
|
||||
PromotionMessage promotionMessage = new PromotionMessage(seckillVO.getId(), PromotionTypeEnum.SECKILL.name(), PromotionStatusEnum.START.name(), seckillVO.getStartTime(), seckillVO.getEndTime());
|
||||
//更新延时任务
|
||||
this.timeTrigger.edit(TimeExecuteConstant.PROMOTION_EXECUTOR,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.lili.modules.promotion.tools;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.lili.common.enums.PromotionTypeEnum;
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.utils.DateUtil;
|
||||
@@ -8,7 +9,6 @@ import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
|
||||
import cn.lili.modules.promotion.entity.dto.BasePromotion;
|
||||
import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum;
|
||||
import cn.lili.common.enums.PromotionTypeEnum;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -120,7 +120,9 @@ public class PromotionTools {
|
||||
promotionGoods.setPromotionId(promotion.getId());
|
||||
promotionGoods.setStoreName(promotion.getStoreName());
|
||||
promotionGoods.setTitle(promotion.getPromotionName());
|
||||
promotionGoods.setStartTime(promotion.getStartTime());
|
||||
if (promotionGoods.getStartTime() == null) {
|
||||
promotionGoods.setStartTime(promotion.getStartTime());
|
||||
}
|
||||
if (promotion.getEndTime() == null) {
|
||||
promotionGoods.setEndTime(promotion.getEndTime());
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.DateFormat;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
@@ -30,6 +31,7 @@ import java.util.Map;
|
||||
@Document(indexName = "#{@elasticsearchProperties.indexPrefix}_" + EsSuffix.GOODS_INDEX_NAME)
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class EsGoodsIndex implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6856471777036048874L;
|
||||
@@ -99,6 +101,20 @@ public class EsGoodsIndex implements Serializable {
|
||||
@ApiModelProperty("品牌id")
|
||||
private String brandId;
|
||||
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
@Field(type = FieldType.Keyword, fielddata = true)
|
||||
@ApiModelProperty("品牌名称")
|
||||
private String brandName;
|
||||
|
||||
/**
|
||||
* 品牌图片地址
|
||||
*/
|
||||
@Field(type = FieldType.Keyword, fielddata = true)
|
||||
@ApiModelProperty("品牌图片地址")
|
||||
private String brandUrl;
|
||||
|
||||
/**
|
||||
* 分类path
|
||||
*/
|
||||
@@ -106,6 +122,13 @@ public class EsGoodsIndex implements Serializable {
|
||||
@ApiModelProperty("分类path")
|
||||
private String categoryPath;
|
||||
|
||||
/**
|
||||
* 分类名称path
|
||||
*/
|
||||
@Field(type = FieldType.Keyword)
|
||||
@ApiModelProperty("分类名称path")
|
||||
private String categoryNamePath;
|
||||
|
||||
/**
|
||||
* 店铺分类id
|
||||
*/
|
||||
@@ -113,6 +136,13 @@ public class EsGoodsIndex implements Serializable {
|
||||
@ApiModelProperty("店铺分类id")
|
||||
private String storeCategoryPath;
|
||||
|
||||
/**
|
||||
* 店铺分类名称
|
||||
*/
|
||||
@Field(type = FieldType.Keyword)
|
||||
@ApiModelProperty("店铺分类名称")
|
||||
private String storeCategoryNamePath;
|
||||
|
||||
/**
|
||||
* 商品价格
|
||||
*/
|
||||
@@ -279,8 +309,8 @@ public class EsGoodsIndex implements Serializable {
|
||||
/**
|
||||
* 参数索引增加
|
||||
*
|
||||
* @param sku
|
||||
* @param goodsParamDTOS
|
||||
* @param sku 商品sku信息
|
||||
* @param goodsParamDTOS 商品参数信息
|
||||
*/
|
||||
public EsGoodsIndex(GoodsSku sku, List<GoodsParamsDTO> goodsParamDTOS) {
|
||||
this(sku);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package cn.lili.modules.search.service;
|
||||
|
||||
import cn.lili.modules.goods.entity.dto.GoodsParamsDTO;
|
||||
import cn.lili.common.enums.PromotionTypeEnum;
|
||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsParamsDTO;
|
||||
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
|
||||
import cn.lili.modules.promotion.entity.dto.BasePromotion;
|
||||
import cn.lili.common.enums.PromotionTypeEnum;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||
|
||||
import java.util.List;
|
||||
@@ -33,22 +33,19 @@ public interface EsGoodsIndexService {
|
||||
void updateIndex(EsGoodsIndex goods);
|
||||
|
||||
/**
|
||||
* 更新商品索引的购买数量
|
||||
* 更新商品索引的的部分属性(只填写更新的字段,不需要更新的字段不要填写)
|
||||
*
|
||||
* @param id 商品索引id
|
||||
* @param buyCount 更新后的购买数量
|
||||
* @param goods 更新后的购买数量
|
||||
*/
|
||||
void updateIndexBuyNum(String id, Integer buyCount);
|
||||
void updateIndex(String id, EsGoodsIndex goods);
|
||||
|
||||
/**
|
||||
* 更新商品索引的评论相关数据
|
||||
* 批量商品索引的的属性(ID 必填, 其他字段只填写更新的字段,不需要更新的字段不要填写。)
|
||||
*
|
||||
* @param id 商品索引ID
|
||||
* @param commentNum 评论数量
|
||||
* @param highPraiseNum 好评数量
|
||||
* @param grade 好评率
|
||||
* @param goodsIndices 商品索引列表
|
||||
*/
|
||||
void updateIndexCommentNum(String id, Integer commentNum, Integer highPraiseNum, Double grade);
|
||||
void updateBulkIndex(List<EsGoodsIndex> goodsIndices);
|
||||
|
||||
/**
|
||||
* 删除索引
|
||||
|
||||
@@ -2,8 +2,10 @@ package cn.lili.modules.search.serviceimpl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.extra.pinyin.PinyinUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.lili.cache.Cache;
|
||||
import cn.lili.cache.CachePrefix;
|
||||
import cn.lili.common.enums.PromotionTypeEnum;
|
||||
@@ -28,6 +30,8 @@ import cn.lili.modules.search.service.EsGoodsSearchService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.assertj.core.util.IterableUtil;
|
||||
import org.elasticsearch.action.bulk.BulkRequest;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.indices.AnalyzeRequest;
|
||||
import org.elasticsearch.client.indices.AnalyzeResponse;
|
||||
@@ -39,6 +43,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -52,6 +57,10 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements EsGoodsIndexService {
|
||||
|
||||
private static final String IGNORE_FIELD = "serialVersionUID,promotionMap,id,goodsId";
|
||||
|
||||
private final Map<String, Field> fieldMap = ReflectUtil.getFieldMap(EsGoodsIndex.class);
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchProperties elasticsearchProperties;
|
||||
@Autowired
|
||||
@@ -99,34 +108,49 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品索引的购买数量
|
||||
* 更新商品索引的的部分属性(只填写更新的字段,不需要更新的字段不要填写)
|
||||
*
|
||||
* @param id 商品索引id
|
||||
* @param buyCount 更新后的购买数量
|
||||
* @param id 商品索引id
|
||||
* @param goods 更新后的购买数量
|
||||
*/
|
||||
@Override
|
||||
public void updateIndexBuyNum(String id, Integer buyCount) {
|
||||
public void updateIndex(String id, EsGoodsIndex goods) {
|
||||
EsGoodsIndex goodsIndex = this.findById(id);
|
||||
goodsIndex.setBuyCount(buyCount);
|
||||
this.updateIndex(goodsIndex);
|
||||
// 通过反射获取全部字段,在根据参数字段是否为空,设置要更新的字段
|
||||
for (Map.Entry<String, Field> entry : fieldMap.entrySet()) {
|
||||
Object fieldValue = ReflectUtil.getFieldValue(goods, entry.getValue());
|
||||
if (fieldValue != null && !IGNORE_FIELD.contains(entry.getKey())) {
|
||||
ReflectUtil.setFieldValue(goodsIndex, entry.getValue(), fieldValue);
|
||||
}
|
||||
}
|
||||
goodsIndexRepository.save(goods);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品索引的评论相关数据
|
||||
* 批量商品索引的的属性(ID 必填, 其他字段只填写更新的字段,不需要更新的字段不要填写。)
|
||||
*
|
||||
* @param id 商品索引ID
|
||||
* @param commentNum 评论数量
|
||||
* @param highPraiseNum 好评数量
|
||||
* @param grade 好评率
|
||||
* @param goodsIndices 商品索引列表
|
||||
*/
|
||||
@Override
|
||||
public void updateIndexCommentNum(String id, Integer commentNum, Integer highPraiseNum, Double grade) {
|
||||
EsGoodsIndex goodsIndex = this.findById(id);
|
||||
//写入新的商品数据
|
||||
goodsIndex.setCommentNum(commentNum);
|
||||
goodsIndex.setHighPraiseNum(highPraiseNum);
|
||||
goodsIndex.setGrade(grade);
|
||||
this.updateIndex(goodsIndex);
|
||||
public void updateBulkIndex(List<EsGoodsIndex> goodsIndices) {
|
||||
try {
|
||||
//索引名称拼接
|
||||
String indexName = elasticsearchProperties.getIndexPrefix() + "_" + EsSuffix.GOODS_INDEX_NAME;
|
||||
|
||||
BulkRequest request = new BulkRequest();
|
||||
|
||||
for (EsGoodsIndex goodsIndex : goodsIndices) {
|
||||
UpdateRequest updateRequest = new UpdateRequest(indexName, goodsIndex.getId());
|
||||
|
||||
JSONObject jsonObject = JSONUtil.parseObj(goodsIndex);
|
||||
jsonObject.set("releaseTime", goodsIndex.getReleaseTime().getTime());
|
||||
updateRequest.doc(jsonObject);
|
||||
request.add(updateRequest);
|
||||
}
|
||||
client.bulk(request, RequestOptions.DEFAULT);
|
||||
} catch (IOException e) {
|
||||
log.error("批量更新商品索引异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -208,7 +232,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
//更新索引
|
||||
this.updateGoodsIndexPromotion(goodsIndex, key, promotion);
|
||||
} else {
|
||||
log.error("更新索引商品促销信息失败!skuId 为 【{}】的索引不存在!", id);
|
||||
log.error("更新索引商品促销信息失败!skuId 为 {} 的索引不存在!", id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,7 +426,6 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
Map<String, Object> goodsCurrentPromotionMap = promotionService.getGoodsCurrentPromotionMap(index);
|
||||
//写入促销信息
|
||||
index.setPromotionMap(goodsCurrentPromotionMap);
|
||||
this.addIndex(index);
|
||||
return index;
|
||||
}
|
||||
|
||||
@@ -473,7 +496,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
* @param words 商品关键字
|
||||
*/
|
||||
private void wordsToDb(String words) {
|
||||
if (StrUtil.isEmpty(words)) {
|
||||
if (CharSequenceUtil.isEmpty(words)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -493,16 +516,4 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
}
|
||||
}
|
||||
|
||||
// public List<EsGoodsIndex> searchList(String index) {
|
||||
// SearchResponse searchResponse = search(index);
|
||||
// SearchHit[] hits = searchResponse.getHits().getHits();
|
||||
// List<EsGoodsIndex> goodsIndices = new ArrayList<>();
|
||||
// Arrays.stream(hits).forEach(hit -> {
|
||||
// Map<String, Object> sourceAsMap = hit.getSourceAsMap();
|
||||
// EsGoodsIndex person = BeanUtil.mapToBean(sourceAsMap, EsGoodsIndex.class, false, CopyOptions.create());
|
||||
// goodsIndices.add(person);
|
||||
// });
|
||||
// return goodsIndices;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -2,22 +2,18 @@ package cn.lili.modules.search.serviceimpl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.lili.cache.Cache;
|
||||
import cn.lili.cache.CachePrefix;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.modules.goods.entity.dos.Brand;
|
||||
import cn.lili.modules.goods.entity.dos.Category;
|
||||
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.search.entity.dos.EsGoodsIndex;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsRelatedInfo;
|
||||
import cn.lili.modules.search.entity.dto.EsGoodsSearchDTO;
|
||||
import cn.lili.modules.search.entity.dto.HotWordsDTO;
|
||||
import cn.lili.modules.search.entity.dto.ParamOptions;
|
||||
import cn.lili.modules.search.entity.dto.SelectorOptions;
|
||||
import cn.lili.modules.search.repository.EsGoodsIndexRepository;
|
||||
import cn.lili.modules.search.service.EsGoodsSearchService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
@@ -61,21 +57,9 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
private static final String ATTR_VALUE = "attrList.value";
|
||||
private static final String ATTR_NAME = "attrList.name";
|
||||
private static final String ATTR_SORT = "attrList.sort";
|
||||
private static final String ATTR_BRAND_ID = "brandId";
|
||||
private static final String ATTR_NAME_KEY = "nameList";
|
||||
private static final String ATTR_VALUE_KEY = "valueList";
|
||||
|
||||
@Autowired
|
||||
private EsGoodsIndexRepository goodsIndexRepository;
|
||||
/**
|
||||
* 商品分类
|
||||
*/
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
/**
|
||||
* 品牌
|
||||
*/
|
||||
@Autowired
|
||||
private BrandService brandService;
|
||||
/**
|
||||
* ES
|
||||
*/
|
||||
@@ -123,9 +107,14 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
public EsGoodsRelatedInfo getSelector(EsGoodsSearchDTO goodsSearch, PageVO pageVo) {
|
||||
NativeSearchQueryBuilder builder = createSearchQueryBuilder(goodsSearch, null, true);
|
||||
//分类
|
||||
builder.addAggregation(AggregationBuilders.terms("categoryAgg").field("categoryPath"));
|
||||
AggregationBuilder categoryNameBuilder = AggregationBuilders.terms("categoryNameAgg").field("categoryNamePath.keyword");
|
||||
builder.addAggregation(AggregationBuilders.terms("categoryAgg").field("categoryPath").subAggregation(categoryNameBuilder));
|
||||
|
||||
//品牌
|
||||
builder.addAggregation(AggregationBuilders.terms("brandAgg").field("brandId").size(Integer.MAX_VALUE));
|
||||
AggregationBuilder brandNameBuilder = AggregationBuilders.terms("brandNameAgg").field("brandName.keyword");
|
||||
builder.addAggregation(AggregationBuilders.terms("brandIdNameAgg").field(ATTR_BRAND_ID).size(Integer.MAX_VALUE).subAggregation(brandNameBuilder));
|
||||
AggregationBuilder brandUrlBuilder = AggregationBuilders.terms("brandUrlAgg").field("brandUrl.keyword");
|
||||
builder.addAggregation(AggregationBuilders.terms("brandIdUrlAgg").field(ATTR_BRAND_ID).size(Integer.MAX_VALUE).subAggregation(brandUrlBuilder));
|
||||
//参数
|
||||
AggregationBuilder valuesBuilder = AggregationBuilders.terms("valueAgg").field(ATTR_VALUE);
|
||||
AggregationBuilder sortBuilder = AggregationBuilders.sum("sortAgg").field(ATTR_SORT);
|
||||
@@ -162,18 +151,22 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
if (categoryBuckets != null && !categoryBuckets.isEmpty()) {
|
||||
for (Terms.Bucket categoryBucket : categoryBuckets) {
|
||||
String categoryPath = categoryBucket.getKey().toString();
|
||||
String[] split = categoryPath.split(",");
|
||||
for (String s : split) {
|
||||
if (CharSequenceUtil.isNotEmpty(s)) {
|
||||
Category category = categoryService.getById(s);
|
||||
if (category != null) {
|
||||
SelectorOptions so = new SelectorOptions();
|
||||
so.setName(category.getName());
|
||||
so.setValue(category.getId());
|
||||
if (!categoryOptions.contains(so)) {
|
||||
categoryOptions.add(so);
|
||||
}
|
||||
}
|
||||
ParsedStringTerms categoryNameAgg = categoryBucket.getAggregations().get("categoryNameAgg");
|
||||
List<? extends Terms.Bucket> categoryNameBuckets = categoryNameAgg.getBuckets();
|
||||
|
||||
|
||||
String categoryNamePath = categoryPath;
|
||||
if (!categoryBuckets.isEmpty()) {
|
||||
categoryNamePath = categoryNameBuckets.get(0).getKey().toString();
|
||||
}
|
||||
String[] split = ArrayUtil.distinct(categoryPath.split(","));
|
||||
String[] nameSplit = categoryNamePath.split(",");
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
SelectorOptions so = new SelectorOptions();
|
||||
so.setName(nameSplit[i]);
|
||||
so.setValue(split[i]);
|
||||
if (!categoryOptions.contains(so)) {
|
||||
categoryOptions.add(so);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,25 +175,47 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
esGoodsRelatedInfo.setCategories(categoryOptions);
|
||||
|
||||
//品牌
|
||||
ParsedStringTerms brandTerms = (ParsedStringTerms) aggregationMap.get("brandAgg");
|
||||
List<? extends Terms.Bucket> brandBuckets = brandTerms.getBuckets();
|
||||
ParsedStringTerms brandNameTerms = (ParsedStringTerms) aggregationMap.get("brandIdNameAgg");
|
||||
ParsedStringTerms brandUrlTerms = (ParsedStringTerms) aggregationMap.get("brandIdUrlAgg");
|
||||
List<? extends Terms.Bucket> brandBuckets = brandNameTerms.getBuckets();
|
||||
List<? extends Terms.Bucket> brandUrlBuckets = brandUrlTerms.getBuckets();
|
||||
List<SelectorOptions> brandOptions = new ArrayList<>();
|
||||
if (brandBuckets != null && !brandBuckets.isEmpty()) {
|
||||
for (Terms.Bucket brandBucket : brandBuckets) {
|
||||
for (int i = 0; i < brandBuckets.size(); i++) {
|
||||
String brandId = brandBuckets.get(i).getKey().toString();
|
||||
if (CharSequenceUtil.isNotEmpty(goodsSearch.getBrandId())) {
|
||||
List<String> brandList = Arrays.asList(goodsSearch.getBrandId().split("@"));
|
||||
if (brandList.contains(brandBucket.getKey().toString())) {
|
||||
if (brandList.contains(brandId)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Brand brand = brandService.getById(brandBucket.getKey().toString());
|
||||
if (brand != null) {
|
||||
SelectorOptions so = new SelectorOptions();
|
||||
so.setName(brand.getName());
|
||||
so.setValue(brand.getId());
|
||||
so.setUrl(brand.getLogo());
|
||||
brandOptions.add(so);
|
||||
|
||||
String brandName = "";
|
||||
if (brandBuckets.get(i).getAggregations() != null && brandBuckets.get(i).getAggregations().get("brandNameAgg") != null) {
|
||||
ParsedStringTerms brandNameAgg = brandBuckets.get(i).getAggregations().get("brandNameAgg");
|
||||
List<? extends Terms.Bucket> categoryNameBuckets = brandNameAgg.getBuckets();
|
||||
if (categoryNameBuckets != null && !categoryNameBuckets.isEmpty()) {
|
||||
brandName = categoryNameBuckets.get(0).getKey().toString();
|
||||
}
|
||||
}
|
||||
|
||||
String brandUrl = "";
|
||||
if (brandUrlBuckets != null && !brandUrlBuckets.isEmpty() &&
|
||||
brandUrlBuckets.get(i).getAggregations() != null &&
|
||||
brandUrlBuckets.get(i).getAggregations().get("brandUrlAgg") != null) {
|
||||
|
||||
ParsedStringTerms brandUrlAgg = brandUrlBuckets.get(i).getAggregations().get("brandUrlAgg");
|
||||
List<? extends Terms.Bucket> categoryUrlBuckets = brandUrlAgg.getBuckets();
|
||||
if (categoryUrlBuckets != null && !categoryUrlBuckets.isEmpty()) {
|
||||
brandUrl = categoryUrlBuckets.get(0).getKey().toString();
|
||||
}
|
||||
|
||||
}
|
||||
SelectorOptions so = new SelectorOptions();
|
||||
so.setName(brandName);
|
||||
so.setValue(brandId);
|
||||
so.setUrl(brandUrl);
|
||||
brandOptions.add(so);
|
||||
}
|
||||
}
|
||||
esGoodsRelatedInfo.setBrands(brandOptions);
|
||||
@@ -339,7 +354,7 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
//品牌判定
|
||||
if (CharSequenceUtil.isNotEmpty(searchDTO.getBrandId())) {
|
||||
String[] brands = searchDTO.getBrandId().split("@");
|
||||
filterBuilder.must(QueryBuilders.termsQuery("brandId", brands));
|
||||
filterBuilder.must(QueryBuilders.termsQuery(ATTR_BRAND_ID, brands));
|
||||
}
|
||||
if (searchDTO.getRecommend() != null) {
|
||||
filterBuilder.filter(QueryBuilders.termQuery("storeId", searchDTO.getRecommend()));
|
||||
|
||||
@@ -22,6 +22,14 @@ public interface StoreGoodsLabelService extends IService<StoreGoodsLabel> {
|
||||
*/
|
||||
List<StoreGoodsLabelVO> listByStoreId(String storeId);
|
||||
|
||||
/**
|
||||
* 根据分类id集合获取所有店铺分类根据层级排序
|
||||
*
|
||||
* @param ids 商家ID
|
||||
* @return 店铺分类列表
|
||||
*/
|
||||
List<StoreGoodsLabel> listByStoreIds(List<String> ids);
|
||||
|
||||
/**
|
||||
* 添加商品分类
|
||||
*
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package cn.lili.modules.store.serviceimpl;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.lili.cache.Cache;
|
||||
import cn.lili.cache.CachePrefix;
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.security.AuthUser;
|
||||
import cn.lili.common.security.context.UserContext;
|
||||
import cn.lili.modules.store.entity.dos.StoreGoodsLabel;
|
||||
@@ -61,23 +64,32 @@ public class StoreGoodsLabelServiceImpl extends ServiceImpl<StoreGoodsLabelMappe
|
||||
});
|
||||
|
||||
//调整店铺分类排序
|
||||
storeGoodsLabelVOList.sort(new Comparator<StoreGoodsLabelVO>() {
|
||||
@Override
|
||||
public int compare(StoreGoodsLabelVO o1, StoreGoodsLabelVO o2) {
|
||||
return o1.getSortOrder().compareTo(o2.getSortOrder());
|
||||
}
|
||||
});
|
||||
storeGoodsLabelVOList.sort(Comparator.comparing(StoreGoodsLabelVO::getSortOrder));
|
||||
|
||||
if (storeGoodsLabelVOList.size() != 0) {
|
||||
if (!storeGoodsLabelVOList.isEmpty()) {
|
||||
cache.put(CachePrefix.CATEGORY.getPrefix() + storeId + "tree", storeGoodsLabelVOList);
|
||||
}
|
||||
return storeGoodsLabelVOList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类id集合获取所有店铺分类根据层级排序
|
||||
*
|
||||
* @param ids 商家ID
|
||||
* @return 店铺分类列表
|
||||
*/
|
||||
@Override
|
||||
public List<StoreGoodsLabel> listByStoreIds(List<String> ids) {
|
||||
return this.list(new LambdaQueryWrapper<StoreGoodsLabel>().in(StoreGoodsLabel::getId, ids).orderByAsc(StoreGoodsLabel::getLevel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public StoreGoodsLabel addStoreGoodsLabel(StoreGoodsLabel storeGoodsLabel) {
|
||||
//获取当前登录商家账号
|
||||
AuthUser tokenUser = UserContext.getCurrentUser();
|
||||
if (tokenUser == null || CharSequenceUtil.isEmpty(tokenUser.getStoreId())) {
|
||||
throw new ServiceException(ResultCode.USER_NOT_LOGIN);
|
||||
}
|
||||
storeGoodsLabel.setStoreId(tokenUser.getStoreId());
|
||||
//保存店铺分类
|
||||
this.save(storeGoodsLabel);
|
||||
@@ -90,6 +102,9 @@ public class StoreGoodsLabelServiceImpl extends ServiceImpl<StoreGoodsLabelMappe
|
||||
public StoreGoodsLabel editStoreGoodsLabel(StoreGoodsLabel storeGoodsLabel) {
|
||||
//修改当前店铺的商品分类
|
||||
AuthUser tokenUser = UserContext.getCurrentUser();
|
||||
if (tokenUser == null || CharSequenceUtil.isEmpty(tokenUser.getStoreId())) {
|
||||
throw new ServiceException(ResultCode.USER_NOT_LOGIN);
|
||||
}
|
||||
LambdaUpdateWrapper<StoreGoodsLabel> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
||||
lambdaUpdateWrapper.eq(StoreGoodsLabel::getStoreId, tokenUser.getStoreId());
|
||||
lambdaUpdateWrapper.eq(StoreGoodsLabel::getId, storeGoodsLabel.getId());
|
||||
@@ -103,11 +118,15 @@ public class StoreGoodsLabelServiceImpl extends ServiceImpl<StoreGoodsLabelMappe
|
||||
@Override
|
||||
public void removeStoreGoodsLabel(String storeLabelId) {
|
||||
|
||||
AuthUser tokenUser = UserContext.getCurrentUser();
|
||||
if (tokenUser == null || CharSequenceUtil.isEmpty(tokenUser.getStoreId())) {
|
||||
throw new ServiceException(ResultCode.USER_NOT_LOGIN);
|
||||
}
|
||||
//删除店铺分类
|
||||
this.removeById(storeLabelId);
|
||||
|
||||
//清除缓存
|
||||
removeCache(UserContext.getCurrentUser().getStoreId());
|
||||
removeCache(tokenUser.getStoreId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,14 @@ public enum GoodsTagsEnum {
|
||||
* "生成商品索引"
|
||||
*/
|
||||
GENERATOR_GOODS_INDEX("生成商品索引"),
|
||||
/**
|
||||
* "更新商品索引"
|
||||
*/
|
||||
UPDATE_GOODS_INDEX("更新商品索引"),
|
||||
/**
|
||||
* "重置商品索引"
|
||||
*/
|
||||
RESET_GOODS_INDEX("重置商品索引"),
|
||||
/**
|
||||
* "删除商品"
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user