明树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
b714cc4e
Commit
b714cc4e
authored
Dec 02, 2025
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
6361c278
Pipeline
#104035
passed with stage
in 3 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
77 deletions
+86
-77
a.js
a.js
+85
-77
roleController.js
controller/roleController.js
+1
-0
No files found.
a.js
View file @
b714cc4e
...
...
@@ -35,53 +35,61 @@ function flattenTree(forest, idDes = 'id', parentIdDes = 'parentId') {
}
// 扩展测试:包含额外字段和标准children字段
let
complexForest
=
[
{
xh
:
"1"
,
zb
:
"项目资本金"
,
dw
:
"万元"
,
children
:
[
{
xh
:
"1.1"
,
zb
:
"能建方出资"
,
dw
:
"万元"
},
{
xh
:
"1.2"
,
zb
:
"外部股东"
,
dw
:
"万元"
}
]
},
{
xh
:
"2"
,
zb
:
"贷款"
,
dw
:
"万元"
,
children
:
[
{
xh
:
"2.1"
,
zb
:
"其中:并非表项目我方贷款/投保额"
,
dw
:
"万元"
}
]
},
{
xh
:
"3"
,
zb
:
"其他出资"
,
dw
:
"万元"
,
children
:
[
{
xh
:
"3.1"
,
zb
:
"其中:能建方出资"
,
dw
:
"万元"
}
]
},
{
xh
:
""
,
zb
:
"批复总出资"
,
dw
:
"万元"
}
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'
));
...
...
@@ -95,37 +103,37 @@ console.log(flattenTree(complexForest, 'xh', 'parentXh'));
{ 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
:
[]
}]));
//
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'
)
}
}
});
//
// 遍历所有节点,并将它们添加到对应父节点的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'
)))
//
// 从映射中提取顶级节点(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"
:
[]
}]
\ No newline at end of file
// [{ "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": [] }]
\ No newline at end of file
controller/roleController.js
View file @
b714cc4e
const
errorMessage
=
require
(
"../utils/errorMessage"
);
const
userModule
=
require
(
'../module/userModule'
);
const
{
Op
}
=
require
(
'sequelize'
);
async
function
createRole
(
req
,
res
,
next
)
{
try
{
...
...
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