Commit 5f57cc6247ce3ad0cc01a5746c4792f35fe4b008
1 parent
aec8e853
trade:砍价记录的详情 50%
Showing
15 changed files
with
236 additions
and
44 deletions
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 |
| 10 | 10 | import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.activity.AppBargainActivityRespVO; |
| 11 | 11 | import cn.iocoder.yudao.module.promotion.convert.bargain.BargainActivityConvert; |
| 12 | 12 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; |
| 13 | +import cn.iocoder.yudao.module.promotion.enums.bargain.BargainRecordStatusEnum; | |
| 13 | 14 | import cn.iocoder.yudao.module.promotion.service.bargain.BargainActivityService; |
| 15 | +import cn.iocoder.yudao.module.promotion.service.bargain.BargainRecordService; | |
| 14 | 16 | import com.google.common.cache.CacheLoader; |
| 15 | 17 | import com.google.common.cache.LoadingCache; |
| 16 | 18 | import io.swagger.v3.oas.annotations.Operation; |
| ... | ... | @@ -53,6 +55,9 @@ public class AppBargainActivityController { |
| 53 | 55 | @Resource |
| 54 | 56 | private BargainActivityService bargainActivityService; |
| 55 | 57 | @Resource |
| 58 | + private BargainRecordService bargainRecordService; | |
| 59 | + | |
| 60 | + @Resource | |
| 56 | 61 | private ProductSpuApi spuApi; |
| 57 | 62 | |
| 58 | 63 | @GetMapping("/list") |
| ... | ... | @@ -94,8 +99,9 @@ public class AppBargainActivityController { |
| 94 | 99 | return success(null); |
| 95 | 100 | } |
| 96 | 101 | // 拼接数据 |
| 102 | + Integer successUserCount = bargainRecordService.getBargainRecordUserCount(id, BargainRecordStatusEnum.SUCCESS.getStatus()); | |
| 97 | 103 | ProductSpuRespDTO spu = spuApi.getSpu(activity.getSpuId()); |
| 98 | - return success(BargainActivityConvert.INSTANCE.convert(activity, spu)); | |
| 104 | + return success(BargainActivityConvert.INSTANCE.convert(activity, successUserCount, spu)); | |
| 99 | 105 | } |
| 100 | 106 | |
| 101 | 107 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainHelpController.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.controller.app.bargain; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; | |
| 6 | +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; | |
| 4 | 7 | import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.help.AppBargainHelpCreateReqVO; |
| 5 | 8 | import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.help.AppBargainHelpRespVO; |
| 9 | +import cn.iocoder.yudao.module.promotion.convert.bargain.BargainHelpConvert; | |
| 6 | 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainHelpDO; |
| 7 | 11 | import cn.iocoder.yudao.module.promotion.service.bargain.BargainHelpService; |
| 8 | 12 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | 14 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 10 | 15 | import org.springframework.validation.annotation.Validated; |
| 11 | 16 | import org.springframework.web.bind.annotation.*; |
| 12 | 17 | |
| 13 | 18 | import javax.annotation.Resource; |
| 14 | -import java.time.LocalDateTime; | |
| 15 | -import java.util.ArrayList; | |
| 19 | +import java.util.Collections; | |
| 16 | 20 | import java.util.List; |
| 21 | +import java.util.Map; | |
| 17 | 22 | |
| 18 | 23 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 24 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 19 | 25 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 20 | 26 | |
| 21 | 27 | @Tag(name = "用户 App - 砍价助力") |
| ... | ... | @@ -27,6 +33,9 @@ public class AppBargainHelpController { |
| 27 | 33 | @Resource |
| 28 | 34 | private BargainHelpService bargainHelpService; |
| 29 | 35 | |
| 36 | + @Resource | |
| 37 | + private MemberUserApi memberUserApi; | |
| 38 | + | |
| 30 | 39 | @PostMapping("/create") |
| 31 | 40 | @Operation(summary = "创建砍价助力", description = "给拼团记录砍一刀") // 返回结果为砍价金额,单位:分 |
| 32 | 41 | public CommonResult<Integer> createBargainHelp(@RequestBody AppBargainHelpCreateReqVO reqVO) { |
| ... | ... | @@ -36,18 +45,18 @@ public class AppBargainHelpController { |
| 36 | 45 | |
| 37 | 46 | @GetMapping("/list") |
| 38 | 47 | @Operation(summary = "获得砍价助力列表") |
| 39 | - // TODO 芋艿:swagger | |
| 48 | + @Parameter(name = "recordId", description = "砍价记录编号", required = true, example = "111") | |
| 40 | 49 | public CommonResult<List<AppBargainHelpRespVO>> getBargainHelpList(@RequestParam("recordId") Long recordId) { |
| 41 | - List<AppBargainHelpRespVO> list = new ArrayList<>(); | |
| 42 | - for (int i = 0; i < 10; i++) { | |
| 43 | - AppBargainHelpRespVO vo = new AppBargainHelpRespVO(); | |
| 44 | - vo.setNickname("用户" + i); | |
| 45 | - vo.setAvatar("https://www.iocoder.cn/avatar/" + i + ".jpg"); | |
| 46 | - vo.setReducePrice((i + 1) * 100); | |
| 47 | - vo.setCreateTime(LocalDateTime.now()); | |
| 48 | - list.add(vo); | |
| 50 | + List<BargainHelpDO> helps = bargainHelpService.getBargainHelpListByRecordId(recordId); | |
| 51 | + if (CollUtil.isEmpty(helps)) { | |
| 52 | + return success(Collections.emptyList()); | |
| 49 | 53 | } |
| 50 | - return success(list); | |
| 54 | + helps.sort((o1, o2) -> o2.getCreateTime().compareTo(o1.getCreateTime())); // 倒序展示 | |
| 55 | + | |
| 56 | + // 拼接数据 | |
| 57 | + Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap( | |
| 58 | + convertSet(helps, BargainHelpDO::getUserId)); | |
| 59 | + return success(BargainHelpConvert.INSTANCE.convertList(helps, userMap)); | |
| 51 | 60 | } |
| 52 | 61 | |
| 53 | 62 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.controller.app.bargain; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.hutool.core.lang.Assert; | |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 6 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | -import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; | |
| 8 | 8 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; |
| 9 | 9 | import cn.iocoder.yudao.module.member.api.user.MemberUserApi; |
| 10 | 10 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| ... | ... | @@ -19,16 +19,18 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityD |
| 19 | 19 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO; |
| 20 | 20 | import cn.iocoder.yudao.module.promotion.enums.bargain.BargainRecordStatusEnum; |
| 21 | 21 | import cn.iocoder.yudao.module.promotion.service.bargain.BargainActivityService; |
| 22 | +import cn.iocoder.yudao.module.promotion.service.bargain.BargainHelpService; | |
| 22 | 23 | import cn.iocoder.yudao.module.promotion.service.bargain.BargainRecordService; |
| 23 | 24 | import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; |
| 24 | 25 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; |
| 25 | 26 | import io.swagger.v3.oas.annotations.Operation; |
| 27 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 28 | +import io.swagger.v3.oas.annotations.Parameters; | |
| 26 | 29 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 27 | 30 | import org.springframework.validation.annotation.Validated; |
| 28 | 31 | import org.springframework.web.bind.annotation.*; |
| 29 | 32 | |
| 30 | 33 | import javax.annotation.Resource; |
| 31 | -import java.time.Duration; | |
| 32 | 34 | import java.util.Collections; |
| 33 | 35 | import java.util.List; |
| 34 | 36 | import java.util.Map; |
| ... | ... | @@ -47,6 +49,8 @@ public class AppBargainRecordController { |
| 47 | 49 | private BargainRecordService bargainRecordService; |
| 48 | 50 | @Resource |
| 49 | 51 | private BargainActivityService bargainActivityService; |
| 52 | + @Resource | |
| 53 | + private BargainHelpService bargainHelpService; | |
| 50 | 54 | |
| 51 | 55 | @Resource |
| 52 | 56 | private MemberUserApi memberUserApi; |
| ... | ... | @@ -78,23 +82,67 @@ public class AppBargainRecordController { |
| 78 | 82 | |
| 79 | 83 | @GetMapping("/get-detail") |
| 80 | 84 | @Operation(summary = "获得砍价记录的明细") |
| 81 | - // TODO 芋艿:swagger;id 和 activityId 二选一 | |
| 85 | + @Parameters({ | |
| 86 | + @Parameter(name = "id", description = "砍价记录编号", example = "111"), // 场景一:查看指定的砍价记录 | |
| 87 | + @Parameter(name = "activityId", description = "砍价活动编号", example = "222") // 场景二:查看指定的砍价活动 | |
| 88 | + }) | |
| 82 | 89 | public CommonResult<AppBargainRecordDetailRespVO> getBargainRecordDetail( |
| 83 | 90 | @RequestParam(value = "id", required = false) Long id, |
| 84 | 91 | @RequestParam(value = "activityId", required = false) Long activityId) { |
| 85 | - AppBargainRecordDetailRespVO detail = new AppBargainRecordDetailRespVO(); | |
| 86 | - detail.setId(1L); | |
| 87 | - detail.setUserId(1L); | |
| 88 | - detail.setSpuId(1L); | |
| 89 | - detail.setSkuId(1L); | |
| 90 | - detail.setPrice(500); | |
| 91 | - detail.setActivityId(1L); | |
| 92 | - detail.setBargainPrice(150); | |
| 93 | - detail.setPrice(200); | |
| 94 | - detail.setPayPrice(180); | |
| 95 | - detail.setStatus(1); | |
| 96 | - detail.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(2))); | |
| 97 | - return success(detail); | |
| 92 | + // 1. 查询砍价记录 + 砍价活动 | |
| 93 | + Assert.isTrue(id != null || activityId != null, "砍价记录编号和活动编号不能同时为空"); | |
| 94 | + BargainRecordDO record = id != null ? bargainRecordService.getBargainRecord(id) | |
| 95 | + : bargainRecordService.getInProgressBargainRecord(getLoginUserId(), activityId); | |
| 96 | + if (activityId == null || record != null) { | |
| 97 | + activityId = record.getActivityId(); | |
| 98 | + } | |
| 99 | + // 2. 查询助力记录 | |
| 100 | + Integer helpAction = getHelpAction(record, activityId); | |
| 101 | + // 3. 如果是自己的订单,则查询订单信息 | |
| 102 | + // TODO 继续查询别的字段 | |
| 103 | + | |
| 104 | + // 拼接返回 | |
| 105 | + return success(BargainRecordConvert.INSTANCE.convert02(record, helpAction)); | |
| 106 | +// | |
| 107 | +// AppBargainRecordDetailRespVO detail = new AppBargainRecordDetailRespVO(); | |
| 108 | +// detail.setId(1L); | |
| 109 | +// detail.setUserId(1L); | |
| 110 | +// detail.setSpuId(1L); | |
| 111 | +// detail.setSkuId(1L); | |
| 112 | +// detail.setPrice(500); | |
| 113 | +// detail.setActivityId(1L); | |
| 114 | +// detail.setBargainPrice(150); | |
| 115 | +// detail.setPrice(200); | |
| 116 | +// detail.setPayPrice(180); | |
| 117 | +// detail.setStatus(1); | |
| 118 | +// detail.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(2))); | |
| 119 | +// return success(detail); | |
| 120 | + } | |
| 121 | + | |
| 122 | + private Integer getHelpAction(BargainRecordDO record, Long activityId) { | |
| 123 | + // 0.1 如果没有活动,无法帮砍 | |
| 124 | + if (activityId == null) { | |
| 125 | + return null; | |
| 126 | + } | |
| 127 | + // 0.2 如果是自己的砍价记录,无法帮砍 | |
| 128 | + Long userId = getLoginUserId(); | |
| 129 | + if (record != null && record.getUserId().equals(userId)) { | |
| 130 | + return null; | |
| 131 | + } | |
| 132 | + | |
| 133 | + // 1. 判断是否已经助力 | |
| 134 | + if (record != null | |
| 135 | + && bargainHelpService.getBargainHelp(record.getId(), userId) != null) { | |
| 136 | + return AppBargainRecordDetailRespVO.HELP_ACTION_SUCCESS; | |
| 137 | + } | |
| 138 | + // 2. 判断是否满助力 | |
| 139 | + BargainActivityDO activity = bargainActivityService.getBargainActivity(activityId); | |
| 140 | + if (activity != null | |
| 141 | + && bargainHelpService.getBargainHelpCountByActivity(activityId, userId) >= activity.getBargainCount()) { | |
| 142 | + return AppBargainRecordDetailRespVO.HELP_ACTION_FULL; | |
| 143 | + } | |
| 144 | + | |
| 145 | + return AppBargainRecordDetailRespVO.HELP_ACTION_NONE; | |
| 98 | 146 | } |
| 99 | 147 | |
| 100 | 148 | @GetMapping("/page") | ... | ... |
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 { |
| 45 | 45 | @Schema(description = "商品单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "个") // 从 SPU 的 unit 读取,然后转换 |
| 46 | 46 | private String unitName; |
| 47 | 47 | |
| 48 | + @Schema(description = "砍价起始价格,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "200") | |
| 49 | + private Integer bargainFirstPrice; | |
| 50 | + | |
| 48 | 51 | @Schema(description = "砍价最低金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") |
| 49 | - private Integer bargainPrice; | |
| 52 | + private Integer bargainMinPrice; | |
| 50 | 53 | |
| 51 | 54 | @Schema(description = "砍价成功数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") |
| 52 | - private Integer successCount; | |
| 55 | + private Integer successUserCount; | |
| 53 | 56 | |
| 54 | 57 | } | ... | ... |
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; |
| 9 | 9 | @Data |
| 10 | 10 | public class AppBargainHelpRespVO { |
| 11 | 11 | |
| 12 | + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 13 | + private Long userId; | |
| 14 | + | |
| 12 | 15 | @Schema(description = "助力用户的昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 13 | 16 | private String nickname; |
| 14 | 17 | ... | ... |
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; |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.Data; |
| 5 | 5 | |
| 6 | -import java.time.LocalDateTime; | |
| 7 | - | |
| 8 | 6 | @Schema(description = "用户 App - 砍价记录的明细 Response VO") |
| 9 | 7 | @Data |
| 10 | 8 | public class AppBargainRecordDetailRespVO { |
| ... | ... | @@ -13,21 +11,44 @@ public class AppBargainRecordDetailRespVO { |
| 13 | 11 | public static final int HELP_ACTION_FULL = 2; // 帮砍动作 - 未帮砍,无法帮砍(可帮砍次数已满) |
| 14 | 12 | public static final int HELP_ACTION_SUCCESS = 3; // 帮砍动作 - 已帮砍 |
| 15 | 13 | |
| 14 | + // ========== 砍价记录 ========== | |
| 15 | + | |
| 16 | + @Schema(description = "砍价记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 16 | 17 | private Long id; |
| 18 | + | |
| 19 | + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") | |
| 17 | 20 | private Long userId; |
| 21 | + | |
| 22 | + @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") | |
| 18 | 23 | private Long spuId; |
| 24 | + @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") | |
| 19 | 25 | private Long skuId; |
| 26 | + | |
| 27 | + @Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") | |
| 20 | 28 | private Long activityId; |
| 29 | + | |
| 30 | + @Schema(description = "砍价起始价格,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") | |
| 31 | + private Integer bargainFirstPrice; | |
| 32 | + | |
| 33 | + @Schema(description = "当前砍价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") | |
| 21 | 34 | private Integer bargainPrice; |
| 22 | - private Integer price; | |
| 23 | - private Integer payPrice; | |
| 35 | + | |
| 36 | + @Schema(description = "砍价记录状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 24 | 37 | private Integer status; |
| 25 | 38 | |
| 26 | - private LocalDateTime expireTime; | |
| 39 | + // ========== 订单相关 ========== 注意:只有是自己的砍价记录,才会返回,保证隐私性 | |
| 27 | 40 | |
| 41 | + @Schema(description = "订单编号", example = "1024") | |
| 28 | 42 | private Long orderId; |
| 43 | + | |
| 44 | + @Schema(description = "支付状态", example = "true") | |
| 29 | 45 | private Boolean payStatus; |
| 30 | 46 | |
| 47 | + @Schema(description = "支付订单编号", example = "1024") | |
| 48 | + private Long payOrderId; | |
| 49 | + | |
| 50 | + // ========== 助力记录 ========== | |
| 51 | + | |
| 31 | 52 | private Integer helpAction; |
| 32 | 53 | |
| 33 | 54 | } | ... | ... |
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 { |
| 61 | 61 | |
| 62 | 62 | AppBargainActivityDetailRespVO convert1(BargainActivityDO bean); |
| 63 | 63 | |
| 64 | - default AppBargainActivityDetailRespVO convert(BargainActivityDO bean, ProductSpuRespDTO spu) { | |
| 65 | - AppBargainActivityDetailRespVO detail = convert1(bean); | |
| 64 | + default AppBargainActivityDetailRespVO convert(BargainActivityDO bean, Integer successUserCount, ProductSpuRespDTO spu) { | |
| 65 | + AppBargainActivityDetailRespVO detail = convert1(bean).setSuccessUserCount(successUserCount); | |
| 66 | 66 | if (spu != null) { |
| 67 | - detail.setPicUrl(spu.getPicUrl()); | |
| 68 | - detail.setMarketPrice(spu.getMarketPrice()); | |
| 69 | - detail.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())); | |
| 67 | + detail.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()) | |
| 68 | + .setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())); | |
| 70 | 69 | } |
| 71 | 70 | return detail; |
| 72 | 71 | } | ... | ... |
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; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| 5 | 5 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| 6 | 6 | import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.help.BargainHelpRespVO; |
| 7 | +import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.help.AppBargainHelpRespVO; | |
| 7 | 8 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainHelpDO; |
| 8 | 9 | import org.mapstruct.Mapper; |
| 9 | 10 | import org.mapstruct.factory.Mappers; |
| 10 | 11 | |
| 12 | +import java.util.List; | |
| 11 | 13 | import java.util.Map; |
| 12 | 14 | |
| 13 | 15 | /** |
| ... | ... | @@ -31,4 +33,14 @@ public interface BargainHelpConvert { |
| 31 | 33 | } |
| 32 | 34 | PageResult<BargainHelpRespVO> convertPage(PageResult<BargainHelpDO> page); |
| 33 | 35 | |
| 36 | + default List<AppBargainHelpRespVO> convertList(List<BargainHelpDO> helps, | |
| 37 | + Map<Long, MemberUserRespDTO> userMap) { | |
| 38 | + List<AppBargainHelpRespVO> helpVOs = convertList02(helps); | |
| 39 | + helpVOs.forEach(help -> | |
| 40 | + MapUtils.findAndThen(userMap, help.getUserId(), | |
| 41 | + user -> help.setNickname(user.getNickname()).setAvatar(user.getAvatar()))); | |
| 42 | + return helpVOs; | |
| 43 | + } | |
| 44 | + List<AppBargainHelpRespVO> convertList02(List<BargainHelpDO> helps); | |
| 45 | + | |
| 34 | 46 | } | ... | ... |
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; |
| 6 | 6 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| 7 | 7 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 8 | 8 | import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.recrod.BargainRecordPageItemRespVO; |
| 9 | +import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordDetailRespVO; | |
| 9 | 10 | import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordRespVO; |
| 10 | 11 | import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordSummaryRespVO; |
| 11 | 12 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; |
| ... | ... | @@ -82,4 +83,6 @@ public interface BargainRecordConvert { |
| 82 | 83 | return summary; |
| 83 | 84 | } |
| 84 | 85 | |
| 86 | + AppBargainRecordDetailRespVO convert02(BargainRecordDO record, Integer helpAction); | |
| 87 | + | |
| 85 | 88 | } | ... | ... |
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<BargainHelpDO> { |
| 72 | 72 | .orderByDesc(BargainHelpDO::getId)); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | + default List<BargainHelpDO> selectListByRecordId(Long recordId) { | |
| 76 | + return selectList(new LambdaQueryWrapperX<BargainHelpDO>() | |
| 77 | + .eq(BargainHelpDO::getRecordId, recordId)); | |
| 78 | + } | |
| 79 | + | |
| 75 | 80 | } | ... | ... |
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; |
| 15 | 15 | import org.apache.ibatis.annotations.Param; |
| 16 | 16 | import org.apache.ibatis.annotations.Select; |
| 17 | 17 | |
| 18 | +import java.time.LocalDateTime; | |
| 18 | 19 | import java.util.Collection; |
| 19 | 20 | import java.util.Collections; |
| 20 | 21 | import java.util.List; |
| ... | ... | @@ -71,9 +72,16 @@ public interface BargainRecordMapper extends BaseMapperX<BargainRecordDO> { |
| 71 | 72 | record -> MapUtil.getInt(record, "userCount" )); |
| 72 | 73 | } |
| 73 | 74 | |
| 74 | - @Select("SELECT COUNT(DISTINCT(user_id)) FROM promotion_bargain_record WHERE status = #{status}") | |
| 75 | + @Select("SELECT COUNT(DISTINCT(user_id)) FROM promotion_bargain_record " + | |
| 76 | + "WHERE status = #{status}") | |
| 75 | 77 | Integer selectUserCountByStatus(@Param("status") Integer status); |
| 76 | 78 | |
| 79 | + @Select("SELECT COUNT(DISTINCT(user_id)) FROM promotion_bargain_record " + | |
| 80 | + "WHERE activity_id = #{activityId} " + | |
| 81 | + "AND status = #{status}") | |
| 82 | + Integer selectUserCountByActivityIdAndStatus(@Param("activityId") Long activityId, | |
| 83 | + @Param("status") Integer status); | |
| 84 | + | |
| 77 | 85 | default PageResult<BargainRecordDO> selectPage(BargainRecordPageReqVO reqVO) { |
| 78 | 86 | return selectPage(reqVO, new LambdaQueryWrapperX<BargainRecordDO>() |
| 79 | 87 | .eqIfPresent(BargainRecordDO::getStatus, reqVO.getStatus()) |
| ... | ... | @@ -101,7 +109,7 @@ public interface BargainRecordMapper extends BaseMapperX<BargainRecordDO> { |
| 101 | 109 | * @return 更新数量 |
| 102 | 110 | */ |
| 103 | 111 | default int updateOrderIdById(Long id, Long orderId) { |
| 104 | - return update(new BargainRecordDO().setOrderId(orderId), | |
| 112 | + return update(new BargainRecordDO().setOrderId(orderId).setEndTime(LocalDateTime.now()), | |
| 105 | 113 | new LambdaQueryWrapper<>(BargainRecordDO.class) |
| 106 | 114 | .eq(BargainRecordDO::getId, id) |
| 107 | 115 | .isNull(BargainRecordDO::getOrderId)); | ... | ... |
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 |
| 6 | 6 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainHelpDO; |
| 7 | 7 | |
| 8 | 8 | import java.util.Collection; |
| 9 | +import java.util.List; | |
| 9 | 10 | import java.util.Map; |
| 10 | 11 | |
| 11 | 12 | /** |
| ... | ... | @@ -41,6 +42,15 @@ public interface BargainHelpService { |
| 41 | 42 | Map<Long, Integer> getBargainHelpUserCountMapByRecord(Collection<Long> recordIds); |
| 42 | 43 | |
| 43 | 44 | /** |
| 45 | + * 【砍价活动】获得用户的助力次数 | |
| 46 | + * | |
| 47 | + * @param activityId 活动编号 | |
| 48 | + * @param userId 用户编号 | |
| 49 | + * @return 助力次数 | |
| 50 | + */ | |
| 51 | + Long getBargainHelpCountByActivity(Long activityId, Long userId); | |
| 52 | + | |
| 53 | + /** | |
| 44 | 54 | * 获得砍价助力分页 |
| 45 | 55 | * |
| 46 | 56 | * @param pageReqVO 分页查询 |
| ... | ... | @@ -48,4 +58,21 @@ public interface BargainHelpService { |
| 48 | 58 | */ |
| 49 | 59 | PageResult<BargainHelpDO> getBargainHelpPage(BargainHelpPageReqVO pageReqVO); |
| 50 | 60 | |
| 61 | + /** | |
| 62 | + * 获得指定砍价记录编号,对应的砍价助力列表 | |
| 63 | + * | |
| 64 | + * @param recordId 砍价记录编号 | |
| 65 | + * @return 砍价助力列表 | |
| 66 | + */ | |
| 67 | + List<BargainHelpDO> getBargainHelpListByRecordId(Long recordId); | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * 获得助力记录 | |
| 71 | + * | |
| 72 | + * @param recordId 砍价记录编号 | |
| 73 | + * @param userId 用户编号 | |
| 74 | + * @return 助力记录 | |
| 75 | + */ | |
| 76 | + BargainHelpDO getBargainHelp(Long recordId, Long userId); | |
| 77 | + | |
| 51 | 78 | } | ... | ... |
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; |
| 18 | 18 | import javax.annotation.Resource; |
| 19 | 19 | |
| 20 | 20 | import java.util.Collection; |
| 21 | +import java.util.List; | |
| 21 | 22 | import java.util.Map; |
| 22 | 23 | |
| 23 | 24 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| ... | ... | @@ -115,8 +116,23 @@ public class BargainHelpServiceImpl implements BargainHelpService { |
| 115 | 116 | } |
| 116 | 117 | |
| 117 | 118 | @Override |
| 119 | + public Long getBargainHelpCountByActivity(Long activityId, Long userId) { | |
| 120 | + return bargainHelpMapper.selectCountByUserIdAndActivityId(userId, activityId); | |
| 121 | + } | |
| 122 | + | |
| 123 | + @Override | |
| 118 | 124 | public PageResult<BargainHelpDO> getBargainHelpPage(BargainHelpPageReqVO pageReqVO) { |
| 119 | 125 | return bargainHelpMapper.selectPage(pageReqVO); |
| 120 | 126 | } |
| 121 | 127 | |
| 128 | + @Override | |
| 129 | + public List<BargainHelpDO> getBargainHelpListByRecordId(Long recordId) { | |
| 130 | + return bargainHelpMapper.selectListByRecordId(recordId); | |
| 131 | + } | |
| 132 | + | |
| 133 | + @Override | |
| 134 | + public BargainHelpDO getBargainHelp(Long recordId, Long userId) { | |
| 135 | + return bargainHelpMapper.selectByUserIdAndRecordId(userId, recordId); | |
| 136 | + } | |
| 137 | + | |
| 122 | 138 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordService.java
| ... | ... | @@ -74,6 +74,17 @@ public interface BargainRecordService { |
| 74 | 74 | BargainRecordDO getBargainRecord(Long id); |
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | + * 获得用户当前正在【砍价中】+ 指定活动的砍价记录 | |
| 78 | + * | |
| 79 | + * 因为一个用户,在一个砍价活动,【砍价中】只存在一条 | |
| 80 | + * | |
| 81 | + * @param userId 用户编号 | |
| 82 | + * @param activityId 砍价记录编号 | |
| 83 | + * @return 砍价记录 | |
| 84 | + */ | |
| 85 | + BargainRecordDO getInProgressBargainRecord(Long userId, Long activityId); | |
| 86 | + | |
| 87 | + /** | |
| 77 | 88 | * 获得砍价人数 Map |
| 78 | 89 | * |
| 79 | 90 | * @param activityIds 活动编号 |
| ... | ... | @@ -83,7 +94,7 @@ public interface BargainRecordService { |
| 83 | 94 | Map<Long, Integer> getBargainRecordUserCountMap(Collection<Long> activityIds, @Nullable Integer status); |
| 84 | 95 | |
| 85 | 96 | /** |
| 86 | - * 获得砍价人数 Map | |
| 97 | + * 获得砍价人数 | |
| 87 | 98 | * |
| 88 | 99 | * @param status 砍价记录状态 |
| 89 | 100 | * @return 砍价人数 |
| ... | ... | @@ -91,6 +102,15 @@ public interface BargainRecordService { |
| 91 | 102 | Integer getBargainRecordUserCount(Integer status); |
| 92 | 103 | |
| 93 | 104 | /** |
| 105 | + * 获得砍价人数 | |
| 106 | + * | |
| 107 | + * @param activityId 砍价活动编号 | |
| 108 | + * @param status 砍价记录状态 | |
| 109 | + * @return 砍价人数 | |
| 110 | + */ | |
| 111 | + Integer getBargainRecordUserCount(Long activityId, Integer status); | |
| 112 | + | |
| 113 | + /** | |
| 94 | 114 | * 【管理员】获得砍价记录分页 |
| 95 | 115 | * |
| 96 | 116 | * @param pageReqVO 分页查询 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordServiceImpl.java
| ... | ... | @@ -115,6 +115,13 @@ public class BargainRecordServiceImpl implements BargainRecordService { |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | @Override |
| 118 | + public BargainRecordDO getInProgressBargainRecord(Long userId, Long activityId) { | |
| 119 | + List<BargainRecordDO> list = bargainRecordMapper.selectListByUserIdAndActivityIdAndStatus( | |
| 120 | + userId, activityId, BargainRecordStatusEnum.IN_PROGRESS.getStatus()); | |
| 121 | + return CollUtil.getFirst(list); | |
| 122 | + } | |
| 123 | + | |
| 124 | + @Override | |
| 118 | 125 | public Map<Long, Integer> getBargainRecordUserCountMap(Collection<Long> activityIds, @Nullable Integer status) { |
| 119 | 126 | return bargainRecordMapper.selectUserCountByActivityIdsAndStatus(activityIds, status); |
| 120 | 127 | } |
| ... | ... | @@ -125,6 +132,11 @@ public class BargainRecordServiceImpl implements BargainRecordService { |
| 125 | 132 | } |
| 126 | 133 | |
| 127 | 134 | @Override |
| 135 | + public Integer getBargainRecordUserCount(Long activityId, Integer status) { | |
| 136 | + return bargainRecordMapper.selectUserCountByActivityIdAndStatus(activityId, status); | |
| 137 | + } | |
| 138 | + | |
| 139 | + @Override | |
| 128 | 140 | public PageResult<BargainRecordDO> getBargainRecordPage(BargainRecordPageReqVO pageReqVO) { |
| 129 | 141 | return bargainRecordMapper.selectPage(pageReqVO); |
| 130 | 142 | } | ... | ... |