diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java index 3383ec879..d70c21626 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java @@ -56,7 +56,7 @@ public interface BaseMapperX extends MPJBaseMapper { } default Long selectCount() { - return selectCount(new QueryWrapper()); + return selectCount(new QueryWrapper<>()); } default Long selectCount(String field, Object value) { diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java index 631670e98..e7086518f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java @@ -74,7 +74,7 @@ public class CombinationActivityController { @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") public CommonResult getCombinationActivity(@RequestParam("id") Long id) { CombinationActivityDO activity = combinationActivityService.getCombinationActivity(id); - List products = combinationActivityService.getCombinationProductsByActivityIds(newArrayList(id)); + List products = combinationActivityService.getCombinationProductListByActivityIds(newArrayList(id)); return success(CombinationActivityConvert.INSTANCE.convert(activity, products)); } @@ -98,7 +98,7 @@ public class CombinationActivityController { Map recordCountMap = combinationRecordService.getCombinationRecordCountMapByActivity( activityIds, null, null); // 拼接数据 - List products = combinationActivityService.getCombinationProductsByActivityIds( + List products = combinationActivityService.getCombinationProductListByActivityIds( convertSet(pageResult.getList(), CombinationActivityDO::getId)); List spus = productSpuApi.getSpuList( convertSet(pageResult.getList(), CombinationActivityDO::getSpuId)); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java index d8a3b5245..1e6b3954c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java @@ -78,7 +78,7 @@ public class CombinationRecordController { private Map getCombinationRecordSummary0() { Map hashMap = MapUtil.newHashMap(3); - hashMap.put("userCount", combinationRecordService.getCombinationRecordsCount());// 获取所有拼团记录 + hashMap.put("userCount", combinationRecordService.getCombinationRecordCount());// 获取所有拼团记录 hashMap.put("successCount", combinationRecordService.getCombinationRecordsSuccessCount());// 获取成团记录 hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount());// 获取虚拟成团记录 return hashMap; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java index 55e2ee7ac..6534c4efc 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java @@ -30,7 +30,6 @@ import java.time.Duration; import java.util.Collections; import java.util.List; -import static cn.hutool.core.util.ObjectUtil.defaultIfNull; 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; @@ -56,6 +55,7 @@ public class AppCombinationActivityController { @Resource private CombinationActivityService activityService; + @Resource private ProductSpuApi spuApi; @@ -68,40 +68,45 @@ public class AppCombinationActivityController { } private List getCombinationActivityList0(Integer count) { - List list = activityService.getCombinationActivityListByCount(defaultIfNull(count, 6)); - if (CollUtil.isEmpty(list)) { + List activityList = activityService.getCombinationActivityListByCount(count); + if (CollUtil.isEmpty(activityList)) { return Collections.emptyList(); } // 拼接返回 - List spuList = spuApi.getSpuList(convertList(list, CombinationActivityDO::getSpuId)); - return CombinationActivityConvert.INSTANCE.convertAppList(list, spuList); + List productList = activityService.getCombinationProductListByActivityIds( + convertList(activityList, CombinationActivityDO::getId)); + List spuList = spuApi.getSpuList(convertList(activityList, CombinationActivityDO::getSpuId)); + return CombinationActivityConvert.INSTANCE.convertAppList(activityList, productList, spuList); } @GetMapping("/page") @Operation(summary = "获得拼团活动分页") public CommonResult> getCombinationActivityPage(PageParam pageParam) { - PageResult result = activityService.getCombinationActivityPage(pageParam); - if (CollUtil.isEmpty(result.getList())) { - return success(PageResult.empty(result.getTotal())); + PageResult pageResult = activityService.getCombinationActivityPage(pageParam); + if (CollUtil.isEmpty(pageResult.getList())) { + return success(PageResult.empty(pageResult.getTotal())); } // 拼接返回 - List spuList = spuApi.getSpuList(convertList(result.getList(), CombinationActivityDO::getSpuId)); - return success(CombinationActivityConvert.INSTANCE.convertAppPage(result, spuList)); + List productList = activityService.getCombinationProductListByActivityIds( + convertList(pageResult.getList(), CombinationActivityDO::getId)); + List spuList = spuApi.getSpuList(convertList(pageResult.getList(), CombinationActivityDO::getSpuId)); + return success(CombinationActivityConvert.INSTANCE.convertAppPage(pageResult, productList, spuList)); } @GetMapping("/get-detail") @Operation(summary = "获得拼团活动明细") @Parameter(name = "id", description = "活动编号", required = true, example = "1024") public CommonResult getCombinationActivityDetail(@RequestParam("id") Long id) { - // 1、获取活动 - CombinationActivityDO combinationActivity = activityService.getCombinationActivity(id); - if (combinationActivity == null - || ObjectUtil.equal(combinationActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { + // 1. 获取活动 + CombinationActivityDO activity = activityService.getCombinationActivity(id); + if (activity == null + || ObjectUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { return success(null); } - // 2、获取活动商品 - List products = activityService.getCombinationProductsByActivityId(combinationActivity.getId()); - return success(CombinationActivityConvert.INSTANCE.convert3(combinationActivity, products)); + + // 2. 获取活动商品 + List products = activityService.getCombinationProductsByActivityId(activity.getId()); + return success(CombinationActivityConvert.INSTANCE.convert3(activity, products)); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java index 2d4b813ff..280809626 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java @@ -39,21 +39,21 @@ public class AppCombinationRecordController { @GetMapping("/get-summary") @Operation(summary = "获得拼团记录的概要信息", description = "用于小程序首页") - // TODO 芋艿:增加 @Cache 缓存,1 分钟过期 public CommonResult getCombinationRecordSummary() { - // 获取所有拼团记录 - Long count = combinationRecordService.getCombinationRecordsCount(); AppCombinationRecordSummaryRespVO summary = new AppCombinationRecordSummaryRespVO(); - if (count == null || count == 0L) { + // 1. 获得拼团记录数量 + Long count = combinationRecordService.getCombinationRecordCount(); + if (count == 0) { summary.setAvatars(Collections.emptyList()); summary.setUserCount(count); return success(summary); } - summary.setUserCount(count); - // TODO 只返回最近的 7 个 - int num = 7; - summary.setAvatars(convertList(combinationRecordService.getLatestCombinationRecordList(num), CombinationRecordDO::getAvatar)); + + // 2. 获得拼团记录头像 + List records = combinationRecordService.getLatestCombinationRecordList( + AppCombinationRecordSummaryRespVO.AVATAR_COUNT); + summary.setAvatars(convertList(records, CombinationRecordDO::getAvatar)); return success(summary); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSummaryRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSummaryRespVO.java index 5c79f9f73..d9ea03d6f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSummaryRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSummaryRespVO.java @@ -9,6 +9,11 @@ import java.util.List; @Data public class AppCombinationRecordSummaryRespVO { + /** + * 加载 {@link #avatars} 的数量 + */ + public static final Integer AVATAR_COUNT = 7; + @Schema(description = "拼团用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long userCount; 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 5c85a6ff8..1b4945334 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 @@ -86,7 +86,8 @@ public class AppSeckillActivityController { // 2.1 查询满足当前阶段的活动 List activityList = activityService.getSeckillActivityListByConfigIdAndStatus(config.getId(), CommonStatusEnum.ENABLE.getStatus()); - List productList = activityService.getSeckillProductListByActivityId(convertList(activityList, SeckillActivityDO::getId)); + List productList = activityService.getSeckillProductListByActivityId( + convertList(activityList, SeckillActivityDO::getId)); // 2.2 获取 spu 信息 List spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId)); return SeckillActivityConvert.INSTANCE.convert(config, activityList, productList, spuList); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java index 4a70a63a9..73abb53b4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java @@ -28,7 +28,7 @@ import org.mapstruct.factory.Mappers; import java.util.List; import java.util.Map; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; /** @@ -120,10 +120,16 @@ public interface CombinationActivityConvert { List convertAppList(List list); - default List convertAppList(List list, List spuList) { + default List convertAppList(List list, + List productList, + List spuList) { List activityList = convertAppList(list); Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); + Map> productMap = convertMultiMap(productList, CombinationProductDO::getActivityId); return CollectionUtils.convertList(activityList, item -> { + // 设置 product 信息 + item.setCombinationPrice(getMinValue(productMap.get(item.getId()), CombinationProductDO::getCombinationPrice)); + // 设置 SPU 信息 findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice())); return item; }); @@ -131,13 +137,17 @@ public interface CombinationActivityConvert { PageResult convertAppPage(PageResult result); - default PageResult convertAppPage(PageResult result, List spuList) { + default PageResult convertAppPage(PageResult result, + List productList, + List spuList) { PageResult appPage = convertAppPage(result); Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); + Map> productMap = convertMultiMap(productList, CombinationProductDO::getActivityId); List list = CollectionUtils.convertList(appPage.getList(), item -> { - findAndThen(spuMap, item.getSpuId(), spu -> { - item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()); - }); + // 设置 product 信息 + item.setCombinationPrice(getMinValue(productMap.get(item.getId()), CombinationProductDO::getCombinationPrice)); + // 设置 SPU 信息 + findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice())); return item; }); appPage.setList(list); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java index 54f998d44..691044dc9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java @@ -77,7 +77,7 @@ public interface CombinationRecordMapper extends BaseMapperX selectLatestList(int count) { return selectList(new LambdaQueryWrapperX() - .orderByDesc(CombinationRecordDO::getCreateTime) + .orderByDesc(CombinationRecordDO::getId) .last("LIMIT " + count)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java index d55be29fe..adb6cb21a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java @@ -73,7 +73,7 @@ public interface CombinationActivityService { * @return 拼团活动的商品列表 */ default List getCombinationProductsByActivityId(Long activityId) { - return getCombinationProductsByActivityIds(Collections.singletonList(activityId)); + return getCombinationProductListByActivityIds(Collections.singletonList(activityId)); } /** @@ -82,7 +82,7 @@ public interface CombinationActivityService { * @param activityIds 拼团活动 ids * @return 拼团活动的商品列表 */ - List getCombinationProductsByActivityIds(Collection activityIds); + List getCombinationProductListByActivityIds(Collection activityIds); /** * 获取正在进行的活动分页数据 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index db0f1ff66..1f62b307a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -200,7 +200,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic } @Override - public List getCombinationProductsByActivityIds(Collection activityIds) { + public List getCombinationProductListByActivityIds(Collection activityIds) { return combinationProductMapper.selectListByActivityIds(activityIds); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java index ca651ce1a..43372f674 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java @@ -96,7 +96,7 @@ public interface CombinationRecordService { * * @return 记录数 */ - Long getCombinationRecordsCount(); + Long getCombinationRecordCount(); /** * 获取成功记录数 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index d6b9f84d7..6566c7ce2 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -227,7 +227,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } @Override - public Long getCombinationRecordsCount() { + public Long getCombinationRecordCount() { return recordMapper.selectCount(); }