修复清除无效索引时的异常。某些情况下新建用户会创建两条member_wallet数据。优化代码。

This commit is contained in:
paulGao 2021-12-27 14:38:45 +08:00
parent 2af334d793
commit 9bf1dbe030
7 changed files with 23 additions and 26 deletions

View File

@ -21,6 +21,7 @@ public class MemberWalletExecute implements MemberRegisterEvent {
@Override @Override
public void memberRegister(Member member) { public void memberRegister(Member member) {
memberWalletService.save(member.getId(),member.getUsername()); // 有些情况下会同时创建一个member_id的两条数据
// memberWalletService.save(member.getId(),member.getUsername());
} }
} }

View File

@ -44,7 +44,7 @@ public class PromotionEverydayExecute implements EveryDayExecute {
*/ */
@Override @Override
public void execute() { public void execute() {
//查询条件 //清除所以商品索引的无效促销活动
this.esGoodsIndexService.cleanInvalidPromotion(); this.esGoodsIndexService.cleanInvalidPromotion();
//定时创建活动 //定时创建活动
addSeckill(); addSeckill();

View File

@ -71,7 +71,7 @@ public class ElasticsearchConfig extends AbstractElasticsearchConfiguration {
@Bean("elasticsearchRestTemplate") @Bean("elasticsearchRestTemplate")
public ElasticsearchRestTemplate elasticsearchRestTemplate() { public ElasticsearchRestTemplate elasticsearchRestTemplate() {
return new ElasticsearchRestTemplate(elasticsearchClient()); return new ElasticsearchRestTemplate(this.client);
} }
private HttpHost[] getHttpHosts() { private HttpHost[] getHttpHosts() {

View File

@ -93,8 +93,8 @@ public class CouponSearchParams extends BasePromotionsSearchParams implements Se
queryWrapper.nested(i -> i.gt(PromotionTools.START_TIME_COLUMN, new Date()).gt(PromotionTools.END_TIME_COLUMN, new Date())); queryWrapper.nested(i -> i.gt(PromotionTools.START_TIME_COLUMN, new Date()).gt(PromotionTools.END_TIME_COLUMN, new Date()));
break; break;
case START: case START:
queryWrapper.nested(i -> i.le(PromotionTools.START_TIME_COLUMN, new Date()).ge(PromotionTools.END_TIME_COLUMN, new Date())); queryWrapper.nested(i -> i.le(PromotionTools.START_TIME_COLUMN, new Date()).ge(PromotionTools.END_TIME_COLUMN, new Date()))
// .or(i -> i.gt("effective_days", 0).eq(RANGE_DAY_TYPE_COLUMN, CouponRangeDayEnum.DYNAMICTIME.name())); .or(i -> i.gt("effective_days", 0).eq(RANGE_DAY_TYPE_COLUMN, CouponRangeDayEnum.DYNAMICTIME.name()));
break; break;
case END: case END:
queryWrapper.nested(i -> i.lt(PromotionTools.START_TIME_COLUMN, new Date()).lt(PromotionTools.END_TIME_COLUMN, new Date())); queryWrapper.nested(i -> i.lt(PromotionTools.START_TIME_COLUMN, new Date()).lt(PromotionTools.END_TIME_COLUMN, new Date()));

View File

@ -15,8 +15,6 @@ import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum;
import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams;
import cn.lili.modules.promotion.entity.vos.SeckillSearchParams; import cn.lili.modules.promotion.entity.vos.SeckillSearchParams;
import cn.lili.modules.promotion.mapper.PromotionGoodsMapper; import cn.lili.modules.promotion.mapper.PromotionGoodsMapper;
import cn.lili.modules.promotion.service.CouponService;
import cn.lili.modules.promotion.service.FullDiscountService;
import cn.lili.modules.promotion.service.PromotionGoodsService; import cn.lili.modules.promotion.service.PromotionGoodsService;
import cn.lili.modules.promotion.service.SeckillApplyService; import cn.lili.modules.promotion.service.SeckillApplyService;
import cn.lili.modules.promotion.tools.PromotionTools; import cn.lili.modules.promotion.tools.PromotionTools;
@ -46,6 +44,8 @@ import java.util.List;
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper, PromotionGoods> implements PromotionGoodsService { public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper, PromotionGoods> implements PromotionGoodsService {
private static final String SKU_ID_COLUMN = "sku_id";
/** /**
* Redis * Redis
*/ */
@ -62,12 +62,6 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
@Autowired @Autowired
private GoodsSkuService goodsSkuService; private GoodsSkuService goodsSkuService;
@Autowired
private FullDiscountService fullDiscountService;
@Autowired
private CouponService couponService;
@Override @Override
public List<PromotionGoods> findSkuValidPromotion(String skuId, String storeIds) { public List<PromotionGoods> findSkuValidPromotion(String skuId, String storeIds) {
@ -77,7 +71,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
} }
QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>(); QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>();
queryWrapper.and(i -> i.or(j -> j.eq("sku_id", skuId)) queryWrapper.and(i -> i.or(j -> j.eq(SKU_ID_COLUMN, skuId))
.or(n -> n.eq("scope_type", PromotionsScopeTypeEnum.ALL.name())) .or(n -> n.eq("scope_type", PromotionsScopeTypeEnum.ALL.name()))
.or(n -> n.and(k -> k.eq("scope_type", PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name()) .or(n -> n.and(k -> k.eq("scope_type", PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name())
.and(l -> l.like("scope_id", sku.getCategoryPath()))))); .and(l -> l.like("scope_id", sku.getCategoryPath())))));
@ -123,7 +117,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
@Override @Override
public PromotionGoods getValidPromotionsGoods(String skuId, List<String> promotionTypes) { public PromotionGoods getValidPromotionsGoods(String skuId, List<String> promotionTypes) {
QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>(); QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("sku_id", skuId); queryWrapper.eq(SKU_ID_COLUMN, skuId);
queryWrapper.in("promotion_type", promotionTypes); queryWrapper.in("promotion_type", promotionTypes);
queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)); queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START));
return this.getOne(queryWrapper, false); return this.getOne(queryWrapper, false);
@ -139,7 +133,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
@Override @Override
public Double getValidPromotionsGoodsPrice(String skuId, List<String> promotionTypes) { public Double getValidPromotionsGoodsPrice(String skuId, List<String> promotionTypes) {
QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>(); QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("sku_id", skuId); queryWrapper.eq(SKU_ID_COLUMN, skuId);
queryWrapper.in("promotion_type", promotionTypes); queryWrapper.in("promotion_type", promotionTypes);
queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)); queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START));
return this.baseMapper.selectPromotionsGoodsPrice(queryWrapper); return this.baseMapper.selectPromotionsGoodsPrice(queryWrapper);

View File

@ -480,17 +480,13 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
//获取商品索引 //获取商品索引
if (promotionMap != null && !promotionMap.isEmpty()) { if (promotionMap != null && !promotionMap.isEmpty()) {
//促销不为空则进行清洗 //促销不为空则进行清洗
for (Map.Entry<String, Object> entry : promotionMap.entrySet()) { promotionMap.entrySet().removeIf(i -> {
BasePromotions promotion = (BasePromotions) entry.getValue(); BasePromotions promotion = (BasePromotions) i.getValue();
//判定条件为活动已结束 if (i.getKey().contains(PromotionTypeEnum.SECKILL.name()) || i.getKey().contains(PromotionTypeEnum.PINTUAN.name())) {
if (promotion.getEndTime() != null && promotion.getEndTime().getTime() < DateUtil.date().getTime()) { goodsIndex.setPromotionPrice(goodsIndex.getPrice());
if (entry.getKey().contains(PromotionTypeEnum.SECKILL.name()) || entry.getKey().contains(PromotionTypeEnum.PINTUAN.name())) {
goodsIndex.setPromotionPrice(goodsIndex.getPrice());
}
promotionMap.remove(entry.getKey());
} }
return promotion.getEndTime() != null && promotion.getEndTime().getTime() < DateUtil.date().getTime();
} });
} }
} }
goodsIndexRepository.saveAll(all); goodsIndexRepository.saveAll(all);

View File

@ -80,6 +80,12 @@ class EsTest {
} }
@Test
void cleanInvalidPromotion() {
this.esGoodsIndexService.cleanInvalidPromotion();
Assertions.assertTrue(true);
}
@Test @Test
void searchGoods() { void searchGoods() {
EsGoodsSearchDTO goodsSearchDTO = new EsGoodsSearchDTO(); EsGoodsSearchDTO goodsSearchDTO = new EsGoodsSearchDTO();