<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
  <bpmn:collaboration id="Collaboration_1">
    <bpmn:participant id="Participant_Main" name="Airflow DAG: Создание кроссов на основе фида PCM" processRef="Process_1"/>
  </bpmn:collaboration>
  <bpmn:process id="Process_1" isExecutable="false">
    <bpmn:laneSet id="LaneSet_1">
      <bpmn:lane id="Lane_0" name="Airflow">
        <bpmn:flowNodeRef>StartEvent_1</bpmn:flowNodeRef>
        <bpmn:flowNodeRef>Task_step-1</bpmn:flowNodeRef>
        <bpmn:flowNodeRef>Task_step-2</bpmn:flowNodeRef>
        <bpmn:flowNodeRef>Task_step-3</bpmn:flowNodeRef>
        <bpmn:flowNodeRef>Task_step-4</bpmn:flowNodeRef>
        <bpmn:flowNodeRef>Task_step-5</bpmn:flowNodeRef>
        <bpmn:flowNodeRef>Task_step-6</bpmn:flowNodeRef>
        <bpmn:flowNodeRef>Task_step-7</bpmn:flowNodeRef>
        <bpmn:flowNodeRef>Task_step-8</bpmn:flowNodeRef>
        <bpmn:flowNodeRef>Task_step-9</bpmn:flowNodeRef>
        <bpmn:flowNodeRef>Task_step-10</bpmn:flowNodeRef>
        <bpmn:flowNodeRef>Task_step-11</bpmn:flowNodeRef>
        <bpmn:flowNodeRef>GW_1</bpmn:flowNodeRef>
        <bpmn:flowNodeRef>EndEvent_logged_not_found</bpmn:flowNodeRef>
        <bpmn:flowNodeRef>EndEvent_ready</bpmn:flowNodeRef>
      </bpmn:lane>
    </bpmn:laneSet>
    <bpmn:startEvent id="StartEvent_1" name="Ежедневное расписание (2 раза в день)">
      <bpmn:outgoing>Flow_start_step_1</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:serviceTask id="Task_step-1" name="Запуск DAG Airflow">
      <bpmn:documentation>Airflow запускает DAG по расписанию.
Система: Airflow
Время: Мгновенно</bpmn:documentation>
      <bpmn:incoming>Flow_startevent_1_step_1</bpmn:incoming>
      <bpmn:outgoing>Flow_step_1_step_2</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="Task_step-2" name="Ожидание завершения сбора фида PCM">
      <bpmn:documentation>DAG ожидает подтверждения завершения сбора фида PCM от команды PCM.
Система: Airflow
Время: Зависит от команды PCM</bpmn:documentation>
      <bpmn:incoming>Flow_step_1_step_2</bpmn:incoming>
      <bpmn:outgoing>Flow_step_2_step_3</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="Task_step-3" name="Скачивание фида PCM / Доступ к ClickHouse">
      <bpmn:documentation>DAG скачивает фид PCM по предоставленной ссылке или получает доступ к данным фида из ClickHouse.
Система: Airflow, ClickHouse
Время: 5-30 мин</bpmn:documentation>
      <bpmn:incoming>Flow_step_2_step_3</bpmn:incoming>
      <bpmn:outgoing>Flow_step_3_step_4</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="Task_step-4" name="Нормализация полей фида PCM">
      <bpmn:documentation>Нормализация полей `article`, `original_article`, `brand` в данных фида PCM.
Система: Airflow
Время: 10-60 мин</bpmn:documentation>
      <bpmn:incoming>Flow_step_3_step_4</bpmn:incoming>
      <bpmn:outgoing>Flow_step_4_step_5</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="Task_step-5" name="Запрос текущих запчастей и жидкостей из Pimcore">
      <bpmn:documentation>Выполнение GraphQL-запроса к Pimcore для получения текущих запчастей и жидкостей с их кроссами.
Система: Airflow, Pimcore
Время: 5-30 мин</bpmn:documentation>
      <bpmn:incoming>Flow_step_4_step_5</bpmn:incoming>
      <bpmn:outgoing>Flow_step_5_step_6</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="Task_step-6" name="Поиск запчастей/жидкостей из Pimcore в фиде PCM">
      <bpmn:documentation>Для каждой запчасти/жидкости (clean) из Pimcore выполняется поиск в нормализованном фиде PCM.
Система: Airflow
Время: 30-120 мин</bpmn:documentation>
      <bpmn:incoming>Flow_step_5_step_6</bpmn:incoming>
      <bpmn:outgoing>Flow_step_6_gw_1</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="Task_step-7" name="Поиск по `original_article` и дедупликация">
      <bpmn:documentation>Проверка поля `original_article` и поиск уникальных значений, затем дедупликация результатов.
