import { findStaff } from "../../../domains/assist-platform/services.js"; import { 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 handleStaff( parsed: CliParsedArgs, runtime: CliRuntime ): Promise { const client = resolveAssistClient(parsed, runtime); const corpId = parsed.args[0] || stringOption(parsed.options, ["corp", "corpid", "id"]) || runtime.selectedCorp?.id; const staffName = parsed.args[1] || stringOption(parsed.options, ["name", "user", "staff"]); if (!corpId || !staffName) { return { stdout: "", stderr: "用法: hose-use assist-platform staff <企业ID> <员工姓名>\n示例: hose-use assist-platform staff Cxa3oOtQi2eS$g 李志财\n", exitCode: 1, }; } const staffList = await findStaff(client, corpId, staffName); if (runtime.jsonMode) { return { stdout: printJson({ corporationId: corpId, queryName: staffName, items: staffList }, runtime.outputOptions), stderr: "", exitCode: 0, }; } if (staffList.length === 0) { return { stdout: `企业 [${corpId}] 中未找到名为 "${staffName}" 的员工。\n`, stderr: "", exitCode: 0, }; } const rows = staffList.map((s, i) => [ String(i + 1), s.name, s.code || "-", s.admin ? "👑 是" : "否", s.cellphone || "-", s.email || "-", s.id, ]); const table = printTable( ["#", "姓名", "工号", "管理员", "手机号码", "邮箱地址", "员工全局 ID (Staff ID)"], rows ); return { stdout: `====== 企业 [${corpId}] 员工查询结果 ("${staffName}") ======\n${table}\n\n操作提示: 可使用 hose-use assist-platform enter ${corpId} --staff ${staffName} --save --yes 一键换票导入\n`, stderr: "", exitCode: 0, }; }