feat(bill): 支持未提交草稿查询与 flowId 直读
- bill list --state=draft/草稿 改走 flows/my 草稿列表,修复草稿不在 invoice/search 台账索引中导致 --state=draft 返回空的问题 - 新增 --template/--title/--staff/--page 过滤与分页;服务端 RQL 结合 客户端兜底匹配,模板版本化 ID 自动剥离哈希 - bill get 新增 flowId 直读通道,工作流/他人创建的草稿无需 flows/my 可见 - 补充域层与 CLI 单测、bill 文档、Skill 与 OpenAPI 参数说明 Fixes #153 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
baec8be6d3
commit
4b4a7049a0
12 files changed
+716
-36
No files matched your search
@@ -376,6 +376,7 @@ export const COMMAND_METADATA: Record<string, CliCommandMetadata> = {
|
||||
"--dry-run 只预览审批动作",
|
||||
"--yes/--confirm 确认执行审批动作",
|
||||
"--comment=<原因> 驳回或评论内容",
|
||||
"--state=draft/草稿 查询未提交草稿(数据源为 flows/my),支持 --template/--title/--staff/--page 过滤",
|
||||
"trace 的 --no-invoice/--noInvoice/--basic 为兼容空操作;穿透诊断本身不补充加载发票详情"
|
||||
],
|
||||
"aliases": [
|
||||
@@ -415,7 +416,7 @@ export const COMMAND_METADATA: Record<string, CliCommandMetadata> = {
|
||||
"url": "link",
|
||||
"specification": "spec"
|
||||
},
|
||||
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 template title to amount reason fee-type feeType", "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 page 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 template title to amount reason fee-type feeType", "value") }
|
||||
},
|
||||
"flow": {
|
||||
"summary": "审批流全域透视与穿透诊断",
|
||||
@@ -447,7 +448,7 @@ export const COMMAND_METADATA: Record<string, CliCommandMetadata> = {
|
||||
"show": "get",
|
||||
"find": "get"
|
||||
},
|
||||
flags: { ...flagList("audit basic confirm distinct 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 to", "value") }
|
||||
flags: { ...flagList("audit basic confirm distinct 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 page 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 to", "value") }
|
||||
},
|
||||
"contact": {
|
||||
"summary": "企业通讯录与人员检索",
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
import { afterEach, describe, expect, it, spyOn } from "bun:test";
|
||||
import * as session from "../../../core/http/hose-web-session-client.js";
|
||||
import { parseArgs } from "../../parser.js";
|
||||
import { createBillActionContext } from "./context.js";
|
||||
import { handleList } from "./search.js";
|
||||
|
||||
const spies: Array<{ mockRestore(): void }> = [];
|
||||
afterEach(() => {
|
||||
for (const spy of spies.splice(0).reverse()) spy.mockRestore();
|
||||
});
|
||||
|
||||
function json(value: unknown): Response {
|
||||
return new Response(JSON.stringify(value));
|
||||
}
|
||||
|
||||
function draftClient(corpId: string) {
|
||||
const flowsPosts: any[] = [];
|
||||
const client = {
|
||||
get: async (url: string) => {
|
||||
if (url.includes("staffs/actives")) {
|
||||
return json({ items: [{ id: "staff-1", name: "张三", code: "1001" }] });
|
||||
}
|
||||
return json({});
|
||||
},
|
||||
post: async (url: string, payload: any) => {
|
||||
if (url.includes("datalink/entity/search")) return json({ items: [] });
|
||||
if (url.endsWith("/flows/my")) {
|
||||
flowsPosts.push({ url, payload, corpId });
|
||||
return json({
|
||||
count: 1,
|
||||
items: [{
|
||||
flow: {
|
||||
id: "flow-cli-draft",
|
||||
state: "draft",
|
||||
formType: "payment",
|
||||
createTime: 1781682826000,
|
||||
updateTime: 1781682870000,
|
||||
},
|
||||
form: {
|
||||
code: "FK26000009",
|
||||
title: "付款草稿CLI",
|
||||
specificationId: { id: "spec-pay", name: "对公付款单" },
|
||||
submitterId: { id: "staff-1", name: "张三", code: "1001" },
|
||||
payMoney: { standard: "10.00", standardSymbol: "¥", standardStrCode: "CNY" },
|
||||
},
|
||||
}],
|
||||
});
|
||||
}
|
||||
return json({});
|
||||
},
|
||||
};
|
||||
return { client, flowsPosts };
|
||||
}
|
||||
|
||||
function context(args: string[], corpId: string, jsonMode: boolean) {
|
||||
const corp = { id: corpId, name: "测试企业", credentials: { corpId } };
|
||||
return createBillActionContext(parseArgs(args), { jsonMode, selectedCorp: corp } as any);
|
||||
}
|
||||
|
||||
describe("bill list draft mode", () => {
|
||||
it("routes --state=draft to flows/my with template, title, submitter and page filters", async () => {
|
||||
const { client, flowsPosts } = draftClient("cli-draft-corp-json");
|
||||
spies.push(spyOn(session, "createSessionClient").mockResolvedValue(client as any));
|
||||
|
||||
const args = [
|
||||
"bill", "list", "--state=draft", "--mine",
|
||||
`--template=spec-pay:${"a".repeat(32)}`,
|
||||
"--title=付款", "--staff=张三",
|
||||
"--page=2", "--count=10", "--json",
|
||||
];
|
||||
const result = await handleList(context(args, "cli-draft-corp-json", true));
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
const output = JSON.parse(result.stdout);
|
||||
expect(output.total).toBe(1);
|
||||
expect(output.items[0]).toMatchObject({
|
||||
billId: "flow-cli-draft",
|
||||
billCode: "FK26000009",
|
||||
billName: "付款草稿CLI",
|
||||
state: "draft",
|
||||
});
|
||||
expect(output.items[0].amount).toContain("10.00");
|
||||
|
||||
expect(flowsPosts).toHaveLength(1);
|
||||
const filterBy = flowsPosts[0].payload.json.filterBy as string;
|
||||
expect(filterBy).toContain('(state.in("draft"))');
|
||||
expect(filterBy).toContain('INSTR(form.title, "付款")');
|
||||
expect(filterBy).toContain('INSTR(form.specificationId, "spec-pay")');
|
||||
expect(filterBy).not.toContain("a".repeat(32));
|
||||
expect(filterBy).toContain('INSTR(form.submitterId, "staff-1")');
|
||||
expect(flowsPosts[0].payload.json.limit).toEqual({ start: 10, count: 10 });
|
||||
expect(flowsPosts[0].payload.json.orderBy).toEqual([{ value: "createTime", order: "DESC" }]);
|
||||
});
|
||||
|
||||
it("renders a draft-specific text header for --state=草稿", async () => {
|
||||
const { client } = draftClient("cli-draft-corp-text");
|
||||
spies.push(spyOn(session, "createSessionClient").mockResolvedValue(client as any));
|
||||
|
||||
const result = await handleList(context(["bill", "list", "--state=草稿"], "cli-draft-corp-text", false));
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain("单据草稿列表");
|
||||
expect(result.stdout).toContain("FK26000009");
|
||||
expect(result.stdout).toContain("bill submit");
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,10 @@
|
||||
import { getBillByCodeOrId, getBillRisk, searchAndFormatBills, traceBillFlowDetail } from "../../../domains/bill/tools.js";
|
||||
import {
|
||||
getBillByCodeOrId,
|
||||
getBillRisk,
|
||||
searchAndFormatBills,
|
||||
searchAndFormatDraftBills,
|
||||
traceBillFlowDetail,
|
||||
} from "../../../domains/bill/tools.js";
|
||||
import { booleanOption, numberOption, stringOption } from "../../parser.js";
|
||||
import { printJson, printTable, printKeyValue } from "../../printer.js";
|
||||
import type { CliResult } from "../../types.js";
|
||||
@@ -6,8 +12,10 @@ import type { BillActionContext } from "./context.js";
|
||||
|
||||
export async function handleList(ctx: BillActionContext): Promise<CliResult> {
|
||||
const { parsed, runtime, corp, corpId } = ctx;
|
||||
const state = stringOption(parsed.options, ["state", "s"]);
|
||||
const isDraft = state ? /^(draft|草稿)$/i.test(state.trim()) : false;
|
||||
const mine = booleanOption(parsed.options, ["mine", "my", "self"]);
|
||||
if (mine) {
|
||||
if (mine && !isDraft) {
|
||||
const { handleTaskCommand } = await import("./../task.js");
|
||||
return handleTaskCommand(
|
||||
{
|
||||
@@ -23,8 +31,9 @@ export async function handleList(ctx: BillActionContext): Promise<CliResult> {
|
||||
const keyword = stringOption(parsed.options, ["keyword", "k", "q", "query"]);
|
||||
const searchFields = stringOption(parsed.options, ["search-fields", "searchFields", "search-field", "sf"]);
|
||||
const stage = stringOption(parsed.options, ["stage"]);
|
||||
const state = stringOption(parsed.options, ["state", "s"]);
|
||||
const count = numberOption(parsed.options, ["count", "limit", "n"], 20);
|
||||
const count = numberOption(parsed.options, ["count", "limit", "n"], 20) ?? 20;
|
||||
const page = Math.max(1, numberOption(parsed.options, ["page"], 1) ?? 1);
|
||||
const start = (page - 1) * count;
|
||||
const since = stringOption(parsed.options, ["since", "days", "d"]);
|
||||
const startDate = stringOption(parsed.options, ["start-date", "startDate", "from", "start"]);
|
||||
const endDate = stringOption(parsed.options, ["end-date", "endDate", "to", "end"]);
|
||||
@@ -34,21 +43,54 @@ export async function handleList(ctx: BillActionContext): Promise<CliResult> {
|
||||
const select = stringOption(parsed.options, ["select", "fields"]);
|
||||
const distinct = booleanOption(parsed.options, ["distinct"]);
|
||||
|
||||
const result = await searchAndFormatBills(await ctx.getClient(), corpId, {
|
||||
code,
|
||||
keyword,
|
||||
searchFields,
|
||||
stage,
|
||||
state,
|
||||
count,
|
||||
since,
|
||||
startDate,
|
||||
endDate,
|
||||
order,
|
||||
filterBy,
|
||||
select,
|
||||
distinct,
|
||||
});
|
||||
const title = stringOption(parsed.options, ["title"]);
|
||||
const rawTemplate = stringOption(parsed.options, [
|
||||
"template",
|
||||
"spec",
|
||||
"specification",
|
||||
"specification-id",
|
||||
"specificationId",
|
||||
]);
|
||||
const templateId = rawTemplate
|
||||
? rawTemplate
|
||||
.trim()
|
||||
.replace(/^\[|\]$/g, "")
|
||||
.replace(/:[0-9a-f]{32,64}$/i, "")
|
||||
: undefined;
|
||||
const staffValues = ctx.listOption(["staff", "staff-id"]);
|
||||
const submitterIds =
|
||||
isDraft && staffValues?.length ? await ctx.resolveApproverIds(staffValues) : undefined;
|
||||
|
||||
const result = isDraft
|
||||
? await searchAndFormatDraftBills(await ctx.getClient(), corpId, {
|
||||
code,
|
||||
keyword,
|
||||
title,
|
||||
templateId,
|
||||
submitterIds,
|
||||
start,
|
||||
count,
|
||||
since,
|
||||
startDate,
|
||||
endDate,
|
||||
order,
|
||||
})
|
||||
: await searchAndFormatBills(await ctx.getClient(), corpId, {
|
||||
code,
|
||||
keyword,
|
||||
searchFields,
|
||||
stage,
|
||||
state,
|
||||
start,
|
||||
count,
|
||||
since,
|
||||
startDate,
|
||||
endDate,
|
||||
order,
|
||||
filterBy,
|
||||
select,
|
||||
distinct,
|
||||
});
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
@@ -67,7 +109,7 @@ export async function handleList(ctx: BillActionContext): Promise<CliResult> {
|
||||
};
|
||||
}
|
||||
|
||||
const headers = ["#", "单据编号 (单号)", "单据名称", "阶段", "状态", "金额", "提交时间"];
|
||||
const headers = ["#", "单据编号 (单号)", "单据名称", "阶段", "状态", "金额", isDraft ? "创建时间" : "提交时间"];
|
||||
const rows = result.items.map((b, idx) => [
|
||||
idx + 1,
|
||||
b.billCode,
|
||||
@@ -75,7 +117,7 @@ export async function handleList(ctx: BillActionContext): Promise<CliResult> {
|
||||
b.stage || "-",
|
||||
b.state || "-",
|
||||
b.amount || "-",
|
||||
b.submitDate || b.createTime || "-",
|
||||
isDraft ? b.createTime || b.submitDate || "-" : b.submitDate || b.createTime || "-",
|
||||
]);
|
||||
|
||||
const filterSummary: string[] = [];
|
||||
@@ -87,14 +129,23 @@ export async function handleList(ctx: BillActionContext): Promise<CliResult> {
|
||||
}
|
||||
if (stage) filterSummary.push(`阶段: ${stage}`);
|
||||
if (state) filterSummary.push(`状态: ${state}`);
|
||||
if (isDraft) {
|
||||
if (templateId) filterSummary.push(`模板: ${templateId}`);
|
||||
if (title) filterSummary.push(`标题: ${title}`);
|
||||
if (staffValues?.length) filterSummary.push(`提交人: ${staffValues.join(", ")}`);
|
||||
if (page > 1) filterSummary.push(`第 ${page} 页`);
|
||||
}
|
||||
const filterTag = filterSummary.length > 0 ? ` | 筛选: ${filterSummary.join(", ")}` : "";
|
||||
|
||||
const tableOutput = printTable(headers, rows);
|
||||
const title = `====== 单据与费用明细列表 (企业: ${corp.name}${filterTag} | 匹配总数: ${result.total} | 本次返回: ${result.returned}) ======\n`;
|
||||
const tip = `\n提示: 运行 hose-use bill get <单号> 查看表单结构化详情与发票明细\n`;
|
||||
const listLabel = isDraft ? "单据草稿列表" : "单据与费用明细列表";
|
||||
const titleLine = `====== ${listLabel} (企业: ${corp.name}${filterTag} | 匹配总数: ${result.total} | 本次返回: ${result.returned}) ======\n`;
|
||||
const tip = isDraft
|
||||
? `\n提示: 运行 hose-use bill get <单号|flowId> 查看草稿详情;提交使用 hose-use bill submit <单号|flowId> --yes\n`
|
||||
: `\n提示: 运行 hose-use bill get <单号> 查看表单结构化详情与发票明细\n`;
|
||||
|
||||
return {
|
||||
stdout: title + tableOutput + tip,
|
||||
stdout: titleLine + tableOutput + tip,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user