Commit 4bdaf7d7 by Billy Larru

creando un metodo para generar hora y minuto aleatoria

parent 5b4789ed
......@@ -33,8 +33,8 @@ public class MysqlDAOFactory extends DAOFactory {
try {
conexion = DriverManager.getConnection(
"jdbc:mysql://172.16.2.39:3306/nuevo",
"root",
"mysql");
"melani",
"melani");
} catch (Exception e) {
e.printStackTrace();
......
......@@ -9,8 +9,6 @@ import java.sql.Connection;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import salidasautomaticas.dao.SalidasDAO;
......@@ -212,32 +210,16 @@ public class SalidasMysqlDAO implements SalidasDAO {
// if(salidaPersonal==null || salidaPersonal.isEmpty()){
// continue;
// }
String[] splitHoraConsulta = salidaPersonal.split(":");
int min = Integer.parseInt(splitHoraConsulta[1]);
int hora = Integer.parseInt(splitHoraConsulta[0]);
System.out.println("obj " + asistencia);
//Actualizacion de salidas
if (min == 0) {
aleatorioHora = (int) Math.floor(Math.random() * 2 + (hora - 1));
} else {
aleatorioHora = hora;
}
if (hora == aleatorioHora) {
if (min == 0) {
aleatorioMin = (int) Math.floor(Math.random() * (3 - 0 + 1) + 0);
} else {
aleatorioMin = (int) Math.floor(Math.random() * (33 - 27 + 1) + 27);
}
} else {
aleatorioMin = (int) Math.floor(Math.random() * 3 + 57);
}
int[] aleatorio = generarHoraMinutoAleatorio(salidaPersonal);
aleatorioHora = aleatorio[0];
aleatorioMin = aleatorio[1];
String queryPersonal = "update asistencia set horasal= ?,minsal=? where codasis=? ";
JSONArray parametros = new JSONArray();
parametros.put(aleatorioHora);
parametros.put(aleatorioMin);
parametros.put(asistencia.getString("codasis"));
// System.out.println("consulta "+queryPersonal+ " "+parametros);
resultado = EstandarDAO.getInstance().ejecutar(cn, queryPersonal, parametros);
System.out.println("Asistencia actualizada");
}
......@@ -245,8 +227,33 @@ public class SalidasMysqlDAO implements SalidasDAO {
return resultado;
}
private int[] generarHoraMinutoAleatorio(String horaMinuto) {
int[] aleatorio = new int[2];//horaAleatoria index=0, minAleatorio index=1
String[] splitHoraConsulta = horaMinuto.split(":");
int min = Integer.parseInt(splitHoraConsulta[1]);
int hora = Integer.parseInt(splitHoraConsulta[0]);
// Actualizacion de salidas
if (min == 0) {
aleatorio[0] = (int) Math.floor(Math.random() * 2 + (hora - 1));
} else {
aleatorio[0] = hora;
}
if (hora == aleatorio[0]) {
if (min == 0) {
aleatorio[1] = (int) Math.floor(Math.random() * (3 - 0 + 1) + 0);
} else {
aleatorio[1] = (int) Math.floor(Math.random() * (33 - 27 + 1) + 27);
}
} else {
aleatorio[1] = (int) Math.floor(Math.random() * 3 + 57);
}
return aleatorio;
}
public static void main(String[] args) {
// SalidasMysqlDAO s = new SalidasMysqlDAO();
SalidasMysqlDAO s = new SalidasMysqlDAO();
// try {
// JSONObject obj = s.actualizarSalida("17:00");
// System.out.println(obj);
......@@ -255,20 +262,15 @@ public class SalidasMysqlDAO implements SalidasDAO {
// }
// System.out.println(s.getFechaAyer());
String query = "SELECT "
+ " p.codper, "
+ " su.salidaLV, "
+ " su.salidaS, "
+ "FROM "
+ " personal p "
+ "INNER JOIN salidas_update su ON p.codcargo=su.codcargo "
+ "WHERE retirado=0 AND p.horaing=su.horaLV "
+ "and p.mining=su.minutoLV and p.horaingsabado=su.sabadoLV AND p.miningsabado=su.sabadoS "
+ "and NOT p.codlocal in('L035','L053','L038') AND NOT pronoe=1 "
+ "AND not p.codcargo in (71,13) and horaing < 19 and "
+ "(nullif(p.salidaLV,'') is null and nullif(p.salidaS, '') is null) ORDER BY p.codper ";
System.out.println(query);
// String hora = "09:30";
// Integer h = new Integer(1);
// Integer m = new Integer(1);
//
// s.generarHoraMinutoAleatorio(hora, h, m);
//
// System.out.println("hora=" + h.intValue() + ", minuto=" + m.intValue());
// int[] i = s.generarHoraMinutoAleatorio("10:00");
// System.out.println("h=" + i[0] + ", m=" + i[1]);
}
@Override
......
......@@ -30,9 +30,19 @@ public class ActualizarSalidaTask extends TimerTask{
public void run() {
System.out.println("Ejecutando salida "+horaSalida);
JSONObject objJSON= services.actualizarSalidas(horaSalida);
JSONArray objNuevasSalidas = services.obtenerSalidasNuevas();
JSONArray objPersonalSinSalida = services.obtenerPersonalNuevoSinSalida();
JSONObject objSalidaAsignada= services.asignarHorarioSalida();
if(objSalidaAsignada.getInt("msg")>0){
System.out.println("Se asignaron horarios de salida correctamente, filas afectadas="+objSalidaAsignada.getInt("msg"));
}else{
System.out.println("No se pudo asignar horarios de salida");
}
// JSONArray objNuevasSalidas = services.obtenerSalidasNuevas();
// JSONArray objPersonalSinSalida = services.obtenerPersonalNuevoSinSalida();
System.out.println("Matando timer "+timer);
......
......@@ -15,7 +15,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import salidasautomaticas.services.SalidasServices;
import salidasautomaticas.util.Metodos;
/**
......@@ -24,15 +23,13 @@ import salidasautomaticas.util.Metodos;
*/
public class ProgramarSalidasTask extends TimerTask {
SalidasServices service = new SalidasServices();
@Override
public void run() {
try {
// JSONArray listaHorarios = service.obtenerHorariosSalida();
JSONArray listaHorarios = new JSONArray();
String[] arraySalidas = {"18:39", "14:46", "14:50", "17:00", "17:30", "18:00"};
String[] arraySalidas = {"10:29", "14:46", "14:50", "17:00", "17:30", "18:00"};
for (String salida : arraySalidas) {
listaHorarios.put(new JSONObject().put("salida", salida));
......@@ -40,10 +37,9 @@ public class ProgramarSalidasTask extends TimerTask {
System.out.println("Listando horarios " + listaHorarios + "\n");
Iterator it = listaHorarios.iterator();
Timer timer;
ActualizarSalidaTask task;
while (it.hasNext()) {
for(Iterator it = listaHorarios.iterator(); it.hasNext();) {
JSONObject obj = (JSONObject) it.next();
String horaSalida = obj.getString("salida");
......
......@@ -66,4 +66,15 @@ public class SalidasServices {
return valor;
}
public JSONObject asignarHorarioSalida(){
JSONObject valor = new JSONObject();
try {
valor = salidadao.asignarHorarioSalida();
} catch (Exception e) {
e.printStackTrace();
}
return valor;
}
}
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