|
|
@ -36,6 +36,8 @@ import mx.gob.jumapacelaya.services.DatabaseService; |
|
|
|
import mx.gob.jumapacelaya.services.EmailService; |
|
|
|
import mx.gob.jumapacelaya.services.SecurityService; |
|
|
|
import mx.gob.jumapacelaya.services.UserService; |
|
|
|
import oracle.net.aso.h; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.vaadin.lineawesome.LineAwesomeIcon; |
|
|
|
|
|
|
@ -100,7 +102,16 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse |
|
|
|
//Selector de fecha |
|
|
|
this.fecha = new DatePicker("Fecha"); |
|
|
|
fecha.setRequired(true); |
|
|
|
//fecha.setPlaceholder("Fecha"); |
|
|
|
fecha.setLocale(new Locale("es", "MX")); |
|
|
|
DatePicker.DatePickerI18n i18n = new DatePicker.DatePickerI18n() |
|
|
|
.setWeekdays(List.of("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado")) |
|
|
|
.setWeekdaysShort(List.of("Dom","Lun","Mar","Mié","Jue","Vie","Sáb")) |
|
|
|
.setMonthNames(List.of("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre")) |
|
|
|
.setFirstDayOfWeek(1) |
|
|
|
.setToday("Hoy") |
|
|
|
.setCancel("Cancelar") |
|
|
|
.setDateFormat("dd/MM/yyyy"); |
|
|
|
fecha.setI18n(i18n); |
|
|
|
|
|
|
|
|
|
|
|
// Campo de texto para el ID de MTTOPROGRAMADO |
|
|
@ -485,167 +496,154 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse |
|
|
|
|
|
|
|
|
|
|
|
btnGuardar.addClickListener(event -> { |
|
|
|
|
|
|
|
LocalDate fechaSeleccionada = fecha.getValue(); |
|
|
|
TiposMantenimiento tiposMantenimiento = tipoMantt.getValue(); |
|
|
|
TiposMantenimiento tiposMantenimiento = tipoMantt.getValue(); |
|
|
|
String tipoMantId = tiposMantenimiento != null ? tiposMantenimiento.getTipomantId() : null; |
|
|
|
String planAnualvalue = txtPlananualID.getValue(); |
|
|
|
String planAnualValue = txtPlananualID.getValue(); |
|
|
|
|
|
|
|
// Cambié aquí para obtener el departamento seleccionado correctamente |
|
|
|
DepartamentosModel departamentoSeleccionado = area.getValue(); |
|
|
|
String departamentoId = departamentoSeleccionado != null ? departamentoSeleccionado.getDepartamentoId().toString() : null; |
|
|
|
|
|
|
|
// Obtener el empleado y el equipo |
|
|
|
Usuario usuarioSeleccionado = usuario.getValue(); |
|
|
|
String empleadoId = usuarioSeleccionado != null ? usuarioSeleccionado.getEmpleadoId().toString() : null; |
|
|
|
String equipoId = txtNombreEquipo.getValue(); |
|
|
|
|
|
|
|
// AQUI SE MANEJA LA OPCION SELECCIONADA EN LA FORMA DE MANTENIMIENTO (REMOTA o MANUAL) |
|
|
|
String formaSeleccionada = formaGroup.getValue(); |
|
|
|
String formaMantt = null; |
|
|
|
|
|
|
|
if ("Remota".equals(formaSeleccionada)) { |
|
|
|
formaMantt = "R"; |
|
|
|
} else if ("Manual".equals(formaSeleccionada)) { |
|
|
|
formaMantt = "M"; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// VALIDACION PARA QUE TODOS LOS CAMPOS OBLIGATORIOS SEAN LLENADOS |
|
|
|
if (fechaSeleccionada == null || tipoMantId == null || departamentoId == null || empleadoId == null || equipoId == null || formaMantt == null || planAnualvalue == null) { |
|
|
|
// Validación de campos obligatorios |
|
|
|
if (fechaSeleccionada == null || tipoMantId == null || departamentoId == null || empleadoId == null || |
|
|
|
equipoId == null || equipoId.trim().isEmpty() || formaMantt == null || planAnualValue == null || planAnualValue.trim().isEmpty()) { |
|
|
|
Notification.show("Por favor, completa todos los campos requeridos", 4000, Notification.Position.MIDDLE); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Captura las firmas en Base64 usando el metodo getImageBase64 |
|
|
|
byte[] userSignatureBytes = userSignPad.getImageBase64(); |
|
|
|
byte[] smtSignatureBytes = smtSignPad.getImageBase64(); |
|
|
|
byte[] gciatiSignatureBytes = gciatiSignPad.getImageBase64(); |
|
|
|
byte[] gciaSignatureBytes = gciatiSignPad.getImageBase64(); |
|
|
|
|
|
|
|
|
|
|
|
// 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); |
|
|
|
|
|
|
|
String gciaSignatureBase64 = Base64.getEncoder().encodeToString(gciaSignatureBytes); |
|
|
|
|
|
|
|
// Validacion de firmas si es igual o no a la cadena de firma vacia |
|
|
|
if (esFirmaVacia(userSignatureBase64) || esFirmaVacia(smtSignatureBase64) || esFirmaVacia(gciaSignatureBase64)) { |
|
|
|
Notification.show("Por favor, completa todas las firmas antes de guardar.", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_WARNING); |
|
|
|
return; // Detiene la ejecución |
|
|
|
Notification.show("Por favor, completa todas las firmas antes de guardar.", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_WARNING); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Validación de campos de hardware |
|
|
|
List<Map<String, String>> detallesHardware = new ArrayList<>(); |
|
|
|
for (HorizontalLayout layout : hardwareLayouts) { |
|
|
|
ComboBox<TiposHardware> tipoHardware = (ComboBox<TiposHardware>) layout.getComponentAt(0); |
|
|
|
TextField noSerie = (TextField) layout.getComponentAt(1); |
|
|
|
TextField modelo = (TextField) layout.getComponentAt(2); |
|
|
|
TextField placa = (TextField) layout.getComponentAt(3); |
|
|
|
|
|
|
|
// Aqui se manda llamar al metodo de insertar mantenimiento en DatabaseService y se le pasan los argumentos necesarios |
|
|
|
int isInserted = databaseService.insertarMantenimiento( |
|
|
|
fechaSeleccionada, tipoMantId, departamentoId, empleadoId, formaMantt, equipoId, |
|
|
|
userSignatureBase64, smtSignatureBase64, gciaSignatureBase64, planAnualvalue); |
|
|
|
TiposHardware tipoSeleccionado = tipoHardware.getValue(); |
|
|
|
if (tipoSeleccionado == null) { |
|
|
|
Notification.show("Por favor, selecciona un tipo de hardware", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_WARNING); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// AQUI SE MANEJA LA INSERCION DE LOS DETALLES DE HARDWARE (TIPO DE HARDWARE, NO. DE SERIE, MODELO, PLACA) |
|
|
|
if (isInserted > 0) { |
|
|
|
int mantenimientoId = databaseService.getUltimoMantenimientoId(); |
|
|
|
boolean esOpcional = Arrays.asList("TECLADO", "MOUSE").contains(tipoSeleccionado.getNombreHardware()); |
|
|
|
|
|
|
|
String numSerie = noSerie.getValue(); |
|
|
|
String modeloVal = modelo.getValue(); |
|
|
|
String placaVal = placa.getValue(); |
|
|
|
|
|
|
|
for (HorizontalLayout layout : hardwareLayouts) { |
|
|
|
ComboBox<TiposHardware> tipoHardware = (ComboBox<TiposHardware>) layout.getComponentAt(0); // Ahora es ComboBox<TiposHardware> |
|
|
|
TextField noSerie = (TextField) layout.getComponentAt(1); |
|
|
|
TextField modelo = (TextField) layout.getComponentAt(2); |
|
|
|
TextField placa = (TextField) layout.getComponentAt(3); |
|
|
|
|
|
|
|
|
|
|
|
TiposHardware tipoSeleccionado = tipoHardware.getValue(); |
|
|
|
|
|
|
|
// Definir tipos de hardware opcionales (sin necesidad de modelo, número de serie y placa) |
|
|
|
List<String> tiposOpcionales = Arrays.asList("TECLADO", "MOUSE"); |
|
|
|
|
|
|
|
// Verificar si el tipo de hardware es opcional |
|
|
|
boolean esOpcional = tipoSeleccionado != null && tiposOpcionales.contains(tipoSeleccionado.getNombreHardware()); |
|
|
|
|
|
|
|
// Validar campos solo si el tipo de hardware no es opcional |
|
|
|
String numSerieInt = noSerie.getValue(); |
|
|
|
String placaInt = placa.getValue(); |
|
|
|
|
|
|
|
|
|
|
|
// Validaciones antes de insertar detalles del hardware |
|
|
|
if (!esOpcional) { |
|
|
|
if (tipoHardware.getValue() == null || modelo.getValue() == null || numSerieInt == null || numSerieInt.isEmpty() || placaInt == null || placaInt.isEmpty()) { |
|
|
|
Notification.show("Por favor, completa todos los campos de hardware", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_WARNING); |
|
|
|
return; |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (tipoSeleccionado == null) { |
|
|
|
Notification.show("Por favor, selecciona un tipo de hardware", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_WARNING); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!esOpcional && (modeloVal == null || modeloVal.isEmpty() || numSerie == null || numSerie.isEmpty() || placaVal == null || placaVal.isEmpty())) { |
|
|
|
Notification.show("Por favor, completa todos los campos de hardware.", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_WARNING); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// Obtener el ID de tipo de hardware seleccionado |
|
|
|
String tipoHardwareId = tipoSeleccionado.getTipoHardwareId(); |
|
|
|
Map<String, String> hw = new HashMap<>(); |
|
|
|
hw.put("tipoHardwareId", tipoSeleccionado.getTipoHardwareId()); |
|
|
|
hw.put("numSerie", numSerie); |
|
|
|
hw.put("modelo", modeloVal); |
|
|
|
hw.put("placa", placaVal); |
|
|
|
detallesHardware.add(hw); |
|
|
|
} |
|
|
|
|
|
|
|
boolean isHardwareInserted = databaseService.insertarHardware( |
|
|
|
tipoHardwareId, // Ahora usamos el ID del tipo de hardware |
|
|
|
numSerieInt, |
|
|
|
modelo.getValue(), |
|
|
|
placaInt, |
|
|
|
mantenimientoId |
|
|
|
); |
|
|
|
Set<String> actualizacionesSeleccionadas = actualizaciones.getSelectedItems(); |
|
|
|
String otrasActualizaciones = null; |
|
|
|
if ("Si".equals(masActualizacionesGroup.getValue())) { |
|
|
|
otrasActualizaciones = txtCuales.getValue(); |
|
|
|
if (otrasActualizaciones == null || otrasActualizaciones.trim().isEmpty()) { |
|
|
|
Notification.show("Especifica las otras actualizaciones", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_WARNING); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Limpiar los campos después de la inserción |
|
|
|
tipoHardware.clear(); |
|
|
|
modelo.clear(); |
|
|
|
placa.clear(); |
|
|
|
noSerie.clear(); |
|
|
|
// Una vez que validamos todos los campos del formulario, procedemos a insertar en BD |
|
|
|
try { |
|
|
|
int isInserted = databaseService.insertarMantenimiento(fechaSeleccionada, tipoMantId, departamentoId, empleadoId, formaMantt, equipoId, userSignatureBase64, smtSignatureBase64, gciaSignatureBase64, planAnualValue); |
|
|
|
|
|
|
|
if (!isHardwareInserted) { |
|
|
|
Notification.show("Error al insertar detalles del hardware", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (isInserted <= 0) { |
|
|
|
Notification.show("Error al guardar el mantenimiento", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
int mantenimientoId = databaseService.getUltimoMantenimientoId(); |
|
|
|
|
|
|
|
// AQUI MANEJO LA INSERCION DE LOS DATOS DE LOS CHECKBOXES DE ACTUALIZACIONES DE SEGURIDAD!!! |
|
|
|
for (String actualizacionSelecionada : actualizaciones.getSelectedItems()) { |
|
|
|
boolean isActualizacionInserted = databaseService.insertActualizacionSeg(actualizacionSelecionada, null, mantenimientoId); |
|
|
|
for (Map<String, String> hw : detallesHardware) { |
|
|
|
boolean ok = databaseService.insertarHardware( |
|
|
|
hw.get("tipoHardwareId"), |
|
|
|
hw.get("numSerie"), |
|
|
|
hw.get("modelo"), |
|
|
|
hw.get("placa"), |
|
|
|
mantenimientoId |
|
|
|
); |
|
|
|
|
|
|
|
if (!isActualizacionInserted) { |
|
|
|
Notification.show("Error al insertar actualizacion de seguridad", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
|
if (!ok) { |
|
|
|
Notification.show("Error al insertar detalles del hardware: ", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (masActualizacionesGroup.getValue().equals("Si")) { |
|
|
|
String otrasActu = txtCuales.getValue(); |
|
|
|
String actualizacion = "Otras"; |
|
|
|
if (otrasActu != null && !otrasActu.trim().isEmpty()){ |
|
|
|
boolean isOtrasActualizaciones = databaseService.insertActualizacionSeg(actualizacion, otrasActu, mantenimientoId); |
|
|
|
|
|
|
|
if (!isOtrasActualizaciones) { |
|
|
|
Notification.show("Error al insertar otras actualizaciones", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
|
return; |
|
|
|
} |
|
|
|
for (String act : actualizacionesSeleccionadas) { |
|
|
|
boolean ok = databaseService.insertActualizacionSeg(act, null, mantenimientoId); |
|
|
|
if (!ok) { |
|
|
|
Notification.show("Error al insertar actualización de seguridad", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// NOTIFICACION DE GUARDADO EXITOSO Y LIMPIEZA DE LOS CAMPOS!!! |
|
|
|
Notification.show("!!Mantenimiento guardado exitosamente!!", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_SUCCESS); |
|
|
|
if (otrasActualizaciones != null) { |
|
|
|
boolean ok = databaseService.insertActualizacionSeg("Otras", otrasActualizaciones, mantenimientoId); |
|
|
|
if (!ok) { |
|
|
|
Notification.show("Error al insertar otras actualizaciones", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// === EXITO === |
|
|
|
Notification.show("¡Mantenimiento guardado exitosamente!", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_SUCCESS); |
|
|
|
|
|
|
|
// Envio del correo electronico |
|
|
|
try { |
|
|
|
enviarCorreo(); // Intento de envío de correo |
|
|
|
enviarCorreo(); |
|
|
|
} catch (Exception e) { |
|
|
|
Notification.show("Error al enviar el correo", 4000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
// Limpiar campos |
|
|
|
fecha.clear(); |
|
|
|
txtPlananualID.clear(); |
|
|
|
tipoMantt.clear(); |
|
|
@ -660,11 +658,20 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse |
|
|
|
smtSignPad.clear(); |
|
|
|
gciatiSignPad.clear(); |
|
|
|
|
|
|
|
for (HorizontalLayout layout : hardwareLayouts) { |
|
|
|
((ComboBox<?>) layout.getComponentAt(0)).clear(); |
|
|
|
((TextField) layout.getComponentAt(1)).clear(); |
|
|
|
((TextField) layout.getComponentAt(2)).clear(); |
|
|
|
((TextField) layout.getComponentAt(3)).clear(); |
|
|
|
} |
|
|
|
|
|
|
|
UI.getCurrent().navigate("/"); |
|
|
|
} else { |
|
|
|
Notification.show("Error al guardar el mantenimeinto", 4000, Notification.Position.MIDDLE); |
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception ex) { |
|
|
|
Notification.show("Ocurrio un error inesperado: " + ex.getMessage(), 5000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
|
ex.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
buttonsLayout.setSizeFull(); |
|
|
|