This commit is contained in:
张良(004796)
2024-05-06 16:45:54 +08:00
parent ff3bd85992
commit 8a5c145c49

View File

@@ -191,7 +191,15 @@ public class BorrowServiceImpl extends ServiceImpl<BorrowMapper, Borrow> impleme
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public void withdraw(Double withdrawAmount, Long customerId) { public void withdraw(Double withdrawAmount, Long customerId) {
Customer customer = customerService.getById(customerId);
if(customer.getAccount().doubleValue() < withdrawAmount){
throw new CustomException(MessageUtils.message("dk.withdraw.balance.not.enough.error"));
}
if(BooleanUtils.isNotTrue(customer.getAllowWithdrawFlag())){
throw new CustomException(MessageUtils.message("dk.withdraw.account.error"));
}
Borrow borrow = this.getByCustomerId(customerId); Borrow borrow = this.getByCustomerId(customerId);
if(borrow == null){ if(borrow == null){
throw new CustomException(MessageUtils.message("dk.withdraw.account.error")); throw new CustomException(MessageUtils.message("dk.withdraw.account.error"));
@@ -204,13 +212,6 @@ public class BorrowServiceImpl extends ServiceImpl<BorrowMapper, Borrow> impleme
} }
} }
} }
Customer customer = customerService.getById(customerId);
if(BooleanUtils.isNotTrue(customer.getAllowWithdrawFlag())){
throw new CustomException(MessageUtils.message("dk.withdraw.account.error"));
}
if(customer.getAccount().doubleValue() < withdrawAmount){
throw new CustomException(MessageUtils.message("dk.withdraw.balance.not.enough.error"));
}
Borrow one = this.getOne(Wrappers.lambdaQuery(Borrow.class).eq(Borrow::getCustomerId,customerId)); Borrow one = this.getOne(Wrappers.lambdaQuery(Borrow.class).eq(Borrow::getCustomerId,customerId));
if(one == null){ if(one == null){
throw new CustomException(MessageUtils.message("dk.withdraw.fail")); throw new CustomException(MessageUtils.message("dk.withdraw.fail"));