fix(order): 前置余额扣减并统一金额精度处理,补充余额校验与单测

- 抽取 validateSufficientBalance,统一使用 normalizeMoney 校验与比较,提升健壮性\n- AbstractOrderPlacementStrategy:在创建订单前根据 shouldDeduct 进行余额校验与扣减,使用上下文 orderId 记录流水,避免不一致\n- deductCustomerBalance:使用 amountToDeduct 变量并先归一化后运算,修正可能的精度问题\n- 调整/补充测试用例:扣减失败不插入订单、不保存用户信息;更新 selectById 调用次数校验
This commit is contained in:
irving
2025-11-02 16:03:59 -05:00
parent 79b516d81c
commit c463179e83
3 changed files with 31 additions and 9 deletions

View File

@@ -733,6 +733,8 @@ private PlayOrderLogInfoMapper orderLogInfoMapper;
assertThrows(ServiceException.class, () -> lifecycleService.placeOrder(command));
verify(customUserInfoService, never()).updateAccountBalanceById(anyString(), any(), any(), anyString(), anyString(), any(), any(), anyString());
verify(orderInfoMapper, never()).insert(any());
verify(customUserInfoService, never()).saveOrderInfo(any());
}
@Test
@@ -863,6 +865,8 @@ private PlayOrderLogInfoMapper orderLogInfoMapper;
null);
assertThrows(ServiceException.class, () -> lifecycleService.placeOrder(command));
verify(orderInfoMapper, never()).insert(any());
verify(customUserInfoService, never()).saveOrderInfo(any());
}
@Test
@@ -962,7 +966,7 @@ private PlayOrderLogInfoMapper orderLogInfoMapper;
null,
null));
verify(customUserInfoService).selectById(context.getPurchaserBy());
verify(customUserInfoService, times(2)).selectById(context.getPurchaserBy());
verify(customUserInfoService).updateAccountBalanceById(
eq(customer.getId()),
eq(customer.getAccountBalance()),