feat: include risk snapshot in bill details

This commit is contained in:
gitea committed 2026-09-05 21:07:48 +08:00
1 parent 06da94152d
commit 2b4bf49663
5 files changed
+61 -6

No files matched your search

+2 -1
View File
@@ -32,7 +32,7 @@ metadata:
| 首次登录 / 账密认证 / Token过期 / 多账号 | `hose auth login`, `hose auth status`, `hose auth refresh` | [references/auth.md](references/auth.md) |
| 代客协助凭证导入 / 探针连通性诊断 | `hose auth import`, `hose probe` | [references/auth.md](references/auth.md) |
| 企业租户切换 / 查看当前企业 | `hose corps list`, `hose corps switch <id>` | [references/auth.md](references/auth.md) |
| 报销单据检索 / 费用明细下钻 / 中文字典 | `hose bill list`, `hose bill get <单号|ID>` | [references/bill.md](references/bill.md) |
| 报销单据检索 / 费用明细下钻 / 中文字典 | `hose bill list`, `hose bill get <单号|ID> [--risk]` | [references/bill.md](references/bill.md) |
| 单据审批历史 / 当前节点 / 后续流程 | `hose bill flow <单号|ID>` | [references/bill.md](references/bill.md) |
| 单据风控预警 / 预算状态 / 发票风险 | `hose bill risk <单号|ID>` | [references/bill.md](references/bill.md) |
| 单据引用 ID 二级解析(人员/部门/费用类型) | `hose bill refs <单号|ID>` | [references/bill.md](references/bill.md) |
@@ -82,6 +82,7 @@ hose bill list # 查看最新单据与报
hose bill link CL20260901001 # 生成官方 Web 详情直达免密跳转链接
hose bill list --json -o /tmp/bills.json # 导出全量单据报文至本地磁盘
hose bill get n0GMIM0dkQmKbS # 精准查询单据详情 (中文字段映射)
hose bill get S26000001 --risk # 在详情中附加费控风控与发票风险快照
hose bill refs S26000001 # 解析提交人、归属人、部门、法人实体与费用类型
hose bill relations S26000001 # 追溯冲借款、事前申请和合同关联
hose bill budget S26000001 # 查看单据预算超限和预算接口状态
+7
View File
@@ -38,6 +38,13 @@ hose-use bill get CL20260903001 --json
hose-use bill flow CL20260903001
```
在详情中附加风控与合规快照时加 `--risk`。该选项会沿用审批详情页的风控、预算和发票风险接口,并在 JSON 的每个单据项中增加 `risk` 字段:
```bash
hose bill get S26000001 --risk
hose bill get S26000001 --risk --json
```
### 中文字段智能映射字典
合思底层原生单据接口通常返回类似 `c0_1`, `d1_4`, `u_fee_amount` 等混淆字段。
`hose-use` 内置**动态中文 Label 字典转换引擎**:
+27 -3
View File
@@ -1,6 +1,6 @@
import { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
import { printJson, printTable } from "../printer.js";
import { stringOption, numberOption } from "../parser.js";
import { booleanOption, stringOption, numberOption } from "../parser.js";
import { createEkbClient } from "../../core/auth/ekb.js";
import {
searchAndFormatBills,
@@ -111,6 +111,11 @@ export async function handleBillCommand(
};
}
const withRisk = booleanOption(parsed.options, ["risk", "with-risk", "audit"]);
const riskReports = withRisk
? await Promise.all(bills.map((bill) => getBillRisk(client, corpId, bill.billId || bill.billCode)))
: [];
if (runtime.jsonMode) {
return {
stdout: printJson(
@@ -118,7 +123,7 @@ export async function handleBillCommand(
corpId,
corpName: corp.name,
count: bills.length,
bills,
bills: bills.map((bill, index) => withRisk ? { ...bill, risk: riskReports[index] ?? null } : bill),
},
runtime.outputOptions
),
@@ -153,6 +158,25 @@ export async function handleBillCommand(
outputs.push(` ${k.padEnd(maxKeyLen + 2)}: ${formattedVal}`);
}
}
if (withRisk) {
const risk = riskReports[i];
outputs.push(`\n --- 费控风控与合规风险提示 ---`);
if (!risk) {
outputs.push(" (未找到审批流程风控快照)");
} else {
outputs.push(` 风控流程 ID : ${risk.flowId}`);
outputs.push(` 预算超限 : ${risk.budgetExceeded ? "是" : "否"}`);
if (risk.warnings.length === 0 && risk.invoiceWarnings.length === 0) {
outputs.push(" 风险预警 : (暂无风险预警)");
} else {
for (const warning of risk.warnings) {
outputs.push(` [${warning.riskLevel || "提示"}] ${warning.controlName || warning.title || warning.type || "风控规则"}: ${warning.messages.join(";") || "-"}`);
}
outputs.push(` 发票风险 : ${risk.invoiceWarnings.length} 条`);
}
}
}
}
return {
@@ -473,6 +497,6 @@ export async function handleBillCommand(
}
default:
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号>, refs <单号>, relations <单号>, attachments <单号>, download <单号>, flow <单号>, risk <单号>, budget <单号>, schema, link <单号>`);
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号> [--risk], refs <单号>, relations <单号>, attachments <单号>, download <单号>, flow <单号>, risk <单号>, budget <单号>, schema, link <单号>`);
}
}
+2 -1
View File
@@ -119,7 +119,7 @@ export function printHelp(): string {
corps 多企业租户管理 (list, switch, current)
config 全局运行模式与路径诊断 (show, paths, mode <stateful|stateless>, set)
workflow 工作流管理 (list, get, find, analyze, toggle)
bill 单据与费用明细检索 (list, get <单号|ID>, refs <单号|ID>, relations <单号|ID>, attachments <单号|ID>, download <单号|ID>, flow <单号|ID>, risk <单号|ID>, budget <单号|ID>, schema, link <单号|ID>)
bill 单据与费用明细检索 (list, get <单号|ID> [--risk], refs <单号|ID>, relations <单号|ID>, attachments <单号|ID>, download <单号|ID>, flow <单号|ID>, risk <单号|ID>, budget <单号|ID>, schema, link <单号|ID>)
contact 企业通讯录与人员检索 (list, search <关键词>, get <staffId>)
task 待办中心与审批任务 (todo, approved, records, submitted, cc)
message 消息中心与通知管理 (list, count, read, read-all)
@@ -179,6 +179,7 @@ export function printHelp(): string {
hose-use bill link CL20260901001 # 获取单据 Web 详情直达免密跳转链接
hose-use bill list --json -o /tmp/bills.json # 导出单据报文到本地磁盘并防爆
hose-use bill get n0GMIM0dkQmKbS # 根据单号精准查询单据结构化详情
hose-use bill get S26000001 --risk # 在详情中附加费控风控与发票风险快照
hose-use http --port=8888 # 启动本地 HTTP 服务与可视化交互文档
hose-use service start # 后台启动常驻守护进程服务
hose-use service status # 查看守护进程运行状态与接口地址
+23 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect } from "bun:test";
import { formatSingleBill, getBillReferences, getBillRelations, getBillAttachments } from "./tools.js";
import { formatSingleBill, getBillReferences, getBillRelations, getBillAttachments, getBillRisk } from "./tools.js";
import { RawBillItemSchema, EntitySchema } from "./types.js";
describe("Bill Domain", () => {
@@ -169,4 +169,26 @@ describe("Bill Domain", () => {
thumbUrl: "https://files.example/thumb",
});
});
it("normalizes risk warnings, budget state and invoice warnings", async () => {
const client = {
post: async (path: string) => {
if (path.includes("backlogs/search")) {
return new Response(JSON.stringify({ items: [{ id: "backlog-risk", flowId: { id: "flow-risk", form: { code: "S26000004", submitterId: { id: "staff-1" } } } }] }));
}
return new Response(JSON.stringify({ value: { id: "backlog-risk", flowId: { id: "flow-risk", form: { code: "S26000004", submitterId: { id: "staff-1" } } } } }));
},
get: async (path: string) => {
if (path.includes("coalition")) return new Response(JSON.stringify({ riskWarning: [{ riskLevel: "WARNING", controlName: "重复报销", messages: ["命中测试规则"] }] }));
if (path.includes("budget/report")) return new Response(JSON.stringify({ value: true, status: "OVER" }));
if (path.includes("invoice/riskWarning")) return new Response(JSON.stringify({ items: [{ type: "invoice", message: "发票抬头不一致" }] }));
return new Response(JSON.stringify({}));
},
} as any;
const result = await getBillRisk(client, "corp-risk", "S26000004");
expect(result?.flowId).toBe("flow-risk");
expect(result?.budgetExceeded).toBe(true);
expect(result?.warnings[0]?.controlName).toBe("重复报销");
expect(result?.invoiceWarnings).toHaveLength(1);
});
});