Система: Airflow
Время: 10-60 мин</bpmn:documentation>
      <bpmn:incoming>Flow_gw_1_step_7</bpmn:incoming>
      <bpmn:outgoing>Flow_step_7_step_9</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="Task_step-8" name="Логирование ненахождения запчасти/жидкости">
      <bpmn:documentation>Запись в лог информации о запчастях/жидкостях из Pimcore, которые не были найдены в фиде PCM.
Система: Airflow
Время: Мгновенно</bpmn:documentation>
      <bpmn:incoming>Flow_gw_1_step_8</bpmn:incoming>
      <bpmn:outgoing>Flow_step_8_end_logged_not_found</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="Task_step-9" name="Формирование пар для создания кроссов">
      <bpmn:documentation>Определение типа кросса (двухсторонний, замена) на основе условий поиска.
Система: Airflow
Время: 5-30 мин</bpmn:documentation>
      <bpmn:incoming>Flow_step_7_step_9</bpmn:incoming>
      <bpmn:outgoing>Flow_step_9_step_10</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="Task_step-10" name="Создание/обновление элементов в MongoDB">
      <bpmn:documentation>Запись или обновление информации о кроссах в коллекции `parts_crosses` в MongoDB.
Система: Airflow, MongoDB
Время: 5-30 мин</bpmn:documentation>
      <bpmn:incoming>Flow_step_9_step_10</bpmn:incoming>
      <bpmn:outgoing>Flow_step_10_step_11</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="Task_step-11" name="Отправка результатов в RabbitMQ">
      <bpmn:documentation>Отправка данных о созданных/обновленных кроссах в очередь RabbitMQ для дальнейшей обработки и обновления в Pimcore.
