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
2777b54d
Commit
2777b54d
authored
Sep 22, 2018
by
Billy Larru
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[EDIT main, programarsalidastask, hilo principal iniciando a las 06:00]
parent
989dbc46
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
42 deletions
+45
-42
Main.java
src/salidasautomaticas/main/Main.java
+1
-1
ProgramarSalidasTask.java
src/salidasautomaticas/schedule/ProgramarSalidasTask.java
+44
-41
No files found.
src/salidasautomaticas/main/Main.java
View file @
2777b54d
...
@@ -24,7 +24,7 @@ public class Main {
...
@@ -24,7 +24,7 @@ public class Main {
setLogLevel
(
Level
.
INFO
);
//PRODUCCION
setLogLevel
(
Level
.
INFO
);
//PRODUCCION
log
.
info
(
"Inicializando programa [Salidas Automaticas]..."
);
log
.
info
(
"Inicializando programa [Salidas Automaticas]..."
);
Date
horaInicio
=
Metodos
.
getHoraEjecucion
(
"
12:3
0"
);
Date
horaInicio
=
Metodos
.
getHoraEjecucion
(
"
06:0
0"
);
int
periodo
=
86400000
;
//El codigo se ejecutará cada 24h, 86400000 representa 24h en milisegundos
int
periodo
=
86400000
;
//El codigo se ejecutará cada 24h, 86400000 representa 24h en milisegundos
TimerTask
task
=
new
ProgramarSalidasTask
();
TimerTask
task
=
new
ProgramarSalidasTask
();
...
...
src/salidasautomaticas/schedule/ProgramarSalidasTask.java
View file @
2777b54d
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
*/
*/
package
salidasautomaticas
.
schedule
;
package
salidasautomaticas
.
schedule
;
import
java.time.LocalDateTime
;
import
java.time.LocalTime
;
import
java.time.LocalTime
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.Iterator
;
import
java.util.Iterator
;
...
@@ -23,59 +24,61 @@ import salidasautomaticas.util.Metodos;
...
@@ -23,59 +24,61 @@ import salidasautomaticas.util.Metodos;
*/
*/
public
class
ProgramarSalidasTask
extends
TimerTask
{
public
class
ProgramarSalidasTask
extends
TimerTask
{
private
static
final
Logger
log
=
LogManager
.
getLogger
(
ProgramarSalidasTask
.
class
);
private
static
final
Logger
log
=
LogManager
.
getLogger
(
ProgramarSalidasTask
.
class
);
private
static
SalidasServices
service
=
new
SalidasServices
();
private
static
SalidasServices
service
=
new
SalidasServices
();
@Override
@Override
public
void
run
()
{
public
void
run
()
{
try
{
try
{
JSONArray
listaHorarios
=
service
.
obtenerHorariosSalida
();
LocalDateTime
hoy
=
LocalDateTime
.
now
();
log
.
info
(
"Obteniendo la lista de horarios ["
+
hoy
.
toString
()
+
"]"
);
JSONArray
listaHorarios
=
service
.
obtenerHorariosSalida
();
Timer
timer
;
Timer
timer
;
TimerTask
task
;
TimerTask
task
;
log
.
info
(
"horario leido= "
+
listaHorarios
);
log
.
info
(
"horario leido= "
+
listaHorarios
);
for
(
Iterator
it
=
listaHorarios
.
iterator
();
it
.
hasNext
();)
{
for
(
Iterator
it
=
listaHorarios
.
iterator
();
it
.
hasNext
();)
{
JSONObject
obj
=
(
JSONObject
)
it
.
next
();
JSONObject
obj
=
(
JSONObject
)
it
.
next
();
String
horaSalida
=
obj
.
getString
(
"salida"
);
String
horaSalida
=
obj
.
getString
(
"salida"
);
log
.
trace
(
"Leyendo hora de salida "
+
horaSalida
);
log
.
trace
(
"Leyendo hora de salida "
+
horaSalida
);
if
(
validarProgramacionSalida
(
horaSalida
))
{
if
(
validarProgramacionSalida
(
horaSalida
))
{
log
.
info
(
"Programando hora de salida "
+
horaSalida
);
log
.
info
(
"Programando hora de salida "
+
horaSalida
);
Date
horaEjecucion
=
Metodos
.
getHoraEjecucion
(
horaSalida
);
Date
horaEjecucion
=
Metodos
.
getHoraEjecucion
(
horaSalida
);
timer
=
new
Timer
();
timer
=
new
Timer
();
task
=
new
ActualizarSalidaTask
(
timer
,
horaSalida
);
task
=
new
ActualizarSalidaTask
(
timer
,
horaSalida
);
timer
.
schedule
(
task
,
horaEjecucion
);
timer
.
schedule
(
task
,
horaEjecucion
);
log
.
trace
(
"Timer "
+
timer
);
log
.
trace
(
"Timer "
+
timer
);
}
else
{
}
else
{
log
.
trace
(
"Ya pasó la hora "
+
horaSalida
);
log
.
warn
(
"No se programa la hora de salida "
+
horaSalida
+
", porque ya ha pasado la hora"
);
}
}
}
}
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
log
.
error
(
"error"
,
ex
);
log
.
error
(
"error"
,
ex
);
}
}
}
}
private
boolean
validarProgramacionSalida
(
String
horaSalida
)
{
private
boolean
validarProgramacionSalida
(
String
horaSalida
)
{
boolean
valido
=
false
;
boolean
valido
=
false
;
String
[]
splitHora
=
horaSalida
.
split
(
":"
);
String
[]
splitHora
=
horaSalida
.
split
(
":"
);
int
min
=
Integer
.
parseInt
(
splitHora
[
1
]);
int
min
=
Integer
.
parseInt
(
splitHora
[
1
]);
int
hora
=
Integer
.
parseInt
(
splitHora
[
0
]);
int
hora
=
Integer
.
parseInt
(
splitHora
[
0
]);
int
cantMinutos
=
hora
*
60
+
min
;
int
cantMinutos
=
hora
*
60
+
min
;
LocalTime
timeSystem
=
LocalTime
.
now
();
LocalTime
timeSystem
=
LocalTime
.
now
();
int
cantMinutosSistema
=
timeSystem
.
getHour
()
*
60
+
timeSystem
.
getMinute
();
int
cantMinutosSistema
=
timeSystem
.
getHour
()
*
60
+
timeSystem
.
getMinute
();
if
(
cantMinutos
>
cantMinutosSistema
)
{
if
(
cantMinutos
>
cantMinutosSistema
)
{
valido
=
true
;
valido
=
true
;
}
}
return
valido
;
return
valido
;
}
}
}
}
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