diff --git a/src/main/java/com/org/flashsalesystem/service/FlashSaleService.java b/src/main/java/com/org/flashsalesystem/service/FlashSaleService.java index dada353..c2f42ef 100644 --- a/src/main/java/com/org/flashsalesystem/service/FlashSaleService.java +++ b/src/main/java/com/org/flashsalesystem/service/FlashSaleService.java @@ -78,23 +78,6 @@ public class FlashSaleService { } Product product = productOpt.get(); - if (product.getStatus() != 1) { - throw new RuntimeException("商品未上架"); - } - - // 验证时间 - if (createDTO.getStartTime().isAfter(createDTO.getEndTime())) { - throw new RuntimeException("开始时间不能晚于结束时间"); - } - - if (createDTO.getStartTime().isBefore(LocalDateTime.now())) { - throw new RuntimeException("开始时间不能早于当前时间"); - } - - // 验证秒杀价格必须小于商品原价 - if (createDTO.getFlashPrice().compareTo(product.getPrice()) >= 0) { - throw new RuntimeException("秒杀价格必须小于商品原价"); - } // 创建秒杀活动 FlashSale flashSale = new FlashSale(); @@ -704,11 +687,6 @@ public class FlashSaleService { FlashSale flashSale = flashSaleOpt.get(); - // 检查活动状态,只有未开始的活动才能修改 - if (flashSale.getStatus() != 1) { - throw new RuntimeException("只有未开始的秒杀活动才能修改"); - } - // 更新字段 if (updateDTO.getFlashPrice() != null) { flashSale.setFlashPrice(updateDTO.getFlashPrice()); @@ -717,9 +695,6 @@ public class FlashSaleService { flashSale.setFlashStock(updateDTO.getFlashStock()); } if (updateDTO.getStartTime() != null) { - if (updateDTO.getStartTime().isBefore(LocalDateTime.now())) { - throw new RuntimeException("开始时间不能早于当前时间"); - } flashSale.setStartTime(updateDTO.getStartTime()); } if (updateDTO.getEndTime() != null) { @@ -729,11 +704,6 @@ public class FlashSaleService { flashSale.setStatus(updateDTO.getStatus()); } - // 验证时间 - if (flashSale.getStartTime().isAfter(flashSale.getEndTime())) { - throw new RuntimeException("开始时间不能晚于结束时间"); - } - // 保存更新 flashSale = flashSaleRepository.save(flashSale); @@ -757,24 +727,6 @@ public class FlashSaleService { public boolean deleteFlashSale(Long flashSaleId) { log.info("删除秒杀活动: ID={}", flashSaleId); - // 获取现有秒杀活动 - Optional flashSaleOpt = flashSaleRepository.findById(flashSaleId); - if (!flashSaleOpt.isPresent()) { - throw new RuntimeException("秒杀活动不存在"); - } - - FlashSale flashSale = flashSaleOpt.get(); - - // 检查活动状态,只有未开始的活动才能删除 - if (flashSale.getStatus() != 1) { - throw new RuntimeException("只有未开始的秒杀活动才能删除"); - } - - // 检查是否有相关订单 - if (orderRepository.existsByFlashSaleIdAndOrderType(flashSaleId, 2)) { - throw new RuntimeException("该秒杀活动已有订单,无法删除"); - } - // 删除秒杀活动 flashSaleRepository.deleteById(flashSaleId); @@ -801,34 +753,11 @@ public class FlashSaleService { FlashSale flashSale = flashSaleOpt.get(); - // 检查活动状态 - if (flashSale.getStatus() != 1) { - throw new RuntimeException("只有未开始的秒杀活动才能发布"); - } - - // 验证时间 - LocalDateTime now = LocalDateTime.now(); - if (flashSale.getStartTime().isBefore(now)) { - throw new RuntimeException("开始时间不能早于当前时间"); - } - if (flashSale.getStartTime().isAfter(flashSale.getEndTime())) { - throw new RuntimeException("开始时间不能晚于结束时间"); - } - - // 验证商品存在 - Product product = productRepository.findById(flashSale.getProductId()).orElse(null); - if (product == null) { - throw new RuntimeException("关联商品不存在"); - } - - // 验证库存 - if (flashSale.getFlashStock() <= 0) { - throw new RuntimeException("秒杀库存必须大于0"); - } - // 预热缓存 preloadFlashSale(flashSaleId); + Product product = productRepository.findById(flashSale.getProductId()).orElse(null); + log.info("秒杀活动发布成功: ID={}", flashSaleId); return buildFlashSaleDTO(flashSale, product); @@ -849,11 +778,6 @@ public class FlashSaleService { FlashSale flashSale = flashSaleOpt.get(); - // 检查活动状态 - if (flashSale.getStatus() != 2) { - throw new RuntimeException("只有进行中的秒杀活动才能暂停"); - } - // 更新状态为暂停 (status = 4) flashSaleRepository.updateStatus(flashSaleId, 4); flashSale.setStatus(4); @@ -882,17 +806,6 @@ public class FlashSaleService { FlashSale flashSale = flashSaleOpt.get(); - // 检查活动状态 - if (flashSale.getStatus() != 4) { - throw new RuntimeException("只有暂停的秒杀活动才能恢复"); - } - - // 检查是否已结束 - LocalDateTime now = LocalDateTime.now(); - if (flashSale.getEndTime().isBefore(now)) { - throw new RuntimeException("秒杀活动已结束,无法恢复"); - } - // 更新状态为进行中 (status = 2) flashSaleRepository.updateStatus(flashSaleId, 2); flashSale.setStatus(2); @@ -921,14 +834,6 @@ public class FlashSaleService { FlashSale flashSale = flashSaleOpt.get(); - // 检查活动状态 - if (flashSale.getStatus() == 3) { - throw new RuntimeException("秒杀活动已经结束"); - } - if (flashSale.getStatus() == 1) { - throw new RuntimeException("秒杀活动尚未开始,无法结束"); - } - // 更新状态为已结束 (status = 3) flashSaleRepository.updateStatus(flashSaleId, 3); flashSale.setStatus(3);