我有一个方法,用post-to-some-url调用两个api,从第一个响应得到accountbalanceresponse对象的几乎所有值,然后我需要用第一个api的响应调用第二个api,这两个调用都返回mono对象,然后,当我使用“mapfuture.get()”来填充响应对象的最后一个值,但是api调用什么都不做。。。在日志中我看到“o.s.w.r.f.client.exchangefunctions:[20852e1]httpposthttps://apiurlicall“但是程序就这样一直没有结果。有什么线索吗?谢谢你。
private Mono<AccountBalanceResponse> getDebts(UserInfo userInfo, String msisdn, String
codService, String documentType,
String documentNumber) {
AccountBalanceResponse accountBalance = new AccountBalanceResponse();
HashMap<String, Object> listPositiveAmount = new LinkedHashMap<>();
LOGGER.info("UserInfo: {}", userInfo);
LOGGER.info("msisdn: {}", msisdn);
LOGGER.info("codService: {}", codService);
LOGGER.info("documentType: {}", documentType);
LOGGER.info("documentNumber: {}", documentNumber);
String accountCode = userInfo.getAccountCode();
if (StringUtils.equals(accountCode, null)) {
accountBalance.setErrorCode(userInfo.getErrorCode());
accountBalance.setErrorDescription(userInfo.getErrorDescription());
accountBalance.setStatusResponse(500);
return Mono.just(accountBalance);
}
LOGGER.info("Account code: {}", accountCode);
Mono<JsonNode> objectNode = accountBalanceRestClient.getAccountBalance(accountCode, documentNumber);
return objectNode.map(jsonNodeResponse->{
AccountBalanceResponse accountBalanceFuture = new AccountBalanceResponse();
LOGGER.info("<Response Account Balance>: {}", objectNode);
Double amountRA;
String unitsRA;
Integer amountPA = 0;
String unitsPA = null;
Mono<String> webViewPagos = null;
JsonNode remainedAmount = jsonNodeResponse.get(0).get("remainedAmount");
JsonNode positiveAmount = jsonNodeResponse.get(0).get("positiveAmount");
String issueDate = StringUtils
.substring(jsonNodeResponse.get(0).get("validFor").get("startDateTime").asText(), 0,
10);
String issueDateParsed = StringUtils.replaceEach(issueDate, new String[] { "-", "-" },
new String[] { "", "" });
LOGGER.info("Issue Date: {}", issueDate);
LOGGER.info("Issue Date Parsed: {}", issueDateParsed);
String dueDate = calculateBillDatesUtil.calculateDueDate(issueDateParsed, "C");
Integer statusNew = Utils.compareDateWithToday(dueDate, DATE_FORMAT);
String statusDebt = DeudaUtil.getEstadoDeuda(statusNew.intValue());
String codeStatusDebt = DeudaUtil.getCodigoEstadoDeuda(statusNew.intValue());
amountRA = remainedAmount.get(AMOUNT).asDouble();
unitsRA = remainedAmount.get(UNITS).asText();
int receiptsTotal = 1;
int receiptsToPay = 0;
if (amountRA <= Double.valueOf(0.0)) {
statusDebt = "Sin deuda";
codeStatusDebt = "S";
} else {
webViewPagos = webViewPagosService.getWebViewPagosProd(msisdn, codService, documentType,
documentNumber);
receiptsToPay++;
}
if (positiveAmount != null && positiveAmount.has(AMOUNT)) {
amountPA = positiveAmount.get(AMOUNT).asInt();
unitsPA = positiveAmount.get(UNITS).asText();
}
ObjectMapper mapper = new ObjectMapper();
listPositiveAmount.put(AMOUNT, amountPA);
listPositiveAmount.put(UNITS, unitsPA == null ? unitsRA : unitsPA);
accountBalanceFuture.setSumTaxTotal(String.format("%.2f", amountRA));
accountBalanceFuture.setInvoiceCurrency(unitsRA);
accountBalanceFuture.setPositiveAmount(listPositiveAmount);
accountBalanceFuture.setInvoiceDate(dueDate == null ? "null" : dueDate);
accountBalanceFuture.setCodeStatusDebt(codeStatusDebt);
accountBalanceFuture.setStatusDebt(statusDebt);
accountBalanceFuture.setStatusResponse(200);
accountBalanceFuture.setInvoiceList(mapper.createArrayNode());
accountBalanceFuture.setReceiptsTotal(receiptsTotal);
accountBalanceFuture.setReceiptsToPay(receiptsToPay);
accountBalanceFuture.setCodPayment(msisdn);
CompletableFuture<AccountBalanceResponse> mapFuture = webViewPagos.toFuture()
.thenApplyAsync(urlResponse -> {
AccountBalanceResponse accountBFuture = new AccountBalanceResponse();
accountBFuture.setWebViewPagosURL(urlResponse);
return accountBFuture;
});
try {
accountBalanceFuture.setWebViewPagosURL(mapFuture.get().getWebViewPagosURL());
} catch (InterruptedException | ExecutionException e) {
LOGGER.error(e.toString());
Thread.currentThread().interrupt();
}
return accountBalanceFuture;
});
}
1条答案
按热度按时间bxfogqkk1#
我必须重构所有我这样做的方法才能正常工作: