| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- 'use strict';
- // 合同目录与 Web 端使用相同的节点关系;数量只统计当前用户可见的合同。
- function buildCatalog(folders, contracts) {
- const folderById = new Map();
- const nodes = folders.map(folder => {
- const node = {
- id: String(folder.contract_id),
- parentId: String(folder.contract_pid),
- code: folder.code || '',
- name: folder.name || '',
- order: folder.order || 0,
- kind: 'folder',
- count: 0,
- };
- folderById.set(node.id, node);
- return node;
- });
- const seenContracts = new Set();
- for (const contract of contracts) {
- const contractId = String(contract.contract_id);
- if (seenContracts.has(contractId)) continue;
- const parentId = String(contract.contract_pid);
- // 与 Web 端树结构一致,不展示无法挂接到目录的合同。
- if (!folderById.has(parentId)) continue;
- seenContracts.add(contractId);
- nodes.push({
- id: contractId,
- rowId: String(contract.id),
- parentId,
- code: contract.c_code || '',
- name: contract.name || '',
- order: contract.order || 0,
- kind: 'contract',
- fileCount: contract.fileCount || 0,
- });
- const visited = new Set();
- let currentId = parentId;
- while (folderById.has(currentId) && !visited.has(currentId)) {
- visited.add(currentId);
- const folder = folderById.get(currentId);
- folder.count++;
- currentId = folder.parentId;
- }
- }
- return nodes;
- }
- module.exports = { buildCatalog };
|