Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SalidasAutomaticas
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Billy Larru
SalidasAutomaticas
Commits
a45ef710
Commit
a45ef710
authored
Apr 06, 2018
by
Billy Larru
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
programando salidas, hay datos de pruebas
parent
23767bc9
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
228 additions
and
39 deletions
+228
-39
SalidasDAO.java
src/salidasautomaticas/dao/SalidasDAO.java
+1
-0
Main.java
src/salidasautomaticas/main/Main.java
+9
-21
SalidasMysqlDAO.java
src/salidasautomaticas/mysqldao/SalidasMysqlDAO.java
+58
-10
ActualizarSalidaTask.java
src/salidasautomaticas/schedule/ActualizarSalidaTask.java
+15
-7
ProgramarSalidasTask.java
src/salidasautomaticas/schedule/ProgramarSalidasTask.java
+89
-0
SalidasServices.java
src/salidasautomaticas/services/SalidasServices.java
+12
-0
EstandarDAO.java
src/salidasautomaticas/util/EstandarDAO.java
+1
-1
Metodos.java
src/salidasautomaticas/util/Metodos.java
+43
-0
No files found.
src/salidasautomaticas/dao/SalidasDAO.java
View file @
a45ef710
...
...
@@ -17,4 +17,5 @@ public interface SalidasDAO {
public
JSONArray
obtenerHorariosSalida
()
throws
Exception
;
public
JSONArray
obtenerAsistencias
(
String
horaProgramada
)
throws
Exception
;
public
JSONObject
actualizarSalida
()
throws
Exception
;
public
JSONObject
actualizarSalida
(
String
horaSalida
)
throws
Exception
;
}
src/salidasautomaticas/main/Main.java
View file @
a45ef710
...
...
@@ -4,31 +4,19 @@ import java.util.Calendar;
import
java.util.Date
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
salidasautomaticas.schedule.Temporizador
;
import
salidasautomaticas.schedule.ProgramarSalidasTask
;
import
salidasautomaticas.util.Metodos
;
public
class
Main
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Date
horaInicio
=
new
Date
(
System
.
currentTimeMillis
());
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
horaInicio
);
// System.out.println(c.get(Calendar.DAY_OF_WEEK));
// Si la hora es posterior a las 8am se programa la alarma para el dia siguiente
if
(
c
.
get
(
Calendar
.
HOUR_OF_DAY
)
>=
22
)
{
c
.
set
(
Calendar
.
DAY_OF_YEAR
,
c
.
get
(
Calendar
.
DAY_OF_YEAR
)
+
1
);
}
c
.
set
(
Calendar
.
HOUR_OF_DAY
,
20
);
c
.
set
(
Calendar
.
MINUTE
,
18
);
c
.
set
(
Calendar
.
SECOND
,
0
);
horaInicio
=
c
.
getTime
();
public
static
void
main
(
String
[]
args
){
System
.
out
.
println
(
"Inicializando programa..."
);
Date
horaInicio
=
Metodos
.
getHoraEjecucion
(
"09:10"
);
int
periodo
=
86400000
;
//El codigo se ejecutará cada 24h, representa 24h en milisegundos
TimerTask
task
=
new
ProgramarSalidasTask
();
Timer
timer
=
new
Timer
();
// timer.schedule(new Temporizador(), horaInicio, 1);
timer
.
schedule
(
new
Temporizador
(),
0
);
timer
.
schedule
(
task
,
horaInicio
,
periodo
);
}
}
src/salidasautomaticas/mysqldao/SalidasMysqlDAO.java
View file @
a45ef710
...
...
@@ -71,25 +71,28 @@ public class SalidasMysqlDAO implements SalidasDAO {
+
" asistencia.codasis,\n"
+
"asistencia.fecha_asis,\n"
+
"(WEEKDAY(asistencia.fecha_asis) + 1) AS numDia,\n"
+
"
?
\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 (
? <='*'
AND asistencia.fecha_asis='2018-04-05'\n"
+
"OR asistencia.fecha_asis BETWEEN '2018-0
4-03
' AND '2018-04-04')\n"
+
"AND
?
is not NULL \n"
+
"AND (
{campo_salida} <= ?
AND asistencia.fecha_asis='2018-04-05'\n"
+
"OR asistencia.fecha_asis BETWEEN '2018-0
3-31
' AND '2018-04-04')\n"
+
"AND
{campo_salida}
is not NULL \n"
+
"AND (WEEKDAY(asistencia.fecha_asis) + 1) !=7 AND personal.retirado=0 "
;
if
(
diaSemana
>=
1
&&
diaSemana
<=
5
)
{
query
=
query
.
replaceAll
(
"\\
?
"
,
"personal.salidaLV"
);
query
=
query
.
replaceAll
(
"\\
{campo_salida\\}
"
,
"personal.salidaLV"
);
}
else
if
(
diaSemana
==
6
)
{
query
=
query
.
replaceAll
(
"\\
?
"
,
"personal.salidaS"
);
query
=
query
.
replaceAll
(
"\\
{campo_salida\\}
"
,
"personal.salidaS"
);
}
query
=
query
.
replaceAll
(
"\\*"
,
horaProgramada
);
JSONArray
jsonArray
=
EstandarDAO
.
getInstance
().
consultar
(
cn
,
query
);
JSONArray
parametros
=
new
JSONArray
();
parametros
.
put
(
horaProgramada
);
JSONArray
jsonArray
=
EstandarDAO
.
getInstance
().
consultar
(
cn
,
query
,
parametros
);
return
jsonArray
;
}
...
...
@@ -119,7 +122,7 @@ public class SalidasMysqlDAO implements SalidasDAO {
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
]);
...
...
@@ -147,7 +150,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
);
}
}
}
...
...
@@ -155,4 +158,49 @@ public class SalidasMysqlDAO implements SalidasDAO {
return
resultado
;
}
@Override
public
JSONObject
actualizarSalida
(
String
horaSalida
)
throws
Exception
{
JSONObject
resultado
=
null
;
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
);
for
(
Iterator
it
=
listaAsistencias
.
iterator
();
it
.
hasNext
();)
{
JSONObject
asistencia
=
(
JSONObject
)
it
.
next
();
String
[]
splitHoraConsulta
=
asistencia
.
getString
(
"salida"
).
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
));
}
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
(
asistencia
.
getString
(
"codasis"
));
// System.out.println("consulta "+queryPersonal+ " "+parametros);
resultado
=
EstandarDAO
.
getInstance
().
ejecutar
(
cn
,
queryPersonal
,
parametros
);
System
.
out
.
println
(
"Asistencia actualizada"
);
}
return
resultado
;
}
}
src/salidasautomaticas/schedule/
Temporizador
.java
→
src/salidasautomaticas/schedule/
ActualizarSalidaTask
.java
View file @
a45ef710
...
...
@@ -5,24 +5,32 @@
*/
package
salidasautomaticas
.
schedule
;
import
java.util.
Date
;
import
java.util.
Timer
;
import
java.util.TimerTask
;
import
org.json.JSONObject
;
import
salidasautomaticas.services.SalidasServices
;
/**
*
* @author sistem19user
*/
public
class
Temporizador
extends
TimerTask
{
public
class
ActualizarSalidaTask
extends
TimerTask
{
SalidasServices
services
=
new
SalidasServices
();
private
Timer
timer
;
private
String
horaSalida
;
public
ActualizarSalidaTask
(
Timer
timer
,
String
horaSalida
){
this
.
timer
=
timer
;
this
.
horaSalida
=
horaSalida
;
}
SalidasServices
service
=
new
SalidasServices
();
@Override
public
void
run
()
{
// service.actualizarSalidas(
);
System
.
out
.
println
(
"Actualizar salida"
);
cancel
(
);
System
.
out
.
println
(
"Ejecutando salida "
+
horaSalida
);
JSONObject
objJSON
=
services
.
actualizarSalidas
(
horaSalida
);
System
.
out
.
println
(
"Matando timer "
+
timer
);
timer
.
cancel
();
}
}
src/salidasautomaticas/schedule/ProgramarSalidasTask.java
0 → 100644
View file @
a45ef710
/*
* 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
.
schedule
;
import
java.time.LocalTime
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.Iterator
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
salidasautomaticas.services.SalidasServices
;
import
salidasautomaticas.util.Metodos
;
/**
*
* @author sistem19user
*/
public
class
ProgramarSalidasTask
extends
TimerTask
{
SalidasServices
service
=
new
SalidasServices
();
@Override
public
void
run
()
{
try
{
// JSONArray listaHorarios = service.obtenerHorariosSalida();
JSONArray
listaHorarios
=
new
JSONArray
();
String
[]
arraySalidas
=
{
"15:28"
,
"14:46"
,
"14:50"
,
"17:00"
,
"17:30"
,
"18:00"
};
for
(
String
salida
:
arraySalidas
)
{
listaHorarios
.
put
(
new
JSONObject
().
put
(
"salida"
,
salida
));
}
System
.
out
.
println
(
"Listando horarios "
+
listaHorarios
+
"\n"
);
Iterator
it
=
listaHorarios
.
iterator
();
Timer
timer
;
ActualizarSalidaTask
task
;
while
(
it
.
hasNext
())
{
JSONObject
obj
=
(
JSONObject
)
it
.
next
();
String
horaSalida
=
obj
.
getString
(
"salida"
);
System
.
out
.
println
(
"Leyendo hora de salida "
+
horaSalida
);
if
(
validarProgramacionSalida
(
horaSalida
))
{
System
.
out
.
println
(
"Programando hora de salida "
+
horaSalida
);
Date
horaEjecucion
=
Metodos
.
getHoraEjecucion
(
horaSalida
);
timer
=
new
Timer
();
task
=
new
ActualizarSalidaTask
(
timer
,
horaSalida
);
timer
.
schedule
(
task
,
horaEjecucion
);
System
.
out
.
println
(
"Timer "
+
timer
);
}
else
{
System
.
out
.
println
(
"Ya pasó la hora"
);
}
System
.
out
.
println
();
}
}
catch
(
Exception
ex
)
{
Logger
.
getLogger
(
ProgramarSalidasTask
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
private
boolean
validarProgramacionSalida
(
String
horaSalida
)
{
boolean
valido
=
false
;
String
[]
splitHora
=
horaSalida
.
split
(
":"
);
int
min
=
Integer
.
parseInt
(
splitHora
[
1
]);
int
hora
=
Integer
.
parseInt
(
splitHora
[
0
]);
int
cantMinutos
=
hora
*
60
+
min
;
LocalTime
timeSystem
=
LocalTime
.
now
();
int
cantMinutosSistema
=
timeSystem
.
getHour
()
*
60
+
timeSystem
.
getMinute
();
if
(
cantMinutos
>
cantMinutosSistema
)
{
valido
=
true
;
}
return
valido
;
}
}
src/salidasautomaticas/services/SalidasServices.java
View file @
a45ef710
...
...
@@ -31,6 +31,18 @@ public class SalidasServices {
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
;
}
...
...
src/salidasautomaticas/util/EstandarDAO.java
View file @
a45ef710
...
...
@@ -77,7 +77,7 @@ public class EstandarDAO {
cont
++;
}
}
//
System.out.println("query "+ps);
System
.
out
.
println
(
"query "
+
ps
);
ResultSet
rs
=
ps
.
executeQuery
();
ResultSetMetaData
rm
=
rs
.
getMetaData
();
...
...
src/salidasautomaticas/util/Metodos.java
0 → 100644
View file @
a45ef710
/*
* 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
.
util
;
import
java.util.Calendar
;
import
java.util.Date
;
/**
*
* @author sistem19user
*/
public
class
Metodos
{
/**
* Devuelve un objeto Date con la fecha de hoy y con la hora
* que le pasamos como parametro(en formato hh:mm en 24 horas).
*
* @param horaEjecucion hora que se va a setear al Date del dia de hoy.
* @return
*/
public
static
Date
getHoraEjecucion
(
String
horaEjecucion
)
{
Date
date
=
new
Date
(
System
.
currentTimeMillis
());
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
String
[]
splitHoraSalida
=
horaEjecucion
.
split
(
":"
);
int
hora
=
Integer
.
parseInt
(
splitHoraSalida
[
0
]);
int
minuto
=
Integer
.
parseInt
(
splitHoraSalida
[
1
]);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
hora
);
calendar
.
set
(
Calendar
.
MINUTE
,
minuto
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
date
=
calendar
.
getTime
();
return
date
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment