promotion:完善砍价 API ~ 提交下,准备出门吃饭!!!!

This commit is contained in:
YunaiV 2023-10-05 17:22:17 +08:00
parent 6a04d6c458
commit 1bda3c8b53
24 changed files with 296 additions and 201 deletions

View File

@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.toolkit.Db;

View File

@ -1,12 +1,7 @@
package cn.iocoder.yudao.module.promotion.api.bargain;
import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainRecordCreateReqDTO;
import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainValidateJoinRespDTO;
import javax.validation.Valid;
// TODO @芋艿后面也再撸撸这几个接口
/**
* 砍价记录 API 接口
*
@ -14,13 +9,6 @@ import javax.validation.Valid;
*/
public interface BargainRecordApi {
/**
* 创建砍价记录
*
* @param reqDTO 请求 DTO
*/
void createBargainRecord(@Valid BargainRecordCreateReqDTO reqDTO);
/**
* 下单前校验是否参与砍价活动
* <p>

View File

@ -1,61 +0,0 @@
package cn.iocoder.yudao.module.promotion.api.bargain.dto;
import lombok.Data;
import javax.validation.constraints.NotNull;
// TODO @芋艿这块要在看看
/**
* 砍价记录的创建 Request DTO
*
* @author HUIHUI
*/
@Data
public class BargainRecordCreateReqDTO {
/**
* 砍价活动编号
*/
@NotNull(message = "砍价活动编号不能为空")
private Long activityId;
/**
* spu 编号
*/
@NotNull(message = "spu 编号不能为空")
private Long spuId;
/**
* sku 编号
*/
@NotNull(message = "sku 编号不能为空")
private Long skuId;
/**
* 用户编号
*/
@NotNull(message = "用户编号不能为空")
private Long userId;
/**
* 订单编号
*/
@NotNull(message = "订单编号不能为空")
private Long orderId;
/**
* 砍价商品单价
*/
@NotNull(message = "砍价底价不能为空")
private Integer bargainPrice;
/**
* 商品原价单位分
*/
@NotNull(message = "商品原价不能为空")
private Integer price;
// TODO @puhui999创建时这个参数不应该传递哈
/**
* 开团状态进行中 砍价成功 砍价失败
*/
@NotNull(message = "开团状态不能为空")
private Integer status;
}

View File

@ -11,6 +11,8 @@ import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.activity.AppB
import cn.iocoder.yudao.module.promotion.convert.bargain.BargainActivityConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO;
import cn.iocoder.yudao.module.promotion.service.bargain.BargainActivityService;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -21,10 +23,12 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@Tag(name = "用户 App - 砍价活动")
@ -33,11 +37,42 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
@Validated
public class AppBargainActivityController {
/**
* {@link AppBargainActivityRespVO} 缓存通过它异步刷新 {@link #getBargainActivityList0(Integer)} 所要的首页数据
*/
private final LoadingCache<Integer, List<AppBargainActivityRespVO>> bargainActivityListCache = buildAsyncReloadingCache(Duration.ofSeconds(10L),
new CacheLoader<Integer, List<AppBargainActivityRespVO>>() {
@Override
public List<AppBargainActivityRespVO> load(Integer count) {
return getBargainActivityList0(count);
}
});
@Resource
private BargainActivityService bargainActivityService;
@Resource
private ProductSpuApi spuApi;
@GetMapping("/list")
@Operation(summary = "获得砍价活动列表", description = "用于小程序首页")
@Parameter(name = "count", description = "需要展示的数量", example = "6")
public CommonResult<List<AppBargainActivityRespVO>> getBargainActivityList(
@RequestParam(name = "count", defaultValue = "6") Integer count) {
return success(bargainActivityListCache.getUnchecked(count));
}
private List<AppBargainActivityRespVO>getBargainActivityList0(Integer count) {
List<BargainActivityDO> list = bargainActivityService.getBargainActivityListByCount(count);
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
}
// 拼接数据
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(list, BargainActivityDO::getSpuId));
return BargainActivityConvert.INSTANCE.convertAppList(list, spuList);
}
@GetMapping("/page")
@Operation(summary = "获得砍价活动分页")
public CommonResult<PageResult<AppBargainActivityRespVO>> getBargainActivityPage(PageParam pageReqVO) {
@ -50,21 +85,6 @@ public class AppBargainActivityController {
return success(BargainActivityConvert.INSTANCE.convertAppPage(result, spuList));
}
// TODO 芋艿增加 Spring Cache
@GetMapping("/list")
@Operation(summary = "获得砍价活动列表", description = "用于小程序首页")
@Parameter(name = "count", description = "需要展示的数量", example = "6")
public CommonResult<List<AppBargainActivityRespVO>> getBargainActivityList(
@RequestParam(name = "count", defaultValue = "6") Integer count) {
List<BargainActivityDO> list = bargainActivityService.getBargainActivityListByCount(defaultIfNull(count, 6));
if (CollUtil.isEmpty(list)) {
return success(BargainActivityConvert.INSTANCE.convertAppList(list));
}
// 拼接数据
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(list, BargainActivityDO::getSpuId));
return success(BargainActivityConvert.INSTANCE.convertAppList(list, spuList));
}
@GetMapping("/get-detail")
@Operation(summary = "获得砍价活动详情")
@Parameter(name = "id", description = "活动编号", example = "1")

