diff --git a/src/utils/flowExecution.js b/src/utils/flowExecution.js index 44be2b6..5f06015 100644 --- a/src/utils/flowExecution.js +++ b/src/utils/flowExecution.js @@ -59,14 +59,50 @@ export const loadFlowItemRuntimeRoles = async (items = []) => { return mergeResourceRoleDefinitions(roleGroups) } +/** + * Loads runtime roles without merging equal role keys across flow items. + * Task orchestration needs one independent assignment per detection item because + * two items may use different physical robots even when their workflows define + * the same logical role (for example, `default_robot`). + */ +export const loadFlowItemScopedRuntimeRoles = async (items = []) => { + if (items.some((item) => !item?.itemId)) throw new Error('任务编排中存在缺少流程项ID的数据') + if (!items.length) throw new Error('当前任务没有编排任何流程项') + + const occurrences = new Map() + const roleGroups = await Promise.all(items.map(async (item) => { + const occurrence = (occurrences.get(String(item.itemId)) || 0) + 1 + occurrences.set(String(item.itemId), occurrence) + const response = await getDetect(item.itemId) + const graph = parseFlowData(item.itemName || item.itemId, response.data?.flowData) + return getResourceRoles(graph).map((role) => ({ + ...clone([role])[0], + roleKey: `${item.itemId}:${occurrence}:${role.roleKey}`, + sourceRoleKey: role.roleKey, + itemId: item.itemId, + itemName: item.itemName || String(item.itemId), + displayName: `${item.itemName || item.itemId} / ${role.displayName}`, + })) + })) + return roleGroups.flat() +} + export const loadTaskRuntimeRoles = async (taskId) => { if (!taskId) throw new Error('任务没有关联流程编排') const response = await getFlowParamsApi(taskId) return loadFlowItemRuntimeRoles(response.rows || []) } +export const loadTaskScopedRuntimeRoles = async (taskId) => { + if (!taskId) throw new Error('任务没有关联流程编排') + const response = await getFlowParamsApi(taskId) + return loadFlowItemScopedRuntimeRoles(response.rows || []) +} + export const createRuntimeAssignments = (roles = [], primaryRobotId = '') => roles.map((role, index) => ({ roleKey: role.roleKey, + ...(role.sourceRoleKey ? { sourceRoleKey: role.sourceRoleKey } : {}), + ...(role.itemId != null ? { itemId: role.itemId } : {}), members: [{ memberKey: `${role.roleKey}_1`, robotId: index === 0 ? primaryRobotId || role.legacyRobotId || '' : role.legacyRobotId || '', diff --git a/src/views/flow/components/RuntimeAssignmentsEditor.vue b/src/views/flow/components/RuntimeAssignmentsEditor.vue index 3abd07e..0876c1d 100644 --- a/src/views/flow/components/RuntimeAssignmentsEditor.vue +++ b/src/views/flow/components/RuntimeAssignmentsEditor.vue @@ -154,6 +154,8 @@ const initialize = async () => { const existingMember = existingAssignment?.members?.[0] return { roleKey: role.roleKey, + ...(role.sourceRoleKey ? { sourceRoleKey: role.sourceRoleKey } : {}), + ...(role.itemId != null ? { itemId: role.itemId } : {}), members: [{ ...existingMember, memberKey: `${role.roleKey}_1`, diff --git a/src/views/inspection/runTask/index.vue b/src/views/inspection/runTask/index.vue index 61651ea..e90506c 100644 --- a/src/views/inspection/runTask/index.vue +++ b/src/views/inspection/runTask/index.vue @@ -140,12 +140,14 @@ - +
+ +