Commit 1bda3c8b53bdfa877cd14e1270d67f20d310d4a1
1 parent
6a04d6c4
promotion:完善砍价 API ~ 提交下,准备出门吃饭!!!!
Showing
24 changed files
with
296 additions
and
201 deletions
yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java
| ... | ... | @@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; |
| 7 | 7 | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| 8 | 8 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 9 | 9 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 10 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |
| 10 | 11 | import com.baomidou.mybatisplus.core.metadata.IPage; |
| 11 | 12 | import com.baomidou.mybatisplus.core.toolkit.support.SFunction; |
| 12 | 13 | import com.baomidou.mybatisplus.extension.toolkit.Db; | ... | ... |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainRecordApi.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.api.bargain; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainRecordCreateReqDTO; | |
| 4 | 3 | import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainValidateJoinRespDTO; |
| 5 | 4 | |
| 6 | -import javax.validation.Valid; | |
| 7 | - | |
| 8 | -// TODO @芋艿:后面也再撸撸这几个接口 | |
| 9 | - | |
| 10 | 5 | /** |
| 11 | 6 | * 砍价记录 API 接口 |
| 12 | 7 | * |
| ... | ... | @@ -15,13 +10,6 @@ import javax.validation.Valid; |
| 15 | 10 | public interface BargainRecordApi { |
| 16 | 11 | |
| 17 | 12 | /** |
| 18 | - * 创建砍价记录 | |
| 19 | - * | |
| 20 | - * @param reqDTO 请求 DTO | |
| 21 | - */ | |
| 22 | - void createBargainRecord(@Valid BargainRecordCreateReqDTO reqDTO); | |
| 23 | - | |
| 24 | - /** | |
| 25 | 13 | * 【下单前】校验是否参与砍价活动 |
| 26 | 14 | * <p> |
| 27 | 15 | * 如果校验失败,则抛出业务异常 | ... | ... |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/dto/BargainRecordCreateReqDTO.java deleted
| 1 | -package cn.iocoder.yudao.module.promotion.api.bargain.dto; | |
| 2 | - | |
| 3 | -import lombok.Data; | |
| 4 | - | |
| 5 | -import javax.validation.constraints.NotNull; | |
| 6 | - | |
| 7 | -// TODO @芋艿:这块要在看看 | |
| 8 | - | |
| 9 | -/** | |
| 10 | - * 砍价记录的创建 Request DTO | |
| 11 | - * | |
| 12 | - * @author HUIHUI | |
| 13 | - */ | |
| 14 | -@Data | |
| 15 | -public class BargainRecordCreateReqDTO { | |
| 16 | - | |
| 17 | - /** | |
| 18 | - * 砍价活动编号 | |
| 19 | - */ | |
| 20 | - @NotNull(message = "砍价活动编号不能为空") | |
| 21 | - private Long activityId; | |
| 22 | - /** | |
| 23 | - * spu 编号 | |
| 24 | - */ | |
| 25 | - @NotNull(message = "spu 编号不能为空") | |
| 26 | - private Long spuId; | |
| 27 | - /** | |
| 28 | - * sku 编号 | |
| 29 | - */ | |
| 30 | - @NotNull(message = "sku 编号不能为空") | |
| 31 | - private Long skuId; | |
| 32 | - /** | |
| 33 | - * 用户编号 | |
| 34 | - */ | |
| 35 | - @NotNull(message = "用户编号不能为空") | |
| 36 | - private Long userId; | |
| 37 | - /** | |
| 38 | - * 订单编号 | |
| 39 | - */ | |
| 40 | - @NotNull(message = "订单编号不能为空") | |
| 41 | - private Long orderId; | |
| 42 | - | |
| 43 | - /** | |
| 44 | - * 砍价商品单价 | |
| 45 | - */ | |
| 46 | - @NotNull(message = "砍价底价不能为空") | |
| 47 | - private Integer bargainPrice; | |
| 48 | - /** | |
| 49 | - * 商品原价,单位分 | |
| 50 | - */ | |
| 51 | - @NotNull(message = "商品原价不能为空") | |
| 52 | - private Integer price; | |
| 53 | - | |
| 54 | - // TODO @puhui999:创建时,这个参数不应该传递哈; | |
| 55 | - /** | |
| 56 | - * 开团状态:进行中 砍价成功 砍价失败 | |
| 57 | - */ | |
| 58 | - @NotNull(message = "开团状态不能为空") | |
| 59 | - private Integer status; | |
| 60 | - | |
| 61 | -} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainActivityController.java
| ... | ... | @@ -11,6 +11,8 @@ import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.activity.AppB |
| 11 | 11 | import cn.iocoder.yudao.module.promotion.convert.bargain.BargainActivityConvert; |
| 12 | 12 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; |
| 13 | 13 | import cn.iocoder.yudao.module.promotion.service.bargain.BargainActivityService; |
| 14 | +import com.google.common.cache.CacheLoader; | |
| 15 | +import com.google.common.cache.LoadingCache; | |
| 14 | 16 | import io.swagger.v3.oas.annotations.Operation; |
| 15 | 17 | import io.swagger.v3.oas.annotations.Parameter; |
| 16 | 18 | import io.swagger.v3.oas.annotations.tags.Tag; |
| ... | ... | @@ -21,10 +23,12 @@ import org.springframework.web.bind.annotation.RequestParam; |
| 21 | 23 | import org.springframework.web.bind.annotation.RestController; |
| 22 | 24 | |
| 23 | 25 | import javax.annotation.Resource; |
| 26 | +import java.time.Duration; | |
| 27 | +import java.util.Collections; | |
| 24 | 28 | import java.util.List; |
| 25 | 29 | |
| 26 | -import static cn.hutool.core.util.ObjectUtil.defaultIfNull; | |
| 27 | 30 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 31 | +import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache; | |
| 28 | 32 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| 29 | 33 | |
| 30 | 34 | @Tag(name = "用户 App - 砍价活动") |
| ... | ... | @@ -33,11 +37,42 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. |
| 33 | 37 | @Validated |
| 34 | 38 | public class AppBargainActivityController { |
| 35 | 39 | |
| 40 | + /** | |
| 41 | + * {@link AppBargainActivityRespVO} 缓存,通过它异步刷新 {@link #getBargainActivityList0(Integer)} 所要的首页数据 | |
| 42 | + */ | |
| 43 | + private final LoadingCache<Integer, List<AppBargainActivityRespVO>> bargainActivityListCache = buildAsyncReloadingCache(Duration.ofSeconds(10L), | |
| 44 | + new CacheLoader<Integer, List<AppBargainActivityRespVO>>() { | |
| 45 | + | |
| 46 | + @Override | |
| 47 | + public List<AppBargainActivityRespVO> load(Integer count) { | |
| 48 | + return getBargainActivityList0(count); | |
| 49 | + } | |
| 50 | + | |
| 51 | + }); | |
| 52 | + | |
| 36 | 53 | @Resource |
| 37 | 54 | private BargainActivityService bargainActivityService; |
| 38 | 55 | @Resource |
| 39 | 56 | private ProductSpuApi spuApi; |
| 40 | 57 | |
| 58 | + @GetMapping("/list") | |
| 59 | + @Operation(summary = "获得砍价活动列表", description = "用于小程序首页") | |
| 60 | + @Parameter(name = "count", description = "需要展示的数量", example = "6") | |
| 61 | + public CommonResult<List<AppBargainActivityRespVO>> getBargainActivityList( | |
| 62 | + @RequestParam(name = "count", defaultValue = "6") Integer count) { | |
| 63 | + return success(bargainActivityListCache.getUnchecked(count)); | |
| 64 | + } | |
| 65 | + | |
| 66 | + private List<AppBargainActivityRespVO>getBargainActivityList0(Integer count) { | |
| 67 | + List<BargainActivityDO> list = bargainActivityService.getBargainActivityListByCount(count); | |
| 68 | + if (CollUtil.isEmpty(list)) { | |
| 69 | + return Collections.emptyList(); | |
| 70 | + } | |
| 71 | + // 拼接数据 | |
| 72 | + List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(list, BargainActivityDO::getSpuId)); | |
| 73 | + return BargainActivityConvert.INSTANCE.convertAppList(list, spuList); | |
| 74 | + } | |
| 75 | + | |
| 41 | 76 | @GetMapping("/page") |
| 42 | 77 | @Operation(summary = "获得砍价活动分页") |
| 43 | 78 | public CommonResult<PageResult<AppBargainActivityRespVO>> getBargainActivityPage(PageParam pageReqVO) { |
| ... | ... | @@ -50,21 +85,6 @@ public class AppBargainActivityController { |
| 50 | 85 | return success(BargainActivityConvert.INSTANCE.convertAppPage(result, spuList)); |
| 51 | 86 | } |
| 52 | 87 | |
| 53 | - // TODO 芋艿:增加 Spring Cache | |
| 54 | - @GetMapping("/list") | |
| 55 | - @Operation(summary = "获得砍价活动列表", description = "用于小程序首页") | |
| 56 | - @Parameter(name = "count", description = "需要展示的数量", example = "6") | |
| 57 | - public CommonResult<List<AppBargainActivityRespVO>> getBargainActivityList( | |
| 58 | - @RequestParam(name = "count", defaultValue = "6") Integer count) { | |
| 59 | - List<BargainActivityDO> list = bargainActivityService.getBargainActivityListByCount(defaultIfNull(count, 6)); | |
| 60 | - if (CollUtil.isEmpty(list)) { | |
| 61 | - return success(BargainActivityConvert.INSTANCE.convertAppList(list)); | |
| 62 | - } | |
| 63 | - // 拼接数据 | |
| 64 | - List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(list, BargainActivityDO::getSpuId)); | |
| 65 | - return success(BargainActivityConvert.INSTANCE.convertAppList(list, spuList)); | |
| 66 | - } | |
| 67 | - | |
| 68 | 88 | @GetMapping("/get-detail") |
| 69 | 89 | @Operation(summary = "获得砍价活动详情") |
| 70 | 90 | @Parameter(name = "id", description = "活动编号", example = "1") | ... | ... |
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 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 5 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 7 | import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; |
| 7 | 8 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; |
| 9 | +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; | |
| 10 | +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; | |
| 11 | +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; | |
| 12 | +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | |
| 8 | 13 | import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordCreateReqVO; |
| 9 | 14 | import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordDetailRespVO; |
| 10 | 15 | import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordRespVO; |
| 11 | 16 | import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordSummaryRespVO; |
| 17 | +import cn.iocoder.yudao.module.promotion.convert.bargain.BargainRecordConvert; | |
| 18 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; | |
| 19 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO; | |
| 20 | +import cn.iocoder.yudao.module.promotion.enums.bargain.BargainRecordStatusEnum; | |
| 21 | +import cn.iocoder.yudao.module.promotion.service.bargain.BargainActivityService; | |
| 12 | 22 | import cn.iocoder.yudao.module.promotion.service.bargain.BargainRecordService; |
| 23 | +import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; | |
| 24 | +import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; | |
| 13 | 25 | import io.swagger.v3.oas.annotations.Operation; |
| 14 | 26 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 15 | 27 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -17,9 +29,12 @@ import org.springframework.web.bind.annotation.*; |
| 17 | 29 | |
| 18 | 30 | import javax.annotation.Resource; |
| 19 | 31 | import java.time.Duration; |
| 20 | -import java.util.ArrayList; | |
| 32 | +import java.util.Collections; | |
| 33 | +import java.util.List; | |
| 34 | +import java.util.Map; | |
| 21 | 35 | |
| 22 | 36 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 37 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 23 | 38 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 24 | 39 | |
| 25 | 40 | @Tag(name = "用户 App - 砍价记录") |
| ... | ... | @@ -30,25 +45,35 @@ public class AppBargainRecordController { |
| 30 | 45 | |
| 31 | 46 | @Resource |
| 32 | 47 | private BargainRecordService bargainRecordService; |
| 48 | + @Resource | |
| 49 | + private BargainActivityService bargainActivityService; | |
| 50 | + | |
| 51 | + @Resource | |
| 52 | + private MemberUserApi memberUserApi; | |
| 53 | + @Resource | |
| 54 | + private ProductSpuApi productSpuApi; | |
| 55 | + @Resource | |
| 56 | + private TradeOrderApi tradeOrderApi; | |
| 33 | 57 | |
| 34 | 58 | @GetMapping("/get-summary") |
| 35 | 59 | @Operation(summary = "获得砍价记录的概要信息", description = "用于小程序首页") |
| 36 | - // TODO 芋艿:增加 @Cache 缓存,1 分钟过期 | |
| 37 | 60 | public CommonResult<AppBargainRecordSummaryRespVO> getBargainRecordSummary() { |
| 38 | - AppBargainRecordSummaryRespVO summary = new AppBargainRecordSummaryRespVO(); | |
| 39 | - summary.setUserCount(1024); | |
| 40 | - summary.setSuccessRecords(new ArrayList<>()); | |
| 41 | - AppBargainRecordSummaryRespVO.Record record1 = new AppBargainRecordSummaryRespVO.Record(); | |
| 42 | - record1.setNickname("王**"); | |
| 43 | - record1.setAvatar("https://www.iocoder.cn/xxx.jpg"); | |
| 44 | - record1.setActivityName("天蚕土豆"); | |
| 45 | - AppBargainRecordSummaryRespVO.Record record2 = new AppBargainRecordSummaryRespVO.Record(); | |
| 46 | - record2.setNickname("张**"); | |
| 47 | - record2.setAvatar("https://www.iocoder.cn/yyy.jpg"); | |
| 48 | - record2.setActivityName("斗罗大陆"); | |
| 49 | - summary.getSuccessRecords().add(record1); | |
| 50 | - summary.getSuccessRecords().add(record2); | |
| 51 | - return success(summary); | |
| 61 | + // 砍价成功的用户数量 | |
| 62 | + Integer successUserCount = bargainRecordService.getBargainRecordUserCount( | |
| 63 | + BargainRecordStatusEnum.SUCCESS.getStatus()); | |
| 64 | + if (successUserCount == 0) { | |
| 65 | + return success(new AppBargainRecordSummaryRespVO().setSuccessUserCount(0) | |
| 66 | + .setSuccessList(Collections.emptyList())); | |
| 67 | + } | |
| 68 | + // 砍价成功的用户列表 | |
| 69 | + List<BargainRecordDO> successList = bargainRecordService.getBargainRecordList( | |
| 70 | + BargainRecordStatusEnum.SUCCESS.getStatus(), 7); | |
| 71 | + List<BargainActivityDO> activityList = bargainActivityService.getBargainActivityList( | |
| 72 | + convertSet(successList, BargainRecordDO::getActivityId)); | |
| 73 | + Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap( | |
| 74 | + convertSet(successList, BargainRecordDO::getUserId)); | |
| 75 | + // 拼接返回 | |
| 76 | + return success(BargainRecordConvert.INSTANCE.convert(successUserCount, successList, activityList, userMap)); | |
| 52 | 77 | } |
| 53 | 78 | |
| 54 | 79 | @GetMapping("/get-detail") |
| ... | ... | @@ -75,72 +100,19 @@ public class AppBargainRecordController { |
| 75 | 100 | @GetMapping("/page") |
| 76 | 101 | @Operation(summary = "获得砍价记录的分页") |
| 77 | 102 | public CommonResult<PageResult<AppBargainRecordRespVO>> getBargainRecordPage(PageParam pageParam) { |
| 78 | - PageResult<AppBargainRecordRespVO> page = new PageResult<>(); | |
| 79 | - page.setList(new ArrayList<>()); | |
| 80 | - AppBargainRecordRespVO record1 = new AppBargainRecordRespVO(); | |
| 81 | - record1.setId(1L); | |
| 82 | - record1.setUserId(1L); | |
| 83 | - record1.setSpuId(1L); | |
| 84 | - record1.setSkuId(1L); | |
| 85 | - record1.setPrice(500); | |
| 86 | - record1.setActivityId(1L); | |
| 87 | - record1.setBargainPrice(150); | |
| 88 | - record1.setPrice(200); | |
| 89 | - record1.setPayPrice(180); | |
| 90 | - record1.setStatus(1); | |
| 91 | - record1.setPicUrl("https://static.iocoder.cn/mall/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg"); | |
| 92 | - record1.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(2))); | |
| 93 | - page.getList().add(record1); | |
| 94 | - | |
| 95 | - AppBargainRecordRespVO record2 = new AppBargainRecordRespVO(); | |
| 96 | - record2.setId(1L); | |
| 97 | - record2.setUserId(1L); | |
| 98 | - record2.setSpuId(1L); | |
| 99 | - record2.setSkuId(1L); | |
| 100 | - record2.setPrice(500); | |
| 101 | - record2.setActivityId(1L); | |
| 102 | - record2.setBargainPrice(150); | |
| 103 | - record2.setPrice(200); | |
| 104 | - record2.setPayPrice(280); | |
| 105 | - record2.setStatus(2); | |
| 106 | - record2.setPicUrl("https://static.iocoder.cn/mall/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg"); | |
| 107 | - record2.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(2))); | |
| 108 | - page.getList().add(record2); | |
| 109 | - | |
| 110 | - AppBargainRecordRespVO record3 = new AppBargainRecordRespVO(); | |
| 111 | - record3.setId(1L); | |
| 112 | - record3.setUserId(1L); | |
| 113 | - record3.setSpuId(1L); | |
| 114 | - record3.setSkuId(1L); | |
| 115 | - record3.setPrice(500); | |
| 116 | - record3.setActivityId(1L); | |
| 117 | - record3.setBargainPrice(150); | |
| 118 | - record3.setPrice(200); | |
| 119 | - record3.setPayPrice(380); | |
| 120 | - record3.setStatus(2); | |
| 121 | - record3.setPicUrl("https://static.iocoder.cn/mall/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg"); | |
| 122 | - record3.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(2))); | |
| 123 | - record3.setOrderId(100L); | |
| 124 | - page.getList().add(record3); | |
| 125 | - | |
| 126 | - AppBargainRecordRespVO record4 = new AppBargainRecordRespVO(); | |
| 127 | - record4.setId(1L); | |
| 128 | - record4.setUserId(1L); | |
| 129 | - record4.setSpuId(1L); | |
| 130 | - record4.setSkuId(1L); | |
| 131 | - record4.setPrice(500); | |
| 132 | - record4.setActivityId(1L); | |
| 133 | - record4.setBargainPrice(150); | |
| 134 | - record4.setPrice(200); | |
| 135 | - record4.setPayPrice(380); | |
| 136 | - record4.setStatus(3); | |
| 137 | - record4.setPicUrl("https://static.iocoder.cn/mall/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg"); | |
| 138 | - record4.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(2))); | |
| 139 | - record4.setOrderId(100L); | |
| 140 | - page.getList().add(record4); | |
| 103 | + PageResult<BargainRecordDO> pageResult = bargainRecordService.getBargainRecordPage(getLoginUserId(), pageParam); | |
| 104 | + if (CollUtil.isEmpty(pageResult.getList())) { | |
| 105 | + return success(PageResult.empty(pageResult.getTotal())); | |
| 106 | + } | |
| 141 | 107 | |
| 142 | - page.setTotal(1L); | |
| 143 | - return success(page); | |
| 108 | + // 拼接数据 | |
| 109 | + List<BargainActivityDO> activityList = bargainActivityService.getBargainActivityList( | |
| 110 | + convertSet(pageResult.getList(), BargainRecordDO::getActivityId)); | |
| 111 | + List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList( | |
| 112 | + convertSet(pageResult.getList(), BargainRecordDO::getSpuId)); | |
| 113 | + List<TradeOrderRespDTO> orderList = tradeOrderApi.getOrderList( | |
| 114 | + convertSet(pageResult.getList(), BargainRecordDO::getOrderId)); | |
| 115 | + return success(BargainRecordConvert.INSTANCE.convertPage02(pageResult, activityList, spuList, orderList)); | |
| 144 | 116 | } |
| 145 | 117 | |
| 146 | 118 | @PostMapping("/create") | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/activity/AppBargainActivityRespVO.java
| ... | ... | @@ -30,13 +30,14 @@ public class AppBargainActivityRespVO { |
| 30 | 30 | @Schema(description = "砍价库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "512") |
| 31 | 31 | private Integer stock; |
| 32 | 32 | |
| 33 | - @Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "4096") // 从 SPU 的 picUrl 读取 | |
| 33 | + @Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 picUrl 读取 | |
| 34 | + example = "4096") | |
| 34 | 35 | private String picUrl; |
| 35 | - | |
| 36 | - @Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "50") // 从 SPU 的 marketPrice 读取 | |
| 36 | + @Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 marketPrice 读取 | |
| 37 | + example = "50") | |
| 37 | 38 | private Integer marketPrice; |
| 38 | 39 | |
| 39 | 40 | @Schema(description = "砍价最低金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") |
| 40 | - private Integer bargainPrice; | |
| 41 | + private Integer bargainMinPrice; | |
| 41 | 42 | |
| 42 | 43 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/record/AppBargainRecordRespVO.java
| ... | ... | @@ -9,24 +9,44 @@ import java.time.LocalDateTime; |
| 9 | 9 | @Data |
| 10 | 10 | public class AppBargainRecordRespVO { |
| 11 | 11 | |
| 12 | - // TODO @芋艿:status;如果砍价对应的订单支付超时,算失败么?砍价的支付时间,以 expireTime 为准么? | |
| 13 | - | |
| 12 | + @Schema(description = "砍价记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 14 | 13 | private Long id; |
| 15 | - private Long userId; | |
| 14 | + | |
| 15 | + @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") | |
| 16 | 16 | private Long spuId; |
| 17 | + @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") | |
| 17 | 18 | private Long skuId; |
| 19 | + | |
| 20 | + @Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901") | |
| 18 | 21 | private Long activityId; |
| 19 | - private Integer bargainPrice; | |
| 20 | - private Integer price; | |
| 21 | - private Integer payPrice; | |
| 22 | + | |
| 23 | + @Schema(description = "砍价记录状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 22 | 24 | private Integer status; |
| 23 | - private LocalDateTime expireTime; | |
| 24 | 25 | |
| 25 | - private Long orderId; | |
| 26 | - private Boolean payStatus; | |
| 27 | - private Long payOrderId; | |
| 26 | + @Schema(description = "当前价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "102") | |
| 27 | + private Integer bargainPrice; | |
| 28 | + | |
| 29 | + // ========== 活动相关 ========== | |
| 28 | 30 | |
| 31 | + @Schema(description = "活动名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") | |
| 29 | 32 | private String activityName; |
| 33 | + | |
| 34 | + @Schema(description = "活动结束时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 35 | + private LocalDateTime endTime; | |
| 36 | + | |
| 37 | + @Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 picUrl 读取 | |
| 38 | + example = "https://www.iocoder.cn/xx.png") | |
| 30 | 39 | private String picUrl; |
| 31 | 40 | |
| 41 | + // ========== 订单相关 ========== | |
| 42 | + | |
| 43 | + @Schema(description = "订单编号", example = "1024") | |
| 44 | + private Long orderId; | |
| 45 | + | |
| 46 | + @Schema(description = "支付状态", example = "true") | |
| 47 | + private Boolean payStatus; | |
| 48 | + | |
| 49 | + @Schema(description = "支付订单编号", example = "1024") | |
| 50 | + private Long payOrderId; | |
| 51 | + | |
| 32 | 52 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/vo/record/AppBargainRecordSummaryRespVO.java
| ... | ... | @@ -10,10 +10,10 @@ import java.util.List; |
| 10 | 10 | public class AppBargainRecordSummaryRespVO { |
| 11 | 11 | |
| 12 | 12 | @Schema(description = "砍价用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 13 | - private Integer userCount; | |
| 13 | + private Integer successUserCount; | |
| 14 | 14 | |
| 15 | 15 | @Schema(description = "成功砍价的记录", requiredMode = Schema.RequiredMode.REQUIRED) // 只返回最近的 7 个 |
| 16 | - private List<Record> successRecords; | |
| 16 | + private List<Record> successList; | |
| 17 | 17 | |
| 18 | 18 | @Schema(description = "成功砍价记录") |
| 19 | 19 | @Data | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java
| ... | ... | @@ -27,7 +27,6 @@ import javax.annotation.Resource; |
| 27 | 27 | import java.util.Collections; |
| 28 | 28 | import java.util.List; |
| 29 | 29 | |
| 30 | -import static cn.hutool.core.util.ObjectUtil.defaultIfNull; | |
| 31 | 30 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 32 | 31 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| 33 | 32 | |
| ... | ... | @@ -48,7 +47,7 @@ public class AppCombinationActivityController { |
| 48 | 47 | @Parameter(name = "count", description = "需要展示的数量", example = "6") |
| 49 | 48 | public CommonResult<List<AppCombinationActivityRespVO>> getCombinationActivityList( |
| 50 | 49 | @RequestParam(name = "count", defaultValue = "6") Integer count) { |
| 51 | - List<CombinationActivityDO> list = activityService.getCombinationActivityListByCount(defaultIfNull(count, 6)); | |
| 50 | + List<CombinationActivityDO> list = activityService.getCombinationActivityListByCount(6); | |
| 52 | 51 | if (CollUtil.isEmpty(list)) { |
| 53 | 52 | return success(Collections.emptyList()); |
| 54 | 53 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java
| ... | ... | @@ -74,7 +74,7 @@ public class AppSeckillActivityController { |
| 74 | 74 | @GetMapping("/get-now") |
| 75 | 75 | @Operation(summary = "获得当前秒杀活动", description = "获取当前正在进行的活动,提供给首页使用") |
| 76 | 76 | public CommonResult<AppSeckillActivityNowRespVO> getNowSeckillActivity() { |
| 77 | - return success(nowSeckillActivityCache.getUnchecked("")); | |
| 77 | + return success(nowSeckillActivityCache.getUnchecked("")); // 缓存 | |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | private AppSeckillActivityNowRespVO getNowSeckillActivity0() { | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainRecordConvert.java
| ... | ... | @@ -4,15 +4,21 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| 6 | 6 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| 7 | +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | |
| 7 | 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.AppBargainRecordRespVO; | |
| 10 | +import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordSummaryRespVO; | |
| 8 | 11 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; |
| 9 | 12 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO; |
| 13 | +import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; | |
| 10 | 14 | import org.mapstruct.Mapper; |
| 11 | 15 | import org.mapstruct.factory.Mappers; |
| 12 | 16 | |
| 13 | 17 | import java.util.List; |
| 14 | 18 | import java.util.Map; |
| 15 | 19 | |
| 20 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 21 | + | |
| 16 | 22 | /** |
| 17 | 23 | * 砍价记录 Convert |
| 18 | 24 | * |
| ... | ... | @@ -29,7 +35,7 @@ public interface BargainRecordConvert { |
| 29 | 35 | Map<Long, MemberUserRespDTO> userMap) { |
| 30 | 36 | PageResult<BargainRecordPageItemRespVO> pageResult = convertPage(page); |
| 31 | 37 | // 拼接数据 |
| 32 | - Map<Long, BargainActivityDO> activityMap = CollectionUtils.convertMap(activityList, BargainActivityDO::getId); | |
| 38 | + Map<Long, BargainActivityDO> activityMap = convertMap(activityList, BargainActivityDO::getId); | |
| 33 | 39 | pageResult.getList().forEach(record -> { |
| 34 | 40 | MapUtils.findAndThen(userMap, record.getUserId(), |
| 35 | 41 | user -> record.setNickname(user.getNickname()).setAvatar(user.getAvatar())); |
| ... | ... | @@ -40,4 +46,40 @@ public interface BargainRecordConvert { |
| 40 | 46 | } |
| 41 | 47 | PageResult<BargainRecordPageItemRespVO> convertPage(PageResult<BargainRecordDO> page); |
| 42 | 48 | |
| 49 | + default PageResult<AppBargainRecordRespVO> convertPage02(PageResult<BargainRecordDO> page, | |
| 50 | + List<BargainActivityDO> activityList, | |
| 51 | + List<ProductSpuRespDTO> spuList, | |
| 52 | + List<TradeOrderRespDTO> orderList) { | |
| 53 | + PageResult<AppBargainRecordRespVO> pageResult = convertPage02(page); | |
| 54 | + // 拼接数据 | |
| 55 | + Map<Long, BargainActivityDO> activityMap = convertMap(activityList, BargainActivityDO::getId); | |
| 56 | + Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId); | |
| 57 | + Map<Long, TradeOrderRespDTO> orderMap = convertMap(orderList, TradeOrderRespDTO::getId); | |
| 58 | + pageResult.getList().forEach(record -> { | |
| 59 | + MapUtils.findAndThen(activityMap, record.getActivityId(), | |
| 60 | + activity -> record.setActivityName(activity.getName()).setEndTime(activity.getEndTime())); | |
| 61 | + MapUtils.findAndThen(spuMap, record.getSpuId(), | |
| 62 | + spu -> record.setPicUrl(record.getPicUrl())); | |
| 63 | + MapUtils.findAndThen(orderMap, record.getOrderId(), | |
| 64 | + order -> record.setPayStatus(order.getPayStatus()).setPayOrderId(order.getPayOrderId())); | |
| 65 | + }); | |
| 66 | + return pageResult; | |
| 67 | + } | |
| 68 | + PageResult<AppBargainRecordRespVO> convertPage02(PageResult<BargainRecordDO> page); | |
| 69 | + | |
| 70 | + default AppBargainRecordSummaryRespVO convert(Integer successUserCount, List<BargainRecordDO> successList, | |
| 71 | + List<BargainActivityDO> activityList, Map<Long, MemberUserRespDTO> userMap) { | |
| 72 | + AppBargainRecordSummaryRespVO summary = new AppBargainRecordSummaryRespVO().setSuccessUserCount(successUserCount); | |
| 73 | + Map<Long, BargainActivityDO> activityMap = convertMap(activityList, BargainActivityDO::getId); | |
| 74 | + summary.setSuccessList(CollectionUtils.convertList(successList, record -> { | |
| 75 | + AppBargainRecordSummaryRespVO.Record recordVO = new AppBargainRecordSummaryRespVO.Record(); | |
| 76 | + MapUtils.findAndThen(userMap, record.getUserId(), | |
| 77 | + user -> recordVO.setNickname(user.getNickname()).setAvatar(user.getAvatar())); | |
| 78 | + MapUtils.findAndThen(activityMap, record.getActivityId(), | |
| 79 | + activity -> recordVO.setActivityName(activity.getName())); | |
| 80 | + return recordVO; | |
| 81 | + })); | |
| 82 | + return summary; | |
| 83 | + } | |
| 84 | + | |
| 43 | 85 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainHelpMapper.java
| ... | ... | @@ -26,7 +26,7 @@ public interface BargainHelpMapper extends BaseMapperX<BargainHelpDO> { |
| 26 | 26 | .eq(BargainHelpDO::getActivityId, activityId)); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - default Long selectCountByRecordId(Long recordId) { | |
| 29 | + default Long selectUserCountMapByRecordId(Long recordId) { | |
| 30 | 30 | return selectCount(BargainHelpDO::getRecordId, recordId); |
| 31 | 31 | } |
| 32 | 32 | |
| ... | ... | @@ -36,7 +36,7 @@ public interface BargainHelpMapper extends BaseMapperX<BargainHelpDO> { |
| 36 | 36 | .eq(BargainHelpDO::getRecordId, recordId)); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - default Map<Long, Integer> selectCountByActivityId(Collection<Long> activityIds) { | |
| 39 | + default Map<Long, Integer> selectUserCountMapByActivityId(Collection<Long> activityIds) { | |
| 40 | 40 | // SQL count 查询 |
| 41 | 41 | List<Map<String, Object>> result = selectMaps(new QueryWrapper<BargainHelpDO>() |
| 42 | 42 | .select("COUNT(DISTINCT(user_id)) AS userCount, activity_id AS activityId") |
| ... | ... | @@ -51,7 +51,7 @@ public interface BargainHelpMapper extends BaseMapperX<BargainHelpDO> { |
| 51 | 51 | record -> MapUtil.getInt(record, "userCount" )); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - default Map<Long, Integer> selectCountByRecordId(Collection<Long> recordIds) { | |
| 54 | + default Map<Long, Integer> selectUserCountMapByRecordId(Collection<Long> recordIds) { | |
| 55 | 55 | // SQL count 查询 |
| 56 | 56 | List<Map<String, Object>> result = selectMaps(new QueryWrapper<BargainHelpDO>() |
| 57 | 57 | .select("COUNT(1) AS userCount, record_id AS recordId") | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainRecordMapper.java
| ... | ... | @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.bargain; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.map.MapUtil; |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 5 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 7 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 7 | 8 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| ... | ... | @@ -11,6 +12,8 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO; |
| 11 | 12 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 12 | 13 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 13 | 14 | import org.apache.ibatis.annotations.Mapper; |
| 15 | +import org.apache.ibatis.annotations.Param; | |
| 16 | +import org.apache.ibatis.annotations.Select; | |
| 14 | 17 | |
| 15 | 18 | import java.util.Collection; |
| 16 | 19 | import java.util.Collections; |
| ... | ... | @@ -52,7 +55,7 @@ public interface BargainRecordMapper extends BaseMapperX<BargainRecordDO> { |
| 52 | 55 | .eq(BargainRecordDO::getBargainPrice, whereBargainPrice)); |
| 53 | 56 | } |
| 54 | 57 | |
| 55 | - default Map<Long, Integer> selectCountByActivityIdsAndStatus(Collection<Long> activityIds, Integer status) { | |
| 58 | + default Map<Long, Integer> selectUserCountByActivityIdsAndStatus(Collection<Long> activityIds, Integer status) { | |
| 56 | 59 | // SQL count 查询 |
| 57 | 60 | List<Map<String, Object>> result = selectMaps(new QueryWrapper<BargainRecordDO>() |
| 58 | 61 | .select("COUNT(DISTINCT(user_id)) AS userCount, activity_id AS activityId") |
| ... | ... | @@ -68,6 +71,9 @@ public interface BargainRecordMapper extends BaseMapperX<BargainRecordDO> { |
| 68 | 71 | record -> MapUtil.getInt(record, "userCount" )); |
| 69 | 72 | } |
| 70 | 73 | |
| 74 | + @Select("SELECT COUNT(DISTINCT(user_id)) FROM promotion_bargain_record WHERE status = #{status}") | |
| 75 | + Integer selectUserCountByStatus(@Param("status") Integer status); | |
| 76 | + | |
| 71 | 77 | default PageResult<BargainRecordDO> selectPage(BargainRecordPageReqVO reqVO) { |
| 72 | 78 | return selectPage(reqVO, new LambdaQueryWrapperX<BargainRecordDO>() |
| 73 | 79 | .eqIfPresent(BargainRecordDO::getStatus, reqVO.getStatus()) |
| ... | ... | @@ -75,4 +81,16 @@ public interface BargainRecordMapper extends BaseMapperX<BargainRecordDO> { |
| 75 | 81 | .orderByDesc(BargainRecordDO::getId)); |
| 76 | 82 | } |
| 77 | 83 | |
| 84 | + default PageResult<BargainRecordDO> selectBargainRecordPage(Long userId, PageParam pageParam) { | |
| 85 | + return selectPage(pageParam, new LambdaQueryWrapperX<BargainRecordDO>() | |
| 86 | + .eq(BargainRecordDO::getUserId, userId) | |
| 87 | + .orderByDesc(BargainRecordDO::getId)); | |
| 88 | + } | |
| 89 | + | |
| 90 | + default List<BargainRecordDO> selectListByStatusAndCount(Integer status, Integer count) { | |
| 91 | + return selectList(new LambdaQueryWrapper<>(BargainRecordDO.class) | |
| 92 | + .eq(BargainRecordDO::getStatus, status) | |
| 93 | + .last("LIMIT " + count)); | |
| 94 | + } | |
| 95 | + | |
| 78 | 96 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java
| ... | ... | @@ -162,7 +162,7 @@ public class BargainActivityServiceImpl implements BargainActivityService { |
| 162 | 162 | if (activity.getStock() <= 0) { |
| 163 | 163 | throw exception(BARGAIN_ACTIVITY_STOCK_NOT_ENOUGH); |
| 164 | 164 | } |
| 165 | - if (LocalDateTimeUtils.isBetween(activity.getStartTime(), activity.getEndTime())) { | |
| 165 | + if (!LocalDateTimeUtils.isBetween(activity.getStartTime(), activity.getEndTime())) { | |
| 166 | 166 | throw exception(BARGAIN_ACTIVITY_TIME_END); |
| 167 | 167 | } |
| 168 | 168 | return activity; | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainHelpServiceImpl.java
| ... | ... | @@ -83,7 +83,7 @@ public class BargainHelpServiceImpl implements BargainHelpService { |
| 83 | 83 | |
| 84 | 84 | // 5. 判断砍价记录是否完成 |
| 85 | 85 | Boolean success = record.getBargainPrice() - reducePrice <= activity.getBargainMinPrice() // 情况一:砍价已经砍到最低价 |
| 86 | - || bargainHelpMapper.selectCountByRecordId(reqVO.getRecordId()) >= activity.getHelpMaxCount(); // 情况二:砍价助力已经达到上限 | |
| 86 | + || bargainHelpMapper.selectUserCountMapByRecordId(reqVO.getRecordId()) >= activity.getHelpMaxCount(); // 情况二:砍价助力已经达到上限 | |
| 87 | 87 | if (!bargainRecordService.updateBargainRecordBargainPrice( |
| 88 | 88 | record.getId(), record.getBargainPrice(), reducePrice, success)) { |
| 89 | 89 | // 多人一起砍价,需要重试 |
| ... | ... | @@ -106,12 +106,12 @@ public class BargainHelpServiceImpl implements BargainHelpService { |
| 106 | 106 | |
| 107 | 107 | @Override |
| 108 | 108 | public Map<Long, Integer> getBargainHelpUserCountMapByActivity(Collection<Long> activityIds) { |
| 109 | - return bargainHelpMapper.selectCountByActivityId(activityIds); | |
| 109 | + return bargainHelpMapper.selectUserCountMapByActivityId(activityIds); | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | @Override |
| 113 | 113 | public Map<Long, Integer> getBargainHelpUserCountMapByRecord(Collection<Long> recordIds) { |
| 114 | - return bargainHelpMapper.selectCountByRecordId(recordIds); | |
| 114 | + return bargainHelpMapper.selectUserCountMapByRecordId(recordIds); | |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | @Override | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordService.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.service.bargain; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 6 | import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainValidateJoinRespDTO; |
| 6 | 7 | import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.recrod.BargainRecordPageReqVO; |
| ... | ... | @@ -9,6 +10,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO; |
| 9 | 10 | |
| 10 | 11 | import javax.annotation.Nullable; |
| 11 | 12 | import java.util.Collection; |
| 13 | +import java.util.List; | |
| 12 | 14 | import java.util.Map; |
| 13 | 15 | |
| 14 | 16 | /** |
| ... | ... | @@ -71,11 +73,37 @@ public interface BargainRecordService { |
| 71 | 73 | Map<Long, Integer> getBargainRecordUserCountMap(Collection<Long> activityIds, @Nullable Integer status); |
| 72 | 74 | |
| 73 | 75 | /** |
| 74 | - * 获得砍价记录分页 | |
| 76 | + * 获得砍价人数 Map | |
| 77 | + * | |
| 78 | + * @param status 砍价记录状态 | |
| 79 | + * @return 砍价人数 | |
| 80 | + */ | |
| 81 | + Integer getBargainRecordUserCount(Integer status); | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * 【管理员】获得砍价记录分页 | |
| 75 | 85 | * |
| 76 | 86 | * @param pageReqVO 分页查询 |
| 77 | 87 | * @return 砍价记录分页 |
| 78 | 88 | */ |
| 79 | 89 | PageResult<BargainRecordDO> getBargainRecordPage(BargainRecordPageReqVO pageReqVO); |
| 80 | 90 | |
| 91 | + /** | |
| 92 | + * 【会员】获得砍价记录分页 | |
| 93 | + * | |
| 94 | + * @param userId 用户编号 | |
| 95 | + * @param pageParam 分页查询 | |
| 96 | + * @return 砍价记录分页 | |
| 97 | + */ | |
| 98 | + PageResult<BargainRecordDO> getBargainRecordPage(Long userId, PageParam pageParam); | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * 获得砍价记录列表 | |
| 102 | + * | |
| 103 | + * @param status 砍价记录状态 | |
| 104 | + * @param count 条数 | |
| 105 | + * @return 砍价记录列表 | |
| 106 | + */ | |
| 107 | + List<BargainRecordDO> getBargainRecordList(Integer status, Integer count); | |
| 108 | + | |
| 81 | 109 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordServiceImpl.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.service.bargain; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.lang.Assert; |
| 5 | 5 | import cn.hutool.core.util.ObjUtil; |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 6 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | 8 | import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainValidateJoinRespDTO; |
| 8 | 9 | import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.recrod.BargainRecordPageReqVO; |
| ... | ... | @@ -17,6 +18,7 @@ import org.springframework.validation.annotation.Validated; |
| 17 | 18 | import javax.annotation.Nullable; |
| 18 | 19 | import javax.annotation.Resource; |
| 19 | 20 | import java.util.Collection; |
| 21 | +import java.util.List; | |
| 20 | 22 | import java.util.Map; |
| 21 | 23 | import java.util.Objects; |
| 22 | 24 | |
| ... | ... | @@ -99,7 +101,12 @@ public class BargainRecordServiceImpl implements BargainRecordService { |
| 99 | 101 | |
| 100 | 102 | @Override |
| 101 | 103 | public Map<Long, Integer> getBargainRecordUserCountMap(Collection<Long> activityIds, @Nullable Integer status) { |
| 102 | - return bargainRecordMapper.selectCountByActivityIdsAndStatus(activityIds, status); | |
| 104 | + return bargainRecordMapper.selectUserCountByActivityIdsAndStatus(activityIds, status); | |
| 105 | + } | |
| 106 | + | |
| 107 | + @Override | |
| 108 | + public Integer getBargainRecordUserCount(Integer status) { | |
| 109 | + return bargainRecordMapper.selectUserCountByStatus(status); | |
| 103 | 110 | } |
| 104 | 111 | |
| 105 | 112 | @Override |
| ... | ... | @@ -107,4 +114,14 @@ public class BargainRecordServiceImpl implements BargainRecordService { |
| 107 | 114 | return bargainRecordMapper.selectPage(pageReqVO); |
| 108 | 115 | } |
| 109 | 116 | |
| 117 | + @Override | |
| 118 | + public PageResult<BargainRecordDO> getBargainRecordPage(Long userId, PageParam pageParam) { | |
| 119 | + return bargainRecordMapper.selectBargainRecordPage(userId, pageParam); | |
| 120 | + } | |
| 121 | + | |
| 122 | + @Override | |
| 123 | + public List<BargainRecordDO> getBargainRecordList(Integer status, Integer count) { | |
| 124 | + return bargainRecordMapper.selectListByStatusAndCount(status, count); | |
| 125 | + } | |
| 126 | + | |
| 110 | 127 | } | ... | ... |
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java
| 1 | 1 | package cn.iocoder.yudao.module.trade.api.order; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; | |
| 3 | 4 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO; |
| 4 | 5 | |
| 5 | 6 | import java.time.LocalDateTime; |
| 7 | +import java.util.Collection; | |
| 8 | +import java.util.List; | |
| 6 | 9 | |
| 7 | 10 | /** |
| 8 | 11 | * 订单 API 接口 |
| ... | ... | @@ -11,6 +14,14 @@ import java.time.LocalDateTime; |
| 11 | 14 | */ |
| 12 | 15 | public interface TradeOrderApi { |
| 13 | 16 | |
| 17 | + /** | |
| 18 | + * 获得订单列表 | |
| 19 | + * | |
| 20 | + * @param ids 订单编号数组 | |
| 21 | + * @return 订单列表 | |
| 22 | + */ | |
| 23 | + List<TradeOrderRespDTO> getOrderList(Collection<Long> ids); | |
| 24 | + | |
| 14 | 25 | // TODO 芋艿:看看是不是可以删除掉; |
| 15 | 26 | /** |
| 16 | 27 | * 获取订单状态 | ... | ... |
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/dto/TradeOrderRespDTO.java
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.trade.api.order; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; | |
| 3 | 4 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO; |
| 5 | +import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; | |
| 4 | 6 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; |
| 5 | 7 | import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; |
| 6 | 8 | import org.springframework.stereotype.Service; |
| ... | ... | @@ -9,6 +11,8 @@ import org.springframework.validation.annotation.Validated; |
| 9 | 11 | import javax.annotation.Resource; |
| 10 | 12 | |
| 11 | 13 | import java.time.LocalDateTime; |
| 14 | +import java.util.Collection; | |
| 15 | +import java.util.List; | |
| 12 | 16 | |
| 13 | 17 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 14 | 18 | import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND; |
| ... | ... | @@ -26,6 +30,11 @@ public class TradeOrderApiImpl implements TradeOrderApi { |
| 26 | 30 | private TradeOrderQueryService tradeOrderQueryService; |
| 27 | 31 | |
| 28 | 32 | @Override |
| 33 | + public List<TradeOrderRespDTO> getOrderList(Collection<Long> ids) { | |
| 34 | + return TradeOrderConvert.INSTANCE.convertList04(tradeOrderQueryService.getOrderList(ids)); | |
| 35 | + } | |
| 36 | + | |
| 37 | + @Override | |
| 29 | 38 | public Integer getOrderStatus(Long id) { |
| 30 | 39 | TradeOrderDO order = tradeOrderQueryService.getOrder(id); |
| 31 | 40 | if (order == null) { | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryService.java
| ... | ... | @@ -41,6 +41,14 @@ public interface TradeOrderQueryService { |
| 41 | 41 | TradeOrderDO getOrder(Long userId, Long id); |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | + * 获得订单列表 | |
| 45 | + * | |
| 46 | + * @param ids 订单编号数组 | |
| 47 | + * @return 订单列表 | |
| 48 | + */ | |
| 49 | + List<TradeOrderDO> getOrderList(Collection<Long> ids); | |
| 50 | + | |
| 51 | + /** | |
| 44 | 52 | * 【管理员】获得交易订单分页 |
| 45 | 53 | * |
| 46 | 54 | * @param reqVO 分页请求 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java
| ... | ... | @@ -70,6 +70,14 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | @Override |
| 73 | + public List<TradeOrderDO> getOrderList(Collection<Long> ids) { | |
| 74 | + if (CollUtil.isEmpty(ids)) { | |
| 75 | + return Collections.emptyList(); | |
| 76 | + } | |
| 77 | + return tradeOrderMapper.selectBatchIds(ids); | |
| 78 | + } | |
| 79 | + | |
| 80 | + @Override | |
| 73 | 81 | public PageResult<TradeOrderDO> getOrderPage(TradeOrderPageReqVO reqVO) { |
| 74 | 82 | // 获得 userId 相关的查询 |
| 75 | 83 | Set<Long> userIds = new HashSet<>(); | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java
| ... | ... | @@ -86,7 +86,9 @@ public class TradePriceCalculatorHelper { |
| 86 | 86 | if (param.getCombinationActivityId() != null) { |
| 87 | 87 | return TradeOrderTypeEnum.COMBINATION.getType(); |
| 88 | 88 | } |
| 89 | - // TODO 砍价敬请期待 | |
| 89 | + if (param.getBargainRecordId() != null) { | |
| 90 | + return TradeOrderTypeEnum.BARGAIN.getType(); | |
| 91 | + } | |
| 90 | 92 | return TradeOrderTypeEnum.NORMAL.getType(); |
| 91 | 93 | } |
| 92 | 94 | ... | ... |