code review:拼团记录流程

This commit is contained in:
YunaiV 2023-10-08 21:14:54 +08:00
parent 781ec1028f
commit 7b727d5ce2
12 changed files with 38 additions and 44 deletions

View File

@ -4,7 +4,6 @@ import lombok.Data;
import javax.validation.constraints.NotNull;
// TODO @芋艿这块要在看看
/**
* 拼团记录的创建 Request DTO
*

View File

@ -55,8 +55,8 @@ public class CombinationRecordController {
public CommonResult<CombinationRecordSummaryVO> getCombinationRecordSummary() {
CombinationRecordSummaryVO summaryVO = new CombinationRecordSummaryVO();
summaryVO.setUserCount(combinationRecordService.getCombinationRecordCount(null, null)); // 获取所有拼团记录
summaryVO.setSuccessCount(combinationRecordService.getCombinationRecordCount(
CombinationRecordStatusEnum.SUCCESS.getStatus(), null));// 获取成团记录
summaryVO.setSuccessCount(combinationRecordService.getCombinationRecordCount( // 获取成团记录
CombinationRecordStatusEnum.SUCCESS.getStatus(), null));
summaryVO.setVirtualGroupCount(combinationRecordService.getCombinationRecordCount(null, Boolean.TRUE));// 获取虚拟成团记录
return success(summaryVO);
}

View File

@ -55,7 +55,6 @@ public class AppActivityController {
if (CollUtil.isEmpty(spuIds)) {
return success(MapUtil.empty());
}
// 每种活动只返回一个key SPU 编号
return success(convertMultiMap(getAppActivityRespVOList(spuIds), AppActivityRespVO::getSpuId));
}
@ -64,20 +63,15 @@ public class AppActivityController {
if (CollUtil.isEmpty(spuIds)) {
return new ArrayList<>();
}
List<AppActivityRespVO> activityList = new ArrayList<>();
// 拼团活动
List<CombinationActivityDO> combinationActivities = combinationActivityService.getCombinationActivityBySpuIdsAndStatus(
spuIds, CommonStatusEnum.ENABLE.getStatus());
if (CollUtil.isNotEmpty(combinationActivities)) {
combinationActivities.forEach(item -> {
activityList.add(new AppActivityRespVO()
.setId(item.getId())
.setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType())
.setName(item.getName())
.setSpuId(item.getSpuId())
.setStartTime(item.getStartTime())
.setEndTime(item.getEndTime()));
activityList.add(new AppActivityRespVO().setId(item.getId())
.setType(PromotionTypeEnum.COMBINATION_ACTIVITY.getType()).setName(item.getName())
.setSpuId(item.getSpuId()).setStartTime(item.getStartTime()).setEndTime(item.getEndTime()));
});
}
// 秒杀活动
@ -85,13 +79,9 @@ public class AppActivityController {
spuIds, CommonStatusEnum.ENABLE.getStatus());
if (CollUtil.isNotEmpty(seckillActivities)) {
seckillActivities.forEach(item -> {
activityList.add(new AppActivityRespVO()
.setId(item.getId())
.setType(PromotionTypeEnum.SECKILL_ACTIVITY.getType())
.setName(item.getName())
.setSpuId(item.getSpuId())
.setStartTime(item.getStartTime())
.setEndTime(item.getEndTime()));
activityList.add(new AppActivityRespVO().setId(item.getId())
.setType(PromotionTypeEnum.SECKILL_ACTIVITY.getType()).setName(item.getName())
.setSpuId(item.getSpuId()).setStartTime(item.getStartTime()).setEndTime(item.getEndTime()));
});
}
// 砍价活动
@ -99,13 +89,9 @@ public class AppActivityController {
spuIds, CommonStatusEnum.ENABLE.getStatus());
if (CollUtil.isNotEmpty(bargainActivities)) {
bargainActivities.forEach(item -> {
activityList.add(new AppActivityRespVO()
.setId(item.getId())
.setType(PromotionTypeEnum.BARGAIN_ACTIVITY.getType())
.setName(item.getName())
.setSpuId(item.getSpuId())
.setStartTime(item.getStartTime())
.setEndTime(item.getEndTime()));
activityList.add(new AppActivityRespVO().setId(item.getId())
.setType(PromotionTypeEnum.BARGAIN_ACTIVITY.getType()).setName(item.getName())
.setSpuId(item.getSpuId()).setStartTime(item.getStartTime()).setEndTime(item.getEndTime()));
});
}
return activityList;

View File

@ -109,22 +109,19 @@ public interface CombinationActivityConvert {
CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO);
// TODO @芋艿 convert 优化下
default CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO,
CombinationActivityDO activity, MemberUserRespDTO user,
ProductSpuRespDTO spu, ProductSkuRespDTO sku) {
return convert(reqDTO)
.setCount(reqDTO.getCount())
.setVirtualGroup(false) // 默认 false 拼团过期都还没有成功则按照 CombinationActivityDO#virtualGroup 来如果为 true 则执行虚拟成团的逻辑
return convert(reqDTO).setVirtualGroup(false)
.setStatus(CombinationRecordStatusEnum.IN_PROGRESS.getStatus()) // 创建后默认状态为进行中
.setStartTime(LocalDateTime.now())
.setStartTime(LocalDateTime.now()) // TODO @puhui999想了下这个 startTime 应该是团长的
// TODO @puhui999有团长的情况下expireTime 应该是团长的
.setExpireTime(activity.getStartTime().plusHours(activity.getLimitDuration()))
.setUserSize(activity.getUserSize())
.setUserCount(1) // 默认就是 1 插入后会接着更新一次所有的拼团记录
.setNickname(user.getNickname())
.setAvatar(user.getAvatar())
.setSpuName(spu.getName())
.setPicUrl(sku.getPicUrl());
.setUserSize(activity.getUserSize()).setUserCount(1) // 默认就是 1 插入后会接着更新一次所有的拼团记录
// 用户信息
.setNickname(user.getNickname()).setAvatar(user.getAvatar())
// 商品信息
.setSpuName(spu.getName()).setPicUrl(sku.getPicUrl());
}

View File

@ -116,6 +116,9 @@ public class CombinationRecordDO extends BaseDO {
private Integer userCount;
/**
* 是否虚拟成团
*
* 默认为 false
* 拼团过期都还没有成功如果 {@link CombinationActivityDO#getVirtualGroup()} true则执行虚拟成团的逻辑才会更新该字段为 true
*/
private Boolean virtualGroup;

