export interface HandlingDetail {
|
id: string;
|
nodeId?: string;
|
expectedUser?: string;
|
deliveryTime?: number | string;
|
hasHandlingRecord?: boolean;
|
[key: string]: any;
|
}
|
|
export interface GroupedHandlingDetail extends HandlingDetail {
|
rowSpan: number;
|
}
|
|
export function groupHandlingDetails(details: HandlingDetail[], completedAt?: number | string): GroupedHandlingDetail[] {
|
const groups = new Map<string, HandlingDetail[]>();
|
details.forEach((detail, index) => {
|
const key = detail.nodeId || detail.id || `row-${index}`;
|
const group = groups.get(key) || [];
|
group.push(detail);
|
groups.set(key, group);
|
});
|
|
const rows = [...groups.values()].flatMap((group) => {
|
const expectedUser = [...new Set(group.map((detail) => detail.expectedUser).filter(Boolean))].join('、');
|
const deliveryTime = group[0]?.deliveryTime;
|
const handled = group.filter((detail) => detail.hasHandlingRecord);
|
const visible = handled.length ? handled : [group.find((detail) => detail.status === '待办理' || detail.status === '等待中') || group[0]];
|
return visible.map((detail, index) => ({
|
...detail,
|
expectedUser,
|
deliveryTime,
|
rowSpan: index === 0 ? visible.length : 0,
|
}));
|
});
|
|
if (completedAt) {
|
rows.push({
|
id: '__flow_completed__',
|
nodeName: '完成',
|
deliveryTime: completedAt,
|
completionTime: completedAt,
|
status: '已完成',
|
rowSpan: 1,
|
});
|
}
|
return rows;
|
}
|