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
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
47 deletions
+66
-47
MysqlDAOFactory.java
src/salidasautomaticas/mysqldao/MysqlDAOFactory.java
+2
-2
SalidasMysqlDAO.java
src/salidasautomaticas/mysqldao/SalidasMysqlDAO.java
+39
-37
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 {
try
{
conexion
=
DriverManager
.
getConnection
(
"jdbc:mysql://172.16.2.39:3306/nuevo"
,
"
root
"
,
"m
ysql
"
);
"
melani
"
,
"m
elani
"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
src/salidasautomaticas/mysqldao/SalidasMysqlDAO.java
View file @
4bdaf7d7
...
...
@@ -9,8 +9,6 @@ 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
;
...
...
@@ -212,32 +210,16 @@ 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
()
*
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
);
}
int
[]
aleatorio
=
generarHoraMinutoAleatorio
(
salidaPersonal
);
aleatorioHora
=
aleatorio
[
0
];
aleatorioMin
=
aleatorio
[
1
];
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"
);
}
...
...
@@ -245,8 +227,33 @@ public class SalidasMysqlDAO implements SalidasDAO {
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
)
{
//
SalidasMysqlDAO s = new SalidasMysqlDAO();
SalidasMysqlDAO
s
=
new
SalidasMysqlDAO
();
// try {
// JSONObject obj = s.actualizarSalida("17:00");
// System.out.println(obj);
...
...
@@ -255,20 +262,15 @@ public class SalidasMysqlDAO implements SalidasDAO {
// }
// System.out.println(s.getFechaAyer());
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 "
;
System
.
out
.
println
(
query
);
// String hora = "09:30";
// Integer h = new Integer(1);
// Integer m = new Integer(1);
//
// s.generarHoraMinutoAleatorio(hora, h, m);
//
// System.out.println("hora=" + h.intValue() + ", minuto=" + m.intValue());
// int[] i = s.generarHoraMinutoAleatorio("10:00");
// System.out.println("h=" + i[0] + ", m=" + i[1]);
}
@Override
...
...
src/salidasautomaticas/schedule/ActualizarSalidaTask.java
View file @
4bdaf7d7
...
...
@@ -30,9 +30,19 @@ 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
();
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
);
...
...
src/salidasautomaticas/schedule/ProgramarSalidasTask.java
View file @
4bdaf7d7
...
...
@@ -15,7 +15,6 @@ 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
;
/**
...
...
@@ -24,15 +23,13 @@ import salidasautomaticas.util.Metodos;
*/
public
class
ProgramarSalidasTask
extends
TimerTask
{
SalidasServices
service
=
new
SalidasServices
();
@Override
public
void
run
()
{
try
{
// JSONArray listaHorarios = service.obtenerHorariosSalida();
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
)
{
listaHorarios
.
put
(
new
JSONObject
().
put
(
"salida"
,
salida
));
...
...
@@ -40,10 +37,9 @@ public class ProgramarSalidasTask extends TimerTask {
System
.
out
.
println
(
"Listando horarios "
+
listaHorarios
+
"\n"
);
Iterator
it
=
listaHorarios
.
iterator
();
Timer
timer
;
ActualizarSalidaTask
task
;
while
(
it
.
hasNext
()
)
{
for
(
Iterator
it
=
listaHorarios
.
iterator
();
it
.
hasNext
();
)
{
JSONObject
obj
=
(
JSONObject
)
it
.
next
();
String
horaSalida
=
obj
.
getString
(
"salida"
);
...
...
src/salidasautomaticas/services/SalidasServices.java
View file @
4bdaf7d7
...
...
@@ -66,4 +66,15 @@ public class SalidasServices {
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