刘光辉
5 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;
}