R23-1/R23-2/R23-4:完成项目沟通回填与收口治理后端
这个提交包含在:
@@ -126,6 +126,8 @@ function getConfig() {
|
||||
wecomEntryEnabled: process.env.WECOM_ENTRY_ENABLED === "true",
|
||||
projectDomainEnabled: process.env.PROJECT_DOMAIN_ENABLED === "true",
|
||||
projectLinkingEnabled: process.env.PROJECT_LINKING_ENABLED === "true",
|
||||
projectCommunicationLogEnabled: process.env.PROJECT_COMMUNICATION_LOG_ENABLED === "true",
|
||||
projectClosureChecklistEnabled: process.env.PROJECT_CLOSURE_CHECKLIST_ENABLED === "true",
|
||||
confidentialDocRefsEnabled: process.env.CONFIDENTIAL_DOC_REFS_ENABLED === "true",
|
||||
publicSecurityHardeningEnabled: process.env.PUBLIC_SECURITY_HARDENING_ENABLED === "true",
|
||||
|
||||
|
||||
+45
-36
@@ -44,6 +44,23 @@ async function evaluateOptionalFlag(fastify, request, flagKey) {
|
||||
return gate.enabled;
|
||||
}
|
||||
|
||||
function canReadAllProjects(fastify, employee) {
|
||||
return fastify.hasPermission(employee, "project.view_all") || fastify.hasPermission(employee, "project.manage") || fastify.hasPermission(employee, "*");
|
||||
}
|
||||
|
||||
function projectScopeWhere(fastify, employee) {
|
||||
if (canReadAllProjects(fastify, employee)) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
OR: [
|
||||
{ owner_employee_id: employee.id },
|
||||
{ manager_employee_id: employee.id },
|
||||
{ members: { some: { employee_id: employee.id, left_at: null } } },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
function resolveWeekStart(rawDateString) {
|
||||
const date = parseDateOnlyString(rawDateString);
|
||||
const day = date.getUTCDay() || 7;
|
||||
@@ -190,6 +207,8 @@ async function portalRoutes(fastify) {
|
||||
todoBoard: await evaluateOptionalFlag(fastify, request, FEATURE_FLAG_KEYS.todoBoard),
|
||||
paymentBatch: await evaluateOptionalFlag(fastify, request, FEATURE_FLAG_KEYS.paymentBatch),
|
||||
projectDomain: await evaluateOptionalFlag(fastify, request, FEATURE_FLAG_KEYS.projectDomain),
|
||||
projectCommunicationLog: await evaluateOptionalFlag(fastify, request, FEATURE_FLAG_KEYS.projectCommunicationLog),
|
||||
projectClosureChecklist: await evaluateOptionalFlag(fastify, request, FEATURE_FLAG_KEYS.projectClosureChecklist),
|
||||
};
|
||||
|
||||
const [
|
||||
@@ -210,6 +229,8 @@ async function portalRoutes(fastify) {
|
||||
overdueProjectMilestoneCount,
|
||||
highPriorityProjectTaskCount,
|
||||
openProjectRiskCount,
|
||||
projectFollowUpDueTodayCount,
|
||||
closurePendingProjectCount,
|
||||
] = await Promise.all([
|
||||
fastify.prisma.workflowTask.count({ where: { status: "pending", OR: assigneeFilters } }),
|
||||
fastify.prisma.reimbursementForm.count({ where: { OR: [{ owner_id: request.employee.id }, { submitter_id: request.employee.id }] } }),
|
||||
@@ -270,15 +291,7 @@ async function portalRoutes(fastify) {
|
||||
: Promise.resolve(0),
|
||||
featureEnabled.projectDomain
|
||||
? fastify.prisma.project.count({
|
||||
where: fastify.hasPermission(request.employee, "project.view_all") || fastify.hasPermission(request.employee, "project.manage") || fastify.hasPermission(request.employee, "*")
|
||||
? {}
|
||||
: {
|
||||
OR: [
|
||||
{ owner_employee_id: request.employee.id },
|
||||
{ manager_employee_id: request.employee.id },
|
||||
{ members: { some: { employee_id: request.employee.id, left_at: null } } },
|
||||
],
|
||||
},
|
||||
where: projectScopeWhere(fastify, request.employee) ?? {},
|
||||
})
|
||||
: Promise.resolve(0),
|
||||
featureEnabled.projectDomain
|
||||
@@ -286,15 +299,7 @@ async function portalRoutes(fastify) {
|
||||
where: {
|
||||
status: { in: ["pending", "in_progress", "delayed"] },
|
||||
due_date: { lt: new Date() },
|
||||
project: fastify.hasPermission(request.employee, "project.view_all") || fastify.hasPermission(request.employee, "project.manage") || fastify.hasPermission(request.employee, "*")
|
||||
? undefined
|
||||
: {
|
||||
OR: [
|
||||
{ owner_employee_id: request.employee.id },
|
||||
{ manager_employee_id: request.employee.id },
|
||||
{ members: { some: { employee_id: request.employee.id, left_at: null } } },
|
||||
],
|
||||
},
|
||||
project: projectScopeWhere(fastify, request.employee),
|
||||
},
|
||||
})
|
||||
: Promise.resolve(0),
|
||||
@@ -303,15 +308,7 @@ async function portalRoutes(fastify) {
|
||||
where: {
|
||||
status: { in: ["todo", "doing", "blocked"] },
|
||||
priority: { in: ["high", "urgent"] },
|
||||
project: fastify.hasPermission(request.employee, "project.view_all") || fastify.hasPermission(request.employee, "project.manage") || fastify.hasPermission(request.employee, "*")
|
||||
? undefined
|
||||
: {
|
||||
OR: [
|
||||
{ owner_employee_id: request.employee.id },
|
||||
{ manager_employee_id: request.employee.id },
|
||||
{ members: { some: { employee_id: request.employee.id, left_at: null } } },
|
||||
],
|
||||
},
|
||||
project: projectScopeWhere(fastify, request.employee),
|
||||
},
|
||||
})
|
||||
: Promise.resolve(0),
|
||||
@@ -319,18 +316,28 @@ async function portalRoutes(fastify) {
|
||||
? fastify.prisma.projectRisk.count({
|
||||
where: {
|
||||
status: { not: "closed" },
|
||||
project: fastify.hasPermission(request.employee, "project.view_all") || fastify.hasPermission(request.employee, "project.manage") || fastify.hasPermission(request.employee, "*")
|
||||
? undefined
|
||||
: {
|
||||
OR: [
|
||||
{ owner_employee_id: request.employee.id },
|
||||
{ manager_employee_id: request.employee.id },
|
||||
{ members: { some: { employee_id: request.employee.id, left_at: null } } },
|
||||
],
|
||||
},
|
||||
project: projectScopeWhere(fastify, request.employee),
|
||||
},
|
||||
})
|
||||
: Promise.resolve(0),
|
||||
featureEnabled.projectDomain && featureEnabled.projectCommunicationLog
|
||||
? fastify.prisma.projectCommunicationLog.count({
|
||||
where: {
|
||||
next_follow_up_date: parseDateOnlyString(today),
|
||||
project: projectScopeWhere(fastify, request.employee),
|
||||
},
|
||||
})
|
||||
: Promise.resolve(0),
|
||||
featureEnabled.projectDomain && featureEnabled.projectClosureChecklist
|
||||
? fastify.prisma.projectClosureChecklistItem.findMany({
|
||||
where: {
|
||||
status: "pending",
|
||||
project: projectScopeWhere(fastify, request.employee),
|
||||
},
|
||||
distinct: ["project_id"],
|
||||
select: { project_id: true },
|
||||
}).then((items) => items.length)
|
||||
: Promise.resolve(0),
|
||||
]);
|
||||
|
||||
const todayPresence = featureEnabled.presenceBoard
|
||||
@@ -507,6 +514,8 @@ async function portalRoutes(fastify) {
|
||||
overdueMilestonesCount: overdueProjectMilestoneCount,
|
||||
highPriorityTaskCount: highPriorityProjectTaskCount,
|
||||
openRiskCount: openProjectRiskCount,
|
||||
followUpDueTodayCount: projectFollowUpDueTodayCount,
|
||||
closurePendingProjectCount,
|
||||
href: "/projects",
|
||||
}
|
||||
: null,
|
||||
|
||||
+350
-51
@@ -86,6 +86,34 @@ const DELIVERY_CREATE_SCHEMA = z.object({
|
||||
ownerEmployeeId: UUID_SCHEMA.optional(),
|
||||
}).strict();
|
||||
|
||||
const COMMUNICATION_CHANNEL_SCHEMA = z.enum(["wechat", "phone", "meeting", "wecom", "email", "onsite", "other"]);
|
||||
const CLOSURE_CHECKLIST_STATUS_SCHEMA = z.enum(["pending", "done", "waived"]);
|
||||
const COMMUNICATION_LOG_CREATE_SCHEMA = z.object({
|
||||
happenedAt: z.string().datetime(),
|
||||
channel: COMMUNICATION_CHANNEL_SCHEMA,
|
||||
externalContactName: z.string().trim().max(120).nullable().optional(),
|
||||
externalOrgName: z.string().trim().max(200).nullable().optional(),
|
||||
summary: z.string().trim().min(1).max(1000),
|
||||
nextAction: z.string().trim().max(300).nullable().optional(),
|
||||
nextFollowUpDate: DATE_SCHEMA.nullable().optional(),
|
||||
}).strict();
|
||||
const COMMUNICATION_LOG_PATCH_SCHEMA = COMMUNICATION_LOG_CREATE_SCHEMA.partial().refine((value) => Object.keys(value).length > 0, { message: "empty_patch" });
|
||||
const CLOSURE_CHECKLIST_PATCH_SCHEMA = z.object({
|
||||
status: CLOSURE_CHECKLIST_STATUS_SCHEMA.optional(),
|
||||
note: z.string().trim().max(500).nullable().optional(),
|
||||
}).strict().refine((value) => Object.keys(value).length > 0, { message: "empty_patch" });
|
||||
|
||||
const PROJECT_CLOSURE_TEMPLATE = [
|
||||
{ itemKey: "delivery_record_checked", title: "确认交付/验收记录齐全", sortOrder: 10 },
|
||||
{ itemKey: "risk_review_done", title: "确认项目风险已收口或转监控", sortOrder: 20 },
|
||||
{ itemKey: "reimbursement_cleared", title: "确认关联报销已处理", sortOrder: 30 },
|
||||
{ itemKey: "travel_cleared", title: "确认关联差旅已处理", sortOrder: 40 },
|
||||
{ itemKey: "contract_archive_confirmed", title: "确认合同台账与归档位置已核对", sortOrder: 50 },
|
||||
{ itemKey: "handover_note_done", title: "确认项目交接说明已补齐", sortOrder: 60 },
|
||||
];
|
||||
|
||||
const PROJECT_COMMUNICATION_EDIT_WINDOW_MS = 24 * 60 * 60 * 1000;
|
||||
|
||||
function buildValidationError(details, statusCode = 400) {
|
||||
return new AppError({ code: "VALID_001", message: "参数校验失败", statusCode, details });
|
||||
}
|
||||
@@ -131,36 +159,51 @@ function hasGlobalProjectManage(fastify, employee) {
|
||||
return fastify.hasPermission(employee, "project.manage") || fastify.hasPermission(employee, "system.settings");
|
||||
}
|
||||
|
||||
async function loadProjectContext(prisma, projectId, employeeId) {
|
||||
return prisma.project.findUnique({
|
||||
where: { id: projectId },
|
||||
include: {
|
||||
owner: { select: { id: true, employee_no: true, name: true } },
|
||||
manager: { select: { id: true, employee_no: true, name: true } },
|
||||
members: {
|
||||
where: { left_at: null },
|
||||
include: { employee: { select: { id: true, employee_no: true, name: true } } },
|
||||
orderBy: [{ role: "asc" }, { joined_at: "asc" }],
|
||||
function buildProjectDetailInclude() {
|
||||
return {
|
||||
owner: { select: { id: true, employee_no: true, name: true } },
|
||||
manager: { select: { id: true, employee_no: true, name: true } },
|
||||
members: {
|
||||
where: { left_at: null },
|
||||
include: { employee: { select: { id: true, employee_no: true, name: true } } },
|
||||
orderBy: [{ role: "asc" }, { joined_at: "asc" }],
|
||||
},
|
||||
milestones: { orderBy: [{ sort_order: "asc" }, { due_date: "asc" }] },
|
||||
tasks: {
|
||||
include: {
|
||||
assignee: { select: { id: true, employee_no: true, name: true } },
|
||||
creator: { select: { id: true, employee_no: true, name: true } },
|
||||
},
|
||||
milestones: { orderBy: [{ sort_order: "asc" }, { due_date: "asc" }] },
|
||||
tasks: { include: { assignee: { select: { id: true, employee_no: true, name: true } }, creator: { select: { id: true, employee_no: true, name: true } } }, orderBy: [{ priority: "desc" }, { due_date: "asc" }, { created_at: "desc" }] },
|
||||
risks: { include: { owner: { select: { id: true, employee_no: true, name: true } } }, orderBy: [{ level: "desc" }, { created_at: "desc" }] },
|
||||
_count: {
|
||||
select: {
|
||||
members: true,
|
||||
milestones: true,
|
||||
tasks: true,
|
||||
risks: true,
|
||||
reimbursements: true,
|
||||
travel_requests: true,
|
||||
todo_items: true,
|
||||
weekly_reports: true,
|
||||
contracts: true,
|
||||
deliveries: true,
|
||||
document_refs: true,
|
||||
},
|
||||
orderBy: [{ priority: "desc" }, { due_date: "asc" }, { created_at: "desc" }],
|
||||
},
|
||||
risks: {
|
||||
include: { owner: { select: { id: true, employee_no: true, name: true } } },
|
||||
orderBy: [{ level: "desc" }, { created_at: "desc" }],
|
||||
},
|
||||
_count: {
|
||||
select: {
|
||||
members: true,
|
||||
milestones: true,
|
||||
tasks: true,
|
||||
risks: true,
|
||||
reimbursements: true,
|
||||
travel_requests: true,
|
||||
todo_items: true,
|
||||
weekly_reports: true,
|
||||
communication_logs: true,
|
||||
closure_checklist_items: true,
|
||||
contracts: true,
|
||||
deliveries: true,
|
||||
document_refs: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function loadProjectContext(prisma, projectId) {
|
||||
return prisma.project.findUnique({
|
||||
where: { id: projectId },
|
||||
include: buildProjectDetailInclude(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -224,6 +267,139 @@ function mapEmployeeBasic(employee) {
|
||||
return { id: employee.id, employeeNo: employee.employee_no, name: employee.name };
|
||||
}
|
||||
|
||||
|
||||
function startOfUtcDay(value = new Date()) {
|
||||
return new Date(`${value.toISOString().slice(0, 10)}T00:00:00.000Z`);
|
||||
}
|
||||
|
||||
function endOfUtcDay(value = new Date()) {
|
||||
return new Date(`${value.toISOString().slice(0, 10)}T23:59:59.999Z`);
|
||||
}
|
||||
|
||||
function mapProjectCommunicationLog(item, canEdit) {
|
||||
return {
|
||||
id: item.id,
|
||||
happenedAt: item.happened_at?.toISOString?.() ?? null,
|
||||
channel: item.channel,
|
||||
externalContactName: item.external_contact_name ?? null,
|
||||
externalOrgName: item.external_org_name ?? null,
|
||||
summary: item.summary,
|
||||
nextAction: item.next_action ?? null,
|
||||
nextFollowUpDate: item.next_follow_up_date?.toISOString?.().slice(0, 10) ?? null,
|
||||
createdBy: item.created_by,
|
||||
createdAt: item.created_at?.toISOString?.() ?? null,
|
||||
updatedAt: item.updated_at?.toISOString?.() ?? null,
|
||||
canEdit,
|
||||
creator: mapEmployeeBasic(item.creator),
|
||||
};
|
||||
}
|
||||
|
||||
function mapProjectClosureChecklistItem(item, canEdit) {
|
||||
return {
|
||||
id: item.id,
|
||||
itemKey: item.item_key,
|
||||
title: item.title,
|
||||
status: item.status,
|
||||
note: item.note ?? null,
|
||||
sortOrder: item.sort_order,
|
||||
completedAt: item.completed_at?.toISOString?.() ?? null,
|
||||
completedBy: item.completed_by ?? null,
|
||||
canEdit,
|
||||
completer: mapEmployeeBasic(item.completer),
|
||||
};
|
||||
}
|
||||
|
||||
function canEditCommunicationLog(fastify, employee, project, item) {
|
||||
if (hasGlobalProjectManage(fastify, employee) || canManageProjectRecord(fastify, employee.id, project)) {
|
||||
return true;
|
||||
}
|
||||
if (item.created_by !== employee.id) {
|
||||
return false;
|
||||
}
|
||||
return Date.now() - new Date(item.created_at).getTime() <= PROJECT_COMMUNICATION_EDIT_WINDOW_MS;
|
||||
}
|
||||
|
||||
async function ensureClosureChecklistBootstrapped(prisma, projectId) {
|
||||
const count = await prisma.projectClosureChecklistItem.count({ where: { project_id: projectId } });
|
||||
if (count > 0) {
|
||||
return false;
|
||||
}
|
||||
await prisma.projectClosureChecklistItem.createMany({
|
||||
data: PROJECT_CLOSURE_TEMPLATE.map((item) => ({
|
||||
project_id: projectId,
|
||||
item_key: item.itemKey,
|
||||
title: item.title,
|
||||
sort_order: item.sortOrder,
|
||||
status: "pending",
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
async function buildProjectCommunicationSummary(prisma, projectId) {
|
||||
const todayStart = startOfUtcDay();
|
||||
const todayEnd = endOfUtcDay();
|
||||
const [totalCount, latest, followUpDueTodayCount, overdueFollowUpCount] = await Promise.all([
|
||||
prisma.projectCommunicationLog.count({ where: { project_id: projectId } }),
|
||||
prisma.projectCommunicationLog.findFirst({ where: { project_id: projectId }, orderBy: [{ happened_at: "desc" }, { updated_at: "desc" }] }),
|
||||
prisma.projectCommunicationLog.count({ where: { project_id: projectId, next_follow_up_date: { gte: todayStart, lte: todayEnd } } }),
|
||||
prisma.projectCommunicationLog.count({ where: { project_id: projectId, next_follow_up_date: { lt: todayStart } } }),
|
||||
]);
|
||||
return {
|
||||
totalCount,
|
||||
latestHappenedAt: latest?.happened_at?.toISOString?.() ?? null,
|
||||
followUpDueTodayCount,
|
||||
overdueFollowUpCount,
|
||||
};
|
||||
}
|
||||
|
||||
async function buildProjectClosureSummary(prisma, projectId) {
|
||||
const items = await prisma.projectClosureChecklistItem.findMany({ where: { project_id: projectId }, select: { status: true } });
|
||||
const pendingCount = items.filter((item) => item.status === "pending").length;
|
||||
const waivedCount = items.filter((item) => item.status === "waived").length;
|
||||
const [openRiskCount, openReimbursementCount, openTravelCount, deliveryRecordCount, contractCount, confidentialDocRefCount] = await Promise.all([
|
||||
prisma.projectRisk.count({ where: { project_id: projectId, status: { not: "closed" } } }),
|
||||
prisma.reimbursementForm.count({ where: { project_id: projectId, status: { notIn: ["paid", "cancelled", "rejected"] } } }),
|
||||
prisma.travelRequest.count({ where: { project_id: projectId, status: { notIn: ["rejected"] } } }),
|
||||
prisma.projectDeliveryRecord.count({ where: { project_id: projectId } }),
|
||||
prisma.contractRegistry.count({ where: { project_id: projectId } }),
|
||||
prisma.confidentialDocumentRef.count({ where: { project_id: projectId } }),
|
||||
]);
|
||||
return {
|
||||
totalCount: items.length,
|
||||
pendingCount,
|
||||
waivedCount,
|
||||
warned: pendingCount > 0,
|
||||
facts: {
|
||||
openRiskCount,
|
||||
openReimbursementCount,
|
||||
openTravelCount,
|
||||
deliveryRecordCount,
|
||||
contractCount,
|
||||
confidentialDocRefCount,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function buildProjectDetailPayload(fastify, request, project) {
|
||||
const [communicationSummary, closureSummary, communicationGate, closureGate] = await Promise.all([
|
||||
buildProjectCommunicationSummary(fastify.prisma, project.id),
|
||||
buildProjectClosureSummary(fastify.prisma, project.id),
|
||||
evaluateFeatureFlag({ prisma: fastify.prisma, config: fastify.config, flagKey: FEATURE_FLAG_KEYS.projectCommunicationLog, departmentId: request.employee.department_id ?? null, strictDepartment: false }),
|
||||
evaluateFeatureFlag({ prisma: fastify.prisma, config: fastify.config, flagKey: FEATURE_FLAG_KEYS.projectClosureChecklist, departmentId: request.employee.department_id ?? null, strictDepartment: false }),
|
||||
]);
|
||||
return {
|
||||
...mapProjectDetail(project),
|
||||
communicationSummary,
|
||||
closureSummary,
|
||||
capabilities: {
|
||||
communicationLogEnabled: communicationGate.enabled,
|
||||
closureChecklistEnabled: closureGate.enabled,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function mapProjectDetail(project) {
|
||||
return {
|
||||
id: project.id,
|
||||
@@ -252,6 +428,8 @@ function mapProjectDetail(project) {
|
||||
travelRequests: project._count?.travel_requests ?? 0,
|
||||
todoItems: project._count?.todo_items ?? 0,
|
||||
weeklyReports: project._count?.weekly_reports ?? 0,
|
||||
communicationLogs: project._count?.communication_logs ?? 0,
|
||||
closureChecklistItems: project._count?.closure_checklist_items ?? 0,
|
||||
contracts: project._count?.contracts ?? 0,
|
||||
deliveries: project._count?.deliveries ?? 0,
|
||||
documentRefs: project._count?.document_refs ?? 0,
|
||||
@@ -405,25 +583,18 @@ async function projectsRoutes(fastify) {
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
owner: { select: { id: true, employee_no: true, name: true } },
|
||||
manager: { select: { id: true, employee_no: true, name: true } },
|
||||
members: { where: { left_at: null }, include: { employee: { select: { id: true, employee_no: true, name: true } } } },
|
||||
milestones: true,
|
||||
tasks: { include: { assignee: { select: { id: true, employee_no: true, name: true } }, creator: { select: { id: true, employee_no: true, name: true } } } },
|
||||
risks: { include: { owner: { select: { id: true, employee_no: true, name: true } } } },
|
||||
_count: { select: { members: true, milestones: true, tasks: true, risks: true, reimbursements: true, travel_requests: true, todo_items: true, weekly_reports: true, contracts: true, deliveries: true, document_refs: true } },
|
||||
},
|
||||
include: buildProjectDetailInclude(),
|
||||
});
|
||||
await writeAudit(fastify, request, "PROJECT_CREATED", created.id, { projectNo: created.project_no });
|
||||
return reply.code(201).send({ requestId: request.id, data: { item: mapProjectDetail(created) } });
|
||||
const payload = await buildProjectDetailPayload(fastify, request, created);
|
||||
return reply.code(201).send({ requestId: request.id, data: { item: payload } });
|
||||
});
|
||||
|
||||
fastify.get("/projects/:id", { preHandler: fastify.authenticate }, async (request, reply) => {
|
||||
await ensureFeatureEnabled(fastify, request, FEATURE_FLAG_KEYS.projectDomain);
|
||||
const projectId = parseId(request.params?.id);
|
||||
const project = await ensureReadableProject(fastify, request, projectId);
|
||||
return sendData(reply, request, { item: mapProjectDetail(project) });
|
||||
return sendData(reply, request, { item: await buildProjectDetailPayload(fastify, request, project) });
|
||||
});
|
||||
|
||||
fastify.patch("/projects/:id", { preHandler: fastify.authenticate }, async (request, reply) => {
|
||||
@@ -431,6 +602,11 @@ async function projectsRoutes(fastify) {
|
||||
const projectId = parseId(request.params?.id);
|
||||
await ensureManageableProject(fastify, request, projectId);
|
||||
const body = parseBody(PROJECT_PATCH_SCHEMA, request.body);
|
||||
const wantsClosureWarning = ["completed", "archived"].includes(body.status ?? "");
|
||||
if (wantsClosureWarning) {
|
||||
await ensureFeatureEnabled(fastify, request, FEATURE_FLAG_KEYS.projectClosureChecklist);
|
||||
await ensureClosureChecklistBootstrapped(fastify.prisma, projectId);
|
||||
}
|
||||
const updated = await fastify.prisma.project.update({
|
||||
where: { id: projectId },
|
||||
data: {
|
||||
@@ -447,27 +623,32 @@ async function projectsRoutes(fastify) {
|
||||
...(body.summary !== undefined ? { summary: body.summary ?? null } : {}),
|
||||
...(body.isConfidential !== undefined ? { is_confidential: body.isConfidential } : {}),
|
||||
},
|
||||
include: {
|
||||
owner: { select: { id: true, employee_no: true, name: true } },
|
||||
manager: { select: { id: true, employee_no: true, name: true } },
|
||||
members: { where: { left_at: null }, include: { employee: { select: { id: true, employee_no: true, name: true } } } },
|
||||
milestones: true,
|
||||
tasks: { include: { assignee: { select: { id: true, employee_no: true, name: true } }, creator: { select: { id: true, employee_no: true, name: true } } } },
|
||||
risks: { include: { owner: { select: { id: true, employee_no: true, name: true } } } },
|
||||
_count: { select: { members: true, milestones: true, tasks: true, risks: true, reimbursements: true, travel_requests: true, todo_items: true, weekly_reports: true, contracts: true, deliveries: true, document_refs: true } },
|
||||
},
|
||||
include: buildProjectDetailInclude(),
|
||||
});
|
||||
await writeAudit(fastify, request, "PROJECT_UPDATED", projectId, { fields: Object.keys(body) });
|
||||
return sendData(reply, request, { item: mapProjectDetail(updated) });
|
||||
const item = await buildProjectDetailPayload(fastify, request, updated);
|
||||
const closureWarning = wantsClosureWarning && item.closureSummary.pendingCount > 0
|
||||
? { pendingCount: item.closureSummary.pendingCount, message: `项目仍有 ${item.closureSummary.pendingCount} 项待收口,请尽快补齐。` }
|
||||
: null;
|
||||
return sendData(reply, request, { item, closureWarning });
|
||||
});
|
||||
|
||||
fastify.post("/projects/:id/archive", { preHandler: fastify.authenticate }, async (request, reply) => {
|
||||
await ensureFeatureEnabled(fastify, request, FEATURE_FLAG_KEYS.projectDomain);
|
||||
const projectId = parseId(request.params?.id);
|
||||
await ensureManageableProject(fastify, request, projectId);
|
||||
const updated = await fastify.prisma.project.update({ where: { id: projectId }, data: { status: "archived", actual_end_at: new Date() } });
|
||||
await writeAudit(fastify, request, "PROJECT_ARCHIVED", projectId, {});
|
||||
return sendData(reply, request, { item: { id: updated.id, status: updated.status } });
|
||||
let closureWarning = null;
|
||||
const closureGate = await evaluateFeatureFlag({ prisma: fastify.prisma, config: fastify.config, flagKey: FEATURE_FLAG_KEYS.projectClosureChecklist, departmentId: request.employee.department_id ?? null, strictDepartment: false });
|
||||
if (closureGate.enabled) {
|
||||
await ensureClosureChecklistBootstrapped(fastify.prisma, projectId);
|
||||
}
|
||||
const updated = await fastify.prisma.project.update({ where: { id: projectId }, data: { status: "archived", actual_end_at: new Date() }, include: buildProjectDetailInclude() });
|
||||
const item = await buildProjectDetailPayload(fastify, request, updated);
|
||||
if (closureGate.enabled && item.closureSummary.pendingCount > 0) {
|
||||
closureWarning = { pendingCount: item.closureSummary.pendingCount, message: `项目仍有 ${item.closureSummary.pendingCount} 项待收口,请尽快补齐。` };
|
||||
}
|
||||
await writeAudit(fastify, request, "PROJECT_ARCHIVED", projectId, { warned: Boolean(closureWarning) });
|
||||
return sendData(reply, request, { item, closureWarning });
|
||||
});
|
||||
|
||||
fastify.get("/projects/:id/members", { preHandler: fastify.authenticate }, async (request, reply) => {
|
||||
@@ -692,6 +873,124 @@ async function projectsRoutes(fastify) {
|
||||
return sendData(reply, request, { items: items.map((item) => ({ id: item.id, weeklyReportId: item.weekly_report_id, weekStart: item.weekly_report.week_start?.toISOString?.().slice(0, 10) ?? null, status: item.weekly_report.status, employee: mapEmployeeBasic(item.weekly_report.employee), progressText: item.progress_text, riskText: item.risk_text, nextStepText: item.next_step_text, updatedAt: item.updated_at?.toISOString?.() ?? null })) });
|
||||
});
|
||||
|
||||
fastify.get("/projects/:id/communication-logs", { preHandler: fastify.authenticate }, async (request, reply) => {
|
||||
await ensureFeatureEnabled(fastify, request, FEATURE_FLAG_KEYS.projectCommunicationLog);
|
||||
const projectId = parseId(request.params?.id);
|
||||
const project = await ensureReadableProject(fastify, request, projectId);
|
||||
const items = await fastify.prisma.projectCommunicationLog.findMany({
|
||||
where: { project_id: projectId },
|
||||
orderBy: [{ happened_at: "desc" }, { updated_at: "desc" }],
|
||||
take: 50,
|
||||
include: { creator: { select: { id: true, employee_no: true, name: true } } },
|
||||
});
|
||||
return sendData(reply, request, { items: items.map((item) => mapProjectCommunicationLog(item, canEditCommunicationLog(fastify, request.employee, project, item))) });
|
||||
});
|
||||
|
||||
fastify.post("/projects/:id/communication-logs", { preHandler: fastify.authenticate }, async (request, reply) => {
|
||||
await ensureFeatureEnabled(fastify, request, FEATURE_FLAG_KEYS.projectCommunicationLog);
|
||||
const projectId = parseId(request.params?.id);
|
||||
await ensureReadableProject(fastify, request, projectId);
|
||||
const body = parseBody(COMMUNICATION_LOG_CREATE_SCHEMA, request.body);
|
||||
const created = await fastify.prisma.projectCommunicationLog.create({
|
||||
data: {
|
||||
project_id: projectId,
|
||||
happened_at: new Date(body.happenedAt),
|
||||
channel: body.channel,
|
||||
external_contact_name: body.externalContactName ?? null,
|
||||
external_org_name: body.externalOrgName ?? null,
|
||||
summary: body.summary,
|
||||
next_action: body.nextAction ?? null,
|
||||
next_follow_up_date: parseDateOnly(body.nextFollowUpDate),
|
||||
created_by: request.employee.id,
|
||||
},
|
||||
include: { creator: { select: { id: true, employee_no: true, name: true } } },
|
||||
});
|
||||
await writeAudit(fastify, request, "PROJECT_COMMUNICATION_LOG_CREATED", projectId, { logId: created.id, channel: created.channel });
|
||||
return reply.code(201).send({ requestId: request.id, data: { item: mapProjectCommunicationLog(created, true) } });
|
||||
});
|
||||
|
||||
fastify.patch("/projects/:id/communication-logs/:logId", { preHandler: fastify.authenticate }, async (request, reply) => {
|
||||
await ensureFeatureEnabled(fastify, request, FEATURE_FLAG_KEYS.projectCommunicationLog);
|
||||
const projectId = parseId(request.params?.id);
|
||||
const logId = parseId(request.params?.logId, "logId");
|
||||
const project = await ensureReadableProject(fastify, request, projectId);
|
||||
const current = await fastify.prisma.projectCommunicationLog.findUnique({
|
||||
where: { id: logId },
|
||||
include: { creator: { select: { id: true, employee_no: true, name: true } } },
|
||||
});
|
||||
if (!current || current.project_id !== projectId) {
|
||||
throw new AppError({ code: "SYS_404", message: "Not Found", statusCode: 404 });
|
||||
}
|
||||
if (!canEditCommunicationLog(fastify, request.employee, project, current)) {
|
||||
throw new AppError({ code: "PERM_001", message: "无权限", statusCode: 403, details: { permission: "project.manage" } });
|
||||
}
|
||||
const body = parseBody(COMMUNICATION_LOG_PATCH_SCHEMA, request.body);
|
||||
const updated = await fastify.prisma.projectCommunicationLog.update({
|
||||
where: { id: logId },
|
||||
data: {
|
||||
...(body.happenedAt !== undefined ? { happened_at: new Date(body.happenedAt) } : {}),
|
||||
...(body.channel !== undefined ? { channel: body.channel } : {}),
|
||||
...(body.externalContactName !== undefined ? { external_contact_name: body.externalContactName ?? null } : {}),
|
||||
...(body.externalOrgName !== undefined ? { external_org_name: body.externalOrgName ?? null } : {}),
|
||||
...(body.summary !== undefined ? { summary: body.summary } : {}),
|
||||
...(body.nextAction !== undefined ? { next_action: body.nextAction ?? null } : {}),
|
||||
...(body.nextFollowUpDate !== undefined ? { next_follow_up_date: parseDateOnly(body.nextFollowUpDate) } : {}),
|
||||
},
|
||||
include: { creator: { select: { id: true, employee_no: true, name: true } } },
|
||||
});
|
||||
await writeAudit(fastify, request, "PROJECT_COMMUNICATION_LOG_UPDATED", projectId, { logId });
|
||||
return sendData(reply, request, { item: mapProjectCommunicationLog(updated, canEditCommunicationLog(fastify, request.employee, project, updated)) });
|
||||
});
|
||||
|
||||
fastify.get("/projects/:id/closure-checklist", { preHandler: fastify.authenticate }, async (request, reply) => {
|
||||
await ensureFeatureEnabled(fastify, request, FEATURE_FLAG_KEYS.projectClosureChecklist);
|
||||
const projectId = parseId(request.params?.id);
|
||||
const project = await ensureReadableProject(fastify, request, projectId);
|
||||
await ensureClosureChecklistBootstrapped(fastify.prisma, projectId);
|
||||
const canEdit = hasGlobalProjectManage(fastify, request.employee) || canManageProjectRecord(fastify, request.employee.id, project);
|
||||
const items = await fastify.prisma.projectClosureChecklistItem.findMany({
|
||||
where: { project_id: projectId },
|
||||
orderBy: [{ sort_order: "asc" }, { created_at: "asc" }],
|
||||
include: { completer: { select: { id: true, employee_no: true, name: true } } },
|
||||
});
|
||||
return sendData(reply, request, { items: items.map((item) => mapProjectClosureChecklistItem(item, canEdit)) });
|
||||
});
|
||||
|
||||
fastify.patch("/projects/:id/closure-checklist/:itemId", { preHandler: fastify.authenticate }, async (request, reply) => {
|
||||
await ensureFeatureEnabled(fastify, request, FEATURE_FLAG_KEYS.projectClosureChecklist);
|
||||
const projectId = parseId(request.params?.id);
|
||||
await ensureManageableProject(fastify, request, projectId);
|
||||
await ensureClosureChecklistBootstrapped(fastify.prisma, projectId);
|
||||
const itemId = parseId(request.params?.itemId, "itemId");
|
||||
const current = await fastify.prisma.projectClosureChecklistItem.findUnique({
|
||||
where: { id: itemId },
|
||||
include: { completer: { select: { id: true, employee_no: true, name: true } } },
|
||||
});
|
||||
if (!current || current.project_id !== projectId) {
|
||||
throw new AppError({ code: "SYS_404", message: "Not Found", statusCode: 404 });
|
||||
}
|
||||
const body = parseBody(CLOSURE_CHECKLIST_PATCH_SCHEMA, request.body);
|
||||
const nextStatus = body.status ?? current.status;
|
||||
const nextNote = body.note !== undefined ? (body.note ?? null) : current.note;
|
||||
if (nextStatus === "waived" && !String(nextNote ?? "").trim()) {
|
||||
throw buildValidationError({ note: "waived_requires_note" });
|
||||
}
|
||||
const completedMeta = nextStatus === "pending"
|
||||
? { completed_at: null, completed_by: null }
|
||||
: { completed_at: new Date(), completed_by: request.employee.id };
|
||||
const updated = await fastify.prisma.projectClosureChecklistItem.update({
|
||||
where: { id: itemId },
|
||||
data: {
|
||||
...(body.status !== undefined ? { status: body.status } : {}),
|
||||
...(body.note !== undefined ? { note: body.note ?? null } : {}),
|
||||
...(body.status !== undefined ? completedMeta : {}),
|
||||
},
|
||||
include: { completer: { select: { id: true, employee_no: true, name: true } } },
|
||||
});
|
||||
await writeAudit(fastify, request, "PROJECT_CLOSURE_CHECKLIST_UPDATED", projectId, { itemId, status: updated.status });
|
||||
return sendData(reply, request, { item: mapProjectClosureChecklistItem(updated, true) });
|
||||
});
|
||||
|
||||
fastify.get("/projects/:id/deliveries", { preHandler: fastify.authenticate }, async (request, reply) => {
|
||||
await ensureFeatureEnabled(fastify, request, FEATURE_FLAG_KEYS.projectLinking);
|
||||
const projectId = parseId(request.params?.id);
|
||||
|
||||
+51
-25
@@ -313,23 +313,38 @@ async function searchRoutes(fastify) {
|
||||
where: {
|
||||
OR: [
|
||||
{ contract_no: { contains: q, mode: "insensitive" } },
|
||||
{ counterparty_name: { contains: q, mode: "insensitive" } },
|
||||
{ summary: { contains: q, mode: "insensitive" } },
|
||||
{
|
||||
AND: [
|
||||
{ confidentiality_level: { in: ["public", "internal"] } },
|
||||
{
|
||||
OR: [
|
||||
{ counterparty_name: { contains: q, mode: "insensitive" } },
|
||||
{ summary: { contains: q, mode: "insensitive" } },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{ project: { is: { project_no: { contains: q, mode: "insensitive" } } } },
|
||||
],
|
||||
},
|
||||
take: limit,
|
||||
orderBy: { updated_at: "desc" },
|
||||
select: { id: true, contract_no: true, counterparty_name: true, confidentiality_level: true, summary: true, updated_at: true },
|
||||
}).then((rows) => rows.map((item) => ({
|
||||
entityType: "contract_registry",
|
||||
entityId: item.id,
|
||||
title: item.contract_no,
|
||||
subtitle: ["confidential", "restricted"].includes(item.confidentiality_level) ? "涉密合同台账" : item.counterparty_name,
|
||||
status: item.confidentiality_level,
|
||||
href: "/contracts-registry",
|
||||
matchedBy: matchByValue(q, item.contract_no, item.counterparty_name, item.summary),
|
||||
updatedAt: item.updated_at?.toISOString?.() ?? null,
|
||||
}))),
|
||||
select: { id: true, contract_no: true, counterparty_name: true, confidentiality_level: true, summary: true, updated_at: true, project: { select: { project_no: true } } },
|
||||
}).then((rows) => rows.map((item) => {
|
||||
const isSensitive = ["confidential", "restricted"].includes(item.confidentiality_level);
|
||||
return {
|
||||
entityType: "contract_registry",
|
||||
entityId: item.id,
|
||||
title: item.contract_no,
|
||||
subtitle: isSensitive ? "涉密合同台账" : item.counterparty_name,
|
||||
status: item.confidentiality_level,
|
||||
href: "/contracts-registry",
|
||||
matchedBy: isSensitive
|
||||
? matchByValue(q, item.contract_no, item.project?.project_no)
|
||||
: matchByValue(q, item.contract_no, item.counterparty_name, item.summary, item.project?.project_no),
|
||||
updatedAt: item.updated_at?.toISOString?.() ?? null,
|
||||
};
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -338,24 +353,35 @@ async function searchRoutes(fastify) {
|
||||
fastify.prisma.confidentialDocumentRef.findMany({
|
||||
where: {
|
||||
OR: [
|
||||
{ title: { contains: q, mode: "insensitive" } },
|
||||
{ document_no: { contains: q, mode: "insensitive" } },
|
||||
{ offline_archive_no: { contains: q, mode: "insensitive" } },
|
||||
{ project: { is: { project_no: { contains: q, mode: "insensitive" } } } },
|
||||
{
|
||||
AND: [
|
||||
{ confidentiality_level: { in: ["public", "internal"] } },
|
||||
{ title: { contains: q, mode: "insensitive" } },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
take: limit,
|
||||
orderBy: { updated_at: "desc" },
|
||||
select: { id: true, title: true, document_no: true, confidentiality_level: true, updated_at: true },
|
||||
}).then((rows) => rows.map((item) => ({
|
||||
entityType: "confidential_doc_ref",
|
||||
entityId: item.id,
|
||||
title: item.document_no || item.title,
|
||||
subtitle: ["confidential", "restricted"].includes(item.confidentiality_level) ? "涉密资料引用" : item.title,
|
||||
status: item.confidentiality_level,
|
||||
href: "/contracts-registry",
|
||||
matchedBy: matchByValue(q, item.title, item.document_no),
|
||||
updatedAt: item.updated_at?.toISOString?.() ?? null,
|
||||
}))),
|
||||
select: { id: true, title: true, document_no: true, offline_archive_no: true, confidentiality_level: true, updated_at: true, project: { select: { project_no: true } } },
|
||||
}).then((rows) => rows.map((item) => {
|
||||
const isSensitive = ["confidential", "restricted"].includes(item.confidentiality_level);
|
||||
return {
|
||||
entityType: "confidential_doc_ref",
|
||||
entityId: item.id,
|
||||
title: item.document_no || item.title,
|
||||
subtitle: isSensitive ? "涉密资料引用" : item.title,
|
||||
status: item.confidentiality_level,
|
||||
href: "/contracts-registry",
|
||||
matchedBy: isSensitive
|
||||
? matchByValue(q, item.document_no, item.offline_archive_no, item.project?.project_no)
|
||||
: matchByValue(q, item.title, item.document_no, item.offline_archive_no, item.project?.project_no),
|
||||
updatedAt: item.updated_at?.toISOString?.() ?? null,
|
||||
};
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -331,6 +331,20 @@ const DEFAULT_FEATURE_FLAGS = [
|
||||
department_ids: [],
|
||||
note: "bootstrap default: force_off",
|
||||
},
|
||||
{
|
||||
flag_key: "project_communication_log_v1",
|
||||
override_mode: "force_off",
|
||||
rollout_type: "global",
|
||||
department_ids: [],
|
||||
note: "bootstrap default: force_off",
|
||||
},
|
||||
{
|
||||
flag_key: "project_closure_checklist_v1",
|
||||
override_mode: "force_off",
|
||||
rollout_type: "global",
|
||||
department_ids: [],
|
||||
note: "bootstrap default: force_off",
|
||||
},
|
||||
{
|
||||
flag_key: "confidential_doc_refs_v1",
|
||||
override_mode: "force_off",
|
||||
|
||||
@@ -263,6 +263,11 @@ async function main() {
|
||||
"weekly_report_v1",
|
||||
"employee_lifecycle_v1",
|
||||
"todo_board_v1",
|
||||
"project_domain_v1",
|
||||
"project_linking_v1",
|
||||
"project_communication_log_v1",
|
||||
"project_closure_checklist_v1",
|
||||
"confidential_doc_refs_v1",
|
||||
]) {
|
||||
await ensureFeatureFlag(prisma, {
|
||||
flag_key: flagKey,
|
||||
|
||||
@@ -17,6 +17,8 @@ const FEATURE_FLAG_KEYS = {
|
||||
wecomEntry: "wecom_entry_v1",
|
||||
projectDomain: "project_domain_v1",
|
||||
projectLinking: "project_linking_v1",
|
||||
projectCommunicationLog: "project_communication_log_v1",
|
||||
projectClosureChecklist: "project_closure_checklist_v1",
|
||||
confidentialDocRefs: "confidential_doc_refs_v1",
|
||||
publicSecurityHardening: "public_security_hardening_v1",
|
||||
};
|
||||
@@ -144,6 +146,14 @@ function resolveEnvGate(config, flagKey) {
|
||||
return Boolean(config.projectLinkingEnabled);
|
||||
}
|
||||
|
||||
if (flagKey === FEATURE_FLAG_KEYS.projectCommunicationLog) {
|
||||
return Boolean(config.projectCommunicationLogEnabled);
|
||||
}
|
||||
|
||||
if (flagKey === FEATURE_FLAG_KEYS.projectClosureChecklist) {
|
||||
return Boolean(config.projectClosureChecklistEnabled);
|
||||
}
|
||||
|
||||
if (flagKey === FEATURE_FLAG_KEYS.confidentialDocRefs) {
|
||||
return Boolean(config.confidentialDocRefsEnabled);
|
||||
}
|
||||
|
||||
@@ -85,8 +85,9 @@ function redactImMessage(config, payload) {
|
||||
}
|
||||
|
||||
if (effectiveType === 'project') {
|
||||
const genericTitle = rawTitle.includes('收口') ? '有项目待收口' : '有项目待跟进';
|
||||
return {
|
||||
title: rawTitle || '项目待处理事项',
|
||||
title: genericTitle,
|
||||
body: '',
|
||||
};
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户