Skip to content

Commit

Permalink
fix: 修复活动优惠券,没有生成商品促销信息问题
Browse files Browse the repository at this point in the history
  • Loading branch information
LeiGaoRobot committed Nov 23, 2023
1 parent 876b801 commit 50c7e20
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ public interface AbstractPromotionsService<T extends BasePromotions> extends ISe
*/
void updateEsGoodsIndex(T promotions);

/**
* 发送更新商品索引消息
*
* @param promotions 促销实体
*/
void sendUpdateEsGoodsMsg(T promotions);

/**
* 当前促销类型
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,25 @@ public void updateEsGoodsIndex(T promotions) {
//删除商品促销消息
applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("删除商品促销事件", rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.DELETE_GOODS_INDEX_PROMOTIONS.name(), JSONUtil.toJsonStr(build)));
} else {

String esPromotionKey = this.getPromotionType().name() + "-" + promotions.getId();
Map<String, Object> map = new HashMap<>();
// es促销key
map.put("esPromotionKey", esPromotionKey);
// 促销类型全路径名
map.put("promotionsType", promotions.getClass().getName());
// 促销实体
map.put("promotions", promotions);
applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("更新商品索引促销事件", rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.UPDATE_GOODS_INDEX_PROMOTIONS.name(), JSONUtil.toJsonStr(map)));
this.sendUpdateEsGoodsMsg(promotions);
}
}

@Override
@Transactional(rollbackFor = Exception.class)
public void sendUpdateEsGoodsMsg(T promotions) {

String esPromotionKey = this.getPromotionType().name() + "-" + promotions.getId();
Map<String, Object> map = new HashMap<>();
// es促销key
map.put("esPromotionKey", esPromotionKey);
// 促销类型全路径名
map.put("promotionsType", promotions.getClass().getName());
// 促销实体
map.put("promotions", promotions);
applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("更新商品索引促销事件", rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.UPDATE_GOODS_INDEX_PROMOTIONS.name(), JSONUtil.toJsonStr(map)));
}

@Override
public boolean allowExistSame() {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package cn.lili.modules.promotion.serviceimpl;

import cn.hutool.core.map.MapBuilder;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.json.JSONUtil;
import cn.lili.common.enums.PromotionTypeEnum;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.event.TransactionCommitSendMQEvent;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.properties.RocketmqCustomProperties;
import cn.lili.common.utils.DateUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.modules.goods.entity.dos.GoodsSku;
Expand All @@ -24,15 +27,18 @@
import cn.lili.modules.promotion.service.*;
import cn.lili.modules.promotion.tools.PromotionTools;
import cn.lili.mybatis.util.PageUtil;
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.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -70,6 +76,12 @@ public class CouponServiceImpl extends AbstractPromotionsServiceImpl<CouponMappe
@Autowired
private CouponActivityItemService couponActivityItemService;

@Autowired
private RocketmqCustomProperties rocketmqCustomProperties;

@Autowired
private ApplicationEventPublisher applicationEventPublisher;

/**
* 领取优惠券
*
Expand Down Expand Up @@ -270,9 +282,16 @@ public boolean updatePromotionsGoods(Coupon promotions) {
* @param promotions 优惠券信息
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void updateEsGoodsIndex(Coupon promotions) {
Coupon coupon = JSONUtil.parse(promotions).toBean(Coupon.class);
super.updateEsGoodsIndex(coupon);
if (!CouponRangeDayEnum.DYNAMICTIME.name().equals(coupon.getRangeDayType()) && promotions.getStartTime() == null && promotions.getEndTime() == null) {
Map<Object, Object> build = MapBuilder.create().put("promotionKey", this.getPromotionType() + "-" + promotions.getId()).put("scopeId", promotions.getScopeId()).build();
//删除商品促销消息
applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("删除商品促销事件", rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.DELETE_GOODS_INDEX_PROMOTIONS.name(), JSONUtil.toJsonStr(build)));
} else {
super.sendUpdateEsGoodsMsg(promotions);
}
}

@Override
Expand Down

0 comments on commit 50c7e20

Please sign in to comment.