mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-15 18:51:54 +08:00
code review:订单部分逻辑
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
@@ -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));
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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 @puhui999:userId 应该接口传递哈;要保证 service 无状态
|
||||
List<CombinationRecordDO> recordList = combinationRecordService.getRecordListByUserIdAndActivityId(
|
||||
getLoginUserId(), reqDTO.getActivityId());
|
||||
// TODO @puhui999:最好 if true return;减少括号层数
|
||||
if (CollUtil.isNotEmpty(recordList)) {
|
||||
// 过滤出拼团成功的
|
||||
// TODO @puhui999:count 要不存一个在 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);
|
||||
|
@@ -128,6 +128,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
|
||||
}
|
||||
|
||||
// 2. 创建拼团记录
|
||||
// TODO @puhui999:可以把 user、spu、sku 一起放 convert 里哈;
|
||||
CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO);
|
||||
record.setVirtualGroup(false);
|
||||
record.setExpireTime(record.getStartTime().plusHours(activity.getLimitDuration()));
|
||||
|
@@ -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);
|
||||
|
||||
/**
|
||||
* 关闭秒杀活动
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新秒杀商品
|
||||
*
|
||||
|
Reference in New Issue
Block a user