<?xml version="1.0" encoding="UTF-8"?>
<pipeline>
  <info>
    <name>citizen_criminal_liability_fz53_flow3</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/05/21 14:05:02.260</created_date>
    <modified_user>-</modified_user>
    <modified_date>2025/05/21 14:05:02.260</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>recruit_id</field>
        <name>recruit_id</name>
      </key>
      <key>
        <condition>=</condition>
        <field>created_at</field>
        <name>created_at</name>
      </key>
      <schema>ervu_dashboard</schema>
      <table>citizen_criminal_liability_fz53</table>
      <value>
        <name>recruit_id</name>
        <rename>recruit_id</rename>
        <update>N</update>
      </value>
      <value>
        <name>created_at</name>
        <rename>created_at</rename>
        <update>N</update>
      </value>
      <value>
        <name>updated_at</name>
        <rename>updated_at</rename>
        <update>Y</update>
      </value>
      <value>
        <name>case_number_before</name>
        <rename>case_number_before</rename>
        <update>Y</update>
      </value>
      <value>
        <name>date_initiation</name>
        <rename>date_initiation</rename>
        <update>Y</update>
      </value>
      <value>
        <name>body_initiated</name>
        <rename>body_initiated</rename>
        <update>Y</update>
      </value>
      <value>
        <name>case_number</name>
        <rename>case_number</rename>
        <update>Y</update>
      </value>
      <value>
        <name>sentence_date</name>
        <rename>sentence_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>court_decision</name>
        <rename>court_decision</rename>
        <update>Y</update>
      </value>
      <value>
        <name>type_punishment</name>
        <rename>type_punishment</rename>
        <update>Y</update>
      </value>
      <value>
        <name>decision_reason</name>
        <rename>decision_reason</rename>
        <update>Y</update>
      </value>
      <value>
        <name>has_criminal_liability_fz53</name>
        <rename>has_criminal_liability_fz53</rename>
        <update>Y</update>
      </value>
    </lookup>
    <update_bypassed>N</update_bypassed>
    <attributes/>
    <GUI>
      <xloc>1120</xloc>
      <yloc>384</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>SELECT
	i.recruit_id,
	i.created_at,
	i.updated_at,
	--, -- сведения о факте уголовного преследования
	i.extra_info->>'preTrialNumber' AS case_number_before, -- номер уголовного дела (досудебный)
	i.extra_info->>'createInfringementDate' AS date_initiation, -- дата возбуждения уголовного дела
	i.extra_info->>'organization' AS body_initiated, -- орган, возбудивший уголовное дело
	i.decision_number AS case_number, -- номер уголовного дела (судебный)
	i.decision_date AS sentence_date, -- дата приговора
	i.extra_info->>'court' AS court_decision, -- суд вынесший приговор
	CASE
		WHEN i.extra_info->>'punishment' = '1' THEN 'Штраф'
		WHEN i.extra_info->>'punishment' = '2' THEN 'Обязательные работы'
		WHEN i.extra_info->>'punishment' = '3' THEN 'Арест'
		WHEN i.extra_info->>'punishment' = '4' THEN 'Лишение свободы на определенный срок'
		ELSE NULL
	END AS type_punishment, -- вид наказания
	CASE 
		WHEN i.decision_reason = '1' THEN 'Уклонение от призыва на военную службу'
		WHEN i.decision_reason = '2' THEN 'Уклонение от прохождения альтернативной гражданской службы лиц, освобожденных от военной службы'
		ELSE null
	END AS decision_reason, -- Причины уголовного наказания в связи с фз53
	CASE
		WHEN i.hidden is false THEN true
		ELSE false 
	END AS has_criminal_liability_fz53
FROM public.infringement i
JOIN public.recruit r ON r.id = i.recruit_id AND '${ID_F3}' != ''  -- Проверка на пустую строку
	    AND COALESCE(r.current_recruitment, r.target_recruitment) = '${ID_F3}'
	    --AND '${INFRINGEMENT_DATE}'::timestamp &lt;= coalesce(i.updated_at, i.created_at) -- для дельты
WHERE --hidden IS FALSE AND 
	i.type = 'CRIMINAL'</sql>
    <variables_active>Y</variables_active>
    <attributes/>
    <GUI>
      <xloc>688</xloc>
      <yloc>384</yloc>
    </GUI>
  </transform>
  <transform_error_handling>
  </transform_error_handling>
  <attributes/>
</pipeline>