Система: Airflow, RabbitMQ
Время: 1-10 мин</bpmn:documentation>
      <bpmn:incoming>Flow_step_10_step_11</bpmn:incoming>
      <bpmn:outgoing>Flow_step_11_end_ready</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:exclusiveGateway id="GW_1" name="Запчасть/жидкость найдена в фиде PCM?">
      <bpmn:incoming>Flow_step_6_gw_1</bpmn:incoming>
      <bpmn:outgoing>Flow_gw_1_step_7</bpmn:outgoing>
      <bpmn:outgoing>Flow_gw_1_step_8</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:endEvent id="EndEvent_logged_not_found" name="Запчасти/жидкости">
      <bpmn:documentation>Запчасти/жидкости, не найденные в фиде PCM, залогированы. Процесс завершен для этих элементов.</bpmn:documentation>
      <bpmn:incoming>Flow_step_8_end_logged_not_found</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:endEvent id="EndEvent_ready" name="обновления в Pimcore">
      <bpmn:documentation>Кроссы созданы/обновлены в MongoDB и отправлены в RabbitMQ для обновления в Pimcore.</bpmn:documentation>
      <bpmn:incoming>Flow_step_11_end_ready</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_startevent_1_step_1" sourceRef="StartEvent_1" targetRef="Task_step-1"/>
    <bpmn:sequenceFlow id="Flow_step_1_step_2" sourceRef="Task_step-1" targetRef="Task_step-2"/>
    <bpmn:sequenceFlow id="Flow_step_2_step_3" sourceRef="Task_step-2" targetRef="Task_step-3"/>
    <bpmn:sequenceFlow id="Flow_step_3_step_4" sourceRef="Task_step-3" targetRef="Task_step-4"/>
    <bpmn:sequenceFlow id="Flow_step_4_step_5" sourceRef="Task_step-4" targetRef="Task_step-5"/>
    <bpmn:sequenceFlow id="Flow_step_5_step_6" sourceRef="Task_step-5" targetRef="Task_step-6"/>
    <bpmn:sequenceFlow id="Flow_step_6_gw_1" sourceRef="Task_step-6" targetRef="GW_1"/>
    <bpmn:sequenceFlow id="Flow_gw_1_step_7" sourceRef="GW_1" targetRef="Task_step-7" name="ДА">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">ДА</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_gw_1_step_8" sourceRef="GW_1" targetRef="Task_step-8" name="НЕТ">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">НЕТ</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_step_7_step_9" sourceRef="Task_step-7" targetRef="Task_step-9"/>
    <bpmn:sequenceFlow id="Flow_step_8_end_logged_not_found" sourceRef="Task_step-8" targetRef="EndEvent_logged_not_found"/>
    <bpmn:sequenceFlow id="Flow_step_9_step_10" sourceRef="Task_step-9" targetRef="Task_step-10"/>
    <bpmn:sequenceFlow id="Flow_step_10_step_11" sourceRef="Task_step-10" targetRef="Task_step-11"/>
    <bpmn:sequenceFlow id="Flow_step_11_end_ready" sourceRef="Task_step-11" targetRef="EndEvent_ready"/>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1">
      <bpmndi:BPMNShape id="Shape_Participant" bpmnElement="Participant_Main" isHorizontal="true">
        <dc:Bounds x="120" y="60" width="4360" height="220"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Shape_Lane_0" bpmnElement="Lane_0" isHorizontal="true">
        <dc:Bounds x="150" y="60" width="4330" height="220"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Shape_Start" bpmnElement="StartEvent_1">
        <dc:Bounds x="200" y="152" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Shape_Task_step-1" bpmnElement="Task_step-1">
        <dc:Bounds x="280" y="125" width="170" height="90"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Shape_Task_step-2" bpmnElement="Task_step-2">
        <dc:Bounds x="540" y="125" width="170" height="90"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Shape_Task_step-3" bpmnElement="Task_step-3">
        <dc:Bounds x="800" y="125" width="170" height="90"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Shape_Task_step-4" bpmnElement="Task_step-4">
        <dc:Bounds x="1060" y="125" width="170" height="90"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Shape_Task_step-5" bpmnElement="Task_step-5">
        <dc:Bounds x="1320" y="125" width="170" height="90"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Shape_Task_step-6" bpmnElement="Task_step-6">
        <dc:Bounds x="1580" y="125" width="170" height="90"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Shape_GW_1" bpmnElement="GW_1" isMarkerVisible="true">
        <dc:Bounds x="1840" y="145" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Shape_Task_step-7" bpmnElement="Task_step-7">
        <dc:Bounds x="2100" y="125" width="170" height="90"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Shape_Task_step-8" bpmnElement="Task_step-8">
        <dc:Bounds x="2360" y="70" width="170" height="90"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Shape_Task_step-9" bpmnElement="Task_step-9">
        <dc:Bounds x="2620" y="125" width="170" height="90"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Shape_Task_step-10" bpmnElement="Task_step-10">
        <dc:Bounds x="2880" y="125" width="170" height="90"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Shape_Task_step-11" bpmnElement="Task_step-11">
        <dc:Bounds x="3140" y="125" width="170" height="90"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Shape_EndEvent_logged_not_found" bpmnElement="EndEvent_logged_not_found">
        <dc:Bounds x="3400" y="152" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Shape_EndEvent_ready" bpmnElement="EndEvent_ready">
        <dc:Bounds x="3660" y="152" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Edge_Flow_startevent_1_step_1" bpmnElement="Flow_startevent_1_step_1">
        <di:waypoint x="236" y="170"/>
        <di:waypoint x="280" y="170"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Edge_Flow_step_1_step_2" bpmnElement="Flow_step_1_step_2">
        <di:waypoint x="450" y="170"/>
        <di:waypoint x="540" y="170"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Edge_Flow_step_2_step_3" bpmnElement="Flow_step_2_step_3">
        <di:waypoint x="710" y="170"/>
        <di:waypoint x="800" y="170"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Edge_Flow_step_3_step_4" bpmnElement="Flow_step_3_step_4">
        <di:waypoint x="970" y="170"/>
        <di:waypoint x="1060" y="170"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Edge_Flow_step_4_step_5" bpmnElement="Flow_step_4_step_5">
        <di:waypoint x="1230" y="170"/>
        <di:waypoint x="1320" y="170"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Edge_Flow_step_5_step_6" bpmnElement="Flow_step_5_step_6">
        <di:waypoint x="1490" y="170"/>
        <di:waypoint x="1580" y="170"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Edge_Flow_step_6_gw_1" bpmnElement="Flow_step_6_gw_1">
        <di:waypoint x="1750" y="170"/>
        <di:waypoint x="1840" y="170"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Edge_Flow_gw_1_step_7" bpmnElement="Flow_gw_1_step_7">
        <di:waypoint x="1890" y="170"/>
        <di:waypoint x="2100" y="170"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1895" y="152" width="40" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Edge_Flow_gw_1_step_8" bpmnElement="Flow_gw_1_step_8">
        <di:waypoint x="1865" y="145"/>
        <di:waypoint x="1865" y="62"/>
        <di:waypoint x="2445" y="62"/>
        <di:waypoint x="2445" y="70"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1873" y="113" width="40" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Edge_Flow_step_7_step_9" bpmnElement="Flow_step_7_step_9">
        <di:waypoint x="2270" y="170"/>
        <di:waypoint x="2620" y="170"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Edge_Flow_step_8_end_logged_not_found" bpmnElement="Flow_step_8_end_logged_not_found">
        <di:waypoint x="2530" y="115"/>
        <di:waypoint x="2965" y="115"/>
        <di:waypoint x="2965" y="170"/>
        <di:waypoint x="3400" y="170"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Edge_Flow_step_9_step_10" bpmnElement="Flow_step_9_step_10">
        <di:waypoint x="2790" y="170"/>
        <di:waypoint x="2880" y="170"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Edge_Flow_step_10_step_11" bpmnElement="Flow_step_10_step_11">
        <di:waypoint x="3050" y="170"/>
        <di:waypoint x="3140" y="170"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Edge_Flow_step_11_end_ready" bpmnElement="Flow_step_11_end_ready">
        <di:waypoint x="3310" y="170"/>
        <di:waypoint x="3660" y="170"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>
