Commit 5e2fa48f203bd258b0ee5a00d24d0be719ef7673
1 parent
7a7ae3b8
code review:拼团、秒杀活动的代码
Showing
24 changed files
with
149 additions
and
108 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java
| @@ -27,6 +27,7 @@ public class CollectionUtils { | @@ -27,6 +27,7 @@ public class CollectionUtils { | ||
| 27 | return Arrays.stream(collections).anyMatch(CollectionUtil::isEmpty); | 27 | return Arrays.stream(collections).anyMatch(CollectionUtil::isEmpty); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | + // TODO @puhui999:anyMatch 更统一点 | ||
| 30 | public static <T> boolean isAny(Collection<T> from, Predicate<T> predicate) { | 31 | public static <T> boolean isAny(Collection<T> from, Predicate<T> predicate) { |
| 31 | return from.stream().anyMatch(predicate); | 32 | return from.stream().anyMatch(predicate); |
| 32 | } | 33 | } |
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java
| @@ -84,11 +84,11 @@ public class LocalDateTimeUtils { | @@ -84,11 +84,11 @@ public class LocalDateTimeUtils { | ||
| 84 | 84 | ||
| 85 | public static boolean isOverlap(LocalTime startTime1, LocalTime endTime1, LocalTime startTime2, LocalTime endTime2) { | 85 | public static boolean isOverlap(LocalTime startTime1, LocalTime endTime1, LocalTime startTime2, LocalTime endTime2) { |
| 86 | // 日期部分使用了当前日期LocalDate.now() | 86 | // 日期部分使用了当前日期LocalDate.now() |
| 87 | + // TODO @puhui999:LocalDate.now() 抽一个变量,啊哈;然后注释写下;之后 4 个变量不用,直接调方法的时候,直接计算作为入参; | ||
| 87 | LocalDateTime startDateTime1 = LocalDateTime.of(LocalDate.now(), startTime1); | 88 | LocalDateTime startDateTime1 = LocalDateTime.of(LocalDate.now(), startTime1); |
| 88 | LocalDateTime endDateTime1 = LocalDateTime.of(LocalDate.now(), endTime1); | 89 | LocalDateTime endDateTime1 = LocalDateTime.of(LocalDate.now(), endTime1); |
| 89 | LocalDateTime startDateTime2 = LocalDateTime.of(LocalDate.now(), startTime2); | 90 | LocalDateTime startDateTime2 = LocalDateTime.of(LocalDate.now(), startTime2); |
| 90 | LocalDateTime endDateTime2 = LocalDateTime.of(LocalDate.now(), endTime2); | 91 | LocalDateTime endDateTime2 = LocalDateTime.of(LocalDate.now(), endTime2); |
| 91 | - | ||
| 92 | return LocalDateTimeUtil.isOverlap(startDateTime1, endDateTime1, startDateTime2, endDateTime2); | 92 | return LocalDateTimeUtil.isOverlap(startDateTime1, endDateTime1, startDateTime2, endDateTime2); |
| 93 | } | 93 | } |
| 94 | 94 |
yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java
| @@ -44,6 +44,12 @@ public interface BaseMapperX<T> extends BaseMapper<T> { | @@ -44,6 +44,12 @@ public interface BaseMapperX<T> extends BaseMapper<T> { | ||
| 44 | return selectOne(new LambdaQueryWrapper<T>().eq(field1, value1).eq(field2, value2)); | 44 | return selectOne(new LambdaQueryWrapper<T>().eq(field1, value1).eq(field2, value2)); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | + default T selectOne(SFunction<T, ?> field1, Object value1, SFunction<T, ?> field2, Object value2, | ||
| 48 | + SFunction<T, ?> field3, Object value3) { | ||
| 49 | + return selectOne(new LambdaQueryWrapper<T>().eq(field1, value1).eq(field2, value2) | ||
| 50 | + .eq(field3, value3)); | ||
| 51 | + } | ||
| 52 | + | ||
| 47 | default Long selectCount() { | 53 | default Long selectCount() { |
| 48 | return selectCount(new QueryWrapper<T>()); | 54 | return selectCount(new QueryWrapper<T>()); |
| 49 | } | 55 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java
| 1 | package cn.iocoder.yudao.module.product.controller.app.comment; | 1 | package cn.iocoder.yudao.module.product.controller.app.comment; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 6 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; | 6 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; |
| 7 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; | 7 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; |
| 8 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; | 8 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; |
| @@ -27,6 +27,7 @@ import java.util.List; | @@ -27,6 +27,7 @@ import java.util.List; | ||
| 27 | import java.util.Set; | 27 | import java.util.Set; |
| 28 | 28 | ||
| 29 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 29 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 30 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||
| 30 | 31 | ||
| 31 | @Tag(name = "用户 APP - 商品评价") | 32 | @Tag(name = "用户 APP - 商品评价") |
| 32 | @RestController | 33 | @RestController |
| @@ -56,10 +57,17 @@ public class AppProductCommentController { | @@ -56,10 +57,17 @@ public class AppProductCommentController { | ||
| 56 | @GetMapping("/page") | 57 | @GetMapping("/page") |
| 57 | @Operation(summary = "获得商品评价分页") | 58 | @Operation(summary = "获得商品评价分页") |
| 58 | public CommonResult<PageResult<AppProductCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) { | 59 | public CommonResult<PageResult<AppProductCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) { |
| 59 | - PageResult<ProductCommentDO> commentDOPage = productCommentService.getCommentPage(pageVO, Boolean.TRUE); | ||
| 60 | - Set<Long> skuIds = CollectionUtils.convertSet(commentDOPage.getList(), ProductCommentDO::getSkuId); | ||
| 61 | - PageResult<AppProductCommentRespVO> page = ProductCommentConvert.INSTANCE.convertPage02(commentDOPage, productSkuService.getSkuList(skuIds)); | ||
| 62 | - return success(page); | 60 | + // 查询评论分页 |
| 61 | + PageResult<ProductCommentDO> commentPageResult = productCommentService.getCommentPage(pageVO, Boolean.TRUE); | ||
| 62 | + if (CollUtil.isEmpty(commentPageResult.getList())) { | ||
| 63 | + return success(PageResult.empty(commentPageResult.getTotal())); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + // 拼接返回 | ||
| 67 | + Set<Long> skuIds = convertSet(commentPageResult.getList(), ProductCommentDO::getSkuId); | ||
| 68 | + PageResult<AppProductCommentRespVO> commentVOPageResult = ProductCommentConvert.INSTANCE.convertPage02( | ||
| 69 | + commentPageResult, productSkuService.getSkuList(skuIds)); | ||
| 70 | + return success(commentVOPageResult); | ||
| 63 | } | 71 | } |
| 64 | 72 | ||
| 65 | // TODO 芋艿:需要搞下 | 73 | // TODO 芋艿:需要搞下 |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java
| 1 | package cn.iocoder.yudao.module.product.convert.comment; | 1 | package cn.iocoder.yudao.module.product.convert.comment; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.collection.CollUtil; | ||
| 4 | import cn.hutool.core.util.ObjectUtil; | 3 | import cn.hutool.core.util.ObjectUtil; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| @@ -15,7 +14,6 @@ import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProdu | @@ -15,7 +14,6 @@ import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProdu | ||
| 15 | import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; | 14 | import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; |
| 16 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | 15 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| 17 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; | 16 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| 18 | -import com.google.common.collect.Maps; | ||
| 19 | import org.mapstruct.Mapper; | 17 | import org.mapstruct.Mapper; |
| 20 | import org.mapstruct.Mapping; | 18 | import org.mapstruct.Mapping; |
| 21 | import org.mapstruct.Named; | 19 | import org.mapstruct.Named; |
| @@ -52,17 +50,16 @@ public interface ProductCommentConvert { | @@ -52,17 +50,16 @@ public interface ProductCommentConvert { | ||
| 52 | 50 | ||
| 53 | PageResult<AppProductCommentRespVO> convertPage01(PageResult<ProductCommentDO> pageResult); | 51 | PageResult<AppProductCommentRespVO> convertPage01(PageResult<ProductCommentDO> pageResult); |
| 54 | 52 | ||
| 55 | - default PageResult<AppProductCommentRespVO> convertPage02(PageResult<ProductCommentDO> pageResult, List<ProductSkuDO> skuList) { | ||
| 56 | - Map<Long, ProductSkuDO> skuMap = Maps.newLinkedHashMapWithExpectedSize(skuList.size()); | ||
| 57 | - if (CollUtil.isNotEmpty(skuList)) { | ||
| 58 | - skuMap.putAll(CollectionUtils.convertMap(skuList, ProductSkuDO::getId)); | ||
| 59 | - } | 53 | + default PageResult<AppProductCommentRespVO> convertPage02(PageResult<ProductCommentDO> pageResult, |
| 54 | + List<ProductSkuDO> skuList) { | ||
| 55 | + Map<Long, ProductSkuDO> skuMap = CollectionUtils.convertMap(skuList, ProductSkuDO::getId); | ||
| 60 | PageResult<AppProductCommentRespVO> page = convertPage01(pageResult); | 56 | PageResult<AppProductCommentRespVO> page = convertPage01(pageResult); |
| 61 | page.getList().forEach(item -> { | 57 | page.getList().forEach(item -> { |
| 62 | // 判断用户是否选择匿名 | 58 | // 判断用户是否选择匿名 |
| 63 | if (ObjectUtil.equal(item.getAnonymous(), true)) { | 59 | if (ObjectUtil.equal(item.getAnonymous(), true)) { |
| 64 | item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS); | 60 | item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS); |
| 65 | } | 61 | } |
| 62 | + // 设置 SKU 规格值 | ||
| 66 | MapUtils.findAndThen(skuMap, item.getSkuId(), | 63 | MapUtils.findAndThen(skuMap, item.getSkuId(), |
| 67 | sku -> item.setSkuProperties(convertList01(sku.getProperties()))); | 64 | sku -> item.setSkuProperties(convertList01(sku.getProperties()))); |
| 68 | }); | 65 | }); |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java
| @@ -112,10 +112,9 @@ public interface ProductSpuConvert { | @@ -112,10 +112,9 @@ public interface ProductSpuConvert { | ||
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | default List<ProductSpuDetailRespVO> convertForSpuDetailRespListVO(List<ProductSpuDO> spus, List<ProductSkuDO> skus) { | 114 | default List<ProductSpuDetailRespVO> convertForSpuDetailRespListVO(List<ProductSpuDO> spus, List<ProductSkuDO> skus) { |
| 115 | - List<ProductSpuDetailRespVO> vos = new ArrayList<>(spus.size()); | ||
| 116 | Map<Long, List<ProductSkuDO>> skuMultiMap = convertMultiMap(skus, ProductSkuDO::getSpuId); | 115 | Map<Long, List<ProductSkuDO>> skuMultiMap = convertMultiMap(skus, ProductSkuDO::getSpuId); |
| 117 | - CollectionUtils.convertList(spus, spu -> vos.add(convert03(spu).setSkus(ProductSkuConvert.INSTANCE.convertList(skuMultiMap.get(spu.getId()))))); | ||
| 118 | - return vos; | 116 | + return CollectionUtils.convertList(spus, spu -> convert03(spu) |
| 117 | + .setSkus(ProductSkuConvert.INSTANCE.convertList(skuMultiMap.get(spu.getId())))); | ||
| 119 | } | 118 | } |
| 120 | 119 | ||
| 121 | } | 120 | } |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java
| @@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.promotion.api.combination; | @@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.promotion.api.combination; | ||
| 3 | import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; | 3 | import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; |
| 4 | 4 | ||
| 5 | import javax.validation.Valid; | 5 | import javax.validation.Valid; |
| 6 | -// TODO @芋艿:后面也再撸撸这几个接口 | ||
| 7 | 6 | ||
| 7 | +// TODO @芋艿:后面也再撸撸这几个接口 | ||
| 8 | /** | 8 | /** |
| 9 | * 拼团记录 API 接口 | 9 | * 拼团记录 API 接口 |
| 10 | * | 10 | * |
| @@ -17,17 +17,18 @@ public interface CombinationRecordApi { | @@ -17,17 +17,18 @@ public interface CombinationRecordApi { | ||
| 17 | * | 17 | * |
| 18 | * @param reqDTO 请求 DTO | 18 | * @param reqDTO 请求 DTO |
| 19 | */ | 19 | */ |
| 20 | - void createRecord(@Valid CombinationRecordCreateReqDTO reqDTO); | 20 | + void createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO); |
| 21 | 21 | ||
| 22 | /** | 22 | /** |
| 23 | - * 校验拼团是否成功 | 23 | + * 查询拼团记录是否成功 |
| 24 | * | 24 | * |
| 25 | * @param userId 用户编号 | 25 | * @param userId 用户编号 |
| 26 | * @param orderId 订单编号 | 26 | * @param orderId 订单编号 |
| 27 | * @return 拼团是否成功 | 27 | * @return 拼团是否成功 |
| 28 | */ | 28 | */ |
| 29 | - boolean validateRecordStatusIsSuccess(Long userId, Long orderId); | 29 | + boolean isCombinationRecordSuccess(Long userId, Long orderId); |
| 30 | 30 | ||
| 31 | + // TODO @puhui999:updateRecordStatus 和 updateRecordStatusAndStartTime 看看后续是不是可以统一掉; | ||
| 31 | /** | 32 | /** |
| 32 | * 更新开团记录状态 | 33 | * 更新开团记录状态 |
| 33 | * | 34 | * |
| @@ -35,7 +36,7 @@ public interface CombinationRecordApi { | @@ -35,7 +36,7 @@ public interface CombinationRecordApi { | ||
| 35 | * @param orderId 订单编号 | 36 | * @param orderId 订单编号 |
| 36 | * @param status 状态值 | 37 | * @param status 状态值 |
| 37 | */ | 38 | */ |
| 38 | - void updateRecordStatus(Long userId, Long orderId, Integer status); | 39 | + void updateCombinationRecordStatus(Long userId, Long orderId, Integer status); |
| 39 | 40 | ||
| 40 | /** | 41 | /** |
| 41 | * 更新开团记录状态和开始时间 | 42 | * 更新开团记录状态和开始时间 |
| @@ -44,6 +45,6 @@ public interface CombinationRecordApi { | @@ -44,6 +45,6 @@ public interface CombinationRecordApi { | ||
| 44 | * @param orderId 订单编号 | 45 | * @param orderId 订单编号 |
| 45 | * @param status 状态值 | 46 | * @param status 状态值 |
| 46 | */ | 47 | */ |
| 47 | - void updateRecordStatusAndStartTime(Long userId, Long orderId, Integer status); | 48 | + void updateCombinationRecordStatusAndStartTime(Long userId, Long orderId, Integer status); |
| 48 | 49 | ||
| 49 | } | 50 | } |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateReqDTO.java
| @@ -5,8 +5,9 @@ import lombok.Data; | @@ -5,8 +5,9 @@ import lombok.Data; | ||
| 5 | import javax.validation.constraints.NotEmpty; | 5 | import javax.validation.constraints.NotEmpty; |
| 6 | import javax.validation.constraints.NotNull; | 6 | import javax.validation.constraints.NotNull; |
| 7 | 7 | ||
| 8 | +// TODO @芋艿:这块要在看看 | ||
| 8 | /** | 9 | /** |
| 9 | - * 拼团记录 Request DTO | 10 | + * 拼团记录的创建 Request DTO |
| 10 | * | 11 | * |
| 11 | * @author HUIHUI | 12 | * @author HUIHUI |
| 12 | */ | 13 | */ |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java
| @@ -20,23 +20,23 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { | @@ -20,23 +20,23 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { | ||
| 20 | private CombinationRecordService recordService; | 20 | private CombinationRecordService recordService; |
| 21 | 21 | ||
| 22 | @Override | 22 | @Override |
| 23 | - public void createRecord(CombinationRecordCreateReqDTO reqDTO) { | ||
| 24 | - recordService.createRecord(reqDTO); | 23 | + public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { |
| 24 | + recordService.createCombinationRecord(reqDTO); | ||
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | @Override | 27 | @Override |
| 28 | - public boolean validateRecordStatusIsSuccess(Long userId, Long orderId) { | ||
| 29 | - return CombinationRecordStatusEnum.isSuccess(recordService.getRecord(userId, orderId).getStatus()); | 28 | + public boolean isCombinationRecordSuccess(Long userId, Long orderId) { |
| 29 | + return CombinationRecordStatusEnum.isSuccess(recordService.getCombinationRecord(userId, orderId).getStatus()); | ||
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | @Override | 32 | @Override |
| 33 | - public void updateRecordStatus(Long userId, Long orderId, Integer status) { | ||
| 34 | - recordService.updateRecordStatusByUserIdAndOrderId(userId, orderId, status); | 33 | + public void updateCombinationRecordStatus(Long userId, Long orderId, Integer status) { |
| 34 | + recordService.updateCombinationRecordStatusByUserIdAndOrderId(userId, orderId, status); | ||
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | @Override | 37 | @Override |
| 38 | - public void updateRecordStatusAndStartTime(Long userId, Long orderId, Integer status) { | ||
| 39 | - recordService.updateRecordStatusAndStartTimeByUserIdAndOrderId(userId, orderId, status, LocalDateTime.now()); | 38 | + public void updateCombinationRecordStatusAndStartTime(Long userId, Long orderId, Integer status) { |
| 39 | + recordService.updateCombinationRecordStatusAndStartTimeByUserIdAndOrderId(userId, orderId, status, LocalDateTime.now()); | ||
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | } | 42 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java
| @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.promotion.controller.admin.combination; | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.promotion.controller.admin.combination; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 6 | import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; | 5 | import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; |
| 7 | import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; | 6 | import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; |
| 8 | import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; | 7 | import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; |
| @@ -23,9 +22,11 @@ import javax.annotation.Resource; | @@ -23,9 +22,11 @@ import javax.annotation.Resource; | ||
| 23 | import javax.validation.Valid; | 22 | import javax.validation.Valid; |
| 24 | import java.util.Collection; | 23 | import java.util.Collection; |
| 25 | import java.util.List; | 24 | import java.util.List; |
| 25 | +import java.util.Set; | ||
| 26 | 26 | ||
| 27 | import static cn.hutool.core.collection.CollectionUtil.newArrayList; | 27 | import static cn.hutool.core.collection.CollectionUtil.newArrayList; |
| 28 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 28 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 29 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||
| 29 | 30 | ||
| 30 | @Tag(name = "管理后台 - 拼团活动") | 31 | @Tag(name = "管理后台 - 拼团活动") |
| 31 | @RestController | 32 | @RestController |
| @@ -35,6 +36,7 @@ public class CombinationActivityController { | @@ -35,6 +36,7 @@ public class CombinationActivityController { | ||
| 35 | 36 | ||
| 36 | @Resource | 37 | @Resource |
| 37 | private CombinationActivityService combinationActivityService; | 38 | private CombinationActivityService combinationActivityService; |
| 39 | + | ||
| 38 | @Resource | 40 | @Resource |
| 39 | private ProductSpuApi spuApi; | 41 | private ProductSpuApi spuApi; |
| 40 | 42 | ||
| @@ -68,17 +70,18 @@ public class CombinationActivityController { | @@ -68,17 +70,18 @@ public class CombinationActivityController { | ||
| 68 | @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") | 70 | @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") |
| 69 | public CommonResult<CombinationActivityRespVO> getCombinationActivity(@RequestParam("id") Long id) { | 71 | public CommonResult<CombinationActivityRespVO> getCombinationActivity(@RequestParam("id") Long id) { |
| 70 | CombinationActivityDO activity = combinationActivityService.getCombinationActivity(id); | 72 | CombinationActivityDO activity = combinationActivityService.getCombinationActivity(id); |
| 71 | - List<CombinationProductDO> products = combinationActivityService.getProductsByActivityIds(newArrayList(id)); | 73 | + List<CombinationProductDO> products = combinationActivityService.getCombinationProductsByActivityIds(newArrayList(id)); |
| 72 | return success(CombinationActivityConvert.INSTANCE.convert(activity, products)); | 74 | return success(CombinationActivityConvert.INSTANCE.convert(activity, products)); |
| 73 | } | 75 | } |
| 74 | 76 | ||
| 77 | + // TODO @puhui999:是不是可以删掉,貌似没用? | ||
| 75 | @GetMapping("/list") | 78 | @GetMapping("/list") |
| 76 | @Operation(summary = "获得拼团活动列表") | 79 | @Operation(summary = "获得拼团活动列表") |
| 77 | @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") | 80 | @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") |
| 78 | @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") | 81 | @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") |
| 79 | public CommonResult<List<CombinationActivityRespVO>> getCombinationActivityList(@RequestParam("ids") Collection<Long> ids) { | 82 | public CommonResult<List<CombinationActivityRespVO>> getCombinationActivityList(@RequestParam("ids") Collection<Long> ids) { |
| 80 | List<CombinationActivityDO> list = combinationActivityService.getCombinationActivityList(ids); | 83 | List<CombinationActivityDO> list = combinationActivityService.getCombinationActivityList(ids); |
| 81 | - return success(CombinationActivityConvert.INSTANCE.complementList(list)); | 84 | + return success(CombinationActivityConvert.INSTANCE.convertList(list)); |
| 82 | } | 85 | } |
| 83 | 86 | ||
| 84 | @GetMapping("/page") | 87 | @GetMapping("/page") |
| @@ -86,10 +89,14 @@ public class CombinationActivityController { | @@ -86,10 +89,14 @@ public class CombinationActivityController { | ||
| 86 | @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") | 89 | @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") |
| 87 | public CommonResult<PageResult<CombinationActivityRespVO>> getCombinationActivityPage( | 90 | public CommonResult<PageResult<CombinationActivityRespVO>> getCombinationActivityPage( |
| 88 | @Valid CombinationActivityPageReqVO pageVO) { | 91 | @Valid CombinationActivityPageReqVO pageVO) { |
| 92 | + // 查询拼团活动 | ||
| 89 | PageResult<CombinationActivityDO> pageResult = combinationActivityService.getCombinationActivityPage(pageVO); | 93 | PageResult<CombinationActivityDO> pageResult = combinationActivityService.getCombinationActivityPage(pageVO); |
| 94 | + // 拼接数据 | ||
| 95 | + Set<Long> activityIds = convertSet(pageResult.getList(), CombinationActivityDO::getId); | ||
| 96 | + Set<Long> spuIds = convertSet(pageResult.getList(), CombinationActivityDO::getSpuId); | ||
| 90 | return success(CombinationActivityConvert.INSTANCE.convertPage(pageResult, | 97 | return success(CombinationActivityConvert.INSTANCE.convertPage(pageResult, |
| 91 | - combinationActivityService.getProductsByActivityIds(CollectionUtils.convertSet(pageResult.getList(), CombinationActivityDO::getId)), | ||
| 92 | - spuApi.getSpuList(CollectionUtils.convertSet(pageResult.getList(), CombinationActivityDO::getSpuId)))); | 98 | + combinationActivityService.getCombinationProductsByActivityIds(activityIds), |
| 99 | + spuApi.getSpuList(spuIds))); | ||
| 93 | } | 100 | } |
| 94 | 101 | ||
| 95 | } | 102 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillActivityController.java
| @@ -79,6 +79,7 @@ public class SeckillActivityController { | @@ -79,6 +79,7 @@ public class SeckillActivityController { | ||
| 79 | return success(SeckillActivityConvert.INSTANCE.convert(seckillActivity, seckillProducts)); | 79 | return success(SeckillActivityConvert.INSTANCE.convert(seckillActivity, seckillProducts)); |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | + // TODO @puhui999:是不是可以删掉,貌似没用? | ||
| 82 | @GetMapping("/list") | 83 | @GetMapping("/list") |
| 83 | @Operation(summary = "获得秒杀活动列表") | 84 | @Operation(summary = "获得秒杀活动列表") |
| 84 | @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") | 85 | @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") |
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.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 4 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | 5 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| 5 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | 6 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 6 | import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; | 7 | import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; |
| @@ -70,7 +71,7 @@ public interface CombinationActivityConvert { | @@ -70,7 +71,7 @@ public interface CombinationActivityConvert { | ||
| 70 | return respVO; | 71 | return respVO; |
| 71 | } | 72 | } |
| 72 | 73 | ||
| 73 | - List<CombinationActivityRespVO> complementList(List<CombinationActivityDO> list); | 74 | + List<CombinationActivityRespVO> convertList(List<CombinationActivityDO> list); |
| 74 | 75 | ||
| 75 | PageResult<CombinationActivityRespVO> convertPage(PageResult<CombinationActivityDO> page); | 76 | PageResult<CombinationActivityRespVO> convertPage(PageResult<CombinationActivityDO> page); |
| 76 | 77 | ||
| @@ -80,8 +81,10 @@ public interface CombinationActivityConvert { | @@ -80,8 +81,10 @@ public interface CombinationActivityConvert { | ||
| 80 | Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId); | 81 | Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId); |
| 81 | PageResult<CombinationActivityRespVO> pageResult = convertPage(page); | 82 | PageResult<CombinationActivityRespVO> pageResult = convertPage(page); |
| 82 | pageResult.getList().forEach(item -> { | 83 | pageResult.getList().forEach(item -> { |
| 83 | - MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName())); | ||
| 84 | - MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl())); | 84 | + MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> { |
| 85 | + item.setSpuName(spu.getName()); | ||
| 86 | + item.setPicUrl(spu.getPicUrl()); | ||
| 87 | + }); | ||
| 85 | item.setProducts(convertList2(productList)); | 88 | item.setProducts(convertList2(productList)); |
| 86 | }); | 89 | }); |
| 87 | return pageResult; | 90 | return pageResult; |
| @@ -100,7 +103,7 @@ public interface CombinationActivityConvert { | @@ -100,7 +103,7 @@ public interface CombinationActivityConvert { | ||
| 100 | }) | 103 | }) |
| 101 | CombinationProductDO convert(CombinationActivityDO activityDO, CombinationProductBaseVO vo); | 104 | CombinationProductDO convert(CombinationActivityDO activityDO, CombinationProductBaseVO vo); |
| 102 | 105 | ||
| 103 | - default List<CombinationProductDO> complementList(List<? extends CombinationProductBaseVO> products, CombinationActivityDO activityDO) { | 106 | + default List<CombinationProductDO> convertList(List<? extends CombinationProductBaseVO> products, CombinationActivityDO activityDO) { |
| 104 | List<CombinationProductDO> list = new ArrayList<>(); | 107 | List<CombinationProductDO> list = new ArrayList<>(); |
| 105 | products.forEach(sku -> { | 108 | products.forEach(sku -> { |
| 106 | CombinationProductDO productDO = convert(activityDO, sku); | 109 | CombinationProductDO productDO = convert(activityDO, sku); |
| @@ -110,16 +113,12 @@ public interface CombinationActivityConvert { | @@ -110,16 +113,12 @@ public interface CombinationActivityConvert { | ||
| 110 | return list; | 113 | return list; |
| 111 | } | 114 | } |
| 112 | 115 | ||
| 113 | - default List<CombinationProductDO> complementList(List<CombinationProductDO> productDOs, List<CombinationProductUpdateReqVO> vos, CombinationActivityDO activityDO) { | ||
| 114 | - Map<Long, Long> longMap = convertMap(productDOs, CombinationProductDO::getSkuId, CombinationProductDO::getId); | ||
| 115 | - List<CombinationProductDO> list = new ArrayList<>(); | ||
| 116 | - vos.forEach(sku -> { | ||
| 117 | - CombinationProductDO productDO = convert(activityDO, sku); | ||
| 118 | - productDO.setId(longMap.get(sku.getSkuId())); | ||
| 119 | - productDO.setActivityStatus(activityDO.getStatus()); | ||
| 120 | - list.add(productDO); | ||
| 121 | - }); | ||
| 122 | - return list; | 116 | + default List<CombinationProductDO> convertList(List<CombinationProductUpdateReqVO> updateProductVOs, |
| 117 | + List<CombinationProductDO> products, CombinationActivityDO activity) { | ||
| 118 | + Map<Long, Long> productMap = convertMap(products, CombinationProductDO::getSkuId, CombinationProductDO::getId); | ||
| 119 | + return CollectionUtils.convertList(updateProductVOs, updateProductVO -> convert(activity, updateProductVO) | ||
| 120 | + .setId(productMap.get(updateProductVO.getSkuId())) | ||
| 121 | + .setActivityStatus(activity.getStatus())); | ||
| 123 | } | 122 | } |
| 124 | 123 | ||
| 125 | CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO); | 124 | CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO); |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java
| @@ -21,6 +21,8 @@ import java.util.ArrayList; | @@ -21,6 +21,8 @@ import java.util.ArrayList; | ||
| 21 | import java.util.List; | 21 | import java.util.List; |
| 22 | import java.util.Map; | 22 | import java.util.Map; |
| 23 | 23 | ||
| 24 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | ||
| 25 | + | ||
| 24 | /** | 26 | /** |
| 25 | * 秒杀活动 Convert | 27 | * 秒杀活动 Convert |
| 26 | * | 28 | * |
| @@ -37,6 +39,7 @@ public interface SeckillActivityConvert { | @@ -37,6 +39,7 @@ public interface SeckillActivityConvert { | ||
| 37 | 39 | ||
| 38 | SeckillActivityRespVO convert(SeckillActivityDO bean); | 40 | SeckillActivityRespVO convert(SeckillActivityDO bean); |
| 39 | 41 | ||
| 42 | + // TODO @puhui999:这个是不是还是 convertList 好点? | ||
| 40 | List<SeckillActivityRespVO> complementList(List<SeckillActivityDO> list); | 43 | List<SeckillActivityRespVO> complementList(List<SeckillActivityDO> list); |
| 41 | 44 | ||
| 42 | PageResult<SeckillActivityRespVO> convertPage(PageResult<SeckillActivityDO> page); | 45 | PageResult<SeckillActivityRespVO> convertPage(PageResult<SeckillActivityDO> page); |
| @@ -73,7 +76,7 @@ public interface SeckillActivityConvert { | @@ -73,7 +76,7 @@ public interface SeckillActivityConvert { | ||
| 73 | }) | 76 | }) |
| 74 | SeckillProductDO convert(SeckillActivityDO activityDO, SeckillProductBaseVO vo); | 77 | SeckillProductDO convert(SeckillActivityDO activityDO, SeckillProductBaseVO vo); |
| 75 | 78 | ||
| 76 | - default List<SeckillProductDO> complementList(List<? extends SeckillProductBaseVO> products, SeckillActivityDO activityDO) { | 79 | + default List<SeckillProductDO> convertList(List<? extends SeckillProductBaseVO> products, SeckillActivityDO activityDO) { |
| 77 | List<SeckillProductDO> list = new ArrayList<>(); | 80 | List<SeckillProductDO> list = new ArrayList<>(); |
| 78 | products.forEach(sku -> { | 81 | products.forEach(sku -> { |
| 79 | SeckillProductDO productDO = convert(activityDO, sku); | 82 | SeckillProductDO productDO = convert(activityDO, sku); |
| @@ -83,16 +86,12 @@ public interface SeckillActivityConvert { | @@ -83,16 +86,12 @@ public interface SeckillActivityConvert { | ||
| 83 | return list; | 86 | return list; |
| 84 | } | 87 | } |
| 85 | 88 | ||
| 86 | - default List<SeckillProductDO> complementList(List<SeckillProductDO> productDOs, List<SeckillProductUpdateReqVO> vos, SeckillActivityDO activityDO) { | ||
| 87 | - Map<Long, Long> longMap = CollectionUtils.convertMap(productDOs, SeckillProductDO::getSkuId, SeckillProductDO::getId); | ||
| 88 | - List<SeckillProductDO> list = new ArrayList<>(); | ||
| 89 | - vos.forEach(sku -> { | ||
| 90 | - SeckillProductDO productDO = convert(activityDO, sku); | ||
| 91 | - productDO.setId(longMap.get(sku.getSkuId())); | ||
| 92 | - productDO.setActivityStatus(activityDO.getStatus()); | ||
| 93 | - list.add(productDO); | ||
| 94 | - }); | ||
| 95 | - return list; | 89 | + default List<SeckillProductDO> convertList(List<SeckillProductUpdateReqVO> updateProductVOs, |
| 90 | + List<SeckillProductDO> products, SeckillActivityDO activity) { | ||
| 91 | + Map<Long, Long> productMap = convertMap(products, SeckillProductDO::getSkuId, SeckillProductDO::getId); | ||
| 92 | + return CollectionUtils.convertList(updateProductVOs, updateProductVO -> convert(activity, updateProductVO) | ||
| 93 | + .setId(productMap.get(updateProductVO.getSkuId())) | ||
| 94 | + .setActivityStatus(activity.getStatus())); | ||
| 96 | } | 95 | } |
| 97 | 96 | ||
| 98 | List<SeckillProductRespVO> convertList2(List<SeckillProductDO> productDOs); | 97 | List<SeckillProductRespVO> convertList2(List<SeckillProductDO> productDOs); |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java
| @@ -12,6 +12,9 @@ import java.time.LocalDateTime; | @@ -12,6 +12,9 @@ import java.time.LocalDateTime; | ||
| 12 | /** | 12 | /** |
| 13 | * 拼团记录 DO | 13 | * 拼团记录 DO |
| 14 | * | 14 | * |
| 15 | + * 1. 用户参与拼团时,会创建一条记录 | ||
| 16 | + * 2. 团长的拼团记录,和参团人的拼团记录,通过 {@link #headId} 关联 | ||
| 17 | + * | ||
| 15 | * @author HUIHUI | 18 | * @author HUIHUI |
| 16 | */ | 19 | */ |
| 17 | @TableName("promotion_combination_record") | 20 | @TableName("promotion_combination_record") |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java
| @@ -15,6 +15,7 @@ import java.util.List; | @@ -15,6 +15,7 @@ import java.util.List; | ||
| 15 | @Mapper | 15 | @Mapper |
| 16 | public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO> { | 16 | public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO> { |
| 17 | 17 | ||
| 18 | + // TODO @puhui999:selectByUserIdAndOrderId | ||
| 18 | default CombinationRecordDO selectRecord(Long userId, Long orderId) { | 19 | default CombinationRecordDO selectRecord(Long userId, Long orderId) { |
| 19 | return selectOne(CombinationRecordDO::getUserId, userId, | 20 | return selectOne(CombinationRecordDO::getUserId, userId, |
| 20 | CombinationRecordDO::getOrderId, orderId); | 21 | CombinationRecordDO::getOrderId, orderId); |
| @@ -28,7 +29,8 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO | @@ -28,7 +29,8 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO | ||
| 28 | * @return 拼团记录 | 29 | * @return 拼团记录 |
| 29 | */ | 30 | */ |
| 30 | default CombinationRecordDO selectRecordByHeadId(Long headId, Long activityId, Integer status) { | 31 | default CombinationRecordDO selectRecordByHeadId(Long headId, Long activityId, Integer status) { |
| 31 | - return selectOne(CombinationRecordDO::getUserId, headId, CombinationRecordDO::getActivityId, activityId, | 32 | + return selectOne(CombinationRecordDO::getHeadId, headId, |
| 33 | + CombinationRecordDO::getActivityId, activityId, | ||
| 32 | CombinationRecordDO::getStatus, status); | 34 | CombinationRecordDO::getStatus, status); |
| 33 | } | 35 | } |
| 34 | 36 |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java
| @@ -70,6 +70,6 @@ public interface CombinationActivityService { | @@ -70,6 +70,6 @@ public interface CombinationActivityService { | ||
| 70 | * @param ids 拼团活动 ids | 70 | * @param ids 拼团活动 ids |
| 71 | * @return 拼团活动的商品列表 | 71 | * @return 拼团活动的商品列表 |
| 72 | */ | 72 | */ |
| 73 | - List<CombinationProductDO> getProductsByActivityIds(Collection<Long> ids); | 73 | + List<CombinationProductDO> getCombinationProductsByActivityIds(Collection<Long> ids); |
| 74 | 74 | ||
| 75 | } | 75 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java
| @@ -19,14 +19,14 @@ public interface CombinationRecordService { | @@ -19,14 +19,14 @@ public interface CombinationRecordService { | ||
| 19 | * @param orderId 订单编号 | 19 | * @param orderId 订单编号 |
| 20 | * @param status 状态 | 20 | * @param status 状态 |
| 21 | */ | 21 | */ |
| 22 | - void updateRecordStatusByUserIdAndOrderId(Long userId, Long orderId, Integer status); | 22 | + void updateCombinationRecordStatusByUserIdAndOrderId(Long userId, Long orderId, Integer status); |
| 23 | 23 | ||
| 24 | /** | 24 | /** |
| 25 | * 创建拼团记录 | 25 | * 创建拼团记录 |
| 26 | * | 26 | * |
| 27 | * @param reqDTO 创建信息 | 27 | * @param reqDTO 创建信息 |
| 28 | */ | 28 | */ |
| 29 | - void createRecord(CombinationRecordCreateReqDTO reqDTO); | 29 | + void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO); |
| 30 | 30 | ||
| 31 | /** | 31 | /** |
| 32 | * 更新拼团状态和开始时间 | 32 | * 更新拼团状态和开始时间 |
| @@ -36,7 +36,8 @@ public interface CombinationRecordService { | @@ -36,7 +36,8 @@ public interface CombinationRecordService { | ||
| 36 | * @param status 状态 | 36 | * @param status 状态 |
| 37 | * @param startTime 开始时间 | 37 | * @param startTime 开始时间 |
| 38 | */ | 38 | */ |
| 39 | - void updateRecordStatusAndStartTimeByUserIdAndOrderId(Long userId, Long orderId, Integer status, LocalDateTime startTime); | 39 | + void updateCombinationRecordStatusAndStartTimeByUserIdAndOrderId(Long userId, Long orderId, |
| 40 | + Integer status, LocalDateTime startTime); | ||
| 40 | 41 | ||
| 41 | /** | 42 | /** |
| 42 | * 获得拼团状态 | 43 | * 获得拼团状态 |
| @@ -45,6 +46,6 @@ public interface CombinationRecordService { | @@ -45,6 +46,6 @@ public interface CombinationRecordService { | ||
| 45 | * @param orderId 订单编号 | 46 | * @param orderId 订单编号 |
| 46 | * @return 拼团状态 | 47 | * @return 拼团状态 |
| 47 | */ | 48 | */ |
| 48 | - CombinationRecordDO getRecord(Long userId, Long orderId); | 49 | + CombinationRecordDO getCombinationRecord(Long userId, Long orderId); |
| 49 | 50 | ||
| 50 | } | 51 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationServiceImpl.java
| @@ -37,7 +37,7 @@ import java.util.*; | @@ -37,7 +37,7 @@ import java.util.*; | ||
| 37 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 37 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 38 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; | 38 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; |
| 39 | import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; | 39 | import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; |
| 40 | -import static cn.iocoder.yudao.module.promotion.util.PromotionUtils.validateProductSkuExistence; | 40 | +import static cn.iocoder.yudao.module.promotion.util.PromotionUtils.validateProductSkuAllExists; |
| 41 | 41 | ||
| 42 | /** | 42 | /** |
| 43 | * 拼团活动 Service 实现类 | 43 | * 拼团活动 Service 实现类 |
| @@ -66,7 +66,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | @@ -66,7 +66,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | ||
| 66 | // 获取所选 spu下的所有 sku | 66 | // 获取所选 spu下的所有 sku |
| 67 | List<ProductSkuRespDTO> skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(createReqVO.getSpuId())); | 67 | List<ProductSkuRespDTO> skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(createReqVO.getSpuId())); |
| 68 | // 校验商品 sku 是否存在 | 68 | // 校验商品 sku 是否存在 |
| 69 | - validateProductSkuExistence(createReqVO.getProducts(), skus, CombinationProductCreateReqVO::getSkuId); | 69 | + validateProductSkuAllExists(createReqVO.getProducts(), skus, CombinationProductCreateReqVO::getSkuId); |
| 70 | 70 | ||
| 71 | // TODO 艿艿 有个小问题:现在有活动时间和限制时长,活动时间的结束时间早于设置的限制时间怎么算状态比如: | 71 | // TODO 艿艿 有个小问题:现在有活动时间和限制时长,活动时间的结束时间早于设置的限制时间怎么算状态比如: |
| 72 | // 活动时间 2023-08-05 15:00:00 - 2023-08-05 15:20:00 限制时长 2小时,那么活动时间结束就结束还是加时到满两小时 | 72 | // 活动时间 2023-08-05 15:00:00 - 2023-08-05 15:20:00 限制时长 2小时,那么活动时间结束就结束还是加时到满两小时 |
| @@ -80,7 +80,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | @@ -80,7 +80,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | ||
| 80 | activityDO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 80 | activityDO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 81 | combinationActivityMapper.insert(activityDO); | 81 | combinationActivityMapper.insert(activityDO); |
| 82 | // 插入商品 | 82 | // 插入商品 |
| 83 | - List<CombinationProductDO> productDOs = CombinationActivityConvert.INSTANCE.complementList(createReqVO.getProducts(), activityDO); | 83 | + List<CombinationProductDO> productDOs = CombinationActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), activityDO); |
| 84 | combinationProductMapper.insertBatch(productDOs); | 84 | combinationProductMapper.insertBatch(productDOs); |
| 85 | // 返回 | 85 | // 返回 |
| 86 | return activityDO.getId(); | 86 | return activityDO.getId(); |
| @@ -118,7 +118,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | @@ -118,7 +118,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | ||
| 118 | // 获取所选 spu下的所有 sku | 118 | // 获取所选 spu下的所有 sku |
| 119 | List<ProductSkuRespDTO> skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(updateReqVO.getSpuId())); | 119 | List<ProductSkuRespDTO> skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(updateReqVO.getSpuId())); |
| 120 | // 校验商品 sku 是否存在 | 120 | // 校验商品 sku 是否存在 |
| 121 | - validateProductSkuExistence(updateReqVO.getProducts(), skus, CombinationProductUpdateReqVO::getSkuId); | 121 | + validateProductSkuAllExists(updateReqVO.getProducts(), skus, CombinationProductUpdateReqVO::getSkuId); |
| 122 | 122 | ||
| 123 | // 更新 | 123 | // 更新 |
| 124 | CombinationActivityDO updateObj = CombinationActivityConvert.INSTANCE.convert(updateReqVO); | 124 | CombinationActivityDO updateObj = CombinationActivityConvert.INSTANCE.convert(updateReqVO); |
| @@ -140,18 +140,21 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | @@ -140,18 +140,21 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | ||
| 140 | // 前端传过来的活动商品 | 140 | // 前端传过来的活动商品 |
| 141 | Set<Long> convertSet1 = CollectionUtils.convertSet(products, CombinationProductUpdateReqVO::getSkuId); | 141 | Set<Long> convertSet1 = CollectionUtils.convertSet(products, CombinationProductUpdateReqVO::getSkuId); |
| 142 | // 分化数据 | 142 | // 分化数据 |
| 143 | + // TODO @芋艿:看下这个实现 | ||
| 143 | Map<String, List<CombinationProductDO>> data = CollectionUtils.convertCDUMap(convertSet1, convertSet, mapData -> { | 144 | Map<String, List<CombinationProductDO>> data = CollectionUtils.convertCDUMap(convertSet1, convertSet, mapData -> { |
| 144 | HashMap<String, List<CombinationProductDO>> cdu = MapUtil.newHashMap(3); | 145 | HashMap<String, List<CombinationProductDO>> cdu = MapUtil.newHashMap(3); |
| 145 | MapUtils.findAndThen(mapData, "create", list -> { | 146 | MapUtils.findAndThen(mapData, "create", list -> { |
| 146 | - cdu.put("create", CombinationActivityConvert.INSTANCE.complementList(CollectionUtils.filterList(products, item -> list.contains(item.getSkuId())), updateObj)); | 147 | + cdu.put("create", CombinationActivityConvert.INSTANCE.convertList(CollectionUtils.filterList(products, item -> list.contains(item.getSkuId())), updateObj)); |
| 147 | }); | 148 | }); |
| 148 | MapUtils.findAndThen(mapData, "delete", list -> { | 149 | MapUtils.findAndThen(mapData, "delete", list -> { |
| 149 | cdu.put("create", CollectionUtils.filterList(combinationProductDOs, item -> list.contains(item.getSkuId()))); | 150 | cdu.put("create", CollectionUtils.filterList(combinationProductDOs, item -> list.contains(item.getSkuId()))); |
| 150 | }); | 151 | }); |
| 151 | - MapUtils.findAndThen(mapData, "update", list -> { | ||
| 152 | - cdu.put("update", CombinationActivityConvert.INSTANCE.complementList(combinationProductDOs, | ||
| 153 | - CollectionUtils.filterList(products, item -> list.contains(item.getSkuId())), updateObj)); | ||
| 154 | - }); | 152 | + // TODO @芋艿:临时注释,避免有问题 |
| 153 | +// MapUtils.findAndThen(mapData, "update", list -> { | ||
| 154 | +// cdu.put("update", CombinationActivityConvert.INSTANCE.convertList( | ||
| 155 | +// combinationProductDOs, | ||
| 156 | +// CollectionUtils.filterList(products, item -> list.contains(item.getSkuId())), updateObj)); | ||
| 157 | +// }); | ||
| 155 | return cdu; | 158 | return cdu; |
| 156 | }); | 159 | }); |
| 157 | 160 | ||
| @@ -199,12 +202,12 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | @@ -199,12 +202,12 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | ||
| 199 | } | 202 | } |
| 200 | 203 | ||
| 201 | @Override | 204 | @Override |
| 202 | - public List<CombinationProductDO> getProductsByActivityIds(Collection<Long> ids) { | 205 | + public List<CombinationProductDO> getCombinationProductsByActivityIds(Collection<Long> ids) { |
| 203 | return combinationProductMapper.selectListByActivityIds(ids); | 206 | return combinationProductMapper.selectListByActivityIds(ids); |
| 204 | } | 207 | } |
| 205 | 208 | ||
| 206 | @Override | 209 | @Override |
| 207 | - public void updateRecordStatusByUserIdAndOrderId(Long userId, Long orderId, Integer status) { | 210 | + public void updateCombinationRecordStatusByUserIdAndOrderId(Long userId, Long orderId, Integer status) { |
| 208 | // 校验拼团是否存在 | 211 | // 校验拼团是否存在 |
| 209 | CombinationRecordDO recordDO = validateCombinationRecord(userId, orderId); | 212 | CombinationRecordDO recordDO = validateCombinationRecord(userId, orderId); |
| 210 | 213 | ||
| @@ -215,7 +218,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | @@ -215,7 +218,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | ||
| 215 | 218 | ||
| 216 | @Override | 219 | @Override |
| 217 | @Transactional(rollbackFor = Exception.class) | 220 | @Transactional(rollbackFor = Exception.class) |
| 218 | - public void updateRecordStatusAndStartTimeByUserIdAndOrderId(Long userId, Long orderId, Integer status, LocalDateTime startTime) { | 221 | + public void updateCombinationRecordStatusAndStartTimeByUserIdAndOrderId(Long userId, Long orderId, Integer status, LocalDateTime startTime) { |
| 219 | CombinationRecordDO recordDO = validateCombinationRecord(userId, orderId); | 222 | CombinationRecordDO recordDO = validateCombinationRecord(userId, orderId); |
| 220 | // 更新状态 | 223 | // 更新状态 |
| 221 | recordDO.setStatus(status); | 224 | recordDO.setStatus(status); |
| @@ -247,15 +250,15 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | @@ -247,15 +250,15 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | ||
| 247 | } | 250 | } |
| 248 | 251 | ||
| 249 | @Override | 252 | @Override |
| 250 | - public void createRecord(CombinationRecordCreateReqDTO reqDTO) { | ||
| 251 | - // 校验拼团活动 | 253 | + public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { |
| 254 | + // 1.1 校验拼团活动 | ||
| 252 | CombinationActivityDO activity = validateCombinationActivityExists(reqDTO.getActivityId()); | 255 | CombinationActivityDO activity = validateCombinationActivityExists(reqDTO.getActivityId()); |
| 253 | - // 需要校验下,它当前是不是已经参加了该拼团; | 256 | + // 1.2 需要校验下,他当前是不是已经参加了该拼团; |
| 254 | CombinationRecordDO recordDO = recordMapper.selectRecord(reqDTO.getUserId(), reqDTO.getOrderId()); | 257 | CombinationRecordDO recordDO = recordMapper.selectRecord(reqDTO.getUserId(), reqDTO.getOrderId()); |
| 255 | if (recordDO != null) { | 258 | if (recordDO != null) { |
| 256 | throw exception(COMBINATION_RECORD_EXISTS); | 259 | throw exception(COMBINATION_RECORD_EXISTS); |
| 257 | } | 260 | } |
| 258 | - // 父拼团是否存在,是否已经满了 | 261 | + // 1.3 父拼团是否存在,是否已经满了 |
| 259 | if (reqDTO.getHeadId() != null) { | 262 | if (reqDTO.getHeadId() != null) { |
| 260 | CombinationRecordDO recordDO1 = recordMapper.selectRecordByHeadId(reqDTO.getHeadId(), reqDTO.getActivityId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); | 263 | CombinationRecordDO recordDO1 = recordMapper.selectRecordByHeadId(reqDTO.getHeadId(), reqDTO.getActivityId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); |
| 261 | if (recordDO1 == null) { | 264 | if (recordDO1 == null) { |
| @@ -266,9 +269,12 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | @@ -266,9 +269,12 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | ||
| 266 | throw exception(COMBINATION_RECORD_USER_FULL); | 269 | throw exception(COMBINATION_RECORD_USER_FULL); |
| 267 | } | 270 | } |
| 268 | } | 271 | } |
| 272 | + // TODO @puhui999:应该还有一些校验,后续补噶;例如说,一个团,自己已经参与进去了,不能再参与进去; | ||
| 269 | 273 | ||
| 274 | + // 2. 创建拼团记录 | ||
| 270 | CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO); | 275 | CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO); |
| 271 | if (reqDTO.getHeadId() == null) { | 276 | if (reqDTO.getHeadId() == null) { |
| 277 | + // TODO @puhui999:不是自己呀;headId 是父团长的 CombinationRecordDO.id 哈 | ||
| 272 | record.setHeadId(reqDTO.getUserId()); | 278 | record.setHeadId(reqDTO.getUserId()); |
| 273 | } | 279 | } |
| 274 | record.setVirtualGroup(false); | 280 | record.setVirtualGroup(false); |
| @@ -279,7 +285,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | @@ -279,7 +285,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi | ||
| 279 | } | 285 | } |
| 280 | 286 | ||
| 281 | @Override | 287 | @Override |
| 282 | - public CombinationRecordDO getRecord(Long userId, Long orderId) { | 288 | + public CombinationRecordDO getCombinationRecord(Long userId, Long orderId) { |
| 283 | return validateCombinationRecord(userId, orderId); | 289 | return validateCombinationRecord(userId, orderId); |
| 284 | } | 290 | } |
| 285 | 291 |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java
| @@ -34,7 +34,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU | @@ -34,7 +34,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU | ||
| 34 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS; | 34 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS; |
| 35 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; | 35 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; |
| 36 | import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; | 36 | import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; |
| 37 | -import static cn.iocoder.yudao.module.promotion.util.PromotionUtils.validateProductSkuExistence; | 37 | +import static cn.iocoder.yudao.module.promotion.util.PromotionUtils.validateProductSkuAllExists; |
| 38 | 38 | ||
| 39 | /** | 39 | /** |
| 40 | * 秒杀活动 Service 实现类 | 40 | * 秒杀活动 Service 实现类 |
| @@ -74,7 +74,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | @@ -74,7 +74,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | ||
| 74 | .setTotalStock(CollectionUtils.getSumValue(createReqVO.getProducts(), SeckillProductCreateReqVO::getStock, Integer::sum)); | 74 | .setTotalStock(CollectionUtils.getSumValue(createReqVO.getProducts(), SeckillProductCreateReqVO::getStock, Integer::sum)); |
| 75 | seckillActivityMapper.insert(activity); | 75 | seckillActivityMapper.insert(activity); |
| 76 | // 插入商品 | 76 | // 插入商品 |
| 77 | - List<SeckillProductDO> products = SeckillActivityConvert.INSTANCE.complementList(createReqVO.getProducts(), activity); | 77 | + List<SeckillProductDO> products = SeckillActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), activity); |
| 78 | seckillProductMapper.insertBatch(products); | 78 | seckillProductMapper.insertBatch(products); |
| 79 | return activity.getId(); | 79 | return activity.getId(); |
| 80 | } | 80 | } |
| @@ -121,7 +121,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | @@ -121,7 +121,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | ||
| 121 | // 获取所选 spu下的所有 sku | 121 | // 获取所选 spu下的所有 sku |
| 122 | List<ProductSkuRespDTO> skus = productSkuApi.getSkuListBySpuId(CollUtil.newArrayList(updateReqVO.getSpuId())); | 122 | List<ProductSkuRespDTO> skus = productSkuApi.getSkuListBySpuId(CollUtil.newArrayList(updateReqVO.getSpuId())); |
| 123 | // 校验商品 sku 是否存在 | 123 | // 校验商品 sku 是否存在 |
| 124 | - validateProductSkuExistence(updateReqVO.getProducts(), skus, SeckillProductUpdateReqVO::getSkuId); | 124 | + validateProductSkuAllExists(updateReqVO.getProducts(), skus, SeckillProductUpdateReqVO::getSkuId); |
| 125 | 125 | ||
| 126 | // 更新活动 | 126 | // 更新活动 |
| 127 | SeckillActivityDO updateObj = SeckillActivityConvert.INSTANCE.convert(updateReqVO) | 127 | SeckillActivityDO updateObj = SeckillActivityConvert.INSTANCE.convert(updateReqVO) |
| @@ -150,16 +150,17 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | @@ -150,16 +150,17 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { | ||
| 150 | Map<String, List<SeckillProductDO>> data = CollectionUtils.convertCDUMap(voSkuIds, dbSkuIds, mapData -> { | 150 | Map<String, List<SeckillProductDO>> data = CollectionUtils.convertCDUMap(voSkuIds, dbSkuIds, mapData -> { |
| 151 | HashMap<String, List<SeckillProductDO>> cdu = MapUtil.newHashMap(3); | 151 | HashMap<String, List<SeckillProductDO>> cdu = MapUtil.newHashMap(3); |
| 152 | MapUtils.findAndThen(mapData, "create", list -> { | 152 | MapUtils.findAndThen(mapData, "create", list -> { |
| 153 | - cdu.put("create", SeckillActivityConvert.INSTANCE.complementList( | 153 | + cdu.put("create", SeckillActivityConvert.INSTANCE.convertList( |
| 154 | CollectionUtils.filterList(products, item -> list.contains(item.getSkuId())), updateObj)); | 154 | CollectionUtils.filterList(products, item -> list.contains(item.getSkuId())), updateObj)); |
| 155 | }); | 155 | }); |
| 156 | MapUtils.findAndThen(mapData, "delete", list -> { | 156 | MapUtils.findAndThen(mapData, "delete", list -> { |
| 157 | cdu.put("create", CollectionUtils.filterList(seckillProductDOs, item -> list.contains(item.getSkuId()))); | 157 | cdu.put("create", CollectionUtils.filterList(seckillProductDOs, item -> list.contains(item.getSkuId()))); |
| 158 | }); | 158 | }); |
| 159 | - MapUtils.findAndThen(mapData, "update", list -> { | ||
| 160 | - cdu.put("update", SeckillActivityConvert.INSTANCE.complementList(seckillProductDOs, | ||
| 161 | - CollectionUtils.filterList(products, item -> list.contains(item.getSkuId())), updateObj)); | ||
| 162 | - }); | 159 | + // TODO @芋艿:临时注释 |
| 160 | +// MapUtils.findAndThen(mapData, "update", list -> { | ||
| 161 | +// cdu.put("update", SeckillActivityConvert.INSTANCE.convertList(seckillProductDOs, | ||
| 162 | +// CollectionUtils.filterList(products, item -> list.contains(item.getSkuId())), updateObj)); | ||
| 163 | +// }); | ||
| 163 | return cdu; | 164 | return cdu; |
| 164 | }); | 165 | }); |
| 165 | 166 |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java
| @@ -31,18 +31,20 @@ public class PromotionUtils { | @@ -31,18 +31,20 @@ public class PromotionUtils { | ||
| 31 | return LocalDateTimeUtils.beforeNow(endTime) ? CommonStatusEnum.DISABLE.getStatus() : CommonStatusEnum.ENABLE.getStatus(); | 31 | return LocalDateTimeUtils.beforeNow(endTime) ? CommonStatusEnum.DISABLE.getStatus() : CommonStatusEnum.ENABLE.getStatus(); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | + // TODO @puhui999:是不是第一个参数是 sku;然后是 products;这样关联性好点; | ||
| 34 | /** | 35 | /** |
| 35 | - * 校验商品 sku 是否存在 | 36 | + * 校验商品 sku 是否都存在 |
| 36 | * | 37 | * |
| 37 | * @param products 需要校验的商品 | 38 | * @param products 需要校验的商品 |
| 38 | * @param skus 数据库中的商品 skus | 39 | * @param skus 数据库中的商品 skus |
| 39 | * @param func 获取需要校验的商品的 skuId | 40 | * @param func 获取需要校验的商品的 skuId |
| 40 | */ | 41 | */ |
| 41 | - public static <T> void validateProductSkuExistence(List<T> products, List<ProductSkuRespDTO> skus, Function<T, Long> func) { | 42 | + public static <T> void validateProductSkuAllExists(List<T> products, List<ProductSkuRespDTO> skus, Function<T, Long> func) { |
| 42 | // 校验 sku 个数是否一致 | 43 | // 校验 sku 个数是否一致 |
| 43 | Set<Long> skuIdsSet = CollectionUtils.convertSet(products, func); | 44 | Set<Long> skuIdsSet = CollectionUtils.convertSet(products, func); |
| 44 | Set<Long> skuIdsSet1 = CollectionUtils.convertSet(skus, ProductSkuRespDTO::getId); | 45 | Set<Long> skuIdsSet1 = CollectionUtils.convertSet(skus, ProductSkuRespDTO::getId); |
| 45 | // 校验 skuId 是否存在 | 46 | // 校验 skuId 是否存在 |
| 47 | + // TODO @puhui999:findFirst | ||
| 46 | List<Long> f = CollectionUtils.filterList(skuIdsSet, s -> !skuIdsSet1.contains(s)); | 48 | List<Long> f = CollectionUtils.filterList(skuIdsSet, s -> !skuIdsSet1.contains(s)); |
| 47 | if (CollUtil.isNotEmpty(f)) { | 49 | if (CollUtil.isNotEmpty(f)) { |
| 48 | throw exception(SKU_NOT_EXISTS); | 50 | throw exception(SKU_NOT_EXISTS); |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java
| @@ -332,6 +332,7 @@ public interface TradeOrderConvert { | @@ -332,6 +332,7 @@ public interface TradeOrderConvert { | ||
| 332 | @Mapping(target = "avatar", source = "user.avatar"), | 332 | @Mapping(target = "avatar", source = "user.avatar"), |
| 333 | @Mapping(target = "status", ignore = true) | 333 | @Mapping(target = "status", ignore = true) |
| 334 | }) | 334 | }) |
| 335 | - CombinationRecordCreateReqDTO convert(TradeOrderDO order, TradeOrderItemDO orderItem, AppTradeOrderCreateReqVO createReqVO, MemberUserRespDTO user); | 335 | + CombinationRecordCreateReqDTO convert(TradeOrderDO order, TradeOrderItemDO orderItem, |
| 336 | + AppTradeOrderCreateReqVO createReqVO, MemberUserRespDTO user); | ||
| 336 | 337 | ||
| 337 | } | 338 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/message/TradeMessageServiceImpl.java
| @@ -27,11 +27,13 @@ public class TradeMessageServiceImpl implements TradeMessageService { | @@ -27,11 +27,13 @@ public class TradeMessageServiceImpl implements TradeMessageService { | ||
| 27 | // 1、构造消息 | 27 | // 1、构造消息 |
| 28 | Map<String, Object> msgMap = new HashMap<>(); | 28 | Map<String, Object> msgMap = new HashMap<>(); |
| 29 | msgMap.put("orderId", reqDTO.getOrderId()); | 29 | msgMap.put("orderId", reqDTO.getOrderId()); |
| 30 | + // TODO puhui999:应该不是 msg 哇,应该是涉及到的模版参数哈;msg 太大了 | ||
| 30 | msgMap.put("msg", reqDTO.getMessage()); | 31 | msgMap.put("msg", reqDTO.getMessage()); |
| 31 | // 2、发送站内信 | 32 | // 2、发送站内信 |
| 32 | notifyMessageSendApi.sendSingleMessageToMember( | 33 | notifyMessageSendApi.sendSingleMessageToMember( |
| 33 | new NotifySendSingleToUserReqDTO() | 34 | new NotifySendSingleToUserReqDTO() |
| 34 | .setUserId(reqDTO.getUserId()) | 35 | .setUserId(reqDTO.getUserId()) |
| 36 | + // TODO puhui999:短信模版编号,枚举起来; | ||
| 35 | .setTemplateCode("order_delivery") | 37 | .setTemplateCode("order_delivery") |
| 36 | .setTemplateParams(msgMap)); | 38 | .setTemplateParams(msgMap)); |
| 37 | } | 39 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/message/dto/TradeOrderMessageWhenDeliveryOrderReqDTO.java
| @@ -5,6 +5,7 @@ import lombok.Data; | @@ -5,6 +5,7 @@ import lombok.Data; | ||
| 5 | import javax.validation.constraints.NotEmpty; | 5 | import javax.validation.constraints.NotEmpty; |
| 6 | import javax.validation.constraints.NotNull; | 6 | import javax.validation.constraints.NotNull; |
| 7 | 7 | ||
| 8 | +// TODO @puhui999:改成 ReqBO 哈;包名也换了;service 我们还是同一用 bo 对象 | ||
| 8 | /** | 9 | /** |
| 9 | * 订单发货时 Req DTO | 10 | * 订单发货时 Req DTO |
| 10 | * | 11 | * |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java
| @@ -174,7 +174,8 @@ public class TradeOrderServiceImpl implements TradeOrderService { | @@ -174,7 +174,8 @@ public class TradeOrderServiceImpl implements TradeOrderService { | ||
| 174 | if (ObjectUtil.equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { | 174 | if (ObjectUtil.equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { |
| 175 | MemberUserRespDTO user = memberUserApi.getUser(userId); | 175 | MemberUserRespDTO user = memberUserApi.getUser(userId); |
| 176 | // TODO 拼团一次应该只能选择一种规格的商品 | 176 | // TODO 拼团一次应该只能选择一种规格的商品 |
| 177 | - combinationRecordApi.createRecord(TradeOrderConvert.INSTANCE.convert(order, orderItems.get(0), createReqVO, user) | 177 | + // TODO @puhui999:应该是前置校验哈;然后不应该设置状态,而是交给拼团记录那处理; |
| 178 | + combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, orderItems.get(0), createReqVO, user) | ||
| 178 | .setStatus(CombinationRecordStatusEnum.WAITING.getStatus())); | 179 | .setStatus(CombinationRecordStatusEnum.WAITING.getStatus())); |
| 179 | } | 180 | } |
| 180 | // TODO 秒杀扣减库存是下单就扣除还是等待订单支付成功再扣除 | 181 | // TODO 秒杀扣减库存是下单就扣除还是等待订单支付成功再扣除 |
| @@ -311,7 +312,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { | @@ -311,7 +312,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { | ||
| 311 | // 1、拼团活动 | 312 | // 1、拼团活动 |
| 312 | if (ObjectUtil.equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { | 313 | if (ObjectUtil.equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { |
| 313 | // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 | 314 | // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 |
| 314 | - combinationRecordApi.updateRecordStatusAndStartTime(order.getUserId(), order.getId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); | 315 | + combinationRecordApi.updateCombinationRecordStatusAndStartTime(order.getUserId(), order.getId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); |
| 315 | } | 316 | } |
| 316 | // TODO 芋艿:发送订单变化的消息 | 317 | // TODO 芋艿:发送订单变化的消息 |
| 317 | 318 | ||
| @@ -376,10 +377,11 @@ public class TradeOrderServiceImpl implements TradeOrderService { | @@ -376,10 +377,11 @@ public class TradeOrderServiceImpl implements TradeOrderService { | ||
| 376 | return new KeyValue<>(order, payOrder); | 377 | return new KeyValue<>(order, payOrder); |
| 377 | } | 378 | } |
| 378 | 379 | ||
| 380 | + // TODO @芋艿:后续在 review 下发货逻辑 | ||
| 379 | @Override | 381 | @Override |
| 380 | @Transactional(rollbackFor = Exception.class) | 382 | @Transactional(rollbackFor = Exception.class) |
| 381 | public void deliveryOrder(Long userId, TradeOrderDeliveryReqVO deliveryReqVO) { | 383 | public void deliveryOrder(Long userId, TradeOrderDeliveryReqVO deliveryReqVO) { |
| 382 | - // 校验并获得交易订单(可发货) | 384 | + // 1.1 校验并获得交易订单(可发货) |
| 383 | TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId()); | 385 | TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId()); |
| 384 | 386 | ||
| 385 | /* TODO | 387 | /* TODO |
| @@ -388,35 +390,36 @@ public class TradeOrderServiceImpl implements TradeOrderService { | @@ -388,35 +390,36 @@ public class TradeOrderServiceImpl implements TradeOrderService { | ||
| 388 | * 2.如果店铺只支持到店自提那么下单后默认发货不需要物流 | 390 | * 2.如果店铺只支持到店自提那么下单后默认发货不需要物流 |
| 389 | * 3.如果店铺支持 物流-配送-自提 的情况下后台不需要选择配送方式按前端用户选择的配送方式发货即可 | 391 | * 3.如果店铺支持 物流-配送-自提 的情况下后台不需要选择配送方式按前端用户选择的配送方式发货即可 |
| 390 | */ | 392 | */ |
| 391 | - TradeOrderDO tradeOrderDO = new TradeOrderDO(); | 393 | + TradeOrderDO updateOrderObj = new TradeOrderDO(); |
| 392 | // 判断发货类型 | 394 | // 判断发货类型 |
| 393 | - // 快递发货 | 395 | + // 2.1 快递发货 |
| 394 | if (ObjectUtil.equal(deliveryReqVO.getType(), DeliveryTypeEnum.EXPRESS.getMode())) { | 396 | if (ObjectUtil.equal(deliveryReqVO.getType(), DeliveryTypeEnum.EXPRESS.getMode())) { |
| 395 | // 校验快递公司 | 397 | // 校验快递公司 |
| 398 | + // TODO @puhui999:getDeliveryExpress 直接封装一个校验的,会不会好点;因为还有开启关闭啥的; | ||
| 396 | DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(deliveryReqVO.getLogisticsId()); | 399 | DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(deliveryReqVO.getLogisticsId()); |
| 397 | if (deliveryExpress == null) { | 400 | if (deliveryExpress == null) { |
| 398 | throw exception(EXPRESS_NOT_EXISTS); | 401 | throw exception(EXPRESS_NOT_EXISTS); |
| 399 | } | 402 | } |
| 400 | - tradeOrderDO.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo()); | 403 | + updateOrderObj.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo()); |
| 401 | } | 404 | } |
| 402 | - // 用户自提 | 405 | + // 2.2 用户自提 |
| 403 | if (ObjectUtil.equal(deliveryReqVO.getType(), DeliveryTypeEnum.PICK_UP.getMode())) { | 406 | if (ObjectUtil.equal(deliveryReqVO.getType(), DeliveryTypeEnum.PICK_UP.getMode())) { |
| 404 | // TODO 校验自提门店是否存在 | 407 | // TODO 校验自提门店是否存在 |
| 405 | // 重置一下确保快递公司和快递单号为空 | 408 | // 重置一下确保快递公司和快递单号为空 |
| 406 | - tradeOrderDO.setLogisticsId(null).setLogisticsNo(""); | 409 | + updateOrderObj.setLogisticsId(null).setLogisticsNo(""); |
| 407 | } | 410 | } |
| 408 | - // TODO 芋艿:如果无需发货,需要怎么存储? | 411 | + // 2.3 TODO 芋艿:如果无需发货,需要怎么存储?回复:需要把 deliverType 设置为 DeliveryTypeEnum.NULL |
| 409 | if (ObjectUtil.equal(deliveryReqVO.getType(), DeliveryTypeEnum.NULL.getMode())) { | 412 | if (ObjectUtil.equal(deliveryReqVO.getType(), DeliveryTypeEnum.NULL.getMode())) { |
| 410 | // TODO 情况一:正常走发货逻辑和用户自提有点像 不同点:不需要自提门店只需要用户确认收货 | 413 | // TODO 情况一:正常走发货逻辑和用户自提有点像 不同点:不需要自提门店只需要用户确认收货 |
| 411 | // TODO 情况二:用户下单付款后直接确认收货或等待用户确认收货 | 414 | // TODO 情况二:用户下单付款后直接确认收货或等待用户确认收货 |
| 412 | // 重置一下确保快递公司和快递单号为空 | 415 | // 重置一下确保快递公司和快递单号为空 |
| 413 | - tradeOrderDO.setLogisticsId(null).setLogisticsNo(""); | 416 | + updateOrderObj.setLogisticsId(null).setLogisticsNo(""); |
| 414 | } | 417 | } |
| 415 | 418 | ||
| 416 | // 更新 TradeOrderDO 状态为已发货,等待收货 | 419 | // 更新 TradeOrderDO 状态为已发货,等待收货 |
| 417 | - tradeOrderDO.setStatus(TradeOrderStatusEnum.DELIVERED.getStatus()) | 420 | + updateOrderObj.setStatus(TradeOrderStatusEnum.DELIVERED.getStatus()) |
| 418 | .setDeliveryStatus(TradeOrderDeliveryStatusEnum.DELIVERED.getStatus()).setDeliveryTime(LocalDateTime.now()); | 421 | .setDeliveryStatus(TradeOrderDeliveryStatusEnum.DELIVERED.getStatus()).setDeliveryTime(LocalDateTime.now()); |
| 419 | - int updateCount = tradeOrderMapper.updateByIdAndStatus(order.getId(), order.getStatus(), tradeOrderDO); | 422 | + int updateCount = tradeOrderMapper.updateByIdAndStatus(order.getId(), order.getStatus(), updateOrderObj); |
| 420 | if (updateCount == 0) { | 423 | if (updateCount == 0) { |
| 421 | throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED); | 424 | throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED); |
| 422 | } | 425 | } |
| @@ -457,7 +460,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { | @@ -457,7 +460,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { | ||
| 457 | if (ObjectUtil.equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { | 460 | if (ObjectUtil.equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { |
| 458 | // 校验订单拼团是否成功 | 461 | // 校验订单拼团是否成功 |
| 459 | // TODO 用户 ID 使用当前登录用户的还是订单保存的? | 462 | // TODO 用户 ID 使用当前登录用户的还是订单保存的? |
| 460 | - if (combinationRecordApi.validateRecordStatusIsSuccess(order.getUserId(), order.getId())) { | 463 | + if (combinationRecordApi.isCombinationRecordSuccess(order.getUserId(), order.getId())) { |
| 461 | throw exception(ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS); | 464 | throw exception(ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS); |
| 462 | } | 465 | } |
| 463 | } | 466 | } |