明树Git Lab

Commit d136765c authored by zfp1's avatar zfp1

update

parent aa5764b5
Pipeline #104504 passed with stage
in 3 seconds
...@@ -120,13 +120,13 @@ async function createProject(req, res, next) { ...@@ -120,13 +120,13 @@ async function createProject(req, res, next) {
// 处理 projectTzzjll----- // 处理 projectTzzjll-----
// 立项资料 // 立项资料
let lxzl = body.lxzl || []; let lxzl = _.compact(body.lxzl || []);
lxzl = lxzl.map(o => { return { fileId: o.id, projectId: project.id, proFieldKey: 'lxzl' } }); lxzl = lxzl.map(o => { return { fileId: o.id, projectId: project.id, proFieldKey: 'lxzl' } });
// 立项批复文件 // 立项批复文件
let lxpfwj = body.lxpfwj || []; let lxpfwj = _.compact(body.lxpfwj || []);
lxpfwj = lxpfwj.map(o => { return { fileId: o.id, projectId: project.id, proFieldKey: 'lxpfwj' } }); lxpfwj = lxpfwj.map(o => { return { fileId: o.id, projectId: project.id, proFieldKey: 'lxpfwj' } });
// 相关上会材料 // 相关上会材料
let xgshcl = body.xgshcl || []; let xgshcl = _.compact(body.xgshcl || []);
xgshcl = xgshcl.map(o => { return { fileId: o.id, projectId: project.id, proFieldKey: 'xgshcl' } }); xgshcl = xgshcl.map(o => { return { fileId: o.id, projectId: project.id, proFieldKey: 'xgshcl' } });
// 处理文件 // 处理文件
let proFiles = _.concat(lxzl, lxpfwj, xgshcl); let proFiles = _.concat(lxzl, lxpfwj, xgshcl);
...@@ -225,14 +225,14 @@ async function xiangmulixianggengxin(body, projectLzType) { ...@@ -225,14 +225,14 @@ async function xiangmulixianggengxin(body, projectLzType) {
// 立项资料 // 立项资料
let lxzl = body.lxzl || []; let lxzl = _.compact(body.lxzl || []);
let needIds = []; let createIds = []; let needIds = []; let createIds = [];
lxzl.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'lxzl' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'lxzl' } }); lxzl.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'lxzl' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'lxzl' } });
// 立项批复文件 // 立项批复文件
let lxpfwj = body.lxpfwj || []; let lxpfwj = _.compact(body.lxpfwj || []);
lxpfwj.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'lxpfwj' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'lxpfwj' } }); lxpfwj.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'lxpfwj' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'lxpfwj' } });
// 相关上会材料 // 相关上会材料
let xgshcl = body.xgshcl || []; let xgshcl = _.compact(body.xgshcl || []);
xgshcl.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'xgshcl' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'xgshcl' } }); xgshcl.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'xgshcl' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'xgshcl' } });
// 处理文件 // 处理文件
//1. 删除 //1. 删除
...@@ -421,29 +421,29 @@ async function xiangmujuecegengxin(body, projectLzType) { ...@@ -421,29 +421,29 @@ async function xiangmujuecegengxin(body, projectLzType) {
await Promise.all(pns9.map(item => { DB.ProjectSpyjjc.update(item, { where: { id: item.id } }) })); await Promise.all(pns9.map(item => { DB.ProjectSpyjjc.update(item, { where: { id: item.id } }) }));
// 立项资料 // 立项资料
let lxzl = body.lxzl || []; let lxzl = _.compact(body.lxzl || []);
let needIds = []; let createIds = []; let needIds = []; let createIds = [];
lxzl.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'lxzl' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'lxzl' } }); lxzl.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'lxzl' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'lxzl' } });
// 立项批复文件 // 立项批复文件
let lxpfwj = body.lxpfwj || []; let lxpfwj = _.compact(body.lxpfwj || []);
lxpfwj.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'lxpfwj' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'lxpfwj' } }); lxpfwj.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'lxpfwj' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'lxpfwj' } });
// 相关上会材料 // 相关上会材料
let xgshcl = body.xgshcl || []; let xgshcl = _.compact(body.xgshcl || []);
xgshcl.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'xgshcl' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'xgshcl' } }); xgshcl.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'xgshcl' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'xgshcl' } });
// 可研材料 // 可研材料
let kycl = body.kycl || []; let kycl = _.compact(body.kycl || []);
kycl.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'kycl' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'kycl' } }); kycl.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'kycl' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'kycl' } });
// 经济指标初步测算材料 // 经济指标初步测算材料
let jjzbcbcscl = body.jjzbcbcscl || []; let jjzbcbcscl = _.compact(body.jjzbcbcscl || []);
jjzbcbcscl.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'jjzbcbcscl' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'jjzbcbcscl' } }); jjzbcbcscl.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'jjzbcbcscl' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'jjzbcbcscl' } });
// 补充相关支撑材料 // 补充相关支撑材料
let bcxgzccl = body.bcxgzccl || []; let bcxgzccl = _.compact(body.bcxgzccl || []);
bcxgzccl.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'bcxgzccl' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'bcxgzccl' } }); bcxgzccl.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'bcxgzccl' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'bcxgzccl' } });
// 其他相关支撑材料 // 其他相关支撑材料
let qtxgzccl = body.qtxgzccl || []; let qtxgzccl = _.compact(body.qtxgzccl || []);
qtxgzccl.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'qtxgzccl' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'qtxgzccl' } }); qtxgzccl.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'qtxgzccl' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'qtxgzccl' } });
// 上会议案 // 上会议案
let shya = body.shya || []; let shya = _.compact(body.shya || []);
shya.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'shya' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'shya' } }); shya.map(o => { if (!o.proFieldKey) { createIds.push({ id: o.id, proFieldKey: 'shya' }) } else { needIds.push(o.id) }; return { fileId: o.id, projectId: projectInfo.id, proFieldKey: 'shya' } });
// 处理文件 // 处理文件
//1. 删除 //1. 删除
...@@ -825,7 +825,7 @@ async function getProjectInfo(req, res, next) { ...@@ -825,7 +825,7 @@ async function getProjectInfo(req, res, next) {
obj.lixiang = lixiang.lixiang; //快照 obj.lixiang = lixiang.lixiang; //快照
//当项目状态 进入决策信息填报时候 //当项目状态 进入决策信息填报时候
if ([7, 8, 9].includes(ret && ret.projectLzType)) { if ([7, 8, 9].includes(ret && ret.projectLzType)) {
obj.juece = ret; obj.juece = ret;
} }
} else { } else {
obj.lixiang = ret; //这里就只有立项 决策的数据一旦开始填报 证明一定有ProjectLixiang lixiang obj.lixiang = ret; //这里就只有立项 决策的数据一旦开始填报 证明一定有ProjectLixiang lixiang
......
...@@ -9,10 +9,10 @@ const _ = require('lodash') ...@@ -9,10 +9,10 @@ const _ = require('lodash')
async function createResource(req, res, next) { async function createResource(req, res, next) {
try { try {
const body = req.body; const body = req.body;
let ret = await DB.Resources.create(body); let ret = await DB.Resources.create(body);
ret = ret.toJSON(); ret = ret.toJSON();
if (body.resourceInfos && body.resourceInfos.length && ret.id) { if (body.resourceInfos && body.resourceInfos.length && ret.id) {
if(body.type == 1){ if (body.type == 1) {
let ris = []; let ris = [];
for (let index = 0; index < body.resourceInfos.length; index++) { for (let index = 0; index < body.resourceInfos.length; index++) {
const element = body.resourceInfos[index]; const element = body.resourceInfos[index];
...@@ -21,7 +21,7 @@ async function createResource(req, res, next) { ...@@ -21,7 +21,7 @@ async function createResource(req, res, next) {
} }
console.log(ris, "===") console.log(ris, "===")
await DB.ResourcesInfo.bulkCreate(ris); await DB.ResourcesInfo.bulkCreate(ris);
} else if(body.type == 2) { } else if (body.type == 2) {
//树结构 //树结构
let ris = []; let ris = [];
let data = utils.flattenTreeIterative(body.resourceInfos); let data = utils.flattenTreeIterative(body.resourceInfos);
...@@ -236,11 +236,14 @@ async function listResourceAll(req, res, next) { ...@@ -236,11 +236,14 @@ async function listResourceAll(req, res, next) {
) )
let obj = {}; let obj = {};
for (let index = 0; index < datas.length; index++) { for (let index = 0; index < datas.length; index++) {
let element = datas[index]; let element = datas[index];
element = element.toJSON() element = element.toJSON()
// console.log(element.resourcesInfos, "==") // console.log(element.resourcesInfos, "==")
if (element.type == 2) { if (element.type == 2) {
element.resourcesInfos = utils.buildTree2(element.resourcesInfos, 'code', 'parentCode'); element.resourcesInfos = utils.buildTree2(element.resourcesInfos, {
keyName: "code",
parentKeyName: 'parentCode',
});
} }
obj[element.key] = _.orderBy(element.resourcesInfos || [], 'order', 'asc'); obj[element.key] = _.orderBy(element.resourcesInfos || [], 'order', 'asc');
} }
......
...@@ -39,7 +39,7 @@ async function handleProjectData(ret, queryAttrs) { ...@@ -39,7 +39,7 @@ async function handleProjectData(ret, queryAttrs) {
if (rawAttributes[key].zjType == "danxuan") { if (rawAttributes[key].zjType == "danxuan") {
resouInfoIds.push(element[key]); resouInfoIds.push(element[key]);
} }
else if ((!_.isEmpty(element[key])) && rawAttributes[element].zjType == "duoxuan") { else if ((!_.isEmpty(element[key])) && rawAttributes[element].zjType == "duoxuan") {
resouInfoIds = resouInfoIds.concat(element[key]) resouInfoIds = resouInfoIds.concat(element[key])
} }
...@@ -59,8 +59,8 @@ async function handleProjectData(ret, queryAttrs) { ...@@ -59,8 +59,8 @@ async function handleProjectData(ret, queryAttrs) {
// console.log(resMap[String(element[key])], String(element[key]), "=========================") // console.log(resMap[String(element[key])], String(element[key]), "=========================")
element[key] = resMap[String(element[key])]; element[key] = resMap[String(element[key])];
} else if (rawAttributes[key].zjType == "duoxuan") { } else if (rawAttributes[key].zjType == "duoxuan") {
if(_.isArray(element[key]) && element[key].length > 0) { if (_.isArray(element[key]) && element[key].length > 0) {
element[key].map(o => {return resMap[o]}); element[key].map(o => { return resMap[o] });
element[key] = element[key].join(',') element[key] = element[key].join(',')
} }
} }
...@@ -80,7 +80,7 @@ async function handleProjectData(ret, queryAttrs) { ...@@ -80,7 +80,7 @@ async function handleProjectData(ret, queryAttrs) {
async function getResourceInfoByIds(resouInfoIds) { async function getResourceInfoByIds(resouInfoIds) {
let ris = await DB.ResourcesInfo.findAll({ let ris = await DB.ResourcesInfo.findAll({
where: {id: {[Op.in]: resouInfoIds}}, where: { id: { [Op.in]: resouInfoIds } },
// raw: true, // raw: true,
}); });
let risMap = {}; let risMap = {};
...@@ -203,19 +203,22 @@ async function getProjectInfo({ id }) { ...@@ -203,19 +203,22 @@ async function getProjectInfo({ id }) {
return {}; return {};
} }
project = project.toJSON(); project = project.toJSON();
project.projectBjtjs = await DB.ProjectBjtj.findAll({where:{projectId: id}, raw: true}); project.projectBjtjs = await DB.ProjectBjtj.findAll({ where: { projectId: id }, raw: true });
project.projectCwpjzbs = await DB.ProjectCwpjzb.findAll({where:{projectId: id}, raw: true}); project.projectCwpjzbs = await DB.ProjectCwpjzb.findAll({ where: { projectId: id }, raw: true });
project.projectFxgls = await DB.ProjectFxgl.findAll({where:{projectId: id}, raw: true}); project.projectFxgls = await DB.ProjectFxgl.findAll({ where: { projectId: id }, raw: true });
project.projectGdxxs = await DB.ProjectGdxx.findAll({where:{projectId: id}, raw: true}); project.projectGdxxs = await DB.ProjectGdxx.findAll({ where: { projectId: id }, raw: true });
project.projectJczts = await DB.ProjectJczt.findAll({where:{projectId: id}, raw: true}); project.projectJczts = await DB.ProjectJczt.findAll({ where: { projectId: id }, raw: true });
project.projectJsgms = await DB.ProjectJsgm.findAll({where:{projectId: id}, raw: true}); project.projectJsgms = await DB.ProjectJsgm.findAll({ where: { projectId: id }, raw: true });
project.projectLcbjds = await DB.ProjectLcbjd.findAll({where:{projectId: id}, raw: true}); project.projectLcbjds = await DB.ProjectLcbjd.findAll({ where: { projectId: id }, raw: true });
project.projectSpyjs = await DB.ProjectSpyj.findAll({where:{projectId: id}, raw: true}); project.projectSpyjs = await DB.ProjectSpyj.findAll({ where: { projectId: id }, raw: true });
project.projectTzzjlls = await DB.ProjectTzzjll.findAll({where:{projectId: id}, raw: true}); project.projectTzzjlls = await DB.ProjectTzzjll.findAll({ where: { projectId: id }, raw: true });
project.projectTzzts = await DB.ProjectTzzt.findAll({where:{projectId: id}, raw: true}); project.projectTzzts = await DB.ProjectTzzt.findAll({ where: { projectId: id }, raw: true });
project.projectXmtzzes = await DB.ProjectXmtzze.findAll({where:{projectId: id}, raw: true}); project.projectXmtzzes = await DB.ProjectXmtzze.findAll({ where: { projectId: id }, raw: true });
// let files = await DB.ProjectXmtzze.findAll({projectId: id});
project.projectXmtzzes = utils.buildTree2(project.projectXmtzzes, 'xh', 'parentXh'); project.projectXmtzzes = utils.buildTree2(project.projectXmtzzes, {
keyName: "xh",
parentKeyName: 'parentXh',
});
//处理文件 还原成项目各个字段拥有的文件 //处理文件 还原成项目各个字段拥有的文件
let files = project.files || []; let files = project.files || [];
...@@ -282,7 +285,10 @@ async function getProjectInfoByLixiang({ id }) { ...@@ -282,7 +285,10 @@ async function getProjectInfoByLixiang({ id }) {
// raw: true // raw: true
}); });
project = project.toJSON(); project = project.toJSON();
project.projectXmtzzes = utils.buildTree2(project.projectXmtzzes, 'xh', 'parentXh'); project.projectXmtzzes = utils.buildTree2(project.projectXmtzzes, {
keyName: "xh",
parentKeyName: 'parentXh',
});
//处理文件 还原成项目各个字段拥有的文件 //处理文件 还原成项目各个字段拥有的文件
let files = project.files || []; let files = project.files || [];
......
...@@ -129,26 +129,54 @@ function flattenTree(forest, idDes = 'id', parentIdDes = 'parentId') { ...@@ -129,26 +129,54 @@ function flattenTree(forest, idDes = 'id', parentIdDes = 'parentId') {
return result; return result;
} }
// function buildTree2(nodes, options = {}) {
function buildTree2(nodes, keyid = 'id', keyParentId = 'parentId') { // 合并配置和默认值
// 创建一个映射,将节点ID映射到节点对象 const {
const nodeMap = new Map(nodes.map(node => [String(node[keyid]), { ...node, children: [] }])); keyName = 'id',
parentKeyName = 'parentId',
// 遍历所有节点,并将它们添加到对应父节点的children数组中 orderField = 'order',
nodes.forEach(node => { filter = node => node.del === 0
const parentId = String(node[keyParentId]); } = options;
if (parentId !== null) {
// 确保父节点在映射中存在 // 创建节点映射表(使用Map提升性能)
if (nodeMap.has(parentId)) { const nodeMap = new Map();
// 将当前节点添加到父节点的children数组中 nodes.forEach(node => {
nodeMap.get(parentId).children.push(nodeMap.get(String(node[keyid]))); if (!filter(node)) return;
nodeMap.get(parentId).children = _.orderBy(nodeMap.get(parentId).children, ['order', 'code']) nodeMap.set(String(node[keyName]), {
...node,
children: []
});
});
// 构建树形结构
const roots = [];
nodeMap.forEach((node, nodeId) => {
const parentRef = String(node[parentKeyName]);
// 处理根节点
if (!parentRef || parentRef === 'null' || parentRef === 'undefined') {
roots.push(node);
return;
}
// 处理子节点
if (nodeMap.has(parentRef)) {
const parent = nodeMap.get(parentRef);
parent.children.push(node);
// 子节点排序(使用稳定排序)
if (parent.children.length > 1) {
parent.children.sort((a, b) =>
(a[orderField] || 0) - (b[orderField] || 0)
);
} }
} }
}); });
// 从映射中提取顶级节点(parentId为null) // 根节点排序
return _.orderBy(Array.from(nodeMap.values()).filter(node => node[keyParentId] == null), ['order', 'code']); return roots.sort((a, b) =>
(a[orderField] || 0) - (b[orderField] || 0)
);
} }
......
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