Commit 3fdb2946 by Billy Larru

OK

parent 4bdaf7d7
...@@ -16,9 +16,6 @@ public interface SalidasDAO { ...@@ -16,9 +16,6 @@ public interface SalidasDAO {
public JSONArray obtenerHorariosSalida() throws Exception; public JSONArray obtenerHorariosSalida() throws Exception;
public JSONArray obtenerAsistencias(String horaProgramada) throws Exception; public JSONArray obtenerAsistencias(String horaProgramada) throws Exception;
public JSONObject actualizarSalida() throws Exception;
public JSONObject actualizarSalida(String horaSalida) throws Exception; public JSONObject actualizarSalida(String horaSalida) throws Exception;
public JSONArray obtenerSalidasNuevas() throws Exception;
public JSONArray obtenerPersonalNuevoSinSalida() throws Exception;
public JSONObject asignarHorarioSalida() throws Exception; public JSONObject asignarHorarioSalida() throws Exception;
} }
...@@ -7,7 +7,6 @@ package salidasautomaticas.mysqldao; ...@@ -7,7 +7,6 @@ package salidasautomaticas.mysqldao;
import java.sql.Connection; import java.sql.Connection;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime;
import java.util.Iterator; import java.util.Iterator;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -22,8 +21,12 @@ public class SalidasMysqlDAO implements SalidasDAO { ...@@ -22,8 +21,12 @@ public class SalidasMysqlDAO implements SalidasDAO {
@Override @Override
public JSONArray obtenerHorariosSalida() throws Exception { public JSONArray obtenerHorariosSalida() throws Exception {
Connection cn = MysqlDAOFactory.obtenerConexion("nuevo"); JSONArray jsonArray = new JSONArray();
int diaSemana = obtenerDiaSemana(); int diaSemana = obtenerDiaSemana();
if(diaSemana==7) return jsonArray;
Connection cn = MysqlDAOFactory.obtenerConexion("nuevo");
String query = "SELECT {campo_salida} as salida FROM (" String query = "SELECT {campo_salida} as salida FROM ("
+ "SELECT" + "SELECT"
+ " p.salidaLV, " + " p.salidaLV, "
...@@ -33,7 +36,7 @@ public class SalidasMysqlDAO implements SalidasDAO { ...@@ -33,7 +36,7 @@ public class SalidasMysqlDAO implements SalidasDAO {
+ "INNER JOIN personal p ON a.codper = p.codper " + "INNER JOIN personal p ON a.codper = p.codper "
+ "INNER JOIN salidas_update su ON p.codcargo = su.codcargo " + "INNER JOIN salidas_update su ON p.codcargo = su.codcargo "
+ "WHERE " + "WHERE "
+ " a.fecha_asis BETWEEN '2018-04-07' AND '2018-04-07' " + " a.fecha_asis=? "
+ "AND p.retirado = 0 " + "AND p.retirado = 0 "
+ "AND p.horaing = su.horaLV " + "AND p.horaing = su.horaLV "
+ "AND p.mining = su.minutoLV " + "AND p.mining = su.minutoLV "
...@@ -50,7 +53,11 @@ public class SalidasMysqlDAO implements SalidasDAO { ...@@ -50,7 +53,11 @@ public class SalidasMysqlDAO implements SalidasDAO {
} else if (diaSemana == 6) { } else if (diaSemana == 6) {
query = query.replaceAll("\\{campo_salida\\}", "tabla.salidaS"); query = query.replaceAll("\\{campo_salida\\}", "tabla.salidaS");
} }
JSONArray jsonArray = EstandarDAO.getInstance().consultar(cn, query);
JSONArray parametros = new JSONArray();
parametros.put(getFechaHoy());
jsonArray = EstandarDAO.getInstance().consultar(cn, query, parametros);
return jsonArray; return jsonArray;
} }
...@@ -104,7 +111,7 @@ public class SalidasMysqlDAO implements SalidasDAO { ...@@ -104,7 +111,7 @@ public class SalidasMysqlDAO implements SalidasDAO {
+ " asistencia.horasal = '' " + " asistencia.horasal = '' "
+ "AND asistencia.minsal = '' " + "AND asistencia.minsal = '' "
+ "AND ( {campo_salida} <= ? AND asistencia.fecha_asis='{fecha_hoy}' " + "AND ( {campo_salida} <= ? AND asistencia.fecha_asis='{fecha_hoy}' "
+ "OR asistencia.fecha_asis BETWEEN '2018-04-01' AND '{fecha_ayer}') " + "OR asistencia.fecha_asis BETWEEN '{fecha_partida}' AND '{fecha_ayer}') "
+ "AND {campo_salida} is not NULL " + "AND {campo_salida} is not NULL "
+ "AND NOT personal.codlocal IN ('L035', 'L053', 'L038') " + "AND NOT personal.codlocal IN ('L035', 'L053', 'L038') "
+ "AND NOT personal.codcargo IN (71, 13) " + "AND NOT personal.codcargo IN (71, 13) "
...@@ -118,8 +125,11 @@ public class SalidasMysqlDAO implements SalidasDAO { ...@@ -118,8 +125,11 @@ public class SalidasMysqlDAO implements SalidasDAO {
+ "when (WEEKDAY(asistencia.fecha_asis) + 1)=6 then salidaS end " + "when (WEEKDAY(asistencia.fecha_asis) + 1)=6 then salidaS end "
+ ") "; + ") ";
String fechaPartida = "2018-04-01";
query = query.replaceAll("\\{campo_salida\\}", campoSalida); query = query.replaceAll("\\{campo_salida\\}", campoSalida);
query = query.replaceAll("\\{fecha_hoy\\}", getFechaHoy()); query = query.replaceAll("\\{fecha_hoy\\}", getFechaHoy());
query = query.replaceAll("\\{fecha_partida\\}", fechaPartida);
query = query.replaceAll("\\{fecha_ayer\\}", getFechaAyer()); query = query.replaceAll("\\{fecha_ayer\\}", getFechaAyer());
JSONArray parametros = new JSONArray(); JSONArray parametros = new JSONArray();
...@@ -131,67 +141,6 @@ public class SalidasMysqlDAO implements SalidasDAO { ...@@ -131,67 +141,6 @@ public class SalidasMysqlDAO implements SalidasDAO {
} }
@Override @Override
public JSONObject actualizarSalida() throws Exception {
JSONObject resultado = null;
Connection cn = MysqlDAOFactory.obtenerConexion("nuevo");
LocalTime horaSistema = LocalTime.now();
int cantMinSistema = horaSistema.getHour() * 60 + horaSistema.getMinute();
JSONArray listadoHoras = obtenerHorariosSalida();
System.out.println("listadoHoras " + listadoHoras);
for (Iterator iterator = listadoHoras.iterator(); iterator.hasNext();) {
System.out.println("" + 1);
int aleatorioHora = 0, aleatorioMin = 0;
JSONObject objHora = (JSONObject) iterator.next();
System.out.println("objHora " + objHora);
String[] splitHora = objHora.getString("salida").split(":");
int cantidadMin = Integer.parseInt(splitHora[0]) * 60 + Integer.parseInt(splitHora[1]);
if (cantidadMin > cantMinSistema) {
//Reprogramacion
System.out.println("Me reprogramo");
} else {
System.out.println("Programo");
JSONArray listadoProgramar = obtenerAsistencias(objHora.getString("salida"));
System.out.println("listadoProgrmar " + listadoProgramar);
for (Iterator iterator1 = listadoProgramar.iterator(); iterator1.hasNext();) {
JSONObject objPrograma = (JSONObject) iterator1.next();
String[] splitHoraConsulta = objPrograma.getString("salidaLV").split(":");
int min = Integer.parseInt(splitHoraConsulta[1]);
int hora = Integer.parseInt(splitHoraConsulta[0]);
System.out.println("obj " + objPrograma);
//Actualizacion de salidas
if (min == 0) {
aleatorioHora = (int) Math.floor(Math.random() * (hora - (hora - 1) + 1) + (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() * (59 - 56 + 1) + 56);
}
String queryPersonal = "update asistencia set horasal= ?,minsal=? where codasis=? ";
JSONArray parametros = new JSONArray();
parametros.put(aleatorioHora);
parametros.put(aleatorioMin);
parametros.put(objPrograma.getString("codasis"));
// System.out.println("consulta "+queryPersonal+ " "+parametros);
resultado = EstandarDAO.getInstance().ejecutar(cn, queryPersonal, parametros);
System.out.println("Resultado updates =" + resultado);
}
}
}
return resultado;
}
@Override
public JSONObject actualizarSalida(String horaSalida) throws Exception { public JSONObject actualizarSalida(String horaSalida) throws Exception {
JSONObject resultado = null; JSONObject resultado = null;
Connection cn = MysqlDAOFactory.obtenerConexion("nuevo"); Connection cn = MysqlDAOFactory.obtenerConexion("nuevo");
...@@ -216,9 +165,10 @@ public class SalidasMysqlDAO implements SalidasDAO { ...@@ -216,9 +165,10 @@ public class SalidasMysqlDAO implements SalidasDAO {
String queryPersonal = "update asistencia set horasal= ?,minsal=? where codasis=? "; String queryPersonal = "update asistencia set horasal= ?,minsal=? where codasis=? ";
JSONArray parametros = new JSONArray(); JSONArray parametros = new JSONArray();
parametros.put(aleatorioHora); parametros
parametros.put(aleatorioMin); .put(aleatorioHora)
parametros.put(asistencia.getString("codasis")); .put(aleatorioMin)
.put(asistencia.getString("codasis"));
resultado = EstandarDAO.getInstance().ejecutar(cn, queryPersonal, parametros); resultado = EstandarDAO.getInstance().ejecutar(cn, queryPersonal, parametros);
System.out.println("Asistencia actualizada"); System.out.println("Asistencia actualizada");
...@@ -274,49 +224,6 @@ public class SalidasMysqlDAO implements SalidasDAO { ...@@ -274,49 +224,6 @@ public class SalidasMysqlDAO implements SalidasDAO {
} }
@Override @Override
public JSONArray obtenerSalidasNuevas() throws Exception {
Connection cn = MysqlDAOFactory.obtenerConexion("nuevo");
String query = "select tabla1.* from (SELECT codper,dni,apellido,nombre,horaing,mining,horaingsabado,miningsabado,codcargo FROM personal WHERE retirado=0 and "
+ "NOT codlocal in('L035','L053','L038') AND NOT pronoe=1 AND not codcargo in (71,13) and horaing < 19 order by codcargo) as tabla1 "
+ "left join (SELECT "
+ " p.codper "
+ "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 ORDER BY p.codcargo) as tabla2 "
+ "on tabla1.codper=tabla2.codper where tabla2.codper is null";
JSONArray jsonArray = EstandarDAO.getInstance().consultar(cn, query);
return jsonArray;
}
@Override
public JSONArray obtenerPersonalNuevoSinSalida() throws Exception {
Connection cn = MysqlDAOFactory.obtenerConexion("nuevo");
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 ";
JSONArray jsonArray = EstandarDAO.getInstance().consultar(cn, query);
return jsonArray;
}
@Override
public JSONObject asignarHorarioSalida() throws Exception { public JSONObject asignarHorarioSalida() throws Exception {
Connection cn = MysqlDAOFactory.obtenerConexion("nuevo"); Connection cn = MysqlDAOFactory.obtenerConexion("nuevo");
String query = "update personal p, " String query = "update personal p, "
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
package salidasautomaticas.schedule; package salidasautomaticas.schedule;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.Timer; import java.util.Timer;
...@@ -38,7 +37,7 @@ public class ProgramarSalidasTask extends TimerTask { ...@@ -38,7 +37,7 @@ public class ProgramarSalidasTask extends TimerTask {
System.out.println("Listando horarios " + listaHorarios + "\n"); System.out.println("Listando horarios " + listaHorarios + "\n");
Timer timer; Timer timer;
ActualizarSalidaTask task; TimerTask task;
for(Iterator it = listaHorarios.iterator(); it.hasNext();) { for(Iterator it = listaHorarios.iterator(); it.hasNext();) {
JSONObject obj = (JSONObject) it.next(); JSONObject obj = (JSONObject) it.next();
String horaSalida = obj.getString("salida"); String horaSalida = obj.getString("salida");
......
...@@ -26,16 +26,6 @@ public class SalidasServices { ...@@ -26,16 +26,6 @@ public class SalidasServices {
return listaHorarios; return listaHorarios;
} }
public JSONObject actualizarSalidas() {
JSONObject valor = new JSONObject();
try {
valor = salidadao.actualizarSalida();
} catch (Exception e) {
e.printStackTrace();
}
return valor;
}
public JSONObject actualizarSalidas(String horaSalida) { public JSONObject actualizarSalidas(String horaSalida) {
JSONObject valor = new JSONObject(); JSONObject valor = new JSONObject();
try { try {
...@@ -46,27 +36,6 @@ public class SalidasServices { ...@@ -46,27 +36,6 @@ public class SalidasServices {
return valor; return valor;
} }
public JSONArray obtenerSalidasNuevas() {
JSONArray valor = new JSONArray();
try {
valor = salidadao.obtenerSalidasNuevas();
} catch (Exception e) {
e.printStackTrace();
}
return valor;
}
public JSONArray obtenerPersonalNuevoSinSalida() {
JSONArray valor = new JSONArray();
try {
valor = salidadao.obtenerPersonalNuevoSinSalida();
} catch (Exception e) {
e.printStackTrace();
}
return valor;
}
public JSONObject asignarHorarioSalida(){ public JSONObject asignarHorarioSalida(){
JSONObject valor = new JSONObject(); JSONObject valor = new JSONObject();
try { try {
......
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