Отчёты по сотрудникам: To-do report и Employee Activity, события JobTread в data_collector
All checks were successful
ci / test (push) Successful in 23s
ci / deploy (push) Successful in 1m41s

Новый package employee_reports (порт 8091): To-do report перенесён идейно из
khbuild_tests на зеркало Supabase (Stale Days, выбор снимка, Excel-выгрузка) и
дополнен показателем «любая активность в инфополе»; Employee Activity - у каждого
менеджера встроенный график по дням с цветом дня (зелёный - Daily Log, жёлтый -
активность не меньше порога, тёмно-красный - меньше порога) и итоговый график
зелёных и жёлтых людей внизу.

data_collector: модуль events (jt_event, POST /events/sync) - загрузка ленты
событий JobTread; миграция 009; методология docs/activity_methodology.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-15 14:38:00 +03:00
parent 96b53c5487
commit 715546bdae
46 changed files with 3261 additions and 7 deletions

View File

@@ -0,0 +1,50 @@
-- Активность сотрудников в «инфополе»: события JobTread (кто, что и когда сделал), перечень тех, кого ставим на учёт, состояние синхронизации.
-- Методология: docs/activity_methodology.md. Заполняет и читает пакет employee_reports.
-- Лента событий организации JobTread (organization.events): только типы taskCreated, taskUpdated, dailyLogCreated.
-- События неизменяемы: повторная загрузка тех же id ничего не меняет.
create table jt_event (
id text primary key,
type text not null,
created_at timestamptz not null,
user_id text,
user_name text, -- имя пользователя JobTread; сопоставляется с jt_membership.user_name
task_id text,
task_is_todo boolean,
task_type_name text, -- тип задачи на момент загрузки (веха - тип Milestone)
job_id text,
daily_log_id text,
-- классификация для отчёта активности; null - событие не считается активностью:
-- todo_closed, todo_created, milestone_closed, milestone_moved, daily_log_created
kind text check (kind is null or kind in ('todo_closed','todo_created','milestone_closed','milestone_moved','daily_log_created')),
payload jsonb not null default '{}'::jsonb, -- {previous, next} с изменёнными полями задачи или данные дневного лога
loaded_at timestamptz not null default now()
);
create index jt_event_created_idx on jt_event (created_at desc);
create index jt_event_user_created_idx on jt_event (user_name, created_at) where kind is not null;
alter table jt_event enable row level security;
-- Кого ставим на учёт активности (пока три менеджера по строительству). Чат берётся по person.slack_user_id, JobTread - по person.jt_membership_id.
create table activity_tracked_person (
person_id uuid primary key references person(id),
is_enabled boolean not null default true,
note text,
added_at timestamptz not null default now()
);
alter table activity_tracked_person enable row level security;
-- Состояние синхронизации (одна строка на источник), чтобы отчёт показывал, насколько свежи данные.
create table activity_sync_state (
source text primary key,
last_started_at timestamptz,
last_success_at timestamptz,
last_error text,
last_loaded integer not null default 0
);
alter table activity_sync_state enable row level security;
insert into activity_tracked_person (person_id, note)
select p.id, 'менеджер по строительству'
from person p join construction_manager cm on cm.person_id = p.id
where p.email in ('greg@khbuild.pro', 'walter@khbuild.pro', 'zach@khbuild.pro')
on conflict (person_id) do nothing;