修复清除无效索引时的异常。某些情况下新建用户会创建两条member_wallet数据。优化代码。
This commit is contained in:
parent
2af334d793
commit
9bf1dbe030
@ -21,6 +21,7 @@ public class MemberWalletExecute implements MemberRegisterEvent {
|
||||
|
||||
@Override
|
||||
public void memberRegister(Member member) {
|
||||
memberWalletService.save(member.getId(),member.getUsername());
|
||||
// 有些情况下,会同时创建一个member_id的两条数据
|
||||
// memberWalletService.save(member.getId(),member.getUsername());
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class PromotionEverydayExecute implements EveryDayExecute {
|
||||
*/
|
||||
@Override
|
||||
public void execute() {
|
||||
//查询条件
|
||||
//清除所以商品索引的无效促销活动
|
||||
this.esGoodsIndexService.cleanInvalidPromotion();
|
||||
//定时创建活动
|
||||
addSeckill();
|
||||
|
@ -71,7 +71,7 @@ public class ElasticsearchConfig extends AbstractElasticsearchConfiguration {
|
||||
|
||||
@Bean("elasticsearchRestTemplate")
|
||||
public ElasticsearchRestTemplate elasticsearchRestTemplate() {
|
||||
return new ElasticsearchRestTemplate(elasticsearchClient());
|
||||
return new ElasticsearchRestTemplate(this.client);
|
||||
}
|
||||
|
||||
private HttpHost[] getHttpHosts() {
|
||||
|
@ -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()));
|
||||
break;
|
||||
case START:
|
||||
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()));
|
||||
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()));
|
||||
break;
|
||||
case END:
|
||||
queryWrapper.nested(i -> i.lt(PromotionTools.START_TIME_COLUMN, new Date()).lt(PromotionTools.END_TIME_COLUMN, new Date()));
|
||||
|
@ -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.SeckillSearchParams;
|
||||
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.SeckillApplyService;
|
||||
import cn.lili.modules.promotion.tools.PromotionTools;
|
||||
@ -46,6 +44,8 @@ import java.util.List;
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper, PromotionGoods> implements PromotionGoodsService {
|
||||
|
||||
private static final String SKU_ID_COLUMN = "sku_id";
|
||||
|
||||
/**
|
||||
* Redis
|
||||
*/
|
||||
@ -62,12 +62,6 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
||||
@Autowired
|
||||
private GoodsSkuService goodsSkuService;
|
||||
|
||||
@Autowired
|
||||
private FullDiscountService fullDiscountService;
|
||||
|
||||
@Autowired
|
||||
private CouponService couponService;
|
||||
|
||||
@Override
|
||||
public List<PromotionGoods> findSkuValidPromotion(String skuId, String storeIds) {
|
||||
|
||||
@ -77,7 +71,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
||||
}
|
||||
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.and(k -> k.eq("scope_type", PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name())
|
||||
.and(l -> l.like("scope_id", sku.getCategoryPath())))));
|
||||
@ -123,7 +117,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
||||
@Override
|
||||
public PromotionGoods getValidPromotionsGoods(String skuId, List<String> promotionTypes) {
|
||||
QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("sku_id", skuId);
|
||||
queryWrapper.eq(SKU_ID_COLUMN, skuId);
|
||||
queryWrapper.in("promotion_type", promotionTypes);
|
||||
queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START));
|
||||
return this.getOne(queryWrapper, false);
|
||||
@ -139,7 +133,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
||||
@Override
|
||||
public Double getValidPromotionsGoodsPrice(String skuId, List<String> promotionTypes) {
|
||||
QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("sku_id", skuId);
|
||||
queryWrapper.eq(SKU_ID_COLUMN, skuId);
|
||||
queryWrapper.in("promotion_type", promotionTypes);
|
||||
queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START));
|
||||
return this.baseMapper.selectPromotionsGoodsPrice(queryWrapper);
|
||||
|
@ -480,17 +480,13 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
//获取商品索引
|
||||
if (promotionMap != null && !promotionMap.isEmpty()) {
|
||||
//促销不为空则进行清洗
|
||||
for (Map.Entry<String, Object> entry : promotionMap.entrySet()) {
|
||||
BasePromotions promotion = (BasePromotions) entry.getValue();
|
||||
//判定条件为活动已结束
|
||||
if (promotion.getEndTime() != null && promotion.getEndTime().getTime() < DateUtil.date().getTime()) {
|
||||
if (entry.getKey().contains(PromotionTypeEnum.SECKILL.name()) || entry.getKey().contains(PromotionTypeEnum.PINTUAN.name())) {
|
||||
goodsIndex.setPromotionPrice(goodsIndex.getPrice());
|
||||
}
|
||||
promotionMap.remove(entry.getKey());
|
||||
promotionMap.entrySet().removeIf(i -> {
|
||||
BasePromotions promotion = (BasePromotions) i.getValue();
|
||||
if (i.getKey().contains(PromotionTypeEnum.SECKILL.name()) || i.getKey().contains(PromotionTypeEnum.PINTUAN.name())) {
|
||||
goodsIndex.setPromotionPrice(goodsIndex.getPrice());
|
||||
}
|
||||
|
||||
}
|
||||
return promotion.getEndTime() != null && promotion.getEndTime().getTime() < DateUtil.date().getTime();
|
||||
});
|
||||
}
|
||||
}
|
||||
goodsIndexRepository.saveAll(all);
|
||||
|
@ -80,6 +80,12 @@ class EsTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void cleanInvalidPromotion() {
|
||||
this.esGoodsIndexService.cleanInvalidPromotion();
|
||||
Assertions.assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void searchGoods() {
|
||||
EsGoodsSearchDTO goodsSearchDTO = new EsGoodsSearchDTO();
|
||||
|
Loading…
x
Reference in New Issue
Block a user