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
@@ -298,7 +298,8 @@ export const COMMAND_METADATA: Record<string, CliCommandMetadata> = {
|
||||
"link": "生成单据详情链接",
|
||||
"validate": "校验单据派生字段一致性(金额/币种/发票总额/草稿状态)",
|
||||
"copy": "复制单据为新草稿(清空发票绑定,不提交)",
|
||||
"delete": "删除草稿单据(仅 draft,需 --yes)"
|
||||
"delete": "删除草稿单据(仅 draft,需 --yes)",
|
||||
"templates": "查看单据模板(默认仅启用,--all 含停用)"
|
||||
},
|
||||
"options": [
|
||||
"--dry-run 只预览审批动作",
|
||||
@@ -342,7 +343,7 @@ export const COMMAND_METADATA: Record<string, CliCommandMetadata> = {
|
||||
"url": "link",
|
||||
"specification": "spec"
|
||||
},
|
||||
flags: { ...flagList("audit basic confirm distinct drop-attachments dropAttachments force-write keep-it-secret mine my no-invoice noInvoice private remind reminder risk secret self with-risk y yes", "boolean"), ...flagList("add-node-type addNodeType approver approver-id approverIds c code comment count d days dir direction end end-date endDate fields file file-id filter filter-by filterBy flowId from id k keyword limit message mode n opinion order output-dir participant participants q query reject-to rejectTo resubmit-method resubmitMethod s search-field search-fields searchFields select sf since sort spec specification specification-id specificationId staff staff-id stage start start-date startDate state target title to", "value") }
|
||||
flags: { ...flagList("all audit basic confirm distinct drop-attachments dropAttachments force-write keep-it-secret mine my no-invoice noInvoice private remind reminder risk secret self with-risk y yes", "boolean"), ...flagList("add-node-type addNodeType approver approver-id approverIds c code comment count d days dir direction end end-date endDate fields file file-id filter filter-by filterBy flowId from id k keyword limit message mode n opinion order output-dir participant participants q query reject-to rejectTo resubmit-method resubmitMethod s search-field search-fields searchFields select sf since sort spec specification specification-id specificationId staff staff-id stage start start-date startDate state target title to", "value") }
|
||||
},
|
||||
"flow": {
|
||||
"summary": "审批流全域透视与穿透诊断",
|
||||
|
||||
@@ -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