подлежащие постановке для main_dashboard.waiting_registration, total_registered.age, total_registered.busyness; дополнены условия для критерий мобилизации, срочной службы, службы по контракту

This commit is contained in:
Ruslan 2025-03-10 16:07:17 +03:00
parent 44524126eb
commit bfc88c81c6
5 changed files with 57 additions and 30 deletions

View file

@ -252,9 +252,9 @@ registered as (
rh.id as recruit_history_id
from recruits_history rh
join last_status ls on rh.recruit_id=ls. recruit_id and rh.date_time=ls.max_date_time
where rh.status not in ('1', '1.3', '12', '12.1', '12.2', '12.3', '12.4', '12.5', '13')
where rh.status not in ('1', '1.3', '12', '12.1', '12.2', '12.3', '12.4', '12.5', '13') -- критерии от 03.06.2025
--and rh.source is not null
) ,
),
vse AS (
SELECT
distinct
@ -268,6 +268,16 @@ vse AS (
r.gender,
r.birth_date,
r.conscription,
CASE
WHEN jsonb_typeof(ri.info->'svedFL'->'svedPND'->'svedUchetDisp'->'svedUchet') = 'array' THEN
EXISTS (
SELECT 1
FROM jsonb_array_elements(ri.info->'svedFL'->'svedPND'->'svedUchetDisp'->'svedUchet') AS uchet_pnd
WHERE uchet_pnd->>'dataSnyatUchet' <= current_date::text
)
ELSE
false
END AS uchet_pnd,
ri.info
FROM public.recruits AS r
JOIN public.recruits_info AS ri
@ -309,22 +319,25 @@ recruit_data AS (
COUNT(*) FILTER (WHERE gender = 'MALE') AS male_count,
COUNT(*) FILTER (WHERE gender = 'FEMALE') AS female_count,
COUNT(*) FILTER (
WHERE (EXTRACT(YEAR FROM AGE(NOW(), birth_date)) BETWEEN 18 AND 70 AND gender = 'MALE')
OR (EXTRACT(YEAR FROM AGE(NOW(), birth_date)) BETWEEN 18 AND 45 AND gender = 'FEMALE')
AND (conscription IS NULL OR conscription = false)
WHERE (EXTRACT(YEAR FROM AGE(NOW(), birth_date)) BETWEEN 30 AND 50 AND gender = 'MALE') -- мужчины от 30 до 50 лет
OR (EXTRACT(YEAR FROM AGE(NOW(), birth_date)) BETWEEN 30 AND 45 AND gender = 'FEMALE') -- женщины от 30 до 45 лет
AND COALESCE(cc.children_under_16, 0) < 5
) AS mobilization_criterion,
) AS mobilization_criterion, -- критерии от 03.06.2025
COUNT(*) FILTER (
WHERE EXTRACT(YEAR FROM AGE(NOW(), birth_date)) BETWEEN 18 AND 30
AND gender = 'MALE'
AND (conscription IS NULL OR conscription = false)
) AS volunteer_criterion,
AND (conscription IS NULL OR conscription = false) -- нет отсрочки и нет освобождения от службы
) AS volunteer_criterion, -- критерии от 03.06.2025
COUNT(*) FILTER (
WHERE EXTRACT(YEAR FROM AGE(NOW(), birth_date)) BETWEEN 18 AND 50
AND gender = 'MALE'
AND (conscription IS NULL OR conscription = false)
AND ri.info->'svedSudim'->>'prOtsSvedSudim' = '1'
) AS contract_criterion
AND (ri.info->'svedFL'->'svedPND'->>'prOtsSvedPND' = '1'
OR uchet_pnd is false)
AND ri.info->'svedFL'->'svedUchetVICH'->>'prOtsSvedUchetVICH' = '1' -- признак отсутствия сведений о заболевании ВИЧ
--AND ri.info->'svedSudim'->>'prOtsSvedSudim' = '1'
) AS contract_criterion -- критерии от 03.06.2025
FROM vse AS ri
LEFT JOIN children_count AS cc ON ri.recruit_id = cc.recruit_id
GROUP BY ri.r_current_recruitment_id, ri.convicts

View file

