import { searchCorporations } from "../../../domains/assist-platform/services.js"; import { numberOption, 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 handleSearch( parsed: CliParsedArgs, runtime: CliRuntime ): Promise { const client = resolveAssistClient(parsed, runtime); const keyword = parsed.args[0] || stringOption(parsed.options, ["keyword", "query", "q", "name", "id"]) || ""; const count = numberOption(parsed.options, ["count", "limit", "n"]) || 20; const start = numberOption(parsed.options, ["start", "offset"]) || 0; const state = stringOption(parsed.options, ["state", "status"]); const res = await searchCorporations(client, { keyword: keyword.trim() || undefined, state: state?.trim() || undefined, limit: { start, count }, }); if (runtime.jsonMode) { return { stdout: printJson(res, runtime.outputOptions), stderr: "", exitCode: 0, }; } if (res.items.length === 0) { return { stdout: `协助平台企业库中未找到匹配 "${keyword}" 的企业记录。\n`, stderr: "", exitCode: 0, }; } const rows = res.items.map((c, i) => [ String(start + i + 1), c.id, c.name, c.platformName || "app", c.state || "-", c.payType === "TRYOUT" ? "试用" : c.payType === "PAY" ? "付费" : c.payType || "-", c.sumPeople !== null && c.sumPeople !== undefined ? String(c.sumPeople) : "-", c.tel || "-", ]); const table = printTable( ["#", "企业 ID", "企业名称", "集群", "状态", "类型", "授权人数", "联系电话"], rows ); return { stdout: `====== 合思协助平台企业搜索结果 (共匹配 ${res.count} 家,当前显示 ${res.items.length} 条) ======\n${table}\n\n提示: 可使用 hose-use assist-platform tickets <企业ID> 查询协助工单\n`, stderr: "", exitCode: 0, }; }