<?xml version="1.0" encoding="UTF-8"?>
<pipeline>
  <info>
    <name>update_appeal_recruitments</name>
    <name_sync_with_filename>Y</name_sync_with_filename>
    <description/>
    <extended_description/>
    <pipeline_version/>
    <pipeline_type>Normal</pipeline_type>
    <parameters>
    </parameters>
    <capture_transform_performance>N</capture_transform_performance>
    <transform_performance_capturing_delay>1000</transform_performance_capturing_delay>
    <transform_performance_capturing_size_limit>100</transform_performance_capturing_size_limit>
    <created_user>-</created_user>
    <created_date>2025/01/27 13:36:22.747</created_date>
    <modified_user>-</modified_user>
    <modified_date>2025/01/27 13:36:22.747</modified_date>
  </info>
  <notepads>
  </notepads>
  <order>
    <hop>
      <from>Table input</from>
      <to>Insert / update</to>
      <enabled>Y</enabled>
    </hop>
  </order>
  <transform>
    <name>Insert / update</name>
    <type>InsertUpdate</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <commit>100</commit>
    <connection>ervu-dashboard</connection>
    <lookup>
      <key>
        <condition>=</condition>
        <field>region</field>
        <name>region</name>
      </key>
      <schema>appeals</schema>
      <table>appeals_list</table>
      <value>
        <name>region</name>
        <rename>region</rename>
        <update>N</update>
      </value>
      <value>
        <name>region_id</name>
        <rename>idm_id</rename>
        <update>Y</update>
      </value>
    </lookup>
    <update_bypassed>N</update_bypassed>
    <attributes/>
    <GUI>
      <xloc>784</xloc>
      <yloc>144</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Table input</name>
    <type>TableInput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <connection>ervu-dashboard</connection>
    <execute_each_row>N</execute_each_row>
    <limit>0</limit>
    <sql>WITH ranked_recruitment AS (
    SELECT 
        rt.idm_id,
        rt.shortname,
        al.region,
        row_number() OVER (PARTITION BY al.region ORDER BY rt.shortname) AS rn
    FROM 
        appeals.appeals_list al
    JOIN 
       ervu_dashboard.recruitment rt
    ON 
   (al.region ILIKE '%Адыге%' AND rt.shortname ILIKE '%Адыге%')
OR (al.region ILIKE '%Республик%Башк%р%' AND rt.shortname ILIKE '%Республик%Башк%р%')
OR (al.region ILIKE '%Республик%Бурят%' AND rt.shortname ILIKE '%Республик%Бурят%')
OR (al.region ILIKE '%Республик%Алтай%' AND rt.shortname ILIKE '%Республик%Алтай%')
OR (al.region ILIKE '%Дагест%' AND rt.shortname ILIKE '%Дагест%')
OR (al.region ILIKE '%Ингушет%' AND rt.shortname ILIKE '%Ингушет%')
OR (al.region ILIKE '%Кабардино-Балкар%' AND rt.shortname ILIKE '%Кабардино-Балкар%')
OR (al.region ILIKE '%Республик%Калмыки%' AND rt.shortname ILIKE '%Республик%Калмыки%')
OR (al.region ILIKE '%Карачаево-Черкесс%Республик%' AND rt.shortname ILIKE '%Карачаево-Черкесс%Республик%')
OR (al.region ILIKE '%Карел%' AND rt.shortname ILIKE '%Карел%')
OR (al.region ILIKE '%Коми%' AND rt.shortname ILIKE '%Коми%')
OR (al.region ILIKE '%Марий%Эл%' AND rt.shortname ILIKE '%Марий%Эл%')
OR (al.region ILIKE '%Мордови%' AND rt.shortname ILIKE '%Мордови%')
OR (al.region ILIKE '%Саха%(Якутия)%' AND rt.shortname ILIKE '%Саха%(Якутия)%')
OR (al.region ILIKE '%Северн%Осети%Алан%' AND rt.shortname ILIKE '%Северн%Осети%Алан%')
OR (al.region ILIKE '%Татарстан%' AND rt.shortname ILIKE '%Татарстан%')
OR (al.region ILIKE '%Тыва%' AND rt.shortname ILIKE '%Тыва%')
OR (al.region ILIKE '%Удмуртск%' AND rt.shortname ILIKE '%Удмуртск%')
OR (al.region ILIKE '%Хакас%' AND rt.shortname ILIKE '%Хакас%')
OR (al.region ILIKE '%Чеченск%' AND rt.shortname ILIKE '%Чеченск%')
OR (al.region ILIKE '%Чуваш%' AND rt.shortname ILIKE '%Чуваш%')
OR (al.region ILIKE '%Алтайск%кра%' AND rt.shortname ILIKE '%Алтайск%кра%')
OR (al.region ILIKE '%Краснодарск%' AND rt.shortname ILIKE '%Краснодарск%')
OR (al.region ILIKE '%Красноярск%' AND rt.shortname ILIKE '%Красноярск%')
OR (al.region ILIKE '%Приморск%' AND rt.shortname ILIKE '%Приморск%')
OR (al.region ILIKE '%Ставропольск%' AND rt.shortname ILIKE '%Ставропольск%')
OR (al.region ILIKE '%Хабаровск%' AND rt.shortname ILIKE '%Хабаровск%')
OR (al.region ILIKE '%Амурск%' AND rt.shortname ILIKE '%Амурск%')
OR (al.region ILIKE '%Архангельск%' AND rt.shortname ILIKE '%Архангельск%')
OR (al.region ILIKE '%Астраханск%' AND rt.shortname ILIKE '%Астраханск%')
OR (al.region ILIKE '%Белгородск%' AND rt.shortname ILIKE '%Белгородск%')
OR (al.region ILIKE '%Брянск%' AND rt.shortname ILIKE '%Брянск%')
OR (al.region ILIKE '%Владимирск%' AND rt.shortname ILIKE '%Владимирск%')
OR (al.region ILIKE '%Волгоградск%' AND rt.shortname ILIKE '%Волгоградск%')
OR (al.region ILIKE '%Вологодск%' AND rt.shortname ILIKE '%Вологодск%')
OR (al.region ILIKE '%Воронежск%' AND rt.shortname ILIKE '%Воронежск%')
OR (al.region ILIKE '%Ивановск%' AND rt.shortname ILIKE '%Ивановск%')
OR (al.region ILIKE '%Иркутск%' AND rt.shortname ILIKE '%Иркутск%')
OR (al.region ILIKE '%Калининградск%' AND rt.shortname ILIKE '%Калининградск%')
OR (al.region ILIKE '%Калужск%' AND rt.shortname ILIKE '%Калужск%')
OR (al.region ILIKE '%Камчатск%' AND rt.shortname ILIKE '%Камчатск%')
OR (al.region ILIKE '%Кемеровск%' AND rt.shortname ILIKE '%Кемеровск%')
OR (al.region ILIKE '%Кировск%' AND rt.shortname ILIKE '%Кировск%')
OR (al.region ILIKE '%Костромск%' AND rt.shortname ILIKE '%Костромск%')
OR (al.region ILIKE '%Курганск%' AND rt.shortname ILIKE '%Курганск%')
OR (al.region ILIKE '%Курск%' AND rt.shortname ILIKE '%Курск%')
OR (al.region ILIKE '%Ленинградск%' AND rt.shortname ILIKE '%Ленинградск%')
OR (al.region ILIKE '%Липецк%' AND rt.shortname ILIKE '%Липецк%')
OR (al.region ILIKE '%Магаданск%' AND rt.shortname ILIKE '%Магаданск%')
OR (al.region ILIKE '%Московск%' AND rt.shortname ILIKE '%Московск%')
OR (al.region ILIKE '%Мурманск%' AND rt.shortname ILIKE '%Мурманск%')
OR (al.region ILIKE '%Нижегородск%' AND rt.shortname ILIKE '%Нижегородск%')
OR (al.region ILIKE '%Новгородск%' AND rt.shortname ILIKE '%Новгородск%')
OR (al.region ILIKE '%Новосибирск%' AND rt.shortname ILIKE '%Новосибирск%')
OR (al.region ILIKE '%Омск%обл%' AND rt.shortname ILIKE 'ВК Омск%обл%' and rt.shortname NOT ILIKE '%Костромс%' and rt.shortname NOT ILIKE 'Военный комиссариат Томск%')
OR (al.region ILIKE '%Оренбургск%' AND rt.shortname ILIKE '%Оренбургск%')
OR (al.region ILIKE '%Орловск%' AND rt.shortname ILIKE '%Орловск%')
OR (al.region ILIKE '%Пензенск%' AND rt.shortname ILIKE '%Пензенск%')
OR (al.region ILIKE '%Пермск$' AND rt.shortname ILIKE '%Пермск$')
OR (al.region ILIKE '%Псковск%' AND rt.shortname ILIKE '%Псковск%')
OR (al.region ILIKE '%Ростовск%' AND rt.shortname ILIKE '%Ростовск%')
OR (al.region ILIKE '%Рязанск%' AND rt.shortname ILIKE '%Рязанск%')
OR (al.region ILIKE '%Самарск%' AND rt.shortname ILIKE '%Самарск%')
OR (al.region ILIKE '%Саратовск%' AND rt.shortname ILIKE '%Саратовск%')
OR (al.region ILIKE '%Сахалинск%' AND rt.shortname ILIKE '%Сахалинск%')
OR (al.region ILIKE '%Свердловск%' AND rt.shortname ILIKE '%Свердловск%')
OR (al.region ILIKE '%Смоленск%' AND rt.shortname ILIKE '%Смоленск%')
OR (al.region ILIKE '%Тамбовск%' AND rt.shortname ILIKE '%Тамбовск%')
OR (al.region ILIKE '%Тверск%' AND rt.shortname ILIKE '%Тверск%')
OR (al.region ILIKE '%Томск%обл%' AND rt.shortname ILIKE 'Военный комиссариат Томской обл%' and rt.shortname NOT ILIKE '%Костромс%' and rt.shortname NOT ILIKE 'Военный комиссариат Омск%')
OR (al.region ILIKE '%Тульск%' AND rt.shortname ILIKE '%Тульск%')
OR (al.region ILIKE '%Тюменск%' AND rt.shortname ILIKE '%Тюменск%')
OR (al.region ILIKE '%Ульяновск%' AND rt.shortname ILIKE '%Ульяновск%')
OR (al.region ILIKE '%Челябинск%' AND rt.shortname ILIKE '%Челябинск%')
OR (al.region ILIKE '%Забайкальск%' AND rt.shortname ILIKE '%Забайкальск%')
OR (al.region ILIKE '%Ярославск%' AND rt.shortname ILIKE '%Ярославск%')
OR (al.region ILIKE '%г%Москв%' AND rt.shortname ILIKE '%г%Москв%')
OR (al.region ILIKE '%г%Санкт-Петербург%' AND rt.shortname ILIKE '%г%Санкт-Петербург%')
OR (al.region ILIKE '%Еврейск%автономн%' AND rt.shortname ILIKE '%Еврейск%автономн%')
OR (al.region ILIKE '%Ненецк%автономн%' AND rt.shortname ILIKE '%Ненецк%автономн%')
OR (al.region ILIKE '%Хант%Мансийск%' AND rt.shortname ILIKE '%Хант%Мансийск%')
OR (al.region ILIKE '%Чукотск%автономн%' AND rt.shortname ILIKE '%Чукотск%автономн%')
OR (al.region ILIKE '%Ямал%Ненецк%автономн%' AND rt.shortname ILIKE '%Ямал%Ненецк%автономн%')
OR (al.region ILIKE '%Крым%' AND rt.shortname ILIKE '%Крым%')
OR (al.region ILIKE '%г%Севастопол%' AND rt.shortname ILIKE '%г%Севастопол%')
OR (al.region ILIKE '%Запорожск%' AND rt.shortname ILIKE '%Запорожск%')
OR (al.region ILIKE '%Донецк%Народн%' AND rt.shortname ILIKE '%Донецк%Народн%')
OR (al.region ILIKE '%Луганск%Народн%' AND rt.shortname ILIKE '%Луганск%Народн%')
OR (al.region ILIKE '%Херсонск%' AND rt.shortname ILIKE '%Херсонск%')           
WHERE 
        rt.schema = 'Organization'
)
SELECT DISTINCT
    idm_id,
    shortname,
    region
