@ -33,11 +33,10 @@ import mx.gob.jumapacelaya.models.TiposHardware;
import mx.gob.jumapacelaya.models.TiposMantenimiento ;
import mx.gob.jumapacelaya.models.Usuario ;
import mx.gob.jumapacelaya.services.DatabaseService ;
import mx.gob.jumapacelaya.services.UserService ;
import java.time.LocalDate ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.List ;
import java.util.* ;
@PermitAll
@ -52,21 +51,26 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
private final VerticalLayout etiquetaLayout ;
private final HorizontalLayout firmasLayout ;
private final DatePicker fecha ;
private final TextField txtPlananualID ;
private final ComboBox < TiposMantenimiento > tipoMantt ;
private final ComboBox < DepartamentosModel > area ;
private final ComboBox < Usuario > usuario ;
private final TextField nombreEquipo ;
private final UserService userService ;
private RadioButtonGroup < String > formaGroup ;
private CheckboxGroup < String > actualizaciones ;
private final HorizontalLayout botonesLayout ;
private TextArea txtCuales ;
private RadioButtonGroup < String > masActualizacionesGroup ;
private SignaturePad userSignPad ;
private SignaturePad smtSignPad ;
private SignaturePad gciatiSignPad ;
Span userSignSpan = new Span ( "Nombre Usuario" ) ;
public MantenimientoView ( ) {
public MantenimientoView ( UserService userService ) {
this . databaseService = new DatabaseService ( ) ;
this . controlsLayout = new VerticalLayout ( ) ;
this . actualizacionesLayout = new VerticalLayout ( ) ;
@ -90,6 +94,11 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
/ / fecha . setPlaceholder ( "Fecha" ) ;
/ / Campo de texto para el ID de MTTOPROGRAMADO
this . txtPlananualID = new TextField ( "Plan Anual ID" ) ;
txtPlananualID . setReadOnly ( true ) ;
txtPlananualID . addClassName ( "mantenimiento-text-field" ) ;
/ / ComboBox Tipo de Mantenimiento
this . tipoMantt = new ComboBox < > ( "Tipo de Mantenimiento" ) ;
@ -128,7 +137,7 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
etiquetaLayout . removeAll ( ) ; / / Limpia el layout
}
} ) ;
fechaLayout . add ( this . fecha ) ;
fechaLayout . add ( this . fecha /*, this.txtPlananualID*/ ) ;
fechaLayout . addAndExpand ( new HorizontalLayout ( ) ) ;
fechaLayout . add ( tipoMantt , nomenclatura ) ;
fechaLayout . setWidthFull ( ) ;
@ -174,6 +183,7 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
add ( fechaLayout , departamentoLayout , controlsLayout , actualizacionesLayout , etiquetaLayout , firmasLayout , botonesLayout ) ;
this . userService = userService ;
}
@ -372,7 +382,7 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
private void signLayout ( ) {
VerticalLayout userSignLayout = new VerticalLayout ( ) ;
SignaturePad userSignPad = new SignaturePad ( ) ;
userSignPad = new SignaturePad ( ) ;
userSignPad . setBackgroundColor ( 0 , 0 , 0 , 0 ) ;
userSignPad . setHeight ( "200px" ) ;
userSignPad . setPenColor ( "#000000" ) ;
@ -385,7 +395,7 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
userSignLayout . add ( userSignPad , userSignSpan , tituloUser ) ;
VerticalLayout smtSignLayout = new VerticalLayout ( ) ;
SignaturePad smtSignPad = new SignaturePad ( ) ;
smtSignPad = new SignaturePad ( ) ;
smtSignPad . setHeight ( "200px" ) ;
smtSignPad . setBackgroundColor ( 0 , 0 , 0 , 0 ) ;
smtSignPad . setPenColor ( "#000000" ) ;
@ -399,13 +409,13 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
smtSignLayout . add ( smtSignPad , smtSignSpan , tituloSMT ) ;
VerticalLayout gcialSignLayout = new VerticalLayout ( ) ;
SignaturePad gciatiSignPad = new SignaturePad ( ) ;
gciatiSignPad = new SignaturePad ( ) ;
gciatiSignPad . setBackgroundColor ( 0 , 0 , 0 , 0 ) ;
gciatiSignPad . setHeight ( "200px" ) ;
gciatiSignPad . setPenColor ( "#000000" ) ;
gciatiSignPad . getElement ( ) . getStyle ( ) . set ( "border" , "1px solid black" ) ;
Span gciatiSignSpan = new Span ( "L.I. Sandra E. Rodriguez Ramirez " ) ;
Span tituloGerente = new Span ( "Gerencia de Tecnologias de la Información " ) ;
Span gciatiSignSpan = new Span ( "L.I. David Olivares Ramos " ) ;
Span tituloGerente = new Span ( "Encargado de Despacho Gcia. T.I " ) ;
gcialSignLayout . setSizeFull ( ) ;
gcialSignLayout . setSpacing ( false ) ;
gcialSignLayout . setAlignItems ( Alignment . CENTER ) ;
@ -428,6 +438,7 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
LocalDate fechaSeleccionada = fecha . getValue ( ) ;
TiposMantenimiento tiposMantenimiento = tipoMantt . getValue ( ) ;
String tipoMantId = tiposMantenimiento ! = null ? tiposMantenimiento . getTipomantId ( ) : null ;
String planAnualvalue = txtPlananualID . getValue ( ) ;
/ / Cambié aquí para obtener el departamento seleccionado correctamente
DepartamentosModel departamentoSeleccionado = area . getValue ( ) ;
@ -448,13 +459,38 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
formaMantt = "M" ;
}
/ / VALIDACION PARA QUE TODOS LOS CAMPOS OBLIGATORIOS SEAN LLENADOS
if ( fechaSeleccionada = = null | | tipoMantId = = null | | departamentoId = = null | | empleadoId = = null | | equipoId = = null | | formaMantt = = null ) {
if ( fechaSeleccionada = = null | | tipoMantId = = null | | departamentoId = = null | | empleadoId = = null | | equipoId = = null | | formaMantt = = null | | planAnualvalue = = null ) {
Notification . show ( "Por favor, completa todos los campos requeridos" , 4000 , Notification . Position . MIDDLE ) ;
return ;
}
int isInserted = databaseService . insertarMantenimiento ( fechaSeleccionada , tipoMantId , departamentoId , empleadoId , formaMantt , equipoId ) ;
/ / Captura las firmas en Base64 usando el metodo getImageBase64
byte [ ] userSignatureBytes = userSignPad . getImageBase64 ( ) ;
byte [ ] smtSignatureBytes = smtSignPad . getImageBase64 ( ) ;
byte [ ] gciatiSignatureBytes = gciatiSignPad . getImageBase64 ( ) ;
/ / Valida si los campos de firma estan vacios
if ( userSignatureBytes = = null | | userSignatureBytes . length = = 0 | |
smtSignatureBytes = = null | | smtSignatureBytes . length = = 0 | |
gciatiSignatureBytes = = null | | gciatiSignatureBytes . length = = 0 ) {
Notification . show ( "Por favor, firme el mantenimiento." , 4000 , Notification . Position . MIDDLE )
. addThemeVariants ( NotificationVariant . LUMO_WARNING ) ;
return ;
}
/ / Convierte los byte [ ] a String en formato Base64
String userSignatureBase64 = Base64 . getEncoder ( ) . encodeToString ( userSignatureBytes ) ;
String smtSignatureBase64 = Base64 . getEncoder ( ) . encodeToString ( smtSignatureBytes ) ;
String gciaSignatureBase64 = Base64 . getEncoder ( ) . encodeToString ( gciatiSignatureBytes ) ;
int isInserted = databaseService . insertarMantenimiento (
fechaSeleccionada , tipoMantId , departamentoId , empleadoId , formaMantt , equipoId ,
userSignatureBase64 , smtSignatureBase64 , gciaSignatureBase64 , planAnualvalue ) ;
/ / AQUI SE MANEJA LA INSERCION DE LOS DETALLES DE HARDWARE ( TIPO DE HARDWARE , NO . DE SERIE , MODELO , PLACA )
if ( isInserted > 0 ) {
@ -550,6 +586,7 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
. addThemeVariants ( NotificationVariant . LUMO_SUCCESS ) ;
fecha . clear ( ) ;
txtPlananualID . clear ( ) ;
tipoMantt . clear ( ) ;
area . clear ( ) ;
usuario . clear ( ) ;
@ -558,12 +595,16 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
actualizaciones . clear ( ) ;
masActualizacionesGroup . clear ( ) ;
txtCuales . clear ( ) ;
userSignPad . clear ( ) ;
smtSignPad . clear ( ) ;
gciatiSignPad . clear ( ) ;
UI . getCurrent ( ) . navigate ( "/" ) ;
} else {
Notification . show ( "Error al guardar el mantenimeinto" , 4000 , Notification . Position . MIDDLE ) ;
}
} ) ;
buttonsLayout . setSizeFull ( ) ;
buttonsLayout . add ( btnGuardar ) ;
botonesLayout . add ( buttonsLayout ) ;
@ -577,7 +618,11 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
: null ;
String tipoParam = beforeEnterEvent . getLocation ( ) . getQueryParameters ( ) . getParameters ( ) . get ( "tipo" ) ! = null
? beforeEnterEvent . getLocation ( ) . getQueryParameters ( ) . getParameters ( "tipo" ) . stream ( ) . findFirst ( ) . orElse ( null )
? beforeEnterEvent . getLocation ( ) . getQueryParameters ( ) . getParameters ( ) . get ( "tipo" ) . stream ( ) . findFirst ( ) . orElse ( null )
: null ;
String idParam = beforeEnterEvent . getLocation ( ) . getQueryParameters ( ) . getParameters ( ) . get ( "id" ) ! = null
? beforeEnterEvent . getLocation ( ) . getQueryParameters ( ) . getParameters ( ) . get ( "id" ) . stream ( ) . findFirst ( ) . orElse ( null )
: null ;
if ( fechaParam ! = null ) {
@ -614,5 +659,12 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
tipoMantt . setReadOnly ( true ) ;
}
}
/ / Establecemos el ID desde el plan anual
if ( idParam ! = null ) {
txtPlananualID . setValue ( idParam ) ; / / Establece el ID en el campo de texto
} else {
txtPlananualID . setValue ( "Sin ID" ) ; / / O un valor por defecto si no hay ID
}
}
}