diff --git a/apps/app-pc/src/api/workflow.ts b/apps/app-pc/src/api/workflow.ts index 9aae186d..0272248f 100644 --- a/apps/app-pc/src/api/workflow.ts +++ b/apps/app-pc/src/api/workflow.ts @@ -12,8 +12,29 @@ export const changeState = (id:string) => { } /** - * 当前用户是否可执行「强制同步运行中实例」(仅流程管理员) + * 当前用户是否可执行「同步流程」(仅流程管理员) */ export const forceSyncPermission = () => { return httpClient.get('/api/query/workflow/permission/forceSync'); } + +export interface ForceSyncRequest { + /** 流程编码 */ + workCode: string; + /** 需要同步的流程实例,未指定的实例不受影响 */ + processIds: string[]; +} + +export interface ForceSyncResult { + workflowRuntimeId: number; + workVersion: number; + syncedProcessIds: string[]; + skippedProcessIds: string[]; +} + +/** + * 把指定流程实例的配置同步为最新流程设计 + */ +export const forceSync = (request: ForceSyncRequest) => { + return httpClient.post('/api/cmd/record/forceSync', request); +} diff --git a/apps/app-pc/src/components/workflow-list/index.tsx b/apps/app-pc/src/components/workflow-list/index.tsx index 77356662..a52aa7d7 100644 --- a/apps/app-pc/src/components/workflow-list/index.tsx +++ b/apps/app-pc/src/components/workflow-list/index.tsx @@ -2,8 +2,8 @@ import {Table, type TableProps} from "@coding-flow/flow-pc-ui"; import {type ActionType} from "@coding-flow/flow-core"; import React from "react"; import {Button, message, Popconfirm, Space} from "antd"; -import {DesignImport, DesignPanel, DesignSyncInstance} from "@coding-flow/flow-design"; -import {changeState, forceSyncPermission, list, remove} from "@/api/workflow.ts"; +import {DesignImport, DesignPanel} from "@coding-flow/flow-design"; +import {changeState, list, remove} from "@/api/workflow.ts"; import dayjs from "dayjs"; import { FlowMessageKey, FlowMessageRegistry } from "@coding-flow/flow-core"; @@ -13,16 +13,6 @@ export const WorkflowList = () => { const [currentId, setCurrentId] = React.useState(''); const [editable, setEditable] = React.useState(false); const [importVisible, setImportVisible] = React.useState(false); - const [syncVisible, setSyncVisible] = React.useState(false); - const [syncWorkCode, setSyncWorkCode] = React.useState(''); - // 强制同步属于流程管理员的干预操作,非管理员不展示该操作 - const [canForceSync, setCanForceSync] = React.useState(false); - - React.useEffect(() => { - forceSyncPermission().then(res => { - setCanForceSync(!!res.data); - }) - }, []); const handleChangeState = (id: any) => { @@ -118,14 +108,6 @@ export const WorkflowList = () => { setCurrentId(record.id); setEditable(true); }}>编辑 - { - canForceSync && ( - { - setSyncWorkCode(record.code); - setSyncVisible(true); - }}>强制同步 - ) - } { @@ -195,14 +177,6 @@ export const WorkflowList = () => { actionType.current?.reload(); }} /> - - { - setSyncVisible(false); - }} - /> ) } diff --git a/apps/app-pc/src/pages/todo.tsx b/apps/app-pc/src/pages/todo.tsx index 092fedb7..e102edaf 100644 --- a/apps/app-pc/src/pages/todo.tsx +++ b/apps/app-pc/src/pages/todo.tsx @@ -1,8 +1,9 @@ import React from "react"; import { done, list, notify, todo } from "@/api/record.ts"; +import { forceSync, forceSyncPermission, type ForceSyncResult } from "@/api/workflow.ts"; import { ApprovalPanelDrawer, FlowTitle, WorkflowSelectModal } from "@coding-flow/flow-pc-approval"; import { Table, type TableProps } from "@coding-flow/flow-pc-ui"; -import { Button, Space, Tabs, type TabsProps } from "antd"; +import { Button, message, Popconfirm, Space, Tabs, type TabsProps } from "antd"; import dayjs from "dayjs"; import { EventBus, type ActionType } from "@coding-flow/flow-core"; @@ -19,6 +20,34 @@ const TodoPage: React.FC = () => { const [workflowCode, setWorkflowCode] = React.useState(''); const [currentRecordId, setCurrentRecordId] = React.useState(''); const [currentTab, setCurrentTab] = React.useState('todo'); + // 同步流程属于流程管理员的干预操作,非管理员不展示该操作 + const [canForceSync, setCanForceSync] = React.useState(false); + + React.useEffect(() => { + forceSyncPermission().then(res => { + setCanForceSync(!!res.data); + }) + }, []); + + /** + * 把该流程实例的配置同步为最新流程设计(仅未完成的流程允许操作) + */ + const handleForceSync = (record: any) => { + forceSync({ + workCode: record.workCode, + processIds: [record.processId], + }).then(res => { + if (res.success) { + const result = res.data as ForceSyncResult | undefined; + if ((result?.syncedProcessIds?.length ?? 0) > 0) { + message.success('同步成功'); + } else { + message.info('该流程已是最新设计,无需同步'); + } + actionAll.current?.reload(); + } + }) + } const columns: TableProps['columns'] = [ { @@ -86,6 +115,31 @@ const TodoPage: React.FC = () => { >办理 ) + } else if (currentTab === 'all') { + return ( + + { + setCurrentRecordId(record.recordId); + setReviewVisible(true); + setApprovalVisible(true); + }} + >详情 + { + // 仅未完成的流程(flowState=0 运行中)允许把配置同步为最新设计 + canForceSync && record.flowState === 0 && ( + { + handleForceSync(record); + }} + > + 同步流程 + + ) + } + + ) } else { return ( diff --git a/packages/flow-core/src/message.ts b/packages/flow-core/src/message.ts index 773ccb4c..1e97c402 100644 --- a/packages/flow-core/src/message.ts +++ b/packages/flow-core/src/message.ts @@ -53,10 +53,6 @@ export const FlowMessageKey = { DESIGN_SCRIPT_COMPILE_ERROR: 'design.script_compile_error', DESIGN_VIEW_CODE_SAVE_SUCCESS: 'design.view_code_save_success', DESIGN_GROOVY_META_FAILED: 'design.groovy_meta_failed', - /** 运行中实例强制同步成功 */ - DESIGN_FORCE_SYNC_SUCCESS: 'design.force_sync_success', - /** 运行中实例强制同步未选择实例 */ - DESIGN_FORCE_SYNC_NO_SELECTED: 'design.force_sync_no_selected', // ---- App 层 ---- APP_LOGIN_SUCCESS: 'app.login_success', @@ -171,9 +167,6 @@ function getDefaultMessages(): Record { [FlowMessageKey.DESIGN_SCRIPT_COMPILE_ERROR]: '脚本编译请求失败', [FlowMessageKey.DESIGN_VIEW_CODE_SAVE_SUCCESS]: '保存成功', [FlowMessageKey.DESIGN_GROOVY_META_FAILED]: '获取脚本元数据失败', - [FlowMessageKey.DESIGN_FORCE_SYNC_SUCCESS]: (data: any) => - `已同步 ${data?.count ?? 0} 条流程实例,跳过 ${data?.skipped ?? 0} 条已是最新配置的实例`, - [FlowMessageKey.DESIGN_FORCE_SYNC_NO_SELECTED]: '请先选择需要同步的流程实例', // App 层 [FlowMessageKey.APP_LOGIN_SUCCESS]: 'login success', diff --git a/packages/flow-design/src/components/design-sync-instance/design_sync_instance.module.scss b/packages/flow-design/src/components/design-sync-instance/design_sync_instance.module.scss deleted file mode 100644 index 746601d1..00000000 --- a/packages/flow-design/src/components/design-sync-instance/design_sync_instance.module.scss +++ /dev/null @@ -1,3 +0,0 @@ -.notice { - margin-bottom: 12px; -} diff --git a/packages/flow-design/src/components/design-sync-instance/index.tsx b/packages/flow-design/src/components/design-sync-instance/index.tsx deleted file mode 100644 index ecde29b0..00000000 --- a/packages/flow-design/src/components/design-sync-instance/index.tsx +++ /dev/null @@ -1,128 +0,0 @@ -import React from "react"; -import {Alert, message, Modal, type TableColumnsType} from "antd"; -import {Table} from "@coding-flow/flow-pc-ui"; -import {FlowMessageKey, FlowMessageRegistry} from "@coding-flow/flow-core"; -import {forceSync, runningInstances, type ForceSyncResult, type RunningInstanceItem} from "@/api/workflow"; -import {toProcessIds} from "./selection"; -import styles from "./design_sync_instance.module.scss"; - -export interface DesignSyncInstanceProps { - /** 是否展示 */ - open: boolean; - /** 当前设计的流程编码 */ - workCode: string; - /** 关闭 */ - onClose: () => void; -} - -const columns: TableColumnsType = [ - { - title: '流程标题', - dataIndex: 'title', - ellipsis: true, - }, - { - title: '发起人', - dataIndex: 'createOperatorName', - width: 140, - render: (value: string | undefined) => value || '-', - }, - { - title: '创建时间', - dataIndex: 'createTime', - width: 200, - render: (value: number | undefined) => (value ? new Date(value).toLocaleString() : '-'), - }, -]; - -/** - * 运行中实例强制同步最新流程设计。 - * - *

只同步勾选的流程实例,未勾选的实例继续使用原运行时快照; - * 后端会校验流程结构与运行实例一致,新增/删除节点、调整节点顺序或删除已有按钮时不允许同步。

- */ -export const DesignSyncInstance: React.FC = (props) => { - - const [selectedRows, setSelectedRows] = React.useState([]); - const [submitting, setSubmitting] = React.useState(false); - - React.useEffect(() => { - if (!props.open) { - setSelectedRows([]); - setSubmitting(false); - } - }, [props.open]); - - const submit = async () => { - const processIds = toProcessIds(selectedRows); - if (processIds.length === 0) { - message.warning( - FlowMessageRegistry.getInstance().get(FlowMessageKey.DESIGN_FORCE_SYNC_NO_SELECTED) - ); - return; - } - setSubmitting(true); - try { - const response = await forceSync({ - workCode: props.workCode, - processIds, - }); - if (response.success) { - const result = response.data as ForceSyncResult | undefined; - message.success( - FlowMessageRegistry.getInstance().get(FlowMessageKey.DESIGN_FORCE_SYNC_SUCCESS, { - count: result?.syncedProcessIds?.length ?? 0, - skipped: result?.skippedProcessIds?.length ?? 0, - }) - ); - props.onClose(); - } - } finally { - setSubmitting(false); - } - }; - - return ( - - - - rowKey={"processId"} - columns={columns} - request={async (params) => { - const response = await runningInstances({ - workCode: props.workCode, - current: params.current, - pageSize: params.pageSize, - }); - return { - data: response.data ?? [], - success: response.success, - total: response.total ?? 0, - }; - }} - rowSelection={{ - selectedRowKeys: toProcessIds(selectedRows), - onChange: (_keys, rows) => { - setSelectedRows(rows); - }, - }} - /> - - ); -} diff --git a/packages/flow-design/src/components/design-sync-instance/selection.ts b/packages/flow-design/src/components/design-sync-instance/selection.ts deleted file mode 100644 index 1049c914..00000000 --- a/packages/flow-design/src/components/design-sync-instance/selection.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type {RunningInstanceItem} from "@/api/workflow"; - -/** - * 汇总选中实例的流程id。 - * - *

跨页勾选时 antd Table 会返回多行数据(同一实例以开始节点记录代表一行), - * 这里按 processId 去重并过滤空值,避免重复提交同一实例。

- */ -export const toProcessIds = (rows: RunningInstanceItem[]): string[] => { - const processIds = rows - .map((row) => row.processId) - .filter((processId): processId is string => !!processId); - return Array.from(new Set(processIds)); -} diff --git a/packages/flow-design/src/index.ts b/packages/flow-design/src/index.ts index a9e9ba8a..9f3ab042 100644 --- a/packages/flow-design/src/index.ts +++ b/packages/flow-design/src/index.ts @@ -1,4 +1,3 @@ export * from '@/components/design-panel'; export * from '@/components/design-import'; -export * from '@/components/design-sync-instance'; export * from '@/plugins'; diff --git a/packages/flow-design/tests/components/sync-instance-selection.test.ts b/packages/flow-design/tests/components/sync-instance-selection.test.ts deleted file mode 100644 index 402fad54..00000000 --- a/packages/flow-design/tests/components/sync-instance-selection.test.ts +++ /dev/null @@ -1,49 +0,0 @@ -import {describe, expect, it} from "@rstest/core"; -import {toProcessIds} from "@/components/design-sync-instance/selection"; -import type {RunningInstanceItem} from "@/api/workflow"; - -/** - * 运行中实例强制同步(后端 issue #281) - * - * 选择弹窗按「开始节点记录」代表一个流程实例,提交时只传流程id; - * 跨页勾选可能重复返回同一实例,需要去重并过滤空值。 - */ -describe('强制同步实例选择', () => { - - const row = (processId: string): RunningInstanceItem => ({ - processId, - recordId: 1, - }); - - it('应返回选中实例的流程id', () => { - // when - const processIds = toProcessIds([row('p1'), row('p2')]); - - // then - expect(processIds).toEqual(['p1', 'p2']); - }); - - it('应对重复的流程id去重', () => { - // when - const processIds = toProcessIds([row('p1'), row('p1'), row('p2')]); - - // then - expect(processIds).toEqual(['p1', 'p2']); - }); - - it('应过滤空流程id', () => { - // when - const processIds = toProcessIds([row(''), row('p1')]); - - // then - expect(processIds).toEqual(['p1']); - }); - - it('未选择时应返回空数组', () => { - // when - const processIds = toProcessIds([]); - - // then - expect(processIds).toEqual([]); - }); -});