明树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) { ...@@ -15,7 +15,7 @@ async function upload(req, res, next) {
filename: req.file.filename, filename: req.file.filename,
path: req.file.path, path: req.file.path,
// nginxpath, // nginxpath,
size: req.file.size, size: (req.file.size / (1048576)).toFixed(2),
}); });
res.sendData(ret); res.sendData(ret);
} catch (error) { } catch (error) {
......
...@@ -893,7 +893,9 @@ async function listProject(req, res, next) { ...@@ -893,7 +893,9 @@ async function listProject(req, res, next) {
search.attributes = req.body.attributes; search.attributes = req.body.attributes;
} }
console.log(search) console.log(search)
search.raw = true
let ret = await DB.Project.findAndCountAll(search); let ret = await DB.Project.findAndCountAll(search);
// ret = await projectModule.handleProjectData(ret, search.attributes);
return res.sendData(ret); return res.sendData(ret);
} catch (error) { } catch (error) {
next(error); next(error);
......
...@@ -13,26 +13,52 @@ const moment = require('moment'); ...@@ -13,26 +13,52 @@ const moment = require('moment');
async function handleProjectData(ret, queryAttrs) { async function handleProjectData(ret, queryAttrs) {
let rawAttributes = _.cloneDeep(DB.Project.rawAttributes); let rawAttributes = _.cloneDeep(DB.Project.rawAttributes);
console.log(ret, "====") // console.log(ret, "====")
let queryRawAtr = [], resourceKeys = []; // let queryRawAtr = [], resourceKeys = [];
for (let index = 0; index < queryAttrs.length; index++) { // for (let index = 0; index < queryAttrs.length; index++) {
const element = queryAttrs[index]; // const element = queryAttrs[index];
if (rawAttributes[element]) { // if (rawAttributes[element]) {
queryRawAtr.push(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); // 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 resMap = await getResourceInfoByIds(resouInfoIds);
let newRet = [];
for (let index = 0; index < ret.rows.length; index++) { for (let index = 0; index < ret.rows.length; index++) {
const element = ret.rows[index]; const element = ret.rows[index];
console.log(element); // console.log(element);
for (const key in element) { for (const key in element) {
if (!_.isEmpty(resources[key])) { if (!_.isEmpty(element[key]) && rawAttributes[element].zjType) {
element[key] = resources[key][element[key]] 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) { ...@@ -43,6 +69,20 @@ async function handleProjectData(ret, queryAttrs) {
return ret; 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) { async function getResourceByKeys(keys) {
if (!(keys && keys.length)) { if (!(keys && keys.length)) {
...@@ -71,7 +111,7 @@ async function getResourceByKeys(keys) { ...@@ -71,7 +111,7 @@ async function getResourceByKeys(keys) {
return obj; return obj;
} }
async function getProjectInfo({id}) { async function getProjectInfo({ id }) {
let project = await DB.Project.findOne({ let project = await DB.Project.findOne({
where: { id: id }, where: { id: id },
// raw: true, // raw: true,
...@@ -150,8 +190,8 @@ async function getProjectInfo({id}) { ...@@ -150,8 +190,8 @@ async function getProjectInfo({id}) {
], ],
// raw: true // raw: true
}); });
if(!project) { if (!project) {
return res.sendError(errorMessage.resourceNotFound); return {};
} }
project = project.toJSON(); project = project.toJSON();
project.projectXmtzzes = utils.buildTree2(project.projectXmtzzes, 'xh', 'parentXh'); project.projectXmtzzes = utils.buildTree2(project.projectXmtzzes, 'xh', 'parentXh');
...@@ -169,7 +209,7 @@ async function getProjectInfo({id}) { ...@@ -169,7 +209,7 @@ async function getProjectInfo({id}) {
} }
async function getProjectInfoByLixiang({id}) { async function getProjectInfoByLixiang({ id }) {
let project = await DB.Project.findOne({ let project = await DB.Project.findOne({
where: { id: id }, where: { id: id },
// raw: true, // 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