View File

@ -1,15 +1,27 @@
package cn.iocoder.yudao.module.promotion.controller.app.bargain;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordDetailRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordSummaryRespVO;
import cn.iocoder.yudao.module.promotion.convert.bargain.BargainRecordConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO;
import cn.iocoder.yudao.module.promotion.enums.bargain.BargainRecordStatusEnum;
import cn.iocoder.yudao.module.promotion.service.bargain.BargainActivityService;
import cn.iocoder.yudao.module.promotion.service.bargain.BargainRecordService;
import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
@ -17,9 +29,12 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Tag(name = "用户 App - 砍价记录")
@ -30,25 +45,35 @@ public class AppBargainRecordController {
@Resource
private BargainRecordService bargainRecordService;
@Resource
private BargainActivityService bargainActivityService;
@Resource
private MemberUserApi memberUserApi;
@Resource
private ProductSpuApi productSpuApi;
@Resource
private TradeOrderApi tradeOrderApi;
@GetMapping("/get-summary")
@Operation(summary = "获得砍价记录的概要信息", description = "用于小程序首页")
// TODO 芋艿增加 @Cache 缓存1 分钟过期
public CommonResult<AppBargainRecordSummaryRespVO> getBargainRecordSummary() {
AppBargainRecordSummaryRespVO summary = new AppBargainRecordSummaryRespVO();
summary.setUserCount(1024);
summary.setSuccessRecords(new ArrayList<>());
AppBargainRecordSummaryRespVO.Record record1 = new AppBargainRecordSummaryRespVO.Record();
record1.setNickname("王**");
record1.setAvatar("https://www.iocoder.cn/xxx.jpg");
record1.setActivityName("天蚕土豆");
AppBargainRecordSummaryRespVO.Record record2 = new AppBargainRecordSummaryRespVO.Record();
record2.setNickname("张**");
record2.setAvatar("https://www.iocoder.cn/yyy.jpg");
record2.setActivityName("斗罗大陆");
summary.getSuccessRecords().add(record1);
summary.getSuccessRecords().add(record2);
return success(summary);
// 砍价成功的用户数量
Integer successUserCount = bargainRecordService.getBargainRecordUserCount(
BargainRecordStatusEnum.SUCCESS.getStatus());
if (successUserCount == 0) {
return success(new AppBargainRecordSummaryRespVO().setSuccessUserCount(0)
.setSuccessList(Collections.emptyList()));
}
// 砍价成功的用户列表
List<BargainRecordDO> successList = bargainRecordService.getBargainRecordList(
BargainRecordStatusEnum.SUCCESS.getStatus(), 7);
List<BargainActivityDO> activityList = bargainActivityService.getBargainActivityList(
convertSet(successList, BargainRecordDO::getActivityId));
Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(
convertSet(successList, BargainRecordDO::getUserId));
// 拼接返回
return success(BargainRecordConvert.INSTANCE.convert(successUserCount, successList, activityList, userMap));
}
@GetMapping("/get-detail")
@ -75,72 +100,19 @@ public class AppBargainRecordController {
@GetMapping("/page")
@Operation(summary = "获得砍价记录的分页")
public CommonResult<PageResult<AppBargainRecordRespVO>> getBargainRecordPage(PageParam pageParam) {
PageResult<AppBargainRecordRespVO> page = new PageResult<>();
page.setList(new ArrayList<>());
AppBargainRecordRespVO record1 = new AppBargainRecordRespVO();
record1.setId(1L);
record1.setUserId(1L);
record1.setSpuId(1L);
record1.setSkuId(1L);
record1.setPrice(500);
record1.setActivityId(1L);
record1.setBargainPrice(150);
record1.setPrice(200);
record1.setPayPrice(180);
record1.setStatus(1);
record1.setPicUrl("https://static.iocoder.cn/mall/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg");
record1.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(2)));
page.getList().add(record1);
PageResult<BargainRecordDO> pageResult = bargainRecordService.getBargainRecordPage(getLoginUserId(), pageParam);
if (CollUtil.isEmpty(pageResult.getList())) {
return success(PageResult.empty(pageResult.getTotal()));
}
AppBargainRecordRespVO record2 = new AppBargainRecordRespVO();
record2.setId(1L);
record2.setUserId(1L);
record2.setSpuId(1L);
record2.setSkuId(1L);
record2.setPrice(500);
record2.setActivityId(1L);
record2.setBargainPrice(150);
record2.setPrice(200);
record2.setPayPrice(280);
record2.setStatus(2);
record2.setPicUrl("https://static.iocoder.cn/mall/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg");
record2.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(2)));
page.getList().add(record2);
AppBargainRecordRespVO record3 = new AppBargainRecordRespVO();
record3.setId(1L);
record3.setUserId(1L);
record3.setSpuId(1L);
record3.setSkuId(1L);
record3.setPrice(500);
record3.setActivityId(1L);
record3.setBargainPrice(150);
record3.setPrice(200);
record3.setPayPrice(380);
record3.setStatus(2);
record3.setPicUrl("https://static.iocoder.cn/mall/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg");
record3.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(2)));
record3.setOrderId(100L);
page.getList().add(record3);
AppBargainRecordRespVO record4 = new AppBargainRecordRespVO();
record4.setId(1L);
record4.setUserId(1L);
record4.setSpuId(1L);
record4.setSkuId(1L);
record4.setPrice(500);
record4.setActivityId(1L);
record4.setBargainPrice(150);
record4.setPrice(200);
record4.setPayPrice(380);
record4.setStatus(3);
record4.setPicUrl("https://static.iocoder.cn/mall/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg");
record4.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(2)));
record4.setOrderId(100L);
page.getList().add(record4);
page.setTotal(1L);
return success(page);
// 拼接数据
List<BargainActivityDO> activityList = bargainActivityService.getBargainActivityList(
convertSet(pageResult.getList(), BargainRecordDO::getActivityId));
List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(
convertSet(pageResult.getList(), BargainRecordDO::getSpuId));
List<TradeOrderRespDTO> orderList = tradeOrderApi.getOrderList(
convertSet(pageResult.getList(), BargainRecordDO::getOrderId));
return success(BargainRecordConvert.INSTANCE.convertPage02(pageResult, activityList, spuList, orderList));
}
@PostMapping("/create")

