<?xml version="1.0" encoding="UTF-8"?>
<pipeline>
  <info>
    <name>citizen_education_diplomas_received</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/02/14 13:03:35.892</created_date>
    <modified_user>-</modified_user>
    <modified_date>2025/02/14 13:03:35.892</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>10000</commit>
    <connection>ervu-dashboard</connection>
    <lookup>
      <key>
        <condition>=</condition>
        <field>recruit_id</field>
        <name>recruit_id</name>
        <name2/>
      </key>
      <schema>ervu_dashboard</schema>
      <table>citizen_education_diplomas_received</table>
      <value>
        <name>recruit_id</name>
        <rename>recruit_id</rename>
        <update>N</update>
      </value>
      <value>
        <name>type_organization</name>
        <rename>type_organization</rename>
        <update>Y</update>
      </value>
      <value>
        <name>name_edu_organization</name>
        <rename>name_edu_organization</rename>
        <update>Y</update>
      </value>
      <value>
        <name>inn</name>
        <rename>inn</rename>
        <update>Y</update>
      </value>
      <value>
        <name>kpp</name>
        <rename>kpp</rename>
        <update>Y</update>
      </value>
      <value>
        <name>ogrn</name>
        <rename>ogrn</rename>
        <update>Y</update>
      </value>
      <value>
        <name>address_edu_organization</name>
        <rename>address_edu_organization</rename>
        <update>Y</update>
      </value>
      <value>
        <name>student_status</name>
        <rename>student_status</rename>
        <update>Y</update>
      </value>
      <value>
        <name>education_level_org</name>
        <rename>education_level_org</rename>
        <update>Y</update>
      </value>
      <value>
        <name>course_training</name>
        <rename>course_training</rename>
        <update>Y</update>
      </value>
      <value>
        <name>receipt_date</name>
        <rename>receipt_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>order_number</name>
        <rename>order_number</rename>
        <update>Y</update>
      </value>
      <value>
        <name>order_date</name>
        <rename>order_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>restore_date</name>
        <rename>restore_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>order_number_restore</name>
        <rename>order_number_restore</rename>
        <update>Y</update>
      </value>
      <value>
        <name>order_date_restore</name>
        <rename>order_date_restore</rename>
        <update>Y</update>
      </value>
    </lookup>
    <update_bypassed>N</update_bypassed>
    <attributes/>
    <GUI>
      <xloc>928</xloc>
      <yloc>320</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_person_registry</connection>
    <execute_each_row>N</execute_each_row>
    <limit>0</limit>
    <sql>with vuz as
(select jsonb_array_elements(ri.info->'svedFL'->'svedVUZ'->'vuz') as vuz,
 		ri.recruit_id recruit_id
from public.recruits_info ri
JOIN public.recruits r ON ri.recruit_id = r.id AND r.system_update_date >= '${UP_D}'
where jsonb_typeof(ri.info->'svedFL'->'svedVUZ'->'vuz') = 'array' 
--AND r.system_update_date >= '${UP_D}'
--limit 2
)
select 
		r.id recruit_id,
		--vuz->'svedOrg'->>'kodTipOrg',
              vuz->'svedOrg'->>'naimTipOrg' as type_organization,
		vuz->'svedOrg'->>'naimOrg' as name_edu_organization,
		vuz->'svedOrg'->>'inn' as inn,
		vuz->'svedOrg'->>'kpp' as kpp,
		coalesce (vuz->'svedOrg'->>'ogrn', vuz->'svedOrg'->>'ogrnip') as ogrn,
		vuz->'svedOrg'->>'adresOrg' as address_edu_organization,

		vuz->>'naimStatus' as student_status,
		vuz->>'naimUrovObr' as education_level_org,
		vuz->>'nomerKursa' as course_training,
		to_date(vuz->>'dataZachisl', 'YYYY-MM-DD') as receipt_date,
		--vuz->>'prPervObuch' ,
		vuz->>'nomPrikazZachisl' as order_number,
		to_date(vuz->>'dataPrikazZachisl', 'YYYY-MM-DD') as order_date,
		--vuz->'svedObrProg'->>'prVUSpecz',
		--vuz->'svedObrProg'->>'dataNachObuch',
		--vuz->'svedObrProg'->>'kodFormaObuch',
		--vuz->'svedObrProg'->>'naimFormaObuch',
		--vuz->'svedObrProg'->>'planDataOkonch',
		--vuz->'svedObrProg'->'svedSpeczMinobr'->>'kodSpecz',
		--vuz->'svedObrProg'->'svedSpeczMinobr'->>'naimSpecz',
		--vuz->'svedObrProg'->'svedSpeczMinprosv'->>'kodSpecz',
		--vuz->'svedObrProg'->'svedSpeczMinprosv'->>'naimSpecz',

		to_date(vuz->'svedVosst'->>'dataVosst', 'YYYY-MM-DD') as restore_date,
		vuz->'svedVosst'->>'nomPrikazVosst' as order_number_restore,
		to_date(vuz->'svedVosst'->>'dataPrikazVosst', 'YYYY-MM-DD') as order_date_restore
from public.recruits r
join vuz on r.id = vuz.recruit_id
</sql>
    <variables_active>Y</variables_active>
    <attributes/>
    <GUI>
      <xloc>464</xloc>
      <yloc>320</yloc>
    </GUI>
  </transform>
  <transform_error_handling>
  </transform_error_handling>
  <attributes/>
</pipeline>
