修复下架商品没有删除商品索引问题。修复下单使用优惠券使金额变为0元时消费服务获取数据不正确导致没有及时更新订单状态问题。
This commit is contained in:
@@ -2,6 +2,9 @@ package cn.lili.modules.goods.mapper;
|
||||
|
||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 规格项数据处理层
|
||||
@@ -11,4 +14,13 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
*/
|
||||
public interface GoodsSkuMapper extends BaseMapper<GoodsSku> {
|
||||
|
||||
/**
|
||||
* 根据商品id获取全部skuId的集合
|
||||
*
|
||||
* @param goodsId goodsId
|
||||
* @return 全部skuId的集合
|
||||
*/
|
||||
@Select("SELECT id FROM li_goods_sku WHERE goods_id = #{goodsId}")
|
||||
List<String> getGoodsSkuIdByGoodsId(String goodsId);
|
||||
|
||||
}
|
||||
@@ -202,4 +202,12 @@ public interface GoodsSkuService extends IService<GoodsSku> {
|
||||
* @param promotionPrice 促销价格
|
||||
*/
|
||||
void updateGoodsSkuPromotion(String skuId, Double promotionPrice);
|
||||
|
||||
/**
|
||||
* 根据商品id获取全部skuId的集合
|
||||
*
|
||||
* @param goodsId goodsId
|
||||
* @return 全部skuId的集合
|
||||
*/
|
||||
List<String> getSkuIdsByGoodsId(String goodsId);
|
||||
}
|
||||
@@ -304,6 +304,14 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
||||
for (Goods goods : goodsList) {
|
||||
goodsSkuService.updateGoodsSkuStatus(goods);
|
||||
}
|
||||
|
||||
if (GoodsStatusEnum.DOWN.equals(goodsStatusEnum)) {
|
||||
|
||||
//商品删除消息
|
||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GOODS_DELETE.name();
|
||||
//发送mq消息
|
||||
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goodsIds), RocketmqSendCallbackBuilder.commonCallback());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -351,12 +359,13 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
||||
for (Goods goods : goodsList) {
|
||||
//修改SKU状态
|
||||
goodsSkuService.updateGoodsSkuStatus(goods);
|
||||
//商品删除消息
|
||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GOODS_DELETE.name();
|
||||
//发送mq消息
|
||||
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goods), RocketmqSendCallbackBuilder.commonCallback());
|
||||
}
|
||||
|
||||
//商品删除消息
|
||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GOODS_DELETE.name();
|
||||
//发送mq消息
|
||||
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goodsIds), RocketmqSendCallbackBuilder.commonCallback());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.lili.modules.goods.serviceimpl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -13,7 +14,6 @@ import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.properties.RocketmqCustomProperties;
|
||||
import cn.lili.common.security.context.UserContext;
|
||||
import cn.lili.common.utils.StringUtils;
|
||||
import cn.lili.modules.goods.entity.dos.Goods;
|
||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
||||
@@ -221,7 +221,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
//获取商品VO
|
||||
GoodsVO goodsVO = goodsService.getGoodsVO(goodsId);
|
||||
//如果skuid为空,则使用商品VO中sku信息获取
|
||||
if (StringUtils.isEmpty(skuId) || "undefined".equals(skuId)) {
|
||||
if (CharSequenceUtil.isEmpty(skuId) || "undefined".equals(skuId)) {
|
||||
skuId = goodsVO.getSkuList().get(0).getId();
|
||||
}
|
||||
//从缓存拿商品Sku
|
||||
@@ -532,6 +532,17 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
cache.remove(GoodsSkuService.getCacheKeys(skuId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商品id获取全部skuId的集合
|
||||
*
|
||||
* @param goodsId goodsId
|
||||
* @return 全部skuId的集合
|
||||
*/
|
||||
@Override
|
||||
public List<String> getSkuIdsByGoodsId(String goodsId) {
|
||||
return this.baseMapper.getGoodsSkuIdByGoodsId(goodsId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送生成ES商品索引
|
||||
*
|
||||
@@ -539,6 +550,10 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
*/
|
||||
@Override
|
||||
public void generateEs(Goods goods) {
|
||||
// 不生成没有审核通过且没有上架的商品
|
||||
if (!GoodsStatusEnum.UPPER.name().equals(goods.getMarketEnable()) || !GoodsAuthEnum.PASS.name().equals(goods.getAuthFlag())) {
|
||||
return;
|
||||
}
|
||||
ThreadUtil.execAsync(() -> {
|
||||
try {
|
||||
// 延时执行,防止商品未保存完成就去生成商品索引导致生成索引时找不到商品问题
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -79,6 +79,13 @@ public interface EsGoodsIndexService {
|
||||
*/
|
||||
void deleteIndexById(String id);
|
||||
|
||||
/**
|
||||
* 删除索引
|
||||
*
|
||||
* @param ids 商品索引id集合
|
||||
*/
|
||||
void deleteIndexByIds(List<String> ids);
|
||||
|
||||
/**
|
||||
* 初始化商品索引
|
||||
*
|
||||
|
||||
@@ -49,8 +49,11 @@ import org.elasticsearch.index.reindex.UpdateByQueryRequest;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.mybatis.spring.MyBatisSystemException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.core.SearchHit;
|
||||
import org.springframework.data.elasticsearch.core.SearchPage;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -100,6 +103,10 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
@Autowired
|
||||
private Cache<Object> cache;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("elasticsearchRestTemplate")
|
||||
private ElasticsearchRestTemplate restTemplate;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
//获取索引任务标识
|
||||
@@ -286,6 +293,19 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
goodsIndexRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除索引
|
||||
*
|
||||
* @param ids 商品索引id集合
|
||||
*/
|
||||
@Override
|
||||
public void deleteIndexByIds(List<String> ids) {
|
||||
NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder();
|
||||
queryBuilder.withQuery(QueryBuilders.termsQuery("id", ids.toArray()));
|
||||
this.restTemplate.delete(queryBuilder.build(), EsGoodsIndex.class);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initIndex(List<EsGoodsIndex> goodsIndexList) {
|
||||
if (goodsIndexList == null || goodsIndexList.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user