Отчёт активности: сообщения сотрудника, записанные под менеджером проекта, считаются; ночная проверка: received_at по времени сообщения, молчание агента - не обработка
All checks were successful
ci / test (push) Successful in 51s
ci / deploy (push) Successful in 2m54s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-29 10:08:38 +03:00
parent 54b38d9076
commit 68da50b77b
2 changed files with 7 additions and 5 deletions

View File

@@ -141,7 +141,7 @@ export const EVENT_COUNTS_SQL = `
/**
* Сообщения сотрудника в чате с ассистентом и в проектных каналах Slack. Пока в журнале ассистента нет автора (до миграции 008) считаем,
* что писал сам менеджер канала. Сообщение проектного канала, которое уже есть в журнале ассистента, считается один раз.
* что писал сам менеджер канала. Сообщение проектного канала, которое уже есть в журнале ассистента как сообщение этого же сотрудника, считается один раз; сообщение сотрудника, записанное в журнал под менеджером проекта (его писал не менеджер, например бухгалтер или CFO, в том числе когда агент не смог ответить), считается по каналу.
*/
export const CHAT_COUNTS_SQL = `
with msgs as (
@@ -154,7 +154,7 @@ export const CHAT_COUNTS_SQL = `
from slack_channel_message c
join project_channel pc on pc.channel_id = c.channel_id and pc.track_activity
where c.user_id = $5
and not exists (select 1 from slack_message_log l where l.channel_id = c.channel_id and l.message_ts = c.message_ts)
and not exists (select 1 from slack_message_log l where l.channel_id = c.channel_id and l.message_ts = c.message_ts and l.manager_person_id = $1 and (l.sender_slack_user_id is null or l.sender_slack_user_id = $5))
)
select (at at time zone $4)::date::text as day, count(*)::int as n
from msgs
@@ -186,7 +186,7 @@ export const USER_ACTIVITY_DAYS_SQL = `
join project_channel pc on pc.channel_id = c.channel_id and pc.track_activity
join person p on p.slack_user_id = c.user_id
join jt_membership mb on mb.id = p.jt_membership_id
where not exists (select 1 from slack_message_log l where l.channel_id = c.channel_id and l.message_ts = c.message_ts)
where not exists (select 1 from slack_message_log l where l.channel_id = c.channel_id and l.message_ts = c.message_ts and l.manager_person_id = p.id and (l.sender_slack_user_id is null or l.sender_slack_user_id = p.slack_user_id))
),
chat as (
select user_name, (at at time zone $3)::date::text as day, count(*)::int as n