Commit c766f7daa573cc194eee3f7da6b0a4ac2d14fb28
1 parent
1b154699
code review:砍价、秒杀的逻辑
Showing
18 changed files
with
68 additions
and
51 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java
| ... | ... | @@ -50,6 +50,7 @@ public class LocalDateTimeUtils { |
| 50 | 50 | * @return 指定时间 |
| 51 | 51 | */ |
| 52 | 52 | public static LocalDateTime buildTime(String timeStr) { |
| 53 | + // TODO @puhui999:这个方法的实现,和 LocalDateTimeUtil.parse() 的差异点是啥呀 | |
| 53 | 54 | return LocalDateTime.of(LocalDate.now(), LocalTime.parse(timeStr)); |
| 54 | 55 | } |
| 55 | 56 | ... | ... |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java
| ... | ... | @@ -31,7 +31,7 @@ public interface CombinationRecordApi { |
| 31 | 31 | boolean isCombinationRecordSuccess(Long userId, Long orderId); |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | - * 更新拼团状态为 成功 | |
| 34 | + * 更新拼团状态为【成功】 | |
| 35 | 35 | * |
| 36 | 36 | * @param userId 用户编号 |
| 37 | 37 | * @param orderId 订单编号 |
| ... | ... | @@ -39,7 +39,7 @@ public interface CombinationRecordApi { |
| 39 | 39 | void updateRecordStatusToSuccess(Long userId, Long orderId); |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | - * 更新拼团状态为 失败 | |
| 42 | + * 更新拼团状态为【失败】 | |
| 43 | 43 | * |
| 44 | 44 | * @param userId 用户编号 |
| 45 | 45 | * @param orderId 订单编号 | ... | ... |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/BargainActivityController.java
| ... | ... | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.promotion.controller.admin.bargain; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 7 | 6 | import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; |
| 8 | 7 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 9 | 8 | import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityCreateReqVO; |
| ... | ... | @@ -25,6 +24,7 @@ import javax.validation.Valid; |
| 25 | 24 | import java.util.List; |
| 26 | 25 | |
| 27 | 26 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 27 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | |
| 28 | 28 | |
| 29 | 29 | @Tag(name = "管理后台 - 砍价活动") |
| 30 | 30 | @RestController |
| ... | ... | @@ -79,7 +79,9 @@ public class BargainActivityController { |
| 79 | 79 | if (CollUtil.isEmpty(pageResult.getList())) { |
| 80 | 80 | return success(PageResult.empty(pageResult.getTotal())); |
| 81 | 81 | } |
| 82 | - List<ProductSpuRespDTO> spuList = spuApi.getSpuList(CollectionUtils.convertList(pageResult.getList(), BargainActivityDO::getSpuId)); | |
| 82 | + | |
| 83 | + // 拼接数据 | |
| 84 | + List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(pageResult.getList(), BargainActivityDO::getSpuId)); | |
| 83 | 85 | return success(BargainActivityConvert.INSTANCE.convertPage(pageResult, spuList)); |
| 84 | 86 | } |
| 85 | 87 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainActivityController.java
| ... | ... | @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 8 | 7 | import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; |
| 9 | 8 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 10 | 9 | import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.activity.AppBargainActivityDetailRespVO; |
| ... | ... | @@ -25,6 +24,7 @@ import javax.annotation.Resource; |
| 25 | 24 | import java.util.List; |
| 26 | 25 | |
| 27 | 26 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 27 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | |
| 28 | 28 | |
| 29 | 29 | @Tag(name = "用户 App - 砍价活动") |
| 30 | 30 | @RestController |
| ... | ... | @@ -39,27 +39,27 @@ public class AppBargainActivityController { |
| 39 | 39 | @GetMapping("/page") |
| 40 | 40 | @Operation(summary = "获得砍价活动分页") |
| 41 | 41 | public CommonResult<PageResult<AppBargainActivityRespVO>> getBargainActivityPage(PageParam pageReqVO) { |
| 42 | - PageResult<BargainActivityDO> result = bargainActivityService.getBargainActivityAppPage(pageReqVO); | |
| 42 | + PageResult<BargainActivityDO> result = bargainActivityService.getBargainActivityPageForApp(pageReqVO); | |
| 43 | 43 | if (CollUtil.isEmpty(result.getList())) { |
| 44 | 44 | return success(PageResult.empty(result.getTotal())); |
| 45 | 45 | } |
| 46 | - | |
| 47 | - List<ProductSpuRespDTO> spuList = spuApi.getSpuList(CollectionUtils.convertList(result.getList(), BargainActivityDO::getSpuId)); | |
| 46 | + // 拼接数据 | |
| 47 | + List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(result.getList(), BargainActivityDO::getSpuId)); | |
| 48 | 48 | return success(BargainActivityConvert.INSTANCE.convertAppPage(result, spuList)); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | + // TODO 芋艿:增加 Spring Cache | |
| 51 | 52 | @GetMapping("/list") |
| 52 | 53 | @Operation(summary = "获得砍价活动列表", description = "用于小程序首页") |
| 53 | 54 | @Parameter(name = "count", description = "需要展示的数量", example = "6") |
| 54 | 55 | public CommonResult<List<AppBargainActivityRespVO>> getBargainActivityList( |
| 55 | 56 | @RequestParam(name = "count", defaultValue = "6") Integer count) { |
| 56 | - List<BargainActivityDO> list = bargainActivityService.getBargainActivityAppList(count); | |
| 57 | + List<BargainActivityDO> list = bargainActivityService.getBargainActivityListForApp(count); | |
| 57 | 58 | if (CollUtil.isEmpty(list)) { |
| 58 | 59 | return success(BargainActivityConvert.INSTANCE.convertAppList(list)); |
| 59 | 60 | } |
| 60 | - | |
| 61 | - List<ProductSpuRespDTO> spuList = spuApi.getSpuList(CollectionUtils.convertList(list, BargainActivityDO::getSpuId)); | |
| 62 | - // TODO 芋艿:增加 Spring Cache | |
| 61 | + // 拼接数据 | |
| 62 | + List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(list, BargainActivityDO::getSpuId)); | |
| 63 | 63 | return success(BargainActivityConvert.INSTANCE.convertAppList(list, spuList)); |
| 64 | 64 | } |
| 65 | 65 | |
| ... | ... | @@ -71,9 +71,9 @@ public class AppBargainActivityController { |
| 71 | 71 | if (activity == null) { |
| 72 | 72 | return success(null); |
| 73 | 73 | } |
| 74 | - | |
| 74 | + // 拼接数据 | |
| 75 | 75 | ProductSpuRespDTO spu = spuApi.getSpu(activity.getSpuId()); |
| 76 | - return success(BargainActivityConvert.INSTANCE.convert1(activity, spu)); | |
| 76 | + return success(BargainActivityConvert.INSTANCE.convert(activity, spu)); | |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java
| ... | ... | @@ -4,7 +4,6 @@ import cn.hutool.core.util.ObjectUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 8 | 7 | import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; |
| 9 | 8 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 10 | 9 | import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.activity.AppSeckillActivityDetailRespVO; |
| ... | ... | @@ -33,8 +32,7 @@ import java.util.List; |
| 33 | 32 | |
| 34 | 33 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 35 | 34 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 36 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; | |
| 37 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst; | |
| 35 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | |
| 38 | 36 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.isBetween; |
| 39 | 37 | import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_ACTIVITY_FAIL_STATUS_CLOSED; |
| 40 | 38 | |
| ... | ... | @@ -56,30 +54,33 @@ public class AppSeckillActivityController { |
| 56 | 54 | @Operation(summary = "获得当前秒杀活动") // 提供给首页使用 |
| 57 | 55 | // TODO 芋艿:需要增加 spring cache |
| 58 | 56 | public CommonResult<AppSeckillActivityNowRespVO> getNowSeckillActivity() { |
| 59 | - // 1、获取当前时间处在哪个秒杀阶段 | |
| 57 | + // 1. 获取当前时间处在哪个秒杀阶段 | |
| 58 | + // TODO @puhui999:可以考虑在 service 写个方法;这样 controller 不用关注过多逻辑 | |
| 60 | 59 | List<SeckillConfigDO> configList = configService.getSeckillConfigList(); |
| 61 | 60 | SeckillConfigDO filteredConfig = findFirst(configList, config -> ObjectUtil.equal(config.getStatus(), |
| 62 | 61 | CommonStatusEnum.ENABLE.getStatus()) && isBetween(config.getStartTime(), config.getEndTime())); |
| 63 | - // 1、1 时段不存在直接返回 null | |
| 64 | - if (filteredConfig == null) { | |
| 62 | + if (filteredConfig == null) { // 时段不存在直接返回 null | |
| 65 | 63 | return success(null); |
| 66 | 64 | } |
| 67 | 65 | |
| 68 | - // 2、查询满足当前阶段的活动 | |
| 66 | + // 2. 查询满足当前阶段的活动 | |
| 67 | + // TODO @puhui999:最好直接返回开启的;不多查询数据 | |
| 69 | 68 | List<SeckillActivityDO> activityList = activityService.getSeckillActivityListByConfigIds(Arrays.asList(filteredConfig.getId())); |
| 70 | 69 | List<SeckillActivityDO> filteredList = filterList(activityList, item -> ObjectUtil.equal(item.getStatus(), CommonStatusEnum.ENABLE.getStatus())); |
| 71 | - // 2、1 获取 spu 信息 | |
| 72 | - List<ProductSpuRespDTO> spuList = spuApi.getSpuList(CollectionUtils.convertList(filteredList, SeckillActivityDO::getSpuId)); | |
| 70 | + | |
| 71 | + // 3. 拼接数据 | |
| 72 | + List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(filteredList, SeckillActivityDO::getSpuId)); | |
| 73 | 73 | return success(SeckillActivityConvert.INSTANCE.convert(filteredConfig, filteredList, spuList)); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | @GetMapping("/page") |
| 77 | 77 | @Operation(summary = "获得秒杀活动分页") |
| 78 | 78 | public CommonResult<PageResult<AppSeckillActivityRespVO>> getSeckillActivityPage(AppSeckillActivityPageReqVO pageReqVO) { |
| 79 | - // 1、查询满足当前阶段的活动 | |
| 79 | + // 1. 查询满足当前阶段的活动 | |
| 80 | 80 | PageResult<SeckillActivityDO> pageResult = activityService.getSeckillActivityAppPageByConfigId(pageReqVO); |
| 81 | - // 1、1 获取 spu 信息 | |
| 82 | - List<ProductSpuRespDTO> spuList = spuApi.getSpuList(CollectionUtils.convertList(pageResult.getList(), SeckillActivityDO::getSpuId)); | |
| 81 | + | |
| 82 | + // 2. 拼接数据 | |
| 83 | + List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(pageResult.getList(), SeckillActivityDO::getSpuId)); | |
| 83 | 84 | return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult, spuList)); |
| 84 | 85 | } |
| 85 | 86 | |
| ... | ... | @@ -88,15 +89,15 @@ public class AppSeckillActivityController { |
| 88 | 89 | @Parameter(name = "id", description = "活动编号", required = true, example = "1024") |
| 89 | 90 | public CommonResult<AppSeckillActivityDetailRespVO> getSeckillActivity(@RequestParam("id") Long id) { |
| 90 | 91 | // 1、获取当前时间处在哪个秒杀阶段 |
| 92 | + // TODO puhui999:这里,和 58 行是雷同的 | |
| 91 | 93 | List<SeckillConfigDO> configList = configService.getSeckillConfigList(); |
| 92 | 94 | SeckillConfigDO filteredConfig = findFirst(configList, config -> ObjectUtil.equal(config.getStatus(), |
| 93 | 95 | CommonStatusEnum.ENABLE.getStatus()) && isBetween(config.getStartTime(), config.getEndTime())); |
| 94 | - // 1、1 时段不存在直接返回 null | |
| 95 | - if (filteredConfig == null) { | |
| 96 | + if (filteredConfig == null) { // 时段不存在直接返回 null | |
| 96 | 97 | return success(null); |
| 97 | 98 | } |
| 98 | 99 | |
| 99 | - // 2、获取活动 | |
| 100 | + // 2. 获取活动 | |
| 100 | 101 | SeckillActivityDO seckillActivity = activityService.getSeckillActivity(id); |
| 101 | 102 | if (seckillActivity == null) { |
| 102 | 103 | return success(null); |
| ... | ... | @@ -106,7 +107,7 @@ public class AppSeckillActivityController { |
| 106 | 107 | throw exception(SECKILL_ACTIVITY_FAIL_STATUS_CLOSED); |
| 107 | 108 | } |
| 108 | 109 | |
| 109 | - // 3、获取活动商品 | |
| 110 | + // 3. 拼接数据 | |
| 110 | 111 | List<SeckillProductDO> products = activityService.getSeckillProductListByActivityId(seckillActivity.getId()); |
| 111 | 112 | return success(SeckillActivityConvert.INSTANCE.convert3(seckillActivity, products, filteredConfig)); |
| 112 | 113 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillConfigController.java
| ... | ... | @@ -32,19 +32,12 @@ public class AppSeckillConfigController { |
| 32 | 32 | @Operation(summary = "获得秒杀时间段列表") |
| 33 | 33 | public CommonResult<List<AppSeckillConfigRespVO>> getSeckillConfigList() { |
| 34 | 34 | List<SeckillConfigDO> list = configService.getSeckillConfigListByStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 35 | + // TODO @puhui999:如果这种,不用判空也问题不大; | |
| 35 | 36 | if (CollectionUtil.isEmpty(list)) { |
| 36 | 37 | return success(Collections.emptyList()); |
| 37 | 38 | } |
| 38 | 39 | |
| 39 | 40 | return success(SeckillConfigConvert.INSTANCE.convertList2(list)); |
| 40 | - //return success(Arrays.asList( | |
| 41 | - // new AppSeckillConfigRespVO().setId(1L).setStartTime("00:00").setEndTime("09:59") | |
| 42 | - // .setSliderPicUrls(Arrays.asList("https://static.iocoder.cn/mall/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg", | |
| 43 | - // "https://static.iocoder.cn/mall/132.jpeg")), | |
| 44 | - // new AppSeckillConfigRespVO().setId(2L).setStartTime("10:00").setEndTime("12:59"), | |
| 45 | - // new AppSeckillConfigRespVO().setId(2L).setStartTime("13:00").setEndTime("22:59"), | |
| 46 | - // new AppSeckillConfigRespVO().setId(2L).setStartTime("23:00").setEndTime("23:59") | |
| 47 | - //)); | |
| 48 | 41 | } |
| 49 | 42 | |
| 50 | 43 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java
| ... | ... | @@ -42,9 +42,11 @@ public interface BargainActivityConvert { |
| 42 | 42 | |
| 43 | 43 | default PageResult<BargainActivityRespVO> convertPage(PageResult<BargainActivityDO> page, List<ProductSpuRespDTO> spuList) { |
| 44 | 44 | PageResult<BargainActivityRespVO> result = convertPage(page); |
| 45 | + // 拼接关联属性 | |
| 45 | 46 | Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId); |
| 46 | 47 | List<BargainActivityRespVO> list = CollectionUtils.convertList(result.getList(), item -> { |
| 47 | 48 | findAndThen(spuMap, item.getSpuId(), spu -> { |
| 49 | + // TODO @puhui999:这里可以使用链式哈 | |
| 48 | 50 | item.setPicUrl(spu.getPicUrl()); |
| 49 | 51 | item.setSpuName(spu.getName()); |
| 50 | 52 | }); |
| ... | ... | @@ -56,7 +58,7 @@ public interface BargainActivityConvert { |
| 56 | 58 | |
| 57 | 59 | AppBargainActivityDetailRespVO convert1(BargainActivityDO bean); |
| 58 | 60 | |
| 59 | - default AppBargainActivityDetailRespVO convert1(BargainActivityDO bean, ProductSpuRespDTO spu) { | |
| 61 | + default AppBargainActivityDetailRespVO convert(BargainActivityDO bean, ProductSpuRespDTO spu) { | |
| 60 | 62 | AppBargainActivityDetailRespVO detail = convert1(bean); |
| 61 | 63 | if (spu != null) { |
| 62 | 64 | detail.setPicUrl(spu.getPicUrl()); |
| ... | ... | @@ -70,9 +72,11 @@ public interface BargainActivityConvert { |
| 70 | 72 | |
| 71 | 73 | default PageResult<AppBargainActivityRespVO> convertAppPage(PageResult<BargainActivityDO> page, List<ProductSpuRespDTO> spuList) { |
| 72 | 74 | PageResult<AppBargainActivityRespVO> result = convertAppPage(page); |
| 75 | + // 拼接关联属性 | |
| 73 | 76 | Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId); |
| 74 | 77 | List<AppBargainActivityRespVO> list = CollectionUtils.convertList(result.getList(), item -> { |
| 75 | 78 | findAndThen(spuMap, item.getSpuId(), spu -> { |
| 79 | + // TODO @puhui999:这里可以使用链式哈 | |
| 76 | 80 | item.setPicUrl(spu.getPicUrl()); |
| 77 | 81 | item.setMarketPrice(spu.getMarketPrice()); |
| 78 | 82 | }); |
| ... | ... | @@ -89,6 +93,7 @@ public interface BargainActivityConvert { |
| 89 | 93 | Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId); |
| 90 | 94 | return CollectionUtils.convertList(activityList, item -> { |
| 91 | 95 | findAndThen(spuMap, item.getSpuId(), spu -> { |
| 96 | + // TODO @puhui999:这里可以使用链式哈 | |
| 92 | 97 | item.setPicUrl(spu.getPicUrl()); |
| 93 | 98 | item.setMarketPrice(spu.getMarketPrice()); |
| 94 | 99 | }); | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java
| ... | ... | @@ -94,8 +94,10 @@ public interface CombinationActivityConvert { |
| 94 | 94 | |
| 95 | 95 | CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO); |
| 96 | 96 | |
| 97 | - default CombinationRecordDO convert1(CombinationRecordCreateReqDTO reqDTO, CombinationActivityDO activity, MemberUserRespDTO user, | |
| 98 | - ProductSpuRespDTO spu, ProductSkuRespDTO sku) { | |
| 97 | + default CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO, | |
| 98 | + CombinationActivityDO activity, MemberUserRespDTO user, | |
| 99 | + ProductSpuRespDTO spu, ProductSkuRespDTO sku) { | |
| 100 | + // TODO @puhui999:搞成链式的 set;这样会更规整一点; | |
| 99 | 101 | CombinationRecordDO record = convert(reqDTO); |
| 100 | 102 | record.setVirtualGroup(false); |
| 101 | 103 | record.setExpireTime(record.getStartTime().plusHours(activity.getLimitDuration())); | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java
| ... | ... | @@ -98,6 +98,7 @@ public interface SeckillActivityConvert { |
| 98 | 98 | Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId); |
| 99 | 99 | respVO.setActivities(CollectionUtils.convertList(convertList3(activityList), item -> { |
| 100 | 100 | findAndThen(spuMap, item.getSpuId(), spu -> { |
| 101 | + // TODO @puhui999:可以尝试链式 set 哈; | |
| 101 | 102 | item.setPicUrl(spu.getPicUrl()); |
| 102 | 103 | item.setMarketPrice(spu.getMarketPrice()); |
| 103 | 104 | item.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())); |
| ... | ... | @@ -114,6 +115,7 @@ public interface SeckillActivityConvert { |
| 114 | 115 | Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId); |
| 115 | 116 | List<AppSeckillActivityRespVO> list = CollectionUtils.convertList(result.getList(), item -> { |
| 116 | 117 | findAndThen(spuMap, item.getSpuId(), spu -> { |
| 118 | + // TODO @puhui999:可以尝试链式 set 哈; | |
| 117 | 119 | item.setPicUrl(spu.getPicUrl()); |
| 118 | 120 | item.setMarketPrice(spu.getMarketPrice()); |
| 119 | 121 | item.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())); |
| ... | ... | @@ -131,6 +133,7 @@ public interface SeckillActivityConvert { |
| 131 | 133 | default AppSeckillActivityDetailRespVO convert3(SeckillActivityDO seckillActivity, List<SeckillProductDO> products, SeckillConfigDO filteredConfig) { |
| 132 | 134 | AppSeckillActivityDetailRespVO respVO = convert2(seckillActivity); |
| 133 | 135 | respVO.setProducts(convertList1(products)); |
| 136 | + // TODO @puhui999:可以尝试链式 set 哈; | |
| 134 | 137 | respVO.setStartTime(buildTime(filteredConfig.getStartTime())); |
| 135 | 138 | respVO.setEndTime(buildTime(filteredConfig.getEndTime())); |
| 136 | 139 | return respVO; | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java
| ... | ... | @@ -41,7 +41,7 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> { |
| 41 | 41 | default int updateActivityStock(Long id, int count) { |
| 42 | 42 | return update(null, new LambdaUpdateWrapper<BargainActivityDO>() |
| 43 | 43 | .eq(BargainActivityDO::getId, id) |
| 44 | - .gt(BargainActivityDO::getStock, count) | |
| 44 | + .ge(BargainActivityDO::getStock, count) | |
| 45 | 45 | .setSql("stock = stock - " + count)); |
| 46 | 46 | } |
| 47 | 47 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java
| ... | ... | @@ -52,6 +52,7 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> { |
| 52 | 52 | default PageResult<SeckillActivityDO> selectPage(AppSeckillActivityPageReqVO pageReqVO, Integer status) { |
| 53 | 53 | return selectPage(pageReqVO, new LambdaQueryWrapperX<SeckillActivityDO>() |
| 54 | 54 | .eqIfPresent(SeckillActivityDO::getStatus, status) |
| 55 | + // TODO 芋艿:对 find in set 的想法; | |
| 55 | 56 | .apply(ObjectUtil.isNotNull(pageReqVO.getConfigId()), "FIND_IN_SET(" + pageReqVO.getConfigId() + ",config_ids) > 0")); |
| 56 | 57 | } |
| 57 | 58 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java
| ... | ... | @@ -63,19 +63,22 @@ public interface BargainActivityService { |
| 63 | 63 | */ |
| 64 | 64 | PageResult<BargainActivityDO> getBargainActivityPage(BargainActivityPageReqVO pageReqVO); |
| 65 | 65 | |
| 66 | + // TODO @puhui999:这里可以改成进行中的活动;尽量避免专门为 app 定制,或者类似的名字哈;mapper 那也是 | |
| 67 | + | |
| 66 | 68 | /** |
| 67 | 69 | * 获取 APP 端活动分页数据 |
| 68 | 70 | * |
| 69 | 71 | * @param pageReqVO 分页请求 |
| 70 | 72 | * @return 砍价活动分页 |
| 71 | 73 | */ |
| 72 | - PageResult<BargainActivityDO> getBargainActivityAppPage(PageParam pageReqVO); | |
| 74 | + PageResult<BargainActivityDO> getBargainActivityPageForApp(PageParam pageReqVO); | |
| 73 | 75 | |
| 74 | 76 | /** |
| 75 | 77 | * 获取 APP 端活动展示数据 |
| 76 | 78 | * |
| 77 | 79 | * @param count 需要的数量 |
| 78 | - * @return | |
| 80 | + * @return 砍价活动分页 | |
| 79 | 81 | */ |
| 80 | - List<BargainActivityDO> getBargainActivityAppList(Integer count); | |
| 82 | + List<BargainActivityDO> getBargainActivityListForApp(Integer count); | |
| 83 | + | |
| 81 | 84 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java
| ... | ... | @@ -142,18 +142,20 @@ public class BargainActivityServiceImpl implements BargainActivityService { |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | @Override |
| 145 | - public PageResult<BargainActivityDO> getBargainActivityAppPage(PageParam pageReqVO) { | |
| 145 | + public PageResult<BargainActivityDO> getBargainActivityPageForApp(PageParam pageReqVO) { | |
| 146 | 146 | // 只查询进行中,且在时间范围内的 |
| 147 | 147 | return bargainActivityMapper.selectAppPage(pageReqVO, CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now()); |
| 148 | - | |
| 149 | 148 | } |
| 150 | 149 | |
| 151 | 150 | @Override |
| 152 | - public List<BargainActivityDO> getBargainActivityAppList(Integer count) { | |
| 151 | + public List<BargainActivityDO> getBargainActivityListForApp(Integer count) { | |
| 152 | + // TODO @puhui999:这种 default count 的逻辑,可以放到 controller 哈;然后可以使用 ObjectUtils.default 方法 | |
| 153 | 153 | if (count == null) { |
| 154 | 154 | count = 6; |
| 155 | 155 | } |
| 156 | - PageResult<BargainActivityDO> result = bargainActivityMapper.selectAppPage(new PageParam().setPageSize(count), CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now()); | |
| 156 | + // TODO @puhui999:这种不要用 page;会浪费一次 count; | |
| 157 | + PageResult<BargainActivityDO> result = bargainActivityMapper.selectAppPage(new PageParam().setPageSize(count), | |
| 158 | + CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now()); | |
| 157 | 159 | return result.getList(); |
| 158 | 160 | } |
| 159 | 161 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java
| ... | ... | @@ -223,6 +223,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic |
| 223 | 223 | throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE); |
| 224 | 224 | } |
| 225 | 225 | // 1.3 校验是否超出单次限购数量 |
| 226 | + // TODO puhui999:count > activity.getSingleLimitCount() 会更好理解点; | |
| 226 | 227 | if (activity.getSingleLimitCount() < count) { |
| 227 | 228 | throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED); |
| 228 | 229 | } |
| ... | ... | @@ -242,7 +243,6 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic |
| 242 | 243 | if (activity.getTotalLimitCount() < countSum) { |
| 243 | 244 | throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED); |
| 244 | 245 | } |
| 245 | - | |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
| ... | ... | @@ -132,7 +132,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 132 | 132 | MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); |
| 133 | 133 | ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); |
| 134 | 134 | ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); |
| 135 | - recordMapper.insert(CombinationActivityConvert.INSTANCE.convert1(reqDTO, activity, user, spu, sku)); | |
| 135 | + recordMapper.insert(CombinationActivityConvert.INSTANCE.convert(reqDTO, activity, user, spu, sku)); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | @Override | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/TradeBeforeOrderCreateReqBO.java