mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 08:58:48 +00:00
terminado
This commit is contained in:
@ -22,15 +22,20 @@ public class InternationalizationConfig implements WebMvcConfigurer {
|
||||
@Bean
|
||||
public LocaleResolver localeResolver() {
|
||||
SessionLocaleResolver slr = new SessionLocaleResolver();
|
||||
slr.setDefaultLocale(Locale.of("es"));
|
||||
slr.setDefaultLocale(Locale.forLanguageTag("es")); // idioma por defecto
|
||||
return slr;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LocaleChangeInterceptor localeChangeInterceptor() {
|
||||
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
|
||||
lci.setParamName("lang"); // parámetro ?lang=en, ?lang=es
|
||||
return lci;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
|
||||
interceptor.setParamName("lang");
|
||||
registry.addInterceptor(interceptor);
|
||||
registry.addInterceptor(localeChangeInterceptor());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ -40,22 +45,22 @@ public class InternationalizationConfig implements WebMvcConfigurer {
|
||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
Resource[] resources = resolver.getResources("classpath*:i18n/*.properties");
|
||||
|
||||
// Extraer los nombres base sin extensión ni sufijos (_en, _es, etc.)
|
||||
// Extraer nombres base sin sufijos de idioma
|
||||
Set<String> basenames = Arrays.stream(resources)
|
||||
.map(res -> {
|
||||
try {
|
||||
String uri = Objects.requireNonNull(res.getURI()).toString();
|
||||
// Ej: file:/.../i18n/login_en.properties
|
||||
String path = uri.substring(uri.indexOf("/i18n/") + 1); // i18n/login_en.properties
|
||||
String base = path.replaceAll("_[a-z]{2}\\.properties$", "") // login.properties
|
||||
.replaceAll("\\.properties$", "");
|
||||
return "classpath:" + base;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
.map(res -> {
|
||||
try {
|
||||
String uri = Objects.requireNonNull(res.getURI()).toString();
|
||||
// Ejemplo: file:/.../i18n/login_en.properties
|
||||
String path = uri.substring(uri.indexOf("/i18n/") + 1); // i18n/login_en.properties
|
||||
String base = path.replaceAll("_[a-z]{2}\\.properties$", "") // login.properties
|
||||
.replaceAll("\\.properties$", "");
|
||||
return "classpath:" + base;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
source.setBasenames(basenames.toArray(new String[0]));
|
||||
source.setDefaultEncoding("UTF-8");
|
||||
|
||||
@ -16,6 +16,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
@ -27,6 +28,8 @@ import com.imprimelibros.erp.presupuesto.classes.ImagenPresupuesto;
|
||||
import com.imprimelibros.erp.presupuesto.classes.PresupuestoMaquetacion;
|
||||
import com.imprimelibros.erp.presupuesto.validation.PresupuestoValidationGroups;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/presupuesto")
|
||||
public class PresupuestoController {
|
||||
@ -93,7 +96,7 @@ public class PresupuestoController {
|
||||
@PostMapping("/public/validar/cubierta")
|
||||
public ResponseEntity<?> validarCubierta(
|
||||
@Validated(PresupuestoValidationGroups.Cubierta.class) Presupuesto presupuesto,
|
||||
BindingResult result,
|
||||
BindingResult result,
|
||||
@RequestParam(name = "calcular", defaultValue = "true") boolean calcular,
|
||||
Locale locale) {
|
||||
|
||||
@ -150,6 +153,9 @@ public class PresupuestoController {
|
||||
Map<String, Object> resultado = new HashMap<>();
|
||||
// servicios extra
|
||||
resultado.putAll(presupuestoService.obtenerServiciosExtras(presupuesto, locale, apiClient));
|
||||
Map<String, String> language = new HashMap<>();
|
||||
language.put("calcular", messageSource.getMessage("presupuesto.calcular", null, locale));
|
||||
resultado.put("language", language);
|
||||
|
||||
return ResponseEntity.ok(resultado);
|
||||
}
|
||||
@ -307,23 +313,35 @@ public class PresupuestoController {
|
||||
|
||||
}
|
||||
|
||||
@GetMapping(value="/public/maquetacion/form", produces = MediaType.TEXT_HTML_VALUE)
|
||||
@GetMapping(value = "/public/maquetacion/form", produces = MediaType.TEXT_HTML_VALUE)
|
||||
public String getMaquetacionForm(Model model) {
|
||||
model.addAttribute("presupuestoMaquetacion", new PresupuestoMaquetacion());
|
||||
return "imprimelibros/presupuestos/presupuesto-maquetacion-form :: maquetacionForm";
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/public/maquetacion")
|
||||
public ResponseEntity<?> getPresupuestoMaquetacion(
|
||||
PresupuestoMaquetacion presupuestoMaquetacion,
|
||||
Model model, Locale locale) {
|
||||
Map<String, Object> resultado = presupuestoService.getPrecioMaquetacion(presupuestoMaquetacion);
|
||||
if((Double)resultado.get("precio") == 0.0 && (Integer)resultado.get("numPaginasEstimadas") == 0
|
||||
&& (Double)resultado.get("precioPaginaEstimado") == 0.0){
|
||||
return ResponseEntity.badRequest().body(messageSource.getMessage("presupuesto.errores.presupuesto-maquetacion", null, locale));
|
||||
}
|
||||
return ResponseEntity.ok(resultado);
|
||||
@Valid @ModelAttribute PresupuestoMaquetacion presupuestoMaquetacion,
|
||||
BindingResult result,
|
||||
Locale locale) {
|
||||
|
||||
if (result.hasErrors()) {
|
||||
// Construimos un mapa field -> mensaje para tu AJAX
|
||||
Map<String, String> errores = result.getFieldErrors().stream()
|
||||
.collect(java.util.stream.Collectors.toMap(
|
||||
fe -> fe.getField(),
|
||||
fe -> fe.getDefaultMessage(),
|
||||
(a, b) -> a));
|
||||
return ResponseEntity.badRequest().body(errores);
|
||||
}
|
||||
|
||||
Map<String, Object> resultado = presupuestoService.getPrecioMaquetacion(presupuestoMaquetacion, locale);
|
||||
if ((Double) resultado.get("precio") == 0.0 && (Integer) resultado.get("numPaginasEstimadas") == 0
|
||||
&& (Double) resultado.get("precioPaginaEstimado") == 0.0) {
|
||||
return ResponseEntity.badRequest()
|
||||
.body(messageSource.getMessage("presupuesto.errores.presupuesto-maquetacion", null, locale));
|
||||
}
|
||||
return ResponseEntity.ok(resultado);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -593,7 +593,7 @@ public class PresupuestoService {
|
||||
return price_prototipo;
|
||||
}
|
||||
|
||||
public HashMap<String, Object> getPrecioMaquetacion(PresupuestoMaquetacion presupuestoMaquetacion) {
|
||||
public HashMap<String, Object> getPrecioMaquetacion(PresupuestoMaquetacion presupuestoMaquetacion, Locale locale) {
|
||||
try {
|
||||
List<MaquetacionPrecios> lista = maquetacionPreciosRepository.findAll();
|
||||
|
||||
@ -657,6 +657,11 @@ public class PresupuestoService {
|
||||
out.put("precio", precioRedondeado.doubleValue());
|
||||
out.put("numPaginasEstimadas", numPaginas);
|
||||
out.put("precioPaginaEstimado", precioPaginaEstimado);
|
||||
HashMap<String, String> language = new HashMap<>();
|
||||
language.put("add_to_presupuesto", messageSource.getMessage("presupuesto.add-to-presupuesto", null, locale));
|
||||
language.put("cancel", messageSource.getMessage("app.cancelar", null, locale));
|
||||
language.put("presupuesto_maquetacion", messageSource.getMessage("presupuesto.maquetacion", null, locale));
|
||||
out.put("language", language);
|
||||
return out;
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -1,25 +1,36 @@
|
||||
package com.imprimelibros.erp.presupuesto.classes;
|
||||
|
||||
import com.imprimelibros.erp.presupuesto.maquetacion.MaquetacionMatrices.FontSize;
|
||||
import com.imprimelibros.erp.presupuesto.maquetacion.MaquetacionMatrices.Formato;;
|
||||
import com.imprimelibros.erp.presupuesto.maquetacion.MaquetacionMatrices.Formato;
|
||||
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
public class PresupuestoMaquetacion {
|
||||
|
||||
private int numCaracteres = 200000;
|
||||
@NotNull(message = "{validation.required}")
|
||||
@Min(value = 1, message = "{validation.min}")
|
||||
private Integer numCaracteres = 200000;
|
||||
private Formato formato = Formato.A5;
|
||||
private FontSize cuerpoTexto = FontSize.medium;
|
||||
private int numTablas = 0;
|
||||
private int numColumnas = 1;
|
||||
private int numFotos = 0;
|
||||
@Min(value = 0, message = "{validation.min}")
|
||||
@NotNull(message = "{validation.required}")
|
||||
private Integer numTablas = 0;
|
||||
@Min(value = 1, message = "{validation.min}")
|
||||
@NotNull(message = "{validation.required}")
|
||||
private Integer numColumnas = 1;
|
||||
@Min(value = 0, message = "{validation.min}")
|
||||
@NotNull(message = "{validation.required}")
|
||||
private Integer numFotos = 0;
|
||||
private boolean correccionOrtotipografica = false;
|
||||
private boolean textoMecanografiado = false;
|
||||
private boolean disenioPortada = false;
|
||||
private boolean epub = false;
|
||||
|
||||
public int getNumCaracteres() {
|
||||
public Integer getNumCaracteres() {
|
||||
return numCaracteres;
|
||||
}
|
||||
public void setNumCaracteres(int numCaracteres) {
|
||||
public void setNumCaracteres(Integer numCaracteres) {
|
||||
this.numCaracteres = numCaracteres;
|
||||
}
|
||||
public Formato getFormato() {
|
||||
@ -34,22 +45,22 @@ public class PresupuestoMaquetacion {
|
||||
public void setCuerpoTexto(FontSize cuerpoTexto) {
|
||||
this.cuerpoTexto = cuerpoTexto;
|
||||
}
|
||||
public int getNumTablas() {
|
||||
public Integer getNumTablas() {
|
||||
return numTablas;
|
||||
}
|
||||
public void setNumTablas(int numTablas) {
|
||||
public void setNumTablas(Integer numTablas) {
|
||||
this.numTablas = numTablas;
|
||||
}
|
||||
public int getNumColumnas() {
|
||||
public Integer getNumColumnas() {
|
||||
return numColumnas;
|
||||
}
|
||||
public void setNumColumnas(int numColumnas) {
|
||||
public void setNumColumnas(Integer numColumnas) {
|
||||
this.numColumnas = numColumnas;
|
||||
}
|
||||
public int getNumFotos() {
|
||||
public Integer getNumFotos() {
|
||||
return numFotos;
|
||||
}
|
||||
public void setNumFotos(int numFotos) {
|
||||
public void setNumFotos(Integer numFotos) {
|
||||
this.numFotos = numFotos;
|
||||
}
|
||||
public boolean isCorreccionOrtotipografica() {
|
||||
|
||||
Reference in New Issue
Block a user