View File

@ -30,13 +30,14 @@ public class AppBargainActivityRespVO {
@Schema(description = "砍价库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "512")
private Integer stock;
@Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "4096") // SPU picUrl 读取
@Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, // SPU picUrl 读取
example = "4096")
private String picUrl;
@Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "50") // SPU marketPrice 读取
@Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, // SPU marketPrice 读取
example = "50")
private Integer marketPrice;
@Schema(description = "砍价最低金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Integer bargainPrice;
private Integer bargainMinPrice;
}

View File

@ -9,24 +9,44 @@ import java.time.LocalDateTime;
@Data
public class AppBargainRecordRespVO {
// TODO @芋艿status如果砍价对应的订单支付超时算失败么砍价的支付时间 expireTime 为准么
@Schema(description = "砍价记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
private Long userId;
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
private Long spuId;
@Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
private Long skuId;
@Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901")
private Long activityId;
private Integer bargainPrice;
private Integer price;
private Integer payPrice;
@Schema(description = "砍价记录状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
private LocalDateTime expireTime;
private Long orderId;
private Boolean payStatus;
private Long payOrderId;
@Schema(description = "当前价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "102")
private Integer bargainPrice;
// ========== 活动相关 ==========
@Schema(description = "活动名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
private String activityName;
@Schema(description = "活动结束时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime endTime;
@Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, // SPU picUrl 读取
example = "https://www.iocoder.cn/xx.png")
private String picUrl;
// ========== 订单相关 ==========
@Schema(description = "订单编号", example = "1024")
private Long orderId;
@Schema(description = "支付状态", example = "true")
private Boolean payStatus;
@Schema(description = "支付订单编号", example = "1024")
private Long payOrderId;
}

View File

@ -10,10 +10,10 @@ import java.util.List;
public class AppBargainRecordSummaryRespVO {
@Schema(description = "砍价用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer userCount;
private Integer successUserCount;
@Schema(description = "成功砍价的记录", requiredMode = Schema.RequiredMode.REQUIRED) // 只返回最近的 7
private List<Record> successRecords;
private List<Record> successList;
@Schema(description = "成功砍价记录")
@Data

View File

@ -27,7 +27,6 @@ import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@ -48,7 +47,7 @@ public class AppCombinationActivityController {
@Parameter(name = "count", description = "需要展示的数量", example = "6")
public CommonResult<List<AppCombinationActivityRespVO>> getCombinationActivityList(
@RequestParam(name = "count", defaultValue = "6") Integer count) {
List<CombinationActivityDO> list = activityService.getCombinationActivityListByCount(defaultIfNull(count, 6));
List<CombinationActivityDO> list = activityService.getCombinationActivityListByCount(6);
if (CollUtil.isEmpty(list)) {
return success(Collections.emptyList());
}

View File

@ -74,7 +74,7 @@ public class AppSeckillActivityController {
@GetMapping("/get-now")
@Operation(summary = "获得当前秒杀活动", description = "获取当前正在进行的活动,提供给首页使用")
public CommonResult<AppSeckillActivityNowRespVO> getNowSeckillActivity() {
return success(nowSeckillActivityCache.getUnchecked(""));
return success(nowSeckillActivityCache.getUnchecked("")); // 缓存
}
private AppSeckillActivityNowRespVO getNowSeckillActivity0() {

View File

@ -4,15 +4,21 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.recrod.BargainRecordPageItemRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordSummaryRespVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO;
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.factory.Mappers;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/**
* 砍价记录 Convert
*
@ -29,7 +35,7 @@ public interface BargainRecordConvert {
Map<Long, MemberUserRespDTO> userMap) {
PageResult<BargainRecordPageItemRespVO> pageResult = convertPage(page);
// 拼接数据
Map<Long, BargainActivityDO> activityMap = CollectionUtils.convertMap(activityList, BargainActivityDO::getId);
Map<Long, BargainActivityDO> activityMap = convertMap(activityList, BargainActivityDO::getId);
pageResult.getList().forEach(record -> {
MapUtils.findAndThen(userMap, record.getUserId(),
user -> record.setNickname(user.getNickname()).setAvatar(user.getAvatar()));
@ -40,4 +46,40 @@ public interface BargainRecordConvert {
}
PageResult<BargainRecordPageItemRespVO> convertPage(PageResult<BargainRecordDO> page);
default PageResult<AppBargainRecordRespVO> convertPage02(PageResult<BargainRecordDO> page,
List<BargainActivityDO> activityList,
List<ProductSpuRespDTO> spuList,
List<TradeOrderRespDTO> orderList) {
PageResult<AppBargainRecordRespVO> pageResult = convertPage02(page);
// 拼接数据
Map<Long, BargainActivityDO> activityMap = convertMap(activityList, BargainActivityDO::getId);
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
Map<Long, TradeOrderRespDTO> orderMap = convertMap(orderList, TradeOrderRespDTO::getId);
pageResult.getList().forEach(record -> {
MapUtils.findAndThen(activityMap, record.getActivityId(),
activity -> record.setActivityName(activity.getName()).setEndTime(activity.getEndTime()));
MapUtils.findAndThen(spuMap, record.getSpuId(),
spu -> record.setPicUrl(record.getPicUrl()));
MapUtils.findAndThen(orderMap, record.getOrderId(),
order -> record.setPayStatus(order.getPayStatus()).setPayOrderId(order.getPayOrderId()));
});
return pageResult;
}
PageResult<AppBargainRecordRespVO> convertPage02(PageResult<BargainRecordDO> page);
default AppBargainRecordSummaryRespVO convert(Integer successUserCount, List<BargainRecordDO> successList,
List<BargainActivityDO> activityList, Map<Long, MemberUserRespDTO> userMap) {
AppBargainRecordSummaryRespVO summary = new AppBargainRecordSummaryRespVO().setSuccessUserCount(successUserCount);
Map<Long, BargainActivityDO> activityMap = convertMap(activityList, BargainActivityDO::getId);
summary.setSuccessList(CollectionUtils.convertList(successList, record -> {
AppBargainRecordSummaryRespVO.Record recordVO = new AppBargainRecordSummaryRespVO.Record();
MapUtils.findAndThen(userMap, record.getUserId(),
user -> recordVO.setNickname(user.getNickname()).setAvatar(user.getAvatar()));
MapUtils.findAndThen(activityMap, record.getActivityId(),
activity -> recordVO.setActivityName(activity.getName()));
return recordVO;
}));
return summary;
}
}

View File

@ -26,7 +26,7 @@ public interface BargainHelpMapper extends BaseMapperX<BargainHelpDO> {
.eq(BargainHelpDO::getActivityId, activityId));
}
default Long selectCountByRecordId(Long recordId) {
default Long selectUserCountMapByRecordId(Long recordId) {
return selectCount(BargainHelpDO::getRecordId, recordId);
}
@ -36,7 +36,7 @@ public interface BargainHelpMapper extends BaseMapperX<BargainHelpDO> {
.eq(BargainHelpDO::getRecordId, recordId));
}
default Map<Long, Integer> selectCountByActivityId(Collection<Long> activityIds) {
default Map<Long, Integer> selectUserCountMapByActivityId(Collection<Long> activityIds) {
// SQL count 查询
List<Map<String, Object>> result = selectMaps(new QueryWrapper<BargainHelpDO>()
.select("COUNT(DISTINCT(user_id)) AS userCount, activity_id AS activityId")
@ -51,7 +51,7 @@ public interface BargainHelpMapper extends BaseMapperX<BargainHelpDO> {
record -> MapUtil.getInt(record, "userCount" ));
}
default Map<Long, Integer> selectCountByRecordId(Collection<Long> recordIds) {
default Map<Long, Integer> selectUserCountMapByRecordId(Collection<Long> recordIds) {
// SQL count 查询
List<Map<String, Object>> result = selectMaps(new QueryWrapper<BargainHelpDO>()
.select("COUNT(1) AS userCount, record_id AS recordId")

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.bargain;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
@ -11,6 +12,8 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Collection;
import java.util.Collections;
@ -52,7 +55,7 @@ public interface BargainRecordMapper extends BaseMapperX<BargainRecordDO> {
.eq(BargainRecordDO::getBargainPrice, whereBargainPrice));
}
default Map<Long, Integer> selectCountByActivityIdsAndStatus(Collection<Long> activityIds, Integer status) {
default Map<Long, Integer> selectUserCountByActivityIdsAndStatus(Collection<Long> activityIds, Integer status) {
// SQL count 查询
List<Map<String, Object>> result = selectMaps(new QueryWrapper<BargainRecordDO>()
.select("COUNT(DISTINCT(user_id)) AS userCount, activity_id AS activityId")
@ -68,6 +71,9 @@ public interface BargainRecordMapper extends BaseMapperX<BargainRecordDO> {
record -> MapUtil.getInt(record, "userCount" ));
}
@Select("SELECT COUNT(DISTINCT(user_id)) FROM promotion_bargain_record WHERE status = #{status}")
Integer selectUserCountByStatus(@Param("status") Integer status);
default PageResult<BargainRecordDO> selectPage(BargainRecordPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<BargainRecordDO>()
.eqIfPresent(BargainRecordDO::getStatus, reqVO.getStatus())
@ -75,4 +81,16 @@ public interface BargainRecordMapper extends BaseMapperX<BargainRecordDO> {
.orderByDesc(BargainRecordDO::getId));
}
default PageResult<BargainRecordDO> selectBargainRecordPage(Long userId, PageParam pageParam) {
return selectPage(pageParam, new LambdaQueryWrapperX<BargainRecordDO>()
.eq(BargainRecordDO::getUserId, userId)
.orderByDesc(BargainRecordDO::getId));
}
default List<BargainRecordDO> selectListByStatusAndCount(Integer status, Integer count) {
return selectList(new LambdaQueryWrapper<>(BargainRecordDO.class)
.eq(BargainRecordDO::getStatus, status)
.last("LIMIT " + count));
}
}

View File

@ -162,7 +162,7 @@ public class BargainActivityServiceImpl implements BargainActivityService {
if (activity.getStock() <= 0) {
throw exception(BARGAIN_ACTIVITY_STOCK_NOT_ENOUGH);
}
if (LocalDateTimeUtils.isBetween(activity.getStartTime(), activity.getEndTime())) {
if (!LocalDateTimeUtils.isBetween(activity.getStartTime(), activity.getEndTime())) {
throw exception(BARGAIN_ACTIVITY_TIME_END);
}
return activity;

View File

@ -83,7 +83,7 @@ public class BargainHelpServiceImpl implements BargainHelpService {
// 5. 判断砍价记录是否完成
Boolean success = record.getBargainPrice() - reducePrice <= activity.getBargainMinPrice() // 情况一砍价已经砍到最低价
|| bargainHelpMapper.selectCountByRecordId(reqVO.getRecordId()) >= activity.getHelpMaxCount(); // 情况二砍价助力已经达到上限
|| bargainHelpMapper.selectUserCountMapByRecordId(reqVO.getRecordId()) >= activity.getHelpMaxCount(); // 情况二砍价助力已经达到上限
if (!bargainRecordService.updateBargainRecordBargainPrice(
record.getId(), record.getBargainPrice(), reducePrice, success)) {
// 多人一起砍价需要重试
@ -106,12 +106,12 @@ public class BargainHelpServiceImpl implements BargainHelpService {
@Override
public Map<Long, Integer> getBargainHelpUserCountMapByActivity(Collection<Long> activityIds) {
return bargainHelpMapper.selectCountByActivityId(activityIds);
return bargainHelpMapper.selectUserCountMapByActivityId(activityIds);
}
@Override
public Map<Long, Integer> getBargainHelpUserCountMapByRecord(Collection<Long> recordIds) {
return bargainHelpMapper.selectCountByRecordId(recordIds);
return bargainHelpMapper.selectUserCountMapByRecordId(recordIds);
}
@Override

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.promotion.service.bargain;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainValidateJoinRespDTO;
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;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
@ -71,11 +73,37 @@ public interface BargainRecordService {
Map<Long, Integer> getBargainRecordUserCountMap(Collection<Long> activityIds, @Nullable Integer status);
/**
* 获得砍价记录分页
* 获得砍价人数 Map
*
* @param status 砍价记录状态
* @return 砍价人数
*/
Integer getBargainRecordUserCount(Integer status);
/**
* 管理员获得砍价记录分页
*
* @param pageReqVO 分页查询
* @return 砍价记录分页
*/
PageResult<BargainRecordDO> getBargainRecordPage(BargainRecordPageReqVO pageReqVO);
/**
* 会员获得砍价记录分页
*
* @param userId 用户编号
* @param pageParam 分页查询
* @return 砍价记录分页
*/
PageResult<BargainRecordDO> getBargainRecordPage(Long userId, PageParam pageParam);
/**
* 获得砍价记录列表
*
* @param status 砍价记录状态
* @param count 条数
* @return 砍价记录列表
*/
List<BargainRecordDO> getBargainRecordList(Integer status, Integer count);
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.service.bargain;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjUtil;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainValidateJoinRespDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.recrod.BargainRecordPageReqVO;
@ -17,6 +18,7 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -99,7 +101,12 @@ public class BargainRecordServiceImpl implements BargainRecordService {
@Override
public Map<Long, Integer> getBargainRecordUserCountMap(Collection<Long> activityIds, @Nullable Integer status) {
return bargainRecordMapper.selectCountByActivityIdsAndStatus(activityIds, status);
return bargainRecordMapper.selectUserCountByActivityIdsAndStatus(activityIds, status);
}
@Override
public Integer getBargainRecordUserCount(Integer status) {
return bargainRecordMapper.selectUserCountByStatus(status);
}
@Override
@ -107,4 +114,14 @@ public class BargainRecordServiceImpl implements BargainRecordService {
return bargainRecordMapper.selectPage(pageReqVO);
}
@Override
public PageResult<BargainRecordDO> getBargainRecordPage(Long userId, PageParam pageParam) {
return bargainRecordMapper.selectBargainRecordPage(userId, pageParam);
}
@Override
public List<BargainRecordDO> getBargainRecordList(Integer status, Integer count) {
return bargainRecordMapper.selectListByStatusAndCount(status, count);
}
}

View File

@ -1,8 +1,11 @@
package cn.iocoder.yudao.module.trade.api.order;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
/**
* 订单 API 接口
@ -11,6 +14,14 @@ import java.time.LocalDateTime;
*/
public interface TradeOrderApi {
/**
* 获得订单列表
*
* @param ids 订单编号数组
* @return 订单列表
*/
List<TradeOrderRespDTO> getOrderList(Collection<Long> ids);
// TODO 芋艿看看是不是可以删除掉
/**
* 获取订单状态

View File

@ -84,4 +84,14 @@ public class TradeOrderRespDTO {
*/
private Boolean commentStatus;
// ========== 价格 + 支付基本信息 ==========
/**
* 支付订单编号
*/
private Long payOrderId;
/**
* 是否已支付
*/
private Boolean payStatus;
}

View File

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.trade.api.order;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO;
import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
import org.springframework.stereotype.Service;
@ -9,6 +11,8 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND;
@ -25,6 +29,11 @@ public class TradeOrderApiImpl implements TradeOrderApi {
@Resource
private TradeOrderQueryService tradeOrderQueryService;
@Override
public List<TradeOrderRespDTO> getOrderList(Collection<Long> ids) {
return TradeOrderConvert.INSTANCE.convertList04(tradeOrderQueryService.getOrderList(ids));
}
@Override
public Integer getOrderStatus(Long id) {
TradeOrderDO order = tradeOrderQueryService.getOrder(id);

View File

@ -261,4 +261,6 @@ public interface TradeOrderConvert {
return bo;
}
List<TradeOrderRespDTO> convertList04(List<TradeOrderDO> list);
}

View File

@ -40,6 +40,14 @@ public interface TradeOrderQueryService {
*/
TradeOrderDO getOrder(Long userId, Long id);
/**
* 获得订单列表
*
* @param ids 订单编号数组
* @return 订单列表
*/
List<TradeOrderDO> getOrderList(Collection<Long> ids);
/**
* 管理员获得交易订单分页
*

View File

@ -69,6 +69,14 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
return order;
}
@Override
public List<TradeOrderDO> getOrderList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return Collections.emptyList();
}
return tradeOrderMapper.selectBatchIds(ids);
}
@Override
public PageResult<TradeOrderDO> getOrderPage(TradeOrderPageReqVO reqVO) {
// 获得 userId 相关的查询

View File

@ -86,7 +86,9 @@ public class TradePriceCalculatorHelper {
if (param.getCombinationActivityId() != null) {
return TradeOrderTypeEnum.COMBINATION.getType();
}
// TODO 砍价敬请期待
if (param.getBargainRecordId() != null) {
return TradeOrderTypeEnum.BARGAIN.getType();
}
return TradeOrderTypeEnum.NORMAL.getType();
}