|
|
@ -229,6 +229,7 @@ public class PredioServicio { |
|
|
|
rs.getString("uso"), |
|
|
|
rs.getInt("actividadid"), |
|
|
|
rs.getString("actividad"), |
|
|
|
null, |
|
|
|
null |
|
|
|
)); |
|
|
|
} |
|
|
@ -240,4 +241,341 @@ public class PredioServicio { |
|
|
|
return Optional.empty(); |
|
|
|
} |
|
|
|
|
|
|
|
@ReadOnly |
|
|
|
public Optional<PredioDTO> obtenerPredioAPC(String valor) { |
|
|
|
String query = """ |
|
|
|
SELECT predioid, contrato, clienteid, c.nombre nomcliente, |
|
|
|
fn_getdomicilio(p.direcid) direccion, fn_get_direccion(p.direcid) direccionmostrar, |
|
|
|
fn_direccionshort(p.direcid) direccioncorta, |
|
|
|
p.coordx, p.coordy, p.zonafactid, p.serialmed, |
|
|
|
edopredioid, e.nombre edopredio, usoid, u.nombre uso, |
|
|
|
actividadid, a.nombre actividad |
|
|
|
FROM predios p |
|
|
|
LEFT JOIN clientes c USING (clienteid) |
|
|
|
LEFT JOIN estadospredio e USING(edopredioid) |
|
|
|
LEFT JOIN usos u USING (usoid) |
|
|
|
LEFT JOIN actividades a USING (usoid, actividadid) |
|
|
|
WHERE ( |
|
|
|
(LENGTH(?) = 30 AND predioid = SUBSTR(?, 24, 6)) OR |
|
|
|
(LENGTH(?) = 8 AND REGEXP_LIKE(contrato, ?)) OR |
|
|
|
(LENGTH(?) <= 6 AND predioid = TO_NUMBER(?)) |
|
|
|
) |
|
|
|
"""; |
|
|
|
|
|
|
|
try (Connection connection = dataSource.getConnection(); |
|
|
|
PreparedStatement stmt = connection.prepareStatement(query)) { |
|
|
|
|
|
|
|
for (int i = 1; i <= 6; i++) { |
|
|
|
stmt.setString(i, valor); |
|
|
|
} |
|
|
|
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) { |
|
|
|
if (rs.next()) { |
|
|
|
return Optional.of(new PredioDTO( |
|
|
|
rs.getLong("predioid"), |
|
|
|
rs.getLong("clienteid"), |
|
|
|
rs.getString("contrato"), |
|
|
|
rs.getString("nomcliente"), |
|
|
|
rs.getString("direccion"), |
|
|
|
rs.getString("direccionmostrar"), |
|
|
|
rs.getString("direccioncorta"), |
|
|
|
null, |
|
|
|
rs.getDouble("coordx"), |
|
|
|
rs.getDouble("coordy"), |
|
|
|
rs.getString("zonafactid"), |
|
|
|
rs.getString("serialmed"), |
|
|
|
null, |
|
|
|
null, |
|
|
|
rs.getString("edopredioid"), |
|
|
|
rs.getString("edopredio"), |
|
|
|
rs.getString("usoid"), |
|
|
|
rs.getString("uso"), |
|
|
|
rs.getInt("actividadid"), |
|
|
|
rs.getString("actividad") |
|
|
|
)); |
|
|
|
} else { |
|
|
|
return Optional.empty(); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (SQLException e) { |
|
|
|
throw new RuntimeException("Error al consultar predio APC: " + e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ReadOnly |
|
|
|
public Optional<PredioDTO> obtenerPredioAppOTs(Long predioId) { |
|
|
|
String query = """ |
|
|
|
SELECT predioid, contrato, clienteid, c.nombre nomcliente, |
|
|
|
fn_getdomicilio(p.direcid) direccion, fn_get_direccion(p.direcid) direccionmostrar, |
|
|
|
fn_direccionshort(p.direcid) direccioncorta, |
|
|
|
p.coordx, p.coordy, p.zonafactid, p.serialmed, |
|
|
|
edopredioid, e.nombre edopredio, usoid, u.nombre uso, |
|
|
|
actividadid, a.nombre actividad, fn_get_tarifa(p.predioid) tarifa |
|
|
|
FROM predios p |
|
|
|
LEFT JOIN clientes c USING (clienteid) |
|
|
|
LEFT JOIN estadospredio e USING (edopredioid) |
|
|
|
LEFT JOIN usos u USING (usoid) |
|
|
|
LEFT JOIN actividades a USING (usoid, actividadid) |
|
|
|
WHERE predioid = ? |
|
|
|
"""; |
|
|
|
|
|
|
|
try (Connection connection = dataSource.getConnection(); |
|
|
|
PreparedStatement stmt = connection.prepareStatement(query)) { |
|
|
|
|
|
|
|
stmt.setLong(1, predioId); |
|
|
|
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) { |
|
|
|
if (rs.next()) { |
|
|
|
return Optional.of(new PredioDTO( |
|
|
|
rs.getLong("predioid"), |
|
|
|
rs.getLong("clienteid"), |
|
|
|
rs.getString("contrato"), |
|
|
|
rs.getString("nomcliente"), |
|
|
|
rs.getString("direccion"), |
|
|
|
rs.getString("direccionmostrar"), |
|
|
|
rs.getString("direccioncorta"), |
|
|
|
null, |
|
|
|
rs.getDouble("coordx"), |
|
|
|
rs.getDouble("coordy"), |
|
|
|
rs.getString("zonafactid"), |
|
|
|
rs.getString("serialmed"), |
|
|
|
null, |
|
|
|
null, |
|
|
|
rs.getString("edopredioid"), |
|
|
|
rs.getString("edopredio"), |
|
|
|
rs.getString("usoid"), |
|
|
|
rs.getString("uso"), |
|
|
|
rs.getInt("actividadid"), |
|
|
|
rs.getString("actividad"), |
|
|
|
null, |
|
|
|
rs.getString("tarifa") |
|
|
|
) |
|
|
|
); |
|
|
|
} else { |
|
|
|
return Optional.empty(); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (SQLException e) { |
|
|
|
throw new RuntimeException("Error al consultar predio AppOTs: " + e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ReadOnly |
|
|
|
public Optional<PredioDTO> obtenerDireccionPredio(Long predioId) { |
|
|
|
String query = """ |
|
|
|
SELECT predioid, contrato, clienteid, c.nombre nomcliente, |
|
|
|
fn_getdomicilio(p.direcid) direccion, |
|
|
|
fn_get_direccion(p.direcid) direccionmostrar, |
|
|
|
fn_direccionshort(p.direcid) direccioncorta |
|
|
|
FROM predios p |
|
|
|
LEFT JOIN clientes c USING (clienteid) |
|
|
|
WHERE predioid = ? |
|
|
|
"""; |
|
|
|
|
|
|
|
try (Connection connection = dataSource.getConnection(); |
|
|
|
PreparedStatement stmt = connection.prepareStatement(query)) { |
|
|
|
|
|
|
|
stmt.setLong(1, predioId); |
|
|
|
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) { |
|
|
|
if (rs.next()) { |
|
|
|
return Optional.of(new PredioDTO( |
|
|
|
rs.getLong("predioid"), |
|
|
|
rs.getLong("clienteid"), |
|
|
|
rs.getString("contrato"), |
|
|
|
rs.getString("nomcliente"), |
|
|
|
rs.getString("direccion"), |
|
|
|
rs.getString("direccionmostrar"), |
|
|
|
rs.getString("direccioncorta"), |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (SQLException e) { |
|
|
|
throw new RuntimeException("Error al obtener dirección del predio: " + e.getMessage(), e); |
|
|
|
} |
|
|
|
return Optional.empty(); |
|
|
|
} |
|
|
|
|
|
|
|
@ReadOnly |
|
|
|
public String obtenerDireccionCooper(Long predioId) { |
|
|
|
String query = "SELECT fn_direccionshort(p.direcid) AS direccion FROM predios p WHERE predioid = ?"; |
|
|
|
|
|
|
|
try (Connection connection = dataSource.getConnection(); |
|
|
|
PreparedStatement stmt = connection.prepareStatement(query)) { |
|
|
|
|
|
|
|
stmt.setLong(1, predioId); |
|
|
|
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) { |
|
|
|
if (rs.next()) { |
|
|
|
String direccion = rs.getString("direccion"); |
|
|
|
if (direccion != null && !direccion.isBlank()) { |
|
|
|
return "TU DIRECCIÓN ES: " + direccion; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (SQLException e) { |
|
|
|
throw new RuntimeException("Error al obtener la dirección corta del predio: " + e.getMessage(), e); |
|
|
|
} |
|
|
|
|
|
|
|
return "El número de predio: " + predioId + " no existe. Por favor verificalo en tu recibo."; |
|
|
|
} |
|
|
|
|
|
|
|
@ReadOnly |
|
|
|
public Optional<String> obtenerDireccionCoopers(Long predioId) { |
|
|
|
String query = "SELECT fn_direccionshort(p.direcid) AS direccion FROM predios p WHERE predioid = ?"; |
|
|
|
|
|
|
|
try (Connection connection = dataSource.getConnection(); |
|
|
|
PreparedStatement stmt = connection.prepareStatement(query)) { |
|
|
|
|
|
|
|
stmt.setLong(1, predioId); |
|
|
|
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) { |
|
|
|
if (rs.next()) { |
|
|
|
return Optional.ofNullable(rs.getString("direccion")); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (SQLException e) { |
|
|
|
throw new RuntimeException("Error al obtener la dirección corta cruda: " + e.getMessage(), e); |
|
|
|
} |
|
|
|
|
|
|
|
return Optional.empty(); |
|
|
|
} |
|
|
|
|
|
|
|
@ReadOnly |
|
|
|
public Optional<Double> obtenerCoordX(Long predioId) { |
|
|
|
String query = "SELECT coordx FROM predios WHERE predioid = ?"; |
|
|
|
|
|
|
|
try (Connection connection = dataSource.getConnection(); |
|
|
|
PreparedStatement stmt = connection.prepareStatement(query)) { |
|
|
|
|
|
|
|
stmt.setLong(1, predioId); |
|
|
|
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) { |
|
|
|
if (rs.next()) { |
|
|
|
return Optional.ofNullable(rs.getDouble("coordx")); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (SQLException e) { |
|
|
|
throw new RuntimeException("Error al obtener coordx: " + e.getMessage(), e); |
|
|
|
} |
|
|
|
|
|
|
|
return Optional.empty(); |
|
|
|
} |
|
|
|
|
|
|
|
@ReadOnly |
|
|
|
public Optional<Double> obtenerCoordY(Long predioId) { |
|
|
|
String query = "SELECT coordy FROM predios WHERE predioid = ?"; |
|
|
|
|
|
|
|
try (Connection connection = dataSource.getConnection(); |
|
|
|
PreparedStatement stmt = connection.prepareStatement(query)) { |
|
|
|
|
|
|
|
stmt.setLong(1, predioId); |
|
|
|
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) { |
|
|
|
if (rs.next()) { |
|
|
|
return Optional.ofNullable(rs.getDouble("coordy")); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (SQLException e) { |
|
|
|
throw new RuntimeException("Error al obtener coordy: " + e.getMessage(), e); |
|
|
|
} |
|
|
|
|
|
|
|
return Optional.empty(); |
|
|
|
} |
|
|
|
|
|
|
|
@ReadOnly |
|
|
|
public Optional<Long> obtenerClienteId(Long predioId) { |
|
|
|
String query = "SELECT clienteid FROM predios WHERE predioid = ?"; |
|
|
|
|
|
|
|
try (Connection connection = dataSource.getConnection(); |
|
|
|
PreparedStatement stmt = connection.prepareStatement(query)) { |
|
|
|
|
|
|
|
stmt.setLong(1, predioId); |
|
|
|
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) { |
|
|
|
if (rs.next()) { |
|
|
|
return Optional.of(rs.getLong("clienteid")); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (SQLException e) { |
|
|
|
throw new RuntimeException("Error al obtener clienteid: " + e.getMessage(), e); |
|
|
|
} |
|
|
|
|
|
|
|
return Optional.empty(); |
|
|
|
} |
|
|
|
|
|
|
|
@ReadOnly |
|
|
|
public Optional<Long> obtenerOT(Long predioId, String motivoId) { |
|
|
|
String query = """ |
|
|
|
SELECT MAX(otid) otid |
|
|
|
FROM ordentrabajoenc |
|
|
|
WHERE predioid = ? |
|
|
|
AND motivoid = ? |
|
|
|
AND fechaprecierre IS NULL |
|
|
|
AND fechaanulacion IS NULL |
|
|
|
"""; |
|
|
|
|
|
|
|
try (Connection connection = dataSource.getConnection(); |
|
|
|
PreparedStatement stmt = connection.prepareStatement(query)) { |
|
|
|
|
|
|
|
stmt.setLong(1, predioId); |
|
|
|
stmt.setString(2, motivoId); |
|
|
|
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) { |
|
|
|
if (rs.next()) { |
|
|
|
long otid = rs.getLong("otid"); |
|
|
|
if (!rs.wasNull()) { |
|
|
|
return Optional.of(otid); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (SQLException e) { |
|
|
|
throw new RuntimeException("Error al obtener OT: " + e.getMessage(), e); |
|
|
|
} |
|
|
|
|
|
|
|
return Optional.empty(); |
|
|
|
} |
|
|
|
|
|
|
|
@ReadOnly |
|
|
|
public Optional<String> obtenerSituacionCorte(Long predioId, String tipo) { |
|
|
|
String query = "SELECT fn_getsituacioncorte(?, ?) AS situacion FROM dual"; |
|
|
|
|
|
|
|
try (Connection connection = dataSource.getConnection(); |
|
|
|
PreparedStatement stmt = connection.prepareStatement(query)) { |
|
|
|
|
|
|
|
stmt.setLong(1, predioId); |
|
|
|
stmt.setString(2, tipo); |
|
|
|
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) { |
|
|
|
if (rs.next()) { |
|
|
|
String situacion = rs.getString("situacion"); |
|
|
|
if (situacion != null && !situacion.trim().isEmpty() && |
|
|
|
!situacion.equalsIgnoreCase("Sin Corte") && |
|
|
|
!situacion.equalsIgnoreCase("Reconexion Solicitada")) { |
|
|
|
return Optional.of(situacion); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (SQLException e) { |
|
|
|
throw new RuntimeException("Error al consultar situación de corte: " + e.getMessage(), e); |
|
|
|
} |
|
|
|
|
|
|
|
return Optional.empty(); |
|
|
|
} |
|
|
|
|
|
|
|
} |