修复下架商品没有删除商品索引问题。修复下单使用优惠券使金额变为0元时消费服务获取数据不正确导致没有及时更新订单状态问题。
This commit is contained in:
parent
e7563203fe
commit
168c630a13
@ -8,7 +8,6 @@ import cn.lili.modules.order.order.entity.dos.Receipt;
|
|||||||
import cn.lili.modules.order.order.entity.vo.OrderVO;
|
import cn.lili.modules.order.order.entity.vo.OrderVO;
|
||||||
import cn.lili.modules.order.order.entity.vo.ReceiptVO;
|
import cn.lili.modules.order.order.entity.vo.ReceiptVO;
|
||||||
import cn.lili.modules.order.order.service.ReceiptService;
|
import cn.lili.modules.order.order.service.ReceiptService;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -34,25 +33,23 @@ public class OrderCreateReceiptExecute implements TradeEvent {
|
|||||||
//获取发票信息
|
//获取发票信息
|
||||||
ReceiptVO receiptVO = tradeDTO.getReceiptVO();
|
ReceiptVO receiptVO = tradeDTO.getReceiptVO();
|
||||||
//如果需要获取发票则保存发票信息
|
//如果需要获取发票则保存发票信息
|
||||||
if (tradeDTO.getNeedReceipt()) {
|
if (Boolean.TRUE.equals(tradeDTO.getNeedReceipt()) && !orderList.isEmpty()) {
|
||||||
if (orderList.size() > 0) {
|
List<Receipt> receipts = new ArrayList<>();
|
||||||
List<Receipt> receipts = new ArrayList<>();
|
for (OrderVO orderVO : orderList) {
|
||||||
for (OrderVO orderVO : orderList) {
|
Receipt receipt = new Receipt();
|
||||||
Receipt receipt = new Receipt();
|
BeanUtil.copyProperties(receiptVO, receipt);
|
||||||
BeanUtil.copyProperties(receiptVO, receipt);
|
receipt.setMemberId(orderVO.getMemberId());
|
||||||
receipt.setMemberId(orderVO.getMemberId());
|
receipt.setMemberName(orderVO.getMemberName());
|
||||||
receipt.setMemberName(orderVO.getMemberName());
|
receipt.setStoreId(orderVO.getStoreId());
|
||||||
receipt.setStoreId(orderVO.getStoreId());
|
receipt.setStoreName(orderVO.getStoreName());
|
||||||
receipt.setStoreName(orderVO.getStoreName());
|
receipt.setOrderSn(orderVO.getSn());
|
||||||
receipt.setOrderSn(orderVO.getSn());
|
receipt.setReceiptDetail(JSONUtil.toJsonStr(orderVO.getOrderItems()));
|
||||||
receipt.setReceiptDetail(JSONUtil.toJsonStr(orderVO.getOrderItems()));
|
receipt.setReceiptPrice(orderVO.getFlowPrice());
|
||||||
receipt.setReceiptPrice(orderVO.getFlowPrice());
|
receipt.setReceiptStatus(0);
|
||||||
receipt.setReceiptStatus(0);
|
receipts.add(receipt);
|
||||||
receipts.add(receipt);
|
|
||||||
}
|
|
||||||
//保存发票
|
|
||||||
receiptService.saveBatch(receipts);
|
|
||||||
}
|
}
|
||||||
|
//保存发票
|
||||||
|
receiptService.saveBatch(receipts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,12 +186,28 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
|
|||||||
break;
|
break;
|
||||||
//审核商品
|
//审核商品
|
||||||
case GOODS_AUDIT:
|
case GOODS_AUDIT:
|
||||||
updateGoodsNum(messageExt);
|
Goods goods = JSONUtil.toBean(new String(messageExt.getBody()), Goods.class);
|
||||||
|
updateGoodsNum(goods);
|
||||||
break;
|
break;
|
||||||
//删除商品
|
//删除商品
|
||||||
case GOODS_DELETE:
|
case GOODS_DELETE:
|
||||||
deleteGoods(messageExt);
|
try {
|
||||||
updateGoodsNum(messageExt);
|
String goodsIdsJsonStr = new String(messageExt.getBody());
|
||||||
|
for (String goodsId : JSONUtil.toList(goodsIdsJsonStr, String.class)) {
|
||||||
|
Goods goodsById = this.goodsService.getById(goodsId);
|
||||||
|
if (goodsById != null) {
|
||||||
|
this.deleteGoods(goodsById);
|
||||||
|
this.updateGoodsNum(goodsById);
|
||||||
|
List<String> skuIdsByGoodsId = this.goodsSkuService.getSkuIdsByGoodsId(goodsId);
|
||||||
|
if (skuIdsByGoodsId != null && !skuIdsByGoodsId.isEmpty()) {
|
||||||
|
this.goodsIndexService.deleteIndexByIds(skuIdsByGoodsId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("删除商品索引事件执行异常,商品信息 {}", new String(messageExt.getBody()));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
//规格删除
|
//规格删除
|
||||||
case SKU_DELETE:
|
case SKU_DELETE:
|
||||||
@ -380,10 +396,9 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
|
|||||||
* 2.删除分销员-分销商品绑定关系
|
* 2.删除分销员-分销商品绑定关系
|
||||||
* 3.删除分销商品
|
* 3.删除分销商品
|
||||||
*
|
*
|
||||||
* @param messageExt 消息
|
* @param goods 消息
|
||||||
*/
|
*/
|
||||||
private void deleteGoods(MessageExt messageExt) {
|
private void deleteGoods(Goods goods) {
|
||||||
Goods goods = JSONUtil.toBean(new String(messageExt.getBody()), Goods.class);
|
|
||||||
|
|
||||||
DistributionGoodsSearchParams searchParams = new DistributionGoodsSearchParams();
|
DistributionGoodsSearchParams searchParams = new DistributionGoodsSearchParams();
|
||||||
searchParams.setGoodsId(goods.getId());
|
searchParams.setGoodsId(goods.getId());
|
||||||
@ -403,17 +418,15 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
|
|||||||
/**
|
/**
|
||||||
* 修改商品数量
|
* 修改商品数量
|
||||||
*
|
*
|
||||||
* @param messageExt 信息体
|
* @param goods 信息体
|
||||||
*/
|
*/
|
||||||
private void updateGoodsNum(MessageExt messageExt) {
|
private void updateGoodsNum(Goods goods) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Goods goods = JSONUtil.toBean(new String(messageExt.getBody()), Goods.class);
|
|
||||||
//更新店铺商品数量
|
//更新店铺商品数量
|
||||||
assert goods != null;
|
assert goods != null;
|
||||||
storeService.updateStoreGoodsNum(goods.getStoreId());
|
storeService.updateStoreGoodsNum(goods.getStoreId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("商品MQ信息错误:{}", messageExt.toString());
|
log.error("修改商品数量错误");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public class OrderMessageListener implements RocketMQListener<MessageExt> {
|
|||||||
//订单创建
|
//订单创建
|
||||||
case ORDER_CREATE:
|
case ORDER_CREATE:
|
||||||
String key = new String(messageExt.getBody());
|
String key = new String(messageExt.getBody());
|
||||||
TradeDTO tradeDTO = (TradeDTO) cache.get(key);
|
TradeDTO tradeDTO = JSONUtil.toBean(cache.getString(key), TradeDTO.class);
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
for (TradeEvent event : tradeEvent) {
|
for (TradeEvent event : tradeEvent) {
|
||||||
try {
|
try {
|
||||||
|
@ -2,6 +2,9 @@ package cn.lili.modules.goods.mapper;
|
|||||||
|
|
||||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
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> {
|
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 促销价格
|
* @param promotionPrice 促销价格
|
||||||
*/
|
*/
|
||||||
void updateGoodsSkuPromotion(String skuId, Double 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) {
|
for (Goods goods : goodsList) {
|
||||||
goodsSkuService.updateGoodsSkuStatus(goods);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,12 +359,13 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|||||||
for (Goods goods : goodsList) {
|
for (Goods goods : goodsList) {
|
||||||
//修改SKU状态
|
//修改SKU状态
|
||||||
goodsSkuService.updateGoodsSkuStatus(goods);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package cn.lili.modules.goods.serviceimpl;
|
|||||||
|
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
|
import cn.hutool.core.text.CharSequenceUtil;
|
||||||
import cn.hutool.core.thread.ThreadUtil;
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import cn.hutool.core.util.NumberUtil;
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
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.exception.ServiceException;
|
||||||
import cn.lili.common.properties.RocketmqCustomProperties;
|
import cn.lili.common.properties.RocketmqCustomProperties;
|
||||||
import cn.lili.common.security.context.UserContext;
|
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.Goods;
|
||||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||||
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
||||||
@ -221,7 +221,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
//获取商品VO
|
//获取商品VO
|
||||||
GoodsVO goodsVO = goodsService.getGoodsVO(goodsId);
|
GoodsVO goodsVO = goodsService.getGoodsVO(goodsId);
|
||||||
//如果skuid为空,则使用商品VO中sku信息获取
|
//如果skuid为空,则使用商品VO中sku信息获取
|
||||||
if (StringUtils.isEmpty(skuId) || "undefined".equals(skuId)) {
|
if (CharSequenceUtil.isEmpty(skuId) || "undefined".equals(skuId)) {
|
||||||
skuId = goodsVO.getSkuList().get(0).getId();
|
skuId = goodsVO.getSkuList().get(0).getId();
|
||||||
}
|
}
|
||||||
//从缓存拿商品Sku
|
//从缓存拿商品Sku
|
||||||
@ -532,6 +532,17 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
cache.remove(GoodsSkuService.getCacheKeys(skuId));
|
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商品索引
|
* 发送生成ES商品索引
|
||||||
*
|
*
|
||||||
@ -539,6 +550,10 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void generateEs(Goods goods) {
|
public void generateEs(Goods goods) {
|
||||||
|
// 不生成没有审核通过且没有上架的商品
|
||||||
|
if (!GoodsStatusEnum.UPPER.name().equals(goods.getMarketEnable()) || !GoodsAuthEnum.PASS.name().equals(goods.getAuthFlag())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ThreadUtil.execAsync(() -> {
|
ThreadUtil.execAsync(() -> {
|
||||||
try {
|
try {
|
||||||
// 延时执行,防止商品未保存完成就去生成商品索引导致生成索引时找不到商品问题
|
// 延时执行,防止商品未保存完成就去生成商品索引导致生成索引时找不到商品问题
|
||||||
|
File diff suppressed because one or more lines are too long
@ -79,6 +79,13 @@ public interface EsGoodsIndexService {
|
|||||||
*/
|
*/
|
||||||
void deleteIndexById(String id);
|
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.elasticsearch.script.Script;
|
||||||
import org.mybatis.spring.MyBatisSystemException;
|
import org.mybatis.spring.MyBatisSystemException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.SearchHit;
|
||||||
import org.springframework.data.elasticsearch.core.SearchPage;
|
import org.springframework.data.elasticsearch.core.SearchPage;
|
||||||
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
@ -100,6 +103,10 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
|||||||
@Autowired
|
@Autowired
|
||||||
private Cache<Object> cache;
|
private Cache<Object> cache;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("elasticsearchRestTemplate")
|
||||||
|
private ElasticsearchRestTemplate restTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
//获取索引任务标识
|
//获取索引任务标识
|
||||||
@ -286,6 +293,19 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
|||||||
goodsIndexRepository.deleteById(id);
|
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
|
@Override
|
||||||
public void initIndex(List<EsGoodsIndex> goodsIndexList) {
|
public void initIndex(List<EsGoodsIndex> goodsIndexList) {
|
||||||
if (goodsIndexList == null || goodsIndexList.isEmpty()) {
|
if (goodsIndexList == null || goodsIndexList.isEmpty()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user