完善订单和活动 review 提到的问题

This commit is contained in:
puhui999 2023-09-20 16:06:29 +08:00
parent 52848d6341
commit 6ef94ade6a
27 changed files with 248 additions and 186 deletions

View File

@ -43,17 +43,6 @@ public class LocalDateTimeUtils {
return LocalDateTime.of(year, mouth, day, 0, 0, 0);
}
/**
* 创建指定时间
*
* @param timeStr 时间字符串
* @return 指定时间
*/
public static LocalDateTime buildTime(String timeStr) {
// TODO @puhui999这个方法的实现 LocalDateTimeUtil.parse() 的差异点是啥呀
return LocalDateTime.of(LocalDate.now(), LocalTime.parse(timeStr));
}
public static LocalDateTime[] buildBetweenTime(int year1, int mouth1, int day1,
int year2, int mouth2, int day2) {
return new LocalDateTime[]{buildTime(year1, mouth1, day1), buildTime(year2, mouth2, day2)};

View File

@ -7,14 +7,13 @@ package cn.iocoder.yudao.module.promotion.api.seckill;
*/
public interface SeckillActivityApi {
// TODO @puhui999activityId 改成 id 好点哈
/**
* 更新秒杀库存
*
* @param activityId 活动编号
* @param id 活动编号
* @param skuId sku 编号
* @param count 数量
*/
void updateSeckillStock(Long activityId, Long skuId, Integer count);
void updateSeckillStock(Long id, Long skuId, Integer count);
}

View File

@ -17,8 +17,8 @@ public class SeckillActivityApiImpl implements SeckillActivityApi {
private SeckillActivityService activityService;
@Override
public void updateSeckillStock(Long activityId, Long skuId, Integer count) {
activityService.updateSeckillStock(activityId, skuId, count);
public void updateSeckillStock(Long id, Long skuId, Integer count) {
activityService.updateSeckillStock(id, skuId, count);
}
}

View File

@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
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;
@ -39,7 +40,7 @@ public class AppBargainActivityController {
@GetMapping("/page")
@Operation(summary = "获得砍价活动分页")
public CommonResult<PageResult<AppBargainActivityRespVO>> getBargainActivityPage(PageParam pageReqVO) {
PageResult<BargainActivityDO> result = bargainActivityService.getBargainActivityPageForApp(pageReqVO);
PageResult<BargainActivityDO> result = bargainActivityService.getBargainActivityPage(pageReqVO);
if (CollUtil.isEmpty(result.getList())) {
return success(PageResult.empty(result.getTotal()));
}
@ -54,7 +55,7 @@ public class AppBargainActivityController {
@Parameter(name = "count", description = "需要展示的数量", example = "6")
public CommonResult<List<AppBargainActivityRespVO>> getBargainActivityList(
@RequestParam(name = "count", defaultValue = "6") Integer count) {
List<BargainActivityDO> list = bargainActivityService.getBargainActivityListForApp(count);
List<BargainActivityDO> list = bargainActivityService.getBargainActivityListByCount(defaultIfNull(count, 6));
if (CollUtil.isEmpty(list)) {
return success(BargainActivityConvert.INSTANCE.convertAppList(list));
}

View File

@ -27,6 +27,7 @@ import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@ -49,7 +50,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.getCombinationActivityAppList(count);
List<CombinationActivityDO> list = activityService.getCombinationActivityListByCount(defaultIfNull(count, 6));
if (CollUtil.isEmpty(list)) {
return success(CombinationActivityConvert.INSTANCE.convertAppList(list));
}
@ -62,7 +63,7 @@ public class AppCombinationActivityController {
@GetMapping("/page")
@Operation(summary = "获得拼团活动分页")
public CommonResult<PageResult<AppCombinationActivityRespVO>> getCombinationActivityPage(PageParam pageParam) {
PageResult<CombinationActivityDO> result = activityService.getCombinationActivityAppPage(pageParam);
PageResult<CombinationActivityDO> result = activityService.getCombinationActivityPage(pageParam);
if (CollUtil.isEmpty(result.getList())) {
return success(PageResult.empty(result.getTotal()));
}

View File

@ -27,13 +27,11 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.isBetween;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_ACTIVITY_APP_STATUS_CLOSED;
@Tag(name = "用户 App - 秒杀活动")
@ -54,22 +52,17 @@ public class AppSeckillActivityController {
@Operation(summary = "获得当前秒杀活动", description = "获取当前正在进行的活动,提供给首页使用")
public CommonResult<AppSeckillActivityNowRespVO> getNowSeckillActivity() {
// 1. 获取当前时间处在哪个秒杀阶段
// TODO @puhui999可以考虑在 service 写个方法这样 controller 不用关注过多逻辑
List<SeckillConfigDO> configList = configService.getSeckillConfigList();
SeckillConfigDO filteredConfig = findFirst(configList, config -> ObjectUtil.equal(config.getStatus(),
CommonStatusEnum.ENABLE.getStatus()) && isBetween(config.getStartTime(), config.getEndTime()));
if (filteredConfig == null) { // 时段不存在直接返回 null
SeckillConfigDO configList = configService.getSeckillConfigListByStatusOnCurrentTime(CommonStatusEnum.ENABLE.getStatus());
if (configList == null) { // 时段不存在直接返回 null
return success(null);
}
// 2. 查询满足当前阶段的活动
// TODO @puhui999最好直接返回开启的不多查询数据
List<SeckillActivityDO> activityList = activityService.getSeckillActivityListByConfigIds(Arrays.asList(filteredConfig.getId()));
List<SeckillActivityDO> filteredList = filterList(activityList, item -> ObjectUtil.equal(item.getStatus(), CommonStatusEnum.ENABLE.getStatus()));
List<SeckillActivityDO> activityList = activityService.getSeckillActivityListByConfigIdAndStatus(configList.getId(), CommonStatusEnum.ENABLE.getStatus());
// 3 获取 spu 信息
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(filteredList, SeckillActivityDO::getSpuId));
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId));
// TODO 芋艿需要增加 spring cache
return success(SeckillActivityConvert.INSTANCE.convert(filteredConfig, filteredList, spuList));
return success(SeckillActivityConvert.INSTANCE.convert(configList, activityList, spuList));
}
@GetMapping("/page")
@ -87,12 +80,9 @@ public class AppSeckillActivityController {
@Operation(summary = "获得秒杀活动明细")
@Parameter(name = "id", description = "活动编号", required = true, example = "1024")
public CommonResult<AppSeckillActivityDetailRespVO> getSeckillActivity(@RequestParam("id") Long id) {
// 1获取当前时间处在哪个秒杀阶段
// TODO puhui999这里 58 行是雷同的
List<SeckillConfigDO> configList = configService.getSeckillConfigList();
SeckillConfigDO filteredConfig = findFirst(configList, config -> ObjectUtil.equal(config.getStatus(),
CommonStatusEnum.ENABLE.getStatus()) && isBetween(config.getStartTime(), config.getEndTime()));
if (filteredConfig == null) { // 时段不存在直接返回 null
// 1. 获取当前时间处在哪个秒杀阶段
SeckillConfigDO configList = configService.getSeckillConfigListByStatusOnCurrentTime(CommonStatusEnum.ENABLE.getStatus());
if (configList == null) { // 时段不存在直接返回 null
return success(null);
}
@ -107,7 +97,7 @@ public class AppSeckillActivityController {
// 3. 拼接数据
List<SeckillProductDO> products = activityService.getSeckillProductListByActivityId(seckillActivity.getId());
return success(SeckillActivityConvert.INSTANCE.convert3(seckillActivity, products, filteredConfig));
return success(SeckillActivityConvert.INSTANCE.convert3(seckillActivity, products, configList));
}
}

View File

@ -1,11 +1,9 @@
package cn.iocoder.yudao.module.promotion.controller.app.seckill;
import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.config.AppSeckillConfigRespVO;
import cn.iocoder.yudao.module.promotion.convert.seckill.seckillconfig.SeckillConfigConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillconfig.SeckillConfigDO;
import cn.iocoder.yudao.module.promotion.service.seckill.SeckillConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -15,7 +13,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -31,13 +28,7 @@ public class AppSeckillConfigController {
@GetMapping("/list")
@Operation(summary = "获得秒杀时间段列表")
public CommonResult<List<AppSeckillConfigRespVO>> getSeckillConfigList() {
List<SeckillConfigDO> list = configService.getSeckillConfigListByStatus(CommonStatusEnum.ENABLE.getStatus());
// TODO @puhui999如果这种不用判空也问题不大
if (CollectionUtil.isEmpty(list)) {
return success(Collections.emptyList());
}
return success(SeckillConfigConvert.INSTANCE.convertList2(list));
return success(SeckillConfigConvert.INSTANCE.convertList2(configService.getSeckillConfigListByStatus(CommonStatusEnum.ENABLE.getStatus())));
}
}

View File

@ -46,9 +46,7 @@ public interface BargainActivityConvert {
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
List<BargainActivityRespVO> list = CollectionUtils.convertList(result.getList(), item -> {
findAndThen(spuMap, item.getSpuId(), spu -> {
// TODO @puhui999这里可以使用链式哈
item.setPicUrl(spu.getPicUrl());
item.setSpuName(spu.getName());
item.setPicUrl(spu.getPicUrl()).setSpuName(spu.getName());
});
return item;
});
@ -76,9 +74,7 @@ public interface BargainActivityConvert {
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
List<AppBargainActivityRespVO> list = CollectionUtils.convertList(result.getList(), item -> {
findAndThen(spuMap, item.getSpuId(), spu -> {
// TODO @puhui999这里可以使用链式哈
item.setPicUrl(spu.getPicUrl());
item.setMarketPrice(spu.getMarketPrice());
item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice());
});
return item;
});
@ -93,9 +89,7 @@ public interface BargainActivityConvert {
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
return CollectionUtils.convertList(activityList, item -> {
findAndThen(spuMap, item.getSpuId(), spu -> {
// TODO @puhui999这里可以使用链式哈
item.setPicUrl(spu.getPicUrl());
item.setMarketPrice(spu.getMarketPrice());
item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice());
});
return item;
});

View File

@ -62,8 +62,7 @@ public interface CombinationActivityConvert {
PageResult<CombinationActivityRespVO> pageResult = convertPage(page);
pageResult.getList().forEach(item -> {
MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> {
item.setSpuName(spu.getName());
item.setPicUrl(spu.getPicUrl());
item.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl());
});
item.setProducts(convertList2(productList));
});
@ -100,16 +99,15 @@ public interface CombinationActivityConvert {
default CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO,
CombinationActivityDO activity, MemberUserRespDTO user,
ProductSpuRespDTO spu, ProductSkuRespDTO sku) {
// TODO @puhui999搞成链式的 set这样会更规整一点
CombinationRecordDO record = convert(reqDTO);
record.setVirtualGroup(false);
record.setExpireTime(record.getStartTime().plusHours(activity.getLimitDuration()));
record.setUserSize(activity.getUserSize());
record.setNickname(user.getNickname());
record.setAvatar(user.getAvatar());
record.setSpuName(spu.getName());
record.setPicUrl(sku.getPicUrl());
return record;
// TODO @puhui999订单付款后需要设置开始时间和结束时间
return convert(reqDTO)
.setVirtualGroup(false)
.setExpireTime(activity.getStartTime().plusHours(activity.getLimitDuration()))
.setUserSize(activity.getUserSize())
.setNickname(user.getNickname())
.setAvatar(user.getAvatar())
.setSpuName(spu.getName())
.setPicUrl(sku.getPicUrl());
}
List<CombinationRecordRespDTO> convert(List<CombinationRecordDO> bean);
@ -121,8 +119,7 @@ public interface CombinationActivityConvert {
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
return CollectionUtils.convertList(activityList, item -> {
findAndThen(spuMap, item.getSpuId(), spu -> {
item.setPicUrl(spu.getPicUrl());
item.setMarketPrice(spu.getMarketPrice());
item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice());
});
return item;
});
@ -135,8 +132,7 @@ public interface CombinationActivityConvert {
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
List<AppCombinationActivityRespVO> list = CollectionUtils.convertList(appPage.getList(), item -> {
findAndThen(spuMap, item.getSpuId(), spu -> {
item.setPicUrl(spu.getPicUrl());
item.setMarketPrice(spu.getMarketPrice());
item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice());
});
return item;
});
@ -149,9 +145,7 @@ public interface CombinationActivityConvert {
List<AppCombinationActivityDetailRespVO.Product> convertList1(List<CombinationProductDO> products);
default AppCombinationActivityDetailRespVO convert3(CombinationActivityDO combinationActivity, List<CombinationProductDO> products) {
AppCombinationActivityDetailRespVO detailRespVO = convert2(combinationActivity);
detailRespVO.setProducts(convertList1(products));
return detailRespVO;
return convert2(combinationActivity).setProducts(convertList1(products));
}
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity;
import cn.hutool.core.date.LocalDateTimeUtil;
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;
@ -29,7 +30,6 @@ import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
/**
* 秒杀活动 Convert
@ -98,10 +98,9 @@ public interface SeckillActivityConvert {
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
respVO.setActivities(CollectionUtils.convertList(convertList3(activityList), item -> {
findAndThen(spuMap, item.getSpuId(), spu -> {
// TODO @puhui999可以尝试链式 set
item.setPicUrl(spu.getPicUrl());
item.setMarketPrice(spu.getMarketPrice());
item.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()));
item.setPicUrl(spu.getPicUrl())
.setMarketPrice(spu.getMarketPrice())
.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()));
});
return item;
}));
@ -115,10 +114,9 @@ public interface SeckillActivityConvert {
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
List<AppSeckillActivityRespVO> list = CollectionUtils.convertList(result.getList(), item -> {
findAndThen(spuMap, item.getSpuId(), spu -> {
// TODO @puhui999可以尝试链式 set
item.setPicUrl(spu.getPicUrl());
item.setMarketPrice(spu.getMarketPrice());
item.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()));
item.setPicUrl(spu.getPicUrl())
.setMarketPrice(spu.getMarketPrice())
.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()));
});
return item;
});
@ -131,12 +129,12 @@ public interface SeckillActivityConvert {
List<AppSeckillActivityDetailRespVO.Product> convertList1(List<SeckillProductDO> products);
default AppSeckillActivityDetailRespVO convert3(SeckillActivityDO seckillActivity, List<SeckillProductDO> products, SeckillConfigDO filteredConfig) {
AppSeckillActivityDetailRespVO respVO = convert2(seckillActivity);
respVO.setProducts(convertList1(products));
// TODO @puhui999可以尝试链式 set
respVO.setStartTime(buildTime(filteredConfig.getStartTime()));
respVO.setEndTime(buildTime(filteredConfig.getEndTime()));
return respVO;
return convert2(seckillActivity)
.setProducts(convertList1(products))
.setStartTime(LocalDateTimeUtil.parse(LocalDateTimeUtil.format(seckillActivity.getStartTime(), "yyyy-MM-dd") + " " + filteredConfig.getStartTime(),
"yyyy-MM-dd HH:mm:ss")) // 活动开始日期和时段结合
.setEndTime(LocalDateTimeUtil.parse(LocalDateTimeUtil.format(seckillActivity.getEndTime(), "yyyy-MM-dd") + " " + filteredConfig.getEndTime(),
"yyyy-MM-dd HH:mm:ss")); // 活动结束日期和时段结合
}
}

View File

@ -45,11 +45,34 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> {
.setSql("stock = stock - " + count));
}
default PageResult<BargainActivityDO> selectAppPage(PageParam pageReqVO, Integer status, LocalDateTime now) {
/**
* 查询处在 now 日期时间且是 status 状态的活动分页
*
* @param pageReqVO 分页参数
* @param status 状态
* @param now 当前日期时间
* @return 活动分页
*/
default PageResult<BargainActivityDO> selectPage(PageParam pageReqVO, Integer status, LocalDateTime now) {
return selectPage(pageReqVO, new LambdaQueryWrapperX<BargainActivityDO>()
.eq(BargainActivityDO::getStatus, status)
.le(BargainActivityDO::getStartTime, now)
.ge(BargainActivityDO::getEndTime, now));
}
/**
* 查询处在 now 日期时间且是 status 状态的活动分页
*
* @param status 状态
* @param now 当前日期时间
* @return 活动分页
*/
default List<BargainActivityDO> selectList(Integer count, Integer status, LocalDateTime now) {
return selectList(new LambdaQueryWrapperX<BargainActivityDO>()
.eq(BargainActivityDO::getStatus, status)
.le(BargainActivityDO::getStartTime, now)
.ge(BargainActivityDO::getEndTime, now)
.apply("LIMIT " + count));
}
}

View File

@ -29,9 +29,29 @@ public interface CombinationActivityMapper extends BaseMapperX<CombinationActivi
return selectList(CombinationActivityDO::getStatus, status);
}
default PageResult<CombinationActivityDO> selectAppPage(PageParam pageParam, Integer status) {
/**
* 查询 status 状态的活动分页
*
* @param pageParam 分页参数
* @param status 状态
* @return 活动分页
*/
default PageResult<CombinationActivityDO> selectPage(PageParam pageParam, Integer status) {
return selectPage(pageParam, new LambdaQueryWrapperX<CombinationActivityDO>()
.eq(CombinationActivityDO::getStatus, status));
}
/**
* 查询 status 状态的活动分页
*
* @param status 状态
* @param count 限制条数
* @return 活动分页
*/
default List<CombinationActivityDO> selectList(Integer status, Integer count) {
return selectList(new LambdaQueryWrapperX<CombinationActivityDO>()
.eq(CombinationActivityDO::getStatus, status)
.apply("LIMIT " + count));
}
}

View File

@ -63,22 +63,20 @@ public interface BargainActivityService {
*/
PageResult<BargainActivityDO> getBargainActivityPage(BargainActivityPageReqVO pageReqVO);
// TODO @puhui999这里可以改成进行中的活动尽量避免专门为 app 定制或者类似的名字哈mapper 那也是
/**
* 获取 APP 活动分页数据
* 获取正在进行的活动分页数据
*
* @param pageReqVO 分页请求
* @return 砍价活动分页
*/
PageResult<BargainActivityDO> getBargainActivityPageForApp(PageParam pageReqVO);
PageResult<BargainActivityDO> getBargainActivityPage(PageParam pageReqVO);
/**
* 获取 APP 端活动展示数据
* 获取正在进行的活动分页数据
*
* @param count 需要的数量
* @return 砍价活动分页
*/
List<BargainActivityDO> getBargainActivityListForApp(Integer count);
List<BargainActivityDO> getBargainActivityListByCount(Integer count);
}

View File

@ -142,21 +142,14 @@ public class BargainActivityServiceImpl implements BargainActivityService {
}
@Override
public PageResult<BargainActivityDO> getBargainActivityPageForApp(PageParam pageReqVO) {
public PageResult<BargainActivityDO> getBargainActivityPage(PageParam pageReqVO) {
// 只查询进行中且在时间范围内的
return bargainActivityMapper.selectAppPage(pageReqVO, CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now());
return bargainActivityMapper.selectPage(pageReqVO, CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now());
}
@Override
public List<BargainActivityDO> getBargainActivityListForApp(Integer count) {
// TODO @puhui999这种 default count 的逻辑可以放到 controller 然后可以使用 ObjectUtils.default 方法
if (count == null) {
count = 6;
}
// TODO @puhui999这种不要用 page会浪费一次 count
PageResult<BargainActivityDO> result = bargainActivityMapper.selectAppPage(new PageParam().setPageSize(count),
CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now());
return result.getList();
public List<BargainActivityDO> getBargainActivityListByCount(Integer count) {
return bargainActivityMapper.selectList(count, CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now());
}
}

View File

@ -85,19 +85,19 @@ public interface CombinationActivityService {
void validateCombination(Long activityId, Long userId, Long skuId, Integer count);
/**
* 获取 APP 端活动展示数据
* 获取正在进行的活动分页数据
*
* @param count 需要的数量
* @return 活动列表
* @return 拼团活动分页
*/
List<CombinationActivityDO> getCombinationActivityAppList(Integer count);
List<CombinationActivityDO> getCombinationActivityListByCount(Integer count);
/**
* 获取 APP 活动分页数据
* 获取正在进行的活动分页数据
*
* @param pageParam 分页参数
* @return 活动分页数据
* @param pageParam 分页请求
* @return 拼团活动分页
*/
PageResult<CombinationActivityDO> getCombinationActivityAppPage(PageParam pageParam);
PageResult<CombinationActivityDO> getCombinationActivityPage(PageParam pageParam);
}

View File

@ -224,8 +224,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE);
}
// 1.3 校验是否超出单次限购数量
// TODO puhui999count > activity.getSingleLimitCount() 会更好理解点
if (activity.getSingleLimitCount() < count) {
if (count > activity.getSingleLimitCount()) {
throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED);
}
@ -247,19 +246,13 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
}
@Override
public List<CombinationActivityDO> getCombinationActivityAppList(Integer count) {
if (count == null) {
count = 6;
}
PageResult<CombinationActivityDO> result = combinationActivityMapper.selectAppPage(new PageParam().setPageSize(count),
CommonStatusEnum.ENABLE.getStatus());
return result.getList();
public List<CombinationActivityDO> getCombinationActivityListByCount(Integer count) {
return combinationActivityMapper.selectList(CommonStatusEnum.ENABLE.getStatus(), count);
}
@Override
public PageResult<CombinationActivityDO> getCombinationActivityAppPage(PageParam pageParam) {
return combinationActivityMapper.selectAppPage(pageParam, CommonStatusEnum.ENABLE.getStatus());
public PageResult<CombinationActivityDO> getCombinationActivityPage(PageParam pageParam) {
return combinationActivityMapper.selectPage(pageParam, CommonStatusEnum.ENABLE.getStatus());
}
}

View File

@ -37,11 +37,11 @@ public interface SeckillActivityService {
/**
* 更新秒杀库存
*
* @param activityId 活动编号
* @param id 活动编号
* @param skuId sku 编号
* @param count 数量
*/
void updateSeckillStock(Long activityId, Long skuId, Integer count);
void updateSeckillStock(Long id, Long skuId, Integer count);
/**
* 关闭秒杀活动
@ -97,6 +97,15 @@ public interface SeckillActivityService {
*/
List<SeckillActivityDO> getSeckillActivityListByConfigIds(Collection<Long> ids);
/**
* 通过活动时段编号获取指定 status 的秒杀活动
*
* @param configId 时段配置编号
* @param status 状态
* @return 秒杀活动列表
*/
List<SeckillActivityDO> getSeckillActivityListByConfigIdAndStatus(Long configId, Integer status);
/**
* 通过活动时段获取秒杀活动
*

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.promotion.service.seckill;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
@ -31,6 +30,7 @@ import java.util.Map;
import static cn.hutool.core.collection.CollUtil.isNotEmpty;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.isBetween;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
@ -148,16 +148,16 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
@Override
@Transactional(rollbackFor = Exception.class)
public void updateSeckillStock(Long activityId, Long skuId, Integer count) {
public void updateSeckillStock(Long id, Long skuId, Integer count) {
// 1校验秒杀活动是否存在
SeckillActivityDO seckillActivity = getSeckillActivity(activityId);
SeckillActivityDO seckillActivity = getSeckillActivity(id);
// 1.1校验库存是否充足
if (seckillActivity.getTotalStock() < count) {
throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL);
}
// 2获取活动商品
List<SeckillProductDO> products = getSeckillProductListByActivityId(activityId);
List<SeckillProductDO> products = getSeckillProductListByActivityId(id);
// 2.1过滤出购买的商品
SeckillProductDO product = findFirst(products, item -> ObjectUtil.equal(skuId, item.getSkuId()));
// 2.2检查活动商品库存是否充足
@ -268,8 +268,15 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
@Override
public List<SeckillActivityDO> getSeckillActivityListByConfigIds(Collection<Long> ids) {
return CollectionUtils.filterList(seckillActivityMapper.selectList(),
item -> CollectionUtils.anyMatch(item.getConfigIds(), ids::contains));
return filterList(seckillActivityMapper.selectList(),
item -> anyMatch(item.getConfigIds(), ids::contains));
}
@Override
public List<SeckillActivityDO> getSeckillActivityListByConfigIdAndStatus(Long configId, Integer status) {
return filterList(seckillActivityMapper.selectList(SeckillActivityDO::getStatus, status),
item -> anyMatch(item.getConfigIds(), id -> ObjectUtil.equal(id, configId)) // 校验时段
&& isBetween(item.getStartTime(), item.getEndTime())); // 追加当前日期是否处在活动日期之间的校验条件
}
@Override

View File

@ -54,6 +54,7 @@ public interface SeckillConfigService {
*/
List<SeckillConfigDO> getSeckillConfigList();
/**
* 校验秒杀时段是否存在
*
@ -85,4 +86,12 @@ public interface SeckillConfigService {
*/
void updateSeckillConfigStatus(Long id, Integer status);
/**
* 获取当前日期时间处于的秒杀时段且状态为 status
*
* @param status 状态
* @return 时段
*/
SeckillConfigDO getSeckillConfigListByStatusOnCurrentTime(Integer status);
}

View File

@ -20,6 +20,8 @@ import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.isBetween;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
/**
@ -67,6 +69,12 @@ public class SeckillConfigServiceImpl implements SeckillConfigService {
seckillConfigMapper.updateById(new SeckillConfigDO().setId(id).setStatus(status));
}
@Override
public SeckillConfigDO getSeckillConfigListByStatusOnCurrentTime(Integer status) {
return findFirst(seckillConfigMapper.selectList(SeckillConfigDO::getStatus, status),
config -> isBetween(config.getStartTime(), config.getEndTime()));
}
@Override
public void deleteSeckillConfig(Long id) {
// 校验存在

View File

@ -12,7 +12,7 @@ import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespDTO;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespVO;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService;
import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
@ -87,13 +87,13 @@ public class TradeAfterSaleController {
// 拼接数据
MemberUserRespDTO user = memberUserApi.getUser(afterSale.getUserId());
// 获取售后日志
List<TradeAfterSaleLogRespDTO> logs = afterSaleLogService.getLog(afterSale.getId());
List<TradeAfterSaleLogRespVO> logs = afterSaleLogService.getLog(afterSale.getId());
// TODO 方便测试看效果review 后移除
if (logs == null) {
logs = new ArrayList<>();
}
for (int i = 1; i <= 6; i++) {
TradeAfterSaleLogRespDTO respVO = new TradeAfterSaleLogRespDTO();
TradeAfterSaleLogRespVO respVO = new TradeAfterSaleLogRespVO();
respVO.setId((long) i);
respVO.setUserId((long) i);
respVO.setUserType(i % 2 == 0 ? 2 : 1);

View File

@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleDetailRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRespPageItemVO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.log.TradeAfterSaleLogRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderBaseVO;
@ -16,7 +15,7 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleLogDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespDTO;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespVO;
import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@ -68,10 +67,10 @@ public interface TradeAfterSaleConvert {
PageResult<AppTradeAfterSaleRespVO> convertPage02(PageResult<TradeAfterSaleDO> page);
List<TradeAfterSaleLogRespDTO> convertList(List<TradeAfterSaleLogDO> list);
List<TradeAfterSaleLogRespVO> convertList(List<TradeAfterSaleLogDO> list);
default TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, TradeOrderDO order, List<TradeOrderItemDO> orderItems,
MemberUserRespDTO user, List<TradeAfterSaleLogRespDTO> logs) {
MemberUserRespDTO user, List<TradeAfterSaleLogRespVO> logs) {
TradeAfterSaleDetailRespVO respVO = convert(afterSale, orderItems);
// 处理用户信息
respVO.setUser(convert(user));
@ -81,7 +80,8 @@ public interface TradeAfterSaleConvert {
respVO.setLogs(convertList1(logs));
return respVO;
}
List<TradeAfterSaleLogRespVO> convertList1(List<TradeAfterSaleLogRespDTO> list);
List<cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.log.TradeAfterSaleLogRespVO> convertList1(List<TradeAfterSaleLogRespVO> list);
@Mapping(target = "id", source = "afterSale.id")
TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, List<TradeOrderItemDO> orderItems);
TradeOrderBaseVO convert(TradeOrderDO order);

View File

@ -8,7 +8,6 @@ import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
// TODO @puhui999这个是不是应该搞成 vo
/**
* 贸易售后日志详情 DTO
*
@ -17,7 +16,7 @@ import java.time.LocalDateTime;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class TradeAfterSaleLogRespDTO {
public class TradeAfterSaleLogRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20669")
private Long id;

View File

@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespDTO;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespVO;
import java.util.List;
@ -29,6 +29,6 @@ public interface AfterSaleLogService {
* @param afterSaleId 售后编号
* @return 售后日志
*/
List<TradeAfterSaleLogRespDTO> getLog(Long afterSaleId);
List<TradeAfterSaleLogRespVO> getLog(Long afterSaleId);
}

View File

@ -26,7 +26,7 @@ import cn.iocoder.yudao.module.trade.enums.aftersale.TradeAfterSaleWayEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespDTO;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespVO;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService;
import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
@ -450,7 +450,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
}
@Override
public List<TradeAfterSaleLogRespDTO> getLog(Long afterSaleId) {
public List<TradeAfterSaleLogRespVO> getLog(Long afterSaleId) {
// TODO 不熟悉流程先这么滴
List<TradeAfterSaleLogDO> saleLogDOs = tradeAfterSaleLogMapper.selectList(TradeAfterSaleLogDO::getAfterSaleId, afterSaleId);
return TradeAfterSaleConvert.INSTANCE.convertList(saleLogDOs);

View File

@ -553,41 +553,49 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
tradeOrderMapper.updateById(update);
// TODO @芋艿改价时赠送的积分要不要做改动
// TODO @puhui999应该是按照 payPrice 分配并且要考虑取余问题payPrice 也要考虑item 里的
// TODO先按 adjustPrice 实现没明白 payPrice 怎么搞哈哈哈
// TODO @puhui999就是对比新老 adjustPrice 的差值然后计算补充的 adjustPrice 最终值另外可以不用区分 items.size 是不是 > 1 应该是一致的逻辑分摊的逻辑有点类似 dividePrice 方法噢
// 5更新 TradeOrderItem
if (items.size() > 1) {
// TradeOrderItemDO 需要做 adjustPrice 的分摊
int price = reqVO.getAdjustPrice() / items.size();
int remainderPrice = reqVO.getAdjustPrice() % items.size();
List<TradeOrderItemDO> orders = new ArrayList<>();
for (int i = 0; i < items.size(); i++) {
// 把平摊后剩余的金额加到第一个订单项
if (remainderPrice != 0 && i == 0) {
orders.add(convertOrderItemPrice(items.get(i), price + remainderPrice));
}
orders.add(convertOrderItemPrice(items.get(i), price));
}
tradeOrderItemMapper.updateBatch(orders);
} else {
TradeOrderItemDO orderItem = items.get(0);
TradeOrderItemDO updateItem = convertOrderItemPrice(orderItem, reqVO.getAdjustPrice());
tradeOrderItemMapper.updateById(updateItem);
// TradeOrderItemDO 需要做 adjustPrice 的分摊
List<Integer> dividePrices = dividePrice(items, orderPayPrice);
List<TradeOrderItemDO> updateItems = new ArrayList<>();
for (int i = 0; i < items.size(); i++) {
TradeOrderItemDO item = items.get(i);
Integer adjustPrice = item.getPrice() - dividePrices.get(i); // 计算调整的金额
updateItems.add(new TradeOrderItemDO().setId(item.getId()).setAdjustPrice(adjustPrice)
.setPayPrice(item.getPayPrice() - adjustPrice));
}
tradeOrderItemMapper.updateBatch(updateItems);
// 6更新支付订单
payOrderApi.updatePayOrderPrice(order.getPayOrderId(), update.getPayPrice());
}
private TradeOrderItemDO convertOrderItemPrice(TradeOrderItemDO orderItem, Integer price) {
TradeOrderItemDO newOrderItem = new TradeOrderItemDO();
newOrderItem.setId(orderItem.getId());
newOrderItem.setAdjustPrice(price);
int payPrice = orderItem.getAdjustPrice() != null ? (orderItem.getPayPrice() - orderItem.getAdjustPrice())
+ price : orderItem.getPayPrice() + price;
newOrderItem.setPayPrice(payPrice);
return newOrderItem;
/**
* 计算订单调价价格分摊
*
* @param items 订单项
* @param orderPayPrice 订单支付金额
* @return 分摊金额数组和传入的 orderItems 一一对应
*/
private List<Integer> dividePrice(List<TradeOrderItemDO> items, Integer orderPayPrice) {
Integer total = getSumValue(items, TradeOrderItemDO::getPrice, Integer::sum);
assert total != null;
// 遍历每一个进行分摊
List<Integer> prices = new ArrayList<>(items.size());
int remainPrice = orderPayPrice;
for (int i = 0; i < items.size(); i++) {
TradeOrderItemDO orderItem = items.get(i);
int partPrice;
if (i < items.size() - 1) { // 减一的原因是因为拆分时如果按照比例可能会出现.所以最后一个使用反减
partPrice = (int) (orderPayPrice * (1.0D * orderItem.getPayPrice() / total));
remainPrice -= partPrice;
} else {
partPrice = remainPrice;
}
Assert.isTrue(partPrice >= 0, "分摊金额必须大于等于 0");
prices.add(partPrice);
}
return prices;
}
@Override

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.trade.service.order.bo;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -14,36 +15,73 @@ import javax.validation.constraints.NotNull;
@Data
public class TradeBeforeOrderCreateReqBO {
// TODO @puhui999注释也写下哈bo 还是写注释噢
/**
* 订单类型
*
* 枚举 {@link TradeOrderTypeEnum}
*/
@NotNull(message = "订单类型不能为空")
private Integer orderType;
/**
* 用户编号
*
* 关联 MemberUserDO id 编号
*/
@NotNull(message = "用户编号不能为空")
private Long userId;
// ========== 秒杀活动相关字段 ==========
/**
*
*/
@Schema(description = "秒杀活动编号", example = "1024")
private Long seckillActivityId;
// ========== 拼团活动相关字段 ==========
/**
* 拼团活动编号
*/
@Schema(description = "拼团活动编号", example = "1024")
private Long combinationActivityId;
/**
* 拼团团长编号
*/
@Schema(description = "拼团团长编号", example = "2048")
private Long combinationHeadId;
// ========== 砍价活动相关字段 ==========
/**
* 砍价活动编号
*/
@Schema(description = "砍价活动编号", example = "123")
private Long bargainActivityId;
// ========== 活动购买商品相关字段 ==========
/**
* 商品 SPU 编号
*
* 关联 ProductSkuDO spuId 编号
*/
@NotNull(message = "SPU 编号不能为空")
private Long spuId;
/**
* 商品 SKU 编号
*
* 关联 ProductSkuDO id 编号
*/
@NotNull(message = "SKU 编号活动商品不能为空")
private Long skuId;
@NotNull(message = "用户编号不能为空")
private Long userId;
/**
* 购买的商品数量
*/
@NotNull(message = "购买数量不能为空")
private Integer count;