| | |
| | | import com.ruoyi.goods.controller.management.dto.GoodsSeckillQuery; |
| | | import com.ruoyi.goods.controller.management.dto.GoodsSeckillUpd; |
| | | import com.ruoyi.goods.controller.management.vo.GoodsSeckillVO; |
| | | import com.ruoyi.goods.domain.GoodsSeckillAppointment; |
| | | import com.ruoyi.goods.domain.MemberGoodsCollection; |
| | | import com.ruoyi.goods.mapper.GoodsSeckillMapper; |
| | | import com.ruoyi.goods.service.IGoodsSeckillAppointmentService; |
| | | import com.ruoyi.goods.service.IGoodsSeckillService; |
| | | import com.ruoyi.goods.service.IGoodsSkuService; |
| | | import com.ruoyi.goods.service.IMemberGoodsCollectionService; |
| | | import com.ruoyi.goods.service.async.AsyncMethodService; |
| | | import com.ruoyi.system.api.constants.DelayTaskEnum; |
| | | import com.ruoyi.system.api.constants.NotificationTypeConstant; |
| | | import com.ruoyi.system.api.domain.GoodsBrand; |
| | | import com.ruoyi.system.api.domain.GoodsCategory; |
| | |
| | | import com.ruoyi.system.api.domain.GoodsSeries; |
| | | import com.ruoyi.system.api.domain.GoodsSku; |
| | | import com.ruoyi.system.api.domain.WebsocketMessageDTO; |
| | | import com.ruoyi.system.api.domain.dto.GoodsStockUpdDTO; |
| | | import com.ruoyi.system.api.domain.dto.HomeGoodsSkuDTO; |
| | | import com.ruoyi.system.api.domain.dto.ListStatusDTO; |
| | | import com.ruoyi.system.api.domain.vo.HomeGoodsSeckillInfoVO; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.Optional; |
| | | import java.util.Set; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | |
| | | |
| | | @Resource |
| | | private IMemberGoodsCollectionService iMemberGoodsCollectionService; |
| | | |
| | | @Resource |
| | | private IGoodsSeckillAppointmentService iGoodsSeckillAppointmentService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addGoodsSeckill(GoodsSeckillDTO dto) { |
| | |
| | | goodsSeckill.setEndTime(dto.getEndTime()); |
| | | goodsSeckill.setStartStatus(StartStatusEnum.NOT_STARTED); |
| | | } |
| | | // 查询该时间范围内,是否已经存在该秒杀商品 |
| | | List<GoodsSeckill> list = this.lambdaQuery() |
| | | .ne(GoodsSeckill::getStartStatus, StartStatusEnum.ENDED) |
| | | .eq(GoodsSeckill::getListingStatus, ListingStatusEnum.ON_SHELVES) |
| | | .le(GoodsSeckill::getStartTime, dto.getStartTime()) |
| | | .ge(GoodsSeckill::getEndTime, dto.getStartTime()).list(); |
| | | Set<Long> existGoodsSkuIdSet = list.stream().map(GoodsSeckill::getGoodsSkuId) |
| | | .collect(Collectors.toSet()); |
| | | if (!existGoodsSkuIdSet.isEmpty()) { |
| | | List<GoodsSku> goodsSkuList = goodsSkuService.listByIds(existGoodsSkuIdSet); |
| | | Map<Long, String> goodsSkuMap = goodsSkuList.stream() |
| | | .collect(Collectors.toMap(GoodsSku::getId, GoodsSku::getSkuName)); |
| | | List<GoodsSeckill> collect = goodsSeckills.stream() |
| | | .filter(goodsSeckill -> existGoodsSkuIdSet.contains( |
| | | goodsSeckill.getGoodsSkuId())) |
| | | .collect(Collectors.toList()); |
| | | if (!collect.isEmpty()) { |
| | | String goodsSkuNames = collect.stream().map(item -> { |
| | | return goodsSkuMap.get(item.getGoodsSkuId()); |
| | | }).filter(Objects::nonNull) |
| | | .collect(Collectors.joining(",")); |
| | | throw new ServiceException( |
| | | String.format("添加失败,商品%s在该时间段内有其他秒杀活动", goodsSkuNames)); |
| | | } |
| | | } |
| | | this.saveBatch(goodsSeckills); |
| | | |
| | | for (GoodsSeckill goodsSeckill : goodsSeckills) { |
| | |
| | | if (StringUtils.isNull(goodsSku)) { |
| | | throw new ServiceException("商品不存在"); |
| | | } |
| | | |
| | | Integer seckillStock = goodsSeckill.getSeckillStock(); |
| | | goodsSkuService.lambdaUpdate() |
| | | .set(GoodsSku::getStock, goodsSku.getStock() - seckillStock) |
| | | .ge(GoodsSku::getStock, seckillStock) |
| | | .eq(GoodsSku::getId, goodsSku.getId()); |
| | | if (goodsSku.getStock() < seckillStock) { |
| | | throw new ServiceException( |
| | | String.format("秒杀商品%s剩余库存不足,请修改秒杀库存", |
| | | goodsSku.getSkuName())); |
| | | } |
| | | GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); |
| | | goodsStockUpdDTO.setAuctionStock(seckillStock * -1); |
| | | goodsStockUpdDTO.setGoodsSkuId(goodsSku.getId()); |
| | | goodsSkuService.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO)); |
| | | asyncMethodService.seckillScheduleTask(Lists.newArrayList(goodsSeckill)); |
| | | } |
| | | } |
| | |
| | | if (StringUtils.isNull(goodsSeckill)) { |
| | | throw new ServiceException("秒杀商品不存在"); |
| | | } |
| | | if (goodsSeckill.getStartStatus().equals(StartStatusEnum.STARTED)) { |
| | | if (goodsSeckill.getStartStatus().equals(StartStatusEnum.STARTED) |
| | | && goodsSeckill.getListingStatus().equals(ListingStatusEnum.ON_SHELVES)) { |
| | | throw new ServiceException("秒杀商品已开始秒杀,不能修改"); |
| | | } |
| | | GoodsSku goodsSku = goodsSkuService.getById(goodsSeckill.getGoodsSkuId()); |
| | | if (goodsSku.getStock() < upd.getSeckillStock()) { |
| | | throw new ServiceException("编辑失败,商品库存不足"); |
| | | } |
| | | GoodsSeckill goodsSeckillUpd = BeanUtils.copyBean(upd, GoodsSeckill.class); |
| | | goodsSeckillUpd.setListingStatus(ListingStatusEnum.ON_SHELVES); |
| | | this.updateById(goodsSeckillUpd); |
| | | GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); |
| | | goodsStockUpdDTO.setAuctionStock(upd.getSeckillStock() * -1); |
| | | goodsStockUpdDTO.setGoodsSkuId(goodsSeckill.getGoodsSkuId()); |
| | | goodsSkuService.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO)); |
| | | asyncMethodService.seckillScheduleTask(Lists.newArrayList(goodsSeckill)); |
| | | } |
| | | |
| | |
| | | if (StringUtils.isNull(goodsSeckill)) { |
| | | throw new ServiceException("秒杀商品不存在"); |
| | | } |
| | | this.lambdaUpdate() |
| | | .eq(GoodsSeckill::getId, dto.getId()) |
| | | .set(GoodsSeckill::getListingStatus, dto.getListingStatus()) |
| | | .update(); |
| | | goodsSeckill.setListingStatus(dto.getListingStatus()); |
| | | if (dto.getListingStatus().equals(ListingStatusEnum.REMOVED_FROM_THE_SHELF)) { |
| | | //移除该秒杀商品的延时任务 |
| | | redisService.deleteObject( |
| | | DelayTaskEnum.SECKILL_START_TASK.getCode() + "-" + goodsSeckill.getId()); |
| | | redisService.deleteObject( |
| | | DelayTaskEnum.SECKILL_END_TASK.getCode() + "-" + goodsSeckill.getId()); |
| | | // 退回剩余库存 |
| | | GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); |
| | | goodsStockUpdDTO.setAuctionStock(goodsSeckill.getSeckillStock()); |
| | | goodsStockUpdDTO.setGoodsSkuId(goodsSeckill.getGoodsSkuId()); |
| | | goodsSkuService.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO)); |
| | | } |
| | | this.updateById(goodsSeckill); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | GoodsSeckillVO vo = BeanUtils.copyBean(goodsSeckill, GoodsSeckillVO.class); |
| | | GoodsSku goods = goodsSkuService.getById(goodsSeckill.getGoodsSkuId()); |
| | | Optional.of(goods).ifPresent(goodsSku -> vo.setGoodsSkuName(goodsSku.getSkuName())); |
| | | Integer num = orderClient.getSeckillMembers(goodsSeckill.getGoodsSkuId(), |
| | | Optional.of(goods).ifPresent(goodsSku -> { |
| | | vo.setGoodsSkuName(goodsSku.getSkuName()); |
| | | vo.setGoodsSkuStock(goodsSku.getStock()); |
| | | }); |
| | | Integer num = orderClient.getSeckillMembers(goodsSeckill.getId(), |
| | | SecurityConstants.INNER).getData(); |
| | | vo.setNumberOfPurchasedMembers(StringUtils.isNull(num) ? 0 : num); |
| | | return vo; |
| | |
| | | GoodsSeckill goodsSeckill = this.getById(seckillId); |
| | | // 秒杀商品不能为空且上架状态为上架中 状态为未开始 |
| | | if (StringUtils.isNotNull(goodsSeckill) |
| | | && goodsSeckill.getStartStatus().equals(StartStatusEnum.NOT_STARTED) && |
| | | goodsSeckill.getListingStatus() |
| | | .equals(ListingStatusEnum.ON_SHELVES)) { |
| | | && goodsSeckill.getStartStatus().equals(StartStatusEnum.NOT_STARTED)) { |
| | | //开始秒杀 |
| | | this.lambdaUpdate().set(GoodsSeckill::getStartStatus, StartStatusEnum.STARTED) |
| | | .eq(GoodsSeckill::getId, seckillId).update(); |
| | |
| | | public PageDTO<HomeGoodsSeckillVO> getHomeGoodsSeckillVOList(HomeGoodsSkuDTO homeGoodsSkuDTO) { |
| | | LambdaQueryWrapper<GoodsSku> wrapper3= Wrappers.lambdaQuery(); |
| | | wrapper3.eq(GoodsSku::getDelFlag,0); |
| | | wrapper3.eq(GoodsSku::getListingStatus,0); |
| | | if (homeGoodsSkuDTO.getSkuName()!=null){ |
| | | if (homeGoodsSkuDTO.getSkuName()!=null && homeGoodsSkuDTO.getSkuName()!=""){ |
| | | wrapper3.like(GoodsSku::getSkuName,homeGoodsSkuDTO.getSkuName()); |
| | | } |
| | | if (homeGoodsSkuDTO.getBrandId()!=null){ |
| | |
| | | in.add(0); |
| | | in.add(1); |
| | | wrapper4.in(GoodsSeckill::getStartStatus,in); |
| | | wrapper4.in(GoodsSeckill::getGoodsSkuId,goodsSkuIdList); |
| | | wrapper4.orderByAsc(GoodsSeckill::getSortNum); |
| | | if(goodsSkuIdList.size()>0){ |
| | | wrapper4.in(GoodsSeckill::getGoodsSkuId,goodsSkuIdList); |
| | | } |
| | | |
| | | wrapper4.orderByDesc(GoodsSeckill::getSortNum); |
| | | Page<GoodsSeckill> page2 = this.page(page, wrapper4); |
| | | |
| | | PageDTO<HomeGoodsSeckillVO> HomeGoodsSeckillVOPageDTO = PageDTO.of(page2, HomeGoodsSeckillVO.class); |
| | |
| | | GoodsCategory data1 = goodsSkuClient.getCategoryOne(data6.getCategoryId(), SecurityConstants.INNER).getData(); |
| | | GoodsSeries data2 = goodsSkuClient.getSeriesOne(data6.getSeriesId(), SecurityConstants.INNER).getData(); |
| | | GoodsFlavorType data3 = goodsSkuClient.getFlavorTypeOne(data6.getFlavorTypeId(), SecurityConstants.INNER).getData(); |
| | | homeGoodsSeckillInfoVO.setBrand(data.getBrandName()); |
| | | if(data!=null){ |
| | | homeGoodsSeckillInfoVO.setBrand(data.getBrandName()); |
| | | } |
| | | if(data1!=null){ |
| | | homeGoodsSeckillInfoVO.setCategory(data1.getCategoryName()); |
| | | } |
| | | if(data2!=null){ |
| | | homeGoodsSeckillInfoVO.setSeries(data2.getSeriesName()); |
| | | } |
| | | if(data3!=null){ |
| | | homeGoodsSeckillInfoVO.setFlavorType(data3.getFlavorTypeName()); |
| | | } |
| | | |
| | | homeGoodsSeckillInfoVO.setPrice(data6.getPrice()); |
| | | homeGoodsSeckillInfoVO.setSoldQuantity(byId.getSoldQuantity()); |
| | | homeGoodsSeckillInfoVO.setUnit(data6.getUnit()); |
| | |
| | | homeGoodsSeckillInfoVO.setStartTime(byId.getStartTime()); |
| | | homeGoodsSeckillInfoVO.setEndTime(byId.getEndTime()); |
| | | homeGoodsSeckillInfoVO.setStartStatus(byId.getStartStatus()); |
| | | homeGoodsSeckillInfoVO.setSeckillStock(byId.getSeckillStock()); |
| | | |
| | | |
| | | LambdaQueryWrapper<MemberGoodsCollection> wrapper3= Wrappers.lambdaQuery(); |
| | | wrapper3.eq(MemberGoodsCollection::getDelFlag,0); |
| | |
| | | }else{ |
| | | homeGoodsSeckillInfoVO.setIsCollection(1); |
| | | } |
| | | |
| | | LambdaQueryWrapper<GoodsSeckillAppointment> wrapper4= Wrappers.lambdaQuery(); |
| | | wrapper4.eq(GoodsSeckillAppointment::getDelFlag,0); |
| | | wrapper4.eq(GoodsSeckillAppointment::getMemberId,homeGoodsSkuDTO.getMemberId()); |
| | | wrapper4.eq(GoodsSeckillAppointment::getGoodsSeckillId,homeGoodsSkuDTO.getGoodsSkuId()); |
| | | List<GoodsSeckillAppointment> list2 = iGoodsSeckillAppointmentService.list(wrapper4); |
| | | if (list2.size()>0){ |
| | | homeGoodsSeckillInfoVO.setIsAppointment(2); |
| | | }else{ |
| | | homeGoodsSeckillInfoVO.setIsAppointment(1); |
| | | } |
| | | |
| | | return homeGoodsSeckillInfoVO; |
| | | } |
| | | } |