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 280809626..ded52759c 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 @@ -1,8 +1,6 @@ package cn.iocoder.yudao.module.promotion.controller.app.combination; -import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordDetailRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordSummaryRespVO; @@ -23,6 +21,7 @@ import javax.annotation.Resource; import javax.validation.constraints.Max; import java.util.Collections; import java.util.List; +import java.util.Objects; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; @@ -61,7 +60,7 @@ public class AppCombinationRecordController { @Operation(summary = "获得最近 n 条拼团记录(团长发起的)") @Parameters({ @Parameter(name = "activityId", description = "拼团活动编号"), - @Parameter(name = "status", description = "状态"), + @Parameter(name = "status", description = "拼团状态"), // 对应 CombinationRecordStatusEnum 枚举 @Parameter(name = "count", description = "数量") }) public CommonResult> getHeadCombinationRecordList( @@ -69,44 +68,37 @@ public class AppCombinationRecordController { @RequestParam("status") Integer status, @RequestParam(value = "count", defaultValue = "20") @Max(20) Integer count) { return success(CombinationActivityConvert.INSTANCE.convertList3( - combinationRecordService.getCombinationRecordListWithHead(activityId, status, count))); + combinationRecordService.getHeadCombinationRecordList(activityId, status, count))); } @GetMapping("/get-detail") @Operation(summary = "获得拼团记录明细") @Parameter(name = "id", description = "拼团记录编号", required = true, example = "1024") public CommonResult getCombinationRecordDetail(@RequestParam("id") Long id) { - // 1、查询这条记录 + // 1. 查找这条拼团记录 CombinationRecordDO record = combinationRecordService.getCombinationRecordById(id); if (record == null) { return success(null); } - AppCombinationRecordDetailRespVO detail = new AppCombinationRecordDetailRespVO(); - List records; - // 2、判断是否为团长 - if (record.getHeadId() == null) { - detail.setHeadRecord(CombinationActivityConvert.INSTANCE.convert(record)); - // 2.1、查找团员拼团记录 - records = combinationRecordService.getCombinationRecordListByHeadId(record.getId()); - } else { - // 2.2、查找团长拼团记录 - CombinationRecordDO headRecord = combinationRecordService.getCombinationRecordById(record.getHeadId()); - if (headRecord == null) { - return success(null); - } - - detail.setHeadRecord(CombinationActivityConvert.INSTANCE.convert(headRecord)); - // 2.3、查找团员拼团记录 - records = combinationRecordService.getCombinationRecordListByHeadId(headRecord.getId()); - + // 2. 查找该拼团的参团记录 + CombinationRecordDO headRecord; + List memberRecords; + if (Objects.equals(record.getHeadId(), CombinationRecordDO.HEAD_ID_GROUP)) { // 情况一:团长 + headRecord = record; + memberRecords = combinationRecordService.getCombinationRecordListByHeadId(record.getId()); + } else { // 情况二:团员 + headRecord = combinationRecordService.getCombinationRecordById(record.getHeadId()); + memberRecords = combinationRecordService.getCombinationRecordListByHeadId(headRecord.getId()); } - detail.setMemberRecords(CombinationActivityConvert.INSTANCE.convertList3(records)); - // 3、获取当前用户参团记录订单编号 - CombinationRecordDO userRecord = CollectionUtils.findFirst(records, r -> ObjectUtil.equal(r.getUserId(), getLoginUserId())); - detail.setOrderId(userRecord == null ? null : userRecord.getOrderId()); // 如果没参团,返回 null - return success(detail); + // 3. 拼接数据 + return success(CombinationActivityConvert.INSTANCE.convert(getLoginUserId(), headRecord, memberRecords)); } + // TODO @puhui:新增一个取消拼团的接口,cancel + // 1. 需要先校验拼团记录未完成; + // 2. 在 Order 那增加一个 cancelPaidOrder 接口,用于取消已支付的订单 + // 3. order 完成后,取消拼团记录。另外,如果它是团长,则顺序(下单时间)继承 + } 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 7a410f702..6b1316e71 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 @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.convert.combination; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.MapUtils; @@ -16,6 +17,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityDetailRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityRespVO; +import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordDetailRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordRespVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; @@ -168,4 +170,16 @@ public interface CombinationActivityConvert { PageResult convert(PageResult result); + default AppCombinationRecordDetailRespVO convert(Long userId, CombinationRecordDO headRecord, List memberRecords) { + AppCombinationRecordDetailRespVO respVO = new AppCombinationRecordDetailRespVO() + .setHeadRecord(convert(headRecord)).setMemberRecords(convertList3(memberRecords)); + // 处理自己参与拼团的 orderId + CombinationRecordDO userRecord = CollectionUtils.findFirst(memberRecords, r -> ObjectUtil.equal(r.getUserId(), userId)); + if (userRecord == null && ObjectUtil.equal(headRecord.getUserId(), userId)) { + userRecord = headRecord; + } + respVO.setOrderId(userRecord == null ? null : userRecord.getOrderId()); + return respVO; + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java index faf65a2c6..07d40d1e5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java @@ -31,7 +31,7 @@ public class CombinationRecordDO extends BaseDO { /** * 团长编号 - 团长 */ - public static final Integer HEAD_ID_GROUP = 0; + public static final Long HEAD_ID_GROUP = 0L; /** * 编号,主键自增 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 163b5eef0..494b89974 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 @@ -81,25 +81,18 @@ public interface CombinationRecordMapper extends BaseMapperX selectList(Long activityId, Integer status, Integer count) { + default List selectListByActivityIdAndStatusAndHeadId(Long activityId, Integer status, + Long headId, Integer count) { return selectList(new LambdaQueryWrapperX() - .eqIfPresent(CombinationRecordDO::getActivityId, activityId) - .eqIfPresent(CombinationRecordDO::getStatus, status) - .eq(CombinationRecordDO::getHeadId, null) // TODO 团长的 headId 是不是 null 还是自己的记录编号来着? - .orderByDesc(CombinationRecordDO::getCreateTime) + .eq(CombinationRecordDO::getActivityId, activityId) + .eq(CombinationRecordDO::getStatus, status) + .eq(CombinationRecordDO::getHeadId, headId) + .orderByDesc(CombinationRecordDO::getId) .last("LIMIT " + count)); } default Map selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(Collection activityIds, - Integer status, Integer headId) { + Integer status, Long headId) { // SQL count 查询 List> result = selectMaps(new QueryWrapper() .select("COUNT(DISTINCT(user_id)) AS recordCount, activity_id AS activityId") 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 68f218d59..80408560b 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 @@ -139,7 +139,7 @@ public interface CombinationRecordService { * @param count 数量 * @return 拼团记录列表 */ - List getCombinationRecordListWithHead(Long activityId, Integer status, Integer count); + List getHeadCombinationRecordList(Long activityId, Integer status, Integer count); /** * 获取指定编号的拼团记录 @@ -175,6 +175,6 @@ public interface CombinationRecordService { */ Map getCombinationRecordCountMapByActivity(Collection activityIds, @Nullable Integer status, - @Nullable Integer headId); + @Nullable Long headId); } 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 25445d4b2..6a9a53a80 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 @@ -216,6 +216,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); recordMapper.insert(CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku)); + // TODO @puhui999:status 未设置;headId 未设置 + recordMapper.insert(CombinationActivityConvert.INSTANCE.convert(reqDTO, activity, user, spu, sku)); } @Override @@ -263,8 +265,9 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } @Override - public List getCombinationRecordListWithHead(Long activityId, Integer status, Integer count) { - return recordMapper.selectList(activityId, status, count); + public List getHeadCombinationRecordList(Long activityId, Integer status, Integer count) { + return recordMapper.selectListByActivityIdAndStatusAndHeadId(activityId, status, + CombinationRecordDO.HEAD_ID_GROUP, count); } @Override @@ -284,7 +287,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Override public Map getCombinationRecordCountMapByActivity(Collection activityIds, - @Nullable Integer status, @Nullable Integer headId) { + @Nullable Integer status, @Nullable Long headId) { return recordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId); }