优化这段代码 // 判断该用户是否是自研用户 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 15:46:48 浏览: 175
这段代码是用来判断用户是否可以从基金转到银行卡的。
首先,它会判断用户是否是自研用户,如果不是,就会抛出一个业务异常,提示用户“非自研用户,无法使用基金提取至银行卡”。
然后,它会判断币种信息是否为人民币,如果是,也会抛出一个业务异常,提示用户“人民币无法使用该功能”。
接下来,它会获取用户所有的银行卡信息,并判断第一张银行卡是否满足出金要求,如果不满足,也会抛出一个业务异常,提示用户“根据监管要求,请使用单笔入金达到10000港币(或等值其他货币)的银行卡进行出金操作”。
最后,它会判断第一张银行卡是否已经绑定了交易账户,如果已经绑定,就会获取该交易账户的出金限制信息,否则,就会直接返回一个空的出金限制信息。
相关问题
优化一下这段代码 // 判断该用户是否是自研用户 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;
这段代码的作用是用来判断是否允许从基金提取至银行卡。
优化建议:
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, "根据监
优化一下代码并给出详细代码 // 判断该用户是否是自研用户 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;
下面是优化后的代码:
```
// 判断该用户是否是自研用户
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.isEmpty()) {
throw new BusinessException(180021, "根据监管要求,请使用单笔入金达到10000港币(或等值其他货币)的银行卡进行出金操作");
}
OwnBankCardVo bankCard = allOwnBankCards.get(0);
if (!bankCard.isBoundTrans() || !verifyBankWithdrawFundsRepository.verifyBankWithdrawFunds(clientId, bankCard.getNumber(), deviceId)) {
throw new BusinessException(180021, "根据监管要求,请使用单笔入金达到10000港币(或等值其他货币)的银行卡进行出金操作");
}
```
我对代码进行了一些细微的修改,并将两个判断条件合并到了一起。
如果有其他问题或疑问,欢迎继续提问。
阅读全文