code review:拼团记录流程
This commit is contained in:
parent
781ec1028f
commit
7b727d5ce2
|
@ -4,7 +4,6 @@ import lombok.Data;
|
|||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
// TODO @芋艿:这块要在看看
|
||||
/**
|
||||
* 拼团记录的创建 Request DTO
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -116,6 +116,9 @@ public class CombinationRecordDO extends BaseDO {
|
|||
private Integer userCount;
|
||||
/**
|
||||
* 是否虚拟成团
|
||||
*
|
||||
* 默认为 false。
|
||||
* 拼团过期都还没有成功,如果 {@link CombinationActivityDO#getVirtualGroup()} 为 true,则执行虚拟成团的逻辑,才会更新该字段为 true
|
||||
*/
|
||||
private Boolean virtualGroup;
|
||||
|
||||
|
|
|
@ -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 只返回一条记录
|
||||
*
|
||||
|
|
|
@ -43,6 +43,7 @@ public interface CombinationActivityMapper extends BaseMapperX<CombinationActivi
|
|||
.last("LIMIT " + count));
|
||||
}
|
||||
|
||||
// TODO @puhui999:类似 BargainActivityMapper
|
||||
/**
|
||||
* 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录
|
||||
*
|
||||
|
|
|
@ -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) // 统计团信息则指定团长
|
||||
|
|
|
@ -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 只返回一条记录
|
||||
*
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue