Commit c719526b by Billy Larru

obteniendo salidas nuevas

parent 21651919
...@@ -18,4 +18,7 @@ public interface SalidasDAO { ...@@ -18,4 +18,7 @@ public interface SalidasDAO {
public JSONArray obtenerAsistencias(String horaProgramada) throws Exception; public JSONArray obtenerAsistencias(String horaProgramada) throws Exception;
public JSONObject actualizarSalida() 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(JSONArray listaPersonalNuevo) throws Exception;
} }
...@@ -9,6 +9,8 @@ import java.sql.Connection; ...@@ -9,6 +9,8 @@ import java.sql.Connection;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.Iterator; import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import salidasautomaticas.dao.SalidasDAO; import salidasautomaticas.dao.SalidasDAO;
...@@ -33,8 +35,8 @@ public class SalidasMysqlDAO implements SalidasDAO { ...@@ -33,8 +35,8 @@ 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-03' AND '2018-04-05' " + " a.fecha_asis BETWEEN '2018-04-07' AND '2018-04-07' "
+ "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 "
+ "AND p.horaingsabado = su.sabadoLV " + "AND p.horaingsabado = su.sabadoLV "
...@@ -62,36 +64,32 @@ public class SalidasMysqlDAO implements SalidasDAO { ...@@ -62,36 +64,32 @@ public class SalidasMysqlDAO implements SalidasDAO {
return diaSemana; return diaSemana;
} }
private String getFechaHoy(){ private String getFechaHoy() {
String fechaHoy; String fechaHoy;
LocalDate date = LocalDate.now(); LocalDate date = LocalDate.now();
int anio = date.getYear(); int anio = date.getYear();
int mes = date.getMonthValue(); int mes = date.getMonthValue();
int dia = date.getDayOfMonth(); int dia = date.getDayOfMonth();
fechaHoy = String.format("%s-%02d-%02d", anio, mes, dia); fechaHoy = String.format("%s-%02d-%02d", anio, mes, dia);
return fechaHoy; return fechaHoy;
} }
private String getFechaAyer() {
private String getFechaAyer(){
String fechaAyer; String fechaAyer;
LocalDate date = LocalDate.now(); LocalDate date = LocalDate.now();
date.plusDays(-1); date = date.minusDays(1);
int anio = date.getYear(); int anio = date.getYear();
int mes = date.getMonthValue(); int mes = date.getMonthValue();
int dia = date.getDayOfMonth(); int dia = date.getDayOfMonth();
fechaAyer = String.format("%s-%02d-%02d", anio, mes, dia); fechaAyer = String.format("%s-%02d-%02d", anio, mes, dia);
return fechaAyer; return fechaAyer;
} }
@Override @Override
public JSONArray obtenerAsistencias(String horaProgramada) throws Exception { public JSONArray obtenerAsistencias(String horaProgramada) throws Exception {
...@@ -108,7 +106,7 @@ public class SalidasMysqlDAO implements SalidasDAO { ...@@ -108,7 +106,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-03-17' AND '{fecha_ayer}') " + "OR asistencia.fecha_asis BETWEEN '2018-04-01' 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) "
...@@ -125,8 +123,7 @@ public class SalidasMysqlDAO implements SalidasDAO { ...@@ -125,8 +123,7 @@ public class SalidasMysqlDAO implements SalidasDAO {
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_ayer\\}", getFechaAyer()); query = query.replaceAll("\\{fecha_ayer\\}", getFechaAyer());
JSONArray parametros = new JSONArray(); JSONArray parametros = new JSONArray();
parametros.put(horaProgramada); parametros.put(horaProgramada);
...@@ -204,25 +201,24 @@ public class SalidasMysqlDAO implements SalidasDAO { ...@@ -204,25 +201,24 @@ public class SalidasMysqlDAO implements SalidasDAO {
int aleatorioHora = 0, aleatorioMin = 0; int aleatorioHora = 0, aleatorioMin = 0;
JSONArray listaAsistencias = obtenerAsistencias("17:00"); JSONArray listaAsistencias = obtenerAsistencias("17:00");
System.out.println("tamaño lista=" + listaAsistencias.length());
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();) { for (Iterator it = listaAsistencias.iterator(); it.hasNext();) {
JSONObject asistencia = (JSONObject) it.next(); JSONObject asistencia = (JSONObject) it.next();
String salidaPersonal = asistencia.getString("salida"); String salidaPersonal = asistencia.getString("salida");
// if(salidaPersonal==null || salidaPersonal.isEmpty()){ // if(salidaPersonal==null || salidaPersonal.isEmpty()){
// continue; // continue;
// } // }
String[] splitHoraConsulta = salidaPersonal.split(":"); String[] splitHoraConsulta = salidaPersonal.split(":");
int min = Integer.parseInt(splitHoraConsulta[1]); int min = Integer.parseInt(splitHoraConsulta[1]);
int hora = Integer.parseInt(splitHoraConsulta[0]); int hora = Integer.parseInt(splitHoraConsulta[0]);
System.out.println("obj " + asistencia); System.out.println("obj " + asistencia);
//Actualizacion de salidas //Actualizacion de salidas
if (min == 0) { if (min == 0) {
aleatorioHora = (int) Math.floor(Math.random() * (hora - (hora - 1) + 1) + (hora - 1)); aleatorioHora = (int) Math.floor(Math.random() * 2 + (hora - 1));
} else { } else {
aleatorioHora = hora; aleatorioHora = hora;
} }
...@@ -233,7 +229,7 @@ public class SalidasMysqlDAO implements SalidasDAO { ...@@ -233,7 +229,7 @@ public class SalidasMysqlDAO implements SalidasDAO {
aleatorioMin = (int) Math.floor(Math.random() * (33 - 27 + 1) + 27); aleatorioMin = (int) Math.floor(Math.random() * (33 - 27 + 1) + 27);
} }
} else { } else {
aleatorioMin = (int) Math.floor(Math.random() * (59 - 56 + 1) + 56); aleatorioMin = (int) Math.floor(Math.random() * 3 + 57);
} }
String queryPersonal = "update asistencia set horasal= ?,minsal=? where codasis=? "; String queryPersonal = "update asistencia set horasal= ?,minsal=? where codasis=? ";
...@@ -248,4 +244,70 @@ public class SalidasMysqlDAO implements SalidasDAO { ...@@ -248,4 +244,70 @@ public class SalidasMysqlDAO implements SalidasDAO {
return resultado; return resultado;
} }
public static void main(String[] args) {
SalidasMysqlDAO s = new SalidasMysqlDAO();
// try {
// JSONObject obj = s.actualizarSalida("17:00");
// System.out.println(obj);
// } catch (Exception ex) {
// Logger.getLogger(SalidasMysqlDAO.class.getName()).log(Level.SEVERE, null, ex);
// }
System.out.println(s.getFechaAyer());
}
@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(JSONArray listaPersonalNuevo) throws Exception {
Connection cn = MysqlDAOFactory.obtenerConexion("nuevo");
String query = "UPDATE personal SET salidaLV=?,salidaS=? WHERE codper=?;";
JSONObject jsonArray = EstandarDAO.getInstance().consultar(cn, query);
return jsonArray;
}
} }
...@@ -7,6 +7,7 @@ package salidasautomaticas.schedule; ...@@ -7,6 +7,7 @@ package salidasautomaticas.schedule;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import salidasautomaticas.services.SalidasServices; import salidasautomaticas.services.SalidasServices;
...@@ -29,6 +30,11 @@ public class ActualizarSalidaTask extends TimerTask{ ...@@ -29,6 +30,11 @@ public class ActualizarSalidaTask extends TimerTask{
public void run() { public void run() {
System.out.println("Ejecutando salida "+horaSalida); System.out.println("Ejecutando salida "+horaSalida);
JSONObject objJSON= services.actualizarSalidas(horaSalida); JSONObject objJSON= services.actualizarSalidas(horaSalida);
JSONArray objNuevasSalidas = services.obtenerSalidasNuevas();
JSONArray objPersonalSinSalida = services.obtenerPersonalNuevoSinSalida();
System.out.println("Matando timer "+timer); System.out.println("Matando timer "+timer);
timer.cancel(); timer.cancel();
} }
......
...@@ -32,7 +32,7 @@ public class ProgramarSalidasTask extends TimerTask { ...@@ -32,7 +32,7 @@ public class ProgramarSalidasTask extends TimerTask {
try { try {
// JSONArray listaHorarios = service.obtenerHorariosSalida(); // JSONArray listaHorarios = service.obtenerHorariosSalida();
JSONArray listaHorarios = new JSONArray(); JSONArray listaHorarios = new JSONArray();
String[] arraySalidas = {"12:59", "14:46", "14:50", "17:00", "17:30", "18:00"}; String[] arraySalidas = {"18:39", "14:46", "14:50", "17:00", "17:30", "18:00"};
for (String salida : arraySalidas) { for (String salida : arraySalidas) {
listaHorarios.put(new JSONObject().put("salida", salida)); listaHorarios.put(new JSONObject().put("salida", salida));
......
package salidasautomaticas.services; package salidasautomaticas.services;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import salidasautomaticas.dao.DAOFactory; import salidasautomaticas.dao.DAOFactory;
...@@ -11,9 +10,10 @@ import salidasautomaticas.dao.SalidasDAO; ...@@ -11,9 +10,10 @@ import salidasautomaticas.dao.SalidasDAO;
* @author sistem19user * @author sistem19user
*/ */
public class SalidasServices { public class SalidasServices {
DAOFactory daofactory = DAOFactory.getFactory(DAOFactory.MYSQL); DAOFactory daofactory = DAOFactory.getFactory(DAOFactory.MYSQL);
SalidasDAO salidadao = daofactory.getSalidasDAO(); SalidasDAO salidadao = daofactory.getSalidasDAO();
public JSONArray obtenerHorariosSalida() throws Exception { public JSONArray obtenerHorariosSalida() throws Exception {
JSONArray listaHorarios = null; JSONArray listaHorarios = null;
...@@ -25,26 +25,45 @@ public class SalidasServices { ...@@ -25,26 +25,45 @@ public class SalidasServices {
return listaHorarios; return listaHorarios;
} }
public JSONObject actualizarSalidas(){ public JSONObject actualizarSalidas() {
JSONObject valor=new JSONObject(); JSONObject valor = new JSONObject();
try {
valor = salidadao.actualizarSalida();
} catch (Exception e) {
e.printStackTrace();
}
return valor;
}
public JSONObject actualizarSalidas(String horaSalida) {
JSONObject valor = new JSONObject();
try {
valor = salidadao.actualizarSalida(horaSalida);
} catch (Exception e) {
e.printStackTrace();
}
return valor;
}
public JSONArray obtenerSalidasNuevas() {
JSONArray valor = new JSONArray();
try { try {
valor=salidadao.actualizarSalida(); valor = salidadao.obtenerSalidasNuevas();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return valor; return valor;
} }
public JSONArray obtenerPersonalNuevoSinSalida() {
public JSONObject actualizarSalidas(String horaSalida){ JSONArray valor = new JSONArray();
JSONObject valor=new JSONObject();
try { try {
valor=salidadao.actualizarSalida(horaSalida); valor = salidadao.obtenerPersonalNuevoSinSalida();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return valor; return valor;
} }
} }
...@@ -77,7 +77,7 @@ public class EstandarDAO { ...@@ -77,7 +77,7 @@ public class EstandarDAO {
cont++; cont++;
} }
} }
System.out.println("query "+ps); System.out.println("query [SELECT] ="+ps);
ResultSet rs = ps.executeQuery(); ResultSet rs = ps.executeQuery();
ResultSetMetaData rm = rs.getMetaData(); ResultSetMetaData rm = rs.getMetaData();
......
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