diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainRecordApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainRecordApi.java index 5639ab1d7..58add749a 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainRecordApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainRecordApi.java @@ -14,10 +14,19 @@ import javax.validation.Valid; public interface BargainRecordApi { /** - * 创建开团记录 + * 创建砍价记录 * * @param reqDTO 请求 DTO */ void createRecord(@Valid BargainRecordCreateReqDTO reqDTO); + /** + * 查询砍价是否成功 + * + * @param userId 用户编号 + * @param orderId 订单编号 + * @return 砍价是否成功 + */ + boolean validateRecordSuccess(Long userId, Long orderId); + } diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java index 2a83ed984..c9e683e8a 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java @@ -1,11 +1,14 @@ package cn.iocoder.yudao.module.promotion.api.combination; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO; import javax.validation.Valid; +import java.util.List; // TODO @芋艿:后面也再撸撸这几个接口 + /** * 拼团记录 API 接口 * @@ -18,7 +21,7 @@ public interface CombinationRecordApi { * * @param reqDTO 请求 DTO */ - void createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO); + void createRecord(@Valid CombinationRecordCreateReqDTO reqDTO); /** * 查询拼团记录是否成功 @@ -27,7 +30,26 @@ public interface CombinationRecordApi { * @param orderId 订单编号 * @return 拼团是否成功 */ - boolean isCombinationRecordSuccess(Long userId, Long orderId); + boolean validateRecordSuccess(Long userId, Long orderId); + + /** + * 获取拼团记录 + * + * @param userId 用户编号 + * @param activityId 活动编号 + * @return 拼团记录列表 + */ + List getRecordListByUserIdAndActivityId(Long userId, Long activityId); + + /** + * 验证组合限制数 + * 校验是否满足限购要求 + * + * @param count 本次购买数量 + * @param sumCount 已购买数量合计 + * @param activityId 活动编号 + */ + void validateCombinationLimitCount(Long activityId, Integer count, Integer sumCount); // TODO @puhui999:是不是搞成具体的方法,拼团成功,拼团失败,这种方法; diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordRespDTO.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordRespDTO.java new file mode 100644 index 000000000..486200d3f --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordRespDTO.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.module.promotion.api.combination.dto; + +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 拼团记录 Response DTO + * + * @author HUIHUI + */ +@Data +public class CombinationRecordRespDTO { + + /** + * 拼团活动编号 + */ + @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 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 e2f2bb98c..8770045e9 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 @@ -67,17 +67,18 @@ public interface ErrorCodeConstants { ErrorCode COMBINATION_RECORD_NOT_EXISTS = new ErrorCode(1013010004, "拼团不存在"); ErrorCode COMBINATION_RECORD_EXISTS = new ErrorCode(1013010005, "拼团失败,已参与过该拼团"); ErrorCode COMBINATION_RECORD_HEAD_NOT_EXISTS = new ErrorCode(1013010006, "拼团失败,父拼团不存在"); - ErrorCode COMBINATION_RECORD_USER_FULL = new ErrorCode(1013010006, "拼团失败,拼团人数已满"); + ErrorCode COMBINATION_RECORD_USER_FULL = new ErrorCode(1013010007, "拼团失败,拼团人数已满"); + ErrorCode COMBINATION_RECORD_FAILED_HAVE_JOINED = new ErrorCode(1013010008, "拼团失败,已参与其它拼团"); + ErrorCode COMBINATION_RECORD_FAILED_TIME_END = new ErrorCode(1013010009, "拼团失败,活动已经结束"); + ErrorCode COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED = new ErrorCode(1013010010, "拼团失败,单次限购超出"); + ErrorCode COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED = new ErrorCode(1013010011, "拼团失败,单次限购超出"); // ========== 砍价活动 1013011000 ========== ErrorCode BARGAIN_ACTIVITY_NOT_EXISTS = new ErrorCode(1013011000, "砍价活动不存在"); ErrorCode BARGAIN_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1013011001, "存在商品参加了其它砍价活动"); ErrorCode BARGAIN_ACTIVITY_STATUS_DISABLE = new ErrorCode(1013011002, "砍价活动已关闭不能修改"); ErrorCode BARGAIN_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013011003, "砍价活动未关闭或未结束,不能删除"); - - // TODO @puhui999:拆分成砍价记录 - - ErrorCode BARGAIN_RECORD_NOT_EXISTS = new ErrorCode(1013011004, "砍价不存在"); + ErrorCode BARGAIN_RECORD_NOT_EXISTS = new ErrorCode(1013011004, "砍价记录不存在"); ErrorCode BARGAIN_RECORD_EXISTS = new ErrorCode(1013011005, "砍价失败,已参与过该砍价"); ErrorCode BARGAIN_RECORD_HEAD_NOT_EXISTS = new ErrorCode(1013011006, "砍价失败,父砍价不存在"); ErrorCode BARGAIN_RECORD_USER_FULL = new ErrorCode(1013011007, "砍价失败,砍价人数已满"); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java index b21f7bee9..855c51074 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java @@ -1,12 +1,15 @@ package cn.iocoder.yudao.module.promotion.api.combination; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO; +import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.List; /** * 拼团活动 API 实现类 @@ -20,15 +23,25 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { private CombinationRecordService recordService; @Override - public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { + public void createRecord(CombinationRecordCreateReqDTO reqDTO) { recordService.createCombinationRecord(reqDTO); } @Override - public boolean isCombinationRecordSuccess(Long userId, Long orderId) { + public boolean validateRecordSuccess(Long userId, Long orderId) { return CombinationRecordStatusEnum.isSuccess(recordService.getCombinationRecord(userId, orderId).getStatus()); } + @Override + public List getRecordListByUserIdAndActivityId(Long userId, Long activityId) { + return CombinationActivityConvert.INSTANCE.convert(recordService.getRecordListByUserIdAndActivityId(userId, activityId)); + } + + @Override + public void validateCombinationLimitCount(Long activityId, Integer count, Integer sumCount) { + recordService.validateCombinationLimitCount(activityId, count, sumCount); + } + @Override public void updateCombinationRecordStatus(CombinationRecordUpdateStatusReqDTO reqDTO) { if (null == reqDTO.getStartTime()) { diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/BargainActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/BargainActivityController.java index 1e8e14f12..673d4dd09 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/BargainActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/BargainActivityController.java @@ -3,13 +3,11 @@ package cn.iocoder.yudao.module.promotion.controller.admin.bargain; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityPageReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityRespVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.convert.bargain.BargainActivityConvert; -import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; -import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainProductDO; import cn.iocoder.yudao.module.promotion.service.bargain.BargainActivityService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -20,12 +18,8 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; -import java.util.Set; -import static cn.hutool.core.collection.CollectionUtil.newArrayList; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @Tag(name = "管理后台 - 砍价活动") @RestController @@ -68,9 +62,7 @@ public class BargainActivityController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('promotion:bargain-activity:query')") public CommonResult getBargainActivity(@RequestParam("id") Long id) { - BargainActivityDO activity = activityService.getBargainActivity(id); - List products = activityService.getBargainProductsByActivityIds(newArrayList(id)); - return success(BargainActivityConvert.INSTANCE.convert(activity, products)); + return success(BargainActivityConvert.INSTANCE.convert(activityService.getBargainActivity(id))); } @GetMapping("/page") @@ -78,14 +70,7 @@ public class BargainActivityController { @PreAuthorize("@ss.hasPermission('promotion:bargain-activity:query')") public CommonResult> getBargainActivityPage( @Valid BargainActivityPageReqVO pageVO) { - // 查询砍价活动 - PageResult pageResult = activityService.getBargainActivityPage(pageVO); - // 拼接数据 - Set activityIds = convertSet(pageResult.getList(), BargainActivityDO::getId); - Set spuIds = convertSet(pageResult.getList(), BargainActivityDO::getSpuId); - return success(BargainActivityConvert.INSTANCE.convertPage(pageResult, - activityService.getBargainProductsByActivityIds(activityIds), - spuApi.getSpuList(spuIds))); + return success(BargainActivityConvert.INSTANCE.convertPage(activityService.getBargainActivityPage(pageVO))); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityBaseVO.java similarity index 77% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityBaseVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityBaseVO.java index 560c88bcf..ec969c2c3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityBaseVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityBaseVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity; +package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -26,6 +26,22 @@ public class BargainActivityBaseVO { @NotNull(message = "砍价商品不能为空") private Long spuId; + @Schema(description = "商品 skuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") + @NotNull(message = "商品 skuId 不能为空") + private Long skuId; + + @Schema(description = "砍价起始价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") + @NotNull(message = "砍价起始价格不能为空") + private Integer bargainFirstPrice; + + @Schema(description = "砍价底价", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") + @NotNull(message = "砍价底价不能为空") + private Integer bargainPrice; + + @Schema(description = "活动库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") + @NotNull(message = "活动库存不能为空") + private Integer stock; + @Schema(description = "总限购数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "16218") @NotNull(message = "总限购数量不能为空") private Integer totalLimitCount; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityCreateReqVO.java similarity index 64% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductUpdateReqVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityCreateReqVO.java index 986a4c8f8..f49b489ea 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductUpdateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityCreateReqVO.java @@ -1,14 +1,14 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product; +package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo; 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 BargainProductUpdateReqVO extends BargainProductBaseVO { +public class BargainActivityCreateReqVO extends BargainActivityBaseVO { } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityPageReqVO.java new file mode 100644 index 000000000..9412c6292 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityPageReqVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.bargain.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; + +@Schema(description = "管理后台 - 砍价活动分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class BargainActivityPageReqVO extends PageParam { + + @Schema(description = "砍价名称", example = "赵六") + private String name; + + @Schema(description = "活动状态:0开启 1关闭", 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/bargain/vo/activity/BargainActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityRespVO.java similarity index 75% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityRespVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityRespVO.java index 064e4e8ac..2e5b6a008 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityRespVO.java @@ -1,24 +1,18 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity; +package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductRespVO; 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 @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class BargainActivityRespVO extends BargainActivityBaseVO { - // TODO @puhui999:example 补全 - @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") private String spuName; @@ -28,18 +22,14 @@ public class BargainActivityRespVO extends BargainActivityBaseVO { @Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901") private Long id; - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2022-07-01 23:59:59") private LocalDateTime createTime; - @Schema(description = "砍价成功数量", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "砍价成功数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "999") private Integer successCount; @Schema(description = "活动状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") @NotNull(message = "活动状态不能为空") 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/bargain/vo/activity/BargainActivityUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityUpdateReqVO.java similarity index 66% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityUpdateReqVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityUpdateReqVO.java index 242288c30..849616af5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityUpdateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityUpdateReqVO.java @@ -1,14 +1,11 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity; +package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductUpdateReqVO; 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 @@ -20,8 +17,4 @@ public class BargainActivityUpdateReqVO extends BargainActivityBaseVO { @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/bargain/vo/activity/BargainActivityCreateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityCreateReqVO.java deleted file mode 100644 index 38e6fb403..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityCreateReqVO.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity; - -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductCreateReqVO; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.Valid; -import java.util.List; - -@Schema(description = "管理后台 - 砍价活动创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class BargainActivityCreateReqVO extends BargainActivityBaseVO { - - @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/bargain/vo/activity/BargainActivityPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityPageReqVO.java deleted file mode 100644 index 1845a929e..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityPageReqVO.java +++ /dev/null @@ -1,65 +0,0 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity; - -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 BargainActivityPageReqVO 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/bargain/vo/product/BargainProductBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductBaseVO.java deleted file mode 100644 index 2c5ca7ef8..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductBaseVO.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.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 BargainProductBaseVO { - - @Schema(description = "商品 spuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "123") - @NotNull(message = "商品 spuId 不能为空") - private Long spuId; - - @Schema(description = "商品 skuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") - @NotNull(message = "商品 skuId 不能为空") - private Long skuId; - - @Schema(description = "砍价起始价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") - @NotNull(message = "砍价起始价格不能为空") - private Integer bargainFirstPrice; - - @Schema(description = "砍价底价", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") - @NotNull(message = "砍价底价不能为空") - private Integer bargainPrice; - - @Schema(description = "活动库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") - @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/bargain/vo/product/BargainProductCreateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductCreateReqVO.java deleted file mode 100644 index 9b14b1765..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductCreateReqVO.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -// TODO @puhui999:是不是应该把 BargainProductCreateReqVO 和 BargainProductUpdateReqVO 合并在一起哈。就是一个 SaveReqVO -@Schema(description = "管理后台 - 砍价商品创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class BargainProductCreateReqVO extends BargainProductBaseVO { - -} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductRespVO.java deleted file mode 100644 index d0baec008..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductRespVO.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product; - -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 BargainProductRespVO extends BargainProductBaseVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28322") - 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/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 bcd06fdc8..bbef1ab58 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 @@ -5,11 +5,6 @@ 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 @@ -20,46 +15,8 @@ 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/convert/bargain/BargainActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java index ebd1f303a..290f2ab4e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java @@ -1,26 +1,14 @@ package cn.iocoder.yudao.module.promotion.convert.bargain; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.framework.common.util.collection.MapUtils; -import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityRespVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityUpdateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductBaseVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductRespVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; -import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainProductDO; import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; import java.util.List; -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; /** * 拼团活动 Convert @@ -38,57 +26,8 @@ public interface BargainActivityConvert { BargainActivityRespVO convert(BargainActivityDO bean); - BargainProductRespVO convert(BargainProductDO bean); - - default BargainActivityRespVO convert(BargainActivityDO bean, List productDOs) { - return convert(bean).setProducts(convertList2(productDOs)); - } - List convertList(List list); PageResult convertPage(PageResult page); - default PageResult convertPage(PageResult page, - List productList, - List spuList) { - Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); - PageResult pageResult = convertPage(page); - pageResult.getList().forEach(item -> { - MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> { - item.setSpuName(spu.getName()); - item.setPicUrl(spu.getPicUrl()); - }); - item.setProducts(convertList2(productList)); - }); - return pageResult; - } - - List convertList2(List productDOs); - - // TODO @puhui999:参数改成 activity、product 会不会干净一点哈 - @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 = "bargainFirstPrice", source = "vo.bargainFirstPrice"), - @Mapping(target = "bargainPrice", source = "vo.bargainPrice"), - @Mapping(target = "stock", source = "vo.stock"), - @Mapping(target = "activityStartTime", source = "activityDO.startTime"), - @Mapping(target = "activityEndTime", source = "activityDO.endTime") - }) - BargainProductDO convert(BargainActivityDO activityDO, BargainProductBaseVO vo); - - default List convertList(List products, BargainActivityDO activityDO) { - return CollectionUtils.convertList(products, item -> convert(activityDO, item).setActivityStatus(activityDO.getStatus())); - } - - default List convertList(List updateProductVOs, - List products, BargainActivityDO activity) { - Map productMap = convertMap(products, BargainProductDO::getSkuId, BargainProductDO::getId); - return CollectionUtils.convertList(updateProductVOs, updateProductVO -> convert(activity, updateProductVO) - .setId(productMap.get(updateProductVO.getSkuId())) - .setActivityStatus(activity.getStatus())); - } - } 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 436067ed8..6e73510e9 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 @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; @@ -93,4 +94,6 @@ public interface CombinationActivityConvert { CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO); + List convert(List bean); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainActivityDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainActivityDO.java index 034973269..d912542c1 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainActivityDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainActivityDO.java @@ -53,7 +53,18 @@ public class BargainActivityDO extends BaseDO { * 商品 SPU 编号 */ private Long spuId; - + /** + * 商品 SKU 编号 + */ + private Long skuId; + /** + * 砍价起始价格,单位分 + */ + private Integer bargainFirstPrice; + /** + * 砍价底价,单位:分 + */ + private Integer bargainPrice; /** * 达到该人数,才能砍到低价 */ @@ -70,7 +81,7 @@ public class BargainActivityDO extends BaseDO { private Integer totalLimitCount; /** - * 砍价库存 + * 砍价活动库存 */ private Integer stock; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainProductDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainProductDO.java deleted file mode 100644 index 8f47ce1da..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainProductDO.java +++ /dev/null @@ -1,70 +0,0 @@ -package cn.iocoder.yudao.module.promotion.dal.dataobject.bargain; - -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_bargain_product") -@KeySequence("promotion_bargain_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class BargainProductDO extends BaseDO { - - /** - * 编号 - */ - @TableId - private Long id; - /** - * 砍价活动编号 - */ - private Long activityId; - /** - * 商品 SPU 编号 - */ - private Long spuId; - /** - * 商品 SKU 编号 - */ - private Long skuId; - /** - * 砍价商品状态 - * - * 关联 {@link BargainActivityDO#getStatus()} - */ - private Integer activityStatus; - /** - * 活动开始时间点 - */ - private LocalDateTime activityStartTime; - /** - * 活动结束时间点 - */ - private LocalDateTime activityEndTime; - /** - * 砍价起始价格,单位分 - */ - private Integer bargainFirstPrice; - /** - * 砍价底价,单位:分 - */ - private Integer bargainPrice; - /** - * 活动库存 - */ - private Integer stock; - -} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java index af150ef3e..836127ab9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.bargain; 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.bargain.vo.activity.BargainActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityPageReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; import org.apache.ibatis.annotations.Mapper; @@ -20,6 +20,7 @@ public interface BargainActivityMapper extends BaseMapperX { default PageResult selectPage(BargainActivityPageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() .likeIfPresent(BargainActivityDO::getName, reqVO.getName()) + .eqIfPresent(BargainActivityDO::getStatus, reqVO.getStatus()) .orderByDesc(BargainActivityDO::getId)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainProductMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainProductMapper.java deleted file mode 100644 index f35999e8e..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainProductMapper.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.promotion.dal.mysql.bargain; - -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainProductDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.Collection; -import java.util.List; - -/** - * 砍价商品 Mapper - * - * @author HUIHUI - */ -@Mapper -public interface BargainProductMapper extends BaseMapperX { - - default List selectListByActivityIds(Collection ids) { - return selectList(BargainProductDO::getActivityId, ids); - } - -} 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 index a04018772..c2868d191 100644 --- 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 @@ -20,6 +20,7 @@ public interface CombinationActivityMapper extends BaseMapperX selectPage(CombinationActivityPageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() .likeIfPresent(CombinationActivityDO::getName, reqVO.getName()) + .eqIfPresent(CombinationActivityDO::getStatus, reqVO.getStatus()) .orderByDesc(CombinationActivityDO::getId)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java index 8c05b3024..218a24897 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java @@ -20,18 +20,20 @@ public interface CombinationRecordMapper extends BaseMapperX selectListByUserIdAndStatus(Long userId, Integer status) { + return selectList(new LambdaQueryWrapperX() + .eq(CombinationRecordDO::getUserId, userId) + .eq(CombinationRecordDO::getStatus, status)); + } /** * 查询拼团记录 * - * @param headId 团长编号 - * @param activityId 活动编号 + * @param headId 团长编号 * @return 拼团记录 */ - default CombinationRecordDO selectRecordByHeadId(Long headId, Long activityId, Integer status) { + default CombinationRecordDO selectOneByHeadId(Long headId, Integer status) { return selectOne(new LambdaQueryWrapperX() - .eq(CombinationRecordDO::getUserId, headId) - .eq(CombinationRecordDO::getActivityId, activityId) + .eq(CombinationRecordDO::getId, headId) .eq(CombinationRecordDO::getStatus, status)); } @@ -45,4 +47,16 @@ public interface CombinationRecordMapper extends BaseMapperX selectListByUserIdAndActivityId(Long userId, Long activityId) { + return selectList(new LambdaQueryWrapperX() + .eq(CombinationRecordDO::getUserId, userId) + .eq(CombinationRecordDO::getActivityId, activityId)); + } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java index a7b1b0dbd..1c49155a8 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java @@ -1,15 +1,12 @@ package cn.iocoder.yudao.module.promotion.service.bargain; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityPageReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; -import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainProductDO; import javax.validation.Valid; -import java.util.Collection; -import java.util.List; /** * 砍价活动 Service 接口 @@ -56,12 +53,5 @@ public interface BargainActivityService { */ PageResult getBargainActivityPage(BargainActivityPageReqVO pageReqVO); - /** - * 获得砍价活动商品列表 - * - * @param ids 砍价活动 ids - * @return 砍价活动的商品列表 - */ - List getBargainProductsByActivityIds(Collection ids); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainServiceImpl.java index 1a314ebab..96d9d32b1 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainServiceImpl.java @@ -10,31 +10,25 @@ 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.bargain.vo.activity.BargainActivityCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityPageReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityUpdateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.convert.bargain.BargainActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; -import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainProductDO; import cn.iocoder.yudao.module.promotion.dal.mysql.bargain.BargainActivityMapper; -import cn.iocoder.yudao.module.promotion.dal.mysql.bargain.BargainProductMapper; import cn.iocoder.yudao.module.promotion.dal.mysql.bargain.BargainRecordMapper; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; 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.framework.common.util.collection.CollectionUtils.anyMatch; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; +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.validateProductSkuAllExists; /** * 砍价活动 Service 实现类 @@ -50,38 +44,37 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord @Resource private BargainRecordMapper recordMapper; @Resource - private BargainProductMapper bargainProductMapper; - @Resource private ProductSpuApi productSpuApi; @Resource private ProductSkuApi productSkuApi; + private static void validateSku(Long skuId, List skus) { + // 校验商品 sku 是否存在 + if (!CollectionUtils.convertSet(skus, ProductSkuRespDTO::getId).contains(skuId)) { + throw exception(SKU_NOT_EXISTS); + } + } + @Override @Transactional(rollbackFor = Exception.class) public Long createBargainActivity(BargainActivityCreateReqVO createReqVO) { // 校验商品 SPU 是否存在是否参加的别的活动 - validateProductBargainConflict(createReqVO.getSpuId(), null); + validateBargainConflict(createReqVO.getSpuId(), null); // 获取所选 spu下的所有 sku List skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(createReqVO.getSpuId())); - // 校验商品 sku 是否存在 - validateProductSkuAllExists(skus, createReqVO.getProducts(), BargainProductCreateReqVO::getSkuId); + validateSku(createReqVO.getSkuId(), skus); // 插入砍价活动 BargainActivityDO activityDO = BargainActivityConvert.INSTANCE.convert(createReqVO); // TODO 营销相关属性初始化 砍价成功更新相关属性 activityDO.setSuccessCount(0); - // 活动总库存 - activityDO.setStock(getSumValue(createReqVO.getProducts(), BargainProductCreateReqVO::getStock, Integer::sum)); activityDO.setStatus(CommonStatusEnum.ENABLE.getStatus()); bargainActivityMapper.insert(activityDO); - // 插入商品 - List productDOs = BargainActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), activityDO); - bargainProductMapper.insertBatch(productDOs); // 返回 return activityDO.getId(); } - private void validateProductBargainConflict(Long spuId, Long activityId) { + private void validateBargainConflict(Long spuId, Long activityId) { // 校验商品 spu 是否存在 List spuList = productSpuApi.getSpuList(CollUtil.newArrayList(spuId)); if (CollUtil.isEmpty(spuList)) { @@ -109,52 +102,16 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord throw exception(BARGAIN_ACTIVITY_STATUS_DISABLE); } // 校验商品冲突 - validateProductBargainConflict(updateReqVO.getSpuId(), updateReqVO.getId()); + validateBargainConflict(updateReqVO.getSpuId(), updateReqVO.getId()); // 获取所选 spu下的所有 sku List skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(updateReqVO.getSpuId())); // 校验商品 sku 是否存在 - validateProductSkuAllExists(skus, updateReqVO.getProducts(), BargainProductUpdateReqVO::getSkuId); + validateSku(updateReqVO.getSkuId(), skus); // 更新 BargainActivityDO updateObj = BargainActivityConvert.INSTANCE.convert(updateReqVO); - // 更新活动库存 - updateObj.setStock(getSumValue(updateReqVO.getProducts(), BargainProductUpdateReqVO::getStock, Integer::sum)); bargainActivityMapper.updateById(updateObj); - // 更新商品 - updateBargainProduct(updateObj, updateReqVO.getProducts()); - } - /** - * 更新砍价商品 - * - * @param updateObj 更新的活动 - * @param products 商品配置 - */ - private void updateBargainProduct(BargainActivityDO updateObj, List products) { - // 默认全部新增 - List defaultNewList = BargainActivityConvert.INSTANCE.convertList(products, updateObj); - // 数据库中的老数据 - List oldList = bargainProductMapper.selectListByActivityIds(CollUtil.newArrayList(updateObj.getId())); - List> lists = CollectionUtils.diffList(oldList, defaultNewList, (oldVal, newVal) -> { - boolean same = ObjectUtil.equal(oldVal.getSkuId(), newVal.getSkuId()); - if (same) { - newVal.setId(oldVal.getId()); - } - return same; - }); - - // create - if (CollUtil.isNotEmpty(lists.get(0))) { - bargainProductMapper.insertBatch(lists.get(0)); - } - // update - if (CollUtil.isNotEmpty(lists.get(1))) { - bargainProductMapper.updateBatch(lists.get(1)); - } - // delete - if (CollUtil.isNotEmpty(lists.get(2))) { - bargainProductMapper.deleteBatchIds(CollectionUtils.convertList(lists.get(2), BargainProductDO::getId)); - } } @Override @@ -189,9 +146,4 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord return bargainActivityMapper.selectPage(pageReqVO); } - @Override - public List getBargainProductsByActivityIds(Collection ids) { - return bargainProductMapper.selectListByActivityIds(ids); - } - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java index 93473893c..72d68c780 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java @@ -4,6 +4,8 @@ import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCr import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; +import java.util.List; + /** * 商品活动记录 service * @@ -41,4 +43,23 @@ public interface CombinationRecordService { */ CombinationRecordDO getCombinationRecord(Long userId, Long orderId); + /** + * 获取拼团记录 + * + * @param userId 用户 id + * @param activityId 活动 id + * @return 拼团记录列表 + */ + List getRecordListByUserIdAndActivityId(Long userId, Long activityId); + + /** + * 验证组合限制数 + * 校验是否满足限购要求 + * + * @param count 本次购买数量 + * @param sumCount 已购买数量合计 + * @param activityId 活动编号 + */ + void validateCombinationLimitCount(Long activityId, Integer count, Integer sumCount); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationServiceImpl.java index e8efcc2b0..1b6ffd69f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationServiceImpl.java @@ -30,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.time.LocalDateTime; import java.util.Collection; import java.util.List; @@ -68,8 +69,6 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi // 校验商品 sku 是否存在 validateProductSkuAllExists(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 营销相关属性初始化 拼团成功更新相关属性 @@ -132,7 +131,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi * 更新拼团商品 * * @param activity 拼团活动 - * @param products 该活动的最新商品配置 + * @param products 该活动的最新商品配置 */ private void updateCombinationProduct(CombinationActivityDO activity, List products) { // 第一步,对比新老数据,获得添加、修改、删除的列表 @@ -201,6 +200,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi } @Override + @Transactional(rollbackFor = Exception.class) public void updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordUpdateStatusReqDTO reqDTO) { // 校验拼团是否存在 CombinationRecordDO recordDO = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getOrderId()); @@ -244,6 +244,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi } @Override + @Transactional(rollbackFor = Exception.class) public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { // 1.1 校验拼团活动 CombinationActivityDO activity = validateCombinationActivityExists(reqDTO.getActivityId()); @@ -252,9 +253,19 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi if (recordDO != null) { throw exception(COMBINATION_RECORD_EXISTS); } - // 1.3 父拼团是否存在,是否已经满了 + // 1.3 校验用户是否参加了其它拼团 + List recordDOList = recordMapper.selectListByUserIdAndStatus(reqDTO.getUserId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); + if (CollUtil.isNotEmpty(recordDOList)) { + throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED); + } + // 1.4 校验当前活动是否过期 + if (LocalDateTime.now().isAfter(activity.getEndTime())) { + throw exception(COMBINATION_RECORD_FAILED_TIME_END); + } + // 1.5 父拼团是否存在,是否已经满了 if (reqDTO.getHeadId() != null) { - CombinationRecordDO recordDO1 = recordMapper.selectRecordByHeadId(reqDTO.getHeadId(), reqDTO.getActivityId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); + // 查询进行中的父拼团 + CombinationRecordDO recordDO1 = recordMapper.selectOneByHeadId(reqDTO.getHeadId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); if (recordDO1 == null) { throw exception(COMBINATION_RECORD_HEAD_NOT_EXISTS); } @@ -263,7 +274,6 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi throw exception(COMBINATION_RECORD_USER_FULL); } } - // TODO @puhui999:应该还有一些校验,后续补噶;例如说,一个团,自己已经参与进去了,不能再参与进去; // 2. 创建拼团记录 CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO); @@ -288,4 +298,22 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi return recordMapper.selectListByStatus(status); } + public List getRecordListByUserIdAndActivityId(Long userId, Long activityId) { + return recordMapper.selectListByUserIdAndActivityId(userId, activityId); + } + + @Override + public void validateCombinationLimitCount(Long activityId, Integer count, Integer sumCount) { + // 1.1 校验拼团活动 + CombinationActivityDO activity = validateCombinationActivityExists(activityId); + // 校验是否达到限购总限购标准 + if ((sumCount + count) > activity.getTotalLimitCount()) { + throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED); + } + // 单次购买是否达到限购标准 + if (count > activity.getSingleLimitCount()) { + throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED); + } + } + } 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 537cb1e27..4ba3b26a5 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 @@ -62,7 +62,6 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { seckillConfigMapper.updateById(updateObj); } - // TODO @puhui999: 这个要不合并到更新操作里? 不单独有个操作咧; fix: 更新状态不用那么多必须的参数,更新的时候需要校验时间段 @Override public void updateSeckillConfigStatus(Long id, Integer status) { // 校验秒杀时段是否存在 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 2bf583144..81ce84dd4 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 @@ -13,7 +13,6 @@ import org.springframework.context.annotation.Import; import javax.annotation.Resource; -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; @@ -152,19 +151,7 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { // 准备参数 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); 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 7a3e0292b..1be549a0a 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 @@ -31,10 +31,7 @@ public interface ErrorCodeConstants { 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, "交易订单发货失败,拼团未成功"); - // TODO 已移除订单单独发货 - ErrorCode ORDER_DELIVERY_FAILED_ITEMS_NOT_EMPTY = new ErrorCode(1011000023, "订单发货失败,请选择发货商品"); - ErrorCode ORDER_DELIVERY_FAILED_ITEM_NOT_EXISTS = new ErrorCode(1011000024, "订单发货失败,所选发货商品不存在"); - ErrorCode ORDER_DELIVERY_FAILED_ITEM_ALREADY_DELIVERY = new ErrorCode(1011000025, "订单发货失败,所选商品已发货"); + ErrorCode ORDER_DELIVERY_FAIL_BARGAIN_RECORD_STATUS_NOT_SUCCESS = new ErrorCode(1011000023, "交易订单发货失败,砍价未成功"); // ========== 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 67b130ca0..c80bf133a 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 @@ -29,7 +29,5 @@ public class TradeOrderDeliveryReqVO { @NotEmpty(message = "发货物流单号不能为空") 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/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index 765ed58c4..c20742a67 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 @@ -126,8 +126,7 @@ public class AppTradeOrderController { @Operation(summary = "确认交易订单收货") @Parameter(name = "id", description = "交易订单编号") public CommonResult takeOrder(@RequestParam("id") Long id) { - // TODO @芋艿:未实现,mock 用 - return success(true); + return success(tradeOrderService.receiveOrder(getLoginUserId(), id)); } @DeleteMapping("/cancel") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderItemMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderItemMapper.java index 62cccf0f7..553bd5697 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderItemMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderItemMapper.java @@ -25,6 +25,12 @@ public interface TradeOrderItemMapper extends BaseMapperX { return selectList(TradeOrderItemDO::getOrderId, orderIds); } + default List selectListByOrderIdAnSkuId(Collection orderIds, Collection skuIds) { + return selectList(new LambdaQueryWrapperX() + .in(TradeOrderItemDO::getOrderId, orderIds) + .eq(TradeOrderItemDO::getSkuId, skuIds)); + } + default TradeOrderItemDO selectOrderItemByIdAndUserId(Long orderItemId, Long loginUserId) { return selectOne(new LambdaQueryWrapperX() .eq(TradeOrderItemDO::getId, orderItemId) 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 bb234ab85..642c8f464 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 @@ -65,9 +65,10 @@ public interface TradeOrderService { * 【会员】收货交易订单 * * @param userId 用户编号 - * @param id 订单编号 + * @param id 订单编号 + * @return 成功/失败 */ - void receiveOrder(Long userId, Long id); + Boolean receiveOrder(Long userId, Long id); /** * 获得指定编号的交易订单 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 64e90eb52..0a37021fd 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 @@ -9,6 +9,7 @@ import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.TerminalEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; @@ -22,7 +23,9 @@ 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.bargain.BargainRecordApi; import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO; import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO; @@ -108,6 +111,9 @@ public class TradeOrderServiceImpl implements TradeOrderService { @Resource private CombinationRecordApi combinationRecordApi; + @Resource + private BargainRecordApi bargainRecordApi; + // =================== Order =================== @Override @@ -173,8 +179,18 @@ public class TradeOrderServiceImpl implements TradeOrderService { // 拼团 if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { MemberUserRespDTO user = memberUserApi.getUser(userId); + List recordRespDTOS = combinationRecordApi.getRecordListByUserIdAndActivityId(userId, createReqVO.getCombinationActivityId()); // TODO 拼团一次应该只能选择一种规格的商品 - combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, orderItems.get(0), createReqVO, user)); + TradeOrderItemDO orderItemDO = orderItems.get(0); + if (CollUtil.isNotEmpty(recordRespDTOS)) { + List skuIds = convertList(recordRespDTOS, CombinationRecordRespDTO::getSkuId, item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())); + List tradeOrderItemDOS = tradeOrderItemMapper.selectListByOrderIdAnSkuId(convertList(recordRespDTOS, + CombinationRecordRespDTO::getOrderId, item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())), skuIds); + combinationRecordApi.validateCombinationLimitCount(createReqVO.getCombinationActivityId(), + CollectionUtils.getSumValue(tradeOrderItemDOS, TradeOrderItemDO::getCount, Integer::sum), orderItemDO.getCount()); + } + + combinationRecordApi.createRecord(TradeOrderConvert.INSTANCE.convert(order, orderItemDO, createReqVO, user)); } // TODO 秒杀扣减库存是下单就扣除还是等待订单支付成功再扣除 if (Objects.equals(TradeOrderTypeEnum.SECKILL.getType(), order.getType())) { @@ -382,33 +398,23 @@ public class TradeOrderServiceImpl implements TradeOrderService { public void deliveryOrder(Long userId, TradeOrderDeliveryReqVO deliveryReqVO) { // 1.1 校验并获得交易订单(可发货) TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId()); - - /* TODO - * fix: 首先需要店铺设置配送方式如: 自提 、配送、物流-配送、物流-配送-自提、商家配送 - * 1.如果店铺有设置配送方式用户只填写收货地址的情况下店家后台自己选择配送方式 - * 2.如果店铺只支持到店自提那么下单后默认发货不需要物流 - * 3.如果店铺支持 物流-配送-自提 的情况下后台不需要选择配送方式按前端用户选择的配送方式发货即可 - */ TradeOrderDO updateOrderObj = new TradeOrderDO(); // 判断发货类型 // 2.1 快递发货 if (Objects.equals(deliveryReqVO.getType(), DeliveryTypeEnum.EXPRESS.getMode())) { // 校验快递公司 - validateDeliveryExpress(deliveryReqVO); - updateOrderObj.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo()); + DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(deliveryReqVO.getLogisticsId()); + if (deliveryExpress == null) { + throw exception(EXPRESS_NOT_EXISTS); + } + if (deliveryExpress.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())) { + throw exception(EXPRESS_STATUS_NOT_ENABLE); + } + updateOrderObj.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo()).setDeliveryType(DeliveryTypeEnum.EXPRESS.getMode()); } - // 2.2 用户自提 - if (Objects.equals(deliveryReqVO.getType(), DeliveryTypeEnum.PICK_UP.getMode())) { - // TODO 校验自提门店是否存在 - // 重置一下确保快递公司和快递单号为空 - updateOrderObj.setLogisticsId(null).setLogisticsNo(""); - } - // 2.3 TODO 芋艿:如果无需发货,需要怎么存储?回复:需要把 deliverType 设置为 DeliveryTypeEnum.NULL + // 2.2 无需发货 if (Objects.equals(deliveryReqVO.getType(), DeliveryTypeEnum.NULL.getMode())) { - // TODO 情况一:正常走发货逻辑和用户自提有点像 不同点:不需要自提门店只需要用户确认收货 - // TODO 情况二:用户下单付款后直接确认收货或等待用户确认收货 - // 重置一下确保快递公司和快递单号为空 - updateOrderObj.setLogisticsId(null).setLogisticsNo(""); + updateOrderObj.setLogisticsId(null).setLogisticsNo("").setDeliveryType(DeliveryTypeEnum.NULL.getMode()); } // 更新 TradeOrderDO 状态为已发货,等待收货 @@ -428,16 +434,6 @@ public class TradeOrderServiceImpl implements TradeOrderService { // TODO 设计:lili:是不是发货后,才支持售后? } - private void validateDeliveryExpress(TradeOrderDeliveryReqVO deliveryReqVO) { - DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(deliveryReqVO.getLogisticsId()); - if (deliveryExpress == null) { - throw exception(EXPRESS_NOT_EXISTS); - } - if (deliveryExpress.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())) { - throw exception(EXPRESS_STATUS_NOT_ENABLE); - } - } - /** * 校验交易订单满足被发货的条件 * @@ -464,17 +460,23 @@ public class TradeOrderServiceImpl implements TradeOrderService { // 订单类型:拼团 if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { // 校验订单拼团是否成功 - if (combinationRecordApi.isCombinationRecordSuccess(order.getUserId(), order.getId())) { + if (combinationRecordApi.validateRecordSuccess(order.getUserId(), order.getId())) { throw exception(ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS); } } - // TODO puhui999: 校验订单砍价是否成功 + // 订单类类型:砍价 + if (Objects.equals(TradeOrderTypeEnum.BARGAIN.getType(), order.getType())) { + // 校验订单砍价是否成功 + if (bargainRecordApi.validateRecordSuccess(order.getUserId(), order.getId())) { + throw exception(ORDER_DELIVERY_FAIL_BARGAIN_RECORD_STATUS_NOT_SUCCESS); + } + } return order; } @Override @Transactional(rollbackFor = Exception.class) - public void receiveOrder(Long userId, Long id) { + public Boolean receiveOrder(Long userId, Long id) { // 校验并获得交易订单(可收货) TradeOrderDO order = validateOrderReceivable(userId, id); @@ -490,6 +492,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { // TODO 芋艿:lili 发送订单变化的消息 // TODO 芋艿:lili 发送商品被购买完成的数据 + return Boolean.TRUE; } @Override