Commit c719526b by Billy Larru

obteniendo salidas nuevas

parent 21651919
......@@ -18,4 +18,7 @@ public interface SalidasDAO {
public JSONArray obtenerAsistencias(String horaProgramada) throws Exception;
public JSONObject actualizarSalida() 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;
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;
......@@ -33,7 +35,7 @@ public class SalidasMysqlDAO implements SalidasDAO {
+ "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' "
+ " a.fecha_asis BETWEEN '2018-04-07' AND '2018-04-07' "
+ "AND p.retirado = 0 "
+ "AND p.horaing = su.horaLV "
+ "AND p.mining = su.minutoLV "
......@@ -63,7 +65,7 @@ public class SalidasMysqlDAO implements SalidasDAO {
return diaSemana;
}
private String getFechaHoy(){
private String getFechaHoy() {
String fechaHoy;
LocalDate date = LocalDate.now();
int anio = date.getYear();
......@@ -72,15 +74,13 @@ public class SalidasMysqlDAO implements SalidasDAO {
fechaHoy = String.format("%s-%02d-%02d", anio, mes, dia);
return fechaHoy;
}
private String getFechaAyer(){
private String getFechaAyer() {
String fechaAyer;
LocalDate date = LocalDate.now();
date.plusDays(-1);
date = date.minusDays(1);
int anio = date.getYear();
int mes = date.getMonthValue();
......@@ -91,8 +91,6 @@ public class SalidasMysqlDAO implements SalidasDAO {
return fechaAyer;
}
@Override
public JSONArray obtenerAsistencias(String horaProgramada) throws Exception {
Connection cn = MysqlDAOFactory.obtenerConexion("nuevo");
......@@ -108,7 +106,7 @@ public class SalidasMysqlDAO implements SalidasDAO {
+ " asistencia.horasal = '' "
+ "AND asistencia.minsal = '' "
+ "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 NOT personal.codlocal IN ('L035', 'L053', 'L038') "
+ "AND NOT personal.codcargo IN (71, 13) "
......@@ -126,7 +124,6 @@ public class SalidasMysqlDAO implements SalidasDAO {
query = query.replaceAll("\\{fecha_hoy\\}", getFechaHoy());
query = query.replaceAll("\\{fecha_ayer\\}", getFechaAyer());
JSONArray parametros = new JSONArray();
parametros.put(horaProgramada);
......@@ -204,6 +201,7 @@ public class SalidasMysqlDAO implements SalidasDAO {
int aleatorioHora = 0, aleatorioMin = 0;
JSONArray listaAsistencias = obtenerAsistencias("17:00");
System.out.println("tamaño lista=" + listaAsistencias.length());
System.out.println("lista de asistencias para actualizar " + horaSalida + " " + listaAsistencias);
for (Iterator it = listaAsistencias.iterator(); it.hasNext();) {
......@@ -214,15 +212,13 @@ 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() * (hora - (hora - 1) + 1) + (hora - 1));
aleatorioHora = (int) Math.floor(Math.random() * 2 + (hora - 1));
} else {
aleatorioHora = hora;
}
......@@ -233,7 +229,7 @@ public class SalidasMysqlDAO implements SalidasDAO {
aleatorioMin = (int) Math.floor(Math.random() * (33 - 27 + 1) + 27);
}
} 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=? ";
......@@ -248,4 +244,70 @@ public class SalidasMysqlDAO implements SalidasDAO {
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;
import java.util.Timer;
import java.util.TimerTask;
import org.json.JSONArray;
import org.json.JSONObject;
import salidasautomaticas.services.SalidasServices;
......@@ -29,6 +30,11 @@ 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();
System.out.println("Matando timer "+timer);
timer.cancel();
}
......
......@@ -32,7 +32,7 @@ public class ProgramarSalidasTask extends TimerTask {
try {
// JSONArray listaHorarios = service.obtenerHorariosSalida();
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) {
listaHorarios.put(new JSONObject().put("salida", salida));
......
package salidasautomaticas.services;
import org.json.JSONArray;
import org.json.JSONObject;
import salidasautomaticas.dao.DAOFactory;
......@@ -11,6 +10,7 @@ import salidasautomaticas.dao.SalidasDAO;
* @author sistem19user
*/
public class SalidasServices {
DAOFactory daofactory = DAOFactory.getFactory(DAOFactory.MYSQL);
SalidasDAO salidadao = daofactory.getSalidasDAO();
......@@ -26,21 +26,40 @@ public class SalidasServices {
return listaHorarios;
}
public JSONObject actualizarSalidas(){
JSONObject valor=new JSONObject();
public JSONObject actualizarSalidas() {
JSONObject valor = new JSONObject();
try {
valor=salidadao.actualizarSalida();
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 {
valor = salidadao.obtenerSalidasNuevas();
} catch (Exception e) {
e.printStackTrace();
}
return valor;
}
public JSONObject actualizarSalidas(String horaSalida){
JSONObject valor=new JSONObject();
public JSONArray obtenerPersonalNuevoSinSalida() {
JSONArray valor = new JSONArray();
try {
valor=salidadao.actualizarSalida(horaSalida);
valor = salidadao.obtenerPersonalNuevoSinSalida();
} catch (Exception e) {
e.printStackTrace();
}
......
......@@ -77,7 +77,7 @@ public class EstandarDAO {
cont++;
}
}
System.out.println("query "+ps);
System.out.println("query [SELECT] ="+ps);
ResultSet rs = ps.executeQuery();
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