From 8e7b295d24ac19950556710fd4ea50dde2469fcf Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 6 Oct 2023 10:17:41 +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=20100%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bargain/AppBargainRecordController.java | 28 ++++++------------- .../convert/bargain/BargainRecordConvert.java | 6 +++- .../mysql/bargain/BargainRecordMapper.java | 8 ++++++ .../service/bargain/BargainRecordService.java | 6 ++-- .../bargain/BargainRecordServiceImpl.java | 6 ++-- .../module/trade/api/order/TradeOrderApi.java | 8 ++++++ .../trade/api/order/TradeOrderApiImpl.java | 5 ++++ .../convert/order/TradeOrderConvert.java | 2 ++ 8 files changed, 40 insertions(+), 29 deletions(-) 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 36aa741c3..d37163356 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 @@ -92,40 +92,28 @@ public class AppBargainRecordController { // 1. 查询砍价记录 + 砍价活动 Assert.isTrue(id != null || activityId != null, "砍价记录编号和活动编号不能同时为空"); BargainRecordDO record = id != null ? bargainRecordService.getBargainRecord(id) - : bargainRecordService.getInProgressBargainRecord(getLoginUserId(), activityId); + : bargainRecordService.getLastBargainRecord(getLoginUserId(), activityId); if (activityId == null || record != null) { activityId = record.getActivityId(); } // 2. 查询助力记录 - Integer helpAction = getHelpAction(record, activityId); + Long userId = getLoginUserId(); + Integer helpAction = getHelpAction(userId, record, activityId); // 3. 如果是自己的订单,则查询订单信息 + TradeOrderRespDTO order = record != null && record.getOrderId() != null && record.getUserId().equals(getLoginUserId()) + ? tradeOrderApi.getOrder(record.getOrderId()) : null; // 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); + return success(BargainRecordConvert.INSTANCE.convert02(record, helpAction, order)); } - private Integer getHelpAction(BargainRecordDO record, Long activityId) { + private Integer getHelpAction(Long userId, 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; } @@ -141,7 +129,7 @@ public class AppBargainRecordController { && bargainHelpService.getBargainHelpCountByActivity(activityId, userId) >= activity.getBargainCount()) { return AppBargainRecordDetailRespVO.HELP_ACTION_FULL; } - + // 3. 允许助力 return AppBargainRecordDetailRespVO.HELP_ACTION_NONE; } 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 6c67d647f..5c1bf75a3 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 @@ -13,6 +13,7 @@ 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.trade.api.order.dto.TradeOrderRespDTO; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; import java.util.List; @@ -83,6 +84,9 @@ public interface BargainRecordConvert { return summary; } - AppBargainRecordDetailRespVO convert02(BargainRecordDO record, Integer helpAction); + @Mapping(source = "record.id", target = "id") + @Mapping(source = "record.userId", target = "userId") + @Mapping(source = "record.status", target = "status") + AppBargainRecordDetailRespVO convert02(BargainRecordDO record, Integer helpAction, TradeOrderRespDTO order); } 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 771237428..17560db82 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 @@ -42,6 +42,14 @@ public interface BargainRecordMapper extends BaseMapperX { .eq(BargainRecordDO::getStatus, status)); } + default BargainRecordDO selectLastByUserIdAndActivityId(Long userId, Long activityId) { + return selectOne(new LambdaQueryWrapper<>(BargainRecordDO.class) + .eq(BargainRecordDO::getUserId, userId) + .eq(BargainRecordDO::getActivityId, activityId) + .orderByDesc(BargainRecordDO::getId) + .last("LIMIT 1")); + } + default Long selectCountByUserIdAndActivityIdAndStatus( Long userId, Long activityId, Integer status) { return selectCount(new LambdaQueryWrapper<>(BargainRecordDO.class) 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 f89b86748..e3ba206a1 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 @@ -74,15 +74,13 @@ public interface BargainRecordService { BargainRecordDO getBargainRecord(Long id); /** - * 获得用户当前正在【砍价中】+ 指定活动的砍价记录 - * - * 因为一个用户,在一个砍价活动,【砍价中】只存在一条 + * 获得用户在当前砍价活动中的最后一条砍价记录 * * @param userId 用户编号 * @param activityId 砍价记录编号 * @return 砍价记录 */ - BargainRecordDO getInProgressBargainRecord(Long userId, Long activityId); + BargainRecordDO getLastBargainRecord(Long userId, Long activityId); /** * 获得砍价人数 Map 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 307023d64..aa6db4a74 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 @@ -115,10 +115,8 @@ public class BargainRecordServiceImpl implements BargainRecordService { } @Override - public BargainRecordDO getInProgressBargainRecord(Long userId, Long activityId) { - List list = bargainRecordMapper.selectListByUserIdAndActivityIdAndStatus( - userId, activityId, BargainRecordStatusEnum.IN_PROGRESS.getStatus()); - return CollUtil.getFirst(list); + public BargainRecordDO getLastBargainRecord(Long userId, Long activityId) { + return bargainRecordMapper.selectLastByUserIdAndActivityId(userId, activityId); } @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 5b7594d40..0a6620c14 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 @@ -22,6 +22,14 @@ public interface TradeOrderApi { */ List getOrderList(Collection ids); + /** + * 获得订单 + * + * @param id 订单编号 + * @return 订单 + */ + TradeOrderRespDTO getOrder(Long id); + // TODO 芋艿:看看是不是可以删除掉; /** * 获取订单状态 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 5ad0cb107..39f554e29 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 @@ -34,6 +34,11 @@ public class TradeOrderApiImpl implements TradeOrderApi { return TradeOrderConvert.INSTANCE.convertList04(tradeOrderQueryService.getOrderList(ids)); } + @Override + public TradeOrderRespDTO getOrder(Long id) { + return TradeOrderConvert.INSTANCE.convert(tradeOrderQueryService.getOrder(id)); + } + @Override public Integer getOrderStatus(Long id) { TradeOrderDO order = tradeOrderQueryService.getOrder(id); 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 9255460b3..4b672a2b8 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 @@ -38,6 +38,7 @@ import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; +import org.mapstruct.Named; import org.mapstruct.factory.Mappers; import java.util.ArrayList; @@ -261,6 +262,7 @@ public interface TradeOrderConvert { return bo; } + @Named("convertList04") List convertList04(List list); }