From fbd6bed123d1f6c4ad7e737a5899320b2e108270 Mon Sep 17 00:00:00 2001 From: Ruslan Date: Mon, 23 Sep 2024 17:36:50 +0300 Subject: [PATCH] // --- entrypoint.sh | 50 +- mappings/country/appeals.reasons_appeal.ktr | 665 +++++++++++++ mappings/country/main_dashboard.appeals.ktr | 116 +-- .../main_dashboard.recruitment_campaign.ktr | 336 +++---- .../main_dashboard.total_registered.ktr | 105 +- .../main_dashboard.waiting_registration.ktr | 106 +- .../recruitment_campaign.subpoenas.ktr | 508 +++++----- mappings/country/total_registered.age.ktr | 831 ++++++++++++---- .../country/total_registered.busyness.ktr | 707 ++++++++++++- .../country/total_registered.child_minor.ktr | 210 ---- .../total_registered.driver_license.ktr | 210 ---- .../country/total_registered.reg_mil_cat.ktr | 371 +++++-- .../country/total_registered.subpoenas.ktr | 548 +++++------ mappings/info_recruits/disability.ktr | 735 ++++++++++++++ mappings/info_recruits/disease.ktr | 644 ++++++++++++ mappings/info_recruits/drivers_licence.ktr | 743 ++++++++++++++ mappings/info_recruits/job_info_recruits.kjb | 453 ++++++++- .../info_recruits/medical_authorities.ktr | 736 ++++++++++++++ mappings/info_recruits/property.ktr | 931 ++++++++++++++++++ mappings/info_recruits/spouse.ktr | 126 +-- mappings/pack.pub_recruitment.ktr | 2 +- mappings/region/job_recruitments_region.kjb | 28 +- .../region/main_dashboard.appeals(reg).ktr | 72 +- ...in_dashboard.recruitment_campaign(reg).ktr | 246 +++-- .../main_dashboard.total_registered(reg).ktr | 79 +- ...in_dashboard.waiting_registration(reg).ktr | 44 +- .../recruitment_campaign.subpoenas(reg).ktr | 464 +++++---- .../select_recruitments_region(reg).ktr | 14 +- mappings/region/total_registered.age(reg).ktr | 327 ++++-- .../region/total_registered.busyness(reg).ktr | 145 ++- .../total_registered.child_minor(reg).ktr | 238 +++-- .../total_registered.driver_license(reg).ktr | 97 +- .../total_registered.education_level(reg).ktr | 208 ++-- .../total_registered.marital_status(reg).ktr | 253 +++-- .../total_registered.reg_mil_cat(reg).ktr | 497 +++++++++- ...total_registered.removed_registry(reg).ktr | 96 +- .../total_registered.subpoenas(reg).ktr | 785 ++++++++------- 37 files changed, 9620 insertions(+), 3106 deletions(-) create mode 100644 mappings/country/appeals.reasons_appeal.ktr create mode 100644 mappings/info_recruits/disability.ktr create mode 100644 mappings/info_recruits/disease.ktr create mode 100644 mappings/info_recruits/drivers_licence.ktr create mode 100644 mappings/info_recruits/medical_authorities.ktr create mode 100644 mappings/info_recruits/property.ktr diff --git a/entrypoint.sh b/entrypoint.sh index a52d8d2..e5eefbc 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -12,35 +12,35 @@ export TZ=Europe/Moscow cd /opt/pentaho-di/mappings for F in $(find . -type f); do - sed -i "s/1111/$DB_DASHBOARD_PORT/g" $F - sed -i "s/dashboard-dbhost/$DB_DASHBOARD_HOST/g" $F - sed -i "s/dashboard-dbname/$DB_DASHBOARD_NAME/g" $F - sed -i "s/dashboard-dbuser/$DB_DASHBOARD_USERNAME/g" $F - sed -i "s/Encrypted 2daf9dca008c89396af54aa72ce93bcc9/$DB_DASHBOARD_PASSWORD/g" $F + sed -i "s//$DB_DASHBOARD_PORT/g" $F + sed -i "s//$DB_DASHBOARD_HOST/g" $F + sed -i "s//$DB_DASHBOARD_NAME/g" $F + sed -i "s//$DB_DASHBOARD_USERNAME/g" $F + sed -i "s//$DB_DASHBOARD_PASSWORD/g" $F - sed -i "s/2222/$DB_APPEAL_PORT/g" $F - sed -i "s/appeal-dbhost/$DB_APPEAL_HOST/g" $F - sed -i "s/appeal-dbname/$DB_APPEAL_NAME/g" $F - sed -i "s/appeal-dbuser/$DB_APPEAL_USERNAME/g" $F - sed -i "s/Encrypted 2be98afa91ad79785a754aa72ce93bcc9/$DB_APPEAL_PASSWORD/g" $F + sed -i "s//$DB_APPEAL_PORT/g" $F + sed -i "s//$DB_APPEAL_HOST/g" $F + sed -i "s//$DB_APPEAL_NAME/g" $F + sed -i "s//$DB_APPEAL_USERNAME/g" $F + sed -i "s//$DB_APPEAL_PASSWORD/g" $F - sed -i "s/3333/$DB_DECISION_PORT/g" $F - sed -i "s/decision-dbhost/$DB_DECISION_HOST/g" $F - sed -i "s/decision-dbname/$DB_DECISION_NAME/g" $F - sed -i "s/decision-dbuser/$DB_DECISION_USERNAME/g" $F - sed -i "s/Encrypted 2befccaab03d49b8ba554aa72ce93bcc9/$DB_DECISION_PASSWORD/g" $F + sed -i "s//$DB_DECISION_PORT/g" $F + sed -i "s//$DB_DECISION_HOST/g" $F + sed -i "s//$DB_DECISION_NAME/g" $F + sed -i "s//$DB_DECISION_USERNAME/g" $F + sed -i "s//$DB_DECISION_PASSWORD/g" $F - sed -i "s/4444/$DB_PERSON_PORT/g" $F - sed -i "s/person-dbhost/$DB_PERSON_HOST/g" $F - sed -i "s/person-dbname/$DB_PERSON_NAME/g" $F - sed -i "s/person-dbuser/$DB_PERSON_USERNAME/g" $F - sed -i "s/Encrypted 2be98afb80fd5818ba554aa72ce93bcc9/$DB_PERSON_PASSWORD/g" $F + sed -i "s//$DB_PERSON_PORT/g" $F + sed -i "s//$DB_PERSON_HOST/g" $F + sed -i "s//$DB_PERSON_NAME/g" $F + sed -i "s//$DB_PERSON_USERNAME/g" $F + sed -i "s//$DB_PERSON_PASSWORD/g" $F - sed -i "s/5555/$DB_SUBPOENA_PORT/g" $F - sed -i "s/subpoena-dbhost/$DB_SUBPOENA_HOST/g" $F - sed -i "s/subpoena-dbname/$DB_SUBPOENA_NAME/g" $F - sed -i "s/subpoena-dbuser/$DB_SUBPOENA_USERNAME/g" $F - sed -i "s/Encrypted 2beebdaaa1ac8978aaa54aa72ce93bcc9/$DB_SUBPOENA_PASSWORD/g" $F + sed -i "s//$DB_SUBPOENA_PORT/g" $F + sed -i "s//$DB_SUBPOENA_HOST/g" $F + sed -i "s//$DB_SUBPOENA_NAME/g" $F + sed -i "s//$DB_SUBPOENA_USERNAME/g" $F + sed -i "s//$DB_SUBPOENA_PASSWORD/g" $F done; #Запускаем job один раз при старте контейнера diff --git a/mappings/country/appeals.reasons_appeal.ktr b/mappings/country/appeals.reasons_appeal.ktr new file mode 100644 index 0000000..f4d2eb1 --- /dev/null +++ b/mappings/country/appeals.reasons_appeal.ktr @@ -0,0 +1,665 @@ + + + + appeals.reasons_appeal + + + + Normal + 0 + / + + + + + + + + + + + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + TRANSNAME + Y + TRANSNAME + + + STATUS + Y + STATUS + + + LINES_READ + Y + LINES_READ + + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + + LINES_UPDATED + Y + LINES_UPDATED + + + + LINES_INPUT + Y + LINES_INPUT + + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + + LINES_REJECTED + Y + LINES_REJECTED + + + + ERRORS + Y + ERRORS + + + STARTDATE + Y + STARTDATE + + + ENDDATE + Y + ENDDATE + + + LOGDATE + Y + LOGDATE + + + DEPDATE + Y + DEPDATE + + + REPLAYDATE + Y + REPLAYDATE + + + LOG_FIELD + Y + LOG_FIELD + + + EXECUTING_SERVER + N + EXECUTING_SERVER + + + EXECUTING_USER + N + EXECUTING_USER + + + CLIENT + N + CLIENT + + + + + +
+ + + + ID_BATCH + Y + ID_BATCH + + + SEQ_NR + Y + SEQ_NR + + + LOGDATE + Y + LOGDATE + + + TRANSNAME + Y + TRANSNAME + + + STEPNAME + Y + STEPNAME + + + STEP_COPY + Y + STEP_COPY + + + LINES_READ + Y + LINES_READ + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + LINES_UPDATED + Y + LINES_UPDATED + + + LINES_INPUT + Y + LINES_INPUT + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + LINES_REJECTED + Y + LINES_REJECTED + + + ERRORS + Y + ERRORS + + + INPUT_BUFFER_ROWS + Y + INPUT_BUFFER_ROWS + + + OUTPUT_BUFFER_ROWS + Y + OUTPUT_BUFFER_ROWS + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + LOGGING_OBJECT_TYPE + Y + LOGGING_OBJECT_TYPE + + + OBJECT_NAME + Y + OBJECT_NAME + + + OBJECT_COPY + Y + OBJECT_COPY + + + REPOSITORY_DIRECTORY + Y + REPOSITORY_DIRECTORY + + + FILENAME + Y + FILENAME + + + OBJECT_ID + Y + OBJECT_ID + + + OBJECT_REVISION + Y + OBJECT_REVISION + + + PARENT_CHANNEL_ID + Y + PARENT_CHANNEL_ID + + + ROOT_CHANNEL_ID + Y + ROOT_CHANNEL_ID + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + TRANSNAME + Y + TRANSNAME + + + STEPNAME + Y + STEPNAME + + + STEP_COPY + Y + STEP_COPY + + + LINES_READ + Y + LINES_READ + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + LINES_UPDATED + Y + LINES_UPDATED + + + LINES_INPUT + Y + LINES_INPUT + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + LINES_REJECTED + Y + LINES_REJECTED + + + ERRORS + Y + ERRORS + + + LOG_FIELD + N + LOG_FIELD + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + METRICS_DATE + Y + METRICS_DATE + + + METRICS_CODE + Y + METRICS_CODE + + + METRICS_DESCRIPTION + Y + METRICS_DESCRIPTION + + + METRICS_SUBJECT + Y + METRICS_SUBJECT + + + METRICS_TYPE + Y + METRICS_TYPE + + + METRICS_VALUE + Y + METRICS_VALUE + + + + + +
+ + 0.0 + 0.0 + + 10000 + 50 + 50 + N + Y + 50000 + Y + + N + 1000 + 100 + + + + + + + local + localhost + 8888 + + cluster + Encrypted 2be98afc86aa7f2e4cb1aa265cd86aac8 + + + + Y + N + + + + + - + 2024/08/02 11:56:22.507 + - + 2024/08/02 11:56:22.507 + H4sIAAAAAAAAAAMAAAAAAAAAAAA= + N + + + + + ervu-dashboard + dashboard-dbhost + POSTGRESQL + Native + dashboard-dbname + 1111 + dashboard-dbuser + Encrypted 2daf9dca008c89396af54aa72ce93bcc9 + + + + + + EXTRA_OPTION_POSTGRESQL.stringtype + unspecified + + + FORCE_IDENTIFIERS_TO_LOWERCASE + N + + + FORCE_IDENTIFIERS_TO_UPPERCASE + N + + + IS_CLUSTERED + N + + + PORT_NUMBER + 1111 + + + PRESERVE_RESERVED_WORD_CASE + Y + + + QUOTE_ALL_FIELDS + N + + + SUPPORTS_BOOLEAN_DATA_TYPE + N + + + SUPPORTS_TIMESTAMP_DATA_TYPE + N + + + USE_POOLING + N + + + + + postgres.appeal-document-service + appeal-dbhost + POSTGRESQL + Native + appeal-dbname + 2222 + appeal-dbuser + Encrypted 2be98afa91ad79785a754aa72ce93bcc9 + + + + + + FORCE_IDENTIFIERS_TO_LOWERCASE + N + + + FORCE_IDENTIFIERS_TO_UPPERCASE + N + + + IS_CLUSTERED + N + + + PORT_NUMBER + 2222 + + + PRESERVE_RESERVED_WORD_CASE + Y + + + QUOTE_ALL_FIELDS + N + + + SUPPORTS_BOOLEAN_DATA_TYPE + N + + + SUPPORTS_TIMESTAMP_DATA_TYPE + N + + + USE_POOLING + N + + + + + + Table input (appeal_document) РФ + Insert / update (main_dashboard.appeals) + Y + + + + Insert / update (main_dashboard.appeals) + InsertUpdate + + Y + + 1 + + none + + + ervu-dashboard + 100 + N + + main_dashboard +
appeals
+ + recruitment_id + recruitment_id + = + + + + total_appeals + total_appeals + Y + + + recruitment_id + recruitment_id + N + + + + + + + + + + + + 752 + 176 + Y + + + + Table input (appeal_document) РФ + TableInput + + Y + + 1 + + none + + + postgres.appeal-document-service + WITH +t1 AS ( + SELECT COUNT(*) AS total_appeals + FROM public.appeal_document +) -- нет причин обжалований +SELECT + t1.total_appeals, + '00' AS recruitment_id, + 0 AS incorrect_inf, + 0 AS no_data, + 0 AS other, + 0 AS incorrect_inf_percent, + 0 AS no_data_percent, + 0 AS other_percent +FROM t1; + 0 + + N + N + N + + + + + + + + + + 400 + 176 + Y + + + + + + + N + +
diff --git a/mappings/country/main_dashboard.appeals.ktr b/mappings/country/main_dashboard.appeals.ktr index 1178414..21d6da5 100644 --- a/mappings/country/main_dashboard.appeals.ktr +++ b/mappings/country/main_dashboard.appeals.ktr @@ -556,54 +556,12 @@ - - Get variables 3 - Select values 3 - N - - - Select values 3 - Insert / update (main_dashboard.appeals) - N - - - Table input (appeal_document) РФ - Get variables 3 - N - Table input (appeal_document) РФ Insert / update (main_dashboard.appeals) Y - - Get variables 3 - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 416 - 304 - Y - - Insert / update (main_dashboard.appeals) InsertUpdate @@ -682,36 +640,8 @@ - 768 - 160 - Y - - - - Select values 3 - SelectValues - - Y - - 1 - - none - - - - N - - - - - - - - - - - 544 - 304 + 752 + 176 Y @@ -727,13 +657,37 @@ postgres.appeal-document-service - with -t1 as (select count(*) as total_appeals from -public.appeal_document ad), -t2 as (select (avg(trim(both '"' from (ad.extra_info -> 'resultDate')::text)::date - appeal_date)) as average_consideration from public.appeal_document ad) -select t1.total_appeals, t2.average_consideration, '00' as recruitment_id, -0 as resolved, 0 as average_rating, 0 as average_to_face, 0 as average_epgu, 0 as average_to_face_percent, 0 as average_epgu_percent -from t1 full outer join t2 on 1 = 1 + WITH +t1 AS ( + SELECT COUNT(*) AS total_appeals + FROM public.appeal_document +), +t2 AS ( + SELECT + ROUND( + AVG( + (TRIM(BOTH '"' FROM (ad.extra_info ->> 'resultDate')::text)::date - ad.appeal_date) + ), + 2 + ) AS average_consideration + FROM public.appeal_document ad +), +resolved AS (-- решенные обжалования, возможно не верно + SELECT COUNT(*) AS resolved + FROM public.appeal_document ad + WHERE ad.extra_info->>'result' = '1' +) +SELECT + t1.total_appeals, + t2.average_consideration, + r.resolved, + '00' AS recruitment_id, + 0 AS average_rating, + 0 AS average_to_face, + 0 AS average_epgu, + 0 AS average_to_face_percent, + 0 AS average_epgu_percent +FROM t1, t2, resolved AS r; 0 N @@ -748,8 +702,8 @@ from t1 full outer join t2 on 1 = 1 - 224 - 160 + 400 + 176 Y diff --git a/mappings/country/main_dashboard.recruitment_campaign.ktr b/mappings/country/main_dashboard.recruitment_campaign.ktr index 78ad385..c67da70 100644 --- a/mappings/country/main_dashboard.recruitment_campaign.ktr +++ b/mappings/country/main_dashboard.recruitment_campaign.ktr @@ -556,36 +556,6 @@ - - Get variables 4 - Select values 4 - N - - - Select values 4 - Insert / update (main_dashboard.recruitment_campaign) - N - - - Table input (subpoena) РФ/осень - Get variables 4 - N - - - Get variables 4 2 - Select values 4 2 - N - - - Select values 4 2 - Insert / update (main_dashboard.recruitment_campaign) 2 - N - - - Table input (subpoena) РФ/весна - Get variables 4 2 - N - Table input (subpoena) РФ/весна Insert / update (main_dashboard.recruitment_campaign) 2 @@ -597,60 +567,6 @@ Y - - Get variables 4 - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 480 - 288 - Y - - - - Get variables 4 2 - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 480 - 352 - Y - - Insert / update (main_dashboard.recruitment_campaign) InsertUpdate @@ -682,17 +598,17 @@ subpoenas_sent - subpoenas_sent + count_subpoena Y appeared_on_subpoenas - appeared_on_subpoenas + count_appeared Y not_appeared_on_subpoenas - not_appeared_on_subpoenas + count_not_appeared Y @@ -750,8 +666,8 @@ - 960 - 128 + 928 + 288 Y @@ -786,17 +702,17 @@ subpoenas_sent - subpoenas_sent + count_subpoena Y appeared_on_subpoenas - appeared_on_subpoenas + count_appeared Y not_appeared_on_subpoenas - not_appeared_on_subpoenas + count_not_appeared Y @@ -854,63 +770,7 @@ - 960 - 192 - Y - - - - Select values 4 - SelectValues - - Y - - 1 - - none - - - - N - - - - - - - - - - - 656 - 288 - Y - - - - Select values 4 2 - SelectValues - - Y - - 1 - - none - - - - N - - - - - - - - - - - 656 + 928 352 Y @@ -927,29 +787,68 @@ postgres.subpoena - with -t1 as (select count(distinct subpoena.id) as subpoenas_sent FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where subpoena_reason.type='3' and sub_stat_hist.code ='3'), -t2 as (select count(distinct subpoena.id) as appeared_on_subpoenas FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where subpoena_reason.type='3' and sub_stat_hist.code in ('4.1','4.2')), -t3 as (select count(distinct subpoena.id) as not_appeared_on_subpoenas FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where subpoena_reason.type='3' and sub_stat_hist.code ='5') -select t1.subpoenas_sent, t2.appeared_on_subpoenas, t3.not_appeared_on_subpoenas, 1 as org, '00' as recruitment_id, 'Весна' as spring_autumn, -0 as new_recruits, 0 as postponement_have_right, 0 as postponement_granted, 0 as appeared_on_subpoenas_percent, 0 as not_appeared_on_subpoenas_percent, 0 as postponement_have_right_percent, 0 as postponement_granted_percent -from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 - + WITH subpoena_data AS ( + SELECT + s.id AS subpoena_id, + s.status_id, + sr.type, + ssh.code AS sub_stat_hist, + s.send_date, + sh.date_time::timestamp AS history_date, + rdi.restriction_document_cancel_id AS restr_dc, + rdi.applied_date AS ap_date, + rdi.id AS rdi_id, + ssi.delivery_code AS d_code, + ROW_NUMBER() OVER (PARTITION BY s.id ORDER BY sh.date_time DESC) AS rn -- добавляем строку для получения последнего статуса + FROM public.subpoena s + JOIN public.subpoena_history AS sh ON sh.subpoena_id = s.id + JOIN public.subpoena_status AS ss ON ss.id = s.status_id + JOIN public.subpoena_status AS ssh ON ssh.id = sh.status_id + JOIN public.subpoena_reason AS sr ON sr.id = s.reason_id + LEFT JOIN public.restriction_document AS rd ON rd.subpoena_id = s.id + LEFT JOIN public.restriction_document_item AS rdi ON rdi.restriction_document_create_id = rd.id + LEFT JOIN public.subpoena_send_info AS ssi ON ssi.subpoena_id = s.id + WHERE sr.type = '1' -- от 18 до 30 лет и нет отсрочки (нужны эти условия), резделение весна/осень +), +-- фильтруем только последние статусы для каждой повестки +last_status AS ( + SELECT * + FROM subpoena_data + WHERE rn = 1 -- выбираем только последнюю запись для каждой повестки +), +-- Подсчет различных метрик +t1 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_subpoena + FROM last_status + WHERE sub_stat_hist IS NOT NULL +), +t2 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' +), +t3 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_appeared + FROM last_status + WHERE sub_stat_hist = '5' +) +SELECT + t1.count_subpoena, + t2.count_appeared, + t3.count_not_appeared, + ROUND(count_appeared * 100.0 / NULLIF(count_subpoena, 0), 2) AS appeared_on_subpoenas_percent, + ROUND(count_not_appeared * 100.0 / NULLIF(count_subpoena, 0), 2) AS not_appeared_on_subpoenas_percent, + 0 as new_recruits, + 0 as postponement_have_right, + 0 as postponement_granted, + 0 as postponement_have_right_percent, + 0 as postponement_granted_percent, + 'Весна' as spring_autumn, + '00' AS recruitment_id, + 1 AS org +FROM t1 +FULL OUTER JOIN t2 ON 1 = 1 +FULL OUTER JOIN t3 ON 1 = 1; 0 N @@ -964,8 +863,8 @@ from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 - 208 - 192 + 512 + 352 Y @@ -981,29 +880,68 @@ from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 postgres.subpoena - with -t1 as (select count(distinct subpoena.id) as subpoenas_sent FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where subpoena_reason.type='3' and sub_stat_hist.code ='3'), -t2 as (select count(distinct subpoena.id) as appeared_on_subpoenas FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where subpoena_reason.type='3' and sub_stat_hist.code in ('4.1','4.2')), -t3 as (select count(distinct subpoena.id) as not_appeared_on_subpoenas FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where subpoena_reason.type='3' and sub_stat_hist.code ='5') -select t1.subpoenas_sent, t2.appeared_on_subpoenas, t3.not_appeared_on_subpoenas, 1 as org, '00' as recruitment_id, 'Осень' as spring_autumn, -0 as new_recruits, 0 as postponement_have_right, 0 as postponement_granted, 0 as appeared_on_subpoenas_percent, 0 as not_appeared_on_subpoenas_percent, 0 as postponement_have_right_percent, 0 as postponement_granted_percent -from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 - + WITH subpoena_data AS ( + SELECT + s.id AS subpoena_id, + s.status_id, + sr.type, + ssh.code AS sub_stat_hist, + s.send_date, + sh.date_time::timestamp AS history_date, + rdi.restriction_document_cancel_id AS restr_dc, + rdi.applied_date AS ap_date, + rdi.id AS rdi_id, + ssi.delivery_code AS d_code, + ROW_NUMBER() OVER (PARTITION BY s.id ORDER BY sh.date_time DESC) AS rn -- добавляем строку для получения последнего статуса + FROM public.subpoena s + JOIN public.subpoena_history AS sh ON sh.subpoena_id = s.id + JOIN public.subpoena_status AS ss ON ss.id = s.status_id + JOIN public.subpoena_status AS ssh ON ssh.id = sh.status_id + JOIN public.subpoena_reason AS sr ON sr.id = s.reason_id + LEFT JOIN public.restriction_document AS rd ON rd.subpoena_id = s.id + LEFT JOIN public.restriction_document_item AS rdi ON rdi.restriction_document_create_id = rd.id + LEFT JOIN public.subpoena_send_info AS ssi ON ssi.subpoena_id = s.id + WHERE sr.type = '1' -- от 18 до 30 лет и нет отсрочки (нужны эти условия), резделение весна/осень +), +-- фильтруем только последние статусы для каждой повестки +last_status AS ( + SELECT * + FROM subpoena_data + WHERE rn = 1 -- выбираем только последнюю запись для каждой повестки +), +-- Подсчет различных метрик +t1 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_subpoena + FROM last_status + WHERE sub_stat_hist IS NOT NULL +), +t2 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' +), +t3 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_appeared + FROM last_status + WHERE sub_stat_hist = '5' +) +SELECT + t1.count_subpoena, + t2.count_appeared, + t3.count_not_appeared, + ROUND(count_appeared * 100.0 / NULLIF(count_subpoena, 0), 2) AS appeared_on_subpoenas_percent, + ROUND(count_not_appeared * 100.0 / NULLIF(count_subpoena, 0), 2) AS not_appeared_on_subpoenas_percent, + 0 as new_recruits, + 0 as postponement_have_right, + 0 as postponement_granted, + 0 as postponement_have_right_percent, + 0 as postponement_granted_percent, + 'Осень' as spring_autumn, + '00' AS recruitment_id, + 1 AS org +FROM t1 +FULL OUTER JOIN t2 ON 1 = 1 +FULL OUTER JOIN t3 ON 1 = 1; 0 N @@ -1018,8 +956,8 @@ from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 - 208 - 128 + 512 + 288 Y diff --git a/mappings/country/main_dashboard.total_registered.ktr b/mappings/country/main_dashboard.total_registered.ktr index 0a544bd..b5700a3 100644 --- a/mappings/country/main_dashboard.total_registered.ktr +++ b/mappings/country/main_dashboard.total_registered.ktr @@ -556,54 +556,12 @@ - - Get variables 2 - Select values 2 - N - - - Select values 2 - Insert / update (main_dashboard.total_registered) - N - - - Table input (person_registry) РФ - Get variables 2 - N - Table input (person_registry) РФ Insert / update (main_dashboard.total_registered) Y - - Get variables 2 - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 464 - 352 - Y - - Insert / update (main_dashboard.total_registered) InsertUpdate @@ -687,36 +645,8 @@ - 912 - 240 - Y - - - - Select values 2 - SelectValues - - Y - - 1 - - none - - - - N - - - - - - - - - - - 608 - 352 + 1008 + 512 Y @@ -732,18 +662,21 @@ postgres.person_registry - with -t1 as (select count(*) total_count from public.recruits r -where r.vu_current_info -> 'isMilitaryRegistered' = 'true' and r.current_recruitment_id is not null and r.target_recruitment_id is not null), -t2 as (select count(*) filter(where gender='MALE') male_count -from public.recruits r -where r.vu_current_info -> 'isMilitaryRegistered' = 'true' and r.current_recruitment_id is not null and r.target_recruitment_id is not null), -t3 as (select count(*) filter(where gender='FEMALE') female_count -from public.recruits r -where r.vu_current_info -> 'isMilitaryRegistered' = 'true' and r.current_recruitment_id is not null and r.target_recruitment_id is not null) -select t1.total_count, t2.male_count, t3.female_count, '00' as recruitment_id, -0 as mobilization_criterion, 0 as volunteer_criterion, 0 as contract_criterion, 0 as mobilization_criterion_percent, 0 as volunteer_criterion_percent, 0 as contract_criterion_percent -from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 + SELECT + COUNT(*) AS total_count, + COUNT(*) FILTER (WHERE gender = 'MALE') AS male_count, + COUNT(*) FILTER (WHERE gender = 'FEMALE') AS female_count, + '00' AS recruitment_id, + 0 AS mobilization_criterion, + 0 AS volunteer_criterion, + 0 AS contract_criterion, + 0 AS mobilization_criterion_percent, + 0 AS volunteer_criterion_percent, + 0 AS contract_criterion_percent +FROM public.recruits r +WHERE r.vu_current_info ->> 'isMilitaryRegistered' = 'true' + AND r.current_recruitment_id IS NOT NULL + AND r.target_recruitment_id IS NOT NULL; 0 N @@ -758,8 +691,8 @@ from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 - 192 - 240 + 672 + 512 Y diff --git a/mappings/country/main_dashboard.waiting_registration.ktr b/mappings/country/main_dashboard.waiting_registration.ktr index 5fd588f..3f2e115 100644 --- a/mappings/country/main_dashboard.waiting_registration.ktr +++ b/mappings/country/main_dashboard.waiting_registration.ktr @@ -556,54 +556,12 @@ - - Table input 2 (person_registry) РФ - Get variables - N - - - Get variables - Select values - N - - - Select values - Insert / update (main_dashboard.waiting_registration) - N - Table input 2 (person_registry) РФ Insert / update (main_dashboard.waiting_registration) Y - - Get variables - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 592 - 320 - Y - - Insert / update (main_dashboard.waiting_registration) InsertUpdate @@ -672,6 +630,11 @@ contract_criterion_percent Y + + waiting_registration_percent + waiting_percent + Y + recruitment_id recruitment_id @@ -687,36 +650,8 @@ - 1024 - 144 - Y - - - - Select values - SelectValues - - Y - - 1 - - none - - - - N - - - - - - - - - - - 736 - 320 + 816 + 336 Y @@ -732,13 +667,22 @@ postgres.person_registry - with -t1 as (select count(*) waiting_count from public.recruits r where r.system_pgs_status = '1'), -t2 as (select count(*) filter(where gender='MALE') male_count from public.recruits r where r.system_pgs_status = '1'), -t3 as (select count(*) filter(where gender='FEMALE') female_count from public.recruits r where r.system_pgs_status = '1') -select t1.waiting_count, t2.male_count, t3.female_count, '00' as recruitment_id, -0 as mobilization_criterion, 0 as volunteer_criterion, 0 as contract_criterion, 0 as mobilization_criterion_percent, 0 as volunteer_criterion_percent, 0 as contract_criterion_percent -from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 + SELECT + COUNT(*) AS waiting_count, + COUNT(*) FILTER (WHERE gender = 'MALE') AS male_count, + COUNT(*) FILTER (WHERE gender = 'FEMALE') AS female_count, + '00' AS recruitment_id, + 0 AS mobilization_criterion, + 0 AS volunteer_criterion, + 0 AS contract_criterion, + 0 AS mobilization_criterion_percent, + 0 AS volunteer_criterion_percent, + 0 AS contract_criterion_percent, + ROUND(COALESCE((COUNT(*)::DECIMAL / NULLIF((SELECT COUNT(*) FROM public.recruits), 0) * 100), 0), 2) AS waiting_percent +FROM public.recruits r +WHERE r.vu_current_info ->> 'isMilitaryRegistered' = 'false' + AND r.current_recruitment_id IS NOT NULL + AND r.target_recruitment_id IS NOT NULL; 0 N @@ -753,8 +697,8 @@ from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 - 336 - 144 + 496 + 336 Y diff --git a/mappings/country/recruitment_campaign.subpoenas.ktr b/mappings/country/recruitment_campaign.subpoenas.ktr index 50c07a8..544b6e4 100644 --- a/mappings/country/recruitment_campaign.subpoenas.ktr +++ b/mappings/country/recruitment_campaign.subpoenas.ktr @@ -543,36 +543,6 @@ - - Get variables 4 - Select values 4 - N - - - Select values 4 - Insert / update (recruitment_campaign.subpoenas) - N - - - Table input (subpoena) осень/РФ - Get variables 4 - N - - - Get variables 4 2 - Select values 4 2 - N - - - Select values 4 2 - Insert / update (recruitment_campaign.subpoenas) 2 - N - - - Table input (subpoena) Весна/РФ - Get variables 4 2 - N - Table input (subpoena) осень/РФ Insert / update (recruitment_campaign.subpoenas) @@ -584,60 +554,6 @@ Y - - Get variables 4 - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 432 - 368 - Y - - - - Get variables 4 2 - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 432 - 480 - Y - - Insert / update (recruitment_campaign.subpoenas) InsertUpdate @@ -669,37 +585,37 @@ subpoena - subpoena + count_subpoena Y appeared - appeared + count_appeared Y not_appeared - not_appeared + count_not_appeared Y not_ap_good_reason - not_ap_good_reason + count_not_ap_good_reason Y introduced_measures - introduced_measures + count_introduced_measures Y ap_not_required - ap_not_required + count_ap_not_required Y restrictions_applied - restrictions_applied + count_restrictions_applied Y @@ -779,51 +695,51 @@ recruitment_campaign subpoenas
- - spring_autumn - spring_autumn - = - - recruitment_id recruitment_id = + + spring_autumn + spring_autumn + = + + subpoena - subpoena + count_subpoena Y appeared - appeared + count_appeared Y not_appeared - not_appeared + count_not_appeared Y not_ap_good_reason - not_ap_good_reason + count_not_ap_good_reason Y introduced_measures - introduced_measures + count_introduced_measures Y ap_not_required - ap_not_required + count_ap_not_required Y restrictions_applied - restrictions_applied + count_restrictions_applied Y @@ -886,62 +802,6 @@ Y
- - Select values 4 - SelectValues - - Y - - 1 - - none - - - - N - - - - - - - - - - - 592 - 368 - Y - - - - Select values 4 2 - SelectValues - - Y - - 1 - - none - - - - N - - - - - - - - - - - 592 - 480 - Y - - Table input (subpoena) Весна/РФ TableInput @@ -954,51 +814,125 @@ postgres.subpoena - with -t1 as (select count(distinct subpoena.id) as subpoena FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code ='3'), -t2 as (select count(distinct subpoena.id) as appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code in ('4.1','4.2')), -t3 as (select count(distinct subpoena.id) as not_appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code ='5'), -t4 as (select count(*) as not_ap_good_reason FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code='5.1'), -t5 as (select count(distinct subpoena.id) as ap_not_required FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code in ('3.8','5.2')), -t6 as (select count(distinct rdi.id) as restrictions_applied from restriction_document_item rdi -join restriction_document on restriction_document.id = rdi.restriction_document_create_id -join subpoena on subpoena.id = restriction_document.subpoena_id -join subpoena_reason on subpoena_reason.id = subpoena.reason_id -where rdi.restriction_document_cancel_id is null and subpoena_reason.type = '3'), -t7 as (select count(distinct rdi.id) as introduced_measures from restriction_document_item rdi -join restriction_document on restriction_document.id = rdi.restriction_document_create_id -join subpoena on subpoena.id = restriction_document.subpoena_id -join subpoena_reason on subpoena_reason.id = subpoena.reason_id -where rdi.restriction_document_cancel_id is null and rdi.applied_date is not null and subpoena_reason.type = '3') -select t1.subpoena, t2.appeared, t3.not_appeared, t4.not_ap_good_reason, t5.ap_not_required, t6.restrictions_applied, t7.introduced_measures, 1 as mil_reg, '00' as recruitment_id, 1 as org, -0 as appeared_percent, 0 as not_appeared_percent, 0 as not_ap_good_reason_percent, 0 as ap_not_required_percent, 0 as restrictions_applied_percent, 0 as introduced_measures_percent, 0 as rest, 'Весна' as spring_autumn -from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 full outer join t4 on 1 = 1 full outer join t5 on 1 = 1 full outer join t6 on 1 = 1 full outer join t7 on 1 = 1 - + WITH subpoena_data AS ( + SELECT + s.id AS subpoena_id, + s.status_id, + sr.type, + ssh.code AS sub_stat_hist, + s.send_date, + sh.date_time::timestamp AS history_date, + rdi.restriction_document_cancel_id AS restr_dc, + rdi.applied_date AS ap_date, + rdi.id AS rdi_id, + ssi.delivery_code AS d_code, + ROW_NUMBER() OVER (PARTITION BY s.id ORDER BY sh.date_time DESC) AS rn -- добавляем строку для получения последнего статуса + FROM public.subpoena s + JOIN public.subpoena_history AS sh ON sh.subpoena_id = s.id + JOIN public.subpoena_status AS ss ON ss.id = s.status_id + JOIN public.subpoena_status AS ssh ON ssh.id = sh.status_id + JOIN public.subpoena_reason AS sr ON sr.id = s.reason_id + LEFT JOIN public.restriction_document AS rd ON rd.subpoena_id = s.id + LEFT JOIN public.restriction_document_item AS rdi ON rdi.restriction_document_create_id = rd.id + LEFT JOIN public.subpoena_send_info AS ssi ON ssi.subpoena_id = s.id + WHERE sr.type = '3' +), +-- фильтруем только последние статусы для каждой повестки +last_status AS ( + SELECT * + FROM subpoena_data + WHERE rn = 1 -- выбираем только последнюю запись для каждой повестки +), +-- Подсчет различных метрик +t1 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_subpoena + FROM last_status + WHERE sub_stat_hist IS NOT NULL +), +t2 AS ( + SELECT ROUND(AVG(EXTRACT(DAY FROM (history_date::timestamp - send_date::timestamp))), 1) AS average_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' +), +t3 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' +), +t4 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_appeared + FROM last_status + WHERE sub_stat_hist = '5' +), +t5 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_ap_good_reason + FROM last_status + WHERE sub_stat_hist = '5.1' +), +t6 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_ap_not_required + FROM last_status + WHERE sub_stat_hist IN ('3.8', '5.2') +), +t7 AS ( -- количество повесток по которым применены ограничения + SELECT COUNT(DISTINCT subpoena_id) AS count_restrictions_applied + FROM last_status + WHERE restr_dc IS NULL +), +t8 AS ( -- количество повесток по которым введены меры + SELECT COUNT(DISTINCT subpoena_id) AS count_introduced_measures + FROM last_status + WHERE restr_dc IS NULL AND ap_date IS NOT NULL +), +t9 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_paper + FROM last_status + WHERE d_code = '14' +), +t10 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_electron + FROM last_status + WHERE d_code = '7' +), +t11 AS ( + SELECT COUNT (DISTINCT rdi_id) AS count_restrictions + FROM last_status +) +SELECT + t1.count_subpoena, + t2.average_appeared, + t3.count_appeared, + t4.count_not_appeared, + t5.count_not_ap_good_reason, + t6.count_ap_not_required, + t7.count_restrictions_applied, + t8.count_introduced_measures, + t9.count_paper, + t10.count_electron, + t11.count_restrictions, + ROUND(count_appeared * 100.0 / NULLIF(count_subpoena, 0), 2) AS appeared_percent, + ROUND(count_not_appeared * 100.0 / NULLIF(count_subpoena, 0), 2) AS not_appeared_percent, + ROUND(count_not_ap_good_reason * 100.0 / NULLIF(count_subpoena, 0), 2) AS not_ap_good_reason_percent, + ROUND(count_ap_not_required * 100.0 / NULLIF(count_subpoena, 0), 2) AS ap_not_required_percent, + ROUND(count_electron * 100.0 / NULLIF(count_subpoena, 0), 2) AS electron_percent, + ROUND(count_paper * 100.0 / NULLIF(count_subpoena, 0), 2) AS paper_percent, + ROUND(count_restrictions_applied * 100.0 / NULLIF(count_subpoena, 0), 2) AS restrictions_applied_percent, + ROUND(count_introduced_measures * 100.0 / NULLIF(count_subpoena, 0), 2) AS introduced_measures_percent, + '00' AS recruitment_id, + 0 as rest, + 'Весна' as spring_autumn, + 1 AS org +FROM t1 +FULL OUTER JOIN t2 ON 1 = 1 +FULL OUTER JOIN t3 ON 1 = 1 +FULL OUTER JOIN t4 ON 1 = 1 +FULL OUTER JOIN t5 ON 1 = 1 +FULL OUTER JOIN t6 ON 1 = 1 +FULL OUTER JOIN t7 ON 1 = 1 +FULL OUTER JOIN t8 ON 1 = 1 +FULL OUTER JOIN t9 ON 1 = 1 +FULL OUTER JOIN t10 ON 1 = 1 +FULL OUTER JOIN t11 ON 1 = 1; 0 N @@ -1030,51 +964,125 @@ from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 full outer join postgres.subpoena - with -t1 as (select count(distinct subpoena.id) as subpoena FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code ='3'), -t2 as (select count(distinct subpoena.id) as appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code in ('4.1','4.2')), -t3 as (select count(distinct subpoena.id) as not_appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code ='5'), -t4 as (select count(*) as not_ap_good_reason FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code='5.1'), -t5 as (select count(distinct subpoena.id) as ap_not_required FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code in ('3.8','5.2')), -t6 as (select count(distinct rdi.id) as restrictions_applied from restriction_document_item rdi -join restriction_document on restriction_document.id = rdi.restriction_document_create_id -join subpoena on subpoena.id = restriction_document.subpoena_id -join subpoena_reason on subpoena_reason.id = subpoena.reason_id -where rdi.restriction_document_cancel_id is null and subpoena_reason.type = '3'), -t7 as (select count(distinct rdi.id) as introduced_measures from restriction_document_item rdi -join restriction_document on restriction_document.id = rdi.restriction_document_create_id -join subpoena on subpoena.id = restriction_document.subpoena_id -join subpoena_reason on subpoena_reason.id = subpoena.reason_id -where rdi.restriction_document_cancel_id is null and rdi.applied_date is not null and subpoena_reason.type = '3') -select t1.subpoena, t2.appeared, t3.not_appeared, t4.not_ap_good_reason, t5.ap_not_required, t6.restrictions_applied, t7.introduced_measures, 1 as mil_reg, '00' as recruitment_id, 1 as org, -0 as appeared_percent, 0 as not_appeared_percent, 0 as not_ap_good_reason_percent, 0 as ap_not_required_percent, 0 as restrictions_applied_percent, 0 as introduced_measures_percent, 0 as rest, 'Осень' as spring_autumn -from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 full outer join t4 on 1 = 1 full outer join t5 on 1 = 1 full outer join t6 on 1 = 1 full outer join t7 on 1 = 1 - + WITH subpoena_data AS ( + SELECT + s.id AS subpoena_id, + s.status_id, + sr.type, + ssh.code AS sub_stat_hist, + s.send_date, + sh.date_time::timestamp AS history_date, + rdi.restriction_document_cancel_id AS restr_dc, + rdi.applied_date AS ap_date, + rdi.id AS rdi_id, + ssi.delivery_code AS d_code, + ROW_NUMBER() OVER (PARTITION BY s.id ORDER BY sh.date_time DESC) AS rn -- добавляем строку для получения последнего статуса + FROM public.subpoena s + JOIN public.subpoena_history AS sh ON sh.subpoena_id = s.id + JOIN public.subpoena_status AS ss ON ss.id = s.status_id + JOIN public.subpoena_status AS ssh ON ssh.id = sh.status_id + JOIN public.subpoena_reason AS sr ON sr.id = s.reason_id + LEFT JOIN public.restriction_document AS rd ON rd.subpoena_id = s.id + LEFT JOIN public.restriction_document_item AS rdi ON rdi.restriction_document_create_id = rd.id + LEFT JOIN public.subpoena_send_info AS ssi ON ssi.subpoena_id = s.id + WHERE sr.type = '3' -- код про призывную комиссию +), +-- фильтруем только последние статусы для каждой повестки +last_status AS ( + SELECT * + FROM subpoena_data + WHERE rn = 1 -- выбираем только последнюю запись для каждой повестки +), +-- Подсчет различных метрик +t1 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_subpoena + FROM last_status + WHERE sub_stat_hist IS NOT NULL +), +t2 AS ( + SELECT ROUND(AVG(EXTRACT(DAY FROM (history_date::timestamp - send_date::timestamp))), 1) AS average_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' +), +t3 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' +), +t4 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_appeared + FROM last_status + WHERE sub_stat_hist = '5' +), +t5 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_ap_good_reason + FROM last_status + WHERE sub_stat_hist = '5.1' +), +t6 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_ap_not_required + FROM last_status + WHERE sub_stat_hist IN ('3.8', '5.2') +), +t7 AS ( -- количество повесток по которым применены ограничения + SELECT COUNT(DISTINCT subpoena_id) AS count_restrictions_applied + FROM last_status + WHERE restr_dc IS NULL +), +t8 AS ( -- количество повесток по которым введены меры + SELECT COUNT(DISTINCT subpoena_id) AS count_introduced_measures + FROM last_status + WHERE restr_dc IS NULL AND ap_date IS NOT NULL +), +t9 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_paper + FROM last_status + WHERE d_code = '14' +), +t10 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_electron + FROM last_status + WHERE d_code = '7' +), +t11 AS ( + SELECT COUNT (DISTINCT rdi_id) AS count_restrictions + FROM last_status +) +SELECT + t1.count_subpoena, + t2.average_appeared, + t3.count_appeared, + t4.count_not_appeared, + t5.count_not_ap_good_reason, + t6.count_ap_not_required, + t7.count_restrictions_applied, + t8.count_introduced_measures, + t9.count_paper, + t10.count_electron, + t11.count_restrictions, + ROUND(count_appeared * 100.0 / NULLIF(count_subpoena, 0), 2) AS appeared_percent, + ROUND(count_not_appeared * 100.0 / NULLIF(count_subpoena, 0), 2) AS not_appeared_percent, + ROUND(count_not_ap_good_reason * 100.0 / NULLIF(count_subpoena, 0), 2) AS not_ap_good_reason_percent, + ROUND(count_ap_not_required * 100.0 / NULLIF(count_subpoena, 0), 2) AS ap_not_required_percent, + ROUND(count_electron * 100.0 / NULLIF(count_subpoena, 0), 2) AS electron_percent, + ROUND(count_paper * 100.0 / NULLIF(count_subpoena, 0), 2) AS paper_percent, + ROUND(count_restrictions_applied * 100.0 / NULLIF(count_subpoena, 0), 2) AS restrictions_applied_percent, + ROUND(count_introduced_measures * 100.0 / NULLIF(count_subpoena, 0), 2) AS introduced_measures_percent, + '00' AS recruitment_id, + 0 as rest, + 'Осень' as spring_autumn, + 1 AS org +FROM t1 +FULL OUTER JOIN t2 ON 1 = 1 +FULL OUTER JOIN t3 ON 1 = 1 +FULL OUTER JOIN t4 ON 1 = 1 +FULL OUTER JOIN t5 ON 1 = 1 +FULL OUTER JOIN t6 ON 1 = 1 +FULL OUTER JOIN t7 ON 1 = 1 +FULL OUTER JOIN t8 ON 1 = 1 +FULL OUTER JOIN t9 ON 1 = 1 +FULL OUTER JOIN t10 ON 1 = 1 +FULL OUTER JOIN t11 ON 1 = 1; 0 N diff --git a/mappings/country/total_registered.age.ktr b/mappings/country/total_registered.age.ktr index a46eed2..2c2956a 100644 --- a/mappings/country/total_registered.age.ktr +++ b/mappings/country/total_registered.age.ktr @@ -557,147 +557,36 @@ - Get variables - Select values - N - - - Table input (person_registry) РФ/все - Get variables - N - - - Select values - Insert / update (total_registered.age) - N - - - Get variables 2 - Select values 2 - N - - - Table input (person_registry) РФ/мужчины - Get variables 2 - N - - - Get variables 2 2 - Select values 2 2 - N - - - Table input (person_registry) РФ/женщины - Get variables 2 2 - N - - - Select values 2 - Insert / update (total_registered.age) 2 - N - - - Select values 2 2 - Insert / update (total_registered.age) 3 - N - - - Table input (person_registry) РФ/женщины + Table input (person_registry) РФ/женщины/на учете Insert / update (total_registered.age) 3 Y - Table input (person_registry) РФ/мужчины + Table input (person_registry) РФ/мужчины/на учете Insert / update (total_registered.age) 2 Y - Table input (person_registry) РФ/все + Table input (person_registry) РФ/все/на учете Insert / update (total_registered.age) Y + + Table input (person_registry) РФ/все/не на учете + Insert / update (total_registered.age) 4 + Y + + + Table input (person_registry) РФ/женщины/не на учете + Insert / update (total_registered.age) 3 2 + Y + + + Table input (person_registry) РФ/мужчины/не на учете + Insert / update (total_registered.age) 2 2 + Y + - - Get variables - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 656 - 608 - Y - - - - Get variables 2 - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 656 - 704 - Y - - - - Get variables 2 2 - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 656 - 800 - Y - - Insert / update (total_registered.age) InsertUpdate @@ -988,6 +877,151 @@ Y + + Insert / update (total_registered.age) 2 2 + InsertUpdate + + Y + + 1 + + none + + + ervu-dashboard + 100 + Y + + total_registered + age
+ + recruitment_id + recruitment_id + = + + + + gender + "all_M_W" + = + + + + registered + registered + = + + + + "17_yaers" + 17_year_count + Y + + + "18-26_years" + 18-26_year_count + Y + + + "27-30_years" + 27-30_year_count + Y + + + "31-35_years" + 31-35_year_count + Y + + + "36-40_years" + 36-40_year_count + Y + + + "41-45_years" + 41-45_year_count + Y + + + "51+_years" + 41-45_year_count + Y + + + "all_M_W" + gender + N + + + "46-50_years" + 46-50_year_count + Y + + + "17_yaers_percent" + 17_year_percent + Y + + + "18-26_years_percent" + 18-26_year_percent + Y + + + "27-30_years_percent" + 27-30_year_percent + Y + + + "31-35_years_percent" + 31-35_year_percent + Y + + + "36-40_years_percent" + 36-40_year_percent + Y + + + "41-45_years_percent" + 41-45_year_percent + Y + + + "46-50_years_percent" + 46-50_year_percent + Y + + + "51+_years_percent" + 51+_year_percent + Y + + + recruitment_id + recruitment_id + N + + + registered + registered + N + +
+ + + + + + + + + + 1024 + 672 + Y + +
Insert / update (total_registered.age) 3 InsertUpdate @@ -1134,8 +1168,8 @@ - Select values - SelectValues + Insert / update (total_registered.age) 3 2 + InsertUpdate Y @@ -1144,9 +1178,126 @@ none - - N - + ervu-dashboard + 100 + Y + + total_registered + age
+ + recruitment_id + recruitment_id + = + + + + gender + "all_M_W" + = + + + + registered + registered + = + + + + "17_yaers" + 17_year_count + Y + + + "18-26_years" + 18-26_year_count + Y + + + "27-30_years" + 27-30_year_count + Y + + + "31-35_years" + 31-35_year_count + Y + + + "36-40_years" + 36-40_year_count + Y + + + "41-45_years" + 41-45_year_count + Y + + + "51+_years" + 41-45_year_count + Y + + + "all_M_W" + gender + N + + + "46-50_years" + 46-50_year_count + Y + + + "17_yaers_percent" + 17_year_percent + Y + + + "18-26_years_percent" + 18-26_year_percent + Y + + + "27-30_years_percent" + 27-30_year_percent + Y + + + "31-35_years_percent" + 31-35_year_percent + Y + + + "36-40_years_percent" + 36-40_year_percent + Y + + + "41-45_years_percent" + 41-45_year_percent + Y + + + "46-50_years_percent" + 46-50_year_percent + Y + + + "51+_years_percent" + 51+_year_percent + Y + + + recruitment_id + recruitment_id + N + + + registered + registered + N + +
@@ -1156,14 +1307,14 @@ - 800 - 608 + 1024 + 768 Y
- Select values 2 - SelectValues + Insert / update (total_registered.age) 4 + InsertUpdate Y @@ -1172,9 +1323,126 @@ none - - N - + ervu-dashboard + 100 + Y + + total_registered + age
+ + recruitment_id + recruitment_id + = + + + + gender + "all_M_W" + = + + + + registered + registered + = + + + + "17_yaers" + 17_year_count + Y + + + "18-26_years" + 18-26_year_count + Y + + + "27-30_years" + 27-30_year_count + Y + + + "31-35_years" + 31-35_year_count + Y + + + "36-40_years" + 36-40_year_count + Y + + + "41-45_years" + 41-45_year_count + Y + + + "51+_years" + 41-45_year_count + Y + + + "all_M_W" + gender + N + + + "46-50_years" + 46-50_year_count + Y + + + "17_yaers_percent" + 17_year_percent + Y + + + "18-26_years_percent" + 18-26_year_percent + Y + + + "27-30_years_percent" + 27-30_year_percent + Y + + + "31-35_years_percent" + 31-35_year_percent + Y + + + "36-40_years_percent" + 36-40_year_percent + Y + + + "41-45_years_percent" + 41-45_year_percent + Y + + + "46-50_years_percent" + 46-50_year_percent + Y + + + "51+_years_percent" + 51+_year_percent + Y + + + recruitment_id + recruitment_id + N + + + registered + registered + N + +
@@ -1184,41 +1452,13 @@ - 800 - 704 + 1024 + 576 Y
- Select values 2 2 - SelectValues - - Y - - 1 - - none - - - - N - - - - - - - - - - - 800 - 800 - Y - - - - Table input (person_registry) РФ/все + Table input (person_registry) РФ/все/на учете TableInput Y @@ -1299,7 +1539,88 @@ FROM age_counts, total_count; - Table input (person_registry) РФ/женщины + Table input (person_registry) РФ/все/не на учете + TableInput + + Y + + 1 + + none + + + ervu_person_registry + WITH total_count AS ( + SELECT COUNT(*) AS total + FROM public.recruits r + join public.recruits_info ri on ri.recruit_id=r.id + WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' and r.current_recruitment_id is not null and r.target_recruitment_id is not null +), +age_counts AS ( + SELECT + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) = 17) AS "17_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 18 AND 26) AS "18-26_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 27 AND 30) AS "27-30_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 31 AND 35) AS "31-35_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 36 AND 40) AS "36-40_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 41 AND 45) AS "41-45_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 46 AND 50) AS "46-50_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) >= 51) AS "51+_year_count" + FROM public.recruits r + join public.recruits_info ri on ri.recruit_id=r.id + WHERE r.vu_current_info->>'isMilitaryRegistered' = 'false' and r.current_recruitment_id is not null and r.target_recruitment_id is not null +) +SELECT + age_counts."17_year_count", + ROUND((age_counts."17_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "17_year_percent", + + age_counts."18-26_year_count", + ROUND((age_counts."18-26_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "18-26_year_percent", + + age_counts."27-30_year_count", + ROUND((age_counts."27-30_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "27-30_year_percent", + + age_counts."31-35_year_count", + ROUND((age_counts."31-35_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "31-35_year_percent", + + age_counts."36-40_year_count", + ROUND((age_counts."36-40_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "36-40_year_percent", + + age_counts."41-45_year_count", + ROUND((age_counts."41-45_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "41-45_year_percent", + + age_counts."46-50_year_count", + ROUND((age_counts."46-50_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "46-50_year_percent", + + age_counts."51+_year_count", + ROUND((age_counts."51+_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "51+_year_percent", + + '00' as recruitment_id, + 'ALL' as gender, + 'false' as registered + +FROM age_counts, total_count; + 0 + + N + N + N + + + + + + + + + + 400 + 576 + Y + + + + Table input (person_registry) РФ/женщины/на учете TableInput Y @@ -1380,7 +1701,88 @@ FROM age_counts, total_count; - Table input (person_registry) РФ/мужчины + Table input (person_registry) РФ/женщины/не на учете + TableInput + + Y + + 1 + + none + + + ervu_person_registry + WITH total_count AS ( + SELECT COUNT(*) AS total + FROM public.recruits r + join public.recruits_info ri on ri.recruit_id=r.id + WHERE r.gender = 'FEMALE' AND r.vu_current_info->>'isMilitaryRegistered' = 'true' and r.current_recruitment_id is not null and r.target_recruitment_id is not null +), +age_counts AS ( + SELECT + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) = 17) AS "17_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 18 AND 26) AS "18-26_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 27 AND 30) AS "27-30_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 31 AND 35) AS "31-35_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 36 AND 40) AS "36-40_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 41 AND 45) AS "41-45_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 46 AND 50) AS "46-50_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) >= 51) AS "51+_year_count" + FROM public.recruits r + join public.recruits_info ri on ri.recruit_id=r.id + WHERE r.gender = 'FEMALE' AND r.vu_current_info->>'isMilitaryRegistered' = 'false' and r.current_recruitment_id is not null and r.target_recruitment_id is not null +) +SELECT + age_counts."17_year_count", + ROUND((age_counts."17_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "17_year_percent", + + age_counts."18-26_year_count", + ROUND((age_counts."18-26_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "18-26_year_percent", + + age_counts."27-30_year_count", + ROUND((age_counts."27-30_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "27-30_year_percent", + + age_counts."31-35_year_count", + ROUND((age_counts."31-35_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "31-35_year_percent", + + age_counts."36-40_year_count", + ROUND((age_counts."36-40_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "36-40_year_percent", + + age_counts."41-45_year_count", + ROUND((age_counts."41-45_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "41-45_year_percent", + + age_counts."46-50_year_count", + ROUND((age_counts."46-50_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "46-50_year_percent", + + age_counts."51+_year_count", + ROUND((age_counts."51+_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "51+_year_percent", + + '00' as recruitment_id, + 'W' as gender, + 'false' as registered + +FROM age_counts, total_count; + 0 + + N + N + N + + + + + + + + + + 400 + 768 + Y + + + + Table input (person_registry) РФ/мужчины/на учете TableInput Y @@ -1460,6 +1862,87 @@ FROM age_counts, total_count; Y + + Table input (person_registry) РФ/мужчины/не на учете + TableInput + + Y + + 1 + + none + + + ervu_person_registry + WITH total_count AS ( + SELECT COUNT(*) AS total + FROM public.recruits r + join public.recruits_info ri on ri.recruit_id=r.id + WHERE r.gender = 'MALE' AND r.vu_current_info->>'isMilitaryRegistered' = 'true' and r.current_recruitment_id is not null and r.target_recruitment_id is not null +), +age_counts AS ( + SELECT + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) = 17) AS "17_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 18 AND 26) AS "18-26_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 27 AND 30) AS "27-30_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 31 AND 35) AS "31-35_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 36 AND 40) AS "36-40_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 41 AND 45) AS "41-45_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 46 AND 50) AS "46-50_year_count", + COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) >= 51) AS "51+_year_count" + FROM public.recruits r + join public.recruits_info ri on ri.recruit_id=r.id + WHERE r.gender = 'MALE' AND r.vu_current_info->>'isMilitaryRegistered' = 'false' and r.current_recruitment_id is not null and r.target_recruitment_id is not null +) +SELECT + age_counts."17_year_count", + ROUND((age_counts."17_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "17_year_percent", + + age_counts."18-26_year_count", + ROUND((age_counts."18-26_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "18-26_year_percent", + + age_counts."27-30_year_count", + ROUND((age_counts."27-30_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "27-30_year_percent", + + age_counts."31-35_year_count", + ROUND((age_counts."31-35_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "31-35_year_percent", + + age_counts."36-40_year_count", + ROUND((age_counts."36-40_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "36-40_year_percent", + + age_counts."41-45_year_count", + ROUND((age_counts."41-45_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "41-45_year_percent", + + age_counts."46-50_year_count", + ROUND((age_counts."46-50_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "46-50_year_percent", + + age_counts."51+_year_count", + ROUND((age_counts."51+_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "51+_year_percent", + + '00' as recruitment_id, + 'M' as gender, + 'false' as registered + +FROM age_counts, total_count; + 0 + + N + N + N + + + + + + + + + + 400 + 672 + Y + + diff --git a/mappings/country/total_registered.busyness.ktr b/mappings/country/total_registered.busyness.ktr index 45d46e5..358beb4 100644 --- a/mappings/country/total_registered.busyness.ktr +++ b/mappings/country/total_registered.busyness.ktr @@ -557,20 +557,35 @@ - Table input (person_registry) РФ/все + Table input (person_registry) РФ/все/на учете Insert / update (total_registered.busyness) Y - Table input (person_registry) РФ/мужчины + Table input (person_registry) РФ/мужчины/на учете Insert / update (total_registered.busyness) 2 Y - Table input (person_registry) РФ/женщины + Table input (person_registry) РФ/женщины/на учете Insert / update (total_registered.busyness) 3 Y + + Table input (person_registry) РФ/все/не на учете + Insert / update (total_registered.busyness) 4 + Y + + + Table input (person_registry) РФ/женщины/не на учете + Insert / update (total_registered.busyness) 3 2 + Y + + + Table input (person_registry) РФ/мужчины/не на учете + Insert / update (total_registered.busyness) 2 2 + Y + Insert / update (total_registered.busyness) @@ -772,6 +787,106 @@ Y + + Insert / update (total_registered.busyness) 2 2 + InsertUpdate + + Y + + 1 + + none + + + ervu-dashboard + 100 + Y + + total_registered + busyness
+ + recruitment_id + recruitment_id + = + + + + gender + "all_M_W" + = + + + + registered + registered + = + + + + study + study + Y + + + work + work + Y + + + study_percent + study_percent + Y + + + work_percent + work_percent + Y + + + recruitment_id + recruitment_id + N + + + registered + registered + N + + + "all_M_W" + gender + N + + + not_work + not_work + Y + + + not_work_percent + not_work_percent + Y + + + busyness + total_people + Y + +
+ + + + + + + + + + 1024 + 672 + Y + +
Insert / update (total_registered.busyness) 3 InsertUpdate @@ -873,7 +988,207 @@ - Table input (person_registry) РФ/все + Insert / update (total_registered.busyness) 3 2 + InsertUpdate + + Y + + 1 + + none + + + ervu-dashboard + 100 + Y + + total_registered + busyness
+ + recruitment_id + recruitment_id + = + + + + gender + "all_M_W" + = + + + + registered + registered + = + + + + study + study + Y + + + work + work + Y + + + study_percent + study_percent + Y + + + work_percent + work_percent + Y + + + recruitment_id + recruitment_id + N + + + registered + registered + N + + + "all_M_W" + gender + N + + + not_work + not_work + Y + + + not_work_percent + not_work_percent + Y + + + busyness + total_people + Y + +
+ + + + + + + + + + 1024 + 768 + Y + +
+ + Insert / update (total_registered.busyness) 4 + InsertUpdate + + Y + + 1 + + none + + + ervu-dashboard + 100 + Y + + total_registered + busyness
+ + recruitment_id + recruitment_id + = + + + + gender + "all_M_W" + = + + + + registered + registered + = + + + + study + study + Y + + + work + work + Y + + + study_percent + study_percent + Y + + + work_percent + work_percent + Y + + + recruitment_id + recruitment_id + N + + + registered + registered + N + + + "all_M_W" + gender + N + + + not_work + not_work + Y + + + not_work_percent + not_work_percent + Y + + + busyness + total_people + Y + +
+ + + + + + + + + + 1024 + 576 + Y + +
+ + Table input (person_registry) РФ/все/на учете TableInput Y @@ -999,7 +1314,133 @@ FROM summary; - Table input (person_registry) РФ/женщины + Table input (person_registry) РФ/все/не на учете + TableInput + + Y + + 1 + + none + + + ervu_person_registry + -- в json отсутствует инфа об обучении в школе + +WITH status_info AS ( + SELECT + -- Проверка на обучение в вузе (есть информация и обучается) + ( + CASE + WHEN jsonb_typeof(info->'svedVUZ'->'vuz') = 'array' THEN + EXISTS ( + SELECT 1 + FROM jsonb_array_elements(info->'svedVUZ'->'vuz') AS vuz + WHERE vuz->>'kodStatus' = '1' + ) + ELSE false + END + ) AS is_studying_in_vuz, + + -- Проверка на обучение в колледже (есть информация и обучается) + ( + CASE + WHEN jsonb_typeof(info->'svedKolledzh'->'kolledzh') = 'array' THEN + EXISTS ( + SELECT 1 + FROM jsonb_array_elements(info->'svedKolledzh'->'kolledzh') AS kolledzh + WHERE kolledzh->>'kodStatus' = '1' + ) + ELSE false + END + ) AS is_studying_in_college, + + -- Проверка на работу (есть информация и работает) + ( + CASE + WHEN jsonb_typeof(info->'svedTrud'->'trudDeyat') = 'array' THEN + EXISTS ( + SELECT 1 + FROM jsonb_array_elements(info->'svedTrud'->'trudDeyat') AS trud + WHERE trud->>'prAktMestRab' = '1' + ) + ELSE false + END + ) AS is_working, + + -- Проверка на отсутствие сведений о вузе + info->'svedVUZ'->>'prOtsSvedVUZ' = '1' AS no_info_vuz, + + -- Проверка на отсутствие сведений о колледже + info->'svedKolledzh'->>'prOtsSvedKolledzh' = '1' AS no_info_college, + + -- Проверка на отсутствие сведений о работе + info->'svedTrud'->>'prOtsSvedTrud' = '1' AS no_info_work + FROM public.recruits_info ri + JOIN public.recruits r ON ri.recruit_id = r.id + WHERE r.vu_current_info -> 'isMilitaryRegistered' = 'false' and r.current_recruitment_id is not null and r.target_recruitment_id is not null +), +summary AS ( + SELECT + -- Количество людей, которые учатся (в вузе или колледже) + COUNT(CASE WHEN is_studying_in_vuz OR is_studying_in_college THEN 1 END) AS study, + + -- Количество людей, которые работают + COUNT(CASE WHEN is_working THEN 1 END) AS work, + + -- Количество людей, которые ни учатся, ни работают + -- COUNT(CASE WHEN NOT is_studying_in_vuz AND NOT is_studying_in_college AND NOT is_working THEN 1 END) AS not_work, + + -- Количество людей, для которых отсутствуют сведения о вузе, колледже и работе + COUNT(CASE WHEN no_info_vuz AND no_info_college AND no_info_work THEN 1 END) AS no_info, + + -- Общее количество людей + COUNT(*) AS total_people + FROM status_info +) +SELECT + 'ALL' as gender, + 'false' as registered, + '00' as recruitment_id, + study, + work, + 0 as not_work, + 0 as not_work_percent, + total_people, + + -- Процент людей, которые учатся + ROUND(study * 100.0 / NULLIF(total_people, 0), 2) AS study_percent, + + -- Процент людей, которые работают + ROUND(work * 100.0 / NULLIF(total_people, 0), 2) AS work_percent + + -- Процент людей, которые ни учатся, ни работают + -- ROUND(not_work * 100.0 / NULLIF(total_people, 0), 2) AS not_work_percent + + -- Процент людей, для которых отсутствуют сведения + -- ROUND(no_info * 100.0 / NULLIF(total_people, 0), 2) AS no_info_percent +FROM summary; + 0 + + N + N + N + + + + + + + + + + 400 + 576 + Y + + + + Table input (person_registry) РФ/женщины/на учете TableInput Y @@ -1126,7 +1567,134 @@ FROM summary; - Table input (person_registry) РФ/мужчины + Table input (person_registry) РФ/женщины/не на учете + TableInput + + Y + + 1 + + none + + + ervu_person_registry + -- в json отсутствует инфа об обучении в школе + +WITH status_info AS ( + SELECT + -- Проверка на обучение в вузе (есть информация и обучается) + ( + CASE + WHEN jsonb_typeof(info->'svedVUZ'->'vuz') = 'array' THEN + EXISTS ( + SELECT 1 + FROM jsonb_array_elements(info->'svedVUZ'->'vuz') AS vuz + WHERE vuz->>'kodStatus' = '1' + ) + ELSE false + END + ) AS is_studying_in_vuz, + + -- Проверка на обучение в колледже (есть информация и обучается) + ( + CASE + WHEN jsonb_typeof(info->'svedKolledzh'->'kolledzh') = 'array' THEN + EXISTS ( + SELECT 1 + FROM jsonb_array_elements(info->'svedKolledzh'->'kolledzh') AS kolledzh + WHERE kolledzh->>'kodStatus' = '1' + ) + ELSE false + END + ) AS is_studying_in_college, + + -- Проверка на работу (есть информация и работает) + ( + CASE + WHEN jsonb_typeof(info->'svedTrud'->'trudDeyat') = 'array' THEN + EXISTS ( + SELECT 1 + FROM jsonb_array_elements(info->'svedTrud'->'trudDeyat') AS trud + WHERE trud->>'prAktMestRab' = '1' + ) + ELSE false + END + ) AS is_working, + + -- Проверка на отсутствие сведений о вузе + info->'svedVUZ'->>'prOtsSvedVUZ' = '1' AS no_info_vuz, + + -- Проверка на отсутствие сведений о колледже + info->'svedKolledzh'->>'prOtsSvedKolledzh' = '1' AS no_info_college, + + -- Проверка на отсутствие сведений о работе + info->'svedTrud'->>'prOtsSvedTrud' = '1' AS no_info_work + FROM public.recruits_info ri + JOIN public.recruits r ON ri.recruit_id = r.id + WHERE r.vu_current_info -> 'isMilitaryRegistered' = 'false' and r.current_recruitment_id is not null and r.target_recruitment_id is not null + AND gender = 'FEMALE' +), +summary AS ( + SELECT + -- Количество людей, которые учатся (в вузе или колледже) + COUNT(CASE WHEN is_studying_in_vuz OR is_studying_in_college THEN 1 END) AS study, + + -- Количество людей, которые работают + COUNT(CASE WHEN is_working THEN 1 END) AS work, + + -- Количество людей, которые ни учатся, ни работают + -- COUNT(CASE WHEN NOT is_studying_in_vuz AND NOT is_studying_in_college AND NOT is_working THEN 1 END) AS not_work, + + -- Количество людей, для которых отсутствуют сведения о вузе, колледже и работе + COUNT(CASE WHEN no_info_vuz AND no_info_college AND no_info_work THEN 1 END) AS no_info, + + -- Общее количество людей + COUNT(*) AS total_people + FROM status_info +) +SELECT + 'W' as gender, + 'false' as registered, + '00' as recruitment_id, + 0 as not_work, + 0 as not_work_percent, + study, + work, + total_people, + + -- Процент людей, которые учатся + ROUND(study * 100.0 / NULLIF(total_people, 0), 2) AS study_percent, + + -- Процент людей, которые работают + ROUND(work * 100.0 / NULLIF(total_people, 0), 2) AS work_percent + + -- Процент людей, которые ни учатся, ни работают + -- ROUND(not_work * 100.0 / NULLIF(total_people, 0), 2) AS not_work_percent + + -- Процент людей, для которых отсутствуют сведения + -- ROUND(no_info * 100.0 / NULLIF(total_people, 0), 2) AS no_info_percent +FROM summary; + 0 + + N + N + N + + + + + + + + + + 400 + 768 + Y + + + + Table input (person_registry) РФ/мужчины/на учете TableInput Y @@ -1252,6 +1820,133 @@ FROM summary; Y + + Table input (person_registry) РФ/мужчины/не на учете + TableInput + + Y + + 1 + + none + + + ervu_person_registry + -- в json отсутствует инфа об обучении в школе + +WITH status_info AS ( + SELECT + -- Проверка на обучение в вузе (есть информация и обучается) + ( + CASE + WHEN jsonb_typeof(info->'svedVUZ'->'vuz') = 'array' THEN + EXISTS ( + SELECT 1 + FROM jsonb_array_elements(info->'svedVUZ'->'vuz') AS vuz + WHERE vuz->>'kodStatus' = '1' + ) + ELSE false + END + ) AS is_studying_in_vuz, + + -- Проверка на обучение в колледже (есть информация и обучается) + ( + CASE + WHEN jsonb_typeof(info->'svedKolledzh'->'kolledzh') = 'array' THEN + EXISTS ( + SELECT 1 + FROM jsonb_array_elements(info->'svedKolledzh'->'kolledzh') AS kolledzh + WHERE kolledzh->>'kodStatus' = '1' + ) + ELSE false + END + ) AS is_studying_in_college, + + -- Проверка на работу (есть информация и работает) + ( + CASE + WHEN jsonb_typeof(info->'svedTrud'->'trudDeyat') = 'array' THEN + EXISTS ( + SELECT 1 + FROM jsonb_array_elements(info->'svedTrud'->'trudDeyat') AS trud + WHERE trud->>'prAktMestRab' = '1' + ) + ELSE false + END + ) AS is_working, + + -- Проверка на отсутствие сведений о вузе + info->'svedVUZ'->>'prOtsSvedVUZ' = '1' AS no_info_vuz, + + -- Проверка на отсутствие сведений о колледже + info->'svedKolledzh'->>'prOtsSvedKolledzh' = '1' AS no_info_college, + + -- Проверка на отсутствие сведений о работе + info->'svedTrud'->>'prOtsSvedTrud' = '1' AS no_info_work + FROM public.recruits_info ri + JOIN public.recruits r ON ri.recruit_id = r.id + WHERE r.vu_current_info -> 'isMilitaryRegistered' = 'false' and r.current_recruitment_id is not null and r.target_recruitment_id is not null + AND gender = 'MALE' +), +summary AS ( + SELECT + -- Количество людей, которые учатся (в вузе или колледже) + COUNT(CASE WHEN is_studying_in_vuz OR is_studying_in_college THEN 1 END) AS study, + + -- Количество людей, которые работают + COUNT(CASE WHEN is_working THEN 1 END) AS work, + + -- Количество людей, которые ни учатся, ни работают + -- COUNT(CASE WHEN NOT is_studying_in_vuz AND NOT is_studying_in_college AND NOT is_working THEN 1 END) AS not_work, + + -- Количество людей, для которых отсутствуют сведения о вузе, колледже и работе + COUNT(CASE WHEN no_info_vuz AND no_info_college AND no_info_work THEN 1 END) AS no_info, + + -- Общее количество людей + COUNT(*) AS total_people + FROM status_info +) +SELECT + 'M' as gender, + 'false' as registered, + '00' as recruitment_id, + 0 as not_work_percent, + 0 as not_work, + study, + work, + total_people, + + -- Процент людей, которые учатся + ROUND(study * 100.0 / NULLIF(total_people, 0), 2) AS study_percent, + + -- Процент людей, которые работают + ROUND(work * 100.0 / NULLIF(total_people, 0), 2) AS work_percent + + -- Процент людей, которые ни учатся, ни работают + -- ROUND(not_work * 100.0 / NULLIF(total_people, 0), 2) AS not_work_percent + + -- Процент людей, для которых отсутствуют сведения + -- ROUND(no_info * 100.0 / NULLIF(total_people, 0), 2) AS no_info_percent +FROM summary; + 0 + + N + N + N + + + + + + + + + + 400 + 672 + Y + + diff --git a/mappings/country/total_registered.child_minor.ktr b/mappings/country/total_registered.child_minor.ktr index e6ed79b..29540a7 100644 --- a/mappings/country/total_registered.child_minor.ktr +++ b/mappings/country/total_registered.child_minor.ktr @@ -556,51 +556,6 @@ - - Get variables 4 - Select values 4 - N - - - Table input (person_registry)РФ/все - Get variables 4 - N - - - Select values 4 - Insert / update (total_registered.child_minor) - N - - - Get variables 4 2 - Select values 4 2 - N - - - Table input (person_registry)РФ/мужчины - Get variables 4 2 - N - - - Get variables 4 2 2 - Select values 4 2 2 - N - - - Table input (person_registry)РФ/женщины - Get variables 4 2 2 - N - - - Select values 4 2 2 - Insert / update (total_registered.child_minor) 3 - N - - - Select values 4 2 - Insert / update (total_registered.child_minor) 2 - N - Table input (person_registry)РФ/женщины Insert / update (total_registered.child_minor) 3 @@ -617,87 +572,6 @@ Y - - Get variables 4 - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 560 - 592 - Y - - - - Get variables 4 2 - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 576 - 688 - Y - - - - Get variables 4 2 2 - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 576 - 784 - Y - - Insert / update (total_registered.child_minor) InsertUpdate @@ -1010,90 +884,6 @@ Y - - Select values 4 - SelectValues - - Y - - 1 - - none - - - - N - - - - - - - - - - - 752 - 592 - Y - - - - Select values 4 2 - SelectValues - - Y - - 1 - - none - - - - N - - - - - - - - - - - 768 - 688 - Y - - - - Select values 4 2 2 - SelectValues - - Y - - 1 - - none - - - - N - - - - - - - - - - - 752 - 784 - Y - - Table input (person_registry)РФ/все TableInput diff --git a/mappings/country/total_registered.driver_license.ktr b/mappings/country/total_registered.driver_license.ktr index 911c5d0..e0d0fb1 100644 --- a/mappings/country/total_registered.driver_license.ktr +++ b/mappings/country/total_registered.driver_license.ktr @@ -556,51 +556,6 @@ - - Get variables - Select values - N - - - Table input (person_registry) РФ/все - Get variables - N - - - Select values - Insert / update (total_registered.driver_license) 2 - N - - - Get variables 2 - Select values 2 - N - - - Select values 2 - Insert / update (total_registered.driver_license) 2 2 - N - - - Table input (person_registry) РФ/мужчины - Get variables 2 - N - - - Get variables 2 2 - Select values 2 2 - N - - - Select values 2 2 - Insert / update (total_registered.driver_license) 2 2 2 - N - - - Table input (person_registry) РФ/женщины - Get variables 2 2 - N - Table input (person_registry) РФ/женщины Insert / update (total_registered.driver_license) 2 2 2 @@ -617,87 +572,6 @@ Y - - Get variables - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 848 - 496 - Y - - - - Get variables 2 - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 848 - 592 - Y - - - - Get variables 2 2 - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 848 - 688 - Y - - Insert / update (total_registered.driver_license) 2 InsertUpdate @@ -1025,90 +899,6 @@ Y - - Select values - SelectValues - - Y - - 1 - - none - - - - N - - - - - - - - - - - 992 - 496 - Y - - - - Select values 2 - SelectValues - - Y - - 1 - - none - - - - N - - - - - - - - - - - 992 - 592 - Y - - - - Select values 2 2 - SelectValues - - Y - - 1 - - none - - - - N - - - - - - - - - - - 992 - 688 - Y - - Table input (person_registry) РФ/все TableInput diff --git a/mappings/country/total_registered.reg_mil_cat.ktr b/mappings/country/total_registered.reg_mil_cat.ktr index a3200e9..ef72d4d 100644 --- a/mappings/country/total_registered.reg_mil_cat.ktr +++ b/mappings/country/total_registered.reg_mil_cat.ktr @@ -505,7 +505,7 @@ - postgres.person_registry + ervu_person_registry person-dbhost POSTGRESQL Native @@ -557,53 +557,16 @@ - Table input (person_registry) РФ - Get variables - N - - - Get variables - Select values - N - - - Select values - Insert / update (total_registered.reg_mil_cat) - N - - - Table input (person_registry) РФ + Table input (person_registry) РФ/на учете Insert / update (total_registered.reg_mil_cat) Y + + Table input (person_registry) РФ/не на учете + Insert / update (total_registered.reg_mil_cat) 2 + Y + - - Get variables - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 448 - 416 - Y - - Insert / update (total_registered.reg_mil_cat) InsertUpdate @@ -713,14 +676,14 @@ - 816 - 144 + 736 + 288 Y - Select values - SelectValues + Insert / update (total_registered.reg_mil_cat) 2 + InsertUpdate Y @@ -729,9 +692,95 @@ none - - N - + ervu-dashboard + 100 + N + + total_registered + reg_mil_cat
+ + recruitment_id + recruitment_id + = + + + + mil_reg + mil_reg + = + + + + first_reg_17 + first_reg_17 + Y + + + first_reg_18 + first_reg_18 + Y + + + "mil_spec_W" + mil_spec_w + Y + + + recruitment_id + recruitment_id + N + + + returned_dep_liberty + returned_dep_liberty + Y + + + punished + punished + Y + + + received_citizenship + received_citizenship + Y + + + first_reg_17_percent + first_reg_17_percent + Y + + + first_reg_18_percent + first_reg_18_percent + Y + + + returned_dep_liberty_percent + returned_dep_liberty_percent + Y + + + "mil_spec_W_percent" + mil_spec_w_percent + Y + + + punished_percent + punished_percent + Y + + + received_citizenship_percent + received_citizenship_percent + Y + + + mil_reg + mil_reg + N + +
@@ -741,13 +790,13 @@ - 592 + 736 416 Y
- Table input (person_registry) РФ + Table input (person_registry) РФ/на учете TableInput Y @@ -757,48 +806,88 @@ none - postgres.person_registry - WITH + ervu_person_registry + WITH base_data AS ( + -- Основной набор данных + SELECT + r.registration_reasons, + r.gender, + r.vu_current_info ->> 'isMilitaryRegistered' AS is_military_registered + FROM public.recruits r + WHERE r.vu_current_info ->> 'isMilitaryRegistered' = 'true' + AND r.current_recruitment_id IS NOT NULL + AND r.target_recruitment_id IS NOT NULL +), +total AS ( + -- Общее количество записей + SELECT COUNT(*) AS total_count + FROM base_data +), t1 AS ( + -- Первоначальная постановка 17 лет SELECT COUNT(*) AS first_reg_17 - FROM recruits r - WHERE r.system_pgs_status = '1' - AND AGE(CURRENT_DATE, r.birth_date) < INTERVAL '18 years' + FROM base_data + WHERE registration_reasons @> '"5"' ), t2 AS ( - -- Первоначальная постановка совершеннолетние + -- Первоначальная постановка 18 лет SELECT COUNT(*) AS first_reg_18 - FROM recruits r - WHERE r.system_pgs_status = '1' - AND AGE(CURRENT_DATE, r.birth_date) >= INTERVAL '18 years' + FROM base_data + WHERE registration_reasons @> '"6"' + OR registration_reasons @> '"3"' + OR registration_reasons @> '"1"' + OR registration_reasons @> '"4"' + OR registration_reasons @> '"2"' ), t3 AS ( - -- Совершеннолетние женщины с ВУС + -- Женщины, получившие ВУС SELECT COUNT(*) AS mil_spec_w - FROM recruits r - WHERE r.system_pgs_status = '1' - AND AGE(CURRENT_DATE, r.birth_date) >= INTERVAL '18 years' - AND r.gender = 'FEMALE' + FROM base_data + WHERE registration_reasons @> '"3"' AND gender = 'FEMALE' +), +t4 AS ( + -- Возвратившиеся из мест лишения свободы + SELECT COUNT(*) AS returned_dep_liberty + FROM base_data + WHERE registration_reasons @> '"1"' +), +t5 AS ( + -- Отбывающие наказание в местах лишения свободы + SELECT COUNT(*) AS punished + FROM base_data + WHERE registration_reasons @> '"4"' +), +t6 AS ( + -- Получившие гражданство + SELECT COUNT(*) AS received_citizenship + FROM base_data + WHERE registration_reasons @> '"2"' ) SELECT - t1.first_reg_17, - t2.first_reg_18, - t3.mil_spec_w, - '00' AS recruitment_id, - 0 AS returned_dep_liberty, - 0 AS punished, - 0 AS received_citizenship, - 0 AS first_reg_17_percent, - 0 AS first_reg_18_percent, - 0 AS returned_dep_liberty_percent, - 0 AS mil_spec_w_percent, - 0 AS punished_percent, - 0 AS received_citizenship_percent, - 1 AS mil_reg, + total.total_count, + t1.first_reg_17, + t2.first_reg_18, + t3.mil_spec_w, + t4.returned_dep_liberty, + t5.punished, + t6.received_citizenship, + -- Вычисление процентов + ROUND(t1.first_reg_17 * 100.0 / NULLIF(total.total_count, 0), 2) AS first_reg_17_percent, + ROUND(t2.first_reg_18 * 100.0 / NULLIF(total.total_count, 0), 2) AS first_reg_18_percent, + ROUND(t4.returned_dep_liberty * 100.0 / NULLIF(total.total_count, 0), 2) AS returned_dep_liberty_percent, + ROUND(t3.mil_spec_w * 100.0 / NULLIF(total.total_count, 0), 2) AS mil_spec_w_percent, + ROUND(t5.punished * 100.0 / NULLIF(total.total_count, 0), 2) AS punished_percent, + ROUND(t6.received_citizenship * 100.0 / NULLIF(total.total_count, 0), 2) AS received_citizenship_percent, + '00' AS recruitment_id, + 1 AS mil_reg, 1 AS org -FROM t1 +FROM total +FULL OUTER JOIN t1 ON 1 = 1 FULL OUTER JOIN t2 ON 1 = 1 -FULL OUTER JOIN t3 ON 1 = 1; +FULL OUTER JOIN t3 ON 1 = 1 +FULL OUTER JOIN t4 ON 1 = 1 +FULL OUTER JOIN t5 ON 1 = 1 +FULL OUTER JOIN t6 ON 1 = 1; 0 N @@ -813,8 +902,120 @@ FULL OUTER JOIN t3 ON 1 = 1; - 176 - 144 + 304 + 288 + Y + + + + Table input (person_registry) РФ/не на учете + TableInput + + Y + + 1 + + none + + + ervu_person_registry + WITH base_data AS ( + -- Основной набор данных + SELECT + r.registration_reasons, + r.gender, + r.vu_current_info ->> 'isMilitaryRegistered' AS is_military_registered + FROM public.recruits r + WHERE r.vu_current_info ->> 'isMilitaryRegistered' = 'false' + AND r.current_recruitment_id IS NOT NULL + AND r.target_recruitment_id IS NOT NULL +), +total AS ( + -- Общее количество записей + SELECT COUNT(*) AS total_count + FROM base_data +), +t1 AS ( + -- Первоначальная постановка 17 лет + SELECT COUNT(*) AS first_reg_17 + FROM base_data + WHERE registration_reasons @> '"5"' +), +t2 AS ( + -- Первоначальная постановка 18 лет + SELECT COUNT(*) AS first_reg_18 + FROM base_data + WHERE registration_reasons @> '"6"' + OR registration_reasons @> '"3"' + OR registration_reasons @> '"1"' + OR registration_reasons @> '"4"' + OR registration_reasons @> '"2"' +), +t3 AS ( + -- Женщины, получившие ВУС + SELECT COUNT(*) AS mil_spec_w + FROM base_data + WHERE registration_reasons @> '"3"' AND gender = 'FEMALE' +), +t4 AS ( + -- Возвратившиеся из мест лишения свободы + SELECT COUNT(*) AS returned_dep_liberty + FROM base_data + WHERE registration_reasons @> '"1"' +), +t5 AS ( + -- Отбывающие наказание в местах лишения свободы + SELECT COUNT(*) AS punished + FROM base_data + WHERE registration_reasons @> '"4"' +), +t6 AS ( + -- Получившие гражданство + SELECT COUNT(*) AS received_citizenship + FROM base_data + WHERE registration_reasons @> '"2"' +) +SELECT + total.total_count, + t1.first_reg_17, + t2.first_reg_18, + t3.mil_spec_w, + t4.returned_dep_liberty, + t5.punished, + t6.received_citizenship, + -- Вычисление процентов + ROUND(t1.first_reg_17 * 100.0 / NULLIF(total.total_count, 0), 2) AS first_reg_17_percent, + ROUND(t2.first_reg_18 * 100.0 / NULLIF(total.total_count, 0), 2) AS first_reg_18_percent, + ROUND(t4.returned_dep_liberty * 100.0 / NULLIF(total.total_count, 0), 2) AS returned_dep_liberty_percent, + ROUND(t3.mil_spec_w * 100.0 / NULLIF(total.total_count, 0), 2) AS mil_spec_w_percent, + ROUND(t5.punished * 100.0 / NULLIF(total.total_count, 0), 2) AS punished_percent, + ROUND(t6.received_citizenship * 100.0 / NULLIF(total.total_count, 0), 2) AS received_citizenship_percent, + '00' AS recruitment_id, + 0 AS mil_reg, + 1 AS org +FROM total +FULL OUTER JOIN t1 ON 1 = 1 +FULL OUTER JOIN t2 ON 1 = 1 +FULL OUTER JOIN t3 ON 1 = 1 +FULL OUTER JOIN t4 ON 1 = 1 +FULL OUTER JOIN t5 ON 1 = 1 +FULL OUTER JOIN t6 ON 1 = 1; + 0 + + N + N + N + + + + + + + + + + 304 + 416 Y diff --git a/mappings/country/total_registered.subpoenas.ktr b/mappings/country/total_registered.subpoenas.ktr index 97140ff..ce9d6fa 100644 --- a/mappings/country/total_registered.subpoenas.ktr +++ b/mappings/country/total_registered.subpoenas.ktr @@ -556,101 +556,17 @@ - - Get variables 4 - Select values 4 - N - Table input (subpoena)РФ/рег - Get variables 4 - N - - - Select values 4 Insert / update (total_registered.subpoenas) - N - - - Get variables 4 3 - Select values 4 3 - N - - - Select values 4 3 - Insert / update (total_registered.subpoenas) 2 - N - - - Table input (subpoena) РФ/не рег - Get variables 4 3 - N - - - Table input (subpoena) РФ/не рег - Insert / update (total_registered.subpoenas) 2 Y - Table input (subpoena)РФ/рег - Insert / update (total_registered.subpoenas) + Table input (subpoena) РФ/не рег + Insert / update (total_registered.subpoenas) 2 Y - - Get variables 4 - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 480 - 352 - Y - - - - Get variables 4 3 - GetVariable - - Y - - 1 - - none - - - - - - - - - - - - - - 480 - 448 - Y - - Insert / update (total_registered.subpoenas) InsertUpdate @@ -682,12 +598,12 @@ subpoena - subpoena + count_subpoena Y appeared - appeared + count_appeared Y @@ -697,37 +613,37 @@ not_appeared - not_appeared + count_not_appeared Y not_ap_good_reason - not_ap_good_reason + count_not_ap_good_reason Y introduced_measures - introduced_measures + count_introduced_measures Y ap_not_required - ap_not_required + count_ap_not_required Y electron - electron + count_electron Y paper - paper + count_paper Y restrictions_applied - restrictions_applied + count_restrictions_applied Y @@ -790,8 +706,8 @@ - 864 - 64 + 672 + 272 Y @@ -826,12 +742,12 @@ subpoena - subpoena + count_subpoena Y appeared - appeared + count_appeared Y @@ -841,37 +757,37 @@ not_appeared - not_appeared + count_not_appeared Y not_ap_good_reason - not_ap_good_reason + count_not_ap_good_reason Y introduced_measures - introduced_measures + count_introduced_measures Y ap_not_required - ap_not_required + count_ap_not_required Y electron - electron + count_electron Y paper - paper + count_paper Y restrictions_applied - restrictions_applied + count_restrictions_applied Y @@ -933,65 +849,9 @@ - - 864 - 160 - Y - -
- - Select values 4 - SelectValues - - Y - - 1 - - none - - - - N - - - - - - - - - 672 - 352 - Y - - - - Select values 4 3 - SelectValues - - Y - - 1 - - none - - - - N - - - - - - - - - - - 672 - 448 + 432 Y @@ -1007,65 +867,124 @@ postgres.subpoena - with -t1 as (select count(distinct subpoena.id) as subpoena FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='1' and sub_stat_hist.code ='3'), -t2 as (select round(avg(extract(day from subpoena_history.date_time::timestamp - (subpoena.send_date::timestamptz AT time zone 'UTC')::timestamp)), 1) as average_appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where subpoena_reason.type = '1' and (sub_stat_hist.code = '4.1' or sub_stat_hist.code = '4.2')), -t3 as (select count(distinct subpoena.id) as appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='1' and sub_stat_hist.code in ('4.1','4.2')), -t4 as (select count(distinct subpoena.id) as not_appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='1' and sub_stat_hist.code ='5'), -t5 as (select count(*) as not_ap_good_reason FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='1' and sub_stat_hist.code='5.1'), -t6 as (select count(distinct subpoena.id) as ap_not_required FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='1' and sub_stat_hist.code in ('3.8','5.2')), -t7 as (select count(distinct rdi.id) as restrictions_applied from restriction_document_item rdi -join restriction_document on restriction_document.id = rdi.restriction_document_create_id -join subpoena on subpoena.id = restriction_document.subpoena_id -join subpoena_reason on subpoena_reason.id = subpoena.reason_id -where rdi.restriction_document_cancel_id is null and subpoena_reason.type = '1'), -t8 as (select count(distinct rdi.id) as introduced_measures from restriction_document_item rdi -join restriction_document on restriction_document.id = rdi.restriction_document_create_id -join subpoena on subpoena.id = restriction_document.subpoena_id -join subpoena_reason on subpoena_reason.id = subpoena.reason_id -where rdi.restriction_document_cancel_id is null and rdi.applied_date is not null and subpoena_reason.type = '1'), -t9 as (select count(distinct subpoena.id) as paper FROM subpoena -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -join subpoena_send_info on subpoena_send_info.subpoena_id = subpoena.id -where subpoena_reason.type = '1' and subpoena_send_info.delivery_code = '14'), -t10 as (select count(distinct subpoena.id) as electron FROM subpoena -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -join subpoena_send_info on subpoena_send_info.subpoena_id = subpoena.id -where subpoena_reason.type = '1' and subpoena_send_info.delivery_code = '7') -select t1.subpoena, t2.average_appeared, t3.appeared, t4.not_appeared, t5.not_ap_good_reason, t6.ap_not_required, t7.restrictions_applied, t8.introduced_measures, t9.paper, t10.electron, '00' as recruitment_id, 1 as org, 0 as mil_reg, -0 as appeared_percent, 0 as not_appeared_percent, 0 as not_ap_good_reason_percent, 0 as ap_not_required_percent, 0 as electron_percent, 0 as paper_percent, 0 as restrictions_applied_percent, 0 as introduced_measures_percent -from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 full outer join t4 on 1 = 1 full outer join t5 on 1 = 1 full outer join t6 on 1 = 1 full outer join t7 on 1 = 1 full outer join t8 on 1 = 1 full outer join t9 on 1 = 1 full outer join t10 on 1 = 1 - + WITH subpoena_data AS ( + SELECT + s.id AS subpoena_id, + s.status_id, + sr.type, + ssh.code AS sub_stat_hist, + s.send_date, + sh.date_time::timestamp AS history_date, + rdi.restriction_document_cancel_id AS restr_dc, + rdi.applied_date AS ap_date, + rdi.id AS rdi_id, + ssi.delivery_code AS d_code, + ROW_NUMBER() OVER (PARTITION BY s.id ORDER BY sh.date_time DESC) AS rn -- добавляем строку для получения последнего статуса + FROM subpoena s + JOIN subpoena_history AS sh ON sh.subpoena_id = s.id + JOIN subpoena_status AS ss ON ss.id = s.status_id + JOIN subpoena_status AS ssh ON ssh.id = sh.status_id + JOIN subpoena_reason AS sr ON sr.id = s.reason_id + LEFT JOIN restriction_document AS rd ON rd.subpoena_id = s.id + LEFT JOIN restriction_document_item AS rdi ON rdi.restriction_document_create_id = rd.id + LEFT JOIN subpoena_send_info AS ssi ON ssi.subpoena_id = s.id + WHERE sr.type = '1' +), +-- фильтруем только последние статусы для каждой повестки +last_status AS ( + SELECT * + FROM subpoena_data + WHERE rn = 1 -- выбираем только последнюю запись для каждой повестки +), +-- Подсчет различных метрик +t1 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_subpoena + FROM last_status + WHERE sub_stat_hist IS NOT NULL +), +t2 AS ( + SELECT ROUND(AVG(EXTRACT(DAY FROM (history_date::timestamp - send_date::timestamp))), 1) AS average_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' +), +t3 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' +), +t4 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_appeared + FROM last_status + WHERE sub_stat_hist = '5' +), +t5 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_ap_good_reason + FROM last_status + WHERE sub_stat_hist = '5.1' +), +t6 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_ap_not_required + FROM last_status + WHERE sub_stat_hist IN ('3.8', '5.2') +), +t7 AS ( -- количество повесток по которым применены ограничения + SELECT COUNT(DISTINCT subpoena_id) AS count_restrictions_applied + FROM last_status + WHERE restr_dc IS NULL +), +t8 AS ( -- количество повесток по которым введены меры + SELECT COUNT(DISTINCT subpoena_id) AS count_introduced_measures + FROM last_status + WHERE restr_dc IS NULL AND ap_date IS NOT NULL +), +t9 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_paper + FROM last_status + WHERE d_code = '14' +), +t10 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_electron + FROM last_status + WHERE d_code = '7' +), +t11 AS ( + SELECT COUNT (DISTINCT rdi_id) AS count_restrictions + FROM last_status +) +SELECT + t1.count_subpoena, + t2.average_appeared, + t3.count_appeared, + t4.count_not_appeared, + t5.count_not_ap_good_reason, + t6.count_ap_not_required, + t7.count_restrictions_applied, + t8.count_introduced_measures, + t9.count_paper, + t10.count_electron, + t11.count_restrictions, + ROUND(count_appeared * 100.0 / NULLIF(count_subpoena, 0), 2) AS appeared_percent, + ROUND(count_not_appeared * 100.0 / NULLIF(count_subpoena, 0), 2) AS not_appeared_percent, + ROUND(count_not_ap_good_reason * 100.0 / NULLIF(count_subpoena, 0), 2) AS not_ap_good_reason_percent, + ROUND(count_ap_not_required * 100.0 / NULLIF(count_subpoena, 0), 2) AS ap_not_required_percent, + ROUND(count_electron * 100.0 / NULLIF(count_subpoena, 0), 2) AS electron_percent, + ROUND(count_paper * 100.0 / NULLIF(count_subpoena, 0), 2) AS paper_percent, + ROUND(count_restrictions_applied * 100.0 / NULLIF(count_subpoena, 0), 2) AS restrictions_applied_percent, + ROUND(count_introduced_measures * 100.0 / NULLIF(count_subpoena, 0), 2) AS introduced_measures_percent, + '00' AS recruitment_id, + 1 AS org, + 0 AS mil_reg +FROM t1 +FULL OUTER JOIN t2 ON 1 = 1 +FULL OUTER JOIN t3 ON 1 = 1 +FULL OUTER JOIN t4 ON 1 = 1 +FULL OUTER JOIN t5 ON 1 = 1 +FULL OUTER JOIN t6 ON 1 = 1 +FULL OUTER JOIN t7 ON 1 = 1 +FULL OUTER JOIN t8 ON 1 = 1 +FULL OUTER JOIN t9 ON 1 = 1 +FULL OUTER JOIN t10 ON 1 = 1 +FULL OUTER JOIN t11 ON 1 = 1; 0 N @@ -1080,8 +999,8 @@ from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 full outer join - 256 - 160 + 336 + 432 Y
@@ -1097,65 +1016,124 @@ from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 full outer join postgres.subpoena - with -t1 as (select count(distinct subpoena.id) as subpoena FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type !='1' and sub_stat_hist.code ='3'), -t2 as (select round(avg(extract(day from subpoena_history.date_time::timestamp - (subpoena.send_date::timestamptz AT time zone 'UTC')::timestamp)), 1) as average_appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where subpoena_reason.type != '1' and (sub_stat_hist.code = '4.1' or sub_stat_hist.code = '4.2')), -t3 as (select count(distinct subpoena.id) as appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type !='1' and sub_stat_hist.code in ('4.1','4.2')), -t4 as (select count(distinct subpoena.id) as not_appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type !='1' and sub_stat_hist.code ='5'), -t5 as (select count(*) as not_ap_good_reason FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type !='1' and sub_stat_hist.code='5.1'), -t6 as (select count(distinct subpoena.id) as ap_not_required FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type !='1' and sub_stat_hist.code in ('3.8','5.2')), -t7 as (select count(distinct rdi.id) as restrictions_applied from restriction_document_item rdi -join restriction_document on restriction_document.id = rdi.restriction_document_create_id -join subpoena on subpoena.id = restriction_document.subpoena_id -join subpoena_reason on subpoena_reason.id = subpoena.reason_id -where rdi.restriction_document_cancel_id is null and subpoena_reason.type != '1'), -t8 as (select count(distinct rdi.id) as introduced_measures from restriction_document_item rdi -join restriction_document on restriction_document.id = rdi.restriction_document_create_id -join subpoena on subpoena.id = restriction_document.subpoena_id -join subpoena_reason on subpoena_reason.id = subpoena.reason_id -where rdi.restriction_document_cancel_id is null and rdi.applied_date is not null and subpoena_reason.type != '1'), -t9 as (select count(distinct subpoena.id) as paper FROM subpoena -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -join subpoena_send_info on subpoena_send_info.subpoena_id = subpoena.id -where subpoena_reason.type != '1' and subpoena_send_info.delivery_code = '14'), -t10 as (select count(distinct subpoena.id) as electron FROM subpoena -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -join subpoena_send_info on subpoena_send_info.subpoena_id = subpoena.id -where subpoena_reason.type != '1' and subpoena_send_info.delivery_code = '7') -select t1.subpoena, t2.average_appeared, t3.appeared, t4.not_appeared, t5.not_ap_good_reason, t6.ap_not_required, t7.restrictions_applied, t8.introduced_measures, t9.paper, t10.electron, '00' as recruitment_id, 1 as org, 1 as mil_reg, -0 as appeared_percent, 0 as not_appeared_percent, 0 as not_ap_good_reason_percent, 0 as ap_not_required_percent, 0 as electron_percent, 0 as paper_percent, 0 as restrictions_applied_percent, 0 as introduced_measures_percent -from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 full outer join t4 on 1 = 1 full outer join t5 on 1 = 1 full outer join t6 on 1 = 1 full outer join t7 on 1 = 1 full outer join t8 on 1 = 1 full outer join t9 on 1 = 1 full outer join t10 on 1 = 1 - + WITH subpoena_data AS ( + SELECT + s.id AS subpoena_id, + s.status_id, + sr.type, + ssh.code AS sub_stat_hist, + s.send_date, + sh.date_time::timestamp AS history_date, + rdi.restriction_document_cancel_id AS restr_dc, + rdi.applied_date AS ap_date, + rdi.id AS rdi_id, + ssi.delivery_code AS d_code, + ROW_NUMBER() OVER (PARTITION BY s.id ORDER BY sh.date_time DESC) AS rn -- добавляем строку для получения последнего статуса + FROM subpoena s + JOIN subpoena_history AS sh ON sh.subpoena_id = s.id + JOIN subpoena_status AS ss ON ss.id = s.status_id + JOIN subpoena_status AS ssh ON ssh.id = sh.status_id + JOIN subpoena_reason AS sr ON sr.id = s.reason_id + LEFT JOIN restriction_document AS rd ON rd.subpoena_id = s.id + LEFT JOIN restriction_document_item AS rdi ON rdi.restriction_document_create_id = rd.id + LEFT JOIN subpoena_send_info AS ssi ON ssi.subpoena_id = s.id + WHERE sr.type != '1' +), +-- фильтруем только последние статусы для каждой повестки +last_status AS ( + SELECT * + FROM subpoena_data + WHERE rn = 1 -- выбираем только последнюю запись для каждой повестки +), +-- Подсчет различных метрик +t1 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_subpoena + FROM last_status + WHERE sub_stat_hist IS NOT NULL +), +t2 AS ( + SELECT ROUND(AVG(EXTRACT(DAY FROM (history_date::timestamp - send_date::timestamp))), 1) AS average_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' +), +t3 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' +), +t4 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_appeared + FROM last_status + WHERE sub_stat_hist = '5' +), +t5 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_ap_good_reason + FROM last_status + WHERE sub_stat_hist = '5.1' +), +t6 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_ap_not_required + FROM last_status + WHERE sub_stat_hist IN ('3.8', '5.2') +), +t7 AS ( -- количество повесток по которым применены ограничения + SELECT COUNT(DISTINCT subpoena_id) AS count_restrictions_applied + FROM last_status + WHERE restr_dc IS NULL +), +t8 AS ( -- количество повесток по которым введены меры + SELECT COUNT(DISTINCT subpoena_id) AS count_introduced_measures + FROM last_status + WHERE restr_dc IS NULL AND ap_date IS NOT NULL +), +t9 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_paper + FROM last_status + WHERE d_code = '14' +), +t10 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_electron + FROM last_status + WHERE d_code = '7' +), +t11 AS ( + SELECT COUNT (DISTINCT rdi_id) AS count_restrictions + FROM last_status +) +SELECT + t1.count_subpoena, + t2.average_appeared, + t3.count_appeared, + t4.count_not_appeared, + t5.count_not_ap_good_reason, + t6.count_ap_not_required, + t7.count_restrictions_applied, + t8.count_introduced_measures, + t9.count_paper, + t10.count_electron, + t11.count_restrictions, + ROUND(count_appeared * 100.0 / NULLIF(count_subpoena, 0), 2) AS appeared_percent, + ROUND(count_not_appeared * 100.0 / NULLIF(count_subpoena, 0), 2) AS not_appeared_percent, + ROUND(count_not_ap_good_reason * 100.0 / NULLIF(count_subpoena, 0), 2) AS not_ap_good_reason_percent, + ROUND(count_ap_not_required * 100.0 / NULLIF(count_subpoena, 0), 2) AS ap_not_required_percent, + ROUND(count_electron * 100.0 / NULLIF(count_subpoena, 0), 2) AS electron_percent, + ROUND(count_paper * 100.0 / NULLIF(count_subpoena, 0), 2) AS paper_percent, + ROUND(count_restrictions_applied * 100.0 / NULLIF(count_subpoena, 0), 2) AS restrictions_applied_percent, + ROUND(count_introduced_measures * 100.0 / NULLIF(count_subpoena, 0), 2) AS introduced_measures_percent, + '00' AS recruitment_id, + 1 AS org, + 1 AS mil_reg +FROM t1 +FULL OUTER JOIN t2 ON 1 = 1 +FULL OUTER JOIN t3 ON 1 = 1 +FULL OUTER JOIN t4 ON 1 = 1 +FULL OUTER JOIN t5 ON 1 = 1 +FULL OUTER JOIN t6 ON 1 = 1 +FULL OUTER JOIN t7 ON 1 = 1 +FULL OUTER JOIN t8 ON 1 = 1 +FULL OUTER JOIN t9 ON 1 = 1 +FULL OUTER JOIN t10 ON 1 = 1 +FULL OUTER JOIN t11 ON 1 = 1; 0 N @@ -1170,8 +1148,8 @@ from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 full outer join - 224 - 64 + 336 + 272 Y
diff --git a/mappings/info_recruits/disability.ktr b/mappings/info_recruits/disability.ktr new file mode 100644 index 0000000..136fb7d --- /dev/null +++ b/mappings/info_recruits/disability.ktr @@ -0,0 +1,735 @@ + + + + disability + + + + Normal + / + + + + + + + + + + + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + TRANSNAME + Y + TRANSNAME + + + STATUS + Y + STATUS + + + LINES_READ + Y + LINES_READ + + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + + LINES_UPDATED + Y + LINES_UPDATED + + + + LINES_INPUT + Y + LINES_INPUT + + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + + LINES_REJECTED + Y + LINES_REJECTED + + + + ERRORS + Y + ERRORS + + + STARTDATE + Y + STARTDATE + + + ENDDATE + Y + ENDDATE + + + LOGDATE + Y + LOGDATE + + + DEPDATE + Y + DEPDATE + + + REPLAYDATE + Y + REPLAYDATE + + + LOG_FIELD + Y + LOG_FIELD + + + EXECUTING_SERVER + N + EXECUTING_SERVER + + + EXECUTING_USER + N + EXECUTING_USER + + + CLIENT + N + CLIENT + + + + + +
+ + + + ID_BATCH + Y + ID_BATCH + + + SEQ_NR + Y + SEQ_NR + + + LOGDATE + Y + LOGDATE + + + TRANSNAME + Y + TRANSNAME + + + STEPNAME + Y + STEPNAME + + + STEP_COPY + Y + STEP_COPY + + + LINES_READ + Y + LINES_READ + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + LINES_UPDATED + Y + LINES_UPDATED + + + LINES_INPUT + Y + LINES_INPUT + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + LINES_REJECTED + Y + LINES_REJECTED + + + ERRORS + Y + ERRORS + + + INPUT_BUFFER_ROWS + Y + INPUT_BUFFER_ROWS + + + OUTPUT_BUFFER_ROWS + Y + OUTPUT_BUFFER_ROWS + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + LOGGING_OBJECT_TYPE + Y + LOGGING_OBJECT_TYPE + + + OBJECT_NAME + Y + OBJECT_NAME + + + OBJECT_COPY + Y + OBJECT_COPY + + + REPOSITORY_DIRECTORY + Y + REPOSITORY_DIRECTORY + + + FILENAME + Y + FILENAME + + + OBJECT_ID + Y + OBJECT_ID + + + OBJECT_REVISION + Y + OBJECT_REVISION + + + PARENT_CHANNEL_ID + Y + PARENT_CHANNEL_ID + + + ROOT_CHANNEL_ID + Y + ROOT_CHANNEL_ID + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + TRANSNAME + Y + TRANSNAME + + + STEPNAME + Y + STEPNAME + + + STEP_COPY + Y + STEP_COPY + + + LINES_READ + Y + LINES_READ + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + LINES_UPDATED + Y + LINES_UPDATED + + + LINES_INPUT + Y + LINES_INPUT + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + LINES_REJECTED + Y + LINES_REJECTED + + + ERRORS + Y + ERRORS + + + LOG_FIELD + N + LOG_FIELD + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + METRICS_DATE + Y + METRICS_DATE + + + METRICS_CODE + Y + METRICS_CODE + + + METRICS_DESCRIPTION + Y + METRICS_DESCRIPTION + + + METRICS_SUBJECT + Y + METRICS_SUBJECT + + + METRICS_TYPE + Y + METRICS_TYPE + + + METRICS_VALUE + Y + METRICS_VALUE + + + + + +
+ + 0.0 + 0.0 + + 10000 + 50 + 50 + N + Y + 50000 + Y + + N + 1000 + 100 + + + + + + + + + - + 2024/08/15 14:02:51.713 + - + 2024/08/15 14:02:51.713 + H4sIAAAAAAAAAAMAAAAAAAAAAAA= + N + + + + + ervu-dashboard + dashboard-dbhost + POSTGRESQL + Native + dashboard-dbname + 1111 + dashboard-dbuser + Encrypted 2daf9dca008c89396af54aa72ce93bcc9 + + + + + + EXTRA_OPTION_POSTGRESQL.stringtype + unspecified + + + FORCE_IDENTIFIERS_TO_LOWERCASE + N + + + FORCE_IDENTIFIERS_TO_UPPERCASE + N + + + IS_CLUSTERED + N + + + PORT_NUMBER + 1111 + + + PRESERVE_RESERVED_WORD_CASE + Y + + + QUOTE_ALL_FIELDS + N + + + SUPPORTS_BOOLEAN_DATA_TYPE + N + + + SUPPORTS_TIMESTAMP_DATA_TYPE + N + + + USE_POOLING + N + + + + + ervu_person_registry + person-dbhost + POSTGRESQL + Native + person-dbname + 4444 + person-dbuser + Encrypted 2be98afb80fd5818ba554aa72ce93bcc9 + + + + + + FORCE_IDENTIFIERS_TO_LOWERCASE + N + + + FORCE_IDENTIFIERS_TO_UPPERCASE + N + + + IS_CLUSTERED + N + + + PORT_NUMBER + 4444 + + + PRESERVE_RESERVED_WORD_CASE + Y + + + QUOTE_ALL_FIELDS + N + + + SUPPORTS_BOOLEAN_DATA_TYPE + N + + + SUPPORTS_TIMESTAMP_DATA_TYPE + N + + + USE_POOLING + N + + + + + + Table input + Table output + Y + + + Table input 2 + Table output 2 + Y + + + + Table input + TableInput + + Y + + 1 + + none + + + ervu_person_registry + select + r.id recruit_id, + case when ri.info->'svedInvalid'->'invalid'->>'gruppa'='1' then 'I группа' + when ri.info->'svedInvalid'->'invalid'->>'gruppa'='2' then 'II группа' + when ri.info->'svedInvalid'->'invalid'->>'gruppa'='3' then 'III группа' + when ri.info->'svedInvalid'->'invalid'->>'gruppa'='4' then 'ребенок-инвалид' + end disability_group, + ri.info->'svedInvalid'->'invalid'->>'ustanOrg' organization_name, + to_date(ri.info->'svedInvalid'->'invalid'->'ustanInvalid'->>'dataUstan', 'YYYY-MM-DD') start_date, + to_date(ri.info->'svedInvalid'->'invalid'->'ustanInvalid'->>'dataSnyat', 'YYYY-MM-DD') close_date, + to_date(ri.info->'svedInvalid'->'invalid'->'ustanInvalid'->>'dataPodtverzhdPlan', 'YYYY-MM-DD') confirmation_date, + true disability +from public.recruits r +join public.recruits_info ri on r.id = ri.recruit_id +where ri.info->'svedInvalid'->'invalid'->>'gruppa' is not null; + 0 + + N + N + N + + + + + + + + + + 208 + 208 + Y + + + + Table input 2 + TableInput + + Y + + 1 + + none + + + ervu_person_registry + select + r.id recruit_id, + ri.info->'svedNedeesp'->'nedeesposob'->>'naimSud' organization_name, + to_date(ri.info->'svedNedeesp'->'nedeesposob'->>'dataPrisv', 'YYYY-MM-DD') start_date, + to_date(ri.info->'svedNedeesp'->'nedeesposob'->>'dataOtmeny', 'YYYY-MM-DD') close_date +from public.recruits r +join public.recruits_info ri on r.id = ri.recruit_id +where ri.info->'svedNedeesp'->'nedeesposob'->>'naimSud' is not null; + 0 + + N + N + N + + + + + + + + + + 208 + 304 + Y + + + + Table output + TableOutput + + Y + + 1 + + none + + + ervu-dashboard + ervu_dashboard +
disability
+ 1000 + N + N + Y + N + N + + N + Y + N + + Y + N + + + + + + + + + + + + + 416 + 208 + Y + + + + Table output 2 + TableOutput + + Y + + 1 + + none + + + ervu-dashboard + ervu_dashboard + disability
+ 1000 + N + N + Y + N + N + + N + Y + N + + Y + N + + + + + + + + + + + + + 416 + 304 + Y + +
+ + + + + N + +
diff --git a/mappings/info_recruits/disease.ktr b/mappings/info_recruits/disease.ktr new file mode 100644 index 0000000..9dd33bb --- /dev/null +++ b/mappings/info_recruits/disease.ktr @@ -0,0 +1,644 @@ + + + + disease + + + + Normal + / + + + + + + + + + + + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + TRANSNAME + Y + TRANSNAME + + + STATUS + Y + STATUS + + + LINES_READ + Y + LINES_READ + + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + + LINES_UPDATED + Y + LINES_UPDATED + + + + LINES_INPUT + Y + LINES_INPUT + + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + + LINES_REJECTED + Y + LINES_REJECTED + + + + ERRORS + Y + ERRORS + + + STARTDATE + Y + STARTDATE + + + ENDDATE + Y + ENDDATE + + + LOGDATE + Y + LOGDATE + + + DEPDATE + Y + DEPDATE + + + REPLAYDATE + Y + REPLAYDATE + + + LOG_FIELD + Y + LOG_FIELD + + + EXECUTING_SERVER + N + EXECUTING_SERVER + + + EXECUTING_USER + N + EXECUTING_USER + + + CLIENT + N + CLIENT + + + + + +
+ + + + ID_BATCH + Y + ID_BATCH + + + SEQ_NR + Y + SEQ_NR + + + LOGDATE + Y + LOGDATE + + + TRANSNAME + Y + TRANSNAME + + + STEPNAME + Y + STEPNAME + + + STEP_COPY + Y + STEP_COPY + + + LINES_READ + Y + LINES_READ + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + LINES_UPDATED + Y + LINES_UPDATED + + + LINES_INPUT + Y + LINES_INPUT + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + LINES_REJECTED + Y + LINES_REJECTED + + + ERRORS + Y + ERRORS + + + INPUT_BUFFER_ROWS + Y + INPUT_BUFFER_ROWS + + + OUTPUT_BUFFER_ROWS + Y + OUTPUT_BUFFER_ROWS + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + LOGGING_OBJECT_TYPE + Y + LOGGING_OBJECT_TYPE + + + OBJECT_NAME + Y + OBJECT_NAME + + + OBJECT_COPY + Y + OBJECT_COPY + + + REPOSITORY_DIRECTORY + Y + REPOSITORY_DIRECTORY + + + FILENAME + Y + FILENAME + + + OBJECT_ID + Y + OBJECT_ID + + + OBJECT_REVISION + Y + OBJECT_REVISION + + + PARENT_CHANNEL_ID + Y + PARENT_CHANNEL_ID + + + ROOT_CHANNEL_ID + Y + ROOT_CHANNEL_ID + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + TRANSNAME + Y + TRANSNAME + + + STEPNAME + Y + STEPNAME + + + STEP_COPY + Y + STEP_COPY + + + LINES_READ + Y + LINES_READ + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + LINES_UPDATED + Y + LINES_UPDATED + + + LINES_INPUT + Y + LINES_INPUT + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + LINES_REJECTED + Y + LINES_REJECTED + + + ERRORS + Y + ERRORS + + + LOG_FIELD + N + LOG_FIELD + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + METRICS_DATE + Y + METRICS_DATE + + + METRICS_CODE + Y + METRICS_CODE + + + METRICS_DESCRIPTION + Y + METRICS_DESCRIPTION + + + METRICS_SUBJECT + Y + METRICS_SUBJECT + + + METRICS_TYPE + Y + METRICS_TYPE + + + METRICS_VALUE + Y + METRICS_VALUE + + + + + +
+ + 0.0 + 0.0 + + 10000 + 50 + 50 + N + Y + 50000 + Y + + N + 1000 + 100 + + + + + + + + + - + 2024/08/15 14:02:51.713 + - + 2024/08/15 14:02:51.713 + H4sIAAAAAAAAAAMAAAAAAAAAAAA= + N + + + + + ervu-dashboard + dashboard-dbhost + POSTGRESQL + Native + dashboard-dbname + 1111 + dashboard-dbuser + Encrypted 2daf9dca008c89396af54aa72ce93bcc9 + + + + + + EXTRA_OPTION_POSTGRESQL.stringtype + unspecified + + + FORCE_IDENTIFIERS_TO_LOWERCASE + N + + + FORCE_IDENTIFIERS_TO_UPPERCASE + N + + + IS_CLUSTERED + N + + + PORT_NUMBER + 1111 + + + PRESERVE_RESERVED_WORD_CASE + Y + + + QUOTE_ALL_FIELDS + N + + + SUPPORTS_BOOLEAN_DATA_TYPE + N + + + SUPPORTS_TIMESTAMP_DATA_TYPE + N + + + USE_POOLING + N + + + + + ervu_person_registry + person-dbhost + POSTGRESQL + Native + person-dbname + 4444 + person-dbuser + Encrypted 2be98afb80fd5818ba554aa72ce93bcc9 + + + + + + FORCE_IDENTIFIERS_TO_LOWERCASE + N + + + FORCE_IDENTIFIERS_TO_UPPERCASE + N + + + IS_CLUSTERED + N + + + PORT_NUMBER + 4444 + + + PRESERVE_RESERVED_WORD_CASE + Y + + + QUOTE_ALL_FIELDS + N + + + SUPPORTS_BOOLEAN_DATA_TYPE + N + + + SUPPORTS_TIMESTAMP_DATA_TYPE + N + + + USE_POOLING + N + + + + + + Table input + Table output + Y + + + + Table input + TableInput + + Y + + 1 + + none + + + ervu_person_registry + with zdorov as +(select jsonb_array_elements(ri.info->'svedSostZdorov'->'svedZdorov'->'sostZdorov') z, + ri.recruit_id +from public.recruits_info ri +where jsonb_typeof(ri.info->'svedSostZdorov'->'svedZdorov'->'sostZdorov') = 'array') +select + r.id recruit_id, + z->>'kodZabol' code, + z->>'naimZabol' name, + to_date(z->>'dataDiagn', 'YYYY-MM-DD') reg_date +from public.recruits r +join zdorov on r.id = zdorov.recruit_id; + 0 + + N + N + N + + + + + + + + + + 208 + 208 + Y + + + + Table output + TableOutput + + Y + + 1 + + none + + + ervu-dashboard + ervu_dashboard +
disease
+ 1000 + N + N + Y + N + N + + N + Y + N + + Y + N + + + + + + + + + + + + + 416 + 208 + Y + + + + + + + N + +
diff --git a/mappings/info_recruits/drivers_licence.ktr b/mappings/info_recruits/drivers_licence.ktr new file mode 100644 index 0000000..70cba5b --- /dev/null +++ b/mappings/info_recruits/drivers_licence.ktr @@ -0,0 +1,743 @@ + + + + drivers_licence + + + + Normal + / + + + + + + + + + + + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + TRANSNAME + Y + TRANSNAME + + + STATUS + Y + STATUS + + + LINES_READ + Y + LINES_READ + + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + + LINES_UPDATED + Y + LINES_UPDATED + + + + LINES_INPUT + Y + LINES_INPUT + + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + + LINES_REJECTED + Y + LINES_REJECTED + + + + ERRORS + Y + ERRORS + + + STARTDATE + Y + STARTDATE + + + ENDDATE + Y + ENDDATE + + + LOGDATE + Y + LOGDATE + + + DEPDATE + Y + DEPDATE + + + REPLAYDATE + Y + REPLAYDATE + + + LOG_FIELD + Y + LOG_FIELD + + + EXECUTING_SERVER + N + EXECUTING_SERVER + + + EXECUTING_USER + N + EXECUTING_USER + + + CLIENT + N + CLIENT + + + + + +
+ + + + ID_BATCH + Y + ID_BATCH + + + SEQ_NR + Y + SEQ_NR + + + LOGDATE + Y + LOGDATE + + + TRANSNAME + Y + TRANSNAME + + + STEPNAME + Y + STEPNAME + + + STEP_COPY + Y + STEP_COPY + + + LINES_READ + Y + LINES_READ + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + LINES_UPDATED + Y + LINES_UPDATED + + + LINES_INPUT + Y + LINES_INPUT + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + LINES_REJECTED + Y + LINES_REJECTED + + + ERRORS + Y + ERRORS + + + INPUT_BUFFER_ROWS + Y + INPUT_BUFFER_ROWS + + + OUTPUT_BUFFER_ROWS + Y + OUTPUT_BUFFER_ROWS + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + LOGGING_OBJECT_TYPE + Y + LOGGING_OBJECT_TYPE + + + OBJECT_NAME + Y + OBJECT_NAME + + + OBJECT_COPY + Y + OBJECT_COPY + + + REPOSITORY_DIRECTORY + Y + REPOSITORY_DIRECTORY + + + FILENAME + Y + FILENAME + + + OBJECT_ID + Y + OBJECT_ID + + + OBJECT_REVISION + Y + OBJECT_REVISION + + + PARENT_CHANNEL_ID + Y + PARENT_CHANNEL_ID + + + ROOT_CHANNEL_ID + Y + ROOT_CHANNEL_ID + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + TRANSNAME + Y + TRANSNAME + + + STEPNAME + Y + STEPNAME + + + STEP_COPY + Y + STEP_COPY + + + LINES_READ + Y + LINES_READ + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + LINES_UPDATED + Y + LINES_UPDATED + + + LINES_INPUT + Y + LINES_INPUT + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + LINES_REJECTED + Y + LINES_REJECTED + + + ERRORS + Y + ERRORS + + + LOG_FIELD + N + LOG_FIELD + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + METRICS_DATE + Y + METRICS_DATE + + + METRICS_CODE + Y + METRICS_CODE + + + METRICS_DESCRIPTION + Y + METRICS_DESCRIPTION + + + METRICS_SUBJECT + Y + METRICS_SUBJECT + + + METRICS_TYPE + Y + METRICS_TYPE + + + METRICS_VALUE + Y + METRICS_VALUE + + + + + +
+ + 0.0 + 0.0 + + 10000 + 50 + 50 + N + Y + 50000 + Y + + N + 1000 + 100 + + + + + + + + + - + 2024/08/15 14:02:51.713 + - + 2024/08/15 14:02:51.713 + H4sIAAAAAAAAAAMAAAAAAAAAAAA= + N + + + + + ervu-dashboard + dashboard-dbhost + POSTGRESQL + Native + dashboard-dbname + 1111 + dashboard-dbuser + Encrypted 2daf9dca008c89396af54aa72ce93bcc9 + + + + + + EXTRA_OPTION_POSTGRESQL.stringtype + unspecified + + + FORCE_IDENTIFIERS_TO_LOWERCASE + N + + + FORCE_IDENTIFIERS_TO_UPPERCASE + N + + + IS_CLUSTERED + N + + + PORT_NUMBER + 1111 + + + PRESERVE_RESERVED_WORD_CASE + Y + + + QUOTE_ALL_FIELDS + N + + + SUPPORTS_BOOLEAN_DATA_TYPE + N + + + SUPPORTS_TIMESTAMP_DATA_TYPE + N + + + USE_POOLING + N + + + + + ervu_person_registry + person-dbhost + POSTGRESQL + Native + person-dbname + 4444 + person-dbuser + Encrypted 2be98afb80fd5818ba554aa72ce93bcc9 + + + + + + FORCE_IDENTIFIERS_TO_LOWERCASE + N + + + FORCE_IDENTIFIERS_TO_UPPERCASE + N + + + IS_CLUSTERED + N + + + PORT_NUMBER + 4444 + + + PRESERVE_RESERVED_WORD_CASE + Y + + + QUOTE_ALL_FIELDS + N + + + SUPPORTS_BOOLEAN_DATA_TYPE + N + + + SUPPORTS_TIMESTAMP_DATA_TYPE + N + + + USE_POOLING + N + + + + + + Table input + Table output + Y + + + Table input 2 + Table output 2 + Y + + + + Table input + TableInput + + Y + + 1 + + none + + + ervu_person_registry + select + r.id recruit_id, + ri.info->'svedVoditUdost'->'voditUdost'->>'serVodUd' licence_series, + ri.info->'svedVoditUdost'->'voditUdost'->>'nomVodUd' licence_number, + to_date(ri.info->'svedVoditUdost'->'voditUdost'->>'dataVodUd', 'YYYY-MM-DD') start_date, + to_date(ri.info->'svedVoditUdost'->'voditUdost'->>'srokVodUd', 'YYYY-MM-DD') close_date, + array_to_string(array( + select kat->>'kategoriya' + from jsonb_array_elements(ri.info->'svedVoditUdost'->'voditUdost'->'svedKat') as kat + where jsonb_typeof(ri.info->'svedVoditUdost'->'voditUdost'->'svedKat') = 'array'), ',') categories +from public.recruits r +join public.recruits_info ri on r.id = ri.recruit_id +where ri.info->'svedVoditUdost'->'voditUdost'->>'serVodUd' is not null; + 0 + + N + N + N + + + + + + + + + + 208 + 208 + Y + + + + Table input 2 + TableInput + + Y + + 1 + + none + + + ervu_person_registry + select + r.id recruit_id, + ri.info->'svedUdostrTraktMash'->'udostrTraktMash'->>'serUTM' licence_series, + ri.info->'svedUdostrTraktMash'->'udostrTraktMash'->>'nomUTM' licence_number, + to_date(ri.info->'svedUdostrTraktMash'->'udostrTraktMash'->>'dataVydUTM', 'YYYY-MM-DD') start_date, + to_date(ri.info->'svedUdostrTraktMash'->'udostrTraktMash'->>'dataOkonchUTM', 'YYYY-MM-DD') close_date, + to_date(ri.info->'svedUdostrTraktMash'->'udostrTraktMash'->>'dataIztUTM', 'YYYY-MM-DD') seizure_date, + to_date(ri.info->'svedUdostrTraktMash'->'udostrTraktMash'->>'dataZamUTM', 'YYYY-MM-DD') replacement_date, + to_date(ri.info->'svedUdostrTraktMash'->'udostrTraktMash'->>'dataVozUTM', 'YYYY-MM-DD') return_date, + array_to_string(array( + select kat->>'kategoriya' + from jsonb_array_elements(ri.info->'svedVoditUdost'->'voditUdost'->'svedKat') as kat + where jsonb_typeof(ri.info->'svedVoditUdost'->'voditUdost'->'svedKat') = 'array'), ',') categories, + true tractor_driver +from public.recruits r +join public.recruits_info ri on r.id = ri.recruit_id +where ri.info->'svedUdostrTraktMash'->'udostrTraktMash'->>'serUTM' is not null; + + 0 + + N + N + N + + + + + + + + + + 208 + 304 + Y + + + + Table output + TableOutput + + Y + + 1 + + none + + + ervu-dashboard + ervu_dashboard +
drivers_licence
+ 1000 + N + N + Y + N + N + + N + Y + N + + Y + N + + + + + + + + + + + + + 416 + 208 + Y + + + + Table output 2 + TableOutput + + Y + + 1 + + none + + + ervu-dashboard + ervu_dashboard + drivers_licence
+ 1000 + N + N + Y + N + N + + N + Y + N + + Y + N + + + + + + + + + + + + + 416 + 304 + Y + +
+ + + + + N + +
diff --git a/mappings/info_recruits/job_info_recruits.kjb b/mappings/info_recruits/job_info_recruits.kjb index 3161a95..937c917 100644 --- a/mappings/info_recruits/job_info_recruits.kjb +++ b/mappings/info_recruits/job_info_recruits.kjb @@ -360,8 +360,8 @@ N Y 0 - 96 - 224 + 192 + 320 @@ -372,8 +372,8 @@ N Y 0 - 560 - 224 + 880 + 320 @@ -410,8 +410,8 @@ N Y 0 - 384 - 224 + 608 + 160 @@ -428,8 +428,8 @@ N Y 0 - 240 - 224 + 464 + 160 @@ -446,8 +446,8 @@ N Y 0 - 240 - 144 + 464 + 80 @@ -464,8 +464,8 @@ N Y 0 - 240 - 304 + 464 + 240 @@ -482,8 +482,8 @@ N Y 0 - 240 - 384 + 464 + 320 @@ -520,8 +520,8 @@ N Y 0 - 384 - 144 + 608 + 80 @@ -558,8 +558,8 @@ N Y 0 - 384 - 304 + 608 + 240 @@ -596,10 +596,290 @@ N Y 0 - 384 + 608 + 320 + + + + SQL.disease + + SQL + + delete from ervu_dashboard.disease + F + F + + F + ervu-dashboard + N + Y + 0 + 464 384 + + disease + + TRANS + + filename + + ${Internal.Entry.Current.Directory}/disease.ktr + + N + N + N + Y + N + N + + + N + N + Basic + N + + N + Y + N + N + N + Pentaho local + + Y + + N + Y + 0 + 608 + 384 + + + + SQL.medical_authorities + + SQL + + delete from ervu_dashboard.medical_authorities + F + F + + F + ervu-dashboard + N + Y + 0 + 464 + 448 + + + + medical_authorities + + TRANS + + filename + + ${Internal.Entry.Current.Directory}/medical_authorities.ktr + + N + N + N + Y + N + N + + + N + N + Basic + N + + N + Y + N + N + N + Pentaho local + + Y + + N + Y + 0 + 608 + 448 + + + + SQL.disability + + SQL + + delete from ervu_dashboard.disability + F + F + + F + ervu-dashboard + N + Y + 0 + 464 + 512 + + + + disability + + TRANS + + filename + + ${Internal.Entry.Current.Directory}/disability.ktr + + N + N + N + Y + N + N + + + N + N + Basic + N + + N + Y + N + N + N + Pentaho local + + Y + + N + Y + 0 + 608 + 512 + + + + SQL.drivers_licence + + SQL + + delete from ervu_dashboard.drivers_licence + F + F + + F + ervu-dashboard + N + Y + 0 + 464 + 576 + + + + drivers_licence + + TRANS + + filename + + ${Internal.Entry.Current.Directory}/drivers_licence.ktr + + N + N + N + Y + N + N + + + N + N + Basic + N + + N + Y + N + N + N + Pentaho local + + Y + + N + Y + 0 + 608 + 576 + + + + SQL.property + + SQL + + delete from ervu_dashboard.property + F + F + + F + ervu-dashboard + N + Y + 0 + 464 + 640 + + + + property + + TRANS + + filename + + ${Internal.Entry.Current.Directory}/property.ktr + + N + N + N + Y + N + N + + + N + N + Basic + N + + N + Y + N + N + N + Pentaho local + + Y + + N + Y + 0 + 608 + 640 + + @@ -710,6 +990,141 @@ Y Y + + Start + SQL.disease + 0 + 0 + Y + Y + Y + + + SQL.disease + disease + 0 + 0 + Y + Y + N + + + Start + SQL.medical_authorities + 0 + 0 + Y + Y + Y + + + SQL.medical_authorities + medical_authorities + 0 + 0 + Y + Y + N + + + disease + Success + 0 + 0 + Y + Y + N + + + medical_authorities + Success + 0 + 0 + Y + Y + N + + + Start + SQL.disability + 0 + 0 + Y + Y + Y + + + SQL.disability + disability + 0 + 0 + Y + Y + N + + + disability + Success + 0 + 0 + Y + Y + N + + + Start + SQL.drivers_licence + 0 + 0 + Y + Y + Y + + + SQL.drivers_licence + drivers_licence + 0 + 0 + Y + Y + N + + + drivers_licence + Success + 0 + 0 + Y + Y + N + + + Start + SQL.property + 0 + 0 + Y + Y + Y + + + SQL.property + property + 0 + 0 + Y + Y + N + + + property + Success + 0 + 0 + Y + Y + N + diff --git a/mappings/info_recruits/medical_authorities.ktr b/mappings/info_recruits/medical_authorities.ktr new file mode 100644 index 0000000..b8044f8 --- /dev/null +++ b/mappings/info_recruits/medical_authorities.ktr @@ -0,0 +1,736 @@ + + + + medical_authorities + + + + Normal + / + + + + + + + + + + + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + TRANSNAME + Y + TRANSNAME + + + STATUS + Y + STATUS + + + LINES_READ + Y + LINES_READ + + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + + LINES_UPDATED + Y + LINES_UPDATED + + + + LINES_INPUT + Y + LINES_INPUT + + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + + LINES_REJECTED + Y + LINES_REJECTED + + + + ERRORS + Y + ERRORS + + + STARTDATE + Y + STARTDATE + + + ENDDATE + Y + ENDDATE + + + LOGDATE + Y + LOGDATE + + + DEPDATE + Y + DEPDATE + + + REPLAYDATE + Y + REPLAYDATE + + + LOG_FIELD + Y + LOG_FIELD + + + EXECUTING_SERVER + N + EXECUTING_SERVER + + + EXECUTING_USER + N + EXECUTING_USER + + + CLIENT + N + CLIENT + + + + + +
+ + + + ID_BATCH + Y + ID_BATCH + + + SEQ_NR + Y + SEQ_NR + + + LOGDATE + Y + LOGDATE + + + TRANSNAME + Y + TRANSNAME + + + STEPNAME + Y + STEPNAME + + + STEP_COPY + Y + STEP_COPY + + + LINES_READ + Y + LINES_READ + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + LINES_UPDATED + Y + LINES_UPDATED + + + LINES_INPUT + Y + LINES_INPUT + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + LINES_REJECTED + Y + LINES_REJECTED + + + ERRORS + Y + ERRORS + + + INPUT_BUFFER_ROWS + Y + INPUT_BUFFER_ROWS + + + OUTPUT_BUFFER_ROWS + Y + OUTPUT_BUFFER_ROWS + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + LOGGING_OBJECT_TYPE + Y + LOGGING_OBJECT_TYPE + + + OBJECT_NAME + Y + OBJECT_NAME + + + OBJECT_COPY + Y + OBJECT_COPY + + + REPOSITORY_DIRECTORY + Y + REPOSITORY_DIRECTORY + + + FILENAME + Y + FILENAME + + + OBJECT_ID + Y + OBJECT_ID + + + OBJECT_REVISION + Y + OBJECT_REVISION + + + PARENT_CHANNEL_ID + Y + PARENT_CHANNEL_ID + + + ROOT_CHANNEL_ID + Y + ROOT_CHANNEL_ID + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + TRANSNAME + Y + TRANSNAME + + + STEPNAME + Y + STEPNAME + + + STEP_COPY + Y + STEP_COPY + + + LINES_READ + Y + LINES_READ + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + LINES_UPDATED + Y + LINES_UPDATED + + + LINES_INPUT + Y + LINES_INPUT + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + LINES_REJECTED + Y + LINES_REJECTED + + + ERRORS + Y + ERRORS + + + LOG_FIELD + N + LOG_FIELD + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + METRICS_DATE + Y + METRICS_DATE + + + METRICS_CODE + Y + METRICS_CODE + + + METRICS_DESCRIPTION + Y + METRICS_DESCRIPTION + + + METRICS_SUBJECT + Y + METRICS_SUBJECT + + + METRICS_TYPE + Y + METRICS_TYPE + + + METRICS_VALUE + Y + METRICS_VALUE + + + + + +
+ + 0.0 + 0.0 + + 10000 + 50 + 50 + N + Y + 50000 + Y + + N + 1000 + 100 + + + + + + + + + - + 2024/08/15 14:02:51.713 + - + 2024/08/15 14:02:51.713 + H4sIAAAAAAAAAAMAAAAAAAAAAAA= + N + + + + + ervu-dashboard + dashboard-dbhost + POSTGRESQL + Native + dashboard-dbname + 1111 + dashboard-dbuser + Encrypted 2daf9dca008c89396af54aa72ce93bcc9 + + + + + + EXTRA_OPTION_POSTGRESQL.stringtype + unspecified + + + FORCE_IDENTIFIERS_TO_LOWERCASE + N + + + FORCE_IDENTIFIERS_TO_UPPERCASE + N + + + IS_CLUSTERED + N + + + PORT_NUMBER + 1111 + + + PRESERVE_RESERVED_WORD_CASE + Y + + + QUOTE_ALL_FIELDS + N + + + SUPPORTS_BOOLEAN_DATA_TYPE + N + + + SUPPORTS_TIMESTAMP_DATA_TYPE + N + + + USE_POOLING + N + + + + + ervu_person_registry + person-dbhost + POSTGRESQL + Native + person-dbname + 4444 + person-dbuser + Encrypted 2be98afb80fd5818ba554aa72ce93bcc9 + + + + + + FORCE_IDENTIFIERS_TO_LOWERCASE + N + + + FORCE_IDENTIFIERS_TO_UPPERCASE + N + + + IS_CLUSTERED + N + + + PORT_NUMBER + 4444 + + + PRESERVE_RESERVED_WORD_CASE + Y + + + QUOTE_ALL_FIELDS + N + + + SUPPORTS_BOOLEAN_DATA_TYPE + N + + + SUPPORTS_TIMESTAMP_DATA_TYPE + N + + + USE_POOLING + N + + + + + + Table input hiv + Table output + Y + + + Table input 2 + Table output 2 + Y + + + + Table input 2 + TableInput + + Y + + 1 + + none + + + ervu_person_registry + with uchet as +(select jsonb_array_elements(ri.info->'svedPND'->'svedUchetDisp'->'svedUchet') u, + ri.recruit_id +from public.recruits_info ri +where jsonb_typeof(ri.info->'svedPND'->'svedUchetDisp'->'svedUchet') = 'array') +select + r.id recruit_id, + u->>'dataPostUchet' start_date, + u->>'dataSnyatUchet' close_date, + u->>'dataPlan' change_date +from public.recruits r +join uchet on r.id = uchet.recruit_id; + 0 + + N + N + N + + + + + + + + + + 208 + 352 + Y + + + + Table input hiv + TableInput + + Y + + 1 + + none + + + ervu_person_registry + with uchet as +(select jsonb_array_elements(ri.info->'svedUchetVICH'->'uchetVICH') u, + ri.recruit_id +from public.recruits_info ri +where jsonb_typeof(ri.info->'svedUchetVICH'->'uchetVICH') = 'array') +select + r.id recruit_id, + to_date(u->>'dataPostUchet', 'YYYY-MM-DD') start_date, + to_date(u->>'dataSnyat', 'YYYY-MM-DD') close_date, + true HIV +from public.recruits r +join uchet on r.id = uchet.recruit_id; + 0 + + N + N + N + + + + + + + + + + 208 + 208 + Y + + + + Table output + TableOutput + + Y + + 1 + + none + + + ervu-dashboard + ervu_dashboard +
medical_authorities
+ 1000 + N + N + Y + N + N + + N + Y + N + + Y + N + + + + + + + + + + + + + 416 + 208 + Y + + + + Table output 2 + TableOutput + + Y + + 1 + + none + + + ervu-dashboard + ervu_dashboard + medical_authorities
+ 1000 + N + N + Y + N + N + + N + Y + N + + Y + N + + + + + + + + + + + + + 416 + 352 + Y + +
+ + + + + N + +
diff --git a/mappings/info_recruits/property.ktr b/mappings/info_recruits/property.ktr new file mode 100644 index 0000000..938d0ec --- /dev/null +++ b/mappings/info_recruits/property.ktr @@ -0,0 +1,931 @@ + + + + property + + + + Normal + / + + + + + + + + + + + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + TRANSNAME + Y + TRANSNAME + + + STATUS + Y + STATUS + + + LINES_READ + Y + LINES_READ + + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + + LINES_UPDATED + Y + LINES_UPDATED + + + + LINES_INPUT + Y + LINES_INPUT + + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + + LINES_REJECTED + Y + LINES_REJECTED + + + + ERRORS + Y + ERRORS + + + STARTDATE + Y + STARTDATE + + + ENDDATE + Y + ENDDATE + + + LOGDATE + Y + LOGDATE + + + DEPDATE + Y + DEPDATE + + + REPLAYDATE + Y + REPLAYDATE + + + LOG_FIELD + Y + LOG_FIELD + + + EXECUTING_SERVER + N + EXECUTING_SERVER + + + EXECUTING_USER + N + EXECUTING_USER + + + CLIENT + N + CLIENT + + + + + +
+ + + + ID_BATCH + Y + ID_BATCH + + + SEQ_NR + Y + SEQ_NR + + + LOGDATE + Y + LOGDATE + + + TRANSNAME + Y + TRANSNAME + + + STEPNAME + Y + STEPNAME + + + STEP_COPY + Y + STEP_COPY + + + LINES_READ + Y + LINES_READ + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + LINES_UPDATED + Y + LINES_UPDATED + + + LINES_INPUT + Y + LINES_INPUT + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + LINES_REJECTED + Y + LINES_REJECTED + + + ERRORS + Y + ERRORS + + + INPUT_BUFFER_ROWS + Y + INPUT_BUFFER_ROWS + + + OUTPUT_BUFFER_ROWS + Y + OUTPUT_BUFFER_ROWS + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + LOGGING_OBJECT_TYPE + Y + LOGGING_OBJECT_TYPE + + + OBJECT_NAME + Y + OBJECT_NAME + + + OBJECT_COPY + Y + OBJECT_COPY + + + REPOSITORY_DIRECTORY + Y + REPOSITORY_DIRECTORY + + + FILENAME + Y + FILENAME + + + OBJECT_ID + Y + OBJECT_ID + + + OBJECT_REVISION + Y + OBJECT_REVISION + + + PARENT_CHANNEL_ID + Y + PARENT_CHANNEL_ID + + + ROOT_CHANNEL_ID + Y + ROOT_CHANNEL_ID + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + TRANSNAME + Y + TRANSNAME + + + STEPNAME + Y + STEPNAME + + + STEP_COPY + Y + STEP_COPY + + + LINES_READ + Y + LINES_READ + + + LINES_WRITTEN + Y + LINES_WRITTEN + + + LINES_UPDATED + Y + LINES_UPDATED + + + LINES_INPUT + Y + LINES_INPUT + + + LINES_OUTPUT + Y + LINES_OUTPUT + + + LINES_REJECTED + Y + LINES_REJECTED + + + ERRORS + Y + ERRORS + + + LOG_FIELD + N + LOG_FIELD + + + + + +
+ + + ID_BATCH + Y + ID_BATCH + + + CHANNEL_ID + Y + CHANNEL_ID + + + LOG_DATE + Y + LOG_DATE + + + METRICS_DATE + Y + METRICS_DATE + + + METRICS_CODE + Y + METRICS_CODE + + + METRICS_DESCRIPTION + Y + METRICS_DESCRIPTION + + + METRICS_SUBJECT + Y + METRICS_SUBJECT + + + METRICS_TYPE + Y + METRICS_TYPE + + + METRICS_VALUE + Y + METRICS_VALUE + + + + + +
+ + 0.0 + 0.0 + + 10000 + 50 + 50 + N + Y + 50000 + Y + + N + 1000 + 100 + + + + + + + + + - + 2024/08/15 14:02:51.713 + - + 2024/08/15 14:02:51.713 + H4sIAAAAAAAAAAMAAAAAAAAAAAA= + N + + + + + ervu-dashboard + dashboard-dbhost + POSTGRESQL + Native + dashboard-dbname + 1111 + dashboard-dbuser + Encrypted 2daf9dca008c89396af54aa72ce93bcc9 + + + + + + EXTRA_OPTION_POSTGRESQL.stringtype + unspecified + + + FORCE_IDENTIFIERS_TO_LOWERCASE + N + + + FORCE_IDENTIFIERS_TO_UPPERCASE + N + + + IS_CLUSTERED + N + + + PORT_NUMBER + 1111 + + + PRESERVE_RESERVED_WORD_CASE + Y + + + QUOTE_ALL_FIELDS + N + + + SUPPORTS_BOOLEAN_DATA_TYPE + N + + + SUPPORTS_TIMESTAMP_DATA_TYPE + N + + + USE_POOLING + N + + + + + ervu_person_registry + person-dbhost + POSTGRESQL + Native + person-dbname + 4444 + person-dbuser + Encrypted 2be98afb80fd5818ba554aa72ce93bcc9 + + + + + + FORCE_IDENTIFIERS_TO_LOWERCASE + N + + + FORCE_IDENTIFIERS_TO_UPPERCASE + N + + + IS_CLUSTERED + N + + + PORT_NUMBER + 4444 + + + PRESERVE_RESERVED_WORD_CASE + Y + + + QUOTE_ALL_FIELDS + N + + + SUPPORTS_BOOLEAN_DATA_TYPE + N + + + SUPPORTS_TIMESTAMP_DATA_TYPE + N + + + USE_POOLING + N + + + + + + Table input + Table output + Y + + + Table input 2 + Table output 2 + Y + + + Table input 2 2 + Table output 2 2 + Y + + + Table input 2 2 2 + Table output 2 2 2 + Y + + + + Table input + TableInput + + Y + + 1 + + none + + + ervu_person_registry + with prop as +(select jsonb_array_elements(ri.info->'svedON'->'on') u, + ri.recruit_id +from public.recruits_info ri +where jsonb_typeof(ri.info->'svedON'->'on') = 'array') +select + r.id recruit_id, + u->>'naimVidPrav' kind_right, + u->'adrObSob'->>'adrObSobTekst' address, + to_date(u->>'dataRegPrav', 'YYYY-MM-DD') start_date, + to_date(u->>'dataPrekPrav', 'YYYY-MM-DD') close_date, + 'realty' type_property +from public.recruits r +join prop on r.id = prop.recruit_id; + 0 + + N + N + N + + + + + + + + + + 480 + 208 + Y + + + + Table input 2 + TableInput + + Y + + 1 + + none + + + ervu_person_registry + with prop as +(select jsonb_array_elements(ri.info->'svedNazTS'->'nazTS') u, + ri.recruit_id +from public.recruits_info ri +where jsonb_typeof(ri.info->'svedNazTS'->'nazTS') = 'array') +select + r.id recruit_id, + u->>'vidTS' vehicle_type, + u->>'godVyp' issue_year, + u->>'markaTS' brand_model, + u->>'gosRegZn' reg_plate, + u->>'idenNom' vin, + to_date(u->>'dataRegPrav', 'YYYY-MM-DD') start_date, + to_date(u->>'dataPrekPrav', 'YYYY-MM-DD') close_date, + 'ground_transportation' type_property +from public.recruits r +join prop on r.id = prop.recruit_id; + 0 + + N + N + N + + + + + + + + + + 480 + 304 + Y + + + + Table input 2 2 + TableInput + + Y + + 1 + + none + + + ervu_person_registry + with prop as +(select jsonb_array_elements(ri.info->'svedVozTS'->'vozTS') u, + ri.recruit_id +from public.recruits_info ri +where jsonb_typeof(ri.info->'svedVozTS'->'vozTS') = 'array') +select + r.id recruit_id, + u->>'naimVid' vehicle_type, + u->>'naznKat' vehicle_category, + to_date(u->>'dataRegPrav', 'YYYY-MM-DD') start_date, + to_date(u->>'dataPrekPrav', 'YYYY-MM-DD') close_date, + 'air_vehicles' type_property +from public.recruits r +join prop on r.id = prop.recruit_id; + 0 + + N + N + N + + + + + + + + + + 480 + 384 + Y + + + + Table input 2 2 2 + TableInput + + Y + + 1 + + none + + + ervu_person_registry + with prop as +(select jsonb_array_elements(ri.info->'svedVozTS'->'vozTS') u, + ri.recruit_id +from public.recruits_info ri +where jsonb_typeof(ri.info->'svedVozTS'->'vozTS') = 'array') +select + r.id recruit_id, + u->>'naimVid' vehicle_type, + u->>'naznKat' vehicle_category, + to_date(u->>'dataRegPrav', 'YYYY-MM-DD') start_date, + to_date(u->>'dataPrekPrav', 'YYYY-MM-DD') close_date, + 'air_vehicles' type_property +from public.recruits r +join prop on r.id = prop.recruit_id; + 0 + + N + N + N + + + + + + + + + + 480 + 464 + Y + + + + Table output + TableOutput + + Y + + 1 + + none + + + ervu-dashboard + ervu_dashboard +
property
+ 1000 + N + N + Y + N + N + + N + Y + N + + Y + N + + + + + + + + + + + + + 688 + 208 + Y + + + + Table output 2 + TableOutput + + Y + + 1 + + none + + + ervu-dashboard + ervu_dashboard + property
+ 1000 + N + N + Y + N + N + + N + Y + N + + Y + N + + + + + + + + + + + + + 688 + 304 + Y + +
+ + Table output 2 2 + TableOutput + + Y + + 1 + + none + + + ervu-dashboard + ervu_dashboard + property
+ 1000 + N + N + Y + N + N + + N + Y + N + + Y + N + + + + + + + + + + + + + 688 + 384 + Y + +
+ + Table output 2 2 2 + TableOutput + + Y + + 1 + + none + + + ervu-dashboard + ervu_dashboard + property
+ 1000 + N + N + Y + N + N + + N + Y + N + + Y + N + + + + + + + + + + + + + 688 + 464 + Y + +
+ + + + + N + +
diff --git a/mappings/info_recruits/spouse.ktr b/mappings/info_recruits/spouse.ktr index dd30c4b..2d27d4a 100644 --- a/mappings/info_recruits/spouse.ktr +++ b/mappings/info_recruits/spouse.ktr @@ -553,6 +553,68 @@ Y + + Select values + SelectValues + + Y + + 1 + + none + + + + N + + marriage_date + marriage_date + Date + -2 + -2 + yyyy-MM-dd + false + + + false + + + + + + + + divorce_date + divorce_date + Date + -2 + -2 + yyyy-MM-dd + false + + + false + + + + + + + + + + + + + + + + + 448 + 208 + Y + + Table input TableInput @@ -659,72 +721,10 @@ join suprug on r.id = suprug.recruit_id Y - - Select values - SelectValues - - Y - - 1 - - none - - - - N - - marriage_date - marriage_date - Date - -2 - -2 - yyyy-MM-dd - false - - - false - - - - - - - - divorce_date - divorce_date - Date - -2 - -2 - yyyy-MM-dd - false - - - false - - - - - - - - - - - - - - - - - 448 - 208 - Y - - Select values - Modified JavaScript value + N diff --git a/mappings/pack.pub_recruitment.ktr b/mappings/pack.pub_recruitment.ktr index ea6c484..5aa3746 100644 --- a/mappings/pack.pub_recruitment.ktr +++ b/mappings/pack.pub_recruitment.ktr @@ -565,7 +565,7 @@ rt2.id, rt2.shortname, rt2.parent_id, rt2.idm_id, r.code from region r left join recruitment rt on rt.region_id=r.idm_id::text left join recruitment rt2 on rt2.parent_id=rt.idm_id::text -where r.code in ('12', '62','65') and rt2.idm_id is not null +where r.code in ('12', '62','65','48') and rt2.idm_id is not null 0 diff --git a/mappings/region/job_recruitments_region.kjb b/mappings/region/job_recruitments_region.kjb index 94f9f03..10f25cf 100644 --- a/mappings/region/job_recruitments_region.kjb +++ b/mappings/region/job_recruitments_region.kjb @@ -897,7 +897,7 @@ SQL - DELETE FROM main_dashboard.appeals where recruitment_id in ('12', '62', '65') and recording_date = current_date + DELETE FROM main_dashboard.appeals where recruitment_id in ('12', '62', '65', '48') and recording_date = current_date F F @@ -915,7 +915,7 @@ SQL - DELETE FROM main_dashboard.recruitment_campaign where recruitment_id in ('12', '62', '65') and recording_date = current_date + DELETE FROM main_dashboard.recruitment_campaign where recruitment_id in ('12', '62', '65', '48') and recording_date = current_date F F @@ -933,7 +933,7 @@ SQL - DELETE FROM main_dashboard.total_registered where recruitment_id in ('12', '62', '65') and recording_date = current_date + DELETE FROM main_dashboard.total_registered where recruitment_id in ('12', '62', '65', '48') and recording_date = current_date F F @@ -951,7 +951,7 @@ SQL - DELETE FROM main_dashboard.waiting_registration where recruitment_id in ('12', '62', '65') and recording_date = current_date + DELETE FROM main_dashboard.waiting_registration where recruitment_id in ('12', '62', '65', '48') and recording_date = current_date F F @@ -969,7 +969,7 @@ SQL - DELETE FROM recruitment_campaign.subpoenas where recruitment_id in ('12', '62', '65') and recording_date = current_date + DELETE FROM recruitment_campaign.subpoenas where recruitment_id in ('12', '62', '65', '48') and recording_date = current_date F F @@ -987,7 +987,7 @@ SQL - DELETE FROM total_registered.reg_mil_cat where recruitment_id in ('12', '62', '65') and recording_date = current_date + DELETE FROM total_registered.reg_mil_cat where recruitment_id in ('12', '62', '65', '48') and recording_date = current_date F F @@ -1005,7 +1005,7 @@ SQL - DELETE FROM total_registered.removed_registry where recruitment_id in ('12', '62', '65') and recording_date = current_date + DELETE FROM total_registered.removed_registry where recruitment_id in ('12', '62', '65', '48') and recording_date = current_date F F @@ -1023,7 +1023,7 @@ SQL - DELETE FROM total_registered.subpoenas where recruitment_id in ('12', '62', '65') and recording_date = current_date + DELETE FROM total_registered.subpoenas where recruitment_id in ('12', '62', '65', '48') and recording_date = current_date F F @@ -1101,7 +1101,7 @@ SQL - DELETE FROM total_registered.driver_license where recruitment_id in ('12', '62', '65') and recording_date = current_date + DELETE FROM total_registered.driver_license where recruitment_id in ('12', '62', '65', '48') and recording_date = current_date F F @@ -1179,7 +1179,7 @@ SQL - DELETE FROM total_registered.child_minor where recruitment_id in ('12', '62', '65') and recording_date = current_date + DELETE FROM total_registered.child_minor where recruitment_id in ('12', '62', '65', '48') and recording_date = current_date F F @@ -1257,7 +1257,7 @@ SQL - DELETE FROM total_registered.age where recruitment_id in ('12', '62', '65') and recording_date = current_date + DELETE FROM total_registered.age where recruitment_id in ('12', '62', '65', '48') and recording_date = current_date F F @@ -1335,7 +1335,7 @@ SQL - DELETE FROM total_registered.marital_status where recruitment_id in ('12', '62', '65') and recording_date = current_date + DELETE FROM total_registered.marital_status where recruitment_id in ('12', '62', '65', '48') and recording_date = current_date F F @@ -1413,7 +1413,7 @@ SQL - DELETE FROM total_registered.education_level where recruitment_id in ('12', '62', '65') and recording_date = current_date + DELETE FROM total_registered.education_level where recruitment_id in ('12', '62', '65', '48') and recording_date = current_date F F @@ -1491,7 +1491,7 @@ SQL - DELETE FROM total_registered.busyness where recruitment_id in ('12', '62', '65') and recording_date = current_date + DELETE FROM total_registered.busyness where recruitment_id in ('12', '62', '65', '48') and recording_date = current_date F F diff --git a/mappings/region/main_dashboard.appeals(reg).ktr b/mappings/region/main_dashboard.appeals(reg).ktr index 07a084d..d8ccbf8 100644 --- a/mappings/region/main_dashboard.appeals(reg).ktr +++ b/mappings/region/main_dashboard.appeals(reg).ktr @@ -780,20 +780,68 @@ postgres.appeal-document-service - with -t1 as (select count(*) as total_appeals from public.appeal_document ad where - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR vk_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) + WITH +t1 AS ( + SELECT + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) + END AS total_appeals + FROM public.appeal_document + WHERE + ( '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' + OR vk_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + )) ), -t2 as (select (avg(trim(both '"' from (ad.extra_info -> 'resultDate')::text)::date - appeal_date)) as average_consideration from public.appeal_document ad where - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR vk_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) +t2 AS ( + SELECT + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE ROUND( + AVG( + (TRIM(BOTH '"' FROM (ad.extra_info ->> 'resultDate')::text)::date - ad.appeal_date) + ), + 2 + ) + END AS average_consideration + FROM public.appeal_document ad + WHERE + ( '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' + OR vk_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + )) +), +resolved AS ( + SELECT + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) + END AS resolved + FROM public.appeal_document ad + WHERE ad.extra_info->>'result' = '1' + AND ( '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' + OR vk_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + )) ) -select t1.total_appeals, t2.average_consideration, '${REG_ID}' as recruitment_id, -0 as resolved, 0 as average_rating, 0 as average_to_face, 0 as average_epgu, 0 as average_to_face_percent, 0 as average_epgu_percent -from t1 full outer join t2 on 1 = 1 +SELECT + t1.total_appeals, + t2.average_consideration, + r.resolved, + '${REG_ID}' AS recruitment_id, + 0 AS average_rating, + 0 AS average_to_face, + 0 AS average_epgu, + 0 AS average_to_face_percent, + 0 AS average_epgu_percent +FROM t1, t2, resolved AS r; 0 N diff --git a/mappings/region/main_dashboard.recruitment_campaign(reg).ktr b/mappings/region/main_dashboard.recruitment_campaign(reg).ktr index 948dbf1..01d01c8 100644 --- a/mappings/region/main_dashboard.recruitment_campaign(reg).ktr +++ b/mappings/region/main_dashboard.recruitment_campaign(reg).ktr @@ -561,11 +561,6 @@ Select values 4 3 Y - - Select values 4 3 - Insert / update (main_dashboard.recruitment_campaign) 3 - Y - Table input (subpoena) регион/осень Get variables 4 3 @@ -577,13 +572,18 @@ Y - Select values 4 3 2 - Insert / update (main_dashboard.recruitment_campaign) 3 2 + Table input (subpoena) регион/весна + Get variables 4 3 2 Y - Table input (subpoena) регион/весна - Get variables 4 3 2 + Select values 4 3 + Insert / update (main_dashboard.recruitment_campaign) + Y + + + Select values 4 3 2 + Insert / update (main_dashboard.recruitment_campaign) 2 Y @@ -690,7 +690,7 @@ - Insert / update (main_dashboard.recruitment_campaign) 3 + Insert / update (main_dashboard.recruitment_campaign) InsertUpdate Y @@ -714,17 +714,17 @@ subpoenas_sent - subpoenas_sent + count_subpoena Y appeared_on_subpoenas - appeared_on_subpoenas + count_appeared Y not_appeared_on_subpoenas - not_appeared_on_subpoenas + count_not_appeared Y @@ -782,13 +782,13 @@ - 944 + 960 432 Y - Insert / update (main_dashboard.recruitment_campaign) 3 2 + Insert / update (main_dashboard.recruitment_campaign) 2 InsertUpdate Y @@ -812,17 +812,17 @@ subpoenas_sent - subpoenas_sent + count_subpoena Y appeared_on_subpoenas - appeared_on_subpoenas + count_appeared Y not_appeared_on_subpoenas - not_appeared_on_subpoenas + count_not_appeared Y @@ -1021,44 +1021,75 @@ postgres.subpoena - with -t1 as (select count(distinct subpoena.id) as subpoenas_sent FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where subpoena_reason.type='3' and sub_stat_hist.code ='3' -AND ( + WITH subpoena_data AS ( + SELECT + s.id AS subpoena_id, + s.status_id, + sr.type, + ssh.code AS sub_stat_hist, + s.send_date, + sh.date_time::timestamp AS history_date, + rdi.restriction_document_cancel_id AS restr_dc, + rdi.applied_date AS ap_date, + rdi.id AS rdi_id, + ssi.delivery_code AS d_code, + ROW_NUMBER() OVER (PARTITION BY s.id ORDER BY sh.date_time DESC) AS rn -- добавляем строку для получения последнего статуса + FROM public.subpoena s + JOIN public.subpoena_history AS sh ON sh.subpoena_id = s.id + JOIN public.subpoena_status AS ss ON ss.id = s.status_id + JOIN public.subpoena_status AS ssh ON ssh.id = sh.status_id + JOIN public.subpoena_reason AS sr ON sr.id = s.reason_id + LEFT JOIN public.restriction_document AS rd ON rd.subpoena_id = s.id + LEFT JOIN public.restriction_document_item AS rdi ON rdi.restriction_document_create_id = rd.id + LEFT JOIN public.subpoena_send_info AS ssi ON ssi.subpoena_id = s.id + WHERE sr.type = '1' -- от 18 до 30 лет и нет отсрочки (нужны эти условия), разделение весна/осень + AND ( '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t2 as (select count(distinct subpoena.id) as appeared_on_subpoenas FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where subpoena_reason.type='3' and sub_stat_hist.code in ('4.1','4.2') -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t3 as (select count(distinct subpoena.id) as not_appeared_on_subpoenas FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where subpoena_reason.type='3' and sub_stat_hist.code ='5' -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )) -select t1.subpoenas_sent, t2.appeared_on_subpoenas, t3.not_appeared_on_subpoenas, 1 as org, '${REG_ID}' as recruitment_id, 'Весна' as spring_autumn, -0 as new_recruits, 0 as postponement_have_right, 0 as postponement_granted, 0 as appeared_on_subpoenas_percent, 0 as not_appeared_on_subpoenas_percent, 0 as postponement_have_right_percent, 0 as postponement_granted_percent -from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 - + OR '${VK_ARRAY}' = '' + OR s.department_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) +), +last_status AS ( + SELECT * + FROM subpoena_data + WHERE rn = 1 -- выбираем только последнюю запись для каждой повестки +), +t1 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_subpoena + FROM last_status + WHERE sub_stat_hist IS NOT NULL +), +t2 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_appeared + FROM last_status + WHERE sub_stat_hist IN ('4.1', '4.2') +), +t3 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_appeared + FROM last_status + WHERE sub_stat_hist = '5' +) +SELECT + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t1.count_subpoena END AS count_subpoena, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t2.count_appeared END AS count_appeared, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t3.count_not_appeared END AS count_not_appeared, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(t2.count_appeared * 100.0 / NULLIF(t1.count_subpoena, 0), 2) END AS appeared_on_subpoenas_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(t3.count_not_appeared * 100.0 / NULLIF(t1.count_subpoena, 0), 2) END AS not_appeared_on_subpoenas_percent, + 0 AS new_recruits, + 0 AS postponement_have_right, + 0 AS postponement_granted, + 0 AS postponement_have_right_percent, + 0 AS postponement_granted_percent, + 'Весна' AS spring_autumn, + '${REG_ID}' AS recruitment_id, + 1 AS org +FROM t1 +FULL OUTER JOIN t2 ON 1 = 1 +FULL OUTER JOIN t3 ON 1 = 1; 0 N @@ -1090,44 +1121,75 @@ from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 postgres.subpoena - with -t1 as (select count(distinct subpoena.id) as subpoenas_sent FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where subpoena_reason.type='3' and sub_stat_hist.code ='3' -AND ( + WITH subpoena_data AS ( + SELECT + s.id AS subpoena_id, + s.status_id, + sr.type, + ssh.code AS sub_stat_hist, + s.send_date, + sh.date_time::timestamp AS history_date, + rdi.restriction_document_cancel_id AS restr_dc, + rdi.applied_date AS ap_date, + rdi.id AS rdi_id, + ssi.delivery_code AS d_code, + ROW_NUMBER() OVER (PARTITION BY s.id ORDER BY sh.date_time DESC) AS rn -- добавляем строку для получения последнего статуса + FROM public.subpoena s + JOIN public.subpoena_history AS sh ON sh.subpoena_id = s.id + JOIN public.subpoena_status AS ss ON ss.id = s.status_id + JOIN public.subpoena_status AS ssh ON ssh.id = sh.status_id + JOIN public.subpoena_reason AS sr ON sr.id = s.reason_id + LEFT JOIN public.restriction_document AS rd ON rd.subpoena_id = s.id + LEFT JOIN public.restriction_document_item AS rdi ON rdi.restriction_document_create_id = rd.id + LEFT JOIN public.subpoena_send_info AS ssi ON ssi.subpoena_id = s.id + WHERE sr.type = '1' -- от 18 до 30 лет и нет отсрочки (нужны эти условия), разделение весна/осень + AND ( '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t2 as (select count(distinct subpoena.id) as appeared_on_subpoenas FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where subpoena_reason.type='3' and sub_stat_hist.code in ('4.1','4.2') -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t3 as (select count(distinct subpoena.id) as not_appeared_on_subpoenas FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where subpoena_reason.type='3' and sub_stat_hist.code ='5' -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )) -select t1.subpoenas_sent, t2.appeared_on_subpoenas, t3.not_appeared_on_subpoenas, 1 as org, '${REG_ID}' as recruitment_id, 'Осень' as spring_autumn, -0 as new_recruits, 0 as postponement_have_right, 0 as postponement_granted, 0 as appeared_on_subpoenas_percent, 0 as not_appeared_on_subpoenas_percent, 0 as postponement_have_right_percent, 0 as postponement_granted_percent -from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 - + OR '${VK_ARRAY}' = '' + OR s.department_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) +), +last_status AS ( + SELECT * + FROM subpoena_data + WHERE rn = 1 -- выбираем только последнюю запись для каждой повестки +), +t1 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_subpoena + FROM last_status + WHERE sub_stat_hist IS NOT NULL +), +t2 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_appeared + FROM last_status + WHERE sub_stat_hist IN ('4.1', '4.2') +), +t3 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_appeared + FROM last_status + WHERE sub_stat_hist = '5' +) +SELECT + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t1.count_subpoena END AS count_subpoena, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t2.count_appeared END AS count_appeared, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t3.count_not_appeared END AS count_not_appeared, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(t2.count_appeared * 100.0 / NULLIF(t1.count_subpoena, 0), 2) END AS appeared_on_subpoenas_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(t3.count_not_appeared * 100.0 / NULLIF(t1.count_subpoena, 0), 2) END AS not_appeared_on_subpoenas_percent, + 0 AS new_recruits, + 0 AS postponement_have_right, + 0 AS postponement_granted, + 0 AS postponement_have_right_percent, + 0 AS postponement_granted_percent, + 'Осень' AS spring_autumn, + '${REG_ID}' AS recruitment_id, + 1 AS org +FROM t1 +FULL OUTER JOIN t2 ON 1 = 1 +FULL OUTER JOIN t3 ON 1 = 1; 0 N diff --git a/mappings/region/main_dashboard.total_registered(reg).ktr b/mappings/region/main_dashboard.total_registered(reg).ktr index fe288ba..e923737 100644 --- a/mappings/region/main_dashboard.total_registered(reg).ktr +++ b/mappings/region/main_dashboard.total_registered(reg).ktr @@ -618,7 +618,7 @@ - 352 + 560 304 Y @@ -706,7 +706,7 @@ - 864 + 1024 304 Y @@ -768,7 +768,7 @@ - 560 + 768 304 Y @@ -785,43 +785,46 @@ postgres.person_registry - WITH -t1 AS ( - SELECT COUNT(*) AS total_count + WITH recruit_data AS ( + SELECT + COUNT(*) AS total_count, + COUNT(*) FILTER (WHERE gender = 'MALE') AS male_count, + COUNT(*) FILTER (WHERE gender = 'FEMALE') AS female_count FROM public.recruits r WHERE r.vu_current_info ->> 'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) -), -t2 AS ( - SELECT COUNT(*) FILTER (WHERE gender = 'MALE') AS male_count - FROM public.recruits r - WHERE r.vu_current_info ->> 'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) -), -t3 AS ( - SELECT COUNT(*) FILTER (WHERE gender = 'FEMALE') AS female_count - FROM public.recruits r - WHERE r.vu_current_info ->> 'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN ARRAY[]::uuid[] + ELSE string_to_array(trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',')::uuid[] + END + ) + ) ) -SELECT t1.total_count, t2.male_count, t3.female_count, '${REG_ID}' AS recruitment_id, -0 AS mobilization_criterion, 0 AS volunteer_criterion, 0 AS contract_criterion, -0 AS mobilization_criterion_percent, 0 AS volunteer_criterion_percent, 0 AS contract_criterion_percent -FROM t1 -FULL OUTER JOIN t2 ON 1 = 1 -FULL OUTER JOIN t3 ON 1 = 1; +SELECT + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE rd.total_count + END AS total_count, + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE rd.male_count + END AS male_count, + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE rd.female_count + END AS female_count, + '${REG_ID}' AS recruitment_id, + 0 AS mobilization_criterion, + 0 AS volunteer_criterion, + 0 AS contract_criterion, + 0 AS mobilization_criterion_percent, + 0 AS volunteer_criterion_percent, + 0 AS contract_criterion_percent +FROM recruit_data rd; 0 N @@ -836,7 +839,7 @@ FULL OUTER JOIN t3 ON 1 = 1; - 128 + 352 304 Y diff --git a/mappings/region/main_dashboard.waiting_registration(reg).ktr b/mappings/region/main_dashboard.waiting_registration(reg).ktr index 8b4cf31..ba3bc3b 100644 --- a/mappings/region/main_dashboard.waiting_registration(reg).ktr +++ b/mappings/region/main_dashboard.waiting_registration(reg).ktr @@ -785,28 +785,30 @@ postgres.person_registry - with -t1 as (select count(*) waiting_count from public.recruits r where r.system_pgs_status = '1' -AND ( + SELECT + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COUNT(*) END AS waiting_count, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COUNT(*) FILTER (WHERE gender = 'MALE') END AS male_count, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COUNT(*) FILTER (WHERE gender = 'FEMALE') END AS female_count, + '${REG_ID}' AS recruitment_id, + 0 AS mobilization_criterion, + 0 AS volunteer_criterion, + 0 AS contract_criterion, + 0 AS mobilization_criterion_percent, + 0 AS volunteer_criterion_percent, + 0 AS contract_criterion_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE((COUNT(*)::DECIMAL / NULLIF((SELECT COUNT(*) FROM public.recruits), 0) * 100), 0), 2) END AS waiting_percent +FROM public.recruits r +WHERE r.vu_current_info ->> 'isMilitaryRegistered' = 'false' + AND r.current_recruitment_id IS NOT NULL + AND ( '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t2 as (select count(*) filter(where gender='MALE') male_count from public.recruits r where r.system_pgs_status = '1' -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t3 as (select count(*) filter(where gender='FEMALE') female_count from public.recruits r where r.system_pgs_status = '1' -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )) -select t1.waiting_count, t2.male_count, t3.female_count, '${REG_ID}' as recruitment_id, -0 as mobilization_criterion, 0 as volunteer_criterion, 0 as contract_criterion, 0 as mobilization_criterion_percent, 0 as volunteer_criterion_percent, 0 as contract_criterion_percent -from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ); 0 N diff --git a/mappings/region/recruitment_campaign.subpoenas(reg).ktr b/mappings/region/recruitment_campaign.subpoenas(reg).ktr index 90a27d4..d7c3ffc 100644 --- a/mappings/region/recruitment_campaign.subpoenas(reg).ktr +++ b/mappings/region/recruitment_campaign.subpoenas(reg).ktr @@ -548,11 +548,6 @@ Select values 4 3 Y - - Select values 4 3 - Insert / update (recruitment_campaign.subpoenas) 3 - Y - Table input (subpoena) осень/регионы Get variables 4 3 @@ -564,13 +559,18 @@ Y - Select values 4 3 2 - Insert / update (recruitment_campaign.subpoenas) 3 2 + Table input (subpoena) весна/регионы + Get variables 4 3 2 Y - Table input (subpoena) весна/регионы - Get variables 4 3 2 + Select values 4 3 + Insert / update (recruitment_campaign.subpoenas) + Y + + + Select values 4 3 2 + Insert / update (recruitment_campaign.subpoenas) 2 Y @@ -677,7 +677,7 @@ - Insert / update (recruitment_campaign.subpoenas) 3 + Insert / update (recruitment_campaign.subpoenas) InsertUpdate Y @@ -701,37 +701,37 @@ subpoena - subpoena + count_subpoena Y appeared - appeared + count_appeared Y not_appeared - not_appeared + count_not_appeared Y not_ap_good_reason - not_ap_good_reason + count_not_ap_good_reason Y introduced_measures - introduced_measures + count_introduced_measures Y ap_not_required - ap_not_required + count_ap_not_required Y restrictions_applied - restrictions_applied + count_restrictions_applied Y @@ -795,7 +795,7 @@ - Insert / update (recruitment_campaign.subpoenas) 3 2 + Insert / update (recruitment_campaign.subpoenas) 2 InsertUpdate Y @@ -819,37 +819,37 @@ subpoena - subpoena + count_subpoena Y appeared - appeared + count_appeared Y not_appeared - not_appeared + count_not_appeared Y not_ap_good_reason - not_ap_good_reason + count_not_ap_good_reason Y introduced_measures - introduced_measures + count_introduced_measures Y ap_not_required - ap_not_required + count_ap_not_required Y restrictions_applied - restrictions_applied + count_restrictions_applied Y @@ -969,7 +969,7 @@ - 576 + 592 400 Y @@ -1048,86 +1048,134 @@ postgres.subpoena - with -t1 as (select count(distinct subpoena.id) as subpoena FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code ='3' -AND ( + WITH subpoena_data AS ( + SELECT + s.id AS subpoena_id, + s.status_id, + sr.type, + ssh.code AS sub_stat_hist, + s.send_date, + sh.date_time::timestamp AS history_date, + rdi.restriction_document_cancel_id AS restr_dc, + rdi.applied_date AS ap_date, + rdi.id AS rdi_id, + ssi.delivery_code AS d_code, + ROW_NUMBER() OVER (PARTITION BY s.id ORDER BY sh.date_time DESC) AS rn + FROM public.subpoena s + JOIN public.subpoena_history AS sh ON sh.subpoena_id = s.id + JOIN public.subpoena_status AS ss ON ss.id = s.status_id + JOIN public.subpoena_status AS ssh ON ssh.id = sh.status_id + JOIN public.subpoena_reason AS sr ON sr.id = s.reason_id + LEFT JOIN public.restriction_document AS rd ON rd.subpoena_id = s.id + LEFT JOIN public.restriction_document_item AS rdi ON rdi.restriction_document_create_id = rd.id + LEFT JOIN public.subpoena_send_info AS ssi ON ssi.subpoena_id = s.id + WHERE sr.type = '3' + AND ( '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t2 as (select count(distinct subpoena.id) as appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code in ('4.1','4.2') -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t3 as (select count(distinct subpoena.id) as not_appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code ='5' -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t4 as (select count(*) as not_ap_good_reason FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code='5.1' -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t5 as (select count(distinct subpoena.id) as ap_not_required FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code in ('3.8','5.2') -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t6 as (select count(distinct rdi.id) as restrictions_applied from restriction_document_item rdi -join restriction_document on restriction_document.id = rdi.restriction_document_create_id -join subpoena on subpoena.id = restriction_document.subpoena_id -join subpoena_reason on subpoena_reason.id = subpoena.reason_id -where rdi.restriction_document_cancel_id is null and subpoena_reason.type = '3' -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t7 as (select count(distinct rdi.id) as introduced_measures from restriction_document_item rdi -join restriction_document on restriction_document.id = rdi.restriction_document_create_id -join subpoena on subpoena.id = restriction_document.subpoena_id -join subpoena_reason on subpoena_reason.id = subpoena.reason_id -where rdi.restriction_document_cancel_id is null and rdi.applied_date is not null and subpoena_reason.type = '3' -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )) -select t1.subpoena, t2.appeared, t3.not_appeared, t4.not_ap_good_reason, t5.ap_not_required, t6.restrictions_applied, t7.introduced_measures, 1 as mil_reg, '${REG_ID}' as recruitment_id, 1 as org, -0 as appeared_percent, 0 as not_appeared_percent, 0 as not_ap_good_reason_percent, 0 as ap_not_required_percent, 0 as restrictions_applied_percent, 0 as introduced_measures_percent, 0 as rest, 'Весна' as spring_autumn -from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 full outer join t4 on 1 = 1 full outer join t5 on 1 = 1 full outer join t6 on 1 = 1 full outer join t7 on 1 = 1 - + OR '${VK_ARRAY}' = '' + OR s.department_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) +), +last_status AS ( + SELECT * + FROM subpoena_data + WHERE rn = 1 +), +t1 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_subpoena + FROM last_status + WHERE sub_stat_hist IS NOT NULL +), +t2 AS ( + SELECT ROUND(AVG(EXTRACT(DAY FROM (history_date::timestamp - send_date::timestamp))), 1) AS average_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' +), +t3 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' +), +t4 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_appeared + FROM last_status + WHERE sub_stat_hist = '5' +), +t5 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_ap_good_reason + FROM last_status + WHERE sub_stat_hist = '5.1' +), +t6 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_ap_not_required + FROM last_status + WHERE sub_stat_hist IN ('3.8', '5.2') +), +t7 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_restrictions_applied + FROM last_status + WHERE restr_dc IS NULL +), +t8 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_introduced_measures + FROM last_status + WHERE restr_dc IS NULL AND ap_date IS NOT NULL +), +t9 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_paper + FROM last_status + WHERE d_code = '14' +), +t10 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_electron + FROM last_status + WHERE d_code = '7' +), +t11 AS ( + SELECT COUNT(DISTINCT rdi_id) AS count_restrictions + FROM last_status +) + +SELECT + COALESCE(t1.count_subpoena, 0) AS count_subpoena, + COALESCE(t2.average_appeared, 0) AS average_appeared, + COALESCE(t3.count_appeared, 0) AS count_appeared, + COALESCE(t4.count_not_appeared, 0) AS count_not_appeared, + COALESCE(t5.count_not_ap_good_reason, 0) AS count_not_ap_good_reason, + COALESCE(t6.count_ap_not_required, 0) AS count_ap_not_required, + COALESCE(t7.count_restrictions_applied, 0) AS count_restrictions_applied, + COALESCE(t8.count_introduced_measures, 0) AS count_introduced_measures, + COALESCE(t9.count_paper, 0) AS count_paper, + COALESCE(t10.count_electron, 0) AS count_electron, + COALESCE(t11.count_restrictions, 0) AS count_restrictions, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 ELSE ROUND(COALESCE(t3.count_appeared, 0) * 100.0 / t1.count_subpoena, 2) END AS appeared_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 ELSE ROUND(COALESCE(t4.count_not_appeared, 0) * 100.0 / t1.count_subpoena, 2) END AS not_appeared_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 ELSE ROUND(COALESCE(t5.count_not_ap_good_reason, 0) * 100.0 / t1.count_subpoena, 2) END AS not_ap_good_reason_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 ELSE ROUND(COALESCE(t6.count_ap_not_required, 0) * 100.0 / t1.count_subpoena, 2) END AS ap_not_required_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 ELSE ROUND(COALESCE(t10.count_electron, 0) * 100.0 / t1.count_subpoena, 2) END AS electron_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 ELSE ROUND(COALESCE(t9.count_paper, 0) * 100.0 / t1.count_subpoena, 2) END AS paper_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 ELSE ROUND(COALESCE(t7.count_restrictions_applied, 0) * 100.0 / t1.count_subpoena, 2) END AS restrictions_applied_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 ELSE ROUND(COALESCE(t8.count_introduced_measures, 0) * 100.0 / t1.count_subpoena, 2) END AS introduced_measures_percent, + '${REG_ID}' AS recruitment_id, + 0 AS rest, + 'Весна' AS spring_autumn, + 1 AS org +FROM t1 +FULL OUTER JOIN t2 ON 1 = 1 +FULL OUTER JOIN t3 ON 1 = 1 +FULL OUTER JOIN t4 ON 1 = 1 +FULL OUTER JOIN t5 ON 1 = 1 +FULL OUTER JOIN t6 ON 1 = 1 +FULL OUTER JOIN t7 ON 1 = 1 +FULL OUTER JOIN t8 ON 1 = 1 +FULL OUTER JOIN t9 ON 1 = 1 +FULL OUTER JOIN t10 ON 1 = 1 +FULL OUTER JOIN t11 ON 1 = 1 +WHERE NOT (('${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '') AND (COALESCE(t1.count_subpoena, 0) > 0 OR COALESCE(t2.average_appeared, 0) > 0 OR COALESCE(t3.count_appeared, 0) > 0 OR COALESCE(t4.count_not_appeared, 0) > 0 OR COALESCE(t5.count_not_ap_good_reason, 0) > 0 OR COALESCE(t6.count_ap_not_required, 0) > 0 OR COALESCE(t7.count_restrictions_applied, 0) > 0 OR COALESCE(t8.count_introduced_measures, 0) > 0 OR COALESCE(t9.count_paper, 0) > 0 OR COALESCE(t10.count_electron, 0) > 0 OR COALESCE(t11.count_restrictions, 0) > 0)); 0 N @@ -1159,86 +1207,134 @@ from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 full outer join postgres.subpoena - with -t1 as (select count(distinct subpoena.id) as subpoena FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code ='3' -AND ( + WITH subpoena_data AS ( + SELECT + s.id AS subpoena_id, + s.status_id, + sr.type, + ssh.code AS sub_stat_hist, + s.send_date, + sh.date_time::timestamp AS history_date, + rdi.restriction_document_cancel_id AS restr_dc, + rdi.applied_date AS ap_date, + rdi.id AS rdi_id, + ssi.delivery_code AS d_code, + ROW_NUMBER() OVER (PARTITION BY s.id ORDER BY sh.date_time DESC) AS rn + FROM public.subpoena s + JOIN public.subpoena_history AS sh ON sh.subpoena_id = s.id + JOIN public.subpoena_status AS ss ON ss.id = s.status_id + JOIN public.subpoena_status AS ssh ON ssh.id = sh.status_id + JOIN public.subpoena_reason AS sr ON sr.id = s.reason_id + LEFT JOIN public.restriction_document AS rd ON rd.subpoena_id = s.id + LEFT JOIN public.restriction_document_item AS rdi ON rdi.restriction_document_create_id = rd.id + LEFT JOIN public.subpoena_send_info AS ssi ON ssi.subpoena_id = s.id + WHERE sr.type = '3' + AND ( '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t2 as (select count(distinct subpoena.id) as appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code in ('4.1','4.2') -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t3 as (select count(distinct subpoena.id) as not_appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code ='5' -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t4 as (select count(*) as not_ap_good_reason FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code='5.1' -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t5 as (select count(distinct subpoena.id) as ap_not_required FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='3' and sub_stat_hist.code in ('3.8','5.2') -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t6 as (select count(distinct rdi.id) as restrictions_applied from restriction_document_item rdi -join restriction_document on restriction_document.id = rdi.restriction_document_create_id -join subpoena on subpoena.id = restriction_document.subpoena_id -join subpoena_reason on subpoena_reason.id = subpoena.reason_id -where rdi.restriction_document_cancel_id is null and subpoena_reason.type = '3' -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )), -t7 as (select count(distinct rdi.id) as introduced_measures from restriction_document_item rdi -join restriction_document on restriction_document.id = rdi.restriction_document_create_id -join subpoena on subpoena.id = restriction_document.subpoena_id -join subpoena_reason on subpoena_reason.id = subpoena.reason_id -where rdi.restriction_document_cancel_id is null and rdi.applied_date is not null and subpoena_reason.type = '3' -AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - )) -select t1.subpoena, t2.appeared, t3.not_appeared, t4.not_ap_good_reason, t5.ap_not_required, t6.restrictions_applied, t7.introduced_measures, 1 as mil_reg, '${REG_ID}' as recruitment_id, 1 as org, -0 as appeared_percent, 0 as not_appeared_percent, 0 as not_ap_good_reason_percent, 0 as ap_not_required_percent, 0 as restrictions_applied_percent, 0 as introduced_measures_percent, 0 as rest, 'Осень' as spring_autumn -from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 full outer join t4 on 1 = 1 full outer join t5 on 1 = 1 full outer join t6 on 1 = 1 full outer join t7 on 1 = 1 - + OR '${VK_ARRAY}' = '' + OR s.department_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) +), +last_status AS ( + SELECT * + FROM subpoena_data + WHERE rn = 1 +), +t1 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_subpoena + FROM last_status + WHERE sub_stat_hist IS NOT NULL +), +t2 AS ( + SELECT ROUND(AVG(EXTRACT(DAY FROM (history_date::timestamp - send_date::timestamp))), 1) AS average_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' +), +t3 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' +), +t4 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_appeared + FROM last_status + WHERE sub_stat_hist = '5' +), +t5 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_ap_good_reason + FROM last_status + WHERE sub_stat_hist = '5.1' +), +t6 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_ap_not_required + FROM last_status + WHERE sub_stat_hist IN ('3.8', '5.2') +), +t7 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_restrictions_applied + FROM last_status + WHERE restr_dc IS NULL +), +t8 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_introduced_measures + FROM last_status + WHERE restr_dc IS NULL AND ap_date IS NOT NULL +), +t9 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_paper + FROM last_status + WHERE d_code = '14' +), +t10 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_electron + FROM last_status + WHERE d_code = '7' +), +t11 AS ( + SELECT COUNT(DISTINCT rdi_id) AS count_restrictions + FROM last_status +) + +SELECT + COALESCE(t1.count_subpoena, 0) AS count_subpoena, + COALESCE(t2.average_appeared, 0) AS average_appeared, + COALESCE(t3.count_appeared, 0) AS count_appeared, + COALESCE(t4.count_not_appeared, 0) AS count_not_appeared, + COALESCE(t5.count_not_ap_good_reason, 0) AS count_not_ap_good_reason, + COALESCE(t6.count_ap_not_required, 0) AS count_ap_not_required, + COALESCE(t7.count_restrictions_applied, 0) AS count_restrictions_applied, + COALESCE(t8.count_introduced_measures, 0) AS count_introduced_measures, + COALESCE(t9.count_paper, 0) AS count_paper, + COALESCE(t10.count_electron, 0) AS count_electron, + COALESCE(t11.count_restrictions, 0) AS count_restrictions, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 ELSE ROUND(COALESCE(t3.count_appeared, 0) * 100.0 / t1.count_subpoena, 2) END AS appeared_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 ELSE ROUND(COALESCE(t4.count_not_appeared, 0) * 100.0 / t1.count_subpoena, 2) END AS not_appeared_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 ELSE ROUND(COALESCE(t5.count_not_ap_good_reason, 0) * 100.0 / t1.count_subpoena, 2) END AS not_ap_good_reason_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 ELSE ROUND(COALESCE(t6.count_ap_not_required, 0) * 100.0 / t1.count_subpoena, 2) END AS ap_not_required_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 ELSE ROUND(COALESCE(t10.count_electron, 0) * 100.0 / t1.count_subpoena, 2) END AS electron_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 ELSE ROUND(COALESCE(t9.count_paper, 0) * 100.0 / t1.count_subpoena, 2) END AS paper_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 ELSE ROUND(COALESCE(t7.count_restrictions_applied, 0) * 100.0 / t1.count_subpoena, 2) END AS restrictions_applied_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 ELSE ROUND(COALESCE(t8.count_introduced_measures, 0) * 100.0 / t1.count_subpoena, 2) END AS introduced_measures_percent, + '${REG_ID}' AS recruitment_id, + 0 AS rest, + 'Осень' AS spring_autumn, + 1 AS org +FROM t1 +FULL OUTER JOIN t2 ON 1 = 1 +FULL OUTER JOIN t3 ON 1 = 1 +FULL OUTER JOIN t4 ON 1 = 1 +FULL OUTER JOIN t5 ON 1 = 1 +FULL OUTER JOIN t6 ON 1 = 1 +FULL OUTER JOIN t7 ON 1 = 1 +FULL OUTER JOIN t8 ON 1 = 1 +FULL OUTER JOIN t9 ON 1 = 1 +FULL OUTER JOIN t10 ON 1 = 1 +FULL OUTER JOIN t11 ON 1 = 1 +WHERE NOT (('${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '') AND (COALESCE(t1.count_subpoena, 0) > 0 OR COALESCE(t2.average_appeared, 0) > 0 OR COALESCE(t3.count_appeared, 0) > 0 OR COALESCE(t4.count_not_appeared, 0) > 0 OR COALESCE(t5.count_not_ap_good_reason, 0) > 0 OR COALESCE(t6.count_ap_not_required, 0) > 0 OR COALESCE(t7.count_restrictions_applied, 0) > 0 OR COALESCE(t8.count_introduced_measures, 0) > 0 OR COALESCE(t9.count_paper, 0) > 0 OR COALESCE(t10.count_electron, 0) > 0 OR COALESCE(t11.count_restrictions, 0) > 0)); 0 N diff --git a/mappings/region/select_recruitments_region(reg).ktr b/mappings/region/select_recruitments_region(reg).ktr index a6b4741..5c0f2a4 100644 --- a/mappings/region/select_recruitments_region(reg).ktr +++ b/mappings/region/select_recruitments_region(reg).ktr @@ -536,11 +536,12 @@ ervu-dashboard WITH -t1 AS (SELECT ARRAY_AGG(t.idm_id) AS RECRUITMENT48_ID FROM ervu_dashboard.recruitment AS t WHERE t.code = '12'), +t1 AS (SELECT ARRAY_AGG(t.idm_id) AS RECRUITMENT12_ID FROM ervu_dashboard.recruitment AS t WHERE t.code = '12'), t2 AS (SELECT ARRAY_AGG(t.idm_id) AS RECRUITMENT62_ID FROM ervu_dashboard.recruitment AS t WHERE t.code = '62'), -t3 AS (SELECT ARRAY_AGG(t.idm_id) AS RECRUITMENT65_ID FROM ervu_dashboard.recruitment AS t WHERE t.code = '65') +t3 AS (SELECT ARRAY_AGG(t.idm_id) AS RECRUITMENT65_ID FROM ervu_dashboard.recruitment AS t WHERE t.code = '65'), +t4 AS (SELECT ARRAY_AGG(t.idm_id) AS RECRUITMENT48_ID FROM ervu_dashboard.recruitment AS t WHERE t.code = '48') SELECT - t1.RECRUITMENT48_ID AS VK_ARRAY_ID, + t1.RECRUITMENT12_ID AS VK_ARRAY_ID, '12' AS RECRUITMENT_REG_ID FROM t1 UNION ALL @@ -552,7 +553,12 @@ UNION ALL SELECT t3.RECRUITMENT65_ID, '65' -FROM t3; +FROM t3 +UNION ALL +SELECT + t4.RECRUITMENT48_ID, + '48' +FROM t4; 10 N diff --git a/mappings/region/total_registered.age(reg).ktr b/mappings/region/total_registered.age(reg).ktr index 5de2c70..e1fa9fd 100644 --- a/mappings/region/total_registered.age(reg).ktr +++ b/mappings/region/total_registered.age(reg).ktr @@ -1353,64 +1353,101 @@ ervu_person_registry WITH total_count AS ( - SELECT COUNT(*) AS total + SELECT + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) + END AS total FROM public.recruits r - join public.recruits_info ri on ri.recruit_id=r.id + JOIN public.recruits_info ri ON ri.recruit_id = r.id WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), age_counts AS ( - SELECT - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) = 17) AS "17_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 18 AND 26) AS "18-26_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 27 AND 30) AS "27-30_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 31 AND 35) AS "31-35_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 36 AND 40) AS "36-40_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 41 AND 45) AS "41-45_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 46 AND 50) AS "46-50_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) >= 51) AS "51+_year_count" + SELECT + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) = 17) + END AS "17_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 18 AND 26) + END AS "18-26_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 27 AND 30) + END AS "27-30_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 31 AND 35) + END AS "31-35_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 36 AND 40) + END AS "36-40_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 41 AND 45) + END AS "41-45_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 46 AND 50) + END AS "46-50_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) >= 51) + END AS "51+_year_count" FROM public.recruits r - join public.recruits_info ri on ri.recruit_id=r.id + JOIN public.recruits_info ri ON ri.recruit_id = r.id WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ) SELECT age_counts."17_year_count", - ROUND((age_counts."17_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "17_year_percent", + ROUND((age_counts."17_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "17_year_percent", age_counts."18-26_year_count", - ROUND((age_counts."18-26_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "18-26_year_percent", + ROUND((age_counts."18-26_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "18-26_year_percent", age_counts."27-30_year_count", - ROUND((age_counts."27-30_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "27-30_year_percent", + ROUND((age_counts."27-30_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "27-30_year_percent", age_counts."31-35_year_count", - ROUND((age_counts."31-35_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "31-35_year_percent", + ROUND((age_counts."31-35_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "31-35_year_percent", age_counts."36-40_year_count", - ROUND((age_counts."36-40_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "36-40_year_percent", + ROUND((age_counts."36-40_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "36-40_year_percent", age_counts."41-45_year_count", - ROUND((age_counts."41-45_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "41-45_year_percent", + ROUND((age_counts."41-45_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "41-45_year_percent", age_counts."46-50_year_count", - ROUND((age_counts."46-50_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "46-50_year_percent", + ROUND((age_counts."46-50_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "46-50_year_percent", age_counts."51+_year_count", - ROUND((age_counts."51+_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "51+_year_percent", + ROUND((age_counts."51+_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "51+_year_percent", - '${REG_ID}' as recruitment_id, - 'ALL' as gender, - 'true' as registered - + '${REG_ID}' AS recruitment_id, + 'ALL' AS gender, + 'true' AS registered FROM age_counts, total_count; 0 @@ -1444,64 +1481,103 @@ FROM age_counts, total_count; ervu_person_registry WITH total_count AS ( - SELECT COUNT(*) AS total + SELECT + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) + END AS total FROM public.recruits r - join public.recruits_info ri on ri.recruit_id=r.id - WHERE r.gender = 'FEMALE' AND r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + JOIN public.recruits_info ri ON ri.recruit_id = r.id + WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' + AND r.current_recruitment_id IS NOT NULL + AND r.gender = 'FEMALE' + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), age_counts AS ( - SELECT - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) = 17) AS "17_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 18 AND 26) AS "18-26_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 27 AND 30) AS "27-30_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 31 AND 35) AS "31-35_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 36 AND 40) AS "36-40_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 41 AND 45) AS "41-45_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 46 AND 50) AS "46-50_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) >= 51) AS "51+_year_count" + SELECT + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) = 17) + END AS "17_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 18 AND 26) + END AS "18-26_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 27 AND 30) + END AS "27-30_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 31 AND 35) + END AS "31-35_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 36 AND 40) + END AS "36-40_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 41 AND 45) + END AS "41-45_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 46 AND 50) + END AS "46-50_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) >= 51) + END AS "51+_year_count" FROM public.recruits r - join public.recruits_info ri on ri.recruit_id=r.id - WHERE r.gender = 'FEMALE' AND r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + JOIN public.recruits_info ri ON ri.recruit_id = r.id + WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' + AND r.gender = 'FEMALE' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ) SELECT age_counts."17_year_count", - ROUND((age_counts."17_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "17_year_percent", + ROUND((age_counts."17_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "17_year_percent", age_counts."18-26_year_count", - ROUND((age_counts."18-26_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "18-26_year_percent", + ROUND((age_counts."18-26_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "18-26_year_percent", age_counts."27-30_year_count", - ROUND((age_counts."27-30_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "27-30_year_percent", + ROUND((age_counts."27-30_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "27-30_year_percent", age_counts."31-35_year_count", - ROUND((age_counts."31-35_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "31-35_year_percent", + ROUND((age_counts."31-35_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "31-35_year_percent", age_counts."36-40_year_count", - ROUND((age_counts."36-40_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "36-40_year_percent", + ROUND((age_counts."36-40_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "36-40_year_percent", age_counts."41-45_year_count", - ROUND((age_counts."41-45_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "41-45_year_percent", + ROUND((age_counts."41-45_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "41-45_year_percent", age_counts."46-50_year_count", - ROUND((age_counts."46-50_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "46-50_year_percent", + ROUND((age_counts."46-50_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "46-50_year_percent", age_counts."51+_year_count", - ROUND((age_counts."51+_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "51+_year_percent", - - '${REG_ID}' as recruitment_id, - 'W' as gender, - 'true' as registered + ROUND((age_counts."51+_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "51+_year_percent", + '${REG_ID}' AS recruitment_id, + 'W' AS gender, + 'true' AS registered FROM age_counts, total_count; 0 @@ -1535,64 +1611,103 @@ FROM age_counts, total_count; ervu_person_registry WITH total_count AS ( - SELECT COUNT(*) AS total + SELECT + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) + END AS total FROM public.recruits r - join public.recruits_info ri on ri.recruit_id=r.id - WHERE r.gender = 'MALE' AND r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + JOIN public.recruits_info ri ON ri.recruit_id = r.id + WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' + AND r.current_recruitment_id IS NOT NULL + AND r.gender = 'MALE' + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), age_counts AS ( - SELECT - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) = 17) AS "17_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 18 AND 26) AS "18-26_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 27 AND 30) AS "27-30_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 31 AND 35) AS "31-35_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 36 AND 40) AS "36-40_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 41 AND 45) AS "41-45_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 46 AND 50) AS "46-50_year_count", - COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) >= 51) AS "51+_year_count" + SELECT + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) = 17) + END AS "17_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 18 AND 26) + END AS "18-26_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 27 AND 30) + END AS "27-30_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 31 AND 35) + END AS "31-35_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 36 AND 40) + END AS "36-40_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 41 AND 45) + END AS "41-45_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) BETWEEN 46 AND 50) + END AS "46-50_year_count", + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER (WHERE EXTRACT(YEAR FROM AGE(birth_date)) >= 51) + END AS "51+_year_count" FROM public.recruits r - join public.recruits_info ri on ri.recruit_id=r.id - WHERE r.gender = 'MALE' AND r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + JOIN public.recruits_info ri ON ri.recruit_id = r.id + WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' + AND r.gender = 'MALE' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ) SELECT age_counts."17_year_count", - ROUND((age_counts."17_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "17_year_percent", + ROUND((age_counts."17_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "17_year_percent", age_counts."18-26_year_count", - ROUND((age_counts."18-26_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "18-26_year_percent", + ROUND((age_counts."18-26_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "18-26_year_percent", age_counts."27-30_year_count", - ROUND((age_counts."27-30_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "27-30_year_percent", + ROUND((age_counts."27-30_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "27-30_year_percent", age_counts."31-35_year_count", - ROUND((age_counts."31-35_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "31-35_year_percent", + ROUND((age_counts."31-35_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "31-35_year_percent", age_counts."36-40_year_count", - ROUND((age_counts."36-40_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "36-40_year_percent", + ROUND((age_counts."36-40_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "36-40_year_percent", age_counts."41-45_year_count", - ROUND((age_counts."41-45_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "41-45_year_percent", + ROUND((age_counts."41-45_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "41-45_year_percent", age_counts."46-50_year_count", - ROUND((age_counts."46-50_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "46-50_year_percent", + ROUND((age_counts."46-50_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "46-50_year_percent", age_counts."51+_year_count", - ROUND((age_counts."51+_year_count" * 100.0) / NULLIF(total_count.total, 0),2) AS "51+_year_percent", - - '${REG_ID}' as recruitment_id, - 'M' as gender, - 'true' as registered + ROUND((age_counts."51+_year_count" * 100.0) / NULLIF(total_count.total, 0), 2) AS "51+_year_percent", + '${REG_ID}' AS recruitment_id, + 'M' AS gender, + 'true' AS registered FROM age_counts, total_count; 0 diff --git a/mappings/region/total_registered.busyness(reg).ktr b/mappings/region/total_registered.busyness(reg).ktr index a64e24d..7179e38 100644 --- a/mappings/region/total_registered.busyness(reg).ktr +++ b/mappings/region/total_registered.busyness(reg).ktr @@ -1217,9 +1217,7 @@ ervu_person_registry - -- в json отсутствует инфа об обучении в школе - -WITH status_info AS ( + WITH status_info AS ( SELECT -- Проверка на обучение в вузе (есть информация и обучается) ( @@ -1270,12 +1268,17 @@ WITH status_info AS ( info->'svedTrud'->>'prOtsSvedTrud' = '1' AS no_info_work FROM public.recruits_info ri JOIN public.recruits r ON ri.recruit_id = r.id - WHERE r.vu_current_info -> 'isMilitaryRegistered' = 'true' and r.current_recruitment_id is not null - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR r.target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + WHERE r.vu_current_info -> 'isMilitaryRegistered' = 'true' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), summary AS ( SELECT @@ -1285,9 +1288,6 @@ summary AS ( -- Количество людей, которые работают COUNT(CASE WHEN is_working THEN 1 END) AS work, - -- Количество людей, которые ни учатся, ни работают - -- COUNT(CASE WHEN NOT is_studying_in_vuz AND NOT is_studying_in_college AND NOT is_working THEN 1 END) AS not_work, - -- Количество людей, для которых отсутствуют сведения о вузе, колледже и работе COUNT(CASE WHEN no_info_vuz AND no_info_college AND no_info_work THEN 1 END) AS no_info, @@ -1296,26 +1296,23 @@ summary AS ( FROM status_info ) SELECT - 'ALL' as gender, - 'true' as registered, - '${REG_ID}' as recruitment_id, - study, - work, - 0 as not_work, - 0 as not_work_percent, + 'ALL' AS gender, + 'true' AS registered, + '${REG_ID}' AS recruitment_id, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE study END AS study, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE work END AS work, + 0 AS not_work, + 0 AS not_work_percent, total_people, -- Процент людей, которые учатся - ROUND(study * 100.0 / NULLIF(total_people, 0), 2) AS study_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(study * 100.0 / NULLIF(total_people, 0), 2) END AS study_percent, -- Процент людей, которые работают - ROUND(work * 100.0 / NULLIF(total_people, 0), 2) AS work_percent - - -- Процент людей, которые ни учатся, ни работают - -- ROUND(not_work * 100.0 / NULLIF(total_people, 0), 2) AS not_work_percent + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(work * 100.0 / NULLIF(total_people, 0), 2) END AS work_percent -- Процент людей, для которых отсутствуют сведения - -- ROUND(no_info * 100.0 / NULLIF(total_people, 0), 2) AS no_info_percent + -- CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(no_info * 100.0 / NULLIF(total_people, 0), 2) END AS no_info_percent FROM summary; 0 @@ -1348,9 +1345,7 @@ FROM summary; ervu_person_registry - -- в json отсутствует инфа об обучении в школе - -WITH status_info AS ( + WITH status_info AS ( SELECT -- Проверка на обучение в вузе (есть информация и обучается) ( @@ -1401,13 +1396,18 @@ WITH status_info AS ( info->'svedTrud'->>'prOtsSvedTrud' = '1' AS no_info_work FROM public.recruits_info ri JOIN public.recruits r ON ri.recruit_id = r.id - WHERE r.vu_current_info -> 'isMilitaryRegistered' = 'true' and r.current_recruitment_id is not null - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR r.target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) - AND gender = 'FEMALE' + WHERE r.vu_current_info -> 'isMilitaryRegistered' = 'true' + AND r.gender = 'FEMALE' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), summary AS ( SELECT @@ -1417,9 +1417,6 @@ summary AS ( -- Количество людей, которые работают COUNT(CASE WHEN is_working THEN 1 END) AS work, - -- Количество людей, которые ни учатся, ни работают - -- COUNT(CASE WHEN NOT is_studying_in_vuz AND NOT is_studying_in_college AND NOT is_working THEN 1 END) AS not_work, - -- Количество людей, для которых отсутствуют сведения о вузе, колледже и работе COUNT(CASE WHEN no_info_vuz AND no_info_college AND no_info_work THEN 1 END) AS no_info, @@ -1428,26 +1425,23 @@ summary AS ( FROM status_info ) SELECT - 'W' as gender, - 'true' as registered, - '${REG_ID}' as recruitment_id, - 0 as not_work, - 0 as not_work_percent, - study, - work, + 'W' AS gender, + 'true' AS registered, + '${REG_ID}' AS recruitment_id, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE study END AS study, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE work END AS work, + 0 AS not_work, + 0 AS not_work_percent, total_people, -- Процент людей, которые учатся - ROUND(study * 100.0 / NULLIF(total_people, 0), 2) AS study_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(study * 100.0 / NULLIF(total_people, 0), 2) END AS study_percent, -- Процент людей, которые работают - ROUND(work * 100.0 / NULLIF(total_people, 0), 2) AS work_percent - - -- Процент людей, которые ни учатся, ни работают - -- ROUND(not_work * 100.0 / NULLIF(total_people, 0), 2) AS not_work_percent + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(work * 100.0 / NULLIF(total_people, 0), 2) END AS work_percent -- Процент людей, для которых отсутствуют сведения - -- ROUND(no_info * 100.0 / NULLIF(total_people, 0), 2) AS no_info_percent + -- CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(no_info * 100.0 / NULLIF(total_people, 0), 2) END AS no_info_percent FROM summary; 0 @@ -1480,9 +1474,7 @@ FROM summary; ervu_person_registry - -- в json отсутствует инфа об обучении в школе - -WITH status_info AS ( + WITH status_info AS ( SELECT -- Проверка на обучение в вузе (есть информация и обучается) ( @@ -1533,13 +1525,18 @@ WITH status_info AS ( info->'svedTrud'->>'prOtsSvedTrud' = '1' AS no_info_work FROM public.recruits_info ri JOIN public.recruits r ON ri.recruit_id = r.id - WHERE r.vu_current_info -> 'isMilitaryRegistered' = 'true' and r.current_recruitment_id is not null - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR r.target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) - AND gender = 'MALE' + WHERE r.vu_current_info -> 'isMilitaryRegistered' = 'true' + AND r.gender = 'MALE' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), summary AS ( SELECT @@ -1549,9 +1546,6 @@ summary AS ( -- Количество людей, которые работают COUNT(CASE WHEN is_working THEN 1 END) AS work, - -- Количество людей, которые ни учатся, ни работают - -- COUNT(CASE WHEN NOT is_studying_in_vuz AND NOT is_studying_in_college AND NOT is_working THEN 1 END) AS not_work, - -- Количество людей, для которых отсутствуют сведения о вузе, колледже и работе COUNT(CASE WHEN no_info_vuz AND no_info_college AND no_info_work THEN 1 END) AS no_info, @@ -1560,26 +1554,23 @@ summary AS ( FROM status_info ) SELECT - 'M' as gender, - 'true' as registered, - '${REG_ID}' as recruitment_id, - 0 as not_work_percent, - 0 as not_work, - study, - work, + 'M' AS gender, + 'true' AS registered, + '${REG_ID}' AS recruitment_id, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE study END AS study, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE work END AS work, + 0 AS not_work, + 0 AS not_work_percent, total_people, -- Процент людей, которые учатся - ROUND(study * 100.0 / NULLIF(total_people, 0), 2) AS study_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(study * 100.0 / NULLIF(total_people, 0), 2) END AS study_percent, -- Процент людей, которые работают - ROUND(work * 100.0 / NULLIF(total_people, 0), 2) AS work_percent - - -- Процент людей, которые ни учатся, ни работают - -- ROUND(not_work * 100.0 / NULLIF(total_people, 0), 2) AS not_work_percent + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(work * 100.0 / NULLIF(total_people, 0), 2) END AS work_percent -- Процент людей, для которых отсутствуют сведения - -- ROUND(no_info * 100.0 / NULLIF(total_people, 0), 2) AS no_info_percent + -- CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(no_info * 100.0 / NULLIF(total_people, 0), 2) END AS no_info_percent FROM summary; 0 diff --git a/mappings/region/total_registered.child_minor(reg).ktr b/mappings/region/total_registered.child_minor(reg).ktr index 3590b76..5d2a613 100644 --- a/mappings/region/total_registered.child_minor(reg).ktr +++ b/mappings/region/total_registered.child_minor(reg).ktr @@ -648,8 +648,8 @@ - 496 - 96 + 592 + 288 Y @@ -699,8 +699,8 @@ - 496 - 192 + 592 + 384 Y @@ -750,8 +750,8 @@ - 496 - 288 + 592 + 480 Y @@ -848,8 +848,8 @@ - 944 - 96 + 1040 + 288 Y @@ -946,8 +946,8 @@ - 944 - 192 + 1040 + 384 Y @@ -1044,8 +1044,8 @@ - 944 - 288 + 1040 + 480 Y @@ -1106,8 +1106,8 @@ - 688 - 96 + 784 + 288 Y @@ -1168,8 +1168,8 @@ - 688 - 192 + 784 + 384 Y @@ -1230,8 +1230,8 @@ - 688 - 288 + 784 + 480 Y @@ -1257,12 +1257,17 @@ WHERE jsonb_typeof(ri.info->'svedDeti'->'rebenok') = 'array' AND r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR r.target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) AND r.gender = 'FEMALE' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), children_birth_dates AS ( SELECT @@ -1295,43 +1300,53 @@ final_counts AS ( JOIN public.recruits r ON ri.recruit_id = r.id WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR r.target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) AND r.gender = 'FEMALE' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) GROUP BY COALESCE(children_under_18, 0) ), -total_men AS ( +total_women AS ( SELECT - COUNT(*) AS total_men_count + COUNT(*) AS total_women_count FROM public.recruits_info ri JOIN public.recruits r ON ri.recruit_id = r.id WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR r.target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) AND r.gender = 'FEMALE' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ) SELECT 'W' AS gender, '${REG_ID}' AS recruitment_id, - COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) AS no_children, - COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) AS one_child, - COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) AS two_children, - COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) AS three_children, - COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) AS four_or_more_children, - ROUND(COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) AS no_children_percent, - ROUND(COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) AS one_child_percent, - ROUND(COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) AS two_children_percent, - ROUND(COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) AS three_children_percent, - ROUND(COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) AS four_or_more_children_percent + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) END AS no_children, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) END AS one_child, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) END AS two_children, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) END AS three_children, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) END AS four_or_more_children, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_women_count FROM total_women), 0), 2) END AS no_children_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_women_count FROM total_women), 0), 2) END AS one_child_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_women_count FROM total_women), 0), 2) END AS two_children_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_women_count FROM total_women), 0), 2) END AS three_children_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_women_count FROM total_women), 0), 2) END AS four_or_more_children_percent FROM final_counts; 0 @@ -1348,8 +1363,8 @@ FROM - 256 - 288 + 352 + 480 Y @@ -1375,12 +1390,17 @@ FROM WHERE jsonb_typeof(ri.info->'svedDeti'->'rebenok') = 'array' AND r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR r.target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) AND r.gender = 'MALE' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), children_birth_dates AS ( SELECT @@ -1413,12 +1433,17 @@ final_counts AS ( JOIN public.recruits r ON ri.recruit_id = r.id WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR r.target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) AND r.gender = 'MALE' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) GROUP BY COALESCE(children_under_18, 0) ), @@ -1430,26 +1455,31 @@ total_men AS ( JOIN public.recruits r ON ri.recruit_id = r.id WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR r.target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) AND r.gender = 'MALE' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ) SELECT 'M' AS gender, '${REG_ID}' AS recruitment_id, - COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) AS no_children, - COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) AS one_child, - COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) AS two_children, - COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) AS three_children, - COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) AS four_or_more_children, - ROUND(COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) AS no_children_percent, - ROUND(COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) AS one_child_percent, - ROUND(COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) AS two_children_percent, - ROUND(COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) AS three_children_percent, - ROUND(COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) AS four_or_more_children_percent + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) END AS no_children, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) END AS one_child, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) END AS two_children, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) END AS three_children, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) END AS four_or_more_children, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) END AS no_children_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) END AS one_child_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) END AS two_children_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) END AS three_children_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) END AS four_or_more_children_percent FROM final_counts; 0 @@ -1466,8 +1496,8 @@ FROM - 256 - 192 + 352 + 384 Y @@ -1489,15 +1519,20 @@ FROM jsonb_array_elements_text(ri.info->'svedDeti'->'rebenok') AS child FROM public.recruits_info ri - JOIN public.recruits r ON ri.recruit_id = r.id + JOIN public.recruits r ON ri.recruit_id = r.id WHERE jsonb_typeof(ri.info->'svedDeti'->'rebenok') = 'array' AND r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR r.target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), children_birth_dates AS ( SELECT @@ -1527,12 +1562,17 @@ final_counts AS ( public.recruits_info ri LEFT JOIN children_count cc ON ri.recruit_id = cc.recruit_id - JOIN public.recruits r ON ri.recruit_id = r.id - WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( + JOIN public.recruits r ON ri.recruit_id = r.id + WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' + AND r.current_recruitment_id IS NOT NULL + AND ( '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR r.target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) ) GROUP BY COALESCE(children_under_18, 0) @@ -1542,18 +1582,18 @@ total_people AS ( FROM final_counts ) SELECT - 'ALL' AS gender, - '${REG_ID}' as recruitment_id, - COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) AS no_children, - COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) AS one_child, - COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) AS two_children, - COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) AS three_children, - COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) AS four_or_more_children, - ROUND(COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_count FROM total_people), 0), 2) AS no_children_percent, - ROUND(COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_count FROM total_people), 0), 2) AS one_child_percent, - ROUND(COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_count FROM total_people), 0), 2) AS two_children_percent, - ROUND(COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_count FROM total_people), 0), 2) AS three_children_percent, - ROUND(COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_count FROM total_people), 0), 2) AS four_or_more_children_percent + 'ALL' AS gender, + '${REG_ID}' as recruitment_id, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) END AS no_children, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) END AS one_child, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) END AS two_children, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) END AS three_children, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) END AS four_or_more_children, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_count FROM total_people), 0), 2) END AS no_children_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_count FROM total_people), 0), 2) END AS one_child_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_count FROM total_people), 0), 2) END AS two_children_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_count FROM total_people), 0), 2) END AS three_children_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_count FROM total_people), 0), 2) END AS four_or_more_children_percent FROM final_counts; 0 @@ -1570,8 +1610,8 @@ FROM - 256 - 96 + 352 + 288 Y diff --git a/mappings/region/total_registered.driver_license(reg).ktr b/mappings/region/total_registered.driver_license(reg).ktr index 79109b5..c0f839f 100644 --- a/mappings/region/total_registered.driver_license(reg).ktr +++ b/mappings/region/total_registered.driver_license(reg).ktr @@ -1273,17 +1273,22 @@ jsonb_path_exists(ri.info, '$.svedVoditUdost.voditUdost.svedKat[*]?(@.kategoriya like_regex "E")') AS has_E FROM public.recruits_info ri JOIN public.recruits r ON ri.recruit_id = r.id - where r.vu_current_info -> 'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR r.target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + WHERE r.vu_current_info -> 'isMilitaryRegistered' = 'true' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), aggregated AS ( SELECT 'ALL' AS gender, - '${REG_ID}' as recruitment_id, + '${REG_ID}' AS recruitment_id, COUNT(*) FILTER (WHERE NOT has_A AND NOT has_B AND NOT has_C AND NOT has_D AND NOT has_E) AS nope, COUNT(*) FILTER (WHERE has_A) AS a, COUNT(*) FILTER (WHERE has_B) AS b, @@ -1294,12 +1299,12 @@ aggregated AS ( FROM categorized ) SELECT *, - ROUND((nope * 100.0) / NULLIF(total, 0), 2) AS nope_percent, - ROUND((a * 100.0) / NULLIF(total, 0), 2) AS a_percent, - ROUND((b * 100.0) / NULLIF(total, 0), 2) AS b_percent, - ROUND((c * 100.0) / NULLIF(total, 0), 2) AS c_percent, - ROUND((d * 100.0) / NULLIF(total, 0), 2) AS d_percent, - ROUND((e * 100.0) / NULLIF(total, 0), 2) AS e_percent + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((nope * 100.0) / NULLIF(total, 0), 2) END AS nope_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((a * 100.0) / NULLIF(total, 0), 2) END AS a_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((b * 100.0) / NULLIF(total, 0), 2) END AS b_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((c * 100.0) / NULLIF(total, 0), 2) END AS c_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((d * 100.0) / NULLIF(total, 0), 2) END AS d_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((e * 100.0) / NULLIF(total, 0), 2) END AS e_percent FROM aggregated; 0 @@ -1343,18 +1348,23 @@ FROM aggregated; jsonb_path_exists(ri.info, '$.svedVoditUdost.voditUdost.svedKat[*]?(@.kategoriya like_regex "E")') AS has_E FROM public.recruits_info ri JOIN public.recruits r ON ri.recruit_id = r.id - where r.vu_current_info -> 'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR r.target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) - AND r.gender = 'FEMALE' + WHERE r.vu_current_info -> 'isMilitaryRegistered' = 'true' + AND r.gender = 'FEMALE' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), aggregated AS ( SELECT 'W' AS gender, - '${REG_ID}' as recruitment_id, + '${REG_ID}' AS recruitment_id, COUNT(*) FILTER (WHERE NOT has_A AND NOT has_B AND NOT has_C AND NOT has_D AND NOT has_E) AS nope, COUNT(*) FILTER (WHERE has_A) AS a, COUNT(*) FILTER (WHERE has_B) AS b, @@ -1365,12 +1375,12 @@ aggregated AS ( FROM categorized ) SELECT *, - ROUND((nope * 100.0) / NULLIF(total, 0), 2) AS nope_percent, - ROUND((a * 100.0) / NULLIF(total, 0), 2) AS a_percent, - ROUND((b * 100.0) / NULLIF(total, 0), 2) AS b_percent, - ROUND((c * 100.0) / NULLIF(total, 0), 2) AS c_percent, - ROUND((d * 100.0) / NULLIF(total, 0), 2) AS d_percent, - ROUND((e * 100.0) / NULLIF(total, 0), 2) AS e_percent + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((nope * 100.0) / NULLIF(total, 0), 2) END AS nope_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((a * 100.0) / NULLIF(total, 0), 2) END AS a_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((b * 100.0) / NULLIF(total, 0), 2) END AS b_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((c * 100.0) / NULLIF(total, 0), 2) END AS c_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((d * 100.0) / NULLIF(total, 0), 2) END AS d_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((e * 100.0) / NULLIF(total, 0), 2) END AS e_percent FROM aggregated; 0 @@ -1414,18 +1424,23 @@ FROM aggregated; jsonb_path_exists(ri.info, '$.svedVoditUdost.voditUdost.svedKat[*]?(@.kategoriya like_regex "E")') AS has_E FROM public.recruits_info ri JOIN public.recruits r ON ri.recruit_id = r.id - where r.vu_current_info -> 'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR r.target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) - AND r.gender = 'MALE' + WHERE r.vu_current_info -> 'isMilitaryRegistered' = 'true' + AND r.gender = 'MALE' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), aggregated AS ( SELECT 'M' AS gender, - '${REG_ID}' as recruitment_id, + '${REG_ID}' AS recruitment_id, COUNT(*) FILTER (WHERE NOT has_A AND NOT has_B AND NOT has_C AND NOT has_D AND NOT has_E) AS nope, COUNT(*) FILTER (WHERE has_A) AS a, COUNT(*) FILTER (WHERE has_B) AS b, @@ -1436,12 +1451,12 @@ aggregated AS ( FROM categorized ) SELECT *, - ROUND((nope * 100.0) / NULLIF(total, 0), 2) AS nope_percent, - ROUND((a * 100.0) / NULLIF(total, 0), 2) AS a_percent, - ROUND((b * 100.0) / NULLIF(total, 0), 2) AS b_percent, - ROUND((c * 100.0) / NULLIF(total, 0), 2) AS c_percent, - ROUND((d * 100.0) / NULLIF(total, 0), 2) AS d_percent, - ROUND((e * 100.0) / NULLIF(total, 0), 2) AS e_percent + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((nope * 100.0) / NULLIF(total, 0), 2) END AS nope_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((a * 100.0) / NULLIF(total, 0), 2) END AS a_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((b * 100.0) / NULLIF(total, 0), 2) END AS b_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((c * 100.0) / NULLIF(total, 0), 2) END AS c_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((d * 100.0) / NULLIF(total, 0), 2) END AS d_percent, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND((e * 100.0) / NULLIF(total, 0), 2) END AS e_percent FROM aggregated; 0 diff --git a/mappings/region/total_registered.education_level(reg).ktr b/mappings/region/total_registered.education_level(reg).ktr index 44fed2f..823584f 100644 --- a/mappings/region/total_registered.education_level(reg).ktr +++ b/mappings/region/total_registered.education_level(reg).ktr @@ -1237,17 +1237,20 @@ FROM public.recruits_info ri JOIN public.recruits r ON ri.recruit_id = r.id WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), education_status AS ( SELECT ri.id, - - -- Высшее образование (российское или иностранное) EXISTS ( SELECT 1 FROM jsonb_array_elements(ri.info->'svedRObr'->'robr') AS education @@ -1259,8 +1262,7 @@ education_status AS ( WHERE jsonb_typeof(ri.info->'svedInObr'->'inObr') = 'array' AND education->>'kodUrObr' IN ('1', '2', '3', '4', '5') ) AS has_higher, - - -- Среднее профессиональное образование (если нет высшего) + EXISTS ( SELECT 1 FROM jsonb_array_elements(ri.info->'svedRObr'->'robr') AS education @@ -1273,7 +1275,6 @@ education_status AS ( AND education->>'kodUrObr' = '10' ) AS has_average_prof, - -- Общее образование (если нет высшего и среднего) EXISTS ( SELECT 1 FROM jsonb_array_elements(ri.info->'svedRObr'->'robr') AS education @@ -1286,17 +1287,20 @@ education_status AS ( AND education->>'kodUrObr' IN ('7', '9') ) AS has_only_general, - -- Нет данных об образовании (российское или иностранное) (ri.info->'svedRObr'->>'prOtsRObr' = '1' OR ri.info->'svedInObr'->>'prOtsInObr' = '1') AS has_no_data - FROM public.recruits_info ri JOIN public.recruits r ON ri.recruit_id = r.id WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), final_counts AS ( SELECT @@ -1309,15 +1313,15 @@ final_counts AS ( SELECT 'ALL' AS gender, '${REG_ID}' AS recruitment_id, - higher, - average_prof, - only_general, - count_nodata, - total_count.total, - ROUND(higher * 100.0 / NULLIF(total_count.total, 0), 2) AS higher_percentage, - ROUND(average_prof * 100.0 / NULLIF(total_count.total, 0), 2) AS average_prof_percentage, - ROUND(only_general * 100.0 / NULLIF(total_count.total, 0), 2) AS only_general_percentage, - ROUND(count_nodata * 100.0 / NULLIF(total_count.total, 0), 2) AS count_nodata_percentage + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE higher END AS higher, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE average_prof END AS average_prof, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE only_general END AS only_general, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE count_nodata END AS count_nodata, + total_count.total, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(higher * 100.0 / NULLIF(total_count.total, 0), 2) END AS higher_percentage, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(average_prof * 100.0 / NULLIF(total_count.total, 0), 2) END AS average_prof_percentage, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(only_general * 100.0 / NULLIF(total_count.total, 0), 2) END AS only_general_percentage, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(count_nodata * 100.0 / NULLIF(total_count.total, 0), 2) END AS count_nodata_percentage FROM final_counts, total_count; 0 @@ -1354,65 +1358,73 @@ FROM final_counts, total_count; SELECT COUNT(*) AS total FROM public.recruits_info ri JOIN public.recruits r ON ri.recruit_id = r.id - WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' AND r.gender = 'FEMALE' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' + AND r.gender = 'FEMALE' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), education_status AS ( SELECT ri.id, - -- Высшее образование: если есть высшее образование в российском или иностранном блоке EXISTS ( SELECT 1 FROM jsonb_array_elements(ri.info->'svedRObr'->'robr') AS education - WHERE jsonb_typeof(ri.info->'svedRObr'->'robr') = 'array' -- проверка на массив + WHERE jsonb_typeof(ri.info->'svedRObr'->'robr') = 'array' AND education->>'kodUrObr' IN ('1', '2', '3', '4', '5') ) OR EXISTS ( SELECT 1 FROM jsonb_array_elements(ri.info->'svedInObr'->'inObr') AS education - WHERE jsonb_typeof(ri.info->'svedInObr'->'inObr') = 'array' -- проверка на массив + WHERE jsonb_typeof(ri.info->'svedInObr'->'inObr') = 'array' AND education->>'kodUrObr' IN ('1', '2', '3', '4', '5') ) AS has_higher, - - -- Среднее профессиональное образование: если есть код 10, но нет высшего + EXISTS ( SELECT 1 FROM jsonb_array_elements(ri.info->'svedRObr'->'robr') AS education - WHERE jsonb_typeof(ri.info->'svedRObr'->'robr') = 'array' -- проверка на массив + WHERE jsonb_typeof(ri.info->'svedRObr'->'robr') = 'array' AND education->>'kodUrObr' = '10' ) OR EXISTS ( SELECT 1 FROM jsonb_array_elements(ri.info->'svedInObr'->'inObr') AS education - WHERE jsonb_typeof(ri.info->'svedInObr'->'inObr') = 'array' -- проверка на массив + WHERE jsonb_typeof(ri.info->'svedInObr'->'inObr') = 'array' AND education->>'kodUrObr' = '10' ) AS has_average_prof, - -- Общее образование: если нет высшего и среднего, но есть код 7 или 9 EXISTS ( SELECT 1 FROM jsonb_array_elements(ri.info->'svedRObr'->'robr') AS education - WHERE jsonb_typeof(ri.info->'svedRObr'->'robr') = 'array' -- проверка на массив + WHERE jsonb_typeof(ri.info->'svedRObr'->'robr') = 'array' AND education->>'kodUrObr' IN ('7', '9') ) OR EXISTS ( SELECT 1 FROM jsonb_array_elements(ri.info->'svedInObr'->'inObr') AS education - WHERE jsonb_typeof(ri.info->'svedInObr'->'inObr') = 'array' -- проверка на массив + WHERE jsonb_typeof(ri.info->'svedInObr'->'inObr') = 'array' AND education->>'kodUrObr' IN ('7', '9') ) AS has_only_general, - -- Нет данных об образовании (ri.info->'svedRObr'->>'prOtsRObr' = '1' OR ri.info->'svedInObr'->>'prOtsInObr' = '1') AS has_no_data FROM public.recruits_info ri JOIN public.recruits r ON ri.recruit_id = r.id - WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' AND r.gender = 'FEMALE' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' + AND r.gender = 'FEMALE' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), final_counts AS ( SELECT @@ -1423,17 +1435,17 @@ final_counts AS ( FROM education_status ) SELECT - 'W' as gender, - '${REG_ID}' as recruitment_id, - higher, - average_prof, - only_general, - count_nodata, - total_count.total, - ROUND(higher * 100.0 / NULLIF(total_count.total, 0), 2) AS higher_percentage, - ROUND(average_prof * 100.0 / NULLIF(total_count.total, 0), 2) AS average_prof_percentage, - ROUND(only_general * 100.0 / NULLIF(total_count.total, 0), 2) AS only_general_percentage, - ROUND(count_nodata * 100.0 / NULLIF(total_count.total, 0), 2) AS count_nodata_percentage + 'W' AS gender, + '${REG_ID}' AS recruitment_id, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE higher END AS higher, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE average_prof END AS average_prof, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE only_general END AS only_general, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE count_nodata END AS count_nodata, + total_count.total, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(higher * 100.0 / NULLIF(total_count.total, 0), 2) END AS higher_percentage, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(average_prof * 100.0 / NULLIF(total_count.total, 0), 2) END AS average_prof_percentage, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(only_general * 100.0 / NULLIF(total_count.total, 0), 2) END AS only_general_percentage, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(count_nodata * 100.0 / NULLIF(total_count.total, 0), 2) END AS count_nodata_percentage FROM final_counts, total_count; 0 @@ -1470,65 +1482,73 @@ FROM final_counts, total_count; SELECT COUNT(*) AS total FROM public.recruits_info ri JOIN public.recruits r ON ri.recruit_id = r.id - WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' AND r.gender = 'MALE' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' + AND r.gender = 'MALE' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), education_status AS ( SELECT ri.id, - -- Высшее образование: если есть высшее образование в российском или иностранном блоке EXISTS ( SELECT 1 FROM jsonb_array_elements(ri.info->'svedRObr'->'robr') AS education - WHERE jsonb_typeof(ri.info->'svedRObr'->'robr') = 'array' -- проверка на массив + WHERE jsonb_typeof(ri.info->'svedRObr'->'robr') = 'array' AND education->>'kodUrObr' IN ('1', '2', '3', '4', '5') ) OR EXISTS ( SELECT 1 FROM jsonb_array_elements(ri.info->'svedInObr'->'inObr') AS education - WHERE jsonb_typeof(ri.info->'svedInObr'->'inObr') = 'array' -- проверка на массив + WHERE jsonb_typeof(ri.info->'svedInObr'->'inObr') = 'array' AND education->>'kodUrObr' IN ('1', '2', '3', '4', '5') ) AS has_higher, - - -- Среднее профессиональное образование: если есть код 10, но нет высшего + EXISTS ( SELECT 1 FROM jsonb_array_elements(ri.info->'svedRObr'->'robr') AS education - WHERE jsonb_typeof(ri.info->'svedRObr'->'robr') = 'array' -- проверка на массив + WHERE jsonb_typeof(ri.info->'svedRObr'->'robr') = 'array' AND education->>'kodUrObr' = '10' ) OR EXISTS ( SELECT 1 FROM jsonb_array_elements(ri.info->'svedInObr'->'inObr') AS education - WHERE jsonb_typeof(ri.info->'svedInObr'->'inObr') = 'array' -- проверка на массив + WHERE jsonb_typeof(ri.info->'svedInObr'->'inObr') = 'array' AND education->>'kodUrObr' = '10' ) AS has_average_prof, - -- Общее образование: если нет высшего и среднего, но есть код 7 или 9 EXISTS ( SELECT 1 FROM jsonb_array_elements(ri.info->'svedRObr'->'robr') AS education - WHERE jsonb_typeof(ri.info->'svedRObr'->'robr') = 'array' -- проверка на массив + WHERE jsonb_typeof(ri.info->'svedRObr'->'robr') = 'array' AND education->>'kodUrObr' IN ('7', '9') ) OR EXISTS ( SELECT 1 FROM jsonb_array_elements(ri.info->'svedInObr'->'inObr') AS education - WHERE jsonb_typeof(ri.info->'svedInObr'->'inObr') = 'array' -- проверка на массив + WHERE jsonb_typeof(ri.info->'svedInObr'->'inObr') = 'array' AND education->>'kodUrObr' IN ('7', '9') ) AS has_only_general, - -- Нет данных об образовании (ri.info->'svedRObr'->>'prOtsRObr' = '1' OR ri.info->'svedInObr'->>'prOtsInObr' = '1') AS has_no_data FROM public.recruits_info ri JOIN public.recruits r ON ri.recruit_id = r.id - WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' AND r.gender = 'MALE' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true' + AND r.gender = 'MALE' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) ), final_counts AS ( SELECT @@ -1539,17 +1559,17 @@ final_counts AS ( FROM education_status ) SELECT - 'M' as gender, - '${REG_ID}' as recruitment_id, - higher, - average_prof, - only_general, - count_nodata, - total_count.total, - ROUND(higher * 100.0 / NULLIF(total_count.total, 0), 2) AS higher_percentage, - ROUND(average_prof * 100.0 / NULLIF(total_count.total, 0), 2) AS average_prof_percentage, - ROUND(only_general * 100.0 / NULLIF(total_count.total, 0), 2) AS only_general_percentage, - ROUND(count_nodata * 100.0 / NULLIF(total_count.total, 0), 2) AS count_nodata_percentage + 'M' AS gender, + '${REG_ID}' AS recruitment_id, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE higher END AS higher, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE average_prof END AS average_prof, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE only_general END AS only_general, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE count_nodata END AS count_nodata, + total_count.total, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(higher * 100.0 / NULLIF(total_count.total, 0), 2) END AS higher_percentage, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(average_prof * 100.0 / NULLIF(total_count.total, 0), 2) END AS average_prof_percentage, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(only_general * 100.0 / NULLIF(total_count.total, 0), 2) END AS only_general_percentage, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(count_nodata * 100.0 / NULLIF(total_count.total, 0), 2) END AS count_nodata_percentage FROM final_counts, total_count; 0 diff --git a/mappings/region/total_registered.marital_status(reg).ktr b/mappings/region/total_registered.marital_status(reg).ktr index f832215..e7e9194 100644 --- a/mappings/region/total_registered.marital_status(reg).ktr +++ b/mappings/region/total_registered.marital_status(reg).ktr @@ -1173,52 +1173,69 @@ ervu_person_registry SELECT - COUNT(*) FILTER ( - WHERE - ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('Вдова/Вдовец', 'В разводе') - OR ri.info->'svedSemPolozh'->'semPolozhNaim' IS NULL - ) AS not_married, - - COUNT(*) FILTER ( - WHERE - ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('В браке') - ) AS married, - - COUNT(*) AS total, - - CASE - WHEN COUNT(*) = 0 THEN 0 - ELSE ROUND( - COUNT(*) FILTER ( + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER ( WHERE ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('Вдова/Вдовец', 'В разводе') OR ri.info->'svedSemPolozh'->'semPolozhNaim' IS NULL - ) * 100.0 / COUNT(*), 2 - ) END AS not_married_percent, + ) + END AS not_married, - CASE - WHEN COUNT(*) = 0 THEN 0 - ELSE ROUND( - COUNT(*) FILTER ( + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER ( WHERE ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('В браке') - ) * 100.0 / COUNT(*), 2 - ) END AS married_percent, - 'ALL' as gender, - '${REG_ID}' as recruitment_id + ) + END AS married, + + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) + END AS total, + + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' OR COUNT(*) = 0 THEN 0 + ELSE ROUND( + COUNT(*) FILTER ( + WHERE + ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('Вдова/Вдовец', 'В разводе') + OR ri.info->'svedSemPolozh'->'semPolozhNaim' IS NULL + ) * 100.0 / COUNT(*), 2 + ) + END AS not_married_percent, + + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' OR COUNT(*) = 0 THEN 0 + ELSE ROUND( + COUNT(*) FILTER ( + WHERE + ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('В браке') + ) * 100.0 / COUNT(*), 2 + ) + END AS married_percent, + + 'ALL' AS gender, + '${REG_ID}' AS recruitment_id FROM public.recruits r JOIN public.recruits_info ri ON ri.recruit_id = r.id WHERE - r.current_recruitment_id IS NOT NULL - AND r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( + r.vu_current_info->>'isMilitaryRegistered' = 'true' + AND r.current_recruitment_id IS NOT NULL + AND ( '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ); + 0 N @@ -1250,54 +1267,70 @@ WHERE ervu_person_registry - SELECT - COUNT(*) FILTER ( - WHERE - ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('Вдова/Вдовец', 'В разводе') - OR ri.info->'svedSemPolozh'->'semPolozhNaim' IS NULL - ) AS not_married, - - COUNT(*) FILTER ( - WHERE - ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('В браке') - ) AS married, - - COUNT(*) AS total, - - CASE - WHEN COUNT(*) = 0 THEN 0 - ELSE ROUND( - COUNT(*) FILTER ( + SELECT + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER ( WHERE ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('Вдова/Вдовец', 'В разводе') OR ri.info->'svedSemPolozh'->'semPolozhNaim' IS NULL - ) * 100.0 / COUNT(*), 2 - ) END AS not_married_percent, + ) + END AS not_married, - CASE - WHEN COUNT(*) = 0 THEN 0 - ELSE ROUND( - COUNT(*) FILTER ( + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER ( WHERE ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('В браке') - ) * 100.0 / COUNT(*), 2 - ) END AS married_percent, - 'W' as gender, - '${REG_ID}' as recruitment_id + ) + END AS married, + + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) + END AS total, + + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' OR COUNT(*) = 0 THEN 0 + ELSE ROUND( + COUNT(*) FILTER ( + WHERE + ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('Вдова/Вдовец', 'В разводе') + OR ri.info->'svedSemPolozh'->'semPolozhNaim' IS NULL + ) * 100.0 / COUNT(*), 2 + ) + END AS not_married_percent, + + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' OR COUNT(*) = 0 THEN 0 + ELSE ROUND( + COUNT(*) FILTER ( + WHERE + ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('В браке') + ) * 100.0 / COUNT(*), 2 + ) + END AS married_percent, + + 'W' AS gender, + '${REG_ID}' AS recruitment_id FROM public.recruits r JOIN public.recruits_info ri ON ri.recruit_id = r.id WHERE - r.current_recruitment_id IS NOT NULL - AND r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( + r.vu_current_info->>'isMilitaryRegistered' = 'true' + AND r.gender = 'FEMALE' + AND r.current_recruitment_id IS NOT NULL + AND ( '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) - AND r.gender = 'FEMALE'; + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ); 0 @@ -1331,53 +1364,69 @@ WHERE ervu_person_registry SELECT - COUNT(*) FILTER ( - WHERE - ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('Вдова/Вдовец', 'В разводе') - OR ri.info->'svedSemPolozh'->'semPolozhNaim' IS NULL - ) AS not_married, - - COUNT(*) FILTER ( - WHERE - ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('В браке') - ) AS married, - - COUNT(*) AS total, - - CASE - WHEN COUNT(*) = 0 THEN 0 - ELSE ROUND( - COUNT(*) FILTER ( + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER ( WHERE ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('Вдова/Вдовец', 'В разводе') OR ri.info->'svedSemPolozh'->'semPolozhNaim' IS NULL - ) * 100.0 / COUNT(*), 2 - ) END AS not_married_percent, + ) + END AS not_married, - CASE - WHEN COUNT(*) = 0 THEN 0 - ELSE ROUND( - COUNT(*) FILTER ( + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) FILTER ( WHERE ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('В браке') - ) * 100.0 / COUNT(*), 2 - ) END AS married_percent, - 'M' as gender, - '${REG_ID}' as recruitment_id + ) + END AS married, + + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) + END AS total, + + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' OR COUNT(*) = 0 THEN 0 + ELSE ROUND( + COUNT(*) FILTER ( + WHERE + ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('Вдова/Вдовец', 'В разводе') + OR ri.info->'svedSemPolozh'->'semPolozhNaim' IS NULL + ) * 100.0 / COUNT(*), 2 + ) + END AS not_married_percent, + + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' OR COUNT(*) = 0 THEN 0 + ELSE ROUND( + COUNT(*) FILTER ( + WHERE + ri.info->'svedSemPolozh'->>'semPolozhNaim' IN ('В браке') + ) * 100.0 / COUNT(*), 2 + ) + END AS married_percent, + + 'M' AS gender, + '${REG_ID}' AS recruitment_id FROM public.recruits r JOIN public.recruits_info ri ON ri.recruit_id = r.id WHERE - r.current_recruitment_id IS NOT NULL - AND r.vu_current_info->>'isMilitaryRegistered' = 'true' - AND ( + r.vu_current_info->>'isMilitaryRegistered' = 'true' + AND r.gender = 'MALE' + AND r.current_recruitment_id IS NOT NULL + AND ( '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) - AND r.gender = 'MALE'; + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ); 0 diff --git a/mappings/region/total_registered.reg_mil_cat(reg).ktr b/mappings/region/total_registered.reg_mil_cat(reg).ktr index b19b361..d58dadd 100644 --- a/mappings/region/total_registered.reg_mil_cat(reg).ktr +++ b/mappings/region/total_registered.reg_mil_cat(reg).ktr @@ -562,13 +562,28 @@ Y - Select values 3 - Insert / update (total_registered.reg_mil_cat) 3 + Table input (person_registry) военком/рег + Get variables 3 Y - Table input (person_registry) военком - Get variables 3 + Get variables 3 2 + Select values 3 2 + Y + + + Table input (person_registry) военком 2 + Get variables 3 2 + Y + + + Select values 3 + Insert / update (total_registered.reg_mil_cat) + Y + + + Select values 3 2 + Insert / update (total_registered.reg_mil_cat) 2 Y @@ -618,13 +633,64 @@ - 432 - 320 + 656 + 288 Y - Insert / update (total_registered.reg_mil_cat) 3 + Get variables 3 2 + GetVariable + + Y + + 1 + + none + + + + + REG_ID + + String + + + + + -1 + -1 + none + + + VK_ARRAY + + String + + + + + -1 + -1 + none + + + + + + + + + + + + 656 + 400 + Y + + + + Insert / update (total_registered.reg_mil_cat) InsertUpdate Y @@ -726,8 +792,116 @@ - 816 - 320 + 1056 + 288 + Y + + + + Insert / update (total_registered.reg_mil_cat) 2 + InsertUpdate + + Y + + 1 + + none + + + ervu-dashboard + 100 + N + + total_registered + reg_mil_cat
+ + REG_ID + recruitment_id + = + + + + first_reg_17 + first_reg_17 + Y + + + first_reg_18 + first_reg_18 + Y + + + "mil_spec_W" + mil_spec_w + Y + + + recruitment_id + recruitment_id + N + + + returned_dep_liberty + returned_dep_liberty + Y + + + punished + punished + Y + + + received_citizenship + received_citizenship + Y + + + first_reg_17_percent + first_reg_17_percent + Y + + + first_reg_18_percent + first_reg_18_percent + Y + + + returned_dep_liberty_percent + returned_dep_liberty_percent + Y + + + "mil_spec_W_percent" + mil_spec_w_percent + Y + + + punished_percent + punished_percent + Y + + + received_citizenship_percent + received_citizenship_percent + Y + + + mil_reg + mil_reg + N + +
+ + + + + + + + + + 1056 + 400 Y
@@ -788,13 +962,75 @@ - 576 - 320 + 800 + 288 Y - Table input (person_registry) военком + Select values 3 2 + SelectValues + + Y + + 1 + + none + + + + N + + REG_ID + REG_ID + String + -2 + -2 + + false + + + false + + + + + + + + VK_ARRAY + VK_ARRAY + String + -2 + -2 + + false + + + false + + + + + + + + + + + + + + + + + 800 + 400 + Y + + + + Table input (person_registry) военком 2 TableInput Y @@ -805,46 +1041,96 @@ postgres.person_registry - WITH + WITH base_data AS ( + -- Основной набор данных + SELECT + r.registration_reasons, + r.gender, + r.vu_current_info ->> 'isMilitaryRegistered' AS is_military_registered + FROM public.recruits r + WHERE r.vu_current_info ->> 'isMilitaryRegistered' = 'true' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN ARRAY[]::uuid[] + ELSE string_to_array(trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',')::uuid[] + END + ) + ) +), +total AS ( + -- Общее количество записей + SELECT COUNT(*) AS total_count + FROM base_data +), t1 AS ( + -- Первоначальная постановка 17 лет SELECT COUNT(*) AS first_reg_17 - FROM recruits r - WHERE r.system_pgs_status = '1' - AND AGE(CURRENT_DATE, r.birth_date) < INTERVAL '18 years' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + FROM base_data + WHERE registration_reasons @> '"5"' ), t2 AS ( - -- Первоначальная постановка совершеннолетние + -- Первоначальная постановка 18 лет SELECT COUNT(*) AS first_reg_18 - FROM recruits r - WHERE r.system_pgs_status = '1' - AND AGE(CURRENT_DATE, r.birth_date) >= INTERVAL '18 years' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + FROM base_data + WHERE registration_reasons @> '"6"' + OR registration_reasons @> '"3"' + OR registration_reasons @> '"1"' + OR registration_reasons @> '"4"' + OR registration_reasons @> '"2"' ), t3 AS ( - -- Совершеннолетние женщины с ВУС + -- Женщины, получившие ВУС SELECT COUNT(*) AS mil_spec_w - FROM recruits r - WHERE r.system_pgs_status = '1' - AND AGE(CURRENT_DATE, r.birth_date) >= INTERVAL '18 years' - AND r.gender = 'FEMALE' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + FROM base_data + WHERE registration_reasons @> '"3"' AND gender = 'FEMALE' +), +t4 AS ( + -- Возвратившиеся из мест лишения свободы + SELECT COUNT(*) AS returned_dep_liberty + FROM base_data + WHERE registration_reasons @> '"1"' +), +t5 AS ( + -- Отбывающие наказание в местах лишения свободы + SELECT COUNT(*) AS punished + FROM base_data + WHERE registration_reasons @> '"4"' +), +t6 AS ( + -- Получившие гражданство + SELECT COUNT(*) AS received_citizenship + FROM base_data + WHERE registration_reasons @> '"2"' ) -select t1.first_reg_17, t2.first_reg_18, t3.mil_spec_w, '${REG_ID}' as recruitment_id, 0 as returned_dep_liberty, 0 as punished, 0 as received_citizenship, 0 as first_reg_17_percent, -0 as first_reg_18_percent, 0 as returned_dep_liberty_percent, 0 as mil_spec_W_percent, 0 as punished_percent, 0 as received_citizenship_percent, 1 as mil_reg, 1 as org -from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 +SELECT + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(total.total_count, 0) END AS total_count, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(t1.first_reg_17, 0) END AS first_reg_17, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(t2.first_reg_18, 0) END AS first_reg_18, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(t3.mil_spec_w, 0) END AS mil_spec_w, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(t4.returned_dep_liberty, 0) END AS returned_dep_liberty, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(t5.punished, 0) END AS punished, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(t6.received_citizenship, 0) END AS received_citizenship, + -- Вычисление процентов + ROUND(CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t1.first_reg_17 * 100.0 / NULLIF(total.total_count, 0) END, 2) AS first_reg_17_percent, + ROUND(CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t2.first_reg_18 * 100.0 / NULLIF(total.total_count, 0) END, 2) AS first_reg_18_percent, + ROUND(CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t4.returned_dep_liberty * 100.0 / NULLIF(total.total_count, 0) END, 2) AS returned_dep_liberty_percent, + ROUND(CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t3.mil_spec_w * 100.0 / NULLIF(total.total_count, 0) END, 2) AS mil_spec_w_percent, + ROUND(CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t5.punished * 100.0 / NULLIF(total.total_count, 0) END, 2) AS punished_percent, + ROUND(CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t6.received_citizenship * 100.0 / NULLIF(total.total_count, 0) END, 2) AS received_citizenship_percent, + '${REG_ID}' AS recruitment_id, + 0 AS mil_reg, + 1 AS org +FROM total +FULL OUTER JOIN t1 ON 1 = 1 +FULL OUTER JOIN t2 ON 1 = 1 +FULL OUTER JOIN t3 ON 1 = 1 +FULL OUTER JOIN t4 ON 1 = 1 +FULL OUTER JOIN t5 ON 1 = 1 +FULL OUTER JOIN t6 ON 1 = 1; 0 N @@ -859,8 +1145,129 @@ from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1
- 176 - 320 + 400 + 400 + Y + + + + Table input (person_registry) военком/рег + TableInput + + Y + + 1 + + none + + + postgres.person_registry + WITH base_data AS ( + -- Основной набор данных + SELECT + r.registration_reasons, + r.gender, + r.vu_current_info ->> 'isMilitaryRegistered' AS is_military_registered + FROM public.recruits r + WHERE r.vu_current_info ->> 'isMilitaryRegistered' = 'true' + AND r.current_recruitment_id IS NOT NULL + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN ARRAY[]::uuid[] + ELSE string_to_array(trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',')::uuid[] + END + ) + ) +), +total AS ( + -- Общее количество записей + SELECT COUNT(*) AS total_count + FROM base_data +), +t1 AS ( + -- Первоначальная постановка 17 лет + SELECT COUNT(*) AS first_reg_17 + FROM base_data + WHERE registration_reasons @> '"5"' +), +t2 AS ( + -- Первоначальная постановка 18 лет + SELECT COUNT(*) AS first_reg_18 + FROM base_data + WHERE registration_reasons @> '"6"' + OR registration_reasons @> '"3"' + OR registration_reasons @> '"1"' + OR registration_reasons @> '"4"' + OR registration_reasons @> '"2"' +), +t3 AS ( + -- Женщины, получившие ВУС + SELECT COUNT(*) AS mil_spec_w + FROM base_data + WHERE registration_reasons @> '"3"' AND gender = 'FEMALE' +), +t4 AS ( + -- Возвратившиеся из мест лишения свободы + SELECT COUNT(*) AS returned_dep_liberty + FROM base_data + WHERE registration_reasons @> '"1"' +), +t5 AS ( + -- Отбывающие наказание в местах лишения свободы + SELECT COUNT(*) AS punished + FROM base_data + WHERE registration_reasons @> '"4"' +), +t6 AS ( + -- Получившие гражданство + SELECT COUNT(*) AS received_citizenship + FROM base_data + WHERE registration_reasons @> '"2"' +) +SELECT + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(total.total_count, 0) END AS total_count, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(t1.first_reg_17, 0) END AS first_reg_17, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(t2.first_reg_18, 0) END AS first_reg_18, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(t3.mil_spec_w, 0) END AS mil_spec_w, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(t4.returned_dep_liberty, 0) END AS returned_dep_liberty, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(t5.punished, 0) END AS punished, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(t6.received_citizenship, 0) END AS received_citizenship, + -- Вычисление процентов + ROUND(CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t1.first_reg_17 * 100.0 / NULLIF(total.total_count, 0) END, 2) AS first_reg_17_percent, + ROUND(CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t2.first_reg_18 * 100.0 / NULLIF(total.total_count, 0) END, 2) AS first_reg_18_percent, + ROUND(CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t4.returned_dep_liberty * 100.0 / NULLIF(total.total_count, 0) END, 2) AS returned_dep_liberty_percent, + ROUND(CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t3.mil_spec_w * 100.0 / NULLIF(total.total_count, 0) END, 2) AS mil_spec_w_percent, + ROUND(CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t5.punished * 100.0 / NULLIF(total.total_count, 0) END, 2) AS punished_percent, + ROUND(CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE t6.received_citizenship * 100.0 / NULLIF(total.total_count, 0) END, 2) AS received_citizenship_percent, + '${REG_ID}' AS recruitment_id, + 1 AS mil_reg, + 1 AS org +FROM total +FULL OUTER JOIN t1 ON 1 = 1 +FULL OUTER JOIN t2 ON 1 = 1 +FULL OUTER JOIN t3 ON 1 = 1 +FULL OUTER JOIN t4 ON 1 = 1 +FULL OUTER JOIN t5 ON 1 = 1 +FULL OUTER JOIN t6 ON 1 = 1; + 0 + + N + Y + N + + + + + + + + + + 400 + 288 Y diff --git a/mappings/region/total_registered.removed_registry(reg).ktr b/mappings/region/total_registered.removed_registry(reg).ktr index c98cdbd..598d32c 100644 --- a/mappings/region/total_registered.removed_registry(reg).ktr +++ b/mappings/region/total_registered.removed_registry(reg).ktr @@ -994,31 +994,53 @@ postgres.decision-document-service - with t1 as -(select count(*) as age_limit -from public.decision d --(БД решений) -inner join public.decision_type dt on dt.id = d.type_id and dt.code = '9' -where d.extra_info -> 'cause' = '"ageLimit"' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR d.recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) -) , -t2 as (select count(*) as death -from public.decision d --(БД решений) -inner join public.decision_type dt on dt.id = d.type_id and dt.code = '9' -where d.extra_info -> 'cause' = '"notAlive"' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR d.recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) -) -select t1.age_limit, t2.death, 1 as org, '${REG_ID}' as recruitment_id, 0 as deprivation_citizenship, 0 as travel_abroad, 0 as living_abroad, 0 as other, -0 as deprivation_citizen_percents, 0 as age_limit_percent, 0 as death_percent, 0 as travel_abroad_percent, 0 as living_abroad_percent, 0 as other_percent -from t1 full outer join t2 on 1 = 1 - + WITH t1 AS ( + SELECT COUNT(*) AS age_limit + FROM public.decision d + INNER JOIN public.decision_type dt ON dt.id = d.type_id AND dt.code = '9' + WHERE d.extra_info ->> 'cause' = '"ageLimit"' + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR d.recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) +), +t2 AS ( + SELECT COUNT(*) AS death + FROM public.decision d + INNER JOIN public.decision_type dt ON dt.id = d.type_id AND dt.code = '9' + WHERE d.extra_info ->> 'cause' = '"notAlive"' + AND ( + '${VK_ARRAY}' IS NULL + OR '${VK_ARRAY}' = '' + OR d.recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ) +) +SELECT + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(t1.age_limit, 0) END AS age_limit, + CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(t2.death, 0) END AS death, + 1 AS org, + '${REG_ID}' AS recruitment_id, + 0 AS deprivation_citizenship, + 0 AS travel_abroad, + 0 AS living_abroad, + 0 AS other, + 0 AS deprivation_citizen_percents, + 0 AS age_limit_percent, + 0 AS death_percent, + 0 AS travel_abroad_percent, + 0 AS living_abroad_percent, + 0 AS other_percent +FROM t1 +FULL OUTER JOIN t2 ON 1 = 1; 0 N @@ -1050,14 +1072,24 @@ from t1 full outer join t2 on 1 = 1 postgres.person_registry - select count(*) as removed_registry, 1 org -from recruits r -where r.system_pgs_status = '1.3' - AND ( + SELECT + CASE + WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 + ELSE COUNT(*) + END AS removed_registry, + 1 AS org +FROM recruits r +WHERE r.system_pgs_status = '1.3' + AND r.current_recruitment_id IS NOT NULL + AND ( '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR target_recruitment_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) + OR '${VK_ARRAY}' = '' + OR r.target_recruitment_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) + ); 0 N diff --git a/mappings/region/total_registered.subpoenas(reg).ktr b/mappings/region/total_registered.subpoenas(reg).ktr index 4505e4e..8f37399 100644 --- a/mappings/region/total_registered.subpoenas(reg).ktr +++ b/mappings/region/total_registered.subpoenas(reg).ktr @@ -566,24 +566,24 @@ Get variables 4 2 Y - - Select values 4 2 - Insert / update (total_registered.subpoenas) 3 - Y - Get variables 4 2 2 Select values 4 2 2 Y - Select values 4 2 2 - Insert / update (total_registered.subpoenas) 2 2 + Table input (subpoena) регион/не рег + Get variables 4 2 2 Y - Table input (subpoena) регион/не рег - Get variables 4 2 2 + Select values 4 2 + Insert / update (total_registered.subpoenas) + Y + + + Select values 4 2 2 + Insert / update (total_registered.subpoenas) 2 Y @@ -690,7 +690,7 @@ - Insert / update (total_registered.subpoenas) 2 2 + Insert / update (total_registered.subpoenas) InsertUpdate Y @@ -714,12 +714,12 @@ subpoena - subpoena + count_subpoena Y appeared - appeared + count_appeared Y @@ -729,37 +729,175 @@ not_appeared - not_appeared + count_not_appeared Y not_ap_good_reason - not_ap_good_reason + count_not_ap_good_reason Y introduced_measures - introduced_measures + count_introduced_measures Y ap_not_required - ap_not_required + count_ap_not_required Y electron - electron + count_electron Y paper - paper + count_paper Y restrictions_applied - restrictions_applied + count_restrictions_applied + Y + + + recruitment_id + recruitment_id + N + + + mil_reg + mil_reg + N + + + appeared_percent + appeared_percent + Y + + + not_appeared_percent + not_appeared_percent + Y + + + not_ap_good_reason_percent + not_ap_good_reason_percent + Y + + + ap_not_required_percent + ap_not_required_percent + Y + + + electron_percent + electron_percent + Y + + + paper_percent + paper_percent + Y + + + restrictions_applied_percent + restrictions_applied_percent + Y + + + introduced_measures_percent + introduced_measures_percent + Y + + + + + + + + + + + + 912 + 400 + Y + + + + Insert / update (total_registered.subpoenas) 2 + InsertUpdate + + Y + + 1 + + none + + + ervu-dashboard + 100 + N + + total_registered + subpoenas
+ + REG_ID + recruitment_id + = + + + + subpoena + count_subpoena + Y + + + appeared + count_appeared + Y + + + average_appeared + average_appeared + Y + + + not_appeared + count_not_appeared + Y + + + not_ap_good_reason + count_not_ap_good_reason + Y + + + introduced_measures + count_introduced_measures + Y + + + ap_not_required + count_ap_not_required + Y + + + electron + count_electron + Y + + + paper + count_paper + Y + + + restrictions_applied + count_restrictions_applied Y @@ -827,144 +965,6 @@ Y
- - Insert / update (total_registered.subpoenas) 3 - InsertUpdate - - Y - - 1 - - none - - - ervu-dashboard - 100 - N - - total_registered - subpoenas
- - REG_ID - recruitment_id - = - - - - subpoena - subpoena - Y - - - appeared - appeared - Y - - - average_appeared - average_appeared - Y - - - not_appeared - not_appeared - Y - - - not_ap_good_reason - not_ap_good_reason - Y - - - introduced_measures - introduced_measures - Y - - - ap_not_required - ap_not_required - Y - - - electron - electron - Y - - - paper - paper - Y - - - restrictions_applied - restrictions_applied - Y - - - recruitment_id - recruitment_id - N - - - mil_reg - mil_reg - N - - - appeared_percent - appeared_percent - Y - - - not_appeared_percent - not_appeared_percent - Y - - - not_ap_good_reason_percent - not_ap_good_reason_percent - Y - - - ap_not_required_percent - ap_not_required_percent - Y - - - electron_percent - electron_percent - Y - - - paper_percent - paper_percent - Y - - - restrictions_applied_percent - restrictions_applied_percent - Y - - - introduced_measures_percent - introduced_measures_percent - Y - -
- - - - - - - - - - 896 - 400 - Y - -
Select values 4 2 SelectValues @@ -1101,125 +1101,147 @@ postgres.subpoena - with -t1 as (select count(distinct subpoena.id) as subpoena FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='1' and sub_stat_hist.code ='3' - AND ( + WITH subpoena_data AS ( + SELECT + s.id AS subpoena_id, + s.status_id, + sr.type, + ssh.code AS sub_stat_hist, + s.send_date, + sh.date_time::timestamp AS history_date, + rdi.restriction_document_cancel_id AS restr_dc, + rdi.applied_date AS ap_date, + rdi.id AS rdi_id, + ssi.delivery_code AS d_code, + ROW_NUMBER() OVER (PARTITION BY s.id ORDER BY sh.date_time DESC) AS rn + FROM subpoena s + JOIN subpoena_history AS sh ON sh.subpoena_id = s.id + JOIN subpoena_status AS ss ON ss.id = s.status_id + JOIN subpoena_status AS ssh ON ssh.id = sh.status_id + JOIN subpoena_reason AS sr ON sr.id = s.reason_id + LEFT JOIN restriction_document AS rd ON rd.subpoena_id = s.id + LEFT JOIN restriction_document_item AS rdi ON rdi.restriction_document_create_id = rd.id + LEFT JOIN subpoena_send_info AS ssi ON ssi.subpoena_id = s.id + WHERE sr.type = '1' + AND ( '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) + OR '${VK_ARRAY}' = '' + OR s.department_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) ) ), -t2 as (select round(avg(extract(day from subpoena_history.date_time::timestamp - (subpoena.send_date::timestamptz AT time zone 'UTC')::timestamp)), 1) as average_appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where subpoena_reason.type = '1' and (sub_stat_hist.code = '4.1' or sub_stat_hist.code = '4.2') - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +last_status AS ( + SELECT * + FROM subpoena_data + WHERE rn = 1 ), -t3 as (select count(distinct subpoena.id) as appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='1' and sub_stat_hist.code in ('4.1','4.2') - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +t1 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_subpoena + FROM last_status + WHERE sub_stat_hist IS NOT NULL ), -t4 as (select count(distinct subpoena.id) as not_appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='1' and sub_stat_hist.code ='5' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +t2 AS ( + SELECT ROUND(AVG(EXTRACT(DAY FROM (history_date::timestamp - send_date::timestamp))), 1) AS average_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' ), -t5 as (select count(*) as not_ap_good_reason FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='1' and sub_stat_hist.code='5.1' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +t3 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' ), -t6 as (select count(distinct subpoena.id) as ap_not_required FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type='1' and sub_stat_hist.code in ('3.8','5.2') - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +t4 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_appeared + FROM last_status + WHERE sub_stat_hist = '5' ), -t7 as (select count(distinct rdi.id) as restrictions_applied from restriction_document_item rdi -join restriction_document on restriction_document.id = rdi.restriction_document_create_id -join subpoena on subpoena.id = restriction_document.subpoena_id -join subpoena_reason on subpoena_reason.id = subpoena.reason_id -where rdi.restriction_document_cancel_id is null and subpoena_reason.type = '1' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +t5 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_ap_good_reason + FROM last_status + WHERE sub_stat_hist = '5.1' ), -t8 as (select count(distinct rdi.id) as introduced_measures from restriction_document_item rdi -join restriction_document on restriction_document.id = rdi.restriction_document_create_id -join subpoena on subpoena.id = restriction_document.subpoena_id -join subpoena_reason on subpoena_reason.id = subpoena.reason_id -where rdi.restriction_document_cancel_id is null and rdi.applied_date is not null and subpoena_reason.type = '1' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +t6 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_ap_not_required + FROM last_status + WHERE sub_stat_hist IN ('3.8', '5.2') ), -t9 as (select count(distinct subpoena.id) as paper FROM subpoena -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -join subpoena_send_info on subpoena_send_info.subpoena_id = subpoena.id -where subpoena_reason.type = '1' and subpoena_send_info.delivery_code = '14' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +t7 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_restrictions_applied + FROM last_status + WHERE restr_dc IS NULL ), -t10 as (select count(distinct subpoena.id) as electron FROM subpoena -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -join subpoena_send_info on subpoena_send_info.subpoena_id = subpoena.id -where subpoena_reason.type = '1' and subpoena_send_info.delivery_code = '7' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +t8 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_introduced_measures + FROM last_status + WHERE restr_dc IS NULL AND ap_date IS NOT NULL +), +t9 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_paper + FROM last_status + WHERE d_code = '14' +), +t10 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_electron + FROM last_status + WHERE d_code = '7' +), +t11 AS ( + SELECT COUNT(DISTINCT rdi_id) AS count_restrictions + FROM last_status ) -select t1.subpoena, t2.average_appeared, t3.appeared, t4.not_appeared, t5.not_ap_good_reason, t6.ap_not_required, t7.restrictions_applied, t8.introduced_measures, t9.paper, t10.electron, '${REG_ID}' as recruitment_id, 1 as org, 0 as mil_reg, -0 as appeared_percent, 0 as not_appeared_percent, 0 as not_ap_good_reason_percent, 0 as ap_not_required_percent, 0 as electron_percent, 0 as paper_percent, 0 as restrictions_applied_percent, 0 as introduced_measures_percent -from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 full outer join t4 on 1 = 1 full outer join t5 on 1 = 1 full outer join t6 on 1 = 1 full outer join t7 on 1 = 1 full outer join t8 on 1 = 1 full outer join t9 on 1 = 1 full outer join t10 on 1 = 1 - +SELECT + COALESCE(t1.count_subpoena, 0) AS count_subpoena, + COALESCE(t2.average_appeared, 0) AS average_appeared, + COALESCE(t3.count_appeared, 0) AS count_appeared, + COALESCE(t4.count_not_appeared, 0) AS count_not_appeared, + COALESCE(t5.count_not_ap_good_reason, 0) AS count_not_ap_good_reason, + COALESCE(t6.count_ap_not_required, 0) AS count_ap_not_required, + COALESCE(t7.count_restrictions_applied, 0) AS count_restrictions_applied, + COALESCE(t8.count_introduced_measures, 0) AS count_introduced_measures, + COALESCE(t9.count_paper, 0) AS count_paper, + COALESCE(t10.count_electron, 0) AS count_electron, + COALESCE(t11.count_restrictions, 0) AS count_restrictions, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 + ELSE ROUND(COALESCE(t3.count_appeared, 0) * 100.0 / NULLIF(t1.count_subpoena, 0), 2) + END AS appeared_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 + ELSE ROUND(COALESCE(t4.count_not_appeared, 0) * 100.0 / NULLIF(t1.count_subpoena, 0), 2) + END AS not_appeared_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 + ELSE ROUND(COALESCE(t5.count_not_ap_good_reason, 0) * 100.0 / NULLIF(t1.count_subpoena, 0), 2) + END AS not_ap_good_reason_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 + ELSE ROUND(COALESCE(t6.count_ap_not_required, 0) * 100.0 / NULLIF(t1.count_subpoena, 0), 2) + END AS ap_not_required_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 + ELSE ROUND(COALESCE(t10.count_electron, 0) * 100.0 / NULLIF(t1.count_subpoena, 0), 2) + END AS electron_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 + ELSE ROUND(COALESCE(t9.count_paper, 0) * 100.0 / NULLIF(t1.count_subpoena, 0), 2) + END AS paper_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 + ELSE ROUND(COALESCE(t7.count_restrictions_applied, 0) * 100.0 / NULLIF(t1.count_subpoena, 0), 2) + END AS restrictions_applied_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 + ELSE ROUND(COALESCE(t8.count_introduced_measures, 0) * 100.0 / NULLIF(t1.count_subpoena, 0), 2) + END AS introduced_measures_percent, + '${REG_ID}' AS recruitment_id, + 1 AS org, + 0 AS mil_reg +FROM t1 +FULL OUTER JOIN t2 ON 1 = 1 +FULL OUTER JOIN t3 ON 1 = 1 +FULL OUTER JOIN t4 ON 1 = 1 +FULL OUTER JOIN t5 ON 1 = 1 +FULL OUTER JOIN t6 ON 1 = 1 +FULL OUTER JOIN t7 ON 1 = 1 +FULL OUTER JOIN t8 ON 1 = 1 +FULL OUTER JOIN t9 ON 1 = 1 +FULL OUTER JOIN t10 ON 1 = 1 +FULL OUTER JOIN t11 ON 1 = 1; 0 N @@ -1251,124 +1273,147 @@ from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 full outer join postgres.subpoena - with -t1 as (select count(distinct subpoena.id) as subpoena FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type !='1' and sub_stat_hist.code ='3' - AND ( + WITH subpoena_data AS ( + SELECT + s.id AS subpoena_id, + s.status_id, + sr.type, + ssh.code AS sub_stat_hist, + s.send_date, + sh.date_time::timestamp AS history_date, + rdi.restriction_document_cancel_id AS restr_dc, + rdi.applied_date AS ap_date, + rdi.id AS rdi_id, + ssi.delivery_code AS d_code, + ROW_NUMBER() OVER (PARTITION BY s.id ORDER BY sh.date_time DESC) AS rn + FROM subpoena s + JOIN subpoena_history AS sh ON sh.subpoena_id = s.id + JOIN subpoena_status AS ss ON ss.id = s.status_id + JOIN subpoena_status AS ssh ON ssh.id = sh.status_id + JOIN subpoena_reason AS sr ON sr.id = s.reason_id + LEFT JOIN restriction_document AS rd ON rd.subpoena_id = s.id + LEFT JOIN restriction_document_item AS rdi ON rdi.restriction_document_create_id = rd.id + LEFT JOIN subpoena_send_info AS ssi ON ssi.subpoena_id = s.id + WHERE sr.type != '1' + AND ( '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) + OR '${VK_ARRAY}' = '' + OR s.department_id = ANY ( + string_to_array( + trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ',' + )::uuid[] + ) ) ), -t2 as (select round(avg(extract(day from subpoena_history.date_time::timestamp - (subpoena.send_date::timestamptz AT time zone 'UTC')::timestamp)), 1) as average_appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where subpoena_reason.type != '1' and (sub_stat_hist.code = '4.1' or sub_stat_hist.code = '4.2') - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +last_status AS ( + SELECT * + FROM subpoena_data + WHERE rn = 1 ), -t3 as (select count(distinct subpoena.id) as appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type !='1' and sub_stat_hist.code in ('4.1','4.2') - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +t1 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_subpoena + FROM last_status + WHERE sub_stat_hist IS NOT NULL ), -t4 as (select count(distinct subpoena.id) as not_appeared FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type !='1' and sub_stat_hist.code ='5' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +t2 AS ( + SELECT ROUND(AVG(EXTRACT(DAY FROM (history_date::timestamp - send_date::timestamp))), 1) AS average_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' ), -t5 as (select count(*) as not_ap_good_reason FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type !='1' and sub_stat_hist.code='5.1' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +t3 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_appeared + FROM last_status + WHERE sub_stat_hist = '4.1' OR sub_stat_hist = '4.2' ), -t6 as (select count(distinct subpoena.id) as ap_not_required FROM subpoena -JOIN subpoena_history ON subpoena_history.subpoena_id = subpoena.id -JOIN subpoena_status AS sub_status ON sub_status.id = subpoena.status_id -JOIN subpoena_status AS sub_stat_hist ON sub_stat_hist.id = subpoena_history.status_id -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -where not subpoena_reason.type !='1' and sub_stat_hist.code in ('3.8','5.2') - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +t4 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_appeared + FROM last_status + WHERE sub_stat_hist = '5' ), -t7 as (select count(distinct rdi.id) as restrictions_applied from restriction_document_item rdi -join restriction_document on restriction_document.id = rdi.restriction_document_create_id -join subpoena on subpoena.id = restriction_document.subpoena_id -join subpoena_reason on subpoena_reason.id = subpoena.reason_id -where rdi.restriction_document_cancel_id is null and subpoena_reason.type != '1' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +t5 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_not_ap_good_reason + FROM last_status + WHERE sub_stat_hist = '5.1' ), -t8 as (select count(distinct rdi.id) as introduced_measures from restriction_document_item rdi -join restriction_document on restriction_document.id = rdi.restriction_document_create_id -join subpoena on subpoena.id = restriction_document.subpoena_id -join subpoena_reason on subpoena_reason.id = subpoena.reason_id -where rdi.restriction_document_cancel_id is null and rdi.applied_date is not null and subpoena_reason.type != '1' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +t6 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_ap_not_required + FROM last_status + WHERE sub_stat_hist IN ('3.8', '5.2') ), -t9 as (select count(distinct subpoena.id) as paper FROM subpoena -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -join subpoena_send_info on subpoena_send_info.subpoena_id = subpoena.id -where subpoena_reason.type != '1' and subpoena_send_info.delivery_code = '14' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +t7 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_restrictions_applied + FROM last_status + WHERE restr_dc IS NULL ), -t10 as (select count(distinct subpoena.id) as electron FROM subpoena -JOIN subpoena_reason ON subpoena_reason.id = subpoena.reason_id -join subpoena_send_info on subpoena_send_info.subpoena_id = subpoena.id -where subpoena_reason.type != '1' and subpoena_send_info.delivery_code = '7' - AND ( - '${VK_ARRAY}' IS NULL - OR '${VK_ARRAY}' = '{}' - OR subpoena.department_id = ANY (string_to_array(NULLIF('${VK_ARRAY}', ''), ',')::uuid[]) - ) +t8 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_introduced_measures + FROM last_status + WHERE restr_dc IS NULL AND ap_date IS NOT NULL +), +t9 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_paper + FROM last_status + WHERE d_code = '14' +), +t10 AS ( + SELECT COUNT(DISTINCT subpoena_id) AS count_electron + FROM last_status + WHERE d_code = '7' +), +t11 AS ( + SELECT COUNT(DISTINCT rdi_id) AS count_restrictions + FROM last_status ) -select t1.subpoena, t2.average_appeared, t3.appeared, t4.not_appeared, t5.not_ap_good_reason, t6.ap_not_required, t7.restrictions_applied, t8.introduced_measures, t9.paper, t10.electron, '${REG_ID}' as recruitment_id, 1 as org, 1 as mil_reg, -0 as appeared_percent, 0 as not_appeared_percent, 0 as not_ap_good_reason_percent, 0 as ap_not_required_percent, 0 as electron_percent, 0 as paper_percent, 0 as restrictions_applied_percent, 0 as introduced_measures_percent -from t1 full outer join t2 on 1 = 1 full outer join t3 on 1 = 1 full outer join t4 on 1 = 1 full outer join t5 on 1 = 1 full outer join t6 on 1 = 1 full outer join t7 on 1 = 1 full outer join t8 on 1 = 1 full outer join t9 on 1 = 1 full outer join t10 on 1 = 1 +SELECT + COALESCE(t1.count_subpoena, 0) AS count_subpoena, + COALESCE(t2.average_appeared, 0) AS average_appeared, + COALESCE(t3.count_appeared, 0) AS count_appeared, + COALESCE(t4.count_not_appeared, 0) AS count_not_appeared, + COALESCE(t5.count_not_ap_good_reason, 0) AS count_not_ap_good_reason, + COALESCE(t6.count_ap_not_required, 0) AS count_ap_not_required, + COALESCE(t7.count_restrictions_applied, 0) AS count_restrictions_applied, + COALESCE(t8.count_introduced_measures, 0) AS count_introduced_measures, + COALESCE(t9.count_paper, 0) AS count_paper, + COALESCE(t10.count_electron, 0) AS count_electron, + COALESCE(t11.count_restrictions, 0) AS count_restrictions, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 + ELSE ROUND(COALESCE(t3.count_appeared, 0) * 100.0 / NULLIF(t1.count_subpoena, 0), 2) + END AS appeared_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 + ELSE ROUND(COALESCE(t4.count_not_appeared, 0) * 100.0 / NULLIF(t1.count_subpoena, 0), 2) + END AS not_appeared_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 + ELSE ROUND(COALESCE(t5.count_not_ap_good_reason, 0) * 100.0 / NULLIF(t1.count_subpoena, 0), 2) + END AS not_ap_good_reason_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 + ELSE ROUND(COALESCE(t6.count_ap_not_required, 0) * 100.0 / NULLIF(t1.count_subpoena, 0), 2) + END AS ap_not_required_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 + ELSE ROUND(COALESCE(t10.count_electron, 0) * 100.0 / NULLIF(t1.count_subpoena, 0), 2) + END AS electron_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 + ELSE ROUND(COALESCE(t9.count_paper, 0) * 100.0 / NULLIF(t1.count_subpoena, 0), 2) + END AS paper_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 + ELSE ROUND(COALESCE(t7.count_restrictions_applied, 0) * 100.0 / NULLIF(t1.count_subpoena, 0), 2) + END AS restrictions_applied_percent, + CASE WHEN COALESCE(t1.count_subpoena, 0) = 0 THEN 0 + ELSE ROUND(COALESCE(t8.count_introduced_measures, 0) * 100.0 / NULLIF(t1.count_subpoena, 0), 2) + END AS introduced_measures_percent, + '${REG_ID}' AS recruitment_id, + 1 AS org, + 1 AS mil_reg +FROM t1 +FULL OUTER JOIN t2 ON 1 = 1 +FULL OUTER JOIN t3 ON 1 = 1 +FULL OUTER JOIN t4 ON 1 = 1 +FULL OUTER JOIN t5 ON 1 = 1 +FULL OUTER JOIN t6 ON 1 = 1 +FULL OUTER JOIN t7 ON 1 = 1 +FULL OUTER JOIN t8 ON 1 = 1 +FULL OUTER JOIN t9 ON 1 = 1 +FULL OUTER JOIN t10 ON 1 = 1 +FULL OUTER JOIN t11 ON 1 = 1; 0 N