View File

@ -85,6 +85,8 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> {
.last("LIMIT " + count));
}
// TODO @puhui999一个商品在统一时间不会参与多个活动so 是不是不用 inner join
// PS如果可以参与多个其实可以这样写 select * from promotion_bargain_activity group by spu_id ORDER BY create_time DESC通过 group 来过滤
/**
* 获取指定 spu 编号最近参加的活动每个 spuId 只返回一条记录
*

View File

@ -43,6 +43,7 @@ public interface CombinationActivityMapper extends BaseMapperX<CombinationActivi
.last("LIMIT " + count));
}
// TODO @puhui999类似 BargainActivityMapper
/**
* 获取指定 spu 编号最近参加的活动每个 spuId 只返回一条记录
*

View File

@ -100,7 +100,8 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
.betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime()));
}
default Long selectRecordCount(Integer status, Boolean virtualGroup) {
// TODO @puhui999这个最好把 headId 也作为一个参数因为有个要求 userCount它要 DISTINCT 整体可以参考 selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId
default Long selectCountByHeadAndStatusAndVirtualGroup(Integer status, Boolean virtualGroup) {
return selectCount(new LambdaQueryWrapperX<CombinationRecordDO>()
.eq(status != null || virtualGroup != null,
CombinationRecordDO::getHeadId, CombinationRecordDO.HEAD_ID_GROUP) // 统计团信息则指定团长

View File

@ -58,6 +58,7 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> {
.apply(ObjectUtil.isNotNull(pageReqVO.getConfigId()), "FIND_IN_SET(" + pageReqVO.getConfigId() + ",config_ids) > 0"));
}
// TODO @puhui999类似 BargainActivityMapper
/**
* 获取指定 spu 编号最近参加的活动每个 spuId 只返回一条记录
*

View File

@ -169,19 +169,22 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(reqDTO.getUserId(),
reqDTO.getActivityId(), reqDTO.getHeadId(), reqDTO.getSkuId(), reqDTO.getCount());
// 2. 组合数据创建拼团记录
// 2.1 组合数据创建拼团记录
MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId());
ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId());
ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId());
CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku);
// 3. 如果是团长需要设置 headId CombinationRecordDO#HEAD_ID_GROUP
record.setHeadId(record.getHeadId() == null ? CombinationRecordDO.HEAD_ID_GROUP : record.getHeadId());
// 2.2 如果是团长需要设置 headId CombinationRecordDO#HEAD_ID_GROUP
if (record.getHeadId() == null) {
record.setHeadId(CombinationRecordDO.HEAD_ID_GROUP);
}
recordMapper.insert(record);
if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, record.getHeadId())) {
return record.getId();
}
// TODO @puhui是不是这里的更新放到 order 模块那支付完成后
// 4更新拼团相关信息到订单
tradeOrderApi.updateOrderCombinationInfo(record.getOrderId(), record.getActivityId(), record.getId(), record.getHeadId());
// 4更新拼团记录
@ -239,7 +242,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
@Override
public Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup) {
return recordMapper.selectRecordCount(status, virtualGroup);
return recordMapper.selectCountByHeadAndStatusAndVirtualGroup(status, virtualGroup);
}
@Override

View File

@ -153,15 +153,15 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
* @return 物流轨迹
*/
private List<ExpressTrackRespDTO> getExpressTrackList(TradeOrderDO order) {
// 查询物流公司
if (order.getLogisticsId() == null) {
return Collections.emptyList();
}
// 查询物流公司
DeliveryExpressDO express = deliveryExpressService.getDeliveryExpress(order.getLogisticsId());
if (express == null) {
throw exception(EXPRESS_NOT_EXISTS);
}
// 查询物流轨迹
return getSelf().getExpressTrackList(express.getCode(), order.getLogisticsNo(), order.getReceiverMobile());
}

View File

@ -743,6 +743,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
// 校验交易订单
TradeOrderDO order = validateOrderExists(reqVO.getId());
// 发货后不允许修改
// TODO @puhui999只有待发货可以执行 update
if (TradeOrderStatusEnum.isDelivered(order.getStatus())) {
throw exception(ORDER_UPDATE_ADDRESS_FAIL_STATUS_NOT_DELIVERED);
}