code review:订单部分逻辑

This commit is contained in:
YunaiV 2023-09-12 13:54:52 +08:00
parent bdd81e4cbc
commit e8bdd8349c
14 changed files with 33 additions and 40 deletions

View File

@ -59,6 +59,7 @@ public class ProductSkuRespDTO {
* 商品体积单位m^3 平米
*/
private Double volume;
// TODO @puhui999firstBrokeragePrice 尴尬我当时打错了secondBrokeragePrice
/**
* 一级分销的佣金单位
*/

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.api.combination;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationActivityUpdateStockReqDTO;
// TODO @puhui999是不是改成 CombinationActivityApi
/**
* 拼团活动 Api 接口
*
@ -14,6 +15,7 @@ public interface CombinationApi {
*
* @param reqDTO 请求
*/
// TODO @puhui999应该是更新哇还是校验哈
void validateCombination(CombinationActivityUpdateStockReqDTO reqDTO);
}

View File

@ -13,6 +13,8 @@ import javax.validation.constraints.NotNull;
@Data
public class CombinationActivityUpdateStockReqDTO {
// TODO @puhui999是不是一个 activityIdcountskuId 参数就完事啦
@NotNull(message = "活动编号不能为空")
private Long activityId;

View File

@ -13,6 +13,8 @@ import javax.validation.constraints.NotNull;
@Data
public class CombinationRecordCreateReqDTO {
// TODO @puhui999注释还是要的哈
@NotNull(message = "拼团活动编号不能为空")
private Long activityId;

View File

@ -13,6 +13,8 @@ import javax.validation.constraints.NotNull;
@Data
public class SeckillActivityUpdateStockReqDTO {
// TODO @puhui999可以不用 dto直接 activityIdskuIdcount 即可
@NotNull(message = "活动编号不能为空")
private Long activityId;

View File

@ -39,7 +39,7 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> {
default int updateActivityStock(Long id, int count) {
return update(null, new LambdaUpdateWrapper<BargainActivityDO>()
.eq(BargainActivityDO::getId, id)
.gt(BargainActivityDO::getStock, 0)
.gt(BargainActivityDO::getStock, 0) // TODO @puhui999不是 > 0是要大于 count
.setSql("stock = stock - " + count));
}

View File

@ -34,7 +34,7 @@ public interface SeckillProductMapper extends BaseMapperX<SeckillProductDO> {
default int updateActivityStock(Long id, int count) {
return update(null, new LambdaUpdateWrapper<SeckillProductDO>()
.eq(SeckillProductDO::getId, id)
.gt(SeckillProductDO::getStock, 0)
.gt(SeckillProductDO::getStock, 0) // TODO @puhui999不是 > 0是要大于 count
.setSql("stock = stock - " + count));
}

View File

@ -82,8 +82,8 @@ public class BargainActivityServiceImpl implements BargainActivityService {
}
// 更新砍价库存
int row = bargainActivityMapper.updateActivityStock(id, count);
if (row == 0) {
int updateCount = bargainActivityMapper.updateActivityStock(id, count);
if (updateCount == 0) {
throw exception(BARGAIN_ACTIVITY_UPDATE_STOCK_FAIL);
}
}

View File

@ -215,23 +215,29 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
@Override
public void validateCombination(CombinationActivityUpdateStockReqDTO reqDTO) {
// 1校验拼团活动是否存在
// 1.1 校验拼团活动是否存在
CombinationActivityDO activity = validateCombinationActivityExists(reqDTO.getActivityId());
// 1.1校验活动是否开启
// 1.2 校验活动是否开启
if (ObjectUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE);
}
// 1.2校验是否超出单次限购数量
// 1.3 校验是否超出单次限购数量
if (activity.getSingleLimitCount() < reqDTO.getCount()) {
throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED);
}
// 1.3校验是否超出总限购数量
List<CombinationRecordDO> recordList = combinationRecordService.getRecordListByUserIdAndActivityId(getLoginUserId(), reqDTO.getActivityId());
// 2. 校验是否超出总限购数量
// TODO @puhui999userId 应该接口传递哈要保证 service 无状态
List<CombinationRecordDO> recordList = combinationRecordService.getRecordListByUserIdAndActivityId(
getLoginUserId(), reqDTO.getActivityId());
// TODO @puhui999最好 if true return减少括号层数
if (CollUtil.isNotEmpty(recordList)) {
// 过滤出拼团成功的
// TODO @puhui999count 要不存一个在 record
List<Long> skuIds = convertList(recordList, CombinationRecordDO::getSkuId,
item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus()));
Integer countSum = tradeOrderApi.getOrderItemCountSumByOrderIdAndSkuId(convertList(recordList, CombinationRecordDO::getOrderId,
Integer countSum = tradeOrderApi.getOrderItemCountSumByOrderIdAndSkuId(convertList(recordList,
CombinationRecordDO::getOrderId,
item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())), skuIds);
if (activity.getTotalLimitCount() < countSum) {
throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED);

View File

@ -128,6 +128,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
}
// 2. 创建拼团记录
// TODO @puhui999可以把 userspusku 一起放 convert 里哈
CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO);
record.setVirtualGroup(false);
record.setExpireTime(record.getStartTime().plusHours(activity.getLimitDuration()));

View File

@ -34,25 +34,12 @@ public interface SeckillActivityService {
*/
void updateSeckillActivity(@Valid SeckillActivityUpdateReqVO updateReqVO);
/**
* 更新秒杀活动
*
* @param activityDO 秒杀活动
*/
void updateSeckillActivity(SeckillActivityDO activityDO);
/**
* 更新秒杀库存
*
* @param updateStockReqDTO 更新信息
*/
void updateSeckillStock(SeckillActivityUpdateStockReqDTO updateStockReqDTO);
/**
* 更新秒杀活动商品
*
* @param productList 活动商品列表
*/
void updateSeckillActivityProductList(List<SeckillProductDO> productList);
/**
* 关闭秒杀活动

View File

@ -145,11 +145,6 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
updateSeckillProduct(updateObj, updateReqVO.getProducts());
}
@Override
public void updateSeckillActivity(SeckillActivityDO activityDO) {
seckillActivityMapper.updateById(activityDO);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateSeckillStock(SeckillActivityUpdateStockReqDTO updateStockReqDTO) {
@ -171,23 +166,18 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
}
// 3更新活动商品库存
int itemRow = seckillProductMapper.updateActivityStock(product.getId(), updateStockReqDTO.getItem().getCount());
if (itemRow == 0) {
int updateCount = seckillProductMapper.updateActivityStock(product.getId(), updateStockReqDTO.getItem().getCount());
if (updateCount == 0) {
throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL);
}
// 4更新活动库存
int row = seckillActivityMapper.updateActivityStock(seckillActivity.getId(), updateStockReqDTO.getCount());
if (row == 0) {
updateCount = seckillActivityMapper.updateActivityStock(seckillActivity.getId(), updateStockReqDTO.getCount());
if (updateCount == 0) {
throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL);
}
}
@Override
public void updateSeckillActivityProductList(List<SeckillProductDO> productList) {
seckillProductMapper.updateBatch(productList);
}
/**
* 更新秒杀商品
*

View File

@ -34,7 +34,6 @@ import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEn
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO;
import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties;
import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO;
import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO;
import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterOrderCreateReqBO;
import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO;
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
@ -281,7 +280,7 @@ public interface TradeOrderConvert {
return new BrokerageAddReqBO().setBizId(String.valueOf(item.getId())).setSourceUserId(item.getUserId())
.setBasePrice(item.getPayPrice() * item.getCount())
.setTitle(BrokerageRecordBizTypeEnum.ORDER.getTitle()) // TODO @疯狂标题类似木晴冰雪成功购买云时代的JVM原理与实战茫农成功购买深入拆解消息队列47讲
.setFirstFixedPrice(sku.getFirstBrokerageRecord()).getSecondBrokerageRecord(sku.getSecondBrokerageRecord());
.setFirstFixedPrice(sku.getFirstBrokerageRecord()).setSecondFixedPrice(sku.getSecondBrokerageRecord());
}
@Mapping(target = "activityId", source = "reqBO.seckillActivityId")

View File

@ -542,11 +542,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
int orderPayPrice = order.getAdjustPrice() != null ? (order.getPayPrice() - order.getAdjustPrice())
+ reqVO.getAdjustPrice() : order.getPayPrice() + reqVO.getAdjustPrice();
update.setPayPrice(orderPayPrice);
// TODO @芋艿改价时赠送的积分要不要做改动
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 的分摊