- 彻底移除旧内部狭隘命名与垫片包袱,一步到位全仓整体重命名: * session-client.ts ➔ hose-web-session-client.ts (合思 Web 主站会话客户端) * script-engine-client.ts ➔ piper-workflow-client.ts (Piper 工作流引擎客户端) * unity-client.ts ➔ unity-easo-client.ts (Unity / EASO 运营中台与动态集群客户端) * sso-client.ts ➔ sso-auth-client.ts (SSO 与扫码鉴权客户端) - 新增 hose-docs-client.ts 纳为第 7 大通信底座客户端,收口 docs.ekuaibao.com 文档站点通信 - 端正 Piper 工作流引擎定位,完整覆盖工作流创建、保存、发布、108 类节点编排与 Job 流转 - 彻底整体替换全仓 import 引用与测试套件,新增 clients-semantics.test.ts 自动化校验 - 全量自动化测试 150 files 1155 tests 全部通过,类型检查零错误
74 lines
3.5 KiB
TypeScript
74 lines
3.5 KiB
TypeScript
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
|
||
import { booleanOption, numberOption, stringOption } from "../parser.js";
|
||
import { printJson, printTable } from "../printer.js";
|
||
import { createSessionClient } from "../../core/http/hose-web-session-client.js";
|
||
import { listTasks } from "../../domains/task/tools.js";
|
||
import type { TaskView } from "../../domains/task/types.js";
|
||
|
||
function dateOption(value: string | undefined): number | undefined {
|
||
if (!value) return undefined;
|
||
const numeric = Number(value);
|
||
if (Number.isFinite(numeric)) return numeric;
|
||
const parsed = Date.parse(value);
|
||
return Number.isNaN(parsed) ? undefined : parsed;
|
||
}
|
||
|
||
export async function handleTaskCommand(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||
const corp = runtime.selectedCorp;
|
||
if (!corp) throw new Error("未指定或未找到有效企业。请运行 hose-use corps list 或指定 --corp=<id>");
|
||
const action = parsed.action || parsed.args[0] || "todo";
|
||
const view: TaskView | undefined = action === "todo" || action === "pending"
|
||
? "todo"
|
||
: action === "approved" || action === "done"
|
||
? "approved"
|
||
: action === "processed" || action === "records" || action === "history"
|
||
? "processed"
|
||
: action === "cc" || action === "carboncopy" || action === "carbon-copy"
|
||
? "cc"
|
||
: action === "submitted" || action === "mine" || action === "created"
|
||
? "submitted"
|
||
: undefined;
|
||
if (!view) {
|
||
throw new Error("未知 task 子命令。支持: todo, approved, records, submitted, cc");
|
||
}
|
||
const count = numberOption(parsed.options, ["count", "limit", "n"], 20);
|
||
const start = numberOption(parsed.options, ["start", "offset"], 0);
|
||
const staffId = stringOption(parsed.options, ["staff", "staff-id", "staffId"]);
|
||
const from = dateOption(stringOption(parsed.options, ["from", "start-date"]));
|
||
const to = dateOption(stringOption(parsed.options, ["to", "end-date"]));
|
||
const read = booleanOption(parsed.options, ["read"]);
|
||
const unread = booleanOption(parsed.options, ["unread"]);
|
||
// Carbon copy defaults to unread, while the other views do not use this flag.
|
||
const readFilter = view === "cc" ? read && !unread : undefined;
|
||
const result = await listTasks(await createSessionClient(corp), corp.corpId || corp.id, view, { start, count, staffId, from, to, read: readFilter });
|
||
|
||
if (runtime.jsonMode) {
|
||
return { stdout: printJson({ corpId: corp.corpId || corp.id, corpName: corp.name, ...result }, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||
}
|
||
const headers = ["#", "任务 ID", "单号", "标题", "模板", "提交人", "金额", "状态", "当前节点", "动作"];
|
||
const rows = result.items.map((item, index) => [
|
||
index + 1,
|
||
item.taskId,
|
||
item.billCode || "-",
|
||
item.title || "-",
|
||
item.templateName || "-",
|
||
item.submitter ? `${item.submitter.name || "-"}${item.submitter.code ? `(${item.submitter.code})` : ""}` : "-",
|
||
item.amount ? `${item.amount.symbol || ""}${item.amount.value} ${item.amount.currency || ""}`.trim() : "-",
|
||
item.state || "-",
|
||
item.nodeName || "-",
|
||
item.action || "-",
|
||
]);
|
||
const labels: Record<TaskView, string> = {
|
||
todo: "待审批",
|
||
approved: "已审批",
|
||
processed: "审批记录",
|
||
submitted: "我发起的",
|
||
cc: readFilter ? "抄送(已读)" : "抄送(未读)",
|
||
};
|
||
return {
|
||
stdout: `====== ${labels[view]}任务 (企业: ${corp.name} | 总数: ${result.total} | 当前返回: ${result.items.length}) ======\n${printTable(headers, rows)}\n`,
|
||
stderr: "",
|
||
exitCode: 0,
|
||
};
|
||
}
|