|
|
@ -535,31 +535,43 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// METODO PARA ENVIAR LOS CORREOS ELECTRONICOS |
|
|
|
|
|
private void enviarCorreo() { |
|
|
private void enviarCorreo() { |
|
|
Usuario usuarioDestino = cbUsuario.getValue(); |
|
|
Usuario usuarioDestino = cbUsuario.getValue(); |
|
|
if (usuarioDestino != null && usuarioDestino.getEmail() != null) { |
|
|
|
|
|
try { |
|
|
|
|
|
String token = service.crearTokenEncuesta(mantenimientoIdActual); |
|
|
|
|
|
|
|
|
|
|
|
String destinatario = usuarioDestino.getEmail(); |
|
|
|
|
|
String asunto = "Encuesta de satisfacción - Mantenimiento #" + mantenimientoIdActual; |
|
|
|
|
|
String linkEncuesta = baseUrl + "/encuesta?token=" + token; |
|
|
|
|
|
String cuerpo = "<html><body><a href='" + linkEncuesta + "'><img src='cid:image_id'/></a></body></html>"; |
|
|
|
|
|
String imagePath = "META-INF/resources/images/imgCorreo/imgEncuesta.png"; |
|
|
|
|
|
|
|
|
if (usuarioDestino == null || usuarioDestino.getEmail() == null) { |
|
|
|
|
|
Notification.show("Por favor, selecciona un usuario destino", 3000, Notification.Position.MIDDLE); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
emailService.enviarCorreo(destinatario, asunto, cuerpo, imagePath); |
|
|
|
|
|
|
|
|
String tokenExistente = service.getTokenPorMtto(mantenimientoIdActual); |
|
|
|
|
|
|
|
|
Notification.show("Encuesta enviada correctamente", 3000, Notification.Position.BOTTOM_END) |
|
|
|
|
|
.addThemeVariants(NotificationVariant.LUMO_SUCCESS); |
|
|
|
|
|
|
|
|
if (tokenExistente != null) { |
|
|
|
|
|
showNotiReenvio(usuarioDestino, tokenExistente); |
|
|
|
|
|
} else { |
|
|
|
|
|
try { |
|
|
|
|
|
String nuevoToken = service.crearTokenEncuesta(mantenimientoIdActual); |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
Notification.show("Error: No se pudo enviar. Es probable que ya exista una encuesta generada.", |
|
|
|
|
|
5000, Notification.Position.MIDDLE) |
|
|
|
|
|
|
|
|
Notification.show("Error al generar la encuesta: " + e.getMessage(), 5000, Notification.Position.MIDDLE) |
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
|
|
|
Notification.show("Por favor, seleccione un usuario destino", 3000, Notification.Position.MIDDLE); |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void ejecutarEnvio(Usuario usuario, String token) { |
|
|
|
|
|
try { |
|
|
|
|
|
String destinatario = usuario.getEmail(); |
|
|
|
|
|
String asunto = "Encuesta de satisfacción - Mantenimiento #" + mantenimientoIdActual; |
|
|
|
|
|
String linkEncuesta = baseUrl + "/encuesta?token=" + token; |
|
|
|
|
|
String cuerpo = "<html><body><a href='" + linkEncuesta + "'><img src='cid:image_id'/></a></body></html>"; |
|
|
|
|
|
String imagePath = "META-INF/resources/images/imgCorreo/imgEncuesta.png"; |
|
|
|
|
|
|
|
|
|
|
|
emailService.enviarCorreo(destinatario, asunto, cuerpo, imagePath); |
|
|
|
|
|
|
|
|
|
|
|
Notification.show("Encuesta enviada correctamente", 3000, Notification.Position.BOTTOM_END) |
|
|
|
|
|
.addThemeVariants(NotificationVariant.LUMO_SUCCESS); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
Notification.show("Error al enviar el correo: " + e.getMessage(), 5000, Notification.Position.MIDDLE) |
|
|
|
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -684,4 +696,30 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void showNotiReenvio(Usuario usuario, String tokenExistente) { |
|
|
|
|
|
Notification ntf = new Notification(); |
|
|
|
|
|
ntf.setDuration(0); |
|
|
|
|
|
ntf.setPosition(Notification.Position.MIDDLE); |
|
|
|
|
|
ntf.addThemeVariants(NotificationVariant.LUMO_WARNING); |
|
|
|
|
|
|
|
|
|
|
|
Span text = new Span("Atención: Ya se ha enviado una encuesta para este mantenimiento. ¿Deseas reenviar el link actual?"); |
|
|
|
|
|
|
|
|
|
|
|
Button reenvioBtn = new Button("Reenviar", new Icon("lumo", "reload"), event -> { |
|
|
|
|
|
ejecutarEnvio(usuario, tokenExistente); |
|
|
|
|
|
ntf.close(); |
|
|
|
|
|
}); |
|
|
|
|
|
reenvioBtn.addThemeVariants(ButtonVariant.LUMO_PRIMARY); |
|
|
|
|
|
|
|
|
|
|
|
Button cancelBtn = new Button(new Icon("lumo", "cross"), event -> ntf.close()); |
|
|
|
|
|
cancelBtn.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE); |
|
|
|
|
|
|
|
|
|
|
|
HorizontalLayout layout = new HorizontalLayout(text, reenvioBtn, cancelBtn); |
|
|
|
|
|
layout.setAlignItems(Alignment.CENTER); |
|
|
|
|
|
|
|
|
|
|
|
ntf.add(layout); |
|
|
|
|
|
ntf.open(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |