Commit 8e7b295d24ac19950556710fd4ea50dde2469fcf
1 parent
5f57cc62
trade:砍价记录的详情 100%
Showing
8 changed files
with
40 additions
and
29 deletions
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 { | @@ -92,40 +92,28 @@ public class AppBargainRecordController { | ||
| 92 | // 1. 查询砍价记录 + 砍价活动 | 92 | // 1. 查询砍价记录 + 砍价活动 |
| 93 | Assert.isTrue(id != null || activityId != null, "砍价记录编号和活动编号不能同时为空"); | 93 | Assert.isTrue(id != null || activityId != null, "砍价记录编号和活动编号不能同时为空"); |
| 94 | BargainRecordDO record = id != null ? bargainRecordService.getBargainRecord(id) | 94 | BargainRecordDO record = id != null ? bargainRecordService.getBargainRecord(id) |
| 95 | - : bargainRecordService.getInProgressBargainRecord(getLoginUserId(), activityId); | 95 | + : bargainRecordService.getLastBargainRecord(getLoginUserId(), activityId); |
| 96 | if (activityId == null || record != null) { | 96 | if (activityId == null || record != null) { |
| 97 | activityId = record.getActivityId(); | 97 | activityId = record.getActivityId(); |
| 98 | } | 98 | } |
| 99 | // 2. 查询助力记录 | 99 | // 2. 查询助力记录 |
| 100 | - Integer helpAction = getHelpAction(record, activityId); | 100 | + Long userId = getLoginUserId(); |
| 101 | + Integer helpAction = getHelpAction(userId, record, activityId); | ||
| 101 | // 3. 如果是自己的订单,则查询订单信息 | 102 | // 3. 如果是自己的订单,则查询订单信息 |
| 103 | + TradeOrderRespDTO order = record != null && record.getOrderId() != null && record.getUserId().equals(getLoginUserId()) | ||
| 104 | + ? tradeOrderApi.getOrder(record.getOrderId()) : null; | ||
| 102 | // TODO 继续查询别的字段 | 105 | // TODO 继续查询别的字段 |
| 103 | 106 | ||
| 104 | // 拼接返回 | 107 | // 拼接返回 |
| 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); | 108 | + return success(BargainRecordConvert.INSTANCE.convert02(record, helpAction, order)); |
| 120 | } | 109 | } |
| 121 | 110 | ||
| 122 | - private Integer getHelpAction(BargainRecordDO record, Long activityId) { | 111 | + private Integer getHelpAction(Long userId, BargainRecordDO record, Long activityId) { |
| 123 | // 0.1 如果没有活动,无法帮砍 | 112 | // 0.1 如果没有活动,无法帮砍 |
| 124 | if (activityId == null) { | 113 | if (activityId == null) { |
| 125 | return null; | 114 | return null; |
| 126 | } | 115 | } |
| 127 | // 0.2 如果是自己的砍价记录,无法帮砍 | 116 | // 0.2 如果是自己的砍价记录,无法帮砍 |
| 128 | - Long userId = getLoginUserId(); | ||
| 129 | if (record != null && record.getUserId().equals(userId)) { | 117 | if (record != null && record.getUserId().equals(userId)) { |
| 130 | return null; | 118 | return null; |
| 131 | } | 119 | } |
| @@ -141,7 +129,7 @@ public class AppBargainRecordController { | @@ -141,7 +129,7 @@ public class AppBargainRecordController { | ||
| 141 | && bargainHelpService.getBargainHelpCountByActivity(activityId, userId) >= activity.getBargainCount()) { | 129 | && bargainHelpService.getBargainHelpCountByActivity(activityId, userId) >= activity.getBargainCount()) { |
| 142 | return AppBargainRecordDetailRespVO.HELP_ACTION_FULL; | 130 | return AppBargainRecordDetailRespVO.HELP_ACTION_FULL; |
| 143 | } | 131 | } |
| 144 | - | 132 | + // 3. 允许助力 |
| 145 | return AppBargainRecordDetailRespVO.HELP_ACTION_NONE; | 133 | return AppBargainRecordDetailRespVO.HELP_ACTION_NONE; |
| 146 | } | 134 | } |
| 147 | 135 |
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 | @@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityD | ||
| 13 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO; | 13 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO; |
| 14 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; | 14 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; |
| 15 | import org.mapstruct.Mapper; | 15 | import org.mapstruct.Mapper; |
| 16 | +import org.mapstruct.Mapping; | ||
| 16 | import org.mapstruct.factory.Mappers; | 17 | import org.mapstruct.factory.Mappers; |
| 17 | 18 | ||
| 18 | import java.util.List; | 19 | import java.util.List; |
| @@ -83,6 +84,9 @@ public interface BargainRecordConvert { | @@ -83,6 +84,9 @@ public interface BargainRecordConvert { | ||
| 83 | return summary; | 84 | return summary; |
| 84 | } | 85 | } |
| 85 | 86 | ||
| 86 | - AppBargainRecordDetailRespVO convert02(BargainRecordDO record, Integer helpAction); | 87 | + @Mapping(source = "record.id", target = "id") |
| 88 | + @Mapping(source = "record.userId", target = "userId") | ||
| 89 | + @Mapping(source = "record.status", target = "status") | ||
| 90 | + AppBargainRecordDetailRespVO convert02(BargainRecordDO record, Integer helpAction, TradeOrderRespDTO order); | ||
| 87 | 91 | ||
| 88 | } | 92 | } |
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<BargainRecordDO> { | @@ -42,6 +42,14 @@ public interface BargainRecordMapper extends BaseMapperX<BargainRecordDO> { | ||
| 42 | .eq(BargainRecordDO::getStatus, status)); | 42 | .eq(BargainRecordDO::getStatus, status)); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | + default BargainRecordDO selectLastByUserIdAndActivityId(Long userId, Long activityId) { | ||
| 46 | + return selectOne(new LambdaQueryWrapper<>(BargainRecordDO.class) | ||
| 47 | + .eq(BargainRecordDO::getUserId, userId) | ||
| 48 | + .eq(BargainRecordDO::getActivityId, activityId) | ||
| 49 | + .orderByDesc(BargainRecordDO::getId) | ||
| 50 | + .last("LIMIT 1")); | ||
| 51 | + } | ||
| 52 | + | ||
| 45 | default Long selectCountByUserIdAndActivityIdAndStatus( | 53 | default Long selectCountByUserIdAndActivityIdAndStatus( |
| 46 | Long userId, Long activityId, Integer status) { | 54 | Long userId, Long activityId, Integer status) { |
| 47 | return selectCount(new LambdaQueryWrapper<>(BargainRecordDO.class) | 55 | return selectCount(new LambdaQueryWrapper<>(BargainRecordDO.class) |
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 { | @@ -74,15 +74,13 @@ public interface BargainRecordService { | ||
| 74 | BargainRecordDO getBargainRecord(Long id); | 74 | BargainRecordDO getBargainRecord(Long id); |
| 75 | 75 | ||
| 76 | /** | 76 | /** |
| 77 | - * 获得用户当前正在【砍价中】+ 指定活动的砍价记录 | ||
| 78 | - * | ||
| 79 | - * 因为一个用户,在一个砍价活动,【砍价中】只存在一条 | 77 | + * 获得用户在当前砍价活动中的最后一条砍价记录 |
| 80 | * | 78 | * |
| 81 | * @param userId 用户编号 | 79 | * @param userId 用户编号 |
| 82 | * @param activityId 砍价记录编号 | 80 | * @param activityId 砍价记录编号 |
| 83 | * @return 砍价记录 | 81 | * @return 砍价记录 |
| 84 | */ | 82 | */ |
| 85 | - BargainRecordDO getInProgressBargainRecord(Long userId, Long activityId); | 83 | + BargainRecordDO getLastBargainRecord(Long userId, Long activityId); |
| 86 | 84 | ||
| 87 | /** | 85 | /** |
| 88 | * 获得砍价人数 Map | 86 | * 获得砍价人数 Map |
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 { | @@ -115,10 +115,8 @@ public class BargainRecordServiceImpl implements BargainRecordService { | ||
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | @Override | 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); | 118 | + public BargainRecordDO getLastBargainRecord(Long userId, Long activityId) { |
| 119 | + return bargainRecordMapper.selectLastByUserIdAndActivityId(userId, activityId); | ||
| 122 | } | 120 | } |
| 123 | 121 | ||
| 124 | @Override | 122 | @Override |
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 { | @@ -22,6 +22,14 @@ public interface TradeOrderApi { | ||
| 22 | */ | 22 | */ |
| 23 | List<TradeOrderRespDTO> getOrderList(Collection<Long> ids); | 23 | List<TradeOrderRespDTO> getOrderList(Collection<Long> ids); |
| 24 | 24 | ||
| 25 | + /** | ||
| 26 | + * 获得订单 | ||
| 27 | + * | ||
| 28 | + * @param id 订单编号 | ||
| 29 | + * @return 订单 | ||
| 30 | + */ | ||
| 31 | + TradeOrderRespDTO getOrder(Long id); | ||
| 32 | + | ||
| 25 | // TODO 芋艿:看看是不是可以删除掉; | 33 | // TODO 芋艿:看看是不是可以删除掉; |
| 26 | /** | 34 | /** |
| 27 | * 获取订单状态 | 35 | * 获取订单状态 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java
| @@ -35,6 +35,11 @@ public class TradeOrderApiImpl implements TradeOrderApi { | @@ -35,6 +35,11 @@ public class TradeOrderApiImpl implements TradeOrderApi { | ||
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | @Override | 37 | @Override |
| 38 | + public TradeOrderRespDTO getOrder(Long id) { | ||
| 39 | + return TradeOrderConvert.INSTANCE.convert(tradeOrderQueryService.getOrder(id)); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + @Override | ||
| 38 | public Integer getOrderStatus(Long id) { | 43 | public Integer getOrderStatus(Long id) { |
| 39 | TradeOrderDO order = tradeOrderQueryService.getOrder(id); | 44 | TradeOrderDO order = tradeOrderQueryService.getOrder(id); |
| 40 | if (order == null) { | 45 | if (order == null) { |
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; | @@ -38,6 +38,7 @@ import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; | ||
| 38 | import org.mapstruct.Mapper; | 38 | import org.mapstruct.Mapper; |
| 39 | import org.mapstruct.Mapping; | 39 | import org.mapstruct.Mapping; |
| 40 | import org.mapstruct.Mappings; | 40 | import org.mapstruct.Mappings; |
| 41 | +import org.mapstruct.Named; | ||
| 41 | import org.mapstruct.factory.Mappers; | 42 | import org.mapstruct.factory.Mappers; |
| 42 | 43 | ||
| 43 | import java.util.ArrayList; | 44 | import java.util.ArrayList; |
| @@ -261,6 +262,7 @@ public interface TradeOrderConvert { | @@ -261,6 +262,7 @@ public interface TradeOrderConvert { | ||
| 261 | return bo; | 262 | return bo; |
| 262 | } | 263 | } |
| 263 | 264 | ||
| 265 | + @Named("convertList04") | ||
| 264 | List<TradeOrderRespDTO> convertList04(List<TradeOrderDO> list); | 266 | List<TradeOrderRespDTO> convertList04(List<TradeOrderDO> list); |
| 265 | 267 | ||
| 266 | } | 268 | } |