From 409ec555e899646b92bc2325ec9f2ce4766cd2f4 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 3 Jul 2023 08:07:05 +0800 Subject: [PATCH 01/12] =?UTF-8?q?feat=EF=BC=9Amall=20CombinationActivity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProductCommentServiceImplTest.java | 1 - .../promotion/enums/ErrorCodeConstants.java | 2 + .../CombinationActivityController.java | 99 +++++++ .../vo/CombinationActivityBaseVO.java | 72 +++++ .../vo/CombinationActivityCreateReqVO.java | 14 + .../vo/CombinationActivityExcelVO.java | 65 +++++ .../vo/CombinationActivityExportReqVO.java | 60 +++++ .../vo/CombinationActivityPageReqVO.java | 65 +++++ .../vo/CombinationActivityRespVO.java | 22 ++ .../vo/CombinationActivityUpdateReqVO.java | 20 ++ .../CombinationActivityConvert.java | 36 +++ .../combination/CombinationActivityDO.java | 87 ++++++ .../CombinationActivityMapper.java | 59 ++++ .../CombinationActivityService.java | 75 ++++++ .../CombinationActivityServiceImpl.java | 85 ++++++ .../SeckillActivityServiceImpl.java | 6 +- .../CombinationActivityServiceImplTest.java | 251 ++++++++++++++++++ .../service/order/TradeOrderServiceTest.java | 13 +- 18 files changed, 1022 insertions(+), 10 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityBaseVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityCreateReqVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityExcelVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityExportReqVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityPageReqVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityRespVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityUpdateReqVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationActivityDO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java index 7684def99..8d3a3d5b8 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java +++ b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java @@ -151,7 +151,6 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { // 测试分页 tab count AppCommentStatisticsRespVO tabsCount = productCommentService.getCommentStatistics(spuId, Boolean.TRUE); - assertEquals(6, tabsCount.getAllCount()); assertEquals(4, tabsCount.getGoodCount()); assertEquals(2, tabsCount.getMediocreCount()); assertEquals(0, tabsCount.getNegativeCount()); diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index 945709697..2a804b4e8 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -59,4 +59,6 @@ public interface ErrorCodeConstants { ErrorCode SECKILL_TIME_EQUAL = new ErrorCode(1013009002, "秒杀时段开始时间和结束时间不能相等"); ErrorCode SECKILL_START_TIME_BEFORE_END_TIME = new ErrorCode(1013009003, "秒杀时段开始时间不能在结束时间之后"); + // ========== 拼团活动 1013010000 ========== + ErrorCode COMBINATION_ACTIVITY_NOT_EXISTS = new ErrorCode(1013010000, "拼团活动不存在"); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java new file mode 100644 index 000000000..eb2e8c54c --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java @@ -0,0 +1,99 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.*; +import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; +import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.io.IOException; +import java.util.Collection; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; + +@Tag(name = "管理后台 - 拼团活动") +@RestController +@RequestMapping("/promotion/combination-activity") +@Validated +public class CombinationActivityController { + + @Resource + private CombinationActivityService combinationActivityService; + + @PostMapping("/create") + @Operation(summary = "创建拼团活动") + @PreAuthorize("@ss.hasPermission('promotion:combination-activity:create')") + public CommonResult createCombinationActivity(@Valid @RequestBody CombinationActivityCreateReqVO createReqVO) { + return success(combinationActivityService.createCombinationActivity(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新拼团活动") + @PreAuthorize("@ss.hasPermission('promotion:combination-activity:update')") + public CommonResult updateCombinationActivity(@Valid @RequestBody CombinationActivityUpdateReqVO updateReqVO) { + combinationActivityService.updateCombinationActivity(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除拼团活动") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('promotion:combination-activity:delete')") + public CommonResult deleteCombinationActivity(@RequestParam("id") Long id) { + combinationActivityService.deleteCombinationActivity(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得拼团活动") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") + public CommonResult getCombinationActivity(@RequestParam("id") Long id) { + CombinationActivityDO combinationActivity = combinationActivityService.getCombinationActivity(id); + return success(CombinationActivityConvert.INSTANCE.convert(combinationActivity)); + } + + @GetMapping("/list") + @Operation(summary = "获得拼团活动列表") + @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") + @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") + public CommonResult> getCombinationActivityList(@RequestParam("ids") Collection ids) { + List list = combinationActivityService.getCombinationActivityList(ids); + return success(CombinationActivityConvert.INSTANCE.convertList(list)); + } + + @GetMapping("/page") + @Operation(summary = "获得拼团活动分页") + @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") + public CommonResult> getCombinationActivityPage(@Valid CombinationActivityPageReqVO pageVO) { + PageResult pageResult = combinationActivityService.getCombinationActivityPage(pageVO); + return success(CombinationActivityConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出拼团活动 Excel") + @PreAuthorize("@ss.hasPermission('promotion:combination-activity:export')") + @OperateLog(type = EXPORT) + public void exportCombinationActivityExcel(@Valid CombinationActivityExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = combinationActivityService.getCombinationActivityList(exportReqVO); + // 导出 Excel + List datas = CombinationActivityConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "拼团活动.xls", "数据", CombinationActivityExcelVO.class, datas); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityBaseVO.java new file mode 100644 index 000000000..df5aa4c02 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityBaseVO.java @@ -0,0 +1,72 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotNull; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +/** + * 拼团活动 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class CombinationActivityBaseVO { + + @Schema(description = "拼团名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") + @NotNull(message = "拼团名称不能为空") + private String name; + + @Schema(description = "商品 SPU 编号关联 ProductSpuDO 的 id", example = "14016") + private Long spuId; + + @Schema(description = "总限购数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "16218") + @NotNull(message = "总限购数量不能为空") + private Integer totalLimitCount; + + @Schema(description = "单次限购数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "28265") + @NotNull(message = "单次限购数量不能为空") + private Integer singleLimitCount; + + @Schema(description = "开始时间", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "开始时间不能为空") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime startTime; + + @Schema(description = "结束时间", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "结束时间不能为空") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime endTime; + + @Schema(description = "购买人数", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "购买人数不能为空") + private Integer userSize; + + @Schema(description = "开团组数", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "开团组数不能为空") + private Integer totalNum; + + @Schema(description = "成团组数", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "成团组数不能为空") + private Integer successNum; + + @Schema(description = "参与人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "25222") + @NotNull(message = "参与人数不能为空") + private Integer orderUserCount; + + @Schema(description = "虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "虚拟成团不能为空") + private Integer virtualGroup; + + @Schema(description = "活动状态:0开启 1关闭", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") + @NotNull(message = "活动状态:0开启 1关闭不能为空") + private Integer status; + + @Schema(description = "限制时长(小时)", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "限制时长(小时)不能为空") + private Integer limitDuration; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityCreateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityCreateReqVO.java new file mode 100644 index 000000000..ba810671f --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityCreateReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +@Schema(description = "管理后台 - 拼团活动创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class CombinationActivityCreateReqVO extends CombinationActivityBaseVO { + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityExcelVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityExcelVO.java new file mode 100644 index 000000000..2ed5134c2 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityExcelVO.java @@ -0,0 +1,65 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo; + +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; + +import java.time.LocalDateTime; + + +/** + * 拼团活动 Excel VO + * + * @author HUIHUI + */ +@Data +public class CombinationActivityExcelVO { + + @ExcelProperty("活动编号") + private Long id; + + @ExcelProperty("拼团名称") + private String name; + + @ExcelProperty("商品 SPU 编号关联 ProductSpuDO 的 id") + private Long spuId; + + @ExcelProperty("总限购数量") + private Integer totalLimitCount; + + @ExcelProperty("单次限购数量") + private Integer singleLimitCount; + + @ExcelProperty("开始时间") + private LocalDateTime startTime; + + @ExcelProperty("结束时间") + private LocalDateTime endTime; + + @ExcelProperty("购买人数") + private Integer userSize; + + @ExcelProperty("开团组数") + private Integer totalNum; + + @ExcelProperty("成团组数") + private Integer successNum; + + @ExcelProperty("参与人数") + private Integer orderUserCount; + + @ExcelProperty("虚拟成团") + private Integer virtualGroup; + + @ExcelProperty(value = "活动状态:0开启 1关闭", converter = DictConvert.class) + @DictFormat("common_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 + private Integer status; + + @ExcelProperty("限制时长(小时)") + private Integer limitDuration; + + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityExportReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityExportReqVO.java new file mode 100644 index 000000000..8529ead67 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityExportReqVO.java @@ -0,0 +1,60 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 拼团活动 Excel 导出 Request VO,参数和 CombinationActivityPageReqVO 是一致的") +@Data +public class CombinationActivityExportReqVO { + + @Schema(description = "拼团名称", example = "赵六") + private String name; + + @Schema(description = "商品 SPU 编号关联 ProductSpuDO 的 id", example = "14016") + private Long spuId; + + @Schema(description = "总限购数量", example = "16218") + private Integer totalLimitCount; + + @Schema(description = "单次限购数量", example = "28265") + private Integer singleLimitCount; + + @Schema(description = "开始时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] startTime; + + @Schema(description = "结束时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] endTime; + + @Schema(description = "购买人数") + private Integer userSize; + + @Schema(description = "开团组数") + private Integer totalNum; + + @Schema(description = "成团组数") + private Integer successNum; + + @Schema(description = "参与人数", example = "25222") + private Integer orderUserCount; + + @Schema(description = "虚拟成团") + private Integer virtualGroup; + + @Schema(description = "活动状态:0开启 1关闭", example = "0") + private Integer status; + + @Schema(description = "限制时长(小时)") + private Integer limitDuration; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityPageReqVO.java new file mode 100644 index 000000000..9c2feb928 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityPageReqVO.java @@ -0,0 +1,65 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 拼团活动分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class CombinationActivityPageReqVO extends PageParam { + + @Schema(description = "拼团名称", example = "赵六") + private String name; + + @Schema(description = "商品 SPU 编号关联 ProductSpuDO 的 id", example = "14016") + private Long spuId; + + @Schema(description = "总限购数量", example = "16218") + private Integer totalLimitCount; + + @Schema(description = "单次限购数量", example = "28265") + private Integer singleLimitCount; + + @Schema(description = "开始时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] startTime; + + @Schema(description = "结束时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] endTime; + + @Schema(description = "购买人数") + private Integer userSize; + + @Schema(description = "开团组数") + private Integer totalNum; + + @Schema(description = "成团组数") + private Integer successNum; + + @Schema(description = "参与人数", example = "25222") + private Integer orderUserCount; + + @Schema(description = "虚拟成团") + private Integer virtualGroup; + + @Schema(description = "活动状态:0开启 1关闭", example = "0") + private Integer status; + + @Schema(description = "限制时长(小时)") + private Integer limitDuration; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityRespVO.java new file mode 100644 index 000000000..64b22bde1 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityRespVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 拼团活动 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class CombinationActivityRespVO extends CombinationActivityBaseVO { + + @Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901") + private Long id; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime createTime; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityUpdateReqVO.java new file mode 100644 index 000000000..750080c79 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityUpdateReqVO.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import javax.validation.constraints.NotNull; + +@Schema(description = "管理后台 - 拼团活动更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class CombinationActivityUpdateReqVO extends CombinationActivityBaseVO { + + @Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901") + @NotNull(message = "活动编号不能为空") + private Long id; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java new file mode 100644 index 000000000..e1c8e9951 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.module.promotion.convert.combination; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityExcelVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * 拼团活动 Convert + * + * @author HUIHUI + */ +@Mapper +public interface CombinationActivityConvert { + + CombinationActivityConvert INSTANCE = Mappers.getMapper(CombinationActivityConvert.class); + + CombinationActivityDO convert(CombinationActivityCreateReqVO bean); + + CombinationActivityDO convert(CombinationActivityUpdateReqVO bean); + + CombinationActivityRespVO convert(CombinationActivityDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationActivityDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationActivityDO.java new file mode 100644 index 000000000..f5eef6ef0 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationActivityDO.java @@ -0,0 +1,87 @@ +package cn.iocoder.yudao.module.promotion.dal.dataobject.combination; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.sun.xml.internal.bind.v2.TODO; +import lombok.*; + +import java.time.LocalDateTime; + +/** + * 拼团活动 DO + * + * @author HUIHUI + */ +@TableName("promotion_combination_activity") +@KeySequence("promotion_combination_activity_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class CombinationActivityDO extends BaseDO { + + /** + * 活动编号 + */ + @TableId + private Long id; + /** + * 拼团名称 + */ + private String name; + /** + * 商品 SPU 编号关联 ProductSpuDO 的 id + */ + private Long spuId; + /** + * 总限购数量 + */ + private Integer totalLimitCount; + /** + * 单次限购数量 + */ + private Integer singleLimitCount; + /** + * 开始时间 + */ + private LocalDateTime startTime; + /** + * 结束时间 + */ + private LocalDateTime endTime; + /** + * 购买人数 + */ + private Integer userSize; + /** + * 开团组数 + */ + private Integer totalNum; + /** + * 成团组数 + */ + private Integer successNum; + /** + * 参与人数 + */ + private Integer orderUserCount; + /** + * 虚拟成团 + */ + private Integer virtualGroup; + /** + * 活动状态:0开启 1关闭 + *

+ * 枚举 {@link TODO common_status 对应的类} + */ + private Integer status; + /** + * 限制时长(小时) + */ + private Integer limitDuration; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java new file mode 100644 index 000000000..b672d0fab --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java @@ -0,0 +1,59 @@ +package cn.iocoder.yudao.module.promotion.dal.mysql.combination; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityExportReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * 拼团活动 Mapper + * + * @author HUIHUI + */ +@Mapper +public interface CombinationActivityMapper extends BaseMapperX { + + default PageResult selectPage(CombinationActivityPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(CombinationActivityDO::getName, reqVO.getName()) + .eqIfPresent(CombinationActivityDO::getSpuId, reqVO.getSpuId()) + .eqIfPresent(CombinationActivityDO::getTotalLimitCount, reqVO.getTotalLimitCount()) + .eqIfPresent(CombinationActivityDO::getSingleLimitCount, reqVO.getSingleLimitCount()) + .betweenIfPresent(CombinationActivityDO::getStartTime, reqVO.getStartTime()) + .betweenIfPresent(CombinationActivityDO::getEndTime, reqVO.getEndTime()) + .eqIfPresent(CombinationActivityDO::getUserSize, reqVO.getUserSize()) + .eqIfPresent(CombinationActivityDO::getTotalNum, reqVO.getTotalNum()) + .eqIfPresent(CombinationActivityDO::getSuccessNum, reqVO.getSuccessNum()) + .eqIfPresent(CombinationActivityDO::getOrderUserCount, reqVO.getOrderUserCount()) + .eqIfPresent(CombinationActivityDO::getVirtualGroup, reqVO.getVirtualGroup()) + .eqIfPresent(CombinationActivityDO::getStatus, reqVO.getStatus()) + .eqIfPresent(CombinationActivityDO::getLimitDuration, reqVO.getLimitDuration()) + .betweenIfPresent(CombinationActivityDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(CombinationActivityDO::getId)); + } + + default List selectList(CombinationActivityExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .likeIfPresent(CombinationActivityDO::getName, reqVO.getName()) + .eqIfPresent(CombinationActivityDO::getSpuId, reqVO.getSpuId()) + .eqIfPresent(CombinationActivityDO::getTotalLimitCount, reqVO.getTotalLimitCount()) + .eqIfPresent(CombinationActivityDO::getSingleLimitCount, reqVO.getSingleLimitCount()) + .betweenIfPresent(CombinationActivityDO::getStartTime, reqVO.getStartTime()) + .betweenIfPresent(CombinationActivityDO::getEndTime, reqVO.getEndTime()) + .eqIfPresent(CombinationActivityDO::getUserSize, reqVO.getUserSize()) + .eqIfPresent(CombinationActivityDO::getTotalNum, reqVO.getTotalNum()) + .eqIfPresent(CombinationActivityDO::getSuccessNum, reqVO.getSuccessNum()) + .eqIfPresent(CombinationActivityDO::getOrderUserCount, reqVO.getOrderUserCount()) + .eqIfPresent(CombinationActivityDO::getVirtualGroup, reqVO.getVirtualGroup()) + .eqIfPresent(CombinationActivityDO::getStatus, reqVO.getStatus()) + .eqIfPresent(CombinationActivityDO::getLimitDuration, reqVO.getLimitDuration()) + .betweenIfPresent(CombinationActivityDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(CombinationActivityDO::getId)); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java new file mode 100644 index 000000000..a4bbf1fbc --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java @@ -0,0 +1,75 @@ +package cn.iocoder.yudao.module.promotion.service.combination; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityExportReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; + +import javax.validation.Valid; +import java.util.Collection; +import java.util.List; + +/** + * 拼团活动 Service 接口 + * + * @author HUIHUI + */ +public interface CombinationActivityService { + + /** + * 创建拼团活动 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createCombinationActivity(@Valid CombinationActivityCreateReqVO createReqVO); + + /** + * 更新拼团活动 + * + * @param updateReqVO 更新信息 + */ + void updateCombinationActivity(@Valid CombinationActivityUpdateReqVO updateReqVO); + + /** + * 删除拼团活动 + * + * @param id 编号 + */ + void deleteCombinationActivity(Long id); + + /** + * 获得拼团活动 + * + * @param id 编号 + * @return 拼团活动 + */ + CombinationActivityDO getCombinationActivity(Long id); + + /** + * 获得拼团活动列表 + * + * @param ids 编号 + * @return 拼团活动列表 + */ + List getCombinationActivityList(Collection ids); + + /** + * 获得拼团活动分页 + * + * @param pageReqVO 分页查询 + * @return 拼团活动分页 + */ + PageResult getCombinationActivityPage(CombinationActivityPageReqVO pageReqVO); + + /** + * 获得拼团活动列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 拼团活动列表 + */ + List getCombinationActivityList(CombinationActivityExportReqVO exportReqVO); + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java new file mode 100644 index 000000000..1b1d87796 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -0,0 +1,85 @@ +package cn.iocoder.yudao.module.promotion.service.combination; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityExportReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; +import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationActivityMapper; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.util.Collection; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_ACTIVITY_NOT_EXISTS; + +/** + * 拼团活动 Service 实现类 + * + * @author HUIHUI + */ +@Service +@Validated +public class CombinationActivityServiceImpl implements CombinationActivityService { + + @Resource + private CombinationActivityMapper combinationActivityMapper; + + @Override + public Long createCombinationActivity(CombinationActivityCreateReqVO createReqVO) { + // 插入 + CombinationActivityDO combinationActivity = CombinationActivityConvert.INSTANCE.convert(createReqVO); + combinationActivityMapper.insert(combinationActivity); + // 返回 + return combinationActivity.getId(); + } + + @Override + public void updateCombinationActivity(CombinationActivityUpdateReqVO updateReqVO) { + // 校验存在 + validateCombinationActivityExists(updateReqVO.getId()); + // 更新 + CombinationActivityDO updateObj = CombinationActivityConvert.INSTANCE.convert(updateReqVO); + combinationActivityMapper.updateById(updateObj); + } + + @Override + public void deleteCombinationActivity(Long id) { + // 校验存在 + validateCombinationActivityExists(id); + // 删除 + combinationActivityMapper.deleteById(id); + } + + private void validateCombinationActivityExists(Long id) { + if (combinationActivityMapper.selectById(id) == null) { + throw exception(COMBINATION_ACTIVITY_NOT_EXISTS); + } + } + + @Override + public CombinationActivityDO getCombinationActivity(Long id) { + return combinationActivityMapper.selectById(id); + } + + @Override + public List getCombinationActivityList(Collection ids) { + return combinationActivityMapper.selectBatchIds(ids); + } + + @Override + public PageResult getCombinationActivityPage(CombinationActivityPageReqVO pageReqVO) { + return combinationActivityMapper.selectPage(pageReqVO); + } + + @Override + public List getCombinationActivityList(CombinationActivityExportReqVO exportReqVO) { + return combinationActivityMapper.selectList(exportReqVO); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java index e95449649..dc86a85ca 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.promotion.service.seckill.seckillactivity; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -26,6 +25,7 @@ import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; @@ -109,13 +109,13 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { // 过滤出所有 spuIds 有交集的活动 List doList = activityDOs.stream().filter(s -> { // 判断 spu 是否有交集 - List spuIdsClone = ArrayUtil.clone(s.getSpuIds()); + ArrayList spuIdsClone = CollUtil.newArrayList(s.getSpuIds()); spuIdsClone.retainAll(spuIds); if (CollUtil.isEmpty(spuIdsClone)) { return false; } // 判断秒杀时段是否有交集 - List configIdsClone = ArrayUtil.clone(s.getConfigIds()); + List configIdsClone = CollUtil.newArrayList(s.getConfigIds()); configIdsClone.retainAll(configIds); return CollUtil.isNotEmpty(configIdsClone); }).collect(Collectors.toList()); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java new file mode 100644 index 000000000..ba757e1ea --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java @@ -0,0 +1,251 @@ +package cn.iocoder.yudao.module.promotion.service.combination; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityExportReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; +import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationActivityMapper; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_ACTIVITY_NOT_EXISTS; +import static org.junit.jupiter.api.Assertions.*; + +/** + * {@link CombinationActivityServiceImpl} 的单元测试类 + * + * @author HUIHUI + */ +@Import(CombinationActivityServiceImpl.class) +public class CombinationActivityServiceImplTest extends BaseDbUnitTest { + + @Resource + private CombinationActivityServiceImpl combinationActivityService; + + @Resource + private CombinationActivityMapper combinationActivityMapper; + + @Test + public void testCreateCombinationActivity_success() { + // 准备参数 + CombinationActivityCreateReqVO reqVO = randomPojo(CombinationActivityCreateReqVO.class); + + // 调用 + Long combinationActivityId = combinationActivityService.createCombinationActivity(reqVO); + // 断言 + assertNotNull(combinationActivityId); + // 校验记录的属性是否正确 + CombinationActivityDO combinationActivity = combinationActivityMapper.selectById(combinationActivityId); + assertPojoEquals(reqVO, combinationActivity); + } + + @Test + public void testUpdateCombinationActivity_success() { + // mock 数据 + CombinationActivityDO dbCombinationActivity = randomPojo(CombinationActivityDO.class); + combinationActivityMapper.insert(dbCombinationActivity);// @Sql: 先插入出一条存在的数据 + // 准备参数 + CombinationActivityUpdateReqVO reqVO = randomPojo(CombinationActivityUpdateReqVO.class, o -> { + o.setId(dbCombinationActivity.getId()); // 设置更新的 ID + }); + + // 调用 + combinationActivityService.updateCombinationActivity(reqVO); + // 校验是否更新正确 + CombinationActivityDO combinationActivity = combinationActivityMapper.selectById(reqVO.getId()); // 获取最新的 + assertPojoEquals(reqVO, combinationActivity); + } + + @Test + public void testUpdateCombinationActivity_notExists() { + // 准备参数 + CombinationActivityUpdateReqVO reqVO = randomPojo(CombinationActivityUpdateReqVO.class); + + // 调用, 并断言异常 + assertServiceException(() -> combinationActivityService.updateCombinationActivity(reqVO), COMBINATION_ACTIVITY_NOT_EXISTS); + } + + @Test + public void testDeleteCombinationActivity_success() { + // mock 数据 + CombinationActivityDO dbCombinationActivity = randomPojo(CombinationActivityDO.class); + combinationActivityMapper.insert(dbCombinationActivity);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Long id = dbCombinationActivity.getId(); + + // 调用 + combinationActivityService.deleteCombinationActivity(id); + // 校验数据不存在了 + assertNull(combinationActivityMapper.selectById(id)); + } + + @Test + public void testDeleteCombinationActivity_notExists() { + // 准备参数 + Long id = randomLongId(); + + // 调用, 并断言异常 + assertServiceException(() -> combinationActivityService.deleteCombinationActivity(id), COMBINATION_ACTIVITY_NOT_EXISTS); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetCombinationActivityPage() { + // mock 数据 + CombinationActivityDO dbCombinationActivity = randomPojo(CombinationActivityDO.class, o -> { // 等会查询到 + o.setName(null); + o.setSpuId(null); + o.setTotalLimitCount(null); + o.setSingleLimitCount(null); + o.setStartTime(null); + o.setEndTime(null); + o.setUserSize(null); + o.setTotalNum(null); + o.setSuccessNum(null); + o.setOrderUserCount(null); + o.setVirtualGroup(null); + o.setStatus(null); + o.setLimitDuration(null); + o.setCreateTime(null); + }); + combinationActivityMapper.insert(dbCombinationActivity); + // 测试 name 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setName(null))); + // 测试 spuId 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSpuId(null))); + // 测试 totalLimitCount 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalLimitCount(null))); + // 测试 singleLimitCount 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSingleLimitCount(null))); + // 测试 startTime 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setStartTime(null))); + // 测试 endTime 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setEndTime(null))); + // 测试 userSize 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setUserSize(null))); + // 测试 totalNum 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalNum(null))); + // 测试 successNum 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSuccessNum(null))); + // 测试 orderUserCount 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setOrderUserCount(null))); + // 测试 virtualGroup 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setVirtualGroup(null))); + // 测试 status 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setStatus(null))); + // 测试 limitDuration 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setLimitDuration(null))); + // 测试 createTime 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setCreateTime(null))); + // 准备参数 + CombinationActivityPageReqVO reqVO = new CombinationActivityPageReqVO(); + reqVO.setName(null); + reqVO.setSpuId(null); + reqVO.setTotalLimitCount(null); + reqVO.setSingleLimitCount(null); + reqVO.setStartTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); + reqVO.setEndTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); + reqVO.setUserSize(null); + reqVO.setTotalNum(null); + reqVO.setSuccessNum(null); + reqVO.setOrderUserCount(null); + reqVO.setVirtualGroup(null); + reqVO.setStatus(null); + reqVO.setLimitDuration(null); + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); + + // 调用 + PageResult pageResult = combinationActivityService.getCombinationActivityPage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbCombinationActivity, pageResult.getList().get(0)); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetCombinationActivityList() { + // mock 数据 + CombinationActivityDO dbCombinationActivity = randomPojo(CombinationActivityDO.class, o -> { // 等会查询到 + o.setName(null); + o.setSpuId(null); + o.setTotalLimitCount(null); + o.setSingleLimitCount(null); + o.setStartTime(null); + o.setEndTime(null); + o.setUserSize(null); + o.setTotalNum(null); + o.setSuccessNum(null); + o.setOrderUserCount(null); + o.setVirtualGroup(null); + o.setStatus(null); + o.setLimitDuration(null); + o.setCreateTime(null); + }); + combinationActivityMapper.insert(dbCombinationActivity); + // 测试 name 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setName(null))); + // 测试 spuId 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSpuId(null))); + // 测试 totalLimitCount 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalLimitCount(null))); + // 测试 singleLimitCount 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSingleLimitCount(null))); + // 测试 startTime 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setStartTime(null))); + // 测试 endTime 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setEndTime(null))); + // 测试 userSize 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setUserSize(null))); + // 测试 totalNum 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalNum(null))); + // 测试 successNum 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSuccessNum(null))); + // 测试 orderUserCount 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setOrderUserCount(null))); + // 测试 virtualGroup 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setVirtualGroup(null))); + // 测试 status 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setStatus(null))); + // 测试 limitDuration 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setLimitDuration(null))); + // 测试 createTime 不匹配 + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setCreateTime(null))); + // 准备参数 + CombinationActivityExportReqVO reqVO = new CombinationActivityExportReqVO(); + reqVO.setName(null); + reqVO.setSpuId(null); + reqVO.setTotalLimitCount(null); + reqVO.setSingleLimitCount(null); + reqVO.setStartTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); + reqVO.setEndTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); + reqVO.setUserSize(null); + reqVO.setTotalNum(null); + reqVO.setSuccessNum(null); + reqVO.setOrderUserCount(null); + reqVO.setVirtualGroup(null); + reqVO.setStatus(null); + reqVO.setLimitDuration(null); + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); + + // 调用 + List list = combinationActivityService.getCombinationActivityList(reqVO); + // 断言 + assertEquals(1, list.size()); + assertPojoEquals(dbCombinationActivity, list.get(0)); + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceTest.java index 184d1c178..db8079ac4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceTest.java @@ -115,7 +115,8 @@ public class TradeOrderServiceTest extends BaseDbUnitTest { when(productSpuApi.getSpuList(eq(asSet(11L, 21L)))).thenReturn(Arrays.asList(spu01, spu02)); // mock 方法(用户收件地址的校验) AddressRespDTO addressRespDTO = new AddressRespDTO().setId(10L).setUserId(userId).setName("芋艿") - .setMobile("15601691300").setAreaId(3306).setPostCode("85757").setDetailAddress("土豆村"); + //.setMobile("15601691300").setAreaId(3306).setPostCode("85757").setDetailAddress("土豆村"); + .setMobile("15601691300").setAreaId(3306).setDetailAddress("土豆村"); when(addressApi.getAddress(eq(10L), eq(userId))).thenReturn(addressRespDTO); // mock 方法(价格计算) PriceCalculateRespDTO.OrderItem priceOrderItem01 = new PriceCalculateRespDTO.OrderItem() @@ -150,12 +151,12 @@ public class TradeOrderServiceTest extends BaseDbUnitTest { }))).thenReturn(1000L); // 调用方法 - Long tradeOrderId = tradeOrderService.createOrder(userId, userIp, reqVO); + TradeOrderDO order = tradeOrderService.createOrder(userId, userIp, reqVO); // 断言 TradeOrderDO 订单 List tradeOrderDOs = tradeOrderMapper.selectList(); assertEquals(tradeOrderDOs.size(), 1); TradeOrderDO tradeOrderDO = tradeOrderDOs.get(0); - assertEquals(tradeOrderDO.getId(), tradeOrderId); + assertEquals(tradeOrderDO.getId(), order.getId()); assertNotNull(tradeOrderDO.getNo()); assertEquals(tradeOrderDO.getType(), TradeOrderTypeEnum.NORMAL.getType()); assertEquals(tradeOrderDO.getTerminal(), TerminalEnum.H5.getTerminal()); @@ -195,7 +196,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest { TradeOrderItemDO tradeOrderItemDO01 = tradeOrderItemDOs.get(0); assertNotNull(tradeOrderItemDO01.getId()); assertEquals(tradeOrderItemDO01.getUserId(), userId); - assertEquals(tradeOrderItemDO01.getOrderId(), tradeOrderId); + assertEquals(tradeOrderItemDO01.getOrderId(), order.getId()); assertEquals(tradeOrderItemDO01.getSpuId(), 11L); assertEquals(tradeOrderItemDO01.getSkuId(), 1L); assertEquals(tradeOrderItemDO01.getProperties().size(), 1); @@ -213,7 +214,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest { TradeOrderItemDO tradeOrderItemDO02 = tradeOrderItemDOs.get(1); assertNotNull(tradeOrderItemDO02.getId()); assertEquals(tradeOrderItemDO02.getUserId(), userId); - assertEquals(tradeOrderItemDO02.getOrderId(), tradeOrderId); + assertEquals(tradeOrderItemDO02.getOrderId(), order.getId()); assertEquals(tradeOrderItemDO02.getSpuId(), 21L); assertEquals(tradeOrderItemDO02.getSkuId(), 2L); assertEquals(tradeOrderItemDO02.getProperties().size(), 1); @@ -239,7 +240,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest { verify(couponApi).useCoupon(argThat(reqDTO -> { assertEquals(reqDTO.getId(), reqVO.getCouponId()); assertEquals(reqDTO.getUserId(), userId); - assertEquals(reqDTO.getOrderId(), tradeOrderId); + assertEquals(reqDTO.getOrderId(), order.getId()); return true; })); } From c5630518418d01e214371e28885971d913bda597 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 3 Jul 2023 14:44:27 +0800 Subject: [PATCH 02/12] =?UTF-8?q?feat=EF=BC=9Amall=20product=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E9=80=9A=E8=BF=87=20spuIds=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=20spu=20=E8=AF=A6=E6=83=85=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/spu/ProductSpuController.java | 10 ++++++++++ .../product/convert/spu/ProductSpuConvert.java | 13 +++++++++++++ .../product/service/sku/ProductSkuService.java | 2 +- .../product/service/sku/ProductSkuServiceImpl.java | 2 +- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java index 0df57ca4f..2fcffb275 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java +++ b/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; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -100,6 +101,15 @@ public class ProductSpuController { return success(ProductSpuConvert.INSTANCE.convertList02(list)); } + @GetMapping("/list") + @Operation(summary = "获得商品 SPU 详情列表") + @Parameter(name = "spuIds", description = "spu 编号列表", required = true, example = "[1,2,3]") + @PreAuthorize("@ss.hasPermission('product:spu:query')") + public CommonResult> getSpuList(@RequestParam("spuIds") Collection spuIds) { + return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespListVO( + productSpuService.getSpuList(spuIds), productSkuService.getSkuListBySpuId(spuIds))); + } + @GetMapping("/page") @Operation(summary = "获得商品 SPU 分页") @PreAuthorize("@ss.hasPermission('product:spu:query')") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java index aaad240a4..833ed0722 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.product.convert.spu; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; @@ -18,6 +19,7 @@ import org.mapstruct.factory.Mappers; import java.util.ArrayList; import java.util.List; +import java.util.Map; import static cn.hutool.core.util.ObjectUtil.defaultIfNull; @@ -107,4 +109,15 @@ public interface ProductSpuConvert { return detailRespVO; } + default List convertForSpuDetailRespListVO(List spus, List skus) { + ArrayList vos = new ArrayList<>(); + Map> skuMultiMap = CollectionUtils.convertMultiMap(skus, ProductSkuDO::getSpuId); + spus.forEach(spu -> { + ProductSpuDetailRespVO detailRespVO = convert03(spu); + detailRespVO.setSkus(ProductSkuConvert.INSTANCE.convertList(skuMultiMap.get(spu.getId()))); + vos.add(detailRespVO); + }); + return vos; + } + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java index 4c106d1bc..fbc9830bf 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java +++ b/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 { * @param spuIds spu 编码集合 * @return 商品 sku 集合 */ - List getSkuListBySpuId(List spuIds); + List getSkuListBySpuId(Collection spuIds); /** * 通过 spuId 删除 sku 信息 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java index 3f77fbe8d..7c6c5030e 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java +++ b/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 { } @Override - public List getSkuListBySpuId(List spuIds) { + public List getSkuListBySpuId(Collection spuIds) { return productSkuMapper.selectListBySpuId(spuIds); } From 41d996f7f3d940b3bba2bd63d457a3f4c8fe8c8c Mon Sep 17 00:00:00 2001 From: puhui999 Date: Tue, 4 Jul 2023 11:21:03 +0800 Subject: [PATCH 03/12] =?UTF-8?q?feat=EF=BC=9Amall=20promotion=20Combinati?= =?UTF-8?q?onProduct?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/enums/ErrorCodeConstants.java | 1 + .../CombinationActivityController.java | 4 +- .../CombinationActivityBaseVO.java | 41 +++------- .../CombinationActivityCreateReqVO.java | 20 +++++ .../CombinationActivityExcelVO.java | 2 +- .../CombinationActivityExportReqVO.java | 2 +- .../CombinationActivityPageReqVO.java | 2 +- .../activity/CombinationActivityRespVO.java | 43 ++++++++++ .../CombinationActivityUpdateReqVO.java | 2 +- .../vo/product/CombinationProductBaseVO.java | 27 +++++++ .../CombinationProductCreateReqVO.java} | 6 +- .../vo/product/CombinationProductExcelVO.java | 43 ++++++++++ .../CombinationProductExportReqVO.java | 42 ++++++++++ .../product/CombinationProductPageReqVO.java | 47 +++++++++++ .../CombinationProductRespVO.java} | 8 +- .../CombinationProductUpdateReqVO.java | 20 +++++ .../CombinationActivityConvert.java | 31 +++++-- .../CombinationActivityDO.java | 12 ++- .../CombinationProductDO.java | 60 ++++++++++++++ .../dataobject/combination/package-info.java | 1 + .../CombinationActivityMapper.java | 59 -------------- .../CombinationActivityMapper.java | 37 +++++++++ .../CombinationProductMapper.java | 47 +++++++++++ .../dal/mysql/combination/package-info.java | 1 + .../CombinationActivityService.java | 10 +-- .../CombinationActivityServiceImpl.java | 80 ++++++++++++++++--- .../SeckillActivityServiceImpl.java | 37 +++------ .../module/promotion/util/PromotionUtils.java | 22 +++++ .../CombinationActivityServiceImplTest.java | 20 ++--- 29 files changed, 561 insertions(+), 166 deletions(-) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/{ => activity}/CombinationActivityBaseVO.java (54%) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityCreateReqVO.java rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/{ => activity}/CombinationActivityExcelVO.java (98%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/{ => activity}/CombinationActivityExportReqVO.java (99%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/{ => activity}/CombinationActivityPageReqVO.java (99%) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/{ => activity}/CombinationActivityUpdateReqVO.java (96%) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductBaseVO.java rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/{CombinationActivityCreateReqVO.java => product/CombinationProductCreateReqVO.java} (62%) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductExcelVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductExportReqVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductPageReqVO.java rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/{CombinationActivityRespVO.java => product/CombinationProductRespVO.java} (63%) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductUpdateReqVO.java rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/{ => combinationactivity}/CombinationActivityDO.java (83%) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationProductDO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/package-info.java delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationActivityMapper.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/package-info.java diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index 2a804b4e8..21d464fb5 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -61,4 +61,5 @@ public interface ErrorCodeConstants { // ========== 拼团活动 1013010000 ========== ErrorCode COMBINATION_ACTIVITY_NOT_EXISTS = new ErrorCode(1013010000, "拼团活动不存在"); + ErrorCode COMBINATION_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1013010000, "存在商品参加了其它拼团活动"); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java index eb2e8c54c..3e97673bb 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java @@ -4,9 +4,9 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.*; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.*; import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; -import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityBaseVO.java similarity index 54% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityBaseVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityBaseVO.java index df5aa4c02..1130779e0 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityBaseVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityBaseVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -6,6 +6,7 @@ import org.springframework.format.annotation.DateTimeFormat; import javax.validation.constraints.NotNull; import java.time.LocalDateTime; +import java.util.List; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @@ -16,12 +17,13 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @Data public class CombinationActivityBaseVO { - @Schema(description = "拼团名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") + @Schema(description = "拼团名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "越拼越省钱") @NotNull(message = "拼团名称不能为空") private String name; - @Schema(description = "商品 SPU 编号关联 ProductSpuDO 的 id", example = "14016") - private Long spuId; + @Schema(description = "商品 SPU 编号关联 ProductSpuDO 的 id", example = "[1,2,3]") + @NotNull(message = "拼团商品不能为空") + private List spuIds; @Schema(description = "总限购数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "16218") @NotNull(message = "总限购数量不能为空") @@ -31,40 +33,15 @@ public class CombinationActivityBaseVO { @NotNull(message = "单次限购数量不能为空") private Integer singleLimitCount; - @Schema(description = "开始时间", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "开始时间不能为空") + @Schema(description = "活动时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]") + @NotNull(message = "活动时间不能为空") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime startTime; - - @Schema(description = "结束时间", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "结束时间不能为空") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime endTime; - - @Schema(description = "购买人数", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "购买人数不能为空") - private Integer userSize; - - @Schema(description = "开团组数", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "开团组数不能为空") - private Integer totalNum; - - @Schema(description = "成团组数", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "成团组数不能为空") - private Integer successNum; + private LocalDateTime[] activityTime; @Schema(description = "参与人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "25222") @NotNull(message = "参与人数不能为空") private Integer orderUserCount; - @Schema(description = "虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "虚拟成团不能为空") - private Integer virtualGroup; - - @Schema(description = "活动状态:0开启 1关闭", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") - @NotNull(message = "活动状态:0开启 1关闭不能为空") - private Integer status; - @Schema(description = "限制时长(小时)", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "限制时长(小时)不能为空") private Integer limitDuration; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityCreateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityCreateReqVO.java new file mode 100644 index 000000000..e75ee8b49 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityCreateReqVO.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity; + +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductCreateReqVO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.util.List; + +@Schema(description = "管理后台 - 拼团活动创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class CombinationActivityCreateReqVO extends CombinationActivityBaseVO { + + @Schema(description = "秒杀商品", requiredMode = Schema.RequiredMode.REQUIRED) + private List products; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityExcelVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityExcelVO.java similarity index 98% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityExcelVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityExcelVO.java index 2ed5134c2..29537a5d3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityExcelVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityExcelVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity; import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityExportReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityExportReqVO.java similarity index 99% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityExportReqVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityExportReqVO.java index 8529ead67..f2fe0df3e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityExportReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityExportReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityPageReqVO.java similarity index 99% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityPageReqVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityPageReqVO.java index 9c2feb928..e6cfce527 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityPageReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityPageReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity; import cn.iocoder.yudao.framework.common.pojo.PageParam; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java new file mode 100644 index 000000000..f7163967d --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java @@ -0,0 +1,43 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import javax.validation.constraints.NotNull; +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 拼团活动 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class CombinationActivityRespVO extends CombinationActivityBaseVO { + + @Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901") + private Long id; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime createTime; + + @Schema(description = "购买人数", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "购买人数不能为空") + private Integer userSize; + + @Schema(description = "开团组数", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "开团组数不能为空") + private Integer totalNum; + + @Schema(description = "成团组数", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "成团组数不能为空") + private Integer successNum; + + @Schema(description = "虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "虚拟成团不能为空") + private Integer virtualGroup; + + @Schema(description = "活动状态:0开启 1关闭", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") + @NotNull(message = "活动状态:0开启 1关闭不能为空") + private Integer status; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityUpdateReqVO.java similarity index 96% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityUpdateReqVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityUpdateReqVO.java index 750080c79..1ecbf1e48 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityUpdateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityUpdateReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductBaseVO.java new file mode 100644 index 000000000..fac9cddd0 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductBaseVO.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 拼团商品 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class CombinationProductBaseVO { + + @Schema(description = "商品 spuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "30563") + @NotNull(message = "商品 spuId 不能为空") + private Long spuId; + + @Schema(description = "商品 skuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "30563") + @NotNull(message = "商品 skuId 不能为空") + private Long skuId; + + @Schema(description = "拼团价格,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "27682") + @NotNull(message = "拼团价格,单位分不能为空") + private Integer activePrice; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityCreateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductCreateReqVO.java similarity index 62% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityCreateReqVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductCreateReqVO.java index ba810671f..ee805bccc 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityCreateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductCreateReqVO.java @@ -1,14 +1,14 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -@Schema(description = "管理后台 - 拼团活动创建 Request VO") +@Schema(description = "管理后台 - 拼团商品创建 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class CombinationActivityCreateReqVO extends CombinationActivityBaseVO { +public class CombinationProductCreateReqVO extends CombinationProductBaseVO { } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductExcelVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductExcelVO.java new file mode 100644 index 000000000..831b7cfec --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductExcelVO.java @@ -0,0 +1,43 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product; + +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 拼团商品 Excel VO + * + * @author HUIHUI + */ +@Data +public class CombinationProductExcelVO { + + @ExcelProperty("编号") + private Long id; + + @ExcelProperty("拼团活动编号") + private Long activityId; + + @ExcelProperty("商品 SPU 编号") + private Long spuId; + + @ExcelProperty("商品 SKU 编号") + private Long skuId; + + @ExcelProperty("拼团商品状态") + private Integer activityStatus; + + @ExcelProperty("活动开始时间点") + private LocalDateTime activityStartTime; + + @ExcelProperty("活动结束时间点") + private LocalDateTime activityEndTime; + + @ExcelProperty("拼团价格,单位分") + private Integer activePrice; + + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductExportReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductExportReqVO.java new file mode 100644 index 000000000..45cdd49bb --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductExportReqVO.java @@ -0,0 +1,42 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 拼团商品 Excel 导出 Request VO,参数和 CombinationProductPageReqVO 是一致的") +@Data +public class CombinationProductExportReqVO { + + @Schema(description = "拼团活动编号", example = "6829") + private Long activityId; + + @Schema(description = "商品 SPU 编号", example = "18731") + private Long spuId; + + @Schema(description = "商品 SKU 编号", example = "31675") + private Long skuId; + + @Schema(description = "拼团商品状态", example = "2") + private Integer activityStatus; + + @Schema(description = "活动开始时间点") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] activityStartTime; + + @Schema(description = "活动结束时间点") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] activityEndTime; + + @Schema(description = "拼团价格,单位分", example = "27682") + private Integer activePrice; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductPageReqVO.java new file mode 100644 index 000000000..02bcc070c --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductPageReqVO.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 拼团商品分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class CombinationProductPageReqVO extends PageParam { + + @Schema(description = "拼团活动编号", example = "6829") + private Long activityId; + + @Schema(description = "商品 SPU 编号", example = "18731") + private Long spuId; + + @Schema(description = "商品 SKU 编号", example = "31675") + private Long skuId; + + @Schema(description = "拼团商品状态", example = "2") + private Integer activityStatus; + + @Schema(description = "活动开始时间点") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] activityStartTime; + + @Schema(description = "活动结束时间点") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] activityEndTime; + + @Schema(description = "拼团价格,单位分", example = "27682") + private Integer activePrice; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductRespVO.java similarity index 63% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityRespVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductRespVO.java index 64b22bde1..eeac5c3b5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/CombinationActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo; +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -7,13 +7,13 @@ import lombok.ToString; import java.time.LocalDateTime; -@Schema(description = "管理后台 - 拼团活动 Response VO") +@Schema(description = "管理后台 - 拼团商品 Response VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class CombinationActivityRespVO extends CombinationActivityBaseVO { +public class CombinationProductRespVO extends CombinationProductBaseVO { - @Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901") + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28322") private Long id; @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductUpdateReqVO.java new file mode 100644 index 000000000..80365db84 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductUpdateReqVO.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import javax.validation.constraints.NotNull; + +@Schema(description = "管理后台 - 拼团商品更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class CombinationProductUpdateReqVO extends CombinationProductBaseVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28322") + @NotNull(message = "编号不能为空") + private Long id; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java index e1c8e9951..4bdebcf84 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java @@ -1,14 +1,18 @@ package cn.iocoder.yudao.module.promotion.convert.combination; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityExcelVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityRespVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityUpdateReqVO; -import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityExcelVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductCreateReqVO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; +import java.util.ArrayList; import java.util.List; /** @@ -21,6 +25,8 @@ public interface CombinationActivityConvert { CombinationActivityConvert INSTANCE = Mappers.getMapper(CombinationActivityConvert.class); + @Mapping(target = "startTime", expression = "java(bean.getActivityTime()[0])") + @Mapping(target = "endTime", expression = "java(bean.getActivityTime()[1])") CombinationActivityDO convert(CombinationActivityCreateReqVO bean); CombinationActivityDO convert(CombinationActivityUpdateReqVO bean); @@ -33,4 +39,19 @@ public interface CombinationActivityConvert { List convertList02(List list); + default List convertList(CombinationActivityDO activityDO, List products) { + ArrayList productDOs = new ArrayList<>(); + products.forEach(item -> { + CombinationProductDO productDO = new CombinationProductDO(); + productDO.setActivityId(activityDO.getId()); + productDO.setSpuId(item.getSpuId()); + productDO.setSkuId(item.getSkuId()); + productDO.setActivityStatus(0); // TODO 拼团状态枚举未定义不确定有些什么状态 + productDO.setActivityStartTime(activityDO.getStartTime()); + productDO.setActivityEndTime(activityDO.getEndTime()); + productDO.setActivePrice(item.getActivePrice()); + productDOs.add(productDO); + }); + return productDOs; + } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationActivityDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationActivityDO.java similarity index 83% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationActivityDO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationActivityDO.java index f5eef6ef0..ee20c3393 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationActivityDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationActivityDO.java @@ -1,13 +1,16 @@ -package cn.iocoder.yudao.module.promotion.dal.dataobject.combination; +package cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler; import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import com.sun.xml.internal.bind.v2.TODO; import lombok.*; import java.time.LocalDateTime; +import java.util.List; /** * 拼团活动 DO @@ -36,7 +39,8 @@ public class CombinationActivityDO extends BaseDO { /** * 商品 SPU 编号关联 ProductSpuDO 的 id */ - private Long spuId; + @TableField(typeHandler = LongListTypeHandler.class) + private List spuIds; /** * 总限购数量 */ @@ -76,7 +80,7 @@ public class CombinationActivityDO extends BaseDO { /** * 活动状态:0开启 1关闭 *

- * 枚举 {@link TODO common_status 对应的类} + * 枚举 {@link CommonStatusEnum} */ private Integer status; /** diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationProductDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationProductDO.java new file mode 100644 index 000000000..5c4744ee9 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationProductDO.java @@ -0,0 +1,60 @@ +package cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; + +import java.time.LocalDateTime; + +/** + * 拼团商品 DO + * + * @author HUIHUI + */ +@TableName("promotion_combination_product") +@KeySequence("promotion_combination_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class CombinationProductDO extends BaseDO { + + /** + * 编号 + */ + @TableId + private Long id; + /** + * 拼团活动编号 + */ + private Long activityId; + /** + * 商品 SPU 编号 + */ + private Long spuId; + /** + * 商品 SKU 编号 + */ + private Long skuId; + /** + * 拼团商品状态 + */ + private Integer activityStatus; + /** + * 活动开始时间点 + */ + private LocalDateTime activityStartTime; + /** + * 活动结束时间点 + */ + private LocalDateTime activityEndTime; + /** + * 拼团价格,单位分 + */ + private Integer activePrice; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/package-info.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/package-info.java new file mode 100644 index 000000000..c8403140e --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.module.promotion.dal.dataobject.combination; \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java deleted file mode 100644 index b672d0fab..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java +++ /dev/null @@ -1,59 +0,0 @@ -package cn.iocoder.yudao.module.promotion.dal.mysql.combination; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityExportReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityPageReqVO; -import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; - -/** - * 拼团活动 Mapper - * - * @author HUIHUI - */ -@Mapper -public interface CombinationActivityMapper extends BaseMapperX { - - default PageResult selectPage(CombinationActivityPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .likeIfPresent(CombinationActivityDO::getName, reqVO.getName()) - .eqIfPresent(CombinationActivityDO::getSpuId, reqVO.getSpuId()) - .eqIfPresent(CombinationActivityDO::getTotalLimitCount, reqVO.getTotalLimitCount()) - .eqIfPresent(CombinationActivityDO::getSingleLimitCount, reqVO.getSingleLimitCount()) - .betweenIfPresent(CombinationActivityDO::getStartTime, reqVO.getStartTime()) - .betweenIfPresent(CombinationActivityDO::getEndTime, reqVO.getEndTime()) - .eqIfPresent(CombinationActivityDO::getUserSize, reqVO.getUserSize()) - .eqIfPresent(CombinationActivityDO::getTotalNum, reqVO.getTotalNum()) - .eqIfPresent(CombinationActivityDO::getSuccessNum, reqVO.getSuccessNum()) - .eqIfPresent(CombinationActivityDO::getOrderUserCount, reqVO.getOrderUserCount()) - .eqIfPresent(CombinationActivityDO::getVirtualGroup, reqVO.getVirtualGroup()) - .eqIfPresent(CombinationActivityDO::getStatus, reqVO.getStatus()) - .eqIfPresent(CombinationActivityDO::getLimitDuration, reqVO.getLimitDuration()) - .betweenIfPresent(CombinationActivityDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(CombinationActivityDO::getId)); - } - - default List selectList(CombinationActivityExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .likeIfPresent(CombinationActivityDO::getName, reqVO.getName()) - .eqIfPresent(CombinationActivityDO::getSpuId, reqVO.getSpuId()) - .eqIfPresent(CombinationActivityDO::getTotalLimitCount, reqVO.getTotalLimitCount()) - .eqIfPresent(CombinationActivityDO::getSingleLimitCount, reqVO.getSingleLimitCount()) - .betweenIfPresent(CombinationActivityDO::getStartTime, reqVO.getStartTime()) - .betweenIfPresent(CombinationActivityDO::getEndTime, reqVO.getEndTime()) - .eqIfPresent(CombinationActivityDO::getUserSize, reqVO.getUserSize()) - .eqIfPresent(CombinationActivityDO::getTotalNum, reqVO.getTotalNum()) - .eqIfPresent(CombinationActivityDO::getSuccessNum, reqVO.getSuccessNum()) - .eqIfPresent(CombinationActivityDO::getOrderUserCount, reqVO.getOrderUserCount()) - .eqIfPresent(CombinationActivityDO::getVirtualGroup, reqVO.getVirtualGroup()) - .eqIfPresent(CombinationActivityDO::getStatus, reqVO.getStatus()) - .eqIfPresent(CombinationActivityDO::getLimitDuration, reqVO.getLimitDuration()) - .betweenIfPresent(CombinationActivityDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(CombinationActivityDO::getId)); - } - -} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationActivityMapper.java new file mode 100644 index 000000000..80ed4e0ec --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationActivityMapper.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityExportReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * 拼团活动 Mapper + * + * @author HUIHUI + */ +@Mapper +public interface CombinationActivityMapper extends BaseMapperX { + + default PageResult selectPage(CombinationActivityPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(CombinationActivityDO::getName, reqVO.getName()) + .orderByDesc(CombinationActivityDO::getId)); + } + + default List selectList(CombinationActivityExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .likeIfPresent(CombinationActivityDO::getName, reqVO.getName()) + .eqIfPresent(CombinationActivityDO::getStatus, reqVO.getStatus()) + .orderByDesc(CombinationActivityDO::getId)); + } + + default List selectListByStatus(Integer status) { + return selectList(CombinationActivityDO::getStatus, status); + } +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java new file mode 100644 index 000000000..54e13053a --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductExportReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductPageReqVO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * 拼团商品 Mapper + * + * @author HUIHUI + */ +@Mapper +public interface CombinationProductMapper extends BaseMapperX { + + default PageResult selectPage(CombinationProductPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(CombinationProductDO::getActivityId, reqVO.getActivityId()) + .eqIfPresent(CombinationProductDO::getSpuId, reqVO.getSpuId()) + .eqIfPresent(CombinationProductDO::getSkuId, reqVO.getSkuId()) + .eqIfPresent(CombinationProductDO::getActivityStatus, reqVO.getActivityStatus()) + .betweenIfPresent(CombinationProductDO::getActivityStartTime, reqVO.getActivityStartTime()) + .betweenIfPresent(CombinationProductDO::getActivityEndTime, reqVO.getActivityEndTime()) + .eqIfPresent(CombinationProductDO::getActivePrice, reqVO.getActivePrice()) + .betweenIfPresent(CombinationProductDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(CombinationProductDO::getId)); + } + + default List selectList(CombinationProductExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .eqIfPresent(CombinationProductDO::getActivityId, reqVO.getActivityId()) + .eqIfPresent(CombinationProductDO::getSpuId, reqVO.getSpuId()) + .eqIfPresent(CombinationProductDO::getSkuId, reqVO.getSkuId()) + .eqIfPresent(CombinationProductDO::getActivityStatus, reqVO.getActivityStatus()) + .betweenIfPresent(CombinationProductDO::getActivityStartTime, reqVO.getActivityStartTime()) + .betweenIfPresent(CombinationProductDO::getActivityEndTime, reqVO.getActivityEndTime()) + .eqIfPresent(CombinationProductDO::getActivePrice, reqVO.getActivePrice()) + .betweenIfPresent(CombinationProductDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(CombinationProductDO::getId)); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/package-info.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/package-info.java new file mode 100644 index 000000000..b63efd052 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.module.promotion.dal.mysql.combination; \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java index a4bbf1fbc..0417b2bd9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.module.promotion.service.combination; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityExportReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityPageReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityUpdateReqVO; -import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityExportReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; import javax.validation.Valid; import java.util.Collection; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index 1b1d87796..b388c3e18 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -1,22 +1,37 @@ package cn.iocoder.yudao.module.promotion.service.combination; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityExportReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityPageReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityUpdateReqVO; +import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; +import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityExportReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductCreateReqVO; import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; -import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; -import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationActivityMapper; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; +import cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity.CombinationActivityMapper; +import cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity.CombinationProductMapper; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_ACTIVITY_NOT_EXISTS; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_ACTIVITY_SPU_CONFLICTS; +import static cn.iocoder.yudao.module.promotion.util.PromotionUtils.validateProductSkuExistence; /** * 拼团活动 Service 实现类 @@ -29,14 +44,59 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic @Resource private CombinationActivityMapper combinationActivityMapper; + @Resource + private CombinationProductMapper combinationProductMapper; + @Resource + private ProductSpuApi productSpuApi; + @Resource + private ProductSkuApi productSkuApi; @Override public Long createCombinationActivity(CombinationActivityCreateReqVO createReqVO) { - // 插入 - CombinationActivityDO combinationActivity = CombinationActivityConvert.INSTANCE.convert(createReqVO); - combinationActivityMapper.insert(combinationActivity); + // 校验商品 SPU 是否存在是否参加的别的活动 + validateProductCombinationConflict(createReqVO.getSpuIds()); + // 获取所选 spu下的所有 sku + List skus = productSkuApi.getSkuListBySpuId(createReqVO.getSpuIds()); + // 校验商品 sku 是否存在 + validateProductSkuExistence(skus, createReqVO.getProducts(), CombinationProductCreateReqVO::getSkuId); + + // TODO 艿艿 有个小问题:现在有活动时间和限制时长,活动时间的结束时间早于设置的限制时间怎么算状态比如: + // 活动时间 2023-08-05 15:00:00 - 2023-08-05 15:20:00 限制时长 2小时,那么活动时间结束就结束还是加时到满两小时 + // 插入拼团活动 + CombinationActivityDO activityDO = CombinationActivityConvert.INSTANCE.convert(createReqVO); + // TODO 营销相关属性初始化 + activityDO.setUserSize(0); + activityDO.setTotalNum(0); + activityDO.setSuccessNum(0); + activityDO.setOrderUserCount(0); + activityDO.setVirtualGroup(0); + activityDO.setStatus(CommonStatusEnum.ENABLE.getStatus()); + combinationActivityMapper.insert(activityDO); + // 插入商品 + List productDOs = CombinationActivityConvert.INSTANCE.convertList(activityDO, createReqVO.getProducts()); + combinationProductMapper.insertBatch(productDOs); // 返回 - return combinationActivity.getId(); + return activityDO.getId(); + } + + private void validateProductCombinationConflict(List spuIds) { + // 校验商品 spu 是否存在 + List spuList = productSpuApi.getSpuList(spuIds); + if (ObjectUtil.notEqual(spuIds.size(), spuList.size())) { + throw exception(SPU_NOT_EXISTS); + } + // 查询所有开启的秒杀活动 + List activityDOs = combinationActivityMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus()); + // 过滤出所有 spuIds 有交集的活动 + List doList = activityDOs.stream().filter(s -> { + // 判断 spu 是否有交集 + ArrayList spuIdsClone = CollUtil.newArrayList(s.getSpuIds()); + spuIdsClone.retainAll(spuIds); + return CollUtil.isNotEmpty(spuIdsClone); + }).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(doList)) { + throw exception(COMBINATION_ACTIVITY_SPU_CONFLICTS); + } } @Override diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java index dc86a85ca..9c9e559b2 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; @@ -12,7 +11,8 @@ import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductBaseVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductUpdateReqVO; import cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity.SeckillActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; @@ -28,13 +28,12 @@ import javax.annotation.Resource; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Set; import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.module.promotion.util.PromotionUtils.validateProductSkuExistence; import static java.util.Arrays.asList; /** @@ -61,8 +60,10 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { public Long createSeckillActivity(SeckillActivityCreateReqVO createReqVO) { // 校验商品秒秒杀时段是否冲突 validateProductSpuSeckillConflict(createReqVO.getConfigIds(), createReqVO.getSpuIds()); + // 获取所选 spu下的所有 sku + List skus = productSkuApi.getSkuListBySpuId(createReqVO.getSpuIds()); // 校验商品 sku 是否存在 - validateProductSkuExistence(createReqVO.getSpuIds(), createReqVO.getProducts()); + validateProductSkuExistence(skus, createReqVO.getProducts(), SeckillProductCreateReqVO::getSkuId); // 插入秒杀活动 SeckillActivityDO activity = SeckillActivityConvert.INSTANCE.convert(createReqVO) @@ -74,28 +75,6 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { return activity.getId(); } - private void validateProductSkuExistence(List spuIds, List products) { - // 校验 spu 个数是否相等 - // TODO @puhui999:不用校验 SPU 哈,只校验 sku 对应的 spuId 是否一致; - Set convertedSpuIds = CollectionUtils.convertSet(products, T::getSpuId); - if (ObjectUtil.notEqual(spuIds.size(), convertedSpuIds.size())) { - throw exception(SKU_NOT_EXISTS); - } - // 获取所选 spu下的所有 sku - // TODO @puhui999:变量可以简单一点;skus - List skuRespDTOs = productSkuApi.getSkuListBySpuId(spuIds); - // 校验 sku 个数是否一致 - Set skuIdsSet = CollectionUtils.convertSet(products, T::getSkuId); - Set skuIdsSet1 = CollectionUtils.convertSet(skuRespDTOs, ProductSkuRespDTO::getId); - if (ObjectUtil.notEqual(skuIdsSet.size(), skuIdsSet1.size())) { - throw exception(SKU_NOT_EXISTS); - } - // 校验 skuId 是否存在 - if (!skuIdsSet1.containsAll(skuIdsSet) || !skuIdsSet.containsAll(skuIdsSet1)) { - throw exception(SKU_NOT_EXISTS); - } - } - private void validateProductSpuSeckillConflict(List configIds, List spuIds) { // 校验秒杀时段是否存在 seckillConfigService.validateSeckillConfigExists(configIds); @@ -133,8 +112,10 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { } // 校验商品是否冲突 validateProductSpuSeckillConflict(updateReqVO.getConfigIds(), updateReqVO.getSpuIds()); + // 获取所选 spu下的所有 sku + List skus = productSkuApi.getSkuListBySpuId(updateReqVO.getSpuIds()); // 校验商品 sku 是否存在 - validateProductSkuExistence(updateReqVO.getSpuIds(), updateReqVO.getProducts()); + validateProductSkuExistence(skus, updateReqVO.getProducts(), SeckillProductUpdateReqVO::getSkuId); // 更新活动 SeckillActivityDO updateObj = SeckillActivityConvert.INSTANCE.convert(updateReqVO) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java index 2ad362fe2..d21d6abf3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java @@ -1,9 +1,18 @@ package cn.iocoder.yudao.module.promotion.util; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; +import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import java.time.LocalDateTime; +import java.util.List; +import java.util.Set; +import java.util.function.Function; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS; /** * 活动工具类 @@ -22,4 +31,17 @@ public class PromotionUtils { return LocalDateTimeUtils.beforeNow(endTime) ? CommonStatusEnum.DISABLE.getStatus() : CommonStatusEnum.ENABLE.getStatus(); } + public static void validateProductSkuExistence(List skus, List products, Function func) { + // 校验 sku 个数是否一致 + Set skuIdsSet = CollectionUtils.convertSet(products, func); + Set skuIdsSet1 = CollectionUtils.convertSet(skus, ProductSkuRespDTO::getId); + if (ObjectUtil.notEqual(skuIdsSet.size(), skuIdsSet1.size())) { + throw exception(SKU_NOT_EXISTS); + } + // 校验 skuId 是否存在 + if (!skuIdsSet1.containsAll(skuIdsSet) || !skuIdsSet.containsAll(skuIdsSet1)) { + throw exception(SKU_NOT_EXISTS); + } + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java index ba757e1ea..28fcbdea4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java @@ -2,12 +2,12 @@ package cn.iocoder.yudao.module.promotion.service.combination; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityExportReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityPageReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.CombinationActivityUpdateReqVO; -import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; -import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationActivityMapper; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityExportReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; +import cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity.CombinationActivityMapper; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Import; @@ -107,7 +107,7 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { // mock 数据 CombinationActivityDO dbCombinationActivity = randomPojo(CombinationActivityDO.class, o -> { // 等会查询到 o.setName(null); - o.setSpuId(null); + //o.setSpuId(null); o.setTotalLimitCount(null); o.setSingleLimitCount(null); o.setStartTime(null); @@ -125,7 +125,7 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { // 测试 name 不匹配 combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setName(null))); // 测试 spuId 不匹配 - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSpuId(null))); + //combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSpuId(null))); // 测试 totalLimitCount 不匹配 combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalLimitCount(null))); // 测试 singleLimitCount 不匹配 @@ -181,7 +181,7 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { // mock 数据 CombinationActivityDO dbCombinationActivity = randomPojo(CombinationActivityDO.class, o -> { // 等会查询到 o.setName(null); - o.setSpuId(null); + //o.setSpuId(null); o.setTotalLimitCount(null); o.setSingleLimitCount(null); o.setStartTime(null); @@ -199,7 +199,7 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { // 测试 name 不匹配 combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setName(null))); // 测试 spuId 不匹配 - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSpuId(null))); + //combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSpuId(null))); // 测试 totalLimitCount 不匹配 combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalLimitCount(null))); // 测试 singleLimitCount 不匹配 From 78b3d2a20fc2357b0051b273ca17d7ddbfc7a723 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 5 Jul 2023 11:31:16 +0800 Subject: [PATCH 04/12] =?UTF-8?q?fix=EF=BC=9Amall=20promotion=20Combinatio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/product/api/sku/ProductSkuApi.java | 3 +- .../product/api/sku/ProductSkuApiImpl.java | 2 +- .../promotion/enums/ErrorCodeConstants.java | 3 +- .../vo/activity/SeckillActivityBaseVO.java | 7 +- .../vo/activity/SeckillActivityRespVO.java | 2 +- .../vo/product/SeckillProductBaseVO.java | 6 - .../vo/product/SeckillProductUpdateReqVO.java | 9 +- .../SeckillActivityConvert.java | 77 +++++----- .../seckillactivity/SeckillActivityDO.java | 3 +- .../SeckillActivityServiceImpl.java | 136 +++++++++--------- .../SeckillConfigServiceImpl.java | 14 +- .../module/promotion/util/PromotionUtils.java | 4 - 12 files changed, 126 insertions(+), 140 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/ProductSkuApi.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/ProductSkuApi.java index 21fcf7d96..2ed262cde 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/ProductSkuApi.java +++ b/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 { */ List getSkuList(Collection ids); - // TODO puhui999:入参用 Collection 更通用 /** * 批量查询 SKU 数组 * * @param spuIds SPU 编号列表 * @return SKU 数组 */ - List getSkuListBySpuId(List spuIds); + List getSkuListBySpuId(Collection spuIds); /** * 更新 SKU 库存 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/sku/ProductSkuApiImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/sku/ProductSkuApiImpl.java index 4a8425f61..bd0258efa 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/sku/ProductSkuApiImpl.java +++ b/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 { } @Override - public List getSkuListBySpuId(List spuIds) { + public List getSkuListBySpuId(Collection spuIds) { if (CollUtil.isEmpty(spuIds)) { return Collections.emptyList(); } diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index 21d464fb5..ca3f36af1 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/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; /** * Promotion 错误码枚举类 - * + *

* promotion 系统,使用 1-013-000-000 段 */ public interface ErrorCodeConstants { @@ -58,6 +58,7 @@ public interface ErrorCodeConstants { ErrorCode SECKILL_TIME_CONFLICTS = new ErrorCode(1013009001, "秒杀时段冲突"); ErrorCode SECKILL_TIME_EQUAL = new ErrorCode(1013009002, "秒杀时段开始时间和结束时间不能相等"); ErrorCode SECKILL_START_TIME_BEFORE_END_TIME = new ErrorCode(1013009003, "秒杀时段开始时间不能在结束时间之后"); + ErrorCode SECKILL_TIME_DISABLE = new ErrorCode(1013009004, "秒杀时段已关闭"); // ========== 拼团活动 1013010000 ========== ErrorCode COMBINATION_ACTIVITY_NOT_EXISTS = new ErrorCode(1013010000, "拼团活动不存在"); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityBaseVO.java index ac1126d8c..504d4a057 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityBaseVO.java +++ b/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_ @Data public class SeckillActivityBaseVO { - // TODO @puhui999:对应单 spuId 哈 @Schema(description = "秒杀活动商品id", requiredMode = Schema.RequiredMode.REQUIRED, example = "[121,1212]") @NotNull(message = "秒杀活动商品不能为空") - private List spuIds; + private Long spuId; @Schema(description = "秒杀活动名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") @NotNull(message = "秒杀活动名称不能为空") @@ -56,8 +55,4 @@ public class SeckillActivityBaseVO { @Schema(description = "单次限够数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "31683") private Integer singleLimitCount; - // TODO @puhui999:这个应该是计算出来的字段,只返回,create 和 update 不用哈 - @Schema(description = "秒杀总库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") - private Integer totalStock; - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java index 64f5c301a..37ae289a5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java @@ -23,7 +23,7 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO { private Long id; @Schema(description = "秒杀商品", requiredMode = Schema.RequiredMode.REQUIRED) - private List products; // TODO puhui: 考虑是否去除 + private List products; @Schema(description = "活动状态 开启:0 禁用:1", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") private Integer status; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductBaseVO.java index 4dba74fe1..a11d78930 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductBaseVO.java +++ b/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; @Data public class SeckillProductBaseVO { - // TODO @puhui:spuId 不用传递;因为一个秒杀活动只对应一个 SPU 哈; - @Schema(description = "商品spu_id", requiredMode = Schema.RequiredMode.REQUIRED, example = "30563") - @NotNull(message = "商品spu_id不能为空") - private Long spuId; - @Schema(description = "商品sku_id", requiredMode = Schema.RequiredMode.REQUIRED, example = "30563") @NotNull(message = "商品sku_id不能为空") private Long skuId; @@ -31,5 +26,4 @@ public class SeckillProductBaseVO { @NotNull(message = "秒杀库存不能为空") private Integer stock; - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductUpdateReqVO.java index 3f964255a..b0b14d044 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductUpdateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductUpdateReqVO.java @@ -1,8 +1,9 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import javax.validation.constraints.*; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; /** * 管理后台 - 秒杀参与商品更新 Request VO @@ -15,8 +16,4 @@ import javax.validation.constraints.*; @ToString(callSuper = true) public class SeckillProductUpdateReqVO extends SeckillProductBaseVO { - @Schema(description = "秒杀参与商品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "256") - @NotNull(message = "秒杀参与商品编号不能为空") - private Long id; - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java index 7d62b4f2d..53e5b5e3d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java @@ -1,20 +1,24 @@ package cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity; -import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityDetailRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductBaseVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * 秒杀活动 Convert @@ -26,8 +30,6 @@ public interface SeckillActivityConvert { SeckillActivityConvert INSTANCE = Mappers.getMapper(SeckillActivityConvert.class); - SeckillProductDO convert(SeckillProductCreateReqVO product); - SeckillActivityDO convert(SeckillActivityCreateReqVO bean); SeckillActivityDO convert(SeckillActivityUpdateReqVO bean); @@ -40,51 +42,38 @@ public interface SeckillActivityConvert { SeckillActivityDetailRespVO convert(SeckillActivityDO seckillActivity, List seckillProducts); + @Mappings({ + @Mapping(target = "activityId", source = "activityDO.id"), + @Mapping(target = "configIds", source = "activityDO.configIds"), + @Mapping(target = "spuId", source = "activityDO.spuId"), + @Mapping(target = "skuId", source = "vo.skuId"), + @Mapping(target = "seckillPrice", source = "vo.seckillPrice"), + @Mapping(target = "stock", source = "vo.stock"), + @Mapping(target = "activityStartTime", source = "activityDO.startTime"), + @Mapping(target = "activityEndTime", source = "activityDO.endTime") + }) + SeckillProductDO convert(SeckillActivityDO activityDO, SeckillProductBaseVO vo); - /** - * 比较两个秒杀商品对象是否相等 - * - * @param productDO 数据库中的商品 - * @param productVO 前端传入的商品 - * @return 是否匹配 - */ - default boolean isEquals(SeckillProductDO productDO, SeckillProductCreateReqVO productVO) { - return ObjectUtil.equals(productDO.getSpuId(), 1) // TODO puhui:再看看 - && ObjectUtil.equals(productDO.getSkuId(), productVO.getSkuId()) - && ObjectUtil.equals(productDO.getSeckillPrice(), productVO.getSeckillPrice()); - //&& ObjectUtil.equals(productDO.getQuota(), productVO.getQuota()) - //&& ObjectUtil.equals(productDO.getLimitCount(), productVO.getLimitCount()); - } - - /** - * 比较两个秒杀商品对象是否相等 - * - * @param productDO 商品1 - * @param productVO 商品2 - * @return 是否匹配 - */ - default boolean isEquals(SeckillProductDO productDO, SeckillProductDO productVO) { - return ObjectUtil.equals(productDO.getSpuId(), productVO.getSpuId()) - && ObjectUtil.equals(productDO.getSkuId(), productVO.getSkuId()) - && ObjectUtil.equals(productDO.getSeckillPrice(), productVO.getSeckillPrice()); - //&& ObjectUtil.equals(productDO.getQuota(), productVO.getQuota()) - //&& ObjectUtil.equals(productDO.getLimitCount(), productVO.getLimitCount()); - } - - default List convertList(SeckillActivityDO seckillActivity, List products) { + default List convertList(SeckillActivityDO activityDO, List products) { List list = new ArrayList<>(); products.forEach(sku -> { - SeckillProductDO productDO = new SeckillProductDO(); - productDO.setActivityId(seckillActivity.getId()); - productDO.setConfigIds(seckillActivity.getConfigIds()); - productDO.setSpuId(sku.getSpuId()); - productDO.setSkuId(sku.getSkuId()); - productDO.setSeckillPrice(sku.getSeckillPrice()); - productDO.setStock(sku.getStock()); + SeckillProductDO productDO = convert(activityDO, sku); productDO.setActivityStatus(CommonStatusEnum.ENABLE.getStatus()); - productDO.setActivityStartTime(seckillActivity.getStartTime()); - productDO.setActivityEndTime(seckillActivity.getEndTime()); + list.add(productDO); }); return list; } + + default List convertList1(SeckillActivityDO activityDO, List vos, List productDOs) { + Map longMap = CollectionUtils.convertMap(productDOs, SeckillProductDO::getSkuId, SeckillProductDO::getId); + List list = new ArrayList<>(); + vos.forEach(sku -> { + SeckillProductDO productDO = convert(activityDO, sku); + productDO.setId(longMap.get(sku.getSkuId())); + productDO.setActivityStatus(CommonStatusEnum.ENABLE.getStatus()); + list.add(productDO); + }); + return list; + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java index be6663592..a8c7eb265 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java @@ -34,8 +34,7 @@ public class SeckillActivityDO extends BaseDO { /** * 秒杀活动商品 */ - @TableField(typeHandler = LongListTypeHandler.class) - private List spuIds; + private Long spuId; /** * 秒杀活动名称 */ diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java index 9c9e559b2..ffc68c4bc 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; @@ -18,23 +19,21 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity. import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillActivityMapper; import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillProductMapper; -import cn.iocoder.yudao.module.promotion.enums.common.PromotionActivityStatusEnum; import cn.iocoder.yudao.module.promotion.service.seckill.seckillconfig.SeckillConfigService; import cn.iocoder.yudao.module.promotion.util.PromotionUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; +import java.util.Set; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.promotion.util.PromotionUtils.validateProductSkuExistence; -import static java.util.Arrays.asList; /** * 秒杀活动 Service 实现类 @@ -57,17 +56,19 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { private ProductSkuApi productSkuApi; @Override + @Transactional(rollbackFor = Exception.class) public Long createSeckillActivity(SeckillActivityCreateReqVO createReqVO) { // 校验商品秒秒杀时段是否冲突 - validateProductSpuSeckillConflict(createReqVO.getConfigIds(), createReqVO.getSpuIds()); + validateProductSpuSeckillConflict(createReqVO.getConfigIds(), createReqVO.getSpuId(), null); // 获取所选 spu下的所有 sku - List skus = productSkuApi.getSkuListBySpuId(createReqVO.getSpuIds()); + List skus = productSkuApi.getSkuListBySpuId(CollUtil.newArrayList(createReqVO.getSpuId())); // 校验商品 sku 是否存在 validateProductSkuExistence(skus, createReqVO.getProducts(), SeckillProductCreateReqVO::getSkuId); // 插入秒杀活动 SeckillActivityDO activity = SeckillActivityConvert.INSTANCE.convert(createReqVO) - .setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getEndTime())); + .setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getEndTime())) + .setTotalStock(CollectionUtils.getSumValue(createReqVO.getProducts(), SeckillProductCreateReqVO::getStock, Integer::sum)); seckillActivityMapper.insert(activity); // 插入商品 List product = SeckillActivityConvert.INSTANCE.convertList(activity, createReqVO.getProducts()); @@ -75,119 +76,124 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { return activity.getId(); } - private void validateProductSpuSeckillConflict(List configIds, List spuIds) { + private void validateProductSpuSeckillConflict(List configIds, Long spuId, Long activityId) { // 校验秒杀时段是否存在 seckillConfigService.validateSeckillConfigExists(configIds); // 校验商品 spu 是否存在 - List spuList = productSpuApi.getSpuList(spuIds); - if (ObjectUtil.notEqual(spuIds.size(), spuList.size())) { + List spuList = productSpuApi.getSpuList(CollUtil.newArrayList(spuId)); + if (CollUtil.isEmpty(spuList)) { throw exception(SPU_NOT_EXISTS); } // 查询所有开启的秒杀活动 List activityDOs = seckillActivityMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus()); - // 过滤出所有 spuIds 有交集的活动 - List doList = activityDOs.stream().filter(s -> { - // 判断 spu 是否有交集 - ArrayList spuIdsClone = CollUtil.newArrayList(s.getSpuIds()); - spuIdsClone.retainAll(spuIds); - if (CollUtil.isEmpty(spuIdsClone)) { - return false; - } + if (activityId != null) { + // 更新时移除本活动 + activityDOs.removeIf(item -> ObjectUtil.equal(item.getId(), activityId)); + } + // 过滤出所有 spuId 有交集的活动 + List activityDOs1 = CollectionUtils.convertList(activityDOs, c -> c, s -> ObjectUtil.equal(s.getSpuId(), spuId)); + if (CollUtil.isNotEmpty(activityDOs1)) { + throw exception(SECKILL_ACTIVITY_SPU_CONFLICTS); + } + List activityDOs2 = CollectionUtils.convertList(activityDOs, c -> c, s -> { // 判断秒杀时段是否有交集 List configIdsClone = CollUtil.newArrayList(s.getConfigIds()); configIdsClone.retainAll(configIds); return CollUtil.isNotEmpty(configIdsClone); - }).collect(Collectors.toList()); - if (CollUtil.isNotEmpty(doList)) { - throw exception(SECKILL_ACTIVITY_SPU_CONFLICTS); + }); + if (CollUtil.isNotEmpty(activityDOs2)) { + throw exception(SECKILL_TIME_CONFLICTS); } } @Override + @Transactional(rollbackFor = Exception.class) public void updateSeckillActivity(SeckillActivityUpdateReqVO updateReqVO) { // 校验存在 SeckillActivityDO seckillActivity = validateSeckillActivityExists(updateReqVO.getId()); - if (CommonStatusEnum.ENABLE.getStatus().equals(seckillActivity.getStatus())) { + if (CommonStatusEnum.DISABLE.getStatus().equals(seckillActivity.getStatus())) { throw exception(SECKILL_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED); } // 校验商品是否冲突 - validateProductSpuSeckillConflict(updateReqVO.getConfigIds(), updateReqVO.getSpuIds()); + validateProductSpuSeckillConflict(updateReqVO.getConfigIds(), updateReqVO.getSpuId(), updateReqVO.getId()); // 获取所选 spu下的所有 sku - List skus = productSkuApi.getSkuListBySpuId(updateReqVO.getSpuIds()); + List skus = productSkuApi.getSkuListBySpuId(CollUtil.newArrayList(updateReqVO.getSpuId())); // 校验商品 sku 是否存在 validateProductSkuExistence(skus, updateReqVO.getProducts(), SeckillProductUpdateReqVO::getSkuId); // 更新活动 SeckillActivityDO updateObj = SeckillActivityConvert.INSTANCE.convert(updateReqVO) - .setStatus(PromotionUtils.calculateActivityStatus(updateReqVO.getEndTime())); + .setStatus(PromotionUtils.calculateActivityStatus(updateReqVO.getEndTime())) + .setTotalStock(CollectionUtils.getSumValue(updateReqVO.getProducts(), SeckillProductUpdateReqVO::getStock, Integer::sum)); seckillActivityMapper.updateById(updateObj); // 更新商品 - //updateSeckillProduct(updateReqVO); + updateSeckillProduct(updateObj, updateReqVO.getProducts()); } /** * 更新秒杀商品 - * 后台查出的数据和前台查出的数据进行遍历, - * 1. 对前台数据进行遍历:如果不存在于后台的 sku 中需要新增 - * 2. 对后台数据进行遍历:如果不存在于前台的 sku 中需要删除 - * 3. 最后对当前活动商品全部更新,更新秒杀时段id列表 * - * @param updateReqVO 更新的请求VO + * @param updateObj DO + * @param products 商品配置 */ - private void updateSeckillProduct(SeckillActivityUpdateReqVO updateReqVO) { - // TODO puhui999:要不这里简单一点;删除原本的,插入新增的;不做的这么细致 - // TODO puhui999:后续完善 - //List seckillProductDOs = seckillProductMapper.selectListByActivityId(updateReqVO.getId()); - //List products = updateReqVO.getProducts(); - - ////计算需要删除的数据 - //List deleteIds = CollectionUtils.convertList(seckillProductDOs, SeckillProductDO::getId, - // seckillProductDO -> products.stream() - // .noneMatch(product -> SeckillActivityConvert.INSTANCE.isEquals(seckillProductDO, product))); - //if (CollUtil.isNotEmpty(deleteIds)) { - // seckillProductMapper.deleteBatchIds(deleteIds); - //} - // - //// 计算需要新增的数据 - //List newSeckillProductDOs = CollectionUtils.convertList(products, - // product -> SeckillActivityConvert.INSTANCE.convert(product).setActivityId(updateReqVO.getId())); - //newSeckillProductDOs.removeIf(product -> seckillProductDOs.stream() - // .anyMatch(seckillProduct -> SeckillActivityConvert.INSTANCE.isEquals(seckillProduct, product))); - //if (CollUtil.isNotEmpty(newSeckillProductDOs)) { - // seckillProductMapper.insertBatch(newSeckillProductDOs); - //} - - //全量更新当前活动商品的秒杀时段id列表(timeIds) - seckillProductMapper.updateTimeIdsByActivityId(updateReqVO.getId(), updateReqVO.getConfigIds()); + private void updateSeckillProduct(SeckillActivityDO updateObj, List products) { + List seckillProductDOs = seckillProductMapper.selectListByActivityId(updateObj.getId()); + // 数据库中的活动商品 + Set convertSet = CollectionUtils.convertSet(seckillProductDOs, SeckillProductDO::getSkuId); + // 前端传过来的活动商品 + Set convertSet1 = CollectionUtils.convertSet(products, SeckillProductUpdateReqVO::getSkuId); + // 删除后台存在的前端不存在的商品 + List d = CollectionUtils.filterList(convertSet, item -> !convertSet1.contains(item)); + if (CollUtil.isNotEmpty(d)) { + seckillProductMapper.deleteBatchIds(d); + } + // 前端存在的后端不存在的商品 + List c = CollectionUtils.filterList(convertSet1, item -> !convertSet.contains(item)); + if (CollUtil.isNotEmpty(c)) { + List vos = CollectionUtils.filterList(products, item -> c.contains(item.getSkuId())); + List productDOs = SeckillActivityConvert.INSTANCE.convertList(updateObj, vos); + seckillProductMapper.insertBatch(productDOs); + } + // 更新已存在的商品 + List u = CollectionUtils.filterList(convertSet1, convertSet::contains); + if (CollUtil.isNotEmpty(u)) { + List vos = CollectionUtils.filterList(products, item -> u.contains(item.getSkuId())); + List productDOs = SeckillActivityConvert.INSTANCE.convertList1(updateObj, vos, seckillProductDOs); + seckillProductMapper.insertBatch(productDOs); + } } @Override + @Transactional(rollbackFor = Exception.class) public void closeSeckillActivity(Long id) { + // TODO 待验证没使用过 // 校验存在 - SeckillActivityDO seckillActivity = this.validateSeckillActivityExists(id); - if (PromotionActivityStatusEnum.CLOSE.getStatus().equals(seckillActivity.getStatus())) { + SeckillActivityDO seckillActivity = validateSeckillActivityExists(id); + if (CommonStatusEnum.DISABLE.getStatus().equals(seckillActivity.getStatus())) { throw exception(SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED); } - if (PromotionActivityStatusEnum.END.getStatus().equals(seckillActivity.getStatus())) { - throw exception(SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_END); - } + // 更新 - SeckillActivityDO updateObj = new SeckillActivityDO().setId(id).setStatus(PromotionActivityStatusEnum.CLOSE.getStatus()); + SeckillActivityDO updateObj = new SeckillActivityDO().setId(id).setStatus(CommonStatusEnum.DISABLE.getStatus()); seckillActivityMapper.updateById(updateObj); } @Override + @Transactional(rollbackFor = Exception.class) public void deleteSeckillActivity(Long id) { // 校验存在 SeckillActivityDO seckillActivity = this.validateSeckillActivityExists(id); - List statuses = asList(PromotionActivityStatusEnum.CLOSE.getStatus(), PromotionActivityStatusEnum.END.getStatus()); - if (!statuses.contains(seckillActivity.getStatus())) { + if (CommonStatusEnum.ENABLE.getStatus().equals(seckillActivity.getStatus())) { throw exception(SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END); } - // 删除 + // 删除活动 seckillActivityMapper.deleteById(id); + // 删除活动商品 + List productDOs = seckillProductMapper.selectListByActivityId(id); + Set convertSet = CollectionUtils.convertSet(productDOs, SeckillProductDO::getSkuId); + seckillProductMapper.deleteBatchIds(convertSet); } private SeckillActivityDO validateSeckillActivityExists(Long id) { diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillconfig/SeckillConfigServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillconfig/SeckillConfigServiceImpl.java index 599973d5b..d233a2d38 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillconfig/SeckillConfigServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillconfig/SeckillConfigServiceImpl.java @@ -1,8 +1,10 @@ package cn.iocoder.yudao.module.promotion.service.seckill.seckillconfig; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigUpdateReqVO; @@ -127,10 +129,18 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { if (CollUtil.isEmpty(configIds)) { throw exception(SECKILL_TIME_NOT_EXISTS); } - if (seckillConfigMapper.selectBatchIds(configIds).size() != configIds.size()) { + List configDOs = seckillConfigMapper.selectBatchIds(configIds); + if (CollUtil.isEmpty(configDOs)) { + throw exception(SECKILL_TIME_NOT_EXISTS); + } + // 过滤出关闭的时段 + List filterList = CollectionUtils.filterList(configDOs, item -> ObjectUtil.equal(item.getStatus(), CommonStatusEnum.DISABLE.getStatus())); + if (CollUtil.isNotEmpty(filterList)) { + throw exception(SECKILL_TIME_DISABLE); + } + if (configDOs.size() != configIds.size()) { throw exception(SECKILL_TIME_NOT_EXISTS); } - // TODO @puhui999:应该要校验个 status 哈;如果有禁用的,也不行 } @Override diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java index d21d6abf3..96da50841 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.promotion.util; -import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; @@ -35,9 +34,6 @@ public class PromotionUtils { // 校验 sku 个数是否一致 Set skuIdsSet = CollectionUtils.convertSet(products, func); Set skuIdsSet1 = CollectionUtils.convertSet(skus, ProductSkuRespDTO::getId); - if (ObjectUtil.notEqual(skuIdsSet.size(), skuIdsSet1.size())) { - throw exception(SKU_NOT_EXISTS); - } // 校验 skuId 是否存在 if (!skuIdsSet1.containsAll(skuIdsSet) || !skuIdsSet.containsAll(skuIdsSet1)) { throw exception(SKU_NOT_EXISTS); From b78f814552f31868c580d70e26fbf73ec9ac50e4 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 5 Jul 2023 22:05:05 +0800 Subject: [PATCH 05/12] =?UTF-8?q?fix=EF=BC=9Amall=20promotion=20SeckillAct?= =?UTF-8?q?ivity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seckill/SeckillActivityController.java | 19 +- .../vo/activity/SeckillActivityRespVO.java | 25 ++ .../SeckillActivityConvert.java | 24 +- .../seckillactivity/SeckillProductMapper.java | 4 + .../SeckillActivityService.java | 8 + .../SeckillActivityServiceImpl.java | 9 +- .../module/promotion/util/PromotionUtils.java | 4 +- .../src/test/resources/sql/clean.sql | 23 +- .../src/test/resources/sql/create_tables.sql | 290 ++++++++++-------- 9 files changed, 260 insertions(+), 146 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillActivityController.java index ba750b296..0631bfc11 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillActivityController.java +++ b/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; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.*; import cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity.SeckillActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; @@ -18,6 +21,7 @@ import javax.annotation.Resource; import javax.validation.Valid; import java.util.Collection; import java.util.List; +import java.util.Set; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -29,6 +33,8 @@ public class SeckillActivityController { @Resource private SeckillActivityService seckillActivityService; + @Resource + private ProductSpuApi spuApi; @PostMapping("/create") @Operation(summary = "创建秒杀活动") @@ -69,11 +75,8 @@ public class SeckillActivityController { @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')") public CommonResult getSeckillActivity(@RequestParam("id") Long id) { SeckillActivityDO seckillActivity = seckillActivityService.getSeckillActivity(id); - if (seckillActivity == null) { - return success(null); - } - List seckillProducts = seckillActivityService.getSeckillProductListByActivityId(id); - return success(SeckillActivityConvert.INSTANCE.convert(seckillActivity,seckillProducts)); + List seckillProducts = seckillActivityService.getSeckillProductListByActivityId(id); + return success(SeckillActivityConvert.INSTANCE.convert(seckillActivity, seckillProducts)); } @GetMapping("/list") @@ -90,7 +93,11 @@ public class SeckillActivityController { @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')") public CommonResult> getSeckillActivityPage(@Valid SeckillActivityPageReqVO pageVO) { PageResult pageResult = seckillActivityService.getSeckillActivityPage(pageVO); - return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult)); + Set aIds = CollectionUtils.convertSet(pageResult.getList(), SeckillActivityDO::getId); + List seckillProducts = seckillActivityService.getSeckillProductListByActivityId(aIds); + Set spuIds = CollectionUtils.convertSet(pageResult.getList(), SeckillActivityDO::getSpuId); + List spuList = spuApi.getSpuList(spuIds); + return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult, seckillProducts, spuList)); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java index 37ae289a5..959b8a8fa 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java @@ -6,6 +6,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import java.time.LocalDateTime; import java.util.List; /** @@ -19,6 +20,12 @@ import java.util.List; @ToString(callSuper = true) public class SeckillActivityRespVO extends SeckillActivityBaseVO { + @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") + private String spuName; + + @Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") + private String picUrl; + @Schema(description = "秒杀活动id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") private Long id; @@ -28,4 +35,22 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO { @Schema(description = "活动状态 开启:0 禁用:1", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") private Integer status; + @Schema(description = "订单实付金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "22354") + private Integer totalPrice; + + @Schema(description = "秒杀库存", example = "10") + private Integer stock; + + @Schema(description = "秒杀总库存", example = "20") + private Integer totalStock; + + @Schema(description = "新增订单数", example = "20") + private Integer orderCount; + + @Schema(description = "付款人数", example = "20") + private Integer userCount; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime createTime; + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java index 53e5b5e3d..7e004c4c2 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java @@ -3,11 +3,13 @@ package cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityDetailRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductBaseVO; +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; @@ -40,9 +42,27 @@ public interface SeckillActivityConvert { PageResult convertPage(PageResult page); - SeckillActivityDetailRespVO convert(SeckillActivityDO seckillActivity, List seckillProducts); + default PageResult convertPage(PageResult page, List seckillProducts, List spuList) { + Map spuMap = CollectionUtils.convertMap(spuList, ProductSpuRespDTO::getId, c -> c); + PageResult pageResult = convertPage(page); + pageResult.getList().forEach(item -> { + item.setSpuName(spuMap.get(item.getSpuId()).getName()); + item.setPicUrl(spuMap.get(item.getSpuId()).getPicUrl()); + item.setProducts(convertList2(seckillProducts)); + }); + return pageResult; + } + + SeckillActivityDetailRespVO convert1(SeckillActivityDO seckillActivity); + + default SeckillActivityDetailRespVO convert(SeckillActivityDO seckillActivity, List seckillProducts) { + SeckillActivityDetailRespVO respVO = convert1(seckillActivity); + respVO.setProducts(convertList2(seckillProducts)); + return respVO; + } @Mappings({ + @Mapping(target = "id", expression = "java(null)"), @Mapping(target = "activityId", source = "activityDO.id"), @Mapping(target = "configIds", source = "activityDO.configIds"), @Mapping(target = "spuId", source = "activityDO.spuId"), @@ -76,4 +96,6 @@ public interface SeckillActivityConvert { return list; } + List convertList2(List productDOs); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java index fd6d87bdf..625769901 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java +++ b/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 { return selectList(SeckillProductDO::getActivityId, id); } + default List selectListByActivityId(Collection ids) { + return selectList(SeckillProductDO::getActivityId, ids); + } + default List selectListBySkuIds(Collection skuIds) { return selectList(SeckillProductDO::getSkuId, skuIds); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityService.java index 1c3ed38fe..4096f0087 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityService.java +++ b/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 { */ List getSeckillProductListByActivityId(Long id); + /** + * 通过活动编号获取活动商品 + * + * @param ids 活动编号 + * @return 活动商品列表 + */ + List getSeckillProductListByActivityId(Collection ids); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java index ffc68c4bc..8221a2d46 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillactivity/SeckillActivityServiceImpl.java @@ -160,7 +160,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { if (CollUtil.isNotEmpty(u)) { List vos = CollectionUtils.filterList(products, item -> u.contains(item.getSkuId())); List productDOs = SeckillActivityConvert.INSTANCE.convertList1(updateObj, vos, seckillProductDOs); - seckillProductMapper.insertBatch(productDOs); + seckillProductMapper.updateBatch(productDOs); } } @@ -206,7 +206,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { @Override public SeckillActivityDO getSeckillActivity(Long id) { - return seckillActivityMapper.selectById(id); + return validateSeckillActivityExists(id); } @Override @@ -224,4 +224,9 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { return seckillProductMapper.selectListByActivityId(id); } + @Override + public List getSeckillProductListByActivityId(Collection ids) { + return seckillProductMapper.selectListByActivityId(ids); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java index 96da50841..fbefe10a5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.util; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; @@ -35,7 +36,8 @@ public class PromotionUtils { Set skuIdsSet = CollectionUtils.convertSet(products, func); Set skuIdsSet1 = CollectionUtils.convertSet(skus, ProductSkuRespDTO::getId); // 校验 skuId 是否存在 - if (!skuIdsSet1.containsAll(skuIdsSet) || !skuIdsSet.containsAll(skuIdsSet1)) { + List f = CollectionUtils.filterList(skuIdsSet, s -> !skuIdsSet1.contains(s)); + if (CollUtil.isNotEmpty(f)) { throw exception(SKU_NOT_EXISTS); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/test/resources/sql/clean.sql b/yudao-module-mall/yudao-module-promotion-biz/src/test/resources/sql/clean.sql index d848bf556..defacab26 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/test/resources/sql/clean.sql +++ b/yudao-module-mall/yudao-module-promotion-biz/src/test/resources/sql/clean.sql @@ -1,7 +1,16 @@ -DELETE FROM "market_activity"; -DELETE FROM "promotion_coupon_template"; -DELETE FROM "promotion_coupon"; -DELETE FROM "promotion_reward_activity"; -DELETE FROM "promotion_discount_activity"; -DELETE FROM "promotion_discount_product"; -DELETE FROM "promotion_seckill_config"; +DELETE +FROM "market_activity"; +DELETE +FROM "promotion_coupon_template"; +DELETE +FROM "promotion_coupon"; +DELETE +FROM "promotion_reward_activity"; +DELETE +FROM "promotion_discount_activity"; +DELETE +FROM "promotion_discount_product"; +DELETE +FROM "promotion_seckill_config"; +DELETE +FROM "promotion_combination_activity"; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/test/resources/sql/create_tables.sql b/yudao-module-mall/yudao-module-promotion-biz/src/test/resources/sql/create_tables.sql index 33b6edc48..c7a3b56da 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-mall/yudao-module-promotion-biz/src/test/resources/sql/create_tables.sql @@ -1,151 +1,183 @@ -CREATE TABLE IF NOT EXISTS "market_activity" ( - "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "title" varchar(50) NOT NULL, - "activity_type" tinyint(4) NOT NULL, - "status" tinyint(4) NOT NULL, - "start_time" datetime NOT NULL, - "end_time" datetime NOT NULL, - "invalid_time" datetime, - "delete_time" datetime, +CREATE TABLE IF NOT EXISTS "market_activity" +( + "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "title" varchar(50) NOT NULL, + "activity_type" tinyint(4) NOT NULL, + "status" tinyint(4) NOT NULL, + "start_time" datetime NOT NULL, + "end_time" datetime NOT NULL, + "invalid_time" datetime, + "delete_time" datetime, "time_limited_discount" varchar(2000), - "full_privilege" varchar(2000), - "creator" varchar(64) DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint(20) NOT NULL, + "full_privilege" varchar(2000), + "creator" varchar(64) DEFAULT '', + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar(64) DEFAULT '', + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + "tenant_id" bigint(20) NOT NULL, PRIMARY KEY ("id") - ) COMMENT '促销活动'; +) COMMENT '促销活动'; -CREATE TABLE IF NOT EXISTS "promotion_coupon_template" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar NOT NULL, - "status" int NOT NULL, - "total_count" int NOT NULL, - "take_limit_count" int NOT NULL, - "take_type" int NOT NULL, - "use_price" int NOT NULL, - "product_scope" int NOT NULL, - "product_spu_ids" varchar, - "validity_type" int NOT NULL, - "valid_start_time" datetime, - "valid_end_time" datetime, - "fixed_start_term" int, - "fixed_end_term" int, - "discount_type" int NOT NULL, - "discount_percent" int, - "discount_price" int, - "discount_limit_price" int, - "take_count" int NOT NULL DEFAULT 0, - "use_count" int NOT NULL DEFAULT 0, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") +CREATE TABLE IF NOT EXISTS "promotion_coupon_template" +( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "name" varchar NOT NULL, + "status" int NOT NULL, + "total_count" int NOT NULL, + "take_limit_count" int NOT NULL, + "take_type" int NOT NULL, + "use_price" int NOT NULL, + "product_scope" int NOT NULL, + "product_spu_ids" varchar, + "validity_type" int NOT NULL, + "valid_start_time" datetime, + "valid_end_time" datetime, + "fixed_start_term" int, + "fixed_end_term" int, + "discount_type" int NOT NULL, + "discount_percent" int, + "discount_price" int, + "discount_limit_price" int, + "take_count" int NOT NULL DEFAULT 0, + "use_count" int NOT NULL DEFAULT 0, + "creator" varchar DEFAULT '', + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar DEFAULT '', + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + PRIMARY KEY ("id") ) COMMENT '优惠劵模板'; -CREATE TABLE IF NOT EXISTS "promotion_coupon" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "template_id" bigint NOT NULL, - "name" varchar NOT NULL, - "status" int NOT NULL, - "user_id" bigint NOT NULL, - "take_type" int NOT NULL, - "useprice" int NOT NULL, - "valid_start_time" datetime NOT NULL, - "valid_end_time" datetime NOT NULL, - "product_scope" int NOT NULL, - "product_spu_ids" varchar, - "discount_type" int NOT NULL, - "discount_percent" int, - "discount_price" int, +CREATE TABLE IF NOT EXISTS "promotion_coupon" +( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "template_id" bigint NOT NULL, + "name" varchar NOT NULL, + "status" int NOT NULL, + "user_id" bigint NOT NULL, + "take_type" int NOT NULL, + "useprice" int NOT NULL, + "valid_start_time" datetime NOT NULL, + "valid_end_time" datetime NOT NULL, + "product_scope" int NOT NULL, + "product_spu_ids" varchar, + "discount_type" int NOT NULL, + "discount_percent" int, + "discount_price" int, "discount_limit_price" int, - "use_order_id" bigint, - "use_time" datetime, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, + "use_order_id" bigint, + "use_time" datetime, + "creator" varchar DEFAULT '', + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar DEFAULT '', + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, PRIMARY KEY ("id") ) COMMENT '优惠劵'; -CREATE TABLE IF NOT EXISTS "promotion_reward_activity" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar NOT NULL, - "status" int NOT NULL, - "start_time" datetime NOT NULL, - "end_time" datetime NOT NULL, - "remark" varchar, - "condition_type" int NOT NULL, - "product_scope" int NOT NULL, - "product_spu_ids" varchar, - "rules" varchar, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") +CREATE TABLE IF NOT EXISTS "promotion_reward_activity" +( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "name" varchar NOT NULL, + "status" int NOT NULL, + "start_time" datetime NOT NULL, + "end_time" datetime NOT NULL, + "remark" varchar, + "condition_type" int NOT NULL, + "product_scope" int NOT NULL, + "product_spu_ids" varchar, + "rules" varchar, + "creator" varchar DEFAULT '', + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar DEFAULT '', + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + PRIMARY KEY ("id") ) COMMENT '满减送活动'; -CREATE TABLE IF NOT EXISTS "promotion_discount_activity" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar NOT NULL, - "status" int NOT NULL, - "start_time" datetime NOT NULL, - "end_time" datetime NOT NULL, - "remark" varchar, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") +CREATE TABLE IF NOT EXISTS "promotion_discount_activity" +( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "name" varchar NOT NULL, + "status" int NOT NULL, + "start_time" datetime NOT NULL, + "end_time" datetime NOT NULL, + "remark" varchar, + "creator" varchar DEFAULT '', + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar DEFAULT '', + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + PRIMARY KEY ("id") ) COMMENT '限时折扣活动'; -- 将该建表 SQL 语句,添加到 yudao-module-promotion-biz 模块的 test/resources/sql/create_tables.sql 文件里 -CREATE TABLE IF NOT EXISTS "promotion_seckill_activity" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "spu_id" bigint NOT NULL, - "name" varchar NOT NULL, - "status" int NOT NULL, - "remark" varchar, - "start_time" varchar NOT NULL, - "end_time" varchar NOT NULL, - "sort" int NOT NULL, - "config_ids" varchar NOT NULL, - "order_count" int NOT NULL, - "user_count" int NOT NULL, - "total_price" int NOT NULL, - "total_limit_count" int, +CREATE TABLE IF NOT EXISTS "promotion_seckill_activity" +( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "spu_id" bigint NOT NULL, + "name" varchar NOT NULL, + "status" int NOT NULL, + "remark" varchar, + "start_time" varchar NOT NULL, + "end_time" varchar NOT NULL, + "sort" int NOT NULL, + "config_ids" varchar NOT NULL, + "order_count" int NOT NULL, + "user_count" int NOT NULL, + "total_price" int NOT NULL, + "total_limit_count" int, "single_limit_count" int, - "stock" int, - "total_stock" int, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint NOT NULL, + "stock" int, + "total_stock" int, + "creator" varchar DEFAULT '', + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar DEFAULT '', + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + "tenant_id" bigint NOT NULL, PRIMARY KEY ("id") ) COMMENT '秒杀活动'; -CREATE TABLE IF NOT EXISTS "promotion_seckill_config" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar NOT NULL, - "start_time" varchar NOT NULL, - "end_time" varchar NOT NULL, - "pic_url" varchar NOT NULL, - "status" int NOT NULL, - "creator" varchar DEFAULT '', +CREATE TABLE IF NOT EXISTS "promotion_seckill_config" +( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "name" varchar NOT NULL, + "start_time" varchar NOT NULL, + "end_time" varchar NOT NULL, + "pic_url" varchar NOT NULL, + "status" int NOT NULL, + "creator" varchar DEFAULT '', "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', + "updater" varchar DEFAULT '', "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint NOT NULL, + "deleted" bit NOT NULL DEFAULT FALSE, + "tenant_id" bigint NOT NULL, PRIMARY KEY ("id") ) COMMENT '秒杀时段配置'; + +CREATE TABLE IF NOT EXISTS "promotion_combination_activity" +( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "name" varchar NOT NULL, + "spu_id" bigint, + "total_limit_count" int NOT NULL, + "single_limit_count" int NOT NULL, + "start_time" varchar NOT NULL, + "end_time" varchar NOT NULL, + "user_size" int NOT NULL, + "total_num" int NOT NULL, + "success_num" int NOT NULL, + "order_user_count" int NOT NULL, + "virtual_group" int NOT NULL, + "status" int NOT NULL, + "limit_duration" int NOT NULL, + "creator" varchar DEFAULT '', + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar DEFAULT '', + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + "tenant_id" bigint NOT NULL, + PRIMARY KEY ("id") +) COMMENT '拼团活动'; \ No newline at end of file From e7d86436650ba7850026d7ba760a4d512b8f6737 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 10 Jul 2023 16:35:49 +0800 Subject: [PATCH 06/12] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=20mall=20r?= =?UTF-8?q?eview=20@puhui999?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/util/date/LocalDateTimeUtils.java | 22 +++++- .../product/enums/ErrorCodeConstants.java | 2 +- .../comment/vo/ProductCommentBaseVO.java | 13 ---- .../comment/vo/ProductCommentPageReqVO.java | 3 +- .../comment/vo/ProductCommentRespVO.java | 12 ++++ .../admin/spu/ProductSpuController.java | 5 -- .../admin/spu/vo/ProductSpuCreateReqVO.java | 5 -- .../admin/spu/vo/ProductSpuDetailRespVO.java | 6 -- .../admin/spu/vo/ProductSpuExportReqVO.java | 5 -- .../admin/spu/vo/ProductSpuPageReqVO.java | 5 -- .../admin/spu/vo/ProductSpuRespVO.java | 5 -- .../admin/spu/vo/ProductSpuSimpleRespVO.java | 5 -- .../admin/spu/vo/ProductSpuUpdateReqVO.java | 5 -- .../spu/vo/ProductSpuUpdateStatusReqVO.java | 5 -- .../comment/AppProductCommentController.java | 28 ++------ .../comment/vo/AppProductCommentRespVO.java | 5 -- .../comment/ProductCommentConvert.java | 30 ++++++-- .../mysql/comment/ProductCommentMapper.java | 4 +- .../comment/ProductCommentService.java | 2 +- .../comment/ProductCommentServiceImpl.java | 22 +++--- .../ProductCommentServiceImplTest.java | 9 ++- .../seckill/SeckillConfigController.java | 5 -- .../vo/activity/SeckillActivityRespVO.java | 5 -- .../vo/config/SeckillConfigBaseVO.java | 22 +++++- .../vo/config/SeckillConfigPageReqVO.java | 6 -- .../vo/product/SeckillProductCreateReqVO.java | 13 +--- .../vo/product/SeckillProductRespVO.java | 10 ++- .../vo/product/SeckillProductUpdateReqVO.java | 5 -- .../seckillconfig/SeckillConfigDO.java | 21 +++--- .../seckillconfig/SeckillConfigMapper.java | 7 ++ .../SeckillConfigServiceImpl.java | 69 ++++++++----------- .../trade/enums/ErrorCodeConstants.java | 2 + .../app/order/AppTradeOrderController.java | 28 +------- .../AppTradeOrderItemCommentCreateReqVO.java | 5 -- .../convert/order/TradeOrderConvert.java | 1 - .../service/order/TradeOrderService.java | 11 +++ .../service/order/TradeOrderServiceImpl.java | 31 ++++++++- .../address/AddressServiceImplTest.java | 12 ++-- 38 files changed, 207 insertions(+), 244 deletions(-) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java index 62e0e4441..3473852f7 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java +++ b/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; import java.time.Duration; import java.time.LocalDateTime; +import java.time.LocalTime; /** * 时间工具类,用于 {@link java.time.LocalDateTime} @@ -50,7 +51,7 @@ public class LocalDateTimeUtils { * 判断当前时间是否在该时间范围内 * * @param startTime 开始时间 - * @param endTime 结束时间 + * @param endTime 结束时间 * @return 是否 */ public static boolean isBetween(LocalDateTime startTime, LocalDateTime endTime) { @@ -60,4 +61,23 @@ public class LocalDateTimeUtils { return LocalDateTimeUtil.isIn(LocalDateTime.now(), startTime, endTime); } + /** + * 检查时间重叠 不包含日期 + * + * @param startTime1 需要校验的开始时间 + * @param endTime1 需要校验的结束时间 + * @param startTime2 校验所需的开始时间 + * @param endTime2 校验所需的结束时间 + * @return 是否重叠 + */ + public static boolean checkTimeOverlap(LocalTime startTime1, LocalTime endTime1, LocalTime startTime2, LocalTime endTime2) { + // 判断时间是否重叠 + // 开始时间在已配置时段的结束时间之前 且 结束时间在已配置时段的开始时间之后 [] + return startTime1.isBefore(endTime2) && endTime1.isAfter(startTime2) + // 开始时间在已配置时段的开始时间之前 且 结束时间在已配置时段的开始时间之后 (] 或 () + || startTime1.isBefore(startTime2) && endTime1.isAfter(startTime2) + // 开始时间在已配置时段的结束时间之前 且 结束时间在已配值时段的结束时间之后 [) 或 () + || startTime1.isBefore(endTime2) && endTime1.isAfter(endTime2); + } + } diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java index d97a2613f..4c31a8baa 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java +++ b/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 { // ========== 商品 评价 1008007000 ========== ErrorCode COMMENT_NOT_EXISTS = new ErrorCode(1008007000, "商品 评价 不存在"); - ErrorCode ORDER_SPU_COMMENT_EXISTS = new ErrorCode(1008007001, "订单 商品评价 已存在"); + ErrorCode ORDER_SKU_COMMENT_EXISTS = new ErrorCode(1008007001, "订单 商品评价 已存在"); ErrorCode COMMENT_ERROR_OPT = new ErrorCode(1008007002, "商品评价非法操作"); ErrorCode COMMENT_ADDITIONAL_EXISTS = new ErrorCode(1008007003, "商品追加评价已存在"); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java index c2e791a44..24d6a5456 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java +++ b/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 { @NotNull(message = "评价人头像不能为空") private String userAvatar; - // TODO @puhui:spuId、spuName 是不是只有 ProductCommentRespVO 有呀。 - @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑透气小短袖") - @NotNull(message = "商品 SPU 编号不能为空") - private Long spuId; - - @Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") - @NotNull(message = "商品 SPU 名称不能为空") - private String spuName; - @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @NotNull(message = "商品 SKU 编号不能为空") private Long skuId; - @Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") - @NotNull(message = "评分星级不能为空") - private Integer scores; - @Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") @NotNull(message = "描述星级不能为空") private Integer descriptionScores; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentPageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentPageReqVO.java index f6e913fea..3791f572e 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentPageReqVO.java +++ b/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 { @InEnum(ProductCommentScoresEnum.class) private Integer scores; - // TODO @puhui999:replyStatus 哈 @Schema(description = "商家是否回复", example = "true") - private Boolean replied; + private Boolean replyStatus; @Schema(description = "创建时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java index a75e9ec0c..9205e34cc 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java +++ b/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; import lombok.EqualsAndHashCode; import lombok.ToString; +import javax.validation.constraints.NotNull; import java.time.LocalDateTime; @Schema(description = "管理后台 - 商品评价 Response VO") @@ -40,4 +41,15 @@ public class ProductCommentRespVO extends ProductCommentBaseVO { @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; + @Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") + private Integer scores; + + @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑透气小短袖") + @NotNull(message = "商品 SPU 编号不能为空") + private Long spuId; + + @Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") + @NotNull(message = "商品 SPU 名称不能为空") + private String spuName; + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java index 2fcffb275..e1c70f01c 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java @@ -30,11 +30,6 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; -/** - * 商品 SPU 相关接口 - * - * @author HUIHUI - */ @Tag(name = "管理后台 - 商品 SPU") @RestController @RequestMapping("/product/spu") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuCreateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuCreateReqVO.java index b2fef56e2..baf6adfab 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuCreateReqVO.java +++ b/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; import javax.validation.Valid; import java.util.List; -/** - * 商品 SPU 创建 Request VO - * - * @author HUIHUI - */ @Schema(description = "管理后台 - 商品 SPU 创建 Request VO") @Data @EqualsAndHashCode(callSuper = true) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuDetailRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuDetailRespVO.java index eff229c9d..1be96632d 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuDetailRespVO.java +++ b/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; import java.util.List; -/** - * 商品 SPU 详细 Response VO - * 包括关联的 SKU 等信息 - * - * @author HUIHUI - */ @Schema(description = "管理后台 - 商品 SPU 详细 Response VO") @Data @EqualsAndHashCode(callSuper = true) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuExportReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuExportReqVO.java index f1da656d1..aaeca8622 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuExportReqVO.java +++ b/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; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; -/** - * 商品Spu导出 Request VO,参数和 ProductSpuPageReqVO 是一致的 - * - * @author HUIHUI - */ @Schema(description = "管理后台 - 商品Spu导出 Request VO,参数和 ProductSpuPageReqVO 是一致的") @Data @NoArgsConstructor diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuPageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuPageReqVO.java index d428164dd..81cff4210 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuPageReqVO.java +++ b/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; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; -/** - * 商品 SPU 分页 Request VO - * - * @author HUIHUI - */ @Schema(description = "管理后台 - 商品 SPU 分页 Request VO") @Data @EqualsAndHashCode(callSuper = true) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuRespVO.java index 346614ad0..bd35d5b9a 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuRespVO.java @@ -7,11 +7,6 @@ import lombok.ToString; import java.time.LocalDateTime; -/** - * 商品 SPU Response VO - * - * @author HUIHUI - */ @Schema(description = "管理后台 - 商品 SPU Response VO") @Data @EqualsAndHashCode(callSuper = true) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuSimpleRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuSimpleRespVO.java index 1c943a912..7d9d0d05d 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuSimpleRespVO.java +++ b/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; import lombok.Data; import lombok.ToString; -/** - * 商品 SPU 精简 Response VO - * TODO 商品 SPU 精简 VO 暂时没有使用到,用到的时候再按需添加\修改属性 - * @author HUIHUI - */ @Schema(description = "管理后台 - 商品 SPU 精简 Response VO") @Data @ToString(callSuper = true) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuUpdateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuUpdateReqVO.java index c7c424fa0..bb69eb4cf 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuUpdateReqVO.java +++ b/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; import javax.validation.constraints.NotNull; import java.util.List; -/** - * 商品 SPU 更新 Request VO - * - * @author HUIHUI - */ @Schema(description = "管理后台 - 商品 SPU 更新 Request VO") @Data @EqualsAndHashCode(callSuper = true) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuUpdateStatusReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuUpdateStatusReqVO.java index 57bda636c..e36e68466 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuUpdateStatusReqVO.java +++ b/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; import javax.validation.constraints.NotNull; -/** - * 商品 SPU Status 更新 Request VO - * - * @author HUIHUI - */ @Schema(description = "管理后台 - 商品 SPU Status 更新 Request VO") @Data public class ProductSpuUpdateStatusReqVO{ diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java index 1bcd4a138..3b79a2855 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java @@ -1,18 +1,18 @@ package cn.iocoder.yudao.module.product.controller.app.comment; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; -import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; +import com.google.common.collect.Maps; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; @@ -26,11 +26,9 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -61,26 +59,14 @@ public class AppProductCommentController { @GetMapping("/page") @Operation(summary = "获得商品评价分页") public CommonResult> getCommentPage(@Valid AppCommentPageReqVO pageVO) { - PageResult page = productCommentService.getCommentPage(pageVO, Boolean.TRUE); - // TODO @puhui CollUtils 有简化 convertmap 和 list 的方法 - Set skuIds = page.getList().stream().map(AppProductCommentRespVO::getSkuId).collect(Collectors.toSet()); + PageResult commentDOPage = productCommentService.getCommentPage(pageVO, Boolean.TRUE); + Set skuIds = CollectionUtils.convertSet(commentDOPage.getList(), ProductCommentDO::getSkuId); List skuList = productSkuService.getSkuList(skuIds); - Map skuDOMap = new HashMap<>(skuIds.size()); + Map skuDOMap = Maps.newLinkedHashMapWithExpectedSize(skuIds.size()); if (CollUtil.isNotEmpty(skuList)) { - skuDOMap.putAll(skuList.stream().collect(Collectors.toMap(ProductSkuDO::getId, c -> c))); + skuDOMap.putAll(CollectionUtils.convertMap(skuList, ProductSkuDO::getId, c -> c)); } - // TODO @puihui999:下面也可以放到 convert 里哈 - page.getList().forEach(item -> { - // 判断用户是否选择匿名 - if (ObjectUtil.equal(item.getAnonymous(), true)) { - item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS); - } - ProductSkuDO productSkuDO = skuDOMap.get(item.getSkuId()); - if (productSkuDO != null) { - List skuProperties = ProductCommentConvert.INSTANCE.convertList01(productSkuDO.getProperties()); - item.setSkuProperties(skuProperties); - } - }); + PageResult page = ProductCommentConvert.INSTANCE.convertPage02(commentDOPage, skuDOMap); return success(page); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java index d13a2b0ac..2ea3af496 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java +++ b/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; import java.time.LocalDateTime; import java.util.List; -/** - * 用户 App - 商品评价详情 Response VO - * - * @author HUIHUI - */ @Schema(description = "用户 App - 商品评价详情 Response VO") @Data @ToString(callSuper = true) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java index 170a3f0f4..92c661881 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.product.convert.comment; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; @@ -19,6 +20,7 @@ import org.mapstruct.factory.Mappers; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.List; +import java.util.Map; /** * 商品评价 Convert @@ -32,10 +34,12 @@ public interface ProductCommentConvert { ProductCommentRespVO convert(ProductCommentDO bean); - // TODO @puhui999:这里貌似字段对上,就不用 mapping 了;可以测试下看看哈 - @Mapping(target = "goodCount", source = "goodCount") - @Mapping(target = "mediocreCount", source = "mediocreCount") - @Mapping(target = "negativeCount", source = "negativeCount") + @Named("calculateOverallScore") + default double calculateOverallScore(long goodCount, long mediocreCount, long negativeCount) { + return (goodCount * 5 + mediocreCount * 3 + negativeCount) / (double) (goodCount + mediocreCount + negativeCount); + } + + @Mapping(target = "scores", expression = "java(calculateOverallScore(goodCount, mediocreCount, negativeCount))") AppCommentStatisticsRespVO convert(Long goodCount, Long mediocreCount, Long negativeCount); List convertList(List list); @@ -44,7 +48,23 @@ public interface ProductCommentConvert { PageResult convertPage(PageResult page); - PageResult convertPage02(PageResult pageResult); + PageResult convertPage01(PageResult pageResult); + + default PageResult convertPage02(PageResult pageResult, Map skuDOMap) { + PageResult page = convertPage01(pageResult); + page.getList().forEach(item -> { + // 判断用户是否选择匿名 + if (ObjectUtil.equal(item.getAnonymous(), true)) { + item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS); + } + ProductSkuDO productSkuDO = skuDOMap.get(item.getSkuId()); + if (productSkuDO != null) { + List skuProperties = ProductCommentConvert.INSTANCE.convertList01(productSkuDO.getProperties()); + item.setSkuProperties(skuProperties); + } + }); + return page; + } /** * 计算综合评分 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java index 1426073a5..48b651a55 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java +++ b/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 { return selectPage(reqVO, queryWrapper); } - default ProductCommentDO selectByUserIdAndOrderItemIdAndSpuId(Long userId, Long orderItemId, Long spuId) { + default ProductCommentDO selectByUserIdAndOrderItemIdAndSpuId(Long userId, Long orderItemId, Long skuId) { return selectOne(new LambdaQueryWrapperX() .eq(ProductCommentDO::getUserId, userId) .eq(ProductCommentDO::getOrderItemId, orderItemId) - .eq(ProductCommentDO::getSpuId, spuId)); + .eq(ProductCommentDO::getSpuId, skuId)); } default Long selectCountBySpuId(Long spuId, Boolean visible, Integer type) { diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java index 7f615677c..2c2b35197 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java +++ b/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 { * @param visible 是否可见 * @return 商品评价分页 */ - PageResult getCommentPage(AppCommentPageReqVO pageVO, Boolean visible); + PageResult getCommentPage(AppCommentPageReqVO pageVO, Boolean visible); /** * 创建商品评论 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java index b0822e96c..3409344d1 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java +++ b/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 { @Transactional(rollbackFor = Exception.class) public void createComment(ProductCommentCreateReqVO createReqVO) { // 校验评论 - validateComment(createReqVO.getSpuId(), createReqVO.getUserId(), createReqVO.getOrderItemId()); + validateComment(createReqVO.getSkuId(), createReqVO.getUserId(), createReqVO.getOrderItemId()); ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqVO); productCommentMapper.insert(commentDO); @@ -108,11 +108,11 @@ public class ProductCommentServiceImpl implements ProductCommentService { return commentDO.getId(); } - private void validateComment(Long spuId, Long userId, Long orderItemId) { + private void validateComment(Long skuId, Long userId, Long orderItemId) { // 判断当前订单的当前商品用户是否评价过 - ProductCommentDO exist = productCommentMapper.selectByUserIdAndOrderItemIdAndSpuId(userId, orderItemId, spuId); + ProductCommentDO exist = productCommentMapper.selectByUserIdAndOrderItemIdAndSpuId(userId, orderItemId, skuId); if (null != exist) { - throw exception(ORDER_SPU_COMMENT_EXISTS); + throw exception(ORDER_SKU_COMMENT_EXISTS); } } @@ -141,23 +141,17 @@ public class ProductCommentServiceImpl implements ProductCommentService { productCommentMapper.selectCountBySpuId(spuId, visible, AppCommentPageReqVO.MEDIOCRE_COMMENT), // 查询商品 id = spuId 的所有差评数量 productCommentMapper.selectCountBySpuId(spuId, visible, AppCommentPageReqVO.NEGATIVE_COMMENT) - ).setScores(3.0); // TODO @puhui999:这里要实现下;; + ); } @Override public List getCommentList(Long spuId, Integer count) { - // 校验商品 spu 是否存在 - // TODO @puhui 这里校验可以去掉哈。 - ProductSpuDO spuDO = validateSpu(spuId); - return ProductCommentConvert.INSTANCE.convertList02(productCommentMapper.selectCommentList(spuDO.getId(), count).getList()); + return ProductCommentConvert.INSTANCE.convertList02(productCommentMapper.selectCommentList(spuId, count).getList()); } - // TODO @puhui 可以放到 controller 去 convert 哈 @Override - public PageResult getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) { - // TODO @puhui 可以放到 controller 去 convert 哈 - return ProductCommentConvert.INSTANCE.convertPage02( - productCommentMapper.selectPage(pageVO, visible)); + public PageResult getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) { + return productCommentMapper.selectPage(pageVO, visible); } @Override diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java index 8d3a3d5b8..2f55af837 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java +++ b/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 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper; @@ -128,7 +127,7 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { productCommentPageReqVO.setSpuId(spuId); productCommentPageReqVO.setSpuName("感冒药"); productCommentPageReqVO.setScores(ProductCommentScoresEnum.FOUR.getScores()); - productCommentPageReqVO.setReplied(Boolean.TRUE); + productCommentPageReqVO.setReplyStatus(Boolean.TRUE); PageResult commentPage = productCommentService.getCommentPage(productCommentPageReqVO); PageResult result = ProductCommentConvert.INSTANCE.convertPage(productCommentMapper.selectPage(productCommentPageReqVO)); @@ -138,15 +137,15 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { assertEquals(8, all.getTotal()); // 测试获取所有商品分页评论数据 - PageResult result1 = productCommentService.getCommentPage(new AppCommentPageReqVO(), Boolean.TRUE); + PageResult result1 = productCommentService.getCommentPage(new AppCommentPageReqVO(), Boolean.TRUE); assertEquals(7, result1.getTotal()); // 测试获取所有商品分页中评数据 - PageResult result2 = productCommentService.getCommentPage(new AppCommentPageReqVO().setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); + PageResult result2 = productCommentService.getCommentPage(new AppCommentPageReqVO().setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); assertEquals(2, result2.getTotal()); // 测试获取指定 spuId 商品分页中评数据 - PageResult result3 = productCommentService.getCommentPage(new AppCommentPageReqVO().setSpuId(spuId).setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); + PageResult result3 = productCommentService.getCommentPage(new AppCommentPageReqVO().setSpuId(spuId).setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); assertEquals(2, result3.getTotal()); // 测试分页 tab count diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillConfigController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillConfigController.java index 628c6d1c2..671b1f61b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/SeckillConfigController.java +++ b/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; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -/** - * 管理后台 - 秒杀时段相关接口 - * - * @author HUIHUI - */ @Tag(name = "管理后台 - 秒杀时段") @RestController @RequestMapping("/promotion/seckill-config") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java index 959b8a8fa..680a26cf5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java @@ -9,11 +9,6 @@ import lombok.ToString; import java.time.LocalDateTime; import java.util.List; -/** - * 管理后台 - 秒杀活动 Response VO - * - * @author HUIHUI - */ @Schema(description = "管理后台 - 秒杀活动 Response VO") @Data @EqualsAndHashCode(callSuper = true) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/config/SeckillConfigBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/config/SeckillConfigBaseVO.java index 27b69b2b1..78a1c51df 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/config/SeckillConfigBaseVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/config/SeckillConfigBaseVO.java @@ -1,9 +1,13 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config; +import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import javax.validation.constraints.AssertTrue; import javax.validation.constraints.NotNull; +import java.time.LocalTime; +import java.util.List; /** * 秒杀时段 Base VO,提供给添加、修改、详细的子 VO 使用 @@ -26,12 +30,24 @@ public class SeckillConfigBaseVO { @NotNull(message = "结束时间点不能为空") private String endTime; - @Schema(description = "秒杀主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn") - @NotNull(message = "秒杀主图不能为空") - private String picUrl; + @Schema(description = "秒杀轮播图", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png]") + @NotNull(message = "秒杀轮播图不能为空") + private List sliderPicUrls; @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") @NotNull(message = "状态不能为空") private Integer status; + @AssertTrue(message = "秒杀时段开始时间和结束时间不能相等") + @JsonIgnore + public boolean isValidStartTimeValid() { + return !LocalTime.parse(startTime).equals(LocalTime.parse(endTime)); + } + + @AssertTrue(message = "秒杀时段开始时间不能在结束时间之后") + @JsonIgnore + public boolean isValidEndTimeValid() { + return !LocalTime.parse(startTime).isAfter(LocalTime.parse(endTime)); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/config/SeckillConfigPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/config/SeckillConfigPageReqVO.java index e49a02837..92211385a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/config/SeckillConfigPageReqVO.java +++ b/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; import lombok.EqualsAndHashCode; import lombok.ToString; -// TODO @puhui:VO 上不写注释,已经有注解啦。 -/** - * 管理后台 - 秒杀时段分页 Request VO - * - * @author HUIHUI - */ @Schema(description = "管理后台 - 秒杀时段分页 Request VO") @Data @EqualsAndHashCode(callSuper = true) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductCreateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductCreateReqVO.java index 9b06f98f6..8ee4884ea 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductCreateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductCreateReqVO.java @@ -1,16 +1,9 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product; -import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductBaseVO; -import lombok.*; -import java.util.*; import io.swagger.v3.oas.annotations.media.Schema; -import javax.validation.constraints.*; - -/** - * 管理后台 - 秒杀参与商品创建 Request VO - * - * @author HUIHUI - */ +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; @Schema(description = "管理后台 - 秒杀参与商品创建 Request VO") @Data @EqualsAndHashCode(callSuper = true) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductRespVO.java index bb33fab58..96b7eec4c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductRespVO.java @@ -1,14 +1,12 @@ package cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + import java.time.LocalDateTime; -/** - * 管理后台 - 秒杀参与商品 Response VO - * - * @author HUIHUI - */ @Schema(description = "管理后台 - 秒杀参与商品 Response VO") @Data @EqualsAndHashCode(callSuper = true) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductUpdateReqVO.java index b0b14d044..5fdccf8d0 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductUpdateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/product/SeckillProductUpdateReqVO.java @@ -5,11 +5,6 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -/** - * 管理后台 - 秒杀参与商品更新 Request VO - * - * @author HUIHUI - */ @Schema(description = "管理后台 - 秒杀参与商品更新 Request VO") @Data @EqualsAndHashCode(callSuper = true) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillconfig/SeckillConfigDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillconfig/SeckillConfigDO.java index f8fe41a18..c741a9fb5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillconfig/SeckillConfigDO.java +++ b/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; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; +import lombok.*; + +import java.util.List; /** * 秒杀时段 DO * * @author 芋道源码 */ -@TableName("promotion_seckill_config") +@TableName(value = "promotion_seckill_config", autoResultMap = true) @KeySequence("promotion_seckill_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor public class SeckillConfigDO extends BaseDO { /** @@ -38,14 +43,14 @@ public class SeckillConfigDO extends BaseDO { * 结束时间点 */ private String endTime; - // TODO puhui999:应该是轮播图; private List sliderPicUrls; /** - * 秒杀主图 + * 秒杀轮播图 */ - private String picUrl; + @TableField(typeHandler = JacksonTypeHandler.class) + private List sliderPicUrls; /** * 状态 - * + *

* 枚举 {@link CommonStatusEnum 对应的类} */ private Integer status; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillconfig/SeckillConfigMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillconfig/SeckillConfigMapper.java index e94c61949..53da4b0bc 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillconfig/SeckillConfigMapper.java +++ b/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 import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillconfig.SeckillConfigDO; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + @Mapper public interface SeckillConfigMapper extends BaseMapperX { @@ -17,4 +19,9 @@ public interface SeckillConfigMapper extends BaseMapperX { .orderByDesc(SeckillConfigDO::getId)); } + default List selectListByStatus(Integer status) { + return selectList(SeckillConfigDO::getStatus, status); + } + + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillconfig/SeckillConfigServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillconfig/SeckillConfigServiceImpl.java index d233a2d38..630001247 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillconfig/SeckillConfigServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillconfig/SeckillConfigServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigUpdateReqVO; @@ -12,14 +13,13 @@ import cn.iocoder.yudao.module.promotion.convert.seckill.seckillconfig.SeckillCo import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillconfig.SeckillConfigDO; import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillconfig.SeckillConfigMapper; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalTime; import java.util.Collection; import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; @@ -37,9 +37,10 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { private SeckillConfigMapper seckillConfigMapper; @Override + @Transactional(rollbackFor = Exception.class) public Long createSeckillConfig(SeckillConfigCreateReqVO createReqVO) { // 校验时间段是否冲突 - validateSeckillConfigConflict(createReqVO.getStartTime(), createReqVO.getEndTime()); + validateSeckillConfigConflict(createReqVO.getStartTime(), createReqVO.getEndTime(), null); // 插入 SeckillConfigDO seckillConfig = SeckillConfigConvert.INSTANCE.convert(createReqVO); @@ -49,18 +50,30 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { } @Override + @Transactional(rollbackFor = Exception.class) public void updateSeckillConfig(SeckillConfigUpdateReqVO updateReqVO) { // 校验存在 validateSeckillConfigExists(updateReqVO.getId()); // 校验时间段是否冲突 - validateSeckillConfigConflict(updateReqVO.getStartTime(), updateReqVO.getEndTime()); + validateSeckillConfigConflict(updateReqVO.getStartTime(), updateReqVO.getEndTime(), updateReqVO.getId()); // 更新 SeckillConfigDO updateObj = SeckillConfigConvert.INSTANCE.convert(updateReqVO); seckillConfigMapper.updateById(updateObj); } + // TODO @puhui999: 这个要不合并到更新操作里? 不单独有个操作咧; 更新状态不用那么多必须的参数,更新的时候需要校验时间段 @Override + public void updateSeckillConfigStatus(Long id, Integer status) { + // 校验秒杀时段是否存在 + validateSeckillConfigExists(id); + + // 更新状态 + seckillConfigMapper.updateById(new SeckillConfigDO().setId(id).setStatus(status)); + } + + @Override + @Transactional(rollbackFor = Exception.class) public void deleteSeckillConfig(Long id) { // 校验存在 validateSeckillConfigExists(id); @@ -81,39 +94,29 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { * @param startTime 开始时间 * @param endTime 结束时间 */ - private void validateSeckillConfigConflict(String startTime, String endTime) { + private void validateSeckillConfigConflict(String startTime, String endTime, Long seckillConfigId) { LocalTime startTime1 = LocalTime.parse(startTime); LocalTime endTime1 = LocalTime.parse(endTime); - // TODO @puhui999: 这个可以用 validator 里的 assertTrue 去做哈; - // 检查选择的时间是否相等 - if (startTime1.equals(endTime1)) { - throw exception(SECKILL_TIME_EQUAL); - } - // 检查开始时间是否在结束时间之前 - if (startTime1.isAfter(endTime1)) { - throw exception(SECKILL_START_TIME_BEFORE_END_TIME); - } // 查询出所有的时段配置 List configDOs = seckillConfigMapper.selectList(); + // 更新时排除自己 + if (seckillConfigId != null) { + configDOs.removeIf(item -> ObjectUtil.equal(item.getId(), seckillConfigId)); + } // 过滤出重叠的时段 ids - // TODO @puhui999:感觉 findOne 就可以了? - Set ids = configDOs.stream().filter((config) -> { + boolean hasConflict = configDOs.stream().anyMatch(config -> { LocalTime startTime2 = LocalTime.parse(config.getStartTime()); LocalTime endTime2 = LocalTime.parse(config.getEndTime()); // 判断时间是否重叠 - // 开始时间在已配置时段的结束时间之前 且 结束时间在已配置时段的开始时间之后 [] - // todo @puhui999:LocalDateUtils 可以写个工具类?是否是有重叠的时间?感觉别的场景,可能也会有需要 - return startTime1.isBefore(endTime2) && endTime1.isAfter(startTime2) - // 开始时间在已配置时段的开始时间之前 且 结束时间在已配置时段的开始时间之后 (] 或 () - || startTime1.isBefore(startTime2) && endTime1.isAfter(startTime2) - // 开始时间在已配置时段的结束时间之前 且 结束时间在已配值时段的结束时间之后 [) 或 () - || startTime1.isBefore(endTime2) && endTime1.isAfter(endTime2); - }).map(SeckillConfigDO::getId).collect(Collectors.toSet()); - if (CollUtil.isNotEmpty(ids)) { + return LocalDateTimeUtils.checkTimeOverlap(startTime1, endTime1, startTime2, endTime2); + }); + + if (hasConflict) { throw exception(SECKILL_TIME_CONFLICTS); } } + @Override public SeckillConfigDO getSeckillConfig(Long id) { return seckillConfigMapper.selectById(id); @@ -148,23 +151,9 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { return seckillConfigMapper.selectPage(pageVO); } - // TODO @puhui999:写个查询状态的; 尽可能通用哈 @Override public List getListAllSimple() { - return seckillConfigMapper.selectList(SeckillConfigDO::getStatus, CommonStatusEnum.ENABLE.getStatus()); - } - - // TODO @puhui999: 这个要不合并到更新操作里? 不单独有个操作咧; - @Override - public void updateSeckillConfigStatus(Long id, Integer status) { - // 校验秒杀时段是否存在 - validateSeckillConfigExists(id); - - SeckillConfigDO seckillConfigDO = new SeckillConfigDO(); - seckillConfigDO.setId(id); - seckillConfigDO.setStatus(status); - // 更新状态 - seckillConfigMapper.updateById(seckillConfigDO); + return seckillConfigMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus()); } } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 1b3c73c30..4646fedb7 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -27,6 +27,8 @@ public interface ErrorCodeConstants { ErrorCode ORDER_UPDATE_PAID_FAIL_PAY_PRICE_NOT_MATCH = new ErrorCode(1011000016, "交易订单更新支付状态失败,支付单金额不匹配"); ErrorCode ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED = new ErrorCode(1011000017, "交易订单发货失败,订单不是【待发货】状态"); ErrorCode ORDER_RECEIVE_FAIL_STATUS_NOT_DELIVERED = new ErrorCode(1011000018, "交易订单收货失败,订单不是【待收货】状态"); + ErrorCode ORDER_COMMENT_FAIL_STATUS_NOT_COMPLETED = new ErrorCode(1011000019, "创建交易订单项的评价失败,订单不是【已完成】状态"); + ErrorCode ORDER_COMMENT_STATUS_NOT_FALSE = new ErrorCode(1011000019, "创建交易订单项的评价失败,订单已评价"); // ========== After Sale 模块 1011000100 ========== ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index 6567e3169..d46550765 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/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; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.module.pay.api.notify.dto.PayOrderNotifyReqDTO; -import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi; -import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; import cn.iocoder.yudao.module.product.api.property.ProductPropertyValueApi; import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.*; @@ -30,13 +28,10 @@ import javax.validation.Valid; import java.util.List; import java.util.Map; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_ITEM_NOT_FOUND; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND; @Tag(name = "用户 App - 交易订单") @RestController @@ -47,12 +42,8 @@ public class AppTradeOrderController { @Resource private TradeOrderService tradeOrderService; - @Resource private ProductPropertyValueApi productPropertyValueApi; - @Resource - private ProductCommentApi productCommentApi; - @Resource private TradeOrderProperties tradeOrderProperties; @@ -121,7 +112,7 @@ public class AppTradeOrderController { // 待发货 orderCount.put("undeliveredCount", tradeOrderService.getOrderCount(getLoginUserId(), TradeOrderStatusEnum.UNDELIVERED.getStatus(), null)); // 待收货 - orderCount.put("deliveredCount", tradeOrderService.getOrderCount(getLoginUserId(), TradeOrderStatusEnum.DELIVERED.getStatus(), null)); + orderCount.put("deliveredCount", tradeOrderService.getOrderCount(getLoginUserId(), TradeOrderStatusEnum.DELIVERED.getStatus(), null)); // 待评价 orderCount.put("uncommentedCount", tradeOrderService.getOrderCount(getLoginUserId(), TradeOrderStatusEnum.COMPLETED.getStatus(), false)); return success(orderCount); @@ -164,22 +155,7 @@ public class AppTradeOrderController { @PostMapping("/item/create-comment") @Operation(summary = "创建交易订单项的评价") public CommonResult createOrderItemComment(@RequestBody AppTradeOrderItemCommentCreateReqVO createReqVO) { - // TODO @puhui999:这个逻辑,最好写到 service 哈; - Long loginUserId = getLoginUserId(); - // 先通过订单项 ID 查询订单项是否存在 - TradeOrderItemDO orderItemDO = tradeOrderService.getOrderItemByIdAndUserId(createReqVO.getOrderItemId(), loginUserId); - if (orderItemDO == null) { - throw exception(ORDER_ITEM_NOT_FOUND); - } - // 校验订单 - TradeOrderDO orderDO = tradeOrderService.getOrderByIdAndUserId(orderItemDO.getOrderId(), loginUserId); - if (orderDO == null) { - throw exception(ORDER_NOT_FOUND); - } - // TODO @puhui999:要校验订单已完成,但是未评价; - - ProductCommentCreateReqDTO productCommentCreateReqDTO = TradeOrderConvert.INSTANCE.convert04(createReqVO, orderItemDO); - return success(productCommentApi.createComment(productCommentCreateReqDTO)); + return success(tradeOrderService.createOrderItemComment(createReqVO)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/item/AppTradeOrderItemCommentCreateReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/item/AppTradeOrderItemCommentCreateReqVO.java index 349b071d5..69ffef241 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/item/AppTradeOrderItemCommentCreateReqVO.java +++ b/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 { @NotNull(message = "交易订单项编号不能为空") private Long orderItemId; - // TODO @puhui999:貌似不用这个字段哈; - @Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") - @NotNull(message = "评分星级 1-5 分不能为空") - private Integer scores; - @Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") @NotNull(message = "描述星级 1-5 分不能为空") private Integer descriptionScores; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index 88ce02300..30a01cdab 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -270,7 +270,6 @@ public interface TradeOrderConvert { @Mapping(target = "skuId", source = "tradeOrderItemDO.skuId") @Mapping(target = "orderId", source = "tradeOrderItemDO.orderId") @Mapping(target = "orderItemId", source = "tradeOrderItemDO.id") - @Mapping(target = "scores", source = "createReqVO.scores") @Mapping(target = "descriptionScores", source = "createReqVO.descriptionScores") @Mapping(target = "benefitScores", source = "createReqVO.benefitScores") @Mapping(target = "content", source = "createReqVO.content") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderService.java index d49baf49c..c0ab69be1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderService.java +++ b/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 import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; +import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; @@ -177,4 +178,14 @@ public interface TradeOrderService { * @return 得到订单 */ TradeOrderDO getOrderByIdAndUserId(Long orderId, Long loginUserId); + + /** + * 创建订单项评论 + * 创建交易订单项的评价 + * + * @param createReqVO 创建请求 + * @return 得到评价 id + */ + Long createOrderItemComment(AppTradeOrderItemCommentCreateReqVO createReqVO); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java index d06987ba6..0dc2b6e5c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java @@ -17,19 +17,21 @@ import cn.iocoder.yudao.module.pay.api.order.PayOrderApi; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO; import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum; +import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi; +import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO; import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi; import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO; -import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; +import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; @@ -57,6 +59,7 @@ import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.PAY_ORDER_NOT_FOUND; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; @@ -93,7 +96,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { @Resource private MemberUserApi memberUserApi; @Resource - private AdminUserApi adminUserApi; + private ProductCommentApi productCommentApi; @Resource private NotifyMessageSendApi notifyMessageSendApi; @@ -556,6 +559,30 @@ public class TradeOrderServiceImpl implements TradeOrderService { return tradeOrderMapper.selectOrderByIdAndUserId(orderId, loginUserId); } + @Override + public Long createOrderItemComment(AppTradeOrderItemCommentCreateReqVO createReqVO) { + Long loginUserId = getLoginUserId(); + // 先通过订单项 ID 查询订单项是否存在 + TradeOrderItemDO orderItemDO = getOrderItemByIdAndUserId(createReqVO.getOrderItemId(), loginUserId); + if (orderItemDO == null) { + throw exception(ORDER_ITEM_NOT_FOUND); + } + // 校验订单 + TradeOrderDO orderDO = getOrderByIdAndUserId(orderItemDO.getOrderId(), loginUserId); + if (orderDO == null) { + throw exception(ORDER_NOT_FOUND); + } + if (ObjectUtil.notEqual(orderDO.getStatus(), TradeOrderStatusEnum.COMPLETED.getStatus())) { + throw exception(ORDER_COMMENT_FAIL_STATUS_NOT_COMPLETED); + } + if (ObjectUtil.notEqual(orderDO.getCommentStatus(), Boolean.FALSE)) { + throw exception(ORDER_COMMENT_STATUS_NOT_FALSE); + } + + ProductCommentCreateReqDTO productCommentCreateReqDTO = TradeOrderConvert.INSTANCE.convert04(createReqVO, orderItemDO); + return productCommentApi.createComment(productCommentCreateReqDTO); + } + /** * 判断指定订单的所有订单项,是不是都售后成功 * diff --git a/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImplTest.java b/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImplTest.java index 77b40705e..c25b76ca6 100644 --- a/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImplTest.java +++ b/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; import static org.junit.jupiter.api.Assertions.assertNull; /** -* {@link AddressServiceImpl} 的单元测试类 -* -* @author 芋道源码 -*/ + * {@link AddressServiceImpl} 的单元测试类 + * + * @author 芋道源码 + */ @Import(AddressServiceImpl.class) public class AddressServiceImplTest extends BaseDbUnitTest { @@ -82,8 +82,8 @@ public class AddressServiceImplTest extends BaseDbUnitTest { // 调用 addressService.deleteAddress(dbAddress.getUserId(), id); - // 校验数据不存在了 - assertNull(addressMapper.selectById(id)); + // 校验数据不存在了 + assertNull(addressMapper.selectById(id)); } @Test From 7cdb321fe4b10ac02f3c82c19dc37336fb84472f Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 14 Jul 2023 17:08:37 +0800 Subject: [PATCH 07/12] =?UTF-8?q?fix=EF=BC=9A=E5=AE=8C=E5=96=84=E6=8B=BC?= =?UTF-8?q?=E5=9B=A2=E6=B4=BB=E5=8A=A8CRUD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/enums/ErrorCodeConstants.java | 4 +- .../CombinationActivityController.java | 4 +- .../activity/CombinationActivityBaseVO.java | 3 +- .../CombinationActivityCreateReqVO.java | 4 +- .../activity/CombinationActivityRespVO.java | 7 ++ .../CombinationActivityUpdateReqVO.java | 7 ++ .../CombinationProductUpdateReqVO.java | 6 -- .../CombinationActivityConvert.java | 89 ++++++++++++--- .../CombinationActivityDO.java | 6 +- .../CombinationActivityMapper.java | 1 + .../CombinationProductMapper.java | 4 + .../CombinationActivityService.java | 8 ++ .../CombinationActivityServiceImpl.java | 101 ++++++++++++++---- 13 files changed, 191 insertions(+), 53 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index ca3f36af1..c1f0d9135 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -62,5 +62,7 @@ public interface ErrorCodeConstants { // ========== 拼团活动 1013010000 ========== ErrorCode COMBINATION_ACTIVITY_NOT_EXISTS = new ErrorCode(1013010000, "拼团活动不存在"); - ErrorCode COMBINATION_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1013010000, "存在商品参加了其它拼团活动"); + ErrorCode COMBINATION_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1013010001, "存在商品参加了其它拼团活动"); + ErrorCode COMBINATION_ACTIVITY_STATUS_DISABLE = new ErrorCode(1013010002, "拼团活动已关闭不能修改"); + ErrorCode COMBINATION_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013010003, "拼团活动未关闭或未结束,不能删除"); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java index 3e97673bb..2a8f6b9dd 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.*; import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -64,7 +65,8 @@ public class CombinationActivityController { @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") public CommonResult getCombinationActivity(@RequestParam("id") Long id) { CombinationActivityDO combinationActivity = combinationActivityService.getCombinationActivity(id); - return success(CombinationActivityConvert.INSTANCE.convert(combinationActivity)); + List productDOs = combinationActivityService.getProductsByActivityId(id); + return success(CombinationActivityConvert.INSTANCE.convert(combinationActivity, productDOs)); } @GetMapping("/list") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityBaseVO.java index 1130779e0..df7dd6416 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityBaseVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityBaseVO.java @@ -6,7 +6,6 @@ import org.springframework.format.annotation.DateTimeFormat; import javax.validation.constraints.NotNull; import java.time.LocalDateTime; -import java.util.List; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @@ -23,7 +22,7 @@ public class CombinationActivityBaseVO { @Schema(description = "商品 SPU 编号关联 ProductSpuDO 的 id", example = "[1,2,3]") @NotNull(message = "拼团商品不能为空") - private List spuIds; + private Long spuId; @Schema(description = "总限购数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "16218") @NotNull(message = "总限购数量不能为空") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityCreateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityCreateReqVO.java index e75ee8b49..ea7879e4e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityCreateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityCreateReqVO.java @@ -6,6 +6,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import javax.validation.Valid; import java.util.List; @Schema(description = "管理后台 - 拼团活动创建 Request VO") @@ -14,7 +15,8 @@ import java.util.List; @ToString(callSuper = true) public class CombinationActivityCreateReqVO extends CombinationActivityBaseVO { - @Schema(description = "秒杀商品", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED) + @Valid private List products; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java index f7163967d..31ffad293 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java @@ -1,12 +1,15 @@ package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductRespVO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import javax.validation.Valid; import javax.validation.constraints.NotNull; import java.time.LocalDateTime; +import java.util.List; @Schema(description = "管理后台 - 拼团活动 Response VO") @Data @@ -40,4 +43,8 @@ public class CombinationActivityRespVO extends CombinationActivityBaseVO { @NotNull(message = "活动状态:0开启 1关闭不能为空") private Integer status; + @Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED) + @Valid + private List products; + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityUpdateReqVO.java index 1ecbf1e48..c4f8cf0c3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityUpdateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityUpdateReqVO.java @@ -1,11 +1,14 @@ package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductUpdateReqVO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import javax.validation.Valid; import javax.validation.constraints.NotNull; +import java.util.List; @Schema(description = "管理后台 - 拼团活动更新 Request VO") @Data @@ -17,4 +20,8 @@ public class CombinationActivityUpdateReqVO extends CombinationActivityBaseVO { @NotNull(message = "活动编号不能为空") private Long id; + @Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED) + @Valid + private List products; + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductUpdateReqVO.java index 80365db84..5fab798da 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductUpdateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/product/CombinationProductUpdateReqVO.java @@ -5,16 +5,10 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -import javax.validation.constraints.NotNull; - @Schema(description = "管理后台 - 拼团商品更新 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class CombinationProductUpdateReqVO extends CombinationProductBaseVO { - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28322") - @NotNull(message = "编号不能为空") - private Long id; - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java index 4bdebcf84..0ddd81580 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java @@ -1,19 +1,27 @@ package cn.iocoder.yudao.module.promotion.convert.combination; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityExcelVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductBaseVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.Named; import org.mapstruct.factory.Mappers; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * 拼团活动 Convert @@ -25,33 +33,82 @@ public interface CombinationActivityConvert { CombinationActivityConvert INSTANCE = Mappers.getMapper(CombinationActivityConvert.class); - @Mapping(target = "startTime", expression = "java(bean.getActivityTime()[0])") - @Mapping(target = "endTime", expression = "java(bean.getActivityTime()[1])") + @Mappings({ + @Mapping(target = "startTime", expression = "java(bean.getActivityTime()[0])"), + @Mapping(target = "endTime", expression = "java(bean.getActivityTime()[1])") + }) CombinationActivityDO convert(CombinationActivityCreateReqVO bean); + @Mappings({ + @Mapping(target = "startTime", expression = "java(bean.getActivityTime()[0])"), + @Mapping(target = "endTime", expression = "java(bean.getActivityTime()[1])") + }) CombinationActivityDO convert(CombinationActivityUpdateReqVO bean); + @Named("mergeTime") + default LocalDateTime[] mergeTime(LocalDateTime startTime, LocalDateTime endTime) { + // TODO 有点怪第一次这样写 hh + LocalDateTime[] localDateTime = new LocalDateTime[2]; + localDateTime[0] = startTime; + localDateTime[1] = endTime; + return localDateTime; + } + + @Mappings({ + @Mapping(target = "activityTime", expression = "java(mergeTime(bean.getStartTime(),bean.getEndTime()))") + }) CombinationActivityRespVO convert(CombinationActivityDO bean); + CombinationProductRespVO convert(CombinationProductDO bean); + + default CombinationActivityRespVO convert(CombinationActivityDO bean, List productDOs) { + CombinationActivityRespVO respVO = convert(bean); + ArrayList vos = new ArrayList<>(); + productDOs.forEach(item -> { + vos.add(convert(item)); + }); + respVO.setProducts(vos); + return respVO; + } + List convertList(List list); PageResult convertPage(PageResult page); List convertList02(List list); - default List convertList(CombinationActivityDO activityDO, List products) { - ArrayList productDOs = new ArrayList<>(); - products.forEach(item -> { - CombinationProductDO productDO = new CombinationProductDO(); - productDO.setActivityId(activityDO.getId()); - productDO.setSpuId(item.getSpuId()); - productDO.setSkuId(item.getSkuId()); - productDO.setActivityStatus(0); // TODO 拼团状态枚举未定义不确定有些什么状态 - productDO.setActivityStartTime(activityDO.getStartTime()); - productDO.setActivityEndTime(activityDO.getEndTime()); - productDO.setActivePrice(item.getActivePrice()); - productDOs.add(productDO); + @Mappings({ + @Mapping(target = "id", ignore = true), + @Mapping(target = "activityId", source = "activityDO.id"), + @Mapping(target = "spuId", source = "activityDO.spuId"), + @Mapping(target = "skuId", source = "vo.skuId"), + @Mapping(target = "activePrice", source = "vo.activePrice"), + @Mapping(target = "activityStartTime", source = "activityDO.startTime"), + @Mapping(target = "activityEndTime", source = "activityDO.endTime") + }) + CombinationProductDO convert(CombinationActivityDO activityDO, CombinationProductBaseVO vo); + + default List convertList(CombinationActivityDO activityDO, List products) { + List list = new ArrayList<>(); + products.forEach(sku -> { + CombinationProductDO productDO = convert(activityDO, sku); + // TODO 状态设置 + productDO.setActivityStatus(CommonStatusEnum.ENABLE.getStatus()); + list.add(productDO); }); - return productDOs; + return list; } + + default List convertList1(CombinationActivityDO activityDO, List vos, List productDOs) { + Map longMap = CollectionUtils.convertMap(productDOs, CombinationProductDO::getSkuId, CombinationProductDO::getId); + List list = new ArrayList<>(); + vos.forEach(sku -> { + CombinationProductDO productDO = convert(activityDO, sku); + productDO.setId(longMap.get(sku.getSkuId())); + productDO.setActivityStatus(CommonStatusEnum.ENABLE.getStatus()); + list.add(productDO); + }); + return list; + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationActivityDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationActivityDO.java index ee20c3393..ede493637 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationActivityDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationActivityDO.java @@ -2,15 +2,12 @@ package cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combination import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler; import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; import java.time.LocalDateTime; -import java.util.List; /** * 拼团活动 DO @@ -39,8 +36,7 @@ public class CombinationActivityDO extends BaseDO { /** * 商品 SPU 编号关联 ProductSpuDO 的 id */ - @TableField(typeHandler = LongListTypeHandler.class) - private List spuIds; + private Long spuId; /** * 总限购数量 */ diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationActivityMapper.java index 80ed4e0ec..1053a6757 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationActivityMapper.java @@ -34,4 +34,5 @@ public interface CombinationActivityMapper extends BaseMapperX selectListByStatus(Integer status) { return selectList(CombinationActivityDO::getStatus, status); } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java index 54e13053a..f236e135a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java @@ -44,4 +44,8 @@ public interface CombinationProductMapper extends BaseMapperX selectListByActivityId(Long id) { + return selectList(CombinationProductDO::getActivityId, id); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java index 0417b2bd9..4b0f7b1ee 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activit import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; import javax.validation.Valid; import java.util.Collection; @@ -72,4 +73,11 @@ public interface CombinationActivityService { */ List getCombinationActivityList(CombinationActivityExportReqVO exportReqVO); + /** + * 获得拼团活动商品列表 + * + * @param id 拼团活动 ID + * @return 拼团活动的商品列表 + */ + List getProductsByActivityId(Long id); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index b388c3e18..16bd79ded 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -1,9 +1,11 @@ package cn.iocoder.yudao.module.promotion.service.combination; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; @@ -13,6 +15,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activit import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductUpdateReqVO; import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; @@ -22,15 +25,13 @@ import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; +import java.util.Set; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_ACTIVITY_NOT_EXISTS; -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_ACTIVITY_SPU_CONFLICTS; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.promotion.util.PromotionUtils.validateProductSkuExistence; /** @@ -54,9 +55,9 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic @Override public Long createCombinationActivity(CombinationActivityCreateReqVO createReqVO) { // 校验商品 SPU 是否存在是否参加的别的活动 - validateProductCombinationConflict(createReqVO.getSpuIds()); + validateProductCombinationConflict(createReqVO.getSpuId(), null); // 获取所选 spu下的所有 sku - List skus = productSkuApi.getSkuListBySpuId(createReqVO.getSpuIds()); + List skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(createReqVO.getSpuId())); // 校验商品 sku 是否存在 validateProductSkuExistence(skus, createReqVO.getProducts(), CombinationProductCreateReqVO::getSkuId); @@ -79,21 +80,20 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic return activityDO.getId(); } - private void validateProductCombinationConflict(List spuIds) { + private void validateProductCombinationConflict(Long spuId, Long activityId) { // 校验商品 spu 是否存在 - List spuList = productSpuApi.getSpuList(spuIds); - if (ObjectUtil.notEqual(spuIds.size(), spuList.size())) { + List spuList = productSpuApi.getSpuList(CollUtil.newArrayList(spuId)); + if (CollUtil.isEmpty(spuList)) { throw exception(SPU_NOT_EXISTS); } - // 查询所有开启的秒杀活动 + // 查询所有开启的拼团活动 List activityDOs = combinationActivityMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus()); + // 更新时排除自己 + if (activityId != null) { + activityDOs.removeIf(item -> ObjectUtil.equal(item.getId(), activityId)); + } // 过滤出所有 spuIds 有交集的活动 - List doList = activityDOs.stream().filter(s -> { - // 判断 spu 是否有交集 - ArrayList spuIdsClone = CollUtil.newArrayList(s.getSpuIds()); - spuIdsClone.retainAll(spuIds); - return CollUtil.isNotEmpty(spuIdsClone); - }).collect(Collectors.toList()); + List doList = CollectionUtils.convertList(activityDOs, c -> c, s -> ObjectUtil.equal(s.getId(), spuId)); if (CollUtil.isNotEmpty(doList)) { throw exception(COMBINATION_ACTIVITY_SPU_CONFLICTS); } @@ -102,29 +102,83 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic @Override public void updateCombinationActivity(CombinationActivityUpdateReqVO updateReqVO) { // 校验存在 - validateCombinationActivityExists(updateReqVO.getId()); + CombinationActivityDO activityDO = validateCombinationActivityExists(updateReqVO.getId()); + // 校验状态 + if (ObjectUtil.equal(activityDO.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { + throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE); + } + // 校验商品冲突 + validateProductCombinationConflict(updateReqVO.getSpuId(), updateReqVO.getId()); + // 获取所选 spu下的所有 sku + List skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(updateReqVO.getSpuId())); + // 校验商品 sku 是否存在 + validateProductSkuExistence(skus, updateReqVO.getProducts(), CombinationProductUpdateReqVO::getSkuId); + // 更新 CombinationActivityDO updateObj = CombinationActivityConvert.INSTANCE.convert(updateReqVO); combinationActivityMapper.updateById(updateObj); + // 更新商品 + updateCombinationProduct(updateObj, updateReqVO.getProducts()); + } + + /** + * 更新秒杀商品 + * TODO 更新商品要不要封装成通用方法 + * + * @param updateObj DO + * @param products 商品配置 + */ + private void updateCombinationProduct(CombinationActivityDO updateObj, List products) { + List combinationProductDOs = combinationProductMapper.selectListByActivityId(updateObj.getId()); + // 数据库中的活动商品 + Set convertSet = CollectionUtils.convertSet(combinationProductDOs, CombinationProductDO::getSkuId); + // 前端传过来的活动商品 + Set convertSet1 = CollectionUtils.convertSet(products, CombinationProductUpdateReqVO::getSkuId); + // 删除后台存在的前端不存在的商品 + List d = CollectionUtils.filterList(convertSet, item -> !convertSet1.contains(item)); + if (CollUtil.isNotEmpty(d)) { + combinationProductMapper.deleteBatchIds(d); + } + // 前端存在的后端不存在的商品 + List c = CollectionUtils.filterList(convertSet1, item -> !convertSet.contains(item)); + if (CollUtil.isNotEmpty(c)) { + List vos = CollectionUtils.filterList(products, item -> c.contains(item.getSkuId())); + List productDOs = CombinationActivityConvert.INSTANCE.convertList(updateObj, vos); + combinationProductMapper.insertBatch(productDOs); + } + // 更新已存在的商品 + List u = CollectionUtils.filterList(convertSet1, convertSet::contains); + if (CollUtil.isNotEmpty(u)) { + List vos = CollectionUtils.filterList(products, item -> u.contains(item.getSkuId())); + List productDOs = CombinationActivityConvert.INSTANCE.convertList1(updateObj, vos, combinationProductDOs); + combinationProductMapper.updateBatch(productDOs); + } } @Override public void deleteCombinationActivity(Long id) { // 校验存在 - validateCombinationActivityExists(id); + CombinationActivityDO activityDO = validateCombinationActivityExists(id); + // 校验状态 + if (ObjectUtil.equal(activityDO.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { + throw exception(COMBINATION_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END); + } + // 删除 combinationActivityMapper.deleteById(id); } - private void validateCombinationActivityExists(Long id) { - if (combinationActivityMapper.selectById(id) == null) { + private CombinationActivityDO validateCombinationActivityExists(Long id) { + CombinationActivityDO activityDO = combinationActivityMapper.selectById(id); + if (activityDO == null) { throw exception(COMBINATION_ACTIVITY_NOT_EXISTS); } + return activityDO; } @Override public CombinationActivityDO getCombinationActivity(Long id) { - return combinationActivityMapper.selectById(id); + return validateCombinationActivityExists(id); } @Override @@ -142,4 +196,9 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic return combinationActivityMapper.selectList(exportReqVO); } + @Override + public List getProductsByActivityId(Long id) { + return combinationProductMapper.selectListByActivityId(id); + } + } From 147cd271b83bcb5b1c4663704feddb70ee0252d4 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 14 Jul 2023 17:34:37 +0800 Subject: [PATCH 08/12] =?UTF-8?q?fix=EF=BC=9A=E5=AE=8C=E5=96=84=E6=8B=BC?= =?UTF-8?q?=E5=9B=A2=E6=B4=BB=E5=8A=A8=E5=88=97=E8=A1=A8=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CombinationActivityController.java | 15 ++++++++++++-- .../activity/CombinationActivityRespVO.java | 6 ++++++ .../vo/activity/SeckillActivityRespVO.java | 2 +- .../CombinationActivityConvert.java | 20 ++++++++++++++----- .../SeckillActivityConvert.java | 2 +- .../CombinationProductMapper.java | 5 +++-- .../CombinationActivityService.java | 4 ++-- .../CombinationActivityServiceImpl.java | 6 +++--- 8 files changed, 44 insertions(+), 16 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java index 2a8f6b9dd..883ff2ffc 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationActivityController.java @@ -1,9 +1,13 @@ package cn.iocoder.yudao.module.promotion.controller.admin.combination; +import cn.hutool.core.collection.CollectionUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.*; import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; @@ -22,6 +26,7 @@ import javax.validation.Valid; import java.io.IOException; import java.util.Collection; import java.util.List; +import java.util.Set; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; @@ -34,6 +39,8 @@ public class CombinationActivityController { @Resource private CombinationActivityService combinationActivityService; + @Resource + private ProductSpuApi spuApi; @PostMapping("/create") @Operation(summary = "创建拼团活动") @@ -65,7 +72,7 @@ public class CombinationActivityController { @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") public CommonResult getCombinationActivity(@RequestParam("id") Long id) { CombinationActivityDO combinationActivity = combinationActivityService.getCombinationActivity(id); - List productDOs = combinationActivityService.getProductsByActivityId(id); + List productDOs = combinationActivityService.getProductsByActivityIds(CollectionUtil.newArrayList(id)); return success(CombinationActivityConvert.INSTANCE.convert(combinationActivity, productDOs)); } @@ -83,7 +90,11 @@ public class CombinationActivityController { @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") public CommonResult> getCombinationActivityPage(@Valid CombinationActivityPageReqVO pageVO) { PageResult pageResult = combinationActivityService.getCombinationActivityPage(pageVO); - return success(CombinationActivityConvert.INSTANCE.convertPage(pageResult)); + Set aIds = CollectionUtils.convertSet(pageResult.getList(), CombinationActivityDO::getId); + List productDOs = combinationActivityService.getProductsByActivityIds(aIds); + Set spuIds = CollectionUtils.convertSet(pageResult.getList(), CombinationActivityDO::getSpuId); + List spuList = spuApi.getSpuList(spuIds); + return success(CombinationActivityConvert.INSTANCE.convertPage(pageResult, productDOs, spuList)); } @GetMapping("/export-excel") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java index 31ffad293..3d95ef704 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java @@ -17,6 +17,12 @@ import java.util.List; @ToString(callSuper = true) public class CombinationActivityRespVO extends CombinationActivityBaseVO { + @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") + private String spuName; + + @Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png") + private String picUrl; + @Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901") private Long id; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java index 680a26cf5..ad78a9464 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java @@ -18,7 +18,7 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO { @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") private String spuName; - @Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") + @Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png") private String picUrl; @Schema(description = "秒杀活动id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java index 0ddd81580..dc8f161b3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.convert.combination; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityExcelVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO; @@ -63,11 +64,7 @@ public interface CombinationActivityConvert { default CombinationActivityRespVO convert(CombinationActivityDO bean, List productDOs) { CombinationActivityRespVO respVO = convert(bean); - ArrayList vos = new ArrayList<>(); - productDOs.forEach(item -> { - vos.add(convert(item)); - }); - respVO.setProducts(vos); + respVO.setProducts(convertList2(productDOs)); return respVO; } @@ -75,6 +72,19 @@ public interface CombinationActivityConvert { PageResult convertPage(PageResult page); + default PageResult convertPage(PageResult page, List productDOList, List spuList) { + Map spuMap = CollectionUtils.convertMap(spuList, ProductSpuRespDTO::getId, c -> c); + PageResult pageResult = convertPage(page); + pageResult.getList().forEach(item -> { + item.setSpuName(spuMap.get(item.getSpuId()).getName()); + item.setPicUrl(spuMap.get(item.getSpuId()).getPicUrl()); + item.setProducts(convertList2(productDOList)); + }); + return pageResult; + } + + List convertList2(List productDOs); + List convertList02(List list); @Mappings({ diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java index 7e004c4c2..689ddb17c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java @@ -62,7 +62,7 @@ public interface SeckillActivityConvert { } @Mappings({ - @Mapping(target = "id", expression = "java(null)"), + @Mapping(target = "id", ignore = true), @Mapping(target = "activityId", source = "activityDO.id"), @Mapping(target = "configIds", source = "activityDO.configIds"), @Mapping(target = "spuId", source = "activityDO.spuId"), diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java index f236e135a..ced6de6d4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationProductMapper.java @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; import org.apache.ibatis.annotations.Mapper; +import java.util.Collection; import java.util.List; /** @@ -44,8 +45,8 @@ public interface CombinationProductMapper extends BaseMapperX selectListByActivityId(Long id) { - return selectList(CombinationProductDO::getActivityId, id); + default List selectListByActivityIds(Collection ids) { + return selectList(CombinationProductDO::getActivityId, ids); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java index 4b0f7b1ee..01e3a0663 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java @@ -76,8 +76,8 @@ public interface CombinationActivityService { /** * 获得拼团活动商品列表 * - * @param id 拼团活动 ID + * @param ids 拼团活动 ids * @return 拼团活动的商品列表 */ - List getProductsByActivityId(Long id); + List getProductsByActivityIds(Collection ids); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index 16bd79ded..7fb377d11 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -129,7 +129,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic * @param products 商品配置 */ private void updateCombinationProduct(CombinationActivityDO updateObj, List products) { - List combinationProductDOs = combinationProductMapper.selectListByActivityId(updateObj.getId()); + List combinationProductDOs = combinationProductMapper.selectListByActivityIds(CollUtil.newArrayList(updateObj.getId())); // 数据库中的活动商品 Set convertSet = CollectionUtils.convertSet(combinationProductDOs, CombinationProductDO::getSkuId); // 前端传过来的活动商品 @@ -197,8 +197,8 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic } @Override - public List getProductsByActivityId(Long id) { - return combinationProductMapper.selectListByActivityId(id); + public List getProductsByActivityIds(Collection ids) { + return combinationProductMapper.selectListByActivityIds(ids); } } From 259807600a57f4180842427b57bbb3597bc56b57 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 21 Jul 2023 16:47:04 +0800 Subject: [PATCH 09/12] =?UTF-8?q?feat=EF=BC=9A=E6=8B=BC=E5=9B=A2=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E9=9B=86=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/combination/CombinationApi.java | 39 +++++++ .../dto/CombinationRecordReqDTO.java | 77 +++++++++++++ .../promotion/enums/ErrorCodeConstants.java | 1 + .../CombinationRecordStatusEnum.java | 38 +++++++ .../api/combination/CombinationApiImpl.java | 36 ++++++ .../activity/CombinationActivityBaseVO.java | 6 +- .../activity/CombinationActivityExcelVO.java | 2 +- .../CombinationActivityExportReqVO.java | 2 +- .../CombinationActivityPageReqVO.java | 2 +- .../activity/CombinationActivityRespVO.java | 6 +- .../CombinationActivityConvert.java | 4 + .../CombinationActivityDO.java | 2 +- .../CombinationRecordDO.java | 105 ++++++++++++++++++ .../CombinationRecordMapper.java | 19 ++++ .../CombinationActivityService.java | 29 +++++ .../CombinationActivityServiceImpl.java | 49 +++++++- .../trade/enums/ErrorCodeConstants.java | 1 + .../order/vo/TradeOrderDeliveryReqVO.java | 17 ++- .../vo/AppTradeOrderSettlementReqVO.java | 6 - .../convert/order/TradeOrderConvert.java | 43 ++++--- .../service/order/TradeOrderServiceImpl.java | 56 ++++++++-- 21 files changed, 498 insertions(+), 42 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java create mode 100644 yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordReqDTO.java create mode 100644 yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/combination/CombinationRecordStatusEnum.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationRecordDO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationRecordMapper.java diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java new file mode 100644 index 000000000..9ccbab62d --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.promotion.api.combination; + +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordReqDTO; + +import javax.validation.Valid; + +/** + * 拼团活动 API 接口 + * + * @author HUIHUI + */ +public interface CombinationApi { + + /** + * 创建开团记录 + * + * @param reqDTO 请求 DTO + */ + void createRecord(@Valid CombinationRecordReqDTO reqDTO); + + /** + * 更新开团记录状态 + * + * @param userId 用户编号 + * @param orderId 订单编号 + * @param status 状态值 + */ + void updateRecordStatus(Long userId, Long orderId, Integer status); + + /** + * 更新开团记录状态和开始时间 + * + * @param userId 用户编号 + * @param orderId 订单编号 + * @param status 状态值 + */ + void updateRecordStatusAndStartTime(Long userId, Long orderId, Integer status); + +} diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordReqDTO.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordReqDTO.java new file mode 100644 index 000000000..a5d1048d9 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordReqDTO.java @@ -0,0 +1,77 @@ +package cn.iocoder.yudao.module.promotion.api.combination.dto; + +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** + * 拼团记录 Request DTO + * + * @author HUIHUI + */ +@Data +public class CombinationRecordReqDTO { + + /** + * 拼团活动编号 + */ + @NotNull(message = "拼团活动编号不能为空") + private Long activityId; + /** + * spu 编号 + */ + @NotNull(message = "spu 编号不能为空") + private Long spuId; + /** + * sku 编号 + */ + @NotNull(message = "sku 编号不能为空") + private Long skuId; + /** + * 用户编号 + */ + @NotNull(message = "用户编号不能为空") + private Long userId; + /** + * 订单编号 + */ + @NotNull(message = "订单编号不能为空") + private Long orderId; + /** + * 团长编号 + */ + @NotNull(message = "团长编号不能为空") + private Long headId; + /** + * 商品名字 + */ + @NotEmpty(message = "商品名字不能为空") + private String spuName; + /** + * 商品图片 + */ + @NotEmpty(message = "商品图片不能为空") + private String picUrl; + /** + * 拼团商品单价 + */ + @NotNull(message = "拼团商品单价不能为空") + private Integer combinationPrice; + /** + * 用户昵称 + */ + @NotEmpty(message = "用户昵称不能为空") + private String nickname; + /** + * 用户头像 + */ + @NotEmpty(message = "用户头像不能为空") + private String avatar; + /** + * 开团状态:正在开团 拼团成功 拼团失败 TODO 等待支付 + */ + @NotNull(message = "开团状态不能为空") + private Integer status; + +} diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index c1f0d9135..6a646a11d 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -65,4 +65,5 @@ public interface ErrorCodeConstants { ErrorCode COMBINATION_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1013010001, "存在商品参加了其它拼团活动"); ErrorCode COMBINATION_ACTIVITY_STATUS_DISABLE = new ErrorCode(1013010002, "拼团活动已关闭不能修改"); ErrorCode COMBINATION_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013010003, "拼团活动未关闭或未结束,不能删除"); + ErrorCode COMBINATION_RECORD_NOT_EXISTS = new ErrorCode(1013010004, "拼团不存在"); } diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/combination/CombinationRecordStatusEnum.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/combination/CombinationRecordStatusEnum.java new file mode 100644 index 000000000..cc475133e --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/combination/CombinationRecordStatusEnum.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.module.promotion.enums.combination; + +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * 拼团状态枚举 + * + * @author HUIHUI + */ +@AllArgsConstructor +@Getter +public enum CombinationRecordStatusEnum implements IntArrayValuable { + NOT_PAY(0, "未付款"), + ONGOING(1, "进行中"), + SUCCESS(2, "拼团成功"), + FAILED(3, "拼团失败"); + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CombinationRecordStatusEnum::getStatus).toArray(); + + /** + * 状态值 + */ + private final Integer status; + /** + * 状态名 + */ + private final String name; + + @Override + public int[] array() { + return ARRAYS; + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java new file mode 100644 index 000000000..d4774ab99 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.module.promotion.api.combination; + +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordReqDTO; +import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.time.LocalDateTime; + +/** + * 拼团活动 API 实现类 + * + * @author HUIHUI + */ +@Service +public class CombinationApiImpl implements CombinationApi { + @Resource + private CombinationActivityService activityService; + + @Override + public void createRecord(CombinationRecordReqDTO reqDTO) { + activityService.createRecord(reqDTO); + } + + @Override + public void updateRecordStatus(Long userId, Long orderId, Integer status) { + activityService.updateRecordStatusByUserIdAndOrderId(userId, orderId, status); + } + + @Override + public void updateRecordStatusAndStartTime(Long userId, Long orderId, Integer status) { + activityService.updateRecordStatusAndStartTimeByUserIdAndOrderId(userId, orderId, status, LocalDateTime.now()); + } + + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityBaseVO.java index df7dd6416..daebc9905 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityBaseVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityBaseVO.java @@ -37,9 +37,9 @@ public class CombinationActivityBaseVO { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] activityTime; - @Schema(description = "参与人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "25222") - @NotNull(message = "参与人数不能为空") - private Integer orderUserCount; + @Schema(description = "开团人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "25222") + @NotNull(message = "开团人数不能为空") + private Integer userSize; @Schema(description = "限制时长(小时)", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "限制时长(小时)不能为空") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityExcelVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityExcelVO.java index 29537a5d3..4ca035c9d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityExcelVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityExcelVO.java @@ -37,7 +37,7 @@ public class CombinationActivityExcelVO { @ExcelProperty("结束时间") private LocalDateTime endTime; - @ExcelProperty("购买人数") + @ExcelProperty("开团人数") private Integer userSize; @ExcelProperty("开团组数") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityExportReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityExportReqVO.java index f2fe0df3e..99f73cfa2 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityExportReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityExportReqVO.java @@ -32,7 +32,7 @@ public class CombinationActivityExportReqVO { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] endTime; - @Schema(description = "购买人数") + @Schema(description = "开团人数") private Integer userSize; @Schema(description = "开团组数") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityPageReqVO.java index e6cfce527..bcd06fdc8 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityPageReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityPageReqVO.java @@ -37,7 +37,7 @@ public class CombinationActivityPageReqVO extends PageParam { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] endTime; - @Schema(description = "购买人数") + @Schema(description = "开团人数") private Integer userSize; @Schema(description = "开团组数") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java index 3d95ef704..106021264 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityRespVO.java @@ -29,8 +29,8 @@ public class CombinationActivityRespVO extends CombinationActivityBaseVO { @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; - @Schema(description = "购买人数", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "购买人数不能为空") + @Schema(description = "开团人数", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "开团人数不能为空") private Integer userSize; @Schema(description = "开团组数", requiredMode = Schema.RequiredMode.REQUIRED) @@ -46,7 +46,7 @@ public class CombinationActivityRespVO extends CombinationActivityBaseVO { private Integer virtualGroup; @Schema(description = "活动状态:0开启 1关闭", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") - @NotNull(message = "活动状态:0开启 1关闭不能为空") + @NotNull(message = "活动状态不能为空") private Integer status; @Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java index dc8f161b3..5cf99a18d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordReqDTO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityExcelVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO; @@ -13,6 +14,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationRecordDO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; @@ -121,4 +123,6 @@ public interface CombinationActivityConvert { return list; } + CombinationRecordDO convert(CombinationRecordReqDTO reqDTO); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationActivityDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationActivityDO.java index ede493637..58e62d30b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationActivityDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationActivityDO.java @@ -54,7 +54,7 @@ public class CombinationActivityDO extends BaseDO { */ private LocalDateTime endTime; /** - * 购买人数 + * 几人团 */ private Integer userSize; /** diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationRecordDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationRecordDO.java new file mode 100644 index 000000000..7dd509ff5 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationRecordDO.java @@ -0,0 +1,105 @@ +package cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; + +import java.time.LocalDateTime; + +/** + * 拼团记录 DO + * + * @author HUIHUI + */ +@TableName("promotion_combination_record") +@KeySequence("promotion_combination_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class CombinationRecordDO extends BaseDO { + + @TableId + private Long id; + /** + * 拼团活动编号 + */ + private Long activityId; + /** + * spu 编号 + */ + private Long spuId; + /** + * sku 编号 + */ + private Long skuId; + /** + * 用户编号 + */ + private Long userId; + /** + * 订单编号 + */ + private Long orderId; + /** + * 团长编号 + *

+ * 关联 {@link CombinationRecordDO#getUserId()} + */ + private Long headId; + /** + * 商品名字 + */ + private String spuName; + /** + * 商品图片 + */ + private String picUrl; + /** + * 拼团商品单价 + */ + private Integer combinationPrice; + /** + * 用户昵称 + */ + private String nickname; + /** + * 用户头像 + */ + private String avatar; + /** + * 开团状态: 正在开团 拼团成功 拼团失败 + */ + private Integer status; + /** + * 是否虚拟成团 + */ + private Boolean virtualGroup; + /** + * 过期时间,单位:小时 + * 关联关联 {@link CombinationActivityDO#getLimitDuration()} + */ + private Integer expireTime; + /** + * 开始时间 (订单付款后开始的时间) + */ + private LocalDateTime startTime; + /** + * 结束时间(成团时间/失败时间) + */ + private LocalDateTime endTime; + /** + * 开团需要人数 + * 关联 {@link CombinationActivityDO#getUserSize()} + */ + private Integer userSize; + /** + * 已加入拼团人数 + */ + private Integer userCount; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationRecordMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationRecordMapper.java new file mode 100644 index 000000000..a601e284e --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationRecordMapper.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationRecordDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 拼团记录 Mapper + * + * @author HUIHUI + */ +@Mapper +public interface CombinationRecordMapper extends BaseMapperX { + + default CombinationRecordDO selectRecord(Long userId, Long orderId) { + return selectOne(CombinationRecordDO::getUserId, userId, CombinationRecordDO::getOrderId, orderId); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java index 01e3a0663..482b3034e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.promotion.service.combination; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordReqDTO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityExportReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; @@ -9,6 +10,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationa import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; import javax.validation.Valid; +import java.time.LocalDateTime; import java.util.Collection; import java.util.List; @@ -80,4 +82,31 @@ public interface CombinationActivityService { * @return 拼团活动的商品列表 */ List getProductsByActivityIds(Collection ids); + + /** + * 更新拼团状态 + * + * @param userId 用户编号 + * @param orderId 订单编号 + * @param status 状态 + */ + void updateRecordStatusByUserIdAndOrderId(Long userId, Long orderId, Integer status); + + /** + * 更新拼团状态和开始时间 + * + * @param userId 用户编号 + * @param orderId 订单编号 + * @param status 状态 + * @param startTime 开始时间 + */ + void updateRecordStatusAndStartTimeByUserIdAndOrderId(Long userId, Long orderId, Integer status, LocalDateTime startTime); + + /** + * 创建拼团记录 + * + * @param reqDTO 创建信息 + */ + void createRecord(CombinationRecordReqDTO reqDTO); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index 7fb377d11..4d0f33e2b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordReqDTO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityExportReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; @@ -19,12 +20,15 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationRecordDO; import cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity.CombinationActivityMapper; import cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity.CombinationProductMapper; +import cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity.CombinationRecordMapper; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.time.LocalDateTime; import java.util.Collection; import java.util.List; import java.util.Set; @@ -46,6 +50,8 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic @Resource private CombinationActivityMapper combinationActivityMapper; @Resource + private CombinationRecordMapper recordMapper; + @Resource private CombinationProductMapper combinationProductMapper; @Resource private ProductSpuApi productSpuApi; @@ -66,7 +72,6 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic // 插入拼团活动 CombinationActivityDO activityDO = CombinationActivityConvert.INSTANCE.convert(createReqVO); // TODO 营销相关属性初始化 - activityDO.setUserSize(0); activityDO.setTotalNum(0); activityDO.setSuccessNum(0); activityDO.setOrderUserCount(0); @@ -201,4 +206,46 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic return combinationProductMapper.selectListByActivityIds(ids); } + @Override + public void updateRecordStatusByUserIdAndOrderId(Long userId, Long orderId, Integer status) { + // 校验拼团是否存在 + CombinationRecordDO recordDO = validateCombinationRecord(userId, orderId); + + // 更新状态 + recordDO.setStatus(status); + recordMapper.updateById(recordDO); + } + + @Override + public void updateRecordStatusAndStartTimeByUserIdAndOrderId(Long userId, Long orderId, Integer status, LocalDateTime startTime) { + CombinationRecordDO recordDO = validateCombinationRecord(userId, orderId); + + // 更新状态 + recordDO.setStatus(status); + // 更新开始时间 + recordDO.setStartTime(startTime); + recordMapper.updateById(recordDO); + } + + private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) { + // 校验拼团是否存在 + CombinationRecordDO recordDO = recordMapper.selectRecord(userId, orderId); + if (recordDO == null) { + throw exception(COMBINATION_RECORD_NOT_EXISTS); + } + return recordDO; + } + + @Override + public void createRecord(CombinationRecordReqDTO reqDTO) { + // 校验拼团活动 + CombinationActivityDO activityDO = validateCombinationActivityExists(reqDTO.getActivityId()); + + CombinationRecordDO recordDO = CombinationActivityConvert.INSTANCE.convert(reqDTO); + recordDO.setVirtualGroup(false); + recordDO.setExpireTime(activityDO.getLimitDuration()); + recordDO.setUserSize(activityDO.getUserSize()); + recordMapper.insert(recordDO); + } + } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 4646fedb7..ef2987c51 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -29,6 +29,7 @@ public interface ErrorCodeConstants { ErrorCode ORDER_RECEIVE_FAIL_STATUS_NOT_DELIVERED = new ErrorCode(1011000018, "交易订单收货失败,订单不是【待收货】状态"); ErrorCode ORDER_COMMENT_FAIL_STATUS_NOT_COMPLETED = new ErrorCode(1011000019, "创建交易订单项的评价失败,订单不是【已完成】状态"); ErrorCode ORDER_COMMENT_STATUS_NOT_FALSE = new ErrorCode(1011000019, "创建交易订单项的评价失败,订单已评价"); + ErrorCode ORDER_DELIVERY_FAIL_REFUND_STATUS_NOT_NONE = new ErrorCode(1011000017, "交易订单发货失败,订单已退款或部分退款"); // ========== After Sale 模块 1011000100 ========== ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDeliveryReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDeliveryReqVO.java index 039fb2f09..97707f5f3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDeliveryReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDeliveryReqVO.java @@ -1,9 +1,10 @@ package cn.iocoder.yudao.module.trade.controller.admin.order.vo; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; @Schema(description = "管理后台 - 订单发货 Request VO") @@ -14,12 +15,18 @@ public class TradeOrderDeliveryReqVO { @NotNull(message = "订单编号不能为空") private Long id; - @Schema(description = "发货物流公司编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "发货物流公司编号不能为空") + @Schema(description = "发货类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") + @InEnum(DeliveryTypeEnum.class) + @NotNull(message = "发货类型不能为空") + private Integer type; + + @Schema(description = "发货物流公司编号", example = "1") private Long logisticsId; - @Schema(description = "发货物流单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "SF123456789") - @NotEmpty(message = "发货物流单号不能为空") + @Schema(description = "发货物流单号", example = "SF123456789") private String logisticsNo; + // =============== 同城配送 ================ + // TODO + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java index f3a7d9120..3e322c786 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java +++ b/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; import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.framework.common.validation.Mobile; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; -import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -19,11 +18,6 @@ import java.util.List; @Data public class AppTradeOrderSettlementReqVO { - @NotNull(message = "交易类型不能为空") - @InEnum(value = TradeOrderTypeEnum.class, message = "交易类型必须是 {value}") - @Deprecated // TODO 芋艿:后续干掉这个字段,对于前端不需要关注这个 - private Integer type = 1; - @Schema(description = "商品项数组", requiredMode = Schema.RequiredMode.REQUIRED) @NotEmpty(message = "商品不能为空") private List items; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index 052a3d7d7..c4e453fc8 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.pay.enums.DictTypeConstants; import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordReqDTO; import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO; import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO; @@ -52,7 +53,6 @@ public interface TradeOrderConvert { @Mapping(source = "createReqVO.couponId", target = "couponId"), @Mapping(target = "remark", ignore = true), @Mapping(source = "createReqVO.remark", target = "userRemark"), - @Mapping(source = "createReqVO.type", target = "type"), @Mapping(source = "calculateRespBO.price.totalPrice", target = "totalPrice"), @Mapping(source = "calculateRespBO.price.discountPrice", target = "discountPrice"), @Mapping(source = "calculateRespBO.price.deliveryPrice", target = "deliveryPrice"), @@ -123,7 +123,7 @@ public interface TradeOrderConvert { // TODO 芋艿:可简化 default PageResult convertPage(PageResult pageResult, List orderItems, List propertyValueDetails, - Map memberUserRespDTOMap) { + Map memberUserRespDTOMap) { Map> orderItemMap = convertMultiMap(orderItems, TradeOrderItemDO::getOrderId); Map propertyValueDetailMap = convertMap(propertyValueDetails, ProductPropertyValueDetailRespDTO::getValueId); // 转化 List @@ -267,22 +267,23 @@ public interface TradeOrderConvert { AppTradeOrderItemRespVO convert03(TradeOrderItemDO bean); - @Mapping(target = "skuId", source = "tradeOrderItemDO.skuId") - @Mapping(target = "orderId", source = "tradeOrderItemDO.orderId") - @Mapping(target = "orderItemId", source = "tradeOrderItemDO.id") - @Mapping(target = "descriptionScores", source = "createReqVO.descriptionScores") - @Mapping(target = "benefitScores", source = "createReqVO.benefitScores") - @Mapping(target = "content", source = "createReqVO.content") - @Mapping(target = "picUrls", source = "createReqVO.picUrls") - @Mapping(target = "anonymous", source = "createReqVO.anonymous") - @Mapping(target = "userId", source = "tradeOrderItemDO.userId") + @Mappings({ + @Mapping(target = "skuId", source = "tradeOrderItemDO.skuId"), + @Mapping(target = "orderId", source = "tradeOrderItemDO.orderId"), + @Mapping(target = "orderItemId", source = "tradeOrderItemDO.id"), + @Mapping(target = "descriptionScores", source = "createReqVO.descriptionScores"), + @Mapping(target = "benefitScores", source = "createReqVO.benefitScores"), + @Mapping(target = "content", source = "createReqVO.content"), + @Mapping(target = "picUrls", source = "createReqVO.picUrls"), + @Mapping(target = "anonymous", source = "createReqVO.anonymous"), + @Mapping(target = "userId", source = "tradeOrderItemDO.userId") + }) ProductCommentCreateReqDTO convert04(AppTradeOrderItemCommentCreateReqVO createReqVO, TradeOrderItemDO tradeOrderItemDO); default TradePriceCalculateReqBO convert(Long userId, AppTradeOrderSettlementReqVO settlementReqVO, List cartList) { TradePriceCalculateReqBO reqBO = new TradePriceCalculateReqBO(); - reqBO.setUserId(userId).setType(settlementReqVO.getType()) - .setCouponId(settlementReqVO.getCouponId()).setAddressId(settlementReqVO.getAddressId()) + reqBO.setUserId(userId).setCouponId(settlementReqVO.getCouponId()).setAddressId(settlementReqVO.getAddressId()) .setItems(new ArrayList<>(settlementReqVO.getItems().size())); // 商品项的构建 Map cartMap = convertMap(cartList, TradeCartDO::getId); @@ -317,4 +318,20 @@ public interface TradeOrderConvert { AppTradeOrderSettlementRespVO convert0(TradePriceCalculateRespBO calculate, AddressRespDTO address); + @Mappings({ + @Mapping(target = "activityId", source = "createReqVO.combinationActivityId"), + @Mapping(target = "spuId", source = "orderItem.spuId"), + @Mapping(target = "skuId", source = "orderItem.skuId"), + @Mapping(target = "userId", source = "order.userId"), + @Mapping(target = "orderId", source = "order.id"), + @Mapping(target = "headId", source = "createReqVO.combinationHeadId"), + @Mapping(target = "spuName", source = "orderItem.spuName"), + @Mapping(target = "picUrl", source = "orderItem.picUrl"), + @Mapping(target = "combinationPrice", source = "orderItem.payPrice"), + @Mapping(target = "nickname", source = "user.nickname"), + @Mapping(target = "avatar", source = "user.avatar"), + @Mapping(target = "status", ignore = true) + }) + CombinationRecordReqDTO convert(TradeOrderDO order, TradeOrderItemDO orderItem, AppTradeOrderCreateReqVO createReqVO, MemberUserRespDTO user); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java index 8ef76ac43..4b5c0b899 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java @@ -21,8 +21,10 @@ import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi; import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; +import cn.iocoder.yudao.module.promotion.api.combination.CombinationApi; import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO; +import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi; import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; @@ -103,6 +105,8 @@ public class TradeOrderServiceImpl implements TradeOrderService { @Resource private TradeOrderProperties tradeOrderProperties; + @Resource + private CombinationApi combinationApi; // =================== Order =================== @Override @@ -158,7 +162,6 @@ public class TradeOrderServiceImpl implements TradeOrderService { public TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO) { // 1. 用户收件地址的校验 AddressRespDTO address = validateAddress(userId, createReqVO.getAddressId()); - // 2. 价格计算 TradePriceCalculateRespBO calculateRespBO = calculatePrice(userId, createReqVO); @@ -166,9 +169,17 @@ public class TradeOrderServiceImpl implements TradeOrderService { TradeOrderDO order = createTradeOrder(userId, userIp, createReqVO, calculateRespBO, address); // 3.2 插入 TradeOrderItemDO 订单项 List orderItems = createTradeOrderItems(order, calculateRespBO); - // 订单创建完后的逻辑 afterCreateTradeOrder(userId, createReqVO, order, orderItems, calculateRespBO); + // 3.3 校验订单类型 + // 拼团 + if (ObjectUtil.equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { + MemberUserRespDTO user = memberUserApi.getUser(userId); + // TODO 拼团一次应该只能选择一种规格的商品 + combinationApi.createRecord(TradeOrderConvert.INSTANCE.convert(order, orderItems.get(0), createReqVO, user) + .setStatus(CombinationRecordStatusEnum.NOT_PAY.getStatus())); + } + // TODO @LeeYan9: 是可以思考下, 订单的营销优惠记录, 应该记录在哪里, 微信讨论起来! return order; } @@ -188,12 +199,29 @@ public class TradeOrderServiceImpl implements TradeOrderService { return address; } + /** + * 校验活动返回订单类型 + * + * @param createReqVO 请求参数 + * @return 订单类型 + */ + private Integer validateActivity(AppTradeOrderCreateReqVO createReqVO) { + if (createReqVO.getSeckillActivityId() != null) { + return TradeOrderTypeEnum.SECKILL.getType(); + } + if (createReqVO.getCombinationActivityId() != null) { + return TradeOrderTypeEnum.COMBINATION.getType(); + } + // TODO 砍价敬请期待 + return TradeOrderTypeEnum.NORMAL.getType(); + } + private TradeOrderDO createTradeOrder(Long userId, String clientIp, AppTradeOrderCreateReqVO createReqVO, TradePriceCalculateRespBO calculateRespBO, AddressRespDTO address) { TradeOrderDO order = TradeOrderConvert.INSTANCE.convert(userId, clientIp, createReqVO, calculateRespBO, address); + order.setType(validateActivity(createReqVO)); order.setNo(IdUtil.getSnowflakeNextId() + ""); // TODO @LeeYan9: 思考下, 怎么生成好点哈; 这个是会展示给用户的; order.setStatus(TradeOrderStatusEnum.UNPAID.getStatus()); - order.setType(TradeOrderTypeEnum.NORMAL.getType()); order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()); order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum)); order.setTerminal(TerminalEnum.H5.getTerminal()); // todo 数据来源? @@ -270,7 +298,12 @@ public class TradeOrderServiceImpl implements TradeOrderService { if (updateCount == 0) { throw exception(ORDER_UPDATE_PAID_STATUS_NOT_UNPAID); } - + // 校验活动 + // 1、拼团活动 + if (ObjectUtil.equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { + // 更新拼团状态 TODO puhui999:订单支付失败或订单过期删除这条拼团记录 + combinationApi.updateRecordStatusAndStartTime(order.getUserId(), order.getId(), CombinationRecordStatusEnum.ONGOING.getStatus()); + } // TODO 芋艿:发送订单变化的消息 // TODO 芋艿:发送站内信 @@ -334,12 +367,12 @@ public class TradeOrderServiceImpl implements TradeOrderService { return new KeyValue<>(order, payOrder); } - // TODO 芋艿:如果无需发货,需要怎么存储? + // TODO 芋艿:如果无需发货,需要怎么存储? fix:更改订单发货类型为无需发货更改发货类型为等待自提,等待用户自提后更改订单状态为已完成 @Override public void deliveryOrder(Long userId, TradeOrderDeliveryReqVO deliveryReqVO) { // 校验并获得交易订单(可发货) TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId()); - // TODO 芋艿:logisticsId 校验存在 发货物流公司 fix + // TODO 判断发货类型,根据发货类型发货 DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(deliveryReqVO.getLogisticsId()); if (deliveryExpress == null) { throw exception(EXPRESS_NOT_EXISTS); @@ -369,7 +402,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { .setTemplateParams(msgMap)); // TODO 芋艿:OrderLog - // TODO 设计:like:是否要单独一个 delivery 发货单表??? + // TODO 设计:like:是否要单独一个 delivery 发货单表??? fix: 确实单独一张发货表就能解决整单发货和单独发货的问题 // TODO 设计:niu:要不要支持一个订单下,多个 order item 单独发货,类似有赞 // TODO 设计:lili:是不是发货后,才支持售后? } @@ -393,6 +426,15 @@ public class TradeOrderServiceImpl implements TradeOrderService { || ObjectUtil.notEqual(order.getDeliveryStatus(), TradeOrderDeliveryStatusEnum.UNDELIVERED.getStatus())) { throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED); } + // 校验订单是否退款 + if (ObjectUtil.notEqual(TradeOrderRefundStatusEnum.NONE.getStatus(), order.getRefundStatus())) { + throw exception(ORDER_DELIVERY_FAIL_REFUND_STATUS_NOT_NONE); + } + // 校验订单拼团是否成功 + if (ObjectUtil.equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { + + } + // TODO puhui999: 校验订单砍价是否成功 return order; } From f23e1b857a19214d3286ba6325e7a5a30f624b7e Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 21 Jul 2023 16:54:58 +0800 Subject: [PATCH 10/12] =?UTF-8?q?fix=EF=BC=9A=E5=90=88=E5=B9=B6=E5=B7=AE?= =?UTF-8?q?=E5=BC=82=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/trade/service/order/TradeOrderServiceImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java index 934b452fb..de63ed22a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java @@ -62,7 +62,6 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; -import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.PAY_ORDER_NOT_FOUND; import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.ORDER_NOT_FOUND; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; @@ -345,7 +344,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { PayOrderRespDTO payOrder = payOrderApi.getOrder(payOrderId); if (payOrder == null) { log.error("[validateOrderPaid][order({}) payOrder({}) 不存在,请进行处理!]", id, payOrderId); - throw exception(cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.ORDER_NOT_FOUND); + throw exception(ORDER_NOT_FOUND); } // 校验支付单已支付 if (!PayOrderStatusEnum.isSuccess(payOrder.getStatus())) { From 8d13ecc9c89014c336c92269249da23e948aa410 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 24 Jul 2023 15:14:16 +0800 Subject: [PATCH 11/12] =?UTF-8?q?fix=EF=BC=9A=E4=BC=98=E5=8C=96=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E5=8F=91=E8=B4=A7=E9=80=BB=E8=BE=91=E4=BD=BF=E5=85=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=B8=80=E5=8D=95=E5=88=86=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/combination/CombinationApi.java | 8 ++ .../api/combination/CombinationApiImpl.java | 5 + .../CombinationActivityService.java | 8 ++ .../CombinationActivityServiceImpl.java | 6 + .../trade/enums/ErrorCodeConstants.java | 11 +- .../order/vo/TradeOrderDeliveryReqVO.java | 7 ++ .../convert/order/TradeOrderConvert.java | 13 ++ .../order/TradeOrderDeliveryDO.java | 60 ++++++++++ .../mysql/order/TradeOrderDeliveryMapper.java | 23 ++++ .../service/order/TradeOrderServiceImpl.java | 113 ++++++++++++++---- 10 files changed, 229 insertions(+), 25 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDeliveryDO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderDeliveryMapper.java diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java index 9ccbab62d..fc1ca72f9 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java @@ -18,6 +18,14 @@ public interface CombinationApi { */ void createRecord(@Valid CombinationRecordReqDTO reqDTO); + /** + * 获取开团记录状态 + * + * @param userId 用户编号 + * @param orderId 订单编号 + */ + Integer getRecordStatus(Long userId, Long orderId); + /** * 更新开团记录状态 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java index d4774ab99..e2ca8698d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java @@ -22,6 +22,11 @@ public class CombinationApiImpl implements CombinationApi { activityService.createRecord(reqDTO); } + @Override + public Integer getRecordStatus(Long userId, Long orderId) { + return activityService.getRecordStatus(userId, orderId); + } + @Override public void updateRecordStatus(Long userId, Long orderId, Integer status) { activityService.updateRecordStatusByUserIdAndOrderId(userId, orderId, status); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java index 482b3034e..247ba95cf 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java @@ -109,4 +109,12 @@ public interface CombinationActivityService { */ void createRecord(CombinationRecordReqDTO reqDTO); + /** + * 获得拼团状态 + * + * @param userId 用户编号 + * @param orderId 订单编号 + * @return 拼团状态 + */ + Integer getRecordStatus(Long userId, Long orderId); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index 4d0f33e2b..f6e6aa3ed 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -248,4 +248,10 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic recordMapper.insert(recordDO); } + @Override + public Integer getRecordStatus(Long userId, Long orderId) { + CombinationRecordDO recordDO = validateCombinationRecord(userId, orderId); + return recordDO.getStatus(); + } + } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index ef2987c51..5c007f7e5 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -28,8 +28,9 @@ public interface ErrorCodeConstants { ErrorCode ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED = new ErrorCode(1011000017, "交易订单发货失败,订单不是【待发货】状态"); ErrorCode ORDER_RECEIVE_FAIL_STATUS_NOT_DELIVERED = new ErrorCode(1011000018, "交易订单收货失败,订单不是【待收货】状态"); ErrorCode ORDER_COMMENT_FAIL_STATUS_NOT_COMPLETED = new ErrorCode(1011000019, "创建交易订单项的评价失败,订单不是【已完成】状态"); - ErrorCode ORDER_COMMENT_STATUS_NOT_FALSE = new ErrorCode(1011000019, "创建交易订单项的评价失败,订单已评价"); - ErrorCode ORDER_DELIVERY_FAIL_REFUND_STATUS_NOT_NONE = new ErrorCode(1011000017, "交易订单发货失败,订单已退款或部分退款"); + ErrorCode ORDER_COMMENT_STATUS_NOT_FALSE = new ErrorCode(1011000020, "创建交易订单项的评价失败,订单已评价"); + ErrorCode ORDER_DELIVERY_FAIL_REFUND_STATUS_NOT_NONE = new ErrorCode(1011000021, "交易订单发货失败,订单已退款或部分退款"); + ErrorCode ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS = new ErrorCode(1011000022, "交易订单发货失败,拼团未成功"); // ========== After Sale 模块 1011000100 ========== ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在"); @@ -66,8 +67,10 @@ public interface ErrorCodeConstants { ErrorCode EXPRESS_TEMPLATE_NOT_EXISTS = new ErrorCode(1011005001, "运费模板不存在"); // ========== 物流 PICK_UP 模块 1011006000 ========== - ErrorCode PICK_UP_STORE_NOT_EXISTS = new ErrorCode(1011006000, "自提门店不存在"); - + // ========== 物流 PICK_UP 模块 1011007000 ========== + ErrorCode ORDER_DELIVERY_FAILED_ITEMS_NOT_EMPTY = new ErrorCode(1011007000, "订单发货失败,请选择发货商品"); + ErrorCode ORDER_DELIVERY_FAILED_ITEM_NOT_EXISTS = new ErrorCode(1011007001, "订单发货失败,所选发货商品不存在"); + ErrorCode ORDER_DELIVERY_FAILED_ITEM_ALREADY_DELIVERY = new ErrorCode(1011007001, "订单发货失败,所选商品已发货"); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDeliveryReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDeliveryReqVO.java index 97707f5f3..887dd1975 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDeliveryReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDeliveryReqVO.java @@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import javax.validation.constraints.NotNull; +import java.util.List; @Schema(description = "管理后台 - 订单发货 Request VO") @Data @@ -26,6 +27,12 @@ public class TradeOrderDeliveryReqVO { @Schema(description = "发货物流单号", example = "SF123456789") private String logisticsNo; + // TODO 订单项商品单独发货 + + @Schema(description = "发货订单项", example = "[1,2,3]") + @NotNull(message = "发货订单项不能为空") + private List orderItemIds; + // =============== 同城配送 ================ // TODO diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index c4e453fc8..da9269d8d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -18,6 +18,7 @@ import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO; import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO; import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO; +import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDetailRespVO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageItemRespVO; import cn.iocoder.yudao.module.trade.controller.app.base.property.AppProductPropertyValueDetailRespVO; @@ -26,6 +27,7 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderI import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDeliveryDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; @@ -334,4 +336,15 @@ public interface TradeOrderConvert { }) CombinationRecordReqDTO convert(TradeOrderDO order, TradeOrderItemDO orderItem, AppTradeOrderCreateReqVO createReqVO, MemberUserRespDTO user); + TradeOrderDeliveryDO covert(Long orderId, Long orderItemId, Long userId, Integer deliveryType, Long logisticsId, String logisticsNo); + + default List covert(TradeOrderDO order, TradeOrderDeliveryReqVO deliveryReqVO) { + ArrayList arrayList = new ArrayList<>(); + deliveryReqVO.getOrderItemIds().forEach(item -> { + arrayList.add(covert(order.getId(), item, order.getUserId(), deliveryReqVO.getType(), + deliveryReqVO.getLogisticsId(), deliveryReqVO.getLogisticsNo())); + }); + return arrayList; + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDeliveryDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDeliveryDO.java new file mode 100644 index 000000000..08e9a8402 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDeliveryDO.java @@ -0,0 +1,60 @@ +package cn.iocoder.yudao.module.trade.dal.dataobject.order; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; + + +/** + * 交易订单发货记录 DO + * + * @author HUIHUI + */ +@TableName("trade_order_delivery") +@KeySequence("trade_order_delivery_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class TradeOrderDeliveryDO extends BaseDO { + + /** + * 订单发货记录 id + */ + private Long id; + /** + * 订单 id + */ + private Long orderId; + /** + * 订单项 id TODO 要不要一个发货记录可对应多个订单项? + */ + private Long orderItemId; + /** + * 用户编号 + * + * 关联 MemberUserDO 的 id 编号 + */ + private Long userId; + /** + * 配送方式 + * + * 枚举 {@link DeliveryTypeEnum} + */ + private Integer deliveryType; + /** + * 发货物流公司编号 + */ + private Long logisticsId; + /** + * 发货物流单号 + */ + private String logisticsNo; + + // TODO 同城配送 + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderDeliveryMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderDeliveryMapper.java new file mode 100644 index 000000000..d80e5ab0a --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderDeliveryMapper.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.module.trade.dal.mysql.order; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDeliveryDO; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * 交易订单发货记录 Mapper + * + * @author HUIHUI + */ +@Mapper +public interface TradeOrderDeliveryMapper extends BaseMapperX { + + default List selsectListByOrderIdAndItemIds(Long orderId, List orderItemIds) { + return selectList(new LambdaQueryWrapperX() + .eq(TradeOrderDeliveryDO::getOrderId, orderId).in(TradeOrderDeliveryDO::getOrderItemId, orderItemIds)); + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java index de63ed22a..f7d9aa1b1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java @@ -38,7 +38,9 @@ import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDeliveryDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; +import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderDeliveryMapper; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper; import cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants; @@ -107,6 +109,8 @@ public class TradeOrderServiceImpl implements TradeOrderService { @Resource private CombinationApi combinationApi; + @Resource + private TradeOrderDeliveryMapper orderDeliveryMapper; // =================== Order =================== @Override @@ -243,7 +247,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { /** * 执行创建完创建完订单后的逻辑 - *

+ * * 例如说:优惠劵的扣减、积分的扣减、支付单的创建等等 * * @param userId 用户编号 @@ -256,7 +260,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { TradePriceCalculateRespBO calculateRespBO) { // 下单时扣减商品库存 productSkuApi.updateSkuStock(new ProductSkuUpdateStockReqDTO(TradeOrderConvert.INSTANCE.convertList(orderItems))); - + // TODO puhui:扣减活动库存 // 删除购物车商品 TODO 芋艿:待实现 // 扣减积分,抵扣金额 TODO 芋艿:待实现 @@ -267,7 +271,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { .setOrderId(tradeOrderDO.getId())); } - // 生成预支付 + // 生成预支付 TODO puhui: 活动支付金额怎么算? createPayOrder(tradeOrderDO, orderItems, calculateRespBO); // 增加订单日志 TODO 芋艿:待实现 @@ -313,7 +317,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { /** * 校验交易订单满足被支付的条件 - *

+ * * 1. 交易订单未支付 * 2. 支付单已支付 * @@ -367,29 +371,50 @@ public class TradeOrderServiceImpl implements TradeOrderService { return new KeyValue<>(order, payOrder); } - // TODO 芋艿:如果无需发货,需要怎么存储? fix:更改订单发货类型为无需发货更改发货类型为等待自提,等待用户自提后更改订单状态为已完成 @Override + @Transactional(rollbackFor = Exception.class) public void deliveryOrder(Long userId, TradeOrderDeliveryReqVO deliveryReqVO) { // 校验并获得交易订单(可发货) TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId()); - // TODO 判断发货类型,根据发货类型发货 - DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(deliveryReqVO.getLogisticsId()); - if (deliveryExpress == null) { - throw exception(EXPRESS_NOT_EXISTS); + + TradeOrderDO tradeOrderDO = new TradeOrderDO(); + List deliveryDOs = new ArrayList<>(); + /* TODO + * fix: 首先需要店铺设置配送方式如: 自提 、配送、物流-配送、物流-配送-自提、商家配送 + * 1.如果店铺有设置配送方式用户只填写收货地址的情况下店家后台自己选择配送方式 + * 2.如果店铺只支持到店自提那么下单后默认发货不需要物流 + * 3.如果店铺支持 物流-配送-自提 的情况下后台不需要选择配送方式按前端用户选择的配送方式发货即可 + */ + // 判断发货类型 + // 快递发货 + if (ObjectUtil.equal(deliveryReqVO.getType(), DeliveryTypeEnum.EXPRESS.getMode())) { + deliveryDOs = express(order, deliveryReqVO); + tradeOrderDO.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo()); + } + // 用户自提 + if (ObjectUtil.equal(deliveryReqVO.getType(), DeliveryTypeEnum.PICK_UP.getMode())) { + deliveryDOs = pickUp(order, deliveryReqVO); + // 重置一下确保快递公司和快递单号为空 + tradeOrderDO.setLogisticsId(null).setLogisticsNo(""); + } + // TODO 芋艿:如果无需发货,需要怎么存储? + if (ObjectUtil.equal(deliveryReqVO.getType(), DeliveryTypeEnum.NULL.getMode())) { + // TODO 情况一:正常走发货逻辑和用户自提有点像 不同点:不需要自提门店只需要用户确认收货 + // TODO 情况二:用户下单付款后直接确认收货或等待用户确认收货 } // 更新 TradeOrderDO 状态为已发货,等待收货 - int updateCount = tradeOrderMapper.updateByIdAndStatus(order.getId(), order.getStatus(), - new TradeOrderDO().setStatus(TradeOrderStatusEnum.DELIVERED.getStatus()) - .setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo()) - .setDeliveryStatus(TradeOrderDeliveryStatusEnum.DELIVERED.getStatus()).setDeliveryTime(LocalDateTime.now())); + tradeOrderDO.setStatus(TradeOrderStatusEnum.DELIVERED.getStatus()) + .setDeliveryStatus(TradeOrderDeliveryStatusEnum.DELIVERED.getStatus()).setDeliveryTime(LocalDateTime.now()); + int updateCount = tradeOrderMapper.updateByIdAndStatus(order.getId(), order.getStatus(), tradeOrderDO); if (updateCount == 0) { throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED); } - + // 发货成功记录发货表 + orderDeliveryMapper.insertBatch(deliveryDOs); // TODO 芋艿:发送订单变化的消息 - // TODO 芋艿:发送站内信 fix + // 发送站内信 // 1、构造消息 Map msgMap = new HashMap<>(); msgMap.put("orderId", deliveryReqVO.getId()); @@ -400,16 +425,59 @@ public class TradeOrderServiceImpl implements TradeOrderService { .setUserId(userId) .setTemplateCode("order_delivery") .setTemplateParams(msgMap)); - // TODO 芋艿:OrderLog - // TODO 设计:like:是否要单独一个 delivery 发货单表??? fix: 确实单独一张发货表就能解决整单发货和单独发货的问题 - // TODO 设计:niu:要不要支持一个订单下,多个 order item 单独发货,类似有赞 + // TODO 芋艿:OrderLog // TODO 设计:lili:是不是发货后,才支持售后? } + private List express(TradeOrderDO order, TradeOrderDeliveryReqVO deliveryReqVO) { + // 校验快递公司 + DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(deliveryReqVO.getLogisticsId()); + if (deliveryExpress == null) { + throw exception(EXPRESS_NOT_EXISTS); + } + // 校验发货商品 + validateDeliveryOrderItem(order, deliveryReqVO); + // 创建发货记录 + return TradeOrderConvert.INSTANCE.covert(order, deliveryReqVO); + } + + private List pickUp(TradeOrderDO order, TradeOrderDeliveryReqVO deliveryReqVO) { + // TODO 校验自提门店是否存在 + // 重置一下确保快递公司和快递单号为空 + deliveryReqVO.setLogisticsId(null); + deliveryReqVO.setLogisticsNo(""); + // 校验发货商品 + validateDeliveryOrderItem(order, deliveryReqVO); + // 创建发货记录 + return TradeOrderConvert.INSTANCE.covert(order, deliveryReqVO); + } + + private void validateDeliveryOrderItem(TradeOrderDO order, TradeOrderDeliveryReqVO deliveryReqVO) { + // TODO 设计:like:是否要单独一个 delivery 发货单表??? fix: 多商品可分开单独发货,添加 trade_order_delivery 交易订单发货日志表关联发货所选订单项设置物流单号 + // TODO 设计:niu:要不要支持一个订单下,多个 order item 单独发货,类似有赞 fix + // 校验发货商品 + if (CollUtil.isEmpty(deliveryReqVO.getOrderItemIds())) { + throw exception(ORDER_DELIVERY_FAILED_ITEMS_NOT_EMPTY); + } + // 校验发货商品是否存在 + List orderItemDOs = tradeOrderItemMapper.selectListByOrderId(order.getId()); + Set itemIds = convertSet(orderItemDOs, TradeOrderItemDO::getId); + if (!itemIds.containsAll(deliveryReqVO.getOrderItemIds())) { + throw exception(ORDER_DELIVERY_FAILED_ITEM_NOT_EXISTS); + } + // 校验所选订单项是否存在有已发货的 + List deliveryDOList = orderDeliveryMapper.selsectListByOrderIdAndItemIds(order.getId(), deliveryReqVO.getOrderItemIds()); + if (CollUtil.isNotEmpty(deliveryDOList)) { + HashSet hashSet = CollUtil.newHashSet(deliveryReqVO.getOrderItemIds()); + hashSet.retainAll(convertSet(deliveryDOList, TradeOrderDeliveryDO::getOrderItemId)); + throw exception(ORDER_DELIVERY_FAILED_ITEM_ALREADY_DELIVERY); + } + } + /** * 校验交易订单满足被发货的条件 - *

+ * * 1. 交易订单未发货 * * @param id 交易订单编号 @@ -432,7 +500,10 @@ public class TradeOrderServiceImpl implements TradeOrderService { } // 校验订单拼团是否成功 if (ObjectUtil.equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { - + // TODO 用户 ID 使用当前登录用户的还是订单保存的? + if (ObjectUtil.notEqual(combinationApi.getRecordStatus(order.getUserId(), order.getId()), CombinationRecordStatusEnum.SUCCESS.getStatus())) { + throw exception(ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS); + } } // TODO puhui999: 校验订单砍价是否成功 return order; @@ -466,7 +537,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { /** * 校验交易订单满足可售货的条件 - *

+ * * 1. 交易订单待收货 * * @param userId 用户编号 From 7957cfa50d3eeb4aca22acb6dd4d5fd4bb1ba235 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 24 Jul 2023 17:29:51 +0800 Subject: [PATCH 12/12] =?UTF-8?q?fix=EF=BC=9A=E4=BC=98=E5=8C=96=E6=8B=BC?= =?UTF-8?q?=E5=9B=A2=E4=B8=8E=E8=AE=A2=E5=8D=95=E9=9B=86=E6=88=90=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/combination/CombinationApi.java | 4 ++- .../api/combination/CombinationApiImpl.java | 4 +-- .../CombinationRecordDO.java | 5 ++- .../CombinationRecordMapper.java | 12 +++++++ .../CombinationActivityService.java | 3 +- .../CombinationActivityServiceImpl.java | 30 ++++++++++++++++-- .../service/order/TradeOrderServiceImpl.java | 31 ++++++++++++------- 7 files changed, 70 insertions(+), 19 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java index fc1ca72f9..486409320 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java @@ -24,7 +24,8 @@ public interface CombinationApi { * @param userId 用户编号 * @param orderId 订单编号 */ - Integer getRecordStatus(Long userId, Long orderId); + boolean validateRecordStatusIsSuccess(Long userId, Long orderId); + /** * 更新开团记录状态 @@ -41,6 +42,7 @@ public interface CombinationApi { * @param userId 用户编号 * @param orderId 订单编号 * @param status 状态值 + * @return */ void updateRecordStatusAndStartTime(Long userId, Long orderId, Integer status); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java index e2ca8698d..2386f9ed6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java @@ -23,8 +23,8 @@ public class CombinationApiImpl implements CombinationApi { } @Override - public Integer getRecordStatus(Long userId, Long orderId) { - return activityService.getRecordStatus(userId, orderId); + public boolean validateRecordStatusIsSuccess(Long userId, Long orderId) { + return activityService.validateRecordStatusIsSuccess(userId, orderId); } @Override diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationRecordDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationRecordDO.java index 7dd509ff5..842f4e9c9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationRecordDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/combinationactivity/CombinationRecordDO.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -72,7 +73,9 @@ public class CombinationRecordDO extends BaseDO { */ private String avatar; /** - * 开团状态: 正在开团 拼团成功 拼团失败 + * 开团状态 + * + * 关联 {@link CombinationRecordStatusEnum} */ private Integer status; /** diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationRecordMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationRecordMapper.java index a601e284e..e121ae9d1 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationRecordMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/combinationactivity/CombinationRecordMapper.java @@ -1,9 +1,12 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationRecordDO; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + /** * 拼团记录 Mapper * @@ -16,4 +19,13 @@ public interface CombinationRecordMapper extends BaseMapperX selectListByHeadIdAndStatus(Long headId, Integer status) { + return selectList(new LambdaQueryWrapperX().eq(CombinationRecordDO::getHeadId, headId) + .eq(CombinationRecordDO::getStatus, status)); + } + + default List selectListByStatus(Integer status) { + return selectList(new LambdaQueryWrapperX().eq(CombinationRecordDO::getStatus, status)); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java index 247ba95cf..0946d5956 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java @@ -99,6 +99,7 @@ public interface CombinationActivityService { * @param orderId 订单编号 * @param status 状态 * @param startTime 开始时间 + * @return */ void updateRecordStatusAndStartTimeByUserIdAndOrderId(Long userId, Long orderId, Integer status, LocalDateTime startTime); @@ -116,5 +117,5 @@ public interface CombinationActivityService { * @param orderId 订单编号 * @return 拼团状态 */ - Integer getRecordStatus(Long userId, Long orderId); + boolean validateRecordStatusIsSuccess(Long userId, Long orderId); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index f6e6aa3ed..68886dabb 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -24,7 +24,9 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationa import cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity.CombinationActivityMapper; import cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity.CombinationProductMapper; import cn.iocoder.yudao.module.promotion.dal.mysql.combination.combinationactivity.CombinationRecordMapper; +import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; @@ -217,14 +219,27 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic } @Override + @Transactional(rollbackFor = Exception.class) public void updateRecordStatusAndStartTimeByUserIdAndOrderId(Long userId, Long orderId, Integer status, LocalDateTime startTime) { CombinationRecordDO recordDO = validateCombinationRecord(userId, orderId); - // 更新状态 recordDO.setStatus(status); // 更新开始时间 recordDO.setStartTime(startTime); recordMapper.updateById(recordDO); + + // 更新拼团参入人数 + List recordDOs = recordMapper.selectListByHeadIdAndStatus(recordDO.getHeadId(), status); + if (CollUtil.isNotEmpty(recordDOs)) { + recordDOs.forEach(item -> { + item.setUserCount(recordDOs.size()); + // 校验拼团是否满足要求 + if (recordDOs.size() >= recordDO.getUserSize()) { + item.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus()); + } + }); + } + recordMapper.updateBatch(recordDOs); } private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) { @@ -249,9 +264,18 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic } @Override - public Integer getRecordStatus(Long userId, Long orderId) { + public boolean validateRecordStatusIsSuccess(Long userId, Long orderId) { CombinationRecordDO recordDO = validateCombinationRecord(userId, orderId); - return recordDO.getStatus(); + return ObjectUtil.equal(recordDO.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus()); + } + + /** + * APP 端获取开团记录 + * + * @return 开团记录 + */ + public List getRecordList() { + return recordMapper.selectListByStatus(CombinationRecordStatusEnum.ONGOING.getStatus()); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java index f7d9aa1b1..ee2feec1a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java @@ -164,13 +164,10 @@ public class TradeOrderServiceImpl implements TradeOrderService { @Override @Transactional(rollbackFor = Exception.class) public TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO) { - // 1. 用户收件地址的校验 - AddressRespDTO address = validateAddress(userId, createReqVO.getAddressId()); // 2. 价格计算 TradePriceCalculateRespBO calculateRespBO = calculatePrice(userId, createReqVO); - // 3.1 插入 TradeOrderDO 订单 - TradeOrderDO order = createTradeOrder(userId, userIp, createReqVO, calculateRespBO, address); + TradeOrderDO order = createTradeOrder(userId, userIp, createReqVO, calculateRespBO); // 3.2 插入 TradeOrderItemDO 订单项 List orderItems = createTradeOrderItems(order, calculateRespBO); // 订单创建完后的逻辑 @@ -183,6 +180,10 @@ public class TradeOrderServiceImpl implements TradeOrderService { combinationApi.createRecord(TradeOrderConvert.INSTANCE.convert(order, orderItems.get(0), createReqVO, user) .setStatus(CombinationRecordStatusEnum.NOT_PAY.getStatus())); } + // TODO 秒杀扣减库存是下单就扣除还是等待订单支付成功再扣除 + if (ObjectUtil.equal(TradeOrderTypeEnum.SECKILL.getType(), order.getType())) { + + } // TODO @LeeYan9: 是可以思考下, 订单的营销优惠记录, 应该记录在哪里, 微信讨论起来! return order; @@ -221,7 +222,13 @@ public class TradeOrderServiceImpl implements TradeOrderService { } private TradeOrderDO createTradeOrder(Long userId, String clientIp, AppTradeOrderCreateReqVO createReqVO, - TradePriceCalculateRespBO calculateRespBO, AddressRespDTO address) { + TradePriceCalculateRespBO calculateRespBO) { + // 用户选择物流配送的时候才需要填写收货地址 + AddressRespDTO address = new AddressRespDTO(); + if (ObjectUtil.equal(createReqVO.getDeliveryType(), DeliveryTypeEnum.EXPRESS.getMode())) { + // 用户收件地址的校验 + address = validateAddress(userId, createReqVO.getAddressId()); + } TradeOrderDO order = TradeOrderConvert.INSTANCE.convert(userId, clientIp, createReqVO, calculateRespBO, address); order.setType(validateActivity(createReqVO)); order.setNo(IdUtil.getSnowflakeNextId() + ""); // TODO @LeeYan9: 思考下, 怎么生成好点哈; 这个是会展示给用户的; @@ -232,7 +239,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { // 支付信息 order.setAdjustPrice(0).setPayStatus(false); // 物流信息 TODO 芋艿:暂时写死物流方式;应该是前端选择的 - order.setDeliveryType(DeliveryTypeEnum.EXPRESS.getMode()).setDeliveryStatus(TradeOrderDeliveryStatusEnum.UNDELIVERED.getStatus()); + order.setDeliveryType(createReqVO.getDeliveryType()).setDeliveryStatus(TradeOrderDeliveryStatusEnum.UNDELIVERED.getStatus()); // 退款信息 order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()).setRefundPrice(0); tradeOrderMapper.insert(order); @@ -260,7 +267,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { TradePriceCalculateRespBO calculateRespBO) { // 下单时扣减商品库存 productSkuApi.updateSkuStock(new ProductSkuUpdateStockReqDTO(TradeOrderConvert.INSTANCE.convertList(orderItems))); - // TODO puhui:扣减活动库存 + // 删除购物车商品 TODO 芋艿:待实现 // 扣减积分,抵扣金额 TODO 芋艿:待实现 @@ -271,7 +278,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { .setOrderId(tradeOrderDO.getId())); } - // 生成预支付 TODO puhui: 活动支付金额怎么算? + // 生成预支付 createPayOrder(tradeOrderDO, orderItems, calculateRespBO); // 增加订单日志 TODO 芋艿:待实现 @@ -289,6 +296,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { } @Override + @Transactional(rollbackFor = Exception.class) public void updateOrderPaid(Long id, Long payOrderId) { // 校验并获得交易订单(可支付) KeyValue orderResult = validateOrderPayable(id, payOrderId); @@ -305,7 +313,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { // 校验活动 // 1、拼团活动 if (ObjectUtil.equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { - // 更新拼团状态 TODO puhui999:订单支付失败或订单过期删除这条拼团记录 + // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 combinationApi.updateRecordStatusAndStartTime(order.getUserId(), order.getId(), CombinationRecordStatusEnum.ONGOING.getStatus()); } // TODO 芋艿:发送订单变化的消息 @@ -498,10 +506,11 @@ public class TradeOrderServiceImpl implements TradeOrderService { if (ObjectUtil.notEqual(TradeOrderRefundStatusEnum.NONE.getStatus(), order.getRefundStatus())) { throw exception(ORDER_DELIVERY_FAIL_REFUND_STATUS_NOT_NONE); } - // 校验订单拼团是否成功 + // 订单类型:拼团 if (ObjectUtil.equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { + // 校验订单拼团是否成功 // TODO 用户 ID 使用当前登录用户的还是订单保存的? - if (ObjectUtil.notEqual(combinationApi.getRecordStatus(order.getUserId(), order.getId()), CombinationRecordStatusEnum.SUCCESS.getStatus())) { + if (combinationApi.validateRecordStatusIsSuccess(order.getUserId(), order.getId())) { throw exception(ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS); } }