71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
import { listAssistTickets } from "../../../domains/assist-platform/services.js";
|
|
import { booleanOption, stringOption } from "../../parser.js";
|
|
import { printJson, printTable } from "../../printer.js";
|
|
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
|
import { resolveAssistClient } from "./common.js";
|
|
|
|
export async function handleTickets(
|
|
parsed: CliParsedArgs,
|
|
runtime: CliRuntime
|
|
): Promise<CliResult> {
|
|
const client = resolveAssistClient(parsed, runtime);
|
|
const isAll = booleanOption(parsed.options, ["all", "a"], false);
|
|
const corpId =
|
|
parsed.args[0] ||
|
|
stringOption(parsed.options, ["corp", "corpid", "id"]) ||
|
|
runtime.selectedCorp?.id;
|
|
|
|
if (!corpId) {
|
|
return {
|
|
stdout: "",
|
|
stderr: "用法: hose-use assist-platform tickets <企业ID> [--all]\n示例: hose-use assist-platform tickets Cxa3oOtQi2eS$g\n",
|
|
exitCode: 1,
|
|
};
|
|
}
|
|
|
|
const tickets = await listAssistTickets(client, corpId);
|
|
|
|
if (runtime.jsonMode) {
|
|
return {
|
|
stdout: printJson({ corporationId: corpId, count: tickets.length, all: isAll, tickets }, runtime.outputOptions),
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
if (tickets.length === 0) {
|
|
return {
|
|
stdout: `企业 [${corpId}] 协助中心未查询到任何协助工单记录。\n`,
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
const rows = tickets.map((t, i) => [
|
|
String(i + 1),
|
|
t.ticketId,
|
|
t.applicant,
|
|
t.principal || "-",
|
|
t.state === "已提供" || t.state === "1"
|
|
? "🟢 生效中"
|
|
: t.state === "待提供" || t.state === "0"
|
|
? "🟡 待提供"
|
|
: t.state === "已过期" || t.state === "2"
|
|
? "⚪ 已结束"
|
|
: t.state,
|
|
t.duration ? `${t.duration}h` : "-",
|
|
t.usePeriodDesc || (t.startTime && t.endTime ? `${new Date(t.startTime).toLocaleDateString()} - ${new Date(t.endTime).toLocaleDateString()}` : "-"),
|
|
]);
|
|
|
|
const table = printTable(
|
|
["#", "授权码 (Ticket ID)", "申请人", "负责人", "工单状态", "时长", "有效期限"],
|
|
rows
|
|
);
|
|
|
|
return {
|
|
stdout: `====== 企业 [${corpId}] 协助工单列表 (共 ${tickets.length} 条) ======\n${table}\n\n操作提示:\n - 一键管理员直通调试: hose-use assist-platform enter ${corpId} --save --yes\n - 一键指定员工身份进入: hose-use assist-platform enter ${corpId} --staff <员工姓名> --save --yes\n`,
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|