feat(bill): list templates grouped by specification group
- bill templates [--all] [--keyword]: 与页面快速新建同源,默认仅启用 - 服务端已按身份过滤可见性,--all 仅尝试带出停用项 - docs: README.bill.md 与 Skill 路由同步
This commit is contained in:
1 parent
5d1e3e5d8e
commit
9d7df10994
8 files changed
+463
-217
No files matched your search
@@ -8,6 +8,7 @@ import { handleSchema, handleLink, handleSpec } from "./meta.js";
|
||||
import { handleValidate } from "./validate.js";
|
||||
import { handleCopy } from "./copy.js";
|
||||
import { handleDelete } from "./delete.js";
|
||||
import { handleTemplates } from "./templates.js";
|
||||
|
||||
export async function handleBillCommand(
|
||||
parsed: CliParsedArgs,
|
||||
@@ -122,7 +123,13 @@ export async function handleBillCommand(
|
||||
case "remove":
|
||||
return handleDelete(ctx);
|
||||
|
||||
case "templates":
|
||||
case "template":
|
||||
case "specs":
|
||||
case "spec-list":
|
||||
return handleTemplates(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`);
|
||||
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]`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { listBillTemplates } from "../../../domains/bill/templates.js";
|
||||
import { booleanOption, stringOption } from "../../parser.js";
|
||||
import { printJson } from "../../printer.js";
|
||||
import type { CliResult } from "../../types.js";
|
||||
import type { BillActionContext } from "./context.js";
|
||||
|
||||
/**
|
||||
* `hose-use bill templates [--all] [--keyword=...]`
|
||||
*
|
||||
* 默认返回当前身份可见且启用中的模板(与页面「快速新建单据」同源、同分组);
|
||||
* `--all` 才会带出停用模板。
|
||||
*/
|
||||
export async function handleTemplates(ctx: BillActionContext): Promise<CliResult> {
|
||||
const { parsed, runtime, corp, corpId } = ctx;
|
||||
const includeInactive = booleanOption(parsed.options, ["all"]);
|
||||
const keyword = (stringOption(parsed.options, ["keyword", "k", "q", "query"]) ?? "").trim();
|
||||
|
||||
const result = await listBillTemplates(await ctx.getClient(), corpId, { includeInactive });
|
||||
let groups = result.groups;
|
||||
if (keyword) {
|
||||
groups = groups
|
||||
.map((group) => ({
|
||||
...group,
|
||||
specifications: group.specifications.filter((spec) => spec.name.includes(keyword)),
|
||||
}))
|
||||
.filter((group) => group.specifications.length > 0);
|
||||
}
|
||||
const total = groups.reduce((sum, group) => sum + group.specifications.length, 0);
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(
|
||||
{
|
||||
corpId,
|
||||
corpName: corp.name,
|
||||
includeInactive,
|
||||
total,
|
||||
inactive: result.inactive,
|
||||
groups,
|
||||
},
|
||||
runtime.outputOptions
|
||||
),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const lines: string[] = [
|
||||
`====== 单据模板(${corp.name} | ${groups.length} 组 / ${total} 个${includeInactive ? ",含停用" : ""})======`,
|
||||
"",
|
||||
];
|
||||
for (const group of groups) {
|
||||
lines.push(`${group.name || "未分组"}`);
|
||||
for (const spec of group.specifications) {
|
||||
const inactiveMark = spec.active ? "" : "(已停用)";
|
||||
lines.push(` - ${spec.name}${inactiveMark} [${spec.type}]`);
|
||||
}
|
||||
lines.push("");
|
||||
}
|
||||
if (!includeInactive) {
|
||||
lines.push("提示: 追加 --all 可查看包含停用模板的全量列表");
|
||||
}
|
||||
return { stdout: lines.join("\n") + "\n", stderr: "", exitCode: 0 };
|
||||
}
|
||||
Reference in new issue
Block a user