Commit 81d9c6bb by Billy Larru

modificacion de query

parent a45ef710
......@@ -24,31 +24,31 @@ public class SalidasMysqlDAO implements SalidasDAO {
public JSONArray obtenerHorariosSalida() throws Exception {
Connection cn = MysqlDAOFactory.obtenerConexion("nuevo");
int diaSemana = obtenerDiaSemana();
String query = "SELECT ? as salida FROM (\n"
+ "SELECT\n"
+ " p.salidaLV,\n"
+ " p.salidaS\n"
+ "FROM\n"
+ " asistencia a\n"
+ "INNER JOIN personal p ON a.codper = p.codper\n"
+ "INNER JOIN salidas_update su ON p.codcargo = su.codcargo\n"
+ "WHERE\n"
+ " a.fecha_asis BETWEEN '2018-04-03' AND '2018-04-05'\n"
+ "AND p.retirado = 0\n"
+ "AND p.horaing = su.horaLV\n"
+ "AND p.mining = su.minutoLV\n"
+ "AND p.horaingsabado = su.sabadoLV\n"
+ "AND p.miningsabado = su.sabadoS\n"
+ "AND NOT p.codlocal IN ('L035', 'L053', 'L038')\n"
+ "AND NOT p.pronoe = 1\n"
+ "AND NOT p.codcargo IN (71, 13)\n"
+ "AND NOT p.horaing > 19\n"
+ "AND NOT p.salidaS = '') as tabla WHERE NULLIF( ? , '') is NOT null GROUP BY ? ";
String query = "SELECT {campo_salida} as salida FROM ("
+ "SELECT"
+ " p.salidaLV, "
+ " p.salidaS "
+ "FROM"
+ " asistencia a "
+ "INNER JOIN personal p ON a.codper = p.codper "
+ "INNER JOIN salidas_update su ON p.codcargo = su.codcargo "
+ "WHERE "
+ " a.fecha_asis BETWEEN '2018-04-03' AND '2018-04-05' "
+ "AND p.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 p.pronoe = 1 "
+ "AND NOT p.codcargo IN (71, 13) "
+ "AND NOT p.horaing > 19 "
+ "AND NOT p.salidaS = '') as tabla WHERE NULLIF( {campo_salida} , '') is NOT null GROUP BY {campo_salida} ";
if (diaSemana >= 1 && diaSemana <= 5) {
query = query.replaceAll("\\?", "tabla.salidaLV");
query = query.replaceAll("\\{campo_salida\\}", "tabla.salidaLV");
} else if (diaSemana == 6) {
query = query.replaceAll("\\?", "tabla.salidaS");
query = query.replaceAll("\\{campo_salida\\}", "tabla.salidaS");
}
JSONArray jsonArray = EstandarDAO.getInstance().consultar(cn, query);
......@@ -62,36 +62,55 @@ public class SalidasMysqlDAO implements SalidasDAO {
return diaSemana;
}
private String getFechaHoy(){
String fechaHoy;
LocalDate date = LocalDate.now();
int anio = date.getYear();
int mes = date.getMonthValue();
int dia = date.getDayOfMonth();
fechaHoy = String.format("%s-%02d-%02d", anio, mes, dia);
return fechaHoy;
}
@Override
public JSONArray obtenerAsistencias(String horaProgramada) throws Exception {
Connection cn = MysqlDAOFactory.obtenerConexion("nuevo");
int diaSemana = obtenerDiaSemana();
String query = "SELECT\n"
+ " asistencia.codasis,\n"
+ "asistencia.fecha_asis,\n"
+ "(WEEKDAY(asistencia.fecha_asis) + 1) AS numDia,\n"
+ "{campo_salida} as salida \n"
+ "FROM\n"
+ " asistencia\n"
+ "INNER JOIN personal ON asistencia.codper = personal.codper\n"
+ "WHERE\n"
+ " asistencia.horasal = ''\n"
+ "AND asistencia.minsal = ''\n"
+ "AND ( {campo_salida} <= ? AND asistencia.fecha_asis='2018-04-05'\n"
+ "OR asistencia.fecha_asis BETWEEN '2018-03-31' AND '2018-04-04')\n"
+ "AND {campo_salida} is not NULL \n"
String query = "SELECT "
+ " asistencia.codasis, "
+ "asistencia.fecha_asis, "
+ "{campo_salida} as salida "
+ "FROM "
+ " asistencia "
+ "INNER JOIN personal ON asistencia.codper = personal.codper "
+ "WHERE "
+ " asistencia.horasal = '' "
+ "AND asistencia.minsal = '' "
+ "AND ( {campo_salida} <= ? AND asistencia.fecha_asis='{fecha_hoy}' "
+ "OR asistencia.fecha_asis BETWEEN '2018-03-31' AND '{fecha_hoy}') "
+ "AND {campo_salida} is not NULL "
+ "AND NOT personal.codlocal IN ('L035', 'L053', 'L038') "
+ "AND NOT personal.codcargo IN (71, 13) "
+ "AND NOT p.pronoe = 1 "
+ "AND (WEEKDAY(asistencia.fecha_asis) + 1) !=7 AND personal.retirado=0 ";
if (diaSemana >= 1 && diaSemana <= 5) {
query = query.replaceAll("\\{campo_salida\\}", "personal.salidaLV");
} else if (diaSemana == 6) {
query = query.replaceAll("\\{campo_salida\\}", "personal.salidaS");
}
String campoSalida = "("
+ "case "
+ "when (WEEKDAY(asistencia.fecha_asis) + 1)<6 then salidaLV "
+ "when (WEEKDAY(asistencia.fecha_asis) + 1)=6 then salidaS end "
+ ") ";
query = query.replaceAll("\\{campo_salida\\}", campoSalida);
query = query.replaceAll("\\{fecha_hoy\\}", getFechaHoy());
JSONArray parametros = new JSONArray();
parametros.put(horaProgramada);
JSONArray jsonArray = EstandarDAO.getInstance().consultar(cn, query, parametros);
return jsonArray;
......@@ -150,7 +169,7 @@ public class SalidasMysqlDAO implements SalidasDAO {
parametros.put(objPrograma.getString("codasis"));
// System.out.println("consulta "+queryPersonal+ " "+parametros);
resultado = EstandarDAO.getInstance().ejecutar(cn, queryPersonal, parametros);
System.out.println("Resultado updates ="+resultado);
System.out.println("Resultado updates =" + resultado);
}
}
}
......@@ -164,10 +183,10 @@ public class SalidasMysqlDAO implements SalidasDAO {
Connection cn = MysqlDAOFactory.obtenerConexion("nuevo");
int aleatorioHora = 0, aleatorioMin = 0;
JSONArray listaAsistencias = obtenerAsistencias("17:00");
System.out.println("lista de asistencias para actualizar "+horaSalida + " "+listaAsistencias);
System.out.println("lista de asistencias para actualizar " + horaSalida + " " + listaAsistencias);
for (Iterator it = listaAsistencias.iterator(); it.hasNext();) {
JSONObject asistencia = (JSONObject) it.next();
......
......@@ -32,7 +32,7 @@ public class ProgramarSalidasTask extends TimerTask {
try {
// JSONArray listaHorarios = service.obtenerHorariosSalida();
JSONArray listaHorarios = new JSONArray();
String[] arraySalidas = {"15:28", "14:46", "14:50", "17:00", "17:30", "18:00"};
String[] arraySalidas = {"17:08", "14:46", "14:50", "17:00", "17:30", "18:00"};
for (String salida : arraySalidas) {
listaHorarios.put(new JSONObject().put("salida", salida));
......
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