@ -268,6 +268,16 @@ vse AS (
r.gender,
r.birth_date,
r.conscription,
CASE
WHEN jsonb_typeof(ri.info->'svedFL'->'svedPND'->'svedUchetDisp'->'svedUchet') = 'array' THEN
EXISTS (
SELECT 1
FROM jsonb_array_elements(ri.info->'svedFL'->'svedPND'->'svedUchetDisp'->'svedUchet') AS uchet_pnd
WHERE uchet_pnd->>'dataSnyatUchet' <= current_date::text
)
ELSE
false
END AS uchet_pnd,
ri.info
FROM public.recruits AS r
JOIN public.recruits_info AS ri
@ -309,22 +319,25 @@ recruit_data AS (
COUNT(*) FILTER (WHERE gender = 'MALE') AS male_count,
COUNT(*) FILTER (WHERE gender = 'FEMALE') AS female_count,
COUNT(*) FILTER (
WHERE (EXTRACT(YEAR FROM AGE(NOW(), birth_date)) BETWEEN 18 AND 70 AND gender = 'MALE')
OR (EXTRACT(YEAR FROM AGE(NOW(), birth_date)) BETWEEN 18 AND 45 AND gender = 'FEMALE')
AND (conscription IS NULL OR conscription = false)
AND COALESCE(cc.children_under_16, 0) < 5
) AS mobilization_criterion,
WHERE (EXTRACT(YEAR FROM AGE(NOW(), birth_date)) BETWEEN 30 AND 50 AND gender = 'MALE') -- мужчины от 30 до 50 лет
OR (EXTRACT(YEAR FROM AGE(NOW(), birth_date)) BETWEEN 30 AND 45 AND gender = 'FEMALE') -- женщины от 30 до 45 лет
AND COALESCE(cc.children_under_16, 0) < 5
) AS mobilization_criterion, -- критерии от 03.06.2025
COUNT(*) FILTER (
WHERE EXTRACT(YEAR FROM AGE(NOW(), birth_date)) BETWEEN 18 AND 30
AND gender = 'MALE'
AND (conscription IS NULL OR conscription = false)
) AS volunteer_criterion,
AND (conscription IS NULL OR conscription = false) -- нет отсрочки и нет освобождения от службы
) AS volunteer_criterion, -- критерии от 03.06.2025
COUNT(*) FILTER (
WHERE EXTRACT(YEAR FROM AGE(NOW(), birth_date)) BETWEEN 18 AND 50
AND gender = 'MALE'
AND (conscription IS NULL OR conscription = false)
AND ri.info->'svedSudim'->>'prOtsSvedSudim' = '1'
) AS contract_criterion
AND (ri.info->'svedFL'->'svedPND'->>'prOtsSvedPND' = '1'
OR uchet_pnd is false)
AND ri.info->'svedFL'->'svedUchetVICH'->>'prOtsSvedUchetVICH' = '1' -- признак отсутствия сведений о заболевании ВИЧ
--AND ri.info->'svedSudim'->>'prOtsSvedSudim' = '1'
) AS contract_criterion -- критерии от 03.06.2025
FROM vse AS ri
LEFT JOIN children_count AS cc ON ri.recruit_id = cc.recruit_id
GROUP BY ri.r_target_recruitment_id

View file

@ -318,9 +318,9 @@ registered as (
--and rh.source is not null
),
last_status_n as (select recruit_id,
max(date_time) filter (where status in ('1', '1.1', '12.2', '12.10')) max_date_time
max(date_time) filter (where status in ('1', '12.7', '8.2', '8.3')) max_date_time
from recruits_history
where status in ('1', '1.1', '12.2', '12.10')
where status in ('1', '12.7', '8.2', '8.3')
group by recruit_id
),
notregistered as (
@ -329,7 +329,7 @@ notregistered as (
rh.id as recruit_history_id
from recruits_history rh
join last_status_n ls on rh.recruit_id=ls. recruit_id and rh.date_time=ls.max_date_time
where rh.status in ('1', '1.1', '12.2', '12.10')
where rh.status in ('1', '12.7', '8.2', '8.3')
--and rh.source is not null
),
recruit_data AS (
@ -373,6 +373,7 @@ recruit_data AS (
r.id in (SELECT recruit_id FROM notregistered) and
rh.id in (SELECT recruit_history_id FROM notregistered)
and coalesce(r.target_recruitment_id,rh.target_recruitment_id) ::uuid IN (SELECT recruitment_id FROM ids)
AND r.current_recruitment_id is null
),
total_count AS (
SELECT

View file

@ -268,9 +268,9 @@ registered as (
--and rh.source is not null
),
last_status_n as (select recruit_id,
max(date_time) filter (where status in ('1', '1.1', '12.2', '12.10')) max_date_time
max(date_time) filter (where status in ('1', '12.7', '8.2', '8.3')) max_date_time
from recruits_history
where status in ('1', '1.1', '12.2', '12.10')
where status in ('1', '12.7', '8.2', '8.3')
group by recruit_id
),
notregistered as (
@ -279,7 +279,7 @@ notregistered as (
rh.id as recruit_history_id
from recruits_history rh
join last_status_n ls on rh.recruit_id=ls. recruit_id and rh.date_time=ls.max_date_time
where rh.status in ('1', '1.1', '12.2', '12.10')
where rh.status in ('1', '12.7', '8.2', '8.3')
--and rh.source is not null
),
status_info AS (
@ -412,6 +412,7 @@ status_info AS (
AND rh.id in (SELECT recruit_history_id FROM notregistered)
--and r.vu_current_info->>'recruitmentCommercialInfo' = 'true'
AND coalesce(r.target_recruitment_id,rh.target_recruitment_id) ::uuid IN (SELECT recruitment_id FROM ids)
AND r.current_recruitment_id is null
),
summary AS (
SELECT

View file

@ -80,7 +80,6 @@
<condition>=</condition>
<field>id_region</field>
<name>REG_ID</name>
<name2/>
</key>
<schema>ratings</schema>
<table>appear_subppoena</table>
@ -177,9 +176,9 @@ total AS (
)
SELECT
'${REG_ID}' AS region_id,
COUNT(*) FILTER (WHERE tt.code IN ('4.1', '4.2', '4')) AS appear_mil_com,
COUNT(*) FILTER (WHERE tt.code IN ('4.1', '4.2')) AS appear_mil_com,
ROUND(
COUNT(*) FILTER (WHERE tt.code IN ('4.1', '4.2', '4'))::NUMERIC / NULLIF(COUNT(*), 0) * 100, 2
COUNT(*) FILTER (WHERE tt.code IN ('4.1', '4.2'))::NUMERIC / NULLIF(COUNT(*), 0) * 100, 2
) AS appear_mil_com_percent
FROM total tt;</sql>
<variables_active>Y</variables_active>