trabajando en obtener lomos

This commit is contained in:
2026-02-25 15:08:30 +01:00
parent 355c5b6019
commit 5286f12d76
5 changed files with 147 additions and 59 deletions

View File

@ -128,6 +128,68 @@ public class skApiClient {
}); });
} }
public Map<String, Object> getLomos(Map<String, Object> requestBody, Locale locale) {
try {
String jsonResponse = performWithRetry(() -> {
String url = this.skApiUrl + "api/get-lomos";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setBearerAuth(authService.getToken()); // token actualizado
Map<String, Object> data = new HashMap<>();
data.put("clienteId", requestBody.get("clienteId"));
data.put("tamanio", requestBody.get("tamanio"));
data.put("tirada", requestBody.get("tirada"));
data.put("paginas", requestBody.get("paginas"));
data.put("paginasColor", requestBody.get("paginasColor"));
data.put("papelInteriorDiferente", 0);
data.put("paginasCuadernillo", requestBody.get("paginasCuadernillo"));
data.put("tipo", requestBody.get("tipo"));
data.put("isColor", requestBody.get("isColor"));
data.put("isHq", requestBody.get("isHq"));
data.put("interior", requestBody.get("interior"));
data.put("cubierta", requestBody.get("cubierta"));
HttpEntity<Map<String, Object>> entity = new HttpEntity<>(data, headers);
ResponseEntity<String> response = restTemplate.exchange(
url,
HttpMethod.POST,
entity,
String.class);
return response.getBody();
});
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(jsonResponse);
if (root.get("lomoInterior") == null || !root.get("lomoInterior").isInt()) {
throw new RuntimeException(
messageSource.getMessage("presupuesto.errores.error-interior", new Object[] { 1 }, locale));
}
Double lomoInterior = root.get("lomoInterior").asDouble();
Double lomoCubierta = root.get("lomoCubierta").asDouble();
return Map.of(
"lomoInterior", lomoInterior,
"lomoCubierta", lomoCubierta);
} catch (JsonProcessingException e) {
// Fallback al 80% del ancho
Map<String, Object> tamanio = new ObjectMapper().convertValue(
requestBody.get("tamanio"),
new TypeReference<Map<String, Object>>() {
});
return Map.of(
"lomoInterior", 0.0,
"lomoCubierta", 0.0);
}
}
public Map<String, Object> savePresupuesto(Map<String, Object> requestBody) { public Map<String, Object> savePresupuesto(Map<String, Object> requestBody) {
return performWithRetryMap(() -> { return performWithRetryMap(() -> {
String url = this.skApiUrl + "api/guardar"; String url = this.skApiUrl + "api/guardar";

View File

@ -908,6 +908,14 @@ public class PresupuestoController {
return ResponseEntity.badRequest().body(errores); return ResponseEntity.badRequest().body(errores);
} }
try{
Map<String, Object> lomos = presupuestoService.obtenerLomos(presupuesto);
presupuesto.setLomo(Double.valueOf(lomos.get("lomoInterior").toString()));
presupuesto.setLomoCubierta(Double.valueOf(lomos.get("lomoCubierta").toString()));
}catch(Exception ex){
log.error("Error al obtener lomos desde SK API", ex);
}
try { try {
Map<String, Object> saveResult = presupuestoService.guardarPresupuesto( Map<String, Object> saveResult = presupuestoService.guardarPresupuesto(

View File

@ -1297,6 +1297,20 @@ public class PresupuestoService {
} }
public Map<String, Object> obtenerLomos(Presupuesto presupuesto) {
try {
Long papelInteriorId = presupuesto.getPapelInteriorId() != null ? presupuesto.getPapelInteriorId() : 0L;
Long papelCubiertaId = presupuesto.getPapelCubiertaId() != null ? presupuesto.getPapelCubiertaId() : 0L;
int paginas = presupuesto.getPaginasNegro() + presupuesto.getPaginasColor();
Map<String, Object> response = apiClient.getLomos(papelInteriorId, papelCubiertaId, paginas);
return response.get("data") != null ? (Map<String, Object>) response.get("data") : Map.of();
} catch (Exception e) {
System.out.println("Error obteniendo lomos: " + e.getMessage());
return Map.of();
}
}
/** /**
* PRIVADO (futuro botón "Guardar"): persiste el presupuesto como borrador. * PRIVADO (futuro botón "Guardar"): persiste el presupuesto como borrador.
*/ */

View File

@ -57,4 +57,3 @@
file: db/changelog/changesets/0028-add-lomo-cubierta-to-presupuesto.yml file: db/changelog/changesets/0028-add-lomo-cubierta-to-presupuesto.yml
- include: - include:
file: db/changelog/changesets/0029-update-estados-pedidos-lineas.yml file: db/changelog/changesets/0029-update-estados-pedidos-lineas.yml

View File

@ -1690,6 +1690,11 @@ export default class PresupuestoWizard {
this.divTiradas.append(item.renderCol(this.divTiradas)); this.divTiradas.append(item.renderCol(this.divTiradas));
} }
if(data.lomo_cubierta) {
this.formData.lomoCubierta = data.lomo_cubierta;
this.#cacheFormData();
}
if (this.divTiradas.find('.tirada-card input[type="radio"]:checked').length === 0) { if (this.divTiradas.find('.tirada-card input[type="radio"]:checked').length === 0) {
this.divTiradas.find('.tirada-card input[type="radio"]').first().prop('checked', true).trigger('change'); this.divTiradas.find('.tirada-card input[type="radio"]').first().prop('checked', true).trigger('change');
this.formData.selectedTirada = this.divTiradas.find('.tirada-card input[type="radio"]').first().data('unidades') || data.tiradas[0]; this.formData.selectedTirada = this.divTiradas.find('.tirada-card input[type="radio"]').first().data('unidades') || data.tiradas[0];