From 4dbbd7d9cc80320a444472b4e32b25ce746eaf9d Mon Sep 17 00:00:00 2001 From: ssw Date: Thu, 30 Jul 2026 12:02:03 +0800 Subject: [PATCH] auto(14b5ea1b9bd9): session end @ 2026-07-30T12:02:03 (+4f) --- src/commands/workflow/index.ts | 4 ++ src/commands/workflow/launch.ts | 55 ++++++++++++++++------- src/commands/workflow/tasks.ts | 15 ++++--- tests/unit/workflow_command_smoke.test.ts | 10 ++--- 4 files changed, 57 insertions(+), 27 deletions(-) diff --git a/src/commands/workflow/index.ts b/src/commands/workflow/index.ts index f3e8166..9ec60d1 100644 --- a/src/commands/workflow/index.ts +++ b/src/commands/workflow/index.ts @@ -17,6 +17,8 @@ import { buildWorkflowSelectorCommand } from './selector.ts' import { buildWorkflowTasksCommand } from './tasks.ts' import { buildWorkflowSyncFormCommand } from './syncForm.ts' import { buildWorkflowAssignApproversCommand } from './assignApprovers.ts' +import { buildWorkflowSignCommand } from './sign.ts' +import { buildWorkflowHandleCommand } from './handle.ts' export function buildWorkflowCommand(): Command { const cmd = new Command('workflow').description('流程引擎 (模板 CRUD + 发起/审批 + 我的任务)') @@ -32,5 +34,7 @@ export function buildWorkflowCommand(): Command { cmd.addCommand(buildWorkflowTasksCommand()) cmd.addCommand(buildWorkflowSyncFormCommand()) // BS-新27 (jxcj 2026-07-01): 同步 form.formData cmd.addCommand(buildWorkflowAssignApproversCommand()) + cmd.addCommand(buildWorkflowSignCommand()) + cmd.addCommand(buildWorkflowHandleCommand()) return cmd } diff --git a/src/commands/workflow/launch.ts b/src/commands/workflow/launch.ts index 72ebdd1..949eb82 100644 --- a/src/commands/workflow/launch.ts +++ b/src/commands/workflow/launch.ts @@ -40,6 +40,38 @@ interface Opts { verbose?: boolean } +/** 镜像 FlowParser.vue 提交流程的请求体。status=1 才会创建首个 operator。 */ +export function buildWorkflowLaunchBody(flowId: string, formId: string, formData: Record) { + return { + id: '', + flowId, + formData, + formId, + status: 1, + flowUrgent: 1, + } +} + +/** 回查待签(category=0)与待办(category=1); 两者都是用户可继续处理的 actionable operator。 */ +export async function getLaunchOperatorList( + getList: (input: { category: number; flowId?: string; taskId?: string }) => Promise, + input: { flowId: string; taskId: string }, +): Promise> { + const results = await Promise.all([ + getList({ category: 0 }), + getList({ category: 1 }), + ]) + return results.flatMap(resp => { + const list: Array<{ id?: string; taskId?: string; taskNodeId?: string; userId?: string | number; handleId?: string | number }> = resp?.data?.list ?? resp?.list ?? [] + return list + .filter(o => !input.taskId || o.taskId === input.taskId) + .map(o => { + const userId = o.userId ?? o.handleId + return { ...o, userId: userId != null ? String(userId) : undefined } + }) + }) +} + export function buildWorkflowLaunchCommand(): Command { const cmd = new Command('launch') .description('发起流程 (绑定 formId + flowId, data 为表单数据 JSON). 严格策略: 发起后回查 actionable task + 可选 --auto-authorize') @@ -74,13 +106,7 @@ export function buildWorkflowLaunchCommand(): Command { } catch (e) { return ctx.fail(`--data 不是合法 JSON: ${(e as Error).message}`, { flowId: opts.flowId }) } - const body = { - flowId: opts.flowId, - formId: opts.formId, - formData: formDataObj, - status: 0, - approverUserId: '', - } + const body = buildWorkflowLaunchBody(opts.flowId, opts.formId, formDataObj) log.info(`POST /workflow/task flowId=${opts.flowId} formId=${opts.formId}`) const r = await c.postJson<{ id?: string; taskId?: string }>('/workflow/task', body) if (r.code !== 200) { @@ -110,15 +136,14 @@ export function buildWorkflowLaunchCommand(): Command { } // webapi 镜像 web task.ts:71-73 getFlowBeforeList (P0 严格镜像, BS-新147 修) - // - loadOperator.getFlowBeforeList({ category, flowId, taskId }) → JnpfResp - // - 镜像后无任何自写解析 (0 漂移, 跟 web task.ts 一致) - // - LaunchVerifyWebapi 契约需要 array of {id?, userId?}, 从 .data.list 取 + 边界 userId 类型 cast + // - defHttp shim 自动解包信封, 返回 ListResp; 兼容历史 wrapped 测试桩 + // - category=0 待签 + category=1 待办, 再按本次 taskId 本地筛选 + // - 后端 operator 用户字段是 handleId, 归一为 verifyLaunched 契约的 userId const verifyWebapi: LaunchVerifyWebapi = { - getFlowTaskOperatorList: async (input) => { - const resp = await loadOperator.getFlowBeforeList({ category: 2, flowId: input.flowId, taskId: input.taskId }) - const list: Array<{ id?: string; taskNodeId?: string; userId?: string | number }> = resp?.data?.list ?? [] - return list.map((o) => ({ ...o, userId: o.userId != null ? String(o.userId) : undefined })) - }, + getFlowTaskOperatorList: async (input) => getLaunchOperatorList( + params => loadOperator.getFlowBeforeList(params), + input, + ), postAuthorize: async (input) => { return c.postJson('/permission/authorize', { objectType: 'flowtask', flowId: input.flowId, taskId: input.taskId }) }, diff --git a/src/commands/workflow/tasks.ts b/src/commands/workflow/tasks.ts index 4a0e726..8246f00 100644 --- a/src/commands/workflow/tasks.ts +++ b/src/commands/workflow/tasks.ts @@ -2,7 +2,7 @@ * commands/workflow/tasks.ts — 查我的流程任务 (P1 NEW-CMD, v0.11+) * * API: GET /api/workflow/operator/List/{category}?keyword=&flowId=¤tPage=&pageSize= - * category: 1=待签 2=待办 3=已办 4=抄送 (默认 2 待办) + * category: 0=待签 1=待办 2=在办 3=已办 4=抄送 (默认 1 待办) * * 注意: web workFlow/task.ts 用了 @vben/stores (Pinia), 暂不镜像. * 本命令直接调 JNPF REST API. @@ -25,8 +25,9 @@ interface Opts { } const CATEGORY_NAMES: Record = { - '1': '待签', - '2': '待办', + '0': '待签', + '1': '待办', + '2': '在办', '3': '已办', '4': '抄送', } @@ -34,7 +35,7 @@ const CATEGORY_NAMES: Record = { export function buildWorkflowTasksCommand(): Command { const cmd = new Command('tasks') .description('查我的流程任务 (P1 NEW-CMD, AI 审批任务管理)') - .option('--category <1|2|3|4>', '任务分类 1=待签 2=待办 3=已办 4=抄送 (默认 2)', '2') + .option('--category <0|1|2|3|4>', '任务分类 0=待签 1=待办 2=在办 3=已办 4=抄送 (默认 1)', '1') .option('--flowId ', '按流程模板 id 过滤') .option('--keyword ', '按关键字模糊搜索 (流程名/发起人/单号)') addOutputOptions(cmd) @@ -51,7 +52,7 @@ export function buildWorkflowTasksCommand(): Command { fixes: [], }, async (ctx) => { try { - const category = opts.category || '2' + const category = opts.category || '1' const params: Record = { currentPage: '1', pageSize: '20', @@ -98,13 +99,13 @@ export function buildWorkflowTasksCommand(): Command { installHelpHook(cmd, { purpose: '查我的流程任务 (待签/待办/已办/抄送 4 类)', optional: { - '--category': '1=待签 2=待办 3=已办 4=抄送', + '--category': '0=待签 1=待办 2=在办 3=已办 4=抄送', '--flowId': '按流程模板 id 过滤', '--keyword': '按关键字模糊搜索', }, example: [ 'dacli workflow tasks # 默认查待办', - 'dacli workflow tasks --category=1 # 待签', + 'dacli workflow tasks --category=0 # 待签', 'dacli workflow tasks --keyword=请假', 'dacli workflow tasks --json', ], diff --git a/tests/unit/workflow_command_smoke.test.ts b/tests/unit/workflow_command_smoke.test.ts index 8301c0d..737b7e4 100644 --- a/tests/unit/workflow_command_smoke.test.ts +++ b/tests/unit/workflow_command_smoke.test.ts @@ -62,23 +62,23 @@ describe('workflow command smoke (6 commands)', () => { }) describe('tasks', () => { - it('--category=2 --flowId → 解析 (默认待办)', async () => { + it('--category=1 --flowId → 解析 (待办)', async () => { const cmd = buildWorkflowTasksCommand() try { - await cmd.parseAsync(['--category', '2', '--flowId', 'F1'], { from: 'user' }) + await cmd.parseAsync(['--category', '1', '--flowId', 'F1'], { from: 'user' }) } catch { /* ignore */ } const opts = cmd.opts<{ category?: string; flowId?: string }>() - expect(opts.category).toBe('2') + expect(opts.category).toBe('1') expect(opts.flowId).toBe('F1') }) - it('不传 --category → 默认 2 (待办)', async () => { + it('不传 --category → 默认 1 (待办)', async () => { const cmd = buildWorkflowTasksCommand() try { await cmd.parseAsync([], { from: 'user' }) } catch { /* ignore */ } const opts = cmd.opts<{ category?: string }>() - expect(opts.category).toBe('2') + expect(opts.category).toBe('1') }) })