Commit 9431acfd by Sofía Benitez

Incorporación de beneficios

parent 1d92d714
...@@ -45,7 +45,7 @@ public class Scheduler { ...@@ -45,7 +45,7 @@ public class Scheduler {
@Scheduled(cron = "0 * * * * *") @Scheduled(cron = "0 * * * * *")
public void cumples() { public void cumples() {
String url = "https://hooks.slack.com/services/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"; String url = "https://hooks.slack.com/services/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";
// verificar que no sea feriado // Verificar que no sea feriado
Feriado esFeriado = feriadoRepository.findByFecha(new Date()); Feriado esFeriado = feriadoRepository.findByFecha(new Date());
if (esFeriado != null){ if (esFeriado != null){
return; return;
...@@ -54,12 +54,12 @@ public class Scheduler { ...@@ -54,12 +54,12 @@ public class Scheduler {
int contador = 1; int contador = 1;
Date hoy = new Date(); Date hoy = new Date();
Date fechaAyer = new Date(hoy.getTime() - ((1000 * 60 * 60 * 24) * contador) ); Date fechaAyer = new Date(hoy.getTime() - ((1000 * 60 * 60 * 24) * contador) );
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
SimpleDateFormat f = new SimpleDateFormat("EEEE"); SimpleDateFormat f = new SimpleDateFormat("EEEE");
String diaAyer = f.format(fechaAyer); String diaAyer = f.format(fechaAyer);
Boolean diaNoHabil = false; Boolean diaNoHabil = false;
// Verificar que no sea Sábado ni domingo
if ((diaAyer.equals("sábado")) || (diaAyer.equals("domingo"))){ if ((diaAyer.equals("sábado")) || (diaAyer.equals("domingo"))){
diaNoHabil = true; diaNoHabil = true;
} }
...@@ -82,7 +82,6 @@ public class Scheduler { ...@@ -82,7 +82,6 @@ public class Scheduler {
diaNoHabil = false; diaNoHabil = false;
hoy = new Date(); hoy = new Date();
fechaAyer = new Date(hoy.getTime() - ((1000 * 60 * 60 * 24) * contador) ); fechaAyer = new Date(hoy.getTime() - ((1000 * 60 * 60 * 24) * contador) );
f = new SimpleDateFormat("EEEE"); f = new SimpleDateFormat("EEEE");
diaAyer = f.format(fechaAyer); diaAyer = f.format(fechaAyer);
if ((diaAyer.equals("sábado")) || (diaAyer.equals("domingo"))){ if ((diaAyer.equals("sábado")) || (diaAyer.equals("domingo"))){
...@@ -94,51 +93,56 @@ public class Scheduler { ...@@ -94,51 +93,56 @@ public class Scheduler {
diaNoHabil = true; diaNoHabil = true;
} }
} }
for (Birthday cumple : cumplesDiaNoHabiles){ if (cumplesDiaNoHabiles != null )
String json = "{\n" + {
"\"blocks\": [\n" + for (Birthday cumple : cumplesDiaNoHabiles){
"{\n" +
"\"type\": \"section\",\n" + SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
"\"text\": {\n" + String fechaFormateada = formato.format(cumple.getFecha());
"\"type\": \"mrkdwn\",\n" + String json = "{\n" +
"\"text\": \"Buenos días <!channel> \n En la fecha " + cumple.getFecha() + " estuvo de cumpleaños *" + cumple.getNombreCompleto() + "* <@" + cumple.getIdSlack() + ">. 🥳 ¡Que los cumplas muy feliz te desea Roshka! Que en la vida siempre encuentres razones para sonreír 🥳\",\n" + "\"blocks\": [\n" +
"}" + "{\n" +
"}," + "\"type\": \"section\",\n" +
"{" + "\"text\": {\n" +
"\"type\": \"divider\"" + "\"type\": \"mrkdwn\",\n" +
"}," + "\"text\": \"Buenos días <!channel> \n En la fecha " + fechaFormateada + " estuvo de cumpleaños *" + cumple.getNombreCompleto() + "* <@" + cumple.getIdSlack() + ">. 🥳 ¡Que los cumplas muy feliz te desea Roshka! Que en la vida siempre encuentres razones para sonreír 🥳\",\n" +
"{\n" + "}" +
"\"type\": \"image\",\n" + "}," +
"\"title\": {\n" + "{" +
"\"type\": \"plain_text\",\n" + "\"type\": \"divider\"" +
"\"text\": \"" + cumple.getNombreCompleto() + "\"\n" + "}," +
"},\n" + "{\n" +
"\"block_id\": \"image4\",\n" + "\"type\": \"image\",\n" +
"\"image_url\": \"http://placekitten.com/500/500\",\n" + "\"title\": {\n" +
"\"alt_text\": \"An incredibly cute kitten.\"\n" + "\"type\": \"plain_text\",\n" +
"}\n" + "\"text\": \"" + cumple.getNombreCompleto() + "\"\n" +
"]\n" + "},\n" +
"}" + "\"block_id\": \"image4\",\n" +
""; "\"image_url\": \"http://placekitten.com/500/500\",\n" +
String result = null; "\"alt_text\": \"An incredibly cute kitten.\"\n" +
HttpPost httpPost = new HttpPost(url); "}\n" +
httpPost.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON)); "]\n" +
"}" +
try (CloseableHttpClient httpclient = HttpClients.createDefault()) { "";
try (CloseableHttpResponse response = httpclient.execute(httpPost)) { String result = null;
result = EntityUtils.toString(response.getEntity()); HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
result = EntityUtils.toString(response.getEntity());
}
} catch (IOException | ParseException e) {
e.printStackTrace();
} }
} catch (IOException | ParseException e) {
e.printStackTrace();
} }
System.out.println("FIN"); }
} // Verificar el cumpleaños de quién es
// Verificar el cumpleaños de quien es
List<Birthday> cumples = birthdayRepository.findAllByFecha(new Date()); List<Birthday> cumples = birthdayRepository.findAllByFecha(new Date());
System.out.println("PRUEBA");
for (Birthday cumple : cumples) { for (Birthday cumple : cumples) {
String json = "{\n" + String json = "{\n" +
"\"blocks\": [\n" + "\"blocks\": [\n" +
...@@ -177,26 +181,19 @@ public class Scheduler { ...@@ -177,26 +181,19 @@ public class Scheduler {
} catch (IOException | ParseException e) { } catch (IOException | ParseException e) {
e.printStackTrace(); e.printStackTrace();
} }
System.out.println("FIN");
} }
} }
// @Scheduled(cron = "0 0 1 * * FRI")
@Scheduled(cron = "0 * * * * *")
@Scheduled(cron = "0 0 8 * * MON-FRI")
// @Scheduled(cron = "0 * * * * *")
public void feriados(){
}
@Scheduled(cron = "0 0 1 * * FRI")
// @Scheduled(cron = "0 * * * * *")
public void beneficios() { public void beneficios() {
String url = "https://hooks.slack.com/services/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"; String url = "https://hooks.slack.com/services/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";
// Traer random // Verificar que no sea feriado
Feriado esFeriado = feriadoRepository.findByFecha(new Date());
if (esFeriado != null){
return;
}
Beneficio beneficio = getRandomBeneficio(); Beneficio beneficio = getRandomBeneficio();
if (beneficio != null) { if (beneficio != null) {
String json = "{" + String json = "{" +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment