明树Git Lab

Commit 5faff9c9 authored by zfp1's avatar zfp1

update

parent 923fa4c8
Pipeline #106043 passed with stage
in 3 seconds
...@@ -15,7 +15,7 @@ async function createTzmbzrs(req, res, next) { ...@@ -15,7 +15,7 @@ async function createTzmbzrs(req, res, next) {
if (!req.body.projectId) { if (!req.body.projectId) {
return res.sendError(errorMessage.paramsError); return res.sendError(errorMessage.paramsError);
} }
//处理文件参数 //处理文件参数
req.body.zrswj = (req.body.zrswj || []).map(o => { return o && o.id || o }); req.body.zrswj = (req.body.zrswj || []).map(o => { return o && o.id || o });
req.body.chwj = (req.body.chwj || []).map(o => { return o && o.id || o }); req.body.chwj = (req.body.chwj || []).map(o => { return o && o.id || o });
...@@ -72,18 +72,18 @@ async function updateTzmbzrs(req, res, next) { ...@@ -72,18 +72,18 @@ async function updateTzmbzrs(req, res, next) {
//1.更新责任指标表数据 //1.更新责任指标表数据
let ids = [], infos = [], newtzmbzrsZbs = []; let ids = [], infos = [], newtzmbzrsZbs = [];
tzmbzrsZbs.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id; newtzmbzrsZbs.push(o); } } else { ids.push(o.id); infos.push(o); } return o }); tzmbzrsZbs.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id; newtzmbzrsZbs.push(o); } } else { ids.push(o.id); infos.push(o); } return o });
await DB.TzTzmbzrsZb.destroy({ where: { projectId: req.body.projectId, id: { [Op.notIn]: ids } } }); // 删除id不在传入id数组里面的(用户在界面删除的) await DB.TzTzmbzrsZb.destroy({ where: { projectId: req.body.projectId,sourceId: ret.id, id: { [Op.notIn]: ids } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
await DB.TzTzmbzrsZb.bulkCreate(newtzmbzrsZbs);//创建新的 没有id的 await DB.TzTzmbzrsZb.bulkCreate(newtzmbzrsZbs);//创建新的 没有id的
await Promise.all(infos.map(item => { DB.TzTzmbzrsZb.update(item, { where: { id: item.id } }) })); await Promise.all(infos.map(item => { DB.TzTzmbzrsZb.update(item, { where: { id: item.id } }) }));
//1.更新批复意见 //1.更新批复意见
let ids1 = [], infos1 = [], newtzmbzrsPfyjs = []; let ids1 = [], infos1 = [], newtzmbzrsPfyjs = [];
tzmbzrsPfyjs.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id; newtzmbzrsPfyjs.push(o); } } else { ids1.push(o.id); infos1.push(o); } return o }); tzmbzrsPfyjs.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id; newtzmbzrsPfyjs.push(o); } } else { ids1.push(o.id); infos1.push(o); } return o });
await DB.TzTzmbzrsPfyj.destroy({ where: { projectId: req.body.projectId, id: { [Op.notIn]: ids1 } } }); // 删除id不在传入id数组里面的(用户在界面删除的) await DB.TzTzmbzrsPfyj.destroy({ where: { projectId: req.body.projectId,sourceId: ret.id, id: { [Op.notIn]: ids1 } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
await DB.TzTzmbzrsPfyj.bulkCreate(newtzmbzrsPfyjs);//创建新的 没有id的 await DB.TzTzmbzrsPfyj.bulkCreate(newtzmbzrsPfyjs);//创建新的 没有id的
await Promise.all(infos1.map(item => { DB.TzTzmbzrsPfyj.update(item, { where: { id: item.id } }) })); await Promise.all(infos1.map(item => { DB.TzTzmbzrsPfyj.update(item, { where: { id: item.id } }) }));
let ids2 = [], infos2 = [], newtzmbzrsNds = []; let ids2 = [], infos2 = [], newtzmbzrsNds = [];
tzmbzrsNds.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id; newtzmbzrsNds.push(o); } } else { ids2.push(o.id); infos2.push(o); } return o }); tzmbzrsNds.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id; newtzmbzrsNds.push(o); } } else { ids2.push(o.id); infos2.push(o); } return o });
await DB.TzTzmbzrsNd.destroy({ where: { projectId: req.body.projectId, id: { [Op.notIn]: ids2 } } }); // 删除id不在传入id数组里面的(用户在界面删除的) await DB.TzTzmbzrsNd.destroy({ where: { projectId: req.body.projectId,sourceId: ret.id, id: { [Op.notIn]: ids2 } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
await DB.TzTzmbzrsNd.bulkCreate(newtzmbzrsNds);//创建新的 没有id的 await DB.TzTzmbzrsNd.bulkCreate(newtzmbzrsNds);//创建新的 没有id的
await Promise.all(infos2.map(item => { DB.TzTzmbzrsNd.update(item, { where: { id: item.id } }) })); await Promise.all(infos2.map(item => { DB.TzTzmbzrsNd.update(item, { where: { id: item.id } }) }));
...@@ -157,11 +157,11 @@ async function getTzmbzrsInfo(req, res, next) { ...@@ -157,11 +157,11 @@ async function getTzmbzrsInfo(req, res, next) {
// console.log(tzmbzrsZbs, "============", zrs) // console.log(tzmbzrsZbs, "============", zrs)
//文件处理 //文件处理
let fileIds = [...(zrs.zrswj || []), ...(zrs.chwj || []), ...(zrs.jyglzrs || [])].map(o => {return o && o.id || o}); let fileIds = [...(zrs.zrswj || []), ...(zrs.chwj || []), ...(zrs.jyglzrs || [])].map(o => { return o && o.id || o });
let files = await DB.File.findAll({ where: { id: { [Op.in]: fileIds } }, raw: true }); let files = await DB.File.findAll({ where: { id: { [Op.in]: fileIds } }, raw: true });
let fileMap = {}; let fileMap = {};
files.map(o => { fileMap[o.id] = o }); files.map(o => { fileMap[o.id] = o });
console.log(fileMap, fileIds, "=======================") console.log(fileMap, fileIds, "=======================")
zrs.zrswj = (zrs.zrswj || []).map(o => { return fileMap[(o && o.id || o)] }); zrs.zrswj = (zrs.zrswj || []).map(o => { return fileMap[(o && o.id || o)] });
zrs.chwj = (zrs.chwj || []).map(o => { return fileMap[(o && o.id || o)] }); zrs.chwj = (zrs.chwj || []).map(o => { return fileMap[(o && o.id || o)] });
zrs.jyglzrs = (zrs.jyglzrs || []).map(o => { return fileMap[(o && o.id || o)] }); zrs.jyglzrs = (zrs.jyglzrs || []).map(o => { return fileMap[(o && o.id || o)] });
...@@ -190,17 +190,17 @@ async function createTzkz(req, res, next) { ...@@ -190,17 +190,17 @@ async function createTzkz(req, res, next) {
} }
//处理文件 //处理文件
req.body.qtjsmbzdpc = (req.body.qtjsmbzdpc || []).map(o => { return o && o.id || o }); req.body.qtjsmbzdpc = (req.body.qtjsmbzdpc || []).map(o => { return o && o.id || o });
// 创建提前 // 创建提前
let ret = await DB.TzTzkz.create(req.body); let ret = await DB.TzTzkz.create(req.body);
//处理财务评价指标 //处理财务评价指标
let tzkzcwpjs = (req.body.tzkzcwpjs || []).map(o => { o.projectId = req.body.projectId; o.sourceId = ret.id; return o; }); let tzkzcwpjs = (req.body.tzkzcwpjs || []).map(o => { o.projectId = req.body.projectId; o.sourceId = ret.id; return o; });
delete req.body.tzkzcwpjs; delete req.body.tzkzcwpjs;
//处理决策批复意见 //处理决策批复意见
let tzkzjcpfyjs = (req.body.tzkzjcpfyjs || []).map(o => { o.projectId = req.body.projectId;o.sourceId = ret.id; return o; });; let tzkzjcpfyjs = (req.body.tzkzjcpfyjs || []).map(o => { o.projectId = req.body.projectId; o.sourceId = ret.id; return o; });;
delete req.body.tzkzjcpfyjs; delete req.body.tzkzjcpfyjs;
//处理投资收益 //处理投资收益
let tzkztzsys = (req.body.tzkztzsys || []).map(o => { o.projectId = req.body.projectId;o.sourceId = ret.id; return o; });; let tzkztzsys = (req.body.tzkztzsys || []).map(o => { o.projectId = req.body.projectId; o.sourceId = ret.id; return o; });;
delete req.body.tzkztzsys; delete req.body.tzkztzsys;
//处理投资额控制 //处理投资额控制
let flattenArr = []; let flattenArr = [];
...@@ -220,7 +220,7 @@ async function createTzkz(req, res, next) { ...@@ -220,7 +220,7 @@ async function createTzkz(req, res, next) {
let tzkzaqzlhbs = (req.body.tzkzaqzlhbs || []).map(o => { o.projectId = req.body.projectId; o.sourceId = ret.id; return o; }); let tzkzaqzlhbs = (req.body.tzkzaqzlhbs || []).map(o => { o.projectId = req.body.projectId; o.sourceId = ret.id; return o; });
delete req.body.tzkzaqzlhbs; delete req.body.tzkzaqzlhbs;
//处理工期 //处理工期
let tzkzgqs = (req.body.tzkzgqs || []).map(o => { o.projectId = req.body.projectId;o.sourceId = ret.id; return o; }); let tzkzgqs = (req.body.tzkzgqs || []).map(o => { o.projectId = req.body.projectId; o.sourceId = ret.id; return o; });
delete req.body.tzkzgqs; delete req.body.tzkzgqs;
//创建 //创建
...@@ -240,8 +240,8 @@ async function updateTzkz(req, res, next) { ...@@ -240,8 +240,8 @@ async function updateTzkz(req, res, next) {
if (!req.body.projectId) { if (!req.body.projectId) {
return res.sendError(errorMessage.paramsError); return res.sendError(errorMessage.paramsError);
} }
let ret = await DB.TzTzkz.findOne({where: {id: req.body.id}, raw: true}); let ret = await DB.TzTzkz.findOne({ where: { id: req.body.id }, raw: true });
if(!(ret && ret.id)) { if (!(ret && ret.id)) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
//处理文件 //处理文件
...@@ -249,22 +249,22 @@ async function updateTzkz(req, res, next) { ...@@ -249,22 +249,22 @@ async function updateTzkz(req, res, next) {
//处理财务评价指标 //处理财务评价指标
let ids = [], infos = [], newtzkzcwpjs = []; let ids = [], infos = [], newtzkzcwpjs = [];
req.body.tzkzcwpjs.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id;newtzkzcwpjs.push(o); } } else { ids.push(o.id); infos.push(o); } return o }); req.body.tzkzcwpjs.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id; newtzkzcwpjs.push(o); } } else { ids.push(o.id); infos.push(o); } return o });
await DB.TzTzkzCwpj.destroy({ where: { projectId: req.body.projectId, id: { [Op.notIn]: ids } } }); // 删除id不在传入id数组里面的(用户在界面删除的) await DB.TzTzkzCwpj.destroy({ where: { projectId: req.body.projectId,sourceId: ret.id, id: { [Op.notIn]: ids } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
await DB.TzTzkzCwpj.bulkCreate(newtzkzcwpjs);//创建新的 没有id的 await DB.TzTzkzCwpj.bulkCreate(newtzkzcwpjs);//创建新的 没有id的
await Promise.all(infos.map(item => { DB.TzTzkzCwpj.update(item, { where: { id: item.id } }) })); await Promise.all(infos.map(item => { DB.TzTzkzCwpj.update(item, { where: { id: item.id } }) }));
delete req.body.tzkzcwpjs; delete req.body.tzkzcwpjs;
//处理决策批复意见 //处理决策批复意见
let ids1 = [], infos1 = [], newtzkzjcpfyjs = []; let ids1 = [], infos1 = [], newtzkzjcpfyjs = [];
req.body.tzkzjcpfyjs.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId;o.sourceId = ret.id; newtzkzjcpfyjs.push(o); } } else { ids1.push(o.id); infos1.push(o); } return o }); req.body.tzkzjcpfyjs.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id; newtzkzjcpfyjs.push(o); } } else { ids1.push(o.id); infos1.push(o); } return o });
await DB.TzTzkzJcpfyj.destroy({ where: { projectId: req.body.projectId, id: { [Op.notIn]: ids1 } } }); // 删除id不在传入id数组里面的(用户在界面删除的) await DB.TzTzkzJcpfyj.destroy({ where: { projectId: req.body.projectId,sourceId: ret.id, id: { [Op.notIn]: ids1 } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
await DB.TzTzkzJcpfyj.bulkCreate(newtzkzjcpfyjs);//创建新的 没有id的 await DB.TzTzkzJcpfyj.bulkCreate(newtzkzjcpfyjs);//创建新的 没有id的
await Promise.all(infos1.map(item => { DB.TzTzkzJcpfyj.update(item, { where: { id: item.id } }) })); await Promise.all(infos1.map(item => { DB.TzTzkzJcpfyj.update(item, { where: { id: item.id } }) }));
delete req.body.tzkzjcpfyjs; delete req.body.tzkzjcpfyjs;
//处理投资收益 //处理投资收益
let ids2 = [], infos2 = [], newtzkztzsys = []; let ids2 = [], infos2 = [], newtzkztzsys = [];
req.body.tzkztzsys.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id;newtzkztzsys.push(o); } } else { ids2.push(o.id); infos2.push(o); } return o }); req.body.tzkztzsys.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id; newtzkztzsys.push(o); } } else { ids2.push(o.id); infos2.push(o); } return o });
await DB.TzTzkzTzsy.destroy({ where: { projectId: req.body.projectId, id: { [Op.notIn]: ids2 } } }); // 删除id不在传入id数组里面的(用户在界面删除的) await DB.TzTzkzTzsy.destroy({ where: { projectId: req.body.projectId, sourceId: ret.id, id: { [Op.notIn]: ids2 } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
await DB.TzTzkzTzsy.bulkCreate(newtzkztzsys);//创建新的 没有id的 await DB.TzTzkzTzsy.bulkCreate(newtzkztzsys);//创建新的 没有id的
await Promise.all(infos2.map(item => { DB.TzTzkzTzsy.update(item, { where: { id: item.id } }) })); await Promise.all(infos2.map(item => { DB.TzTzkzTzsy.update(item, { where: { id: item.id } }) }));
delete req.body.tzkztzsys; delete req.body.tzkztzsys;
...@@ -287,22 +287,22 @@ async function updateTzkz(req, res, next) { ...@@ -287,22 +287,22 @@ async function updateTzkz(req, res, next) {
} }
} }
} }
await DB.TzTzkzTzekz.destroy({ where: { projectId: req.body.projectId, id: { [Op.notIn]: ids3 } } }); // 删除id不在传入id数组里面的(用户在界面删除的) await DB.TzTzkzTzekz.destroy({ where: { projectId: req.body.projectId, sourceId: ret.id,id: { [Op.notIn]: ids3 } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
await DB.TzTzkzTzekz.bulkCreate(newtzkztzekzs);//创建新的 没有id的 await DB.TzTzkzTzekz.bulkCreate(newtzkztzekzs);//创建新的 没有id的
await Promise.all(infos3.map(item => { DB.TzTzkzTzekz.update(item, { where: { id: item.id } }) })); await Promise.all(infos3.map(item => { DB.TzTzkzTzekz.update(item, { where: { id: item.id } }) }));
delete req.body.tzkztzekzs; delete req.body.tzkztzekzs;
//处理工期 //处理工期
let ids4 = [], infos4 = [], newtzkzgqs = []; let ids4 = [], infos4 = [], newtzkzgqs = [];
req.body.tzkzgqs.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id;newtzkzgqs.push(o); } } else { ids4.push(o.id); infos4.push(o); } return o }); req.body.tzkzgqs.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id; newtzkzgqs.push(o); } } else { ids4.push(o.id); infos4.push(o); } return o });
await DB.TzTzkzGq.destroy({ where: { projectId: req.body.projectId, id: { [Op.notIn]: ids4 } } }); // 删除id不在传入id数组里面的(用户在界面删除的) await DB.TzTzkzGq.destroy({ where: { projectId: req.body.projectId, sourceId: ret.id, id: { [Op.notIn]: ids4 } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
await DB.TzTzkzGq.bulkCreate(newtzkzgqs);//创建新的 没有id的 await DB.TzTzkzGq.bulkCreate(newtzkzgqs);//创建新的 没有id的
await Promise.all(infos4.map(item => { DB.TzTzkzGq.update(item, { where: { id: item.id } }) })); await Promise.all(infos4.map(item => { DB.TzTzkzGq.update(item, { where: { id: item.id } }) }));
delete req.body.tzkzgqs; delete req.body.tzkzgqs;
//处理环保 //处理环保
let ids5 = [], infos5 = [], newtzkzaqzlhbs = []; let ids5 = [], infos5 = [], newtzkzaqzlhbs = [];
req.body.tzkzaqzlhbs.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId;o.sourceId = ret.id; newtzkzaqzlhbs.push(o); } } else { ids5.push(o.id); infos5.push(o); } return o }); req.body.tzkzaqzlhbs.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id; newtzkzaqzlhbs.push(o); } } else { ids5.push(o.id); infos5.push(o); } return o });
await DB.TzTzkzAqzlhb.destroy({ where: { projectId: req.body.projectId, id: { [Op.notIn]: ids5 } } }); // 删除id不在传入id数组里面的(用户在界面删除的) await DB.TzTzkzAqzlhb.destroy({ where: { projectId: req.body.projectId,sourceId: ret.id, id: { [Op.notIn]: ids5 } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
await DB.TzTzkzAqzlhb.bulkCreate(newtzkzaqzlhbs);//创建新的 没有id的 await DB.TzTzkzAqzlhb.bulkCreate(newtzkzaqzlhbs);//创建新的 没有id的
await Promise.all(infos5.map(item => { DB.TzTzkzAqzlhb.update(item, { where: { id: item.id } }) })); await Promise.all(infos5.map(item => { DB.TzTzkzAqzlhb.update(item, { where: { id: item.id } }) }));
delete req.body.tzkzaqzlhbs; delete req.body.tzkzaqzlhbs;
...@@ -456,8 +456,8 @@ async function updateZdfx(req, res, next) { ...@@ -456,8 +456,8 @@ async function updateZdfx(req, res, next) {
if (!req.body.projectId) { if (!req.body.projectId) {
return res.sendError(errorMessage.paramsError); return res.sendError(errorMessage.paramsError);
} }
let ret = await DB.TzZdfx.findOne({where: {id: req.body.id}, raw: true}); let ret = await DB.TzZdfx.findOne({ where: { id: req.body.id }, raw: true });
if(!(ret && ret.id)) { if (!(ret && ret.id)) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
// //处理财务指标 // //处理财务指标
...@@ -469,8 +469,8 @@ async function updateZdfx(req, res, next) { ...@@ -469,8 +469,8 @@ async function updateZdfx(req, res, next) {
// delete req.body.zdfxcwzbs; // delete req.body.zdfxcwzbs;
//处理风险处置 //处理风险处置
let ids1 = [], infos1 = [], newzdfxczs = []; let ids1 = [], infos1 = [], newzdfxczs = [];
req.body.zdfxczs.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id;newzdfxczs.push(o); } } else { ids1.push(o.id); infos1.push(o); } return o }); req.body.zdfxczs.map(o => { if (!o.id) { if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id; newzdfxczs.push(o); } } else { ids1.push(o.id); infos1.push(o); } return o });
await DB.TzZdfxcz.destroy({ where: { projectId: req.body.projectId, id: { [Op.notIn]: ids1 } } }); // 删除id不在传入id数组里面的(用户在界面删除的) await DB.TzZdfxcz.destroy({ where: { projectId: req.body.projectId, sourceId: ret.id,id: { [Op.notIn]: ids1 } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
await DB.TzZdfxcz.bulkCreate(newzdfxczs);//创建新的 没有id的 await DB.TzZdfxcz.bulkCreate(newzdfxczs);//创建新的 没有id的
await Promise.all(infos1.map(item => { DB.TzZdfxcz.update(item, { where: { id: item.id } }) })); await Promise.all(infos1.map(item => { DB.TzZdfxcz.update(item, { where: { id: item.id } }) }));
delete req.body.zdfxczs; delete req.body.zdfxczs;
...@@ -644,12 +644,14 @@ async function createJsqtzjc(req, res, next) { ...@@ -644,12 +644,14 @@ async function createJsqtzjc(req, res, next) {
if (!req.body.projectId) { if (!req.body.projectId) {
return res.sendError(errorMessage.paramsError); return res.sendError(errorMessage.paramsError);
} }
let ret = await DB.TzJsqtzjc.create(req.body);
//日常自查 投资(成本)分析会 //日常自查 投资(成本)分析会
let jsqtzjcTzfxs = req.body.jsqtzjcTzfxs || []; let jsqtzjcTzfxs = req.body.jsqtzjcTzfxs || [];
let newjsqtzjcTzfxs = []; let newjsqtzjcTzfxs = [];
for (let index = 0; index < jsqtzjcTzfxs.length; index++) { for (let index = 0; index < jsqtzjcTzfxs.length; index++) {
let element = jsqtzjcTzfxs[index]; let element = jsqtzjcTzfxs[index];
element.projectId = req.body.projectId; element.projectId = req.body.projectId;
element.sourceId = ret.id;
element.tzcbfxhzl = (element.tzcbfxhzl || []).map(o => { return o && o.id || o }); element.tzcbfxhzl = (element.tzcbfxhzl || []).map(o => { return o && o.id || o });
newjsqtzjcTzfxs.push(element); newjsqtzjcTzfxs.push(element);
} }
...@@ -670,6 +672,7 @@ async function createJsqtzjc(req, res, next) { ...@@ -670,6 +672,7 @@ async function createJsqtzjc(req, res, next) {
for (let index = 0; index < jsqtzjcZxjcs.length; index++) { for (let index = 0; index < jsqtzjcZxjcs.length; index++) {
let element = jsqtzjcZxjcs[index]; let element = jsqtzjcZxjcs[index];
element.projectId = req.body.projectId; element.projectId = req.body.projectId;
element.sourceId = ret.id;
element.fjcl = (element.fjcl || []).map(o => { return o && o.id || o }); element.fjcl = (element.fjcl || []).map(o => { return o && o.id || o });
newjsqtzjcZxjcs.push(element); newjsqtzjcZxjcs.push(element);
} }
...@@ -679,7 +682,6 @@ async function createJsqtzjc(req, res, next) { ...@@ -679,7 +682,6 @@ async function createJsqtzjc(req, res, next) {
await DB.TzJsqtzjcTzfx.bulkCreate(jsqtzjcTzfxs); await DB.TzJsqtzjcTzfx.bulkCreate(jsqtzjcTzfxs);
// await DB.TzJsqtzjcrcjc.bulkCreate(jsqtzjcrcjcs); // await DB.TzJsqtzjcrcjc.bulkCreate(jsqtzjcrcjcs);
await DB.TzJsqtzjcZxjc.bulkCreate(jsqtzjcZxjcs); await DB.TzJsqtzjcZxjc.bulkCreate(jsqtzjcZxjcs);
let ret = await DB.TzJsqtzjc.create(req.body);
return res.sendData(ret); return res.sendData(ret);
} catch (error) { } catch (error) {
next(error); next(error);
...@@ -704,7 +706,7 @@ async function getJsqtzjcInfo(req, res, next) { ...@@ -704,7 +706,7 @@ async function getJsqtzjcInfo(req, res, next) {
} }
let newjsqtzjcTzfxs = [], newjsqtzjcrcjcs = [], newjsqtzjcZxjcs = []; let newjsqtzjcTzfxs = [], newjsqtzjcrcjcs = [], newjsqtzjcZxjcs = [];
let jsqtzjcTzfxs = await DB.TzJsqtzjcTzfx.findAll({ where: { projectId: jsqtzjc.projectId }, raw: true }); let jsqtzjcTzfxs = await DB.TzJsqtzjcTzfx.findAll({ where: { projectId: jsqtzjc.projectId, sourceId: jsqtzjc.id }, raw: true });
for (let index = 0; index < jsqtzjcTzfxs.length; index++) { for (let index = 0; index < jsqtzjcTzfxs.length; index++) {
let element = jsqtzjcTzfxs[index]; let element = jsqtzjcTzfxs[index];
// fileids.concat(element.tzcbfxhzl || []); // fileids.concat(element.tzcbfxhzl || []);
...@@ -718,7 +720,7 @@ async function getJsqtzjcInfo(req, res, next) { ...@@ -718,7 +720,7 @@ async function getJsqtzjcInfo(req, res, next) {
// element.fxcl = await DB.File.findAll({ where: { id: { [Op.in]: element.fxcl } } }); // element.fxcl = await DB.File.findAll({ where: { id: { [Op.in]: element.fxcl } } });
// newjsqtzjcrcjcs.push(element); // newjsqtzjcrcjcs.push(element);
// } // }
let jsqtzjcZxjcs = await DB.TzJsqtzjcZxjc.findAll({ where: { projectId: jsqtzjc.projectId }, raw: true }); let jsqtzjcZxjcs = await DB.TzJsqtzjcZxjc.findAll({ where: { projectId: jsqtzjc.projectId, sourceId: jsqtzjc.id }, raw: true });
for (let index = 0; index < jsqtzjcZxjcs.length; index++) { for (let index = 0; index < jsqtzjcZxjcs.length; index++) {
const element = jsqtzjcZxjcs[index]; const element = jsqtzjcZxjcs[index];
// fileids.concat(element.fjcl || []); // fileids.concat(element.fjcl || []);
...@@ -740,11 +742,16 @@ async function updateJsqtzjc(req, res, next) { ...@@ -740,11 +742,16 @@ async function updateJsqtzjc(req, res, next) {
if (!req.body.projectId) { if (!req.body.projectId) {
return res.sendError(errorMessage.paramsError); return res.sendError(errorMessage.paramsError);
} }
let jsqtzjc = await DB.TzJsqtzjc.findOne({ where: search, raw: true });
if (!(jsqtzjc && jsqtzjc.id && jsqtzjc.projectId)) {
return res.sendError(errorMessage.resourceNotFound);
}
let jsqtzjcTzfxs = req.body.jsqtzjcTzfxs || []; let jsqtzjcTzfxs = req.body.jsqtzjcTzfxs || [];
let ids = [], newArr = [], info = []; let ids = [], newArr = [], info = [];
for (let index = 0; index < jsqtzjcTzfxs.length; index++) { for (let index = 0; index < jsqtzjcTzfxs.length; index++) {
let element = jsqtzjcTzfxs[index]; let element = jsqtzjcTzfxs[index];
element.projectId = req.body.projectId; element.projectId = req.body.projectId;
element.sourceId = jsqtzjc.id;
element.tzcbfxhzl = (element.tzcbfxhzl || []).map(o => { return o && o.id || o }); element.tzcbfxhzl = (element.tzcbfxhzl || []).map(o => { return o && o.id || o });
if (element.id) { if (element.id) {
ids.push(element.id); ids.push(element.id);
...@@ -753,7 +760,7 @@ async function updateJsqtzjc(req, res, next) { ...@@ -753,7 +760,7 @@ async function updateJsqtzjc(req, res, next) {
newArr.push(element); newArr.push(element);
} }
} }
await DB.TzJsqtzjcTzfx.destroy({ where: { projectId: req.body.projectId, id: { [Op.notIn]: ids } } }); // 删除id不在传入id数组里面的(用户在界面删除的) await DB.TzJsqtzjcTzfx.destroy({ where: { projectId: req.body.projectId, sourceId: jsqtzjc.id, id: { [Op.notIn]: ids } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
await DB.TzJsqtzjcTzfx.bulkCreate(newArr);//创建新的 没有id的 await DB.TzJsqtzjcTzfx.bulkCreate(newArr);//创建新的 没有id的
await Promise.all(info.map(item => { DB.TzJsqtzjcTzfx.update(item, { where: { id: item.id } }) })); await Promise.all(info.map(item => { DB.TzJsqtzjcTzfx.update(item, { where: { id: item.id } }) }));
delete req.body.jsqtzjcTzfxs; delete req.body.jsqtzjcTzfxs;
...@@ -782,6 +789,7 @@ async function updateJsqtzjc(req, res, next) { ...@@ -782,6 +789,7 @@ async function updateJsqtzjc(req, res, next) {
for (let index = 0; index < jsqtzjcZxjcs.length; index++) { for (let index = 0; index < jsqtzjcZxjcs.length; index++) {
let element = jsqtzjcZxjcs[index]; let element = jsqtzjcZxjcs[index];
element.projectId = req.body.projectId; element.projectId = req.body.projectId;
element.sourceId = jsqtzjc.id;
element.fjcl = (element.fjcl || []).map(o => { return o && o.id || o }); element.fjcl = (element.fjcl || []).map(o => { return o && o.id || o });
if (element.id) { if (element.id) {
ids2.push(element.id); ids2.push(element.id);
...@@ -790,7 +798,7 @@ async function updateJsqtzjc(req, res, next) { ...@@ -790,7 +798,7 @@ async function updateJsqtzjc(req, res, next) {
newArr2.push(element); newArr2.push(element);
} }
} }
await DB.TzJsqtzjcZxjc.destroy({ where: { projectId: req.body.projectId, id: { [Op.notIn]: ids2 } } }); // 删除id不在传入id数组里面的(用户在界面删除的) await DB.TzJsqtzjcZxjc.destroy({ where: { projectId: req.body.projectId, sourceId: jsqtzjc.id, id: { [Op.notIn]: ids2 } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
await DB.TzJsqtzjcZxjc.bulkCreate(newArr2);//创建新的 没有id的 await DB.TzJsqtzjcZxjc.bulkCreate(newArr2);//创建新的 没有id的
await Promise.all(info2.map(item => { DB.TzJsqtzjcZxjc.update(item, { where: { id: item.id } }) })); await Promise.all(info2.map(item => { DB.TzJsqtzjcZxjc.update(item, { where: { id: item.id } }) }));
delete req.body.jsqtzjcZxjcs; delete req.body.jsqtzjcZxjcs;
......
...@@ -28,7 +28,10 @@ const TzJsqtzjcTzfx = sequelize.define('TzJsqtzjcTzfx', { ...@@ -28,7 +28,10 @@ const TzJsqtzjcTzfx = sequelize.define('TzJsqtzjcTzfx', {
type: DataTypes.JSON, type: DataTypes.JSON,
comment: "投资(成本)分析会资料" comment: "投资(成本)分析会资料"
}, },
sourceId: {
type: DataTypes.INTEGER,
comment: "所属投资控制主表id"
},
projectId: { projectId: {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
comment: "所属项目ID", comment: "所属项目ID",
......
...@@ -45,7 +45,10 @@ const TzJsqtzjcZxjc = sequelize.define('TzJsqtzjcZxjc', { ...@@ -45,7 +45,10 @@ const TzJsqtzjcZxjc = sequelize.define('TzJsqtzjcZxjc', {
comment: "附件材料" comment: "附件材料"
}, },
sourceId: {
type: DataTypes.INTEGER,
comment: "所属投资控制主表id"
},
projectId: { projectId: {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
comment: "所属项目ID", comment: "所属项目ID",
......
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