From 5f57cc6247ce3ad0cc01a5746c4792f35fe4b008 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 6 Oct 2023 02:06:38 +0800 Subject: [PATCH] =?UTF-8?q?trade=EF=BC=9A=E7=A0=8D=E4=BB=B7=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E7=9A=84=E8=AF=A6=E6=83=85=2050%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bargain/AppBargainActivityController.java | 8 +- .../app/bargain/AppBargainHelpController.java | 33 +++++--- .../bargain/AppBargainRecordController.java | 80 +++++++++++++++---- .../AppBargainActivityDetailRespVO.java | 7 +- .../bargain/vo/help/AppBargainHelpRespVO.java | 3 + .../record/AppBargainRecordDetailRespVO.java | 31 +++++-- .../bargain/BargainActivityConvert.java | 9 +-- .../convert/bargain/BargainHelpConvert.java | 12 +++ .../convert/bargain/BargainRecordConvert.java | 3 + .../dal/mysql/bargain/BargainHelpMapper.java | 5 ++ .../mysql/bargain/BargainRecordMapper.java | 12 ++- .../service/bargain/BargainHelpService.java | 27 +++++++ .../bargain/BargainHelpServiceImpl.java | 16 ++++ .../service/bargain/BargainRecordService.java | 22 ++++- .../bargain/BargainRecordServiceImpl.java | 12 +++ 15 files changed, 236 insertions(+), 44 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainActivityController.java index 4ced7d565..0de5ba602 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainActivityController.java @@ -10,7 +10,9 @@ import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.activity.AppB import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.activity.AppBargainActivityRespVO; import cn.iocoder.yudao.module.promotion.convert.bargain.BargainActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; +import cn.iocoder.yudao.module.promotion.enums.bargain.BargainRecordStatusEnum; import cn.iocoder.yudao.module.promotion.service.bargain.BargainActivityService; +import cn.iocoder.yudao.module.promotion.service.bargain.BargainRecordService; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import io.swagger.v3.oas.annotations.Operation; @@ -52,6 +54,9 @@ public class AppBargainActivityController { @Resource private BargainActivityService bargainActivityService; + @Resource + private BargainRecordService bargainRecordService; + @Resource private ProductSpuApi spuApi; @@ -94,8 +99,9 @@ public class AppBargainActivityController { return success(null); } // 拼接数据 + Integer successUserCount = bargainRecordService.getBargainRecordUserCount(id, BargainRecordStatusEnum.SUCCESS.getStatus()); ProductSpuRespDTO spu = spuApi.getSpu(activity.getSpuId()); - return success(BargainActivityConvert.INSTANCE.convert(activity, spu)); + return success(BargainActivityConvert.INSTANCE.convert(activity, successUserCount, spu)); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainHelpController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainHelpController.java index 609d8cbb8..48d19ff7f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainHelpController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainHelpController.java @@ -1,21 +1,27 @@ package cn.iocoder.yudao.module.promotion.controller.app.bargain; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.help.AppBargainHelpCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.help.AppBargainHelpRespVO; +import cn.iocoder.yudao.module.promotion.convert.bargain.BargainHelpConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainHelpDO; import cn.iocoder.yudao.module.promotion.service.bargain.BargainHelpService; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import java.time.LocalDateTime; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Map; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @Tag(name = "用户 App - 砍价助力") @@ -27,6 +33,9 @@ public class AppBargainHelpController { @Resource private BargainHelpService bargainHelpService; + @Resource + private MemberUserApi memberUserApi; + @PostMapping("/create") @Operation(summary = "创建砍价助力", description = "给拼团记录砍一刀") // 返回结果为砍价金额,单位:分 public CommonResult createBargainHelp(@RequestBody AppBargainHelpCreateReqVO reqVO) { @@ -36,18 +45,18 @@ public class AppBargainHelpController { @GetMapping("/list") @Operation(summary = "获得砍价助力列表") - // TODO 芋艿:swagger + @Parameter(name = "recordId", description = "砍价记录编号", required = true, example = "111") public CommonResult> getBargainHelpList(@RequestParam("recordId") Long recordId) { - List list = new ArrayList<>(); - for (int i = 0; i < 10; i++) { - AppBargainHelpRespVO vo = new AppBargainHelpRespVO(); - vo.setNickname("用户" + i); - vo.setAvatar("https://www.iocoder.cn/avatar/" + i + ".jpg"); - vo.setReducePrice((i + 1) * 100); - vo.setCreateTime(LocalDateTime.now()); - list.add(vo); + List helps = bargainHelpService.getBargainHelpListByRecordId(recordId); + if (CollUtil.isEmpty(helps)) { + return success(Collections.emptyList()); } - return success(list); + helps.sort((o1, o2) -> o2.getCreateTime().compareTo(o1.getCreateTime())); // 倒序展示 + + // 拼接数据 + Map userMap = memberUserApi.getUserMap( + convertSet(helps, BargainHelpDO::getUserId)); + return success(BargainHelpConvert.INSTANCE.convertList(helps, userMap)); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java index a7bce9265..36aa741c3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java @@ -1,10 +1,10 @@ package cn.iocoder.yudao.module.promotion.controller.app.bargain; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; @@ -19,16 +19,18 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityD import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO; import cn.iocoder.yudao.module.promotion.enums.bargain.BargainRecordStatusEnum; import cn.iocoder.yudao.module.promotion.service.bargain.BargainActivityService; +import cn.iocoder.yudao.module.promotion.service.bargain.BargainHelpService; import cn.iocoder.yudao.module.promotion.service.bargain.BargainRecordService; import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; 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.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Map; @@ -47,6 +49,8 @@ public class AppBargainRecordController { private BargainRecordService bargainRecordService; @Resource private BargainActivityService bargainActivityService; + @Resource + private BargainHelpService bargainHelpService; @Resource private MemberUserApi memberUserApi; @@ -78,23 +82,67 @@ public class AppBargainRecordController { @GetMapping("/get-detail") @Operation(summary = "获得砍价记录的明细") - // TODO 芋艿:swagger;id 和 activityId 二选一 + @Parameters({ + @Parameter(name = "id", description = "砍价记录编号", example = "111"), // 场景一:查看指定的砍价记录 + @Parameter(name = "activityId", description = "砍价活动编号", example = "222") // 场景二:查看指定的砍价活动 + }) public CommonResult getBargainRecordDetail( @RequestParam(value = "id", required = false) Long id, @RequestParam(value = "activityId", required = false) Long activityId) { - AppBargainRecordDetailRespVO detail = new AppBargainRecordDetailRespVO(); - detail.setId(1L); - detail.setUserId(1L); - detail.setSpuId(1L); - detail.setSkuId(1L); - detail.setPrice(500); - detail.setActivityId(1L); - detail.setBargainPrice(150); - detail.setPrice(200); - detail.setPayPrice(180); - detail.setStatus(1); - detail.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(2))); - return success(detail); + // 1. 查询砍价记录 + 砍价活动 + Assert.isTrue(id != null || activityId != null, "砍价记录编号和活动编号不能同时为空"); + BargainRecordDO record = id != null ? bargainRecordService.getBargainRecord(id) + : bargainRecordService.getInProgressBargainRecord(getLoginUserId(), activityId); + if (activityId == null || record != null) { + activityId = record.getActivityId(); + } + // 2. 查询助力记录 + Integer helpAction = getHelpAction(record, activityId); + // 3. 如果是自己的订单,则查询订单信息 + // TODO 继续查询别的字段 + + // 拼接返回 + return success(BargainRecordConvert.INSTANCE.convert02(record, helpAction)); +// +// AppBargainRecordDetailRespVO detail = new AppBargainRecordDetailRespVO(); +// detail.setId(1L); +// detail.setUserId(1L); +// detail.setSpuId(1L); +// detail.setSkuId(1L); +// detail.setPrice(500); +// detail.setActivityId(1L); +// detail.setBargainPrice(150); +// detail.setPrice(200); +// detail.setPayPrice(180); +// detail.setStatus(1); +// detail.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(2))); +// return success(detail); + } + + private Integer getHelpAction(BargainRecordDO record, Long activityId) { + // 0.1 如果没有活动,无法帮砍 + if (activityId == null) { + return null; + } + // 0.2 如果是自己的砍价记录,无法帮砍 + Long userId = getLoginUserId(); + if (record != null && record.getUserId().equals(userId)) { + return null; + } + + // 1. 判断是否已经助力 + if (record != null + && bargainHelpService.getBargainHelp(record.getId(), userId) != null) { + return AppBargainRecordDetailRespVO.HELP_ACTION_SUCCESS; + } + // 2. 判断是否满助力 + BargainActivityDO activity = bargainActivityService.getBargainActivity(activityId); + if (activity != null + && bargainHelpService.getBargainHelpCountByActivity(activityId, userId) >= activity.getBargainCount()) { + return AppBargainRecordDetailRespVO.HELP_ACTION_FULL; + } + + return AppBargainRecordDetailRespVO.HELP_ACTION_NONE; } @GetMapping("/page") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/activity/AppBargainActivityDetailRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/activity/AppBargainActivityDetailRespVO.java index 142028118..4a1f84504 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/activity/AppBargainActivityDetailRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/activity/AppBargainActivityDetailRespVO.java @@ -45,10 +45,13 @@ public class AppBargainActivityDetailRespVO { @Schema(description = "商品单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "个") // 从 SPU 的 unit 读取,然后转换 private String unitName; + @Schema(description = "砍价起始价格,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "200") + private Integer bargainFirstPrice; + @Schema(description = "砍价最低金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") - private Integer bargainPrice; + private Integer bargainMinPrice; @Schema(description = "砍价成功数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") - private Integer successCount; + private Integer successUserCount; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/help/AppBargainHelpRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/help/AppBargainHelpRespVO.java index 5c25fb678..c7bb20fea 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/help/AppBargainHelpRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/help/AppBargainHelpRespVO.java @@ -9,6 +9,9 @@ import java.time.LocalDateTime; @Data public class AppBargainHelpRespVO { + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Long userId; + @Schema(description = "助力用户的昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private String nickname; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/record/AppBargainRecordDetailRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/record/AppBargainRecordDetailRespVO.java index 17997015d..2f408b2c4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/record/AppBargainRecordDetailRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/record/AppBargainRecordDetailRespVO.java @@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import java.time.LocalDateTime; - @Schema(description = "用户 App - 砍价记录的明细 Response VO") @Data public class AppBargainRecordDetailRespVO { @@ -13,21 +11,44 @@ public class AppBargainRecordDetailRespVO { public static final int HELP_ACTION_FULL = 2; // 帮砍动作 - 未帮砍,无法帮砍(可帮砍次数已满) public static final int HELP_ACTION_SUCCESS = 3; // 帮砍动作 - 已帮砍 + // ========== 砍价记录 ========== + + @Schema(description = "砍价记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long id; + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") private Long userId; + + @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") private Long spuId; + @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") private Long skuId; + + @Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") private Long activityId; + + @Schema(description = "砍价起始价格,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") + private Integer bargainFirstPrice; + + @Schema(description = "当前砍价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") private Integer bargainPrice; - private Integer price; - private Integer payPrice; + + @Schema(description = "砍价记录状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") private Integer status; - private LocalDateTime expireTime; + // ========== 订单相关 ========== 注意:只有是自己的砍价记录,才会返回,保证隐私性 + @Schema(description = "订单编号", example = "1024") private Long orderId; + + @Schema(description = "支付状态", example = "true") private Boolean payStatus; + @Schema(description = "支付订单编号", example = "1024") + private Long payOrderId; + + // ========== 助力记录 ========== + private Integer helpAction; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java index 90768978a..47448dfd3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java @@ -61,12 +61,11 @@ public interface BargainActivityConvert { AppBargainActivityDetailRespVO convert1(BargainActivityDO bean); - default AppBargainActivityDetailRespVO convert(BargainActivityDO bean, ProductSpuRespDTO spu) { - AppBargainActivityDetailRespVO detail = convert1(bean); + default AppBargainActivityDetailRespVO convert(BargainActivityDO bean, Integer successUserCount, ProductSpuRespDTO spu) { + AppBargainActivityDetailRespVO detail = convert1(bean).setSuccessUserCount(successUserCount); if (spu != null) { - detail.setPicUrl(spu.getPicUrl()); - detail.setMarketPrice(spu.getMarketPrice()); - detail.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())); + detail.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()) + .setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())); } return detail; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainHelpConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainHelpConvert.java index 0a95d702d..6ec71ce7c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainHelpConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainHelpConvert.java @@ -4,10 +4,12 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.help.BargainHelpRespVO; +import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.help.AppBargainHelpRespVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainHelpDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; +import java.util.List; import java.util.Map; /** @@ -31,4 +33,14 @@ public interface BargainHelpConvert { } PageResult convertPage(PageResult page); + default List convertList(List helps, + Map userMap) { + List helpVOs = convertList02(helps); + helpVOs.forEach(help -> + MapUtils.findAndThen(userMap, help.getUserId(), + user -> help.setNickname(user.getNickname()).setAvatar(user.getAvatar()))); + return helpVOs; + } + List convertList02(List helps); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainRecordConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainRecordConvert.java index 2d94762f7..6c67d647f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainRecordConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainRecordConvert.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.recrod.BargainRecordPageItemRespVO; +import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordDetailRespVO; import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordRespVO; import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordSummaryRespVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; @@ -82,4 +83,6 @@ public interface BargainRecordConvert { return summary; } + AppBargainRecordDetailRespVO convert02(BargainRecordDO record, Integer helpAction); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainHelpMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainHelpMapper.java index 222b78112..8d01ba361 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainHelpMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainHelpMapper.java @@ -72,4 +72,9 @@ public interface BargainHelpMapper extends BaseMapperX { .orderByDesc(BargainHelpDO::getId)); } + default List selectListByRecordId(Long recordId) { + return selectList(new LambdaQueryWrapperX() + .eq(BargainHelpDO::getRecordId, recordId)); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainRecordMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainRecordMapper.java index 51ca4d00d..771237428 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainRecordMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainRecordMapper.java @@ -15,6 +15,7 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; +import java.time.LocalDateTime; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -71,9 +72,16 @@ public interface BargainRecordMapper extends BaseMapperX { record -> MapUtil.getInt(record, "userCount" )); } - @Select("SELECT COUNT(DISTINCT(user_id)) FROM promotion_bargain_record WHERE status = #{status}") + @Select("SELECT COUNT(DISTINCT(user_id)) FROM promotion_bargain_record " + + "WHERE status = #{status}") Integer selectUserCountByStatus(@Param("status") Integer status); + @Select("SELECT COUNT(DISTINCT(user_id)) FROM promotion_bargain_record " + + "WHERE activity_id = #{activityId} " + + "AND status = #{status}") + Integer selectUserCountByActivityIdAndStatus(@Param("activityId") Long activityId, + @Param("status") Integer status); + default PageResult selectPage(BargainRecordPageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() .eqIfPresent(BargainRecordDO::getStatus, reqVO.getStatus()) @@ -101,7 +109,7 @@ public interface BargainRecordMapper extends BaseMapperX { * @return 更新数量 */ default int updateOrderIdById(Long id, Long orderId) { - return update(new BargainRecordDO().setOrderId(orderId), + return update(new BargainRecordDO().setOrderId(orderId).setEndTime(LocalDateTime.now()), new LambdaQueryWrapper<>(BargainRecordDO.class) .eq(BargainRecordDO::getId, id) .isNull(BargainRecordDO::getOrderId)); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainHelpService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainHelpService.java index a617908a5..8aec48597 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainHelpService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainHelpService.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.help.AppBarga import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainHelpDO; import java.util.Collection; +import java.util.List; import java.util.Map; /** @@ -40,6 +41,15 @@ public interface BargainHelpService { */ Map getBargainHelpUserCountMapByRecord(Collection recordIds); + /** + * 【砍价活动】获得用户的助力次数 + * + * @param activityId 活动编号 + * @param userId 用户编号 + * @return 助力次数 + */ + Long getBargainHelpCountByActivity(Long activityId, Long userId); + /** * 获得砍价助力分页 * @@ -48,4 +58,21 @@ public interface BargainHelpService { */ PageResult getBargainHelpPage(BargainHelpPageReqVO pageReqVO); + /** + * 获得指定砍价记录编号,对应的砍价助力列表 + * + * @param recordId 砍价记录编号 + * @return 砍价助力列表 + */ + List getBargainHelpListByRecordId(Long recordId); + + /** + * 获得助力记录 + * + * @param recordId 砍价记录编号 + * @param userId 用户编号 + * @return 助力记录 + */ + BargainHelpDO getBargainHelp(Long recordId, Long userId); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainHelpServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainHelpServiceImpl.java index 238e8a70e..1106ce405 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainHelpServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainHelpServiceImpl.java @@ -18,6 +18,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.Collection; +import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -114,9 +115,24 @@ public class BargainHelpServiceImpl implements BargainHelpService { return bargainHelpMapper.selectUserCountMapByRecordId(recordIds); } + @Override + public Long getBargainHelpCountByActivity(Long activityId, Long userId) { + return bargainHelpMapper.selectCountByUserIdAndActivityId(userId, activityId); + } + @Override public PageResult getBargainHelpPage(BargainHelpPageReqVO pageReqVO) { return bargainHelpMapper.selectPage(pageReqVO); } + @Override + public List getBargainHelpListByRecordId(Long recordId) { + return bargainHelpMapper.selectListByRecordId(recordId); + } + + @Override + public BargainHelpDO getBargainHelp(Long recordId, Long userId) { + return bargainHelpMapper.selectByUserIdAndRecordId(userId, recordId); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordService.java index 23e46abb3..f89b86748 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordService.java @@ -73,6 +73,17 @@ public interface BargainRecordService { */ BargainRecordDO getBargainRecord(Long id); + /** + * 获得用户当前正在【砍价中】+ 指定活动的砍价记录 + * + * 因为一个用户,在一个砍价活动,【砍价中】只存在一条 + * + * @param userId 用户编号 + * @param activityId 砍价记录编号 + * @return 砍价记录 + */ + BargainRecordDO getInProgressBargainRecord(Long userId, Long activityId); + /** * 获得砍价人数 Map * @@ -83,13 +94,22 @@ public interface BargainRecordService { Map getBargainRecordUserCountMap(Collection activityIds, @Nullable Integer status); /** - * 获得砍价人数 Map + * 获得砍价人数 * * @param status 砍价记录状态 * @return 砍价人数 */ Integer getBargainRecordUserCount(Integer status); + /** + * 获得砍价人数 + * + * @param activityId 砍价活动编号 + * @param status 砍价记录状态 + * @return 砍价人数 + */ + Integer getBargainRecordUserCount(Long activityId, Integer status); + /** * 【管理员】获得砍价记录分页 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordServiceImpl.java index f6658f77d..307023d64 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordServiceImpl.java @@ -114,6 +114,13 @@ public class BargainRecordServiceImpl implements BargainRecordService { return bargainRecordMapper.selectById(id); } + @Override + public BargainRecordDO getInProgressBargainRecord(Long userId, Long activityId) { + List list = bargainRecordMapper.selectListByUserIdAndActivityIdAndStatus( + userId, activityId, BargainRecordStatusEnum.IN_PROGRESS.getStatus()); + return CollUtil.getFirst(list); + } + @Override public Map getBargainRecordUserCountMap(Collection activityIds, @Nullable Integer status) { return bargainRecordMapper.selectUserCountByActivityIdsAndStatus(activityIds, status); @@ -124,6 +131,11 @@ public class BargainRecordServiceImpl implements BargainRecordService { return bargainRecordMapper.selectUserCountByStatus(status); } + @Override + public Integer getBargainRecordUserCount(Long activityId, Integer status) { + return bargainRecordMapper.selectUserCountByActivityIdAndStatus(activityId, status); + } + @Override public PageResult getBargainRecordPage(BargainRecordPageReqVO pageReqVO) { return bargainRecordMapper.selectPage(pageReqVO);