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;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.lili.base.BaseEntity;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsOperationDTO;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsStatusEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Max;
|
||||
@ -187,6 +190,11 @@ public class Goods extends BaseEntity {
|
||||
@ApiModelProperty(value = "销售模式", required = true)
|
||||
private String salesModel;
|
||||
|
||||
@ApiModelProperty(value = "商品参数json", hidden = true)
|
||||
@Column(columnDefinition = "TEXT")
|
||||
@JsonIgnore
|
||||
private String params;
|
||||
|
||||
public Goods() {
|
||||
}
|
||||
|
||||
@ -207,6 +215,9 @@ public class Goods extends BaseEntity {
|
||||
this.intro = goodsOperationDTO.getIntro();
|
||||
this.mobileIntro = goodsOperationDTO.getMobileIntro();
|
||||
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();
|
||||
|
||||
|
@ -11,10 +11,7 @@ import cn.lili.common.rocketmq.tags.GoodsTagsEnum;
|
||||
import cn.lili.common.security.context.UserContext;
|
||||
import cn.lili.common.utils.PageUtil;
|
||||
import cn.lili.config.rocketmq.RocketmqCustomProperties;
|
||||
import cn.lili.modules.goods.entity.dos.Goods;
|
||||
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.dos.*;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsSkuStockDTO;
|
||||
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.enums.EvaluationGradeEnum;
|
||||
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.EsGoodsIndex;
|
||||
import cn.lili.modules.search.service.EsGoodsIndexService;
|
||||
@ -83,14 +81,20 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
private GoodsService goodsService;
|
||||
//商品索引
|
||||
private EsGoodsIndexService goodsIndexService;
|
||||
@Autowired
|
||||
private ParametersService parametersService;
|
||||
@Autowired
|
||||
private PromotionService promotionService;
|
||||
|
||||
@Override
|
||||
public void add(List<Map<String, Object>> skuList, Goods goods) {
|
||||
// 检查是否需要生成索引
|
||||
boolean needIndex = checkNeedIndex(goods);
|
||||
List<GoodsSku> newSkuList;
|
||||
// 如果有规格
|
||||
if (skuList != null && !skuList.isEmpty()) {
|
||||
// 添加商品sku
|
||||
newSkuList = this.addGoodsSku(skuList, goods);
|
||||
newSkuList = this.addGoodsSku(skuList, goods, needIndex);
|
||||
} else {
|
||||
throw new ServiceException("规格必须要有一个!");
|
||||
}
|
||||
@ -99,8 +103,23 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
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
|
||||
public void update(List<Map<String, Object>> skuList, Goods goods, Boolean regeneratorSkuFlag) {
|
||||
// 检查是否需要生成索引
|
||||
boolean needIndex = checkNeedIndex(goods);
|
||||
// 是否存在规格
|
||||
if (skuList == null || skuList.isEmpty()) {
|
||||
throw new ServiceException("规格必须要有一个!");
|
||||
@ -120,7 +139,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
//删除sku相册
|
||||
goodsGalleryService.removeByIds(oldSkuIds);
|
||||
// 添加商品sku
|
||||
newSkuList = this.addGoodsSku(skuList, goods);
|
||||
newSkuList = this.addGoodsSku(skuList, goods, needIndex);
|
||||
|
||||
//发送mq消息
|
||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.SKU_DELETE.name();
|
||||
@ -142,7 +161,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
this.updateBatchById(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);
|
||||
if (goodsIndex == null) {
|
||||
goodsIndex = goodsIndexService.resetEsGoodsIndex(goodsSku);
|
||||
goodsIndex = new EsGoodsIndex(goodsSku);
|
||||
goodsIndex.setPromotionMap(promotionService.getGoodsCurrentPromotionMap(goodsIndex));
|
||||
}
|
||||
//商品规格
|
||||
GoodsSkuVO goodsSkuDetail = this.getGoodsSkuVO(goodsSku);
|
||||
@ -416,7 +438,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
//修改规格
|
||||
this.update(goodsSku);
|
||||
//修改规格索引
|
||||
goodsIndexService.updateIndexCommentNum(goodsSku.getId(), goodsSku.getCommentNum(), (int) highPraiseNum, grade);
|
||||
goodsIndexService.updateIndexCommentNum(goodsSku.getId(), goodsSku.getCommentNum(), highPraiseNum, grade);
|
||||
|
||||
//修改商品的评价数量
|
||||
goodsService.updateGoodsCommentNum(goodsSku.getGoodsId());
|
||||
@ -479,7 +501,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
* @param skuList sku列表
|
||||
* @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<EsGoodsIndex> goodsIndices = new ArrayList<>();
|
||||
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());
|
||||
}
|
||||
this.saveBatch(skus);
|
||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GENERATOR_GOODS_INDEX.name();
|
||||
//发送mq消息
|
||||
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goodsIndices), RocketmqSendCallbackBuilder.commonCallback());
|
||||
if (Boolean.TRUE.equals(needIndex)) {
|
||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GENERATOR_GOODS_INDEX.name();
|
||||
//发送mq消息
|
||||
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goodsIndices), RocketmqSendCallbackBuilder.commonCallback());
|
||||
}
|
||||
return skus;
|
||||
}
|
||||
|
||||
@ -615,7 +639,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
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.setWeight(Convert.toDouble(map.get("weight"), 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.common.utils.BeanUtil;
|
||||
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.order.entity.dto.PriceDetailDTO;
|
||||
import cn.lili.modules.order.order.entity.enums.DeliverStatusEnum;
|
||||
@ -210,7 +211,7 @@ public class Order extends BaseEntity {
|
||||
this.setId(oldId);
|
||||
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();
|
||||
if (pintuanId.isPresent()) {
|
||||
promotionId = pintuanId.get();
|
||||
|
@ -25,6 +25,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 商品索引
|
||||
*
|
||||
* @author paulG
|
||||
* @date 2020/10/13
|
||||
**/
|
||||
@ -243,35 +244,6 @@ public class EsGoodsIndex implements Serializable {
|
||||
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) {
|
||||
if (sku != null) {
|
||||
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;
|
||||
|
||||
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.Parameters;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
|
||||
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.ParametersService;
|
||||
import cn.lili.modules.promotion.service.PromotionService;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||
import cn.lili.modules.search.service.EsGoodsIndexService;
|
||||
@ -38,12 +44,18 @@ public class ElasticsearchController {
|
||||
@Autowired
|
||||
private GoodsSkuService goodsSkuService;
|
||||
|
||||
@Autowired
|
||||
private GoodsService goodsService;
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Autowired
|
||||
private PromotionService promotionService;
|
||||
|
||||
@Autowired
|
||||
private ParametersService parametersService;
|
||||
|
||||
@GetMapping
|
||||
public void init() {
|
||||
//查询商品信息
|
||||
@ -53,16 +65,33 @@ public class ElasticsearchController {
|
||||
|
||||
List<GoodsSku> list = goodsSkuService.list(queryWrapper);
|
||||
List<EsGoodsIndex> esGoodsIndices = new ArrayList<>();
|
||||
String goodsId = null;
|
||||
//库存锁是在redis做的,所以生成索引,同时更新一下redis中的库存数量
|
||||
for (GoodsSku goodsSku : list) {
|
||||
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());
|
||||
boolean needIndex = false;
|
||||
if (goodsId == null || !goodsId.equals(goodsSku.getGoodsId())) {
|
||||
goodsId = goodsSku.getGoodsId();
|
||||
Goods goods = goodsService.getById(goodsId);
|
||||
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);
|
||||
Assertions.assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user