powered by simpleCommunicator - 2.0.53     © 2025 Programmizd 02
Форумы / PostgreSQL [игнор отключен] [закрыт для гостей] / Выборка (распределить ресурсы...)
2 сообщений из 2, страница 1 из 1
Выборка (распределить ресурсы...)
    #39772924
igor.n
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Доброго времени суток!

Есть такая схема таблиц:
сс_queue - это таблица настройки очереди, в ней есть поле которое отвечает за максимальное количество задач.
cc_outbound_resource - это таблица которая отвечает за настройки общих ресурсов, в ней есть поле max_call_count - это максимальное количество исходящих сессий для этого ресурса.
cc_queue_routing - это таблица которая распределяет в зависимости от pattern (это regex :(, например ^1, ^2 ... ) и очереди - какие ресурсы можно использовать
cc_resource_in_routing - таблица соединяет cc_queue_routing с cc_outbound_resource (то есть ресурс может быть общий для задач)
сс_member - это таблица участников которым из выборки нужно позвонить/написать...
cc_member_communications - это средства связи сс_member (в выборку должен попасть только 1 номер в зависимости от приоритета и pattern табл cc_queue_routing)

Как максимально быстро соединить cc_member (только 1 c cc_member_communications) с cc_outbound_resource таким образом, чтобы получилось (resource_id = null не должно попадать в результат, это для понимания как работает расстановка ресурсов):
cc_idqueue_ididnumberrn resource_id1311172001R331210032R151310053R161410064R181610085R191710096R171510077null11111118null102820099R21129121010R212210720111R3
Исходные данные:
Код: plsql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
with cc_queue as (
  select 1 as id, 10 as max_call_count, 1 as priority
  union all
  select 2 as id, 5 as max_call_count, 1 as priority
), cc_outbound_resource as (
  select 1 as id, 5 as max_call_count
  union all
  select 2 as id, 2 as max_call_count
  union all
  select 3 as id, 2 as max_call_count
), cc_queue_routing as (
  select 1 as id, '^1' as pattern, 1 as priority, 1 as queue_id
  union all
  select 2 as id, '^12' as pattern, 2 as priority, 1 as queue_id
  union all
  select 3 as id, '^2' as pattern, 3 as priority, 1 as queue_id
  union all
  select 4 as id, '^1' as pattern, 1 as priority, 2 as queue_id
  union all
  select 5 as id, '^12' as pattern, 2 as priority, 2 as queue_id
  union all
  select 6 as id, '^7' as pattern, 2 as priority, 1 as queue_id
  union all
  select 7 as id, '^7' as pattern, 2 as priority, 2 as queue_id
), cc_resource_in_routing as (
  select 1 as id, 1 as routing_id, 1 as resource_id, 1 as priority
  union all
  select 2 as id, 2 as routing_id, 1 as resource_id, 2 as priority
  union all
  select 3 as id, 2 as routing_id, 2 as resource_id, 3 as priority
  union all
  select 4 as id, 3 as routing_id, 2 as resource_id, 3 as priority
  union all
  select 5 as id, 4 as routing_id, 1 as resource_id, 1 as priority
  union all
  select 6 as id, 5 as routing_id, 1 as resource_id, 1 as priority
  union all
  select 7 as id, 6 as routing_id, 3 as resource_id, 1 as priority
  union all
  select 8 as id, 7 as routing_id, 3 as resource_id, 1 as priority
), cc_member as (
  select 1 as id, 1 as queue_id, 1 as priority
  union all
  select 2 as id, 1 as queue_id, 2 as priority
  union all
  select 3 as id, 1 as queue_id, 2 as priority
  union all
  select 4 as id, 1 as queue_id, 2 as priority
  union all
  select 5 as id, 1 as queue_id, 2 as priority
  union all
  select 6 as id, 1 as queue_id, 2 as priority
  union all
  select 7 as id, 1 as queue_id, 2 as priority
  union all
  select 8 as id, 2 as queue_id, 2 as priority
  union all
  select 9 as id, 2 as queue_id, 1 as priority
  union all
  select 10 as id, 2 as queue_id, 1 as priority
  union all
  select 11 as id, 1 as queue_id, 3 as priority
), cc_member_communications as (
    select 1 as id, 1 as member_id, '1111' as number, 2 as priority
    union all
    select 2 as id, 1 as member_id, '1212' as number, 1 as priority
    union all
    select 3 as id, 2 as member_id, '1003' as number, 1 as priority
    union all
    select 4 as id, 3 as member_id, '1004' as number, 1 as priority
    union all
    select 5 as id, 3 as member_id, '1005' as number, 2 as priority
    union all
    select 6 as id, 4 as member_id, '1006' as number, 2 as priority
    union all
    select 7 as id, 5 as member_id, '1007' as number, 2 as priority
    union all
    select 8 as id, 6 as member_id, '1008' as number, 2 as priority
    union all
    select 9 as id, 7 as member_id, '1009' as number, 2 as priority
    union all
    select 13 as id, 11 as member_id, '7200' as number, 3 as priority
--     q2
    union all
    select 10 as id, 8 as member_id, '2009' as number, 2 as priority
    union all
    select 11 as id, 9 as member_id, '1210' as number, 2 as priority
    union all
    select 12 as id, 10 as member_id, '7201' as number, 2 as priority
  )
select m.cc_id as cc_id,
       q.id    as queue_id,
       m.id,
       m.number,
       row_number() over (order by q.priority desc ) as rn,
       null as resource_id
from cc_queue q
   , lateral (select q.max_call_count) as qq(need_calls)
       inner join lateral (
  select c.cc_id as cc_id,
         m.id,
         c.number
  from cc_member m
         inner join lateral (
    select id as cc_id,
           queue_id,
           number
    from cc_member_communications c
    where c.member_id = m.id
      and c.number ~ '.*' -- ? как правильно соединить ресурсы, чтобы учесть макс. количество cc_outbound_resource

    order by priority desc
    limit 1
    ) as c on true

  where m.queue_id = q.id
  order by m.priority desc
  limit qq.need_calls
  ) m on true
order by q.priority desc;



Грубо говоря, мне нужно получить список средств связи которые в зависимости от regex будут использовать максимально
возможное количество cc_outbound_resource.max_call_count но не больше сс_queue.max_call_count
Сортировка: сс_queue.priority > сс_member.priority > cc_member_communications.priority > cc_queue_routing.priority > cc_resource_in_routing.priority
Помогите пожалуйста советом или решением задачи, много времени потерял на этой задаче (если плохо объяснил задачу - напишите) возможно неверная структура БД ? есть возможность сменить.
Главная цель максимально быстро сделать выборку и дать пользователю возможность тонкой настройки исходящих задач и управление ресурсами для этих задач посредством Regex.

DB_VERSION
Версию можно сменить на не старше 9
PostgreSQL 11.1 (Debian 11.1-3.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit


Схема:
...
Рейтинг: 0 / 0
Выборка (распределить ресурсы...)
    #39773884
igor.n
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Удалите пожалуйста этот топик. Вопрос решен иначе.
Спасибо!
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / PostgreSQL [игнор отключен] [закрыт для гостей] / Выборка (распределить ресурсы...)
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]