feat(bill): add pure-API create and submit commands

- bill create: 按模板创建草稿(最小表单 + 一条费用明细,版本化 specificationId)
- bill submit: plans/computed 计算审批计划 → freeflow.submit(未指派节点需显式 --approver)
- 文档与 Skill 路由同步
This commit is contained in:
gitea committed 2026-10-23 17:38:12 +08:00
1 parent 1de9e3f552
commit 3c00a0c0a6
9 files changed
+920 -442

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
import { createBillDraft } from "../../../domains/bill/create.js";
import { isDryRun } from "../../mutation.js";
import { stringOption } from "../../parser.js";
import { printJson } from "../../printer.js";
import type { CliResult } from "../../types.js";
import type { BillActionContext } from "./context.js";
/**
* `hose-use bill create --template <模板ID> [--title=...] [--amount=0.01] [--reason=...] [--dry-run] --yes`
*
* 纯接口创建草稿:最小表头 + 一条费用明细,创建后不提交。
*/
export async function handleCreate(ctx: BillActionContext): Promise<CliResult> {
const { parsed, runtime, corpId } = ctx;
const templateId = stringOption(parsed.options, ["template", "spec", "specification"]);
if (!templateId) {
throw new Error("请通过 --template 指定单据模板 ID: hose-use bill create --template <ID> --yes");
}
const title = stringOption(parsed.options, ["title"]);
const amount = stringOption(parsed.options, ["amount"]) ?? "0.01";
const reason = stringOption(parsed.options, ["reason"]);
const feeTypeName = stringOption(parsed.options, ["fee-type", "feeType"]);
if (isDryRun(parsed, runtime)) {
const preview = { template: templateId, title: title ?? "(模板名称)", amount, reason: reason ?? "", feeType: feeTypeName ?? "简单费用" };
if (runtime.jsonMode) {
return { stdout: printJson({ dryRun: true, ...preview }, runtime.outputOptions), stderr: "", exitCode: 0 };
}
return {
stdout:
`====== 创建单据(dry-run,未创建) ======\n` +
` 模板 : ${preview.template}\n` +
` 标题 : ${preview.title}\n` +
` 金额 : ${preview.amount} CNY\n` +
` 费用类型: ${preview.feeType}\n` +
` 事由 : ${preview.reason || "-"}\n` +
`\n提示: 追加 --yes 执行创建(仍为草稿,不会提交)\n`,
stderr: "",
exitCode: 0,
};
}
await ctx.requireWriteConfirmation();
const result = await createBillDraft(await ctx.getClient(), corpId, {
templateId,
title,
amount,
reason,
feeTypeName,
});
if (runtime.jsonMode) {
return { stdout: printJson({ ...result, submitted: false }, runtime.outputOptions), stderr: "", exitCode: 0 };
}
return {
stdout:
`创建成功(草稿,未提交)\n` +
` 单号 : ${result.code}\n` +
` 流程 ID : ${result.flowId}\n` +
` 标题 : ${result.title}\n` +
` 金额 : ${result.amount} CNY(${result.feeType})\n`,
stderr: "",
exitCode: 0,
};
}
+11 -1
View File
@@ -9,6 +9,8 @@ import { handleValidate } from "./validate.js";
import { handleCopy } from "./copy.js";
import { handleDelete } from "./delete.js";
import { handleTemplates } from "./templates.js";
import { handleCreate } from "./create.js";
import { handleSubmit } from "./submit.js";
export async function handleBillCommand(
parsed: CliParsedArgs,
@@ -129,7 +131,15 @@ export async function handleBillCommand(
case "spec-list":
return handleTemplates(ctx);
case "create":
case "new":
return handleCreate(ctx);
case "submit":
case "send":
return handleSubmit(ctx);
default:
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号> [--risk], trace <单号|ID>, spec <specificationId>, refs <单号>, relations <单号>, attachments <单号>, download <单号>, flow <单号>, risk <单号>, budget <单号>, schema, link <单号>, validate <单号>, copy <单号> --yes, delete <单号> --yes, templates [--all]`);
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号> [--risk], trace <单号|ID>, spec <specificationId>, refs <单号>, relations <单号>, attachments <单号>, download <单号>, flow <单号>, risk <单号>, budget <单号>, schema, link <单号>, validate <单号>, copy <单号> --yes, delete <单号> --yes, templates [--all], create --template <ID> --yes, submit <单号> --yes`);
}
}
+62
View File
@@ -0,0 +1,62 @@
import { resolveBillStaffIds } from "../../../domains/bill/tools.js";
import { submitBillDraft } from "../../../domains/bill/submit.js";
import { isDryRun } from "../../mutation.js";
import { stringOption } from "../../parser.js";
import { printJson } from "../../printer.js";
import type { CliResult } from "../../types.js";
import type { BillActionContext } from "./context.js";
/**
* `hose-use bill submit <单号|ID> [--approver=<员工>] [--dry-run] --yes`
*
* 纯接口提交:计算审批计划 → 补齐未指派审批人 → freeflow.submit。
*/
export async function handleSubmit(ctx: BillActionContext): Promise<CliResult> {
const { parsed, runtime, corpId } = ctx;
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id"]);
if (!target) {
throw new Error("请提供要提交的单号或 ID: hose-use bill submit <单号|ID> [--approver=<员工>] --yes");
}
const approverRaw = stringOption(parsed.options, ["approver", "approver-id", "staff"]);
if (isDryRun(parsed, runtime)) {
if (runtime.jsonMode) {
return {
stdout: printJson({ dryRun: true, target, approver: approverRaw ?? null }, runtime.outputOptions),
stderr: "",
exitCode: 0,
};
}
return {
stdout:
`====== 提交单据(dry-run,未提交) ======\n` +
` 目标 : ${target}\n` +
` 审批人 : ${approverRaw ?? "(使用计划中已指派的人)"}\n` +
`\n提示: 追加 --yes 执行提交(会真实进入审批流)\n`,
stderr: "",
exitCode: 0,
};
}
await ctx.requireWriteConfirmation();
const client = await ctx.getClient();
let approverId: string | undefined;
if (approverRaw) {
const ids = await resolveBillStaffIds(client, corpId, [approverRaw]);
approverId = ids[0];
}
const result = await submitBillDraft(client, corpId, target, { approverId });
if (runtime.jsonMode) {
return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
}
return {
stdout:
`提交成功(已进入审批流)\n` +
` 单号 : ${result.code}\n` +
` 流程 ID : ${result.flowId}\n` +
` 节点数 : ${result.nodeCount}\n`,
stderr: "",
exitCode: 0,
};
}