明树Git Lab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
J
jt_backend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zengfanpei
jt_backend
Commits
83f40631
Commit
83f40631
authored
Dec 06, 2025
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
34260035
Pipeline
#104238
passed with stage
in 3 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
164 deletions
+6
-164
a.js
a.js
+0
-162
templateController.js
controller/templateController.js
+6
-2
No files found.
a.js
deleted
100644 → 0
View file @
34260035
function
flattenTree
(
forest
,
idDes
=
'id'
,
parentIdDes
=
'parentId'
)
{
const
result
=
[];
/**
* 递归处理节点
* @param {Object} node - 当前节点
* @param {string|null} parentId - 父节点ID
*/
function
traverse
(
node
,
parentId
)
{
// 创建节点副本避免修改原数据
const
nodeCopy
=
{
...
node
};
// 添加parentId属性
nodeCopy
[
parentIdDes
]
=
parentId
;
// 移除children属性(使用正确拼写)
delete
nodeCopy
.
children
;
// 添加当前节点到结果集
result
.
push
(
nodeCopy
);
// 处理子节点(兼容chilrden拼写错误)
const
children
=
node
.
chilrden
||
node
.
children
||
[];
for
(
const
child
of
children
)
{
traverse
(
child
,
node
[
idDes
]);
}
}
// 遍历森林中的每棵树
for
(
const
tree
of
forest
)
{
traverse
(
tree
,
null
);
// 根节点parentId为null
}
return
result
;
}
// 扩展测试:包含额外字段和标准children字段
let
complexForest
=
[
{
"xh"
:
"1"
,
"zb"
:
"项目资本金"
,
"dw"
:
"万元"
,
"children"
:
[
{
"xh"
:
"1.1"
,
"zb"
:
"能建方出资"
,
"dw"
:
"万元"
,
"rmbjj"
:
"2"
},
{
"xh"
:
"1.2"
,
"zb"
:
"外部股东"
,
"dw"
:
"万元"
,
"rmbjj"
:
"3"
}
],
"rmbjj"
:
"1"
},
{
"xh"
:
"2"
,
"zb"
:
"贷款"
,
"dw"
:
"万元"
,
"children"
:
[
{
"xh"
:
"2.1"
,
"zb"
:
"其中:并非表项目我方贷款/投保额"
,
"dw"
:
"万元"
,
"rmbjj"
:
"5"
}
],
"rmbjj"
:
"4"
},
{
"xh"
:
"3"
,
"zb"
:
"其他出资"
,
"dw"
:
"万元"
,
"children"
:
[
{
"xh"
:
"3.1"
,
"zb"
:
"其中:能建方出资"
,
"dw"
:
"万元"
,
"rmbjj"
:
"7"
}
],
"rmbjj"
:
"6"
},
{
"xh"
:
""
,
"zb"
:
"批复总出资"
,
"dw"
:
"万元"
,
"rmbjj"
:
"8"
}
]
console
.
log
(
flattenTree
(
complexForest
,
'xh'
,
'parentXh'
));
/* 输出:
[
{ id: 'A', name: 'Root A', parentId: null },
{ id: 'A1', value: 100, parentId: 'A' },
{ id: 'A2', value: 200, parentId: 'A' },
{ id: 'A2a', parentId: 'A2' },
{ id: 'B', name: 'Root B', parentId: null },
{ id: 'B1', parentId: 'B' }
]
*/
// const _ = require('lodash');
// function buildTree(nodes, keyid = 'id', keyParentId = 'parentId') {
// // 创建一个映射,将节点ID映射到节点对象
// const nodeMap = new Map(nodes.map(node => [String(node[keyid]), { ...node, children: [] }]));
// // 遍历所有节点,并将它们添加到对应父节点的children数组中
// nodes.forEach(node => {
// const parentId = String(node[keyParentId]);
// if (parentId !== null) {
// // 确保父节点在映射中存在
// if (nodeMap.has(parentId)) {
// // 将当前节点添加到父节点的children数组中
// nodeMap.get(parentId).children.push(nodeMap.get(String(node[keyid])));
// nodeMap.get(parentId).children = _.orderBy(nodeMap.get(parentId).children, 'order')
// }
// }
// });
// // 从映射中提取顶级节点(parentId为null)
// return _.orderBy(Array.from(nodeMap.values()).filter(node => node[keyParentId] == null), 'order');
// }
// console.log(JSON.stringify(buildTree([
// { xh: '1', zb: '项目资本金', dw: '万元', parentXh: null },
// { xh: '1.1', zb: '能建方出资', dw: '万元', parentXh: '1' },
// { xh: '1.2', zb: '外部股东', dw: '万元', parentXh: '1' },
// { xh: '2', zb: '贷款', dw: '万元', parentXh: null },
// { xh: '2.1', zb: '其中:并非表项目我方贷款/投保额', dw: '万元', parentXh: '2' },
// { xh: '3', zb: '其他出资', dw: '万元', parentXh: null },
// { xh: '3.1', zb: '其中:能建方出资', dw: '万元', parentXh: '3' },
// { xh: '', zb: '批复总出资', dw: '万元', parentXh: null }
// ], 'xh', 'parentXh')))
// [{ "xh": "1", "zb": "项目资本金", "dw": "万元", "parentXh": null, "children": [{ "xh": "1.1", "zb": "能建方出资", "dw": "万元", "parentXh": "1", "children": [] }, { "xh": "1.2", "zb": "外部股东", "dw": "万元", "parentXh": "1", "children": [] }] }, { "xh": "2", "zb": "贷款", "dw": "万元", "parentXh": null, "children": [{ "xh": "2.1", "zb": "其中:并非表项目我方贷款/投保额", "dw": "万元", "parentXh": "2", "children": [] }] }, { "xh": "3", "zb": "其他出资", "dw": "万元", "parentXh": null, "children": [{ "xh": "3.1", "zb": "其中:能建方出资", "dw": "万元", "parentXh": "3", "children": [] }] }, { "xh": "", "zb": "批复总出资", "dw": "万元", "parentXh": null, "children": [] }]
function
disTree
(
tree
)
{
let
parallel
=
[];
function
addToParallel
(
nodes
)
{
nodes
.
forEach
(
node
=>
{
parallel
.
push
({
...
node
,
children
:
undefined
});
if
(
node
.
children
&&
node
.
children
.
length
)
{
addToParallel
(
node
.
children
);
}
});
}
addToParallel
(
tree
)
return
parallel
}
console
.
log
(
disTree
(
[
1
,
2
,
3
]))
\ No newline at end of file
controller/templateController.js
View file @
83f40631
...
...
@@ -87,7 +87,7 @@ async function getXmtzzjllTem({ startYear, endYear, tampName, projectId }) {
// 遍历所有单元格添加边框
worksheet
.
eachRow
((
row
,
rowNumber
)
=>
{
row
.
eachCell
((
cell
,
colNumber
)
=>
{
if
(
rowNumber
>=
4
&&
rowNumber
<=
8
&&
colNumber
>=
4
&&
colNumber
<=
(
3
+
columns
.
length
))
{
if
(
rowNumber
>=
4
&&
rowNumber
<=
worksheet
.
actualRowCount
&&
colNumber
>=
4
&&
colNumber
<=
(
3
+
columns
.
length
))
{
cell
.
numFmt
=
'#,##0.00'
;
//数字格式
}
cell
.
alignment
=
{
...
...
@@ -186,7 +186,11 @@ async function importExcelTempData(req, res, next) {
}
else
if
(
cell
.
type
===
ExcelJS
.
ValueType
.
String
)
{
rowData
.
push
(
cell
.
text
+
"_suffix"
);
}
else
if
(
cell
.
value
===
null
||
cell
.
value
===
undefined
)
{
rowData
.
push
(
""
);
if
([
4
,
14
,
25
,
32
].
includes
(
ri
)
&&
tampName
==
"tjjh"
)
{
rowData
.
push
(
""
);
}
else
{
rowData
.
push
(
0
);
}
}
else
{
rowData
.
push
(
cell
.
value
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment