<?xml version="1.0" encoding="UTF-8"?>
<pipeline>
  <info>
    <name>temporary_measure</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>2024/08/15 14:02:51.713</created_date>
    <modified_user>-</modified_user>
    <modified_date>2024/08/15 14:02:51.713</modified_date>
  </info>
  <notepads>
  </notepads>
  <order>
    <hop>
      <from>Table input</from>
      <to>Table output</to>
      <enabled>N</enabled>
    </hop>
    <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>subpoena_id</field>
        <name>subpoena_id</name>
        <name2/>
      </key>
      <schema>ervu_dashboard</schema>
      <table>temporary_measures</table>
      <value>
        <name>applied_fact</name>
        <rename>applied_fact</rename>
        <update>Y</update>
      </value>
      <value>
        <name>cancel_date</name>
        <rename>cancel_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>decision_date_cancel</name>
        <rename>decision_date_cancel</rename>
        <update>Y</update>
      </value>
      <value>
        <name>decision_date_create</name>
        <rename>decision_date_create</rename>
        <update>Y</update>
      </value>
      <value>
        <name>decision_number_cancel</name>
        <rename>decision_number_cancel</rename>
        <update>Y</update>
      </value>
      <value>
        <name>decision_number_create</name>
        <rename>decision_number_create</rename>
        <update>Y</update>
      </value>
      <value>
        <name>recruit_id</name>
        <rename>recruit_id</rename>
        <update>Y</update>
      </value>
      <value>
        <name>recruitment_id</name>
        <rename>recruitment_id</rename>
        <update>Y</update>
      </value>
      <value>
        <name>recruitment_name</name>
        <rename>recruitment_name</rename>
        <update>Y</update>
      </value>
      <value>
        <name>restriction_name</name>
        <rename>restriction_name</rename>
        <update>Y</update>
      </value>
      <value>
        <name>status_measure</name>
        <rename>status_measure</rename>
        <update>Y</update>
      </value>
      <value>
        <name>subpoena_id</name>
        <rename>subpoena_id</rename>
        <update>N</update>
      </value>
      <value>
        <name>type</name>
        <rename>type</rename>
        <update>Y</update>
      </value>
    </lookup>
    <update_bypassed>N</update_bypassed>
    <attributes/>
    <GUI>
      <xloc>480</xloc>
      <yloc>208</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>postgres.subpoena</connection>
    <execute_each_row>N</execute_each_row>
    <limit>0</limit>
    <sql>SELECT
	rd.subpoena_id,
	rd.vk_id AS recruitment_id,
	s.recruit_id,
	rds.name AS status_measure, -- статус временной меры
	rd.recruitment_name, -- наименоване ВК
	rdi.cancel_date, -- дата, с которой отменена временная мера
	rn.name AS restriction_name, -- наименование ограничения (тип временной меры)
	CASE
		WHEN rd.type='CREATE' THEN 'Применение временной меры'
		WHEN rd.type='CANCEL' THEN 'Отмена временной меры'
	END AS type, -- тип документа ограничения
	CASE
		WHEN rd.type='CREATE' THEN rd.decision_number
		ELSE NULL
	END AS decision_number_create, -- номер решения о применении временной меры
	CASE
		WHEN rd.type='CANCEL' THEN rd.decision_number
		ELSE NULL
	END AS decision_number_cancel, -- номер решения об отмене временной меры
	CASE
		WHEN rd.type='CREATE' THEN rd.decision_date
		ELSE NULL
	END AS decision_date_create, -- дата решения о применении временной меры
	CASE
		WHEN rd.type='CANCEL' THEN rd.decision_date
		ELSE NULL
	END AS decision_date_cancel, -- дата решения об отмене временной меры
	CASE
		WHEN rdi.applied_fact = 'true' THEN 'Временная мера применена'
		WHEN rdi.applied_fact = 'false' THEN 'Временная мера не применена'
		ELSE 'Нет информации'
	END AS applied_fact -- факт применения временной меры
FROM public.restriction_document AS rd
LEFT JOIN public.restriction_document_item AS rdi
	ON rdi.restriction_document_create_id = rd.id
LEFT JOIN public.restriction AS rn
	ON rn.id = rdi.restriction_id
LEFT JOIN public.restriction_document_status AS rds
	ON rds.code = rd.status
LEFT JOIN public.subpoena AS s
	ON s.id = rd.subpoena_id
WHERE s.status_change_date >= '${ST_CH_D}'</sql>
    <variables_active>Y</variables_active>
    <attributes/>
    <GUI>
      <xloc>208</xloc>
      <yloc>208</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Table output</name>
    <type>TableOutput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <commit>1000</commit>
    <connection>ervu-dashboard</connection>
    <fields>
</fields>
    <ignore_errors>N</ignore_errors>
    <only_when_have_rows>N</only_when_have_rows>
    <partitioning_daily>N</partitioning_daily>
    <partitioning_enabled>N</partitioning_enabled>
    <partitioning_monthly>Y</partitioning_monthly>
    <return_keys>N</return_keys>
    <schema>ervu_dashboard</schema>
    <specify_fields>N</specify_fields>
    <table>temporary_measures</table>
    <tablename_in_field>N</tablename_in_field>
    <tablename_in_table>Y</tablename_in_table>
    <truncate>N</truncate>
    <use_batch>Y</use_batch>
    <attributes/>
    <GUI>
      <xloc>432</xloc>
      <yloc>400</yloc>
    </GUI>
  </transform>
  <transform_error_handling>
  </transform_error_handling>
  <attributes/>
</pipeline>
