明树Git Lab

Commit 23e96544 authored by zfp1's avatar zfp1

update

parent fc817346
......@@ -72,9 +72,9 @@ async function updateTzmbzrs(req, res, next) {
//1.更新责任指标表数据
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 });
await DB.TzTzmbzrsZb.destroy({ where: { projectId: req.body.projectId,sourceId: ret.id, 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 Promise.all(infos.map(item => { return DB.TzTzmbzrsZb.update(item, { where: { id: item.id } }) }));
await Promise.all(infos.map(item => { return DB.TzTzmbzrsZb.update(item, { where: { id: item.id } }) }));
console.log(ids, infos, newtzmbzrsZbs, "===================================================================")
......@@ -82,15 +82,15 @@ async function updateTzmbzrs(req, res, next) {
//1.更新批复意见
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 });
await DB.TzTzmbzrsPfyj.destroy({ where: { projectId: req.body.projectId,sourceId: ret.id, 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 Promise.all(infos1.map(item => { return DB.TzTzmbzrsPfyj.update(item, { where: { id: item.id } }) }));
// 更新年度经营
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 });
await DB.TzTzmbzrsNd.destroy({ where: { projectId: req.body.projectId,sourceId: ret.id, 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 Promise.all(infos2.map(item => {return DB.TzTzmbzrsNd.update(item, { where: { id: item.id } }) }));
await Promise.all(infos2.map(item => { return DB.TzTzmbzrsNd.update(item, { where: { id: item.id } }) }));
//2.更新责任书
await DB.TzTzmbzrs.update(req.body, { where: { id: req.body.id } });
......@@ -248,14 +248,14 @@ async function updateTzkz(req, res, next) {
//处理财务评价指标
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 });
await DB.TzTzkzCwpj.destroy({ where: { projectId: req.body.projectId,sourceId: ret.id, 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 Promise.all(infos.map(item => { return DB.TzTzkzCwpj.update(item, { where: { id: item.id } }) }));
delete req.body.tzkzcwpjs;
//处理决策批复意见
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 });
await DB.TzTzkzJcpfyj.destroy({ where: { projectId: req.body.projectId,sourceId: ret.id, 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 Promise.all(infos1.map(item => { return DB.TzTzkzJcpfyj.update(item, { where: { id: item.id } }) }));
delete req.body.tzkzjcpfyjs;
......@@ -285,7 +285,7 @@ async function updateTzkz(req, res, next) {
}
}
}
await DB.TzTzkzTzekz.destroy({ where: { projectId: req.body.projectId, sourceId: ret.id,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 Promise.all(infos3.map(item => { return DB.TzTzkzTzekz.update(item, { where: { id: item.id } }) }));
delete req.body.tzkztzekzs;
......@@ -300,7 +300,7 @@ async function updateTzkz(req, res, next) {
//处理环保
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 });
await DB.TzTzkzAqzlhb.destroy({ where: { projectId: req.body.projectId,sourceId: ret.id, 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 Promise.all(infos5.map(item => { return DB.TzTzkzAqzlhb.update(item, { where: { id: item.id } }) }));
delete req.body.tzkzaqzlhbs;
......@@ -468,7 +468,7 @@ async function updateZdfx(req, res, next) {
//处理风险处置
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 });
await DB.TzZdfxcz.destroy({ where: { projectId: req.body.projectId, sourceId: ret.id,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 Promise.all(infos1.map(item => { return DB.TzZdfxcz.update(item, { where: { id: item.id } }) }));
delete req.body.zdfxczs;
......@@ -573,8 +573,8 @@ async function updateJsqtzhs(req, res, next) {
if (!req.body.projectId) {
return res.sendError(errorMessage.paramsError);
}
let tzhs = await DB.TzJsqtzhs.findOne({ where: {id: req.body.id}, raw: true });
if(!(tzhs &&tzhs.id)) {
let tzhs = await DB.TzJsqtzhs.findOne({ where: { id: req.body.id }, raw: true });
if (!(tzhs && tzhs.id)) {
return res.sendError(errorMessage.resourceNotFound)
}
let jsqtzhss = req.body.jsqtzhss || [[]]; //二维数组 多次上报
......@@ -595,7 +595,7 @@ async function updateJsqtzhs(req, res, next) {
}
}
}
await DB.TzJsqtzhszb.destroy({ where: { projectId: req.body.projectId,sourceId: tzhs.id, id: { [Op.notIn]: ids3 } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
await DB.TzJsqtzhszb.destroy({ where: { projectId: req.body.projectId, sourceId: tzhs.id, id: { [Op.notIn]: ids3 } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
await DB.TzJsqtzhszb.bulkCreate(newtjsqtzhss);//创建新的 没有id的
await Promise.all(infos3.map(item => { return DB.TzJsqtzhszb.update(item, { where: { id: item.id } }) }));
delete req.body.jsqtzhss;
......@@ -847,15 +847,15 @@ async function createZdsxsp(req, res, next) {
return res.sendError(errorMessage.paramsError);
}
//处理文件
req.body.qylht = (req.bodt.qylht || []).map(o => {return o && o.id || o});
req.body.jjlht = (req.bodt.jjlht || []).map(o => {return o && o.id || o});
req.body.zjwj = (req.bodt.zjwj || []).map(o => {return o && o.id || o});
req.body.ybfspwj = (req.bodt.ybfspwj || []).map(o => {return o && o.id || o});
req.body.cwjr = (req.bodt.cwjr || []).map(o => {return o && o.id || o});
req.body.gqjg = (req.bodt.gqjg || []).map(o => {return o && o.id || o});
req.body.qylht = (req.bodt.qylht || []).map(o => { return o && o.id || o });
req.body.jjlht = (req.bodt.jjlht || []).map(o => { return o && o.id || o });
req.body.zjwj = (req.bodt.zjwj || []).map(o => { return o && o.id || o });
req.body.ybfspwj = (req.bodt.ybfspwj || []).map(o => { return o && o.id || o });
req.body.cwjr = (req.bodt.cwjr || []).map(o => { return o && o.id || o });
req.body.gqjg = (req.bodt.gqjg || []).map(o => { return o && o.id || o });
let ret = await DB.TzZdsxsp.create(req.body);
return res.sendData(ret);
} catch (error) {
next(error);
......@@ -878,19 +878,17 @@ async function getZdsxspInfo(req, res, next) {
if (!(zdsxsp && zdsxsp.id && zdsxsp.projectId)) {
return res.sendError(errorMessage.resourceNotFound);
}
let zdsxspfls = await DB.TzZdsxspfl.findAll({
where: { projectId: zdsxsp.projectId, sourceId: zdsxsp.id },
raw: true,
});
let newArr = [];
for (let index = 0; index < zdsxspfls.length; index++) {
const element = zdsxspfls[index];
if (element.wj && element.wj.length > 0) {
element.wj = await DB.File.findAll({ where: { id: { [Op.in]: element.wj } }, raw: true });
}
newArr.push(element);
}
zdsxsp.zdsxspfls = newArr;
let fileIds = [].concat(zdsxsp.qylht).concat(zdsxsp.jjlht).concat(zdsxsp.zjwj).concat(zdsxsp.ybfspwj).concat(zdsxsp.cwjr).concat(zdsxsp.gqjg);
let files = await DB.File.findAll({ where: { id: { [Op.in]: fileIds } }, raw: true });
let fileMap = {};
files.map(o => { fileMap[o.id] = o });
zdsxsp.qylht = (zdsxsp.qylht || []).map(o => { return fileMap[(o && o.id || o)] });
zdsxsp.jjlht = (zdsxsp.jjlht || []).map(o => { return fileMap[(o && o.id || o)] });
zdsxsp.zjwj = (zdsxsp.zjwj || []).map(o => { return fileMap[(o && o.id || o)] });
zdsxsp.ybfspwj = (zdsxsp.ybfspwj || []).map(o => { return fileMap[(o && o.id || o)] });
zdsxsp.cwjr = (zdsxsp.cwjr || []).map(o => { return fileMap[(o && o.id || o)] });
zdsxsp.gqjg = (zdsxsp.gqjg || []).map(o => { return fileMap[(o && o.id || o)] });
return res.sendData(zdsxsp);
} catch (error) {
next(error);
......@@ -902,28 +900,34 @@ async function updateZdsxsp(req, res, next) {
return res.sendError(errorMessage.paramsError);
}
let zdsxsp = await DB.TzZdsxsp.findOne({ where: search, raw: true });
if(!(zdsxsp && zdsxsp.id)) {
if (!(zdsxsp && zdsxsp.id)) {
return res.sendError(errorMessage.resourceNotFound);
}
let zdsxspfls = req.body.zdsxspfls || [];
let ids = [], info = [], newArr = [];
for (let index = 0; index < zdsxspfls.length; index++) {
const element = zdsxspfls[index];
element.projectId = req.body.projectId;
element.sourceId = zdsxsp.id;
element.wj = (element.wj || []).map(o => { return o && o.id || o });
if (element.id) {
ids.push(element.id);
info.push(element);
} else {
newArr.push(element);
}
}
await DB.TzZdsxspfl.destroy({ where: { projectId: req.body.projectId,sourceId: zdsxsp.id, id: { [Op.notIn]: ids } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
await DB.TzZdsxspfl.bulkCreate(newArr);//创建新的 没有id的
await Promise.all(info.map(item => { return DB.TzZdsxspfl.update(item, { where: { id: item.id } }) }));
delete req.body.zdsxspfls;
// let zdsxspfls = req.body.zdsxspfls || [];
// let ids = [], info = [], newArr = [];
// for (let index = 0; index < zdsxspfls.length; index++) {
// const element = zdsxspfls[index];
// element.projectId = req.body.projectId;
// element.sourceId = zdsxsp.id;
// element.wj = (element.wj || []).map(o => { return o && o.id || o });
// if (element.id) {
// ids.push(element.id);
// info.push(element);
// } else {
// newArr.push(element);
// }
// }
// await DB.TzZdsxspfl.destroy({ where: { projectId: req.body.projectId, sourceId: zdsxsp.id, id: { [Op.notIn]: ids } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
// await DB.TzZdsxspfl.bulkCreate(newArr);//创建新的 没有id的
// await Promise.all(info.map(item => { return DB.TzZdsxspfl.update(item, { where: { id: item.id } }) }));
// delete req.body.zdsxspfls;
//处理文件
req.body.qylht = (req.bodt.qylht || []).map(o => { return o && o.id || o });
req.body.jjlht = (req.bodt.jjlht || []).map(o => { return o && o.id || o });
req.body.zjwj = (req.bodt.zjwj || []).map(o => { return o && o.id || o });
req.body.ybfspwj = (req.bodt.ybfspwj || []).map(o => { return o && o.id || o });
req.body.cwjr = (req.bodt.cwjr || []).map(o => { return o && o.id || o });
req.body.gqjg = (req.bodt.gqjg || []).map(o => { return o && o.id || o });
await DB.TzZdsxsp.update(req.body, { where: { id: req.body.id } });
return res.sendData({});
} catch (error) {
......
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