From ce77d510bb7cc5a375960fa3615de9d7f89f779e Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 6 Oct 2023 20:27:22 +0800 Subject: [PATCH 01/19] =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=EF=BC=9A=E6=B7=BB=E5=8A=A0=E6=8B=BC=E5=9B=A2=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CombinationRecordController.java | 87 +++++++++++++++++++ .../vo/recrod/CombinationRecordReqPageVO.java | 38 ++++++++ .../vo/recrod/CombinationRecordRespVO.java | 60 +++++++++++++ .../CombinationActivityConvert.java | 3 + .../combination/CombinationRecordMapper.java | 61 +++++++++++++ .../combination/CombinationRecordService.java | 32 +++++++ .../CombinationRecordServiceImpl.java | 22 +++++ 7 files changed, 303 insertions(+) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java new file mode 100644 index 000000000..de24a7631 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java @@ -0,0 +1,87 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination; + +import cn.hutool.core.map.MapUtil; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordRespVO; +import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; +import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import io.swagger.v3.oas.annotations.Operation; +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.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.validation.Valid; +import java.time.Duration; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache; + +@Tag(name = "管理后台 - 拼团记录") +@RestController +@RequestMapping("/promotion/combination-record") +@Validated +public class CombinationRecordController { + + @Resource + private CombinationRecordService combinationRecordService; + /** + * {@link Map} 缓存,通过它异步刷新 {@link #getCombinationRecordSummary0()} 所要的拼团记录统计数据 + */ + private final LoadingCache> combinationRecordSummary = buildAsyncReloadingCache(Duration.ofSeconds(60L), + new CacheLoader>() { + + @Override + public Map load(String key) { + return getCombinationRecordSummary0(); + } + + }); + + @GetMapping("/page") + @Operation(summary = "获得拼团记录分页") + @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") + public CommonResult> getBargainRecordPage(@Valid CombinationRecordReqPageVO pageVO) { + return success(CombinationActivityConvert.INSTANCE.convert( + combinationRecordService.getBargainRecordPage(pageVO))); + } + + @GetMapping("/get-summary") + @Operation(summary = "获得拼团记录的概要信息", description = "用于拼团记录页面展示") + @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") + public CommonResult> getCombinationRecordSummary() { + return success(combinationRecordSummary.getUnchecked("")); // 缓存 + } + + @GetMapping("/get-count") + @Operation(summary = "获得拼团记录分页 tab count") + @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") + public CommonResult> getSpuCount() { + Map hashMap = MapUtil.newHashMap(7); + hashMap.put("all", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.ALL));// 全部 + hashMap.put("toDay", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.TO_DAY));// 今天 + hashMap.put("yesterday", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.YESTERDAY));// 昨天 + hashMap.put("lastSevenDays", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.LAST_SEVEN_DAYS));// 最近七天 + hashMap.put("last30Days", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.LAST_30_DAYS));// 最近 30 天 + hashMap.put("thisMonth", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.THIS_MONTH));// 本月 + hashMap.put("thisYear", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.THIS_YEAR));// 本年 + return success(hashMap); + } + + private Map getCombinationRecordSummary0() { + Map hashMap = MapUtil.newHashMap(3); + hashMap.put("userCount", combinationRecordService.getRecordsCount());// 获取所有拼团记录 + hashMap.put("successCount", combinationRecordService.getRecordsSuccessCount());// 获取成团记录 + hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount());// 获取虚拟成团记录 + return hashMap; + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java new file mode 100644 index 000000000..bf99dcb7c --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod; + +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 CombinationRecordReqPageVO extends PageParam { + + public static final Integer ALL = 0; // 全部 + public static final Integer TO_DAY = 1; // 今天 + public static final Integer YESTERDAY = 2; // 昨天 + public static final Integer LAST_SEVEN_DAYS = 3; // 最近七天 + public static final Integer LAST_30_DAYS = 4; // 最近 30 天 + public static final Integer THIS_MONTH = 5; // 本月 + public static final Integer THIS_YEAR = 6; // 本年 + + @Schema(description = "日期类型", example = "0") + private Integer dateType; + + @Schema(description = "活动状态", example = "0") + private Integer status; + + @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/recrod/CombinationRecordRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java new file mode 100644 index 000000000..ab1a98607 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java @@ -0,0 +1,60 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod; + +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 = "管理后台 - 拼团记录 Response VO") +@Data +public class CombinationRecordRespVO { + + @Schema(description = "拼团记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Long id; + + @Schema(description = "拼团活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Long activityId; + + @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "花开富贵") + private String nickname; + + @Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") + private String avatar; + + @Schema(description = "团长编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Long headId; + + @Schema(description = "过期时间", requiredMode = Schema.RequiredMode.REQUIRED) + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime expireTime; + + @Schema(description = "可参团人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Integer userSize; + + @Schema(description = "已参团人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") + private Integer userCount; + + @Schema(description = "拼团状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer status; + + @Schema(description = "商品名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是大黄豆") + private String spuName; + + @Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") + private String picUrl; + + @Schema(description = "是否虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "false") + private Boolean virtualGroup; + + @Schema(description = "开始时间 (订单付款后开始的时间)", requiredMode = Schema.RequiredMode.REQUIRED) + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime startTime; + + @Schema(description = "结束时间(成团时间/失败时间)", requiredMode = Schema.RequiredMode.REQUIRED) + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime endTime; + +} 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 ebbb252a3..5419f53a4 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 @@ -12,6 +12,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activit import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; 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.recrod.CombinationRecordRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityDetailRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordRespVO; @@ -146,4 +147,6 @@ public interface CombinationActivityConvert { AppCombinationRecordRespVO convert(CombinationRecordDO record); + PageResult convert(PageResult result); + } 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 91117ad83..a9998852d 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 @@ -1,10 +1,15 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.combination; +import cn.hutool.core.util.ObjectUtil; +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.recrod.CombinationRecordReqPageVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; import org.apache.ibatis.annotations.Mapper; +import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.List; /** @@ -90,4 +95,60 @@ public interface CombinationRecordMapper extends BaseMapperX selectPage(CombinationRecordReqPageVO pageVO) { + // 兼容自选时间段 + if (pageVO.getDateType() != null) { + pageVO.setCreateTime(builderQueryTime(pageVO.getDateType())); + } + return selectPage(pageVO, new LambdaQueryWrapperX() + .eqIfPresent(CombinationRecordDO::getStatus, pageVO.getStatus()) + .betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime())); + } + + default Long selectCount(Integer dateType) { + return selectCount(new LambdaQueryWrapperX() + .betweenIfPresent(CombinationRecordDO::getCreateTime, builderQueryTime(dateType))); + } + } 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 aeac753ad..e965764df 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 @@ -1,8 +1,10 @@ package cn.iocoder.yudao.module.promotion.service.combination; import cn.iocoder.yudao.framework.common.core.KeyValue; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; @@ -93,6 +95,28 @@ public interface CombinationRecordService { */ Long getRecordsCount(); + /** + * 获取成功记录数 + * + * @return 记录数 + */ + Long getRecordsSuccessCount(); + + /** + * 获取虚拟成团记录数 + * + * @return 记录数 + */ + Long getRecordsVirtualGroupCount(); + + /** + * 获取指定日期类型的记录数,比如说获取最近七天的拼团记录数 + * + * @param dateType 日期类型 + * @return 记录数 + */ + Long getRecordsCountByDateType(Integer dateType); + /** * 获取最近的 count 条拼团记录 * @@ -127,4 +151,12 @@ public interface CombinationRecordService { */ List getRecordListByHeadId(Long headId); + /** + * 获取拼团记录分页数据 + * + * @param pageVO 分页请求 + * @return 拼团记录分页数据 + */ + PageResult getBargainRecordPage(CombinationRecordReqPageVO pageVO); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index aa87fb880..83d1dc018 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; @@ -12,6 +13,7 @@ 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.CombinationRecordCreateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; 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.CombinationProductDO; @@ -225,6 +227,21 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return recordMapper.selectCount(); } + @Override + public Long getRecordsSuccessCount() { + return recordMapper.selectCount(CombinationRecordDO::getStatus, CombinationRecordStatusEnum.SUCCESS.getStatus()); + } + + @Override + public Long getRecordsVirtualGroupCount() { + return recordMapper.selectCount(CombinationRecordDO::getVirtualGroup, true); + } + + @Override + public Long getRecordsCountByDateType(Integer dateType) { + return recordMapper.selectCount(dateType); + } + @Override public List getLatestRecordList(int count) { return recordMapper.selectLatestList(count); @@ -245,4 +262,9 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return recordMapper.selectList(CombinationRecordDO::getHeadId, headId); } + @Override + public PageResult getBargainRecordPage(CombinationRecordReqPageVO pageVO) { + return recordMapper.selectPage(pageVO); + } + } From 34bf360da67f22e0d7f61ae218de621c4c412545 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 6 Oct 2023 21:04:37 +0800 Subject: [PATCH 02/19] =?UTF-8?q?trade=EF=BC=9A=E8=B0=83=E6=95=B4=E6=8B=BC?= =?UTF-8?q?=E5=9B=A2=E6=B4=BB=E5=8A=A8=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CombinationActivityController.java | 25 ++++++--- .../activity/CombinationActivityBaseVO.java | 3 ++ .../CombinationActivityPageItemRespVO.java | 53 +++++++++++++++++++ .../CombinationActivityPageReqVO.java | 3 +- .../activity/CombinationActivityRespVO.java | 20 ------- .../vo/activity/SeckillActivityRespVO.java | 22 ++++---- .../CombinationActivityConvert.java | 21 +++++--- .../combination/CombinationActivityDO.java | 14 +---- .../combination/CombinationRecordDO.java | 7 +++ .../combination/CombinationRecordMapper.java | 25 +++++++++ .../CombinationActivityService.java | 2 +- .../CombinationActivityServiceImpl.java | 4 +- .../combination/CombinationRecordService.java | 16 ++++++ .../CombinationRecordServiceImpl.java | 10 ++++ ...adeCombinationActivityPriceCalculator.java | 1 + 15 files changed, 165 insertions(+), 61 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityPageItemRespVO.java 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 28dd326e0..631670e98 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 @@ -5,14 +5,14 @@ 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.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.CombinationActivityPageReqVO; -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.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.CombinationProductDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; +import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService; +import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -23,6 +23,8 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; import java.util.List; +import java.util.Map; +import java.util.Set; import static cn.hutool.core.collection.CollectionUtil.newArrayList; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -36,6 +38,8 @@ public class CombinationActivityController { @Resource private CombinationActivityService combinationActivityService; + @Resource + private CombinationRecordService combinationRecordService; @Resource private ProductSpuApi productSpuApi; @@ -77,7 +81,7 @@ public class CombinationActivityController { @GetMapping("/page") @Operation(summary = "获得拼团活动分页") @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") - public CommonResult> getCombinationActivityPage( + public CommonResult> getCombinationActivityPage( @Valid CombinationActivityPageReqVO pageVO) { // 查询拼团活动 PageResult pageResult = combinationActivityService.getCombinationActivityPage(pageVO); @@ -85,12 +89,21 @@ public class CombinationActivityController { return success(PageResult.empty(pageResult.getTotal())); } + // 统计数据 + Set activityIds = convertSet(pageResult.getList(), CombinationActivityDO::getId); + Map groupCountMap = combinationRecordService.getCombinationRecordCountMapByActivity( + activityIds, null, CombinationRecordDO.HEAD_ID_GROUP); + Map groupSuccessCountMap = combinationRecordService.getCombinationRecordCountMapByActivity( + activityIds, CombinationRecordStatusEnum.SUCCESS.getStatus(), CombinationRecordDO.HEAD_ID_GROUP); + Map recordCountMap = combinationRecordService.getCombinationRecordCountMapByActivity( + activityIds, null, null); // 拼接数据 List products = combinationActivityService.getCombinationProductsByActivityIds( convertSet(pageResult.getList(), CombinationActivityDO::getId)); List spus = productSpuApi.getSpuList( convertSet(pageResult.getList(), CombinationActivityDO::getSpuId)); - return success(CombinationActivityConvert.INSTANCE.convertPage(pageResult, products, spus)); + return success(CombinationActivityConvert.INSTANCE.convertPage(pageResult, products, + groupCountMap, groupSuccessCountMap, recordCountMap, spus)); } } 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 634e3ae2e..edb85e5e6 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 @@ -48,6 +48,9 @@ public class CombinationActivityBaseVO { @NotNull(message = "开团人数不能为空") private Integer userSize; + @Schema(description = "虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Boolean virtualGroup = false; // TODO @puhui999:这个字段界面没做呀。 + @Schema(description = "限制时长(小时)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @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/CombinationActivityPageItemRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityPageItemRespVO.java new file mode 100644 index 000000000..0151adfb9 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityPageItemRespVO.java @@ -0,0 +1,53 @@ +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 java.time.LocalDateTime; +import java.util.List; + +@Schema(description = "管理后台 - 拼团活动的分页项 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class CombinationActivityPageItemRespVO 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, example = "0") + private Integer status; + + @Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED) + private List products; + + // ========== 商品字段 ========== + + @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 name 读取 + example = "618大促") + private String spuName; + @Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 picUrl 读取 + example = "https://www.iocoder.cn/xx.png") + private String picUrl; + @Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 marketPrice 读取 + example = "50") + private Integer marketPrice; + + // ========== 统计字段 ========== + + @Schema(description = "开团组数", requiredMode = Schema.RequiredMode.REQUIRED, example = "33") + private Integer groupCount; + + @Schema(description = "成团组数", requiredMode = Schema.RequiredMode.REQUIRED, example = "20") + private Integer groupSuccessCount; + + @Schema(description = "购买次数", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") + private Integer recordCount; + +} 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 bbef1ab58..bfb54b730 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 @@ -15,8 +15,7 @@ public class CombinationActivityPageReqVO extends PageParam { @Schema(description = "拼团名称", example = "赵六") private String name; - @Schema(description = "活动状态:0开启 1关闭", example = "0") + @Schema(description = "活动状态", 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/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 267695250..0ac77c559 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 @@ -6,8 +6,6 @@ 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; @@ -20,30 +18,12 @@ public class CombinationActivityRespVO extends CombinationActivityBaseVO { @Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901") private Long id; - @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) private LocalDateTime createTime; @Schema(description = "开团人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") private Integer userSize; - @Schema(description = "开团组数", requiredMode = Schema.RequiredMode.REQUIRED, example = "33") - private Integer totalCount; - - @Schema(description = "成团组数", requiredMode = Schema.RequiredMode.REQUIRED, example = "20") - private Integer successCount; - - @Schema(description = "虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Integer virtualGroup; - - @Schema(description = "活动状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") - private Integer status; - @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/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 cb98dd2b7..742c73ba6 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,16 +18,6 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO { @Schema(description = "秒杀活动 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") private Long id; - @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 name 读取 - example = "618大促") - private String spuName; - @Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 picUrl 读取 - example = "https://www.iocoder.cn/xx.png") - private String picUrl; - @Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 marketPrice 读取 - example = "50") - private Integer marketPrice; - @Schema(description = "秒杀商品", requiredMode = Schema.RequiredMode.REQUIRED) private List products; @@ -52,4 +42,16 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO { @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; + // ========== 商品字段 ========== + + @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 name 读取 + example = "618大促") + private String spuName; + @Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 picUrl 读取 + example = "https://www.iocoder.cn/xx.png") + private String picUrl; + @Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 marketPrice 读取 + example = "50") + private Integer marketPrice; + } 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 ebbb252a3..28b313116 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 @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; 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.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageItemRespVO; 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.CombinationProductBaseVO; @@ -53,19 +54,27 @@ public interface CombinationActivityConvert { List convertList(List list); - PageResult convertPage(PageResult page); - default PageResult convertPage(PageResult page, - List productList, - List spuList) { + default PageResult convertPage(PageResult page, + List productList, + Map groupCountMap, + Map groupSuccessCountMap, + Map recordCountMap, + List spuList) { + PageResult pageResult = convertPage(page); Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); - PageResult pageResult = convertPage(page); pageResult.getList().forEach(item -> { - MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl())); + MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl()) + .setMarketPrice(spu.getMarketPrice())); item.setProducts(convertList2(productList)); + // 设置统计字段 + item.setGroupCount(groupCountMap.getOrDefault(item.getId(), 0)) + .setGroupSuccessCount(groupSuccessCountMap.getOrDefault(item.getId(), 0)) + .setRecordCount(recordCountMap.getOrDefault(item.getId(), 0)); }); return pageResult; } + PageResult convertPage(PageResult page); List convertList2(List 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/CombinationActivityDO.java index 84ce8fdc1..5236b303a 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/CombinationActivityDO.java @@ -59,22 +59,10 @@ public class CombinationActivityDO extends BaseDO { * 几人团 */ private Integer userSize; - /** - * 开团组数 - */ - private Integer totalCount; - /** - * 成团组数 - */ - private Integer successCount; - /** - * 参与人数 - */ - private Integer orderUserCount; /** * 虚拟成团 */ - private Integer virtualGroup; + private Boolean virtualGroup; /** * 活动状态 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java index 1b8a73c24..faf65a2c6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java @@ -28,6 +28,11 @@ import java.time.LocalDateTime; @AllArgsConstructor public class CombinationRecordDO extends BaseDO { + /** + * 团长编号 - 团长 + */ + public static final Integer HEAD_ID_GROUP = 0; + /** * 编号,主键自增 */ @@ -84,6 +89,8 @@ public class CombinationRecordDO extends BaseDO { * 团长编号 * * 关联 {@link CombinationRecordDO#getId()} + * + * 如果是团长,则它的值是 {@link #HEAD_ID_GROUP} */ private Long headId; /** 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 91117ad83..54345f7a2 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 @@ -1,11 +1,18 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.combination; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.map.MapUtil; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; 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.CombinationRecordDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.ibatis.annotations.Mapper; +import java.util.Collection; +import java.util.Collections; import java.util.List; +import java.util.Map; /** * 拼团记录 Mapper @@ -90,4 +97,22 @@ public interface CombinationRecordMapper extends BaseMapperX selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(Collection activityIds, + Integer status, Integer headId) { + // SQL count 查询 + List> result = selectMaps(new QueryWrapper() + .select("COUNT(DISTINCT(user_id)) AS recordCount, activity_id AS activityId") + .in("activity_id", activityIds) + .eq(status != null, "status", status) + .eq(headId != null, "head_id", headId) + .groupBy("activity_id")); + if (CollUtil.isEmpty(result)) { + return Collections.emptyMap(); + } + // 转换数据 + return CollectionUtils.convertMap(result, + record -> MapUtil.getLong(record, "activityId"), + record -> MapUtil.getInt(record, "recordCount" )); + } + } 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 83f135c5a..d55be29fe 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 @@ -101,7 +101,7 @@ public interface CombinationActivityService { PageResult getCombinationActivityPage(PageParam pageParam); /** - * 获取指定活动指定 sku 编号的商品 + * 获取指定活动、指定 sku 编号的商品 * * @param activityId 活动编号 * @param skuId sku 编号 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 df254d23b..db0f1ff66 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 @@ -65,13 +65,11 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic // 插入拼团活动 CombinationActivityDO activity = CombinationActivityConvert.INSTANCE.convert(createReqVO) - .setStatus(CommonStatusEnum.ENABLE.getStatus()) - .setTotalCount(0).setSuccessCount(0).setOrderUserCount(0).setVirtualGroup(0); + .setStatus(CommonStatusEnum.ENABLE.getStatus()); combinationActivityMapper.insert(activity); // 插入商品 List products = CombinationActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), activity); combinationProductMapper.insertBatch(products); - // 返回 return activity.getId(); } 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 aeac753ad..de4c4b0b1 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 @@ -7,9 +7,13 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationA import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; +import javax.annotation.Nullable; import java.time.LocalDateTime; +import java.util.Collection; import java.util.List; +import java.util.Map; +// todo @PUHUI:方法名,还是带下 Combination 哈 /** * 拼团记录 Service 接口 * @@ -127,4 +131,16 @@ public interface CombinationRecordService { */ List getRecordListByHeadId(Long headId); + /** + * 【拼团活动】获得拼团记录数量 Map + * + * @param activityIds 活动记录编号数组 + * @param status 拼团状态,允许空 + * @param headId 团长编号,允许空。目的 headId 设置为 {@link CombinationRecordDO#HEAD_ID_GROUP} 时,可以设置 + * @return 拼团记录数量 Map + */ + Map getCombinationRecordCountMapByActivity(Collection activityIds, + @Nullable Integer status, + @Nullable Integer headId); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index aa87fb880..03588ea69 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -25,9 +25,12 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; +import javax.annotation.Nullable; import javax.annotation.Resource; import java.time.LocalDateTime; +import java.util.Collection; 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.util.collection.CollectionUtils.*; @@ -203,6 +206,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Override public CombinationRecordDO getCombinationRecord(Long userId, Long orderId) { + // TODO puhui999:这里直接获得,不适合调用校验的接口; return validateCombinationRecord(userId, orderId); } @@ -245,4 +249,10 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return recordMapper.selectList(CombinationRecordDO::getHeadId, headId); } + @Override + public Map getCombinationRecordCountMapByActivity(Collection activityIds, + @Nullable Integer status, @Nullable Integer headId) { + return recordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId); + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCombinationActivityPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCombinationActivityPriceCalculator.java index 0fec9992a..18296ad63 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCombinationActivityPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCombinationActivityPriceCalculator.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; +// TODO @puhui999:单测可以后补下 /** * 拼团活动的 {@link TradePriceCalculator} 实现类 * From 6099786c1b7a7e8d9f93bb9edcc9fb5db364b3bd Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 6 Oct 2023 21:26:53 +0800 Subject: [PATCH 03/19] =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=EF=BC=9A=E5=AE=8C=E5=96=84=E6=8B=BC=E5=9B=A2=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CombinationRecordController.java | 22 +++++++++--------- .../AppCombinationRecordController.java | 14 +++++------ .../combination/CombinationRecordMapper.java | 6 +---- .../combination/CombinationRecordService.java | 23 +++++++++---------- .../CombinationRecordServiceImpl.java | 20 ++++++++-------- .../CombinationActivityServiceImplTest.java | 18 --------------- 6 files changed, 40 insertions(+), 63 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java index de24a7631..d8a3b5245 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java @@ -51,7 +51,7 @@ public class CombinationRecordController { @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") public CommonResult> getBargainRecordPage(@Valid CombinationRecordReqPageVO pageVO) { return success(CombinationActivityConvert.INSTANCE.convert( - combinationRecordService.getBargainRecordPage(pageVO))); + combinationRecordService.getCombinationRecordPage(pageVO))); } @GetMapping("/get-summary") @@ -64,22 +64,22 @@ public class CombinationRecordController { @GetMapping("/get-count") @Operation(summary = "获得拼团记录分页 tab count") @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") - public CommonResult> getSpuCount() { + public CommonResult> getCombinationRecordCount() { Map hashMap = MapUtil.newHashMap(7); - hashMap.put("all", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.ALL));// 全部 - hashMap.put("toDay", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.TO_DAY));// 今天 - hashMap.put("yesterday", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.YESTERDAY));// 昨天 - hashMap.put("lastSevenDays", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.LAST_SEVEN_DAYS));// 最近七天 - hashMap.put("last30Days", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.LAST_30_DAYS));// 最近 30 天 - hashMap.put("thisMonth", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.THIS_MONTH));// 本月 - hashMap.put("thisYear", combinationRecordService.getRecordsCountByDateType(CombinationRecordReqPageVO.THIS_YEAR));// 本年 + hashMap.put("all", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.ALL));// 全部 + hashMap.put("toDay", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.TO_DAY));// 今天 + hashMap.put("yesterday", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.YESTERDAY));// 昨天 + hashMap.put("lastSevenDays", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.LAST_SEVEN_DAYS));// 最近七天 + hashMap.put("last30Days", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.LAST_30_DAYS));// 最近 30 天 + hashMap.put("thisMonth", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.THIS_MONTH));// 本月 + hashMap.put("thisYear", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.THIS_YEAR));// 本年 return success(hashMap); } private Map getCombinationRecordSummary0() { Map hashMap = MapUtil.newHashMap(3); - hashMap.put("userCount", combinationRecordService.getRecordsCount());// 获取所有拼团记录 - hashMap.put("successCount", combinationRecordService.getRecordsSuccessCount());// 获取成团记录 + hashMap.put("userCount", combinationRecordService.getCombinationRecordsCount());// 获取所有拼团记录 + hashMap.put("successCount", combinationRecordService.getCombinationRecordsSuccessCount());// 获取成团记录 hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount());// 获取虚拟成团记录 return hashMap; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java index 113492504..2d4b813ff 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java @@ -42,7 +42,7 @@ public class AppCombinationRecordController { // TODO 芋艿:增加 @Cache 缓存,1 分钟过期 public CommonResult getCombinationRecordSummary() { // 获取所有拼团记录 - Long count = combinationRecordService.getRecordsCount(); + Long count = combinationRecordService.getCombinationRecordsCount(); AppCombinationRecordSummaryRespVO summary = new AppCombinationRecordSummaryRespVO(); if (count == null || count == 0L) { summary.setAvatars(Collections.emptyList()); @@ -53,7 +53,7 @@ public class AppCombinationRecordController { summary.setUserCount(count); // TODO 只返回最近的 7 个 int num = 7; - summary.setAvatars(convertList(combinationRecordService.getLatestRecordList(num), CombinationRecordDO::getAvatar)); + summary.setAvatars(convertList(combinationRecordService.getLatestCombinationRecordList(num), CombinationRecordDO::getAvatar)); return success(summary); } @@ -69,7 +69,7 @@ public class AppCombinationRecordController { @RequestParam("status") Integer status, @RequestParam(value = "count", defaultValue = "20") @Max(20) Integer count) { return success(CombinationActivityConvert.INSTANCE.convertList3( - combinationRecordService.getRecordListWithHead(activityId, status, count))); + combinationRecordService.getCombinationRecordListWithHead(activityId, status, count))); } @GetMapping("/get-detail") @@ -77,7 +77,7 @@ public class AppCombinationRecordController { @Parameter(name = "id", description = "拼团记录编号", required = true, example = "1024") public CommonResult getCombinationRecordDetail(@RequestParam("id") Long id) { // 1、查询这条记录 - CombinationRecordDO record = combinationRecordService.getRecordById(id); + CombinationRecordDO record = combinationRecordService.getCombinationRecordById(id); if (record == null) { return success(null); } @@ -88,17 +88,17 @@ public class AppCombinationRecordController { if (record.getHeadId() == null) { detail.setHeadRecord(CombinationActivityConvert.INSTANCE.convert(record)); // 2.1、查找团员拼团记录 - records = combinationRecordService.getRecordListByHeadId(record.getId()); + records = combinationRecordService.getCombinationRecordListByHeadId(record.getId()); } else { // 2.2、查找团长拼团记录 - CombinationRecordDO headRecord = combinationRecordService.getRecordById(record.getHeadId()); + CombinationRecordDO headRecord = combinationRecordService.getCombinationRecordById(record.getHeadId()); if (headRecord == null) { return success(null); } detail.setHeadRecord(CombinationActivityConvert.INSTANCE.convert(headRecord)); // 2.3、查找团员拼团记录 - records = combinationRecordService.getRecordListByHeadId(headRecord.getId()); + records = combinationRecordService.getCombinationRecordListByHeadId(headRecord.getId()); } detail.setMemberRecords(CombinationActivityConvert.INSTANCE.convertList3(records)); 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 14992772c..54f998d44 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 @@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.combination; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.map.MapUtil; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; 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.recrod.CombinationRecordReqPageVO; @@ -32,10 +32,6 @@ public interface CombinationRecordMapper extends BaseMapperX selectListByUserId(Long userId) { - return selectList(CombinationRecordDO::getUserId, userId); - } - default List selectListByUserIdAndStatus(Long userId, Integer status) { return selectList(new LambdaQueryWrapperX() .eq(CombinationRecordDO::getUserId, userId) 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 c64872fe1..ca651ce1a 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 @@ -15,7 +15,6 @@ import java.util.Collection; import java.util.List; import java.util.Map; -// todo @PUHUI:方法名,还是带下 Combination 哈 /** * 拼团记录 Service 接口 * @@ -62,11 +61,11 @@ public interface CombinationRecordService { void updateRecordStatusAndStartTimeByUserIdAndOrderId(Integer status, Long userId, Long orderId, LocalDateTime startTime); /** - * 获得拼团状态 + * 获得拼团记录 * * @param userId 用户编号 * @param orderId 订单编号 - * @return 拼团状态 + * @return 拼团记录 */ CombinationRecordDO getCombinationRecord(Long userId, Long orderId); @@ -77,7 +76,7 @@ public interface CombinationRecordService { * @param activityId 活动 id * @return 拼团记录列表 */ - List getRecordListByUserIdAndActivityId(Long userId, Long activityId); + List getCombinationRecordListByUserIdAndActivityId(Long userId, Long activityId); /** * 【下单前】校验是否满足拼团活动条件 @@ -97,14 +96,14 @@ public interface CombinationRecordService { * * @return 记录数 */ - Long getRecordsCount(); + Long getCombinationRecordsCount(); /** * 获取成功记录数 * * @return 记录数 */ - Long getRecordsSuccessCount(); + Long getCombinationRecordsSuccessCount(); /** * 获取虚拟成团记录数 @@ -119,7 +118,7 @@ public interface CombinationRecordService { * @param dateType 日期类型 * @return 记录数 */ - Long getRecordsCountByDateType(Integer dateType); + Long getCombinationRecordsCountByDateType(Integer dateType); /** * 获取最近的 count 条拼团记录 @@ -127,7 +126,7 @@ public interface CombinationRecordService { * @param count 限制数量 * @return 拼团记录列表 */ - List getLatestRecordList(int count); + List getLatestCombinationRecordList(int count); /** * 获得最近 n 条拼团记录(团长发起的) @@ -137,7 +136,7 @@ public interface CombinationRecordService { * @param count 数量 * @return 拼团记录列表 */ - List getRecordListWithHead(Long activityId, Integer status, Integer count); + List getCombinationRecordListWithHead(Long activityId, Integer status, Integer count); /** * 获取指定编号的拼团记录 @@ -145,7 +144,7 @@ public interface CombinationRecordService { * @param id 拼团记录编号 * @return 拼团记录 */ - CombinationRecordDO getRecordById(Long id); + CombinationRecordDO getCombinationRecordById(Long id); /** * 获取指定团长编号的拼团记录 @@ -153,7 +152,7 @@ public interface CombinationRecordService { * @param headId 团长编号 * @return 拼团记录列表 */ - List getRecordListByHeadId(Long headId); + List getCombinationRecordListByHeadId(Long headId); /** * 获取拼团记录分页数据 @@ -161,7 +160,7 @@ public interface CombinationRecordService { * @param pageVO 分页请求 * @return 拼团记录分页数据 */ - PageResult getBargainRecordPage(CombinationRecordReqPageVO pageVO); + PageResult getCombinationRecordPage(CombinationRecordReqPageVO pageVO); /** * 【拼团活动】获得拼团记录数量 Map diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index dee4821d5..d6b9f84d7 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -139,7 +139,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { throw exception(COMBINATION_ACTIVITY_UPDATE_STOCK_FAIL); } // 3、校验是否有拼团记录 - List recordList = getRecordListByUserIdAndActivityId(userId, activityId); + List recordList = getCombinationRecordListByUserIdAndActivityId(userId, activityId); if (CollUtil.isEmpty(recordList)) { return new KeyValue<>(activity, product); } @@ -213,7 +213,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } @Override - public List getRecordListByUserIdAndActivityId(Long userId, Long activityId) { + public List getCombinationRecordListByUserIdAndActivityId(Long userId, Long activityId) { return recordMapper.selectListByUserIdAndActivityId(userId, activityId); } @@ -227,12 +227,12 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } @Override - public Long getRecordsCount() { + public Long getCombinationRecordsCount() { return recordMapper.selectCount(); } @Override - public Long getRecordsSuccessCount() { + public Long getCombinationRecordsSuccessCount() { return recordMapper.selectCount(CombinationRecordDO::getStatus, CombinationRecordStatusEnum.SUCCESS.getStatus()); } @@ -242,32 +242,32 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } @Override - public Long getRecordsCountByDateType(Integer dateType) { + public Long getCombinationRecordsCountByDateType(Integer dateType) { return recordMapper.selectCount(dateType); } @Override - public List getLatestRecordList(int count) { + public List getLatestCombinationRecordList(int count) { return recordMapper.selectLatestList(count); } @Override - public List getRecordListWithHead(Long activityId, Integer status, Integer count) { + public List getCombinationRecordListWithHead(Long activityId, Integer status, Integer count) { return recordMapper.selectList(activityId, status, count); } @Override - public CombinationRecordDO getRecordById(Long id) { + public CombinationRecordDO getCombinationRecordById(Long id) { return recordMapper.selectById(id); } @Override - public List getRecordListByHeadId(Long headId) { + public List getCombinationRecordListByHeadId(Long headId) { return recordMapper.selectList(CombinationRecordDO::getHeadId, headId); } @Override - public PageResult getBargainRecordPage(CombinationRecordReqPageVO pageVO) { + public PageResult getCombinationRecordPage(CombinationRecordReqPageVO pageVO) { return recordMapper.selectPage(pageVO); } 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 86d58d747..f1605dec8 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 @@ -111,9 +111,6 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { o.setStartTime(null); o.setEndTime(null); o.setUserSize(null); - o.setTotalCount(null); - o.setSuccessCount(null); - o.setOrderUserCount(null); o.setVirtualGroup(null); o.setStatus(null); o.setLimitDuration(null); @@ -134,12 +131,6 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setEndTime(null))); // 测试 userSize 不匹配 combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setUserSize(null))); - // 测试 totalNum 不匹配 - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalCount(null))); - // 测试 successNum 不匹配 - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSuccessCount(null))); - // 测试 orderUserCount 不匹配 - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setOrderUserCount(null))); // 测试 virtualGroup 不匹配 combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setVirtualGroup(null))); // 测试 status 不匹配 @@ -173,9 +164,6 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { o.setStartTime(null); o.setEndTime(null); o.setUserSize(null); - o.setTotalCount(null); - o.setSuccessCount(null); - o.setOrderUserCount(null); o.setVirtualGroup(null); o.setStatus(null); o.setLimitDuration(null); @@ -196,12 +184,6 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setEndTime(null))); // 测试 userSize 不匹配 combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setUserSize(null))); - // 测试 totalNum 不匹配 - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalCount(null))); - // 测试 successNum 不匹配 - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSuccessCount(null))); - // 测试 orderUserCount 不匹配 - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setOrderUserCount(null))); // 测试 virtualGroup 不匹配 combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setVirtualGroup(null))); // 测试 status 不匹配 From c8f1269d6ede6fe21d68b9f456921702061a522f Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 6 Oct 2023 22:29:11 +0800 Subject: [PATCH 04/19] =?UTF-8?q?promotion=EF=BC=9A=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=A0=8D=E4=BB=B7=E6=B4=BB=E5=8A=A8=E8=BF=94=E5=9B=9E=E7=9A=84?= =?UTF-8?q?=20combinationPrice=20=E4=B8=BA=E7=A9=BA=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/core/mapper/BaseMapperX.java | 2 +- .../CombinationActivityController.java | 4 +- .../CombinationRecordController.java | 2 +- .../AppCombinationActivityController.java | 39 +++++++++++-------- .../AppCombinationRecordController.java | 16 ++++---- .../AppCombinationRecordSummaryRespVO.java | 5 +++ .../seckill/AppSeckillActivityController.java | 3 +- .../CombinationActivityConvert.java | 22 ++++++++--- .../combination/CombinationRecordMapper.java | 2 +- .../CombinationActivityService.java | 4 +- .../CombinationActivityServiceImpl.java | 2 +- .../combination/CombinationRecordService.java | 2 +- .../CombinationRecordServiceImpl.java | 2 +- 13 files changed, 63 insertions(+), 42 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java index 3383ec879..d70c21626 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java @@ -56,7 +56,7 @@ public interface BaseMapperX extends MPJBaseMapper { } default Long selectCount() { - return selectCount(new QueryWrapper()); + return selectCount(new QueryWrapper<>()); } default Long selectCount(String field, Object value) { 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 631670e98..e7086518f 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 @@ -74,7 +74,7 @@ public class CombinationActivityController { @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") public CommonResult getCombinationActivity(@RequestParam("id") Long id) { CombinationActivityDO activity = combinationActivityService.getCombinationActivity(id); - List products = combinationActivityService.getCombinationProductsByActivityIds(newArrayList(id)); + List products = combinationActivityService.getCombinationProductListByActivityIds(newArrayList(id)); return success(CombinationActivityConvert.INSTANCE.convert(activity, products)); } @@ -98,7 +98,7 @@ public class CombinationActivityController { Map recordCountMap = combinationRecordService.getCombinationRecordCountMapByActivity( activityIds, null, null); // 拼接数据 - List products = combinationActivityService.getCombinationProductsByActivityIds( + List products = combinationActivityService.getCombinationProductListByActivityIds( convertSet(pageResult.getList(), CombinationActivityDO::getId)); List spus = productSpuApi.getSpuList( convertSet(pageResult.getList(), CombinationActivityDO::getSpuId)); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java index d8a3b5245..1e6b3954c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java @@ -78,7 +78,7 @@ public class CombinationRecordController { private Map getCombinationRecordSummary0() { Map hashMap = MapUtil.newHashMap(3); - hashMap.put("userCount", combinationRecordService.getCombinationRecordsCount());// 获取所有拼团记录 + hashMap.put("userCount", combinationRecordService.getCombinationRecordCount());// 获取所有拼团记录 hashMap.put("successCount", combinationRecordService.getCombinationRecordsSuccessCount());// 获取成团记录 hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount());// 获取虚拟成团记录 return hashMap; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java index 55e2ee7ac..6534c4efc 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java @@ -30,7 +30,6 @@ import java.time.Duration; import java.util.Collections; import java.util.List; -import static cn.hutool.core.util.ObjectUtil.defaultIfNull; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; @@ -56,6 +55,7 @@ public class AppCombinationActivityController { @Resource private CombinationActivityService activityService; + @Resource private ProductSpuApi spuApi; @@ -68,40 +68,45 @@ public class AppCombinationActivityController { } private List getCombinationActivityList0(Integer count) { - List list = activityService.getCombinationActivityListByCount(defaultIfNull(count, 6)); - if (CollUtil.isEmpty(list)) { + List activityList = activityService.getCombinationActivityListByCount(count); + if (CollUtil.isEmpty(activityList)) { return Collections.emptyList(); } // 拼接返回 - List spuList = spuApi.getSpuList(convertList(list, CombinationActivityDO::getSpuId)); - return CombinationActivityConvert.INSTANCE.convertAppList(list, spuList); + List productList = activityService.getCombinationProductListByActivityIds( + convertList(activityList, CombinationActivityDO::getId)); + List spuList = spuApi.getSpuList(convertList(activityList, CombinationActivityDO::getSpuId)); + return CombinationActivityConvert.INSTANCE.convertAppList(activityList, productList, spuList); } @GetMapping("/page") @Operation(summary = "获得拼团活动分页") public CommonResult> getCombinationActivityPage(PageParam pageParam) { - PageResult result = activityService.getCombinationActivityPage(pageParam); - if (CollUtil.isEmpty(result.getList())) { - return success(PageResult.empty(result.getTotal())); + PageResult pageResult = activityService.getCombinationActivityPage(pageParam); + if (CollUtil.isEmpty(pageResult.getList())) { + return success(PageResult.empty(pageResult.getTotal())); } // 拼接返回 - List spuList = spuApi.getSpuList(convertList(result.getList(), CombinationActivityDO::getSpuId)); - return success(CombinationActivityConvert.INSTANCE.convertAppPage(result, spuList)); + List productList = activityService.getCombinationProductListByActivityIds( + convertList(pageResult.getList(), CombinationActivityDO::getId)); + List spuList = spuApi.getSpuList(convertList(pageResult.getList(), CombinationActivityDO::getSpuId)); + return success(CombinationActivityConvert.INSTANCE.convertAppPage(pageResult, productList, spuList)); } @GetMapping("/get-detail") @Operation(summary = "获得拼团活动明细") @Parameter(name = "id", description = "活动编号", required = true, example = "1024") public CommonResult getCombinationActivityDetail(@RequestParam("id") Long id) { - // 1、获取活动 - CombinationActivityDO combinationActivity = activityService.getCombinationActivity(id); - if (combinationActivity == null - || ObjectUtil.equal(combinationActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { + // 1. 获取活动 + CombinationActivityDO activity = activityService.getCombinationActivity(id); + if (activity == null + || ObjectUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { return success(null); } - // 2、获取活动商品 - List products = activityService.getCombinationProductsByActivityId(combinationActivity.getId()); - return success(CombinationActivityConvert.INSTANCE.convert3(combinationActivity, products)); + + // 2. 获取活动商品 + List products = activityService.getCombinationProductsByActivityId(activity.getId()); + return success(CombinationActivityConvert.INSTANCE.convert3(activity, products)); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java index 2d4b813ff..280809626 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java @@ -39,21 +39,21 @@ public class AppCombinationRecordController { @GetMapping("/get-summary") @Operation(summary = "获得拼团记录的概要信息", description = "用于小程序首页") - // TODO 芋艿:增加 @Cache 缓存,1 分钟过期 public CommonResult getCombinationRecordSummary() { - // 获取所有拼团记录 - Long count = combinationRecordService.getCombinationRecordsCount(); AppCombinationRecordSummaryRespVO summary = new AppCombinationRecordSummaryRespVO(); - if (count == null || count == 0L) { + // 1. 获得拼团记录数量 + Long count = combinationRecordService.getCombinationRecordCount(); + if (count == 0) { summary.setAvatars(Collections.emptyList()); summary.setUserCount(count); return success(summary); } - summary.setUserCount(count); - // TODO 只返回最近的 7 个 - int num = 7; - summary.setAvatars(convertList(combinationRecordService.getLatestCombinationRecordList(num), CombinationRecordDO::getAvatar)); + + // 2. 获得拼团记录头像 + List records = combinationRecordService.getLatestCombinationRecordList( + AppCombinationRecordSummaryRespVO.AVATAR_COUNT); + summary.setAvatars(convertList(records, CombinationRecordDO::getAvatar)); return success(summary); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSummaryRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSummaryRespVO.java index 5c79f9f73..d9ea03d6f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSummaryRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSummaryRespVO.java @@ -9,6 +9,11 @@ import java.util.List; @Data public class AppCombinationRecordSummaryRespVO { + /** + * 加载 {@link #avatars} 的数量 + */ + public static final Integer AVATAR_COUNT = 7; + @Schema(description = "拼团用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long userCount; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java index 5c85a6ff8..1b4945334 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java @@ -86,7 +86,8 @@ public class AppSeckillActivityController { // 2.1 查询满足当前阶段的活动 List activityList = activityService.getSeckillActivityListByConfigIdAndStatus(config.getId(), CommonStatusEnum.ENABLE.getStatus()); - List productList = activityService.getSeckillProductListByActivityId(convertList(activityList, SeckillActivityDO::getId)); + List productList = activityService.getSeckillProductListByActivityId( + convertList(activityList, SeckillActivityDO::getId)); // 2.2 获取 spu 信息 List spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId)); return SeckillActivityConvert.INSTANCE.convert(config, activityList, productList, spuList); 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 4a70a63a9..73abb53b4 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 @@ -28,7 +28,7 @@ import org.mapstruct.factory.Mappers; import java.util.List; import java.util.Map; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; /** @@ -120,10 +120,16 @@ public interface CombinationActivityConvert { List convertAppList(List list); - default List convertAppList(List list, List spuList) { + default List convertAppList(List list, + List productList, + List spuList) { List activityList = convertAppList(list); Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); + Map> productMap = convertMultiMap(productList, CombinationProductDO::getActivityId); return CollectionUtils.convertList(activityList, item -> { + // 设置 product 信息 + item.setCombinationPrice(getMinValue(productMap.get(item.getId()), CombinationProductDO::getCombinationPrice)); + // 设置 SPU 信息 findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice())); return item; }); @@ -131,13 +137,17 @@ public interface CombinationActivityConvert { PageResult convertAppPage(PageResult result); - default PageResult convertAppPage(PageResult result, List spuList) { + default PageResult convertAppPage(PageResult result, + List productList, + List spuList) { PageResult appPage = convertAppPage(result); Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); + Map> productMap = convertMultiMap(productList, CombinationProductDO::getActivityId); List list = CollectionUtils.convertList(appPage.getList(), item -> { - findAndThen(spuMap, item.getSpuId(), spu -> { - item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()); - }); + // 设置 product 信息 + item.setCombinationPrice(getMinValue(productMap.get(item.getId()), CombinationProductDO::getCombinationPrice)); + // 设置 SPU 信息 + findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice())); return item; }); appPage.setList(list); 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 54f998d44..691044dc9 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 @@ -77,7 +77,7 @@ public interface CombinationRecordMapper extends BaseMapperX selectLatestList(int count) { return selectList(new LambdaQueryWrapperX() - .orderByDesc(CombinationRecordDO::getCreateTime) + .orderByDesc(CombinationRecordDO::getId) .last("LIMIT " + count)); } 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 d55be29fe..adb6cb21a 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 @@ -73,7 +73,7 @@ public interface CombinationActivityService { * @return 拼团活动的商品列表 */ default List getCombinationProductsByActivityId(Long activityId) { - return getCombinationProductsByActivityIds(Collections.singletonList(activityId)); + return getCombinationProductListByActivityIds(Collections.singletonList(activityId)); } /** @@ -82,7 +82,7 @@ public interface CombinationActivityService { * @param activityIds 拼团活动 ids * @return 拼团活动的商品列表 */ - List getCombinationProductsByActivityIds(Collection activityIds); + List getCombinationProductListByActivityIds(Collection activityIds); /** * 获取正在进行的活动分页数据 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 db0f1ff66..1f62b307a 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 @@ -200,7 +200,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic } @Override - public List getCombinationProductsByActivityIds(Collection activityIds) { + public List getCombinationProductListByActivityIds(Collection activityIds) { return combinationProductMapper.selectListByActivityIds(activityIds); } 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 ca651ce1a..43372f674 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 @@ -96,7 +96,7 @@ public interface CombinationRecordService { * * @return 记录数 */ - Long getCombinationRecordsCount(); + Long getCombinationRecordCount(); /** * 获取成功记录数 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index d6b9f84d7..6566c7ce2 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -227,7 +227,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } @Override - public Long getCombinationRecordsCount() { + public Long getCombinationRecordCount() { return recordMapper.selectCount(); } From c7b5df930ed137a7919f8e031b79889e205013af Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 7 Oct 2023 07:09:15 +0800 Subject: [PATCH 05/19] =?UTF-8?q?promotion=EF=BC=9A=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E4=B8=8B=E5=8D=95=E6=97=B6=EF=BC=8C=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=AD=97=E6=AE=B5=E8=AE=B0=E5=BD=95=E4=B8=8D=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E7=9A=84=E6=83=85=E5=86=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/combination/CombinationRecordApi.java | 1 + .../combination/CombinationActivityConvert.java | 2 +- .../combination/CombinationRecordServiceImpl.java | 5 +++-- .../module/trade/convert/order/TradeOrderConvert.java | 8 ++++++-- .../trade/dal/dataobject/order/TradeOrderDO.java | 10 ++++++++-- .../service/order/handler/TradeCombinationHandler.java | 3 ++- .../TradeCombinationActivityPriceCalculator.java | 1 - 7 files changed, 21 insertions(+), 9 deletions(-) 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 21e025520..cc3fd443a 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 @@ -77,6 +77,7 @@ public interface CombinationRecordApi { * @param count 数量 * @return 拼团信息 */ + // TODO @puhui:userId 放最前面;然后应该还有个 headId 参数; CombinationValidateJoinRespDTO validateJoinCombination(Long activityId, Long userId, Long skuId, Integer count); } 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 73abb53b4..7a410f702 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 @@ -108,7 +108,7 @@ public interface CombinationActivityConvert { CombinationActivityDO activity, MemberUserRespDTO user, ProductSpuRespDTO spu, ProductSkuRespDTO sku) { return convert(reqDTO) - .setCount(reqDTO.getCount()) + .setCount(reqDTO.getCount()).setUserCount(1) .setVirtualGroup(false) .setExpireTime(activity.getStartTime().plusHours(activity.getLimitDuration())) .setUserSize(activity.getUserSize()) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 6566c7ce2..9b6212579 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; @@ -97,8 +98,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { item.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus()); } }); + recordMapper.updateBatch(records); } - recordMapper.updateBatch(records); } private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) { @@ -179,7 +180,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED); } // 3、校验活动是否开启 - if (LocalDateTime.now().isAfter(activity.getStartTime())) { + if (!LocalDateTimeUtils.beforeNow(activity.getStartTime())) { throw exception(COMBINATION_RECORD_FAILED_TIME_NOT_START); } // 4、校验当前活动是否过期 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 f67bfe9ba..40260ae4b 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 @@ -207,12 +207,16 @@ public interface TradeOrderConvert { default TradePriceCalculateReqBO convert(Long userId, AppTradeOrderSettlementReqVO settlementReqVO, List cartList) { TradePriceCalculateReqBO reqBO = new TradePriceCalculateReqBO().setUserId(userId) + .setItems(new ArrayList<>(settlementReqVO.getItems().size())) .setCouponId(settlementReqVO.getCouponId()).setPointStatus(settlementReqVO.getPointStatus()) + // 物流信息 .setDeliveryType(settlementReqVO.getDeliveryType()).setAddressId(settlementReqVO.getAddressId()) .setPickUpStoreId(settlementReqVO.getPickUpStoreId()) - .setItems(new ArrayList<>(settlementReqVO.getItems().size())) + // 各种活动 .setSeckillActivityId(settlementReqVO.getSeckillActivityId()) - .setBargainRecordId(settlementReqVO.getBargainRecordId()); + .setBargainRecordId(settlementReqVO.getBargainRecordId()) + .setCombinationActivityId(settlementReqVO.getCombinationActivityId()) + .setCombinationHeadId(settlementReqVO.getCombinationHeadId()); // 商品项的构建 Map cartMap = convertMap(cartList, CartDO::getId); for (AppTradeOrderSettlementReqVO.Item item : settlementReqVO.getItems()) { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java index 275558994..b127004aa 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java @@ -318,10 +318,16 @@ public class TradeOrderDO extends BaseDO { */ private Long combinationActivityId; /** - * 团长编号 + * 拼团团长编号 + * + * 关联 CombinationRecordDO 的 headId 字段 + */ + private Long combinationHeadId; + /** + * 拼团记录编号 * * 关联 CombinationRecordDO 的 id 字段 */ - private Long combinationHeadId; + private Long combinationRecordId; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java index 997d03077..d7eeeb191 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java @@ -47,7 +47,8 @@ public class TradeCombinationHandler implements TradeOrderHandler { // 获取商品信息 TradeOrderItemDO item = orderItems.get(0); - // 创建砍价记录 + // 创建拼团记录 + // TODO puhui:这里应该先不创建;等支付好,才去创建;另外,创建好后,需要更新编号到订单; combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, item)); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCombinationActivityPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCombinationActivityPriceCalculator.java index 18296ad63..d67ee8748 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCombinationActivityPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCombinationActivityPriceCalculator.java @@ -31,7 +31,6 @@ public class TradeCombinationActivityPriceCalculator implements TradePriceCalcul if (param.getCombinationActivityId() == null) { return; } - Assert.isTrue(param.getItems().size() == 1, "拼团时,只允许选择一个商品"); // 2. 校验是否可以参与拼团 TradePriceCalculateRespBO.OrderItem orderItem = result.getItems().get(0); From ec2c3e508a21dd28e8eb724a44b39b47809845c4 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 7 Oct 2023 13:58:12 +0800 Subject: [PATCH 06/19] =?UTF-8?q?promotion=EF=BC=9A=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E8=AE=B0=E5=BD=95=E7=9A=84=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppCombinationRecordController.java | 48 ++++++++----------- .../CombinationActivityConvert.java | 14 ++++++ .../combination/CombinationRecordDO.java | 2 +- .../combination/CombinationRecordMapper.java | 21 +++----- .../combination/CombinationRecordService.java | 4 +- .../CombinationRecordServiceImpl.java | 8 ++-- 6 files changed, 49 insertions(+), 48 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java index 280809626..ded52759c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java @@ -1,8 +1,6 @@ package cn.iocoder.yudao.module.promotion.controller.app.combination; -import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordDetailRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordSummaryRespVO; @@ -23,6 +21,7 @@ import javax.annotation.Resource; import javax.validation.constraints.Max; import java.util.Collections; import java.util.List; +import java.util.Objects; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; @@ -61,7 +60,7 @@ public class AppCombinationRecordController { @Operation(summary = "获得最近 n 条拼团记录(团长发起的)") @Parameters({ @Parameter(name = "activityId", description = "拼团活动编号"), - @Parameter(name = "status", description = "状态"), + @Parameter(name = "status", description = "拼团状态"), // 对应 CombinationRecordStatusEnum 枚举 @Parameter(name = "count", description = "数量") }) public CommonResult> getHeadCombinationRecordList( @@ -69,44 +68,37 @@ public class AppCombinationRecordController { @RequestParam("status") Integer status, @RequestParam(value = "count", defaultValue = "20") @Max(20) Integer count) { return success(CombinationActivityConvert.INSTANCE.convertList3( - combinationRecordService.getCombinationRecordListWithHead(activityId, status, count))); + combinationRecordService.getHeadCombinationRecordList(activityId, status, count))); } @GetMapping("/get-detail") @Operation(summary = "获得拼团记录明细") @Parameter(name = "id", description = "拼团记录编号", required = true, example = "1024") public CommonResult getCombinationRecordDetail(@RequestParam("id") Long id) { - // 1、查询这条记录 + // 1. 查找这条拼团记录 CombinationRecordDO record = combinationRecordService.getCombinationRecordById(id); if (record == null) { return success(null); } - AppCombinationRecordDetailRespVO detail = new AppCombinationRecordDetailRespVO(); - List records; - // 2、判断是否为团长 - if (record.getHeadId() == null) { - detail.setHeadRecord(CombinationActivityConvert.INSTANCE.convert(record)); - // 2.1、查找团员拼团记录 - records = combinationRecordService.getCombinationRecordListByHeadId(record.getId()); - } else { - // 2.2、查找团长拼团记录 - CombinationRecordDO headRecord = combinationRecordService.getCombinationRecordById(record.getHeadId()); - if (headRecord == null) { - return success(null); - } - - detail.setHeadRecord(CombinationActivityConvert.INSTANCE.convert(headRecord)); - // 2.3、查找团员拼团记录 - records = combinationRecordService.getCombinationRecordListByHeadId(headRecord.getId()); - + // 2. 查找该拼团的参团记录 + CombinationRecordDO headRecord; + List memberRecords; + if (Objects.equals(record.getHeadId(), CombinationRecordDO.HEAD_ID_GROUP)) { // 情况一:团长 + headRecord = record; + memberRecords = combinationRecordService.getCombinationRecordListByHeadId(record.getId()); + } else { // 情况二:团员 + headRecord = combinationRecordService.getCombinationRecordById(record.getHeadId()); + memberRecords = combinationRecordService.getCombinationRecordListByHeadId(headRecord.getId()); } - detail.setMemberRecords(CombinationActivityConvert.INSTANCE.convertList3(records)); - // 3、获取当前用户参团记录订单编号 - CombinationRecordDO userRecord = CollectionUtils.findFirst(records, r -> ObjectUtil.equal(r.getUserId(), getLoginUserId())); - detail.setOrderId(userRecord == null ? null : userRecord.getOrderId()); // 如果没参团,返回 null - return success(detail); + // 3. 拼接数据 + return success(CombinationActivityConvert.INSTANCE.convert(getLoginUserId(), headRecord, memberRecords)); } + // TODO @puhui:新增一个取消拼团的接口,cancel + // 1. 需要先校验拼团记录未完成; + // 2. 在 Order 那增加一个 cancelPaidOrder 接口,用于取消已支付的订单 + // 3. order 完成后,取消拼团记录。另外,如果它是团长,则顺序(下单时间)继承 + } 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 7a410f702..6b1316e71 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,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.convert.combination; +import cn.hutool.core.util.ObjectUtil; 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; @@ -16,6 +17,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityDetailRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityRespVO; +import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordDetailRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordRespVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; @@ -168,4 +170,16 @@ public interface CombinationActivityConvert { PageResult convert(PageResult result); + default AppCombinationRecordDetailRespVO convert(Long userId, CombinationRecordDO headRecord, List memberRecords) { + AppCombinationRecordDetailRespVO respVO = new AppCombinationRecordDetailRespVO() + .setHeadRecord(convert(headRecord)).setMemberRecords(convertList3(memberRecords)); + // 处理自己参与拼团的 orderId + CombinationRecordDO userRecord = CollectionUtils.findFirst(memberRecords, r -> ObjectUtil.equal(r.getUserId(), userId)); + if (userRecord == null && ObjectUtil.equal(headRecord.getUserId(), userId)) { + userRecord = headRecord; + } + respVO.setOrderId(userRecord == null ? null : userRecord.getOrderId()); + return respVO; + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java index faf65a2c6..07d40d1e5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java @@ -31,7 +31,7 @@ public class CombinationRecordDO extends BaseDO { /** * 团长编号 - 团长 */ - public static final Integer HEAD_ID_GROUP = 0; + public static final Long HEAD_ID_GROUP = 0L; /** * 编号,主键自增 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 691044dc9..f6b6cf59f 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 @@ -81,25 +81,18 @@ public interface CombinationRecordMapper extends BaseMapperX selectList(Long activityId, Integer status, Integer count) { + default List selectListByActivityIdAndStatusAndHeadId(Long activityId, Integer status, + Long headId, Integer count) { return selectList(new LambdaQueryWrapperX() - .eqIfPresent(CombinationRecordDO::getActivityId, activityId) - .eqIfPresent(CombinationRecordDO::getStatus, status) - .eq(CombinationRecordDO::getHeadId, null) // TODO 团长的 headId 是不是 null 还是自己的记录编号来着? - .orderByDesc(CombinationRecordDO::getCreateTime) + .eq(CombinationRecordDO::getActivityId, activityId) + .eq(CombinationRecordDO::getStatus, status) + .eq(CombinationRecordDO::getHeadId, headId) + .orderByDesc(CombinationRecordDO::getId) .last("LIMIT " + count)); } default Map selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(Collection activityIds, - Integer status, Integer headId) { + Integer status, Long headId) { // SQL count 查询 List> result = selectMaps(new QueryWrapper() .select("COUNT(DISTINCT(user_id)) AS recordCount, activity_id AS activityId") 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 43372f674..08ec022dc 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 @@ -136,7 +136,7 @@ public interface CombinationRecordService { * @param count 数量 * @return 拼团记录列表 */ - List getCombinationRecordListWithHead(Long activityId, Integer status, Integer count); + List getHeadCombinationRecordList(Long activityId, Integer status, Integer count); /** * 获取指定编号的拼团记录 @@ -172,6 +172,6 @@ public interface CombinationRecordService { */ Map getCombinationRecordCountMapByActivity(Collection activityIds, @Nullable Integer status, - @Nullable Integer headId); + @Nullable Long headId); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 9b6212579..140c8ae9f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -204,6 +204,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); + // TODO @puhui999:status 未设置;headId 未设置 recordMapper.insert(CombinationActivityConvert.INSTANCE.convert(reqDTO, activity, user, spu, sku)); } @@ -253,8 +254,9 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } @Override - public List getCombinationRecordListWithHead(Long activityId, Integer status, Integer count) { - return recordMapper.selectList(activityId, status, count); + public List getHeadCombinationRecordList(Long activityId, Integer status, Integer count) { + return recordMapper.selectListByActivityIdAndStatusAndHeadId(activityId, status, + CombinationRecordDO.HEAD_ID_GROUP, count); } @Override @@ -274,7 +276,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Override public Map getCombinationRecordCountMapByActivity(Collection activityIds, - @Nullable Integer status, @Nullable Integer headId) { + @Nullable Integer status, @Nullable Long headId) { return recordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId); } From f40bd23f6a168ef63d7169af0148a597d4cb9627 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sat, 7 Oct 2023 14:30:25 +0800 Subject: [PATCH 07/19] =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=EF=BC=9A=E5=AE=8C=E5=96=84=E6=8B=BC=E5=9B=A2=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=89=8D=E7=9A=84=E6=9D=A1=E4=BB=B6=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/combination/CombinationRecordApi.java | 11 +- .../promotion/enums/ErrorCodeConstants.java | 2 +- .../CombinationRecordStatusEnum.java | 4 + .../combination/CombinationRecordApiImpl.java | 19 +++- .../activity/CombinationActivityBaseVO.java | 5 +- .../combination/CombinationRecordMapper.java | 18 ++- .../combination/CombinationRecordService.java | 17 +-- .../CombinationRecordServiceImpl.java | 106 ++++++++++-------- .../handler/TradeCombinationHandler.java | 3 +- ...adeCombinationActivityPriceCalculator.java | 3 +- 10 files changed, 117 insertions(+), 71 deletions(-) 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 cc3fd443a..06a24f305 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 @@ -18,12 +18,13 @@ public interface CombinationRecordApi { /** * 校验是否满足拼团条件 * - * @param activityId 活动编号 * @param userId 用户编号 + * @param activityId 活动编号 + * @param headId 团长编号 * @param skuId sku 编号 * @param count 数量 */ - void validateCombinationRecord(Long activityId, Long userId, Long skuId, Integer count); + void validateCombinationRecord(Long userId, Long activityId, Long headId, Long skuId, Integer count); /** * 创建开团记录 @@ -71,13 +72,13 @@ public interface CombinationRecordApi { * * 如果校验失败,则抛出业务异常 * - * @param activityId 活动编号 * @param userId 用户编号 + * @param activityId 活动编号 + * @param headId 团长编号 * @param skuId sku 编号 * @param count 数量 * @return 拼团信息 */ - // TODO @puhui:userId 放最前面;然后应该还有个 headId 参数; - CombinationValidateJoinRespDTO validateJoinCombination(Long activityId, Long userId, Long skuId, Integer count); + CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count); } 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 c1130f221..dc4f0ee08 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 @@ -80,7 +80,7 @@ public interface ErrorCodeConstants { ErrorCode COMBINATION_RECORD_EXISTS = new ErrorCode(1_013_011_001, "拼团失败,已参与过该拼团"); ErrorCode COMBINATION_RECORD_HEAD_NOT_EXISTS = new ErrorCode(1_013_011_002, "拼团失败,父拼团不存在"); ErrorCode COMBINATION_RECORD_USER_FULL = new ErrorCode(1_013_011_003, "拼团失败,拼团人数已满"); - ErrorCode COMBINATION_RECORD_FAILED_HAVE_JOINED = new ErrorCode(1_013_011_004, "拼团失败,已参与其它拼团"); + ErrorCode COMBINATION_RECORD_FAILED_HAVE_JOINED = new ErrorCode(1_013_011_004, "拼团失败,原因:存在该活动正在进行的拼团记录"); ErrorCode COMBINATION_RECORD_FAILED_TIME_NOT_START = new ErrorCode(1_013_011_005, "拼团失败,活动未开始"); ErrorCode COMBINATION_RECORD_FAILED_TIME_END = new ErrorCode(1_013_011_006, "拼团失败,活动已经结束"); ErrorCode COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED = new ErrorCode(1_013_011_007, "拼团失败,原因:单次限购超出"); 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 index d1e6114a1..2d12b2048 100644 --- 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 @@ -40,4 +40,8 @@ public enum CombinationRecordStatusEnum implements IntArrayValuable { return ObjectUtil.equal(status, SUCCESS.getStatus()); } + public static boolean isInProgress(Integer status) { + return ObjectUtil.equal(status, IN_PROGRESS.getStatus()); + } + } 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 a32d35e29..b30bdab8d 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 @@ -2,6 +2,7 @@ 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.CombinationValidateJoinRespDTO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; import org.springframework.stereotype.Service; @@ -9,6 +10,9 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.time.LocalDateTime; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_RECORD_NOT_EXISTS; + /** * 拼团活动 API 实现类 * @@ -21,8 +25,8 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { private CombinationRecordService recordService; @Override - public void validateCombinationRecord(Long activityId, Long userId, Long skuId, Integer count) { - recordService.validateCombinationRecord(activityId, userId, skuId, count); + public void validateCombinationRecord(Long userId, Long activityId, Long headId, Long skuId, Integer count) { + recordService.validateCombinationRecord(userId, activityId, headId, skuId, count); } @Override @@ -32,7 +36,12 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { @Override public boolean isCombinationRecordSuccess(Long userId, Long orderId) { - return CombinationRecordStatusEnum.isSuccess(recordService.getCombinationRecord(userId, orderId).getStatus()); + CombinationRecordDO combinationRecord = recordService.getCombinationRecord(userId, orderId); + if (combinationRecord == null) { + throw exception(COMBINATION_RECORD_NOT_EXISTS); + } + + return CombinationRecordStatusEnum.isSuccess(combinationRecord.getStatus()); } @Override @@ -52,8 +61,8 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { } @Override - public CombinationValidateJoinRespDTO validateJoinCombination(Long activityId, Long userId, Long skuId, Integer count) { - return recordService.validateJoinCombination(activityId, userId, skuId, count); + public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count) { + return recordService.validateJoinCombination(userId, activityId, headId, skuId, count); } } 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 edb85e5e6..4b3abeab4 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 @@ -48,8 +48,9 @@ public class CombinationActivityBaseVO { @NotNull(message = "开团人数不能为空") private Integer userSize; - @Schema(description = "虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Boolean virtualGroup = false; // TODO @puhui999:这个字段界面没做呀。 + @Schema(description = "虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "false") + @NotNull(message = "虚拟成团不能为空") + private Boolean virtualGroup; @Schema(description = "限制时长(小时)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @NotNull(message = "限制时长不能为空") 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 691044dc9..163b5eef0 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 @@ -113,7 +113,7 @@ public interface CombinationRecordMapper extends BaseMapperX MapUtil.getLong(record, "activityId"), - record -> MapUtil.getInt(record, "recordCount" )); + record -> MapUtil.getInt(record, "recordCount")); } static LocalDateTime[] builderQueryTime(Integer dateType) { @@ -172,4 +172,20 @@ public interface CombinationRecordMapper extends BaseMapperX selectList(Long activityId, Long headId) { + return selectList(new LambdaQueryWrapperX() + .eq(CombinationRecordDO::getActivityId, activityId) + .eq(CombinationRecordDO::getHeadId, headId) + .or() + .eq(CombinationRecordDO::getId, headId)); + + } + } 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 43372f674..68f218d59 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 @@ -32,16 +32,18 @@ public interface CombinationRecordService { void updateCombinationRecordStatusByUserIdAndOrderId(Integer status, Long userId, Long orderId); /** - * 校验是否满足拼团条件 - * 如果不满足,会抛出异常 + * 【下单前】校验是否满足拼团活动条件 + * + * 如果校验失败,则抛出业务异常 * - * @param activityId 活动编号 * @param userId 用户编号 + * @param activityId 活动编号 + * @param headId 团长编号 * @param skuId sku 编号 * @param count 数量 - * @return 返回拼团活动和拼团活动商品 + * @return 拼团信息 */ - KeyValue validateCombinationRecord(Long activityId, Long userId, Long skuId, Integer count); + KeyValue validateCombinationRecord(Long userId, Long activityId, Long headId, Long skuId, Integer count); /** * 创建拼团记录 @@ -83,13 +85,14 @@ public interface CombinationRecordService { * * 如果校验失败,则抛出业务异常 * - * @param activityId 活动编号 * @param userId 用户编号 + * @param activityId 活动编号 + * @param headId 团长编号 * @param skuId sku 编号 * @param count 数量 * @return 拼团信息 */ - CombinationValidateJoinRespDTO validateJoinCombination(Long activityId, Long userId, Long skuId, Integer count); + CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count); /** * 获取所有拼团记录数 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 9b6212579..25445d4b2 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.module.promotion.service.combination; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; @@ -37,6 +37,8 @@ import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.afterNow; +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.beforeNow; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; // TODO 芋艿:等拼团记录做完,完整 review 下 @@ -114,48 +116,83 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { // TODO @芋艿:在详细预览下; @Override public KeyValue validateCombinationRecord( - Long activityId, Long userId, Long skuId, Integer count) { - // 1.1 校验拼团活动是否存在 + Long userId, Long activityId, Long headId, Long skuId, Integer count) { + // 1 校验拼团活动是否存在 CombinationActivityDO activity = combinationActivityService.validateCombinationActivityExists(activityId); - // 1.2 校验活动是否开启 - if (ObjectUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { + // 1.1 校验活动是否开启 + if (ObjUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE); } - // 2 校验是否超出单次限购数量 + // 1.2、校验活动开始时间 + if (afterNow(activity.getStartTime())) { + throw exception(COMBINATION_RECORD_FAILED_TIME_NOT_START); + } + // 1.3 校验是否超出单次限购数量 if (count > activity.getSingleLimitCount()) { throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED); } - // 2.1、校验活动商品是否存在 + + // 2、父拼团是否存在,是否已经满了 + if (headId != null) { + // 2.1、查询进行中的父拼团 + CombinationRecordDO record = recordMapper.selectOneByHeadId(headId, CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); + if (record == null) { + throw exception(COMBINATION_RECORD_HEAD_NOT_EXISTS); + } + // 2.2、校验拼团是否满足要求 + if (ObjUtil.equal(record.getUserCount(), record.getUserSize())) { + throw exception(COMBINATION_RECORD_USER_FULL); + } + // 2.3、校验拼团是否过期 + if (beforeNow(record.getExpireTime())) { + throw exception(COMBINATION_RECORD_FAILED_TIME_END); + } + } + + // 3、校验当前活动是否结束 + if (beforeNow(activity.getEndTime())) { + throw exception(COMBINATION_RECORD_FAILED_TIME_END); + } + + // 4、校验活动商品是否存在 CombinationProductDO product = combinationActivityService.selectByActivityIdAndSkuId(activityId, skuId); if (product == null) { throw exception(COMBINATION_JOIN_ACTIVITY_PRODUCT_NOT_EXISTS); } - // 2.2、校验 sku 是否存在 + + // 5、校验 sku 是否存在 ProductSkuRespDTO sku = productSkuApi.getSku(skuId); if (sku == null) { throw exception(COMBINATION_JOIN_ACTIVITY_PRODUCT_NOT_EXISTS); } - // 2.3、 校验库存是否充足 + // 5.1、校验库存是否充足 if (count > sku.getStock()) { throw exception(COMBINATION_ACTIVITY_UPDATE_STOCK_FAIL); } - // 3、校验是否有拼团记录 + + // 6、校验是否有拼团记录 List recordList = getCombinationRecordListByUserIdAndActivityId(userId, activityId); if (CollUtil.isEmpty(recordList)) { return new KeyValue<>(activity, product); } - // 4、校验是否超出总限购数量 + // 6.1、校验用户是否有该活动正在进行的拼团 + List filtered = filterList(recordList, record -> CombinationRecordStatusEnum.isInProgress(record.getStatus())); + if (CollUtil.isNotEmpty(filtered)) { + throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED); + } + // 6.2、校验是否超出总限购数量 Integer sumValue = getSumValue(convertList(recordList, CombinationRecordDO::getCount, - item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())), i -> i, Integer::sum); + item -> CombinationRecordStatusEnum.isSuccess(item.getStatus())), i -> i, Integer::sum); if ((sumValue + count) > activity.getTotalLimitCount()) { throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED); } - // 5、校验拼团记录是否存在未支付的订单(如果存在未支付的订单则不允许发起新的拼团) + + // 7、校验拼团记录是否存在未支付的订单(如果存在未支付的订单则不允许发起新的拼团) CombinationRecordDO record = findFirst(recordList, item -> ObjectUtil.equals(item.getStatus(), null)); if (record == null) { return new KeyValue<>(activity, product); } - // 5.1、查询关联的订单是否已经支付 + // 7.1、查询关联的订单是否已经支付 // 当前 activityId 已经有未支付的订单,不允许在发起新的;要么支付,要么去掉先; // TODO 芋艿:看看是不是可以删除掉; Integer orderStatus = tradeOrderApi.getOrderStatus(record.getOrderId()); @@ -171,46 +208,19 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Transactional(rollbackFor = Exception.class) public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { // 1、校验拼团活动 - KeyValue keyValue = validateCombinationRecord( - reqDTO.getActivityId(), reqDTO.getUserId(), reqDTO.getSkuId(), reqDTO.getCount()); - CombinationActivityDO activity = keyValue.getKey(); - // 2、校验用户是否参加了其它拼团 - List recordDOList = recordMapper.selectListByUserIdAndStatus(reqDTO.getUserId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); - if (CollUtil.isNotEmpty(recordDOList)) { - throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED); - } - // 3、校验活动是否开启 - if (!LocalDateTimeUtils.beforeNow(activity.getStartTime())) { - throw exception(COMBINATION_RECORD_FAILED_TIME_NOT_START); - } - // 4、校验当前活动是否过期 - if (LocalDateTime.now().isAfter(activity.getEndTime())) { - throw exception(COMBINATION_RECORD_FAILED_TIME_END); - } - // 5、父拼团是否存在,是否已经满了 - if (reqDTO.getHeadId() != null) { - // 5.1、查询进行中的父拼团 - CombinationRecordDO record = recordMapper.selectOneByHeadId(reqDTO.getHeadId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); - if (record == null) { - throw exception(COMBINATION_RECORD_HEAD_NOT_EXISTS); - } - // 5.2、校验拼团是否满足要求 - if (ObjectUtil.equal(record.getUserCount(), record.getUserSize())) { - throw exception(COMBINATION_RECORD_USER_FULL); - } - } + KeyValue keyValue = validateCombinationRecord(reqDTO.getUserId(), + reqDTO.getActivityId(), reqDTO.getHeadId(), reqDTO.getSkuId(), reqDTO.getCount()); - // 6. 创建拼团记录 + // 2. 组合数据创建拼团记录 MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); - recordMapper.insert(CombinationActivityConvert.INSTANCE.convert(reqDTO, activity, user, spu, sku)); + recordMapper.insert(CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku)); } @Override public CombinationRecordDO getCombinationRecord(Long userId, Long orderId) { - // TODO puhui999:这里直接获得,不适合调用校验的接口; - return validateCombinationRecord(userId, orderId); + return recordMapper.selectByUserIdAndOrderId(userId, orderId); } @Override @@ -219,8 +229,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } @Override - public CombinationValidateJoinRespDTO validateJoinCombination(Long activityId, Long userId, Long skuId, Integer count) { - KeyValue keyValue = validateCombinationRecord(activityId, userId, skuId, count); + public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count) { + KeyValue keyValue = validateCombinationRecord(userId, activityId, headId, skuId, count); return new CombinationValidateJoinRespDTO() .setActivityId(keyValue.getKey().getId()) .setName(keyValue.getKey().getName()) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java index d7eeeb191..95262f95c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java @@ -34,7 +34,8 @@ public class TradeCombinationHandler implements TradeOrderHandler { // 获取商品信息 TradeOrderItemDO item = orderItems.get(0); // 校验是否满足拼团活动相关限制 - combinationRecordApi.validateCombinationRecord(order.getCombinationActivityId(), order.getUserId(), item.getSkuId(), item.getCount()); + combinationRecordApi.validateCombinationRecord(order.getUserId(), order.getCombinationActivityId(), + order.getCombinationHeadId(), item.getSkuId(), item.getCount()); } @Override diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCombinationActivityPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCombinationActivityPriceCalculator.java index d67ee8748..4021bbeae 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCombinationActivityPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCombinationActivityPriceCalculator.java @@ -13,6 +13,7 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; // TODO @puhui999:单测可以后补下 + /** * 拼团活动的 {@link TradePriceCalculator} 实现类 * @@ -35,7 +36,7 @@ public class TradeCombinationActivityPriceCalculator implements TradePriceCalcul // 2. 校验是否可以参与拼团 TradePriceCalculateRespBO.OrderItem orderItem = result.getItems().get(0); CombinationValidateJoinRespDTO combinationActivity = combinationRecordApi.validateJoinCombination( - param.getCombinationActivityId(), param.getUserId(), + param.getUserId(), param.getCombinationActivityId(), param.getCombinationHeadId(), orderItem.getSkuId(), orderItem.getCount()); // 3.1 记录优惠明细 From c485c6e04de2f1d1a0db144e32c44f15c3bfadfd Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sat, 7 Oct 2023 16:30:28 +0800 Subject: [PATCH 08/19] =?UTF-8?q?=E8=AE=A2=E5=8D=95=EF=BC=9A=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E6=8B=BC=E5=9B=A2=E4=B8=8B=E5=8D=95=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=B8=BA=E8=AE=A2=E5=8D=95=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=90=8E=E5=86=8D=E5=88=9B=E5=BB=BA=E6=8B=BC=E5=9B=A2=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/combination/CombinationRecordApi.java | 18 --- .../combination/CombinationRecordApiImpl.java | 12 -- .../CombinationActivityConvert.java | 9 +- .../combination/CombinationRecordMapper.java | 6 - .../combination/CombinationRecordService.java | 11 -- .../CombinationRecordServiceImpl.java | 112 ++++++++++-------- .../module/trade/api/order/TradeOrderApi.java | 19 +-- .../trade/api/order/TradeOrderApiImpl.java | 22 ++-- .../vo/AppTradeOrderSettlementReqVO.java | 1 - .../order/TradeOrderUpdateService.java | 10 ++ .../order/TradeOrderUpdateServiceImpl.java | 19 ++- .../handler/TradeCombinationHandler.java | 15 +-- .../order/handler/TradeOrderHandler.java | 4 +- .../price/bo/TradePriceCalculateReqBO.java | 1 - 14 files changed, 118 insertions(+), 141 deletions(-) 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 06a24f305..a086ecb4d 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 @@ -4,7 +4,6 @@ import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCr import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; import javax.validation.Valid; -import java.time.LocalDateTime; // TODO @芋艿:后面也再撸撸这几个接口 @@ -42,14 +41,6 @@ public interface CombinationRecordApi { */ boolean isCombinationRecordSuccess(Long userId, Long orderId); - /** - * 更新拼团状态为【成功】 - * - * @param userId 用户编号 - * @param orderId 订单编号 - */ - void updateRecordStatusToSuccess(Long userId, Long orderId); - /** * 更新拼团状态为【失败】 * @@ -58,15 +49,6 @@ public interface CombinationRecordApi { */ void updateRecordStatusToFailed(Long userId, Long orderId); - /** - * 更新拼团状态为 进行中 - * - * @param userId 用户编号 - * @param orderId 订单编号 - * @param startTime 开始时间 - */ - void updateRecordStatusToInProgress(Long userId, Long orderId, LocalDateTime startTime); - /** * 【下单前】校验是否满足拼团活动条件 * 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 b30bdab8d..75e5591d3 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 @@ -8,7 +8,6 @@ import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordSe import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_RECORD_NOT_EXISTS; @@ -44,22 +43,11 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { return CombinationRecordStatusEnum.isSuccess(combinationRecord.getStatus()); } - @Override - public void updateRecordStatusToSuccess(Long userId, Long orderId) { - recordService.updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordStatusEnum.SUCCESS.getStatus(), userId, orderId); - } - @Override public void updateRecordStatusToFailed(Long userId, Long orderId) { recordService.updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordStatusEnum.FAILED.getStatus(), userId, orderId); } - @Override - public void updateRecordStatusToInProgress(Long userId, Long orderId, LocalDateTime startTime) { - recordService.updateRecordStatusAndStartTimeByUserIdAndOrderId(CombinationRecordStatusEnum.IN_PROGRESS.getStatus(), - userId, orderId, startTime); - } - @Override public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count) { return recordService.validateJoinCombination(userId, activityId, headId, skuId, count); 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 6b1316e71..d2e8fe9ff 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 @@ -22,11 +22,13 @@ import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.Ap import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; +import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; +import java.time.LocalDateTime; import java.util.List; import java.util.Map; @@ -110,14 +112,19 @@ public interface CombinationActivityConvert { CombinationActivityDO activity, MemberUserRespDTO user, ProductSpuRespDTO spu, ProductSkuRespDTO sku) { return convert(reqDTO) - .setCount(reqDTO.getCount()).setUserCount(1) + .setHeadId(reqDTO.getHeadId()) // 显示性再设置一下 + .setCount(reqDTO.getCount()) .setVirtualGroup(false) + .setStatus(CombinationRecordStatusEnum.IN_PROGRESS.getStatus()) // 创建后默认状态为进行中 + .setStartTime(LocalDateTime.now()) .setExpireTime(activity.getStartTime().plusHours(activity.getLimitDuration())) .setUserSize(activity.getUserSize()) + .setUserCount(1) // 默认就是 1 插入后会接着更新一次所有的拼团记录 .setNickname(user.getNickname()) .setAvatar(user.getAvatar()) .setSpuName(spu.getName()) .setPicUrl(sku.getPicUrl()); + } List convertAppList(List list); 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 494b89974..6226cb2eb 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 @@ -32,12 +32,6 @@ public interface CombinationRecordMapper extends BaseMapperX selectListByUserIdAndStatus(Long userId, Integer status) { - return selectList(new LambdaQueryWrapperX() - .eq(CombinationRecordDO::getUserId, userId) - .eq(CombinationRecordDO::getStatus, status)); - } - /** * 查询拼团记录 * 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 80408560b..3e8a97c0e 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 @@ -10,7 +10,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationP import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; import javax.annotation.Nullable; -import java.time.LocalDateTime; import java.util.Collection; import java.util.List; import java.util.Map; @@ -52,16 +51,6 @@ public interface CombinationRecordService { */ void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO); - /** - * 更新拼团状态和开始时间 - * - * @param status 状态 - * @param userId 用户编号 - * @param orderId 订单编号 - * @param startTime 开始时间 - */ - void updateRecordStatusAndStartTimeByUserIdAndOrderId(Integer status, Long userId, Long orderId, LocalDateTime startTime); - /** * 获得拼团记录 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 6a9a53a80..47e7c552a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.promotion.service.combination; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjUtil; -import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -22,7 +21,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationR import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationRecordMapper; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; -import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -30,7 +28,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Nullable; import javax.annotation.Resource; -import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; @@ -80,30 +78,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { recordMapper.updateById(record); } - @Override - @Transactional(rollbackFor = Exception.class) - public void updateRecordStatusAndStartTimeByUserIdAndOrderId(Integer status, Long userId, Long orderId, LocalDateTime startTime) { - CombinationRecordDO record = validateCombinationRecord(userId, orderId); - // 更新状态 - record.setStatus(status); - // 更新开始时间 - record.setStartTime(startTime); - recordMapper.updateById(record); - - // 更新拼团参入人数 - List records = recordMapper.selectListByHeadIdAndStatus(record.getHeadId(), status); - if (CollUtil.isNotEmpty(records)) { - records.forEach(item -> { - item.setUserCount(records.size()); - // 校验拼团是否满足要求 - if (ObjectUtil.equal(records.size(), record.getUserSize())) { - item.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus()); - } - }); - recordMapper.updateBatch(records); - } - } - private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) { // 校验拼团是否存在 CombinationRecordDO recordDO = recordMapper.selectByUserIdAndOrderId(userId, orderId); @@ -143,15 +117,15 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { if (ObjUtil.equal(record.getUserCount(), record.getUserSize())) { throw exception(COMBINATION_RECORD_USER_FULL); } - // 2.3、校验拼团是否过期 + // 2.3、校验拼团是否过期(有父拼团的时候只校验父拼团的过期时间) if (beforeNow(record.getExpireTime())) { throw exception(COMBINATION_RECORD_FAILED_TIME_END); } - } - - // 3、校验当前活动是否结束 - if (beforeNow(activity.getEndTime())) { - throw exception(COMBINATION_RECORD_FAILED_TIME_END); + } else { + // 3、校验当前活动是否结束(自己是父拼团的时候才校验活动是否结束) + if (beforeNow(activity.getEndTime())) { + throw exception(COMBINATION_RECORD_FAILED_TIME_END); + } } // 4、校验活动商品是否存在 @@ -187,19 +161,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED); } - // 7、校验拼团记录是否存在未支付的订单(如果存在未支付的订单则不允许发起新的拼团) - CombinationRecordDO record = findFirst(recordList, item -> ObjectUtil.equals(item.getStatus(), null)); - if (record == null) { - return new KeyValue<>(activity, product); - } - // 7.1、查询关联的订单是否已经支付 - // 当前 activityId 已经有未支付的订单,不允许在发起新的;要么支付,要么去掉先; - // TODO 芋艿:看看是不是可以删除掉; - Integer orderStatus = tradeOrderApi.getOrderStatus(record.getOrderId()); - if (ObjectUtil.equal(orderStatus, TradeOrderStatusEnum.UNPAID.getStatus())) { - throw exception(COMBINATION_RECORD_FAILED_ORDER_STATUS_UNPAID); - } - return new KeyValue<>(activity, product); } @@ -215,9 +176,62 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); - recordMapper.insert(CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku)); - // TODO @puhui999:status 未设置;headId 未设置 - recordMapper.insert(CombinationActivityConvert.INSTANCE.convert(reqDTO, activity, user, spu, sku)); + CombinationRecordDO recordDO = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku); + recordMapper.insert(recordDO); + + // 3、如果是团长需要设置 headId 为它自己 + if (reqDTO.getHeadId() == null) { + recordMapper.updateById(new CombinationRecordDO().setId(recordDO.getId()).setHeadId(recordDO.getId())); + return; + } + + // TODO 这里要不要弄成异步的 + // 4、更新拼团相关信息到订单 + updateOrderCombinationInfo(recordDO.getOrderId(), recordDO.getActivityId(), recordDO.getId(), recordDO.getHeadId()); + // 4、更新拼团记录 + updateCombinationRecords(keyValue.getKey(), reqDTO.getHeadId()); + + } + + /** + * 更新拼团相关信息到订单 + * + * @param orderId 订单编号 + * @param activityId 拼团活动编号 + * @param combinationRecordId 拼团记录编号 + * @param headId 团长编号 + */ + private void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) { + tradeOrderApi.updateOrderCombinationInfo(orderId, activityId, combinationRecordId, headId); + } + + /** + * 更新拼团记录 + * + * @param activity 活动 + * @param headId 团长编号 + */ + private void updateCombinationRecords(CombinationActivityDO activity, Long headId) { + List records = recordMapper.selectList(CombinationRecordDO::getHeadId, headId); + List updateRecords = new ArrayList<>(); + + if (CollUtil.isEmpty(records)) { + return; + } + + boolean isEqual = ObjUtil.equal(records.size(), activity.getUserSize()); + records.forEach(item -> { + CombinationRecordDO recordDO = new CombinationRecordDO(); + recordDO.setId(item.getId()); + recordDO.setUserCount(records.size()); + // 校验拼团是否满足要求 + if (isEqual) { + recordDO.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus()); + } + updateRecords.add(recordDO); + }); + + recordMapper.updateBatch(updateRecords); } @Override diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java index 0a6620c14..0d72a75e8 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java @@ -30,15 +30,6 @@ public interface TradeOrderApi { */ TradeOrderRespDTO getOrder(Long id); - // TODO 芋艿:看看是不是可以删除掉; - /** - * 获取订单状态 - * - * @param id 订单编号 - * @return 订单状态 - */ - Integer getOrderStatus(Long id); - /** * 获取订单统计 * @@ -48,4 +39,14 @@ public interface TradeOrderApi { */ TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime); + /** + * 更新拼团相关信息到订单 + * + * @param orderId 订单编号 + * @param activityId 拼团活动编号 + * @param combinationRecordId 拼团记录编号 + * @param headId 团长编号 + */ + void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java index 39f554e29..ed1ee1f26 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java @@ -3,20 +3,16 @@ package cn.iocoder.yudao.module.trade.api.order; import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; +import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; 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 static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND; - /** * 订单 API 接口实现类 * @@ -28,6 +24,8 @@ public class TradeOrderApiImpl implements TradeOrderApi { @Resource private TradeOrderQueryService tradeOrderQueryService; + @Resource + private TradeOrderUpdateService tradeOrderUpdateService; @Override public List getOrderList(Collection ids) { @@ -39,18 +37,14 @@ public class TradeOrderApiImpl implements TradeOrderApi { return TradeOrderConvert.INSTANCE.convert(tradeOrderQueryService.getOrder(id)); } - @Override - public Integer getOrderStatus(Long id) { - TradeOrderDO order = tradeOrderQueryService.getOrder(id); - if (order == null) { - throw exception(ORDER_NOT_FOUND); - } - return order.getStatus(); - } - @Override public TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime) { return tradeOrderQueryService.getOrderSummary(beginTime, endTime); } + @Override + public void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) { + tradeOrderUpdateService.updateOrderCombinationInfo(orderId, activityId, combinationRecordId, headId); + } + } 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 153e09905..e8ed038ff 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 @@ -52,7 +52,6 @@ public class AppTradeOrderSettlementReqVO { private Long seckillActivityId; // ========== 拼团活动相关字段 ========== - // TODO @puhui999:是不是拼团记录的编号哈? @Schema(description = "拼团活动编号", example = "1024") private Long combinationActivityId; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java index ffadb15e4..bc8413b3d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java @@ -170,4 +170,14 @@ public interface TradeOrderUpdateService { */ int createOrderItemCommentBySystem(); + /** + * 更新拼团相关信息到订单 + * + * @param orderId 订单编号 + * @param activityId 拼团活动编号 + * @param combinationRecordId 拼团记录编号 + * @param headId 团长编号 + */ + void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index df6767a05..a0bd13f44 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -250,7 +250,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { /** * 订单创建前,执行前置逻辑 * - * @param order 订单 + * @param order 订单 * @param orderItems 订单项 */ private void beforeCreateTradeOrder(TradeOrderDO order, List orderItems) { @@ -267,9 +267,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { *

* 例如说:优惠劵的扣减、积分的扣减、支付单的创建等等 * - * @param order 订单 - * @param orderItems 订单项 - * @param createReqVO 创建订单请求 + * @param order 订单 + * @param orderItems 订单项 + * @param createReqVO 创建订单请求 */ private void afterCreateTradeOrder(TradeOrderDO order, List orderItems, AppTradeOrderCreateReqVO createReqVO) { @@ -331,7 +331,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { } // 3、订单支付成功后 - tradeOrderHandlers.forEach(handler -> handler.afterPayOrder(order)); + List orderItems = tradeOrderItemMapper.selectListByOrderId(id); + tradeOrderHandlers.forEach(handler -> handler.afterPayOrder(order, orderItems)); // 4.1 增加用户积分(赠送) addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_GIVE, order.getId()); @@ -909,6 +910,14 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { return count; } + @Override + @Transactional(rollbackFor = Exception.class) + public void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) { + tradeOrderMapper.updateById( + new TradeOrderDO().setId(orderId).setCombinationActivityId(activityId) + .setCombinationRecordId(combinationRecordId).setCombinationHeadId(headId)); + } + /** * 创建单个订单的评论 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java index 95262f95c..f34da9616 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java @@ -39,29 +39,18 @@ public class TradeCombinationHandler implements TradeOrderHandler { } @Override - public void afterOrderCreate(TradeOrderDO order, List orderItems) { + public void afterPayOrder(TradeOrderDO order, List orderItems) { // 如果不是拼团订单则结束 if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { return; } + Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品"); // 获取商品信息 TradeOrderItemDO item = orderItems.get(0); // 创建拼团记录 - // TODO puhui:这里应该先不创建;等支付好,才去创建;另外,创建好后,需要更新编号到订单; combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, item)); } - @Override - public void afterPayOrder(TradeOrderDO order) { - // 如果不是拼团订单则结束 - if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { - return; - } - - // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 - combinationRecordApi.updateRecordStatusToInProgress(order.getUserId(), order.getId(), order.getPayTime()); - } - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java index eb00c9121..81c41650a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java @@ -33,8 +33,10 @@ public interface TradeOrderHandler { * 支付订单后 * * @param order 订单 + * @param orderItems 订单项 */ - default void afterPayOrder(TradeOrderDO order) {} + default void afterPayOrder(TradeOrderDO order, List orderItems) { + } /** * 订单取消 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java index dac92e743..295dcd3bc 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java @@ -68,7 +68,6 @@ public class TradePriceCalculateReqBO { private Long seckillActivityId; // ========== 拼团活动相关字段 ========== - // TODO @puhui999:是不是拼团记录的编号哈? /** * 拼团活动编号 */ From 89b240c1f946d7b6035fa66a5ad70be43a43d3e4 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sat, 7 Oct 2023 16:58:40 +0800 Subject: [PATCH 09/19] =?UTF-8?q?=E8=AE=A2=E5=8D=95=EF=BC=9A=E4=BB=8B?= =?UTF-8?q?=E5=85=A5=20TradeOrderHandler#cancelOrder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/enums/order/TradeOrderTypeEnum.java | 17 +++++++++++++++++ .../order/TradeOrderUpdateServiceImpl.java | 10 +++++----- .../order/handler/TradeBargainHandler.java | 15 +++++++++++---- .../order/handler/TradeCombinationHandler.java | 12 +++++++++--- .../order/handler/TradeOrderHandler.java | 6 +++++- .../order/handler/TradeSeckillHandler.java | 12 ++++++++++-- 6 files changed, 57 insertions(+), 15 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderTypeEnum.java index 27596197f..f82071206 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderTypeEnum.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.trade.enums.order; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.core.IntArrayValuable; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -37,4 +38,20 @@ public enum TradeOrderTypeEnum implements IntArrayValuable { return ARRAYS; } + public static boolean isNormal(Integer type) { + return ObjectUtil.equal(type, NORMAL.getType()); + } + + public static boolean isSeckill(Integer type) { + return ObjectUtil.equal(type, SECKILL.getType()); + } + + public static boolean isBargain(Integer type) { + return ObjectUtil.equal(type, BARGAIN.getType()); + } + + public static boolean isCombination(Integer type) { + return ObjectUtil.equal(type, COMBINATION.getType()); + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index a0bd13f44..7c5ed91b3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -625,12 +625,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID); } - // 2. TODO 活动相关库存回滚需要活动 id,活动 id 怎么获取?app 端能否传过来;回复:从订单里拿呀 - tradeOrderHandlers.forEach(handler -> handler.cancelOrder()); - - // 3. 回滚库存 List orderItems = tradeOrderItemMapper.selectListByOrderId(id); + // 3. 回滚库存 productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems)); + // 3.1、 活动相关的回滚 + tradeOrderHandlers.forEach(handler -> handler.cancelOrder(order, orderItems)); // 4. 回滚优惠券 if (order.getCouponId() != null && order.getCouponId() > 0) { @@ -807,10 +806,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 2.2 如果全部退款,则进行取消订单 getSelf().cancelOrderByAfterSale(order, orderRefundPrice); - // TODO @puhui999:活动相关的回滚 // 3. 回滚库存 productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(Collections.singletonList(orderItem))); + // 3.1、 活动相关的回滚 + tradeOrderHandlers.forEach(handler -> handler.cancelOrder(order, Collections.singletonList(orderItem))); // 4.1 回滚积分:扣减用户积分(赠送的) reduceUserPoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.AFTER_SALE_DEDUCT_GIVE, orderItem.getAfterSaleId()); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java index fc59d2d24..b83d2771b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.trade.service.order.handler; -import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.module.promotion.api.bargain.BargainActivityApi; import cn.iocoder.yudao.module.promotion.api.bargain.BargainRecordApi; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; @@ -26,9 +25,10 @@ public class TradeBargainHandler implements TradeOrderHandler { @Override public void beforeOrderCreate(TradeOrderDO order, List orderItems) { - if (ObjectUtil.notEqual(TradeOrderTypeEnum.BARGAIN.getType(), order.getType())) { + if (TradeOrderTypeEnum.isBargain(order.getType())) { return; } + // 扣减砍价活动的库存 bargainActivityApi.updateBargainActivityStock(order.getBargainActivityId(), -orderItems.get(0).getCount()); @@ -36,13 +36,20 @@ public class TradeBargainHandler implements TradeOrderHandler { @Override public void afterOrderCreate(TradeOrderDO order, List orderItems) { - if (ObjectUtil.notEqual(TradeOrderTypeEnum.BARGAIN.getType(), order.getType())) { + if (TradeOrderTypeEnum.isBargain(order.getType())) { return; } + // 记录砍价记录对应的订单编号 bargainRecordApi.updateBargainRecordOrderId(order.getBargainRecordId(), order.getId()); } - // TODO 芋艿:取消订单时,需要增加库存 + @Override + public void cancelOrder(TradeOrderDO order, List orderItems) { + if (TradeOrderTypeEnum.isBargain(order.getType())) { + return; + } + // TODO 芋艿:取消订单时,需要增加库存 + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java index f34da9616..a76596dd3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler; import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; @@ -26,7 +25,7 @@ public class TradeCombinationHandler implements TradeOrderHandler { @Override public void beforeOrderCreate(TradeOrderDO order, List orderItems) { // 如果不是拼团订单则结束 - if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { + if (TradeOrderTypeEnum.isCombination(order.getType())) { return; } Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品"); @@ -41,7 +40,7 @@ public class TradeCombinationHandler implements TradeOrderHandler { @Override public void afterPayOrder(TradeOrderDO order, List orderItems) { // 如果不是拼团订单则结束 - if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { + if (TradeOrderTypeEnum.isCombination(order.getType())) { return; } @@ -53,4 +52,11 @@ public class TradeCombinationHandler implements TradeOrderHandler { combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, item)); } + @Override + public void cancelOrder(TradeOrderDO order, List orderItems) { + if (TradeOrderTypeEnum.isCombination(order.getType())) { + return; + } + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java index 81c41650a..646ebd1b7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java @@ -40,7 +40,11 @@ public interface TradeOrderHandler { /** * 订单取消 + * + * @param order 订单 + * @param orderItems 订单项 */ - default void cancelOrder() {} + default void cancelOrder(TradeOrderDO order, List orderItems) { + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java index e9cf974b6..b9bd3e4bd 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.trade.service.order.handler; -import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.module.promotion.api.seckill.SeckillActivityApi; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; @@ -23,12 +22,21 @@ public class TradeSeckillHandler implements TradeOrderHandler { @Override public void beforeOrderCreate(TradeOrderDO order, List orderItems) { - if (ObjectUtil.notEqual(TradeOrderTypeEnum.SECKILL.getType(), order.getType())) { + if (TradeOrderTypeEnum.isSeckill(order.getType())) { return; } + // 扣减秒杀活动的库存 seckillActivityApi.updateSeckillStock(order.getSeckillActivityId(), orderItems.get(0).getSkuId(), orderItems.get(0).getCount()); } + @Override + public void cancelOrder(TradeOrderDO order, List orderItems) { + if (TradeOrderTypeEnum.isSeckill(order.getType())) { + return; + } + + } + } From 1a0fda23b15719b699fd9372b2418ffd6cf0cda8 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sat, 7 Oct 2023 17:11:25 +0800 Subject: [PATCH 10/19] =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=EF=BC=9A=E8=B0=83=E6=95=B4=E5=9B=A2=E9=95=BF=E7=9A=84=20headId?= =?UTF-8?q?=20=E4=B8=BA=20CombinationRecordDO#HEAD=5FID=5FGROUP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/combination/CombinationRecordServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 47e7c552a..cbf2440f7 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -179,9 +179,9 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { CombinationRecordDO recordDO = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku); recordMapper.insert(recordDO); - // 3、如果是团长需要设置 headId 为它自己 + // 3、如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP if (reqDTO.getHeadId() == null) { - recordMapper.updateById(new CombinationRecordDO().setId(recordDO.getId()).setHeadId(recordDO.getId())); + recordMapper.updateById(new CombinationRecordDO().setId(recordDO.getId()).setHeadId(CombinationRecordDO.HEAD_ID_GROUP)); return; } From 6636ee7420dcc55025d5d97d7e975b88936b63cd Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sat, 7 Oct 2023 18:46:19 +0800 Subject: [PATCH 11/19] =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E8=AE=B0=E5=BD=95(APP)?= =?UTF-8?q?=EF=BC=9A=E6=96=B0=E5=A2=9E=E4=B8=80=E4=B8=AA=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/collection/CollectionUtils.java | 8 +++ .../AppCombinationRecordController.java | 31 ++++++-- .../combination/CombinationRecordMapper.java | 16 ----- .../combination/CombinationRecordService.java | 24 ++++++- .../CombinationRecordServiceImpl.java | 70 +++++++++++++++++-- .../module/trade/api/order/TradeOrderApi.java | 8 +++ .../trade/api/order/TradeOrderApiImpl.java | 5 ++ .../order/TradeOrderUpdateService.java | 8 +++ .../order/TradeOrderUpdateServiceImpl.java | 11 +++ 9 files changed, 152 insertions(+), 29 deletions(-) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java index 12d18dc95..5d9613de7 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java @@ -25,6 +25,14 @@ public class CollectionUtils { return Arrays.stream(collections).anyMatch(CollectionUtil::isEmpty); } + public static > List sortedAsc( + Collection from, Function keyExtractor) { + // 按照升序排序 + return from.stream() + .sorted(Comparator.comparing(keyExtractor)) + .collect(Collectors.toList()); + } + public static boolean anyMatch(Collection from, Predicate predicate) { return from.stream().anyMatch(predicate); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java index ded52759c..f22065193 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java @@ -6,11 +6,14 @@ import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.Ap import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordSummaryRespVO; import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; +import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; +import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.context.annotation.Lazy; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -35,6 +38,9 @@ public class AppCombinationRecordController { @Resource private CombinationRecordService combinationRecordService; + @Resource + @Lazy + private TradeOrderApi tradeOrderApi; @GetMapping("/get-summary") @Operation(summary = "获得拼团记录的概要信息", description = "用于小程序首页") @@ -96,9 +102,26 @@ public class AppCombinationRecordController { return success(CombinationActivityConvert.INSTANCE.convert(getLoginUserId(), headRecord, memberRecords)); } - // TODO @puhui:新增一个取消拼团的接口,cancel - // 1. 需要先校验拼团记录未完成; - // 2. 在 Order 那增加一个 cancelPaidOrder 接口,用于取消已支付的订单 - // 3. order 完成后,取消拼团记录。另外,如果它是团长,则顺序(下单时间)继承 + @GetMapping("/cancel") + @Operation(summary = "取消拼团") + @Parameter(name = "id", description = "拼团记录编号", required = true, example = "1024") + public CommonResult cancelCombinationRecord(@RequestParam("id") Long id) { + Long userId = getLoginUserId(); + // 1、查找这条拼团记录 + CombinationRecordDO record = combinationRecordService.getCombinationRecordByIdAndUser(userId, id); + if (record == null) { + return success(Boolean.FALSE); + } + // 1.1、需要先校验拼团记录未完成; + if (!CombinationRecordStatusEnum.isInProgress(record.getStatus())) { + return success(Boolean.FALSE); + } + + // 2. 取消已支付的订单 + tradeOrderApi.cancelPaidOrder(userId, record.getOrderId()); + // 3. 取消拼团记录 + combinationRecordService.cancelCombinationRecord(userId, record.getId(), record.getHeadId()); + return success(Boolean.TRUE); + } } 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 6226cb2eb..8e3e47251 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 @@ -159,20 +159,4 @@ public interface CombinationRecordMapper extends BaseMapperX selectList(Long activityId, Long headId) { - return selectList(new LambdaQueryWrapperX() - .eq(CombinationRecordDO::getActivityId, activityId) - .eq(CombinationRecordDO::getHeadId, headId) - .or() - .eq(CombinationRecordDO::getId, headId)); - - } - } 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 3e8a97c0e..3baf69529 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 @@ -158,12 +158,32 @@ public interface CombinationRecordService { * 【拼团活动】获得拼团记录数量 Map * * @param activityIds 活动记录编号数组 - * @param status 拼团状态,允许空 - * @param headId 团长编号,允许空。目的 headId 设置为 {@link CombinationRecordDO#HEAD_ID_GROUP} 时,可以设置 + * @param status 拼团状态,允许空 + * @param headId 团长编号,允许空。目的 headId 设置为 {@link CombinationRecordDO#HEAD_ID_GROUP} 时,可以设置 * @return 拼团记录数量 Map */ Map getCombinationRecordCountMapByActivity(Collection activityIds, @Nullable Integer status, @Nullable Long headId); + + /** + * 获取拼团记录 + * + * @param userId 用户编号 + * @param id 拼团记录编号 + * @return 拼团记录 + */ + CombinationRecordDO getCombinationRecordByIdAndUser(Long userId, Long id); + + /** + * 取消拼团 + * + * @param userId 用户编号 + * @param id 拼团记录编号 + * @param headId 团长编号 + */ + void cancelCombinationRecord(Long userId, Long id, Long headId); + + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index cbf2440f7..183fda97b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -28,10 +28,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Nullable; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; +import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; @@ -180,7 +177,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { recordMapper.insert(recordDO); // 3、如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP - if (reqDTO.getHeadId() == null) { + if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, reqDTO.getHeadId())) { recordMapper.updateById(new CombinationRecordDO().setId(recordDO.getId()).setHeadId(CombinationRecordDO.HEAD_ID_GROUP)); return; } @@ -212,13 +209,17 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { * @param headId 团长编号 */ private void updateCombinationRecords(CombinationActivityDO activity, Long headId) { - List records = recordMapper.selectList(CombinationRecordDO::getHeadId, headId); + // 团长 + CombinationRecordDO recordHead = recordMapper.selectById(headId); + // 团员 + List records = getCombinationRecordListByHeadId(headId); + // 需要更新的记录 List updateRecords = new ArrayList<>(); if (CollUtil.isEmpty(records)) { return; } - + records.add(recordHead); // 加入团长,团长也需要更新 boolean isEqual = ObjUtil.equal(records.size(), activity.getUserSize()); records.forEach(item -> { CombinationRecordDO recordDO = new CombinationRecordDO(); @@ -305,4 +306,59 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return recordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId); } + @Override + public CombinationRecordDO getCombinationRecordByIdAndUser(Long userId, Long id) { + return recordMapper.selectOne(CombinationRecordDO::getUserId, userId, CombinationRecordDO::getId, id); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void cancelCombinationRecord(Long userId, Long id, Long headId) { + // 删除记录 + recordMapper.deleteById(id); + + // 需要更新的记录 + List updateRecords = new ArrayList<>(); + // 如果它是团长,则顺序(下单时间)继承 + if (Objects.equals(headId, CombinationRecordDO.HEAD_ID_GROUP)) { // 情况一:团长 + // 团员 + List list = getCombinationRecordListByHeadId(id); + if (CollUtil.isEmpty(list)) { + return; + } + // 按照创建时间升序排序 + List recordsSort = sortedAsc(list, CombinationRecordDO::getCreateTime); + CombinationRecordDO newHead = recordsSort.get(0); // 新团长继位 + recordsSort.forEach(item -> { + CombinationRecordDO recordDO = new CombinationRecordDO(); + recordDO.setId(item.getId()); + if (ObjUtil.equal(item.getId(), newHead.getId())) { // 新团长 + recordDO.setHeadId(CombinationRecordDO.HEAD_ID_GROUP); + } else { + recordDO.setHeadId(newHead.getId()); + } + recordDO.setUserCount(recordsSort.size()); + updateRecords.add(recordDO); + }); + } else { // 情况二:团员 + // 团长 + CombinationRecordDO recordHead = recordMapper.selectById(headId); + // 团员 + List records = getCombinationRecordListByHeadId(headId); + if (CollUtil.isEmpty(records)) { + return; + } + records.add(recordHead); // 加入团长,团长数据也需要更新 + records.forEach(item -> { + CombinationRecordDO recordDO = new CombinationRecordDO(); + recordDO.setId(item.getId()); + recordDO.setUserCount(records.size()); + updateRecords.add(recordDO); + }); + } + + // 更新拼团记录 + recordMapper.updateBatch(updateRecords); + } + } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java index 0d72a75e8..91298874c 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java @@ -49,4 +49,12 @@ public interface TradeOrderApi { */ void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId); + /** + * 取消支付订单 + * + * @param userId 用户编号 + * @param orderId 订单编号 + */ + void cancelPaidOrder(Long userId, Long orderId); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java index ed1ee1f26..1013ae71f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java @@ -47,4 +47,9 @@ public class TradeOrderApiImpl implements TradeOrderApi { tradeOrderUpdateService.updateOrderCombinationInfo(orderId, activityId, combinationRecordId, headId); } + @Override + public void cancelPaidOrder(Long userId, Long orderId) { + tradeOrderUpdateService.cancelPaidOrder(userId, orderId); + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java index bc8413b3d..291680578 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java @@ -180,4 +180,12 @@ public interface TradeOrderUpdateService { */ void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId); + /** + * 取消支付订单 + * + * @param userId 用户编号 + * @param orderId 订单编号 + */ + void cancelPaidOrder(Long userId, Long orderId); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 7c5ed91b3..a34859f0b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -918,6 +918,17 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { .setCombinationRecordId(combinationRecordId).setCombinationHeadId(headId)); } + @Override + @Transactional(rollbackFor = Exception.class) + public void cancelPaidOrder(Long userId, Long orderId) { + TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId); + if (order == null) { + throw exception(ORDER_NOT_FOUND); + } + + cancelOrder0(order, TradeOrderCancelTypeEnum.MEMBER_CANCEL); + } + /** * 创建单个订单的评论 * From c917f01d83969ed0f1e3da7dec0b8a308b69d1a0 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 7 Oct 2023 22:47:45 +0800 Subject: [PATCH 12/19] =?UTF-8?q?promotion=EF=BC=9Acode=20review=20?= =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E7=9B=B8=E5=85=B3=E7=9A=84=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/activity/AppActivityController.java | 15 +++++++++------ .../combination/CombinationRecordDO.java | 2 ++ .../dal/mysql/bargain/BargainActivityMapper.java | 1 + .../combination/CombinationActivityMapper.java | 1 + .../combination/CombinationRecordMapper.java | 4 ++-- .../seckillactivity/SeckillActivityMapper.java | 1 + .../combination/CombinationRecordServiceImpl.java | 2 ++ .../enums/order/TradeOrderOperateTypeEnum.java | 2 +- .../order/TradeOrderUpdateServiceImpl.java | 7 +++---- 9 files changed, 22 insertions(+), 13 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java index 5ccc2983e..f467923a7 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java @@ -52,11 +52,11 @@ public class AppActivityController { @Operation(summary = "获得多个商品,近期参与的每个活动") // 每种活动,只返回一个;key 为 SPU 编号 @Parameter(name = "spuIds", description = "商品编号数组", required = true) public CommonResult>> getActivityListBySpuIds(@RequestParam("spuIds") List spuIds) { - if (CollUtil.isEmpty(spuIds)) { return success(MapUtil.empty()); } + // TODO @puhui999:要避免这种 1+n 的查询 Map> map = new HashMap<>(spuIds.size()); spuIds.forEach(spuId -> { map.put(spuId, getAppActivityRespVOList(spuId)); @@ -65,35 +65,38 @@ public class AppActivityController { } private List getAppActivityRespVOList(Long spuId) { - List respList = new ArrayList<>(); + List activityList = new ArrayList<>(); + // 拼团活动 CombinationActivityDO combination = combinationActivityService.getCombinationActivityBySpuId(spuId); if (combination != null) { - respList.add(new AppActivityRespVO() + activityList.add(new AppActivityRespVO() .setId(combination.getId()) .setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType()) .setName(combination.getName()) .setStartTime(combination.getStartTime()) .setEndTime(combination.getEndTime())); } + // 秒杀活动 SeckillActivityDO seckill = seckillActivityService.getSeckillActivityBySpuId(spuId); if (seckill != null) { - respList.add(new AppActivityRespVO() + activityList.add(new AppActivityRespVO() .setId(seckill.getId()) .setType(PromotionTypeEnum.SECKILL_ACTIVITY.getType()) .setName(seckill.getName()) .setStartTime(seckill.getStartTime()) .setEndTime(seckill.getEndTime())); } + // 秒杀活动 BargainActivityDO bargain = bargainActivityService.getBargainActivityBySpuId(spuId); if (bargain != null) { - respList.add(new AppActivityRespVO() + activityList.add(new AppActivityRespVO() .setId(bargain.getId()) .setType(PromotionTypeEnum.BARGAIN_ACTIVITY.getType()) .setName(bargain.getName()) .setStartTime(bargain.getStartTime()) .setEndTime(bargain.getEndTime())); } - return respList; + return activityList; } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java index 07d40d1e5..65b797df4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java @@ -76,6 +76,8 @@ public class CombinationRecordDO extends BaseDO { * 用户编号 */ private Long userId; + + // TODO @puhui999:要不去掉这 2 个字段,通过读取解决?如果去掉,相关接口都要处理下哈; /** * 用户昵称 */ 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 7c5cfbfd8..7a566c961 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 @@ -83,6 +83,7 @@ public interface BargainActivityMapper extends BaseMapperX { .last("LIMIT " + count)); } + // TODO @puhui999:需要开启状态;另外,是不是可以 limit1,不用 throwEx = false 处理呀?另外,时间要满足噢 default BargainActivityDO selectOne(Long spuId) { return selectOne(new LambdaQueryWrapperX() .eq(BargainActivityDO::getSpuId, spuId) 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 3f5e9ec23..5334b8c8e 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 @@ -40,6 +40,7 @@ public interface CombinationActivityMapper extends BaseMapperX() .eq(CombinationActivityDO::getSpuId, spuId) 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 f6b6cf59f..db73cbf10 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 @@ -84,8 +84,8 @@ public interface CombinationRecordMapper extends BaseMapperX selectListByActivityIdAndStatusAndHeadId(Long activityId, Integer status, Long headId, Integer count) { return selectList(new LambdaQueryWrapperX() - .eq(CombinationRecordDO::getActivityId, activityId) - .eq(CombinationRecordDO::getStatus, status) + .eqIfPresent(CombinationRecordDO::getActivityId, activityId) + .eqIfPresent(CombinationRecordDO::getStatus, status) .eq(CombinationRecordDO::getHeadId, headId) .orderByDesc(CombinationRecordDO::getId) .last("LIMIT " + count)); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java index 1c31e74d9..32938ae67 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java @@ -56,6 +56,7 @@ public interface SeckillActivityMapper extends BaseMapperX { .apply(ObjectUtil.isNotNull(pageReqVO.getConfigId()), "FIND_IN_SET(" + pageReqVO.getConfigId() + ",config_ids) > 0")); } + // TODO @puhui999:需要开启状态;另外,是不是可以 limit1,不用 throwEx = false 处理呀?另外,时间要满足噢; default SeckillActivityDO selectOne(Long spuId) { return selectOne(new LambdaQueryWrapperX() .eq(SeckillActivityDO::getSpuId, spuId) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 140c8ae9f..9244c3e3e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -67,6 +67,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Resource private TradeOrderApi tradeOrderApi; + // TODO @芋艿:在详细预览下; @Override @Transactional(rollbackFor = Exception.class) public void updateCombinationRecordStatusByUserIdAndOrderId(Integer status, Long userId, Long orderId) { @@ -78,6 +79,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { recordMapper.updateById(record); } + // TODO @芋艿:在详细预览下; @Override @Transactional(rollbackFor = Exception.class) public void updateRecordStatusAndStartTimeByUserIdAndOrderId(Integer status, Long userId, Long orderId, LocalDateTime startTime) { diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java index bc2287572..c4c7974aa 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java @@ -16,7 +16,7 @@ public enum TradeOrderOperateTypeEnum { MEMBER_CREATE(1, "用户下单"), ADMIN_UPDATE_PRICE(2, "订单价格 {oldPayPrice} 修改,实际支付金额为 {newPayPrice} 元"), MEMBER_PAY(10, "用户付款成功"), - SYSTEM_UP_ADDRESS(11, "订单 {orderId} 收货地址修改"), + ADMIN_UPDATE_ADDRESS(11, "收货地址修改"), ADMIN_DELIVERY(20, "已发货,快递公司:{deliveryName},快递单号:{logisticsNo}"), MEMBER_RECEIVE(30, "用户已收货"), SYSTEM_RECEIVE(31, "到期未收货,系统自动确认收货"), diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index df6767a05..6320b0dcc 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -738,19 +738,18 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { } @Override - @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.SYSTEM_UP_ADDRESS) + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.ADMIN_UPDATE_ADDRESS) public void updateOrderAddress(TradeOrderUpdateAddressReqVO reqVO) { // 校验交易订单 TradeOrderDO order = validateOrderExists(reqVO.getId()); // TODO @puhui999:是否需要校验订单是否发货 - // TODO 发货后是否支持修改收货地址 + // TODO 发货后是否支持修改收货地址;回答:发货后,不允许修改; // 更新 tradeOrderMapper.updateById(TradeOrderConvert.INSTANCE.convert(reqVO)); // 记录订单日志 - TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), order.getStatus(), - MapUtil.builder().put("orderId", order.getId()).build()); + TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), order.getStatus()); } @Override From 99649bfdb82390405bda27df60faeeaeed52cbd8 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 8 Oct 2023 07:43:25 +0800 Subject: [PATCH 13/19] =?UTF-8?q?code=20review=EF=BC=9A=E6=8B=BC=E5=9B=A2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/collection/CollectionUtils.java | 1 + .../api/combination/CombinationRecordApi.java | 3 +- .../combination/CombinationRecordApiImpl.java | 7 +-- .../CombinationRecordController.java | 26 +++----- .../vo/recrod/CombinationRecordReqPageVO.java | 16 ++--- .../vo/recrod/CombinationRecordRespVO.java | 1 + .../CombinationActivityConvert.java | 1 + .../combination/CombinationRecordMapper.java | 59 ------------------- .../combination/CombinationRecordService.java | 8 --- .../CombinationRecordServiceImpl.java | 7 +-- .../order/TradeOrderUpdateService.java | 1 + .../handler/TradeCombinationHandler.java | 1 - 12 files changed, 22 insertions(+), 109 deletions(-) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java index 5d9613de7..e4644a62f 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java @@ -25,6 +25,7 @@ public class CollectionUtils { return Arrays.stream(collections).anyMatch(CollectionUtil::isEmpty); } + // TODO @puhui999: list.sort(); 可以替代呀; public static > List sortedAsc( Collection from, Function keyExtractor) { // 按照升序排序 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 a086ecb4d..4d61de4f1 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 @@ -61,6 +61,7 @@ public interface CombinationRecordApi { * @param count 数量 * @return 拼团信息 */ - CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count); + CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, + Long skuId, Integer count); } 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 75e5591d3..918f36ec6 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 @@ -35,12 +35,11 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { @Override public boolean isCombinationRecordSuccess(Long userId, Long orderId) { - CombinationRecordDO combinationRecord = recordService.getCombinationRecord(userId, orderId); - if (combinationRecord == null) { + CombinationRecordDO record = recordService.getCombinationRecord(userId, orderId); + if (record == null) { throw exception(COMBINATION_RECORD_NOT_EXISTS); } - - return CombinationRecordStatusEnum.isSuccess(combinationRecord.getStatus()); + return CombinationRecordStatusEnum.isSuccess(record.getStatus()); } @Override diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java index 1e6b3954c..0d018c2a4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java @@ -33,6 +33,8 @@ public class CombinationRecordController { @Resource private CombinationRecordService combinationRecordService; + + // TODO @puhui999:这个缓存不用做哈;主要管理后台,对性能要求不高;不像前段; /** * {@link Map} 缓存,通过它异步刷新 {@link #getCombinationRecordSummary0()} 所要的拼团记录统计数据 */ @@ -54,6 +56,7 @@ public class CombinationRecordController { combinationRecordService.getCombinationRecordPage(pageVO))); } + // TODO @puhui999:Map 改成对象,尽量避免 Map 返回结果哈;然后 getCombinationRecordCount、getCombinationRecordsSuccessCount、getRecordsVirtualGroupCount 三个方法,可以合并成一个方法哈,返回这个 vo @GetMapping("/get-summary") @Operation(summary = "获得拼团记录的概要信息", description = "用于拼团记录页面展示") @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") @@ -61,26 +64,11 @@ public class CombinationRecordController { return success(combinationRecordSummary.getUnchecked("")); // 缓存 } - @GetMapping("/get-count") - @Operation(summary = "获得拼团记录分页 tab count") - @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") - public CommonResult> getCombinationRecordCount() { - Map hashMap = MapUtil.newHashMap(7); - hashMap.put("all", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.ALL));// 全部 - hashMap.put("toDay", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.TO_DAY));// 今天 - hashMap.put("yesterday", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.YESTERDAY));// 昨天 - hashMap.put("lastSevenDays", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.LAST_SEVEN_DAYS));// 最近七天 - hashMap.put("last30Days", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.LAST_30_DAYS));// 最近 30 天 - hashMap.put("thisMonth", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.THIS_MONTH));// 本月 - hashMap.put("thisYear", combinationRecordService.getCombinationRecordsCountByDateType(CombinationRecordReqPageVO.THIS_YEAR));// 本年 - return success(hashMap); - } - private Map getCombinationRecordSummary0() { - Map hashMap = MapUtil.newHashMap(3); - hashMap.put("userCount", combinationRecordService.getCombinationRecordCount());// 获取所有拼团记录 - hashMap.put("successCount", combinationRecordService.getCombinationRecordsSuccessCount());// 获取成团记录 - hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount());// 获取虚拟成团记录 + Map hashMap = MapUtil.newHashMap(3); // TODO @puhui999:Maps.newHashMapWithExpectedSize() + hashMap.put("userCount", combinationRecordService.getCombinationRecordCount()); // 获取所有拼团记录 + hashMap.put("successCount", combinationRecordService.getCombinationRecordsSuccessCount()); // 获取成团记录 + hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount()); // 获取虚拟成团记录 return hashMap; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java index bf99dcb7c..9e1423a41 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPageVO.java @@ -1,6 +1,8 @@ package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod; import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.promotion.enums.bargain.BargainRecordStatusEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -17,18 +19,8 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @ToString(callSuper = true) public class CombinationRecordReqPageVO extends PageParam { - public static final Integer ALL = 0; // 全部 - public static final Integer TO_DAY = 1; // 今天 - public static final Integer YESTERDAY = 2; // 昨天 - public static final Integer LAST_SEVEN_DAYS = 3; // 最近七天 - public static final Integer LAST_30_DAYS = 4; // 最近 30 天 - public static final Integer THIS_MONTH = 5; // 本月 - public static final Integer THIS_YEAR = 6; // 本年 - - @Schema(description = "日期类型", example = "0") - private Integer dateType; - - @Schema(description = "活动状态", example = "0") + @Schema(description = "活动状态", example = "1") + @InEnum(BargainRecordStatusEnum.class) private Integer status; @Schema(description = "创建时间") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java index ab1a98607..8e2206dba 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java @@ -8,6 +8,7 @@ import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +// TODO @puhui999:可以参考 BargainRecordPageItemRespVO、BargainRecordRespVO 分成两个;一个给记录列表,一个给记录分页 @Schema(description = "管理后台 - 拼团记录 Response VO") @Data public class CombinationRecordRespVO { 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 d2e8fe9ff..26aa60b82 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 @@ -108,6 +108,7 @@ public interface CombinationActivityConvert { CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO); + // TODO @芋艿:在 convert 优化下; default CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO, CombinationActivityDO activity, MemberUserRespDTO user, ProductSpuRespDTO spu, ProductSkuRespDTO sku) { 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 46e8b7eea..e628c5709 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 @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.combination; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; @@ -12,8 +11,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationR import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.ibatis.annotations.Mapper; -import java.time.LocalDateTime; -import java.time.LocalTime; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -44,12 +41,6 @@ public interface CombinationRecordMapper extends BaseMapperX selectListByHeadIdAndStatus(Long headId, Integer status) { - return selectList(new LambdaQueryWrapperX() - .eq(CombinationRecordDO::getHeadId, headId) - .eq(CombinationRecordDO::getStatus, status)); - } - /** * 查询拼团记录 * @@ -103,60 +94,10 @@ public interface CombinationRecordMapper extends BaseMapperX MapUtil.getInt(record, "recordCount")); } - static LocalDateTime[] builderQueryTime(Integer dateType) { - LocalDateTime now = LocalDateTime.now(); - LocalDateTime[] createTime = null; // 全部时间段 - // 今天-一天开始到结束 - if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.TO_DAY)) { - createTime = new LocalDateTime[]{now.toLocalDate().atStartOfDay(), now.toLocalDate().atTime(LocalTime.MAX)}; - } - // 昨天-昨天开始和结束 - if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.YESTERDAY)) { - createTime = new LocalDateTime[]{now.minusDays(1).toLocalDate().atStartOfDay(), - now.minusDays(1).toLocalDate().atTime(LocalTime.MAX)}; - } - // 最近七天 - if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.LAST_SEVEN_DAYS)) { - createTime = new LocalDateTime[]{now.minusDays(7).toLocalDate().atStartOfDay(), - now.toLocalDate().atTime(LocalTime.MAX)}; - } - // 最近 30 天 - if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.LAST_30_DAYS)) { - createTime = new LocalDateTime[]{now.minusDays(30).toLocalDate().atStartOfDay(), - now.toLocalDate().atTime(LocalTime.MAX)}; - } - // 本月 - if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.THIS_MONTH)) { - // 获取本月的开始时间 - LocalDateTime startTime = now.withDayOfMonth(1).toLocalDate().atStartOfDay(); - // 获取下个月的开始时间,然后减去一秒以获取本月的结束时间 - LocalDateTime endTime = now.withDayOfMonth(1).plusMonths(1).toLocalDate().atStartOfDay().minusSeconds(1); - createTime = new LocalDateTime[]{startTime, endTime}; - } - // 本年 - if (ObjectUtil.equal(dateType, CombinationRecordReqPageVO.THIS_YEAR)) { - // 获取本年的开始时间 - LocalDateTime startTime = now.withDayOfYear(1).toLocalDate().atStartOfDay(); - // 获取下一年的开始时间,然后减去一秒以获取本年的结束时间 - LocalDateTime endTime = now.withDayOfYear(1).plusYears(1).toLocalDate().atStartOfDay().minusSeconds(1); - createTime = new LocalDateTime[]{startTime, endTime}; - } - return createTime; - } - default PageResult selectPage(CombinationRecordReqPageVO pageVO) { - // 兼容自选时间段 - if (pageVO.getDateType() != null) { - pageVO.setCreateTime(builderQueryTime(pageVO.getDateType())); - } return selectPage(pageVO, new LambdaQueryWrapperX() .eqIfPresent(CombinationRecordDO::getStatus, pageVO.getStatus()) .betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime())); } - default Long selectCount(Integer dateType) { - return selectCount(new LambdaQueryWrapperX() - .betweenIfPresent(CombinationRecordDO::getCreateTime, builderQueryTime(dateType))); - } - } 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 3baf69529..4a7498b24 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 @@ -104,14 +104,6 @@ public interface CombinationRecordService { */ Long getRecordsVirtualGroupCount(); - /** - * 获取指定日期类型的记录数,比如说获取最近七天的拼团记录数 - * - * @param dateType 日期类型 - * @return 记录数 - */ - Long getCombinationRecordsCountByDateType(Integer dateType); - /** * 获取最近的 count 条拼团记录 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 5b4145afe..eb52a2c9b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -262,19 +262,16 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Override public Long getCombinationRecordsSuccessCount() { + // TODO @puhui999:这个应该要多查询 headId return recordMapper.selectCount(CombinationRecordDO::getStatus, CombinationRecordStatusEnum.SUCCESS.getStatus()); } @Override public Long getRecordsVirtualGroupCount() { + // TODO @puhui999:这个应该要多查询 headId;然后,recordMapper 要明确的查询哈,不要直接使用 mapper 来拼接查询条件 return recordMapper.selectCount(CombinationRecordDO::getVirtualGroup, true); } - @Override - public Long getCombinationRecordsCountByDateType(Integer dateType) { - return recordMapper.selectCount(dateType); - } - @Override public List getLatestCombinationRecordList(int count) { return recordMapper.selectLatestList(count); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java index 291680578..607128992 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java @@ -178,6 +178,7 @@ public interface TradeOrderUpdateService { * @param combinationRecordId 拼团记录编号 * @param headId 团长编号 */ + // TODO 芋艿:再 review 拼团 void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId); /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java index a76596dd3..75dd2782e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java @@ -43,7 +43,6 @@ public class TradeCombinationHandler implements TradeOrderHandler { if (TradeOrderTypeEnum.isCombination(order.getType())) { return; } - Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品"); // 获取商品信息 From 01e6140d67b78e274dcc46841ed2d1b606cd2efc Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 8 Oct 2023 09:53:09 +0800 Subject: [PATCH 14/19] =?UTF-8?q?code=20review=EF=BC=9A=E6=8B=BC=E5=9B=A2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/collection/CollectionUtils.java | 3 +- .../CombinationRecordStatusEnum.java | 4 + .../combination/CombinationRecordMapper.java | 2 +- .../combination/CombinationRecordService.java | 3 +- .../CombinationRecordServiceImpl.java | 115 +++++++++--------- .../handler/TradeCombinationHandler.java | 4 +- 6 files changed, 66 insertions(+), 65 deletions(-) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java index e4644a62f..00e8a0bd9 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java @@ -241,7 +241,8 @@ public class CollectionUtils { return valueFunc.apply(t); } - public static > V getSumValue(List from, Function valueFunc, BinaryOperator accumulator) { + public static > V getSumValue(List from, Function valueFunc, + BinaryOperator accumulator) { if (CollUtil.isEmpty(from)) { return null; } 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 index 2d12b2048..627e13946 100644 --- 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 @@ -44,4 +44,8 @@ public enum CombinationRecordStatusEnum implements IntArrayValuable { return ObjectUtil.equal(status, IN_PROGRESS.getStatus()); } + public static boolean isFailed(Integer status) { + return ObjectUtil.equal(status, FAILED.getStatus()); + } + } 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 e628c5709..8df124f70 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 @@ -35,7 +35,7 @@ public interface CombinationRecordMapper extends BaseMapperX() .eq(CombinationRecordDO::getId, headId) .eq(CombinationRecordDO::getStatus, status)); 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 4a7498b24..fcaeb2a92 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 @@ -42,7 +42,8 @@ public interface CombinationRecordService { * @param count 数量 * @return 拼团信息 */ - KeyValue validateCombinationRecord(Long userId, Long activityId, Long headId, Long skuId, Integer count); + KeyValue validateCombinationRecord(Long userId, Long activityId, Long headId, + Long skuId, Integer count); /** * 创建拼团记录 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index eb52a2c9b..0b8b92343 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -89,13 +89,13 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Override public KeyValue validateCombinationRecord( Long userId, Long activityId, Long headId, Long skuId, Integer count) { - // 1 校验拼团活动是否存在 + // 1. 校验拼团活动是否存在 CombinationActivityDO activity = combinationActivityService.validateCombinationActivityExists(activityId); // 1.1 校验活动是否开启 if (ObjUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE); } - // 1.2、校验活动开始时间 + // 1.2 校验活动开始时间 if (afterNow(activity.getStartTime())) { throw exception(COMBINATION_RECORD_FAILED_TIME_NOT_START); } @@ -104,69 +104,67 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED); } - // 2、父拼团是否存在,是否已经满了 + // 2. 父拼团是否存在,是否已经满了 if (headId != null) { - // 2.1、查询进行中的父拼团 - CombinationRecordDO record = recordMapper.selectOneByHeadId(headId, CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); + // 2.1. 查询进行中的父拼团 + CombinationRecordDO record = recordMapper.selectByHeadId(headId, CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); if (record == null) { throw exception(COMBINATION_RECORD_HEAD_NOT_EXISTS); } - // 2.2、校验拼团是否满足要求 + // 2.2. 校验拼团是否已满 if (ObjUtil.equal(record.getUserCount(), record.getUserSize())) { throw exception(COMBINATION_RECORD_USER_FULL); } - // 2.3、校验拼团是否过期(有父拼团的时候只校验父拼团的过期时间) + // 2.3 校验拼团是否过期(有父拼团的时候只校验父拼团的过期时间) if (beforeNow(record.getExpireTime())) { throw exception(COMBINATION_RECORD_FAILED_TIME_END); } } else { - // 3、校验当前活动是否结束(自己是父拼团的时候才校验活动是否结束) + // 3. 校验当前活动是否结束(自己是父拼团的时候才校验活动是否结束) if (beforeNow(activity.getEndTime())) { throw exception(COMBINATION_RECORD_FAILED_TIME_END); } } - // 4、校验活动商品是否存在 + // 4.1 校验活动商品是否存在 CombinationProductDO product = combinationActivityService.selectByActivityIdAndSkuId(activityId, skuId); if (product == null) { throw exception(COMBINATION_JOIN_ACTIVITY_PRODUCT_NOT_EXISTS); } - - // 5、校验 sku 是否存在 + // 4.2 校验 sku 是否存在 ProductSkuRespDTO sku = productSkuApi.getSku(skuId); if (sku == null) { throw exception(COMBINATION_JOIN_ACTIVITY_PRODUCT_NOT_EXISTS); } - // 5.1、校验库存是否充足 + // 4.3 校验库存是否充足 if (count > sku.getStock()) { throw exception(COMBINATION_ACTIVITY_UPDATE_STOCK_FAIL); } - // 6、校验是否有拼团记录 - List recordList = getCombinationRecordListByUserIdAndActivityId(userId, activityId); - if (CollUtil.isEmpty(recordList)) { + // 6.1 校验是否有拼团记录 + List recordList = recordMapper.selectListByUserIdAndActivityId(userId, activityId); + recordList.removeIf(record -> CombinationRecordStatusEnum.isFailed(record.getStatus())); // 取消的订单,不算数 + if (CollUtil.isEmpty(recordList)) { // 如果为空,说明可以参与,直接返回 return new KeyValue<>(activity, product); } - // 6.1、校验用户是否有该活动正在进行的拼团 - List filtered = filterList(recordList, record -> CombinationRecordStatusEnum.isInProgress(record.getStatus())); - if (CollUtil.isNotEmpty(filtered)) { + // 6.2 校验用户是否有该活动正在进行的拼团 + CombinationRecordDO inProgressRecord = findFirst(recordList, + record -> CombinationRecordStatusEnum.isInProgress(record.getStatus())); + if (inProgressRecord != null) { throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED); } - // 6.2、校验是否超出总限购数量 - Integer sumValue = getSumValue(convertList(recordList, CombinationRecordDO::getCount, - item -> CombinationRecordStatusEnum.isSuccess(item.getStatus())), i -> i, Integer::sum); - if ((sumValue + count) > activity.getTotalLimitCount()) { + // 6.3 校验是否超出总限购数量 + Integer sumValue = getSumValue(recordList, CombinationRecordDO::getCount, Integer::sum); + if (sumValue != null && sumValue + count > activity.getTotalLimitCount()) { throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED); } - return new KeyValue<>(activity, product); } - // TODO 芋艿:在详细 review 下; @Override @Transactional(rollbackFor = Exception.class) public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { - // 1、校验拼团活动 + // 1. 校验拼团活动 KeyValue keyValue = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getActivityId(), reqDTO.getHeadId(), reqDTO.getSkuId(), reqDTO.getCount()); @@ -174,23 +172,24 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); - CombinationRecordDO recordDO = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku); - recordMapper.insert(recordDO); + CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku); + recordMapper.insert(record); - // 3、如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP + // 3. 如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP + // TODO @puhui999:是不是只要是团长,record 设置了就好啦,不用 update。。。。 if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, reqDTO.getHeadId())) { - recordMapper.updateById(new CombinationRecordDO().setId(recordDO.getId()).setHeadId(CombinationRecordDO.HEAD_ID_GROUP)); + recordMapper.updateById(new CombinationRecordDO().setId(record.getId()).setHeadId(CombinationRecordDO.HEAD_ID_GROUP)); return; } - // TODO 这里要不要弄成异步的 + // TODO 这里要不要弄成异步的;不用异步哈,就是事务好了; // 4、更新拼团相关信息到订单 - updateOrderCombinationInfo(recordDO.getOrderId(), recordDO.getActivityId(), recordDO.getId(), recordDO.getHeadId()); + updateOrderCombinationInfo(record.getOrderId(), record.getActivityId(), record.getId(), record.getHeadId()); // 4、更新拼团记录 - updateCombinationRecords(keyValue.getKey(), reqDTO.getHeadId()); - + updateCombinationRecordWhenCreate(reqDTO.getHeadId(), keyValue.getKey()); } + // TODO @puhui999:这个更新,放到 trade 那就好了;createCombinationRecord 返回一个 recordId; /** * 更新拼团相关信息到订单 * @@ -204,35 +203,31 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } /** - * 更新拼团记录 + * 当新增拼团时,更新拼团记录的进展 * - * @param activity 活动 * @param headId 团长编号 + * @param activity 活动 */ - private void updateCombinationRecords(CombinationActivityDO activity, Long headId) { - // 团长 - CombinationRecordDO recordHead = recordMapper.selectById(headId); - // 团员 + private void updateCombinationRecordWhenCreate(Long headId, CombinationActivityDO activity) { + // 1. 团长 + 团员 List records = getCombinationRecordListByHeadId(headId); - // 需要更新的记录 - List updateRecords = new ArrayList<>(); - if (CollUtil.isEmpty(records)) { return; } - records.add(recordHead); // 加入团长,团长也需要更新 - boolean isEqual = ObjUtil.equal(records.size(), activity.getUserSize()); - records.forEach(item -> { - CombinationRecordDO recordDO = new CombinationRecordDO(); - recordDO.setId(item.getId()); - recordDO.setUserCount(records.size()); - // 校验拼团是否满足要求 - if (isEqual) { - recordDO.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus()); - } - updateRecords.add(recordDO); - }); + CombinationRecordDO headRecord = recordMapper.selectById(headId); + // 2. 批量更新记录 + List updateRecords = new ArrayList<>(); + records.add(headRecord); // 加入团长,团长也需要更新 + boolean isFull = records.size() >= activity.getUserSize(); + records.forEach(item -> { + CombinationRecordDO updateRecord = new CombinationRecordDO(); + updateRecord.setId(item.getId()).setUserCount(records.size()); + if (isFull) { + updateRecord.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus()); + } + updateRecords.add(updateRecord); + }); recordMapper.updateBatch(updateRecords); } @@ -247,12 +242,12 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } @Override - public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count) { - KeyValue keyValue = validateCombinationRecord(userId, activityId, headId, skuId, count); - return new CombinationValidateJoinRespDTO() - .setActivityId(keyValue.getKey().getId()) - .setName(keyValue.getKey().getName()) - .setCombinationPrice(keyValue.getValue().getCombinationPrice()); + public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, + Long skuId, Integer count) { + KeyValue keyValue = validateCombinationRecord(userId, activityId, + headId, skuId, count); + return new CombinationValidateJoinRespDTO().setActivityId(keyValue.getKey().getId()) + .setName(keyValue.getKey().getName()).setCombinationPrice(keyValue.getValue().getCombinationPrice()); } @Override diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java index 75dd2782e..17b01ca0e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java @@ -30,11 +30,11 @@ public class TradeCombinationHandler implements TradeOrderHandler { } Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品"); - // 获取商品信息 - TradeOrderItemDO item = orderItems.get(0); // 校验是否满足拼团活动相关限制 + TradeOrderItemDO item = orderItems.get(0); combinationRecordApi.validateCombinationRecord(order.getUserId(), order.getCombinationActivityId(), order.getCombinationHeadId(), item.getSkuId(), item.getCount()); + // TODO @puhui999:这里还要限制下,是不是已经 createOrder;就是还没支付的时候,重复下单了;需要校验下;不然的话,一个拼团可以下多个单子了; } @Override From 8a11ca8126a6d42595a02de3ab0873c612255931 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 8 Oct 2023 09:59:53 +0800 Subject: [PATCH 15/19] =?UTF-8?q?code=20review=EF=BC=9A=E6=8B=BC=E5=9B=A2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/combination/CombinationRecordServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 0b8b92343..3158f0401 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -173,6 +173,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku); + // TODO @puhui:有 head 的情况下,以 head 结束为准 recordMapper.insert(record); // 3. 如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP From c8a9d689337bab2a36d9de0919eed9e0863f6db2 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sun, 8 Oct 2023 12:08:17 +0800 Subject: [PATCH 16/19] =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=EF=BC=9A=E5=AE=8C=E5=96=84=20review=20=E6=8F=90=E5=88=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/collection/CollectionUtils.java | 9 --- .../dto/CombinationRecordCreateReqDTO.java | 1 - .../CombinationRecordController.java | 59 ++++++++----------- ...spVO.java => CombinationRecordBaseVO.java} | 51 +++++++++++----- .../CombinationRecordPageItemRespVO.java | 19 ++++++ .../vo/recrod/CombinationRecordSummaryVO.java | 19 ++++++ .../AppCombinationRecordController.java | 2 +- .../CombinationActivityConvert.java | 21 +++++-- .../combination/CombinationRecordDO.java | 1 - .../combination/CombinationRecordMapper.java | 8 +++ .../CombinationActivityService.java | 8 +++ .../CombinationActivityServiceImpl.java | 5 ++ .../combination/CombinationRecordService.java | 20 ++----- .../CombinationRecordServiceImpl.java | 28 +++------ 14 files changed, 149 insertions(+), 102 deletions(-) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/{CombinationRecordRespVO.java => CombinationRecordBaseVO.java} (69%) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordPageItemRespVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordSummaryVO.java diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java index e4644a62f..12d18dc95 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java @@ -25,15 +25,6 @@ public class CollectionUtils { return Arrays.stream(collections).anyMatch(CollectionUtil::isEmpty); } - // TODO @puhui999: list.sort(); 可以替代呀; - public static > List sortedAsc( - Collection from, Function keyExtractor) { - // 按照升序排序 - return from.stream() - .sorted(Comparator.comparing(keyExtractor)) - .collect(Collectors.toList()); - } - public static boolean anyMatch(Collection from, Predicate predicate) { return from.stream().anyMatch(predicate); } diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateReqDTO.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateReqDTO.java index 76f240599..26648abf6 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateReqDTO.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateReqDTO.java @@ -46,7 +46,6 @@ public class CombinationRecordCreateReqDTO { /** * 团长编号 */ - @NotNull(message = "团长编号不能为空") private Long headId; /** * 拼团商品单价 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java index 0d018c2a4..e914470b5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java @@ -1,16 +1,19 @@ package cn.iocoder.yudao.module.promotion.controller.admin.combination; -import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordPageItemRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordSummaryVO; 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.CombinationRecordDO; +import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; +import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService; import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.context.annotation.Lazy; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -19,11 +22,10 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.validation.Valid; -import java.time.Duration; -import java.util.Map; +import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @Tag(name = "管理后台 - 拼团记录") @RestController @@ -32,44 +34,31 @@ import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsync public class CombinationRecordController { @Resource + private CombinationActivityService combinationActivityService; + @Resource + @Lazy private CombinationRecordService combinationRecordService; - // TODO @puhui999:这个缓存不用做哈;主要管理后台,对性能要求不高;不像前段; - /** - * {@link Map} 缓存,通过它异步刷新 {@link #getCombinationRecordSummary0()} 所要的拼团记录统计数据 - */ - private final LoadingCache> combinationRecordSummary = buildAsyncReloadingCache(Duration.ofSeconds(60L), - new CacheLoader>() { - - @Override - public Map load(String key) { - return getCombinationRecordSummary0(); - } - - }); - @GetMapping("/page") @Operation(summary = "获得拼团记录分页") @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") - public CommonResult> getBargainRecordPage(@Valid CombinationRecordReqPageVO pageVO) { - return success(CombinationActivityConvert.INSTANCE.convert( - combinationRecordService.getCombinationRecordPage(pageVO))); + public CommonResult> getBargainRecordPage(@Valid CombinationRecordReqPageVO pageVO) { + PageResult recordPage = combinationRecordService.getCombinationRecordPage(pageVO); + List activities = combinationActivityService.getCombinationActivityListByIds( + convertSet(recordPage.getList(), CombinationRecordDO::getActivityId)); + return success(CombinationActivityConvert.INSTANCE.convert(recordPage, activities)); } - // TODO @puhui999:Map 改成对象,尽量避免 Map 返回结果哈;然后 getCombinationRecordCount、getCombinationRecordsSuccessCount、getRecordsVirtualGroupCount 三个方法,可以合并成一个方法哈,返回这个 vo @GetMapping("/get-summary") @Operation(summary = "获得拼团记录的概要信息", description = "用于拼团记录页面展示") @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") - public CommonResult> getCombinationRecordSummary() { - return success(combinationRecordSummary.getUnchecked("")); // 缓存 - } - - private Map getCombinationRecordSummary0() { - Map hashMap = MapUtil.newHashMap(3); // TODO @puhui999:Maps.newHashMapWithExpectedSize() - hashMap.put("userCount", combinationRecordService.getCombinationRecordCount()); // 获取所有拼团记录 - hashMap.put("successCount", combinationRecordService.getCombinationRecordsSuccessCount()); // 获取成团记录 - hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount()); // 获取虚拟成团记录 - return hashMap; + public CommonResult getCombinationRecordSummary() { + CombinationRecordSummaryVO summaryVO = new CombinationRecordSummaryVO(); + summaryVO.setUserCount(combinationRecordService.getCombinationRecordCount(null, null)); // 获取所有拼团记录 + summaryVO.setSuccessCount(combinationRecordService.getCombinationRecordCount( + CombinationRecordStatusEnum.SUCCESS.getStatus(), null));// 获取成团记录 + summaryVO.setVirtualGroupCount(combinationRecordService.getCombinationRecordCount(null, Boolean.TRUE));// 获取虚拟成团记录 + return success(summaryVO); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordBaseVO.java similarity index 69% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordBaseVO.java index 8e2206dba..18c754dc5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordBaseVO.java @@ -4,14 +4,19 @@ 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; -// TODO @puhui999:可以参考 BargainRecordPageItemRespVO、BargainRecordRespVO 分成两个;一个给记录列表,一个给记录分页 -@Schema(description = "管理后台 - 拼团记录 Response VO") +/** + * 拼团记录 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + * + * @author HUIHUI + */ @Data -public class CombinationRecordRespVO { +public class CombinationRecordBaseVO { @Schema(description = "拼团记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long id; @@ -19,15 +24,37 @@ public class CombinationRecordRespVO { @Schema(description = "拼团活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long activityId; - @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "花开富贵") - private String nickname; - - @Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") - private String avatar; - @Schema(description = "团长编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long headId; + // ========== 用户相关 ========== + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "9430") + @NotNull(message = "用户编号不能为空") + private Long userId; + + @Schema(description = "用户昵称", example = "老芋艿") + private String nickname; + + @Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xxx.jpg") + private String avatar; + + // ========== 商品相关 ========== + + @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23622") + @NotNull(message = "商品 SPU 编号不能为空") + private Long spuId; + + @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "29950") + @NotNull(message = "商品 SKU 编号不能为空") + private Long skuId; + + @Schema(description = "商品名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是大黄豆") + private String spuName; + + @Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") + private String picUrl; + @Schema(description = "过期时间", requiredMode = Schema.RequiredMode.REQUIRED) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime expireTime; @@ -41,12 +68,6 @@ public class CombinationRecordRespVO { @Schema(description = "拼团状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") private Integer status; - @Schema(description = "商品名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是大黄豆") - private String spuName; - - @Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") - private String picUrl; - @Schema(description = "是否虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "false") private Boolean virtualGroup; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordPageItemRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordPageItemRespVO.java new file mode 100644 index 000000000..7b1b10bac --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordPageItemRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod; + +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +@Schema(description = "管理后台 - 拼团记录的分页项 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class CombinationRecordPageItemRespVO extends CombinationRecordBaseVO { + + // ========== 活动相关 ========== + + private CombinationActivityRespVO activity; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordSummaryVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordSummaryVO.java new file mode 100644 index 000000000..64d63afe0 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordSummaryVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - 拼团记录信息统计 Response VO") +@Data +public class CombinationRecordSummaryVO { + + @Schema(description = "所有拼团记录", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Long userCount; + + @Schema(description = "成团记录", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Long successCount; + + @Schema(description = "虚拟成团记录", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Long virtualGroupCount; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java index f22065193..1c8004d35 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java @@ -47,7 +47,7 @@ public class AppCombinationRecordController { public CommonResult getCombinationRecordSummary() { AppCombinationRecordSummaryRespVO summary = new AppCombinationRecordSummaryRespVO(); // 1. 获得拼团记录数量 - Long count = combinationRecordService.getCombinationRecordCount(); + Long count = combinationRecordService.getCombinationRecordCount(null, null); if (count == 0) { summary.setAvatars(Collections.emptyList()); summary.setUserCount(count); 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 26aa60b82..73770e711 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 @@ -14,7 +14,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activit import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; 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.recrod.CombinationRecordRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordPageItemRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityDetailRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordDetailRespVO; @@ -79,6 +79,7 @@ public interface CombinationActivityConvert { }); return pageResult; } + PageResult convertPage(PageResult page); List convertList2(List productDOs); @@ -113,9 +114,8 @@ public interface CombinationActivityConvert { CombinationActivityDO activity, MemberUserRespDTO user, ProductSpuRespDTO spu, ProductSkuRespDTO sku) { return convert(reqDTO) - .setHeadId(reqDTO.getHeadId()) // 显示性再设置一下 .setCount(reqDTO.getCount()) - .setVirtualGroup(false) + .setVirtualGroup(false) // 默认 false 拼团过期都还没有成功,则按照 CombinationActivityDO#virtualGroup 来如果为 true 则执行虚拟成团的逻辑 .setStatus(CombinationRecordStatusEnum.IN_PROGRESS.getStatus()) // 创建后默认状态为进行中 .setStartTime(LocalDateTime.now()) .setExpireTime(activity.getStartTime().plusHours(activity.getLimitDuration())) @@ -176,7 +176,20 @@ public interface CombinationActivityConvert { AppCombinationRecordRespVO convert(CombinationRecordDO record); - PageResult convert(PageResult result); + PageResult convert(PageResult result); + + default PageResult convert(PageResult recordPage, List activities) { + PageResult result = convert(recordPage); + Map activityMap = convertMap(activities, CombinationActivityDO::getId); + result.setList(CollectionUtils.convertList(result.getList(), item -> { + findAndThen(activityMap, item.getActivityId(), activity -> { + item.setActivity(convert(activity)); + }); + return item; + })); + return result; + } + default AppCombinationRecordDetailRespVO convert(Long userId, CombinationRecordDO headRecord, List memberRecords) { AppCombinationRecordDetailRespVO respVO = new AppCombinationRecordDetailRespVO() diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java index 65b797df4..3df56a1b4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java @@ -77,7 +77,6 @@ public class CombinationRecordDO extends BaseDO { */ private Long userId; - // TODO @puhui999:要不去掉这 2 个字段,通过读取解决?如果去掉,相关接口都要处理下哈; /** * 用户昵称 */ 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 e628c5709..7919c3496 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 @@ -100,4 +100,12 @@ public interface CombinationRecordMapper extends BaseMapperX() + .eq(status != null || virtualGroup != null, + CombinationRecordDO::getHeadId, CombinationRecordDO.HEAD_ID_GROUP) // 统计团信息则指定团长 + .eqIfPresent(CombinationRecordDO::getStatus, status) + .eqIfPresent(CombinationRecordDO::getVirtualGroup, virtualGroup)); + } + } 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 adb6cb21a..9468cdc82 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 @@ -84,6 +84,14 @@ public interface CombinationActivityService { */ List getCombinationProductListByActivityIds(Collection activityIds); + /** + * 获得拼团活动列表 + * + * @param ids 拼团活动 ids + * @return 拼团活动的列表 + */ + List getCombinationActivityListByIds(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 1f62b307a..3cb531fcd 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 @@ -204,6 +204,11 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic return combinationProductMapper.selectListByActivityIds(activityIds); } + @Override + public List getCombinationActivityListByIds(Collection ids) { + return combinationActivityMapper.selectList(CombinationActivityDO::getId, ids); + } + @Override public List getCombinationActivityListByCount(Integer count) { return combinationActivityMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus(), count); 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 4a7498b24..35e5ad74b 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 @@ -84,25 +84,13 @@ public interface CombinationRecordService { CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count); /** - * 获取所有拼团记录数 + * 获取拼团记录数 * + * @param status 状态-允许为空 + * @param virtualGroup 是否虚拟成团-允许为空 * @return 记录数 */ - Long getCombinationRecordCount(); - - /** - * 获取成功记录数 - * - * @return 记录数 - */ - Long getCombinationRecordsSuccessCount(); - - /** - * 获取虚拟成团记录数 - * - * @return 记录数 - */ - Long getRecordsVirtualGroupCount(); + Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup); /** * 获取最近的 count 条拼团记录 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index eb52a2c9b..66deddf78 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -177,8 +177,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { CombinationRecordDO recordDO = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku); recordMapper.insert(recordDO); - // 3、如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP - if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, reqDTO.getHeadId())) { + // 3、如果是团长(CombinationRecordCreateReqDTO#headId 为 null 时)需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP + if (reqDTO.getHeadId() == null) { recordMapper.updateById(new CombinationRecordDO().setId(recordDO.getId()).setHeadId(CombinationRecordDO.HEAD_ID_GROUP)); return; } @@ -256,20 +256,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } @Override - public Long getCombinationRecordCount() { - return recordMapper.selectCount(); - } - - @Override - public Long getCombinationRecordsSuccessCount() { - // TODO @puhui999:这个应该要多查询 headId - return recordMapper.selectCount(CombinationRecordDO::getStatus, CombinationRecordStatusEnum.SUCCESS.getStatus()); - } - - @Override - public Long getRecordsVirtualGroupCount() { - // TODO @puhui999:这个应该要多查询 headId;然后,recordMapper 要明确的查询哈,不要直接使用 mapper 来拼接查询条件 - return recordMapper.selectCount(CombinationRecordDO::getVirtualGroup, true); + public Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup) { + return recordMapper.selectRecordCount(status, virtualGroup); } @Override @@ -325,9 +313,9 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return; } // 按照创建时间升序排序 - List recordsSort = sortedAsc(list, CombinationRecordDO::getCreateTime); - CombinationRecordDO newHead = recordsSort.get(0); // 新团长继位 - recordsSort.forEach(item -> { + list.sort(Comparator.comparing(CombinationRecordDO::getCreateTime)); // 影响原 list + CombinationRecordDO newHead = list.get(0); // 新团长继位 + list.forEach(item -> { CombinationRecordDO recordDO = new CombinationRecordDO(); recordDO.setId(item.getId()); if (ObjUtil.equal(item.getId(), newHead.getId())) { // 新团长 @@ -335,7 +323,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } else { recordDO.setHeadId(newHead.getId()); } - recordDO.setUserCount(recordsSort.size()); + recordDO.setUserCount(list.size()); updateRecords.add(recordDO); }); } else { // 情况二:团员 From c71bdd158abd09b1093eb8da66bca9b05237ec9a Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sun, 8 Oct 2023 17:19:39 +0800 Subject: [PATCH 17/19] =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=EF=BC=9A=E5=AE=8C=E5=96=84=20review=20=E6=8F=90=E5=88=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/activity/AppActivityController.java | 90 +++++++++++-------- .../app/activity/vo/AppActivityRespVO.java | 6 +- .../mysql/bargain/BargainActivityMapper.java | 27 ++++-- .../CombinationActivityMapper.java | 28 ++++-- .../SeckillActivityMapper.java | 27 ++++-- .../bargain/BargainActivityService.java | 10 ++- .../bargain/BargainActivityServiceImpl.java | 5 +- .../CombinationActivityService.java | 9 +- .../CombinationActivityServiceImpl.java | 4 +- .../seckill/SeckillActivityService.java | 9 +- .../seckill/SeckillActivityServiceImpl.java | 4 +- .../trade/enums/ErrorCodeConstants.java | 1 + .../trade/dal/redis/RedisKeyConstants.java | 8 ++ .../order/TradeOrderQueryServiceImpl.java | 32 ++++++- .../order/TradeOrderUpdateServiceImpl.java | 6 +- .../system/service/dept/DeptServiceImpl.java | 2 +- 16 files changed, 182 insertions(+), 86 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java index f467923a7..46610edce 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.controller.app.activity; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.map.MapUtil; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.promotion.controller.app.activity.vo.AppActivityRespVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; @@ -21,12 +22,10 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap; @Tag(name = "用户 APP - 营销活动") // 用于提供跨多个活动的 HTTP 接口 @RestController @@ -42,59 +41,72 @@ public class AppActivityController { private BargainActivityService bargainActivityService; @GetMapping("/list-by-spu-id") - @Operation(summary = "获得单个商品,近期参与的每个活动") // 每种活动,只返回一个 + @Operation(summary = "获得单个商品,近期参与的每个活动") @Parameter(name = "spuId", description = "商品编号", required = true) public CommonResult> getActivityListBySpuId(@RequestParam("spuId") Long spuId) { - return success(getAppActivityRespVOList(spuId)); + // 每种活动,只返回一个 + return success(getAppActivityRespVOList(Collections.singletonList(spuId))); } @GetMapping("/list-by-spu-ids") - @Operation(summary = "获得多个商品,近期参与的每个活动") // 每种活动,只返回一个;key 为 SPU 编号 + @Operation(summary = "获得多个商品,近期参与的每个活动") @Parameter(name = "spuIds", description = "商品编号数组", required = true) public CommonResult>> getActivityListBySpuIds(@RequestParam("spuIds") List spuIds) { if (CollUtil.isEmpty(spuIds)) { return success(MapUtil.empty()); } - // TODO @puhui999:要避免这种 1+n 的查询 - Map> map = new HashMap<>(spuIds.size()); - spuIds.forEach(spuId -> { - map.put(spuId, getAppActivityRespVOList(spuId)); - }); - return success(map); + // 每种活动,只返回一个;key 为 SPU 编号 + return success(convertMultiMap(getAppActivityRespVOList(spuIds), AppActivityRespVO::getSpuId)); } - private List getAppActivityRespVOList(Long spuId) { + private List getAppActivityRespVOList(Collection spuIds) { + if (CollUtil.isEmpty(spuIds)) { + return new ArrayList<>(); + } + List activityList = new ArrayList<>(); // 拼团活动 - CombinationActivityDO combination = combinationActivityService.getCombinationActivityBySpuId(spuId); - if (combination != null) { - activityList.add(new AppActivityRespVO() - .setId(combination.getId()) - .setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType()) - .setName(combination.getName()) - .setStartTime(combination.getStartTime()) - .setEndTime(combination.getEndTime())); + List combinationActivities = combinationActivityService.getCombinationActivityBySpuIdsAndStatus( + spuIds, CommonStatusEnum.ENABLE.getStatus()); + if (CollUtil.isNotEmpty(combinationActivities)) { + combinationActivities.forEach(item -> { + activityList.add(new AppActivityRespVO() + .setId(item.getId()) + .setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType()) + .setName(item.getName()) + .setSpuId(item.getSpuId()) + .setStartTime(item.getStartTime()) + .setEndTime(item.getEndTime())); + }); } // 秒杀活动 - SeckillActivityDO seckill = seckillActivityService.getSeckillActivityBySpuId(spuId); - if (seckill != null) { - activityList.add(new AppActivityRespVO() - .setId(seckill.getId()) - .setType(PromotionTypeEnum.SECKILL_ACTIVITY.getType()) - .setName(seckill.getName()) - .setStartTime(seckill.getStartTime()) - .setEndTime(seckill.getEndTime())); + List seckillActivities = seckillActivityService.getSeckillActivityBySpuIdsAndStatus( + spuIds, CommonStatusEnum.ENABLE.getStatus()); + if (CollUtil.isNotEmpty(seckillActivities)) { + seckillActivities.forEach(item -> { + activityList.add(new AppActivityRespVO() + .setId(item.getId()) + .setType(PromotionTypeEnum.SECKILL_ACTIVITY.getType()) + .setName(item.getName()) + .setSpuId(item.getSpuId()) + .setStartTime(item.getStartTime()) + .setEndTime(item.getEndTime())); + }); } - // 秒杀活动 - BargainActivityDO bargain = bargainActivityService.getBargainActivityBySpuId(spuId); - if (bargain != null) { - activityList.add(new AppActivityRespVO() - .setId(bargain.getId()) - .setType(PromotionTypeEnum.BARGAIN_ACTIVITY.getType()) - .setName(bargain.getName()) - .setStartTime(bargain.getStartTime()) - .setEndTime(bargain.getEndTime())); + // 砍价活动 + List bargainActivities = bargainActivityService.getBargainActivityBySpuIdsAndStatus( + spuIds, CommonStatusEnum.ENABLE.getStatus()); + if (CollUtil.isNotEmpty(bargainActivities)) { + bargainActivities.forEach(item -> { + activityList.add(new AppActivityRespVO() + .setId(item.getId()) + .setType(PromotionTypeEnum.BARGAIN_ACTIVITY.getType()) + .setName(item.getName()) + .setSpuId(item.getSpuId()) + .setStartTime(item.getStartTime()) + .setEndTime(item.getEndTime())); + }); } return activityList; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/vo/AppActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/vo/AppActivityRespVO.java index b168e17e8..8cb3b281b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/vo/AppActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/vo/AppActivityRespVO.java @@ -13,12 +13,14 @@ public class AppActivityRespVO { private Long id; @Schema(description = "活动类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - // 对应 PromotionTypeEnum 枚举 - private Integer type; + private Integer type; // 对应 PromotionTypeEnum 枚举 @Schema(description = "活动名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618 大促") private String name; + @Schema(description = "spu 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "618") + private Long spuId; + @Schema(description = "活动开始时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime startTime; 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 7a566c961..894b120c1 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 @@ -8,8 +8,10 @@ import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.Ba import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; import java.time.LocalDateTime; +import java.util.Collection; import java.util.List; /** @@ -83,12 +85,23 @@ public interface BargainActivityMapper extends BaseMapperX { .last("LIMIT " + count)); } - // TODO @puhui999:需要开启状态;另外,是不是可以 limit1,不用 throwEx = false 处理呀?另外,时间要满足噢 - default BargainActivityDO selectOne(Long spuId) { - return selectOne(new LambdaQueryWrapperX() - .eq(BargainActivityDO::getSpuId, spuId) - .orderByDesc(BargainActivityDO::getCreateTime) - , false); - } + /** + * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 + * + * @param spuIds spu 编号 + * @param status 状态 + * @return 砍价活动列表 + */ + @Select("SELECT p1.* " + + "FROM promotion_bargain_activity p1 " + + "INNER JOIN ( " + + " SELECT spu_id, MAX(DISTINCT(create_time)) AS max_create_time " + + " FROM promotion_bargain_activity " + + " WHERE spu_id IN #{spuIds} " + + " GROUP BY spu_id " + + ") p2 " + + "ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " + + "ORDER BY p1.create_time DESC;") + List selectListBySpuIds(Collection spuIds, Integer status); } 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 5334b8c8e..21bb68c31 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 @@ -7,7 +7,10 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import java.util.Collection; import java.util.List; /** @@ -40,12 +43,23 @@ public interface CombinationActivityMapper extends BaseMapperX() - .eq(CombinationActivityDO::getSpuId, spuId) - .orderByDesc(CombinationActivityDO::getCreateTime) - , false); - } + /** + * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 + * + * @param spuIds spu 编号 + * @param status 状态 + * @return 拼团活动列表 + */ + @Select("SELECT p1.* " + + "FROM promotion_combination_activity p1 " + + "INNER JOIN ( " + + " SELECT spu_id, MAX(DISTINCT(create_time)) AS max_create_time " + + " FROM promotion_combination_activity " + + " WHERE spu_id IN #{spuIds} " + + " GROUP BY spu_id " + + ") p2 " + + "ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " + + "ORDER BY p1.create_time DESC;") + List selectListBySpuIds(@Param("spuIds") Collection spuIds, @Param("status") Integer status); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java index 32938ae67..5d210773b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java @@ -9,7 +9,9 @@ import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.activity.AppS import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; +import java.util.Collection; import java.util.List; /** @@ -56,12 +58,23 @@ public interface SeckillActivityMapper extends BaseMapperX { .apply(ObjectUtil.isNotNull(pageReqVO.getConfigId()), "FIND_IN_SET(" + pageReqVO.getConfigId() + ",config_ids) > 0")); } - // TODO @puhui999:需要开启状态;另外,是不是可以 limit1,不用 throwEx = false 处理呀?另外,时间要满足噢; - default SeckillActivityDO selectOne(Long spuId) { - return selectOne(new LambdaQueryWrapperX() - .eq(SeckillActivityDO::getSpuId, spuId) - .orderByDesc(SeckillActivityDO::getCreateTime) - , false); - } + /** + * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 + * + * @param spuIds spu 编号 + * @param status 状态 + * @return 秒杀活动列表 + */ + @Select("SELECT p1.* " + + "FROM promotion_seckill_activity p1 " + + "INNER JOIN ( " + + " SELECT spu_id, MAX(DISTINCT(create_time)) AS max_create_time " + + " FROM promotion_seckill_activity " + + " WHERE spu_id IN #{spuIds} " + + " GROUP BY spu_id " + + ") p2 " + + "ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " + + "ORDER BY p1.create_time DESC;") + List selectListBySpuIds(Collection spuIds, Integer status); } 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 8090ebcb1..375ec6967 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 @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.Ba import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; import javax.validation.Valid; +import java.util.Collection; import java.util.List; import java.util.Set; @@ -99,11 +100,12 @@ public interface BargainActivityService { List getBargainActivityListByCount(Integer count); /** - * 获取指定 spu 编号的活动 + * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 * - * @param spuId spu 编号 - * @return 砍价活动 + * @param spuIds spu 编号 + * @param status 状态 + * @return 砍价活动列表 */ - BargainActivityDO getBargainActivityBySpuId(Long spuId); + List getBargainActivityBySpuIdsAndStatus(Collection spuIds, Integer status); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java index bf4e04084..0905a09a7 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java @@ -20,6 +20,7 @@ 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; @@ -176,8 +177,8 @@ public class BargainActivityServiceImpl implements BargainActivityService { } @Override - public BargainActivityDO getBargainActivityBySpuId(Long spuId) { - return bargainActivityMapper.selectOne(spuId); + public List getBargainActivityBySpuIdsAndStatus(Collection spuIds, Integer status) { + return bargainActivityMapper.selectListBySpuIds(spuIds, 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 9468cdc82..790326cbb 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 @@ -118,11 +118,12 @@ public interface CombinationActivityService { CombinationProductDO selectByActivityIdAndSkuId(Long activityId, Long skuId); /** - * 获取指定 spu 编号的活动 + * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 * - * @param spuId spu 编号 - * @return 拼团活动 + * @param spuIds spu 编号 + * @param status 状态 + * @return 拼团活动列表 */ - CombinationActivityDO getCombinationActivityBySpuId(Long spuId); + List getCombinationActivityBySpuIdsAndStatus(Collection spuIds, Integer status); } 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 3cb531fcd..db907ba36 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 @@ -227,8 +227,8 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic } @Override - public CombinationActivityDO getCombinationActivityBySpuId(Long spuId) { - return combinationActivityMapper.selectOne(spuId); + public List getCombinationActivityBySpuIdsAndStatus(Collection spuIds, Integer status) { + return combinationActivityMapper.selectListBySpuIds(spuIds, status); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java index 0d1b8d327..f71c538a8 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java @@ -120,11 +120,12 @@ public interface SeckillActivityService { SeckillValidateJoinRespDTO validateJoinSeckill(Long activityId, Long skuId, Integer count); /** - * 获取指定 spu 编号的活动 + * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 * - * @param spuId spu 编号 - * @return 秒杀活动 + * @param spuIds spu 编号 + * @param status 状态 + * @return 秒杀活动列表 */ - SeckillActivityDO getSeckillActivityBySpuId(Long spuId); + List getSeckillActivityBySpuIdsAndStatus(Collection spuIds, Integer status); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java index 3aa56d098..d2bbc7466 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java @@ -311,8 +311,8 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { } @Override - public SeckillActivityDO getSeckillActivityBySpuId(Long spuId) { - return seckillActivityMapper.selectOne(spuId); + public List getSeckillActivityBySpuIdsAndStatus(Collection spuIds, Integer status) { + return seckillActivityMapper.selectListBySpuIds(spuIds, status); } } 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 8fb0bf40e..9c11aa9ad 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 @@ -33,6 +33,7 @@ public interface ErrorCodeConstants { ErrorCode ORDER_UPDATE_PRICE_FAIL_PRICE_ERROR = new ErrorCode(1_011_000_028, "支付订单调价失败,原因:调整后支付价格不能小于 0.01 元"); ErrorCode ORDER_DELETE_FAIL_STATUS_NOT_CANCEL = new ErrorCode(1_011_000_029, "交易订单删除失败,订单不是【已取消】状态"); ErrorCode ORDER_RECEIVE_FAIL_DELIVERY_TYPE_NOT_PICK_UP = new ErrorCode(1_011_000_030, "交易订单自提失败,收货方式不是【用户自提】"); + ErrorCode ORDER_UPDATE_ADDRESS_FAIL_STATUS_NOT_DELIVERED = new ErrorCode(1_011_000_031, "交易订单修改收货地址失败,原因:订单已发货"); // ========== After Sale 模块 1-011-000-100 ========== ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1_011_000_100, "售后单不存在"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/redis/RedisKeyConstants.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/redis/RedisKeyConstants.java index f9b7d8f0e..eff48e51c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/redis/RedisKeyConstants.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/redis/RedisKeyConstants.java @@ -15,4 +15,12 @@ public interface RedisKeyConstants { */ String TRADE_NO = "trade_no:"; + /** + * 交易序号的缓存 + * + * KEY 格式:express_track:{code-logisticsNo-receiverMobile} + * VALUE 数据格式 String, 物流信息集合 + */ + String EXPRESS_TRACK = "express_track"; + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java index 4f4fd4f68..7afedcb9a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.trade.service.order; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; @@ -14,11 +15,13 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; 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.dal.redis.RedisKeyConstants; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientFactory; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -143,7 +146,6 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { return tradeOrderItemMapper.selectProductSumByOrderId(convertSet(orders, TradeOrderDO::getId)); } - // TODO @puhui999:可以加个 spring 缓存,30 分钟;主要考虑及时性要求不高,但是每次调用需要钱; /** * 获得订单的物流轨迹 * @@ -160,10 +162,25 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { throw exception(EXPRESS_NOT_EXISTS); } + return getSelf().getExpressTrackList(express.getCode(), order.getLogisticsNo(), order.getReceiverMobile()); + } + + /** + * 查询物流轨迹 + * 加个 spring 缓存,30 分钟;主要考虑及时性要求不高,但是每次调用需要钱;TODO @艿艿:这个时间不会搞了。。。交给你了哈哈哈 + * + * @param code 快递公司编码 + * @param logisticsNo 发货快递单号 + * @param receiverMobile 收、寄件人的电话号码 + * @return 物流轨迹 + */ + @Cacheable(cacheNames = RedisKeyConstants.EXPRESS_TRACK, key = "#code + '-' + #logisticsNo + '-' + #receiverMobile", + condition = "#result != null") + public List getExpressTrackList(String code, String logisticsNo, String receiverMobile) { // 查询物流轨迹 return expressClientFactory.getDefaultExpressClient().getExpressTrackList( - new ExpressTrackQueryReqDTO().setExpressCode(express.getCode()).setLogisticsNo(order.getLogisticsNo()) - .setPhone(order.getReceiverMobile())); + new ExpressTrackQueryReqDTO().setExpressCode(code).setLogisticsNo(logisticsNo) + .setPhone(receiverMobile)); } @Override @@ -199,4 +216,13 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { return tradeOrderItemMapper.selectListByOrderId(orderIds); } + /** + * 获得自身的代理对象,解决 AOP 生效问题 + * + * @return 自己 + */ + private TradeOrderQueryServiceImpl getSelf() { + return SpringUtil.getBean(getClass()); + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 167d50e4d..4b3629a2d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -742,8 +742,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { public void updateOrderAddress(TradeOrderUpdateAddressReqVO reqVO) { // 校验交易订单 TradeOrderDO order = validateOrderExists(reqVO.getId()); - // TODO @puhui999:是否需要校验订单是否发货 - // TODO 发货后是否支持修改收货地址;回答:发货后,不允许修改; + // 发货后,不允许修改; + if (TradeOrderStatusEnum.isDelivered(order.getStatus())) { + throw exception(ORDER_UPDATE_ADDRESS_FAIL_STATUS_NOT_DELIVERED); + } // 更新 tradeOrderMapper.updateById(TradeOrderConvert.INSTANCE.convert(reqVO)); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java index d088242fd..cde5a0021 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java @@ -176,7 +176,7 @@ public class DeptServiceImpl implements DeptService { } @Override - @DataPermission(enable = false) // 禁用数据权限,避免简历不正确的缓存 + @DataPermission(enable = false) // 禁用数据权限,避免建立不正确的缓存 @Cacheable(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST, key = "#id") public Set getChildDeptIdListFromCache(Long id) { List children = getChildDeptList(id); From 2c0f1121cad30631a9f71ca158eb9821d76d2dae Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sun, 8 Oct 2023 17:46:48 +0800 Subject: [PATCH 18/19] =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=EF=BC=9A=E5=AE=8C=E5=96=84=20review=20=E6=8F=90=E5=88=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/combination/CombinationRecordApi.java | 3 +- .../combination/CombinationRecordApiImpl.java | 4 +-- .../combination/CombinationRecordService.java | 5 +-- .../CombinationRecordServiceImpl.java | 32 ++++++------------- 4 files changed, 16 insertions(+), 28 deletions(-) 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 4d61de4f1..0bb767423 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 @@ -29,8 +29,9 @@ public interface CombinationRecordApi { * 创建开团记录 * * @param reqDTO 请求 DTO + * @return 开团记录编号 */ - void createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO); + Long createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO); /** * 查询拼团记录是否成功 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 918f36ec6..d4acba1c3 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 @@ -29,8 +29,8 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { } @Override - public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { - recordService.createCombinationRecord(reqDTO); + public Long createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { + return recordService.createCombinationRecord(reqDTO); } @Override 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 ab16f2df7..dd07a8b93 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 @@ -49,8 +49,9 @@ public interface CombinationRecordService { * 创建拼团记录 * * @param reqDTO 创建信息 + * @return 开团记录编号 */ - void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO); + Long createCombinationRecord(CombinationRecordCreateReqDTO reqDTO); /** * 获得拼团记录 @@ -87,7 +88,7 @@ public interface CombinationRecordService { /** * 获取拼团记录数 * - * @param status 状态-允许为空 + * @param status 状态-允许为空 * @param virtualGroup 是否虚拟成团-允许为空 * @return 记录数 */ diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 53081f1d3..be9eb3bfb 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -31,7 +31,8 @@ import javax.annotation.Resource; import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.afterNow; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.beforeNow; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; @@ -163,7 +164,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Override @Transactional(rollbackFor = Exception.class) - public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { + public Long createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { // 1. 校验拼团活动 KeyValue keyValue = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getActivityId(), reqDTO.getHeadId(), reqDTO.getSkuId(), reqDTO.getCount()); @@ -173,34 +174,19 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku); - // TODO @puhui:有 head 的情况下,以 head 结束为准 + // 3. 如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP + record.setHeadId(record.getHeadId() == null ? CombinationRecordDO.HEAD_ID_GROUP : record.getHeadId()); recordMapper.insert(record); - // 3. 如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP - // TODO @puhui999:是不是只要是团长,record 设置了就好啦,不用 update。。。。 - if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, reqDTO.getHeadId())) { - recordMapper.updateById(new CombinationRecordDO().setId(record.getId()).setHeadId(CombinationRecordDO.HEAD_ID_GROUP)); - return; + if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, record.getHeadId())) { + return record.getId(); } - // TODO 这里要不要弄成异步的;不用异步哈,就是事务好了; // 4、更新拼团相关信息到订单 - updateOrderCombinationInfo(record.getOrderId(), record.getActivityId(), record.getId(), record.getHeadId()); + tradeOrderApi.updateOrderCombinationInfo(record.getOrderId(), record.getActivityId(), record.getId(), record.getHeadId()); // 4、更新拼团记录 updateCombinationRecordWhenCreate(reqDTO.getHeadId(), keyValue.getKey()); - } - - // TODO @puhui999:这个更新,放到 trade 那就好了;createCombinationRecord 返回一个 recordId; - /** - * 更新拼团相关信息到订单 - * - * @param orderId 订单编号 - * @param activityId 拼团活动编号 - * @param combinationRecordId 拼团记录编号 - * @param headId 团长编号 - */ - private void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) { - tradeOrderApi.updateOrderCombinationInfo(orderId, activityId, combinationRecordId, headId); + return record.getId(); } /** From 7b727d5ce2a7e53ec5d3b1765afcafdfae38265b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 8 Oct 2023 21:14:54 +0800 Subject: [PATCH 19/19] =?UTF-8?q?code=20review=EF=BC=9A=E6=8B=BC=E5=9B=A2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/CombinationRecordCreateReqDTO.java | 1 - .../CombinationRecordController.java | 4 +-- .../app/activity/AppActivityController.java | 32 ++++++------------- .../CombinationActivityConvert.java | 19 +++++------ .../combination/CombinationRecordDO.java | 3 ++ .../mysql/bargain/BargainActivityMapper.java | 2 ++ .../CombinationActivityMapper.java | 1 + .../combination/CombinationRecordMapper.java | 3 +- .../SeckillActivityMapper.java | 1 + .../CombinationRecordServiceImpl.java | 11 ++++--- .../order/TradeOrderQueryServiceImpl.java | 4 +-- .../order/TradeOrderUpdateServiceImpl.java | 1 + 12 files changed, 38 insertions(+), 44 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateReqDTO.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateReqDTO.java index 26648abf6..ac86c45ea 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateReqDTO.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateReqDTO.java @@ -4,7 +4,6 @@ import lombok.Data; import javax.validation.constraints.NotNull; -// TODO @芋艿:这块要在看看 /** * 拼团记录的创建 Request DTO * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java index e914470b5..88a026fe2 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java @@ -55,8 +55,8 @@ public class CombinationRecordController { public CommonResult getCombinationRecordSummary() { CombinationRecordSummaryVO summaryVO = new CombinationRecordSummaryVO(); summaryVO.setUserCount(combinationRecordService.getCombinationRecordCount(null, null)); // 获取所有拼团记录 - summaryVO.setSuccessCount(combinationRecordService.getCombinationRecordCount( - CombinationRecordStatusEnum.SUCCESS.getStatus(), null));// 获取成团记录 + summaryVO.setSuccessCount(combinationRecordService.getCombinationRecordCount( // 获取成团记录 + CombinationRecordStatusEnum.SUCCESS.getStatus(), null)); summaryVO.setVirtualGroupCount(combinationRecordService.getCombinationRecordCount(null, Boolean.TRUE));// 获取虚拟成团记录 return success(summaryVO); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java index 46610edce..d611a2735 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java @@ -55,7 +55,6 @@ public class AppActivityController { if (CollUtil.isEmpty(spuIds)) { return success(MapUtil.empty()); } - // 每种活动,只返回一个;key 为 SPU 编号 return success(convertMultiMap(getAppActivityRespVOList(spuIds), AppActivityRespVO::getSpuId)); } @@ -64,20 +63,15 @@ public class AppActivityController { if (CollUtil.isEmpty(spuIds)) { return new ArrayList<>(); } - List activityList = new ArrayList<>(); // 拼团活动 List combinationActivities = combinationActivityService.getCombinationActivityBySpuIdsAndStatus( spuIds, CommonStatusEnum.ENABLE.getStatus()); if (CollUtil.isNotEmpty(combinationActivities)) { combinationActivities.forEach(item -> { - activityList.add(new AppActivityRespVO() - .setId(item.getId()) - .setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType()) - .setName(item.getName()) - .setSpuId(item.getSpuId()) - .setStartTime(item.getStartTime()) - .setEndTime(item.getEndTime())); + activityList.add(new AppActivityRespVO().setId(item.getId()) + .setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType()).setName(item.getName()) + .setSpuId(item.getSpuId()).setStartTime(item.getStartTime()).setEndTime(item.getEndTime())); }); } // 秒杀活动 @@ -85,13 +79,9 @@ public class AppActivityController { spuIds, CommonStatusEnum.ENABLE.getStatus()); if (CollUtil.isNotEmpty(seckillActivities)) { seckillActivities.forEach(item -> { - activityList.add(new AppActivityRespVO() - .setId(item.getId()) - .setType(PromotionTypeEnum.SECKILL_ACTIVITY.getType()) - .setName(item.getName()) - .setSpuId(item.getSpuId()) - .setStartTime(item.getStartTime()) - .setEndTime(item.getEndTime())); + activityList.add(new AppActivityRespVO().setId(item.getId()) + .setType(PromotionTypeEnum.SECKILL_ACTIVITY.getType()).setName(item.getName()) + .setSpuId(item.getSpuId()).setStartTime(item.getStartTime()).setEndTime(item.getEndTime())); }); } // 砍价活动 @@ -99,13 +89,9 @@ public class AppActivityController { spuIds, CommonStatusEnum.ENABLE.getStatus()); if (CollUtil.isNotEmpty(bargainActivities)) { bargainActivities.forEach(item -> { - activityList.add(new AppActivityRespVO() - .setId(item.getId()) - .setType(PromotionTypeEnum.BARGAIN_ACTIVITY.getType()) - .setName(item.getName()) - .setSpuId(item.getSpuId()) - .setStartTime(item.getStartTime()) - .setEndTime(item.getEndTime())); + activityList.add(new AppActivityRespVO().setId(item.getId()) + .setType(PromotionTypeEnum.BARGAIN_ACTIVITY.getType()).setName(item.getName()) + .setSpuId(item.getSpuId()).setStartTime(item.getStartTime()).setEndTime(item.getEndTime())); }); } return activityList; 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 73770e711..a344b48fc 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 @@ -109,22 +109,19 @@ public interface CombinationActivityConvert { CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO); - // TODO @芋艿:在 convert 优化下; default CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO, CombinationActivityDO activity, MemberUserRespDTO user, ProductSpuRespDTO spu, ProductSkuRespDTO sku) { - return convert(reqDTO) - .setCount(reqDTO.getCount()) - .setVirtualGroup(false) // 默认 false 拼团过期都还没有成功,则按照 CombinationActivityDO#virtualGroup 来如果为 true 则执行虚拟成团的逻辑 + return convert(reqDTO).setVirtualGroup(false) .setStatus(CombinationRecordStatusEnum.IN_PROGRESS.getStatus()) // 创建后默认状态为进行中 - .setStartTime(LocalDateTime.now()) + .setStartTime(LocalDateTime.now()) // TODO @puhui999:想了下,这个 startTime 应该是团长的; + // TODO @puhui999:有团长的情况下,expireTime 应该是团长的; .setExpireTime(activity.getStartTime().plusHours(activity.getLimitDuration())) - .setUserSize(activity.getUserSize()) - .setUserCount(1) // 默认就是 1 插入后会接着更新一次所有的拼团记录 - .setNickname(user.getNickname()) - .setAvatar(user.getAvatar()) - .setSpuName(spu.getName()) - .setPicUrl(sku.getPicUrl()); + .setUserSize(activity.getUserSize()).setUserCount(1) // 默认就是 1 插入后会接着更新一次所有的拼团记录 + // 用户信息 + .setNickname(user.getNickname()).setAvatar(user.getAvatar()) + // 商品信息 + .setSpuName(spu.getName()).setPicUrl(sku.getPicUrl()); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java index 3df56a1b4..e1ba90bf1 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java @@ -116,6 +116,9 @@ public class CombinationRecordDO extends BaseDO { private Integer userCount; /** * 是否虚拟成团 + * + * 默认为 false。 + * 拼团过期都还没有成功,如果 {@link CombinationActivityDO#getVirtualGroup()} 为 true,则执行虚拟成团的逻辑,才会更新该字段为 true */ private Boolean virtualGroup; 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 894b120c1..d12056d56 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 @@ -85,6 +85,8 @@ public interface BargainActivityMapper extends BaseMapperX { .last("LIMIT " + count)); } + // TODO @puhui999:一个商品,在统一时间,不会参与多个活动;so 是不是不用 inner join 哈? + // PS:如果可以参与多个,其实可以这样写 select * from promotion_bargain_activity group by spu_id ORDER BY create_time DESC;通过 group 来过滤 /** * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 * 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 21bb68c31..1af92b538 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 @@ -43,6 +43,7 @@ public interface CombinationActivityMapper extends BaseMapperX() .eq(status != null || virtualGroup != null, CombinationRecordDO::getHeadId, CombinationRecordDO.HEAD_ID_GROUP) // 统计团信息则指定团长 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java index 5d210773b..b3b75d36b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java @@ -58,6 +58,7 @@ public interface SeckillActivityMapper extends BaseMapperX { .apply(ObjectUtil.isNotNull(pageReqVO.getConfigId()), "FIND_IN_SET(" + pageReqVO.getConfigId() + ",config_ids) > 0")); } + // TODO @puhui999:类似 BargainActivityMapper /** * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index be9eb3bfb..e0548e7e1 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -169,19 +169,22 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { KeyValue keyValue = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getActivityId(), reqDTO.getHeadId(), reqDTO.getSkuId(), reqDTO.getCount()); - // 2. 组合数据创建拼团记录 + // 2.1 组合数据创建拼团记录 MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku); - // 3. 如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP - record.setHeadId(record.getHeadId() == null ? CombinationRecordDO.HEAD_ID_GROUP : record.getHeadId()); + // 2.2 如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP + if (record.getHeadId() == null) { + record.setHeadId(CombinationRecordDO.HEAD_ID_GROUP); + } recordMapper.insert(record); if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, record.getHeadId())) { return record.getId(); } + // TODO @puhui:是不是这里的更新,放到 order 模块那;支付完成后; // 4、更新拼团相关信息到订单 tradeOrderApi.updateOrderCombinationInfo(record.getOrderId(), record.getActivityId(), record.getId(), record.getHeadId()); // 4、更新拼团记录 @@ -239,7 +242,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Override public Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup) { - return recordMapper.selectRecordCount(status, virtualGroup); + return recordMapper.selectCountByHeadAndStatusAndVirtualGroup(status, virtualGroup); } @Override diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java index 7afedcb9a..eb8a0a244 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java @@ -153,15 +153,15 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { * @return 物流轨迹 */ private List getExpressTrackList(TradeOrderDO order) { - // 查询物流公司 if (order.getLogisticsId() == null) { return Collections.emptyList(); } + // 查询物流公司 DeliveryExpressDO express = deliveryExpressService.getDeliveryExpress(order.getLogisticsId()); if (express == null) { throw exception(EXPRESS_NOT_EXISTS); } - + // 查询物流轨迹 return getSelf().getExpressTrackList(express.getCode(), order.getLogisticsNo(), order.getReceiverMobile()); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 4b3629a2d..74a23ff26 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -743,6 +743,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 校验交易订单 TradeOrderDO order = validateOrderExists(reqVO.getId()); // 发货后,不允许修改; + // TODO @puhui999:只有待发货,可以执行 update if (TradeOrderStatusEnum.isDelivered(order.getStatus())) { throw exception(ORDER_UPDATE_ADDRESS_FAIL_STATUS_NOT_DELIVERED); }