feat(dimension): query custom archive catalogs and items
This commit is contained in:
1 parent
a0d13ca36a
commit
1f3334bfbd
12 files changed
+220
-1
No files matched your search
@@ -39,6 +39,7 @@ metadata:
|
||||
| 单据关联关系 / 冲借款与前置申请追溯 | `hose bill relations <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据预算状态 / 超预算与占用信息 | `hose bill budget <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据附件 / 发票原件标准列表 | `hose bill attachments <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 系统/自定义档案维度与档案项 | `hose dimension list`, `hose dimension items <维度>` | [references/dimension.md](references/dimension.md) |
|
||||
| 单据 Web 详情直达链接生成 | `hose bill link <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据实体模型与字段元数据查询 | `hose bill schema` | [references/bill.md](references/bill.md) |
|
||||
| 企业通讯录检索 / 员工档案 / 防爆保护 | `hose contact search`, `hose contact list`, `hose contact get` | [references/contact.md](references/contact.md) |
|
||||
@@ -80,6 +81,8 @@ hose bill refs S26000001 # 解析提交人、归属
|
||||
hose bill relations S26000001 # 追溯冲借款、事前申请和合同关联
|
||||
hose bill budget S26000001 # 查看单据预算超限和预算接口状态
|
||||
hose bill attachments S26000001 # 查看附件和发票原件列表
|
||||
hose dimension list # 查看系统与自定义档案维度
|
||||
hose dimension items 项目 # 查看项目、成本中心等档案项
|
||||
hose bill schema # 查询单据实体元数据字典
|
||||
|
||||
# 4. 待办与消息
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
# 自定义档案与核算维度
|
||||
|
||||
合思前端“系统配置 → 档案设置 → 扩展档案 → 自定义档案”对应 CLI 的 `dimension` 域。
|
||||
|
||||
```bash
|
||||
# 查看系统/自定义档案维度目录
|
||||
hose dimension list
|
||||
hose dimension list --keyword=项目
|
||||
|
||||
# 查看某个维度的档案项(支持维度 ID、编码或名称)
|
||||
hose dimension items 项目
|
||||
hose dimension items DA001 --json
|
||||
```
|
||||
|
||||
目录来源于 `/api/v1/basedata/dimensions/active`,档案项来源于 `/api/v1/basedata/dimensionItems/$<dimensionId>`。结果在同一进程内按企业缓存 10 分钟,JSON 会保留底层 ID、编码、父项 ID 和表单字段。
|
||||
@@ -0,0 +1,35 @@
|
||||
import { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
|
||||
import { printJson, printTable } from "../printer.js";
|
||||
import { numberOption, stringOption } from "../parser.js";
|
||||
import { createEkbClient } from "../../core/auth/ekb.js";
|
||||
import { searchDimensions, resolveDimension } from "../../domains/dimension/tools.js";
|
||||
|
||||
export async function handleDimensionCommand(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const corp = runtime.selectedCorp;
|
||||
if (!corp) throw new Error("未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose auth login 登录。");
|
||||
const client = await createEkbClient(corp);
|
||||
const corpId = corp.corpId || corp.id;
|
||||
const action = parsed.action?.toLowerCase() || "list";
|
||||
if (["list", "search", "catalogs", undefined].includes(action)) {
|
||||
const keyword = stringOption(parsed.options, ["keyword", "q", "query"]) || parsed.args[0];
|
||||
const dimensions = await searchDimensions(client, corpId, { name: keyword });
|
||||
if (runtime.jsonMode) return { stdout: printJson({ corpId, corpName: corp.name, count: dimensions.length, dimensions }, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
const rows = dimensions.map((item, index) => [index + 1, item.name, item.code || "-", item.id, item.type || "-", item.active ? "启用" : "停用"]);
|
||||
return { stdout: `====== 企业档案维度目录 (企业: ${corp.name} | 共 ${dimensions.length} 个) ======\n${rows.length ? printTable(["#", "名称", "编码", "ID", "类型", "状态"], rows) : "暂无匹配档案维度"}\n`, stderr: "", exitCode: 0 };
|
||||
}
|
||||
if (["items", "get", "show"].includes(action)) {
|
||||
const target = parsed.args[0] || stringOption(parsed.options, ["dimension", "id", "code", "name"]);
|
||||
if (!target) throw new Error("请提供档案维度 ID、编码或名称: hose dimension items <维度>");
|
||||
const result = await resolveDimension(client, corpId, target);
|
||||
if (!result) {
|
||||
if (runtime.jsonMode) return { stdout: printJson({ found: false, target }, runtime.outputOptions), stderr: "", exitCode: 1 };
|
||||
return { stdout: "", stderr: `[NOT FOUND] 未找到档案维度: ${target}\n`, exitCode: 1 };
|
||||
}
|
||||
const count = numberOption(parsed.options, ["count", "limit", "n"], 100) || 100;
|
||||
const items = count >= result.items.length ? result.items : result.items.slice(0, count);
|
||||
if (runtime.jsonMode) return { stdout: printJson({ corpId, corpName: corp.name, dimension: result.dimension, count: items.length, items }, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
const rows = items.map((item, index) => [index + 1, item.name, item.code || "-", item.id, item.parentId || "-", item.fullPath || "-"]);
|
||||
return { stdout: `====== 档案项 (维度: ${result.dimension.name} | 共 ${items.length} 条) ======\n${rows.length ? printTable(["#", "名称", "编码", "ID", "上级 ID", "全路径"], rows) : "暂无档案项"}\n`, stderr: "", exitCode: 0 };
|
||||
}
|
||||
throw new Error(`未知 dimension 子命令: ${action}。支持: list, items <维度 ID|编码|名称>`);
|
||||
}
|
||||
@@ -124,6 +124,7 @@ export function printHelp(): string {
|
||||
task 待办中心与审批任务 (todo, approved, records, submitted, cc)
|
||||
message 消息中心与通知管理 (list, count, read, read-all)
|
||||
platform 自建应用管理 (list)
|
||||
dimension 系统/自定义档案维度 (list, items <维度>)
|
||||
skill Agent Skill 管理 (install, status, dump)
|
||||
probe 连通性诊断 (probe [corpId])
|
||||
update 版本自更新与发布记录 (update, update check, update --changelog)
|
||||
@@ -166,6 +167,8 @@ export function printHelp(): string {
|
||||
hose-use bill relations S26000001 # 追溯冲借款、事前申请和合同关联
|
||||
hose-use bill budget S26000001 # 查看单据预算超限和预算接口状态
|
||||
hose-use bill attachments S26000001 # 查看单据附件和发票原件标准列表
|
||||
hose-use dimension list # 查看系统与自定义档案维度
|
||||
hose-use dimension items 项目 # 查看项目档案项
|
||||
hose-use bill link CL20260901001 # 获取单据 Web 详情直达免密跳转链接
|
||||
hose-use bill list --json -o /tmp/bills.json # 导出单据报文到本地磁盘并防爆
|
||||
hose-use bill get n0GMIM0dkQmKbS # 根据单号精准查询单据结构化详情
|
||||
|
||||
@@ -18,6 +18,7 @@ import { handleServiceCommand } from "./commands/service.js";
|
||||
import { handleHttpCommand } from "./commands/http.js";
|
||||
import { handleTaskCommand } from "./commands/task.js";
|
||||
import { handleMessageCommand } from "./commands/message.js";
|
||||
import { handleDimensionCommand } from "./commands/dimension.js";
|
||||
import type { CliResult, CliRunOptions } from "./types.js";
|
||||
|
||||
const STANDING_COMMANDS = new Set(["http", "server", "web", "mcp"]);
|
||||
@@ -141,6 +142,11 @@ async function dispatchCli(
|
||||
case "tasks":
|
||||
case "todo":
|
||||
return await handleTaskCommand(parsed, runtime);
|
||||
case "dimension":
|
||||
case "dimensions":
|
||||
case "archive":
|
||||
case "archives":
|
||||
return await handleDimensionCommand(parsed, runtime);
|
||||
case "message":
|
||||
case "messages":
|
||||
case "notify":
|
||||
|
||||
@@ -34,7 +34,7 @@ describe("embedded-skill - 多文件内嵌 Skill 体系", () => {
|
||||
try {
|
||||
const res = installSkillFiles(tmp);
|
||||
expect(res.targetDir).toBe(tmp);
|
||||
expect(res.files.length).toBe(9);
|
||||
expect(res.files.length).toBe(10);
|
||||
expect(existsSync(join(tmp, "SKILL.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "agents", "openai.yaml"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "auth.md"))).toBe(true);
|
||||
|
||||
@@ -11,6 +11,7 @@ import refService from "../../skills/hose-use/references/service.md" with { type
|
||||
import refContact from "../../skills/hose-use/references/contact.md" with { type: "text" };
|
||||
import refTask from "../../skills/hose-use/references/task.md" with { type: "text" };
|
||||
import refMessage from "../../skills/hose-use/references/message.md" with { type: "text" };
|
||||
import refDimension from "../../skills/hose-use/references/dimension.md" with { type: "text" };
|
||||
|
||||
export const EMBEDDED_SKILL_FILES: Record<string, string> = {
|
||||
"SKILL.md": skillMain,
|
||||
@@ -20,6 +21,7 @@ export const EMBEDDED_SKILL_FILES: Record<string, string> = {
|
||||
"references/contact.md": refContact,
|
||||
"references/task.md": refTask,
|
||||
"references/message.md": refMessage,
|
||||
"references/dimension.md": refDimension,
|
||||
"references/workflow.md": refWorkflow,
|
||||
"references/service.md": refService,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# Dimension 域说明
|
||||
|
||||
Dimension 域负责“系统配置 → 档案设置 → 扩展档案 → 自定义档案”目录和档案项查询。
|
||||
|
||||
- `listDimensionCatalogs` 调用组织权限目录后,分别拉取系统档案 (`preset==1`) 与自定义档案 (`preset==0`);
|
||||
- `listDimensionItems` 调用档案项接口并保留 `id`、`code`、`name`、`parentId`、`fullPath` 和 `form`;
|
||||
- `tools.ts` 按企业在进程内缓存目录与档案项 10 分钟。
|
||||
@@ -0,0 +1,36 @@
|
||||
import { z } from "zod";
|
||||
import type { KyInstance } from "ky";
|
||||
import { DimensionCatalogSchema, DimensionItemSchema, type DimensionCatalog, type DimensionItem } from "./types.js";
|
||||
|
||||
export async function listDimensionCatalogs(client: KyInstance, corpId: string, start = 0, count = 100): Promise<DimensionCatalog[]> {
|
||||
const organizationResponse = await client.get("api/authority/v2/organization/list/$DIMENSION", {
|
||||
searchParams: { start: String(start), count: String(count), model: "DIMENSION", corpId },
|
||||
});
|
||||
const organizationJson = (await organizationResponse.json()) as { items?: Array<{ id?: string }> };
|
||||
const orgId = organizationJson.items?.[0]?.id;
|
||||
if (!orgId) return [];
|
||||
const responses = await Promise.all([0, 1].map((preset) => client.post("api/v1/basedata/dimensions/active", {
|
||||
searchParams: { orgId, corpId },
|
||||
json: {
|
||||
limit: { start, count },
|
||||
select: "id,label,enLabel,code,name,state,type,active",
|
||||
orderBy: [{ value: "createTime", order: "DESC" }],
|
||||
filterBy: `preset==${preset}`,
|
||||
},
|
||||
})));
|
||||
const items: unknown[] = [];
|
||||
for (const response of responses) {
|
||||
const json = (await response.json()) as { items?: unknown[] };
|
||||
items.push(...(json.items ?? []));
|
||||
}
|
||||
return z.array(DimensionCatalogSchema).parse(items);
|
||||
}
|
||||
|
||||
export async function listDimensionItems(client: KyInstance, corpId: string, dimensionId: string, start = 0, count = 100): Promise<DimensionItem[]> {
|
||||
const response = await client.post(`api/v1/basedata/dimensionItems/$${dimensionId}`, {
|
||||
searchParams: { corpId, dimensionItemId: "" },
|
||||
json: { filterBy: "(active == true)", limit: { start, count } },
|
||||
});
|
||||
const json = (await response.json()) as { items?: unknown[] };
|
||||
return z.array(DimensionItemSchema).parse(json.items ?? []);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { searchDimensions, resolveDimension } from "./tools.js";
|
||||
|
||||
describe("Dimension Domain - 自定义档案目录", () => {
|
||||
it("loads preset and custom dimension catalogs and filters by name", async () => {
|
||||
const client = {
|
||||
get: async () => new Response(JSON.stringify({ items: [{ id: "org-1" }] })),
|
||||
post: async (_path: string, options: any) => new Response(JSON.stringify({ items: [
|
||||
options.json.filterBy === "preset==0" ? { id: "dim-custom", name: "项目", code: "DA001", type: "normal", active: true } : { id: "dim-system", name: "法人实体", code: "FRST", type: "legal_entity", active: true },
|
||||
] })),
|
||||
} as any;
|
||||
const result = await searchDimensions(client, "corp-dimension", { name: "项目" });
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0]?.code).toBe("DA001");
|
||||
});
|
||||
|
||||
it("loads dimension items by catalog ID", async () => {
|
||||
const client = {
|
||||
get: async () => new Response(JSON.stringify({ items: [{ id: "org-2" }] })),
|
||||
post: async (path: string) => new Response(JSON.stringify(path.includes("dimensionItems") ? { items: [{ id: "item-1", name: "研发项目", code: "P001", parentId: "", active: true }] } : { items: [{ id: "dim-project", name: "项目", code: "DA001", type: "normal", active: true }] })),
|
||||
} as any;
|
||||
const result = await resolveDimension(client, "corp-items", "项目");
|
||||
expect(result?.dimension.id).toBe("dim-project");
|
||||
expect(result?.items[0]?.name).toBe("研发项目");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,53 @@
|
||||
import { z } from "zod";
|
||||
import type { KyInstance } from "ky";
|
||||
import { listDimensionCatalogs, listDimensionItems } from "./api.js";
|
||||
import type { DimensionCatalog, DimensionItem, DimensionQuery } from "./types.js";
|
||||
|
||||
const cache = new Map<string, { timestamp: number; catalogs: DimensionCatalog[]; items: Map<string, DimensionItem[]> }>();
|
||||
const CACHE_TTL_MS = 10 * 60 * 1000;
|
||||
|
||||
async function getCached(client: KyInstance, corpId: string): Promise<{ catalogs: DimensionCatalog[]; items: Map<string, DimensionItem[]> }> {
|
||||
const existing = cache.get(corpId);
|
||||
if (existing && Date.now() - existing.timestamp < CACHE_TTL_MS) return existing;
|
||||
const catalogs = await listDimensionCatalogs(client, corpId);
|
||||
const result = { timestamp: Date.now(), catalogs, items: new Map<string, DimensionItem[]>() };
|
||||
cache.set(corpId, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function searchDimensions(client: KyInstance, corpId: string, query: DimensionQuery = {}): Promise<DimensionCatalog[]> {
|
||||
const { catalogs } = await getCached(client, corpId);
|
||||
const keyword = (query.name || query.code || query.id || "").trim().toLowerCase();
|
||||
if (!keyword) return catalogs;
|
||||
return catalogs.filter((item) => [item.id, item.name, item.code].some((value) => value.toLowerCase().includes(keyword)));
|
||||
}
|
||||
|
||||
export async function getDimensionItems(client: KyInstance, corpId: string, dimension: DimensionCatalog, start = 0, count = 100): Promise<DimensionItem[]> {
|
||||
const catalog = await getCached(client, corpId);
|
||||
const cached = catalog.items.get(dimension.id);
|
||||
if (cached && start === 0 && count >= cached.length) return cached;
|
||||
const items = await listDimensionItems(client, corpId, dimension.id, start, count);
|
||||
if (start === 0) catalog.items.set(dimension.id, items);
|
||||
return items;
|
||||
}
|
||||
|
||||
export async function resolveDimension(client: KyInstance, corpId: string, target: string): Promise<{ dimension: DimensionCatalog; items: DimensionItem[] } | undefined> {
|
||||
const matches = await searchDimensions(client, corpId, { id: target, code: target, name: target });
|
||||
const dimension = matches[0];
|
||||
if (!dimension) return undefined;
|
||||
return { dimension, items: await getDimensionItems(client, corpId, dimension) };
|
||||
}
|
||||
|
||||
export const dimensionTools = [
|
||||
{
|
||||
name: "dimension_list",
|
||||
description: "列出企业档案管理中的系统/自定义档案维度目录",
|
||||
parameters: z.object({ keyword: z.string().optional(), count: z.number().optional() }),
|
||||
handler: async ({ corpContext }: any, params: { keyword?: string; count?: number }) => {
|
||||
const corp = corpContext.getCurrent();
|
||||
if (!corp) throw new Error("未配置活跃企业上下文");
|
||||
const items = await searchDimensions(await import("../../core/auth/ekb.js").then((m) => m.createEkbClient(corp)), corp.corpId || corp.id, { name: params.keyword });
|
||||
return { count: items.length, dimensions: items.slice(0, params.count ?? 100) };
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,33 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const DimensionCatalogSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string().default(""),
|
||||
code: z.string().optional().default(""),
|
||||
type: z.string().optional().default(""),
|
||||
active: z.boolean().optional().default(true),
|
||||
state: z.string().nullable().optional().transform((value) => value ?? ""),
|
||||
});
|
||||
|
||||
export const DimensionItemSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string().default(""),
|
||||
code: z.string().optional().default(""),
|
||||
parentId: z.string().optional().default(""),
|
||||
dimensionId: z.string().optional().default(""),
|
||||
active: z.boolean().optional().default(true),
|
||||
deleted: z.boolean().optional().default(false),
|
||||
fullPath: z.string().nullable().optional(),
|
||||
form: z.record(z.string(), z.any()).optional().default({}),
|
||||
});
|
||||
|
||||
export type DimensionCatalog = z.infer<typeof DimensionCatalogSchema>;
|
||||
export type DimensionItem = z.infer<typeof DimensionItemSchema>;
|
||||
|
||||
export interface DimensionQuery {
|
||||
id?: string;
|
||||
code?: string;
|
||||
name?: string;
|
||||
start?: number;
|
||||
count?: number;
|
||||
}
|
||||
Reference in new issue
Block a user