Search in sources :

Example 1 with SeckillApply

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()));
}
Also used : ServiceException(cn.lili.common.exception.ServiceException) SeckillApply(cn.lili.modules.promotion.entity.dos.SeckillApply) Seckill(cn.lili.modules.promotion.entity.dos.Seckill) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SeckillApply

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;
}
Also used : DateUtil(cn.hutool.core.date.DateUtil) java.util(java.util) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleDateFormat(java.text.SimpleDateFormat) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) BeanUtil(cn.hutool.core.bean.BeanUtil) SeckillApplyMapper(cn.lili.modules.promotion.mapper.SeckillApplyMapper) PromotionGoodsSearchParams(cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams) GoodsSku(cn.lili.modules.goods.entity.dos.GoodsSku) BasePromotions(cn.lili.modules.promotion.entity.dos.BasePromotions) SeckillService(cn.lili.modules.promotion.service.SeckillService) SeckillApplyVO(cn.lili.modules.promotion.entity.vos.SeckillApplyVO) Service(org.springframework.stereotype.Service) DateTime(cn.hutool.core.date.DateTime) PageVO(cn.lili.common.vo.PageVO) PromotionTypeEnum(cn.lili.common.enums.PromotionTypeEnum) ResultCode(cn.lili.common.enums.ResultCode) ServiceException(cn.lili.common.exception.ServiceException) SeckillGoodsVO(cn.lili.modules.promotion.entity.vos.SeckillGoodsVO) PromotionGoodsService(cn.lili.modules.promotion.service.PromotionGoodsService) ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) Seckill(cn.lili.modules.promotion.entity.dos.Seckill) SeckillSearchParams(cn.lili.modules.promotion.entity.dto.search.SeckillSearchParams) Cache(cn.lili.cache.Cache) SeckillApplyService(cn.lili.modules.promotion.service.SeckillApplyService) CachePrefix(cn.lili.cache.CachePrefix) SeckillApply(cn.lili.modules.promotion.entity.dos.SeckillApply) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) PromotionsApplyStatusEnum(cn.lili.modules.promotion.entity.enums.PromotionsApplyStatusEnum) SeckillTimelineVO(cn.lili.modules.promotion.entity.vos.SeckillTimelineVO) LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) GoodsSkuService(cn.lili.modules.goods.service.GoodsSkuService) PromotionGoods(cn.lili.modules.promotion.entity.dos.PromotionGoods) PromotionTools(cn.lili.modules.promotion.tools.PromotionTools) IPage(com.baomidou.mybatisplus.core.metadata.IPage) DatePattern(cn.hutool.core.date.DatePattern) PageUtil(cn.lili.mybatis.util.PageUtil) Transactional(org.springframework.transaction.annotation.Transactional) GoodsSku(cn.lili.modules.goods.entity.dos.GoodsSku) PromotionGoods(cn.lili.modules.promotion.entity.dos.PromotionGoods) SeckillApply(cn.lili.modules.promotion.entity.dos.SeckillApply) PromotionGoodsSearchParams(cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SeckillApply

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);
        }
    }
}
Also used : UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) SeckillApply(cn.lili.modules.promotion.entity.dos.SeckillApply) Seckill(cn.lili.modules.promotion.entity.dos.Seckill) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with SeckillApply

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());
    }
}
Also used : LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) PromotionGoods(cn.lili.modules.promotion.entity.dos.PromotionGoods) SeckillSearchParams(cn.lili.modules.promotion.entity.dto.search.SeckillSearchParams) SeckillApply(cn.lili.modules.promotion.entity.dos.SeckillApply) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with SeckillApply

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;
}
Also used : SeckillGoodsVO(cn.lili.modules.promotion.entity.vos.SeckillGoodsVO) DateUtil(cn.hutool.core.date.DateUtil) java.util(java.util) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleDateFormat(java.text.SimpleDateFormat) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) BeanUtil(cn.hutool.core.bean.BeanUtil) SeckillApplyMapper(cn.lili.modules.promotion.mapper.SeckillApplyMapper) PromotionGoodsSearchParams(cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams) GoodsSku(cn.lili.modules.goods.entity.dos.GoodsSku) BasePromotions(cn.lili.modules.promotion.entity.dos.BasePromotions) SeckillService(cn.lili.modules.promotion.service.SeckillService) SeckillApplyVO(cn.lili.modules.promotion.entity.vos.SeckillApplyVO) Service(org.springframework.stereotype.Service) DateTime(cn.hutool.core.date.DateTime) PageVO(cn.lili.common.vo.PageVO) PromotionTypeEnum(cn.lili.common.enums.PromotionTypeEnum) ResultCode(cn.lili.common.enums.ResultCode) ServiceException(cn.lili.common.exception.ServiceException) SeckillGoodsVO(cn.lili.modules.promotion.entity.vos.SeckillGoodsVO) PromotionGoodsService(cn.lili.modules.promotion.service.PromotionGoodsService) ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) Seckill(cn.lili.modules.promotion.entity.dos.Seckill) SeckillSearchParams(cn.lili.modules.promotion.entity.dto.search.SeckillSearchParams) Cache(cn.lili.cache.Cache) SeckillApplyService(cn.lili.modules.promotion.service.SeckillApplyService) CachePrefix(cn.lili.cache.CachePrefix) SeckillApply(cn.lili.modules.promotion.entity.dos.SeckillApply) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) PromotionsApplyStatusEnum(cn.lili.modules.promotion.entity.enums.PromotionsApplyStatusEnum) SeckillTimelineVO(cn.lili.modules.promotion.entity.vos.SeckillTimelineVO) LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) GoodsSkuService(cn.lili.modules.goods.service.GoodsSkuService) PromotionGoods(cn.lili.modules.promotion.entity.dos.PromotionGoods) PromotionTools(cn.lili.modules.promotion.tools.PromotionTools) IPage(com.baomidou.mybatisplus.core.metadata.IPage) DatePattern(cn.hutool.core.date.DatePattern) PageUtil(cn.lili.mybatis.util.PageUtil) Transactional(org.springframework.transaction.annotation.Transactional) GoodsSku(cn.lili.modules.goods.entity.dos.GoodsSku) SeckillApply(cn.lili.modules.promotion.entity.dos.SeckillApply) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Aggregations

SeckillApply (cn.lili.modules.promotion.entity.dos.SeckillApply)6 Transactional (org.springframework.transaction.annotation.Transactional)6 Seckill (cn.lili.modules.promotion.entity.dos.Seckill)5 ServiceException (cn.lili.common.exception.ServiceException)4 PromotionGoods (cn.lili.modules.promotion.entity.dos.PromotionGoods)4 LambdaUpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper)4 DateTime (cn.hutool.core.date.DateTime)3 GoodsSku (cn.lili.modules.goods.entity.dos.GoodsSku)3 PromotionGoodsSearchParams (cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams)3 SeckillSearchParams (cn.lili.modules.promotion.entity.dto.search.SeckillSearchParams)3 SeckillApplyVO (cn.lili.modules.promotion.entity.vos.SeckillApplyVO)3 BeanUtil (cn.hutool.core.bean.BeanUtil)2 DatePattern (cn.hutool.core.date.DatePattern)2 DateUtil (cn.hutool.core.date.DateUtil)2 Cache (cn.lili.cache.Cache)2 CachePrefix (cn.lili.cache.CachePrefix)2 PromotionTypeEnum (cn.lili.common.enums.PromotionTypeEnum)2 ResultCode (cn.lili.common.enums.ResultCode)2 PageVO (cn.lili.common.vo.PageVO)2 GoodsSkuService (cn.lili.modules.goods.service.GoodsSkuService)2