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
0d1ad79a
Commit
0d1ad79a
authored
Apr 05, 2018
by
sistem02 user
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
actualizando salidas
parent
0665992c
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
142 additions
and
54 deletions
+142
-54
SalidasDAO.java
src/salidasautomaticas/dao/SalidasDAO.java
+2
-0
Main.java
src/salidasautomaticas/main/Main.java
+2
-3
MysqlDAOFactory.java
src/salidasautomaticas/mysqldao/MysqlDAOFactory.java
+12
-28
SalidasMysqlDAO.java
src/salidasautomaticas/mysqldao/SalidasMysqlDAO.java
+108
-19
Temporizador.java
src/salidasautomaticas/schedule/Temporizador.java
+4
-1
SalidasServices.java
src/salidasautomaticas/services/SalidasServices.java
+9
-0
EstandarDAO.java
src/salidasautomaticas/util/EstandarDAO.java
+5
-3
No files found.
src/salidasautomaticas/dao/SalidasDAO.java
View file @
0d1ad79a
...
...
@@ -13,6 +13,8 @@ import org.json.JSONObject;
* @author sistem19user
*/
public
interface
SalidasDAO
{
public
JSONArray
obtenerHorariosSalida
()
throws
Exception
;
public
JSONArray
obtenerAsistencias
(
String
horaProgramada
)
throws
Exception
;
public
JSONObject
actualizarSalida
()
throws
Exception
;
}
src/salidasautomaticas/main/Main.java
View file @
0d1ad79a
...
...
@@ -9,10 +9,9 @@ public class Main {
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Timer
timer
=
new
Timer
();
// SalidasServices services = new SalidasServices();
// System.out.println(services.obtenerHorariosSalida());
SalidasServices
services
=
new
SalidasServices
();
timer
.
schedule
(
new
Temporizador
(),
0
,
300
0
);
timer
.
schedule
(
new
Temporizador
(),
0
);
}
}
src/salidasautomaticas/mysqldao/MysqlDAOFactory.java
View file @
0d1ad79a
...
...
@@ -5,8 +5,8 @@
*/
package
salidasautomaticas
.
mysqldao
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
javax.sql.DataSource
;
import
org.apache.commons.dbcp.BasicDataSource
;
import
salidasautomaticas.dao.DAOFactory
;
...
...
@@ -18,47 +18,31 @@ import salidasautomaticas.dao.SalidasDAO;
*/
public
class
MysqlDAOFactory
extends
DAOFactory
{
private
static
DataSource
dataSourceMySQL
;
static
{
try
{
createPoolConnectionsMySQL
(
);
Class
.
forName
(
"com.mysql.jdbc.Driver"
);
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
public
static
void
createPoolConnectionsMySQL
()
{
if
(
dataSourceMySQL
==
null
)
{
BasicDataSource
basicDataSource
=
new
BasicDataSource
();
basicDataSource
.
setDriverClassName
(
"com.mysql.jdbc.Driver"
);
basicDataSource
.
setUsername
(
"billy"
);
basicDataSource
.
setPassword
(
"billy"
);
basicDataSource
.
setUrl
(
"jdbc:mysql://172.16.2.39:3306/nuevo"
);
basicDataSource
.
setMaxActive
(
30
);
basicDataSource
.
setMaxIdle
(
30
);
basicDataSource
.
setRemoveAbandoned
(
true
);
basicDataSource
.
setRemoveAbandonedTimeout
(
5000
);
basicDataSource
.
setMaxWait
(
6000
);
dataSourceMySQL
=
basicDataSource
;
}
}
public
static
Connection
getConneccion
(
String
bd
)
{
Connection
connection
=
null
;
if
(
bd
.
equals
(
"nuevo"
))
{
public
static
Connection
obtenerConexion
(
String
base
)
{
Connection
conexion
=
null
;
if
(
base
.
equals
(
"nuevo"
))
{
try
{
connection
=
dataSourceMySQL
.
getConnection
();
conexion
=
DriverManager
.
getConnection
(
"jdbc:mysql://172.16.2.39:3306/nuevo"
,
"root"
,
"mysql"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
return
con
nect
ion
;
return
con
ex
ion
;
}
@Override
public
SalidasDAO
getSalidasDAO
()
{
return
new
SalidasMysqlDAO
();
...
...
src/salidasautomaticas/mysqldao/SalidasMysqlDAO.java
View file @
0d1ad79a
...
...
@@ -7,6 +7,8 @@ package salidasautomaticas.mysqldao;
import
java.sql.Connection
;
import
java.time.LocalDate
;
import
java.time.LocalTime
;
import
java.util.Iterator
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
salidasautomaticas.dao.SalidasDAO
;
...
...
@@ -20,18 +22,34 @@ public class SalidasMysqlDAO implements SalidasDAO {
@Override
public
JSONArray
obtenerHorariosSalida
()
throws
Exception
{
Connection
cn
=
MysqlDAOFactory
.
getConnecc
ion
(
"nuevo"
);
Connection
cn
=
MysqlDAOFactory
.
obtenerConex
ion
(
"nuevo"
);
int
diaSemana
=
obtenerDiaSemana
();
String
query
=
"select ? as salida from personal inner join "
+
"cargo on (personal.codcargo=cargo.codcargo) where NULLIF(? , '') is NOT null and retirado=0 GROUP BY ?"
;
String
query
=
"SELECT ? as salida FROM (\n"
+
"SELECT\n"
+
" p.salidaLV,\n"
+
" p.salidaS\n"
+
"FROM\n"
+
" asistencia a\n"
+
"INNER JOIN personal p ON a.codper = p.codper\n"
+
"INNER JOIN salidas_update su ON p.codcargo = su.codcargo\n"
+
"WHERE\n"
+
" a.fecha_asis BETWEEN '2018-04-03' AND '2018-04-05'\n"
+
"AND p.retirado = 0\n"
+
"AND p.horaing = su.horaLV\n"
+
"AND p.mining = su.minutoLV\n"
+
"AND p.horaingsabado = su.sabadoLV\n"
+
"AND p.miningsabado = su.sabadoS\n"
+
"AND NOT p.codlocal IN ('L035', 'L053', 'L038')\n"
+
"AND NOT p.pronoe = 1\n"
+
"AND NOT p.codcargo IN (71, 13)\n"
+
"AND NOT p.horaing > 19\n"
+
"AND NOT p.salidaS = '') as tabla WHERE NULLIF( ? , '') is NOT null GROUP BY ? "
;
if
(
diaSemana
>=
1
&&
diaSemana
<=
5
)
{
query
=
query
.
replaceAll
(
"\\?"
,
"salidaLV"
);
query
=
query
.
replaceAll
(
"\\?"
,
"
tabla.
salidaLV"
);
}
else
if
(
diaSemana
==
6
)
{
query
=
query
.
replaceAll
(
"\\?"
,
"salidaS"
);
query
=
query
.
replaceAll
(
"\\?"
,
"
tabla.
salidaS"
);
}
JSONArray
jsonArray
=
EstandarDAO
.
getInstance
().
consultar
(
cn
,
query
);
return
jsonArray
;
...
...
@@ -46,24 +64,95 @@ public class SalidasMysqlDAO implements SalidasDAO {
}
@Override
public
JSONArray
obtenerAsistencias
(
String
horaProgramada
)
throws
Exception
{
Connection
cn
=
MysqlDAOFactory
.
obtenerConexion
(
"nuevo"
);
int
diaSemana
=
obtenerDiaSemana
();
String
query
=
"SELECT\n"
+
" asistencia.codasis,\n"
+
"asistencia.fecha_asis,\n"
+
"(WEEKDAY(asistencia.fecha_asis) + 1) AS numDia,\n"
+
"? \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-04-03' AND '2018-04-04')\n"
+
"AND ? 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"
);
}
else
if
(
diaSemana
==
6
)
{
query
=
query
.
replaceAll
(
"\\?"
,
"personal.salidaS"
);
}
query
=
query
.
replaceAll
(
"\\*"
,
horaProgramada
);
JSONArray
jsonArray
=
EstandarDAO
.
getInstance
().
consultar
(
cn
,
query
);
return
jsonArray
;
}
@Override
public
JSONObject
actualizarSalida
()
throws
Exception
{
JSONObject
resultado
=
null
;
Connection
cn
=
MysqlDAOFactory
.
getConnecc
ion
(
"nuevo"
);
String
queryPersonal
=
"select codper from personal where salidaLV='10:00' and retirado=0"
;
JSONArray
jsonArray
=
EstandarDAO
.
getInstance
().
consultar
(
cn
,
queryPersonal
);
for
(
int
i
=
0
;
i
<
jsonArray
.
length
();
i
++){
JSONObject
objJSON
=
(
JSONObject
)
jsonArray
.
get
(
i
);
S
tring
codper
=
objJSON
.
getString
(
"codper"
);
String
query
=
"update asistencia set horasal=2, minsal=0 where codper=?"
;
JSON
Array
parametros
=
new
JSONArray
();
parametros
.
put
(
codper
);
resultado
=
EstandarDAO
.
getInstance
().
ejecutar
(
cn
,
query
);
}
Connection
cn
=
MysqlDAOFactory
.
obtenerConex
ion
(
"nuevo"
);
LocalTime
horaSistema
=
LocalTime
.
now
()
;
int
cantMinSistema
=
horaSistema
.
getHour
()
*
60
+
horaSistema
.
getMinute
(
);
JSONArray
listadoHoras
=
obtenerHorariosSalida
();
System
.
out
.
println
(
"listadoHoras "
+
listadoHoras
);
for
(
Iterator
iterator
=
listadoHoras
.
iterator
();
iterator
.
hasNext
();)
{
S
ystem
.
out
.
println
(
""
+
1
);
int
aleatorioHora
=
0
,
aleatorioMin
=
0
;
JSON
Object
objHora
=
(
JSONObject
)
iterator
.
next
();
System
.
out
.
println
(
"objHora "
+
objHora
);
String
[]
splitHora
=
objHora
.
getString
(
"salida"
).
split
(
":"
);
int
cantidadMin
=
Integer
.
parseInt
(
splitHora
[
0
])
*
60
+
Integer
.
parseInt
(
splitHora
[
1
]);
if
(
cantidadMin
>
cantMinSistema
)
{
//Reprogramacion
System
.
out
.
println
(
"Me reprogramo"
);
}
else
{
System
.
out
.
println
(
"Programo"
);
JSONArray
listadoProgramar
=
obtenerAsistencias
(
objHora
.
getString
(
"salida"
));
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
]);
System
.
out
.
println
(
"obj "
+
objPrograma
);
//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
(
objPrograma
.
getString
(
"codasis"
));
// System.out.println("consulta "+queryPersonal+ " "+parametros);
resultado
=
EstandarDAO
.
getInstance
().
ejecutar
(
cn
,
queryPersonal
,
parametros
);
}
}
}
return
resultado
;
}
}
src/salidasautomaticas/schedule/Temporizador.java
View file @
0d1ad79a
...
...
@@ -7,6 +7,7 @@ package salidasautomaticas.schedule;
import
java.util.Date
;
import
java.util.TimerTask
;
import
salidasautomaticas.services.SalidasServices
;
/**
*
...
...
@@ -14,9 +15,11 @@ import java.util.TimerTask;
*/
public
class
Temporizador
extends
TimerTask
{
SalidasServices
service
=
new
SalidasServices
();
@Override
public
void
run
()
{
System
.
out
.
println
(
new
Date
());
service
.
actualizarSalidas
();
System
.
out
.
println
(
"Actualizar salida"
);
}
}
src/salidasautomaticas/services/SalidasServices.java
View file @
0d1ad79a
...
...
@@ -26,4 +26,13 @@ public class SalidasServices {
return
listaHorarios
;
}
public
JSONObject
actualizarSalidas
(){
JSONObject
valor
=
new
JSONObject
();
try
{
valor
=
salidadao
.
actualizarSalida
();
}
catch
(
Exception
e
)
{
}
return
valor
;
}
}
src/salidasautomaticas/util/EstandarDAO.java
View file @
0d1ad79a
...
...
@@ -77,6 +77,7 @@ public class EstandarDAO {
cont
++;
}
}
// System.out.println("query "+ps);
ResultSet
rs
=
ps
.
executeQuery
();
ResultSetMetaData
rm
=
rs
.
getMetaData
();
...
...
@@ -90,8 +91,8 @@ public class EstandarDAO {
jsonArray
.
put
(
obj
);
}
rs
.
close
();
cn
.
close
();
//
rs.close();
//
cn.close();
}
}
catch
(
Exception
ex
)
{
...
...
@@ -130,13 +131,14 @@ public class EstandarDAO {
}
}
System
.
out
.
println
(
"consulta ..... "
+
ps
);
int
filas
=
ps
.
executeUpdate
();
if
(
filas
>
0
)
{
obj
.
put
(
"msg"
,
filas
);
}
else
{
obj
.
put
(
"msg"
,
0
);
}
cn
.
close
();
//
cn.close();
}
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
...
...
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