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 | 92 | // 1. 查询砍价记录 + 砍价活动 |
| 93 | 93 | Assert.isTrue(id != null || activityId != null, "砍价记录编号和活动编号不能同时为空"); |
| 94 | 94 | BargainRecordDO record = id != null ? bargainRecordService.getBargainRecord(id) |
| 95 | - : bargainRecordService.getInProgressBargainRecord(getLoginUserId(), activityId); | |
| 95 | + : bargainRecordService.getLastBargainRecord(getLoginUserId(), activityId); | |
| 96 | 96 | if (activityId == null || record != null) { |
| 97 | 97 | activityId = record.getActivityId(); |
| 98 | 98 | } |
| 99 | 99 | // 2. 查询助力记录 |
| 100 | - Integer helpAction = getHelpAction(record, activityId); | |
| 100 | + Long userId = getLoginUserId(); | |
| 101 | + Integer helpAction = getHelpAction(userId, record, activityId); | |
| 101 | 102 | // 3. 如果是自己的订单,则查询订单信息 |
| 103 | + TradeOrderRespDTO order = record != null && record.getOrderId() != null && record.getUserId().equals(getLoginUserId()) | |
| 104 | + ? tradeOrderApi.getOrder(record.getOrderId()) : null; | |
| 102 | 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 | 112 | // 0.1 如果没有活动,无法帮砍 |
| 124 | 113 | if (activityId == null) { |
| 125 | 114 | return null; |
| 126 | 115 | } |
| 127 | 116 | // 0.2 如果是自己的砍价记录,无法帮砍 |
| 128 | - Long userId = getLoginUserId(); | |
| 129 | 117 | if (record != null && record.getUserId().equals(userId)) { |
| 130 | 118 | return null; |
| 131 | 119 | } |
| ... | ... | @@ -141,7 +129,7 @@ public class AppBargainRecordController { |
| 141 | 129 | && bargainHelpService.getBargainHelpCountByActivity(activityId, userId) >= activity.getBargainCount()) { |
| 142 | 130 | return AppBargainRecordDetailRespVO.HELP_ACTION_FULL; |
| 143 | 131 | } |
| 144 | - | |
| 132 | + // 3. 允许助力 | |
| 145 | 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 | 13 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO; |
| 14 | 14 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; |
| 15 | 15 | import org.mapstruct.Mapper; |
| 16 | +import org.mapstruct.Mapping; | |
| 16 | 17 | import org.mapstruct.factory.Mappers; |
| 17 | 18 | |
| 18 | 19 | import java.util.List; |
| ... | ... | @@ -83,6 +84,9 @@ public interface BargainRecordConvert { |
| 83 | 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 | 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 | 53 | default Long selectCountByUserIdAndActivityIdAndStatus( |
| 46 | 54 | Long userId, Long activityId, Integer status) { |
| 47 | 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 | 74 | BargainRecordDO getBargainRecord(Long id); |
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | - * 获得用户当前正在【砍价中】+ 指定活动的砍价记录 | |
| 78 | - * | |
| 79 | - * 因为一个用户,在一个砍价活动,【砍价中】只存在一条 | |
| 77 | + * 获得用户在当前砍价活动中的最后一条砍价记录 | |
| 80 | 78 | * |
| 81 | 79 | * @param userId 用户编号 |
| 82 | 80 | * @param activityId 砍价记录编号 |
| 83 | 81 | * @return 砍价记录 |
| 84 | 82 | */ |
| 85 | - BargainRecordDO getInProgressBargainRecord(Long userId, Long activityId); | |
| 83 | + BargainRecordDO getLastBargainRecord(Long userId, Long activityId); | |
| 86 | 84 | |
| 87 | 85 | /** |
| 88 | 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 | 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); | |
| 118 | + public BargainRecordDO getLastBargainRecord(Long userId, Long activityId) { | |
| 119 | + return bargainRecordMapper.selectLastByUserIdAndActivityId(userId, activityId); | |
| 122 | 120 | } |
| 123 | 121 | |
| 124 | 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 | 22 | */ |
| 23 | 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 | 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 | 35 | } |
| 36 | 36 | |
| 37 | 37 | @Override |
| 38 | + public TradeOrderRespDTO getOrder(Long id) { | |
| 39 | + return TradeOrderConvert.INSTANCE.convert(tradeOrderQueryService.getOrder(id)); | |
| 40 | + } | |
| 41 | + | |
| 42 | + @Override | |
| 38 | 43 | public Integer getOrderStatus(Long id) { |
| 39 | 44 | TradeOrderDO order = tradeOrderQueryService.getOrder(id); |
| 40 | 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 | 38 | import org.mapstruct.Mapper; |
| 39 | 39 | import org.mapstruct.Mapping; |
| 40 | 40 | import org.mapstruct.Mappings; |
| 41 | +import org.mapstruct.Named; | |
| 41 | 42 | import org.mapstruct.factory.Mappers; |
| 42 | 43 | |
| 43 | 44 | import java.util.ArrayList; |
| ... | ... | @@ -261,6 +262,7 @@ public interface TradeOrderConvert { |
| 261 | 262 | return bo; |
| 262 | 263 | } |
| 263 | 264 | |
| 265 | + @Named("convertList04") | |
| 264 | 266 | List<TradeOrderRespDTO> convertList04(List<TradeOrderDO> list); |
| 265 | 267 | |
| 266 | 268 | } | ... | ... |