From 5026c23897c962e0267cd45dff029c8babd93b79 Mon Sep 17 00:00:00 2001 From: ilyin Date: Sat, 21 Sep 2024 17:07:14 +0300 Subject: [PATCH] save --- .../config-examples/block.xml | 48 ++---- .../config-examples/removeFromCallList.xml | 20 +-- .../config-examples/removeFromSystem.xml | 157 +++++------------- .../config-examples/unblock.xml | 2 +- сonfig-data-executor/output.log | 0 .../org/micord/service/RequestService.java | 27 +-- 6 files changed, 75 insertions(+), 179 deletions(-) create mode 100644 сonfig-data-executor/output.log diff --git a/сonfig-data-executor/config-examples/block.xml b/сonfig-data-executor/config-examples/block.xml index 4db0347..6518063 100644 --- a/сonfig-data-executor/config-examples/block.xml +++ b/сonfig-data-executor/config-examples/block.xml @@ -16,16 +16,11 @@ ',"dio":'|| coalesce('"'||department_id_old::text||'"','null')|| ',"st":'|| coalesce('"'||system_pgs_status::text||'"','null')||'}')::jsonb ) - where ${clause}; + where id in ${endpointArguments} ${extraConditions}; end $$; ]]> - - - id - - localhost 5432 @@ -44,32 +39,27 @@ DO $$ BEGIN - DELETE FROM subpoena_history where subpoena_id in (select id FROM subpoena where ${clause}); - DELETE FROM subpoena_appearance where subpoena_id in (select id FROM subpoena where ${clause}); - DELETE FROM subpoena_send_info where subpoena_id in (select id FROM subpoena where ${clause}); + DELETE FROM subpoena_history where subpoena_id in (select id FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM subpoena_appearance where subpoena_id in (select id FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions})); + DELETE FROM subpoena_send_info where subpoena_id in (select id FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions})); DELETE FROM notification_item where restriction_document_item_id in ( select id from restriction_document_item where restriction_document_create_id in ( - select id FROM restriction_document where subpoena_id in (select id FROM subpoena where ${clause}))); + select id FROM restriction_document where subpoena_id in (select id FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions})))); DELETE FROM notification_item where restriction_document_item_id in ( select id from restriction_document_item where restriction_document_cancel_id in ( - select id FROM restriction_document where subpoena_id in (select id FROM subpoena where ${clause}))); + select id FROM restriction_document where subpoena_id in (select id FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions})))); DELETE FROM restriction_document_item where restriction_document_create_id in ( - select id FROM restriction_document where subpoena_id in (select id FROM subpoena where ${clause})); + select id FROM restriction_document where subpoena_id in (select id FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions}))); DELETE FROM restriction_document_item where restriction_document_cancel_id in ( - select id FROM restriction_document where subpoena_id in (select id FROM subpoena where ${clause})); - DELETE FROM restriction_document where subpoena_id in (select id FROM subpoena where ${clause}); - DELETE FROM subpoena where ${clause}; + select id FROM restriction_document where subpoena_id in (select id FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions}))); + DELETE FROM restriction_document where subpoena_id in (select id FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions})); + DELETE FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - recruit_id - - localhost 5432 @@ -90,17 +80,12 @@ BEGIN DELETE FROM incident_history - where incident_id in (select id from incident where ${clause}); - DELETE FROM incident where ${clause}; + where incident_id in (select id from incident where recruit_id in ${endpointArguments} ${extraConditions})); + DELETE FROM incident where recruit_id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - recruit_id - - localhost 5432 @@ -119,16 +104,11 @@ DO $$ BEGIN - DELETE FROM notifications where ${clause}; + DELETE FROM notifications where recruit_id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - recruit_id - - localhost 5432 @@ -147,7 +127,7 @@ DO $$ DECLARE - recruitIds uuid[] := '{${ids}}'; + recruitIds uuid[] := '{${endpointArguments}}'; importIds uuid[] := ARRAY(SELECT import_id FROM import_results WHERE recruit_id = ANY (recruitIds)); diff --git a/сonfig-data-executor/config-examples/removeFromCallList.xml b/сonfig-data-executor/config-examples/removeFromCallList.xml index 876c441..673af80 100644 --- a/сonfig-data-executor/config-examples/removeFromCallList.xml +++ b/сonfig-data-executor/config-examples/removeFromCallList.xml @@ -5,19 +5,14 @@ DO $$ BEGIN - DELETE FROM summoned_list where ${clause}; - DELETE FROM recruit_active_list where ${clause}; - DELETE FROM documents where ${clause}; - DELETE FROM subpoena where ${clause}; + DELETE FROM summoned_list where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM recruit_active_list where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM documents where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - recruit_id - - 10.10.31.118 5432 @@ -43,16 +38,11 @@ ,system_pgs_status = '1.2' ,conscription = null ,extra_info = extra_info - ('blocked') - where ${clause}; + where id in ${endpointArguments} ${extraConditions}; end $$; ]]> - - - id - - 10.10.31.118 5432 diff --git a/сonfig-data-executor/config-examples/removeFromSystem.xml b/сonfig-data-executor/config-examples/removeFromSystem.xml index a90d2dc..f185111 100644 --- a/сonfig-data-executor/config-examples/removeFromSystem.xml +++ b/сonfig-data-executor/config-examples/removeFromSystem.xml @@ -5,33 +5,28 @@ DO $$ BEGIN - DELETE FROM subpoena_history where subpoena_id in (select id FROM subpoena where ${clause}); - DELETE FROM subpoena_appearance where subpoena_id in (select id FROM subpoena where ${clause}); - DELETE FROM subpoena_send_info where subpoena_id in (select id FROM subpoena where ${clause}); + DELETE FROM subpoena_history where subpoena_id in (select id FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions}); + DELETE FROM subpoena_appearance where subpoena_id in (select id FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions}); + DELETE FROM subpoena_send_info where subpoena_id in (select id FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions}); DELETE FROM notification_item where restriction_document_item_id in ( select id from restriction_document_item where restriction_document_create_id in ( - select id FROM restriction_document where subpoena_id in (select id FROM subpoena where ${clause}))); + select id FROM restriction_document where subpoena_id in (select id FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions}))); DELETE FROM notification_item where restriction_document_item_id in ( select id from restriction_document_item where restriction_document_cancel_id in ( - select id FROM restriction_document where subpoena_id in (select id FROM subpoena where ${clause}))); + select id FROM restriction_document where subpoena_id in (select id FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions}))); - DELETE FROM restriction_document_item_history WHERE ${clause}; + DELETE FROM restriction_document_item_history WHERE recruit_id in ${endpointArguments} ${extraConditions}; DELETE FROM restriction_document_item where restriction_document_create_id in ( - select id FROM restriction_document where subpoena_id in (select id FROM subpoena where ${clause})); + select id FROM restriction_document where subpoena_id in (select id FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions})); DELETE FROM restriction_document_item where restriction_document_cancel_id in ( - select id FROM restriction_document where subpoena_id in (select id FROM subpoena where ${clause})); - DELETE FROM restriction_document where subpoena_id in (select id FROM subpoena where ${clause}); - DELETE FROM subpoena where ${clause}; + select id FROM restriction_document where subpoena_id in (select id FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions})); + DELETE FROM restriction_document where subpoena_id in (select id FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions}); + DELETE FROM subpoena where recruit_id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - recruit_id - - localhost 5432 @@ -51,16 +46,11 @@ DO $$ BEGIN - DELETE FROM recruits WHERE ${clause}; + DELETE FROM recruits WHERE id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - id - - localhost 5432 @@ -79,21 +69,15 @@ DO $$ BEGIN - DELETE FROM decision where ${clause}; - DELETE FROM foreign_decision where ${clause}; - DELETE FROM infringement where ${clause}; - DELETE FROM system_document where attachment_id in (SELECT id FROM attachment where ${clause}) ; - DELETE FROM attachment where ${clause}; - DELETE FROM recruit where id = any (var1); + DELETE FROM decision where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM foreign_decision where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM infringement where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM system_document where attachment_id in (SELECT id FROM attachment where recruit_id in ${endpointArguments} ${extraConditions}) ; + DELETE FROM attachment where recruit_id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - recruit_id - - localhost 5432 @@ -113,16 +97,11 @@ DO $$ BEGIN - DELETE FROM recruit where ${clause}; + DELETE FROM recruit where id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - id - - localhost 5432 @@ -135,14 +114,13 @@ - - - - id - - localhost 5432 @@ -186,16 +159,11 @@ DO $$ BEGIN - DELETE FROM notifications where ${clause}; + DELETE FROM notifications where recruit_id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - recruit_id - - localhost 5432 @@ -216,18 +184,12 @@ BEGIN DELETE FROM incident_history - where incident_id in (select id from incident where ${clause}); - DELETE FROM incident where ${clause}; - DELETE FROM recruits where id = any (var1); + where incident_id in (select id from incident where recruit_id in ${endpointArguments} ${extraConditions}); + DELETE FROM incident where recruit_id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - recruit_id - - localhost 5432 @@ -247,16 +209,11 @@ DO $$ BEGIN - DELETE FROM recruits where ${clause}; + DELETE FROM recruits where id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - id - - localhost 5432 @@ -275,30 +232,24 @@ DO $$ BEGIN - DELETE FROM recruits_info where ${clause}; - DELETE FROM recruit_xml_data where ${clause}; - DELETE FROM recruits_history where ${clause}; - DELETE FROM application where ${clause}; - DELETE FROM department_history where ${clause}; - DELETE FROM documents where ${clause}; - DELETE FROM decision where ${clause}; - DELETE FROM personal_documents where ${clause}; - DELETE FROM recruit_private_file where ${clause}; - DELETE FROM system_documents where ${clause}; - DELETE FROM system_document_dto where ${clause}; - DELETE FROM subpoena_dto where ${clause}; - DELETE FROM attachments where ${clause}; - DELETE FROM summoned_list where ${clause}; - DELETE FROM recruits where id = any (var1); + DELETE FROM recruits_info where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM recruit_xml_data where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM recruits_history where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM application where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM department_history where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM documents where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM decision where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM personal_documents where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM recruit_private_file where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM system_documents where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM system_document_dto where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM subpoena_dto where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM attachments where recruit_id in ${endpointArguments} ${extraConditions}; + DELETE FROM summoned_list where recruit_id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - recruit_id - - localhost 5432 @@ -318,16 +269,11 @@ DO $$ BEGIN - DELETE FROM recruits where ${clause}; + DELETE FROM recruits where id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - id - - localhost 5432 @@ -346,17 +292,11 @@ DO $$ BEGIN - DELETE FROM appeal_document where ${clause}; - DELETE FROM recruit where id = any (var1); + DELETE FROM appeal_document where recruit_id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - recruit_id - - localhost 5432 @@ -376,16 +316,11 @@ DO $$ BEGIN - DELETE FROM recruit where ${clause}; + DELETE FROM recruit where id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - id - - localhost 5432 @@ -404,16 +339,11 @@ DO $$ BEGIN - delete from cruit_extract where ${clause}; + delete from cruit_extract where recruit_id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - recruit_id - - localhost 5432 @@ -432,16 +362,11 @@ DO $$ BEGIN - delete from application_info where ${clause}; + delete from application_info where recruit_id in ${endpointArguments} ${extraConditions}; END $$; ]]> - - - recruit_id - - localhost 5432 diff --git a/сonfig-data-executor/config-examples/unblock.xml b/сonfig-data-executor/config-examples/unblock.xml index a84c7e1..4184d5c 100644 --- a/сonfig-data-executor/config-examples/unblock.xml +++ b/сonfig-data-executor/config-examples/unblock.xml @@ -12,7 +12,7 @@ ,system_pgs_status = '1.2' ,conscription = null ,extra_info = extra_info - ('blocked') - where ${clause}; + where id in ${endpointArguments} ${extraConditions}; end $$; ]]> diff --git a/сonfig-data-executor/output.log b/сonfig-data-executor/output.log new file mode 100644 index 0000000..e69de29 diff --git a/сonfig-data-executor/src/main/java/org/micord/service/RequestService.java b/сonfig-data-executor/src/main/java/org/micord/service/RequestService.java index ed1d774..e51ed8f 100644 --- a/сonfig-data-executor/src/main/java/org/micord/service/RequestService.java +++ b/сonfig-data-executor/src/main/java/org/micord/service/RequestService.java @@ -8,11 +8,9 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; import com.arangodb.ArangoCursor; import com.arangodb.ArangoDBException; @@ -132,22 +130,25 @@ public class RequestService { } private void processSqlRequests(SqlRequest request, List ids) { + String query = null; try (Connection connection = DatabaseConnection.getConnection( request.getSqlConnectionParams())) { - String query = buildSqlQuery(request, String.join(",", ids)); + query = buildSqlQuery(request, String.join(",", ids)); executeSqlQuery(connection, query); } catch (SQLException e) { - logger.error("SQL query execution failed", e); + logger.error("SQL execution failed for query: {}", query, e); } } private String buildSqlQuery(SqlRequest request, String ids) { - StringBuilder clauseBuilder = new StringBuilder(); + StringBuilder extraConditionsBuilder = new StringBuilder(); + String endpointArguments = " (" + Arrays.stream(ids.split(",")) + .map(id -> "'" + id.trim() + "'") + .collect(Collectors.joining(", ")) + ")"; if (request.getRequestArguments() != null && !request.getRequestArguments().isEmpty()) { for (RequestArgument argument : request.getRequestArguments()) { - clauseBuilder.append(argument.getId()).append(" IN (").append(ids).append(")"); if (argument.getSqlConnectionParams() != null) { try (Connection connection = DatabaseConnection.getConnection( @@ -159,7 +160,7 @@ public class RequestService { String resultSet = String.join(", ", result.stream() .map(s -> "'" + s + "'") .toArray(String[]::new)); - clauseBuilder.append(" OR ") + extraConditionsBuilder.append(" OR ") .append(argument.getId()) .append(" IN (") .append(resultSet) @@ -173,11 +174,11 @@ public class RequestService { } } - String clause = clauseBuilder.toString(); + String extraConditions = extraConditionsBuilder.toString(); return request.getRequestURL() - .replace("${DB}", request.getSqlConnectionParams().getJdbcDatabase()) - .replace("${clause}", clause) - .replace("${ids}", ids); + .replace("${DB}", request.getSqlConnectionParams().getJdbcDatabase()) + .replace("${extraConditions}", extraConditions) + .replace("${endpointArguments}", endpointArguments); } private void executeSqlQuery(Connection connection, String query) throws SQLException {