Агенты: менеджер отвечает за все работы проекта, включая подрядчиков (п.80); дубли todo: автоматические (агент и Claude) закрываются, ручные - с вопросом; правки Юрия в approved
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -31,48 +31,49 @@ const COLS = `
|
||||
coalesce((select array_agg(m.user_name order by m.user_name) from jt_task_assignment a
|
||||
join jt_membership m on m.id = a.membership_id where a.task_id = t.id), '{}') as assignees`;
|
||||
|
||||
// Менеджер отвечает за ВСЕ работы своего проекта, включая подрядчиков (решение владельца 09.11.2026): отбор по проекту, а не по назначению на менеджера.
|
||||
const MANAGER_TASKS = `
|
||||
from jt_task t
|
||||
join jt_task_assignment ma on ma.task_id = t.id and ma.membership_id = $2
|
||||
where t.job_id = $1 and not t.is_deleted and not t.is_group and coalesce(t.progress, 0) < 1`;
|
||||
|
||||
/** Вход (1): не завершённые работы менеджера на этой неделе и просроченные. */
|
||||
/** Вход (1): не завершённые работы проекта (в том числе подрядчиков) на этой неделе и просроченные. */
|
||||
export async function input1(db: Queryable, p: InputParams): Promise<TaskRow[]> {
|
||||
const { rows } = await db.query(
|
||||
`select ${COLS}, null::text as related_task_id ${MANAGER_TASKS} and not t.is_todo
|
||||
and t.end_date is not null and (t.end_date < $3 or (coalesce(t.start_date, t.end_date) <= $5 and t.end_date >= $4))
|
||||
and t.end_date is not null and (t.end_date < $2 or (coalesce(t.start_date, t.end_date) <= $4 and t.end_date >= $3))
|
||||
order by t.end_date, t.name`,
|
||||
[p.jtJobId, p.managerMembershipId, p.today, p.weekStart, p.weekEnd],
|
||||
[p.jtJobId, p.today, p.weekStart, p.weekEnd],
|
||||
);
|
||||
return rows;
|
||||
}
|
||||
|
||||
/** Вход (2): todo менеджера на этой неделе и просроченные. */
|
||||
/** Вход (2): todo проекта на этой неделе и просроченные. */
|
||||
export async function input2(db: Queryable, p: InputParams): Promise<TaskRow[]> {
|
||||
const { rows } = await db.query(
|
||||
`select ${COLS}, null::text as related_task_id ${MANAGER_TASKS} and t.is_todo
|
||||
and coalesce(t.end_date, t.start_date) is not null
|
||||
and (coalesce(t.end_date, t.start_date) < $3 or coalesce(t.end_date, t.start_date) between $4 and $5)
|
||||
and (coalesce(t.end_date, t.start_date) < $2 or coalesce(t.end_date, t.start_date) between $3 and $4)
|
||||
order by coalesce(t.end_date, t.start_date), t.name`,
|
||||
[p.jtJobId, p.managerMembershipId, p.today, p.weekStart, p.weekEnd],
|
||||
[p.jtJobId, p.today, p.weekStart, p.weekEnd],
|
||||
);
|
||||
return rows;
|
||||
}
|
||||
|
||||
/** Вход (3): todo менеджера на следующую неделю. */
|
||||
/** Вход (3): todo проекта на следующую неделю. */
|
||||
export async function input3(db: Queryable, p: InputParams): Promise<TaskRow[]> {
|
||||
const { rows } = await db.query(
|
||||
`select ${COLS}, null::text as related_task_id ${MANAGER_TASKS} and t.is_todo
|
||||
and coalesce(t.end_date, t.start_date) between $3 and $4
|
||||
and coalesce(t.end_date, t.start_date) between $2 and $3
|
||||
order by coalesce(t.end_date, t.start_date), t.name`,
|
||||
[p.jtJobId, p.managerMembershipId, p.nextWeekStart, p.nextWeekEnd],
|
||||
[p.jtJobId, p.nextWeekStart, p.nextWeekEnd],
|
||||
);
|
||||
return rows;
|
||||
}
|
||||
|
||||
// Остальные работы цепочки: все работы проекта, кроме уже попавших во входы (1) и (2) ($2 - их id).
|
||||
const OTHERS = `
|
||||
where t.job_id = $1 and not t.is_deleted and not t.is_group and coalesce(t.progress, 0) < 1
|
||||
and not exists (select 1 from jt_task_assignment a where a.task_id = t.id and a.membership_id = $2)`;
|
||||
and t.id <> all($2::text[])`;
|
||||
|
||||
/**
|
||||
* Вход (4): работы других исполнителей (особенно закупки), зависящие (прямо или через цепочку до 5 звеньев)
|
||||
@@ -82,15 +83,15 @@ export async function input4(db: Queryable, p: InputParams, managerTaskIds: stri
|
||||
if (!managerTaskIds.length) return [];
|
||||
const { rows } = await db.query(
|
||||
`with recursive dep(root, id, depth) as (
|
||||
select s, d.task_id, 1 from unnest($3::text[]) s join jt_task_dependency d on d.depends_on_task_id = s
|
||||
select s, d.task_id, 1 from unnest($2::text[]) s join jt_task_dependency d on d.depends_on_task_id = s
|
||||
union all
|
||||
select dep.root, d.task_id, dep.depth + 1 from dep join jt_task_dependency d on d.depends_on_task_id = dep.id where dep.depth < 5
|
||||
)
|
||||
select distinct on (t.id) ${COLS}, dep.root as related_task_id
|
||||
from dep join jt_task t on t.id = dep.id ${OTHERS}
|
||||
and coalesce(t.start_date, t.end_date) is not null and coalesce(t.start_date, t.end_date) <= $4
|
||||
and coalesce(t.start_date, t.end_date) is not null and coalesce(t.start_date, t.end_date) <= $3
|
||||
order by t.id, dep.depth`,
|
||||
[p.jtJobId, p.managerMembershipId, managerTaskIds, p.horizon],
|
||||
[p.jtJobId, managerTaskIds, p.horizon],
|
||||
);
|
||||
return rows.sort((a, b) => String(a.start_date ?? a.end_date).localeCompare(String(b.start_date ?? b.end_date)) || a.name.localeCompare(b.name));
|
||||
}
|
||||
@@ -100,14 +101,14 @@ export async function input5(db: Queryable, p: InputParams, managerTaskIds: stri
|
||||
if (!managerTaskIds.length) return [];
|
||||
const { rows } = await db.query(
|
||||
`with recursive dep(root, id, depth) as (
|
||||
select s, d.depends_on_task_id, 1 from unnest($3::text[]) s join jt_task_dependency d on d.task_id = s
|
||||
select s, d.depends_on_task_id, 1 from unnest($2::text[]) s join jt_task_dependency d on d.task_id = s
|
||||
union all
|
||||
select dep.root, d.depends_on_task_id, dep.depth + 1 from dep join jt_task_dependency d on d.task_id = dep.id where dep.depth < 5
|
||||
)
|
||||
select distinct on (t.id) ${COLS}, dep.root as related_task_id
|
||||
from dep join jt_task t on t.id = dep.id ${OTHERS}
|
||||
order by t.id, dep.depth`,
|
||||
[p.jtJobId, p.managerMembershipId, managerTaskIds],
|
||||
[p.jtJobId, managerTaskIds],
|
||||
);
|
||||
return rows.sort((a, b) => String(a.end_date ?? a.start_date).localeCompare(String(b.end_date ?? b.start_date)) || a.name.localeCompare(b.name));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user