Commit ec2c3e508a21dd28e8eb724a44b39b47809845c4
1 parent
c7b5df93
promotion:优化拼团记录的详情代码
Showing
6 changed files
with
49 additions
and
48 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java
| 1 | package cn.iocoder.yudao.module.promotion.controller.app.combination; | 1 | package cn.iocoder.yudao.module.promotion.controller.app.combination; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.util.ObjectUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 6 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordDetailRespVO; | 4 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordDetailRespVO; |
| 7 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordRespVO; | 5 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordRespVO; |
| 8 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordSummaryRespVO; | 6 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordSummaryRespVO; |
| @@ -23,6 +21,7 @@ import javax.annotation.Resource; | @@ -23,6 +21,7 @@ import javax.annotation.Resource; | ||
| 23 | import javax.validation.constraints.Max; | 21 | import javax.validation.constraints.Max; |
| 24 | import java.util.Collections; | 22 | import java.util.Collections; |
| 25 | import java.util.List; | 23 | import java.util.List; |
| 24 | +import java.util.Objects; | ||
| 26 | 25 | ||
| 27 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 26 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 28 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | 27 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| @@ -61,7 +60,7 @@ public class AppCombinationRecordController { | @@ -61,7 +60,7 @@ public class AppCombinationRecordController { | ||
| 61 | @Operation(summary = "获得最近 n 条拼团记录(团长发起的)") | 60 | @Operation(summary = "获得最近 n 条拼团记录(团长发起的)") |
| 62 | @Parameters({ | 61 | @Parameters({ |
| 63 | @Parameter(name = "activityId", description = "拼团活动编号"), | 62 | @Parameter(name = "activityId", description = "拼团活动编号"), |
| 64 | - @Parameter(name = "status", description = "状态"), | 63 | + @Parameter(name = "status", description = "拼团状态"), // 对应 CombinationRecordStatusEnum 枚举 |
| 65 | @Parameter(name = "count", description = "数量") | 64 | @Parameter(name = "count", description = "数量") |
| 66 | }) | 65 | }) |
| 67 | public CommonResult<List<AppCombinationRecordRespVO>> getHeadCombinationRecordList( | 66 | public CommonResult<List<AppCombinationRecordRespVO>> getHeadCombinationRecordList( |
| @@ -69,44 +68,37 @@ public class AppCombinationRecordController { | @@ -69,44 +68,37 @@ public class AppCombinationRecordController { | ||
| 69 | @RequestParam("status") Integer status, | 68 | @RequestParam("status") Integer status, |
| 70 | @RequestParam(value = "count", defaultValue = "20") @Max(20) Integer count) { | 69 | @RequestParam(value = "count", defaultValue = "20") @Max(20) Integer count) { |
| 71 | return success(CombinationActivityConvert.INSTANCE.convertList3( | 70 | return success(CombinationActivityConvert.INSTANCE.convertList3( |
| 72 | - combinationRecordService.getCombinationRecordListWithHead(activityId, status, count))); | 71 | + combinationRecordService.getHeadCombinationRecordList(activityId, status, count))); |
| 73 | } | 72 | } |
| 74 | 73 | ||
| 75 | @GetMapping("/get-detail") | 74 | @GetMapping("/get-detail") |
| 76 | @Operation(summary = "获得拼团记录明细") | 75 | @Operation(summary = "获得拼团记录明细") |
| 77 | @Parameter(name = "id", description = "拼团记录编号", required = true, example = "1024") | 76 | @Parameter(name = "id", description = "拼团记录编号", required = true, example = "1024") |
| 78 | public CommonResult<AppCombinationRecordDetailRespVO> getCombinationRecordDetail(@RequestParam("id") Long id) { | 77 | public CommonResult<AppCombinationRecordDetailRespVO> getCombinationRecordDetail(@RequestParam("id") Long id) { |
| 79 | - // 1、查询这条记录 | 78 | + // 1. 查找这条拼团记录 |
| 80 | CombinationRecordDO record = combinationRecordService.getCombinationRecordById(id); | 79 | CombinationRecordDO record = combinationRecordService.getCombinationRecordById(id); |
| 81 | if (record == null) { | 80 | if (record == null) { |
| 82 | return success(null); | 81 | return success(null); |
| 83 | } | 82 | } |
| 84 | 83 | ||
| 85 | - AppCombinationRecordDetailRespVO detail = new AppCombinationRecordDetailRespVO(); | ||
| 86 | - List<CombinationRecordDO> records; | ||
| 87 | - // 2、判断是否为团长 | ||
| 88 | - if (record.getHeadId() == null) { | ||
| 89 | - detail.setHeadRecord(CombinationActivityConvert.INSTANCE.convert(record)); | ||
| 90 | - // 2.1、查找团员拼团记录 | ||
| 91 | - records = combinationRecordService.getCombinationRecordListByHeadId(record.getId()); | ||
| 92 | - } else { | ||
| 93 | - // 2.2、查找团长拼团记录 | ||
| 94 | - CombinationRecordDO headRecord = combinationRecordService.getCombinationRecordById(record.getHeadId()); | ||
| 95 | - if (headRecord == null) { | ||
| 96 | - return success(null); | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | - detail.setHeadRecord(CombinationActivityConvert.INSTANCE.convert(headRecord)); | ||
| 100 | - // 2.3、查找团员拼团记录 | ||
| 101 | - records = combinationRecordService.getCombinationRecordListByHeadId(headRecord.getId()); | ||
| 102 | - | 84 | + // 2. 查找该拼团的参团记录 |
| 85 | + CombinationRecordDO headRecord; | ||
| 86 | + List<CombinationRecordDO> memberRecords; | ||
| 87 | + if (Objects.equals(record.getHeadId(), CombinationRecordDO.HEAD_ID_GROUP)) { // 情况一:团长 | ||
| 88 | + headRecord = record; | ||
| 89 | + memberRecords = combinationRecordService.getCombinationRecordListByHeadId(record.getId()); | ||
| 90 | + } else { // 情况二:团员 | ||
| 91 | + headRecord = combinationRecordService.getCombinationRecordById(record.getHeadId()); | ||
| 92 | + memberRecords = combinationRecordService.getCombinationRecordListByHeadId(headRecord.getId()); | ||
| 103 | } | 93 | } |
| 104 | - detail.setMemberRecords(CombinationActivityConvert.INSTANCE.convertList3(records)); | ||
| 105 | 94 | ||
| 106 | - // 3、获取当前用户参团记录订单编号 | ||
| 107 | - CombinationRecordDO userRecord = CollectionUtils.findFirst(records, r -> ObjectUtil.equal(r.getUserId(), getLoginUserId())); | ||
| 108 | - detail.setOrderId(userRecord == null ? null : userRecord.getOrderId()); // 如果没参团,返回 null | ||
| 109 | - return success(detail); | 95 | + // 3. 拼接数据 |
| 96 | + return success(CombinationActivityConvert.INSTANCE.convert(getLoginUserId(), headRecord, memberRecords)); | ||
| 110 | } | 97 | } |
| 111 | 98 | ||
| 99 | + // TODO @puhui:新增一个取消拼团的接口,cancel | ||
| 100 | + // 1. 需要先校验拼团记录未完成; | ||
| 101 | + // 2. 在 Order 那增加一个 cancelPaidOrder 接口,用于取消已支付的订单 | ||
| 102 | + // 3. order 完成后,取消拼团记录。另外,如果它是团长,则顺序(下单时间)继承 | ||
| 103 | + | ||
| 112 | } | 104 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java
| 1 | package cn.iocoder.yudao.module.promotion.convert.combination; | 1 | package cn.iocoder.yudao.module.promotion.convert.combination; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.util.ObjectUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 5 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | 6 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| @@ -16,6 +17,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product | @@ -16,6 +17,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product | ||
| 16 | import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordRespVO; | 17 | import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordRespVO; |
| 17 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityDetailRespVO; | 18 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityDetailRespVO; |
| 18 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityRespVO; | 19 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityRespVO; |
| 20 | +import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordDetailRespVO; | ||
| 19 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordRespVO; | 21 | import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordRespVO; |
| 20 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; | 22 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; |
| 21 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; | 23 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; |
| @@ -168,4 +170,16 @@ public interface CombinationActivityConvert { | @@ -168,4 +170,16 @@ public interface CombinationActivityConvert { | ||
| 168 | 170 | ||
| 169 | PageResult<CombinationRecordRespVO> convert(PageResult<CombinationRecordDO> result); | 171 | PageResult<CombinationRecordRespVO> convert(PageResult<CombinationRecordDO> result); |
| 170 | 172 | ||
| 173 | + default AppCombinationRecordDetailRespVO convert(Long userId, CombinationRecordDO headRecord, List<CombinationRecordDO> memberRecords) { | ||
| 174 | + AppCombinationRecordDetailRespVO respVO = new AppCombinationRecordDetailRespVO() | ||
| 175 | + .setHeadRecord(convert(headRecord)).setMemberRecords(convertList3(memberRecords)); | ||
| 176 | + // 处理自己参与拼团的 orderId | ||
| 177 | + CombinationRecordDO userRecord = CollectionUtils.findFirst(memberRecords, r -> ObjectUtil.equal(r.getUserId(), userId)); | ||
| 178 | + if (userRecord == null && ObjectUtil.equal(headRecord.getUserId(), userId)) { | ||
| 179 | + userRecord = headRecord; | ||
| 180 | + } | ||
| 181 | + respVO.setOrderId(userRecord == null ? null : userRecord.getOrderId()); | ||
| 182 | + return respVO; | ||
| 183 | + } | ||
| 184 | + | ||
| 171 | } | 185 | } |
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 { | @@ -31,7 +31,7 @@ public class CombinationRecordDO extends BaseDO { | ||
| 31 | /** | 31 | /** |
| 32 | * 团长编号 - 团长 | 32 | * 团长编号 - 团长 |
| 33 | */ | 33 | */ |
| 34 | - public static final Integer HEAD_ID_GROUP = 0; | 34 | + public static final Long HEAD_ID_GROUP = 0L; |
| 35 | 35 | ||
| 36 | /** | 36 | /** |
| 37 | * 编号,主键自增 | 37 | * 编号,主键自增 |
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<CombinationRecordDO | @@ -81,25 +81,18 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO | ||
| 81 | .last("LIMIT " + count)); | 81 | .last("LIMIT " + count)); |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | - /** | ||
| 85 | - * 获得最近 count 条拼团记录(团长发起的) | ||
| 86 | - * | ||
| 87 | - * @param activityId 拼团活动编号 | ||
| 88 | - * @param status 记录状态 | ||
| 89 | - * @param count 数量 | ||
| 90 | - * @return 拼团记录列表 | ||
| 91 | - */ | ||
| 92 | - default List<CombinationRecordDO> selectList(Long activityId, Integer status, Integer count) { | 84 | + default List<CombinationRecordDO> selectListByActivityIdAndStatusAndHeadId(Long activityId, Integer status, |
| 85 | + Long headId, Integer count) { | ||
| 93 | return selectList(new LambdaQueryWrapperX<CombinationRecordDO>() | 86 | return selectList(new LambdaQueryWrapperX<CombinationRecordDO>() |
| 94 | - .eqIfPresent(CombinationRecordDO::getActivityId, activityId) | ||
| 95 | - .eqIfPresent(CombinationRecordDO::getStatus, status) | ||
| 96 | - .eq(CombinationRecordDO::getHeadId, null) // TODO 团长的 headId 是不是 null 还是自己的记录编号来着? | ||
| 97 | - .orderByDesc(CombinationRecordDO::getCreateTime) | 87 | + .eq(CombinationRecordDO::getActivityId, activityId) |
| 88 | + .eq(CombinationRecordDO::getStatus, status) | ||
| 89 | + .eq(CombinationRecordDO::getHeadId, headId) | ||
| 90 | + .orderByDesc(CombinationRecordDO::getId) | ||
| 98 | .last("LIMIT " + count)); | 91 | .last("LIMIT " + count)); |
| 99 | } | 92 | } |
| 100 | 93 | ||
| 101 | default Map<Long, Integer> selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(Collection<Long> activityIds, | 94 | default Map<Long, Integer> selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(Collection<Long> activityIds, |
| 102 | - Integer status, Integer headId) { | 95 | + Integer status, Long headId) { |
| 103 | // SQL count 查询 | 96 | // SQL count 查询 |
| 104 | List<Map<String, Object>> result = selectMaps(new QueryWrapper<CombinationRecordDO>() | 97 | List<Map<String, Object>> result = selectMaps(new QueryWrapper<CombinationRecordDO>() |
| 105 | .select("COUNT(DISTINCT(user_id)) AS recordCount, activity_id AS activityId") | 98 | .select("COUNT(DISTINCT(user_id)) AS recordCount, activity_id AS activityId") |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java
| @@ -136,7 +136,7 @@ public interface CombinationRecordService { | @@ -136,7 +136,7 @@ public interface CombinationRecordService { | ||
| 136 | * @param count 数量 | 136 | * @param count 数量 |
| 137 | * @return 拼团记录列表 | 137 | * @return 拼团记录列表 |
| 138 | */ | 138 | */ |
| 139 | - List<CombinationRecordDO> getCombinationRecordListWithHead(Long activityId, Integer status, Integer count); | 139 | + List<CombinationRecordDO> getHeadCombinationRecordList(Long activityId, Integer status, Integer count); |
| 140 | 140 | ||
| 141 | /** | 141 | /** |
| 142 | * 获取指定编号的拼团记录 | 142 | * 获取指定编号的拼团记录 |
| @@ -172,6 +172,6 @@ public interface CombinationRecordService { | @@ -172,6 +172,6 @@ public interface CombinationRecordService { | ||
| 172 | */ | 172 | */ |
| 173 | Map<Long, Integer> getCombinationRecordCountMapByActivity(Collection<Long> activityIds, | 173 | Map<Long, Integer> getCombinationRecordCountMapByActivity(Collection<Long> activityIds, |
| 174 | @Nullable Integer status, | 174 | @Nullable Integer status, |
| 175 | - @Nullable Integer headId); | 175 | + @Nullable Long headId); |
| 176 | 176 | ||
| 177 | } | 177 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
| @@ -204,6 +204,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -204,6 +204,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 204 | MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); | 204 | MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); |
| 205 | ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); | 205 | ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); |
| 206 | ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); | 206 | ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); |
| 207 | + // TODO @puhui999:status 未设置;headId 未设置 | ||
| 207 | recordMapper.insert(CombinationActivityConvert.INSTANCE.convert(reqDTO, activity, user, spu, sku)); | 208 | recordMapper.insert(CombinationActivityConvert.INSTANCE.convert(reqDTO, activity, user, spu, sku)); |
| 208 | } | 209 | } |
| 209 | 210 | ||
| @@ -253,8 +254,9 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -253,8 +254,9 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 253 | } | 254 | } |
| 254 | 255 | ||
| 255 | @Override | 256 | @Override |
| 256 | - public List<CombinationRecordDO> getCombinationRecordListWithHead(Long activityId, Integer status, Integer count) { | ||
| 257 | - return recordMapper.selectList(activityId, status, count); | 257 | + public List<CombinationRecordDO> getHeadCombinationRecordList(Long activityId, Integer status, Integer count) { |
| 258 | + return recordMapper.selectListByActivityIdAndStatusAndHeadId(activityId, status, | ||
| 259 | + CombinationRecordDO.HEAD_ID_GROUP, count); | ||
| 258 | } | 260 | } |
| 259 | 261 | ||
| 260 | @Override | 262 | @Override |
| @@ -274,7 +276,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -274,7 +276,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 274 | 276 | ||
| 275 | @Override | 277 | @Override |
| 276 | public Map<Long, Integer> getCombinationRecordCountMapByActivity(Collection<Long> activityIds, | 278 | public Map<Long, Integer> getCombinationRecordCountMapByActivity(Collection<Long> activityIds, |
| 277 | - @Nullable Integer status, @Nullable Integer headId) { | 279 | + @Nullable Integer status, @Nullable Long headId) { |
| 278 | return recordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId); | 280 | return recordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId); |
| 279 | } | 281 | } |
| 280 | 282 |