Commit e2ed0b7afb588149289186969612693062e81f7b
Committed by
Gitee
!530 完成拼团活动和秒杀活动 CRUD
Merge pull request !530 from puhui999/feature/mall_product
Showing
90 changed files
with
2974 additions
and
604 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java
| ... | ... | @@ -4,6 +4,7 @@ import cn.hutool.core.date.LocalDateTimeUtil; |
| 4 | 4 | |
| 5 | 5 | import java.time.Duration; |
| 6 | 6 | import java.time.LocalDateTime; |
| 7 | +import java.time.LocalTime; | |
| 7 | 8 | |
| 8 | 9 | /** |
| 9 | 10 | * 时间工具类,用于 {@link java.time.LocalDateTime} |
| ... | ... | @@ -50,7 +51,7 @@ public class LocalDateTimeUtils { |
| 50 | 51 | * 判断当前时间是否在该时间范围内 |
| 51 | 52 | * |
| 52 | 53 | * @param startTime 开始时间 |
| 53 | - * @param endTime 结束时间 | |
| 54 | + * @param endTime 结束时间 | |
| 54 | 55 | * @return 是否 |
| 55 | 56 | */ |
| 56 | 57 | public static boolean isBetween(LocalDateTime startTime, LocalDateTime endTime) { |
| ... | ... | @@ -60,4 +61,23 @@ public class LocalDateTimeUtils { |
| 60 | 61 | return LocalDateTimeUtil.isIn(LocalDateTime.now(), startTime, endTime); |
| 61 | 62 | } |
| 62 | 63 | |
| 64 | + /** | |
| 65 | + * 检查时间重叠 不包含日期 | |
| 66 | + * | |
| 67 | + * @param startTime1 需要校验的开始时间 | |
| 68 | + * @param endTime1 需要校验的结束时间 | |
| 69 | + * @param startTime2 校验所需的开始时间 | |
| 70 | + * @param endTime2 校验所需的结束时间 | |
| 71 | + * @return 是否重叠 | |
| 72 | + */ | |
| 73 | + public static boolean checkTimeOverlap(LocalTime startTime1, LocalTime endTime1, LocalTime startTime2, LocalTime endTime2) { | |
| 74 | + // 判断时间是否重叠 | |
| 75 | + // 开始时间在已配置时段的结束时间之前 且 结束时间在已配置时段的开始时间之后 [] | |
| 76 | + return startTime1.isBefore(endTime2) && endTime1.isAfter(startTime2) | |
| 77 | + // 开始时间在已配置时段的开始时间之前 且 结束时间在已配置时段的开始时间之后 (] 或 () | |
| 78 | + || startTime1.isBefore(startTime2) && endTime1.isAfter(startTime2) | |
| 79 | + // 开始时间在已配置时段的结束时间之前 且 结束时间在已配值时段的结束时间之后 [) 或 () | |
| 80 | + || startTime1.isBefore(endTime2) && endTime1.isAfter(endTime2); | |
| 81 | + } | |
| 82 | + | |
| 63 | 83 | } | ... | ... |
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/ProductSkuApi.java
| ... | ... | @@ -30,14 +30,13 @@ public interface ProductSkuApi { |
| 30 | 30 | */ |
| 31 | 31 | List<ProductSkuRespDTO> getSkuList(Collection<Long> ids); |
| 32 | 32 | |
| 33 | - // TODO puhui999:入参用 Collection<Long> 更通用 | |
| 34 | 33 | /** |
| 35 | 34 | * 批量查询 SKU 数组 |
| 36 | 35 | * |
| 37 | 36 | * @param spuIds SPU 编号列表 |
| 38 | 37 | * @return SKU 数组 |
| 39 | 38 | */ |
| 40 | - List<ProductSkuRespDTO> getSkuListBySpuId(List<Long> spuIds); | |
| 39 | + List<ProductSkuRespDTO> getSkuListBySpuId(Collection<Long> spuIds); | |
| 41 | 40 | |
| 42 | 41 | /** |
| 43 | 42 | * 更新 SKU 库存 | ... | ... |
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java
| ... | ... | @@ -46,7 +46,7 @@ public interface ErrorCodeConstants { |
| 46 | 46 | |
| 47 | 47 | // ========== 商品 评价 1008007000 ========== |
| 48 | 48 | ErrorCode COMMENT_NOT_EXISTS = new ErrorCode(1008007000, "商品 评价 不存在"); |
| 49 | - ErrorCode ORDER_SPU_COMMENT_EXISTS = new ErrorCode(1008007001, "订单 商品评价 已存在"); | |
| 49 | + ErrorCode ORDER_SKU_COMMENT_EXISTS = new ErrorCode(1008007001, "订单 商品评价 已存在"); | |
| 50 | 50 | ErrorCode COMMENT_ERROR_OPT = new ErrorCode(1008007002, "商品评价非法操作"); |
| 51 | 51 | ErrorCode COMMENT_ADDITIONAL_EXISTS = new ErrorCode(1008007003, "商品追加评价已存在"); |
| 52 | 52 | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/sku/ProductSkuApiImpl.java
| ... | ... | @@ -43,7 +43,7 @@ public class ProductSkuApiImpl implements ProductSkuApi { |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | @Override |
| 46 | - public List<ProductSkuRespDTO> getSkuListBySpuId(List<Long> spuIds) { | |
| 46 | + public List<ProductSkuRespDTO> getSkuListBySpuId(Collection<Long> spuIds) { | |
| 47 | 47 | if (CollUtil.isEmpty(spuIds)) { |
| 48 | 48 | return Collections.emptyList(); |
| 49 | 49 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java
| ... | ... | @@ -26,23 +26,10 @@ public class ProductCommentBaseVO { |
| 26 | 26 | @NotNull(message = "评价人头像不能为空") |
| 27 | 27 | private String userAvatar; |
| 28 | 28 | |
| 29 | - // TODO @puhui:spuId、spuName 是不是只有 ProductCommentRespVO 有呀。 | |
| 30 | - @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑透气小短袖") | |
| 31 | - @NotNull(message = "商品 SPU 编号不能为空") | |
| 32 | - private Long spuId; | |
| 33 | - | |
| 34 | - @Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") | |
| 35 | - @NotNull(message = "商品 SPU 名称不能为空") | |
| 36 | - private String spuName; | |
| 37 | - | |
| 38 | 29 | @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 39 | 30 | @NotNull(message = "商品 SKU 编号不能为空") |
| 40 | 31 | private Long skuId; |
| 41 | 32 | |
| 42 | - @Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") | |
| 43 | - @NotNull(message = "评分星级不能为空") | |
| 44 | - private Integer scores; | |
| 45 | - | |
| 46 | 33 | @Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") |
| 47 | 34 | @NotNull(message = "描述星级不能为空") |
| 48 | 35 | private Integer descriptionScores; | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentPageReqVO.java
| ... | ... | @@ -35,9 +35,8 @@ public class ProductCommentPageReqVO extends PageParam { |
| 35 | 35 | @InEnum(ProductCommentScoresEnum.class) |
| 36 | 36 | private Integer scores; |
| 37 | 37 | |
| 38 | - // TODO @puhui999:replyStatus 哈 | |
| 39 | 38 | @Schema(description = "商家是否回复", example = "true") |
| 40 | - private Boolean replied; | |
| 39 | + private Boolean replyStatus; | |
| 41 | 40 | |
| 42 | 41 | @Schema(description = "创建时间") |
| 43 | 42 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java
| ... | ... | @@ -5,6 +5,7 @@ import lombok.Data; |
| 5 | 5 | import lombok.EqualsAndHashCode; |
| 6 | 6 | import lombok.ToString; |
| 7 | 7 | |
| 8 | +import javax.validation.constraints.NotNull; | |
| 8 | 9 | import java.time.LocalDateTime; |
| 9 | 10 | |
| 10 | 11 | @Schema(description = "管理后台 - 商品评价 Response VO") |
| ... | ... | @@ -40,4 +41,15 @@ public class ProductCommentRespVO extends ProductCommentBaseVO { |
| 40 | 41 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 41 | 42 | private LocalDateTime createTime; |
| 42 | 43 | |
| 44 | + @Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") | |
| 45 | + private Integer scores; | |
| 46 | + | |
| 47 | + @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑透气小短袖") | |
| 48 | + @NotNull(message = "商品 SPU 编号不能为空") | |
| 49 | + private Long spuId; | |
| 50 | + | |
| 51 | + @Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") | |
| 52 | + @NotNull(message = "商品 SPU 名称不能为空") | |
| 53 | + private String spuName; | |
| 54 | + | |
| 43 | 55 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java
| ... | ... | @@ -21,6 +21,7 @@ import javax.annotation.Resource; |
| 21 | 21 | import javax.servlet.http.HttpServletResponse; |
| 22 | 22 | import javax.validation.Valid; |
| 23 | 23 | import java.io.IOException; |
| 24 | +import java.util.Collection; | |
| 24 | 25 | import java.util.List; |
| 25 | 26 | import java.util.Map; |
| 26 | 27 | |
| ... | ... | @@ -29,11 +30,6 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 29 | 30 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 30 | 31 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; |
| 31 | 32 | |
| 32 | -/** | |
| 33 | - * 商品 SPU 相关接口 | |
| 34 | - * | |
| 35 | - * @author HUIHUI | |
| 36 | - */ | |
| 37 | 33 | @Tag(name = "管理后台 - 商品 SPU") |
| 38 | 34 | @RestController |
| 39 | 35 | @RequestMapping("/product/spu") |
| ... | ... | @@ -100,6 +96,15 @@ public class ProductSpuController { |
| 100 | 96 | return success(ProductSpuConvert.INSTANCE.convertList02(list)); |
| 101 | 97 | } |
| 102 | 98 | |
| 99 | + @GetMapping("/list") | |
| 100 | + @Operation(summary = "获得商品 SPU 详情列表") | |
| 101 | + @Parameter(name = "spuIds", description = "spu 编号列表", required = true, example = "[1,2,3]") | |
| 102 | + @PreAuthorize("@ss.hasPermission('product:spu:query')") | |
| 103 | + public CommonResult<List<ProductSpuDetailRespVO>> getSpuList(@RequestParam("spuIds") Collection<Long> spuIds) { | |
| 104 | + return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespListVO( | |
| 105 | + productSpuService.getSpuList(spuIds), productSkuService.getSkuListBySpuId(spuIds))); | |
| 106 | + } | |
| 107 | + | |
| 103 | 108 | @GetMapping("/page") |
| 104 | 109 | @Operation(summary = "获得商品 SPU 分页") |
| 105 | 110 | @PreAuthorize("@ss.hasPermission('product:spu:query')") | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuCreateReqVO.java
| ... | ... | @@ -9,11 +9,6 @@ import lombok.ToString; |
| 9 | 9 | import javax.validation.Valid; |
| 10 | 10 | import java.util.List; |
| 11 | 11 | |
| 12 | -/** | |
| 13 | - * 商品 SPU 创建 Request VO | |
| 14 | - * | |
| 15 | - * @author HUIHUI | |
| 16 | - */ | |
| 17 | 12 | @Schema(description = "管理后台 - 商品 SPU 创建 Request VO") |
| 18 | 13 | @Data |
| 19 | 14 | @EqualsAndHashCode(callSuper = true) | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuDetailRespVO.java
| ... | ... | @@ -8,12 +8,6 @@ import lombok.ToString; |
| 8 | 8 | |
| 9 | 9 | import java.util.List; |
| 10 | 10 | |
| 11 | -/** | |
| 12 | - * 商品 SPU 详细 Response VO | |
| 13 | - * 包括关联的 SKU 等信息 | |
| 14 | - * | |
| 15 | - * @author HUIHUI | |
| 16 | - */ | |
| 17 | 11 | @Schema(description = "管理后台 - 商品 SPU 详细 Response VO") |
| 18 | 12 | @Data |
| 19 | 13 | @EqualsAndHashCode(callSuper = true) | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuExportReqVO.java
| ... | ... | @@ -10,11 +10,6 @@ import java.time.LocalDateTime; |
| 10 | 10 | |
| 11 | 11 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
| 12 | 12 | |
| 13 | -/** | |
| 14 | - * 商品Spu导出 Request VO,参数和 ProductSpuPageReqVO 是一致的 | |
| 15 | - * | |
| 16 | - * @author HUIHUI | |
| 17 | - */ | |
| 18 | 13 | @Schema(description = "管理后台 - 商品Spu导出 Request VO,参数和 ProductSpuPageReqVO 是一致的") |
| 19 | 14 | @Data |
| 20 | 15 | @NoArgsConstructor | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuPageReqVO.java
| ... | ... | @@ -11,11 +11,6 @@ import java.time.LocalDateTime; |
| 11 | 11 | |
| 12 | 12 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
| 13 | 13 | |
| 14 | -/** | |
| 15 | - * 商品 SPU 分页 Request VO | |
| 16 | - * | |
| 17 | - * @author HUIHUI | |
| 18 | - */ | |
| 19 | 14 | @Schema(description = "管理后台 - 商品 SPU 分页 Request VO") |
| 20 | 15 | @Data |
| 21 | 16 | @EqualsAndHashCode(callSuper = true) | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuRespVO.java
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuSimpleRespVO.java
| ... | ... | @@ -4,11 +4,6 @@ import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.Data; |
| 5 | 5 | import lombok.ToString; |
| 6 | 6 | |
| 7 | -/** | |
| 8 | - * 商品 SPU 精简 Response VO | |
| 9 | - * TODO 商品 SPU 精简 VO 暂时没有使用到,用到的时候再按需添加\修改属性 | |
| 10 | - * @author HUIHUI | |
| 11 | - */ | |
| 12 | 7 | @Schema(description = "管理后台 - 商品 SPU 精简 Response VO") |
| 13 | 8 | @Data |
| 14 | 9 | @ToString(callSuper = true) | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuUpdateReqVO.java
| ... | ... | @@ -12,11 +12,6 @@ import javax.validation.Valid; |
| 12 | 12 | import javax.validation.constraints.NotNull; |
| 13 | 13 | import java.util.List; |
| 14 | 14 | |
| 15 | -/** | |
| 16 | - * 商品 SPU 更新 Request VO | |
| 17 | - * | |
| 18 | - * @author HUIHUI | |
| 19 | - */ | |
| 20 | 15 | @Schema(description = "管理后台 - 商品 SPU 更新 Request VO") |
| 21 | 16 | @Data |
| 22 | 17 | @EqualsAndHashCode(callSuper = true) | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuUpdateStatusReqVO.java
| ... | ... | @@ -7,11 +7,6 @@ import lombok.Data; |
| 7 | 7 | |
| 8 | 8 | import javax.validation.constraints.NotNull; |
| 9 | 9 | |
| 10 | -/** | |
| 11 | - * 商品 SPU Status 更新 Request VO | |
| 12 | - * | |
| 13 | - * @author HUIHUI | |
| 14 | - */ | |
| 15 | 10 | @Schema(description = "管理后台 - 商品 SPU Status 更新 Request VO") |
| 16 | 11 | @Data |
| 17 | 12 | public class ProductSpuUpdateStatusReqVO{ | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java
| 1 | 1 | package cn.iocoder.yudao.module.product.controller.app.comment; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | -import cn.hutool.core.util.ObjectUtil; | |
| 5 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 7 | 7 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; |
| 8 | 8 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; |
| 9 | 9 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; |
| 10 | -import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; | |
| 11 | 10 | import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; |
| 12 | 11 | import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; |
| 13 | 12 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| 14 | 13 | import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; |
| 15 | 14 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; |
| 15 | +import com.google.common.collect.Maps; | |
| 16 | 16 | import io.swagger.v3.oas.annotations.Operation; |
| 17 | 17 | import io.swagger.v3.oas.annotations.Parameter; |
| 18 | 18 | import io.swagger.v3.oas.annotations.Parameters; |
| ... | ... | @@ -26,11 +26,9 @@ import org.springframework.web.bind.annotation.RestController; |
| 26 | 26 | |
| 27 | 27 | import javax.annotation.Resource; |
| 28 | 28 | import javax.validation.Valid; |
| 29 | -import java.util.HashMap; | |
| 30 | 29 | import java.util.List; |
| 31 | 30 | import java.util.Map; |
| 32 | 31 | import java.util.Set; |
| 33 | -import java.util.stream.Collectors; | |
| 34 | 32 | |
| 35 | 33 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 36 | 34 | |
| ... | ... | @@ -61,26 +59,14 @@ public class AppProductCommentController { |
| 61 | 59 | @GetMapping("/page") |
| 62 | 60 | @Operation(summary = "获得商品评价分页") |
| 63 | 61 | public CommonResult<PageResult<AppProductCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) { |
| 64 | - PageResult<AppProductCommentRespVO> page = productCommentService.getCommentPage(pageVO, Boolean.TRUE); | |
| 65 | - // TODO @puhui CollUtils 有简化 convertmap 和 list 的方法 | |
| 66 | - Set<Long> skuIds = page.getList().stream().map(AppProductCommentRespVO::getSkuId).collect(Collectors.toSet()); | |
| 62 | + PageResult<ProductCommentDO> commentDOPage = productCommentService.getCommentPage(pageVO, Boolean.TRUE); | |
| 63 | + Set<Long> skuIds = CollectionUtils.convertSet(commentDOPage.getList(), ProductCommentDO::getSkuId); | |
| 67 | 64 | List<ProductSkuDO> skuList = productSkuService.getSkuList(skuIds); |
| 68 | - Map<Long, ProductSkuDO> skuDOMap = new HashMap<>(skuIds.size()); | |
| 65 | + Map<Long, ProductSkuDO> skuDOMap = Maps.newLinkedHashMapWithExpectedSize(skuIds.size()); | |
| 69 | 66 | if (CollUtil.isNotEmpty(skuList)) { |
| 70 | - skuDOMap.putAll(skuList.stream().collect(Collectors.toMap(ProductSkuDO::getId, c -> c))); | |
| 67 | + skuDOMap.putAll(CollectionUtils.convertMap(skuList, ProductSkuDO::getId, c -> c)); | |
| 71 | 68 | } |
| 72 | - // TODO @puihui999:下面也可以放到 convert 里哈 | |
| 73 | - page.getList().forEach(item -> { | |
| 74 | - // 判断用户是否选择匿名 | |
| 75 | - if (ObjectUtil.equal(item.getAnonymous(), true)) { | |
| 76 | - item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS); | |
| 77 | - } | |
| 78 | - ProductSkuDO productSkuDO = skuDOMap.get(item.getSkuId()); | |
| 79 | - if (productSkuDO != null) { | |
| 80 | - List<AppProductPropertyValueDetailRespVO> skuProperties = ProductCommentConvert.INSTANCE.convertList01(productSkuDO.getProperties()); | |
| 81 | - item.setSkuProperties(skuProperties); | |
| 82 | - } | |
| 83 | - }); | |
| 69 | + PageResult<AppProductCommentRespVO> page = ProductCommentConvert.INSTANCE.convertPage02(commentDOPage, skuDOMap); | |
| 84 | 70 | return success(page); |
| 85 | 71 | } |
| 86 | 72 | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java
| ... | ... | @@ -10,11 +10,6 @@ import javax.validation.constraints.Size; |
| 10 | 10 | import java.time.LocalDateTime; |
| 11 | 11 | import java.util.List; |
| 12 | 12 | |
| 13 | -/** | |
| 14 | - * 用户 App - 商品评价详情 Response VO | |
| 15 | - * | |
| 16 | - * @author HUIHUI | |
| 17 | - */ | |
| 18 | 13 | @Schema(description = "用户 App - 商品评价详情 Response VO") |
| 19 | 14 | @Data |
| 20 | 15 | @ToString(callSuper = true) | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.product.convert.comment; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.util.ObjectUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 5 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| 5 | 6 | import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; |
| ... | ... | @@ -19,6 +20,7 @@ import org.mapstruct.factory.Mappers; |
| 19 | 20 | import java.math.BigDecimal; |
| 20 | 21 | import java.math.RoundingMode; |
| 21 | 22 | import java.util.List; |
| 23 | +import java.util.Map; | |
| 22 | 24 | |
| 23 | 25 | /** |
| 24 | 26 | * 商品评价 Convert |
| ... | ... | @@ -32,10 +34,12 @@ public interface ProductCommentConvert { |
| 32 | 34 | |
| 33 | 35 | ProductCommentRespVO convert(ProductCommentDO bean); |
| 34 | 36 | |
| 35 | - // TODO @puhui999:这里貌似字段对上,就不用 mapping 了;可以测试下看看哈 | |
| 36 | - @Mapping(target = "goodCount", source = "goodCount") | |
| 37 | - @Mapping(target = "mediocreCount", source = "mediocreCount") | |
| 38 | - @Mapping(target = "negativeCount", source = "negativeCount") | |
| 37 | + @Named("calculateOverallScore") | |
| 38 | + default double calculateOverallScore(long goodCount, long mediocreCount, long negativeCount) { | |
| 39 | + return (goodCount * 5 + mediocreCount * 3 + negativeCount) / (double) (goodCount + mediocreCount + negativeCount); | |
| 40 | + } | |
| 41 | + | |
| 42 | + @Mapping(target = "scores", expression = "java(calculateOverallScore(goodCount, mediocreCount, negativeCount))") | |
| 39 | 43 | AppCommentStatisticsRespVO convert(Long goodCount, Long mediocreCount, Long negativeCount); |
| 40 | 44 | |
| 41 | 45 | List<ProductCommentRespVO> convertList(List<ProductCommentDO> list); |
| ... | ... | @@ -44,7 +48,23 @@ public interface ProductCommentConvert { |
| 44 | 48 | |
| 45 | 49 | PageResult<ProductCommentRespVO> convertPage(PageResult<ProductCommentDO> page); |
| 46 | 50 | |
| 47 | - PageResult<AppProductCommentRespVO> convertPage02(PageResult<ProductCommentDO> pageResult); | |
| 51 | + PageResult<AppProductCommentRespVO> convertPage01(PageResult<ProductCommentDO> pageResult); | |
| 52 | + | |
| 53 | + default PageResult<AppProductCommentRespVO> convertPage02(PageResult<ProductCommentDO> pageResult, Map<Long, ProductSkuDO> skuDOMap) { | |
| 54 | + PageResult<AppProductCommentRespVO> page = convertPage01(pageResult); | |
| 55 | + page.getList().forEach(item -> { | |
| 56 | + // 判断用户是否选择匿名 | |
| 57 | + if (ObjectUtil.equal(item.getAnonymous(), true)) { | |
| 58 | + item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS); | |
| 59 | + } | |
| 60 | + ProductSkuDO productSkuDO = skuDOMap.get(item.getSkuId()); | |
| 61 | + if (productSkuDO != null) { | |
| 62 | + List<AppProductPropertyValueDetailRespVO> skuProperties = ProductCommentConvert.INSTANCE.convertList01(productSkuDO.getProperties()); | |
| 63 | + item.setSkuProperties(skuProperties); | |
| 64 | + } | |
| 65 | + }); | |
| 66 | + return page; | |
| 67 | + } | |
| 48 | 68 | |
| 49 | 69 | /** |
| 50 | 70 | * 计算综合评分 | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.product.convert.spu; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 4 | 5 | import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; |
| 5 | 6 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 6 | 7 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; |
| ... | ... | @@ -18,6 +19,7 @@ import org.mapstruct.factory.Mappers; |
| 18 | 19 | |
| 19 | 20 | import java.util.ArrayList; |
| 20 | 21 | import java.util.List; |
| 22 | +import java.util.Map; | |
| 21 | 23 | |
| 22 | 24 | import static cn.hutool.core.util.ObjectUtil.defaultIfNull; |
| 23 | 25 | |
| ... | ... | @@ -107,4 +109,15 @@ public interface ProductSpuConvert { |
| 107 | 109 | return detailRespVO; |
| 108 | 110 | } |
| 109 | 111 | |
| 112 | + default List<ProductSpuDetailRespVO> convertForSpuDetailRespListVO(List<ProductSpuDO> spus, List<ProductSkuDO> skus) { | |
| 113 | + ArrayList<ProductSpuDetailRespVO> vos = new ArrayList<>(); | |
| 114 | + Map<Long, List<ProductSkuDO>> skuMultiMap = CollectionUtils.convertMultiMap(skus, ProductSkuDO::getSpuId); | |
| 115 | + spus.forEach(spu -> { | |
| 116 | + ProductSpuDetailRespVO detailRespVO = convert03(spu); | |
| 117 | + detailRespVO.setSkus(ProductSkuConvert.INSTANCE.convertList(skuMultiMap.get(spu.getId()))); | |
| 118 | + vos.add(detailRespVO); | |
| 119 | + }); | |
| 120 | + return vos; | |
| 121 | + } | |
| 122 | + | |
| 110 | 123 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java
| ... | ... | @@ -51,11 +51,11 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> { |
| 51 | 51 | return selectPage(reqVO, queryWrapper); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - default ProductCommentDO selectByUserIdAndOrderItemIdAndSpuId(Long userId, Long orderItemId, Long spuId) { | |
| 54 | + default ProductCommentDO selectByUserIdAndOrderItemIdAndSpuId(Long userId, Long orderItemId, Long skuId) { | |
| 55 | 55 | return selectOne(new LambdaQueryWrapperX<ProductCommentDO>() |
| 56 | 56 | .eq(ProductCommentDO::getUserId, userId) |
| 57 | 57 | .eq(ProductCommentDO::getOrderItemId, orderItemId) |
| 58 | - .eq(ProductCommentDO::getSpuId, spuId)); | |
| 58 | + .eq(ProductCommentDO::getSpuId, skuId)); | |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | default Long selectCountBySpuId(Long spuId, Boolean visible, Integer type) { | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java
| ... | ... | @@ -54,7 +54,7 @@ public interface ProductCommentService { |
| 54 | 54 | * @param visible 是否可见 |
| 55 | 55 | * @return 商品评价分页 |
| 56 | 56 | */ |
| 57 | - PageResult<AppProductCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible); | |
| 57 | + PageResult<ProductCommentDO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible); | |
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * 创建商品评论 | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java
| ... | ... | @@ -81,7 +81,7 @@ public class ProductCommentServiceImpl implements ProductCommentService { |
| 81 | 81 | @Transactional(rollbackFor = Exception.class) |
| 82 | 82 | public void createComment(ProductCommentCreateReqVO createReqVO) { |
| 83 | 83 | // 校验评论 |
| 84 | - validateComment(createReqVO.getSpuId(), createReqVO.getUserId(), createReqVO.getOrderItemId()); | |
| 84 | + validateComment(createReqVO.getSkuId(), createReqVO.getUserId(), createReqVO.getOrderItemId()); | |
| 85 | 85 | |
| 86 | 86 | ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqVO); |
| 87 | 87 | productCommentMapper.insert(commentDO); |
| ... | ... | @@ -108,11 +108,11 @@ public class ProductCommentServiceImpl implements ProductCommentService { |
| 108 | 108 | return commentDO.getId(); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - private void validateComment(Long spuId, Long userId, Long orderItemId) { | |
| 111 | + private void validateComment(Long skuId, Long userId, Long orderItemId) { | |
| 112 | 112 | // 判断当前订单的当前商品用户是否评价过 |
| 113 | - ProductCommentDO exist = productCommentMapper.selectByUserIdAndOrderItemIdAndSpuId(userId, orderItemId, spuId); | |
| 113 | + ProductCommentDO exist = productCommentMapper.selectByUserIdAndOrderItemIdAndSpuId(userId, orderItemId, skuId); | |
| 114 | 114 | if (null != exist) { |
| 115 | - throw exception(ORDER_SPU_COMMENT_EXISTS); | |
| 115 | + throw exception(ORDER_SKU_COMMENT_EXISTS); | |
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
| ... | ... | @@ -141,23 +141,17 @@ public class ProductCommentServiceImpl implements ProductCommentService { |
| 141 | 141 | productCommentMapper.selectCountBySpuId(spuId, visible, AppCommentPageReqVO.MEDIOCRE_COMMENT), |
| 142 | 142 | // 查询商品 id = spuId 的所有差评数量 |
| 143 | 143 | productCommentMapper.selectCountBySpuId(spuId, visible, AppCommentPageReqVO.NEGATIVE_COMMENT) |
| 144 | - ).setScores(3.0); // TODO @puhui999:这里要实现下;; | |
| 144 | + ); | |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | @Override |
| 148 | 148 | public List<AppProductCommentRespVO> getCommentList(Long spuId, Integer count) { |
| 149 | - // 校验商品 spu 是否存在 | |
| 150 | - // TODO @puhui 这里校验可以去掉哈。 | |
| 151 | - ProductSpuDO spuDO = validateSpu(spuId); | |
| 152 | - return ProductCommentConvert.INSTANCE.convertList02(productCommentMapper.selectCommentList(spuDO.getId(), count).getList()); | |
| 149 | + return ProductCommentConvert.INSTANCE.convertList02(productCommentMapper.selectCommentList(spuId, count).getList()); | |
| 153 | 150 | } |
| 154 | 151 | |
| 155 | - // TODO @puhui 可以放到 controller 去 convert 哈 | |
| 156 | 152 | @Override |
| 157 | - public PageResult<AppProductCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) { | |
| 158 | - // TODO @puhui 可以放到 controller 去 convert 哈 | |
| 159 | - return ProductCommentConvert.INSTANCE.convertPage02( | |
| 160 | - productCommentMapper.selectPage(pageVO, visible)); | |
| 153 | + public PageResult<ProductCommentDO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) { | |
| 154 | + return productCommentMapper.selectPage(pageVO, visible); | |
| 161 | 155 | } |
| 162 | 156 | |
| 163 | 157 | @Override | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java
| ... | ... | @@ -90,7 +90,7 @@ public interface ProductSkuService { |
| 90 | 90 | * @param spuIds spu 编码集合 |
| 91 | 91 | * @return 商品 sku 集合 |
| 92 | 92 | */ |
| 93 | - List<ProductSkuDO> getSkuListBySpuId(List<Long> spuIds); | |
| 93 | + List<ProductSkuDO> getSkuListBySpuId(Collection<Long> spuIds); | |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * 通过 spuId 删除 sku 信息 | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java
| ... | ... | @@ -148,7 +148,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | @Override |
| 151 | - public List<ProductSkuDO> getSkuListBySpuId(List<Long> spuIds) { | |
| 151 | + public List<ProductSkuDO> getSkuListBySpuId(Collection<Long> spuIds) { | |
| 152 | 152 | return productSkuMapper.selectListBySpuId(spuIds); |
| 153 | 153 | } |
| 154 | 154 | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java
| ... | ... | @@ -10,7 +10,6 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen |
| 10 | 10 | import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; |
| 11 | 11 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; |
| 12 | 12 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; |
| 13 | -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; | |
| 14 | 13 | import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; |
| 15 | 14 | import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; |
| 16 | 15 | import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper; |
| ... | ... | @@ -128,7 +127,7 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { |
| 128 | 127 | productCommentPageReqVO.setSpuId(spuId); |
| 129 | 128 | productCommentPageReqVO.setSpuName("感冒药"); |
| 130 | 129 | productCommentPageReqVO.setScores(ProductCommentScoresEnum.FOUR.getScores()); |
| 131 | - productCommentPageReqVO.setReplied(Boolean.TRUE); | |
| 130 | + productCommentPageReqVO.setReplyStatus(Boolean.TRUE); | |
| 132 | 131 | |
| 133 | 132 | PageResult<ProductCommentDO> commentPage = productCommentService.getCommentPage(productCommentPageReqVO); |
| 134 | 133 | PageResult<ProductCommentRespVO> result = ProductCommentConvert.INSTANCE.convertPage(productCommentMapper.selectPage(productCommentPageReqVO)); |
| ... | ... | @@ -138,15 +137,15 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { |
| 138 | 137 | assertEquals(8, all.getTotal()); |
| 139 | 138 | |
| 140 | 139 | // 测试获取所有商品分页评论数据 |
| 141 | - PageResult<AppProductCommentRespVO> result1 = productCommentService.getCommentPage(new AppCommentPageReqVO(), Boolean.TRUE); | |
| 140 | + PageResult<ProductCommentDO> result1 = productCommentService.getCommentPage(new AppCommentPageReqVO(), Boolean.TRUE); | |
| 142 | 141 | assertEquals(7, result1.getTotal()); |
| 143 | 142 | |
| 144 | 143 | // 测试获取所有商品分页中评数据 |
| 145 | - PageResult<AppProductCommentRespVO> result2 = productCommentService.getCommentPage(new AppCommentPageReqVO().setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); | |
| 144 | + PageResult<ProductCommentDO> result2 = productCommentService.getCommentPage(new AppCommentPageReqVO().setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); | |
| 146 | 145 | assertEquals(2, result2.getTotal()); |
| 147 | 146 | |
| 148 | 147 | // 测试获取指定 spuId 商品分页中评数据 |
| 149 | - PageResult<AppProductCommentRespVO> result3 = productCommentService.getCommentPage(new AppCommentPageReqVO().setSpuId(spuId).setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); | |
| 148 | + PageResult<ProductCommentDO> result3 = productCommentService.getCommentPage(new AppCommentPageReqVO().setSpuId(spuId).setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); | |
| 150 | 149 | assertEquals(2, result3.getTotal()); |
| 151 | 150 | |
| 152 | 151 | // 测试分页 tab count | ... | ... |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.api.combination; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordReqDTO; | |
| 4 | + | |
| 5 | +import javax.validation.Valid; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * 拼团活动 API 接口 | |
| 9 | + * | |
| 10 | + * @author HUIHUI | |
| 11 | + */ | |
| 12 | +public interface CombinationApi { | |
| 13 | + | |
| 14 | + /** | |
| 15 | + * 创建开团记录 | |
| 16 | + * | |
| 17 | + * @param reqDTO 请求 DTO | |
| 18 | + */ | |
| 19 | + void createRecord(@Valid CombinationRecordReqDTO reqDTO); | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 获取开团记录状态 | |
| 23 | + * | |
| 24 | + * @param userId 用户编号 | |
| 25 | + * @param orderId 订单编号 | |
| 26 | + */ | |
| 27 | + boolean validateRecordStatusIsSuccess(Long userId, Long orderId); | |
| 28 | + | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * 更新开团记录状态 | |
| 32 | + * | |
| 33 | + * @param userId 用户编号 | |
| 34 | + * @param orderId 订单编号 | |
| 35 | + * @param status 状态值 | |
| 36 | + */ | |
| 37 | + void updateRecordStatus(Long userId, Long orderId, Integer status); | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * 更新开团记录状态和开始时间 | |
| 41 | + * | |
| 42 | + * @param userId 用户编号 | |
| 43 | + * @param orderId 订单编号 | |
| 44 | + * @param status 状态值 | |
| 45 | + * @return | |
| 46 | + */ | |
| 47 | + void updateRecordStatusAndStartTime(Long userId, Long orderId, Integer status); | |
| 48 | + | |
| 49 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordReqDTO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.api.combination.dto; | |
| 2 | + | |
| 3 | +import lombok.Data; | |
| 4 | + | |
| 5 | +import javax.validation.constraints.NotEmpty; | |
| 6 | +import javax.validation.constraints.NotNull; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * 拼团记录 Request DTO | |
| 10 | + * | |
| 11 | + * @author HUIHUI | |
| 12 | + */ | |
| 13 | +@Data | |
| 14 | +public class CombinationRecordReqDTO { | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 拼团活动编号 | |
| 18 | + */ | |
| 19 | + @NotNull(message = "拼团活动编号不能为空") | |
| 20 | + private Long activityId; | |
| 21 | + /** | |
| 22 | + * spu 编号 | |
| 23 | + */ | |
| 24 | + @NotNull(message = "spu 编号不能为空") | |
| 25 | + private Long spuId; | |
| 26 | + /** | |
| 27 | + * sku 编号 | |
| 28 | + */ | |
| 29 | + @NotNull(message = "sku 编号不能为空") | |
| 30 | + private Long skuId; | |
| 31 | + /** | |
| 32 | + * 用户编号 | |
| 33 | + */ | |
| 34 | + @NotNull(message = "用户编号不能为空") | |
| 35 | + private Long userId; | |
| 36 | + /** | |
| 37 | + * 订单编号 | |
| 38 | + */ | |
| 39 | + @NotNull(message = "订单编号不能为空") | |
| 40 | + private Long orderId; | |
| 41 | + /** | |
| 42 | + * 团长编号 | |
| 43 | + */ | |
| 44 | + @NotNull(message = "团长编号不能为空") | |
| 45 | + private Long headId; | |
| 46 | + /** | |
| 47 | + * 商品名字 | |
| 48 | + */ | |
| 49 | + @NotEmpty(message = "商品名字不能为空") | |
| 50 | + private String spuName; | |
| 51 | + /** | |
| 52 | + * 商品图片 | |
| 53 | + */ | |
| 54 | + @NotEmpty(message = "商品图片不能为空") | |
| 55 | + private String picUrl; | |
| 56 | + /** | |
| 57 | + * 拼团商品单价 | |
| 58 | + */ | |
| 59 | + @NotNull(message = "拼团商品单价不能为空") | |
| 60 | + private Integer combinationPrice; | |
| 61 | + /** | |
| 62 | + * 用户昵称 | |
| 63 | + */ | |
| 64 | + @NotEmpty(message = "用户昵称不能为空") | |
| 65 | + private String nickname; | |
| 66 | + /** | |
| 67 | + * 用户头像 | |
| 68 | + */ | |
| 69 | + @NotEmpty(message = "用户头像不能为空") | |
| 70 | + private String avatar; | |
| 71 | + /** | |
| 72 | + * 开团状态:正在开团 拼团成功 拼团失败 TODO 等待支付 | |
| 73 | + */ | |
| 74 | + @NotNull(message = "开团状态不能为空") | |
| 75 | + private Integer status; | |
| 76 | + | |
| 77 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java
| ... | ... | @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; |
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * Promotion 错误码枚举类 |
| 7 | - * | |
| 7 | + * <p> | |
| 8 | 8 | * promotion 系统,使用 1-013-000-000 段 |
| 9 | 9 | */ |
| 10 | 10 | public interface ErrorCodeConstants { |
| ... | ... | @@ -58,5 +58,12 @@ public interface ErrorCodeConstants { |
| 58 | 58 | ErrorCode SECKILL_TIME_CONFLICTS = new ErrorCode(1013009001, "秒杀时段冲突"); |
| 59 | 59 | ErrorCode SECKILL_TIME_EQUAL = new ErrorCode(1013009002, "秒杀时段开始时间和结束时间不能相等"); |
| 60 | 60 | ErrorCode SECKILL_START_TIME_BEFORE_END_TIME = new ErrorCode(1013009003, "秒杀时段开始时间不能在结束时间之后"); |
| 61 | + ErrorCode SECKILL_TIME_DISABLE = new ErrorCode(1013009004, "秒杀时段已关闭"); | |
| 61 | 62 | |
| 63 | + // ========== 拼团活动 1013010000 ========== | |
| 64 | + ErrorCode COMBINATION_ACTIVITY_NOT_EXISTS = new ErrorCode(1013010000, "拼团活动不存在"); | |
| 65 | + ErrorCode COMBINATION_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1013010001, "存在商品参加了其它拼团活动"); | |
| 66 | + ErrorCode COMBINATION_ACTIVITY_STATUS_DISABLE = new ErrorCode(1013010002, "拼团活动已关闭不能修改"); | |
| 67 | + ErrorCode COMBINATION_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013010003, "拼团活动未关闭或未结束,不能删除"); | |
| 68 | + ErrorCode COMBINATION_RECORD_NOT_EXISTS = new ErrorCode(1013010004, "拼团不存在"); | |
| 62 | 69 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/combination/CombinationRecordStatusEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.enums.combination; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; | |
| 4 | +import lombok.AllArgsConstructor; | |
| 5 | +import lombok.Getter; | |
| 6 | + | |
| 7 | +import java.util.Arrays; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 拼团状态枚举 | |
| 11 | + * | |
| 12 | + * @author HUIHUI | |
| 13 | + */ | |
| 14 | +@AllArgsConstructor | |
| 15 | +@Getter | |
| 16 | +public enum CombinationRecordStatusEnum implements IntArrayValuable { | |
| 17 | + NOT_PAY(0, "未付款"), | |
| 18 | + ONGOING(1, "进行中"), | |
| 19 | + SUCCESS(2, "拼团成功"), | |
| 20 | + FAILED(3, "拼团失败"); | |
| 21 | + | |
| 22 | + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CombinationRecordStatusEnum::getStatus).toArray(); | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 状态值 | |
| 26 | + */ | |
| 27 | + private final Integer status; | |
| 28 | + /** | |
| 29 | + * 状态名 | |
| 30 | + */ | |
| 31 | + private final String name; | |
| 32 | + | |
| 33 | + @Override | |
| 34 | + public int[] array() { | |
| 35 | + return ARRAYS; | |
| 36 | + } | |
| 37 | + | |
| 38 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.api.combination; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordReqDTO; | |
| 4 | +import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService; | |
| 5 | +import org.springframework.stereotype.Service; | |
| 6 | + | |
| 7 | +import javax.annotation.Resource; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 拼团活动 API 实现类 | |
| 12 | + * | |
| 13 | + * @author HUIHUI | |
| 14 | + */ | |
| 15 | +@Service | |
| 16 | +public class CombinationApiImpl implements CombinationApi { | |
| 17 | + @Resource | |
| 18 | + private CombinationActivityService activityService; | |
| 19 | + | |
| 20 | + @Override | |
| 21 | + public void createRecord(CombinationRecordReqDTO reqDTO) { | |
| 22 | + activityService.createRecord(reqDTO); | |
| 23 | + } | |
| 24 | + | |
| 25 | + @Override | |
| 26 | + public boolean validateRecordStatusIsSuccess(Long userId, Long orderId) { | |
| 27 | + return activityService.validateRecordStatusIsSuccess(userId, orderId); | |
| 28 | + } | |
| 29 | + | |
| 30 | + @Override | |
| 31 | + public void updateRecordStatus(Long userId, Long orderId, Integer status) { | |
| 32 | + activityService.updateRecordStatusByUserIdAndOrderId(userId, orderId, status); | |
| 33 | + } | |
| 34 | + | |
| 35 | + @Override | |
| 36 | + public void updateRecordStatusAndStartTime(Long userId, Long orderId, Integer status) { | |
| 37 | + activityService.updateRecordStatusAndStartTimeByUserIdAndOrderId(userId, orderId, status, LocalDateTime.now()); | |
| 38 | + } | |
| 39 | + | |
| 40 | + | |
| 41 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination; | |
| 2 | + | |
| 3 | +import cn.hutool.core.collection.CollectionUtil; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 7 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 8 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 9 | +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; | |
| 10 | +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | |
| 11 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.*; | |
| 12 | +import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; | |
| 13 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; | |
| 14 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; | |
| 15 | +import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService; | |
| 16 | +import io.swagger.v3.oas.annotations.Operation; | |
| 17 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 18 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 19 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 20 | +import org.springframework.validation.annotation.Validated; | |
| 21 | +import org.springframework.web.bind.annotation.*; | |
| 22 | + | |
| 23 | +import javax.annotation.Resource; | |
| 24 | +import javax.servlet.http.HttpServletResponse; | |
| 25 | +import javax.validation.Valid; | |
| 26 | +import java.io.IOException; | |
| 27 | +import java.util.Collection; | |
| 28 | +import java.util.List; | |
| 29 | +import java.util.Set; | |
| 30 | + | |
| 31 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 32 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | |
| 33 | + | |
| 34 | +@Tag(name = "管理后台 - 拼团活动") | |
| 35 | +@RestController | |
| 36 | +@RequestMapping("/promotion/combination-activity") | |
| 37 | +@Validated | |
| 38 | +public class CombinationActivityController { | |
| 39 | + | |
| 40 | + @Resource | |
| 41 | + private CombinationActivityService combinationActivityService; | |
| 42 | + @Resource | |
| 43 | + private ProductSpuApi spuApi; | |
| 44 | + | |
| 45 | + @PostMapping("/create") | |
| 46 | + @Operation(summary = "创建拼团活动") | |
| 47 | + @PreAuthorize("@ss.hasPermission('promotion:combination-activity:create')") | |
| 48 | + public CommonResult<Long> createCombinationActivity(@Valid @RequestBody CombinationActivityCreateReqVO createReqVO) { | |
| 49 | + return success(combinationActivityService.createCombinationActivity(createReqVO)); | |
| 50 | + } | |
| 51 | + | |
| 52 | + @PutMapping("/update") | |
| 53 | + @Operation(summary = "更新拼团活动") | |
| 54 | + @PreAuthorize("@ss.hasPermission('promotion:combination-activity:update')") | |
| 55 | + public CommonResult<Boolean> updateCombinationActivity(@Valid @RequestBody CombinationActivityUpdateReqVO updateReqVO) { | |
| 56 | + combinationActivityService.updateCombinationActivity(updateReqVO); | |
| 57 | + return success(true); | |
| 58 | + } | |
| 59 | + | |
| 60 | + @DeleteMapping("/delete") | |
| 61 | + @Operation(summary = "删除拼团活动") | |
| 62 | + @Parameter(name = "id", description = "编号", required = true) | |
| 63 | + @PreAuthorize("@ss.hasPermission('promotion:combination-activity:delete')") | |
| 64 | + public CommonResult<Boolean> deleteCombinationActivity(@RequestParam("id") Long id) { | |
| 65 | + combinationActivityService.deleteCombinationActivity(id); | |
| 66 | + return success(true); | |
| 67 | + } | |
| 68 | + | |
| 69 | + @GetMapping("/get") | |
| 70 | + @Operation(summary = "获得拼团活动") | |
| 71 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 72 | + @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") | |
| 73 | + public CommonResult<CombinationActivityRespVO> getCombinationActivity(@RequestParam("id") Long id) { | |
| 74 | + CombinationActivityDO combinationActivity = combinationActivityService.getCombinationActivity(id); | |
| 75 | + List<CombinationProductDO> productDOs = combinationActivityService.getProductsByActivityIds(CollectionUtil.newArrayList(id)); | |
| 76 | + return success(CombinationActivityConvert.INSTANCE.convert(combinationActivity, productDOs)); | |
| 77 | + } | |
| 78 | + | |
| 79 | + @GetMapping("/list") | |
| 80 | + @Operation(summary = "获得拼团活动列表") | |
| 81 | + @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") | |
| 82 | + @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") | |
| 83 | + public CommonResult<List<CombinationActivityRespVO>> getCombinationActivityList(@RequestParam("ids") Collection<Long> ids) { | |
| 84 | + List<CombinationActivityDO> list = combinationActivityService.getCombinationActivityList(ids); | |
| 85 | + return success(CombinationActivityConvert.INSTANCE.convertList(list)); | |
| 86 | + } | |
| 87 | + | |
| 88 | + @GetMapping("/page") | |
| 89 | + @Operation(summary = "获得拼团活动分页") | |
| 90 | + @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") | |
| 91 | + public CommonResult<PageResult<CombinationActivityRespVO>> getCombinationActivityPage(@Valid CombinationActivityPageReqVO pageVO) { | |
| 92 | + PageResult<CombinationActivityDO> pageResult = combinationActivityService.getCombinationActivityPage(pageVO); | |
| 93 | + Set<Long> aIds = CollectionUtils.convertSet(pageResult.getList(), CombinationActivityDO::getId); | |
| 94 | + List<CombinationProductDO> productDOs = combinationActivityService.getProductsByActivityIds(aIds); | |
| 95 | + Set<Long> spuIds = CollectionUtils.convertSet(pageResult.getList(), CombinationActivityDO::getSpuId); | |
| 96 | + List<ProductSpuRespDTO> spuList = spuApi.getSpuList(spuIds); | |
| 97 | + return success(CombinationActivityConvert.INSTANCE.convertPage(pageResult, productDOs, spuList)); | |
| 98 | + } | |
| 99 | + | |
| 100 | + @GetMapping("/export-excel") | |
| 101 | + @Operation(summary = "导出拼团活动 Excel") | |
| 102 | + @PreAuthorize("@ss.hasPermission('promotion:combination-activity:export')") | |
| 103 | + @OperateLog(type = EXPORT) | |
| 104 | + public void exportCombinationActivityExcel(@Valid CombinationActivityExportReqVO exportReqVO, | |
| 105 | + HttpServletResponse response) throws IOException { | |
| 106 | + List<CombinationActivityDO> list = combinationActivityService.getCombinationActivityList(exportReqVO); | |
| 107 | + // 导出 Excel | |
| 108 | + List<CombinationActivityExcelVO> datas = CombinationActivityConvert.INSTANCE.convertList02(list); | |
| 109 | + ExcelUtils.write(response, "拼团活动.xls", "数据", CombinationActivityExcelVO.class, datas); | |
| 110 | + } | |
| 111 | + | |
| 112 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityBaseVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 6 | + | |
| 7 | +import javax.validation.constraints.NotNull; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 拼团活动 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 14 | + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 15 | + */ | |
| 16 | +@Data | |
| 17 | +public class CombinationActivityBaseVO { | |
| 18 | + | |
| 19 | + @Schema(description = "拼团名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "越拼越省钱") | |
| 20 | + @NotNull(message = "拼团名称不能为空") | |
| 21 | + private String name; | |
| 22 | + | |
| 23 | + @Schema(description = "商品 SPU 编号关联 ProductSpuDO 的 id", example = "[1,2,3]") | |
| 24 | + @NotNull(message = "拼团商品不能为空") | |
| 25 | + private Long spuId; | |
| 26 | + | |
| 27 | + @Schema(description = "总限购数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "16218") | |
| 28 | + @NotNull(message = "总限购数量不能为空") | |
| 29 | + private Integer totalLimitCount; | |
| 30 | + | |
| 31 | + @Schema(description = "单次限购数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "28265") | |
| 32 | + @NotNull(message = "单次限购数量不能为空") | |
| 33 | + private Integer singleLimitCount; | |
| 34 | + | |
| 35 | + @Schema(description = "活动时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]") | |
| 36 | + @NotNull(message = "活动时间不能为空") | |
| 37 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 38 | + private LocalDateTime[] activityTime; | |
| 39 | + | |
| 40 | + @Schema(description = "开团人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "25222") | |
| 41 | + @NotNull(message = "开团人数不能为空") | |
| 42 | + private Integer userSize; | |
| 43 | + | |
| 44 | + @Schema(description = "限制时长(小时)", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 45 | + @NotNull(message = "限制时长(小时)不能为空") | |
| 46 | + private Integer limitDuration; | |
| 47 | + | |
| 48 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityCreateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductCreateReqVO; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | + | |
| 9 | +import javax.validation.Valid; | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 12 | +@Schema(description = "管理后台 - 拼团活动创建 Request VO") | |
| 13 | +@Data | |
| 14 | +@EqualsAndHashCode(callSuper = true) | |
| 15 | +@ToString(callSuper = true) | |
| 16 | +public class CombinationActivityCreateReqVO extends CombinationActivityBaseVO { | |
| 17 | + | |
| 18 | + @Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 19 | + @Valid | |
| 20 | + private List<CombinationProductCreateReqVO> products; | |
| 21 | + | |
| 22 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityExcelVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 6 | +import lombok.Data; | |
| 7 | + | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * 拼团活动 Excel VO | |
| 13 | + * | |
| 14 | + * @author HUIHUI | |
| 15 | + */ | |
| 16 | +@Data | |
| 17 | +public class CombinationActivityExcelVO { | |
| 18 | + | |
| 19 | + @ExcelProperty("活动编号") | |
| 20 | + private Long id; | |
| 21 | + | |
| 22 | + @ExcelProperty("拼团名称") | |
| 23 | + private String name; | |
| 24 | + | |
| 25 | + @ExcelProperty("商品 SPU 编号关联 ProductSpuDO 的 id") | |
| 26 | + private Long spuId; | |
| 27 | + | |
| 28 | + @ExcelProperty("总限购数量") | |
| 29 | + private Integer totalLimitCount; | |
| 30 | + | |
| 31 | + @ExcelProperty("单次限购数量") | |
| 32 | + private Integer singleLimitCount; | |
| 33 | + | |
| 34 | + @ExcelProperty("开始时间") | |
| 35 | + private LocalDateTime startTime; | |
| 36 | + | |
| 37 | + @ExcelProperty("结束时间") | |
| 38 | + private LocalDateTime endTime; | |
| 39 | + | |
| 40 | + @ExcelProperty("开团人数") | |
| 41 | + private Integer userSize; | |
| 42 | + | |
| 43 | + @ExcelProperty("开团组数") | |
| 44 | + private Integer totalNum; | |
| 45 | + | |
| 46 | + @ExcelProperty("成团组数") | |
| 47 | + private Integer successNum; | |
| 48 | + | |
| 49 | + @ExcelProperty("参与人数") | |
| 50 | + private Integer orderUserCount; | |
| 51 | + | |
| 52 | + @ExcelProperty("虚拟成团") | |
| 53 | + private Integer virtualGroup; | |
| 54 | + | |
| 55 | + @ExcelProperty(value = "活动状态:0开启 1关闭", converter = DictConvert.class) | |
| 56 | + @DictFormat("common_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 | |
| 57 | + private Integer status; | |
| 58 | + | |
| 59 | + @ExcelProperty("限制时长(小时)") | |
| 60 | + private Integer limitDuration; | |
| 61 | + | |
| 62 | + @ExcelProperty("创建时间") | |
| 63 | + private LocalDateTime createTime; | |
| 64 | + | |
| 65 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityExportReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 6 | + | |
| 7 | +import java.time.LocalDateTime; | |
| 8 | + | |
| 9 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 10 | + | |
| 11 | +@Schema(description = "管理后台 - 拼团活动 Excel 导出 Request VO,参数和 CombinationActivityPageReqVO 是一致的") | |
| 12 | +@Data | |
| 13 | +public class CombinationActivityExportReqVO { | |
| 14 | + | |
| 15 | + @Schema(description = "拼团名称", example = "赵六") | |
| 16 | + private String name; | |
| 17 | + | |
| 18 | + @Schema(description = "商品 SPU 编号关联 ProductSpuDO 的 id", example = "14016") | |
| 19 | + private Long spuId; | |
| 20 | + | |
| 21 | + @Schema(description = "总限购数量", example = "16218") | |
| 22 | + private Integer totalLimitCount; | |
| 23 | + | |
| 24 | + @Schema(description = "单次限购数量", example = "28265") | |
| 25 | + private Integer singleLimitCount; | |
| 26 | + | |
| 27 | + @Schema(description = "开始时间") | |
| 28 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 29 | + private LocalDateTime[] startTime; | |
| 30 | + | |
| 31 | + @Schema(description = "结束时间") | |
| 32 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 33 | + private LocalDateTime[] endTime; | |
| 34 | + | |
| 35 | + @Schema(description = "开团人数") | |
| 36 | + private Integer userSize; | |
| 37 | + | |
| 38 | + @Schema(description = "开团组数") | |
| 39 | + private Integer totalNum; | |
| 40 | + | |
| 41 | + @Schema(description = "成团组数") | |
| 42 | + private Integer successNum; | |
| 43 | + | |
| 44 | + @Schema(description = "参与人数", example = "25222") | |
| 45 | + private Integer orderUserCount; | |
| 46 | + | |
| 47 | + @Schema(description = "虚拟成团") | |
| 48 | + private Integer virtualGroup; | |
| 49 | + | |
| 50 | + @Schema(description = "活动状态:0开启 1关闭", example = "0") | |
| 51 | + private Integer status; | |
| 52 | + | |
| 53 | + @Schema(description = "限制时长(小时)") | |
| 54 | + private Integer limitDuration; | |
| 55 | + | |
| 56 | + @Schema(description = "创建时间") | |
| 57 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 58 | + private LocalDateTime[] createTime; | |
| 59 | + | |
| 60 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 13 | + | |
| 14 | +@Schema(description = "管理后台 - 拼团活动分页 Request VO") | |
| 15 | +@Data | |
| 16 | +@EqualsAndHashCode(callSuper = true) | |
| 17 | +@ToString(callSuper = true) | |
| 18 | +public class CombinationActivityPageReqVO extends PageParam { | |
| 19 | + | |
| 20 | + @Schema(description = "拼团名称", example = "赵六") | |
| 21 | + private String name; | |
| 22 | + | |
| 23 | + @Schema(description = "商品 SPU 编号关联 ProductSpuDO 的 id", example = "14016") | |
| 24 | + private Long spuId; | |
| 25 | + | |
| 26 | + @Schema(description = "总限购数量", example = "16218") | |
| 27 | + private Integer totalLimitCount; | |
| 28 | + | |
| 29 | + @Schema(description = "单次限购数量", example = "28265") | |
| 30 | + private Integer singleLimitCount; | |
| 31 | + | |
| 32 | + @Schema(description = "开始时间") | |
| 33 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 34 | + private LocalDateTime[] startTime; | |
| 35 | + | |
| 36 | + @Schema(description = "结束时间") | |
| 37 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 38 | + private LocalDateTime[] endTime; | |
| 39 | + | |
| 40 | + @Schema(description = "开团人数") | |
| 41 | + private Integer userSize; | |
| 42 | + | |
| 43 | + @Schema(description = "开团组数") | |
| 44 | + private Integer totalNum; | |
| 45 | + | |
| 46 | + @Schema(description = "成团组数") | |
| 47 | + private Integer successNum; | |
| 48 | + | |
| 49 | + @Schema(description = "参与人数", example = "25222") | |
| 50 | + private Integer orderUserCount; | |
| 51 | + | |
| 52 | + @Schema(description = "虚拟成团") | |
| 53 | + private Integer virtualGroup; | |
| 54 | + | |
| 55 | + @Schema(description = "活动状态:0开启 1关闭", example = "0") | |
| 56 | + private Integer status; | |
| 57 | + | |
| 58 | + @Schema(description = "限制时长(小时)") | |
| 59 | + private Integer limitDuration; | |
| 60 | + | |
| 61 | + @Schema(description = "创建时间") | |
| 62 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 63 | + private LocalDateTime[] createTime; | |
| 64 | + | |
| 65 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductRespVO; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | + | |
| 9 | +import javax.validation.Valid; | |
| 10 | +import javax.validation.constraints.NotNull; | |
| 11 | +import java.time.LocalDateTime; | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 14 | +@Schema(description = "管理后台 - 拼团活动 Response VO") | |
| 15 | +@Data | |
| 16 | +@EqualsAndHashCode(callSuper = true) | |
| 17 | +@ToString(callSuper = true) | |
| 18 | +public class CombinationActivityRespVO extends CombinationActivityBaseVO { | |
| 19 | + | |
| 20 | + @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") | |
| 21 | + private String spuName; | |
| 22 | + | |
| 23 | + @Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png") | |
| 24 | + private String picUrl; | |
| 25 | + | |
| 26 | + @Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901") | |
| 27 | + private Long id; | |
| 28 | + | |
| 29 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 30 | + private LocalDateTime createTime; | |
| 31 | + | |
| 32 | + @Schema(description = "开团人数", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 33 | + @NotNull(message = "开团人数不能为空") | |
| 34 | + private Integer userSize; | |
| 35 | + | |
| 36 | + @Schema(description = "开团组数", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 37 | + @NotNull(message = "开团组数不能为空") | |
| 38 | + private Integer totalNum; | |
| 39 | + | |
| 40 | + @Schema(description = "成团组数", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 41 | + @NotNull(message = "成团组数不能为空") | |
| 42 | + private Integer successNum; | |
| 43 | + | |
| 44 | + @Schema(description = "虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 45 | + @NotNull(message = "虚拟成团不能为空") | |
| 46 | + private Integer virtualGroup; | |
| 47 | + | |
| 48 | + @Schema(description = "活动状态:0开启 1关闭", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") | |
| 49 | + @NotNull(message = "活动状态不能为空") | |
| 50 | + private Integer status; | |
| 51 | + | |
| 52 | + @Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 53 | + @Valid | |
| 54 | + private List<CombinationProductRespVO> products; | |
| 55 | + | |
| 56 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityUpdateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductUpdateReqVO; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | + | |
| 9 | +import javax.validation.Valid; | |
| 10 | +import javax.validation.constraints.NotNull; | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 拼团活动更新 Request VO") | |
| 14 | +@Data | |
| 15 | +@EqualsAndHashCode(callSuper = true) | |
| 16 | +@ToString(callSuper = true) | |
| 17 | +public class CombinationActivityUpdateReqVO extends CombinationActivityBaseVO { | |
| 18 | + | |
| 19 | + @Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901") | |
| 20 | + @NotNull(message = "活动编号不能为空") | |
| 21 | + private Long id; | |
| 22 | + | |
| 23 | + @Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 24 | + @Valid | |
| 25 | + private List<CombinationProductUpdateReqVO> products; | |
| 26 | + | |
| 27 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductBaseVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +import javax.validation.constraints.NotNull; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * 拼团商品 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 10 | + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 11 | + */ | |
| 12 | +@Data | |
| 13 | +public class CombinationProductBaseVO { | |
| 14 | + | |
| 15 | + @Schema(description = "商品 spuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "30563") | |
| 16 | + @NotNull(message = "商品 spuId 不能为空") | |
| 17 | + private Long spuId; | |
| 18 | + | |
| 19 | + @Schema(description = "商品 skuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "30563") | |
| 20 | + @NotNull(message = "商品 skuId 不能为空") | |
| 21 | + private Long skuId; | |
| 22 | + | |
| 23 | + @Schema(description = "拼团价格,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "27682") | |
| 24 | + @NotNull(message = "拼团价格,单位分不能为空") | |
| 25 | + private Integer activePrice; | |
| 26 | + | |
| 27 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductCreateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | +import lombok.EqualsAndHashCode; | |
| 6 | +import lombok.ToString; | |
| 7 | + | |
| 8 | +@Schema(description = "管理后台 - 拼团商品创建 Request VO") | |
| 9 | +@Data | |
| 10 | +@EqualsAndHashCode(callSuper = true) | |
| 11 | +@ToString(callSuper = true) | |
| 12 | +public class CombinationProductCreateReqVO extends CombinationProductBaseVO { | |
| 13 | + | |
| 14 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductExcelVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product; | |
| 2 | + | |
| 3 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * 拼团商品 Excel VO | |
| 10 | + * | |
| 11 | + * @author HUIHUI | |
| 12 | + */ | |
| 13 | +@Data | |
| 14 | +public class CombinationProductExcelVO { | |
| 15 | + | |
| 16 | + @ExcelProperty("编号") | |
| 17 | + private Long id; | |
| 18 | + | |
| 19 | + @ExcelProperty("拼团活动编号") | |
| 20 | + private Long activityId; | |
| 21 | + | |
| 22 | + @ExcelProperty("商品 SPU 编号") | |
| 23 | + private Long spuId; | |
| 24 | + | |
| 25 | + @ExcelProperty("商品 SKU 编号") | |
| 26 | + private Long skuId; | |
| 27 | + | |
| 28 | + @ExcelProperty("拼团商品状态") | |
| 29 | + private Integer activityStatus; | |
| 30 | + | |
| 31 | + @ExcelProperty("活动开始时间点") | |
| 32 | + private LocalDateTime activityStartTime; | |
| 33 | + | |
| 34 | + @ExcelProperty("活动结束时间点") | |
| 35 | + private LocalDateTime activityEndTime; | |
| 36 | + | |
| 37 | + @ExcelProperty("拼团价格,单位分") | |
| 38 | + private Integer activePrice; | |
| 39 | + | |
| 40 | + @ExcelProperty("创建时间") | |
| 41 | + private LocalDateTime createTime; | |
| 42 | + | |
| 43 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductExportReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 6 | + | |
| 7 | +import java.time.LocalDateTime; | |
| 8 | + | |
| 9 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 10 | + | |
| 11 | +@Schema(description = "管理后台 - 拼团商品 Excel 导出 Request VO,参数和 CombinationProductPageReqVO 是一致的") | |
| 12 | +@Data | |
| 13 | +public class CombinationProductExportReqVO { | |
| 14 | + | |
| 15 | + @Schema(description = "拼团活动编号", example = "6829") | |
| 16 | + private Long activityId; | |
| 17 | + | |
| 18 | + @Schema(description = "商品 SPU 编号", example = "18731") | |
| 19 | + private Long spuId; | |
| 20 | + | |
| 21 | + @Schema(description = "商品 SKU 编号", example = "31675") | |
| 22 | + private Long skuId; | |
| 23 | + | |
| 24 | + @Schema(description = "拼团商品状态", example = "2") | |
| 25 | + private Integer activityStatus; | |
| 26 | + | |
| 27 | + @Schema(description = "活动开始时间点") | |
| 28 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 29 | + private LocalDateTime[] activityStartTime; | |
| 30 | + | |
| 31 | + @Schema(description = "活动结束时间点") | |
| 32 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 33 | + private LocalDateTime[] activityEndTime; | |
| 34 | + | |
| 35 | + @Schema(description = "拼团价格,单位分", example = "27682") | |
| 36 | + private Integer activePrice; | |
| 37 | + | |
| 38 | + @Schema(description = "创建时间") | |
| 39 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 40 | + private LocalDateTime[] createTime; | |
| 41 | + | |
| 42 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 13 | + | |
| 14 | +@Schema(description = "管理后台 - 拼团商品分页 Request VO") | |
| 15 | +@Data | |
| 16 | +@EqualsAndHashCode(callSuper = true) | |
| 17 | +@ToString(callSuper = true) | |
| 18 | +public class CombinationProductPageReqVO extends PageParam { | |
| 19 | + | |
| 20 | + @Schema(description = "拼团活动编号", example = "6829") | |
| 21 | + private Long activityId; | |
| 22 | + | |
| 23 | + @Schema(description = "商品 SPU 编号", example = "18731") | |
| 24 | + private Long spuId; | |
| 25 | + | |
| 26 | + @Schema(description = "商品 SKU 编号", example = "31675") | |
| 27 | + private Long skuId; | |
| 28 | + | |
| 29 | + @Schema(description = "拼团商品状态", example = "2") | |
| 30 | + private Integer activityStatus; | |
| 31 | + | |
| 32 | + @Schema(description = "活动开始时间点") | |
| 33 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 34 | + private LocalDateTime[] activityStartTime; | |
| 35 | + | |
| 36 | + @Schema(description = "活动结束时间点") | |
| 37 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 38 | + private LocalDateTime[] activityEndTime; | |
| 39 | + | |
| 40 | + @Schema(description = "拼团价格,单位分", example = "27682") | |
| 41 | + private Integer activePrice; | |
| 42 | + | |
| 43 | + @Schema(description = "创建时间") | |
| 44 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 45 | + private LocalDateTime[] createTime; | |
| 46 | + | |
| 47 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | +import lombok.EqualsAndHashCode; | |
| 6 | +import lombok.ToString; | |
| 7 | + | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +@Schema(description = "管理后台 - 拼团商品 Response VO") | |
| 11 | +@Data | |
| 12 | +@EqualsAndHashCode(callSuper = true) | |
| 13 | +@ToString(callSuper = true) | |
| 14 | +public class CombinationProductRespVO extends CombinationProductBaseVO { | |
| 15 | + | |
| 16 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28322") | |
| 17 | + private Long id; | |
| 18 | + | |
| 19 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 20 | + private LocalDateTime createTime; | |
| 21 | + | |
| 22 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductUpdateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | +import lombok.EqualsAndHashCode; | |
| 6 | +import lombok.ToString; | |
| 7 | + | |
| 8 | +@Schema(description = "管理后台 - 拼团商品更新 Request VO") | |
| 9 | +@Data | |
| 10 | +@EqualsAndHashCode(callSuper = true) | |
| 11 | +@ToString(callSuper = true) | |
| 12 | +public class CombinationProductUpdateReqVO extends CombinationProductBaseVO { | |
| 13 | + | |
| 14 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillActivityController.java
| ... | ... | @@ -2,6 +2,9 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckill; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 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; | |
| 7 | +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | |
| 5 | 8 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.*; |
| 6 | 9 | import cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity.SeckillActivityConvert; |
| 7 | 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; |
| ... | ... | @@ -18,6 +21,7 @@ import javax.annotation.Resource; |
| 18 | 21 | import javax.validation.Valid; |
| 19 | 22 | import java.util.Collection; |
| 20 | 23 | import java.util.List; |
| 24 | +import java.util.Set; | |
| 21 | 25 | |
| 22 | 26 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 23 | 27 | |
| ... | ... | @@ -29,6 +33,8 @@ public class SeckillActivityController { |
| 29 | 33 | |
| 30 | 34 | @Resource |
| 31 | 35 | private SeckillActivityService seckillActivityService; |
| 36 | + @Resource | |
| 37 | + private ProductSpuApi spuApi; | |
| 32 | 38 | |
| 33 | 39 | @PostMapping("/create") |
| 34 | 40 | @Operation(summary = "创建秒杀活动") |
| ... | ... | @@ -69,11 +75,8 @@ public class SeckillActivityController { |
| 69 | 75 | @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')") |
| 70 | 76 | public CommonResult<SeckillActivityDetailRespVO> getSeckillActivity(@RequestParam("id") Long id) { |
| 71 | 77 | SeckillActivityDO seckillActivity = seckillActivityService.getSeckillActivity(id); |
| 72 | - if (seckillActivity == null) { | |
| 73 | - return success(null); | |
| 74 | - } | |
| 75 | - List<SeckillProductDO> seckillProducts = seckillActivityService.getSeckillProductListByActivityId(id); | |
| 76 | - return success(SeckillActivityConvert.INSTANCE.convert(seckillActivity,seckillProducts)); | |
| 78 | + List<SeckillProductDO> seckillProducts = seckillActivityService.getSeckillProductListByActivityId(id); | |
| 79 | + return success(SeckillActivityConvert.INSTANCE.convert(seckillActivity, seckillProducts)); | |
| 77 | 80 | } |
| 78 | 81 | |
| 79 | 82 | @GetMapping("/list") |
| ... | ... | @@ -90,7 +93,11 @@ public class SeckillActivityController { |
| 90 | 93 | @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')") |
| 91 | 94 | public CommonResult<PageResult<SeckillActivityRespVO>> getSeckillActivityPage(@Valid SeckillActivityPageReqVO pageVO) { |
| 92 | 95 | PageResult<SeckillActivityDO> pageResult = seckillActivityService.getSeckillActivityPage(pageVO); |
| 93 | - return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult)); | |
| 96 | + Set<Long> aIds = CollectionUtils.convertSet(pageResult.getList(), SeckillActivityDO::getId); | |
| 97 | + List<SeckillProductDO> seckillProducts = seckillActivityService.getSeckillProductListByActivityId(aIds); | |
| 98 | + Set<Long> spuIds = CollectionUtils.convertSet(pageResult.getList(), SeckillActivityDO::getSpuId); | |
| 99 | + List<ProductSpuRespDTO> spuList = spuApi.getSpuList(spuIds); | |
| 100 | + return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult, seckillProducts, spuList)); | |
| 94 | 101 | } |
| 95 | 102 | |
| 96 | 103 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillConfigController.java
| ... | ... | @@ -19,11 +19,6 @@ import java.util.List; |
| 19 | 19 | |
| 20 | 20 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 21 | 21 | |
| 22 | -/** | |
| 23 | - * 管理后台 - 秒杀时段相关接口 | |
| 24 | - * | |
| 25 | - * @author HUIHUI | |
| 26 | - */ | |
| 27 | 22 | @Tag(name = "管理后台 - 秒杀时段") |
| 28 | 23 | @RestController |
| 29 | 24 | @RequestMapping("/promotion/seckill-config") | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityBaseVO.java
| ... | ... | @@ -20,10 +20,9 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ |
| 20 | 20 | @Data |
| 21 | 21 | public class SeckillActivityBaseVO { |
| 22 | 22 | |
| 23 | - // TODO @puhui999:对应单 spuId 哈 | |
| 24 | 23 | @Schema(description = "秒杀活动商品id", requiredMode = Schema.RequiredMode.REQUIRED, example = "[121,1212]") |
| 25 | 24 | @NotNull(message = "秒杀活动商品不能为空") |
| 26 | - private List<Long> spuIds; | |
| 25 | + private Long spuId; | |
| 27 | 26 | |
| 28 | 27 | @Schema(description = "秒杀活动名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") |
| 29 | 28 | @NotNull(message = "秒杀活动名称不能为空") |
| ... | ... | @@ -56,8 +55,4 @@ public class SeckillActivityBaseVO { |
| 56 | 55 | @Schema(description = "单次限够数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "31683") |
| 57 | 56 | private Integer singleLimitCount; |
| 58 | 57 | |
| 59 | - // TODO @puhui999:这个应该是计算出来的字段,只返回,create 和 update 不用哈 | |
| 60 | - @Schema(description = "秒杀总库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") | |
| 61 | - private Integer totalStock; | |
| 62 | - | |
| 63 | 58 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java
| ... | ... | @@ -6,26 +6,46 @@ import lombok.Data; |
| 6 | 6 | import lombok.EqualsAndHashCode; |
| 7 | 7 | import lombok.ToString; |
| 8 | 8 | |
| 9 | +import java.time.LocalDateTime; | |
| 9 | 10 | import java.util.List; |
| 10 | 11 | |
| 11 | -/** | |
| 12 | - * 管理后台 - 秒杀活动 Response VO | |
| 13 | - * | |
| 14 | - * @author HUIHUI | |
| 15 | - */ | |
| 16 | 12 | @Schema(description = "管理后台 - 秒杀活动 Response VO") |
| 17 | 13 | @Data |
| 18 | 14 | @EqualsAndHashCode(callSuper = true) |
| 19 | 15 | @ToString(callSuper = true) |
| 20 | 16 | public class SeckillActivityRespVO extends SeckillActivityBaseVO { |
| 21 | 17 | |
| 18 | + @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") | |
| 19 | + private String spuName; | |
| 20 | + | |
| 21 | + @Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png") | |
| 22 | + private String picUrl; | |
| 23 | + | |
| 22 | 24 | @Schema(description = "秒杀活动id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 23 | 25 | private Long id; |
| 24 | 26 | |
| 25 | 27 | @Schema(description = "秒杀商品", requiredMode = Schema.RequiredMode.REQUIRED) |
| 26 | - private List<SeckillProductRespVO> products; // TODO puhui: 考虑是否去除 | |
| 28 | + private List<SeckillProductRespVO> products; | |
| 27 | 29 | |
| 28 | 30 | @Schema(description = "活动状态 开启:0 禁用:1", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") |
| 29 | 31 | private Integer status; |
| 30 | 32 | |
| 33 | + @Schema(description = "订单实付金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "22354") | |
| 34 | + private Integer totalPrice; | |
| 35 | + | |
| 36 | + @Schema(description = "秒杀库存", example = "10") | |
| 37 | + private Integer stock; | |
| 38 | + | |
| 39 | + @Schema(description = "秒杀总库存", example = "20") | |
| 40 | + private Integer totalStock; | |
| 41 | + | |
| 42 | + @Schema(description = "新增订单数", example = "20") | |
| 43 | + private Integer orderCount; | |
| 44 | + | |
| 45 | + @Schema(description = "付款人数", example = "20") | |
| 46 | + private Integer userCount; | |
| 47 | + | |
| 48 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 49 | + private LocalDateTime createTime; | |
| 50 | + | |
| 31 | 51 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/config/SeckillConfigBaseVO.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config; |
| 2 | 2 | |
| 3 | +import com.fasterxml.jackson.annotation.JsonIgnore; | |
| 3 | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 5 | import lombok.Data; |
| 5 | 6 | |
| 7 | +import javax.validation.constraints.AssertTrue; | |
| 6 | 8 | import javax.validation.constraints.NotNull; |
| 9 | +import java.time.LocalTime; | |
| 10 | +import java.util.List; | |
| 7 | 11 | |
| 8 | 12 | /** |
| 9 | 13 | * 秒杀时段 Base VO,提供给添加、修改、详细的子 VO 使用 |
| ... | ... | @@ -26,12 +30,24 @@ public class SeckillConfigBaseVO { |
| 26 | 30 | @NotNull(message = "结束时间点不能为空") |
| 27 | 31 | private String endTime; |
| 28 | 32 | |
| 29 | - @Schema(description = "秒杀主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn") | |
| 30 | - @NotNull(message = "秒杀主图不能为空") | |
| 31 | - private String picUrl; | |
| 33 | + @Schema(description = "秒杀轮播图", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png]") | |
| 34 | + @NotNull(message = "秒杀轮播图不能为空") | |
| 35 | + private List<String> sliderPicUrls; | |
| 32 | 36 | |
| 33 | 37 | @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") |
| 34 | 38 | @NotNull(message = "状态不能为空") |
| 35 | 39 | private Integer status; |
| 36 | 40 | |
| 41 | + @AssertTrue(message = "秒杀时段开始时间和结束时间不能相等") | |
| 42 | + @JsonIgnore | |
| 43 | + public boolean isValidStartTimeValid() { | |
| 44 | + return !LocalTime.parse(startTime).equals(LocalTime.parse(endTime)); | |
| 45 | + } | |
| 46 | + | |
| 47 | + @AssertTrue(message = "秒杀时段开始时间不能在结束时间之后") | |
| 48 | + @JsonIgnore | |
| 49 | + public boolean isValidEndTimeValid() { | |
| 50 | + return !LocalTime.parse(startTime).isAfter(LocalTime.parse(endTime)); | |
| 51 | + } | |
| 52 | + | |
| 37 | 53 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/config/SeckillConfigPageReqVO.java
| ... | ... | @@ -6,12 +6,6 @@ import lombok.Data; |
| 6 | 6 | import lombok.EqualsAndHashCode; |
| 7 | 7 | import lombok.ToString; |
| 8 | 8 | |
| 9 | -// TODO @puhui:VO 上不写注释,已经有注解啦。 | |
| 10 | -/** | |
| 11 | - * 管理后台 - 秒杀时段分页 Request VO | |
| 12 | - * | |
| 13 | - * @author HUIHUI | |
| 14 | - */ | |
| 15 | 9 | @Schema(description = "管理后台 - 秒杀时段分页 Request VO") |
| 16 | 10 | @Data |
| 17 | 11 | @EqualsAndHashCode(callSuper = true) | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductBaseVO.java
| ... | ... | @@ -14,11 +14,6 @@ import javax.validation.constraints.NotNull; |
| 14 | 14 | @Data |
| 15 | 15 | public class SeckillProductBaseVO { |
| 16 | 16 | |
| 17 | - // TODO @puhui:spuId 不用传递;因为一个秒杀活动只对应一个 SPU 哈; | |
| 18 | - @Schema(description = "商品spu_id", requiredMode = Schema.RequiredMode.REQUIRED, example = "30563") | |
| 19 | - @NotNull(message = "商品spu_id不能为空") | |
| 20 | - private Long spuId; | |
| 21 | - | |
| 22 | 17 | @Schema(description = "商品sku_id", requiredMode = Schema.RequiredMode.REQUIRED, example = "30563") |
| 23 | 18 | @NotNull(message = "商品sku_id不能为空") |
| 24 | 19 | private Long skuId; |
| ... | ... | @@ -31,5 +26,4 @@ public class SeckillProductBaseVO { |
| 31 | 26 | @NotNull(message = "秒杀库存不能为空") |
| 32 | 27 | private Integer stock; |
| 33 | 28 | |
| 34 | - | |
| 35 | 29 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductCreateReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductBaseVO; | |
| 4 | -import lombok.*; | |
| 5 | -import java.util.*; | |
| 6 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 7 | -import javax.validation.constraints.*; | |
| 8 | - | |
| 9 | -/** | |
| 10 | - * 管理后台 - 秒杀参与商品创建 Request VO | |
| 11 | - * | |
| 12 | - * @author HUIHUI | |
| 13 | - */ | |
| 4 | +import lombok.Data; | |
| 5 | +import lombok.EqualsAndHashCode; | |
| 6 | +import lombok.ToString; | |
| 14 | 7 | @Schema(description = "管理后台 - 秒杀参与商品创建 Request VO") |
| 15 | 8 | @Data |
| 16 | 9 | @EqualsAndHashCode(callSuper = true) | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductRespVO.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product; |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import lombok.*; | |
| 4 | +import lombok.Data; | |
| 5 | +import lombok.EqualsAndHashCode; | |
| 6 | +import lombok.ToString; | |
| 7 | + | |
| 5 | 8 | import java.time.LocalDateTime; |
| 6 | 9 | |
| 7 | -/** | |
| 8 | - * 管理后台 - 秒杀参与商品 Response VO | |
| 9 | - * | |
| 10 | - * @author HUIHUI | |
| 11 | - */ | |
| 12 | 10 | @Schema(description = "管理后台 - 秒杀参与商品 Response VO") |
| 13 | 11 | @Data |
| 14 | 12 | @EqualsAndHashCode(callSuper = true) | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductUpdateReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product; |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import lombok.*; | |
| 5 | -import javax.validation.constraints.*; | |
| 4 | +import lombok.Data; | |
| 5 | +import lombok.EqualsAndHashCode; | |
| 6 | +import lombok.ToString; | |
| 6 | 7 | |
| 7 | -/** | |
| 8 | - * 管理后台 - 秒杀参与商品更新 Request VO | |
| 9 | - * | |
| 10 | - * @author HUIHUI | |
| 11 | - */ | |
| 12 | 8 | @Schema(description = "管理后台 - 秒杀参与商品更新 Request VO") |
| 13 | 9 | @Data |
| 14 | 10 | @EqualsAndHashCode(callSuper = true) |
| 15 | 11 | @ToString(callSuper = true) |
| 16 | 12 | public class SeckillProductUpdateReqVO extends SeckillProductBaseVO { |
| 17 | 13 | |
| 18 | - @Schema(description = "秒杀参与商品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "256") | |
| 19 | - @NotNull(message = "秒杀参与商品编号不能为空") | |
| 20 | - private Long id; | |
| 21 | - | |
| 22 | 14 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.convert.combination; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 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.dto.ProductSpuRespDTO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordReqDTO; | |
| 8 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; | |
| 9 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityExcelVO; | |
| 10 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO; | |
| 11 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; | |
| 12 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductBaseVO; | |
| 13 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductRespVO; | |
| 14 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductUpdateReqVO; | |
| 15 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; | |
| 16 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; | |
| 17 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationRecordDO; | |
| 18 | +import org.mapstruct.Mapper; | |
| 19 | +import org.mapstruct.Mapping; | |
| 20 | +import org.mapstruct.Mappings; | |
| 21 | +import org.mapstruct.Named; | |
| 22 | +import org.mapstruct.factory.Mappers; | |
| 23 | + | |
| 24 | +import java.time.LocalDateTime; | |
| 25 | +import java.util.ArrayList; | |
| 26 | +import java.util.List; | |
| 27 | +import java.util.Map; | |
| 28 | + | |
| 29 | +/** | |
| 30 | + * 拼团活动 Convert | |
| 31 | + * | |
| 32 | + * @author HUIHUI | |
| 33 | + */ | |
| 34 | +@Mapper | |
| 35 | +public interface CombinationActivityConvert { | |
| 36 | + | |
| 37 | + CombinationActivityConvert INSTANCE = Mappers.getMapper(CombinationActivityConvert.class); | |
| 38 | + | |
| 39 | + @Mappings({ | |
| 40 | + @Mapping(target = "startTime", expression = "java(bean.getActivityTime()[0])"), | |
| 41 | + @Mapping(target = "endTime", expression = "java(bean.getActivityTime()[1])") | |
| 42 | + }) | |
| 43 | + CombinationActivityDO convert(CombinationActivityCreateReqVO bean); | |
| 44 | + | |
| 45 | + @Mappings({ | |
| 46 | + @Mapping(target = "startTime", expression = "java(bean.getActivityTime()[0])"), | |
| 47 | + @Mapping(target = "endTime", expression = "java(bean.getActivityTime()[1])") | |
| 48 | + }) | |
| 49 | + CombinationActivityDO convert(CombinationActivityUpdateReqVO bean); | |
| 50 | + | |
| 51 | + @Named("mergeTime") | |
| 52 | + default LocalDateTime[] mergeTime(LocalDateTime startTime, LocalDateTime endTime) { | |
| 53 | + // TODO 有点怪第一次这样写 hh | |
| 54 | + LocalDateTime[] localDateTime = new LocalDateTime[2]; | |
| 55 | + localDateTime[0] = startTime; | |
| 56 | + localDateTime[1] = endTime; | |
| 57 | + return localDateTime; | |
| 58 | + } | |
| 59 | + | |
| 60 | + @Mappings({ | |
| 61 | + @Mapping(target = "activityTime", expression = "java(mergeTime(bean.getStartTime(),bean.getEndTime()))") | |
| 62 | + }) | |
| 63 | + CombinationActivityRespVO convert(CombinationActivityDO bean); | |
| 64 | + | |
| 65 | + CombinationProductRespVO convert(CombinationProductDO bean); | |
| 66 | + | |
| 67 | + default CombinationActivityRespVO convert(CombinationActivityDO bean, List<CombinationProductDO> productDOs) { | |
| 68 | + CombinationActivityRespVO respVO = convert(bean); | |
| 69 | + respVO.setProducts(convertList2(productDOs)); | |
| 70 | + return respVO; | |
| 71 | + } | |
| 72 | + | |
| 73 | + List<CombinationActivityRespVO> convertList(List<CombinationActivityDO> list); | |
| 74 | + | |
| 75 | + PageResult<CombinationActivityRespVO> convertPage(PageResult<CombinationActivityDO> page); | |
| 76 | + | |
| 77 | + default PageResult<CombinationActivityRespVO> convertPage(PageResult<CombinationActivityDO> page, List<CombinationProductDO> productDOList, List<ProductSpuRespDTO> spuList) { | |
| 78 | + Map<Long, ProductSpuRespDTO> spuMap = CollectionUtils.convertMap(spuList, ProductSpuRespDTO::getId, c -> c); | |
| 79 | + PageResult<CombinationActivityRespVO> pageResult = convertPage(page); | |
| 80 | + pageResult.getList().forEach(item -> { | |
| 81 | + item.setSpuName(spuMap.get(item.getSpuId()).getName()); | |
| 82 | + item.setPicUrl(spuMap.get(item.getSpuId()).getPicUrl()); | |
| 83 | + item.setProducts(convertList2(productDOList)); | |
| 84 | + }); | |
| 85 | + return pageResult; | |
| 86 | + } | |
| 87 | + | |
| 88 | + List<CombinationProductRespVO> convertList2(List<CombinationProductDO> productDOs); | |
| 89 | + | |
| 90 | + List<CombinationActivityExcelVO> convertList02(List<CombinationActivityDO> list); | |
| 91 | + | |
| 92 | + @Mappings({ | |
| 93 | + @Mapping(target = "id", ignore = true), | |
| 94 | + @Mapping(target = "activityId", source = "activityDO.id"), | |
| 95 | + @Mapping(target = "spuId", source = "activityDO.spuId"), | |
| 96 | + @Mapping(target = "skuId", source = "vo.skuId"), | |
| 97 | + @Mapping(target = "activePrice", source = "vo.activePrice"), | |
| 98 | + @Mapping(target = "activityStartTime", source = "activityDO.startTime"), | |
| 99 | + @Mapping(target = "activityEndTime", source = "activityDO.endTime") | |
| 100 | + }) | |
| 101 | + CombinationProductDO convert(CombinationActivityDO activityDO, CombinationProductBaseVO vo); | |
| 102 | + | |
| 103 | + default List<CombinationProductDO> convertList(CombinationActivityDO activityDO, List<? extends CombinationProductBaseVO> products) { | |
| 104 | + List<CombinationProductDO> list = new ArrayList<>(); | |
| 105 | + products.forEach(sku -> { | |
| 106 | + CombinationProductDO productDO = convert(activityDO, sku); | |
| 107 | + // TODO 状态设置 | |
| 108 | + productDO.setActivityStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 109 | + list.add(productDO); | |
| 110 | + }); | |
| 111 | + return list; | |
| 112 | + } | |
| 113 | + | |
| 114 | + default List<CombinationProductDO> convertList1(CombinationActivityDO activityDO, List<CombinationProductUpdateReqVO> vos, List<CombinationProductDO> productDOs) { | |
| 115 | + Map<Long, Long> longMap = CollectionUtils.convertMap(productDOs, CombinationProductDO::getSkuId, CombinationProductDO::getId); | |
| 116 | + List<CombinationProductDO> list = new ArrayList<>(); | |
| 117 | + vos.forEach(sku -> { | |
| 118 | + CombinationProductDO productDO = convert(activityDO, sku); | |
| 119 | + productDO.setId(longMap.get(sku.getSkuId())); | |
| 120 | + productDO.setActivityStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 121 | + list.add(productDO); | |
| 122 | + }); | |
| 123 | + return list; | |
| 124 | + } | |
| 125 | + | |
| 126 | + CombinationRecordDO convert(CombinationRecordReqDTO reqDTO); | |
| 127 | + | |
| 128 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.util.ObjectUtil; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | 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.dto.ProductSpuRespDTO; | |
| 6 | 7 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO; |
| 7 | 8 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityDetailRespVO; |
| 8 | 9 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityRespVO; |
| 9 | 10 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO; |
| 10 | -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductCreateReqVO; | |
| 11 | +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductBaseVO; | |
| 12 | +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductRespVO; | |
| 13 | +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductUpdateReqVO; | |
| 11 | 14 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; |
| 12 | 15 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; |
| 13 | 16 | import org.mapstruct.Mapper; |
| 17 | +import org.mapstruct.Mapping; | |
| 18 | +import org.mapstruct.Mappings; | |
| 14 | 19 | import org.mapstruct.factory.Mappers; |
| 15 | 20 | |
| 16 | 21 | import java.util.ArrayList; |
| 17 | 22 | import java.util.List; |
| 23 | +import java.util.Map; | |
| 18 | 24 | |
| 19 | 25 | /** |
| 20 | 26 | * 秒杀活动 Convert |
| ... | ... | @@ -26,8 +32,6 @@ public interface SeckillActivityConvert { |
| 26 | 32 | |
| 27 | 33 | SeckillActivityConvert INSTANCE = Mappers.getMapper(SeckillActivityConvert.class); |
| 28 | 34 | |
| 29 | - SeckillProductDO convert(SeckillProductCreateReqVO product); | |
| 30 | - | |
| 31 | 35 | SeckillActivityDO convert(SeckillActivityCreateReqVO bean); |
| 32 | 36 | |
| 33 | 37 | SeckillActivityDO convert(SeckillActivityUpdateReqVO bean); |
| ... | ... | @@ -38,53 +42,60 @@ public interface SeckillActivityConvert { |
| 38 | 42 | |
| 39 | 43 | PageResult<SeckillActivityRespVO> convertPage(PageResult<SeckillActivityDO> page); |
| 40 | 44 | |
| 41 | - SeckillActivityDetailRespVO convert(SeckillActivityDO seckillActivity, List<SeckillProductDO> seckillProducts); | |
| 42 | - | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * 比较两个秒杀商品对象是否相等 | |
| 46 | - * | |
| 47 | - * @param productDO 数据库中的商品 | |
| 48 | - * @param productVO 前端传入的商品 | |
| 49 | - * @return 是否匹配 | |
| 50 | - */ | |
| 51 | - default boolean isEquals(SeckillProductDO productDO, SeckillProductCreateReqVO productVO) { | |
| 52 | - return ObjectUtil.equals(productDO.getSpuId(), 1) // TODO puhui:再看看 | |
| 53 | - && ObjectUtil.equals(productDO.getSkuId(), productVO.getSkuId()) | |
| 54 | - && ObjectUtil.equals(productDO.getSeckillPrice(), productVO.getSeckillPrice()); | |
| 55 | - //&& ObjectUtil.equals(productDO.getQuota(), productVO.getQuota()) | |
| 56 | - //&& ObjectUtil.equals(productDO.getLimitCount(), productVO.getLimitCount()); | |
| 45 | + default PageResult<SeckillActivityRespVO> convertPage(PageResult<SeckillActivityDO> page, List<SeckillProductDO> seckillProducts, List<ProductSpuRespDTO> spuList) { | |
| 46 | + Map<Long, ProductSpuRespDTO> spuMap = CollectionUtils.convertMap(spuList, ProductSpuRespDTO::getId, c -> c); | |
| 47 | + PageResult<SeckillActivityRespVO> pageResult = convertPage(page); | |
| 48 | + pageResult.getList().forEach(item -> { | |
| 49 | + item.setSpuName(spuMap.get(item.getSpuId()).getName()); | |
| 50 | + item.setPicUrl(spuMap.get(item.getSpuId()).getPicUrl()); | |
| 51 | + item.setProducts(convertList2(seckillProducts)); | |
| 52 | + }); | |
| 53 | + return pageResult; | |
| 57 | 54 | } |
| 58 | 55 | |
| 59 | - /** | |
| 60 | - * 比较两个秒杀商品对象是否相等 | |
| 61 | - * | |
| 62 | - * @param productDO 商品1 | |
| 63 | - * @param productVO 商品2 | |
| 64 | - * @return 是否匹配 | |
| 65 | - */ | |
| 66 | - default boolean isEquals(SeckillProductDO productDO, SeckillProductDO productVO) { | |
| 67 | - return ObjectUtil.equals(productDO.getSpuId(), productVO.getSpuId()) | |
| 68 | - && ObjectUtil.equals(productDO.getSkuId(), productVO.getSkuId()) | |
| 69 | - && ObjectUtil.equals(productDO.getSeckillPrice(), productVO.getSeckillPrice()); | |
| 70 | - //&& ObjectUtil.equals(productDO.getQuota(), productVO.getQuota()) | |
| 71 | - //&& ObjectUtil.equals(productDO.getLimitCount(), productVO.getLimitCount()); | |
| 56 | + SeckillActivityDetailRespVO convert1(SeckillActivityDO seckillActivity); | |
| 57 | + | |
| 58 | + default SeckillActivityDetailRespVO convert(SeckillActivityDO seckillActivity, List<SeckillProductDO> seckillProducts) { | |
| 59 | + SeckillActivityDetailRespVO respVO = convert1(seckillActivity); | |
| 60 | + respVO.setProducts(convertList2(seckillProducts)); | |
| 61 | + return respVO; | |
| 72 | 62 | } |
| 73 | 63 | |
| 74 | - default List<SeckillProductDO> convertList(SeckillActivityDO seckillActivity, List<SeckillProductCreateReqVO> products) { | |
| 64 | + @Mappings({ | |
| 65 | + @Mapping(target = "id", ignore = true), | |
| 66 | + @Mapping(target = "activityId", source = "activityDO.id"), | |
| 67 | + @Mapping(target = "configIds", source = "activityDO.configIds"), | |
| 68 | + @Mapping(target = "spuId", source = "activityDO.spuId"), | |
| 69 | + @Mapping(target = "skuId", source = "vo.skuId"), | |
| 70 | + @Mapping(target = "seckillPrice", source = "vo.seckillPrice"), | |
| 71 | + @Mapping(target = "stock", source = "vo.stock"), | |
| 72 | + @Mapping(target = "activityStartTime", source = "activityDO.startTime"), | |
| 73 | + @Mapping(target = "activityEndTime", source = "activityDO.endTime") | |
| 74 | + }) | |
| 75 | + SeckillProductDO convert(SeckillActivityDO activityDO, SeckillProductBaseVO vo); | |
| 76 | + | |
| 77 | + default List<SeckillProductDO> convertList(SeckillActivityDO activityDO, List<? extends SeckillProductBaseVO> products) { | |
| 75 | 78 | List<SeckillProductDO> list = new ArrayList<>(); |
| 76 | 79 | products.forEach(sku -> { |
| 77 | - SeckillProductDO productDO = new SeckillProductDO(); | |
| 78 | - productDO.setActivityId(seckillActivity.getId()); | |
| 79 | - productDO.setConfigIds(seckillActivity.getConfigIds()); | |
| 80 | - productDO.setSpuId(sku.getSpuId()); | |
| 81 | - productDO.setSkuId(sku.getSkuId()); | |
| 82 | - productDO.setSeckillPrice(sku.getSeckillPrice()); | |
| 83 | - productDO.setStock(sku.getStock()); | |
| 80 | + SeckillProductDO productDO = convert(activityDO, sku); | |
| 81 | + productDO.setActivityStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 82 | + list.add(productDO); | |
| 83 | + }); | |
| 84 | + return list; | |
| 85 | + } | |
| 86 | + | |
| 87 | + default List<SeckillProductDO> convertList1(SeckillActivityDO activityDO, List<SeckillProductUpdateReqVO> vos, List<SeckillProductDO> productDOs) { | |
| 88 | + Map<Long, Long> longMap = CollectionUtils.convertMap(productDOs, SeckillProductDO::getSkuId, SeckillProductDO::getId); | |
| 89 | + List<SeckillProductDO> list = new ArrayList<>(); | |
| 90 | + vos.forEach(sku -> { | |
| 91 | + SeckillProductDO productDO = convert(activityDO, sku); | |
| 92 | + productDO.setId(longMap.get(sku.getSkuId())); | |
| 84 | 93 | productDO.setActivityStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 85 | - productDO.setActivityStartTime(seckillActivity.getStartTime()); | |
| 86 | - productDO.setActivityEndTime(seckillActivity.getEndTime()); | |
| 94 | + list.add(productDO); | |
| 87 | 95 | }); |
| 88 | 96 | return list; |
| 89 | 97 | } |
| 98 | + | |
| 99 | + List<SeckillProductRespVO> convertList2(List<SeckillProductDO> productDOs); | |
| 100 | + | |
| 90 | 101 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationActivityDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 5 | +import com.baomidou.mybatisplus.annotation.KeySequence; | |
| 6 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 7 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 8 | +import lombok.*; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 拼团活动 DO | |
| 14 | + * | |
| 15 | + * @author HUIHUI | |
| 16 | + */ | |
| 17 | +@TableName("promotion_combination_activity") | |
| 18 | +@KeySequence("promotion_combination_activity_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 19 | +@Data | |
| 20 | +@EqualsAndHashCode(callSuper = true) | |
| 21 | +@ToString(callSuper = true) | |
| 22 | +@Builder | |
| 23 | +@NoArgsConstructor | |
| 24 | +@AllArgsConstructor | |
| 25 | +public class CombinationActivityDO extends BaseDO { | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * 活动编号 | |
| 29 | + */ | |
| 30 | + @TableId | |
| 31 | + private Long id; | |
| 32 | + /** | |
| 33 | + * 拼团名称 | |
| 34 | + */ | |
| 35 | + private String name; | |
| 36 | + /** | |
| 37 | + * 商品 SPU 编号关联 ProductSpuDO 的 id | |
| 38 | + */ | |
| 39 | + private Long spuId; | |
| 40 | + /** | |
| 41 | + * 总限购数量 | |
| 42 | + */ | |
| 43 | + private Integer totalLimitCount; | |
| 44 | + /** | |
| 45 | + * 单次限购数量 | |
| 46 | + */ | |
| 47 | + private Integer singleLimitCount; | |
| 48 | + /** | |
| 49 | + * 开始时间 | |
| 50 | + */ | |
| 51 | + private LocalDateTime startTime; | |
| 52 | + /** | |
| 53 | + * 结束时间 | |
| 54 | + */ | |
| 55 | + private LocalDateTime endTime; | |
| 56 | + /** | |
| 57 | + * 几人团 | |
| 58 | + */ | |
| 59 | + private Integer userSize; | |
| 60 | + /** | |
| 61 | + * 开团组数 | |
| 62 | + */ | |
| 63 | + private Integer totalNum; | |
| 64 | + /** | |
| 65 | + * 成团组数 | |
| 66 | + */ | |
| 67 | + private Integer successNum; | |
| 68 | + /** | |
| 69 | + * 参与人数 | |
| 70 | + */ | |
| 71 | + private Integer orderUserCount; | |
| 72 | + /** | |
| 73 | + * 虚拟成团 | |
| 74 | + */ | |
| 75 | + private Integer virtualGroup; | |
| 76 | + /** | |
| 77 | + * 活动状态:0开启 1关闭 | |
| 78 | + * <p> | |
| 79 | + * 枚举 {@link CommonStatusEnum} | |
| 80 | + */ | |
| 81 | + private Integer status; | |
| 82 | + /** | |
| 83 | + * 限制时长(小时) | |
| 84 | + */ | |
| 85 | + private Integer limitDuration; | |
| 86 | + | |
| 87 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationProductDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 4 | +import com.baomidou.mybatisplus.annotation.KeySequence; | |
| 5 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 6 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 7 | +import lombok.*; | |
| 8 | + | |
| 9 | +import java.time.LocalDateTime; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * 拼团商品 DO | |
| 13 | + * | |
| 14 | + * @author HUIHUI | |
| 15 | + */ | |
| 16 | +@TableName("promotion_combination_product") | |
| 17 | +@KeySequence("promotion_combination_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 18 | +@Data | |
| 19 | +@EqualsAndHashCode(callSuper = true) | |
| 20 | +@ToString(callSuper = true) | |
| 21 | +@Builder | |
| 22 | +@NoArgsConstructor | |
| 23 | +@AllArgsConstructor | |
| 24 | +public class CombinationProductDO extends BaseDO { | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 编号 | |
| 28 | + */ | |
| 29 | + @TableId | |
| 30 | + private Long id; | |
| 31 | + /** | |
| 32 | + * 拼团活动编号 | |
| 33 | + */ | |
| 34 | + private Long activityId; | |
| 35 | + /** | |
| 36 | + * 商品 SPU 编号 | |
| 37 | + */ | |
| 38 | + private Long spuId; | |
| 39 | + /** | |
| 40 | + * 商品 SKU 编号 | |
| 41 | + */ | |
| 42 | + private Long skuId; | |
| 43 | + /** | |
| 44 | + * 拼团商品状态 | |
| 45 | + */ | |
| 46 | + private Integer activityStatus; | |
| 47 | + /** | |
| 48 | + * 活动开始时间点 | |
| 49 | + */ | |
| 50 | + private LocalDateTime activityStartTime; | |
| 51 | + /** | |
| 52 | + * 活动结束时间点 | |
| 53 | + */ | |
| 54 | + private LocalDateTime activityEndTime; | |
| 55 | + /** | |
| 56 | + * 拼团价格,单位分 | |
| 57 | + */ | |
| 58 | + private Integer activePrice; | |
| 59 | + | |
| 60 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationRecordDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 4 | +import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; | |
| 5 | +import com.baomidou.mybatisplus.annotation.KeySequence; | |
| 6 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 7 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 8 | +import lombok.*; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 拼团记录 DO | |
| 14 | + * | |
| 15 | + * @author HUIHUI | |
| 16 | + */ | |
| 17 | +@TableName("promotion_combination_record") | |
| 18 | +@KeySequence("promotion_combination_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 19 | +@Data | |
| 20 | +@EqualsAndHashCode(callSuper = true) | |
| 21 | +@ToString(callSuper = true) | |
| 22 | +@Builder | |
| 23 | +@NoArgsConstructor | |
| 24 | +@AllArgsConstructor | |
| 25 | +public class CombinationRecordDO extends BaseDO { | |
| 26 | + | |
| 27 | + @TableId | |
| 28 | + private Long id; | |
| 29 | + /** | |
| 30 | + * 拼团活动编号 | |
| 31 | + */ | |
| 32 | + private Long activityId; | |
| 33 | + /** | |
| 34 | + * spu 编号 | |
| 35 | + */ | |
| 36 | + private Long spuId; | |
| 37 | + /** | |
| 38 | + * sku 编号 | |
| 39 | + */ | |
| 40 | + private Long skuId; | |
| 41 | + /** | |
| 42 | + * 用户编号 | |
| 43 | + */ | |
| 44 | + private Long userId; | |
| 45 | + /** | |
| 46 | + * 订单编号 | |
| 47 | + */ | |
| 48 | + private Long orderId; | |
| 49 | + /** | |
| 50 | + * 团长编号 | |
| 51 | + * <p> | |
| 52 | + * 关联 {@link CombinationRecordDO#getUserId()} | |
| 53 | + */ | |
| 54 | + private Long headId; | |
| 55 | + /** | |
| 56 | + * 商品名字 | |
| 57 | + */ | |
| 58 | + private String spuName; | |
| 59 | + /** | |
| 60 | + * 商品图片 | |
| 61 | + */ | |
| 62 | + private String picUrl; | |
| 63 | + /** | |
| 64 | + * 拼团商品单价 | |
| 65 | + */ | |
| 66 | + private Integer combinationPrice; | |
| 67 | + /** | |
| 68 | + * 用户昵称 | |
| 69 | + */ | |
| 70 | + private String nickname; | |
| 71 | + /** | |
| 72 | + * 用户头像 | |
| 73 | + */ | |
| 74 | + private String avatar; | |
| 75 | + /** | |
| 76 | + * 开团状态 | |
| 77 | + * | |
| 78 | + * 关联 {@link CombinationRecordStatusEnum} | |
| 79 | + */ | |
| 80 | + private Integer status; | |
| 81 | + /** | |
| 82 | + * 是否虚拟成团 | |
| 83 | + */ | |
| 84 | + private Boolean virtualGroup; | |
| 85 | + /** | |
| 86 | + * 过期时间,单位:小时 | |
| 87 | + * 关联关联 {@link CombinationActivityDO#getLimitDuration()} | |
| 88 | + */ | |
| 89 | + private Integer expireTime; | |
| 90 | + /** | |
| 91 | + * 开始时间 (订单付款后开始的时间) | |
| 92 | + */ | |
| 93 | + private LocalDateTime startTime; | |
| 94 | + /** | |
| 95 | + * 结束时间(成团时间/失败时间) | |
| 96 | + */ | |
| 97 | + private LocalDateTime endTime; | |
| 98 | + /** | |
| 99 | + * 开团需要人数 | |
| 100 | + * 关联 {@link CombinationActivityDO#getUserSize()} | |
| 101 | + */ | |
| 102 | + private Integer userSize; | |
| 103 | + /** | |
| 104 | + * 已加入拼团人数 | |
| 105 | + */ | |
| 106 | + private Integer userCount; | |
| 107 | + | |
| 108 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/package-info.java
0 → 100644
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillconfig/SeckillConfigDO.java
| ... | ... | @@ -3,22 +3,27 @@ package cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillconfig; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 5 | 5 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 6 | +import com.baomidou.mybatisplus.annotation.TableField; | |
| 6 | 7 | import com.baomidou.mybatisplus.annotation.TableId; |
| 7 | 8 | import com.baomidou.mybatisplus.annotation.TableName; |
| 8 | -import lombok.Data; | |
| 9 | -import lombok.EqualsAndHashCode; | |
| 10 | -import lombok.ToString; | |
| 9 | +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | |
| 10 | +import lombok.*; | |
| 11 | + | |
| 12 | +import java.util.List; | |
| 11 | 13 | |
| 12 | 14 | /** |
| 13 | 15 | * 秒杀时段 DO |
| 14 | 16 | * |
| 15 | 17 | * @author 芋道源码 |
| 16 | 18 | */ |
| 17 | -@TableName("promotion_seckill_config") | |
| 19 | +@TableName(value = "promotion_seckill_config", autoResultMap = true) | |
| 18 | 20 | @KeySequence("promotion_seckill_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 |
| 19 | 21 | @Data |
| 20 | 22 | @EqualsAndHashCode(callSuper = true) |
| 21 | 23 | @ToString(callSuper = true) |
| 24 | +@Builder | |
| 25 | +@NoArgsConstructor | |
| 26 | +@AllArgsConstructor | |
| 22 | 27 | public class SeckillConfigDO extends BaseDO { |
| 23 | 28 | |
| 24 | 29 | /** |
| ... | ... | @@ -38,14 +43,14 @@ public class SeckillConfigDO extends BaseDO { |
| 38 | 43 | * 结束时间点 |
| 39 | 44 | */ |
| 40 | 45 | private String endTime; |
| 41 | - // TODO puhui999:应该是轮播图; private List<String> sliderPicUrls; | |
| 42 | 46 | /** |
| 43 | - * 秒杀主图 | |
| 47 | + * 秒杀轮播图 | |
| 44 | 48 | */ |
| 45 | - private String picUrl; | |
| 49 | + @TableField(typeHandler = JacksonTypeHandler.class) | |
| 50 | + private List<String> sliderPicUrls; | |
| 46 | 51 | /** |
| 47 | 52 | * 状态 |
| 48 | - * | |
| 53 | + * <p> | |
| 49 | 54 | * 枚举 {@link CommonStatusEnum 对应的类} |
| 50 | 55 | */ |
| 51 | 56 | private Integer status; | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationActivityMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityExportReqVO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; | |
| 8 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | + | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * 拼团活动 Mapper | |
| 15 | + * | |
| 16 | + * @author HUIHUI | |
| 17 | + */ | |
| 18 | +@Mapper | |
| 19 | +public interface CombinationActivityMapper extends BaseMapperX<CombinationActivityDO> { | |
| 20 | + | |
| 21 | + default PageResult<CombinationActivityDO> selectPage(CombinationActivityPageReqVO reqVO) { | |
| 22 | + return selectPage(reqVO, new LambdaQueryWrapperX<CombinationActivityDO>() | |
| 23 | + .likeIfPresent(CombinationActivityDO::getName, reqVO.getName()) | |
| 24 | + .orderByDesc(CombinationActivityDO::getId)); | |
| 25 | + } | |
| 26 | + | |
| 27 | + default List<CombinationActivityDO> selectList(CombinationActivityExportReqVO reqVO) { | |
| 28 | + return selectList(new LambdaQueryWrapperX<CombinationActivityDO>() | |
| 29 | + .likeIfPresent(CombinationActivityDO::getName, reqVO.getName()) | |
| 30 | + .eqIfPresent(CombinationActivityDO::getStatus, reqVO.getStatus()) | |
| 31 | + .orderByDesc(CombinationActivityDO::getId)); | |
| 32 | + } | |
| 33 | + | |
| 34 | + default List<CombinationActivityDO> selectListByStatus(Integer status) { | |
| 35 | + return selectList(CombinationActivityDO::getStatus, status); | |
| 36 | + } | |
| 37 | + | |
| 38 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductExportReqVO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductPageReqVO; | |
| 8 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | + | |
| 11 | +import java.util.Collection; | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * 拼团商品 Mapper | |
| 16 | + * | |
| 17 | + * @author HUIHUI | |
| 18 | + */ | |
| 19 | +@Mapper | |
| 20 | +public interface CombinationProductMapper extends BaseMapperX<CombinationProductDO> { | |
| 21 | + | |
| 22 | + default PageResult<CombinationProductDO> selectPage(CombinationProductPageReqVO reqVO) { | |
| 23 | + return selectPage(reqVO, new LambdaQueryWrapperX<CombinationProductDO>() | |
| 24 | + .eqIfPresent(CombinationProductDO::getActivityId, reqVO.getActivityId()) | |
| 25 | + .eqIfPresent(CombinationProductDO::getSpuId, reqVO.getSpuId()) | |
| 26 | + .eqIfPresent(CombinationProductDO::getSkuId, reqVO.getSkuId()) | |
| 27 | + .eqIfPresent(CombinationProductDO::getActivityStatus, reqVO.getActivityStatus()) | |
| 28 | + .betweenIfPresent(CombinationProductDO::getActivityStartTime, reqVO.getActivityStartTime()) | |
| 29 | + .betweenIfPresent(CombinationProductDO::getActivityEndTime, reqVO.getActivityEndTime()) | |
| 30 | + .eqIfPresent(CombinationProductDO::getActivePrice, reqVO.getActivePrice()) | |
| 31 | + .betweenIfPresent(CombinationProductDO::getCreateTime, reqVO.getCreateTime()) | |
| 32 | + .orderByDesc(CombinationProductDO::getId)); | |
| 33 | + } | |
| 34 | + | |
| 35 | + default List<CombinationProductDO> selectList(CombinationProductExportReqVO reqVO) { | |
| 36 | + return selectList(new LambdaQueryWrapperX<CombinationProductDO>() | |
| 37 | + .eqIfPresent(CombinationProductDO::getActivityId, reqVO.getActivityId()) | |
| 38 | + .eqIfPresent(CombinationProductDO::getSpuId, reqVO.getSpuId()) | |
| 39 | + .eqIfPresent(CombinationProductDO::getSkuId, reqVO.getSkuId()) | |
| 40 | + .eqIfPresent(CombinationProductDO::getActivityStatus, reqVO.getActivityStatus()) | |
| 41 | + .betweenIfPresent(CombinationProductDO::getActivityStartTime, reqVO.getActivityStartTime()) | |
| 42 | + .betweenIfPresent(CombinationProductDO::getActivityEndTime, reqVO.getActivityEndTime()) | |
| 43 | + .eqIfPresent(CombinationProductDO::getActivePrice, reqVO.getActivePrice()) | |
| 44 | + .betweenIfPresent(CombinationProductDO::getCreateTime, reqVO.getCreateTime()) | |
| 45 | + .orderByDesc(CombinationProductDO::getId)); | |
| 46 | + } | |
| 47 | + | |
| 48 | + default List<CombinationProductDO> selectListByActivityIds(Collection<Long> ids) { | |
| 49 | + return selectList(CombinationProductDO::getActivityId, ids); | |
| 50 | + } | |
| 51 | + | |
| 52 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationRecordMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 5 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationRecordDO; | |
| 6 | +import org.apache.ibatis.annotations.Mapper; | |
| 7 | + | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 拼团记录 Mapper | |
| 12 | + * | |
| 13 | + * @author HUIHUI | |
| 14 | + */ | |
| 15 | +@Mapper | |
| 16 | +public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO> { | |
| 17 | + | |
| 18 | + default CombinationRecordDO selectRecord(Long userId, Long orderId) { | |
| 19 | + return selectOne(CombinationRecordDO::getUserId, userId, CombinationRecordDO::getOrderId, orderId); | |
| 20 | + } | |
| 21 | + | |
| 22 | + default List<CombinationRecordDO> selectListByHeadIdAndStatus(Long headId, Integer status) { | |
| 23 | + return selectList(new LambdaQueryWrapperX<CombinationRecordDO>().eq(CombinationRecordDO::getHeadId, headId) | |
| 24 | + .eq(CombinationRecordDO::getStatus, status)); | |
| 25 | + } | |
| 26 | + | |
| 27 | + default List<CombinationRecordDO> selectListByStatus(Integer status) { | |
| 28 | + return selectList(new LambdaQueryWrapperX<CombinationRecordDO>().eq(CombinationRecordDO::getStatus, status)); | |
| 29 | + } | |
| 30 | + | |
| 31 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/package-info.java
0 → 100644
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java
| ... | ... | @@ -21,6 +21,10 @@ public interface SeckillProductMapper extends BaseMapperX<SeckillProductDO> { |
| 21 | 21 | return selectList(SeckillProductDO::getActivityId, id); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | + default List<SeckillProductDO> selectListByActivityId(Collection<Long> ids) { | |
| 25 | + return selectList(SeckillProductDO::getActivityId, ids); | |
| 26 | + } | |
| 27 | + | |
| 24 | 28 | default List<SeckillProductDO> selectListBySkuIds(Collection<Long> skuIds) { |
| 25 | 29 | return selectList(SeckillProductDO::getSkuId, skuIds); |
| 26 | 30 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillconfig/SeckillConfigMapper.java
| ... | ... | @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.Seck |
| 7 | 7 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillconfig.SeckillConfigDO; |
| 8 | 8 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 9 | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 10 | 12 | @Mapper |
| 11 | 13 | public interface SeckillConfigMapper extends BaseMapperX<SeckillConfigDO> { |
| 12 | 14 | |
| ... | ... | @@ -17,4 +19,9 @@ public interface SeckillConfigMapper extends BaseMapperX<SeckillConfigDO> { |
| 17 | 19 | .orderByDesc(SeckillConfigDO::getId)); |
| 18 | 20 | } |
| 19 | 21 | |
| 22 | + default List<SeckillConfigDO> selectListByStatus(Integer status) { | |
| 23 | + return selectList(SeckillConfigDO::getStatus, status); | |
| 24 | + } | |
| 25 | + | |
| 26 | + | |
| 20 | 27 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.service.combination; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordReqDTO; | |
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; | |
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityExportReqVO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; | |
| 8 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; | |
| 9 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; | |
| 10 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; | |
| 11 | + | |
| 12 | +import javax.validation.Valid; | |
| 13 | +import java.time.LocalDateTime; | |
| 14 | +import java.util.Collection; | |
| 15 | +import java.util.List; | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * 拼团活动 Service 接口 | |
| 19 | + * | |
| 20 | + * @author HUIHUI | |
| 21 | + */ | |
| 22 | +public interface CombinationActivityService { | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 创建拼团活动 | |
| 26 | + * | |
| 27 | + * @param createReqVO 创建信息 | |
| 28 | + * @return 编号 | |
| 29 | + */ | |
| 30 | + Long createCombinationActivity(@Valid CombinationActivityCreateReqVO createReqVO); | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * 更新拼团活动 | |
| 34 | + * | |
| 35 | + * @param updateReqVO 更新信息 | |
| 36 | + */ | |
| 37 | + void updateCombinationActivity(@Valid CombinationActivityUpdateReqVO updateReqVO); | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * 删除拼团活动 | |
| 41 | + * | |
| 42 | + * @param id 编号 | |
| 43 | + */ | |
| 44 | + void deleteCombinationActivity(Long id); | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * 获得拼团活动 | |
| 48 | + * | |
| 49 | + * @param id 编号 | |
| 50 | + * @return 拼团活动 | |
| 51 | + */ | |
| 52 | + CombinationActivityDO getCombinationActivity(Long id); | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * 获得拼团活动列表 | |
| 56 | + * | |
| 57 | + * @param ids 编号 | |
| 58 | + * @return 拼团活动列表 | |
| 59 | + */ | |
| 60 | + List<CombinationActivityDO> getCombinationActivityList(Collection<Long> ids); | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * 获得拼团活动分页 | |
| 64 | + * | |
| 65 | + * @param pageReqVO 分页查询 | |
| 66 | + * @return 拼团活动分页 | |
| 67 | + */ | |
| 68 | + PageResult<CombinationActivityDO> getCombinationActivityPage(CombinationActivityPageReqVO pageReqVO); | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * 获得拼团活动列表, 用于 Excel 导出 | |
| 72 | + * | |
| 73 | + * @param exportReqVO 查询条件 | |
| 74 | + * @return 拼团活动列表 | |
| 75 | + */ | |
| 76 | + List<CombinationActivityDO> getCombinationActivityList(CombinationActivityExportReqVO exportReqVO); | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * 获得拼团活动商品列表 | |
| 80 | + * | |
| 81 | + * @param ids 拼团活动 ids | |
| 82 | + * @return 拼团活动的商品列表 | |
| 83 | + */ | |
| 84 | + List<CombinationProductDO> getProductsByActivityIds(Collection<Long> ids); | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * 更新拼团状态 | |
| 88 | + * | |
| 89 | + * @param userId 用户编号 | |
| 90 | + * @param orderId 订单编号 | |
| 91 | + * @param status 状态 | |
| 92 | + */ | |
| 93 | + void updateRecordStatusByUserIdAndOrderId(Long userId, Long orderId, Integer status); | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * 更新拼团状态和开始时间 | |
| 97 | + * | |
| 98 | + * @param userId 用户编号 | |
| 99 | + * @param orderId 订单编号 | |
| 100 | + * @param status 状态 | |
| 101 | + * @param startTime 开始时间 | |
| 102 | + * @return | |
| 103 | + */ | |
| 104 | + void updateRecordStatusAndStartTimeByUserIdAndOrderId(Long userId, Long orderId, Integer status, LocalDateTime startTime); | |
| 105 | + | |
| 106 | + /** | |
| 107 | + * 创建拼团记录 | |
| 108 | + * | |
| 109 | + * @param reqDTO 创建信息 | |
| 110 | + */ | |
| 111 | + void createRecord(CombinationRecordReqDTO reqDTO); | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * 获得拼团状态 | |
| 115 | + * | |
| 116 | + * @param userId 用户编号 | |
| 117 | + * @param orderId 订单编号 | |
| 118 | + * @return 拼团状态 | |
| 119 | + */ | |
| 120 | + boolean validateRecordStatusIsSuccess(Long userId, Long orderId); | |
| 121 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.service.combination; | |
| 2 | + | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.hutool.core.collection.CollectionUtil; | |
| 5 | +import cn.hutool.core.util.ObjectUtil; | |
| 6 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 7 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 8 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 9 | +import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; | |
| 10 | +import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; | |
| 11 | +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; | |
| 12 | +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | |
| 13 | +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordReqDTO; | |
| 14 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; | |
| 15 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityExportReqVO; | |
| 16 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; | |
| 17 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; | |
| 18 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductCreateReqVO; | |
| 19 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductUpdateReqVO; | |
| 20 | +import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; | |
| 21 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; | |
| 22 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; | |
| 23 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationRecordDO; | |
| 24 | +import cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity.CombinationActivityMapper; | |
| 25 | +import cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity.CombinationProductMapper; | |
| 26 | +import cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity.CombinationRecordMapper; | |
| 27 | +import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; | |
| 28 | +import org.springframework.stereotype.Service; | |
| 29 | +import org.springframework.transaction.annotation.Transactional; | |
| 30 | +import org.springframework.validation.annotation.Validated; | |
| 31 | + | |
| 32 | +import javax.annotation.Resource; | |
| 33 | +import java.time.LocalDateTime; | |
| 34 | +import java.util.Collection; | |
| 35 | +import java.util.List; | |
| 36 | +import java.util.Set; | |
| 37 | + | |
| 38 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 39 | +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; | |
| 40 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; | |
| 41 | +import static cn.iocoder.yudao.module.promotion.util.PromotionUtils.validateProductSkuExistence; | |
| 42 | + | |
| 43 | +/** | |
| 44 | + * 拼团活动 Service 实现类 | |
| 45 | + * | |
| 46 | + * @author HUIHUI | |
| 47 | + */ | |
| 48 | +@Service | |
| 49 | +@Validated | |
| 50 | +public class CombinationActivityServiceImpl implements CombinationActivityService { | |
| 51 | + | |
| 52 | + @Resource | |
| 53 | + private CombinationActivityMapper combinationActivityMapper; | |
| 54 | + @Resource | |
| 55 | + private CombinationRecordMapper recordMapper; | |
| 56 | + @Resource | |
| 57 | + private CombinationProductMapper combinationProductMapper; | |
| 58 | + @Resource | |
| 59 | + private ProductSpuApi productSpuApi; | |
| 60 | + @Resource | |
| 61 | + private ProductSkuApi productSkuApi; | |
| 62 | + | |
| 63 | + @Override | |
| 64 | + public Long createCombinationActivity(CombinationActivityCreateReqVO createReqVO) { | |
| 65 | + // 校验商品 SPU 是否存在是否参加的别的活动 | |
| 66 | + validateProductCombinationConflict(createReqVO.getSpuId(), null); | |
| 67 | + // 获取所选 spu下的所有 sku | |
| 68 | + List<ProductSkuRespDTO> skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(createReqVO.getSpuId())); | |
| 69 | + // 校验商品 sku 是否存在 | |
| 70 | + validateProductSkuExistence(skus, createReqVO.getProducts(), CombinationProductCreateReqVO::getSkuId); | |
| 71 | + | |
| 72 | + // TODO 艿艿 有个小问题:现在有活动时间和限制时长,活动时间的结束时间早于设置的限制时间怎么算状态比如: | |
| 73 | + // 活动时间 2023-08-05 15:00:00 - 2023-08-05 15:20:00 限制时长 2小时,那么活动时间结束就结束还是加时到满两小时 | |
| 74 | + // 插入拼团活动 | |
| 75 | + CombinationActivityDO activityDO = CombinationActivityConvert.INSTANCE.convert(createReqVO); | |
| 76 | + // TODO 营销相关属性初始化 | |
| 77 | + activityDO.setTotalNum(0); | |
| 78 | + activityDO.setSuccessNum(0); | |
| 79 | + activityDO.setOrderUserCount(0); | |
| 80 | + activityDO.setVirtualGroup(0); | |
| 81 | + activityDO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 82 | + combinationActivityMapper.insert(activityDO); | |
| 83 | + // 插入商品 | |
| 84 | + List<CombinationProductDO> productDOs = CombinationActivityConvert.INSTANCE.convertList(activityDO, createReqVO.getProducts()); | |
| 85 | + combinationProductMapper.insertBatch(productDOs); | |
| 86 | + // 返回 | |
| 87 | + return activityDO.getId(); | |
| 88 | + } | |
| 89 | + | |
| 90 | + private void validateProductCombinationConflict(Long spuId, Long activityId) { | |
| 91 | + // 校验商品 spu 是否存在 | |
| 92 | + List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(CollUtil.newArrayList(spuId)); | |
| 93 | + if (CollUtil.isEmpty(spuList)) { | |
| 94 | + throw exception(SPU_NOT_EXISTS); | |
| 95 | + } | |
| 96 | + // 查询所有开启的拼团活动 | |
| 97 | + List<CombinationActivityDO> activityDOs = combinationActivityMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 98 | + // 更新时排除自己 | |
| 99 | + if (activityId != null) { | |
| 100 | + activityDOs.removeIf(item -> ObjectUtil.equal(item.getId(), activityId)); | |
| 101 | + } | |
| 102 | + // 过滤出所有 spuIds 有交集的活动 | |
| 103 | + List<CombinationActivityDO> doList = CollectionUtils.convertList(activityDOs, c -> c, s -> ObjectUtil.equal(s.getId(), spuId)); | |
| 104 | + if (CollUtil.isNotEmpty(doList)) { | |
| 105 | + throw exception(COMBINATION_ACTIVITY_SPU_CONFLICTS); | |
| 106 | + } | |
| 107 | + } | |
| 108 | + | |
| 109 | + @Override | |
| 110 | + public void updateCombinationActivity(CombinationActivityUpdateReqVO updateReqVO) { | |
| 111 | + // 校验存在 | |
| 112 | + CombinationActivityDO activityDO = validateCombinationActivityExists(updateReqVO.getId()); | |
| 113 | + // 校验状态 | |
| 114 | + if (ObjectUtil.equal(activityDO.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { | |
| 115 | + throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE); | |
| 116 | + } | |
| 117 | + // 校验商品冲突 | |
| 118 | + validateProductCombinationConflict(updateReqVO.getSpuId(), updateReqVO.getId()); | |
| 119 | + // 获取所选 spu下的所有 sku | |
| 120 | + List<ProductSkuRespDTO> skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(updateReqVO.getSpuId())); | |
| 121 | + // 校验商品 sku 是否存在 | |
| 122 | + validateProductSkuExistence(skus, updateReqVO.getProducts(), CombinationProductUpdateReqVO::getSkuId); | |
| 123 | + | |
| 124 | + // 更新 | |
| 125 | + CombinationActivityDO updateObj = CombinationActivityConvert.INSTANCE.convert(updateReqVO); | |
| 126 | + combinationActivityMapper.updateById(updateObj); | |
| 127 | + // 更新商品 | |
| 128 | + updateCombinationProduct(updateObj, updateReqVO.getProducts()); | |
| 129 | + } | |
| 130 | + | |
| 131 | + /** | |
| 132 | + * 更新秒杀商品 | |
| 133 | + * TODO 更新商品要不要封装成通用方法 | |
| 134 | + * | |
| 135 | + * @param updateObj DO | |
| 136 | + * @param products 商品配置 | |
| 137 | + */ | |
| 138 | + private void updateCombinationProduct(CombinationActivityDO updateObj, List<CombinationProductUpdateReqVO> products) { | |
| 139 | + List<CombinationProductDO> combinationProductDOs = combinationProductMapper.selectListByActivityIds(CollUtil.newArrayList(updateObj.getId())); | |
| 140 | + // 数据库中的活动商品 | |
| 141 | + Set<Long> convertSet = CollectionUtils.convertSet(combinationProductDOs, CombinationProductDO::getSkuId); | |
| 142 | + // 前端传过来的活动商品 | |
| 143 | + Set<Long> convertSet1 = CollectionUtils.convertSet(products, CombinationProductUpdateReqVO::getSkuId); | |
| 144 | + // 删除后台存在的前端不存在的商品 | |
| 145 | + List<Long> d = CollectionUtils.filterList(convertSet, item -> !convertSet1.contains(item)); | |
| 146 | + if (CollUtil.isNotEmpty(d)) { | |
| 147 | + combinationProductMapper.deleteBatchIds(d); | |
| 148 | + } | |
| 149 | + // 前端存在的后端不存在的商品 | |
| 150 | + List<Long> c = CollectionUtils.filterList(convertSet1, item -> !convertSet.contains(item)); | |
| 151 | + if (CollUtil.isNotEmpty(c)) { | |
| 152 | + List<CombinationProductUpdateReqVO> vos = CollectionUtils.filterList(products, item -> c.contains(item.getSkuId())); | |
| 153 | + List<CombinationProductDO> productDOs = CombinationActivityConvert.INSTANCE.convertList(updateObj, vos); | |
| 154 | + combinationProductMapper.insertBatch(productDOs); | |
| 155 | + } | |
| 156 | + // 更新已存在的商品 | |
| 157 | + List<Long> u = CollectionUtils.filterList(convertSet1, convertSet::contains); | |
| 158 | + if (CollUtil.isNotEmpty(u)) { | |
| 159 | + List<CombinationProductUpdateReqVO> vos = CollectionUtils.filterList(products, item -> u.contains(item.getSkuId())); | |
| 160 | + List<CombinationProductDO> productDOs = CombinationActivityConvert.INSTANCE.convertList1(updateObj, vos, combinationProductDOs); | |
| 161 | + combinationProductMapper.updateBatch(productDOs); | |
| 162 | + } | |
| 163 | + } | |
| 164 | + | |
| 165 | + @Override | |
| 166 | + public void deleteCombinationActivity(Long id) { | |
| 167 | + // 校验存在 | |
| 168 | + CombinationActivityDO activityDO = validateCombinationActivityExists(id); | |
| 169 | + // 校验状态 | |
| 170 | + if (ObjectUtil.equal(activityDO.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { | |
| 171 | + throw exception(COMBINATION_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END); | |
| 172 | + } | |
| 173 | + | |
| 174 | + // 删除 | |
| 175 | + combinationActivityMapper.deleteById(id); | |
| 176 | + } | |
| 177 | + | |
| 178 | + private CombinationActivityDO validateCombinationActivityExists(Long id) { | |
| 179 | + CombinationActivityDO activityDO = combinationActivityMapper.selectById(id); | |
| 180 | + if (activityDO == null) { | |
| 181 | + throw exception(COMBINATION_ACTIVITY_NOT_EXISTS); | |
| 182 | + } | |
| 183 | + return activityDO; | |
| 184 | + } | |
| 185 | + | |
| 186 | + @Override | |
| 187 | + public CombinationActivityDO getCombinationActivity(Long id) { | |
| 188 | + return validateCombinationActivityExists(id); | |
| 189 | + } | |
| 190 | + | |
| 191 | + @Override | |
| 192 | + public List<CombinationActivityDO> getCombinationActivityList(Collection<Long> ids) { | |
| 193 | + return combinationActivityMapper.selectBatchIds(ids); | |
| 194 | + } | |
| 195 | + | |
| 196 | + @Override | |
| 197 | + public PageResult<CombinationActivityDO> getCombinationActivityPage(CombinationActivityPageReqVO pageReqVO) { | |
| 198 | + return combinationActivityMapper.selectPage(pageReqVO); | |
| 199 | + } | |
| 200 | + | |
| 201 | + @Override | |
| 202 | + public List<CombinationActivityDO> getCombinationActivityList(CombinationActivityExportReqVO exportReqVO) { | |
| 203 | + return combinationActivityMapper.selectList(exportReqVO); | |
| 204 | + } | |
| 205 | + | |
| 206 | + @Override | |
| 207 | + public List<CombinationProductDO> getProductsByActivityIds(Collection<Long> ids) { | |
| 208 | + return combinationProductMapper.selectListByActivityIds(ids); | |
| 209 | + } | |
| 210 | + | |
| 211 | + @Override | |
| 212 | + public void updateRecordStatusByUserIdAndOrderId(Long userId, Long orderId, Integer status) { | |
| 213 | + // 校验拼团是否存在 | |
| 214 | + CombinationRecordDO recordDO = validateCombinationRecord(userId, orderId); | |
| 215 | + | |
| 216 | + // 更新状态 | |
| 217 | + recordDO.setStatus(status); | |
| 218 | + recordMapper.updateById(recordDO); | |
| 219 | + } | |
| 220 | + | |
| 221 | + @Override | |
| 222 | + @Transactional(rollbackFor = Exception.class) | |
| 223 | + public void updateRecordStatusAndStartTimeByUserIdAndOrderId(Long userId, Long orderId, Integer status, LocalDateTime startTime) { | |
| 224 | + CombinationRecordDO recordDO = validateCombinationRecord(userId, orderId); | |
| 225 | + // 更新状态 | |
| 226 | + recordDO.setStatus(status); | |
| 227 | + // 更新开始时间 | |
| 228 | + recordDO.setStartTime(startTime); | |
| 229 | + recordMapper.updateById(recordDO); | |
| 230 | + | |
| 231 | + // 更新拼团参入人数 | |
| 232 | + List<CombinationRecordDO> recordDOs = recordMapper.selectListByHeadIdAndStatus(recordDO.getHeadId(), status); | |
| 233 | + if (CollUtil.isNotEmpty(recordDOs)) { | |
| 234 | + recordDOs.forEach(item -> { | |
| 235 | + item.setUserCount(recordDOs.size()); | |
| 236 | + // 校验拼团是否满足要求 | |
| 237 | + if (recordDOs.size() >= recordDO.getUserSize()) { | |
| 238 | + item.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus()); | |
| 239 | + } | |
| 240 | + }); | |
| 241 | + } | |
| 242 | + recordMapper.updateBatch(recordDOs); | |
| 243 | + } | |
| 244 | + | |
| 245 | + private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) { | |
| 246 | + // 校验拼团是否存在 | |
| 247 | + CombinationRecordDO recordDO = recordMapper.selectRecord(userId, orderId); | |
| 248 | + if (recordDO == null) { | |
| 249 | + throw exception(COMBINATION_RECORD_NOT_EXISTS); | |
| 250 | + } | |
| 251 | + return recordDO; | |
| 252 | + } | |
| 253 | + | |
| 254 | + @Override | |
| 255 | + public void createRecord(CombinationRecordReqDTO reqDTO) { | |
| 256 | + // 校验拼团活动 | |
| 257 | + CombinationActivityDO activityDO = validateCombinationActivityExists(reqDTO.getActivityId()); | |
| 258 | + | |
| 259 | + CombinationRecordDO recordDO = CombinationActivityConvert.INSTANCE.convert(reqDTO); | |
| 260 | + recordDO.setVirtualGroup(false); | |
| 261 | + recordDO.setExpireTime(activityDO.getLimitDuration()); | |
| 262 | + recordDO.setUserSize(activityDO.getUserSize()); | |
| 263 | + recordMapper.insert(recordDO); | |
| 264 | + } | |
| 265 | + | |
| 266 | + @Override | |
| 267 | + public boolean validateRecordStatusIsSuccess(Long userId, Long orderId) { | |
| 268 | + CombinationRecordDO recordDO = validateCombinationRecord(userId, orderId); | |
| 269 | + return ObjectUtil.equal(recordDO.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus()); | |
| 270 | + } | |
| 271 | + | |
| 272 | + /** | |
| 273 | + * APP 端获取开团记录 | |
| 274 | + * | |
| 275 | + * @return 开团记录 | |
| 276 | + */ | |
| 277 | + public List<CombinationRecordDO> getRecordList() { | |
| 278 | + return recordMapper.selectListByStatus(CombinationRecordStatusEnum.ONGOING.getStatus()); | |
| 279 | + } | |
| 280 | + | |
| 281 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityService.java
| ... | ... | @@ -79,4 +79,12 @@ public interface SeckillActivityService { |
| 79 | 79 | */ |
| 80 | 80 | List<SeckillProductDO> getSeckillProductListByActivityId(Long id); |
| 81 | 81 | |
| 82 | + /** | |
| 83 | + * 通过活动编号获取活动商品 | |
| 84 | + * | |
| 85 | + * @param ids 活动编号 | |
| 86 | + * @return 活动商品列表 | |
| 87 | + */ | |
| 88 | + List<SeckillProductDO> getSeckillProductListByActivityId(Collection<Long> ids); | |
| 89 | + | |
| 82 | 90 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.service.seckill.seckillactivity; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | -import cn.hutool.core.util.ArrayUtil; | |
| 5 | 4 | import cn.hutool.core.util.ObjectUtil; |
| 6 | 5 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 7 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| ... | ... | @@ -13,29 +12,28 @@ import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 13 | 12 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO; |
| 14 | 13 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityPageReqVO; |
| 15 | 14 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO; |
| 16 | -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductBaseVO; | |
| 15 | +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductCreateReqVO; | |
| 16 | +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductUpdateReqVO; | |
| 17 | 17 | import cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity.SeckillActivityConvert; |
| 18 | 18 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; |
| 19 | 19 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; |
| 20 | 20 | import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillActivityMapper; |
| 21 | 21 | import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillProductMapper; |
| 22 | -import cn.iocoder.yudao.module.promotion.enums.common.PromotionActivityStatusEnum; | |
| 23 | 22 | import cn.iocoder.yudao.module.promotion.service.seckill.seckillconfig.SeckillConfigService; |
| 24 | 23 | import cn.iocoder.yudao.module.promotion.util.PromotionUtils; |
| 25 | 24 | import org.springframework.stereotype.Service; |
| 25 | +import org.springframework.transaction.annotation.Transactional; | |
| 26 | 26 | import org.springframework.validation.annotation.Validated; |
| 27 | 27 | |
| 28 | 28 | import javax.annotation.Resource; |
| 29 | 29 | import java.util.Collection; |
| 30 | 30 | import java.util.List; |
| 31 | 31 | import java.util.Set; |
| 32 | -import java.util.stream.Collectors; | |
| 33 | 32 | |
| 34 | 33 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 35 | -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS; | |
| 36 | 34 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; |
| 37 | 35 | import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; |
| 38 | -import static java.util.Arrays.asList; | |
| 36 | +import static cn.iocoder.yudao.module.promotion.util.PromotionUtils.validateProductSkuExistence; | |
| 39 | 37 | |
| 40 | 38 | /** |
| 41 | 39 | * 秒杀活动 Service 实现类 |
| ... | ... | @@ -58,15 +56,19 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { |
| 58 | 56 | private ProductSkuApi productSkuApi; |
| 59 | 57 | |
| 60 | 58 | @Override |
| 59 | + @Transactional(rollbackFor = Exception.class) | |
| 61 | 60 | public Long createSeckillActivity(SeckillActivityCreateReqVO createReqVO) { |
| 62 | 61 | // 校验商品秒秒杀时段是否冲突 |
| 63 | - validateProductSpuSeckillConflict(createReqVO.getConfigIds(), createReqVO.getSpuIds()); | |
| 62 | + validateProductSpuSeckillConflict(createReqVO.getConfigIds(), createReqVO.getSpuId(), null); | |
| 63 | + // 获取所选 spu下的所有 sku | |
| 64 | + List<ProductSkuRespDTO> skus = productSkuApi.getSkuListBySpuId(CollUtil.newArrayList(createReqVO.getSpuId())); | |
| 64 | 65 | // 校验商品 sku 是否存在 |
| 65 | - validateProductSkuExistence(createReqVO.getSpuIds(), createReqVO.getProducts()); | |
| 66 | + validateProductSkuExistence(skus, createReqVO.getProducts(), SeckillProductCreateReqVO::getSkuId); | |
| 66 | 67 | |
| 67 | 68 | // 插入秒杀活动 |
| 68 | 69 | SeckillActivityDO activity = SeckillActivityConvert.INSTANCE.convert(createReqVO) |
| 69 | - .setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getEndTime())); | |
| 70 | + .setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getEndTime())) | |
| 71 | + .setTotalStock(CollectionUtils.getSumValue(createReqVO.getProducts(), SeckillProductCreateReqVO::getStock, Integer::sum)); | |
| 70 | 72 | seckillActivityMapper.insert(activity); |
| 71 | 73 | // 插入商品 |
| 72 | 74 | List<SeckillProductDO> product = SeckillActivityConvert.INSTANCE.convertList(activity, createReqVO.getProducts()); |
| ... | ... | @@ -74,139 +76,124 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { |
| 74 | 76 | return activity.getId(); |
| 75 | 77 | } |
| 76 | 78 | |
| 77 | - private <T extends SeckillProductBaseVO> void validateProductSkuExistence(List<Long> spuIds, List<T> products) { | |
| 78 | - // 校验 spu 个数是否相等 | |
| 79 | - // TODO @puhui999:不用校验 SPU 哈,只校验 sku 对应的 spuId 是否一致; | |
| 80 | - Set<Long> convertedSpuIds = CollectionUtils.convertSet(products, T::getSpuId); | |
| 81 | - if (ObjectUtil.notEqual(spuIds.size(), convertedSpuIds.size())) { | |
| 82 | - throw exception(SKU_NOT_EXISTS); | |
| 83 | - } | |
| 84 | - // 获取所选 spu下的所有 sku | |
| 85 | - // TODO @puhui999:变量可以简单一点;skus | |
| 86 | - List<ProductSkuRespDTO> skuRespDTOs = productSkuApi.getSkuListBySpuId(spuIds); | |
| 87 | - // 校验 sku 个数是否一致 | |
| 88 | - Set<Long> skuIdsSet = CollectionUtils.convertSet(products, T::getSkuId); | |
| 89 | - Set<Long> skuIdsSet1 = CollectionUtils.convertSet(skuRespDTOs, ProductSkuRespDTO::getId); | |
| 90 | - if (ObjectUtil.notEqual(skuIdsSet.size(), skuIdsSet1.size())) { | |
| 91 | - throw exception(SKU_NOT_EXISTS); | |
| 92 | - } | |
| 93 | - // 校验 skuId 是否存在 | |
| 94 | - if (!skuIdsSet1.containsAll(skuIdsSet) || !skuIdsSet.containsAll(skuIdsSet1)) { | |
| 95 | - throw exception(SKU_NOT_EXISTS); | |
| 96 | - } | |
| 97 | - } | |
| 98 | - | |
| 99 | - private void validateProductSpuSeckillConflict(List<Long> configIds, List<Long> spuIds) { | |
| 79 | + private void validateProductSpuSeckillConflict(List<Long> configIds, Long spuId, Long activityId) { | |
| 100 | 80 | // 校验秒杀时段是否存在 |
| 101 | 81 | seckillConfigService.validateSeckillConfigExists(configIds); |
| 102 | 82 | // 校验商品 spu 是否存在 |
| 103 | - List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(spuIds); | |
| 104 | - if (ObjectUtil.notEqual(spuIds.size(), spuList.size())) { | |
| 83 | + List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(CollUtil.newArrayList(spuId)); | |
| 84 | + if (CollUtil.isEmpty(spuList)) { | |
| 105 | 85 | throw exception(SPU_NOT_EXISTS); |
| 106 | 86 | } |
| 107 | 87 | // 查询所有开启的秒杀活动 |
| 108 | 88 | List<SeckillActivityDO> activityDOs = seckillActivityMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 109 | - // 过滤出所有 spuIds 有交集的活动 | |
| 110 | - List<SeckillActivityDO> doList = activityDOs.stream().filter(s -> { | |
| 111 | - // 判断 spu 是否有交集 | |
| 112 | - List<Long> spuIdsClone = ArrayUtil.clone(s.getSpuIds()); | |
| 113 | - spuIdsClone.retainAll(spuIds); | |
| 114 | - if (CollUtil.isEmpty(spuIdsClone)) { | |
| 115 | - return false; | |
| 116 | - } | |
| 89 | + if (activityId != null) { | |
| 90 | + // 更新时移除本活动 | |
| 91 | + activityDOs.removeIf(item -> ObjectUtil.equal(item.getId(), activityId)); | |
| 92 | + } | |
| 93 | + // 过滤出所有 spuId 有交集的活动 | |
| 94 | + List<SeckillActivityDO> activityDOs1 = CollectionUtils.convertList(activityDOs, c -> c, s -> ObjectUtil.equal(s.getSpuId(), spuId)); | |
| 95 | + if (CollUtil.isNotEmpty(activityDOs1)) { | |
| 96 | + throw exception(SECKILL_ACTIVITY_SPU_CONFLICTS); | |
| 97 | + } | |
| 98 | + List<SeckillActivityDO> activityDOs2 = CollectionUtils.convertList(activityDOs, c -> c, s -> { | |
| 117 | 99 | // 判断秒杀时段是否有交集 |
| 118 | - List<Long> configIdsClone = ArrayUtil.clone(s.getConfigIds()); | |
| 100 | + List<Long> configIdsClone = CollUtil.newArrayList(s.getConfigIds()); | |
| 119 | 101 | configIdsClone.retainAll(configIds); |
| 120 | 102 | return CollUtil.isNotEmpty(configIdsClone); |
| 121 | - }).collect(Collectors.toList()); | |
| 122 | - if (CollUtil.isNotEmpty(doList)) { | |
| 123 | - throw exception(SECKILL_ACTIVITY_SPU_CONFLICTS); | |
| 103 | + }); | |
| 104 | + if (CollUtil.isNotEmpty(activityDOs2)) { | |
| 105 | + throw exception(SECKILL_TIME_CONFLICTS); | |
| 124 | 106 | } |
| 125 | 107 | } |
| 126 | 108 | |
| 127 | 109 | @Override |
| 110 | + @Transactional(rollbackFor = Exception.class) | |
| 128 | 111 | public void updateSeckillActivity(SeckillActivityUpdateReqVO updateReqVO) { |
| 129 | 112 | // 校验存在 |
| 130 | 113 | SeckillActivityDO seckillActivity = validateSeckillActivityExists(updateReqVO.getId()); |
| 131 | - if (CommonStatusEnum.ENABLE.getStatus().equals(seckillActivity.getStatus())) { | |
| 114 | + if (CommonStatusEnum.DISABLE.getStatus().equals(seckillActivity.getStatus())) { | |
| 132 | 115 | throw exception(SECKILL_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED); |
| 133 | 116 | } |
| 134 | 117 | // 校验商品是否冲突 |
| 135 | - validateProductSpuSeckillConflict(updateReqVO.getConfigIds(), updateReqVO.getSpuIds()); | |
| 118 | + validateProductSpuSeckillConflict(updateReqVO.getConfigIds(), updateReqVO.getSpuId(), updateReqVO.getId()); | |
| 119 | + // 获取所选 spu下的所有 sku | |
| 120 | + List<ProductSkuRespDTO> skus = productSkuApi.getSkuListBySpuId(CollUtil.newArrayList(updateReqVO.getSpuId())); | |
| 136 | 121 | // 校验商品 sku 是否存在 |
| 137 | - validateProductSkuExistence(updateReqVO.getSpuIds(), updateReqVO.getProducts()); | |
| 122 | + validateProductSkuExistence(skus, updateReqVO.getProducts(), SeckillProductUpdateReqVO::getSkuId); | |
| 138 | 123 | |
| 139 | 124 | // 更新活动 |
| 140 | 125 | SeckillActivityDO updateObj = SeckillActivityConvert.INSTANCE.convert(updateReqVO) |
| 141 | - .setStatus(PromotionUtils.calculateActivityStatus(updateReqVO.getEndTime())); | |
| 126 | + .setStatus(PromotionUtils.calculateActivityStatus(updateReqVO.getEndTime())) | |
| 127 | + .setTotalStock(CollectionUtils.getSumValue(updateReqVO.getProducts(), SeckillProductUpdateReqVO::getStock, Integer::sum)); | |
| 142 | 128 | seckillActivityMapper.updateById(updateObj); |
| 143 | 129 | // 更新商品 |
| 144 | - //updateSeckillProduct(updateReqVO); | |
| 130 | + updateSeckillProduct(updateObj, updateReqVO.getProducts()); | |
| 145 | 131 | } |
| 146 | 132 | |
| 147 | 133 | |
| 148 | 134 | /** |
| 149 | 135 | * 更新秒杀商品 |
| 150 | - * 后台查出的数据和前台查出的数据进行遍历, | |
| 151 | - * 1. 对前台数据进行遍历:如果不存在于后台的 sku 中需要新增 | |
| 152 | - * 2. 对后台数据进行遍历:如果不存在于前台的 sku 中需要删除 | |
| 153 | - * 3. 最后对当前活动商品全部更新,更新秒杀时段id列表 | |
| 154 | 136 | * |
| 155 | - * @param updateReqVO 更新的请求VO | |
| 137 | + * @param updateObj DO | |
| 138 | + * @param products 商品配置 | |
| 156 | 139 | */ |
| 157 | - private void updateSeckillProduct(SeckillActivityUpdateReqVO updateReqVO) { | |
| 158 | - // TODO puhui999:要不这里简单一点;删除原本的,插入新增的;不做的这么细致 | |
| 159 | - // TODO puhui999:后续完善 | |
| 160 | - //List<SeckillProductDO> seckillProductDOs = seckillProductMapper.selectListByActivityId(updateReqVO.getId()); | |
| 161 | - //List<SeckillProductUpdateReqVO> products = updateReqVO.getProducts(); | |
| 162 | - | |
| 163 | - ////计算需要删除的数据 | |
| 164 | - //List<Long> deleteIds = CollectionUtils.convertList(seckillProductDOs, SeckillProductDO::getId, | |
| 165 | - // seckillProductDO -> products.stream() | |
| 166 | - // .noneMatch(product -> SeckillActivityConvert.INSTANCE.isEquals(seckillProductDO, product))); | |
| 167 | - //if (CollUtil.isNotEmpty(deleteIds)) { | |
| 168 | - // seckillProductMapper.deleteBatchIds(deleteIds); | |
| 169 | - //} | |
| 170 | - // | |
| 171 | - //// 计算需要新增的数据 | |
| 172 | - //List<SeckillProductDO> newSeckillProductDOs = CollectionUtils.convertList(products, | |
| 173 | - // product -> SeckillActivityConvert.INSTANCE.convert(product).setActivityId(updateReqVO.getId())); | |
| 174 | - //newSeckillProductDOs.removeIf(product -> seckillProductDOs.stream() | |
| 175 | - // .anyMatch(seckillProduct -> SeckillActivityConvert.INSTANCE.isEquals(seckillProduct, product))); | |
| 176 | - //if (CollUtil.isNotEmpty(newSeckillProductDOs)) { | |
| 177 | - // seckillProductMapper.insertBatch(newSeckillProductDOs); | |
| 178 | - //} | |
| 179 | - | |
| 180 | - //全量更新当前活动商品的秒杀时段id列表(timeIds) | |
| 181 | - seckillProductMapper.updateTimeIdsByActivityId(updateReqVO.getId(), updateReqVO.getConfigIds()); | |
| 140 | + private void updateSeckillProduct(SeckillActivityDO updateObj, List<SeckillProductUpdateReqVO> products) { | |
| 141 | + List<SeckillProductDO> seckillProductDOs = seckillProductMapper.selectListByActivityId(updateObj.getId()); | |
| 142 | + // 数据库中的活动商品 | |
| 143 | + Set<Long> convertSet = CollectionUtils.convertSet(seckillProductDOs, SeckillProductDO::getSkuId); | |
| 144 | + // 前端传过来的活动商品 | |
| 145 | + Set<Long> convertSet1 = CollectionUtils.convertSet(products, SeckillProductUpdateReqVO::getSkuId); | |
| 146 | + // 删除后台存在的前端不存在的商品 | |
| 147 | + List<Long> d = CollectionUtils.filterList(convertSet, item -> !convertSet1.contains(item)); | |
| 148 | + if (CollUtil.isNotEmpty(d)) { | |
| 149 | + seckillProductMapper.deleteBatchIds(d); | |
| 150 | + } | |
| 151 | + // 前端存在的后端不存在的商品 | |
| 152 | + List<Long> c = CollectionUtils.filterList(convertSet1, item -> !convertSet.contains(item)); | |
| 153 | + if (CollUtil.isNotEmpty(c)) { | |
| 154 | + List<SeckillProductUpdateReqVO> vos = CollectionUtils.filterList(products, item -> c.contains(item.getSkuId())); | |
| 155 | + List<SeckillProductDO> productDOs = SeckillActivityConvert.INSTANCE.convertList(updateObj, vos); | |
| 156 | + seckillProductMapper.insertBatch(productDOs); | |
| 157 | + } | |
| 158 | + // 更新已存在的商品 | |
| 159 | + List<Long> u = CollectionUtils.filterList(convertSet1, convertSet::contains); | |
| 160 | + if (CollUtil.isNotEmpty(u)) { | |
| 161 | + List<SeckillProductUpdateReqVO> vos = CollectionUtils.filterList(products, item -> u.contains(item.getSkuId())); | |
| 162 | + List<SeckillProductDO> productDOs = SeckillActivityConvert.INSTANCE.convertList1(updateObj, vos, seckillProductDOs); | |
| 163 | + seckillProductMapper.updateBatch(productDOs); | |
| 164 | + } | |
| 182 | 165 | } |
| 183 | 166 | |
| 184 | 167 | @Override |
| 168 | + @Transactional(rollbackFor = Exception.class) | |
| 185 | 169 | public void closeSeckillActivity(Long id) { |
| 170 | + // TODO 待验证没使用过 | |
| 186 | 171 | // 校验存在 |
| 187 | - SeckillActivityDO seckillActivity = this.validateSeckillActivityExists(id); | |
| 188 | - if (PromotionActivityStatusEnum.CLOSE.getStatus().equals(seckillActivity.getStatus())) { | |
| 172 | + SeckillActivityDO seckillActivity = validateSeckillActivityExists(id); | |
| 173 | + if (CommonStatusEnum.DISABLE.getStatus().equals(seckillActivity.getStatus())) { | |
| 189 | 174 | throw exception(SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED); |
| 190 | 175 | } |
| 191 | - if (PromotionActivityStatusEnum.END.getStatus().equals(seckillActivity.getStatus())) { | |
| 192 | - throw exception(SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_END); | |
| 193 | - } | |
| 176 | + | |
| 194 | 177 | // 更新 |
| 195 | - SeckillActivityDO updateObj = new SeckillActivityDO().setId(id).setStatus(PromotionActivityStatusEnum.CLOSE.getStatus()); | |
| 178 | + SeckillActivityDO updateObj = new SeckillActivityDO().setId(id).setStatus(CommonStatusEnum.DISABLE.getStatus()); | |
| 196 | 179 | seckillActivityMapper.updateById(updateObj); |
| 197 | 180 | } |
| 198 | 181 | |
| 199 | 182 | @Override |
| 183 | + @Transactional(rollbackFor = Exception.class) | |
| 200 | 184 | public void deleteSeckillActivity(Long id) { |
| 201 | 185 | // 校验存在 |
| 202 | 186 | SeckillActivityDO seckillActivity = this.validateSeckillActivityExists(id); |
| 203 | - List<Integer> statuses = asList(PromotionActivityStatusEnum.CLOSE.getStatus(), PromotionActivityStatusEnum.END.getStatus()); | |
| 204 | - if (!statuses.contains(seckillActivity.getStatus())) { | |
| 187 | + if (CommonStatusEnum.ENABLE.getStatus().equals(seckillActivity.getStatus())) { | |
| 205 | 188 | throw exception(SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END); |
| 206 | 189 | } |
| 207 | 190 | |
| 208 | - // 删除 | |
| 191 | + // 删除活动 | |
| 209 | 192 | seckillActivityMapper.deleteById(id); |
| 193 | + // 删除活动商品 | |
| 194 | + List<SeckillProductDO> productDOs = seckillProductMapper.selectListByActivityId(id); | |
| 195 | + Set<Long> convertSet = CollectionUtils.convertSet(productDOs, SeckillProductDO::getSkuId); | |
| 196 | + seckillProductMapper.deleteBatchIds(convertSet); | |
| 210 | 197 | } |
| 211 | 198 | |
| 212 | 199 | private SeckillActivityDO validateSeckillActivityExists(Long id) { |
| ... | ... | @@ -219,7 +206,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { |
| 219 | 206 | |
| 220 | 207 | @Override |
| 221 | 208 | public SeckillActivityDO getSeckillActivity(Long id) { |
| 222 | - return seckillActivityMapper.selectById(id); | |
| 209 | + return validateSeckillActivityExists(id); | |
| 223 | 210 | } |
| 224 | 211 | |
| 225 | 212 | @Override |
| ... | ... | @@ -237,4 +224,9 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { |
| 237 | 224 | return seckillProductMapper.selectListByActivityId(id); |
| 238 | 225 | } |
| 239 | 226 | |
| 227 | + @Override | |
| 228 | + public List<SeckillProductDO> getSeckillProductListByActivityId(Collection<Long> ids) { | |
| 229 | + return seckillProductMapper.selectListByActivityId(ids); | |
| 230 | + } | |
| 231 | + | |
| 240 | 232 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillconfig/SeckillConfigServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.service.seckill.seckillconfig; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.hutool.core.util.ObjectUtil; | |
| 4 | 5 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 8 | +import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; | |
| 6 | 9 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigCreateReqVO; |
| 7 | 10 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigPageReqVO; |
| 8 | 11 | import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigUpdateReqVO; |
| ... | ... | @@ -10,14 +13,13 @@ import cn.iocoder.yudao.module.promotion.convert.seckill.seckillconfig.SeckillCo |
| 10 | 13 | import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillconfig.SeckillConfigDO; |
| 11 | 14 | import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillconfig.SeckillConfigMapper; |
| 12 | 15 | import org.springframework.stereotype.Service; |
| 16 | +import org.springframework.transaction.annotation.Transactional; | |
| 13 | 17 | import org.springframework.validation.annotation.Validated; |
| 14 | 18 | |
| 15 | 19 | import javax.annotation.Resource; |
| 16 | 20 | import java.time.LocalTime; |
| 17 | 21 | import java.util.Collection; |
| 18 | 22 | import java.util.List; |
| 19 | -import java.util.Set; | |
| 20 | -import java.util.stream.Collectors; | |
| 21 | 23 | |
| 22 | 24 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 23 | 25 | import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; |
| ... | ... | @@ -35,9 +37,10 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { |
| 35 | 37 | private SeckillConfigMapper seckillConfigMapper; |
| 36 | 38 | |
| 37 | 39 | @Override |
| 40 | + @Transactional(rollbackFor = Exception.class) | |
| 38 | 41 | public Long createSeckillConfig(SeckillConfigCreateReqVO createReqVO) { |
| 39 | 42 | // 校验时间段是否冲突 |
| 40 | - validateSeckillConfigConflict(createReqVO.getStartTime(), createReqVO.getEndTime()); | |
| 43 | + validateSeckillConfigConflict(createReqVO.getStartTime(), createReqVO.getEndTime(), null); | |
| 41 | 44 | |
| 42 | 45 | // 插入 |
| 43 | 46 | SeckillConfigDO seckillConfig = SeckillConfigConvert.INSTANCE.convert(createReqVO); |
| ... | ... | @@ -47,18 +50,30 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { |
| 47 | 50 | } |
| 48 | 51 | |
| 49 | 52 | @Override |
| 53 | + @Transactional(rollbackFor = Exception.class) | |
| 50 | 54 | public void updateSeckillConfig(SeckillConfigUpdateReqVO updateReqVO) { |
| 51 | 55 | // 校验存在 |
| 52 | 56 | validateSeckillConfigExists(updateReqVO.getId()); |
| 53 | 57 | // 校验时间段是否冲突 |
| 54 | - validateSeckillConfigConflict(updateReqVO.getStartTime(), updateReqVO.getEndTime()); | |
| 58 | + validateSeckillConfigConflict(updateReqVO.getStartTime(), updateReqVO.getEndTime(), updateReqVO.getId()); | |
| 55 | 59 | |
| 56 | 60 | // 更新 |
| 57 | 61 | SeckillConfigDO updateObj = SeckillConfigConvert.INSTANCE.convert(updateReqVO); |
| 58 | 62 | seckillConfigMapper.updateById(updateObj); |
| 59 | 63 | } |
| 60 | 64 | |
| 65 | + // TODO @puhui999: 这个要不合并到更新操作里? 不单独有个操作咧; 更新状态不用那么多必须的参数,更新的时候需要校验时间段 | |
| 61 | 66 | @Override |
| 67 | + public void updateSeckillConfigStatus(Long id, Integer status) { | |
| 68 | + // 校验秒杀时段是否存在 | |
| 69 | + validateSeckillConfigExists(id); | |
| 70 | + | |
| 71 | + // 更新状态 | |
| 72 | + seckillConfigMapper.updateById(new SeckillConfigDO().setId(id).setStatus(status)); | |
| 73 | + } | |
| 74 | + | |
| 75 | + @Override | |
| 76 | + @Transactional(rollbackFor = Exception.class) | |
| 62 | 77 | public void deleteSeckillConfig(Long id) { |
| 63 | 78 | // 校验存在 |
| 64 | 79 | validateSeckillConfigExists(id); |
| ... | ... | @@ -79,39 +94,29 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { |
| 79 | 94 | * @param startTime 开始时间 |
| 80 | 95 | * @param endTime 结束时间 |
| 81 | 96 | */ |
| 82 | - private void validateSeckillConfigConflict(String startTime, String endTime) { | |
| 97 | + private void validateSeckillConfigConflict(String startTime, String endTime, Long seckillConfigId) { | |
| 83 | 98 | LocalTime startTime1 = LocalTime.parse(startTime); |
| 84 | 99 | LocalTime endTime1 = LocalTime.parse(endTime); |
| 85 | - // TODO @puhui999: 这个可以用 validator 里的 assertTrue 去做哈; | |
| 86 | - // 检查选择的时间是否相等 | |
| 87 | - if (startTime1.equals(endTime1)) { | |
| 88 | - throw exception(SECKILL_TIME_EQUAL); | |
| 89 | - } | |
| 90 | - // 检查开始时间是否在结束时间之前 | |
| 91 | - if (startTime1.isAfter(endTime1)) { | |
| 92 | - throw exception(SECKILL_START_TIME_BEFORE_END_TIME); | |
| 93 | - } | |
| 94 | 100 | // 查询出所有的时段配置 |
| 95 | 101 | List<SeckillConfigDO> configDOs = seckillConfigMapper.selectList(); |
| 102 | + // 更新时排除自己 | |
| 103 | + if (seckillConfigId != null) { | |
| 104 | + configDOs.removeIf(item -> ObjectUtil.equal(item.getId(), seckillConfigId)); | |
| 105 | + } | |
| 96 | 106 | // 过滤出重叠的时段 ids |
| 97 | - // TODO @puhui999:感觉 findOne 就可以了? | |
| 98 | - Set<Long> ids = configDOs.stream().filter((config) -> { | |
| 107 | + boolean hasConflict = configDOs.stream().anyMatch(config -> { | |
| 99 | 108 | LocalTime startTime2 = LocalTime.parse(config.getStartTime()); |
| 100 | 109 | LocalTime endTime2 = LocalTime.parse(config.getEndTime()); |
| 101 | 110 | // 判断时间是否重叠 |
| 102 | - // 开始时间在已配置时段的结束时间之前 且 结束时间在已配置时段的开始时间之后 [] | |
| 103 | - // todo @puhui999:LocalDateUtils 可以写个工具类?是否是有重叠的时间?感觉别的场景,可能也会有需要 | |
| 104 | - return startTime1.isBefore(endTime2) && endTime1.isAfter(startTime2) | |
| 105 | - // 开始时间在已配置时段的开始时间之前 且 结束时间在已配置时段的开始时间之后 (] 或 () | |
| 106 | - || startTime1.isBefore(startTime2) && endTime1.isAfter(startTime2) | |
| 107 | - // 开始时间在已配置时段的结束时间之前 且 结束时间在已配值时段的结束时间之后 [) 或 () | |
| 108 | - || startTime1.isBefore(endTime2) && endTime1.isAfter(endTime2); | |
| 109 | - }).map(SeckillConfigDO::getId).collect(Collectors.toSet()); | |
| 110 | - if (CollUtil.isNotEmpty(ids)) { | |
| 111 | + return LocalDateTimeUtils.checkTimeOverlap(startTime1, endTime1, startTime2, endTime2); | |
| 112 | + }); | |
| 113 | + | |
| 114 | + if (hasConflict) { | |
| 111 | 115 | throw exception(SECKILL_TIME_CONFLICTS); |
| 112 | 116 | } |
| 113 | 117 | } |
| 114 | 118 | |
| 119 | + | |
| 115 | 120 | @Override |
| 116 | 121 | public SeckillConfigDO getSeckillConfig(Long id) { |
| 117 | 122 | return seckillConfigMapper.selectById(id); |
| ... | ... | @@ -127,10 +132,18 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { |
| 127 | 132 | if (CollUtil.isEmpty(configIds)) { |
| 128 | 133 | throw exception(SECKILL_TIME_NOT_EXISTS); |
| 129 | 134 | } |
| 130 | - if (seckillConfigMapper.selectBatchIds(configIds).size() != configIds.size()) { | |
| 135 | + List<SeckillConfigDO> configDOs = seckillConfigMapper.selectBatchIds(configIds); | |
| 136 | + if (CollUtil.isEmpty(configDOs)) { | |
| 137 | + throw exception(SECKILL_TIME_NOT_EXISTS); | |
| 138 | + } | |
| 139 | + // 过滤出关闭的时段 | |
| 140 | + List<SeckillConfigDO> filterList = CollectionUtils.filterList(configDOs, item -> ObjectUtil.equal(item.getStatus(), CommonStatusEnum.DISABLE.getStatus())); | |
| 141 | + if (CollUtil.isNotEmpty(filterList)) { | |
| 142 | + throw exception(SECKILL_TIME_DISABLE); | |
| 143 | + } | |
| 144 | + if (configDOs.size() != configIds.size()) { | |
| 131 | 145 | throw exception(SECKILL_TIME_NOT_EXISTS); |
| 132 | 146 | } |
| 133 | - // TODO @puhui999:应该要校验个 status 哈;如果有禁用的,也不行 | |
| 134 | 147 | } |
| 135 | 148 | |
| 136 | 149 | @Override |
| ... | ... | @@ -138,23 +151,9 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { |
| 138 | 151 | return seckillConfigMapper.selectPage(pageVO); |
| 139 | 152 | } |
| 140 | 153 | |
| 141 | - // TODO @puhui999:写个查询状态的; 尽可能通用哈 | |
| 142 | 154 | @Override |
| 143 | 155 | public List<SeckillConfigDO> getListAllSimple() { |
| 144 | - return seckillConfigMapper.selectList(SeckillConfigDO::getStatus, CommonStatusEnum.ENABLE.getStatus()); | |
| 145 | - } | |
| 146 | - | |
| 147 | - // TODO @puhui999: 这个要不合并到更新操作里? 不单独有个操作咧; | |
| 148 | - @Override | |
| 149 | - public void updateSeckillConfigStatus(Long id, Integer status) { | |
| 150 | - // 校验秒杀时段是否存在 | |
| 151 | - validateSeckillConfigExists(id); | |
| 152 | - | |
| 153 | - SeckillConfigDO seckillConfigDO = new SeckillConfigDO(); | |
| 154 | - seckillConfigDO.setId(id); | |
| 155 | - seckillConfigDO.setStatus(status); | |
| 156 | - // 更新状态 | |
| 157 | - seckillConfigMapper.updateById(seckillConfigDO); | |
| 156 | + return seckillConfigMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 158 | 157 | } |
| 159 | 158 | |
| 160 | 159 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.util; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 4 | 6 | import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; |
| 7 | +import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; | |
| 5 | 8 | |
| 6 | 9 | import java.time.LocalDateTime; |
| 10 | +import java.util.List; | |
| 11 | +import java.util.Set; | |
| 12 | +import java.util.function.Function; | |
| 13 | + | |
| 14 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 15 | +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS; | |
| 7 | 16 | |
| 8 | 17 | /** |
| 9 | 18 | * 活动工具类 |
| ... | ... | @@ -22,4 +31,15 @@ public class PromotionUtils { |
| 22 | 31 | return LocalDateTimeUtils.beforeNow(endTime) ? CommonStatusEnum.DISABLE.getStatus() : CommonStatusEnum.ENABLE.getStatus(); |
| 23 | 32 | } |
| 24 | 33 | |
| 34 | + public static <T> void validateProductSkuExistence(List<ProductSkuRespDTO> skus, List<T> products, Function<T, Long> func) { | |
| 35 | + // 校验 sku 个数是否一致 | |
| 36 | + Set<Long> skuIdsSet = CollectionUtils.convertSet(products, func); | |
| 37 | + Set<Long> skuIdsSet1 = CollectionUtils.convertSet(skus, ProductSkuRespDTO::getId); | |
| 38 | + // 校验 skuId 是否存在 | |
| 39 | + List<Long> f = CollectionUtils.filterList(skuIdsSet, s -> !skuIdsSet1.contains(s)); | |
| 40 | + if (CollUtil.isNotEmpty(f)) { | |
| 41 | + throw exception(SKU_NOT_EXISTS); | |
| 42 | + } | |
| 43 | + } | |
| 44 | + | |
| 25 | 45 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.service.combination; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; | |
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityExportReqVO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; | |
| 8 | +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; | |
| 9 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; | |
| 10 | +import cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity.CombinationActivityMapper; | |
| 11 | +import org.junit.jupiter.api.Disabled; | |
| 12 | +import org.junit.jupiter.api.Test; | |
| 13 | +import org.springframework.context.annotation.Import; | |
| 14 | + | |
| 15 | +import javax.annotation.Resource; | |
| 16 | +import java.util.List; | |
| 17 | + | |
| 18 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; | |
| 19 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | |
| 20 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | |
| 21 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | |
| 22 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; | |
| 23 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | |
| 24 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_ACTIVITY_NOT_EXISTS; | |
| 25 | +import static org.junit.jupiter.api.Assertions.*; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * {@link CombinationActivityServiceImpl} 的单元测试类 | |
| 29 | + * | |
| 30 | + * @author HUIHUI | |
| 31 | + */ | |
| 32 | +@Import(CombinationActivityServiceImpl.class) | |
| 33 | +public class CombinationActivityServiceImplTest extends BaseDbUnitTest { | |
| 34 | + | |
| 35 | + @Resource | |
| 36 | + private CombinationActivityServiceImpl combinationActivityService; | |
| 37 | + | |
| 38 | + @Resource | |
| 39 | + private CombinationActivityMapper combinationActivityMapper; | |
| 40 | + | |
| 41 | + @Test | |
| 42 | + public void testCreateCombinationActivity_success() { | |
| 43 | + // 准备参数 | |
| 44 | + CombinationActivityCreateReqVO reqVO = randomPojo(CombinationActivityCreateReqVO.class); | |
| 45 | + | |
| 46 | + // 调用 | |
| 47 | + Long combinationActivityId = combinationActivityService.createCombinationActivity(reqVO); | |
| 48 | + // 断言 | |
| 49 | + assertNotNull(combinationActivityId); | |
| 50 | + // 校验记录的属性是否正确 | |
| 51 | + CombinationActivityDO combinationActivity = combinationActivityMapper.selectById(combinationActivityId); | |
| 52 | + assertPojoEquals(reqVO, combinationActivity); | |
| 53 | + } | |
| 54 | + | |
| 55 | + @Test | |
| 56 | + public void testUpdateCombinationActivity_success() { | |
| 57 | + // mock 数据 | |
| 58 | + CombinationActivityDO dbCombinationActivity = randomPojo(CombinationActivityDO.class); | |
| 59 | + combinationActivityMapper.insert(dbCombinationActivity);// @Sql: 先插入出一条存在的数据 | |
| 60 | + // 准备参数 | |
| 61 | + CombinationActivityUpdateReqVO reqVO = randomPojo(CombinationActivityUpdateReqVO.class, o -> { | |
| 62 | + o.setId(dbCombinationActivity.getId()); // 设置更新的 ID | |
| 63 | + }); | |
| 64 | + | |
| 65 | + // 调用 | |
| 66 | + combinationActivityService.updateCombinationActivity(reqVO); | |
| 67 | + // 校验是否更新正确 | |
| 68 | + CombinationActivityDO combinationActivity = combinationActivityMapper.selectById(reqVO.getId()); // 获取最新的 | |
| 69 | + assertPojoEquals(reqVO, combinationActivity); | |
| 70 | + } | |
| 71 | + | |
| 72 | + @Test | |
| 73 | + public void testUpdateCombinationActivity_notExists() { | |
| 74 | + // 准备参数 | |
| 75 | + CombinationActivityUpdateReqVO reqVO = randomPojo(CombinationActivityUpdateReqVO.class); | |
| 76 | + | |
| 77 | + // 调用, 并断言异常 | |
| 78 | + assertServiceException(() -> combinationActivityService.updateCombinationActivity(reqVO), COMBINATION_ACTIVITY_NOT_EXISTS); | |
| 79 | + } | |
| 80 | + | |
| 81 | + @Test | |
| 82 | + public void testDeleteCombinationActivity_success() { | |
| 83 | + // mock 数据 | |
| 84 | + CombinationActivityDO dbCombinationActivity = randomPojo(CombinationActivityDO.class); | |
| 85 | + combinationActivityMapper.insert(dbCombinationActivity);// @Sql: 先插入出一条存在的数据 | |
| 86 | + // 准备参数 | |
| 87 | + Long id = dbCombinationActivity.getId(); | |
| 88 | + | |
| 89 | + // 调用 | |
| 90 | + combinationActivityService.deleteCombinationActivity(id); | |
| 91 | + // 校验数据不存在了 | |
| 92 | + assertNull(combinationActivityMapper.selectById(id)); | |
| 93 | + } | |
| 94 | + | |
| 95 | + @Test | |
| 96 | + public void testDeleteCombinationActivity_notExists() { | |
| 97 | + // 准备参数 | |
| 98 | + Long id = randomLongId(); | |
| 99 | + | |
| 100 | + // 调用, 并断言异常 | |
| 101 | + assertServiceException(() -> combinationActivityService.deleteCombinationActivity(id), COMBINATION_ACTIVITY_NOT_EXISTS); | |
| 102 | + } | |
| 103 | + | |
| 104 | + @Test | |
| 105 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 106 | + public void testGetCombinationActivityPage() { | |
| 107 | + // mock 数据 | |
| 108 | + CombinationActivityDO dbCombinationActivity = randomPojo(CombinationActivityDO.class, o -> { // 等会查询到 | |
| 109 | + o.setName(null); | |
| 110 | + //o.setSpuId(null); | |
| 111 | + o.setTotalLimitCount(null); | |
| 112 | + o.setSingleLimitCount(null); | |
| 113 | + o.setStartTime(null); | |
| 114 | + o.setEndTime(null); | |
| 115 | + o.setUserSize(null); | |
| 116 | + o.setTotalNum(null); | |
| 117 | + o.setSuccessNum(null); | |
| 118 | + o.setOrderUserCount(null); | |
| 119 | + o.setVirtualGroup(null); | |
| 120 | + o.setStatus(null); | |
| 121 | + o.setLimitDuration(null); | |
| 122 | + o.setCreateTime(null); | |
| 123 | + }); | |
| 124 | + combinationActivityMapper.insert(dbCombinationActivity); | |
| 125 | + // 测试 name 不匹配 | |
| 126 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setName(null))); | |
| 127 | + // 测试 spuId 不匹配 | |
| 128 | + //combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSpuId(null))); | |
| 129 | + // 测试 totalLimitCount 不匹配 | |
| 130 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalLimitCount(null))); | |
| 131 | + // 测试 singleLimitCount 不匹配 | |
| 132 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSingleLimitCount(null))); | |
| 133 | + // 测试 startTime 不匹配 | |
| 134 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setStartTime(null))); | |
| 135 | + // 测试 endTime 不匹配 | |
| 136 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setEndTime(null))); | |
| 137 | + // 测试 userSize 不匹配 | |
| 138 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setUserSize(null))); | |
| 139 | + // 测试 totalNum 不匹配 | |
| 140 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalNum(null))); | |
| 141 | + // 测试 successNum 不匹配 | |
| 142 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSuccessNum(null))); | |
| 143 | + // 测试 orderUserCount 不匹配 | |
| 144 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setOrderUserCount(null))); | |
| 145 | + // 测试 virtualGroup 不匹配 | |
| 146 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setVirtualGroup(null))); | |
| 147 | + // 测试 status 不匹配 | |
| 148 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setStatus(null))); | |
| 149 | + // 测试 limitDuration 不匹配 | |
| 150 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setLimitDuration(null))); | |
| 151 | + // 测试 createTime 不匹配 | |
| 152 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setCreateTime(null))); | |
| 153 | + // 准备参数 | |
| 154 | + CombinationActivityPageReqVO reqVO = new CombinationActivityPageReqVO(); | |
| 155 | + reqVO.setName(null); | |
| 156 | + reqVO.setSpuId(null); | |
| 157 | + reqVO.setTotalLimitCount(null); | |
| 158 | + reqVO.setSingleLimitCount(null); | |
| 159 | + reqVO.setStartTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 160 | + reqVO.setEndTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 161 | + reqVO.setUserSize(null); | |
| 162 | + reqVO.setTotalNum(null); | |
| 163 | + reqVO.setSuccessNum(null); | |
| 164 | + reqVO.setOrderUserCount(null); | |
| 165 | + reqVO.setVirtualGroup(null); | |
| 166 | + reqVO.setStatus(null); | |
| 167 | + reqVO.setLimitDuration(null); | |
| 168 | + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 169 | + | |
| 170 | + // 调用 | |
| 171 | + PageResult<CombinationActivityDO> pageResult = combinationActivityService.getCombinationActivityPage(reqVO); | |
| 172 | + // 断言 | |
| 173 | + assertEquals(1, pageResult.getTotal()); | |
| 174 | + assertEquals(1, pageResult.getList().size()); | |
| 175 | + assertPojoEquals(dbCombinationActivity, pageResult.getList().get(0)); | |
| 176 | + } | |
| 177 | + | |
| 178 | + @Test | |
| 179 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 180 | + public void testGetCombinationActivityList() { | |
| 181 | + // mock 数据 | |
| 182 | + CombinationActivityDO dbCombinationActivity = randomPojo(CombinationActivityDO.class, o -> { // 等会查询到 | |
| 183 | + o.setName(null); | |
| 184 | + //o.setSpuId(null); | |
| 185 | + o.setTotalLimitCount(null); | |
| 186 | + o.setSingleLimitCount(null); | |
| 187 | + o.setStartTime(null); | |
| 188 | + o.setEndTime(null); | |
| 189 | + o.setUserSize(null); | |
| 190 | + o.setTotalNum(null); | |
| 191 | + o.setSuccessNum(null); | |
| 192 | + o.setOrderUserCount(null); | |
| 193 | + o.setVirtualGroup(null); | |
| 194 | + o.setStatus(null); | |
| 195 | + o.setLimitDuration(null); | |
| 196 | + o.setCreateTime(null); | |
| 197 | + }); | |
| 198 | + combinationActivityMapper.insert(dbCombinationActivity); | |
| 199 | + // 测试 name 不匹配 | |
| 200 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setName(null))); | |
| 201 | + // 测试 spuId 不匹配 | |
| 202 | + //combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSpuId(null))); | |
| 203 | + // 测试 totalLimitCount 不匹配 | |
| 204 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalLimitCount(null))); | |
| 205 | + // 测试 singleLimitCount 不匹配 | |
| 206 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSingleLimitCount(null))); | |
| 207 | + // 测试 startTime 不匹配 | |
| 208 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setStartTime(null))); | |
| 209 | + // 测试 endTime 不匹配 | |
| 210 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setEndTime(null))); | |
| 211 | + // 测试 userSize 不匹配 | |
| 212 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setUserSize(null))); | |
| 213 | + // 测试 totalNum 不匹配 | |
| 214 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalNum(null))); | |
| 215 | + // 测试 successNum 不匹配 | |
| 216 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSuccessNum(null))); | |
| 217 | + // 测试 orderUserCount 不匹配 | |
| 218 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setOrderUserCount(null))); | |
| 219 | + // 测试 virtualGroup 不匹配 | |
| 220 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setVirtualGroup(null))); | |
| 221 | + // 测试 status 不匹配 | |
| 222 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setStatus(null))); | |
| 223 | + // 测试 limitDuration 不匹配 | |
| 224 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setLimitDuration(null))); | |
| 225 | + // 测试 createTime 不匹配 | |
| 226 | + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setCreateTime(null))); | |
| 227 | + // 准备参数 | |
| 228 | + CombinationActivityExportReqVO reqVO = new CombinationActivityExportReqVO(); | |
| 229 | + reqVO.setName(null); | |
| 230 | + reqVO.setSpuId(null); | |
| 231 | + reqVO.setTotalLimitCount(null); | |
| 232 | + reqVO.setSingleLimitCount(null); | |
| 233 | + reqVO.setStartTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 234 | + reqVO.setEndTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 235 | + reqVO.setUserSize(null); | |
| 236 | + reqVO.setTotalNum(null); | |
| 237 | + reqVO.setSuccessNum(null); | |
| 238 | + reqVO.setOrderUserCount(null); | |
| 239 | + reqVO.setVirtualGroup(null); | |
| 240 | + reqVO.setStatus(null); | |
| 241 | + reqVO.setLimitDuration(null); | |
| 242 | + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 243 | + | |
| 244 | + // 调用 | |
| 245 | + List<CombinationActivityDO> list = combinationActivityService.getCombinationActivityList(reqVO); | |
| 246 | + // 断言 | |
| 247 | + assertEquals(1, list.size()); | |
| 248 | + assertPojoEquals(dbCombinationActivity, list.get(0)); | |
| 249 | + } | |
| 250 | + | |
| 251 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/test/resources/sql/clean.sql
| 1 | -DELETE FROM "market_activity"; | |
| 2 | -DELETE FROM "promotion_coupon_template"; | |
| 3 | -DELETE FROM "promotion_coupon"; | |
| 4 | -DELETE FROM "promotion_reward_activity"; | |
| 5 | -DELETE FROM "promotion_discount_activity"; | |
| 6 | -DELETE FROM "promotion_discount_product"; | |
| 7 | -DELETE FROM "promotion_seckill_config"; | |
| 1 | +DELETE | |
| 2 | +FROM "market_activity"; | |
| 3 | +DELETE | |
| 4 | +FROM "promotion_coupon_template"; | |
| 5 | +DELETE | |
| 6 | +FROM "promotion_coupon"; | |
| 7 | +DELETE | |
| 8 | +FROM "promotion_reward_activity"; | |
| 9 | +DELETE | |
| 10 | +FROM "promotion_discount_activity"; | |
| 11 | +DELETE | |
| 12 | +FROM "promotion_discount_product"; | |
| 13 | +DELETE | |
| 14 | +FROM "promotion_seckill_config"; | |
| 15 | +DELETE | |
| 16 | +FROM "promotion_combination_activity"; | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/test/resources/sql/create_tables.sql
| 1 | -CREATE TABLE IF NOT EXISTS "market_activity" ( | |
| 2 | - "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 3 | - "title" varchar(50) NOT NULL, | |
| 4 | - "activity_type" tinyint(4) NOT NULL, | |
| 5 | - "status" tinyint(4) NOT NULL, | |
| 6 | - "start_time" datetime NOT NULL, | |
| 7 | - "end_time" datetime NOT NULL, | |
| 8 | - "invalid_time" datetime, | |
| 9 | - "delete_time" datetime, | |
| 1 | +CREATE TABLE IF NOT EXISTS "market_activity" | |
| 2 | +( | |
| 3 | + "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 4 | + "title" varchar(50) NOT NULL, | |
| 5 | + "activity_type" tinyint(4) NOT NULL, | |
| 6 | + "status" tinyint(4) NOT NULL, | |
| 7 | + "start_time" datetime NOT NULL, | |
| 8 | + "end_time" datetime NOT NULL, | |
| 9 | + "invalid_time" datetime, | |
| 10 | + "delete_time" datetime, | |
| 10 | 11 | "time_limited_discount" varchar(2000), |
| 11 | - "full_privilege" varchar(2000), | |
| 12 | - "creator" varchar(64) DEFAULT '', | |
| 13 | - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 14 | - "updater" varchar(64) DEFAULT '', | |
| 15 | - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 16 | - "deleted" bit NOT NULL DEFAULT FALSE, | |
| 17 | - "tenant_id" bigint(20) NOT NULL, | |
| 12 | + "full_privilege" varchar(2000), | |
| 13 | + "creator" varchar(64) DEFAULT '', | |
| 14 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 15 | + "updater" varchar(64) DEFAULT '', | |
| 16 | + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 17 | + "deleted" bit NOT NULL DEFAULT FALSE, | |
| 18 | + "tenant_id" bigint(20) NOT NULL, | |
| 18 | 19 | PRIMARY KEY ("id") |
| 19 | - ) COMMENT '促销活动'; | |
| 20 | +) COMMENT '促销活动'; | |
| 20 | 21 | |
| 21 | -CREATE TABLE IF NOT EXISTS "promotion_coupon_template" ( | |
| 22 | - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 23 | - "name" varchar NOT NULL, | |
| 24 | - "status" int NOT NULL, | |
| 25 | - "total_count" int NOT NULL, | |
| 26 | - "take_limit_count" int NOT NULL, | |
| 27 | - "take_type" int NOT NULL, | |
| 28 | - "use_price" int NOT NULL, | |
| 29 | - "product_scope" int NOT NULL, | |
| 30 | - "product_spu_ids" varchar, | |
| 31 | - "validity_type" int NOT NULL, | |
| 32 | - "valid_start_time" datetime, | |
| 33 | - "valid_end_time" datetime, | |
| 34 | - "fixed_start_term" int, | |
| 35 | - "fixed_end_term" int, | |
| 36 | - "discount_type" int NOT NULL, | |
| 37 | - "discount_percent" int, | |
| 38 | - "discount_price" int, | |
| 39 | - "discount_limit_price" int, | |
| 40 | - "take_count" int NOT NULL DEFAULT 0, | |
| 41 | - "use_count" int NOT NULL DEFAULT 0, | |
| 42 | - "creator" varchar DEFAULT '', | |
| 43 | - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 44 | - "updater" varchar DEFAULT '', | |
| 45 | - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 46 | - "deleted" bit NOT NULL DEFAULT FALSE, | |
| 47 | - PRIMARY KEY ("id") | |
| 22 | +CREATE TABLE IF NOT EXISTS "promotion_coupon_template" | |
| 23 | +( | |
| 24 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 25 | + "name" varchar NOT NULL, | |
| 26 | + "status" int NOT NULL, | |
| 27 | + "total_count" int NOT NULL, | |
| 28 | + "take_limit_count" int NOT NULL, | |
| 29 | + "take_type" int NOT NULL, | |
| 30 | + "use_price" int NOT NULL, | |
| 31 | + "product_scope" int NOT NULL, | |
| 32 | + "product_spu_ids" varchar, | |
| 33 | + "validity_type" int NOT NULL, | |
| 34 | + "valid_start_time" datetime, | |
| 35 | + "valid_end_time" datetime, | |
| 36 | + "fixed_start_term" int, | |
| 37 | + "fixed_end_term" int, | |
| 38 | + "discount_type" int NOT NULL, | |
| 39 | + "discount_percent" int, | |
| 40 | + "discount_price" int, | |
| 41 | + "discount_limit_price" int, | |
| 42 | + "take_count" int NOT NULL DEFAULT 0, | |
| 43 | + "use_count" int NOT NULL DEFAULT 0, | |
| 44 | + "creator" varchar DEFAULT '', | |
| 45 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 46 | + "updater" varchar DEFAULT '', | |
| 47 | + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 48 | + "deleted" bit NOT NULL DEFAULT FALSE, | |
| 49 | + PRIMARY KEY ("id") | |
| 48 | 50 | ) COMMENT '优惠劵模板'; |
| 49 | 51 | |
| 50 | -CREATE TABLE IF NOT EXISTS "promotion_coupon" ( | |
| 51 | - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 52 | - "template_id" bigint NOT NULL, | |
| 53 | - "name" varchar NOT NULL, | |
| 54 | - "status" int NOT NULL, | |
| 55 | - "user_id" bigint NOT NULL, | |
| 56 | - "take_type" int NOT NULL, | |
| 57 | - "useprice" int NOT NULL, | |
| 58 | - "valid_start_time" datetime NOT NULL, | |
| 59 | - "valid_end_time" datetime NOT NULL, | |
| 60 | - "product_scope" int NOT NULL, | |
| 61 | - "product_spu_ids" varchar, | |
| 62 | - "discount_type" int NOT NULL, | |
| 63 | - "discount_percent" int, | |
| 64 | - "discount_price" int, | |
| 52 | +CREATE TABLE IF NOT EXISTS "promotion_coupon" | |
| 53 | +( | |
| 54 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 55 | + "template_id" bigint NOT NULL, | |
| 56 | + "name" varchar NOT NULL, | |
| 57 | + "status" int NOT NULL, | |
| 58 | + "user_id" bigint NOT NULL, | |
| 59 | + "take_type" int NOT NULL, | |
| 60 | + "useprice" int NOT NULL, | |
| 61 | + "valid_start_time" datetime NOT NULL, | |
| 62 | + "valid_end_time" datetime NOT NULL, | |
| 63 | + "product_scope" int NOT NULL, | |
| 64 | + "product_spu_ids" varchar, | |
| 65 | + "discount_type" int NOT NULL, | |
| 66 | + "discount_percent" int, | |
| 67 | + "discount_price" int, | |
| 65 | 68 | "discount_limit_price" int, |
| 66 | - "use_order_id" bigint, | |
| 67 | - "use_time" datetime, | |
| 68 | - "creator" varchar DEFAULT '', | |
| 69 | - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 70 | - "updater" varchar DEFAULT '', | |
| 71 | - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 72 | - "deleted" bit NOT NULL DEFAULT FALSE, | |
| 69 | + "use_order_id" bigint, | |
| 70 | + "use_time" datetime, | |
| 71 | + "creator" varchar DEFAULT '', | |
| 72 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 73 | + "updater" varchar DEFAULT '', | |
| 74 | + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 75 | + "deleted" bit NOT NULL DEFAULT FALSE, | |
| 73 | 76 | PRIMARY KEY ("id") |
| 74 | 77 | ) COMMENT '优惠劵'; |
| 75 | 78 | |
| 76 | -CREATE TABLE IF NOT EXISTS "promotion_reward_activity" ( | |
| 77 | - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 78 | - "name" varchar NOT NULL, | |
| 79 | - "status" int NOT NULL, | |
| 80 | - "start_time" datetime NOT NULL, | |
| 81 | - "end_time" datetime NOT NULL, | |
| 82 | - "remark" varchar, | |
| 83 | - "condition_type" int NOT NULL, | |
| 84 | - "product_scope" int NOT NULL, | |
| 85 | - "product_spu_ids" varchar, | |
| 86 | - "rules" varchar, | |
| 87 | - "creator" varchar DEFAULT '', | |
| 88 | - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 89 | - "updater" varchar DEFAULT '', | |
| 90 | - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 91 | - "deleted" bit NOT NULL DEFAULT FALSE, | |
| 92 | - PRIMARY KEY ("id") | |
| 79 | +CREATE TABLE IF NOT EXISTS "promotion_reward_activity" | |
| 80 | +( | |
| 81 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 82 | + "name" varchar NOT NULL, | |
| 83 | + "status" int NOT NULL, | |
| 84 | + "start_time" datetime NOT NULL, | |
| 85 | + "end_time" datetime NOT NULL, | |
| 86 | + "remark" varchar, | |
| 87 | + "condition_type" int NOT NULL, | |
| 88 | + "product_scope" int NOT NULL, | |
| 89 | + "product_spu_ids" varchar, | |
| 90 | + "rules" varchar, | |
| 91 | + "creator" varchar DEFAULT '', | |
| 92 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 93 | + "updater" varchar DEFAULT '', | |
| 94 | + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 95 | + "deleted" bit NOT NULL DEFAULT FALSE, | |
| 96 | + PRIMARY KEY ("id") | |
| 93 | 97 | ) COMMENT '满减送活动'; |
| 94 | 98 | |
| 95 | -CREATE TABLE IF NOT EXISTS "promotion_discount_activity" ( | |
| 96 | - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 97 | - "name" varchar NOT NULL, | |
| 98 | - "status" int NOT NULL, | |
| 99 | - "start_time" datetime NOT NULL, | |
| 100 | - "end_time" datetime NOT NULL, | |
| 101 | - "remark" varchar, | |
| 102 | - "creator" varchar DEFAULT '', | |
| 103 | - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 104 | - "updater" varchar DEFAULT '', | |
| 105 | - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 106 | - "deleted" bit NOT NULL DEFAULT FALSE, | |
| 107 | - PRIMARY KEY ("id") | |
| 99 | +CREATE TABLE IF NOT EXISTS "promotion_discount_activity" | |
| 100 | +( | |
| 101 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 102 | + "name" varchar NOT NULL, | |
| 103 | + "status" int NOT NULL, | |
| 104 | + "start_time" datetime NOT NULL, | |
| 105 | + "end_time" datetime NOT NULL, | |
| 106 | + "remark" varchar, | |
| 107 | + "creator" varchar DEFAULT '', | |
| 108 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 109 | + "updater" varchar DEFAULT '', | |
| 110 | + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 111 | + "deleted" bit NOT NULL DEFAULT FALSE, | |
| 112 | + PRIMARY KEY ("id") | |
| 108 | 113 | ) COMMENT '限时折扣活动'; |
| 109 | 114 | |
| 110 | 115 | -- 将该建表 SQL 语句,添加到 yudao-module-promotion-biz 模块的 test/resources/sql/create_tables.sql 文件里 |
| 111 | -CREATE TABLE IF NOT EXISTS "promotion_seckill_activity" ( | |
| 112 | - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 113 | - "spu_id" bigint NOT NULL, | |
| 114 | - "name" varchar NOT NULL, | |
| 115 | - "status" int NOT NULL, | |
| 116 | - "remark" varchar, | |
| 117 | - "start_time" varchar NOT NULL, | |
| 118 | - "end_time" varchar NOT NULL, | |
| 119 | - "sort" int NOT NULL, | |
| 120 | - "config_ids" varchar NOT NULL, | |
| 121 | - "order_count" int NOT NULL, | |
| 122 | - "user_count" int NOT NULL, | |
| 123 | - "total_price" int NOT NULL, | |
| 124 | - "total_limit_count" int, | |
| 116 | +CREATE TABLE IF NOT EXISTS "promotion_seckill_activity" | |
| 117 | +( | |
| 118 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 119 | + "spu_id" bigint NOT NULL, | |
| 120 | + "name" varchar NOT NULL, | |
| 121 | + "status" int NOT NULL, | |
| 122 | + "remark" varchar, | |
| 123 | + "start_time" varchar NOT NULL, | |
| 124 | + "end_time" varchar NOT NULL, | |
| 125 | + "sort" int NOT NULL, | |
| 126 | + "config_ids" varchar NOT NULL, | |
| 127 | + "order_count" int NOT NULL, | |
| 128 | + "user_count" int NOT NULL, | |
| 129 | + "total_price" int NOT NULL, | |
| 130 | + "total_limit_count" int, | |
| 125 | 131 | "single_limit_count" int, |
| 126 | - "stock" int, | |
| 127 | - "total_stock" int, | |
| 128 | - "creator" varchar DEFAULT '', | |
| 129 | - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 130 | - "updater" varchar DEFAULT '', | |
| 131 | - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 132 | - "deleted" bit NOT NULL DEFAULT FALSE, | |
| 133 | - "tenant_id" bigint NOT NULL, | |
| 132 | + "stock" int, | |
| 133 | + "total_stock" int, | |
| 134 | + "creator" varchar DEFAULT '', | |
| 135 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 136 | + "updater" varchar DEFAULT '', | |
| 137 | + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 138 | + "deleted" bit NOT NULL DEFAULT FALSE, | |
| 139 | + "tenant_id" bigint NOT NULL, | |
| 134 | 140 | PRIMARY KEY ("id") |
| 135 | 141 | ) COMMENT '秒杀活动'; |
| 136 | 142 | |
| 137 | -CREATE TABLE IF NOT EXISTS "promotion_seckill_config" ( | |
| 138 | - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 139 | - "name" varchar NOT NULL, | |
| 140 | - "start_time" varchar NOT NULL, | |
| 141 | - "end_time" varchar NOT NULL, | |
| 142 | - "pic_url" varchar NOT NULL, | |
| 143 | - "status" int NOT NULL, | |
| 144 | - "creator" varchar DEFAULT '', | |
| 143 | +CREATE TABLE IF NOT EXISTS "promotion_seckill_config" | |
| 144 | +( | |
| 145 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 146 | + "name" varchar NOT NULL, | |
| 147 | + "start_time" varchar NOT NULL, | |
| 148 | + "end_time" varchar NOT NULL, | |
| 149 | + "pic_url" varchar NOT NULL, | |
| 150 | + "status" int NOT NULL, | |
| 151 | + "creator" varchar DEFAULT '', | |
| 145 | 152 | "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 146 | - "updater" varchar DEFAULT '', | |
| 153 | + "updater" varchar DEFAULT '', | |
| 147 | 154 | "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| 148 | - "deleted" bit NOT NULL DEFAULT FALSE, | |
| 149 | - "tenant_id" bigint NOT NULL, | |
| 155 | + "deleted" bit NOT NULL DEFAULT FALSE, | |
| 156 | + "tenant_id" bigint NOT NULL, | |
| 150 | 157 | PRIMARY KEY ("id") |
| 151 | 158 | ) COMMENT '秒杀时段配置'; |
| 159 | + | |
| 160 | +CREATE TABLE IF NOT EXISTS "promotion_combination_activity" | |
| 161 | +( | |
| 162 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 163 | + "name" varchar NOT NULL, | |
| 164 | + "spu_id" bigint, | |
| 165 | + "total_limit_count" int NOT NULL, | |
| 166 | + "single_limit_count" int NOT NULL, | |
| 167 | + "start_time" varchar NOT NULL, | |
| 168 | + "end_time" varchar NOT NULL, | |
| 169 | + "user_size" int NOT NULL, | |
| 170 | + "total_num" int NOT NULL, | |
| 171 | + "success_num" int NOT NULL, | |
| 172 | + "order_user_count" int NOT NULL, | |
| 173 | + "virtual_group" int NOT NULL, | |
| 174 | + "status" int NOT NULL, | |
| 175 | + "limit_duration" int NOT NULL, | |
| 176 | + "creator" varchar DEFAULT '', | |
| 177 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 178 | + "updater" varchar DEFAULT '', | |
| 179 | + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 180 | + "deleted" bit NOT NULL DEFAULT FALSE, | |
| 181 | + "tenant_id" bigint NOT NULL, | |
| 182 | + PRIMARY KEY ("id") | |
| 183 | +) COMMENT '拼团活动'; | |
| 152 | 184 | \ No newline at end of file | ... | ... |
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java
| ... | ... | @@ -27,6 +27,10 @@ public interface ErrorCodeConstants { |
| 27 | 27 | ErrorCode ORDER_UPDATE_PAID_FAIL_PAY_PRICE_NOT_MATCH = new ErrorCode(1011000016, "交易订单更新支付状态失败,支付单金额不匹配"); |
| 28 | 28 | ErrorCode ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED = new ErrorCode(1011000017, "交易订单发货失败,订单不是【待发货】状态"); |
| 29 | 29 | ErrorCode ORDER_RECEIVE_FAIL_STATUS_NOT_DELIVERED = new ErrorCode(1011000018, "交易订单收货失败,订单不是【待收货】状态"); |
| 30 | + ErrorCode ORDER_COMMENT_FAIL_STATUS_NOT_COMPLETED = new ErrorCode(1011000019, "创建交易订单项的评价失败,订单不是【已完成】状态"); | |
| 31 | + ErrorCode ORDER_COMMENT_STATUS_NOT_FALSE = new ErrorCode(1011000020, "创建交易订单项的评价失败,订单已评价"); | |
| 32 | + ErrorCode ORDER_DELIVERY_FAIL_REFUND_STATUS_NOT_NONE = new ErrorCode(1011000021, "交易订单发货失败,订单已退款或部分退款"); | |
| 33 | + ErrorCode ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS = new ErrorCode(1011000022, "交易订单发货失败,拼团未成功"); | |
| 30 | 34 | |
| 31 | 35 | // ========== After Sale 模块 1011000100 ========== |
| 32 | 36 | ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在"); |
| ... | ... | @@ -63,8 +67,10 @@ public interface ErrorCodeConstants { |
| 63 | 67 | ErrorCode EXPRESS_TEMPLATE_NOT_EXISTS = new ErrorCode(1011005001, "运费模板不存在"); |
| 64 | 68 | |
| 65 | 69 | // ========== 物流 PICK_UP 模块 1011006000 ========== |
| 66 | - | |
| 67 | 70 | ErrorCode PICK_UP_STORE_NOT_EXISTS = new ErrorCode(1011006000, "自提门店不存在"); |
| 68 | 71 | |
| 69 | - | |
| 72 | + // ========== 物流 PICK_UP 模块 1011007000 ========== | |
| 73 | + ErrorCode ORDER_DELIVERY_FAILED_ITEMS_NOT_EMPTY = new ErrorCode(1011007000, "订单发货失败,请选择发货商品"); | |
| 74 | + ErrorCode ORDER_DELIVERY_FAILED_ITEM_NOT_EXISTS = new ErrorCode(1011007001, "订单发货失败,所选发货商品不存在"); | |
| 75 | + ErrorCode ORDER_DELIVERY_FAILED_ITEM_ALREADY_DELIVERY = new ErrorCode(1011007001, "订单发货失败,所选商品已发货"); | |
| 70 | 76 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDeliveryReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.trade.controller.admin.order.vo; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 4 | +import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; | |
| 3 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 6 | import lombok.Data; |
| 5 | 7 | |
| 6 | -import javax.validation.constraints.NotEmpty; | |
| 7 | 8 | import javax.validation.constraints.NotNull; |
| 9 | +import java.util.List; | |
| 8 | 10 | |
| 9 | 11 | @Schema(description = "管理后台 - 订单发货 Request VO") |
| 10 | 12 | @Data |
| ... | ... | @@ -14,12 +16,24 @@ public class TradeOrderDeliveryReqVO { |
| 14 | 16 | @NotNull(message = "订单编号不能为空") |
| 15 | 17 | private Long id; |
| 16 | 18 | |
| 17 | - @Schema(description = "发货物流公司编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 18 | - @NotNull(message = "发货物流公司编号不能为空") | |
| 19 | + @Schema(description = "发货类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") | |
| 20 | + @InEnum(DeliveryTypeEnum.class) | |
| 21 | + @NotNull(message = "发货类型不能为空") | |
| 22 | + private Integer type; | |
| 23 | + | |
| 24 | + @Schema(description = "发货物流公司编号", example = "1") | |
| 19 | 25 | private Long logisticsId; |
| 20 | 26 | |
| 21 | - @Schema(description = "发货物流单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "SF123456789") | |
| 22 | - @NotEmpty(message = "发货物流单号不能为空") | |
| 27 | + @Schema(description = "发货物流单号", example = "SF123456789") | |
| 23 | 28 | private String logisticsNo; |
| 24 | 29 | |
| 30 | + // TODO 订单项商品单独发货 | |
| 31 | + | |
| 32 | + @Schema(description = "发货订单项", example = "[1,2,3]") | |
| 33 | + @NotNull(message = "发货订单项不能为空") | |
| 34 | + private List<Long> orderItemIds; | |
| 35 | + | |
| 36 | + // =============== 同城配送 ================ | |
| 37 | + // TODO | |
| 38 | + | |
| 25 | 39 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java
| ... | ... | @@ -4,8 +4,6 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; |
| 6 | 6 | import cn.iocoder.yudao.module.pay.api.notify.dto.PayOrderNotifyReqDTO; |
| 7 | -import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi; | |
| 8 | -import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; | |
| 9 | 7 | import cn.iocoder.yudao.module.product.api.property.ProductPropertyValueApi; |
| 10 | 8 | import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; |
| 11 | 9 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.*; |
| ... | ... | @@ -30,13 +28,10 @@ import javax.validation.Valid; |
| 30 | 28 | import java.util.List; |
| 31 | 29 | import java.util.Map; |
| 32 | 30 | |
| 33 | -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 34 | 31 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 35 | 32 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| 36 | 33 | import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; |
| 37 | 34 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 38 | -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_ITEM_NOT_FOUND; | |
| 39 | -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND; | |
| 40 | 35 | |
| 41 | 36 | @Tag(name = "用户 App - 交易订单") |
| 42 | 37 | @RestController |
| ... | ... | @@ -47,13 +42,9 @@ public class AppTradeOrderController { |
| 47 | 42 | |
| 48 | 43 | @Resource |
| 49 | 44 | private TradeOrderService tradeOrderService; |
| 50 | - | |
| 51 | 45 | @Resource |
| 52 | 46 | private ProductPropertyValueApi productPropertyValueApi; |
| 53 | 47 | @Resource |
| 54 | - private ProductCommentApi productCommentApi; | |
| 55 | - | |
| 56 | - @Resource | |
| 57 | 48 | private TradeOrderProperties tradeOrderProperties; |
| 58 | 49 | |
| 59 | 50 | @GetMapping("/settlement") |
| ... | ... | @@ -121,7 +112,7 @@ public class AppTradeOrderController { |
| 121 | 112 | // 待发货 |
| 122 | 113 | orderCount.put("undeliveredCount", tradeOrderService.getOrderCount(getLoginUserId(), TradeOrderStatusEnum.UNDELIVERED.getStatus(), null)); |
| 123 | 114 | // 待收货 |
| 124 | - orderCount.put("deliveredCount", tradeOrderService.getOrderCount(getLoginUserId(), TradeOrderStatusEnum.DELIVERED.getStatus(), null)); | |
| 115 | + orderCount.put("deliveredCount", tradeOrderService.getOrderCount(getLoginUserId(), TradeOrderStatusEnum.DELIVERED.getStatus(), null)); | |
| 125 | 116 | // 待评价 |
| 126 | 117 | orderCount.put("uncommentedCount", tradeOrderService.getOrderCount(getLoginUserId(), TradeOrderStatusEnum.COMPLETED.getStatus(), false)); |
| 127 | 118 | return success(orderCount); |
| ... | ... | @@ -164,22 +155,7 @@ public class AppTradeOrderController { |
| 164 | 155 | @PostMapping("/item/create-comment") |
| 165 | 156 | @Operation(summary = "创建交易订单项的评价") |
| 166 | 157 | public CommonResult<Long> createOrderItemComment(@RequestBody AppTradeOrderItemCommentCreateReqVO createReqVO) { |
| 167 | - // TODO @puhui999:这个逻辑,最好写到 service 哈; | |
| 168 | - Long loginUserId = getLoginUserId(); | |
| 169 | - // 先通过订单项 ID 查询订单项是否存在 | |
| 170 | - TradeOrderItemDO orderItemDO = tradeOrderService.getOrderItemByIdAndUserId(createReqVO.getOrderItemId(), loginUserId); | |
| 171 | - if (orderItemDO == null) { | |
| 172 | - throw exception(ORDER_ITEM_NOT_FOUND); | |
| 173 | - } | |
| 174 | - // 校验订单 | |
| 175 | - TradeOrderDO orderDO = tradeOrderService.getOrderByIdAndUserId(orderItemDO.getOrderId(), loginUserId); | |
| 176 | - if (orderDO == null) { | |
| 177 | - throw exception(ORDER_NOT_FOUND); | |
| 178 | - } | |
| 179 | - // TODO @puhui999:要校验订单已完成,但是未评价; | |
| 180 | - | |
| 181 | - ProductCommentCreateReqDTO productCommentCreateReqDTO = TradeOrderConvert.INSTANCE.convert04(createReqVO, orderItemDO); | |
| 182 | - return success(productCommentApi.createComment(productCommentCreateReqDTO)); | |
| 158 | + return success(tradeOrderService.createOrderItemComment(createReqVO)); | |
| 183 | 159 | } |
| 184 | 160 | |
| 185 | 161 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java
| ... | ... | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.trade.controller.app.order.vo; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.validation.Mobile; |
| 5 | 5 | import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; |
| 6 | -import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; | |
| 7 | 6 | import com.fasterxml.jackson.annotation.JsonIgnore; |
| 8 | 7 | import io.swagger.v3.oas.annotations.media.Schema; |
| 9 | 8 | import lombok.Data; |
| ... | ... | @@ -19,11 +18,6 @@ import java.util.List; |
| 19 | 18 | @Data |
| 20 | 19 | public class AppTradeOrderSettlementReqVO { |
| 21 | 20 | |
| 22 | - @NotNull(message = "交易类型不能为空") | |
| 23 | - @InEnum(value = TradeOrderTypeEnum.class, message = "交易类型必须是 {value}") | |
| 24 | - @Deprecated // TODO 芋艿:后续干掉这个字段,对于前端不需要关注这个 | |
| 25 | - private Integer type = 1; | |
| 26 | - | |
| 27 | 21 | @Schema(description = "商品项数组", requiredMode = Schema.RequiredMode.REQUIRED) |
| 28 | 22 | @NotEmpty(message = "商品不能为空") |
| 29 | 23 | private List<Item> items; | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/item/AppTradeOrderItemCommentCreateReqVO.java
| ... | ... | @@ -19,11 +19,6 @@ public class AppTradeOrderItemCommentCreateReqVO { |
| 19 | 19 | @NotNull(message = "交易订单项编号不能为空") |
| 20 | 20 | private Long orderItemId; |
| 21 | 21 | |
| 22 | - // TODO @puhui999:貌似不用这个字段哈; | |
| 23 | - @Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") | |
| 24 | - @NotNull(message = "评分星级 1-5 分不能为空") | |
| 25 | - private Integer scores; | |
| 26 | - | |
| 27 | 22 | @Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") |
| 28 | 23 | @NotNull(message = "描述星级 1-5 分不能为空") |
| 29 | 24 | private Integer descriptionScores; | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java
| ... | ... | @@ -13,10 +13,12 @@ import cn.iocoder.yudao.module.pay.enums.DictTypeConstants; |
| 13 | 13 | import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; |
| 14 | 14 | import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; |
| 15 | 15 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; |
| 16 | +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordReqDTO; | |
| 16 | 17 | import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO; |
| 17 | 18 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; |
| 18 | 19 | import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO; |
| 19 | 20 | import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO; |
| 21 | +import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; | |
| 20 | 22 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDetailRespVO; |
| 21 | 23 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageItemRespVO; |
| 22 | 24 | import cn.iocoder.yudao.module.trade.controller.app.base.property.AppProductPropertyValueDetailRespVO; |
| ... | ... | @@ -25,6 +27,7 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderI |
| 25 | 27 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemRespVO; |
| 26 | 28 | import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; |
| 27 | 29 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; |
| 30 | +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDeliveryDO; | |
| 28 | 31 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; |
| 29 | 32 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum; |
| 30 | 33 | import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; |
| ... | ... | @@ -52,7 +55,6 @@ public interface TradeOrderConvert { |
| 52 | 55 | @Mapping(source = "createReqVO.couponId", target = "couponId"), |
| 53 | 56 | @Mapping(target = "remark", ignore = true), |
| 54 | 57 | @Mapping(source = "createReqVO.remark", target = "userRemark"), |
| 55 | - @Mapping(source = "createReqVO.type", target = "type"), | |
| 56 | 58 | @Mapping(source = "calculateRespBO.price.totalPrice", target = "totalPrice"), |
| 57 | 59 | @Mapping(source = "calculateRespBO.price.discountPrice", target = "discountPrice"), |
| 58 | 60 | @Mapping(source = "calculateRespBO.price.deliveryPrice", target = "deliveryPrice"), |
| ... | ... | @@ -123,7 +125,7 @@ public interface TradeOrderConvert { |
| 123 | 125 | // TODO 芋艿:可简化 |
| 124 | 126 | default PageResult<TradeOrderPageItemRespVO> convertPage(PageResult<TradeOrderDO> pageResult, List<TradeOrderItemDO> orderItems, |
| 125 | 127 | List<ProductPropertyValueDetailRespDTO> propertyValueDetails, |
| 126 | - Map<Long,MemberUserRespDTO> memberUserRespDTOMap) { | |
| 128 | + Map<Long, MemberUserRespDTO> memberUserRespDTOMap) { | |
| 127 | 129 | Map<Long, List<TradeOrderItemDO>> orderItemMap = convertMultiMap(orderItems, TradeOrderItemDO::getOrderId); |
| 128 | 130 | Map<Long, ProductPropertyValueDetailRespDTO> propertyValueDetailMap = convertMap(propertyValueDetails, ProductPropertyValueDetailRespDTO::getValueId); |
| 129 | 131 | // 转化 List |
| ... | ... | @@ -267,23 +269,23 @@ public interface TradeOrderConvert { |
| 267 | 269 | |
| 268 | 270 | AppTradeOrderItemRespVO convert03(TradeOrderItemDO bean); |
| 269 | 271 | |
| 270 | - @Mapping(target = "skuId", source = "tradeOrderItemDO.skuId") | |
| 271 | - @Mapping(target = "orderId", source = "tradeOrderItemDO.orderId") | |
| 272 | - @Mapping(target = "orderItemId", source = "tradeOrderItemDO.id") | |
| 273 | - @Mapping(target = "scores", source = "createReqVO.scores") | |
| 274 | - @Mapping(target = "descriptionScores", source = "createReqVO.descriptionScores") | |
| 275 | - @Mapping(target = "benefitScores", source = "createReqVO.benefitScores") | |
| 276 | - @Mapping(target = "content", source = "createReqVO.content") | |
| 277 | - @Mapping(target = "picUrls", source = "createReqVO.picUrls") | |
| 278 | - @Mapping(target = "anonymous", source = "createReqVO.anonymous") | |
| 279 | - @Mapping(target = "userId", source = "tradeOrderItemDO.userId") | |
| 272 | + @Mappings({ | |
| 273 | + @Mapping(target = "skuId", source = "tradeOrderItemDO.skuId"), | |
| 274 | + @Mapping(target = "orderId", source = "tradeOrderItemDO.orderId"), | |
| 275 | + @Mapping(target = "orderItemId", source = "tradeOrderItemDO.id"), | |
| 276 | + @Mapping(target = "descriptionScores", source = "createReqVO.descriptionScores"), | |
| 277 | + @Mapping(target = "benefitScores", source = "createReqVO.benefitScores"), | |
| 278 | + @Mapping(target = "content", source = "createReqVO.content"), | |
| 279 | + @Mapping(target = "picUrls", source = "createReqVO.picUrls"), | |
| 280 | + @Mapping(target = "anonymous", source = "createReqVO.anonymous"), | |
| 281 | + @Mapping(target = "userId", source = "tradeOrderItemDO.userId") | |
| 282 | + }) | |
| 280 | 283 | ProductCommentCreateReqDTO convert04(AppTradeOrderItemCommentCreateReqVO createReqVO, TradeOrderItemDO tradeOrderItemDO); |
| 281 | 284 | |
| 282 | 285 | default TradePriceCalculateReqBO convert(Long userId, AppTradeOrderSettlementReqVO settlementReqVO, |
| 283 | 286 | List<TradeCartDO> cartList) { |
| 284 | 287 | TradePriceCalculateReqBO reqBO = new TradePriceCalculateReqBO(); |
| 285 | - reqBO.setUserId(userId).setType(settlementReqVO.getType()) | |
| 286 | - .setCouponId(settlementReqVO.getCouponId()).setAddressId(settlementReqVO.getAddressId()) | |
| 288 | + reqBO.setUserId(userId).setCouponId(settlementReqVO.getCouponId()).setAddressId(settlementReqVO.getAddressId()) | |
| 287 | 289 | .setItems(new ArrayList<>(settlementReqVO.getItems().size())); |
| 288 | 290 | // 商品项的构建 |
| 289 | 291 | Map<Long, TradeCartDO> cartMap = convertMap(cartList, TradeCartDO::getId); |
| ... | ... | @@ -318,4 +320,31 @@ public interface TradeOrderConvert { |
| 318 | 320 | |
| 319 | 321 | AppTradeOrderSettlementRespVO convert0(TradePriceCalculateRespBO calculate, AddressRespDTO address); |
| 320 | 322 | |
| 323 | + @Mappings({ | |
| 324 | + @Mapping(target = "activityId", source = "createReqVO.combinationActivityId"), | |
| 325 | + @Mapping(target = "spuId", source = "orderItem.spuId"), | |
| 326 | + @Mapping(target = "skuId", source = "orderItem.skuId"), | |
| 327 | + @Mapping(target = "userId", source = "order.userId"), | |
| 328 | + @Mapping(target = "orderId", source = "order.id"), | |
| 329 | + @Mapping(target = "headId", source = "createReqVO.combinationHeadId"), | |
| 330 | + @Mapping(target = "spuName", source = "orderItem.spuName"), | |
| 331 | + @Mapping(target = "picUrl", source = "orderItem.picUrl"), | |
| 332 | + @Mapping(target = "combinationPrice", source = "orderItem.payPrice"), | |
| 333 | + @Mapping(target = "nickname", source = "user.nickname"), | |
| 334 | + @Mapping(target = "avatar", source = "user.avatar"), | |
| 335 | + @Mapping(target = "status", ignore = true) | |
| 336 | + }) | |
| 337 | + CombinationRecordReqDTO convert(TradeOrderDO order, TradeOrderItemDO orderItem, AppTradeOrderCreateReqVO createReqVO, MemberUserRespDTO user); | |
| 338 | + | |
| 339 | + TradeOrderDeliveryDO covert(Long orderId, Long orderItemId, Long userId, Integer deliveryType, Long logisticsId, String logisticsNo); | |
| 340 | + | |
| 341 | + default List<TradeOrderDeliveryDO> covert(TradeOrderDO order, TradeOrderDeliveryReqVO deliveryReqVO) { | |
| 342 | + ArrayList<TradeOrderDeliveryDO> arrayList = new ArrayList<>(); | |
| 343 | + deliveryReqVO.getOrderItemIds().forEach(item -> { | |
| 344 | + arrayList.add(covert(order.getId(), item, order.getUserId(), deliveryReqVO.getType(), | |
| 345 | + deliveryReqVO.getLogisticsId(), deliveryReqVO.getLogisticsNo())); | |
| 346 | + }); | |
| 347 | + return arrayList; | |
| 348 | + } | |
| 349 | + | |
| 321 | 350 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDeliveryDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.trade.dal.dataobject.order; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 4 | +import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; | |
| 5 | +import com.baomidou.mybatisplus.annotation.KeySequence; | |
| 6 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 7 | +import lombok.*; | |
| 8 | + | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 交易订单发货记录 DO | |
| 12 | + * | |
| 13 | + * @author HUIHUI | |
| 14 | + */ | |
| 15 | +@TableName("trade_order_delivery") | |
| 16 | +@KeySequence("trade_order_delivery_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class TradeOrderDeliveryDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 订单发货记录 id | |
| 27 | + */ | |
| 28 | + private Long id; | |
| 29 | + /** | |
| 30 | + * 订单 id | |
| 31 | + */ | |
| 32 | + private Long orderId; | |
| 33 | + /** | |
| 34 | + * 订单项 id TODO 要不要一个发货记录可对应多个订单项? | |
| 35 | + */ | |
| 36 | + private Long orderItemId; | |
| 37 | + /** | |
| 38 | + * 用户编号 | |
| 39 | + * | |
| 40 | + * 关联 MemberUserDO 的 id 编号 | |
| 41 | + */ | |
| 42 | + private Long userId; | |
| 43 | + /** | |
| 44 | + * 配送方式 | |
| 45 | + * | |
| 46 | + * 枚举 {@link DeliveryTypeEnum} | |
| 47 | + */ | |
| 48 | + private Integer deliveryType; | |
| 49 | + /** | |
| 50 | + * 发货物流公司编号 | |
| 51 | + */ | |
| 52 | + private Long logisticsId; | |
| 53 | + /** | |
| 54 | + * 发货物流单号 | |
| 55 | + */ | |
| 56 | + private String logisticsNo; | |
| 57 | + | |
| 58 | + // TODO 同城配送 | |
| 59 | + | |
| 60 | +} | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderDeliveryMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.trade.dal.mysql.order; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 5 | +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDeliveryDO; | |
| 6 | +import org.apache.ibatis.annotations.Mapper; | |
| 7 | + | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 交易订单发货记录 Mapper | |
| 12 | + * | |
| 13 | + * @author HUIHUI | |
| 14 | + */ | |
| 15 | +@Mapper | |
| 16 | +public interface TradeOrderDeliveryMapper extends BaseMapperX<TradeOrderDeliveryDO> { | |
| 17 | + | |
| 18 | + default List<TradeOrderDeliveryDO> selsectListByOrderIdAndItemIds(Long orderId, List<Long> orderItemIds) { | |
| 19 | + return selectList(new LambdaQueryWrapperX<TradeOrderDeliveryDO>() | |
| 20 | + .eq(TradeOrderDeliveryDO::getOrderId, orderId).in(TradeOrderDeliveryDO::getOrderItemId, orderItemIds)); | |
| 21 | + } | |
| 22 | + | |
| 23 | +} | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderService.java
| ... | ... | @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreate |
| 7 | 7 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO; |
| 8 | 8 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementReqVO; |
| 9 | 9 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; |
| 10 | +import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; | |
| 10 | 11 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; |
| 11 | 12 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; |
| 12 | 13 | |
| ... | ... | @@ -177,4 +178,14 @@ public interface TradeOrderService { |
| 177 | 178 | * @return 得到订单 |
| 178 | 179 | */ |
| 179 | 180 | TradeOrderDO getOrderByIdAndUserId(Long orderId, Long loginUserId); |
| 181 | + | |
| 182 | + /** | |
| 183 | + * 创建订单项评论 | |
| 184 | + * 创建交易订单项的评价 | |
| 185 | + * | |
| 186 | + * @param createReqVO 创建请求 | |
| 187 | + * @return 得到评价 id | |
| 188 | + */ | |
| 189 | + Long createOrderItemComment(AppTradeOrderItemCommentCreateReqVO createReqVO); | |
| 190 | + | |
| 180 | 191 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java
| ... | ... | @@ -17,24 +17,30 @@ import cn.iocoder.yudao.module.pay.api.order.PayOrderApi; |
| 17 | 17 | import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; |
| 18 | 18 | import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO; |
| 19 | 19 | import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum; |
| 20 | +import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi; | |
| 21 | +import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; | |
| 20 | 22 | import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; |
| 21 | 23 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; |
| 24 | +import cn.iocoder.yudao.module.promotion.api.combination.CombinationApi; | |
| 22 | 25 | import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; |
| 23 | 26 | import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO; |
| 27 | +import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; | |
| 24 | 28 | import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi; |
| 25 | 29 | import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO; |
| 26 | -import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | |
| 27 | 30 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; |
| 28 | 31 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReqVO; |
| 29 | 32 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO; |
| 30 | 33 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO; |
| 31 | 34 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementReqVO; |
| 32 | 35 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; |
| 36 | +import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; | |
| 33 | 37 | import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; |
| 34 | 38 | import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; |
| 35 | 39 | import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; |
| 36 | 40 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; |
| 41 | +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDeliveryDO; | |
| 37 | 42 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; |
| 43 | +import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderDeliveryMapper; | |
| 38 | 44 | import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper; |
| 39 | 45 | import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper; |
| 40 | 46 | import cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants; |
| ... | ... | @@ -57,6 +63,7 @@ import java.util.*; |
| 57 | 63 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 58 | 64 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| 59 | 65 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; |
| 66 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 60 | 67 | import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.ORDER_NOT_FOUND; |
| 61 | 68 | import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; |
| 62 | 69 | |
| ... | ... | @@ -93,13 +100,17 @@ public class TradeOrderServiceImpl implements TradeOrderService { |
| 93 | 100 | @Resource |
| 94 | 101 | private MemberUserApi memberUserApi; |
| 95 | 102 | @Resource |
| 96 | - private AdminUserApi adminUserApi; | |
| 103 | + private ProductCommentApi productCommentApi; | |
| 97 | 104 | @Resource |
| 98 | 105 | private NotifyMessageSendApi notifyMessageSendApi; |
| 99 | 106 | |
| 100 | 107 | @Resource |
| 101 | 108 | private TradeOrderProperties tradeOrderProperties; |
| 102 | 109 | |
| 110 | + @Resource | |
| 111 | + private CombinationApi combinationApi; | |
| 112 | + @Resource | |
| 113 | + private TradeOrderDeliveryMapper orderDeliveryMapper; | |
| 103 | 114 | // =================== Order =================== |
| 104 | 115 | |
| 105 | 116 | @Override |
| ... | ... | @@ -153,19 +164,27 @@ public class TradeOrderServiceImpl implements TradeOrderService { |
| 153 | 164 | @Override |
| 154 | 165 | @Transactional(rollbackFor = Exception.class) |
| 155 | 166 | public TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO) { |
| 156 | - // 1. 用户收件地址的校验 | |
| 157 | - AddressRespDTO address = validateAddress(userId, createReqVO.getAddressId()); | |
| 158 | - | |
| 159 | 167 | // 2. 价格计算 |
| 160 | 168 | TradePriceCalculateRespBO calculateRespBO = calculatePrice(userId, createReqVO); |
| 161 | - | |
| 162 | 169 | // 3.1 插入 TradeOrderDO 订单 |
| 163 | - TradeOrderDO order = createTradeOrder(userId, userIp, createReqVO, calculateRespBO, address); | |
| 170 | + TradeOrderDO order = createTradeOrder(userId, userIp, createReqVO, calculateRespBO); | |
| 164 | 171 | // 3.2 插入 TradeOrderItemDO 订单项 |
| 165 | 172 | List<TradeOrderItemDO> orderItems = createTradeOrderItems(order, calculateRespBO); |
| 166 | - | |
| 167 | 173 | // 订单创建完后的逻辑 |
| 168 | 174 | afterCreateTradeOrder(userId, createReqVO, order, orderItems, calculateRespBO); |
| 175 | + // 3.3 校验订单类型 | |
| 176 | + // 拼团 | |
| 177 | + if (ObjectUtil.equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { | |
| 178 | + MemberUserRespDTO user = memberUserApi.getUser(userId); | |
| 179 | + // TODO 拼团一次应该只能选择一种规格的商品 | |
| 180 | + combinationApi.createRecord(TradeOrderConvert.INSTANCE.convert(order, orderItems.get(0), createReqVO, user) | |
| 181 | + .setStatus(CombinationRecordStatusEnum.NOT_PAY.getStatus())); | |
| 182 | + } | |
| 183 | + // TODO 秒杀扣减库存是下单就扣除还是等待订单支付成功再扣除 | |
| 184 | + if (ObjectUtil.equal(TradeOrderTypeEnum.SECKILL.getType(), order.getType())) { | |
| 185 | + | |
| 186 | + } | |
| 187 | + | |
| 169 | 188 | // TODO @LeeYan9: 是可以思考下, 订单的营销优惠记录, 应该记录在哪里, 微信讨论起来! |
| 170 | 189 | return order; |
| 171 | 190 | } |
| ... | ... | @@ -185,19 +204,42 @@ public class TradeOrderServiceImpl implements TradeOrderService { |
| 185 | 204 | return address; |
| 186 | 205 | } |
| 187 | 206 | |
| 207 | + /** | |
| 208 | + * 校验活动返回订单类型 | |
| 209 | + * | |
| 210 | + * @param createReqVO 请求参数 | |
| 211 | + * @return 订单类型 | |
| 212 | + */ | |
| 213 | + private Integer validateActivity(AppTradeOrderCreateReqVO createReqVO) { | |
| 214 | + if (createReqVO.getSeckillActivityId() != null) { | |
| 215 | + return TradeOrderTypeEnum.SECKILL.getType(); | |
| 216 | + } | |
| 217 | + if (createReqVO.getCombinationActivityId() != null) { | |
| 218 | + return TradeOrderTypeEnum.COMBINATION.getType(); | |
| 219 | + } | |
| 220 | + // TODO 砍价敬请期待 | |
| 221 | + return TradeOrderTypeEnum.NORMAL.getType(); | |
| 222 | + } | |
| 223 | + | |
| 188 | 224 | private TradeOrderDO createTradeOrder(Long userId, String clientIp, AppTradeOrderCreateReqVO createReqVO, |
| 189 | - TradePriceCalculateRespBO calculateRespBO, AddressRespDTO address) { | |
| 225 | + TradePriceCalculateRespBO calculateRespBO) { | |
| 226 | + // 用户选择物流配送的时候才需要填写收货地址 | |
| 227 | + AddressRespDTO address = new AddressRespDTO(); | |
| 228 | + if (ObjectUtil.equal(createReqVO.getDeliveryType(), DeliveryTypeEnum.EXPRESS.getMode())) { | |
| 229 | + // 用户收件地址的校验 | |
| 230 | + address = validateAddress(userId, createReqVO.getAddressId()); | |
| 231 | + } | |
| 190 | 232 | TradeOrderDO order = TradeOrderConvert.INSTANCE.convert(userId, clientIp, createReqVO, calculateRespBO, address); |
| 233 | + order.setType(validateActivity(createReqVO)); | |
| 191 | 234 | order.setNo(IdUtil.getSnowflakeNextId() + ""); // TODO @LeeYan9: 思考下, 怎么生成好点哈; 这个是会展示给用户的; |
| 192 | 235 | order.setStatus(TradeOrderStatusEnum.UNPAID.getStatus()); |
| 193 | - order.setType(TradeOrderTypeEnum.NORMAL.getType()); | |
| 194 | 236 | order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()); |
| 195 | 237 | order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum)); |
| 196 | 238 | order.setTerminal(TerminalEnum.H5.getTerminal()); // todo 数据来源? |
| 197 | 239 | // 支付信息 |
| 198 | 240 | order.setAdjustPrice(0).setPayStatus(false); |
| 199 | 241 | // 物流信息 TODO 芋艿:暂时写死物流方式;应该是前端选择的 |
| 200 | - order.setDeliveryType(DeliveryTypeEnum.EXPRESS.getMode()).setDeliveryStatus(TradeOrderDeliveryStatusEnum.UNDELIVERED.getStatus()); | |
| 242 | + order.setDeliveryType(createReqVO.getDeliveryType()).setDeliveryStatus(TradeOrderDeliveryStatusEnum.UNDELIVERED.getStatus()); | |
| 201 | 243 | // 退款信息 |
| 202 | 244 | order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()).setRefundPrice(0); |
| 203 | 245 | tradeOrderMapper.insert(order); |
| ... | ... | @@ -212,7 +254,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { |
| 212 | 254 | |
| 213 | 255 | /** |
| 214 | 256 | * 执行创建完创建完订单后的逻辑 |
| 215 | - * <p> | |
| 257 | + * | |
| 216 | 258 | * 例如说:优惠劵的扣减、积分的扣减、支付单的创建等等 |
| 217 | 259 | * |
| 218 | 260 | * @param userId 用户编号 |
| ... | ... | @@ -254,6 +296,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { |
| 254 | 296 | } |
| 255 | 297 | |
| 256 | 298 | @Override |
| 299 | + @Transactional(rollbackFor = Exception.class) | |
| 257 | 300 | public void updateOrderPaid(Long id, Long payOrderId) { |
| 258 | 301 | // 校验并获得交易订单(可支付) |
| 259 | 302 | KeyValue<TradeOrderDO, PayOrderRespDTO> orderResult = validateOrderPayable(id, payOrderId); |
| ... | ... | @@ -267,7 +310,12 @@ public class TradeOrderServiceImpl implements TradeOrderService { |
| 267 | 310 | if (updateCount == 0) { |
| 268 | 311 | throw exception(ORDER_UPDATE_PAID_STATUS_NOT_UNPAID); |
| 269 | 312 | } |
| 270 | - | |
| 313 | + // 校验活动 | |
| 314 | + // 1、拼团活动 | |
| 315 | + if (ObjectUtil.equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { | |
| 316 | + // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 | |
| 317 | + combinationApi.updateRecordStatusAndStartTime(order.getUserId(), order.getId(), CombinationRecordStatusEnum.ONGOING.getStatus()); | |
| 318 | + } | |
| 271 | 319 | // TODO 芋艿:发送订单变化的消息 |
| 272 | 320 | |
| 273 | 321 | // TODO 芋艿:发送站内信 |
| ... | ... | @@ -277,7 +325,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { |
| 277 | 325 | |
| 278 | 326 | /** |
| 279 | 327 | * 校验交易订单满足被支付的条件 |
| 280 | - * <p> | |
| 328 | + * | |
| 281 | 329 | * 1. 交易订单未支付 |
| 282 | 330 | * 2. 支付单已支付 |
| 283 | 331 | * |
| ... | ... | @@ -308,7 +356,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { |
| 308 | 356 | PayOrderRespDTO payOrder = payOrderApi.getOrder(payOrderId); |
| 309 | 357 | if (payOrder == null) { |
| 310 | 358 | log.error("[validateOrderPaid][order({}) payOrder({}) 不存在,请进行处理!]", id, payOrderId); |
| 311 | - throw exception(cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.ORDER_NOT_FOUND); | |
| 359 | + throw exception(ORDER_NOT_FOUND); | |
| 312 | 360 | } |
| 313 | 361 | // 校验支付单已支付 |
| 314 | 362 | if (!PayOrderStatusEnum.isSuccess(payOrder.getStatus())) { |
| ... | ... | @@ -331,29 +379,50 @@ public class TradeOrderServiceImpl implements TradeOrderService { |
| 331 | 379 | return new KeyValue<>(order, payOrder); |
| 332 | 380 | } |
| 333 | 381 | |
| 334 | - // TODO 芋艿:如果无需发货,需要怎么存储? | |
| 335 | 382 | @Override |
| 383 | + @Transactional(rollbackFor = Exception.class) | |
| 336 | 384 | public void deliveryOrder(Long userId, TradeOrderDeliveryReqVO deliveryReqVO) { |
| 337 | 385 | // 校验并获得交易订单(可发货) |
| 338 | 386 | TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId()); |
| 339 | - // TODO 芋艿:logisticsId 校验存在 发货物流公司 fix | |
| 340 | - DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(deliveryReqVO.getLogisticsId()); | |
| 341 | - if (deliveryExpress == null) { | |
| 342 | - throw exception(EXPRESS_NOT_EXISTS); | |
| 387 | + | |
| 388 | + TradeOrderDO tradeOrderDO = new TradeOrderDO(); | |
| 389 | + List<TradeOrderDeliveryDO> deliveryDOs = new ArrayList<>(); | |
| 390 | + /* TODO | |
| 391 | + * fix: 首先需要店铺设置配送方式如: 自提 、配送、物流-配送、物流-配送-自提、商家配送 | |
| 392 | + * 1.如果店铺有设置配送方式用户只填写收货地址的情况下店家后台自己选择配送方式 | |
| 393 | + * 2.如果店铺只支持到店自提那么下单后默认发货不需要物流 | |
| 394 | + * 3.如果店铺支持 物流-配送-自提 的情况下后台不需要选择配送方式按前端用户选择的配送方式发货即可 | |
| 395 | + */ | |
| 396 | + // 判断发货类型 | |
| 397 | + // 快递发货 | |
| 398 | + if (ObjectUtil.equal(deliveryReqVO.getType(), DeliveryTypeEnum.EXPRESS.getMode())) { | |
| 399 | + deliveryDOs = express(order, deliveryReqVO); | |
| 400 | + tradeOrderDO.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo()); | |
| 401 | + } | |
| 402 | + // 用户自提 | |
| 403 | + if (ObjectUtil.equal(deliveryReqVO.getType(), DeliveryTypeEnum.PICK_UP.getMode())) { | |
| 404 | + deliveryDOs = pickUp(order, deliveryReqVO); | |
| 405 | + // 重置一下确保快递公司和快递单号为空 | |
| 406 | + tradeOrderDO.setLogisticsId(null).setLogisticsNo(""); | |
| 407 | + } | |
| 408 | + // TODO 芋艿:如果无需发货,需要怎么存储? | |
| 409 | + if (ObjectUtil.equal(deliveryReqVO.getType(), DeliveryTypeEnum.NULL.getMode())) { | |
| 410 | + // TODO 情况一:正常走发货逻辑和用户自提有点像 不同点:不需要自提门店只需要用户确认收货 | |
| 411 | + // TODO 情况二:用户下单付款后直接确认收货或等待用户确认收货 | |
| 343 | 412 | } |
| 344 | 413 | |
| 345 | 414 | // 更新 TradeOrderDO 状态为已发货,等待收货 |
| 346 | - int updateCount = tradeOrderMapper.updateByIdAndStatus(order.getId(), order.getStatus(), | |
| 347 | - new TradeOrderDO().setStatus(TradeOrderStatusEnum.DELIVERED.getStatus()) | |
| 348 | - .setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo()) | |
| 349 | - .setDeliveryStatus(TradeOrderDeliveryStatusEnum.DELIVERED.getStatus()).setDeliveryTime(LocalDateTime.now())); | |
| 415 | + tradeOrderDO.setStatus(TradeOrderStatusEnum.DELIVERED.getStatus()) | |
| 416 | + .setDeliveryStatus(TradeOrderDeliveryStatusEnum.DELIVERED.getStatus()).setDeliveryTime(LocalDateTime.now()); | |
| 417 | + int updateCount = tradeOrderMapper.updateByIdAndStatus(order.getId(), order.getStatus(), tradeOrderDO); | |
| 350 | 418 | if (updateCount == 0) { |
| 351 | 419 | throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED); |
| 352 | 420 | } |
| 353 | - | |
| 421 | + // 发货成功记录发货表 | |
| 422 | + orderDeliveryMapper.insertBatch(deliveryDOs); | |
| 354 | 423 | // TODO 芋艿:发送订单变化的消息 |
| 355 | 424 | |
| 356 | - // TODO 芋艿:发送站内信 fix | |
| 425 | + // 发送站内信 | |
| 357 | 426 | // 1、构造消息 |
| 358 | 427 | Map<String, Object> msgMap = new HashMap<>(); |
| 359 | 428 | msgMap.put("orderId", deliveryReqVO.getId()); |
| ... | ... | @@ -364,16 +433,59 @@ public class TradeOrderServiceImpl implements TradeOrderService { |
| 364 | 433 | .setUserId(userId) |
| 365 | 434 | .setTemplateCode("order_delivery") |
| 366 | 435 | .setTemplateParams(msgMap)); |
| 367 | - // TODO 芋艿:OrderLog | |
| 368 | 436 | |
| 369 | - // TODO 设计:like:是否要单独一个 delivery 发货单表??? | |
| 370 | - // TODO 设计:niu:要不要支持一个订单下,多个 order item 单独发货,类似有赞 | |
| 437 | + // TODO 芋艿:OrderLog | |
| 371 | 438 | // TODO 设计:lili:是不是发货后,才支持售后? |
| 372 | 439 | } |
| 373 | 440 | |
| 441 | + private List<TradeOrderDeliveryDO> express(TradeOrderDO order, TradeOrderDeliveryReqVO deliveryReqVO) { | |
| 442 | + // 校验快递公司 | |
| 443 | + DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(deliveryReqVO.getLogisticsId()); | |
| 444 | + if (deliveryExpress == null) { | |
| 445 | + throw exception(EXPRESS_NOT_EXISTS); | |
| 446 | + } | |
| 447 | + // 校验发货商品 | |
| 448 | + validateDeliveryOrderItem(order, deliveryReqVO); | |
| 449 | + // 创建发货记录 | |
| 450 | + return TradeOrderConvert.INSTANCE.covert(order, deliveryReqVO); | |
| 451 | + } | |
| 452 | + | |
| 453 | + private List<TradeOrderDeliveryDO> pickUp(TradeOrderDO order, TradeOrderDeliveryReqVO deliveryReqVO) { | |
| 454 | + // TODO 校验自提门店是否存在 | |
| 455 | + // 重置一下确保快递公司和快递单号为空 | |
| 456 | + deliveryReqVO.setLogisticsId(null); | |
| 457 | + deliveryReqVO.setLogisticsNo(""); | |
| 458 | + // 校验发货商品 | |
| 459 | + validateDeliveryOrderItem(order, deliveryReqVO); | |
| 460 | + // 创建发货记录 | |
| 461 | + return TradeOrderConvert.INSTANCE.covert(order, deliveryReqVO); | |
| 462 | + } | |
| 463 | + | |
| 464 | + private void validateDeliveryOrderItem(TradeOrderDO order, TradeOrderDeliveryReqVO deliveryReqVO) { | |
| 465 | + // TODO 设计:like:是否要单独一个 delivery 发货单表??? fix: 多商品可分开单独发货,添加 trade_order_delivery 交易订单发货日志表关联发货所选订单项设置物流单号 | |
| 466 | + // TODO 设计:niu:要不要支持一个订单下,多个 order item 单独发货,类似有赞 fix | |
| 467 | + // 校验发货商品 | |
| 468 | + if (CollUtil.isEmpty(deliveryReqVO.getOrderItemIds())) { | |
| 469 | + throw exception(ORDER_DELIVERY_FAILED_ITEMS_NOT_EMPTY); | |
| 470 | + } | |
| 471 | + // 校验发货商品是否存在 | |
| 472 | + List<TradeOrderItemDO> orderItemDOs = tradeOrderItemMapper.selectListByOrderId(order.getId()); | |
| 473 | + Set<Long> itemIds = convertSet(orderItemDOs, TradeOrderItemDO::getId); | |
| 474 | + if (!itemIds.containsAll(deliveryReqVO.getOrderItemIds())) { | |
| 475 | + throw exception(ORDER_DELIVERY_FAILED_ITEM_NOT_EXISTS); | |
| 476 | + } | |
| 477 | + // 校验所选订单项是否存在有已发货的 | |
| 478 | + List<TradeOrderDeliveryDO> deliveryDOList = orderDeliveryMapper.selsectListByOrderIdAndItemIds(order.getId(), deliveryReqVO.getOrderItemIds()); | |
| 479 | + if (CollUtil.isNotEmpty(deliveryDOList)) { | |
| 480 | + HashSet<Long> hashSet = CollUtil.newHashSet(deliveryReqVO.getOrderItemIds()); | |
| 481 | + hashSet.retainAll(convertSet(deliveryDOList, TradeOrderDeliveryDO::getOrderItemId)); | |
| 482 | + throw exception(ORDER_DELIVERY_FAILED_ITEM_ALREADY_DELIVERY); | |
| 483 | + } | |
| 484 | + } | |
| 485 | + | |
| 374 | 486 | /** |
| 375 | 487 | * 校验交易订单满足被发货的条件 |
| 376 | - * <p> | |
| 488 | + * | |
| 377 | 489 | * 1. 交易订单未发货 |
| 378 | 490 | * |
| 379 | 491 | * @param id 交易订单编号 |
| ... | ... | @@ -390,6 +502,19 @@ public class TradeOrderServiceImpl implements TradeOrderService { |
| 390 | 502 | || ObjectUtil.notEqual(order.getDeliveryStatus(), TradeOrderDeliveryStatusEnum.UNDELIVERED.getStatus())) { |
| 391 | 503 | throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED); |
| 392 | 504 | } |
| 505 | + // 校验订单是否退款 | |
| 506 | + if (ObjectUtil.notEqual(TradeOrderRefundStatusEnum.NONE.getStatus(), order.getRefundStatus())) { | |
| 507 | + throw exception(ORDER_DELIVERY_FAIL_REFUND_STATUS_NOT_NONE); | |
| 508 | + } | |
| 509 | + // 订单类型:拼团 | |
| 510 | + if (ObjectUtil.equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { | |
| 511 | + // 校验订单拼团是否成功 | |
| 512 | + // TODO 用户 ID 使用当前登录用户的还是订单保存的? | |
| 513 | + if (combinationApi.validateRecordStatusIsSuccess(order.getUserId(), order.getId())) { | |
| 514 | + throw exception(ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS); | |
| 515 | + } | |
| 516 | + } | |
| 517 | + // TODO puhui999: 校验订单砍价是否成功 | |
| 393 | 518 | return order; |
| 394 | 519 | } |
| 395 | 520 | |
| ... | ... | @@ -421,7 +546,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { |
| 421 | 546 | |
| 422 | 547 | /** |
| 423 | 548 | * 校验交易订单满足可售货的条件 |
| 424 | - * <p> | |
| 549 | + * | |
| 425 | 550 | * 1. 交易订单待收货 |
| 426 | 551 | * |
| 427 | 552 | * @param userId 用户编号 |
| ... | ... | @@ -556,6 +681,30 @@ public class TradeOrderServiceImpl implements TradeOrderService { |
| 556 | 681 | return tradeOrderMapper.selectOrderByIdAndUserId(orderId, loginUserId); |
| 557 | 682 | } |
| 558 | 683 | |
| 684 | + @Override | |
| 685 | + public Long createOrderItemComment(AppTradeOrderItemCommentCreateReqVO createReqVO) { | |
| 686 | + Long loginUserId = getLoginUserId(); | |
| 687 | + // 先通过订单项 ID 查询订单项是否存在 | |
| 688 | + TradeOrderItemDO orderItemDO = getOrderItemByIdAndUserId(createReqVO.getOrderItemId(), loginUserId); | |
| 689 | + if (orderItemDO == null) { | |
| 690 | + throw exception(ORDER_ITEM_NOT_FOUND); | |
| 691 | + } | |
| 692 | + // 校验订单 | |
| 693 | + TradeOrderDO orderDO = getOrderByIdAndUserId(orderItemDO.getOrderId(), loginUserId); | |
| 694 | + if (orderDO == null) { | |
| 695 | + throw exception(ORDER_NOT_FOUND); | |
| 696 | + } | |
| 697 | + if (ObjectUtil.notEqual(orderDO.getStatus(), TradeOrderStatusEnum.COMPLETED.getStatus())) { | |
| 698 | + throw exception(ORDER_COMMENT_FAIL_STATUS_NOT_COMPLETED); | |
| 699 | + } | |
| 700 | + if (ObjectUtil.notEqual(orderDO.getCommentStatus(), Boolean.FALSE)) { | |
| 701 | + throw exception(ORDER_COMMENT_STATUS_NOT_FALSE); | |
| 702 | + } | |
| 703 | + | |
| 704 | + ProductCommentCreateReqDTO productCommentCreateReqDTO = TradeOrderConvert.INSTANCE.convert04(createReqVO, orderItemDO); | |
| 705 | + return productCommentApi.createComment(productCommentCreateReqDTO); | |
| 706 | + } | |
| 707 | + | |
| 559 | 708 | /** |
| 560 | 709 | * 判断指定订单的所有订单项,是不是都售后成功 |
| 561 | 710 | * | ... | ... |
yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImplTest.java
| ... | ... | @@ -19,10 +19,10 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 19 | 19 | import static org.junit.jupiter.api.Assertions.assertNull; |
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | -* {@link AddressServiceImpl} 的单元测试类 | |
| 23 | -* | |
| 24 | -* @author 芋道源码 | |
| 25 | -*/ | |
| 22 | + * {@link AddressServiceImpl} 的单元测试类 | |
| 23 | + * | |
| 24 | + * @author 芋道源码 | |
| 25 | + */ | |
| 26 | 26 | @Import(AddressServiceImpl.class) |
| 27 | 27 | public class AddressServiceImplTest extends BaseDbUnitTest { |
| 28 | 28 | |
| ... | ... | @@ -82,8 +82,8 @@ public class AddressServiceImplTest extends BaseDbUnitTest { |
| 82 | 82 | |
| 83 | 83 | // 调用 |
| 84 | 84 | addressService.deleteAddress(dbAddress.getUserId(), id); |
| 85 | - // 校验数据不存在了 | |
| 86 | - assertNull(addressMapper.selectById(id)); | |
| 85 | + // 校验数据不存在了 | |
| 86 | + assertNull(addressMapper.selectById(id)); | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | @Test | ... | ... |