diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java index 4b42aca07..2274d45fd 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.promotion.api.combination; -import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; import javax.validation.Valid; @@ -28,9 +28,9 @@ public interface CombinationRecordApi { * 创建开团记录 * * @param reqDTO 请求 DTO - * @return key 开团记录编号、value 团长编号 + * @return 团信息 */ - KeyValue createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO); + CombinationRecordCreateRespDTO createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO); /** * 查询拼团记录是否成功 diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateRespDTO.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateRespDTO.java new file mode 100644 index 000000000..5f4ea2afd --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateRespDTO.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.promotion.api.combination.dto; + +import lombok.Data; + +/** + * 拼团记录的创建 Response DTO + * + * @author HUIHUI + */ +@Data +public class CombinationRecordCreateRespDTO { + + /** + * 拼团活动编号 + * + * 关联 CombinationActivityDO 的 id 字段 + */ + private Long combinationActivityId; + /** + * 拼团团长编号 + * + * 关联 CombinationRecordDO 的 headId 字段 + */ + private Long combinationHeadId; + /** + * 拼团记录编号 + * + * 关联 CombinationRecordDO 的 id 字段 + */ + private Long combinationRecordId; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java index 5588f3735..5f586dd7d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java @@ -1,8 +1,9 @@ package cn.iocoder.yudao.module.promotion.api.combination; -import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; +import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; @@ -29,10 +30,9 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { recordService.validateCombinationRecord(userId, activityId, headId, skuId, count); } - // TODO @puhui999:搞个创建的 RespDTO 哈; @Override - public KeyValue createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { - return recordService.createCombinationRecord(reqDTO); + public CombinationRecordCreateRespDTO createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { + return CombinationActivityConvert.INSTANCE.convert4(recordService.createCombinationRecord(reqDTO)); } @Override 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 8f2b3fe99..dfb8ec889 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 @@ -3,11 +3,11 @@ package cn.iocoder.yudao.module.promotion.controller.admin.combination; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordPageItemRespVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPage2VO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordSummaryVO; import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService; @@ -40,7 +40,6 @@ public class CombinationRecordController { @Lazy private CombinationRecordService combinationRecordService; - // TODO @puhui999:getBargainRecordPage 和 getBargainRecordPage 是不是可以合并;然后 CombinationRecordReqPageVO 加一个 headId; // 然后如果 headId 非空,并且第一页,单独多查询一条 head ;放到第 0 个位置;相当于说,第一页特殊一点; @GetMapping("/page") @@ -48,21 +47,12 @@ public class CombinationRecordController { @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") public CommonResult> getBargainRecordPage(@Valid CombinationRecordReqPageVO pageVO) { PageResult recordPage = combinationRecordService.getCombinationRecordPage(pageVO); + // 拼接数据 List activities = combinationActivityService.getCombinationActivityListByIds( convertSet(recordPage.getList(), CombinationRecordDO::getActivityId)); - // TODO @puhui999:商品没读取 - return success(CombinationActivityConvert.INSTANCE.convert(recordPage, activities)); - } - - @GetMapping("/page-by-headId") - @Operation(summary = "获得拼团记录分页") - @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") - public CommonResult> getBargainRecordPage(@Valid CombinationRecordReqPage2VO pageVO) { - // 包含团长和团员的分页记录 - PageResult recordPage = combinationRecordService.getCombinationRecordPage2(pageVO); - List activities = combinationActivityService.getCombinationActivityListByIds( + List products = combinationActivityService.getCombinationProductListByActivityIds( convertSet(recordPage.getList(), CombinationRecordDO::getActivityId)); - return success(CombinationActivityConvert.INSTANCE.convert(recordPage, activities)); + return success(CombinationActivityConvert.INSTANCE.convert(recordPage, activities, products)); } @GetMapping("/get-summary") @@ -70,7 +60,7 @@ public class CombinationRecordController { @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") public CommonResult getCombinationRecordSummary() { CombinationRecordSummaryVO summaryVO = new CombinationRecordSummaryVO(); - summaryVO.setUserCount(combinationRecordService.getCombinationRecordCount(null, null, null)); // 获取拼团用户参与数量 + summaryVO.setUserCount(combinationRecordService.getCombinationUserCount()); // 获取拼团用户参与数量 summaryVO.setSuccessCount(combinationRecordService.getCombinationRecordCount( // 获取成团记录 CombinationRecordStatusEnum.SUCCESS.getStatus(), null, CombinationRecordDO.HEAD_ID_GROUP)); summaryVO.setVirtualGroupCount(combinationRecordService.getCombinationRecordCount(// 获取虚拟成团记录 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java index 9e1423a41..a66795d64 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java @@ -23,6 +23,9 @@ public class CombinationRecordReqPageVO extends PageParam { @InEnum(BargainRecordStatusEnum.class) private Integer status; + @Schema(description = "团长编号", example = "1024") + private Long headId; + @Schema(description = "创建时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] createTime; 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 684c7ce9b..e242569ac 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 @@ -47,7 +47,7 @@ public class AppCombinationRecordController { public CommonResult getCombinationRecordSummary() { AppCombinationRecordSummaryRespVO summary = new AppCombinationRecordSummaryRespVO(); // 1. 获得拼团参与用户数量 - Long count = combinationRecordService.getCombinationRecordCount(null, null, null); + Long count = combinationRecordService.getCombinationUserCount(); if (count == 0) { summary.setAvatars(Collections.emptyList()); summary.setUserCount(count); 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 03cac269f..aad8281d6 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 @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageItemRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO; @@ -109,6 +110,11 @@ public interface CombinationActivityConvert { CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO); + default CombinationRecordCreateRespDTO convert4(CombinationRecordDO combinationRecord) { + return new CombinationRecordCreateRespDTO().setCombinationActivityId(combinationRecord.getActivityId()) + .setCombinationRecordId(combinationRecord.getId()).setCombinationHeadId(combinationRecord.getHeadId()); + } + default CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO, CombinationActivityDO activity, MemberUserRespDTO user, ProductSpuRespDTO spu, ProductSkuRespDTO sku) { @@ -172,12 +178,14 @@ public interface CombinationActivityConvert { PageResult convert(PageResult result); - default PageResult convert(PageResult recordPage, List activities) { + default PageResult convert(PageResult recordPage, List activities, List products) { PageResult result = convert(recordPage); + // 拼接关联属性 Map activityMap = convertMap(activities, CombinationActivityDO::getId); + Map> productsMap = convertMultiMap(products, CombinationProductDO::getActivityId); result.setList(CollectionUtils.convertList(result.getList(), item -> { findAndThen(activityMap, item.getActivityId(), activity -> { - item.setActivity(convert(activity)); + item.setActivity(convert(activity).setProducts(convertList2(productsMap.get(item.getActivityId())))); }); return item; })); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java index 0d4b85cd3..1015d1413 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java @@ -86,7 +86,7 @@ public interface BargainActivityMapper extends BaseMapperX { .last("LIMIT " + count)); } - // TODO @puhui999:是不是返回 BargainActivityDO 更干净哈? + // TODO @puhui999:是不是返回 BargainActivityDO 更干净哈?分组后返回 DO 的话需要联表查询 /** * 查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 * 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 5d85c8938..56ec0361a 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 @@ -6,7 +6,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPage2VO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -97,21 +96,19 @@ public interface CombinationRecordMapper extends BaseMapperX selectPage(CombinationRecordReqPageVO pageVO) { - return selectPage(pageVO, new LambdaQueryWrapperX() + LambdaQueryWrapperX queryWrapper = new LambdaQueryWrapperX() .eqIfPresent(CombinationRecordDO::getStatus, pageVO.getStatus()) - .betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime())); - } - - default PageResult selectPage(CombinationRecordReqPage2VO pageVO) { - return selectPage(pageVO, new LambdaQueryWrapperX() - .eq(CombinationRecordDO::getId, pageVO.getHeadId()) - .or() - .eq(CombinationRecordDO::getHeadId, pageVO.getHeadId())); + .betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime()); + if (pageVO.getHeadId() != null) { + queryWrapper.eq(CombinationRecordDO::getId, pageVO.getHeadId()) + .or() + .eq(CombinationRecordDO::getHeadId, pageVO.getHeadId()); + } + return selectPage(pageVO, queryWrapper); } /** * 查询指定条件的记录数 - * 如果参数都为 null 时则查询用户拼团记录(DISTINCT 去重),也就是说查询会员表中的用户有多少人参与过拼团活动每个人只统计一次 * * @param status 状态,可为 null * @param virtualGroup 是否虚拟成团,可为 null @@ -119,12 +116,20 @@ public interface CombinationRecordMapper extends BaseMapperX() + .eqIfPresent(CombinationRecordDO::getStatus, status) + .eqIfPresent(CombinationRecordDO::getVirtualGroup, virtualGroup) + .eqIfPresent(CombinationRecordDO::getHeadId, headId)); + } + + /** + * 查询用户拼团记录(DISTINCT 去重),也就是说查询会员表中的用户有多少人参与过拼团活动每个人只统计一次 + * + * @return 参加过拼团的用户数 + */ + default Long selectUserDistinctCount() { return selectCount(new QueryWrapper() - // TODO @puhui999:这种偏逻辑性的,不要给 mapper 哈;可以考虑拆成 2 个 mapper,上层也是 2 个 service; - .select(status == null && virtualGroup == null && headId == null, "DISTINCT (user_id)") - .eq(status != null, "status", status) - .eq(virtualGroup != null, "virtual_group", virtualGroup) - .eq(headId != null, "head_id", headId) + .select("DISTINCT (user_id)") .groupBy("user_id")); } 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 e6200c4d0..5e6770061 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 @@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPage2VO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; @@ -50,9 +49,9 @@ public interface CombinationRecordService { * 创建拼团记录 * * @param reqDTO 创建信息 - * @return key 开团记录编号 value 团长编号 + * @return 团信息 */ - KeyValue createCombinationRecord(CombinationRecordCreateReqDTO reqDTO); + CombinationRecordDO createCombinationRecord(CombinationRecordCreateReqDTO reqDTO); /** * 获得拼团记录 @@ -94,7 +93,14 @@ public interface CombinationRecordService { * @param headId 团长编号,允许空。目的 headId 设置为 {@link CombinationRecordDO#HEAD_ID_GROUP} 时,可以设置 * @return 记录数 */ - Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup, @Nullable Long headId); + Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup, Long headId); + + /** + * 查询用户拼团记录(DISTINCT 去重),也就是说查询会员表中的用户有多少人参与过拼团活动每个人只统计一次 + * + * @return 参加过拼团的用户数 + */ + Long getCombinationUserCount(); /** * 获取最近的 count 条拼团记录 @@ -138,14 +144,6 @@ public interface CombinationRecordService { */ PageResult getCombinationRecordPage(CombinationRecordReqPageVO pageVO); - /** - * 获取拼团记录分页数据(通过团长查询) - * - * @param pageVO 分页请求 - * @return 拼团记录分页数据(包括团长的) - */ - PageResult getCombinationRecordPage2(CombinationRecordReqPage2VO pageVO); - /** * 【拼团活动】获得拼团记录数量 Map * 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 17b8a6ef4..82baf1931 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 @@ -14,7 +14,6 @@ import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPage2VO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; @@ -23,7 +22,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationR import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationRecordMapper; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -72,9 +70,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { CombinationRecordDO record = validateCombinationRecord(userId, orderId); // 更新状态 - // TODO @puhui999:不要整个更新,new 一个出来;why?例如说,两个线程都去更新,这样存在相互覆盖的问题 - record.setStatus(status); - combinationRecordMapper.updateById(record); + combinationRecordMapper.updateById(new CombinationRecordDO().setId(record.getId()).setStatus(status)); } private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) { @@ -164,7 +160,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Override @Transactional(rollbackFor = Exception.class) - public KeyValue createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { + public CombinationRecordDO createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { // 1. 校验拼团活动 KeyValue keyValue = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getActivityId(), reqDTO.getHeadId(), reqDTO.getSkuId(), reqDTO.getCount()); @@ -191,7 +187,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { if (ObjUtil.notEqual(CombinationRecordDO.HEAD_ID_GROUP, record.getHeadId())) { updateCombinationRecordWhenCreate(reqDTO.getHeadId(), keyValue.getKey()); } - return new KeyValue<>(record.getId(), record.getHeadId()); + return record; } /** @@ -249,6 +245,11 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return combinationRecordMapper.selectCountByHeadAndStatusAndVirtualGroup(status, virtualGroup, headId); } + @Override + public Long getCombinationUserCount() { + return combinationRecordMapper.selectUserDistinctCount(); + } + @Override public List getLatestCombinationRecordList(int count) { return combinationRecordMapper.selectLatestList(count); @@ -275,11 +276,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return combinationRecordMapper.selectPage(pageVO); } - @Override - public PageResult getCombinationRecordPage2(CombinationRecordReqPage2VO pageVO) { - return combinationRecordMapper.selectPage(pageVO); - } - @Override public Map getCombinationRecordCountMapByActivity(Collection activityIds, @Nullable Integer status, @Nullable Long headId) { @@ -343,32 +339,28 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Override public KeyValue expireCombinationRecord() { - // TODO @puhui999:数字一般是 1. 2. 这种格式哈 - // 1。获取所有正在进行中的过期的父拼团 + // 1.获取所有正在进行中的过期的父拼团 List headExpireRecords = combinationRecordMapper.selectListByHeadIdAndStatusAndExpireTimeLt( CombinationRecordDO.HEAD_ID_GROUP, CombinationRecordStatusEnum.IN_PROGRESS.getStatus(), LocalDateTime.now()); if (CollUtil.isEmpty(headExpireRecords)) { return new KeyValue<>(0, 0); } - // 2. 获取拼团活动 - // TODO @puhui999:在自己模块里,变量可以简略点;例如说 activityList - List combinationActivities = combinationActivityService.getCombinationActivityListByIds( + // 2.获取拼团活动 + List activities = combinationActivityService.getCombinationActivityListByIds( convertSet(headExpireRecords, CombinationRecordDO::getActivityId)); - Map activityMap = convertMap(combinationActivities, CombinationActivityDO::getId); + Map activityMap = convertMap(activities, CombinationActivityDO::getId); - // TODO @puhui999:job 一般不建议异步跑;因为可能下次跑,结果上次还没跑完; - // TODO 这里,我们可以每个 record 处理下;然后按照是否需要虚拟拼团,各搞一个方法逻辑 + 事务;这样,保证 job 里面尽量不要大事务,而是 n 个独立小事务的处理。 - // 3. 校验是否虚拟成团 + // 3.校验是否虚拟成团 List virtualGroupHeadRecords = new ArrayList<>(); // 虚拟成团 for (Iterator iterator = headExpireRecords.iterator(); iterator.hasNext(); ) { CombinationRecordDO record = iterator.next(); - // 3.1 不匹配,则直接跳过 + // 3.1.不匹配,则直接跳过 CombinationActivityDO activity = activityMap.get(record.getActivityId()); if (activity == null || !activity.getVirtualGroup()) { // 取不到活动的或者不是虚拟拼团的 continue; } - // 3.2 匹配,则移除,添加到虚拟成团中,并结束寻找 + // 3.2.匹配,则移除,添加到虚拟成团中,并结束寻找 virtualGroupHeadRecords.add(record); iterator.remove(); break; @@ -381,8 +373,13 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return new KeyValue<>(headExpireRecords.size(), virtualGroupHeadRecords.size()); } - @Async - protected void handleExpireRecord(List headExpireRecords) { + /** + * 处理过期拼团 + * + * @param headExpireRecords 过期拼团团长记录列表 + */ + @Transactional(rollbackFor = Exception.class) + public void handleExpireRecord(List headExpireRecords) { if (CollUtil.isEmpty(headExpireRecords)) { return; } @@ -400,8 +397,13 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { }); } - @Async - protected void handleVirtualGroupRecord(List virtualGroupHeadRecords) { + /** + * 处理虚拟拼团 + * + * @param virtualGroupHeadRecords 虚拟成团团长记录列表 + */ + @Transactional(rollbackFor = Exception.class) + public void handleVirtualGroupRecord(List virtualGroupHeadRecords) { if (CollUtil.isEmpty(virtualGroupHeadRecords)) { return; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java index d1b3dc2f8..d942fd853 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java @@ -93,16 +93,19 @@ public interface TradeOrderMapper extends BaseMapperX { return selectOne(TradeOrderDO::getPickUpVerifyCode, pickUpVerifyCode); } - // TODO @hui999:是不是只针对 combinationActivityId 的查询呀? + /** + * 只针对 combinationActivityId 的查询 + * + * @param userId 用户编号 + * @param activityId 拼团活动编号 + * @param status 订单状态 + * @return 交易订单 + */ default TradeOrderDO selectByUserIdAndActivityIdAndStatus(Long userId, Long activityId, Integer status) { return selectOne(new LambdaQueryWrapperX() - .and(q -> q.eq(TradeOrderDO::getUserId, userId) - .eq(TradeOrderDO::getStatus, status)) - .and(q -> q.eq(TradeOrderDO::getCombinationActivityId, activityId) - .or() - .eq(TradeOrderDO::getSeckillActivityId, activityId) - .or() - .eq(TradeOrderDO::getBargainActivityId, activityId)) + .eq(TradeOrderDO::getUserId, userId) + .eq(TradeOrderDO::getStatus, status) + .eq(TradeOrderDO::getCombinationActivityId, activityId) ); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationOrderHandler.java index 9d32190fb..7efdc1650 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationOrderHandler.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.module.trade.service.order.handler; import cn.hutool.core.lang.Assert; -import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateRespDTO; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; @@ -49,7 +49,6 @@ public class TradeCombinationOrderHandler implements TradeOrderHandler { order.getCombinationHeadId(), item.getSkuId(), item.getCount()); // 2. 校验该用户是否存在未支付的拼团活动订单,避免一个拼团可以下多个单子了 - // TODO @puhui999:只校验未支付的拼团订单噢 TradeOrderDO activityOrder = orderQueryService.getActivityOrderByUserIdAndActivityIdAndStatus( order.getUserId(), order.getCombinationActivityId(), TradeOrderStatusEnum.UNPAID.getStatus()); if (activityOrder != null) { @@ -67,13 +66,14 @@ public class TradeCombinationOrderHandler implements TradeOrderHandler { // 2. 创建拼团记录 TradeOrderItemDO item = orderItems.get(0); - KeyValue recordIdAndHeadId = combinationRecordApi.createCombinationRecord( + CombinationRecordCreateRespDTO combinationRecord = combinationRecordApi.createCombinationRecord( TradeOrderConvert.INSTANCE.convert(order, item)); // 3. 更新拼团相关信息到订单 - // TODO 芋艿,只需要更新 record + // TODO 芋艿,只需要更新 record。 如果创建订单时自己是团长的情况下 combinationHeadId 是为 null 的, + // 设置团长编号这个操作时在订单是否后创建拼团记录时才设置的,所以支付完创建拼团记录后需要设置一下记录编号和团长编号 orderUpdateService.updateOrderCombinationInfo(order.getId(), order.getCombinationActivityId(), - recordIdAndHeadId.getKey(), recordIdAndHeadId.getValue()); + combinationRecord.getCombinationRecordId(), combinationRecord.getCombinationHeadId()); } @Override