|
|
@ -15,8 +15,10 @@ import org.springframework.stereotype.Service; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.io.InputStream; |
|
|
import java.io.InputStream; |
|
|
import java.sql.*; |
|
|
import java.sql.*; |
|
|
|
|
|
import java.time.DayOfWeek; |
|
|
import java.time.LocalDate; |
|
|
import java.time.LocalDate; |
|
|
import java.time.ZoneId; |
|
|
import java.time.ZoneId; |
|
|
|
|
|
import java.time.ZonedDateTime; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.UUID; |
|
|
import java.util.UUID; |
|
|
@ -1042,16 +1044,30 @@ public class DatabaseService { |
|
|
|
|
|
|
|
|
public String crearTokenEncuesta(int mantenimientoid) { |
|
|
public String crearTokenEncuesta(int mantenimientoid) { |
|
|
String token = UUID.randomUUID().toString(); |
|
|
String token = UUID.randomUUID().toString(); |
|
|
Timestamp expira = new Timestamp(System.currentTimeMillis() + (24 * 60 * 60 * 1000)); |
|
|
|
|
|
LocalDate fechaEnvio = LocalDate.now(ZoneId.of("America/Mexico_City")); |
|
|
|
|
|
|
|
|
ZoneId zonaMX = ZoneId.of("America/Mexico_City"); |
|
|
|
|
|
ZonedDateTime ahora = ZonedDateTime.now(zonaMX); |
|
|
|
|
|
|
|
|
|
|
|
ZonedDateTime fechaExp = ahora; |
|
|
|
|
|
int diasPorSumar = 3; |
|
|
|
|
|
while (diasPorSumar > 0) { |
|
|
|
|
|
fechaExp = fechaExp.plusDays(1); |
|
|
|
|
|
if (!(fechaExp.getDayOfWeek() == DayOfWeek.SATURDAY || |
|
|
|
|
|
fechaExp.getDayOfWeek() == DayOfWeek.SUNDAY)) { |
|
|
|
|
|
diasPorSumar--; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Timestamp expira = Timestamp.from(fechaExp.toInstant()); |
|
|
|
|
|
LocalDate fechaEnvio = ahora.toLocalDate(); |
|
|
|
|
|
|
|
|
String query = "INSERT INTO ENCUESTATOKENS (TOKEN, MANTENIMIENTOID, FECHAENVIO, FECHAEXPIRACION) VALUES (?, ?, ?, ?)"; |
|
|
String query = "INSERT INTO ENCUESTATOKENS (TOKEN, MANTENIMIENTOID, FECHAENVIO, FECHAEXPIRACION) VALUES (?, ?, ?, ?)"; |
|
|
|
|
|
|
|
|
try (Connection conn = getMysqlConnection(); |
|
|
try (Connection conn = getMysqlConnection(); |
|
|
PreparedStatement stmt = conn.prepareStatement(query)) { |
|
|
PreparedStatement stmt = conn.prepareStatement(query)) { |
|
|
|
|
|
|
|
|
stmt.setString(1, token); |
|
|
stmt.setString(1, token); |
|
|
stmt.setInt(2, mantenimientoid); |
|
|
stmt.setInt(2, mantenimientoid); |
|
|
stmt.setDate(3, Date.valueOf(fechaEnvio)); |
|
|
|
|
|
|
|
|
stmt.setDate(3, java.sql.Date.valueOf(fechaEnvio)); |
|
|
stmt.setTimestamp(4, expira); |
|
|
stmt.setTimestamp(4, expira); |
|
|
stmt.executeUpdate(); |
|
|
stmt.executeUpdate(); |
|
|
|
|
|
|
|
|
|