corregidos varios fallos de presupuesto

This commit is contained in:
2025-10-15 19:43:00 +02:00
parent 70856edc12
commit f20dd9068a
13 changed files with 130 additions and 76 deletions

View File

@ -1,6 +1,7 @@
package com.imprimelibros.erp.externalApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.MessageSource;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
@ -20,6 +21,7 @@ import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.function.Supplier;
import java.util.Locale;
@Service
public class skApiClient {
@ -30,11 +32,13 @@ public class skApiClient {
private final AuthService authService;
private final RestTemplate restTemplate;
private final MargenPresupuestoDao margenPresupuestoDao;
private final MessageSource messageSource;
public skApiClient(AuthService authService, MargenPresupuestoDao margenPresupuestoDao) {
public skApiClient(AuthService authService, MargenPresupuestoDao margenPresupuestoDao, MessageSource messageSource) {
this.authService = authService;
this.restTemplate = new RestTemplate();
this.margenPresupuestoDao = margenPresupuestoDao;
this.messageSource = messageSource;
}
public String getPrice(Map<String, Object> requestBody, TipoEncuadernacion tipoEncuadernacion,
@ -113,7 +117,7 @@ public class skApiClient {
});
}
public Integer getMaxSolapas(Map<String, Object> requestBody) {
public Integer getMaxSolapas(Map<String, Object> requestBody, Locale locale) {
try {
String jsonResponse = performWithRetry(() -> {
String url = this.skApiUrl + "api/calcular-solapas";
@ -150,7 +154,7 @@ public class skApiClient {
JsonNode root = mapper.readTree(jsonResponse);
if (root.get("data") == null || !root.get("data").isInt()) {
throw new RuntimeException("Respuesta inesperada de calcular-solapas: " + jsonResponse);
throw new RuntimeException(messageSource.getMessage("presupuesto.errores.error-interior", new Object[]{1} , locale));
}
return root.get("data").asInt();