FROM ranked_recruitment rrt
where
(rrt.region ILIKE '%Адыге%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Республик%Башк%р%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Республик%Бурят%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Республик%Алтай' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Дагест%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Ингушет%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Кабардино-Балкар%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Республик%Калмыки%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Карачаево-Черкесс%Республик%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Карел%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Коми%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Марий%Эл%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Мордови%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Саха%(Якутия)%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Северн%Осети%Алан%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Татарстан%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Тыва%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Удмуртск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Хакас%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Чеченск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Чуваш%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Алтайск%кра%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Краснодарск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Красноярск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Приморск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Ставропольск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Хабаровск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Амурск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Архангельск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Астраханск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Белгородск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Брянск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Владимирск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Волгоградск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Вологодск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Воронежск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Ивановск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Иркутск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Калининградск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Калужск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Камчатск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Кемеровск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Кировск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Костромск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Курганск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Курск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Ленинградск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Липецк%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Магаданск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Московск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Мурманск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Нижегородск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Новгородск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Новосибирск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Омск%обл%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Оренбургск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Орловск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Пензенск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Пермск$' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Псковск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Ростовск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Рязанск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Самарск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Саратовск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Сахалинск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Свердловск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Смоленск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Тамбовск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Тверск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Томск%обл%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Тульск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Тюменск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Ульяновск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Челябинск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Забайкальск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Ярославск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%г%Москв%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%г%Санкт-Петербург%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Еврейск%автономн%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Ненецк%автономн%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Хант%Мансийск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Чукотск%автономн%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Ямал%Ненецк%автономн%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Крым%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%г%Севастопол%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Запорожск%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Донецк%Народн%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Луганск%Народн%' AND rrt.rn = 1) OR
(rrt.region ILIKE '%Херсонск%' AND rrt.rn = 1);
</sql>
    <variables_active>N</variables_active>
    <attributes/>
    <GUI>
      <xloc>480</xloc>
      <yloc>144</yloc>
    </GUI>
  </transform>
  <transform_error_handling>
  </transform_error_handling>
  <attributes/>
</pipeline>
