use of cn.lili.modules.promotion.entity.dos.SeckillApply in project lilishop by lilishop.
the class SeckillApplyServiceImpl method removeSeckillApply.
/**
* 批量删除秒杀活动申请
*
* @param seckillId 秒杀活动活动id
* @param id id
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void removeSeckillApply(String seckillId, String id) {
Seckill seckill = this.seckillService.getById(seckillId);
if (seckill == null) {
throw new ServiceException(ResultCode.SECKILL_NOT_EXIST_ERROR);
}
SeckillApply seckillApply = this.getById(id);
if (seckillApply == null) {
throw new ServiceException(ResultCode.SECKILL_APPLY_NOT_EXIST_ERROR);
}
// 清除秒杀活动中的商品
this.remove(new LambdaQueryWrapper<SeckillApply>().eq(SeckillApply::getSeckillId, seckillId).in(SeckillApply::getId, id));
this.seckillService.deleteEsGoodsSeckill(seckill, Collections.singletonList(seckillApply.getSkuId()));
// 删除促销商品
this.promotionGoodsService.deletePromotionGoods(seckillId, Collections.singletonList(seckillApply.getSkuId()));
}
use of cn.lili.modules.promotion.entity.dos.SeckillApply in project lilishop by lilishop.
the class SeckillApplyServiceImpl method updateSeckillApplyTime.
/**
* 更新秒杀活动时间
*
* @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).stream().filter(i -> i.getTimeLine() != null && seckill.getHours().contains(i.getTimeLine().toString())).collect(Collectors.toList());
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.setPromotionId(seckill.getId());
promotionGoodsService.deletePromotionGoods(searchParams);
// 初始化促销商品
List<PromotionGoods> promotionGoods = PromotionTools.promotionGoodsInit(promotionGoodsList, seckill, PromotionTypeEnum.SECKILL);
result = promotionGoodsService.saveBatch(promotionGoods);
this.seckillService.updateEsGoodsSeckill(seckill, list);
LambdaQueryWrapper<SeckillApply> deleteWrapper = new LambdaQueryWrapper<>();
deleteWrapper.eq(SeckillApply::getSeckillId, seckill.getId());
deleteWrapper.notIn(SeckillApply::getSkuId, promotionGoodsList.stream().map(PromotionGoods::getSkuId).collect(Collectors.toList()));
this.remove(deleteWrapper);
}
seckillService.updateSeckillGoodsNum(seckill.getId());
return result;
}
use of cn.lili.modules.promotion.entity.dos.SeckillApply in project lilishop by lilishop.
the class SeckillServiceImpl method updateEsGoodsSeckill.
/**
* 更新商品索引限时抢购信息
*
* @param seckill 限时抢购信息
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void updateEsGoodsSeckill(Seckill seckill, List<SeckillApply> seckillApplies) {
if (seckillApplies != null && !seckillApplies.isEmpty()) {
// 更新促销范围
seckill.setScopeId(ArrayUtil.join(seckillApplies.stream().map(SeckillApply::getSkuId).toArray(), ","));
UpdateWrapper<Seckill> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", seckill.getId());
updateWrapper.set("scope_id", seckill.getScopeId());
this.update(updateWrapper);
// 循环秒杀商品数据,将数据按照时间段进行存储
for (SeckillApply seckillApply : seckillApplies) {
if (seckillApply.getPromotionApplyStatus().equals(PromotionsApplyStatusEnum.PASS.name())) {
this.setSeckillApplyTime(seckill, seckillApply);
}
}
if (!seckillApplies.isEmpty()) {
this.updateEsGoodsIndex(seckill);
}
}
}
use of cn.lili.modules.promotion.entity.dos.SeckillApply in project lilishop by lilishop.
the class PromotionGoodsServiceImpl method updatePromotionGoodsStock.
/**
* 更新促销活动商品库存
*
* @param promotionGoodsList 更新促销活动商品信息
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void updatePromotionGoodsStock(List<PromotionGoods> promotionGoodsList) {
for (PromotionGoods promotionGoods : promotionGoodsList) {
String promotionStockKey = PromotionGoodsService.getPromotionGoodsStockCacheKey(PromotionTypeEnum.valueOf(promotionGoods.getPromotionType()), promotionGoods.getPromotionId(), promotionGoods.getSkuId());
if (promotionGoods.getPromotionType().equals(PromotionTypeEnum.SECKILL.name())) {
SeckillSearchParams searchParams = new SeckillSearchParams();
searchParams.setSeckillId(promotionGoods.getPromotionId());
searchParams.setSkuId(promotionGoods.getSkuId());
SeckillApply seckillApply = this.seckillApplyService.getSeckillApply(searchParams);
if (seckillApply != null) {
seckillApplyService.updateSeckillApplySaleNum(promotionGoods.getPromotionId(), promotionGoods.getSkuId(), promotionGoods.getNum());
}
}
LambdaUpdateWrapper<PromotionGoods> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(PromotionGoods::getPromotionType, promotionGoods.getPromotionType()).eq(PromotionGoods::getPromotionId, promotionGoods.getPromotionId()).eq(PromotionGoods::getSkuId, promotionGoods.getSkuId());
updateWrapper.set(PromotionGoods::getQuantity, promotionGoods.getQuantity()).set(PromotionGoods::getNum, promotionGoods.getNum());
this.update(updateWrapper);
stringRedisTemplate.opsForValue().set(promotionStockKey, promotionGoods.getQuantity().toString());
}
}
use of cn.lili.modules.promotion.entity.dos.SeckillApply in project lilishop by lilishop.
the class SeckillApplyServiceImpl method wrapperSeckillGoods.
/**
* 组装当时间秒杀活动的商品数据
* w
*
* @param startTimeline 秒杀活动开始时刻
* @return 当时间秒杀活动的商品数据
*/
private List<SeckillGoodsVO> wrapperSeckillGoods(Integer startTimeline, String seckillId) {
List<SeckillGoodsVO> seckillGoodsVoS = new ArrayList<>();
List<SeckillApply> seckillApplyList = this.list(new LambdaQueryWrapper<SeckillApply>().eq(SeckillApply::getSeckillId, seckillId));
if (!seckillApplyList.isEmpty()) {
List<SeckillApply> collect = seckillApplyList.stream().filter(i -> i.getTimeLine().equals(startTimeline) && i.getPromotionApplyStatus().equals(PromotionsApplyStatusEnum.PASS.name())).collect(Collectors.toList());
for (SeckillApply seckillApply : collect) {
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(seckillApply.getSkuId());
if (goodsSku != null) {
SeckillGoodsVO goodsVO = new SeckillGoodsVO();
BeanUtil.copyProperties(seckillApply, goodsVO);
goodsVO.setGoodsImage(goodsSku.getThumbnail());
goodsVO.setGoodsId(goodsSku.getGoodsId());
goodsVO.setGoodsName(goodsSku.getGoodsName());
String promotionGoodsStockCacheKey = PromotionGoodsService.getPromotionGoodsStockCacheKey(PromotionTypeEnum.SECKILL, seckillId, seckillApply.getSkuId());
Object quantity = cache.get(promotionGoodsStockCacheKey);
if (quantity != null) {
goodsVO.setQuantity((Integer) quantity);
}
seckillGoodsVoS.add(goodsVO);
}
}
}
return seckillGoodsVoS;
}
Aggregations