!135 修复未开始的秒杀活动修改时,先添加秒杀商品后修改时间时,秒杀活动商品时间没有改变问题

Merge pull request !135 from OceansDeep/feature/pg
This commit is contained in:
OceansDeep 2022-03-01 03:50:15 +00:00 committed by Gitee
commit a2c32009f5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 73 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package cn.lili.modules.promotion.service;
import cn.lili.common.vo.PageVO;
import cn.lili.modules.promotion.entity.dos.Seckill;
import cn.lili.modules.promotion.entity.dos.SeckillApply;
import cn.lili.modules.promotion.entity.dto.search.SeckillSearchParams;
import cn.lili.modules.promotion.entity.vos.SeckillApplyVO;
@ -97,4 +98,12 @@ public interface SeckillApplyService extends IService<SeckillApply> {
*/
void updateSeckillApplyQuantity(String seckillId, String skuId, Integer quantity);
/**
* 更新秒杀活动时间
*
* @param seckill 秒杀活动
* @return 是否更新成功
*/
boolean updateSeckillApplyTime(Seckill seckill);
}

View File

@ -185,6 +185,7 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
if (!promotionGoodsList.isEmpty()) {
PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams();
searchParams.setStoreId(storeId);
searchParams.setPromotionType(PromotionTypeEnum.SECKILL.name());
searchParams.setSkuIds(promotionGoodsList.stream().map(PromotionGoods::getSkuId).collect(Collectors.toList()));
promotionGoodsService.deletePromotionGoods(searchParams);
//初始化促销商品
@ -207,6 +208,7 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
* @param id id
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void removeSeckillApply(String seckillId, String id) {
Seckill seckill = this.seckillService.getById(seckillId);
if (seckill == null) {
@ -243,6 +245,41 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
this.update(updateWrapper);
}
/**
* 更新秒杀活动时间
*
* @param seckill 秒杀活动
* @return 是否更新成功
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateSeckillApplyTime(Seckill seckill) {
boolean result = false;
List<PromotionGoods> promotionGoodsList = new ArrayList<>();
LambdaQueryWrapper<SeckillApply> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SeckillApply::getSeckillId, seckill.getId());
List<SeckillApply> list = this.list(queryWrapper);
for (SeckillApply seckillApply : list) {
//获取参与活动的商品信息
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(seckillApply.getSkuId());
//获取促销商品
PromotionGoods promotionGoods = this.setSeckillGoods(goodsSku, seckillApply, seckill);
promotionGoodsList.add(promotionGoods);
}
//保存促销活动商品信息
if (!promotionGoodsList.isEmpty()) {
PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams();
searchParams.setPromotionType(PromotionTypeEnum.SECKILL.name());
searchParams.setSkuIds(promotionGoodsList.stream().map(PromotionGoods::getSkuId).collect(Collectors.toList()));
promotionGoodsService.deletePromotionGoods(searchParams);
//初始化促销商品
PromotionTools.promotionGoodsInit(promotionGoodsList, seckill, PromotionTypeEnum.SECKILL);
result = promotionGoodsService.saveBatch(promotionGoodsList);
this.seckillService.updateEsGoodsSeckill(seckill, list);
}
return result;
}
/**
* 检查秒杀活动申请列表参数信息
*

View File

@ -131,12 +131,31 @@ public class SeckillServiceImpl extends AbstractPromotionsServiceImpl<SeckillMap
}
}
/**
* 通用促销更新
* 调用顺序:
* 1. checkStatus 检查促销状态
* 2. checkPromotions 检查促销参数
* 3. saveOrUpdate 保存促销信息
* 4. updatePromotionGoods 更新促销商品信息
* 5. updateEsGoodsIndex 更新商品索引促销信息
*
* @param promotions 促销信息
* @return 是否更新成功
*/
@Override
public boolean updatePromotions(Seckill promotions) {
seckillApplyService.updateSeckillApplyTime(promotions);
return super.updatePromotions(promotions);
}
/**
* 更新商品索引限时抢购信息
*
* @param seckill 限时抢购信息
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void updateEsGoodsSeckill(Seckill seckill, List<SeckillApply> seckillApplies) {
if (seckillApplies != null && !seckillApplies.isEmpty()) {
// 更新促销范围

View File

@ -14,6 +14,7 @@ import cn.lili.modules.search.entity.dto.EsGoodsSearchDTO;
import cn.lili.modules.search.entity.dto.HotWordsDTO;
import cn.lili.modules.search.entity.dto.ParamOptions;
import cn.lili.modules.search.entity.dto.SelectorOptions;
import cn.lili.modules.search.service.EsGoodsIndexService;
import cn.lili.modules.search.service.EsGoodsSearchService;
import com.alibaba.druid.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
@ -74,6 +75,9 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
@Autowired
@Qualifier("elasticsearchRestTemplate")
private ElasticsearchRestTemplate restTemplate;
@Autowired
private EsGoodsIndexService esGoodsIndexService;
/**
* 缓存
*/
@ -82,6 +86,10 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
@Override
public SearchPage<EsGoodsIndex> searchGoods(EsGoodsSearchDTO searchDTO, PageVO pageVo) {
boolean exists = restTemplate.indexOps(EsGoodsIndex.class).exists();
if (!exists) {
esGoodsIndexService.init();
}
if (CharSequenceUtil.isNotEmpty(searchDTO.getKeyword())) {
cache.incrementScore(CachePrefix.HOT_WORD.getPrefix(), searchDTO.getKeyword());
}