Commit f6b7360a by Billy Larru

apuntando a la base de datos real

parent 2c7ca7d5
package salidasautomaticas.main;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.stream.Collectors;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -13,9 +16,10 @@ import salidasautomaticas.schedule.ProgramarSalidasTask;
import salidasautomaticas.util.Metodos;
public class Main {
private static final Logger log = LogManager.getLogger(Main.class);
public static void main(String[] args){
public static void main(String[] args) {
setLogLevel(Level.TRACE);//DESARROLLO
// setLogLevel(Level.INFO);//PRODUCCION
log.info("Inicializando programa [Salidas Automaticas]...");
......@@ -27,9 +31,8 @@ public class Main {
Timer timer = new Timer();
timer.schedule(task , horaInicio, periodo);
}
private static void setLogLevel(Level l) {
private static void setLogLevel(Level l) {
log.info("Setting log level to " + l.name());
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration conf = ctx.getConfiguration();
......
......@@ -29,6 +29,10 @@ public class MysqlDAOFactory extends DAOFactory {
Connection conexion = null;
if (base.equals("nuevo")) {
try {
// conexion = DriverManager.getConnection(
// "jdbc:mysql://172.16.2.39:3306/nuevo",
// "melani",
// "melani");
conexion = DriverManager.getConnection(
"jdbc:mysql://172.16.2.39:3306/nuevo",
"melani",
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package salidasautomaticas.mysqldao;
import java.sql.Connection;
import java.sql.DriverManager;
import salidasautomaticas.dao.DAOFactory;
import salidasautomaticas.dao.SalidasDAO;
/**
*
* @author sistem08user
*/
public class Prueba extends DAOFactory {
static {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection obtenerConexion(String base) {
Connection conexion = null;
if (base.equals("nuevo")) {
try {
// conexion = DriverManager.getConnection(
// "jdbc:mysql://172.16.2.39:3306/nuevo",
// "melani",
// "melani");
conexion = DriverManager.getConnection("jdbc:sqlserver://localhost:1433; databaseName=prueba; user=sa; password=Saco1357$;");
} catch (Exception e) {
e.printStackTrace();
}
}
return conexion;
}
@Override
public SalidasDAO getSalidasDAO() {
return new SalidasMysqlDAO();
}
}
......@@ -8,6 +8,7 @@ package salidasautomaticas.mysqldao;
import java.sql.Connection;
import java.time.LocalDate;
import java.util.Iterator;
import java.util.logging.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.JSONArray;
......@@ -45,7 +46,7 @@ public class SalidasMysqlDAO implements SalidasDAO {
+ "estado in (1, 2, 5) "//Que sean asistencias 1=Asistio, 2=No marco y 5=Tardanza
+ "AND p.codtipo!=3 "//Que registren asistencia
+ "AND a.fecha_asis=? "
+ "AND p.retirado = 0 "
// + "AND p.retirado = 0 "
// + "AND p.horaing = su.horaLV "
// + "AND p.mining = su.minutoLV "
// + "AND p.horaingsabado = su.sabadoLV "
......@@ -65,7 +66,7 @@ public class SalidasMysqlDAO implements SalidasDAO {
JSONArray parametrosQuery = new JSONArray();
parametrosQuery.put(getFechaHoy());
jsonArray = EstandarDAO.getInstance().consultar(cn, query, parametrosQuery);
return jsonArray;
......@@ -109,7 +110,7 @@ public class SalidasMysqlDAO implements SalidasDAO {
public JSONArray obtenerAsistencias(String horaProgramada) throws Exception {
Connection cn = MysqlDAOFactory.obtenerConexion("nuevo");
String fechaPartida = "2018-01-01";
String fechaPartida = "2018-03-01";
String query = "SELECT * from "
+ "(select "
......@@ -133,7 +134,8 @@ public class SalidasMysqlDAO implements SalidasDAO {
+ "AND asistencia.estado in (1, 2, 5) "//Que sean asistio, tardanza y no marco
// + "AND personal.tmp_id not in (99998, 9998, 99999, 9888) "//Que esten en planilla
+ "AND personal.codtipo!=3 "//Que si registren asistencia
+ "AND personal.retirado=0) as tabla "
// + "AND personal.retirado=0) as tabla "
+ ") as tabla "
+ "where tabla.salida!=''";
String campoSalida = "("
......@@ -250,4 +252,17 @@ public class SalidasMysqlDAO implements SalidasDAO {
return aleatorio;
}
public static void main(String[] args) {
SalidasMysqlDAO dao = new SalidasMysqlDAO();
try {
JSONObject a = dao.actualizarSalida("17:30");
System.out.println(a);
// System.out.println(a.length());
} catch (Exception ex) {
java.util.logging.Logger.getLogger(SalidasMysqlDAO.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
\ No newline at end of file
......@@ -79,7 +79,7 @@ public class EstandarDAO {
//Recorremos la lista de parametros y lo seteamos en el preparedstatement
for (Object parametro : params) {
castingPS(ps, cont, parametro);
setPreparedStatement(ps, cont, parametro);
cont++;
}
}
......@@ -99,7 +99,6 @@ public class EstandarDAO {
// rs.close();
// cn.close();
}
} catch (Exception ex) {
log.error("error", ex);
......@@ -127,12 +126,11 @@ public class EstandarDAO {
obj.put("msg", 0);
} else {
PreparedStatement ps = cn.prepareStatement(query);
if (parametros != null && parametros.length > 0) {
JSONArray params = parametros[0];
int cont = 1;
for (Object parametro : params) {
castingPS(ps, cont, parametro);
setPreparedStatement(ps, cont, parametro);
cont++;
}
}
......@@ -144,7 +142,6 @@ public class EstandarDAO {
} else {
obj.put("msg", 0);
}
// cn.close();
}
} catch (Exception ex) {
log.error("error", ex);
......@@ -162,7 +159,7 @@ public class EstandarDAO {
* @param p parametro de la consulta sql
* @throws SQLException
*/
private void castingPS(PreparedStatement ps, int index, Object p) throws SQLException {
private void setPreparedStatement(PreparedStatement ps, int index, Object p) throws SQLException {
if (p instanceof Integer) {
ps.setInt(index, (int) p);
} else if (p instanceof String) {
......
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