明树Git Lab

Commit 6d2514b4 authored by zfp1's avatar zfp1

update

parents 803b3e13 8674e6c9
......@@ -136,4 +136,27 @@ console.log(flattenTree(complexForest, 'xh', 'parentXh'));
// ], '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": [] }]
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
......@@ -678,8 +678,10 @@ async function getOwnProjects(req, res, next) {
//
let cArr = [
{ projectCreator: req.user.id },
{ id: { [Op.in]: projectIds } }
]
if(projectIds.length > 0) {
cArr.push({ id: { [Op.in]: projectIds } })
}
if (req.body.projectName) {
cArr.push({ projectName: { [Op.like]: `%${req.body.projectName}%` } });
}
......@@ -693,8 +695,7 @@ async function getOwnProjects(req, res, next) {
if (req.body.attributes && req.body.attributes.length) {
search.attributes = req.body.attributes;
}
search.raw = true;
console.log(search, "-==")
console.log(JSON.stringify(search), "-==")
let ret = await DB.Project.findAndCountAll(search);
let lastRet = await projectModule.handleProjectData(ret, search.attributes);
return res.sendData(lastRet);
......
......@@ -14,21 +14,52 @@ const projectModule = require('../module/projectModule');
async function handleProjectData(ret, queryAttrs) {
let rawAttributes = DB.Project.rawAttributes;
let rawAttributes = _.cloneDeep(DB.Project.rawAttributes);
console.log(rawAttributes, "====")
let queryRawAtr = [], resourceKeys = [];
let queryRawAtr = [], resourceKeys = [];
for (let index = 0; index < queryAttrs.length; index++) {
const element = queryAttrs[index];
if(rawAttributes[element]) {
if (rawAttributes[element]) {
queryRawAtr.push(rawAttributes[element]); //查询得所有字段
if(['danxuan'].includes(rawAttributes[element] && rawAttributes[element].zjType)) { //其中需要处理的资源库字段,单选、
if (['danxuan'].includes(rawAttributes[element] && rawAttributes[element].zjType)) { //其中需要处理的资源库字段,单选、
resourceKeys.push(element);
}
}
}
console.log(resourceKeys);
let groupAttr = _.groupBy(queryRawAtr, 'zjType');
return groupAttr;
let resources = await getResourceByKeys(resourceKeys);
console.log(resources);
// let groupAttr = _.groupBy(queryRawAtr, 'zjType');
//获取对应得资源库说明
return resources;
}
async function getResourceByKeys(keys) {
if (!(keys && keys.length)) {
return {};
}
let ret = await DB.Resources.findAll({
where: { key: { [Op.in]: keys } ,del: 0},
include: [
{
model: DB.ResourcesInfo,
as: 'resourcesInfos',
}
]
});
let obj = {};
for (let index = 0; index < ret.length; index++) {
const element = ret[index];
element.resourcesInfos = element.resourcesInfos || [];
let oobj = {};
for (let i = 0; i < element.resourcesInfos.length; i++) {
const e = element.resourcesInfos[i];
oobj[e.key] = e.value;
}
obj[element.key] = oobj;
}
return obj;
}
......
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