Browse Source

Feature con reporte de mantenimiento

master
mramirezg 3 weeks ago
parent
commit
3c3a5554d2
7 changed files with 100 additions and 4 deletions
  1. +18
    -0
      pom.xml
  2. +41
    -0
      src/main/java/mx/gob/jumapacelaya/services/ReportService.java
  3. +39
    -2
      src/main/java/mx/gob/jumapacelaya/ui/DetallesMantView.java
  4. +2
    -2
      src/main/java/mx/gob/jumapacelaya/ui/MantenimientoView.java
  5. BIN
      src/main/resources/META-INF/resources/images/FirmaGerenteTI.png
  6. BIN
      src/main/resources/META-INF/resources/images/firmaGcia.png
  7. BIN
      src/main/resources/META-INF/resources/reportes/mantenimientoReport.jasper

+ 18
- 0
pom.xml View File

@ -159,6 +159,24 @@
<artifactId>commons-io</artifactId>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>7.0.3</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-pdf</artifactId>
<version>7.0.3</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7.js10</version>
</dependency>
</dependencies>
<build>


+ 41
- 0
src/main/java/mx/gob/jumapacelaya/services/ReportService.java View File

@ -0,0 +1,41 @@
package mx.gob.jumapacelaya.services;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Map;
@Service
public class ReportService {
@Value("${db.url}")
private String dbUrl;
@Value("${db.user}")
private String dbUser;
@Value("${db.pass}")
private String dbPass;
public byte[] generarReporte(String nombreReporte, Map<String, Object> parametros) throws Exception {
InputStream logo = getClass().getResourceAsStream("/META-INF/resources/images/LOGO_24'27.png");
parametros.put("logo", logo);
InputStream firmaGcia = getClass().getResourceAsStream("/META-INF/resources/images/FirmaGerenteTI.png");
parametros.put("firmaGcia", firmaGcia);
InputStream jasperStream = getClass().getResourceAsStream("/META-INF/resources/reportes/" + nombreReporte + ".jasper");
if (jasperStream == null) {
throw new IllegalArgumentException("No se encontro el archivo del reporte: " + nombreReporte);
}
try (Connection conn = DriverManager.getConnection(dbUrl, dbUser, dbPass)) {
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperStream, parametros, conn);
return JasperExportManager.exportReportToPdf(jasperPrint);
}
}
}

+ 39
- 2
src/main/java/mx/gob/jumapacelaya/ui/DetallesMantView.java View File

@ -1,9 +1,16 @@
package mx.gob.jumapacelaya.ui;
import java.io.ByteArrayInputStream;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.vaadin.flow.component.html.Anchor;
import com.vaadin.flow.server.StreamResource;
import mx.gob.jumapacelaya.services.ReportService;
import org.springframework.security.core.Authentication;
import org.springframework.cglib.core.Local;
import org.springframework.security.core.context.SecurityContextHolder;
@ -90,10 +97,12 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser
private final SecurityService securityService;
private final DatabaseService service;
private final ReportService reportService;
public DetallesMantView(SecurityService securityService, DatabaseService service) {
public DetallesMantView(SecurityService securityService, DatabaseService service, ReportService reportService) {
this.service = service;
this.securityService = securityService;
this.reportService = reportService;
setPadding(true);
mainLayout = new VerticalLayout();
@ -268,6 +277,34 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser
});
btnImprimirRepo.addClickListener(e -> {
try {
// Prepara los parámetros para el reporte
Map<String, Object> parametros = new HashMap<>();
parametros.put("PLAN_ID", planAnualIdActual);
// Genera el PDF
byte[] pdf = reportService.generarReporte("mantenimientoReport", parametros);
// Se crea el recurso para descarga
StreamResource resource = new StreamResource("reporte.pdf", () -> new ByteArrayInputStream(pdf));
Anchor downloadLink = new Anchor(resource, "Descargar Reporte");
downloadLink.getElement().setAttribute("download", true);
downloadLink.setId("descargar-reporte-link");
add(downloadLink);
getUI().ifPresent(ui ->
ui.getPage().executeJs("document.getElementById('descargar-reporte-link').click();")
);
} catch (Exception ex) {
Notification.show("Error al generar el reporte: " + ex.getMessage(), 4000, Notification.Position.MIDDLE)
.addThemeVariants(NotificationVariant.LUMO_ERROR);
ex.printStackTrace();
}
});
// Se dispara el dialogo de confirmacion
btnGuardar.addClickListener(e -> confirmDialog.open());
@ -554,7 +591,7 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser
smtSignLayout.replace(smtSignPad, firmaSmtImg);
}
Image firmaGcia = new Image("images/firmaGcia.png", "Firma de la Gcia. de T.I");
Image firmaGcia = new Image("images/FirmaGerenteTI.png", "Firma de la Gcia. de T.I");
firmaGcia.setHeight("200px");
firmaGcia.setWidthFull();


+ 2
- 2
src/main/java/mx/gob/jumapacelaya/ui/MantenimientoView.java View File

@ -460,10 +460,10 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
smtSignLayout.add(smtSignPad, smtSignSpan, tituloSMT);
VerticalLayout gcialSignLayout = new VerticalLayout();
Image firmaGcia = new Image("images/firmaGcia.png", "Firma Gerente de Sistemas");
Image firmaGcia = new Image("images/FirmaGerenteTI.png", "Firma Gerente de Sistemas");
firmaGcia.setHeight("200px");
firmaGcia.setWidthFull();
Span gciatiSignSpan = new Span("Lic. Juan Pablo Torres Alvárez");
Span gciatiSignSpan = new Span("Ing. Javier Patiño Martinez");
Span tituloGerente = new Span("Gerente de T.I");
gcialSignLayout.setSizeFull();
gcialSignLayout.setSpacing(false);


BIN
src/main/resources/META-INF/resources/images/FirmaGerenteTI.png View File

Before After
Width: 400  |  Height: 200  |  Size: 14 KiB

BIN
src/main/resources/META-INF/resources/images/firmaGcia.png View File

Before After
Width: 451  |  Height: 301  |  Size: 7.0 KiB

BIN
src/main/resources/META-INF/resources/reportes/mantenimientoReport.jasper View File


Loading…
Cancel
Save