Merge pull request #118 from yunyingk/feat/workflow-action-enums-and-lint
feat(workflow): add action enums, EKB_ENUM resolver, and condition dead-filter lint
This commit is contained in:
10 files changed
+484
-9
No files matched your search
@@ -0,0 +1,79 @@
|
||||
import {
|
||||
resolveWorkflowEnumOptions,
|
||||
SYSTEM_WORKFLOW_ACTION_ENUMS,
|
||||
} from "../../../domains/platform/services.js";
|
||||
import { stringOption } from "../../parser.js";
|
||||
import { printJson, printTable, printKeyValue } from "../../printer.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
import { createJobPiperClient } from "./shared.js";
|
||||
|
||||
export async function handleWorkflowEnum(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const thirdId =
|
||||
parsed.args[0] ||
|
||||
stringOption(parsed.options, ["third-id", "thirdId", "id", "type"]) ||
|
||||
"action";
|
||||
|
||||
let client: any = undefined;
|
||||
if (runtime.selectedCorp) {
|
||||
try {
|
||||
client = await createJobPiperClient(parsed, runtime);
|
||||
} catch {
|
||||
// 离线或创建客户端失败时走本地内置 Fallback
|
||||
}
|
||||
}
|
||||
|
||||
const platformId = stringOption(parsed.options, ["platform-id", "platformId", "app-id", "appId"]);
|
||||
const items = await resolveWorkflowEnumOptions(client, thirdId, platformId);
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(items, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
if (items.length === 0) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `未查询到字典/枚举 [${thirdId}] 的可用选项(可能无网络、无自建应用权限或该 thirdId 不存在)。\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
const isAction = thirdId.toLowerCase() === "action";
|
||||
const rows = items.map((item) => [
|
||||
item.code,
|
||||
item.label,
|
||||
item.description ||
|
||||
(isAction
|
||||
? SYSTEM_WORKFLOW_ACTION_ENUMS.find((s) => s.code === item.code)?.description || "-"
|
||||
: "-"),
|
||||
]);
|
||||
|
||||
const output = [
|
||||
`====== 工作流枚举字典: ${thirdId} (共 ${items.length} 项) ======`,
|
||||
printKeyValue({
|
||||
"字典类别 (thirdId)": thirdId,
|
||||
"总项数": items.length,
|
||||
"数据来源": client ? "在线获取 (含内置兼容)" : "系统内置静态字典 (离线/默认)",
|
||||
}),
|
||||
"",
|
||||
printTable(["Code (底层真实值)", "名称 (界面展示)", "说明 / 适用场景"], rows),
|
||||
"",
|
||||
isAction
|
||||
? "💡 提示:在配置工作流条件节点时,务必选择 [通知类型] (action) 并从下拉列表中选中上述枚举,切勿选择 [审批状态] 匹配汉字!"
|
||||
: "",
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join("\n");
|
||||
|
||||
return {
|
||||
stdout: output + "\n",
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import { handleCreate } from "./create.js";
|
||||
import { handleNodeCommand } from "./node.js";
|
||||
import { handleWorkflowTailCommand } from "./tail.js";
|
||||
import { handleWorkflowLintScript, handleWorkflowEvalScript } from "./script.js";
|
||||
import { handleWorkflowEnum } from "./enum.js";
|
||||
|
||||
export async function handleWorkflowCommand(
|
||||
parsed: CliParsedArgs,
|
||||
@@ -108,10 +109,15 @@ export async function handleWorkflowCommand(
|
||||
case "eval-code":
|
||||
case "run-script":
|
||||
return handleWorkflowEvalScript(parsed, runtime);
|
||||
case "enum":
|
||||
case "enums":
|
||||
case "dictionary":
|
||||
case "dict":
|
||||
return handleWorkflowEnum(parsed, runtime);
|
||||
default:
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `未知 workflow 子命令: ${action}。支持: list, get, find, analyze, toggle, publish, patch, save, history, logs, job, diff, diff-job, check, test, copy, create, delete, node, tail, lint-script, eval-script\n`,
|
||||
stderr: `未知 workflow 子命令: ${action}。支持: list, get, find, analyze, toggle, publish, patch, save, history, logs, job, diff, diff-job, check, test, copy, create, delete, node, tail, lint-script, eval-script, enum\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,16 +6,17 @@ Platform 域负责工作流(EASO/Piper)以及自建应用容器的兼容能
|
||||
|
||||
```text
|
||||
src/domains/platform/
|
||||
├── types.ts # Zod schema 与类型定义(含 Job 执行树、失败节点、节点日志)
|
||||
├── api.ts # HTTP 传输层(含 unwrap 空安全校验与 Piper Job 5 大诊断端点)
|
||||
├── services.ts # 门面聚合与对外服务导出
|
||||
├── types.ts # Zod schema 与类型定义(含 Job 执行树、失败节点、节点日志、枚举类型)
|
||||
├── api.ts # HTTP 传输层(含 unwrap 空安全校验、Piper Job 端点与 EKB_ENUM 字典拉取)
|
||||
├── services.ts # 门面聚合与对外服务导出(含 resolveWorkflowEnumOptions 混合架构)
|
||||
├── workflow/ # 工作流体系子域(高内聚分层架构)
|
||||
│ ├── index.ts # 工作流能力统合导出
|
||||
│ ├── enums.ts # 单据审批事件触发器标准系统枚举(18 项内置字典与翻译器)
|
||||
│ ├── watch/ # 实时任务监听、TaskExecutionTracker 状态机与日志流 (tracker, engine, formatter)
|
||||
│ ├── nodes/ # 声明式节点树编排、树形索引定位、插入追加与重排 (tree, locator, mutations)
|
||||
│ ├── script/ # 脚本 AST 语法校验、上游依赖扫描与隔离沙箱仿真引擎 (lint, scanner, sandbox)
|
||||
│ ├── branch/ # 条件分支与规则解释诊断引擎 (explain, types)
|
||||
│ ├── analysis/ # 工作流静态吞错、禁用状态与联动覆盖巡检 (analyzer, types)
|
||||
│ ├── analysis/ # 工作流静态吞错、审批状态死锁过滤与联动覆盖巡检 (analyzer, types)
|
||||
│ ├── state/ # 草稿版本状态机与发布乐观锁保护
|
||||
│ └── alert/ # 错误指纹告警与 SQLite 本地持久化
|
||||
└── tools.ts # MCP tool 注册
|
||||
@@ -26,6 +27,7 @@ src/domains/platform/
|
||||
```bash
|
||||
hose-use workflow list [--platform-id=<id>|--app-id=<id>]
|
||||
hose-use workflow get <pipelineId>
|
||||
hose-use workflow enum [thirdId] [--third-id=<id>] [--json]
|
||||
hose-use workflow analyze <pipelineId> [--json]
|
||||
hose-use workflow logs <pipelineId> [--has-error] [--state=FAILED]
|
||||
hose-use workflow job <jobId> [--failed] [--node=<name|id>] [--verbose]
|
||||
|
||||
@@ -22,6 +22,8 @@ import {
|
||||
WorkflowSampleDataResultSchema,
|
||||
type WorkflowSampleDataResult,
|
||||
WorkflowDebugSourceResultSchema,
|
||||
WorkflowEnumItemSchema,
|
||||
type WorkflowEnumItem,
|
||||
} from "./types.js";
|
||||
import type { WorkflowState } from "./types.js";
|
||||
|
||||
@@ -410,4 +412,21 @@ export async function getWorkflowSampleData(
|
||||
return unwrap(response, WorkflowSampleDataResultSchema);
|
||||
}
|
||||
|
||||
// ── 工作流/Piper 条件与触发器枚举字典 ──────────────────────────────────────────
|
||||
|
||||
export async function getWorkflowEnumOptions(
|
||||
client: KyInstance,
|
||||
thirdId: string,
|
||||
platformId?: string
|
||||
): Promise<WorkflowEnumItem[]> {
|
||||
const jsonBody = platformId ? { $platformId: platformId } : {};
|
||||
const response = await client.post(
|
||||
`api/easo/dsl/condition/select/EKB_ENUM?thirdId=${encodeURIComponent(thirdId)}`,
|
||||
{
|
||||
json: jsonBody,
|
||||
}
|
||||
);
|
||||
return unwrap(response, z.array(WorkflowEnumItemSchema));
|
||||
}
|
||||
|
||||
|
||||
@@ -940,4 +940,41 @@ export async function getWorkflowSampleData(
|
||||
return api.getWorkflowSampleData(client, pipelineId, type);
|
||||
}
|
||||
|
||||
export function getWorkflowEnumOptions(...args: Parameters<typeof api.getWorkflowEnumOptions>) {
|
||||
return api.getWorkflowEnumOptions(...args);
|
||||
}
|
||||
|
||||
export async function resolveWorkflowEnumOptions(
|
||||
client?: import("ky").KyInstance,
|
||||
thirdId = "action",
|
||||
platformId?: string
|
||||
): Promise<Array<{ code: string; label: string; name: string; description?: string }>> {
|
||||
if (client) {
|
||||
try {
|
||||
const remote = await api.getWorkflowEnumOptions(client, thirdId, platformId);
|
||||
if (remote && remote.length > 0) {
|
||||
return remote.map((item) => ({
|
||||
code: item.code,
|
||||
label: item.label,
|
||||
name: item.name || item.label,
|
||||
}));
|
||||
}
|
||||
} catch {
|
||||
// 远程调用失败(如无权限/网络异常)时 Fallback 到内置字典
|
||||
}
|
||||
}
|
||||
|
||||
if (thirdId.toLowerCase() === "action") {
|
||||
const { SYSTEM_WORKFLOW_ACTION_ENUMS } = await import("./workflow/enums.js");
|
||||
return SYSTEM_WORKFLOW_ACTION_ENUMS.map((item) => ({
|
||||
code: item.code,
|
||||
label: item.label,
|
||||
name: item.name,
|
||||
description: item.description,
|
||||
}));
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
export * from "./workflow/index.js";
|
||||
@@ -699,6 +699,12 @@ export const WorkflowSampleDataResultSchema = z.object({
|
||||
|
||||
export type WorkflowSampleDataResult = z.infer<typeof WorkflowSampleDataResultSchema>;
|
||||
|
||||
// ── 工作流/Piper 枚举选项 (EKB_ENUM) ──────────────────────────────────────────
|
||||
|
||||
export const WorkflowEnumItemSchema = z.object({
|
||||
label: z.string(),
|
||||
code: z.string(),
|
||||
name: z.string().optional().default(""),
|
||||
});
|
||||
|
||||
|
||||
export type WorkflowEnumItem = z.infer<typeof WorkflowEnumItemSchema>;
|
||||
@@ -127,6 +127,33 @@ function getTaskFormEntries(
|
||||
return [];
|
||||
}
|
||||
|
||||
interface LeafFilterItem {
|
||||
key?: unknown;
|
||||
value?: unknown;
|
||||
compare?: unknown;
|
||||
label?: unknown;
|
||||
}
|
||||
|
||||
function extractLeafFilters(filterGroup: unknown): LeafFilterItem[] {
|
||||
if (!filterGroup || typeof filterGroup !== "object") return [];
|
||||
const items: LeafFilterItem[] = [];
|
||||
const rec = filterGroup as Record<string, unknown>;
|
||||
|
||||
if (Array.isArray(rec.filters)) {
|
||||
for (const sub of rec.filters) {
|
||||
items.push(...extractLeafFilters(sub));
|
||||
}
|
||||
} else if ("key" in rec || "value" in rec) {
|
||||
items.push({
|
||||
key: rec.key,
|
||||
value: rec.value,
|
||||
compare: rec.compare,
|
||||
label: rec.label,
|
||||
});
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
export function extractWorkflowSpecificationIds(detail: WorkflowDetail): string[] {
|
||||
const ids = new Set<string>();
|
||||
const walk = (tasks: WorkflowTask[]) => {
|
||||
@@ -351,18 +378,72 @@ export function analyzeWorkflow(
|
||||
const rawFilters = JSON.stringify((task as Record<string, unknown>).combineFilters);
|
||||
if (
|
||||
rawFilters.includes('"key":"state"') &&
|
||||
(rawFilters.includes('"APPROVING"') || rawFilters.includes('"approving"'))
|
||||
(rawFilters.includes('"APPROVING"') ||
|
||||
rawFilters.includes('"approving"') ||
|
||||
rawFilters.includes('"REJECTED"') ||
|
||||
rawFilters.includes('"rejected"') ||
|
||||
rawFilters.includes("被驳回") ||
|
||||
rawFilters.includes("审批驳回"))
|
||||
) {
|
||||
diagnostics.push({
|
||||
severity: "error",
|
||||
code: "DEADLOCK_TRIGGER_STATE_FILTER",
|
||||
path,
|
||||
message: `触发器节点 [${task.label || task.name}] (${task.name}) 配置了 state == APPROVING 状态过滤条件。合思单据审批出站事件属于动作事件(如 backlog.approving),事件载荷中不携带大写 APPROVING 状态字段,该过滤会导致出站事件被 100% 静默丢弃,下游审批流程永久无法触发!建议移除 state 过滤,改用后置条件节点判断审批人。`,
|
||||
message: `触发器节点 [${task.label || task.name}] (${task.name}) 配置了 state 状态过滤条件。合思单据审批出站事件属于动作事件(如 backlog.approving / flow.rejected),事件载荷中单据 state 字段在事件触发初始阶段可能为空或为大写英文 REJECTED,该过滤会导致出站事件被 100% 静默丢弃,下游审批流程永久无法触发!建议移除 state 过滤,改用通知类型(action)或后置条件节点。`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 诊断 5: HTTP 自动审批节点 URL 与中括号校验 (MISSING_BACKLOG_DATA_BRACKETS)
|
||||
// 诊断 5: 条件节点中单据审批状态过滤缺陷与纯文本枚举比对 (DEADLOCK_CONDITION_STATE_FILTER / INVALID_ACTION_ENUM_TEXT_VALUE)
|
||||
if (task.type === "condition") {
|
||||
const raw = task as Record<string, unknown>;
|
||||
const filterSource = raw.combineFilters ?? raw.filters ?? raw.conditions ?? task.inputs;
|
||||
if (filterSource) {
|
||||
const leafFilters = extractLeafFilters(filterSource);
|
||||
for (const leaf of leafFilters) {
|
||||
const keyStr = String(leaf.key || "");
|
||||
const valStr = typeof leaf.value === "string" ? leaf.value : JSON.stringify(leaf.value ?? "");
|
||||
const isStateField =
|
||||
keyStr === "state" ||
|
||||
/"key":"state"/i.test(keyStr) ||
|
||||
/"label":"[^"]*审批状态"/i.test(keyStr);
|
||||
const isActionField =
|
||||
keyStr === "action" ||
|
||||
/"key":"action"/i.test(keyStr) ||
|
||||
/"thirdId":"action"/i.test(keyStr) ||
|
||||
/"label":"[^"]*通知类型"/i.test(keyStr);
|
||||
|
||||
if (isStateField && /被驳回|审批驳回|REJECTED|reject/i.test(valStr)) {
|
||||
diagnostics.push({
|
||||
severity: "error",
|
||||
code: "DEADLOCK_CONDITION_STATE_FILTER",
|
||||
path,
|
||||
message: `条件节点 [${task.label || task.name}] (${task.name}) 配置了使用单据审批状态 [state] 匹配驳回状态。合思单据出站事件为动作事件(Action Event),事件载荷中单据审批状态字段在事件触发初始阶段可能为空或为大写英文 REJECTED,使用中文 [被驳回/审批驳回] 匹配会导致条件 100% 判定为 false!建议改用触发器通知类型 [action],并在下拉选项中选中标准枚举宏(对应 code: flow.rejected)。`,
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
isActionField &&
|
||||
valStr &&
|
||||
!valStr.includes("@{value(") &&
|
||||
!valStr.includes("flow.") &&
|
||||
!valStr.includes("freeflow.") &&
|
||||
!valStr.includes("backlog.") &&
|
||||
!valStr.includes("timeout.") &&
|
||||
/被驳回|已支付|待审批|待支付|待收单|撤回|删除|催办/i.test(valStr)
|
||||
) {
|
||||
diagnostics.push({
|
||||
severity: "error",
|
||||
code: "INVALID_ACTION_ENUM_TEXT_VALUE",
|
||||
path,
|
||||
message: `条件节点 [${task.label || task.name}] (${task.name}) 中通知类型 [action] 为 ENUM 枚举字段,但比对值被配置为了纯文本 [${valStr}]。Piper 运行时会使用底层英文枚举 Code (如 flow.rejected) 进行比对,纯文本将导致条件永远不匹配。请在条件节点右侧通过下拉列表选择标准枚举项。`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 诊断 6: HTTP 自动审批节点 URL 与中括号校验 (MISSING_BACKLOG_DATA_BRACKETS)
|
||||
if (task.type === "http") {
|
||||
const url = String((task as Record<string, unknown>).url || "");
|
||||
if (url.includes("api/openapi/v1/backlog/data")) {
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import {
|
||||
SYSTEM_WORKFLOW_ACTION_ENUMS,
|
||||
translateWorkflowAction,
|
||||
isWorkflowActionCode,
|
||||
matchWorkflowAction,
|
||||
resolveWorkflowEnumOptions,
|
||||
} from "../services.js";
|
||||
import { analyzeWorkflow } from "./analysis/index.js";
|
||||
|
||||
describe("Workflow Action Enums & Diagnostics", () => {
|
||||
it("contains 18 standard system notification action enums", () => {
|
||||
expect(SYSTEM_WORKFLOW_ACTION_ENUMS).toHaveLength(18);
|
||||
const codes = SYSTEM_WORKFLOW_ACTION_ENUMS.map((item) => item.code);
|
||||
expect(codes).toContain("flow.rejected");
|
||||
expect(codes).toContain("flow.paid");
|
||||
expect(codes).toContain("backlog.approving");
|
||||
expect(codes).toContain("backlog.paying");
|
||||
expect(codes).toContain("backlog.receiving");
|
||||
expect(codes).toContain("freeflow.retract");
|
||||
});
|
||||
|
||||
it("translates workflow action codes accurately", () => {
|
||||
expect(translateWorkflowAction("flow.rejected")).toBe("被驳回");
|
||||
expect(translateWorkflowAction("flow.paid")).toBe("已支付/审批完成");
|
||||
expect(translateWorkflowAction("backlog.approving")).toBe("待审批");
|
||||
expect(translateWorkflowAction("unknown.action")).toBe("unknown.action");
|
||||
expect(translateWorkflowAction(undefined)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("checks if a code is a known workflow action", () => {
|
||||
expect(isWorkflowActionCode("flow.rejected")).toBe(true);
|
||||
expect(isWorkflowActionCode("flow.paid")).toBe(true);
|
||||
expect(isWorkflowActionCode("custom.action")).toBe(false);
|
||||
});
|
||||
|
||||
it("matches workflow action by code or label", () => {
|
||||
const matchByLabel = matchWorkflowAction("被驳回");
|
||||
expect(matchByLabel?.code).toBe("flow.rejected");
|
||||
|
||||
const matchByCode = matchWorkflowAction("flow.rejected");
|
||||
expect(matchByCode?.label).toBe("被驳回");
|
||||
|
||||
expect(matchWorkflowAction("不存在的动作")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("resolves fallback options when client is undefined", async () => {
|
||||
const options = await resolveWorkflowEnumOptions(undefined, "action");
|
||||
expect(options).toHaveLength(18);
|
||||
expect(options.find((o) => o.code === "flow.rejected")?.label).toBe("被驳回");
|
||||
});
|
||||
|
||||
it("detects DEADLOCK_CONDITION_STATE_FILTER when condition matches state against '被驳回'", () => {
|
||||
const wf = {
|
||||
id: "wf-cond-deadlock",
|
||||
label: "单据条件判断",
|
||||
state: 1,
|
||||
version: "1",
|
||||
tasks: [
|
||||
{
|
||||
name: "trigger_1",
|
||||
type: "ekuaibao-flowform-trigger",
|
||||
label: "单据审批事件触发器",
|
||||
},
|
||||
{
|
||||
name: "control_1",
|
||||
type: "condition",
|
||||
label: "条件节点",
|
||||
combineFilters: {
|
||||
condition: "or",
|
||||
filters: [
|
||||
{
|
||||
condition: "and",
|
||||
filters: [
|
||||
{
|
||||
key: "@{choose('{\"key\":\"trigger_1\",\"properties\":[{\"key\":\"state\",\"label\":\"审批状态\",\"type\":\"TEXT\"}],\"label\":\"单据审批事件触发器.审批状态\"}')}",
|
||||
compare: "eq",
|
||||
value: "被驳回",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
tasks: [
|
||||
{
|
||||
name: "stop_1",
|
||||
type: "stop",
|
||||
label: "终止",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = analyzeWorkflow(wf as any);
|
||||
const codes = result.diagnostics.map((d) => d.code);
|
||||
expect(codes).toContain("DEADLOCK_CONDITION_STATE_FILTER");
|
||||
const diag = result.diagnostics.find((d) => d.code === "DEADLOCK_CONDITION_STATE_FILTER");
|
||||
expect(diag?.severity).toBe("error");
|
||||
expect(diag?.message).toContain("单据审批状态 [state]");
|
||||
expect(diag?.message).toContain("flow.rejected");
|
||||
});
|
||||
|
||||
it("detects INVALID_ACTION_ENUM_TEXT_VALUE when condition matches action with plain text '被驳回'", () => {
|
||||
const wf = {
|
||||
id: "wf-action-text",
|
||||
label: "单据通知类型错误文本比较",
|
||||
state: 1,
|
||||
version: "1",
|
||||
tasks: [
|
||||
{
|
||||
name: "control_2",
|
||||
type: "condition",
|
||||
label: "条件节点",
|
||||
combineFilters: {
|
||||
condition: "or",
|
||||
filters: [
|
||||
{
|
||||
condition: "and",
|
||||
filters: [
|
||||
{
|
||||
key: "@{choose('{\"key\":\"trigger_1\",\"properties\":[{\"key\":\"action\",\"label\":\"通知类型\",\"type\":\"ENUM\",\"thirdId\":\"action\"}],\"label\":\"单据审批事件触发器.通知类型\"}')}",
|
||||
compare: "eq",
|
||||
value: "被驳回",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
tasks: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = analyzeWorkflow(wf as any);
|
||||
const codes = result.diagnostics.map((d) => d.code);
|
||||
expect(codes).toContain("INVALID_ACTION_ENUM_TEXT_VALUE");
|
||||
const diag = result.diagnostics.find((d) => d.code === "INVALID_ACTION_ENUM_TEXT_VALUE");
|
||||
expect(diag?.severity).toBe("error");
|
||||
expect(diag?.message).toContain("纯文本");
|
||||
});
|
||||
|
||||
it("passes cleanly when condition correctly uses action enum macro @value(flow.rejected)", () => {
|
||||
const wf = {
|
||||
id: "wf-valid-action",
|
||||
label: "单据通知类型正确配置",
|
||||
state: 1,
|
||||
version: "1",
|
||||
tasks: [
|
||||
{
|
||||
name: "control_3",
|
||||
type: "condition",
|
||||
label: "条件节点",
|
||||
combineFilters: {
|
||||
condition: "or",
|
||||
filters: [
|
||||
{
|
||||
condition: "and",
|
||||
filters: [
|
||||
{
|
||||
key: "@{choose('{\"key\":\"trigger_1\",\"properties\":[{\"key\":\"action\",\"label\":\"通知类型\",\"type\":\"ENUM\",\"thirdId\":\"action\"}],\"label\":\"单据审批事件触发器.通知类型\"}')}",
|
||||
compare: "eq",
|
||||
value: "@{value('{\"key\":\"flow.rejected\",\"label\":\"被驳回\"}')}",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
tasks: [
|
||||
{
|
||||
name: "stop_1",
|
||||
type: "stop",
|
||||
label: "终止",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = analyzeWorkflow(wf as any);
|
||||
const codes = result.diagnostics.map((d) => d.code);
|
||||
expect(codes).not.toContain("DEADLOCK_CONDITION_STATE_FILTER");
|
||||
expect(codes).not.toContain("INVALID_ACTION_ENUM_TEXT_VALUE");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* 合思/易快报工作流(Piper / EASO)单据审批事件触发器通知类型标准系统枚举
|
||||
* 对应底层接口:POST /api/easo/dsl/condition/select/EKB_ENUM?thirdId=action
|
||||
*/
|
||||
|
||||
export interface WorkflowActionEnumItem {
|
||||
code: string;
|
||||
label: string;
|
||||
name: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export const SYSTEM_WORKFLOW_ACTION_ENUMS: readonly WorkflowActionEnumItem[] = [
|
||||
{ code: "flow.rejected", label: "被驳回", name: "被驳回", description: "单据审批被驳回时触发" },
|
||||
{ code: "flow.paid", label: "已支付/审批完成", name: "已支付/审批完成", description: "单据已支付或终审完成时触发" },
|
||||
{ code: "backlog.approving", label: "待审批", name: "待审批", description: "单据进入审批待办节点时触发" },
|
||||
{ code: "backlog.paying", label: "待支付", name: "待支付", description: "单据进入待支付节点时触发" },
|
||||
{ code: "backlog.sending", label: "待寄送", name: "待寄送", description: "单据需要寄送发票/材料时触发" },
|
||||
{ code: "backlog.receiving", label: "待收单", name: "待收单", description: "财务待收单时触发" },
|
||||
{ code: "backlog.processed", label: "待办已处理", name: "待办已处理", description: "待办任务已处理完成时触发" },
|
||||
{ code: "backlog.payment", label: "支付中", name: "支付中", description: "银行出纳支付处理中时触发" },
|
||||
{ code: "freeflow.retract", label: "单据撤回", name: "单据撤回", description: "发起人主动撤回单据时触发" },
|
||||
{ code: "freeflow.delete", label: "单据删除", name: "单据删除", description: "单据被彻底删除时触发" },
|
||||
{ code: "freeflow.mention", label: "被@", name: "被@", description: "单据评论或流转中被@提及" },
|
||||
{ code: "freeflow.comment", label: "评论", name: "评论", description: "单据新增审批意见或评论" },
|
||||
{ code: "freeflow.remind", label: "催办", name: "催办", description: "发起人对审批人执行催办" },
|
||||
{ code: "freeflow.carbonCopy", label: "抄送", name: "抄送", description: "单据到达抄送节点或被抄送" },
|
||||
{ code: "freeflow.alter", label: "申请单变更", name: "申请单变更", description: "借款/申请单内容发生变更" },
|
||||
{ code: "freeflow.ticketReserve", label: "审批通过(已开通【差旅管理】的用户)", name: "审批通过(已开通【差旅管理】的用户)", description: "开通差旅模块的用户审批通过预订车票/酒店" },
|
||||
{ code: "freeflow.print", label: "打印提醒", name: "打印提醒", description: "单据触发打印或需要打印提醒" },
|
||||
{ code: "timeout.remind", label: "超时提醒", name: "超时提醒", description: "审批节点到达超时时限自动提醒" },
|
||||
] as const;
|
||||
|
||||
export type SystemWorkflowActionCode = (typeof SYSTEM_WORKFLOW_ACTION_ENUMS)[number]["code"];
|
||||
|
||||
export const WORKFLOW_ACTION_MAP: Record<string, string> = Object.fromEntries(
|
||||
SYSTEM_WORKFLOW_ACTION_ENUMS.map((item) => [item.code, item.label])
|
||||
);
|
||||
|
||||
export const WORKFLOW_ACTION_REVERSE_MAP: Record<string, string> = Object.fromEntries(
|
||||
SYSTEM_WORKFLOW_ACTION_ENUMS.map((item) => [item.label, item.code])
|
||||
);
|
||||
|
||||
export function translateWorkflowAction(action?: string): string | undefined {
|
||||
if (!action) return undefined;
|
||||
return WORKFLOW_ACTION_MAP[action] || action;
|
||||
}
|
||||
|
||||
export function isWorkflowActionCode(code: string): boolean {
|
||||
return code in WORKFLOW_ACTION_MAP;
|
||||
}
|
||||
|
||||
export function matchWorkflowAction(query: string): WorkflowActionEnumItem | undefined {
|
||||
const trimmed = query.trim();
|
||||
if (!trimmed) return undefined;
|
||||
return SYSTEM_WORKFLOW_ACTION_ENUMS.find(
|
||||
(item) => item.code.toLowerCase() === trimmed.toLowerCase() || item.label === trimmed || item.name === trimmed
|
||||
);
|
||||
}
|
||||
@@ -5,3 +5,4 @@ export * from "./branch/index.js";
|
||||
export * from "./analysis/index.js";
|
||||
export * from "./state/index.js";
|
||||
export * from "./alert/index.js";
|
||||
export * from "./enums.js";
|
||||
Reference in new issue
Block a user