forked from SmartBench/CMVR-IOT-UI
feat: 多检测项配置多机器人
This commit is contained in:
parent
8d2f3e37b4
commit
6b8fb06600
@ -59,14 +59,50 @@ export const loadFlowItemRuntimeRoles = async (items = []) => {
|
|||||||
return mergeResourceRoleDefinitions(roleGroups)
|
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) => {
|
export const loadTaskRuntimeRoles = async (taskId) => {
|
||||||
if (!taskId) throw new Error('任务没有关联流程编排')
|
if (!taskId) throw new Error('任务没有关联流程编排')
|
||||||
const response = await getFlowParamsApi(taskId)
|
const response = await getFlowParamsApi(taskId)
|
||||||
return loadFlowItemRuntimeRoles(response.rows || [])
|
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) => ({
|
export const createRuntimeAssignments = (roles = [], primaryRobotId = '') => roles.map((role, index) => ({
|
||||||
roleKey: role.roleKey,
|
roleKey: role.roleKey,
|
||||||
|
...(role.sourceRoleKey ? { sourceRoleKey: role.sourceRoleKey } : {}),
|
||||||
|
...(role.itemId != null ? { itemId: role.itemId } : {}),
|
||||||
members: [{
|
members: [{
|
||||||
memberKey: `${role.roleKey}_1`,
|
memberKey: `${role.roleKey}_1`,
|
||||||
robotId: index === 0 ? primaryRobotId || role.legacyRobotId || '' : role.legacyRobotId || '',
|
robotId: index === 0 ? primaryRobotId || role.legacyRobotId || '' : role.legacyRobotId || '',
|
||||||
|
|||||||
@ -154,6 +154,8 @@ const initialize = async () => {
|
|||||||
const existingMember = existingAssignment?.members?.[0]
|
const existingMember = existingAssignment?.members?.[0]
|
||||||
return {
|
return {
|
||||||
roleKey: role.roleKey,
|
roleKey: role.roleKey,
|
||||||
|
...(role.sourceRoleKey ? { sourceRoleKey: role.sourceRoleKey } : {}),
|
||||||
|
...(role.itemId != null ? { itemId: role.itemId } : {}),
|
||||||
members: [{
|
members: [{
|
||||||
...existingMember,
|
...existingMember,
|
||||||
memberKey: `${role.roleKey}_1`,
|
memberKey: `${role.roleKey}_1`,
|
||||||
|
|||||||
@ -168,7 +168,7 @@ import RuntimeAssignmentsEditor from '@/views/flow/components/RuntimeAssignments
|
|||||||
import {
|
import {
|
||||||
createRuntimeAssignments,
|
createRuntimeAssignments,
|
||||||
firstAssignedRobotId,
|
firstAssignedRobotId,
|
||||||
loadTaskRuntimeRoles,
|
loadTaskScopedRuntimeRoles,
|
||||||
} from '@/utils/flowExecution'
|
} from '@/utils/flowExecution'
|
||||||
|
|
||||||
const topContainerRef = ref();
|
const topContainerRef = ref();
|
||||||
@ -328,7 +328,7 @@ const startTask = async (task) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const roles = await loadTaskRuntimeRoles(taskDefinition.taskConfigId)
|
const roles = await loadTaskScopedRuntimeRoles(taskDefinition.taskConfigId)
|
||||||
runtimeAssignments.value = createRuntimeAssignments(roles, task.robotIdentity)
|
runtimeAssignments.value = createRuntimeAssignments(roles, task.robotIdentity)
|
||||||
runtimeMapId.value = taskDefinition.mapId || ''
|
runtimeMapId.value = taskDefinition.mapId || ''
|
||||||
runtimeRoles.value = roles
|
runtimeRoles.value = roles
|
||||||
|
|||||||
@ -187,7 +187,7 @@ import RuntimeAssignmentsEditor from '@/views/flow/components/RuntimeAssignments
|
|||||||
import {
|
import {
|
||||||
createRuntimeAssignments,
|
createRuntimeAssignments,
|
||||||
firstAssignedRobotId,
|
firstAssignedRobotId,
|
||||||
loadTaskRuntimeRoles,
|
loadTaskScopedRuntimeRoles,
|
||||||
} from '@/utils/flowExecution'
|
} from '@/utils/flowExecution'
|
||||||
|
|
||||||
const topContainerRef = ref();
|
const topContainerRef = ref();
|
||||||
@ -370,7 +370,7 @@ const startTask = async (task) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const roles = await loadTaskRuntimeRoles(taskDefinition.taskConfigId)
|
const roles = await loadTaskScopedRuntimeRoles(taskDefinition.taskConfigId)
|
||||||
runtimeAssignments.value = createRuntimeAssignments(roles)
|
runtimeAssignments.value = createRuntimeAssignments(roles)
|
||||||
runtimeRoles.value = roles
|
runtimeRoles.value = roles
|
||||||
pendingStartTask.value = task
|
pendingStartTask.value = task
|
||||||
|
|||||||
@ -71,7 +71,7 @@ import { taskExecute } from "@/api/test/config"
|
|||||||
import RuntimeAssignmentsEditor from '@/views/flow/components/RuntimeAssignmentsEditor.vue'
|
import RuntimeAssignmentsEditor from '@/views/flow/components/RuntimeAssignmentsEditor.vue'
|
||||||
import {
|
import {
|
||||||
firstAssignedRobotId,
|
firstAssignedRobotId,
|
||||||
loadFlowItemRuntimeRoles,
|
loadFlowItemScopedRuntimeRoles,
|
||||||
} from '@/utils/flowExecution'
|
} from '@/utils/flowExecution'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@ -104,7 +104,7 @@ const getFlowParams = async () => {
|
|||||||
const data = parseConfig(res.rows)
|
const data = parseConfig(res.rows)
|
||||||
formData.value.tableData = data
|
formData.value.tableData = data
|
||||||
runtimeAssignments.value = []
|
runtimeAssignments.value = []
|
||||||
roles.value = await loadFlowItemRuntimeRoles(data)
|
roles.value = await loadFlowItemScopedRuntimeRoles(data)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user