mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-28 14:48:50 +00:00
hecho el backed del presupuesto maquetacion
This commit is contained in:
@ -171,6 +171,12 @@ public class Presupuesto implements Cloneable{
|
|||||||
@Column(name = "alto_faja")
|
@Column(name = "alto_faja")
|
||||||
private Integer altoFaja = 0;
|
private Integer altoFaja = 0;
|
||||||
|
|
||||||
|
@Column(name = "presupuesto_maquetacion")
|
||||||
|
private Boolean presupuestoMaquetacion = false;
|
||||||
|
@Column(name = "presupuesto_maquetacion_data")
|
||||||
|
private String presupuestoMaquetacionData;
|
||||||
|
|
||||||
|
|
||||||
// Getters y Setters
|
// Getters y Setters
|
||||||
public String getAutor() {
|
public String getAutor() {
|
||||||
return autor;
|
return autor;
|
||||||
@ -512,5 +518,16 @@ public class Presupuesto implements Cloneable{
|
|||||||
this.selectedTirada = selectedTirada;
|
this.selectedTirada = selectedTirada;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean getPresupuestoMaquetacion() {
|
||||||
|
return presupuestoMaquetacion;
|
||||||
|
}
|
||||||
|
public void setPresupuestoMaquetacion(Boolean presupuestoMaquetacion) {
|
||||||
|
this.presupuestoMaquetacion = presupuestoMaquetacion;
|
||||||
|
}
|
||||||
|
public String getPresupuestoMaquetacionData() {
|
||||||
|
return presupuestoMaquetacionData;
|
||||||
|
}
|
||||||
|
public void setPresupuestoMaquetacionData(String presupuestoMaquetacionData) {
|
||||||
|
this.presupuestoMaquetacionData = presupuestoMaquetacionData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,16 +12,24 @@ import java.text.NumberFormat;
|
|||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
|
||||||
import com.imprimelibros.erp.configurationERP.VariableService;
|
import com.imprimelibros.erp.configurationERP.VariableService;
|
||||||
import com.imprimelibros.erp.presupuesto.Presupuesto.TipoCubierta;
|
import com.imprimelibros.erp.presupuesto.Presupuesto.TipoCubierta;
|
||||||
import com.imprimelibros.erp.presupuesto.classes.ImagenPresupuesto;
|
import com.imprimelibros.erp.presupuesto.classes.ImagenPresupuesto;
|
||||||
import com.imprimelibros.erp.presupuesto.classes.PresupuestadorItems;
|
import com.imprimelibros.erp.presupuesto.classes.PresupuestadorItems;
|
||||||
|
import com.imprimelibros.erp.presupuesto.maquetacion.MaquetacionPrecios;
|
||||||
|
import com.imprimelibros.erp.presupuesto.maquetacion.MaquetacionPreciosRepository;
|
||||||
|
import com.imprimelibros.erp.presupuesto.classes.PresupuestoMaquetacion;
|
||||||
|
import com.imprimelibros.erp.presupuesto.maquetacion.MaquetacionMatrices;
|
||||||
|
import com.imprimelibros.erp.presupuesto.maquetacion.MaquetacionMatricesRepository;
|
||||||
import com.imprimelibros.erp.externalApi.skApiClient;
|
import com.imprimelibros.erp.externalApi.skApiClient;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -36,6 +44,12 @@ public class PresupuestoService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
protected skApiClient skApiClient;
|
protected skApiClient skApiClient;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected MaquetacionPreciosRepository maquetacionPreciosRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected MaquetacionMatricesRepository maquetacionMatricesRepository;
|
||||||
|
|
||||||
private final PresupuestadorItems presupuestadorItems;
|
private final PresupuestadorItems presupuestadorItems;
|
||||||
|
|
||||||
public PresupuestoService(PresupuestadorItems presupuestadorItems) {
|
public PresupuestoService(PresupuestadorItems presupuestadorItems) {
|
||||||
@ -516,7 +530,7 @@ public class PresupuestoService {
|
|||||||
put("id", "ejemplar-prueba");
|
put("id", "ejemplar-prueba");
|
||||||
put("title", messageSource.getMessage("presupuesto.extras-ejemplar-prueba", null, locale));
|
put("title", messageSource.getMessage("presupuesto.extras-ejemplar-prueba", null, locale));
|
||||||
put("description", "");
|
put("description", "");
|
||||||
if(price_prototipo == 0.0) {
|
if (price_prototipo == 0.0) {
|
||||||
put("price", messageSource.getMessage("presupuesto.consultar-soporte", null, locale));
|
put("price", messageSource.getMessage("presupuesto.consultar-soporte", null, locale));
|
||||||
put("priceUnit", "");
|
put("priceUnit", "");
|
||||||
} else {
|
} else {
|
||||||
@ -578,4 +592,91 @@ public class PresupuestoService {
|
|||||||
}
|
}
|
||||||
return price_prototipo;
|
return price_prototipo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HashMap<String, Object> getPrecioMaquetacion(Presupuesto presupuesto) {
|
||||||
|
try {
|
||||||
|
if (Boolean.TRUE.equals(presupuesto.getPresupuestoMaquetacion())
|
||||||
|
&& presupuesto.getPresupuestoMaquetacionData() != null
|
||||||
|
&& !presupuesto.getPresupuestoMaquetacionData().equals("{}")) {
|
||||||
|
|
||||||
|
String jsonData = presupuesto.getPresupuestoMaquetacionData();
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
PresupuestoMaquetacion pm = objectMapper.readValue(jsonData, PresupuestoMaquetacion.class);
|
||||||
|
List<MaquetacionPrecios> lista = maquetacionPreciosRepository.findAll();
|
||||||
|
|
||||||
|
// helper para obtener un precio por clave
|
||||||
|
java.util.function.Function<String, Double> price = key -> lista.stream()
|
||||||
|
.filter(p -> key.equals(p.getKey()))
|
||||||
|
.map(MaquetacionPrecios::getValue)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(0.0);
|
||||||
|
|
||||||
|
BigDecimal precio = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
// millar_maquetacion * (numCaracteres / 1000.0)
|
||||||
|
BigDecimal millares = BigDecimal.valueOf(pm.getNumCaracteres()).divide(BigDecimal.valueOf(1000), 6,
|
||||||
|
RoundingMode.HALF_UP);
|
||||||
|
precio = precio.add(millares.multiply(BigDecimal.valueOf(price.apply("millar_maquetacion"))));
|
||||||
|
|
||||||
|
// Numero de paginas estimado
|
||||||
|
int numPaginas = 0;
|
||||||
|
Integer matricesPorPagina = maquetacionMatricesRepository.findMatrices(
|
||||||
|
MaquetacionMatrices.Formato.valueOf(pm.getFormato()),
|
||||||
|
MaquetacionMatrices.FontSize.valueOf(pm.getFontSize()));
|
||||||
|
if (matricesPorPagina != null && matricesPorPagina > 0) {
|
||||||
|
numPaginas = pm.getNumCaracteres() / matricesPorPagina;
|
||||||
|
}
|
||||||
|
// Precio por pagina estimado
|
||||||
|
BigDecimal precioRedondeado = precio.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
double precioPaginaEstimado = 0.0;
|
||||||
|
if (numPaginas > 0) {
|
||||||
|
precioPaginaEstimado = precioRedondeado
|
||||||
|
.divide(BigDecimal.valueOf(numPaginas), 2, RoundingMode.HALF_UP)
|
||||||
|
.doubleValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
// tabla, columna, foto
|
||||||
|
precio = precio
|
||||||
|
.add(BigDecimal.valueOf(pm.getNumTablas()).multiply(BigDecimal.valueOf(price.apply("tabla"))));
|
||||||
|
precio = precio.add(
|
||||||
|
BigDecimal.valueOf(pm.getNumColumnas()).multiply(BigDecimal.valueOf(price.apply("columnas"))));
|
||||||
|
precio = precio
|
||||||
|
.add(BigDecimal.valueOf(pm.getNumFotos()).multiply(BigDecimal.valueOf(price.apply("foto"))));
|
||||||
|
|
||||||
|
if (pm.isCorreccionOrtotipografica()) {
|
||||||
|
precio = precio
|
||||||
|
.add(millares.multiply(BigDecimal.valueOf(price.apply("correccion_ortotipografica"))));
|
||||||
|
}
|
||||||
|
if (pm.isTextoMecanografiado()) {
|
||||||
|
precio = precio.add(millares.multiply(BigDecimal.valueOf(price.apply("mecanoescritura_por_millar"))));
|
||||||
|
}
|
||||||
|
if (pm.isDisenioPortada()) {
|
||||||
|
precio = precio.add(BigDecimal.valueOf(price.apply("disenio_portada")));
|
||||||
|
}
|
||||||
|
if (pm.isEpub()) {
|
||||||
|
precio = precio.add(BigDecimal.valueOf(price.apply("epub")));
|
||||||
|
}
|
||||||
|
|
||||||
|
// redondeo final
|
||||||
|
precioRedondeado = precio.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
|
||||||
|
HashMap<String, Object> out = new HashMap<>();
|
||||||
|
out.put("precio", precioRedondeado.doubleValue());
|
||||||
|
out.put("numPaginasEstimadas", numPaginas);
|
||||||
|
out.put("precioPaginaEstimado", precioPaginaEstimado);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
System.out.println("Error procesando JSON de presupuesto maquetacion: " + e.getMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Error procesando presupuesto maquetacion: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap<String, Object> out = new HashMap<>();
|
||||||
|
out.put("precio", 0.0);
|
||||||
|
out.put("numPaginasEstimadas", 0);
|
||||||
|
out.put("precioPaginaEstimado", 0.0);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,78 @@
|
|||||||
|
package com.imprimelibros.erp.presupuesto.classes;
|
||||||
|
|
||||||
|
public class PresupuestoMaquetacion {
|
||||||
|
|
||||||
|
private int numCaracteres;
|
||||||
|
private String formato;
|
||||||
|
private String fontSize;
|
||||||
|
private int numTablas;
|
||||||
|
private int numColumnas;
|
||||||
|
private int numFotos;
|
||||||
|
private boolean correccionOrtotipografica;
|
||||||
|
private boolean textoMecanografiado;
|
||||||
|
private boolean disenioPortada;
|
||||||
|
private boolean epub;
|
||||||
|
|
||||||
|
public int getNumCaracteres() {
|
||||||
|
return numCaracteres;
|
||||||
|
}
|
||||||
|
public void setNumCaracteres(int numCaracteres) {
|
||||||
|
this.numCaracteres = numCaracteres;
|
||||||
|
}
|
||||||
|
public String getFormato() {
|
||||||
|
return formato;
|
||||||
|
}
|
||||||
|
public void setFormato(String formato) {
|
||||||
|
this.formato = formato;
|
||||||
|
}
|
||||||
|
public String getFontSize() {
|
||||||
|
return fontSize;
|
||||||
|
}
|
||||||
|
public void setFontSize(String fontSize) {
|
||||||
|
this.fontSize = fontSize;
|
||||||
|
}
|
||||||
|
public int getNumTablas() {
|
||||||
|
return numTablas;
|
||||||
|
}
|
||||||
|
public void setNumTablas(int numTablas) {
|
||||||
|
this.numTablas = numTablas;
|
||||||
|
}
|
||||||
|
public int getNumColumnas() {
|
||||||
|
return numColumnas;
|
||||||
|
}
|
||||||
|
public void setNumColumnas(int numColumnas) {
|
||||||
|
this.numColumnas = numColumnas;
|
||||||
|
}
|
||||||
|
public int getNumFotos() {
|
||||||
|
return numFotos;
|
||||||
|
}
|
||||||
|
public void setNumFotos(int numFotos) {
|
||||||
|
this.numFotos = numFotos;
|
||||||
|
}
|
||||||
|
public boolean isCorreccionOrtotipografica() {
|
||||||
|
return correccionOrtotipografica;
|
||||||
|
}
|
||||||
|
public void setCorreccionOrtotipografica(boolean correccionOrtotipografica) {
|
||||||
|
this.correccionOrtotipografica = correccionOrtotipografica;
|
||||||
|
}
|
||||||
|
public boolean isTextoMecanografiado() {
|
||||||
|
return textoMecanografiado;
|
||||||
|
}
|
||||||
|
public void setTextoMecanografiado(boolean textoMecanografiado) {
|
||||||
|
this.textoMecanografiado = textoMecanografiado;
|
||||||
|
}
|
||||||
|
public boolean isDisenioPortada() {
|
||||||
|
return disenioPortada;
|
||||||
|
}
|
||||||
|
public void setDisenioPortada(boolean disenioPortada) {
|
||||||
|
this.disenioPortada = disenioPortada;
|
||||||
|
}
|
||||||
|
public boolean isEpub() {
|
||||||
|
return epub;
|
||||||
|
}
|
||||||
|
public void setEpub(boolean epub) {
|
||||||
|
this.epub = epub;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
package com.imprimelibros.erp.presupuesto.maquetacion;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "maquetacion_matrices_formato")
|
||||||
|
public class MaquetacionMatrices {
|
||||||
|
|
||||||
|
public enum Formato{
|
||||||
|
A5, _17x24_, A4
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum FontSize{
|
||||||
|
small, medium, big
|
||||||
|
}
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private Formato formato;
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private FontSize tamanio_letra;
|
||||||
|
|
||||||
|
private int matrices_pagina;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Formato getFormato() {
|
||||||
|
return formato;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FontSize getTamanioLetra() {
|
||||||
|
return tamanio_letra;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMatricesPagina() {
|
||||||
|
return matrices_pagina;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package com.imprimelibros.erp.presupuesto.maquetacion;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface MaquetacionMatricesRepository extends JpaRepository<MaquetacionMatrices, Long> {
|
||||||
|
|
||||||
|
@Query("SELECT m.matrices_pagina FROM MaquetacionMatrices m WHERE m.formato = :formato AND m.tamanio_letra = :tamanioLetra")
|
||||||
|
Integer findMatrices(@Param("formato") MaquetacionMatrices.Formato formato,
|
||||||
|
@Param("tamanioLetra") MaquetacionMatrices.FontSize tamanioLetra);
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package com.imprimelibros.erp.presupuesto.maquetacion;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "maquetacion_precios")
|
||||||
|
public class MaquetacionPrecios {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "keyword")
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
@Column(name = "value")
|
||||||
|
private Double value;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package com.imprimelibros.erp.presupuesto.maquetacion;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface MaquetacionPreciosRepository extends JpaRepository<MaquetacionPrecios, Long> {
|
||||||
|
|
||||||
|
MaquetacionPrecios findByKey(String key);
|
||||||
|
}
|
||||||
@ -4,13 +4,14 @@ logging.level.org.springframework.security=DEBUG
|
|||||||
logging.level.root=WARN
|
logging.level.root=WARN
|
||||||
logging.level.org.springframework=ERROR
|
logging.level.org.springframework=ERROR
|
||||||
|
|
||||||
spring.datasource.url=jdbc:mysql://127.0.0.1:3309/imprimelibros?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Europe/Madrid&characterEncoding=utf8
|
spring.datasource.url=jdbc:mysql://localhost:3309/imprimelibros
|
||||||
|
#spring.datasource.url=jdbc:mysql://127.0.0.1:3309/imprimelibros?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Europe/Madrid&characterEncoding=utf8
|
||||||
spring.datasource.username=imprimelibros_user
|
spring.datasource.username=imprimelibros_user
|
||||||
spring.datasource.password=om91irrDctd
|
spring.datasource.password=om91irrDctd
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
|
|
||||||
#safekat.api.url=http://localhost:8000/
|
safekat.api.url=http://localhost:8000/
|
||||||
safekat.api.url=https://erp-dev.safekat.es/
|
#safekat.api.url=https://erp-dev.safekat.es/
|
||||||
safekat.api.email=imnavajas@coit.es
|
safekat.api.email=imnavajas@coit.es
|
||||||
safekat.api.password=Safekat2024
|
safekat.api.password=Safekat2024
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,49 @@
|
|||||||
|
package com.imprimelibros.erp;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import com.imprimelibros.erp.presupuesto.PresupuestoService;
|
||||||
|
import com.imprimelibros.erp.presupuesto.Presupuesto;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
class presupuestoMaquetacionTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected PresupuestoService presupuestoService;
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(presupuestoMaquetacionTest.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testCalculoMaquetacion() {
|
||||||
|
String resultado = this.test();
|
||||||
|
|
||||||
|
System.out.println("📦 Resultado:");
|
||||||
|
System.out.println(resultado);
|
||||||
|
log.info("📦 Resultado: {}", resultado);
|
||||||
|
|
||||||
|
assertNotNull(resultado, "El resultado no debe ser null");
|
||||||
|
assertTrue(resultado.trim().startsWith("{"), "El resultado debe comenzar con { (JSON)");
|
||||||
|
assertTrue(resultado.trim().endsWith("}"), "El resultado debe terminar con } (JSON)");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String test() {
|
||||||
|
|
||||||
|
Presupuesto presupuesto = new Presupuesto();
|
||||||
|
presupuesto.setPresupuestoMaquetacion(true);
|
||||||
|
presupuesto.setPresupuestoMaquetacionData(
|
||||||
|
"{\"numCaracteres\":200000,\"formato\":\"A5\",\"fontSize\":\"medium\",\"numTablas\":5,\"numColumnas\":1,\"numFotos\":10,\"correccionOrtotipografica\":true,\"textoMecanografiado\":false,\"disenioPortada\":true,\"epub\":true}");
|
||||||
|
|
||||||
|
Map<String, Object> resultado = presupuestoService.getPrecioMaquetacion(presupuesto);
|
||||||
|
return resultado.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user