From 7581ebfa777b33a225e92c3151bc78bc5bea6172 Mon Sep 17 00:00:00 2001 From: XinWei <2718030729@qq.com> Date: Fri, 11 Oct 2024 14:23:23 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=92=E6=9D=80=E6=B4=BB=E5=8A=A8=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E6=98=BE=E7=A4=BA=E6=AD=A3=E5=9C=A8=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/spu/vo/AppProductSpuDetailRespVO.java | 3 ++ .../promotion/enums/ErrorCodeConstants.java | 2 + .../app/activity/AppActivityController.java | 2 +- .../seckill/AppSeckillActivityController.java | 48 ++++++++++++++----- .../seckill/SeckillActivityService.java | 8 ++++ .../seckill/SeckillActivityServiceImpl.java | 18 ++++++- 6 files changed, 68 insertions(+), 13 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuDetailRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuDetailRespVO.java index f1ee49b..b26c5a0 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuDetailRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuDetailRespVO.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.product.controller.app.spu.vo; import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -33,6 +34,8 @@ public class AppProductSpuDetailRespVO { @Schema(description = "商品轮播图", requiredMode = Schema.RequiredMode.REQUIRED) private List sliderPicUrls; + @Schema(description = "商品品牌编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Long brandId; // ========== 营销相关字段 ========= // ========== SKU 相关字段 ========= diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index 1038bad..74fdb33 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -149,4 +149,6 @@ public interface ErrorCodeConstants { ErrorCode POINT_ACTIVITY_JOIN_ACTIVITY_PRODUCT_NOT_EXISTS = new ErrorCode(1_013_007_007, "积分商品兑换失败,原因:商品不存在"); ErrorCode POINT_ACTIVITY_UPDATE_STOCK_FAIL = new ErrorCode(1_013_007_008, "积分商品兑换失败,原因:积分商品库存不足"); + ErrorCode TIME_FORMAT_ERROR = new ErrorCode(1_019_007_008, "秒杀时间段格式化错误"); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java index 38dd72b..7f27de5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java @@ -53,7 +53,7 @@ public class AppActivityController { private RewardActivityService rewardActivityService; @GetMapping("/list-by-spu-id") - @Operation(summary = "获得单个商品,近期参与的每个活动") + @Operation(summary = "获得单个商品,正在参与的所有活动") @Parameter(name = "spuId", description = "商品编号", required = true) public CommonResult> getActivityListBySpuId(@RequestParam("spuId") Long spuId) { // 每种活动,只返回一个 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java index ae33e40..464870f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; @@ -18,6 +19,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillConfigDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillProductDO; import cn.iocoder.yudao.module.promotion.service.seckill.SeckillActivityService; import cn.iocoder.yudao.module.promotion.service.seckill.SeckillConfigService; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import io.swagger.v3.oas.annotations.Operation; @@ -31,19 +33,21 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.time.Duration; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +import java.util.*; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.isBetween; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.TIME_FORMAT_ERROR; @Tag(name = "用户 App - 秒杀活动") @RestController @@ -59,7 +63,7 @@ public class AppSeckillActivityController { @Override public AppSeckillActivityNowRespVO load(String key) { - return getNowSeckillActivity0(); + return getNowSeckillActivity0(); } }); @@ -113,15 +117,37 @@ public class AppSeckillActivityController { @GetMapping("/spuList") @Parameter(name = "count", description = "需要展示的数量", example = "6") - @Operation(summary = "获得秒杀活动分页") - public CommonResult> getSeckillActivitySupList(@RequestParam(name = "count", defaultValue = "6") Integer count) { + @Operation(summary = "获得现在进行的秒杀活动分页") + public CommonResult> getSeckillActivitySupList(@RequestParam(name = "count", defaultValue = "3") Integer count) { AppSeckillActivityPageReqVO pageReqVO = new AppSeckillActivityPageReqVO(); - if (count != null && count != 0){ - pageReqVO.setPageNo(1); - pageReqVO.setPageSize(count); + Page page = new Page<>(1, 3);; + if (count != null && count != 0) { + page = new Page<>(1, count); } + // 先找出当前时间对应的配置时间段id + List configIdList = new ArrayList<>(); + try { + List timeList = configService.getSeckillConfigListByStatus(CommonStatusEnum.ENABLE.getStatus()); + SimpleDateFormat format = new SimpleDateFormat("HH:mm"); + // 当前时间 + Date currentTime = format.parse(format.format(new Date())); + // 遍历所有配置时间段,找出符合时间段的id + for (SeckillConfigDO seckillConfigDO : timeList) { + if (currentTime.before(format.parse(seckillConfigDO.getEndTime())) && currentTime.after(format.parse(seckillConfigDO.getStartTime()))) { + configIdList.add(seckillConfigDO.getId()); + } + } + } catch (ParseException e) { + throw exception(TIME_FORMAT_ERROR); + } + // 对配置时间段的id数组进行判断 + if (configIdList.isEmpty()) { + return success(null); + } + // 获取满足当前正在进行的活动 + PageResult pageResult = activityService.getRunningActivityByConfigIdsCount(configIdList, page); // 1. 查询满足当前阶段的活动 - PageResult pageResult = activityService.getSeckillActivityAppPageByConfigId(pageReqVO); +// PageResult pageResult = activityService.getSeckillActivityAppPageByConfigId(pageReqVO); if (CollUtil.isEmpty(pageResult.getList())) { return success(null); } @@ -135,7 +161,7 @@ public class AppSeckillActivityController { HashMap hashMap = new HashMap<>(); for (AppSeckillActivityRespVO respVO : result.getList()) { arrayList.add(respVO.getSpuId()); - hashMap.put(respVO.getSpuId(),respVO.getId()); + hashMap.put(respVO.getSpuId(), respVO.getId()); } List list = spuApi.getSpuList(arrayList); for (ProductSpuRespDTO respDTO : list) { diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java index 0ed6a4f..347b3ea 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.Se import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.activity.AppSeckillActivityPageReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillProductDO; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import javax.validation.Valid; import java.time.LocalDateTime; @@ -139,4 +140,11 @@ public interface SeckillActivityService { */ List getSeckillActivityBySpuIdsAndStatusAndDateTimeLt(Collection spuIds, Integer status, LocalDateTime dateTime); + /** + * 获取当前正在进行的秒杀活动 + * @param configIdList 符合配置时间段的id + * @param page 分页 + * @return cn.iocoder.yudao.framework.common.pojo.PageResult + */ + PageResult getRunningActivityByConfigIdsCount(List configIdList, Page page); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java index 8ccfb30..2d9535a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java @@ -7,6 +7,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; @@ -23,6 +24,8 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillConfigDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillProductDO; import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillActivityMapper; import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillProductMapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -85,7 +88,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { /** * 校验秒杀商品参与的活动是否存在冲突 - * + *

* 1. 校验秒杀时段是否存在 * 2. 秒杀商品是否参加其它活动 * @@ -336,4 +339,17 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId")), dateTime); } + @Override + public PageResult getRunningActivityByConfigIdsCount(List configIdList, Page page) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SeckillActivityDO::getStatus, CommonStatusEnum.ENABLE.getStatus()) + .ge(SeckillActivityDO::getEndTime, LocalDateTime.now()) + .in(SeckillActivityDO::getConfigIds, configIdList); + Page seckillActivityDOPage = seckillActivityMapper.selectPage(page, wrapper); + PageResult pageResult = new PageResult<>(); + pageResult.setTotal(seckillActivityDOPage.getTotal()); + pageResult.setList(seckillActivityDOPage.getRecords()); + return pageResult; + } + }