明树Git Lab

Commit 1f8b93db authored by zfp1's avatar zfp1

update

parent 5faff9c9
......@@ -526,6 +526,7 @@ async function createJsqtzhs(req, res, next) {
if (!req.body.projectId) {
return res.sendError(errorMessage.paramsError);
}
let ret = await DB.TzJsqtzhs.create(req.body);
//处理财务指标
let flattenArr = [];
let jsqtzhss = req.body.jsqtzhss || [[]]; //二维数组 多次上报
......@@ -536,13 +537,13 @@ async function createJsqtzhs(req, res, next) {
let ei = element[i];
ei.groupBy = index;
ei.projectId = req.body.projectId;
ei.sourceId = ret.id;
flattenArr.push(ei);
}
}
delete req.body.jsqtzhss;
await DB.TzJsqtzhszb.bulkCreate(flattenArr);
let ret = await DB.TzJsqtzhs.create(req.body);
return res.sendData(ret);
} catch (error) {
next(error);
......@@ -555,9 +556,6 @@ async function getJsqtzhsInfo(req, res, next) {
if (req.body.id) {
search.id = req.body.id;
}
if (req.body.projectId) {
search.projectId = req.body.projectId;
}
if (_.isEmpty(search)) {
return res.sendError(errorMessage.paramsError);
}
......@@ -565,7 +563,7 @@ async function getJsqtzhsInfo(req, res, next) {
if (!(tzhs && tzhs.id && tzhs.projectId)) {
return res.sendError(errorMessage.resourceNotFound);
}
let jsqtzhss = await DB.TzJsqtzhszb.findAll({ where: { projectId: tzhs.projectId }, raw: true });
let jsqtzhss = await DB.TzJsqtzhszb.findAll({ where: { projectId: tzhs.projectId, sourceId: tzhs.id }, raw: true });
tzhs.jsqtzhss = _.values(_.groupBy(jsqtzhss, 'groupBy')) || [[]]
return res.sendData(tzhs);
} catch (error) {
......@@ -577,6 +575,10 @@ 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)) {
return res.sendError(errorMessage.resourceNotFound)
}
let jsqtzhss = req.body.jsqtzhss || [[]]; //二维数组 多次上报
let ids3 = [], infos3 = [], newtjsqtzhss = [];
for (let index = 0; index < jsqtzhss.length; index++) {
......@@ -585,6 +587,7 @@ async function updateJsqtzhs(req, res, next) {
let ei = element[i];
ei.groupBy = index;
ei.projectId = req.body.projectId;
ei.sourceId = tzhs.id;
if (!ei.id) {
if (!_.isEmpty(ei)) {
newtjsqtzhss.push(ei);
......@@ -594,7 +597,7 @@ async function updateJsqtzhs(req, res, next) {
}
}
}
await DB.TzJsqtzhszb.destroy({ where: { projectId: req.body.projectId, 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 => { DB.TzJsqtzhszb.update(item, { where: { id: item.id } }) }));
delete req.body.jsqtzhss;
......@@ -845,18 +848,20 @@ async function createZdsxsp(req, res, next) {
if (!req.body.projectId) {
return res.sendError(errorMessage.paramsError);
}
let ret = await DB.TzZdsxsp.create(req.body);
//日常自查 投资(成本)分析会
let zdsxspfls = req.body.zdsxspfls || [];
let newArr = [];
for (let index = 0; index < zdsxspfls.length; index++) {
const element = zdsxspfls[index];
element.projectId = req.body.projectId;
element.sourceId = ret.id;
element.wj = (element.wj || []).map(o => { return o && o.id || o });
newArr.push(element);
}
delete req.body.zdsxspfls;
await DB.TzZdsxspfl.bulkCreate(newArr);
let ret = await DB.TzZdsxsp.create(req.body);
return res.sendData(ret);
} catch (error) {
next(error);
......@@ -880,7 +885,7 @@ async function getZdsxspInfo(req, res, next) {
return res.sendError(errorMessage.resourceNotFound);
}
let zdsxspfls = await DB.TzZdsxspfl.findAll({
where: { projectId: zdsxsp.projectId },
where: { projectId: zdsxsp.projectId, sourceId: zdsxsp.id },
raw: true,
});
let newArr = [];
......@@ -902,11 +907,16 @@ async function updateZdsxsp(req, res, next) {
if (!req.body.projectId) {
return res.sendError(errorMessage.paramsError);
}
let zdsxsp = await DB.TzZdsxsp.findOne({ where: search, raw: true });
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);
......@@ -915,7 +925,7 @@ async function updateZdsxsp(req, res, next) {
newArr.push(element);
}
}
await DB.TzZdsxspfl.destroy({ where: { projectId: req.body.projectId, id: { [Op.notIn]: ids } } }); // 删除id不在传入id数组里面的(用户在界面删除的)
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 => { DB.TzZdsxspfl.update(item, { where: { id: item.id } }) }));
delete req.body.zdsxspfls;
......
......@@ -48,7 +48,10 @@ const TzJsqtzhszb = sequelize.define('TzJsqtzhszb', {
type: DataTypes.INTEGER,
comment: "分组"
},
sourceId: {
type: DataTypes.INTEGER,
comment: "所属投资控制主表id"
},
projectId: {
type: DataTypes.INTEGER,
comment: "所属项目ID",
......
......@@ -16,6 +16,11 @@ const TzZdsxsp = sequelize.define('TzZdsxsp', {
},
qylht: {
type: DataTypes.JSON,
comment: "权益类合同"
},
projectId: {
type: DataTypes.INTEGER,
comment: "所属项目ID",
......
const { DataTypes } = require('sequelize');
const sequelize = require('../index');
const moment = require('moment');
// const { DataTypes } = require('sequelize');
// const sequelize = require('../index');
// const moment = require('moment');
//投中管理- 重大事项审批分类
const TzZdsxspfl = sequelize.define('TzZdsxspfl', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
lx: {
type: DataTypes.JSON,
comment: "类型---级联选择"
},
sm: {
type: DataTypes.TEXT,
comment: "说明"
},
wj: {
type: DataTypes.JSON,
comment: "文件"
},
// //投中管理- 重大事项审批分类
// const TzZdsxspfl = sequelize.define('TzZdsxspfl', {
// id: {
// type: DataTypes.INTEGER,
// primaryKey: true,
// autoIncrement: true
// },
// lx: {
// type: DataTypes.JSON,
// comment: "类型---级联选择"
// },
// sm: {
// type: DataTypes.TEXT,
// comment: "说明"
// },
// wj: {
// type: DataTypes.JSON,
// comment: "文件"
// },
// sourceId: {
// type: DataTypes.INTEGER,
// comment: "所属投资控制主表id"
// },
// projectId: {
// type: DataTypes.INTEGER,
// comment: "所属项目ID",
// },
// del: {
// type: DataTypes.INTEGER,
// defaultValue: 0,
// comment: "0 正常 1 删除"
// },
// createdAt: {
// type: DataTypes.DATE,
// defaultValue: new Date(),
// get() {
// const rawValue = this.getDataValue('createdAt');
// return rawValue ? moment(rawValue).format('YYYY-MM-DD HH:mm:ss') : '';
// }
// },
// updatedAt: { // 同样处理 updatedAt
// type: DataTypes.DATE,
// defaultValue: new Date(),
// get() {
// const rawValue = this.getDataValue('updatedAt');
// return rawValue ? moment(rawValue).format('YYYY-MM-DD HH:mm:ss') : '';
// }
// }
// }, {
// tableName: 'jt_tz_zdsxspfl', // 指定表名(如果与模型名不同)
// timestamps: true, // 是否自动添加 createdAt 和 updatedAt 字段(覆盖全局设置)
// });
projectId: {
type: DataTypes.INTEGER,
comment: "所属项目ID",
},
del: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: "0 正常 1 删除"
},
createdAt: {
type: DataTypes.DATE,
defaultValue: new Date(),
get() {
const rawValue = this.getDataValue('createdAt');
return rawValue ? moment(rawValue).format('YYYY-MM-DD HH:mm:ss') : '';
}
},
updatedAt: { // 同样处理 updatedAt
type: DataTypes.DATE,
defaultValue: new Date(),
get() {
const rawValue = this.getDataValue('updatedAt');
return rawValue ? moment(rawValue).format('YYYY-MM-DD HH:mm:ss') : '';
}
}
}, {
tableName: 'jt_tz_zdsxspfl', // 指定表名(如果与模型名不同)
timestamps: true, // 是否自动添加 createdAt 和 updatedAt 字段(覆盖全局设置)
});
// // 同步模型到数据库(创建表)
// TzZdsxspfl.sync({
// // force: false,
// // force: true ,//会删除已存在表并重新创建
// alter: true
// })
// .then(() => {
// console.log('TzZdsxspfl 表同步成功');
// });
// 同步模型到数据库(创建表)
TzZdsxspfl.sync({
// force: false,
// force: true ,//会删除已存在表并重新创建
alter: true
})
.then(() => {
console.log('TzZdsxspfl 表同步成功');
});
module.exports = TzZdsxspfl;
\ No newline at end of file
// module.exports = TzZdsxspfl;
\ No newline at end of file
......@@ -58,7 +58,7 @@ router.post('/createTzmbzrs', projectTzController.createTzmbzrs);
router.post('/updateTzmbzrs', projectTzController.updateTzmbzrs);
router.post('/getTzmbzrsList', projectTzController.getTzmbzrsList);
router.post('/getTzmbzrsInfo', projectTzController.getTzmbzrsInfo);
router.post('/deleteTzmbzrsInfo', projectTzController.deleteTzmbzrsInfo);
router.post('/deleteTzmbzrs', projectTzController.deleteTzmbzrsInfo);
//投资控制
......@@ -91,7 +91,7 @@ router.post('/getZdsxspList', projectTzController.getZdsxspList);
router.post('/getZdsxspInfo', projectTzController.getZdsxspInfo);
//项目退出
//项目退出-------以下sourceId待改
router.post('/createXmtc', projectTzController.createXmtc);
router.post('/updateXmtc', projectTzController.updateXmtc);
router.post('/getXmtcList', projectTzController.getXmtcList);
......
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