refactor(workbench): simplify appointment tasks
This commit is contained in:
@@ -87,50 +87,13 @@ const runtimeLatestAnalysisSchema = z.object({
|
||||
map_payload: z.unknown().nullable()
|
||||
});
|
||||
|
||||
const runtimeWorkOrderStageSchema = z.object({
|
||||
id: z.string().trim().min(1),
|
||||
const runtimeWorkOrderActivitySchema = z.object({
|
||||
sequence: z.number().int().positive(),
|
||||
occurred_at: z.string().datetime({ offset: true }),
|
||||
actor: z.string().trim().min(1),
|
||||
kind: z.enum(["created", "updated", "feedback"]),
|
||||
title: z.string().trim().min(1),
|
||||
status: z.enum(["done", "current", "pending", "blocked", "skipped"]),
|
||||
owner: z.string().trim().min(1),
|
||||
time_label: z.string().trim().min(1),
|
||||
description: z.string().trim().min(1)
|
||||
});
|
||||
|
||||
const runtimeWorkOrderSubtaskSchema = z.object({
|
||||
id: z.string().trim().min(1),
|
||||
title: z.string().trim().min(1),
|
||||
summary: z.string().trim().min(1),
|
||||
status: z.enum(["pending", "running", "blocked", "completed", "cancelled"]),
|
||||
scheduled_at: z.string().datetime({ offset: true }),
|
||||
location: z.string().trim().min(1),
|
||||
assignee: z.string().trim().min(1),
|
||||
duration_minutes: z.number().int().positive(),
|
||||
reply_window_minutes: z.number().int().positive(),
|
||||
stages: z.array(runtimeWorkOrderStageSchema).min(1),
|
||||
reply_requirements: z.array(z.string().trim().min(1))
|
||||
}).superRefine((subtask, context) => {
|
||||
if (subtask.stages.some((stage, index) => stage.sequence !== index + 1)) {
|
||||
context.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "子任务阶段序号必须从 1 连续递增",
|
||||
path: ["stages"]
|
||||
});
|
||||
}
|
||||
if (new Set(subtask.stages.map((stage) => stage.id)).size !== subtask.stages.length) {
|
||||
context.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "子任务阶段编号不能重复",
|
||||
path: ["stages"]
|
||||
});
|
||||
}
|
||||
if (subtask.stages.filter((stage) => stage.status === "current").length > 1) {
|
||||
context.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "单个子任务最多只能有一个当前阶段",
|
||||
path: ["stages"]
|
||||
});
|
||||
}
|
||||
detail: z.string().trim().min(1)
|
||||
});
|
||||
|
||||
const runtimeWorkOrderSchema = z.object({
|
||||
@@ -147,16 +110,11 @@ const runtimeWorkOrderSchema = z.object({
|
||||
duration_minutes: z.number().int().positive(),
|
||||
source: z.string().trim().min(1),
|
||||
dispatcher: z.string().trim().min(1),
|
||||
location: z.string().trim().min(1).nullable().default(null),
|
||||
assignee: z.string().trim().min(1).nullable().default(null),
|
||||
priority: z.enum(["normal", "urgent"]),
|
||||
subtasks: z.array(runtimeWorkOrderSubtaskSchema).min(1)
|
||||
}).superRefine((workOrder, context) => {
|
||||
if (new Set(workOrder.subtasks.map((subtask) => subtask.id)).size !== workOrder.subtasks.length) {
|
||||
context.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "工单子任务编号不能重复",
|
||||
path: ["subtasks"]
|
||||
});
|
||||
}
|
||||
feedback_requirements: z.array(z.string().trim().min(1)).default([]),
|
||||
activity: z.array(runtimeWorkOrderActivitySchema).default([])
|
||||
});
|
||||
|
||||
const runtimeSnapshotSchema = z.object({
|
||||
@@ -278,26 +236,16 @@ export function parseWorkbenchRuntimeSnapshot(payload: unknown): WorkbenchRuntim
|
||||
dispatcher: workOrder.dispatcher,
|
||||
priority: workOrder.priority,
|
||||
dataSource: "backend",
|
||||
subtasks: workOrder.subtasks.map((subtask) => ({
|
||||
id: subtask.id,
|
||||
title: subtask.title,
|
||||
summary: subtask.summary,
|
||||
status: subtask.status,
|
||||
scheduledAt: subtask.scheduled_at,
|
||||
location: subtask.location,
|
||||
assignee: subtask.assignee,
|
||||
durationMinutes: subtask.duration_minutes,
|
||||
replyWindowMinutes: subtask.reply_window_minutes,
|
||||
stages: subtask.stages.map((stage) => ({
|
||||
id: stage.id,
|
||||
sequence: stage.sequence,
|
||||
title: stage.title,
|
||||
status: stage.status,
|
||||
owner: stage.owner,
|
||||
timeLabel: stage.time_label,
|
||||
description: stage.description
|
||||
})),
|
||||
replyRequirements: subtask.reply_requirements
|
||||
location: workOrder.location ?? undefined,
|
||||
assignee: workOrder.assignee ?? undefined,
|
||||
feedbackRequirements: workOrder.feedback_requirements,
|
||||
activity: workOrder.activity.map((entry) => ({
|
||||
sequence: entry.sequence,
|
||||
occurredAt: entry.occurred_at,
|
||||
actor: entry.actor,
|
||||
kind: entry.kind,
|
||||
title: entry.title,
|
||||
detail: entry.detail
|
||||
}))
|
||||
}))
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user