|
|
@ -5,8 +5,6 @@ import mx.gob.jumapacelaya.models.*; |
|
|
|
import org.apache.poi.ss.usermodel.*; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
|
|
|
|
import javax.swing.plaf.PanelUI; |
|
|
|
import java.io.FileInputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.sql.*; |
|
|
@ -17,7 +15,7 @@ import java.util.List; |
|
|
|
public class DatabaseService { |
|
|
|
|
|
|
|
|
|
|
|
private Connection getConnection() throws SQLException { |
|
|
|
private Connection getMysqlConnection() throws SQLException { |
|
|
|
String url = "jdbc:mysql://mhdb.jumapacelaya.gob.mx:33006/Mantenimientos"; |
|
|
|
String user = "root"; |
|
|
|
String pass = "mantenimientos"; |
|
|
@ -26,12 +24,21 @@ public class DatabaseService { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private Connection getOracleConnection() throws SQLException { |
|
|
|
String url = "jdbc:oracle:thin:@//svradminfinan:1521/admfinpdb.JUMAPACELAYA.GOB.MX"; |
|
|
|
String user = "Finanzas"; |
|
|
|
String pass = "finanzas"; |
|
|
|
|
|
|
|
return DriverManager.getConnection(url, user, pass); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Método para obtener los tipos de mantenimientos |
|
|
|
public List<TiposMantenimiento> getTiposDeMantenimientos() { |
|
|
|
List<TiposMantenimiento> tiposDeMantenimientos = new ArrayList<>(); |
|
|
|
String query = "SELECT tipomantid, nombre FROM TIPOMANT"; |
|
|
|
|
|
|
|
try (Connection connection = getConnection(); |
|
|
|
try (Connection connection = getMysqlConnection(); |
|
|
|
Statement statement = connection.createStatement(); |
|
|
|
ResultSet resultSet = statement.executeQuery(query)) { |
|
|
|
|
|
|
@ -53,7 +60,7 @@ public class DatabaseService { |
|
|
|
String nomenclatura = ""; |
|
|
|
String query = "SELECT nomenclatura FROM TIPOMANT where TIPOMANTID = ?"; |
|
|
|
|
|
|
|
try (Connection connection = getConnection(); |
|
|
|
try (Connection connection = getMysqlConnection(); |
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(query)) { |
|
|
|
preparedStatement.setString(1, tipoMantenimiento); |
|
|
|
|
|
|
@ -74,9 +81,12 @@ public class DatabaseService { |
|
|
|
/* -------------- Metodo para obtener a los usuarios ---------------- */ |
|
|
|
public List<Usuario> getUsuarios() { |
|
|
|
List<Usuario> usuarios = new ArrayList<>(); |
|
|
|
String query = "select EMPLEADOID, NOMBRE from USUARIOSFINAN"; |
|
|
|
String query = "SELECT u.*, e.EMAIL \n" + |
|
|
|
"FROM ADMON.USUARIOS u\n" + |
|
|
|
"INNER JOIN ADMON.EMPLEADOS e ON\n" + |
|
|
|
"u.EMPLEADOID = e.EMPLEADOID"; |
|
|
|
|
|
|
|
try (Connection connection = getConnection(); |
|
|
|
try (Connection connection = getOracleConnection(); |
|
|
|
Statement statement = connection.createStatement(); |
|
|
|
ResultSet resultSet = statement.executeQuery(query)) { |
|
|
|
|
|
|
@ -97,9 +107,9 @@ public class DatabaseService { |
|
|
|
/* -------------- Metodo para obtener los departamentos ---------------- */ |
|
|
|
public List<DepartamentosModel> getDepartamentos() { |
|
|
|
List<DepartamentosModel> departamentos = new ArrayList<>(); |
|
|
|
String query = "select DEPARTAMENTOID, DESCRIPCION from DEPARTAMENTOSFINAN"; |
|
|
|
String query = "select DEPARTAMENTOID, DESCRIPCION from DEPARTAMENTO"; |
|
|
|
|
|
|
|
try (Connection connection = getConnection(); |
|
|
|
try (Connection connection = getOracleConnection(); |
|
|
|
Statement statement = connection.createStatement(); |
|
|
|
ResultSet resultSet = statement.executeQuery(query)) { |
|
|
|
|
|
|
@ -122,7 +132,7 @@ public class DatabaseService { |
|
|
|
List<TiposHardware> tiposHardware = new ArrayList<>(); |
|
|
|
String query = "select TIPOHARDWAREID, NOMBRETIPO from TIPOSHARDWARE"; |
|
|
|
|
|
|
|
try (Connection connection = getConnection(); |
|
|
|
try (Connection connection = getMysqlConnection(); |
|
|
|
Statement statement = connection.createStatement(); |
|
|
|
ResultSet resultSet = statement.executeQuery(query)) { |
|
|
|
|
|
|
@ -140,25 +150,6 @@ public class DatabaseService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* -------------- Obtener los nombres completos de los usuarios ------------- */ |
|
|
|
public String getNombreUsuario(String usuarioId) { |
|
|
|
String nombreUsuario = ""; |
|
|
|
String query = "SELECT nombre FROM USUARIOSFINAN WHERE usuarioid = ?"; |
|
|
|
|
|
|
|
try (Connection connection = getConnection(); |
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(query)) { |
|
|
|
|
|
|
|
preparedStatement.setString(1, usuarioId); |
|
|
|
ResultSet resultSet = preparedStatement.executeQuery(); |
|
|
|
|
|
|
|
if (resultSet.next()) { |
|
|
|
nombreUsuario = resultSet.getString("NOMBRE"); |
|
|
|
} |
|
|
|
} catch (SQLException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return nombreUsuario; |
|
|
|
} |
|
|
|
|
|
|
|
/* ----------------Obtener el Plan Anual de Mantenimiento ---------------- */ |
|
|
|
public List<PlanAnual> getPlanAnual() { |
|
|
@ -170,7 +161,7 @@ public class DatabaseService { |
|
|
|
"FROM MTTOPROGRAMADOS p " + |
|
|
|
"LEFT JOIN MANTENIMIENTOS m ON p.mttoprogramadoid = m.mttoprogramadoid"; |
|
|
|
|
|
|
|
try (Connection connection = getConnection(); |
|
|
|
try (Connection connection = getMysqlConnection(); |
|
|
|
Statement statement = connection.createStatement(); |
|
|
|
ResultSet resultSet = statement.executeQuery(query)) { |
|
|
|
|
|
|
@ -223,7 +214,7 @@ public class DatabaseService { |
|
|
|
Connection connection = null; |
|
|
|
|
|
|
|
try { |
|
|
|
connection = getConnection(); |
|
|
|
connection = getMysqlConnection(); |
|
|
|
|
|
|
|
if (connection == null) { |
|
|
|
throw new SQLException("No se pudo establecer la conexion con la base de datos."); |
|
|
@ -299,7 +290,7 @@ public class DatabaseService { |
|
|
|
String query = "INSERT INTO HARDWAREDET (tipoHardwareId, numSerie, modelo, placa, mantenimientoId) VALUES (?, ?, ?, ?, ?)"; |
|
|
|
boolean isInserted = false; |
|
|
|
|
|
|
|
try (Connection connection = getConnection(); |
|
|
|
try (Connection connection = getMysqlConnection(); |
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(query)) { |
|
|
|
|
|
|
|
preparedStatement.setString(1, tipoHardwareId); |
|
|
@ -319,7 +310,7 @@ public class DatabaseService { |
|
|
|
|
|
|
|
public int getUltimoMantenimientoId() { |
|
|
|
int ultimoId = -1; |
|
|
|
try (Connection connection = getConnection()) { |
|
|
|
try (Connection connection = getMysqlConnection()) { |
|
|
|
String query = "SELECT MAX(mantenimientoid) FROM MANTENIMIENTOS"; |
|
|
|
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) { |
|
|
|
ResultSet resultSet = preparedStatement.executeQuery(); |
|
|
@ -338,7 +329,7 @@ public class DatabaseService { |
|
|
|
public boolean insertActualizacionSeg(String descripcion, String otras, int mantenimientoId) { |
|
|
|
String query = "INSERT INTO ACTUALIZACIONESSEG (actualizacion, otrasactualizaciones, mantenimientoid) VALUES (?, ?, ?)"; |
|
|
|
|
|
|
|
try (Connection connection = getConnection(); |
|
|
|
try (Connection connection = getMysqlConnection(); |
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(query)) { |
|
|
|
|
|
|
|
preparedStatement.setString(1, descripcion); |
|
|
@ -359,7 +350,7 @@ public class DatabaseService { |
|
|
|
"REGULADOR, CPU, IMPRESORA, MINIPRINT, LAPTOP, ESCANER, FECHAPROG, TECNICOSMT, ESTADO) " + |
|
|
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; |
|
|
|
|
|
|
|
try (Connection connection = getConnection(); |
|
|
|
try (Connection connection = getMysqlConnection(); |
|
|
|
//FileInputStream file = new FileInputStream(rutaArchivoExcel); |
|
|
|
Workbook workbook = new XSSFWorkbook(inputStream)) { |
|
|
|
|
|
|
|