明树Git Lab

Commit b714cc4e authored by zfp1's avatar zfp1

update

parent 6361c278
Pipeline #104035 passed with stage
in 3 seconds
......@@ -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
const errorMessage = require("../utils/errorMessage");
const userModule = require('../module/userModule');
const {Op} = require('sequelize');
async function createRole(req, res, next) {
try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment