Merge branch 'master' of gitee.com:beijing_hongye_huicheng/lilishop
This commit is contained in:
commit
0995a3b75f
@ -1,15 +1,18 @@
|
|||||||
package cn.lili.modules.goods.entity.dos;
|
package cn.lili.modules.goods.entity.dos;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
import cn.lili.base.BaseEntity;
|
import cn.lili.base.BaseEntity;
|
||||||
import cn.lili.modules.goods.entity.dto.GoodsOperationDTO;
|
import cn.lili.modules.goods.entity.dto.GoodsOperationDTO;
|
||||||
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
|
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
|
||||||
import cn.lili.modules.goods.entity.enums.GoodsStatusEnum;
|
import cn.lili.modules.goods.entity.enums.GoodsStatusEnum;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.hibernate.validator.constraints.Length;
|
import org.hibernate.validator.constraints.Length;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.validation.constraints.Max;
|
import javax.validation.constraints.Max;
|
||||||
@ -187,6 +190,11 @@ public class Goods extends BaseEntity {
|
|||||||
@ApiModelProperty(value = "销售模式", required = true)
|
@ApiModelProperty(value = "销售模式", required = true)
|
||||||
private String salesModel;
|
private String salesModel;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "商品参数json", hidden = true)
|
||||||
|
@Column(columnDefinition = "TEXT")
|
||||||
|
@JsonIgnore
|
||||||
|
private String params;
|
||||||
|
|
||||||
public Goods() {
|
public Goods() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,6 +215,9 @@ public class Goods extends BaseEntity {
|
|||||||
this.intro = goodsOperationDTO.getIntro();
|
this.intro = goodsOperationDTO.getIntro();
|
||||||
this.mobileIntro = goodsOperationDTO.getMobileIntro();
|
this.mobileIntro = goodsOperationDTO.getMobileIntro();
|
||||||
this.cost = goodsOperationDTO.getCost();
|
this.cost = goodsOperationDTO.getCost();
|
||||||
|
if (goodsOperationDTO.getGoodsParamsList() != null && goodsOperationDTO.getGoodsParamsList().isEmpty()) {
|
||||||
|
this.params = JSONUtil.toJsonStr(goodsOperationDTO.getGoodsParamsList());
|
||||||
|
}
|
||||||
//如果立即上架则
|
//如果立即上架则
|
||||||
this.marketEnable = goodsOperationDTO.isRelease() ? GoodsStatusEnum.UPPER.name() : GoodsStatusEnum.DOWN.name();
|
this.marketEnable = goodsOperationDTO.isRelease() ? GoodsStatusEnum.UPPER.name() : GoodsStatusEnum.DOWN.name();
|
||||||
|
|
||||||
|
@ -11,10 +11,7 @@ import cn.lili.common.rocketmq.tags.GoodsTagsEnum;
|
|||||||
import cn.lili.common.security.context.UserContext;
|
import cn.lili.common.security.context.UserContext;
|
||||||
import cn.lili.common.utils.PageUtil;
|
import cn.lili.common.utils.PageUtil;
|
||||||
import cn.lili.config.rocketmq.RocketmqCustomProperties;
|
import cn.lili.config.rocketmq.RocketmqCustomProperties;
|
||||||
import cn.lili.modules.goods.entity.dos.Goods;
|
import cn.lili.modules.goods.entity.dos.*;
|
||||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
|
||||||
import cn.lili.modules.goods.entity.dos.SpecValues;
|
|
||||||
import cn.lili.modules.goods.entity.dos.Specification;
|
|
||||||
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
||||||
import cn.lili.modules.goods.entity.dto.GoodsSkuStockDTO;
|
import cn.lili.modules.goods.entity.dto.GoodsSkuStockDTO;
|
||||||
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
|
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
|
||||||
@ -26,6 +23,7 @@ import cn.lili.modules.member.entity.dos.FootPrint;
|
|||||||
import cn.lili.modules.member.entity.dos.MemberEvaluation;
|
import cn.lili.modules.member.entity.dos.MemberEvaluation;
|
||||||
import cn.lili.modules.member.entity.enums.EvaluationGradeEnum;
|
import cn.lili.modules.member.entity.enums.EvaluationGradeEnum;
|
||||||
import cn.lili.modules.member.service.MemberEvaluationService;
|
import cn.lili.modules.member.service.MemberEvaluationService;
|
||||||
|
import cn.lili.modules.promotion.service.PromotionService;
|
||||||
import cn.lili.modules.search.entity.dos.EsGoodsAttribute;
|
import cn.lili.modules.search.entity.dos.EsGoodsAttribute;
|
||||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||||
import cn.lili.modules.search.service.EsGoodsIndexService;
|
import cn.lili.modules.search.service.EsGoodsIndexService;
|
||||||
@ -83,14 +81,20 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
private GoodsService goodsService;
|
private GoodsService goodsService;
|
||||||
//商品索引
|
//商品索引
|
||||||
private EsGoodsIndexService goodsIndexService;
|
private EsGoodsIndexService goodsIndexService;
|
||||||
|
@Autowired
|
||||||
|
private ParametersService parametersService;
|
||||||
|
@Autowired
|
||||||
|
private PromotionService promotionService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(List<Map<String, Object>> skuList, Goods goods) {
|
public void add(List<Map<String, Object>> skuList, Goods goods) {
|
||||||
|
// 检查是否需要生成索引
|
||||||
|
boolean needIndex = checkNeedIndex(goods);
|
||||||
List<GoodsSku> newSkuList;
|
List<GoodsSku> newSkuList;
|
||||||
// 如果有规格
|
// 如果有规格
|
||||||
if (skuList != null && !skuList.isEmpty()) {
|
if (skuList != null && !skuList.isEmpty()) {
|
||||||
// 添加商品sku
|
// 添加商品sku
|
||||||
newSkuList = this.addGoodsSku(skuList, goods);
|
newSkuList = this.addGoodsSku(skuList, goods, needIndex);
|
||||||
} else {
|
} else {
|
||||||
throw new ServiceException("规格必须要有一个!");
|
throw new ServiceException("规格必须要有一个!");
|
||||||
}
|
}
|
||||||
@ -99,8 +103,23 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
generateEsCheck(goods);
|
generateEsCheck(goods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkNeedIndex(Goods goods) {
|
||||||
|
if (goods.getParams() != null && !goods.getParams().isEmpty()) {
|
||||||
|
List<GoodsParams> goodsParams = JSONUtil.toList(goods.getParams(), GoodsParams.class);
|
||||||
|
for (GoodsParams goodsParam : goodsParams) {
|
||||||
|
Parameters parameters = parametersService.getById(goodsParam.getParamId());
|
||||||
|
if (parameters.getIsIndex() == 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(List<Map<String, Object>> skuList, Goods goods, Boolean regeneratorSkuFlag) {
|
public void update(List<Map<String, Object>> skuList, Goods goods, Boolean regeneratorSkuFlag) {
|
||||||
|
// 检查是否需要生成索引
|
||||||
|
boolean needIndex = checkNeedIndex(goods);
|
||||||
// 是否存在规格
|
// 是否存在规格
|
||||||
if (skuList == null || skuList.isEmpty()) {
|
if (skuList == null || skuList.isEmpty()) {
|
||||||
throw new ServiceException("规格必须要有一个!");
|
throw new ServiceException("规格必须要有一个!");
|
||||||
@ -120,7 +139,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
//删除sku相册
|
//删除sku相册
|
||||||
goodsGalleryService.removeByIds(oldSkuIds);
|
goodsGalleryService.removeByIds(oldSkuIds);
|
||||||
// 添加商品sku
|
// 添加商品sku
|
||||||
newSkuList = this.addGoodsSku(skuList, goods);
|
newSkuList = this.addGoodsSku(skuList, goods, needIndex);
|
||||||
|
|
||||||
//发送mq消息
|
//发送mq消息
|
||||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.SKU_DELETE.name();
|
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.SKU_DELETE.name();
|
||||||
@ -142,7 +161,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
this.updateBatchById(newSkuList);
|
this.updateBatchById(newSkuList);
|
||||||
}
|
}
|
||||||
this.updateStock(newSkuList);
|
this.updateStock(newSkuList);
|
||||||
generateEsCheck(goods);
|
if (Boolean.TRUE.equals(needIndex)) {
|
||||||
|
generateEsCheck(goods);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,7 +219,8 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
// 获取当前商品的索引信息
|
// 获取当前商品的索引信息
|
||||||
EsGoodsIndex goodsIndex = goodsIndexService.findById(skuId);
|
EsGoodsIndex goodsIndex = goodsIndexService.findById(skuId);
|
||||||
if (goodsIndex == null) {
|
if (goodsIndex == null) {
|
||||||
goodsIndex = goodsIndexService.resetEsGoodsIndex(goodsSku);
|
goodsIndex = new EsGoodsIndex(goodsSku);
|
||||||
|
goodsIndex.setPromotionMap(promotionService.getGoodsCurrentPromotionMap(goodsIndex));
|
||||||
}
|
}
|
||||||
//商品规格
|
//商品规格
|
||||||
GoodsSkuVO goodsSkuDetail = this.getGoodsSkuVO(goodsSku);
|
GoodsSkuVO goodsSkuDetail = this.getGoodsSkuVO(goodsSku);
|
||||||
@ -416,7 +438,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
//修改规格
|
//修改规格
|
||||||
this.update(goodsSku);
|
this.update(goodsSku);
|
||||||
//修改规格索引
|
//修改规格索引
|
||||||
goodsIndexService.updateIndexCommentNum(goodsSku.getId(), goodsSku.getCommentNum(), (int) highPraiseNum, grade);
|
goodsIndexService.updateIndexCommentNum(goodsSku.getId(), goodsSku.getCommentNum(), highPraiseNum, grade);
|
||||||
|
|
||||||
//修改商品的评价数量
|
//修改商品的评价数量
|
||||||
goodsService.updateGoodsCommentNum(goodsSku.getGoodsId());
|
goodsService.updateGoodsCommentNum(goodsSku.getGoodsId());
|
||||||
@ -479,7 +501,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
* @param skuList sku列表
|
* @param skuList sku列表
|
||||||
* @param goods 商品信息
|
* @param goods 商品信息
|
||||||
*/
|
*/
|
||||||
private List<GoodsSku> addGoodsSku(List<Map<String, Object>> skuList, Goods goods) {
|
private List<GoodsSku> addGoodsSku(List<Map<String, Object>> skuList, Goods goods, Boolean needIndex) {
|
||||||
List<GoodsSku> skus = new ArrayList<>();
|
List<GoodsSku> skus = new ArrayList<>();
|
||||||
List<EsGoodsIndex> goodsIndices = new ArrayList<>();
|
List<EsGoodsIndex> goodsIndices = new ArrayList<>();
|
||||||
for (Map<String, Object> skuVO : skuList) {
|
for (Map<String, Object> skuVO : skuList) {
|
||||||
@ -494,9 +516,11 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
stringRedisTemplate.opsForValue().set(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity().toString());
|
stringRedisTemplate.opsForValue().set(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity().toString());
|
||||||
}
|
}
|
||||||
this.saveBatch(skus);
|
this.saveBatch(skus);
|
||||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GENERATOR_GOODS_INDEX.name();
|
if (Boolean.TRUE.equals(needIndex)) {
|
||||||
//发送mq消息
|
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GENERATOR_GOODS_INDEX.name();
|
||||||
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goodsIndices), RocketmqSendCallbackBuilder.commonCallback());
|
//发送mq消息
|
||||||
|
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goodsIndices), RocketmqSendCallbackBuilder.commonCallback());
|
||||||
|
}
|
||||||
return skus;
|
return skus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -615,7 +639,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
sku.setThumbnail(thumbnail);
|
sku.setThumbnail(thumbnail);
|
||||||
|
|
||||||
//规格信息
|
//规格信息
|
||||||
sku.setId(Convert.toStr(map.get("id"), "").toString());
|
sku.setId(Convert.toStr(map.get("id"), ""));
|
||||||
sku.setSn(Convert.toStr(map.get("sn")));
|
sku.setSn(Convert.toStr(map.get("sn")));
|
||||||
sku.setWeight(Convert.toDouble(map.get("weight"), 0D));
|
sku.setWeight(Convert.toDouble(map.get("weight"), 0D));
|
||||||
sku.setPrice(Convert.toDouble(map.get("price"), 0D));
|
sku.setPrice(Convert.toDouble(map.get("price"), 0D));
|
||||||
|
@ -4,6 +4,7 @@ import cn.hutool.json.JSONUtil;
|
|||||||
import cn.lili.base.BaseEntity;
|
import cn.lili.base.BaseEntity;
|
||||||
import cn.lili.common.utils.BeanUtil;
|
import cn.lili.common.utils.BeanUtil;
|
||||||
import cn.lili.modules.base.entity.enums.ClientTypeEnum;
|
import cn.lili.modules.base.entity.enums.ClientTypeEnum;
|
||||||
|
import cn.lili.modules.order.cart.entity.enums.CartTypeEnum;
|
||||||
import cn.lili.modules.order.cart.entity.enums.DeliveryMethodEnum;
|
import cn.lili.modules.order.cart.entity.enums.DeliveryMethodEnum;
|
||||||
import cn.lili.modules.order.order.entity.dto.PriceDetailDTO;
|
import cn.lili.modules.order.order.entity.dto.PriceDetailDTO;
|
||||||
import cn.lili.modules.order.order.entity.enums.DeliverStatusEnum;
|
import cn.lili.modules.order.order.entity.enums.DeliverStatusEnum;
|
||||||
@ -210,7 +211,7 @@ public class Order extends BaseEntity {
|
|||||||
this.setId(oldId);
|
this.setId(oldId);
|
||||||
this.setOrderType(OrderTypeEnum.NORMAL.name());
|
this.setOrderType(OrderTypeEnum.NORMAL.name());
|
||||||
//促销信息填充
|
//促销信息填充
|
||||||
if (cartVO.getSkuList().get(0).getPromotions() != null) {
|
if (cartVO.getSkuList().get(0).getPromotions() != null && tradeDTO.getCartTypeEnum().equals(CartTypeEnum.PINTUAN)) {
|
||||||
Optional<String> pintuanId = cartVO.getSkuList().get(0).getPromotions().stream().filter(i -> i.getPromotionType().equals(PromotionTypeEnum.PINTUAN.name())).map(PromotionGoods::getPromotionId).findFirst();
|
Optional<String> pintuanId = cartVO.getSkuList().get(0).getPromotions().stream().filter(i -> i.getPromotionType().equals(PromotionTypeEnum.PINTUAN.name())).map(PromotionGoods::getPromotionId).findFirst();
|
||||||
if (pintuanId.isPresent()) {
|
if (pintuanId.isPresent()) {
|
||||||
promotionId = pintuanId.get();
|
promotionId = pintuanId.get();
|
||||||
|
@ -25,6 +25,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品索引
|
* 商品索引
|
||||||
|
*
|
||||||
* @author paulG
|
* @author paulG
|
||||||
* @date 2020/10/13
|
* @date 2020/10/13
|
||||||
**/
|
**/
|
||||||
@ -243,35 +244,6 @@ public class EsGoodsIndex implements Serializable {
|
|||||||
private Map<String, Object> promotionMap;
|
private Map<String, Object> promotionMap;
|
||||||
|
|
||||||
|
|
||||||
public void setGoodsSku(GoodsSku sku) {
|
|
||||||
if (sku != null) {
|
|
||||||
this.id = sku.getId();
|
|
||||||
this.goodsId = sku.getGoodsId();
|
|
||||||
this.goodsName = sku.getGoodsName();
|
|
||||||
this.price = sku.getPrice();
|
|
||||||
this.storeName = sku.getStoreName();
|
|
||||||
this.storeId = sku.getStoreId();
|
|
||||||
this.thumbnail = sku.getThumbnail();
|
|
||||||
this.categoryPath = sku.getCategoryPath();
|
|
||||||
this.goodsVideo = sku.getGoodsVideo();
|
|
||||||
this.mobileIntro = sku.getMobileIntro();
|
|
||||||
this.buyCount = sku.getBuyCount();
|
|
||||||
this.commentNum = sku.getCommentNum();
|
|
||||||
this.small = sku.getSmall();
|
|
||||||
this.brandId = sku.getBrandId();
|
|
||||||
this.sn = sku.getSn();
|
|
||||||
this.storeCategoryPath = sku.getStoreCategoryPath();
|
|
||||||
this.sellingPoint = sku.getSellingPoint();
|
|
||||||
this.selfOperated = sku.getSelfOperated();
|
|
||||||
this.salesModel = sku.getSalesModel();
|
|
||||||
this.marketEnable = sku.getMarketEnable();
|
|
||||||
this.isAuth = sku.getIsAuth();
|
|
||||||
this.intro = sku.getIntro();
|
|
||||||
this.grade = sku.getGrade();
|
|
||||||
this.releaseTime = new Date();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public EsGoodsIndex(GoodsSku sku) {
|
public EsGoodsIndex(GoodsSku sku) {
|
||||||
if (sku != null) {
|
if (sku != null) {
|
||||||
this.id = sku.getId();
|
this.id = sku.getId();
|
||||||
@ -315,4 +287,33 @@ public class EsGoodsIndex implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setGoodsSku(GoodsSku sku) {
|
||||||
|
if (sku != null) {
|
||||||
|
this.id = sku.getId();
|
||||||
|
this.goodsId = sku.getGoodsId();
|
||||||
|
this.goodsName = sku.getGoodsName();
|
||||||
|
this.price = sku.getPrice();
|
||||||
|
this.storeName = sku.getStoreName();
|
||||||
|
this.storeId = sku.getStoreId();
|
||||||
|
this.thumbnail = sku.getThumbnail();
|
||||||
|
this.categoryPath = sku.getCategoryPath();
|
||||||
|
this.goodsVideo = sku.getGoodsVideo();
|
||||||
|
this.mobileIntro = sku.getMobileIntro();
|
||||||
|
this.buyCount = sku.getBuyCount();
|
||||||
|
this.commentNum = sku.getCommentNum();
|
||||||
|
this.small = sku.getSmall();
|
||||||
|
this.brandId = sku.getBrandId();
|
||||||
|
this.sn = sku.getSn();
|
||||||
|
this.storeCategoryPath = sku.getStoreCategoryPath();
|
||||||
|
this.sellingPoint = sku.getSellingPoint();
|
||||||
|
this.selfOperated = sku.getSelfOperated();
|
||||||
|
this.salesModel = sku.getSalesModel();
|
||||||
|
this.marketEnable = sku.getMarketEnable();
|
||||||
|
this.isAuth = sku.getIsAuth();
|
||||||
|
this.intro = sku.getIntro();
|
||||||
|
this.grade = sku.getGrade();
|
||||||
|
this.releaseTime = new Date();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
package cn.lili.controller.other;
|
package cn.lili.controller.other;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import cn.lili.modules.goods.entity.dos.Goods;
|
||||||
|
import cn.lili.modules.goods.entity.dos.GoodsParams;
|
||||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||||
|
import cn.lili.modules.goods.entity.dos.Parameters;
|
||||||
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
|
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
|
||||||
import cn.lili.modules.goods.entity.enums.GoodsStatusEnum;
|
import cn.lili.modules.goods.entity.enums.GoodsStatusEnum;
|
||||||
|
import cn.lili.modules.goods.service.GoodsService;
|
||||||
import cn.lili.modules.goods.service.GoodsSkuService;
|
import cn.lili.modules.goods.service.GoodsSkuService;
|
||||||
|
import cn.lili.modules.goods.service.ParametersService;
|
||||||
import cn.lili.modules.promotion.service.PromotionService;
|
import cn.lili.modules.promotion.service.PromotionService;
|
||||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||||
import cn.lili.modules.search.service.EsGoodsIndexService;
|
import cn.lili.modules.search.service.EsGoodsIndexService;
|
||||||
@ -38,12 +44,18 @@ public class ElasticsearchController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private GoodsSkuService goodsSkuService;
|
private GoodsSkuService goodsSkuService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GoodsService goodsService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private StringRedisTemplate stringRedisTemplate;
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PromotionService promotionService;
|
private PromotionService promotionService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ParametersService parametersService;
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public void init() {
|
public void init() {
|
||||||
//查询商品信息
|
//查询商品信息
|
||||||
@ -53,16 +65,33 @@ public class ElasticsearchController {
|
|||||||
|
|
||||||
List<GoodsSku> list = goodsSkuService.list(queryWrapper);
|
List<GoodsSku> list = goodsSkuService.list(queryWrapper);
|
||||||
List<EsGoodsIndex> esGoodsIndices = new ArrayList<>();
|
List<EsGoodsIndex> esGoodsIndices = new ArrayList<>();
|
||||||
|
String goodsId = null;
|
||||||
//库存锁是在redis做的,所以生成索引,同时更新一下redis中的库存数量
|
//库存锁是在redis做的,所以生成索引,同时更新一下redis中的库存数量
|
||||||
for (GoodsSku goodsSku : list) {
|
for (GoodsSku goodsSku : list) {
|
||||||
EsGoodsIndex index = new EsGoodsIndex(goodsSku);
|
boolean needIndex = false;
|
||||||
Map<String, Object> goodsCurrentPromotionMap = promotionService.getGoodsCurrentPromotionMap(index);
|
if (goodsId == null || !goodsId.equals(goodsSku.getGoodsId())) {
|
||||||
index.setPromotionMap(goodsCurrentPromotionMap);
|
goodsId = goodsSku.getGoodsId();
|
||||||
esGoodsIndices.add(index);
|
Goods goods = goodsService.getById(goodsId);
|
||||||
stringRedisTemplate.opsForValue().set(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity().toString());
|
if (goods.getParams() != null && !goods.getParams().isEmpty()) {
|
||||||
|
List<GoodsParams> goodsParams = JSONUtil.toList(goods.getParams(), GoodsParams.class);
|
||||||
|
for (GoodsParams goodsParam : goodsParams) {
|
||||||
|
Parameters parameters = parametersService.getById(goodsParam.getParamId());
|
||||||
|
if (parameters.getIsIndex() == 1) {
|
||||||
|
needIndex = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Boolean.TRUE.equals(needIndex)) {
|
||||||
|
EsGoodsIndex index = new EsGoodsIndex(goodsSku);
|
||||||
|
Map<String, Object> goodsCurrentPromotionMap = promotionService.getGoodsCurrentPromotionMap(index);
|
||||||
|
index.setPromotionMap(goodsCurrentPromotionMap);
|
||||||
|
esGoodsIndices.add(index);
|
||||||
|
stringRedisTemplate.opsForValue().set(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity().toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//初始化商品索引
|
//初始化商品索引
|
||||||
esGoodsIndexService.initIndex(esGoodsIndices);
|
esGoodsIndexService.initIndex(esGoodsIndices);
|
||||||
Assertions.assertTrue(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user