|
@ -6,6 +6,8 @@ import oracle.jdbc.OraclePreparedStatement; |
|
|
import oracle.sql.CLOB; |
|
|
import oracle.sql.CLOB; |
|
|
import org.apache.poi.ss.usermodel.*; |
|
|
import org.apache.poi.ss.usermodel.*; |
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.io.InputStream; |
|
|
import java.io.InputStream; |
|
@ -16,17 +18,19 @@ import java.time.LocalDate; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
public class DatabaseService { |
|
|
public class DatabaseService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Connection getMysqlConnection() throws SQLException { |
|
|
|
|
|
//String url = "jdbc:oracle:thin:@//oracle-xe:1521/XEPDB1"; |
|
|
|
|
|
String url = "jdbc:oracle:thin:@//svrapps:1521/XEPDB1"; |
|
|
|
|
|
String user = "MANTENIMIENTOS"; |
|
|
|
|
|
String pass = "mantenimientos"; |
|
|
|
|
|
|
|
|
|
|
|
return DriverManager.getConnection(url, user, pass); |
|
|
|
|
|
|
|
|
@Value("${db.url}") |
|
|
|
|
|
private String dbUrl; |
|
|
|
|
|
@Value("${db.user}") |
|
|
|
|
|
private String dbUser; |
|
|
|
|
|
@Value("${db.pass}") |
|
|
|
|
|
private String dbPass; |
|
|
|
|
|
|
|
|
|
|
|
private Connection getMysqlConnection() throws SQLException { |
|
|
|
|
|
return DriverManager.getConnection(dbUrl, dbUser, dbPass); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*private Connection getOracleConnection() throws SQLException { |
|
|
/*private Connection getOracleConnection() throws SQLException { |
|
@ -41,7 +45,7 @@ public class DatabaseService { |
|
|
// Método para obtener los tipos de mantenimientos |
|
|
// Método para obtener los tipos de mantenimientos |
|
|
public List<TiposMantenimiento> getTiposDeMantenimientos() { |
|
|
public List<TiposMantenimiento> getTiposDeMantenimientos() { |
|
|
List<TiposMantenimiento> tiposDeMantenimientos = new ArrayList<>(); |
|
|
List<TiposMantenimiento> tiposDeMantenimientos = new ArrayList<>(); |
|
|
String query = "SELECT tipomantid, nombre FROM MANTENIMIENTOS.TIPOMANT"; |
|
|
|
|
|
|
|
|
String query = "SELECT tipomantid, nombre FROM TIPOMANT"; |
|
|
|
|
|
|
|
|
try (Connection connection = getMysqlConnection(); |
|
|
try (Connection connection = getMysqlConnection(); |
|
|
Statement statement = connection.createStatement(); |
|
|
Statement statement = connection.createStatement(); |
|
@ -87,7 +91,7 @@ public class DatabaseService { |
|
|
public List<Usuario> getUsuarios() { |
|
|
public List<Usuario> getUsuarios() { |
|
|
List<Usuario> usuarios = new ArrayList<>(); |
|
|
List<Usuario> usuarios = new ArrayList<>(); |
|
|
String query = "SELECT u.* \n" + |
|
|
String query = "SELECT u.* \n" + |
|
|
"FROM MANTENIMIENTOS.USUARIOS u"; |
|
|
|
|
|
|
|
|
"FROM USUARIOS u"; |
|
|
|
|
|
|
|
|
try (Connection connection = getMysqlConnection(); |
|
|
try (Connection connection = getMysqlConnection(); |
|
|
Statement statement = connection.createStatement(); |
|
|
Statement statement = connection.createStatement(); |
|
@ -111,7 +115,7 @@ public class DatabaseService { |
|
|
/* -------------- Metodo para obtener los departamentos ---------------- */ |
|
|
/* -------------- Metodo para obtener los departamentos ---------------- */ |
|
|
public List<DepartamentosModel> getDepartamentos() { |
|
|
public List<DepartamentosModel> getDepartamentos() { |
|
|
List<DepartamentosModel> departamentos = new ArrayList<>(); |
|
|
List<DepartamentosModel> departamentos = new ArrayList<>(); |
|
|
String query = "select DEPARTAMENTOID, DESCRIPCION from MANTENIMIENTOS.DEPARTAMENTOS"; |
|
|
|
|
|
|
|
|
String query = "select DEPARTAMENTOID, DESCRIPCION from DEPARTAMENTOS"; |
|
|
|
|
|
|
|
|
try (Connection connection = getMysqlConnection(); |
|
|
try (Connection connection = getMysqlConnection(); |
|
|
Statement statement = connection.createStatement(); |
|
|
Statement statement = connection.createStatement(); |
|
@ -134,7 +138,7 @@ public class DatabaseService { |
|
|
/* -------------- Metodo para obtener los tipos de hardware ---------------- */ |
|
|
/* -------------- Metodo para obtener los tipos de hardware ---------------- */ |
|
|
public List<TiposHardware> getTiposHardware() { |
|
|
public List<TiposHardware> getTiposHardware() { |
|
|
List<TiposHardware> tiposHardware = new ArrayList<>(); |
|
|
List<TiposHardware> tiposHardware = new ArrayList<>(); |
|
|
String query = "select TIPOHARDWAREID, DESCRIPCION from MANTENIMIENTOS.TIPOSHARDWARE"; |
|
|
|
|
|
|
|
|
String query = "select TIPOHARDWAREID, DESCRIPCION from TIPOSHARDWARE"; |
|
|
|
|
|
|
|
|
try (Connection connection = getMysqlConnection(); |
|
|
try (Connection connection = getMysqlConnection(); |
|
|
Statement statement = connection.createStatement(); |
|
|
Statement statement = connection.createStatement(); |
|
@ -163,8 +167,8 @@ public class DatabaseService { |
|
|
" p.cpu, p.impresora, p.miniPrint, p.laptop, p.escaner, \r\n" + // |
|
|
" p.cpu, p.impresora, p.miniPrint, p.laptop, p.escaner, \r\n" + // |
|
|
" p.fechaprog, m.fecha AS fechaMantenimiento, \r\n" + // |
|
|
" p.fechaprog, m.fecha AS fechaMantenimiento, \r\n" + // |
|
|
" p.tecnicosmt, p.estado\r\n" + // |
|
|
" p.tecnicosmt, p.estado\r\n" + // |
|
|
"FROM MANTENIMIENTOS.PLANANUAL p\r\n" + // |
|
|
|
|
|
"LEFT JOIN MANTENIMIENTOS.MANTENIMIENTOS m ON p.plananualid = m.plananualid\r\n" + // |
|
|
|
|
|
|
|
|
"FROM PLANANUAL p\r\n" + // |
|
|
|
|
|
"LEFT JOIN MANTENIMIENTOS m ON p.plananualid = m.plananualid\r\n" + // |
|
|
"ORDER BY p.plananualid ASC"; |
|
|
"ORDER BY p.plananualid ASC"; |
|
|
|
|
|
|
|
|
try (Connection connection = getMysqlConnection(); |
|
|
try (Connection connection = getMysqlConnection(); |
|
@ -207,12 +211,12 @@ public class DatabaseService { |
|
|
"\tm.MANTENIMIENTOID ID, p.PLANANUALID, t.NOMBRE TIPO,\r\n" + // |
|
|
"\tm.MANTENIMIENTOID ID, p.PLANANUALID, t.NOMBRE TIPO,\r\n" + // |
|
|
"\td.DESCRIPCION DEPARTAMENTO, u.NOMBRE USUARIO, pa.FECHAPROG,\r\n" + // |
|
|
"\td.DESCRIPCION DEPARTAMENTO, u.NOMBRE USUARIO, pa.FECHAPROG,\r\n" + // |
|
|
"\tm.FECHA FECHAREALIZADO, NOMBREEQUIPO, FORMAMANT, FIRMAUSUARIO, FIRMASMT, FIRMAGCIA \r\n" + // |
|
|
"\tm.FECHA FECHAREALIZADO, NOMBREEQUIPO, FORMAMANT, FIRMAUSUARIO, FIRMASMT, FIRMAGCIA \r\n" + // |
|
|
"FROM MANTENIMIENTOS.MANTENIMIENTOS m\r\n" + // |
|
|
|
|
|
"INNER JOIN MANTENIMIENTOS.TIPOMANT t ON m.TIPOMANTID = t.TIPOMANTID\r\n" + // |
|
|
|
|
|
"INNER JOIN MANTENIMIENTOS.DEPARTAMENTOS d ON m.DEPARTAMENTOID = d.DEPARTAMENTOID\r\n" + // |
|
|
|
|
|
"INNER JOIN MANTENIMIENTOS.USUARIOS u ON u.EMPLEADOID = m.EMPLEADOID\r\n" + // |
|
|
|
|
|
"INNER JOIN MANTENIMIENTOS.PLANANUAL p ON m.PLANANUALID = p.PLANANUALID\r\n" + // |
|
|
|
|
|
"INNER JOIN MANTENIMIENTOS.PLANANUAL pa ON m.PLANANUALID = pa.PLANANUALID \r\n" + // |
|
|
|
|
|
|
|
|
"FROM MANTENIMIENTOS m\r\n" + // |
|
|
|
|
|
"INNER JOIN TIPOMANT t ON m.TIPOMANTID = t.TIPOMANTID\r\n" + // |
|
|
|
|
|
"INNER JOIN DEPARTAMENTOS d ON m.DEPARTAMENTOID = d.DEPARTAMENTOID\r\n" + // |
|
|
|
|
|
"INNER JOIN USUARIOS u ON u.EMPLEADOID = m.EMPLEADOID\r\n" + // |
|
|
|
|
|
"INNER JOIN PLANANUAL p ON m.PLANANUALID = p.PLANANUALID\r\n" + // |
|
|
|
|
|
"INNER JOIN PLANANUAL pa ON m.PLANANUALID = pa.PLANANUALID \r\n" + // |
|
|
"WHERE p.PLANANUALID = ?"; |
|
|
"WHERE p.PLANANUALID = ?"; |
|
|
|
|
|
|
|
|
try (Connection connection = getMysqlConnection(); |
|
|
try (Connection connection = getMysqlConnection(); |
|
@ -250,8 +254,8 @@ public class DatabaseService { |
|
|
public List<HardwareDetalle> getHardwaredetallePorMantId(int mantenimientoId) { |
|
|
public List<HardwareDetalle> getHardwaredetallePorMantId(int mantenimientoId) { |
|
|
List<HardwareDetalle> detalles = new ArrayList<>(); |
|
|
List<HardwareDetalle> detalles = new ArrayList<>(); |
|
|
String query = "SELECT h.MANTENIMIENTOID, h.HARDWAREDETID, t.DESCRIPCION, h.MODELO, h.NUMSERIE, h.PLACA\r\n" + // |
|
|
String query = "SELECT h.MANTENIMIENTOID, h.HARDWAREDETID, t.DESCRIPCION, h.MODELO, h.NUMSERIE, h.PLACA\r\n" + // |
|
|
"FROM MANTENIMIENTOS.HARDWAREDET h\r\n" + // |
|
|
|
|
|
"INNER JOIN MANTENIMIENTOS.TIPOSHARDWARE t ON h.TIPOHARDWAREID = t.TIPOHARDWAREID \r\n" + // |
|
|
|
|
|
|
|
|
"FROM HARDWAREDET h\r\n" + // |
|
|
|
|
|
"INNER JOIN TIPOSHARDWARE t ON h.TIPOHARDWAREID = t.TIPOHARDWAREID \r\n" + // |
|
|
"WHERE h.MANTENIMIENTOID = ?"; |
|
|
"WHERE h.MANTENIMIENTOID = ?"; |
|
|
|
|
|
|
|
|
try (Connection conn = getMysqlConnection(); |
|
|
try (Connection conn = getMysqlConnection(); |
|
@ -320,10 +324,10 @@ public class DatabaseService { |
|
|
String formaMant, String equipoId, String userSignatureBase64, |
|
|
String formaMant, String equipoId, String userSignatureBase64, |
|
|
String smtSignatureBase64, String gciaSignatureBase64, String planAnualId) { |
|
|
String smtSignatureBase64, String gciaSignatureBase64, String planAnualId) { |
|
|
|
|
|
|
|
|
String query = "INSERT INTO MANTENIMIENTOS.MANTENIMIENTOS (fecha, tipoMantId, departamentoId, empleadoId, formaMant, nombreequipo," + |
|
|
|
|
|
|
|
|
String query = "INSERT INTO MANTENIMIENTOS (fecha, tipoMantId, departamentoId, empleadoId, formaMant, nombreequipo," + |
|
|
" firmaUsuario, firmaSmt, firmaGcia, planAnualId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING MANTENIMIENTOID INTO ?"; |
|
|
" firmaUsuario, firmaSmt, firmaGcia, planAnualId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING MANTENIMIENTOID INTO ?"; |
|
|
|
|
|
|
|
|
String updateStatusQuery = "UPDATE MANTENIMIENTOS.PLANANUAL SET estado = 'REALIZADO' WHERE planAnualId = ?"; |
|
|
|
|
|
|
|
|
String updateStatusQuery = "UPDATE PLANANUAL SET estado = 'REALIZADO' WHERE planAnualId = ?"; |
|
|
|
|
|
|
|
|
int nuevoId = -1; |
|
|
int nuevoId = -1; |
|
|
Connection connection = null; |
|
|
Connection connection = null; |
|
@ -418,7 +422,7 @@ public class DatabaseService { |
|
|
|
|
|
|
|
|
// INSERTAR EN LA TABLA: HARDWAREDET |
|
|
// INSERTAR EN LA TABLA: HARDWAREDET |
|
|
public boolean insertarHardware(String tipoHardwareId, String numSerie, String modelo, String placa, int mantenimientoId) { |
|
|
public boolean insertarHardware(String tipoHardwareId, String numSerie, String modelo, String placa, int mantenimientoId) { |
|
|
String query = "INSERT INTO MANTENIMIENTOS.HARDWAREDET (tipoHardwareId, numSerie, modelo, placa, mantenimientoId) VALUES (?, ?, ?, ?, ?)"; |
|
|
|
|
|
|
|
|
String query = "INSERT INTO HARDWAREDET (tipoHardwareId, numSerie, modelo, placa, mantenimientoId) VALUES (?, ?, ?, ?, ?)"; |
|
|
boolean isInserted = false; |
|
|
boolean isInserted = false; |
|
|
|
|
|
|
|
|
try (Connection connection = getMysqlConnection(); |
|
|
try (Connection connection = getMysqlConnection(); |
|
@ -442,7 +446,7 @@ public class DatabaseService { |
|
|
public int getUltimoMantenimientoId() { |
|
|
public int getUltimoMantenimientoId() { |
|
|
int ultimoId = -1; |
|
|
int ultimoId = -1; |
|
|
try (Connection connection = getMysqlConnection()) { |
|
|
try (Connection connection = getMysqlConnection()) { |
|
|
String query = "SELECT MAX(mantenimientoid) FROM MANTENIMIENTOS.MANTENIMIENTOS"; |
|
|
|
|
|
|
|
|
String query = "SELECT MAX(mantenimientoid) FROM MANTENIMIENTOS"; |
|
|
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) { |
|
|
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) { |
|
|
ResultSet resultSet = preparedStatement.executeQuery(); |
|
|
ResultSet resultSet = preparedStatement.executeQuery(); |
|
|
if (resultSet.next()) { |
|
|
if (resultSet.next()) { |
|
@ -458,7 +462,7 @@ public class DatabaseService { |
|
|
|
|
|
|
|
|
// INSERTAR EN LA TABLA: ACTUALIZACIONESSEG |
|
|
// INSERTAR EN LA TABLA: ACTUALIZACIONESSEG |
|
|
public boolean insertActualizacionSeg(String descripcion, String otras, int mantenimientoId) { |
|
|
public boolean insertActualizacionSeg(String descripcion, String otras, int mantenimientoId) { |
|
|
String query = "INSERT INTO MANTENIMIENTOS.ACTUALIZACIONESSEG (descripcion, otrasactualizaciones, mantenimientoid) VALUES (?, ?, ?)"; |
|
|
|
|
|
|
|
|
String query = "INSERT INTO ACTUALIZACIONESSEG (descripcion, otrasactualizaciones, mantenimientoid) VALUES (?, ?, ?)"; |
|
|
|
|
|
|
|
|
try (Connection connection = getMysqlConnection(); |
|
|
try (Connection connection = getMysqlConnection(); |
|
|
PreparedStatement preparedStatement = connection.prepareStatement(query)) { |
|
|
PreparedStatement preparedStatement = connection.prepareStatement(query)) { |
|
@ -477,7 +481,7 @@ public class DatabaseService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void insertarDesdeExcel(InputStream inputStream) { |
|
|
public void insertarDesdeExcel(InputStream inputStream) { |
|
|
String query = "INSERT INTO MANTENIMIENTOS.PLANANUAL (NOMEQUIPO, AREA, MONITOR, TECLADO, MOUSE, " + |
|
|
|
|
|
|
|
|
String query = "INSERT INTO PLANANUAL (NOMEQUIPO, AREA, MONITOR, TECLADO, MOUSE, " + |
|
|
"REGULADOR, CPU, IMPRESORA, MINIPRINT, LAPTOP, ESCANER, FECHAPROG, TECNICOSMT, ESTADO) " + |
|
|
"REGULADOR, CPU, IMPRESORA, MINIPRINT, LAPTOP, ESCANER, FECHAPROG, TECNICOSMT, ESTADO) " + |
|
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; |
|
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; |
|
|
|
|
|
|
|
@ -607,7 +611,7 @@ public class DatabaseService { |
|
|
|
|
|
|
|
|
/* ----------------Actualizar los detalles del del mantenimiento por ID ---------------- */ |
|
|
/* ----------------Actualizar los detalles del del mantenimiento por ID ---------------- */ |
|
|
public boolean actualizarPlanAnual(int planAnualId, String nombreEquipo, LocalDate fechaProg) { |
|
|
public boolean actualizarPlanAnual(int planAnualId, String nombreEquipo, LocalDate fechaProg) { |
|
|
String sql = "UPDATE MANTENIMIENTOS.PLANANUAL SET NOMEQUIPO=?, FECHAPROG=? WHERE PLANANUALID=?"; |
|
|
|
|
|
|
|
|
String sql = "UPDATE PLANANUAL SET NOMEQUIPO=?, FECHAPROG=? WHERE PLANANUALID=?"; |
|
|
try (Connection conn = getMysqlConnection(); |
|
|
try (Connection conn = getMysqlConnection(); |
|
|
PreparedStatement stmt = conn.prepareStatement(sql)) { |
|
|
PreparedStatement stmt = conn.prepareStatement(sql)) { |
|
|
stmt.setString(1, nombreEquipo); |
|
|
stmt.setString(1, nombreEquipo); |
|
@ -621,7 +625,7 @@ public class DatabaseService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public boolean actualizarMantenimiento(int mantenimientoId, int tipoId, String departamentoId, int empleadoId, LocalDate fechaRealizado, String nombreEquipo) { |
|
|
public boolean actualizarMantenimiento(int mantenimientoId, int tipoId, String departamentoId, int empleadoId, LocalDate fechaRealizado, String nombreEquipo) { |
|
|
String sql = "UPDATE MANTENIMIENTOS.MANTENIMIENTOS SET TIPOMANTID=?, DEPARTAMENTOID=?, EMPLEADOID=?, FECHA=?, NOMBREEQUIPO=? WHERE MANTENIMIENTOID=?"; |
|
|
|
|
|
|
|
|
String sql = "UPDATE MANTENIMIENTOS SET TIPOMANTID=?, DEPARTAMENTOID=?, EMPLEADOID=?, FECHA=?, NOMBREEQUIPO=? WHERE MANTENIMIENTOID=?"; |
|
|
try (Connection conn = getMysqlConnection(); |
|
|
try (Connection conn = getMysqlConnection(); |
|
|
PreparedStatement stmt = conn.prepareStatement(sql)) { |
|
|
PreparedStatement stmt = conn.prepareStatement(sql)) { |
|
|
stmt.setInt(1, tipoId); // tipoId es int |
|
|
stmt.setInt(1, tipoId); // tipoId es int |
|
@ -640,7 +644,7 @@ public class DatabaseService { |
|
|
|
|
|
|
|
|
/* ----------------Actualizar los detalles del hardaware por ID ---------------- */ |
|
|
/* ----------------Actualizar los detalles del hardaware por ID ---------------- */ |
|
|
public boolean actualizarHardwareDetalle(HardwareDetalle detalle) { |
|
|
public boolean actualizarHardwareDetalle(HardwareDetalle detalle) { |
|
|
String sql = "UPDATE MANTENIMIENTOS.HARDWAREDET SET MODELO=?, NUMSERIE=?, PLACA=? WHERE HARDWAREDETID=?"; |
|
|
|
|
|
|
|
|
String sql = "UPDATE HARDWAREDET SET MODELO=?, NUMSERIE=?, PLACA=? WHERE HARDWAREDETID=?"; |
|
|
try (Connection conn = getMysqlConnection(); |
|
|
try (Connection conn = getMysqlConnection(); |
|
|
PreparedStatement stmt = conn.prepareStatement(sql)) { |
|
|
PreparedStatement stmt = conn.prepareStatement(sql)) { |
|
|
stmt.setString(1, detalle.getModelo()); |
|
|
stmt.setString(1, detalle.getModelo()); |
|
@ -657,7 +661,7 @@ public class DatabaseService { |
|
|
|
|
|
|
|
|
/* ---------------- Insertar en bitacora ---------------- */ |
|
|
/* ---------------- Insertar en bitacora ---------------- */ |
|
|
public boolean insertarBitacora(int mantenimientoid, String usuarioid, LocalDate fechora, String motivo) { |
|
|
public boolean insertarBitacora(int mantenimientoid, String usuarioid, LocalDate fechora, String motivo) { |
|
|
String query = "INSERT INTO MANTENIMIENTOS.BITACORACTUALIZACIONES (MANTENIMIENTOID, USUARIOID, FECHORA, MOTIVO) VALUES (?, ?, ?, ?)"; |
|
|
|
|
|
|
|
|
String query = "INSERT INTO BITACORACTUALIZACIONES (MANTENIMIENTOID, USUARIOID, FECHORA, MOTIVO) VALUES (?, ?, ?, ?)"; |
|
|
try (Connection conn = getMysqlConnection(); |
|
|
try (Connection conn = getMysqlConnection(); |
|
|
PreparedStatement stmt = conn.prepareStatement(query)) { |
|
|
PreparedStatement stmt = conn.prepareStatement(query)) { |
|
|
stmt.setInt(1, mantenimientoid); |
|
|
stmt.setInt(1, mantenimientoid); |
|
|