优化一下这段代码 // 判断该用户是否是自研用户 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 17:46:47 浏览: 86
这段代码的作用是用来判断是否允许从基金提取至银行卡。
优化建议:
1. 变量名可以考虑使用更具有可读性的名称,例如将 `allOwnBankCards` 改为 `ownBankCards`。
2. 可以考虑将 `OverseaUtils.isOversea(clientId)` 和 `"0".equals(request.getCurrency())` 的判断放在一起,使用 `if` 和 `else if` 结构。
3. 对于重复使用的变量,可以考虑提取出来,例如将 `inComeReq.setIncomeCurrency(request.getCurrency())` 和 `bankCardManagerAppService.getAllOwnBankCards(clientId, null, RequestUtil.getClientIp(), inComeReq)` 中的 `inComeReq` 变量提取出来。
4. `verifyBankWithdrawFundsRepository.verifyBankWithdrawFunds(clientId, allOwnBankCards.get(0).getNumber(), deviceId)` 中的 `deviceId` 变量是否必要?如果不必要,可以将其删除。
5. 可以考虑将所有的异常抛出代码放在一起,方便查看和维护。
例如:
```
if (OverseaUtils.isOversea(clientId)) {
if ("0".equals(request.getCurrency())) {
throw new BusinessException(180001, "人民币无法使用该功能");
}
} else {
throw new BusinessException(180000, "非自研用户,无法使用基金提取至银行卡");
}
InComeReq inComeReq = new InComeReq();
inComeReq.setIncomeCurrency(request.getCurrency());
List<OwnBankCardVo> ownBankCards = bankCardManagerAppService.getAllOwnBankCards(clientId, null, RequestUtil.getClientIp(), inComeReq);
if (ownBankCards.isEmpty()) {
throw new BusinessException(180021, "根据监