feat(assist): 支持协助工单权限转交 (transfer) 并实测交接给陈龙
- 实现 domains/assist-platform 转交 API: searchTransferCandidatesApi (POST /api/userRole/search) 与 transferAssistTicketApi (POST /api/assistPlatform/transfer) - 提供智能接收人解析 (resolveTransferRecipient): 支持姓名模糊匹配、工号或账号精确匹配 - 实现 CLI 命令 hose-use assist-platform transfer: 支持 --candidates 人员字典查询与 --dry-run 安全预览 - 实测将沈玥妍测试企业有效工单 ID01Xenwiu9w0D 成功转交至陈龙 (chenlong3016, 工号 3016) - 补充 domains 与 cli 全套单元测试并在 SKILL.md 与 assist-platform.md 沉淀转交指南
This commit is contained in:
1 parent
82fa0fca0c
commit
7a396f8a95
11 files changed
+1036
-473
No files matched your search
@@ -783,6 +783,7 @@ export const COMMAND_METADATA: Record<string, CliCommandMetadata> = {
|
||||
"apply": "向目标企业发起新的协助授权工单申请",
|
||||
"approve": "审批通过协助授权工单申请(端内管理员授权)",
|
||||
"enter": "一键换取免密直通链接并落盘为本地工作企业",
|
||||
"transfer": "转交协助工单权限给其他同事",
|
||||
"help": "查看帮助信息"
|
||||
},
|
||||
"aliases": [
|
||||
@@ -811,11 +812,14 @@ export const COMMAND_METADATA: Record<string, CliCommandMetadata> = {
|
||||
"pass": "approve",
|
||||
"import": "enter",
|
||||
"token": "enter",
|
||||
"get-token": "enter"
|
||||
"get-token": "enter",
|
||||
"transfer": "transfer",
|
||||
"transmit": "transfer",
|
||||
"forward": "transfer"
|
||||
},
|
||||
flags: {
|
||||
...flagList("token t user name u hose-token jwt ticket ticket-id auth-code staff alias corp-name count limit n start offset state status corpid id keyword query q message msg reason matter hours hour duration days day", "value"),
|
||||
...flagList("logout admin save import persist switch current overwrite", "boolean")
|
||||
...flagList("token t user name u hose-token jwt ticket ticket-id auth-code staff alias corp-name count limit n start offset state status corpid id keyword query q message msg reason matter hours hour duration days day to recipient target remarks comment corp", "value"),
|
||||
...flagList("logout admin save import persist switch current overwrite candidates list-candidates", "boolean")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -217,4 +217,47 @@ describe("CLI Commands - assist-platform (合思协助平台)", () => {
|
||||
expect(res.stdout).toContain("[DRY-RUN]");
|
||||
expect(res.stdout).toContain("24 小时");
|
||||
});
|
||||
|
||||
it("assist-platform transfer 缺少 --to 参数时报错提示", async () => {
|
||||
saveAssistPlatformSession({
|
||||
token: "mock-token",
|
||||
userName: "测试人员",
|
||||
baseUrl: "https://unity.ekuaibao.com/api",
|
||||
updatedAt: Date.now(),
|
||||
});
|
||||
|
||||
const runtime = createMockRuntime(tempDir);
|
||||
const parsed: CliParsedArgs = {
|
||||
action: "transfer",
|
||||
args: ["ID01ofWoOC1wiX"],
|
||||
options: {},
|
||||
raw: ["assist-platform", "transfer", "ID01ofWoOC1wiX"],
|
||||
};
|
||||
|
||||
const res = await handleAssistPlatformCommand(parsed, runtime);
|
||||
expect(res.exitCode).toBe(1);
|
||||
expect(res.stderr).toContain("必须通过 --to 指定接收人员姓名、工号或账号");
|
||||
});
|
||||
|
||||
it("assist-platform transfer --dry-run 能够输出工单转交变更预览", async () => {
|
||||
saveAssistPlatformSession({
|
||||
token: "mock-token",
|
||||
userName: "测试人员",
|
||||
baseUrl: "https://unity.ekuaibao.com/api",
|
||||
updatedAt: Date.now(),
|
||||
});
|
||||
|
||||
const runtime = createMockRuntime(tempDir);
|
||||
const parsed: CliParsedArgs = {
|
||||
action: "transfer",
|
||||
args: ["ID01ofWoOC1wiX", "ID01Xenwiu9w0D"],
|
||||
options: { to: "陈龙", dryRun: true },
|
||||
raw: ["assist-platform", "transfer", "ID01ofWoOC1wiX", "ID01Xenwiu9w0D", "--to", "陈龙", "--dry-run"],
|
||||
};
|
||||
|
||||
const res = await handleAssistPlatformCommand(parsed, runtime);
|
||||
expect(res.stdout).toContain("[DRY-RUN]");
|
||||
expect(res.stdout).toContain("ID01Xenwiu9w0D");
|
||||
expect(res.stdout).toContain("陈龙");
|
||||
});
|
||||
});
|
||||
@@ -7,6 +7,7 @@ import { handleStaff } from "./staff.js";
|
||||
import { handleEnter } from "./enter.js";
|
||||
import { handleApply } from "./apply.js";
|
||||
import { handleApprove } from "./approve.js";
|
||||
import { handleTransfer } from "./transfer.js";
|
||||
|
||||
export async function handleAssistPlatformCommand(
|
||||
parsed: CliParsedArgs,
|
||||
@@ -59,6 +60,11 @@ export async function handleAssistPlatformCommand(
|
||||
case "pass":
|
||||
return handleApprove(parsed, runtime);
|
||||
|
||||
case "transfer":
|
||||
case "transmit":
|
||||
case "forward":
|
||||
return handleTransfer(parsed, runtime);
|
||||
|
||||
case "help":
|
||||
case "--help":
|
||||
case "-h":
|
||||
@@ -84,6 +90,7 @@ function printHelp(): CliResult {
|
||||
apply <企业ID> 向目标企业发起新的协助授权工单申请(待客户管理员审批)
|
||||
approve [工单ID] 审批通过协助授权工单申请(端内管理员通过授权)
|
||||
enter <企业ID> 一键换取协助免密直通链接并进入(可选 --save 落盘为本地工作企业)
|
||||
transfer <企业ID> 转交协助工单权限给其他同事(可指定 --to 与 --ticket,支持 --candidates 查询人员)
|
||||
|
||||
常用选项:
|
||||
--token, -t <TOKEN> 显式指定当前操作使用的协助平台 Token
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
import {
|
||||
listAssistTickets,
|
||||
listTransferCandidates,
|
||||
resolveTransferRecipient,
|
||||
transferAssistTicket,
|
||||
} from "../../../domains/assist-platform/services.js";
|
||||
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../../mutation.js";
|
||||
import { booleanOption, stringOption } from "../../parser.js";
|
||||
import { printJson, printKeyValue } from "../../printer.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
import { resolveAssistClient } from "./common.js";
|
||||
|
||||
export async function handleTransfer(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const client = resolveAssistClient(parsed, runtime);
|
||||
const isListMode = booleanOption(parsed.options, ["candidates", "list-candidates"]);
|
||||
|
||||
// 1. 列出可转交候选人员清单
|
||||
if (isListMode) {
|
||||
const keyword = stringOption(parsed.options, ["keyword", "query", "q", "name"]) || parsed.args[0];
|
||||
const candidates = await listTransferCandidates(client, keyword);
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson({ count: candidates.length, items: candidates }),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
if (candidates.length === 0) {
|
||||
return {
|
||||
stdout: `未找到匹配的可转交人员${keyword ? ` (关键词: ${keyword})` : ""}。\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const lines = candidates.map(
|
||||
(c) => ` • ${c.name.padEnd(8, " ")} | 账号: ${c.id.padEnd(16, " ")} | 工号: ${c.code || "-"} | 角色: ${c.roles.join("、") || "-"}`
|
||||
);
|
||||
|
||||
return {
|
||||
stdout:
|
||||
`====== 协助平台可转交人员列表 (共 ${candidates.length} 人) ======\n` +
|
||||
lines.join("\n") +
|
||||
"\n",
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// 2. 转交指定工单
|
||||
const targetCorpId = parsed.args[0] || stringOption(parsed.options, ["corp", "corpid", "id"]);
|
||||
const targetRecipient = stringOption(parsed.options, ["to", "recipient", "target", "user", "name"]);
|
||||
const remarks = stringOption(parsed.options, ["remarks", "message", "msg", "comment"]);
|
||||
|
||||
if (!targetCorpId) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr:
|
||||
"[ERROR] 必须指定企业 ID 或工单编号。\n" +
|
||||
"用法:\n" +
|
||||
" hose-use assist-platform transfer <企业ID> [--ticket <工单号>] --to <姓名|工号|账号> [--remarks <备注>] --yes\n" +
|
||||
" hose-use assist-platform transfer --candidates [关键词] (查看可转交人员列表)\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
if (!targetRecipient) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr:
|
||||
"[ERROR] 必须通过 --to 指定接收人员姓名、工号或账号。\n" +
|
||||
"可运行 hose-use assist-platform transfer --candidates 查询人员名录。\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
// 解析工单编号:如果 args[1] 提供了则用 args[1],或 --ticket,否则自动在指定企业中查找当前生效中的工单
|
||||
let ticketId = parsed.args[1] || stringOption(parsed.options, ["ticket", "ticket-id"]);
|
||||
let resolvedRecipient;
|
||||
|
||||
try {
|
||||
resolvedRecipient = await resolveTransferRecipient(client, targetRecipient);
|
||||
} catch (err) {
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
resolvedRecipient = {
|
||||
id: targetRecipient,
|
||||
name: targetRecipient,
|
||||
userRoleId: "",
|
||||
roles: [],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `[ERROR] ${err instanceof Error ? err.message : String(err)}\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (!ticketId) {
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
ticketId = "PREVIEW-ACTIVE-TICKET";
|
||||
} else {
|
||||
const tickets = await listAssistTickets(client, targetCorpId);
|
||||
const activeTicket = tickets.find((t) => t.state === "已提供" || t.state === "1");
|
||||
if (!activeTicket) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `[ERROR] 企业 ${targetCorpId} 下未找到处于“已提供”生效状态的协助工单。\n可通过 hose-use assist-platform tickets ${targetCorpId} 查看历史工单。\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
ticketId = activeTicket.ticketId;
|
||||
}
|
||||
}
|
||||
|
||||
const operation = "协助工单转交";
|
||||
const target = `企业 ${targetCorpId} 的工单 [${ticketId}] 转交给 ${resolvedRecipient.name} (${resolvedRecipient.id})`;
|
||||
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
return mutationPreview(parsed, runtime, operation, target, {
|
||||
ticketId,
|
||||
recipientId: resolvedRecipient.id,
|
||||
recipientName: resolvedRecipient.name,
|
||||
recipientCode: resolvedRecipient.code,
|
||||
remarks,
|
||||
});
|
||||
}
|
||||
|
||||
requireMutationConfirmation(
|
||||
parsed,
|
||||
runtime,
|
||||
operation,
|
||||
`hose-use assist-platform transfer ${targetCorpId} ${ticketId} --to "${resolvedRecipient.name}" --yes`
|
||||
);
|
||||
|
||||
const result = await transferAssistTicket(client, {
|
||||
ticketId,
|
||||
recipient: resolvedRecipient.id,
|
||||
remarks,
|
||||
});
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson({
|
||||
success: true,
|
||||
ticketId,
|
||||
corpId: targetCorpId,
|
||||
recipient: resolvedRecipient,
|
||||
remarks,
|
||||
}),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const pairs: Record<string, string> = {
|
||||
转交状态: "🟢 转交成功",
|
||||
目标工单: ticketId,
|
||||
所属企业: targetCorpId,
|
||||
转交接收人: `${resolvedRecipient.name} (${resolvedRecipient.id}${resolvedRecipient.code ? `, 工号: ${resolvedRecipient.code}` : ""})`,
|
||||
};
|
||||
if (remarks) pairs["转交备注"] = remarks;
|
||||
|
||||
return {
|
||||
stdout: `[SUCCESS] 协助工单转交成功!\n${printKeyValue(pairs)}\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user