Commit c8a9d689337bab2a36d9de0919eed9e0863f6db2
1 parent
99649bfd
拼团活动:完善 review 提到的问题
Showing
14 changed files
with
147 additions
and
100 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java
| ... | ... | @@ -25,15 +25,6 @@ public class CollectionUtils { |
| 25 | 25 | return Arrays.stream(collections).anyMatch(CollectionUtil::isEmpty); |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - // TODO @puhui999: list.sort(); 可以替代呀; | |
| 29 | - public static <T, U extends Comparable<? super U>> List<T> sortedAsc( | |
| 30 | - Collection<T> from, Function<? super T, ? extends U> keyExtractor) { | |
| 31 | - // 按照升序排序 | |
| 32 | - return from.stream() | |
| 33 | - .sorted(Comparator.comparing(keyExtractor)) | |
| 34 | - .collect(Collectors.toList()); | |
| 35 | - } | |
| 36 | - | |
| 37 | 28 | public static <T> boolean anyMatch(Collection<T> from, Predicate<T> predicate) { |
| 38 | 29 | return from.stream().anyMatch(predicate); |
| 39 | 30 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateReqDTO.java
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.combination; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.map.MapUtil; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordPageItemRespVO; | |
| 6 | 6 | import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; |
| 7 | -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordRespVO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordSummaryVO; | |
| 8 | 8 | import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; |
| 9 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; | |
| 10 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; | |
| 11 | +import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; | |
| 12 | +import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService; | |
| 9 | 13 | import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; |
| 10 | -import com.google.common.cache.CacheLoader; | |
| 11 | -import com.google.common.cache.LoadingCache; | |
| 12 | 14 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | 15 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 16 | +import org.springframework.context.annotation.Lazy; | |
| 14 | 17 | import org.springframework.security.access.prepost.PreAuthorize; |
| 15 | 18 | import org.springframework.validation.annotation.Validated; |
| 16 | 19 | import org.springframework.web.bind.annotation.GetMapping; |
| ... | ... | @@ -19,11 +22,10 @@ import org.springframework.web.bind.annotation.RestController; |
| 19 | 22 | |
| 20 | 23 | import javax.annotation.Resource; |
| 21 | 24 | import javax.validation.Valid; |
| 22 | -import java.time.Duration; | |
| 23 | -import java.util.Map; | |
| 25 | +import java.util.List; | |
| 24 | 26 | |
| 25 | 27 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 26 | -import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache; | |
| 28 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 27 | 29 | |
| 28 | 30 | @Tag(name = "管理后台 - 拼团记录") |
| 29 | 31 | @RestController |
| ... | ... | @@ -32,44 +34,31 @@ import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsync |
| 32 | 34 | public class CombinationRecordController { |
| 33 | 35 | |
| 34 | 36 | @Resource |
| 37 | + private CombinationActivityService combinationActivityService; | |
| 38 | + @Resource | |
| 39 | + @Lazy | |
| 35 | 40 | private CombinationRecordService combinationRecordService; |
| 36 | 41 | |
| 37 | - // TODO @puhui999:这个缓存不用做哈;主要管理后台,对性能要求不高;不像前段; | |
| 38 | - /** | |
| 39 | - * {@link Map} 缓存,通过它异步刷新 {@link #getCombinationRecordSummary0()} 所要的拼团记录统计数据 | |
| 40 | - */ | |
| 41 | - private final LoadingCache<String, Map<String, Long>> combinationRecordSummary = buildAsyncReloadingCache(Duration.ofSeconds(60L), | |
| 42 | - new CacheLoader<String, Map<String, Long>>() { | |
| 43 | - | |
| 44 | - @Override | |
| 45 | - public Map<String, Long> load(String key) { | |
| 46 | - return getCombinationRecordSummary0(); | |
| 47 | - } | |
| 48 | - | |
| 49 | - }); | |
| 50 | - | |
| 51 | 42 | @GetMapping("/page") |
| 52 | 43 | @Operation(summary = "获得拼团记录分页") |
| 53 | 44 | @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") |
| 54 | - public CommonResult<PageResult<CombinationRecordRespVO>> getBargainRecordPage(@Valid CombinationRecordReqPageVO pageVO) { | |
| 55 | - return success(CombinationActivityConvert.INSTANCE.convert( | |
| 56 | - combinationRecordService.getCombinationRecordPage(pageVO))); | |
| 45 | + public CommonResult<PageResult<CombinationRecordPageItemRespVO>> getBargainRecordPage(@Valid CombinationRecordReqPageVO pageVO) { | |
| 46 | + PageResult<CombinationRecordDO> recordPage = combinationRecordService.getCombinationRecordPage(pageVO); | |
| 47 | + List<CombinationActivityDO> activities = combinationActivityService.getCombinationActivityListByIds( | |
| 48 | + convertSet(recordPage.getList(), CombinationRecordDO::getActivityId)); | |
| 49 | + return success(CombinationActivityConvert.INSTANCE.convert(recordPage, activities)); | |
| 57 | 50 | } |
| 58 | 51 | |
| 59 | - // TODO @puhui999:Map 改成对象,尽量避免 Map 返回结果哈;然后 getCombinationRecordCount、getCombinationRecordsSuccessCount、getRecordsVirtualGroupCount 三个方法,可以合并成一个方法哈,返回这个 vo | |
| 60 | 52 | @GetMapping("/get-summary") |
| 61 | 53 | @Operation(summary = "获得拼团记录的概要信息", description = "用于拼团记录页面展示") |
| 62 | 54 | @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") |
| 63 | - public CommonResult<Map<String, Long>> getCombinationRecordSummary() { | |
| 64 | - return success(combinationRecordSummary.getUnchecked("")); // 缓存 | |
| 65 | - } | |
| 66 | - | |
| 67 | - private Map<String, Long> getCombinationRecordSummary0() { | |
| 68 | - Map<String, Long> hashMap = MapUtil.newHashMap(3); // TODO @puhui999:Maps.newHashMapWithExpectedSize() | |
| 69 | - hashMap.put("userCount", combinationRecordService.getCombinationRecordCount()); // 获取所有拼团记录 | |
| 70 | - hashMap.put("successCount", combinationRecordService.getCombinationRecordsSuccessCount()); // 获取成团记录 | |
| 71 | - hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount()); // 获取虚拟成团记录 | |
| 72 | - return hashMap; | |
| 55 | + public CommonResult<CombinationRecordSummaryVO> getCombinationRecordSummary() { | |
| 56 | + CombinationRecordSummaryVO summaryVO = new CombinationRecordSummaryVO(); | |
| 57 | + summaryVO.setUserCount(combinationRecordService.getCombinationRecordCount(null, null)); // 获取所有拼团记录 | |
| 58 | + summaryVO.setSuccessCount(combinationRecordService.getCombinationRecordCount( | |
| 59 | + CombinationRecordStatusEnum.SUCCESS.getStatus(), null));// 获取成团记录 | |
| 60 | + summaryVO.setVirtualGroupCount(combinationRecordService.getCombinationRecordCount(null, Boolean.TRUE));// 获取虚拟成团记录 | |
| 61 | + return success(summaryVO); | |
| 73 | 62 | } |
| 74 | 63 | |
| 75 | 64 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java renamed to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordBaseVO.java
| ... | ... | @@ -4,14 +4,19 @@ import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.Data; |
| 5 | 5 | import org.springframework.format.annotation.DateTimeFormat; |
| 6 | 6 | |
| 7 | +import javax.validation.constraints.NotNull; | |
| 7 | 8 | import java.time.LocalDateTime; |
| 8 | 9 | |
| 9 | 10 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
| 10 | 11 | |
| 11 | -// TODO @puhui999:可以参考 BargainRecordPageItemRespVO、BargainRecordRespVO 分成两个;一个给记录列表,一个给记录分页 | |
| 12 | -@Schema(description = "管理后台 - 拼团记录 Response VO") | |
| 12 | +/** | |
| 13 | + * 拼团记录 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 14 | + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 15 | + * | |
| 16 | + * @author HUIHUI | |
| 17 | + */ | |
| 13 | 18 | @Data |
| 14 | -public class CombinationRecordRespVO { | |
| 19 | +public class CombinationRecordBaseVO { | |
| 15 | 20 | |
| 16 | 21 | @Schema(description = "拼团记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 17 | 22 | private Long id; |
| ... | ... | @@ -19,14 +24,36 @@ public class CombinationRecordRespVO { |
| 19 | 24 | @Schema(description = "拼团活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 20 | 25 | private Long activityId; |
| 21 | 26 | |
| 22 | - @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "花开富贵") | |
| 27 | + @Schema(description = "团长编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 28 | + private Long headId; | |
| 29 | + | |
| 30 | + // ========== 用户相关 ========== | |
| 31 | + | |
| 32 | + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "9430") | |
| 33 | + @NotNull(message = "用户编号不能为空") | |
| 34 | + private Long userId; | |
| 35 | + | |
| 36 | + @Schema(description = "用户昵称", example = "老芋艿") | |
| 23 | 37 | private String nickname; |
| 24 | 38 | |
| 25 | - @Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 39 | + @Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xxx.jpg") | |
| 26 | 40 | private String avatar; |
| 27 | 41 | |
| 28 | - @Schema(description = "团长编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 29 | - private Long headId; | |
| 42 | + // ========== 商品相关 ========== | |
| 43 | + | |
| 44 | + @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23622") | |
| 45 | + @NotNull(message = "商品 SPU 编号不能为空") | |
| 46 | + private Long spuId; | |
| 47 | + | |
| 48 | + @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "29950") | |
| 49 | + @NotNull(message = "商品 SKU 编号不能为空") | |
| 50 | + private Long skuId; | |
| 51 | + | |
| 52 | + @Schema(description = "商品名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是大黄豆") | |
| 53 | + private String spuName; | |
| 54 | + | |
| 55 | + @Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 56 | + private String picUrl; | |
| 30 | 57 | |
| 31 | 58 | @Schema(description = "过期时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 32 | 59 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
| ... | ... | @@ -41,12 +68,6 @@ public class CombinationRecordRespVO { |
| 41 | 68 | @Schema(description = "拼团状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 42 | 69 | private Integer status; |
| 43 | 70 | |
| 44 | - @Schema(description = "商品名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是大黄豆") | |
| 45 | - private String spuName; | |
| 46 | - | |
| 47 | - @Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 48 | - private String picUrl; | |
| 49 | - | |
| 50 | 71 | @Schema(description = "是否虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "false") |
| 51 | 72 | private Boolean virtualGroup; |
| 52 | 73 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordPageItemRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | + | |
| 9 | +@Schema(description = "管理后台 - 拼团记录的分页项 Response VO") | |
| 10 | +@Data | |
| 11 | +@EqualsAndHashCode(callSuper = true) | |
| 12 | +@ToString(callSuper = true) | |
| 13 | +public class CombinationRecordPageItemRespVO extends CombinationRecordBaseVO { | |
| 14 | + | |
| 15 | + // ========== 活动相关 ========== | |
| 16 | + | |
| 17 | + private CombinationActivityRespVO activity; | |
| 18 | + | |
| 19 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordSummaryVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +@Schema(description = "管理后台 - 拼团记录信息统计 Response VO") | |
| 7 | +@Data | |
| 8 | +public class CombinationRecordSummaryVO { | |
| 9 | + | |
| 10 | + @Schema(description = "所有拼团记录", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 11 | + private Long userCount; | |
| 12 | + | |
| 13 | + @Schema(description = "成团记录", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 14 | + private Long successCount; | |
| 15 | + | |
| 16 | + @Schema(description = "虚拟成团记录", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 17 | + private Long virtualGroupCount; | |
| 18 | + | |
| 19 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java
| ... | ... | @@ -47,7 +47,7 @@ public class AppCombinationRecordController { |
| 47 | 47 | public CommonResult<AppCombinationRecordSummaryRespVO> getCombinationRecordSummary() { |
| 48 | 48 | AppCombinationRecordSummaryRespVO summary = new AppCombinationRecordSummaryRespVO(); |
| 49 | 49 | // 1. 获得拼团记录数量 |
| 50 | - Long count = combinationRecordService.getCombinationRecordCount(); | |
| 50 | + Long count = combinationRecordService.getCombinationRecordCount(null, null); | |
| 51 | 51 | if (count == 0) { |
| 52 | 52 | summary.setAvatars(Collections.emptyList()); |
| 53 | 53 | summary.setUserCount(count); | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java
| ... | ... | @@ -14,7 +14,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activit |
| 14 | 14 | import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; |
| 15 | 15 | import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductBaseVO; |
| 16 | 16 | import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductRespVO; |
| 17 | -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordRespVO; | |
| 17 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordPageItemRespVO; | |
| 18 | 18 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityDetailRespVO; |
| 19 | 19 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityRespVO; |
| 20 | 20 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordDetailRespVO; |
| ... | ... | @@ -79,6 +79,7 @@ public interface CombinationActivityConvert { |
| 79 | 79 | }); |
| 80 | 80 | return pageResult; |
| 81 | 81 | } |
| 82 | + | |
| 82 | 83 | PageResult<CombinationActivityPageItemRespVO> convertPage(PageResult<CombinationActivityDO> page); |
| 83 | 84 | |
| 84 | 85 | List<CombinationProductRespVO> convertList2(List<CombinationProductDO> productDOs); |
| ... | ... | @@ -113,9 +114,8 @@ public interface CombinationActivityConvert { |
| 113 | 114 | CombinationActivityDO activity, MemberUserRespDTO user, |
| 114 | 115 | ProductSpuRespDTO spu, ProductSkuRespDTO sku) { |
| 115 | 116 | return convert(reqDTO) |
| 116 | - .setHeadId(reqDTO.getHeadId()) // 显示性再设置一下 | |
| 117 | 117 | .setCount(reqDTO.getCount()) |
| 118 | - .setVirtualGroup(false) | |
| 118 | + .setVirtualGroup(false) // 默认 false 拼团过期都还没有成功,则按照 CombinationActivityDO#virtualGroup 来如果为 true 则执行虚拟成团的逻辑 | |
| 119 | 119 | .setStatus(CombinationRecordStatusEnum.IN_PROGRESS.getStatus()) // 创建后默认状态为进行中 |
| 120 | 120 | .setStartTime(LocalDateTime.now()) |
| 121 | 121 | .setExpireTime(activity.getStartTime().plusHours(activity.getLimitDuration())) |
| ... | ... | @@ -176,7 +176,20 @@ public interface CombinationActivityConvert { |
| 176 | 176 | |
| 177 | 177 | AppCombinationRecordRespVO convert(CombinationRecordDO record); |
| 178 | 178 | |
| 179 | - PageResult<CombinationRecordRespVO> convert(PageResult<CombinationRecordDO> result); | |
| 179 | + PageResult<CombinationRecordPageItemRespVO> convert(PageResult<CombinationRecordDO> result); | |
| 180 | + | |
| 181 | + default PageResult<CombinationRecordPageItemRespVO> convert(PageResult<CombinationRecordDO> recordPage, List<CombinationActivityDO> activities) { | |
| 182 | + PageResult<CombinationRecordPageItemRespVO> result = convert(recordPage); | |
| 183 | + Map<Long, CombinationActivityDO> activityMap = convertMap(activities, CombinationActivityDO::getId); | |
| 184 | + result.setList(CollectionUtils.convertList(result.getList(), item -> { | |
| 185 | + findAndThen(activityMap, item.getActivityId(), activity -> { | |
| 186 | + item.setActivity(convert(activity)); | |
| 187 | + }); | |
| 188 | + return item; | |
| 189 | + })); | |
| 190 | + return result; | |
| 191 | + } | |
| 192 | + | |
| 180 | 193 | |
| 181 | 194 | default AppCombinationRecordDetailRespVO convert(Long userId, CombinationRecordDO headRecord, List<CombinationRecordDO> memberRecords) { |
| 182 | 195 | AppCombinationRecordDetailRespVO respVO = new AppCombinationRecordDetailRespVO() | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java
| ... | ... | @@ -100,4 +100,12 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO |
| 100 | 100 | .betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime())); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | + default Long selectRecordCount(Integer status, Boolean virtualGroup) { | |
| 104 | + return selectCount(new LambdaQueryWrapperX<CombinationRecordDO>() | |
| 105 | + .eq(status != null || virtualGroup != null, | |
| 106 | + CombinationRecordDO::getHeadId, CombinationRecordDO.HEAD_ID_GROUP) // 统计团信息则指定团长 | |
| 107 | + .eqIfPresent(CombinationRecordDO::getStatus, status) | |
| 108 | + .eqIfPresent(CombinationRecordDO::getVirtualGroup, virtualGroup)); | |
| 109 | + } | |
| 110 | + | |
| 103 | 111 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java
| ... | ... | @@ -85,6 +85,14 @@ public interface CombinationActivityService { |
| 85 | 85 | List<CombinationProductDO> getCombinationProductListByActivityIds(Collection<Long> activityIds); |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | + * 获得拼团活动列表 | |
| 89 | + * | |
| 90 | + * @param ids 拼团活动 ids | |
| 91 | + * @return 拼团活动的列表 | |
| 92 | + */ | |
| 93 | + List<CombinationActivityDO> getCombinationActivityListByIds(Collection<Long> ids); | |
| 94 | + | |
| 95 | + /** | |
| 88 | 96 | * 获取正在进行的活动分页数据 |
| 89 | 97 | * |
| 90 | 98 | * @param count 需要的数量 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java
| ... | ... | @@ -205,6 +205,11 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | @Override |
| 208 | + public List<CombinationActivityDO> getCombinationActivityListByIds(Collection<Long> ids) { | |
| 209 | + return combinationActivityMapper.selectList(CombinationActivityDO::getId, ids); | |
| 210 | + } | |
| 211 | + | |
| 212 | + @Override | |
| 208 | 213 | public List<CombinationActivityDO> getCombinationActivityListByCount(Integer count) { |
| 209 | 214 | return combinationActivityMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus(), count); |
| 210 | 215 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java
| ... | ... | @@ -84,25 +84,13 @@ public interface CombinationRecordService { |
| 84 | 84 | CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count); |
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | - * 获取所有拼团记录数 | |
| 87 | + * 获取拼团记录数 | |
| 88 | 88 | * |
| 89 | + * @param status 状态-允许为空 | |
| 90 | + * @param virtualGroup 是否虚拟成团-允许为空 | |
| 89 | 91 | * @return 记录数 |
| 90 | 92 | */ |
| 91 | - Long getCombinationRecordCount(); | |
| 92 | - | |
| 93 | - /** | |
| 94 | - * 获取成功记录数 | |
| 95 | - * | |
| 96 | - * @return 记录数 | |
| 97 | - */ | |
| 98 | - Long getCombinationRecordsSuccessCount(); | |
| 99 | - | |
| 100 | - /** | |
| 101 | - * 获取虚拟成团记录数 | |
| 102 | - * | |
| 103 | - * @return 记录数 | |
| 104 | - */ | |
| 105 | - Long getRecordsVirtualGroupCount(); | |
| 93 | + Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup); | |
| 106 | 94 | |
| 107 | 95 | /** |
| 108 | 96 | * 获取最近的 count 条拼团记录 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
| ... | ... | @@ -177,8 +177,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 177 | 177 | CombinationRecordDO recordDO = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku); |
| 178 | 178 | recordMapper.insert(recordDO); |
| 179 | 179 | |
| 180 | - // 3、如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP | |
| 181 | - if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, reqDTO.getHeadId())) { | |
| 180 | + // 3、如果是团长(CombinationRecordCreateReqDTO#headId 为 null 时)需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP | |
| 181 | + if (reqDTO.getHeadId() == null) { | |
| 182 | 182 | recordMapper.updateById(new CombinationRecordDO().setId(recordDO.getId()).setHeadId(CombinationRecordDO.HEAD_ID_GROUP)); |
| 183 | 183 | return; |
| 184 | 184 | } |
| ... | ... | @@ -256,20 +256,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | @Override |
| 259 | - public Long getCombinationRecordCount() { | |
| 260 | - return recordMapper.selectCount(); | |
| 261 | - } | |
| 262 | - | |
| 263 | - @Override | |
| 264 | - public Long getCombinationRecordsSuccessCount() { | |
| 265 | - // TODO @puhui999:这个应该要多查询 headId | |
| 266 | - return recordMapper.selectCount(CombinationRecordDO::getStatus, CombinationRecordStatusEnum.SUCCESS.getStatus()); | |
| 267 | - } | |
| 268 | - | |
| 269 | - @Override | |
| 270 | - public Long getRecordsVirtualGroupCount() { | |
| 271 | - // TODO @puhui999:这个应该要多查询 headId;然后,recordMapper 要明确的查询哈,不要直接使用 mapper 来拼接查询条件 | |
| 272 | - return recordMapper.selectCount(CombinationRecordDO::getVirtualGroup, true); | |
| 259 | + public Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup) { | |
| 260 | + return recordMapper.selectRecordCount(status, virtualGroup); | |
| 273 | 261 | } |
| 274 | 262 | |
| 275 | 263 | @Override |
| ... | ... | @@ -325,9 +313,9 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 325 | 313 | return; |
| 326 | 314 | } |
| 327 | 315 | // 按照创建时间升序排序 |
| 328 | - List<CombinationRecordDO> recordsSort = sortedAsc(list, CombinationRecordDO::getCreateTime); | |
| 329 | - CombinationRecordDO newHead = recordsSort.get(0); // 新团长继位 | |
| 330 | - recordsSort.forEach(item -> { | |
| 316 | + list.sort(Comparator.comparing(CombinationRecordDO::getCreateTime)); // 影响原 list | |
| 317 | + CombinationRecordDO newHead = list.get(0); // 新团长继位 | |
| 318 | + list.forEach(item -> { | |
| 331 | 319 | CombinationRecordDO recordDO = new CombinationRecordDO(); |
| 332 | 320 | recordDO.setId(item.getId()); |
| 333 | 321 | if (ObjUtil.equal(item.getId(), newHead.getId())) { // 新团长 |
| ... | ... | @@ -335,7 +323,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 335 | 323 | } else { |
| 336 | 324 | recordDO.setHeadId(newHead.getId()); |
| 337 | 325 | } |
| 338 | - recordDO.setUserCount(recordsSort.size()); | |
| 326 | + recordDO.setUserCount(list.size()); | |
| 339 | 327 | updateRecords.add(recordDO); |
| 340 | 328 | }); |
| 341 | 329 | } else { // 情况二:团员 | ... | ... |