明树Git Lab

Commit 1a47eb90 authored by zfp1's avatar zfp1

update

parent 01517d16
Pipeline #104418 passed with stage
in 4 seconds
......@@ -15,7 +15,7 @@ async function upload(req, res, next) {
filename: req.file.filename,
path: req.file.path,
// nginxpath,
size: req.file.size,
size: (req.file.size / (1048576)).toFixed(2),
});
res.sendData(ret);
} catch (error) {
......
......@@ -893,7 +893,9 @@ async function listProject(req, res, next) {
search.attributes = req.body.attributes;
}
console.log(search)
search.raw = true
let ret = await DB.Project.findAndCountAll(search);
// ret = await projectModule.handleProjectData(ret, search.attributes);
return res.sendData(ret);
} catch (error) {
next(error);
......
......@@ -13,26 +13,52 @@ const moment = require('moment');
async function handleProjectData(ret, queryAttrs) {
let rawAttributes = _.cloneDeep(DB.Project.rawAttributes);
console.log(ret, "====")
let queryRawAtr = [], resourceKeys = [];
for (let index = 0; index < queryAttrs.length; index++) {
const element = queryAttrs[index];
if (rawAttributes[element]) {
queryRawAtr.push(rawAttributes[element]); //查询得所有字段
if (['danxuan'].includes(rawAttributes[element] && rawAttributes[element].zjType)) { //其中需要处理的资源库字段,单选、
resourceKeys.push(element);
// console.log(ret, "====")
// let queryRawAtr = [], resourceKeys = [];
// for (let index = 0; index < queryAttrs.length; index++) {
// const element = queryAttrs[index];
// if (rawAttributes[element]) {
// // queryRawAtr.push(rawAttributes[element]); //查询得所有字段
// if (['danxuan'].includes(rawAttributes[element] && rawAttributes[element].zjType)) { //其中需要处理的资源库字段,单选、
// resourceKeys.push(element);
// }
// if (['duoxuan'].includes()) {
// }
// }
// }
// let resources = await getResourceByKeys(resourceKeys);
let newRet = [], resouInfoIds = [];
for (let index = 0; index < ret.rows.length; index++) {
const element = ret.rows[index];
// console.log(element);
for (const key in element) {
console.log(key)
if (!_.isEmpty(element[key]) && rawAttributes[key].zjType) {
if (rawAttributes[element].zjType == "danxuan") {
resouInfoIds.push(element[key]);
} else if (rawAttributes[element].zjType == "duoxuan") {
resouInfoIds = resouInfoIds.concat(element[key])
}
}
}
}
let resources = await getResourceByKeys(resourceKeys);
let newRet = [];
let resMap = await getResourceInfoByIds(resouInfoIds);
for (let index = 0; index < ret.rows.length; index++) {
const element = ret.rows[index];
console.log(element);
// console.log(element);
for (const key in element) {
if (!_.isEmpty(resources[key])) {
element[key] = resources[key][element[key]]
if (!_.isEmpty(element[key]) && rawAttributes[element].zjType) {
if (rawAttributes[element].zjType == "danxuan") {
element[key] = resMap[element[key]];
} else if (rawAttributes[element].zjType == "duoxuan") {
if(_.isArray(element[key]) && element[key].length > 0) {
element[key].map(o => {return resMap[o]});
element[key] = element[key].join(',')
}
}
}
}
......@@ -43,6 +69,20 @@ async function handleProjectData(ret, queryAttrs) {
return ret;
}
async function getResourceInfoByIds(resouInfoIds) {
let ris = await DB.ResourcesInfo.findAll({
where: {id: {[Op.in]: resouInfoIds}},
raw: true,
});
let risMap = {};
for (let index = 0; index < ris.length; index++) {
const element = ris[index];
risMap[element.id] = element.value;
risMap[String(element.id)] = element.value;
}
return risMap;
}
async function getResourceByKeys(keys) {
if (!(keys && keys.length)) {
......@@ -71,7 +111,7 @@ async function getResourceByKeys(keys) {
return obj;
}
async function getProjectInfo({id}) {
async function getProjectInfo({ id }) {
let project = await DB.Project.findOne({
where: { id: id },
// raw: true,
......@@ -150,8 +190,8 @@ async function getProjectInfo({id}) {
],
// raw: true
});
if(!project) {
return res.sendError(errorMessage.resourceNotFound);
if (!project) {
return {};
}
project = project.toJSON();
project.projectXmtzzes = utils.buildTree2(project.projectXmtzzes, 'xh', 'parentXh');
......@@ -169,7 +209,7 @@ async function getProjectInfo({id}) {
}
async function getProjectInfoByLixiang({id}) {
async function getProjectInfoByLixiang({ id }) {
let project = await DB.Project.findOne({
where: { id: id },
// raw: true,
......
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