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
4bdaf7d7
Commit
4bdaf7d7
authored
May 04, 2018
by
Billy Larru
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
creando un metodo para generar hora y minuto aleatoria
parent
5b4789ed
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
49 deletions
+68
-49
MysqlDAOFactory.java
src/salidasautomaticas/mysqldao/MysqlDAOFactory.java
+2
-2
SalidasMysqlDAO.java
src/salidasautomaticas/mysqldao/SalidasMysqlDAO.java
+41
-39
ActualizarSalidaTask.java
src/salidasautomaticas/schedule/ActualizarSalidaTask.java
+12
-2
ProgramarSalidasTask.java
src/salidasautomaticas/schedule/ProgramarSalidasTask.java
+2
-6
SalidasServices.java
src/salidasautomaticas/services/SalidasServices.java
+11
-0
No files found.
src/salidasautomaticas/mysqldao/MysqlDAOFactory.java
View file @
4bdaf7d7
...
@@ -33,8 +33,8 @@ public class MysqlDAOFactory extends DAOFactory {
...
@@ -33,8 +33,8 @@ public class MysqlDAOFactory extends DAOFactory {
try
{
try
{
conexion
=
DriverManager
.
getConnection
(
conexion
=
DriverManager
.
getConnection
(
"jdbc:mysql://172.16.2.39:3306/nuevo"
,
"jdbc:mysql://172.16.2.39:3306/nuevo"
,
"
root
"
,
"
melani
"
,
"m
ysql
"
);
"m
elani
"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
...
src/salidasautomaticas/mysqldao/SalidasMysqlDAO.java
View file @
4bdaf7d7
...
@@ -9,8 +9,6 @@ import java.sql.Connection;
...
@@ -9,8 +9,6 @@ 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
;
...
@@ -212,32 +210,16 @@ public class SalidasMysqlDAO implements SalidasDAO {
...
@@ -212,32 +210,16 @@ public class SalidasMysqlDAO implements SalidasDAO {
// if(salidaPersonal==null || salidaPersonal.isEmpty()){
// if(salidaPersonal==null || salidaPersonal.isEmpty()){
// continue;
// continue;
// }
// }
String
[]
splitHoraConsulta
=
salidaPersonal
.
split
(
":"
);
int
[]
aleatorio
=
generarHoraMinutoAleatorio
(
salidaPersonal
);
int
min
=
Integer
.
parseInt
(
splitHoraConsulta
[
1
]);
aleatorioHora
=
aleatorio
[
0
];
int
hora
=
Integer
.
parseInt
(
splitHoraConsulta
[
0
]);
aleatorioMin
=
aleatorio
[
1
];
System
.
out
.
println
(
"obj "
+
asistencia
);
//Actualizacion de salidas
if
(
min
==
0
)
{
aleatorioHora
=
(
int
)
Math
.
floor
(
Math
.
random
()
*
2
+
(
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
()
*
3
+
57
);
}
String
queryPersonal
=
"update asistencia set horasal= ?,minsal=? where codasis=? "
;
String
queryPersonal
=
"update asistencia set horasal= ?,minsal=? where codasis=? "
;
JSONArray
parametros
=
new
JSONArray
();
JSONArray
parametros
=
new
JSONArray
();
parametros
.
put
(
aleatorioHora
);
parametros
.
put
(
aleatorioHora
);
parametros
.
put
(
aleatorioMin
);
parametros
.
put
(
aleatorioMin
);
parametros
.
put
(
asistencia
.
getString
(
"codasis"
));
parametros
.
put
(
asistencia
.
getString
(
"codasis"
));
// System.out.println("consulta "+queryPersonal+ " "+parametros);
resultado
=
EstandarDAO
.
getInstance
().
ejecutar
(
cn
,
queryPersonal
,
parametros
);
resultado
=
EstandarDAO
.
getInstance
().
ejecutar
(
cn
,
queryPersonal
,
parametros
);
System
.
out
.
println
(
"Asistencia actualizada"
);
System
.
out
.
println
(
"Asistencia actualizada"
);
}
}
...
@@ -245,8 +227,33 @@ public class SalidasMysqlDAO implements SalidasDAO {
...
@@ -245,8 +227,33 @@ public class SalidasMysqlDAO implements SalidasDAO {
return
resultado
;
return
resultado
;
}
}
private
int
[]
generarHoraMinutoAleatorio
(
String
horaMinuto
)
{
int
[]
aleatorio
=
new
int
[
2
];
//horaAleatoria index=0, minAleatorio index=1
String
[]
splitHoraConsulta
=
horaMinuto
.
split
(
":"
);
int
min
=
Integer
.
parseInt
(
splitHoraConsulta
[
1
]);
int
hora
=
Integer
.
parseInt
(
splitHoraConsulta
[
0
]);
// Actualizacion de salidas
if
(
min
==
0
)
{
aleatorio
[
0
]
=
(
int
)
Math
.
floor
(
Math
.
random
()
*
2
+
(
hora
-
1
));
}
else
{
aleatorio
[
0
]
=
hora
;
}
if
(
hora
==
aleatorio
[
0
])
{
if
(
min
==
0
)
{
aleatorio
[
1
]
=
(
int
)
Math
.
floor
(
Math
.
random
()
*
(
3
-
0
+
1
)
+
0
);
}
else
{
aleatorio
[
1
]
=
(
int
)
Math
.
floor
(
Math
.
random
()
*
(
33
-
27
+
1
)
+
27
);
}
}
else
{
aleatorio
[
1
]
=
(
int
)
Math
.
floor
(
Math
.
random
()
*
3
+
57
);
}
return
aleatorio
;
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
//
SalidasMysqlDAO s = new SalidasMysqlDAO();
SalidasMysqlDAO
s
=
new
SalidasMysqlDAO
();
// try {
// try {
// JSONObject obj = s.actualizarSalida("17:00");
// JSONObject obj = s.actualizarSalida("17:00");
// System.out.println(obj);
// System.out.println(obj);
...
@@ -255,20 +262,15 @@ public class SalidasMysqlDAO implements SalidasDAO {
...
@@ -255,20 +262,15 @@ public class SalidasMysqlDAO implements SalidasDAO {
// }
// }
// System.out.println(s.getFechaAyer());
// System.out.println(s.getFechaAyer());
String
query
=
"SELECT "
// String hora = "09:30";
+
" p.codper, "
// Integer h = new Integer(1);
+
" su.salidaLV, "
// Integer m = new Integer(1);
+
" su.salidaS, "
//
+
"FROM "
// s.generarHoraMinutoAleatorio(hora, h, m);
+
" personal p "
//
+
"INNER JOIN salidas_update su ON p.codcargo=su.codcargo "
// System.out.println("hora=" + h.intValue() + ", minuto=" + m.intValue());
+
"WHERE retirado=0 AND p.horaing=su.horaLV "
// int[] i = s.generarHoraMinutoAleatorio("10:00");
+
"and p.mining=su.minutoLV and p.horaingsabado=su.sabadoLV AND p.miningsabado=su.sabadoS "
// System.out.println("h=" + i[0] + ", m=" + i[1]);
+
"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 "
;
System
.
out
.
println
(
query
);
}
}
@Override
@Override
...
@@ -327,9 +329,9 @@ public class SalidasMysqlDAO implements SalidasDAO {
...
@@ -327,9 +329,9 @@ public class SalidasMysqlDAO implements SalidasDAO {
+
"SET p.salidaLV=tbl.salidaLV, "
+
"SET p.salidaLV=tbl.salidaLV, "
+
" p.salidaS=tbl.salidaS "
+
" p.salidaS=tbl.salidaS "
+
"where tbl.codper=p.codper"
;
+
"where tbl.codper=p.codper"
;
JSONObject
resultado
=
EstandarDAO
.
getInstance
().
ejecutar
(
cn
,
query
);
JSONObject
resultado
=
EstandarDAO
.
getInstance
().
ejecutar
(
cn
,
query
);
return
resultado
;
return
resultado
;
}
}
...
...
src/salidasautomaticas/schedule/ActualizarSalidaTask.java
View file @
4bdaf7d7
...
@@ -30,11 +30,21 @@ public class ActualizarSalidaTask extends TimerTask{
...
@@ -30,11 +30,21 @@ 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
();
JSONObject
objSalidaAsignada
=
services
.
asignarHorarioSalida
();
if
(
objSalidaAsignada
.
getInt
(
"msg"
)>
0
){
System
.
out
.
println
(
"Se asignaron horarios de salida correctamente, filas afectadas="
+
objSalidaAsignada
.
getInt
(
"msg"
));
}
else
{
System
.
out
.
println
(
"No se pudo asignar horarios de salida"
);
}
// JSONArray objNuevasSalidas = services.obtenerSalidasNuevas();
// JSONArray objPersonalSinSalida = services.obtenerPersonalNuevoSinSalida();
System
.
out
.
println
(
"Matando timer "
+
timer
);
System
.
out
.
println
(
"Matando timer "
+
timer
);
timer
.
cancel
();
timer
.
cancel
();
}
}
...
...
src/salidasautomaticas/schedule/ProgramarSalidasTask.java
View file @
4bdaf7d7
...
@@ -15,7 +15,6 @@ import java.util.logging.Level;
...
@@ -15,7 +15,6 @@ import java.util.logging.Level;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
import
salidasautomaticas.services.SalidasServices
;
import
salidasautomaticas.util.Metodos
;
import
salidasautomaticas.util.Metodos
;
/**
/**
...
@@ -24,15 +23,13 @@ import salidasautomaticas.util.Metodos;
...
@@ -24,15 +23,13 @@ import salidasautomaticas.util.Metodos;
*/
*/
public
class
ProgramarSalidasTask
extends
TimerTask
{
public
class
ProgramarSalidasTask
extends
TimerTask
{
SalidasServices
service
=
new
SalidasServices
();
@Override
@Override
public
void
run
()
{
public
void
run
()
{
try
{
try
{
// JSONArray listaHorarios = service.obtenerHorariosSalida();
// JSONArray listaHorarios = service.obtenerHorariosSalida();
JSONArray
listaHorarios
=
new
JSONArray
();
JSONArray
listaHorarios
=
new
JSONArray
();
String
[]
arraySalidas
=
{
"1
8:3
9"
,
"14:46"
,
"14:50"
,
"17:00"
,
"17:30"
,
"18:00"
};
String
[]
arraySalidas
=
{
"1
0:2
9"
,
"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
));
...
@@ -40,10 +37,9 @@ public class ProgramarSalidasTask extends TimerTask {
...
@@ -40,10 +37,9 @@ public class ProgramarSalidasTask extends TimerTask {
System
.
out
.
println
(
"Listando horarios "
+
listaHorarios
+
"\n"
);
System
.
out
.
println
(
"Listando horarios "
+
listaHorarios
+
"\n"
);
Iterator
it
=
listaHorarios
.
iterator
();
Timer
timer
;
Timer
timer
;
ActualizarSalidaTask
task
;
ActualizarSalidaTask
task
;
while
(
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"
);
...
...
src/salidasautomaticas/services/SalidasServices.java
View file @
4bdaf7d7
...
@@ -65,5 +65,16 @@ public class SalidasServices {
...
@@ -65,5 +65,16 @@ public class SalidasServices {
}
}
return
valor
;
return
valor
;
}
}
public
JSONObject
asignarHorarioSalida
(){
JSONObject
valor
=
new
JSONObject
();
try
{
valor
=
salidadao
.
asignarHorarioSalida
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
valor
;
}
}
}
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