fix(bill): use original template ids and bust metadata cache

- bill templates / bill spec 改用服务端 originalId(支持含冒号的原始 ID)
- 元数据 GET 增加 _t 时间戳 + no-cache,避免改名后读到缓存旧值
- skill: 业务输入必须由用户提供,禁止编造驳回意见等占位内容
This commit is contained in:
gitea committed 2026-10-23 17:32:03 +08:00
1 parent 258b347d4d
commit 1de9e3f552
5 files changed
+97 -56

No files matched your search

+5 -4
View File
@@ -610,13 +610,14 @@ export async function getFormSpecification(
): Promise<FormSpecification | undefined> {
const rawId = specificationId.replace(/^\[|\]$/g, "").trim();
if (!rawId) return undefined;
// 服务端用于查询的是「规格组 ID」(`<groupId>`),版本化 ID 形如 `<groupId>:<hash>`;
// 统一剥离版本后缀,保证 `bill templates` 返回的 ID 可直接用于 `bill spec`。
const cleanId = rawId.split(":")[0];
// 服务端用于查询的是「原始规格 ID」,版本化 ID 形如 `<originalId>:<hash>`;
// 仅剥离末尾的 hash(originalId 本身可能包含冒号,如 `<corpId>:system:<name>`)。
const cleanId = rawId.replace(/:[0-9a-f]{32,64}$/i, "");
const response = await client.get(
`api/form/v2/specifications/[${encodeURIComponent(cleanId)}]`,
{
searchParams: { corpId },
searchParams: { corpId, _t: String(Date.now()) },
headers: { "cache-control": "no-cache", pragma: "no-cache" },
}
);
const json = (await response.json()) as {
+24 -4
View File
@@ -6,15 +6,15 @@ const raw = [
name: "报销单拆单",
active: true,
specifications: [
{ id: "a:1", name: "AI合同审批单", type: "custom", active: true },
{ id: "a:2", name: "报销单-汇总", type: "expense", active: true },
{ id: "a:1", originalId: "a", name: "AI合同审批单", type: "custom", active: true },
{ id: "a:2", originalId: "a", name: "报销单-汇总", type: "expense", active: true },
],
},
{
name: "历史模板",
active: true,
specifications: [
{ id: "b:1", name: "旧报销单", type: "expense", active: false },
{ id: "b:1", originalId: "b", name: "旧报销单", type: "expense", active: false },
],
},
{
@@ -26,7 +26,7 @@ const raw = [
name: "停用分组",
active: false,
specifications: [
{ id: "c:1", name: "隐藏模板", type: "expense", active: true },
{ id: "c:1", originalId: "c", name: "隐藏模板", type: "expense", active: true },
],
},
];
@@ -51,6 +51,26 @@ describe("normalizeTemplateGroups", () => {
expect(inactiveSpecs.map((s) => s.name)).toEqual(["旧报销单"]);
});
it("优先使用 originalId,兼容含冒号的原始 ID", () => {
const result = normalizeTemplateGroups([
{
name: "系统模板",
active: true,
specifications: [
{
id: "ID01ofWoOC1wiX:system:预算调整申请单:d3ac4cb25935090ab684d3fa4537b3517a849646",
originalId: "ID01ofWoOC1wiX:system:预算调整申请单",
name: "预算调整申请单",
type: "custom",
active: true,
},
],
},
]);
expect(result.groups[0].specifications[0].id).toBe("ID01ofWoOC1wiX:system:预算调整申请单");
expect(result.groups[0].specifications[0].versionedId).toContain(":d3ac4cb");
});
it("保留分组名与模板类型", () => {
const result = normalizeTemplateGroups(raw);
expect(result.groups[0].specifications[0]).toMatchObject({
+15 -3
View File
@@ -34,11 +34,17 @@ export interface BillTemplateList {
interface RawSpecification {
id?: string;
originalId?: string;
name?: string;
type?: string;
active?: boolean;
}
/** 去掉版本化 ID 末尾的 `:<hash>`,保留可被 `bill spec` 使用的原始 ID。 */
function stripVersionHash(id: string): string {
return id.replace(/:[0-9a-f]{32,64}$/i, "");
}
interface RawGroup {
name?: string;
active?: boolean;
@@ -68,9 +74,13 @@ export function normalizeTemplateGroups(
inactive += 1;
if (!includeInactive) continue;
}
const versionedId = spec.id;
const originalId = typeof spec.originalId === "string" && spec.originalId.trim()
? spec.originalId
: stripVersionHash(versionedId);
specs.push({
id: spec.id.split(":")[0],
versionedId: spec.id,
id: originalId,
versionedId,
name: spec.name,
type: spec.type ?? "unknown",
active,
@@ -91,8 +101,10 @@ export async function listBillTemplates(
corpId: string,
options: ListBillTemplatesOptions = {}
): Promise<BillTemplateList> {
// 服务端/CDN 会缓存该 GET 响应,改名后可能读到旧名称;带时间戳强制回源。
const response = await client.get("api/form/v2/specificationGroups/withSpecificationVersioned", {
searchParams: { corpId },
searchParams: { corpId, _t: String(Date.now()) },
headers: { "cache-control": "no-cache", pragma: "no-cache" },
});
const json = (await response.json()) as { items?: RawGroup[]; value?: { items?: RawGroup[] } };
const items = json.items ?? json.value?.items ?? [];