优化一下代码并给出详细代码 // 判断该用户是否是自研用户 if (!OverseaUtils.isOversea(clientId)) { throw new BusinessException(180000, "非自研用户,无法使用基金提取至银行卡"); } // 判断币种信息 if ("0".equals(request.getCurrency())) { throw new BusinessException(180001, "人民币无法使用该功能"); } DepositBalanceResponse depositBalanceResponse = new DepositBalanceResponse(); WithdrawalsFundReq withdrawalsFundReq = new WithdrawalsFundReq(); InComeReq inComeReq = new InComeReq(); inComeReq.setIncomeCurrency(request.getCurrency()); List<OwnBankCardVo> allOwnBankCards = bankCardManagerAppService.getAllOwnBankCards(clientId, null, RequestUtil.getClientIp(), inComeReq); if (allOwnBankCards.size() > 0) { boolean verifyBankWithdrawFunds = verifyBankWithdrawFundsRepository.verifyBankWithdrawFunds(clientId, allOwnBankCards.get(0).getNumber(), deviceId); if (!verifyBankWithdrawFunds) { throw new BusinessException(180021, "根据监管要求,请使用单笔入金达到10000港币(或等值其他货币)的银行卡进行出金操作"); } if (allOwnBankCards.get(0).isBoundTrans() && allOwnBankCards.get(0).getOutcomeStatus().contains(request.getCurrency())) { withdrawalsFundReq.withdrawalMode = "4"; depositBalanceResponse.setManner("0"); } else { withdrawalsFundReq.withdrawalMode = "6"; depositBalanceResponse.setManner("1"); } } else { throw new BusinessException(180003, "请输入正确的eid"); } withdrawalsFundReq.bankEid = request.getEid(); withdrawalsFundReq.balance = request.getBalance(); withdrawalsFundReq.stockCode = request.getStockCode(); withdrawalsFundReq.clientId = clientId; BaseResponse<WithdrawalsFundDTO> withdrawalsFundDTOBaseResponse = tradeFundHandler.withdrawalsFund(withdrawalsFundReq); if (withdrawalsFundDTOBaseResponse != null) { if (withdrawalsFundDTOBaseResponse.getStatus() == 0 && withdrawalsFundDTOBaseResponse.getData() != null) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); depositBalanceResponse.setClientId(clientId); depositBalanceResponse.setCommitTime(simpleDateFormat.format(new Date())); depositBalanceResponse.setEid(withdrawalsFundDTOBaseResponse.getData().eid); } if (withdrawalsFundDTOBaseResponse.getStatus() != 0) { if (-2302004 == withdrawalsFundDTOBaseResponse.getStatus()) { throw new BusinessException(OutComeEnum.BANKING_SECURITIES_BUSINESS_IS_NOT_ALLOWED.getId(), OutComeEnum.BANKING_SECURITIES_BUSINESS_IS_NOT_ALLOWED.getName()); } throw new BusinessException(withdrawalsFundDTOBaseResponse.getStatus(), withdrawalsFundDTOBaseResponse.getMessage(), false); } } return depositBalanceResponse;
时间: 2023-02-16 20:46:48 浏览: 80
为了优化代码,可以将一些重复的代码抽取到独立的方法中。
比如,将判断用户是否是自研用户的代码和判断币种信息的代码抽取到一个名为 `validateUserAndCurrency` 的方法中:
```
private void validateUserAndCurrency(String clientId, String currency) {
if (!OverseaUtils.isOversea(clientId)) {
throw new BusinessException(180000, "非自研用户,无法使用基金提取至银行卡");
}
if ("0".equals(currency)) {
throw new BusinessException(180001, "人民币无法使用该功能");
}
}
```
然后在代码的适当位置调用这个方法:
```
validateUserAndCurrency(clientId, request.getCurrency());
```
此外,可以将查询用户银行卡列表的代码和判断银行卡是否符合要求的代码抽取到一个名为 `getValidBankCard` 的方法中:
```
private OwnBankCardVo getValidBankCard(String clientId, String deviceId, String currency) {
InComeReq inComeReq = new InComeReq();
inComeReq.setIncomeCurrency(currency);
List<OwnBankCardVo> allOwnBankCards = bankCardManagerAppService.getAllOwnBankCards(clientId, null, RequestUtil.getClientIp(), inComeReq);
if (allOwnBankCards.size() == 0) {
throw new BusinessException(180022, "用户没有绑定可用银行卡");
}
OwnBankCardVo bankCard = allOwnBankCards.get(0);
if (!verifyBankWithdrawFundsRepository.verifyBankWithdrawFunds(clientId, bankCard.getNumber(), deviceId)) {
throw new BusinessException(180021, "根据监管要求,请使用单笔入金达到10000港币(或等值其他货币)的银行卡进行出金操作");