额度限制去除,计费后额度允许为负
This commit is contained in:
+33
-3
@@ -249,6 +249,9 @@ public class CustomerAccountApiImpl implements ICustomerAccountApi
|
||||
String currency = resolveCurrency(command.getCurrency());
|
||||
String username = currentUsername();
|
||||
Long userId = currentUserId();
|
||||
// 计费开单准入:客户被停用(含删除)时直接拦截,与账户状态接口口径保持一致。
|
||||
// 仅占用(新增计费)校验;释放/核销等清欠动作不受限,避免客户被停用后无法平账。
|
||||
assertCustomerActive(customerId);
|
||||
CustomerAccount account = lockAccountForUsage(customerId, currency, username);
|
||||
if (account == null)
|
||||
{
|
||||
@@ -259,10 +262,20 @@ public class CustomerAccountApiImpl implements ICustomerAccountApi
|
||||
BigDecimal beforeUsed = nz(account.getUsedCredit());
|
||||
BigDecimal totalAvailable = nz(account.getTotalCredit()).add(nz(account.getExtraCredit()))
|
||||
.subtract(beforeUsed);
|
||||
if (Boolean.TRUE.equals(command.getCheckAvailable()) && totalAvailable.compareTo(amount) < 0)
|
||||
if (Boolean.TRUE.equals(command.getCheckAvailable()))
|
||||
{
|
||||
throw new ServiceException("客户可用额度不足,当前可用额度:" + totalAvailable.toPlainString()
|
||||
+ " " + currency + ",本次需占用:" + amount.toPlainString());
|
||||
// 已处于超额(欠费)状态:可用额度已为负,任何新增计费一律拦截
|
||||
if (totalAvailable.compareTo(BigDecimal.ZERO) < 0)
|
||||
{
|
||||
throw new ServiceException("客户已超额(欠费),当前可用额度:" + totalAvailable.toPlainString()
|
||||
+ " " + currency + ",请先回款核销恢复额度后再计费开单");
|
||||
}
|
||||
if (totalAvailable.compareTo(amount) < 0)
|
||||
{
|
||||
throw new ServiceException("客户可用额度不足,当前可用额度:" + totalAvailable.toPlainString()
|
||||
+ " " + currency + ",本次需占用:" + amount.toPlainString()
|
||||
+ ",请回款核销或申请调整额度");
|
||||
}
|
||||
}
|
||||
BigDecimal afterUsed = beforeUsed.add(amount).setScale(MONEY_SCALE, RoundingMode.HALF_UP);
|
||||
account.setUsedCredit(afterUsed);
|
||||
@@ -558,6 +571,23 @@ public class CustomerAccountApiImpl implements ICustomerAccountApi
|
||||
customerMoneyMapper.insertCreditFlow(flow);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计费开单准入:客户档案必须存在且为启用状态(is_enable='0')。
|
||||
* 删除(del_flag='1',查询返回null)或停用(is_enable='1')均拒绝新增授信占用。
|
||||
*/
|
||||
private void assertCustomerActive(Long customerId)
|
||||
{
|
||||
BmsCustomer customer = bmsCustomerMapper.selectBmsCustomerByCustomerId(customerId);
|
||||
if (customer == null)
|
||||
{
|
||||
throw new ServiceException("客户不存在或已删除,不可计费开单(客户ID:" + customerId + ")");
|
||||
}
|
||||
if ("1".equals(customer.getIsEnable()))
|
||||
{
|
||||
throw new ServiceException("客户【" + customer.getCustomerName() + "】已停用,不可计费开单");
|
||||
}
|
||||
}
|
||||
|
||||
private void validateUsageCommand(CreditUsageCommand command)
|
||||
{
|
||||
if (command == null || (command.getCustomerId() == null && !StringUtils.hasText(command.getCustomerCode())))
|
||||
|
||||
Reference in New Issue
Block a user