明树Git Lab

Commit 49f1585a authored by zfp1's avatar zfp1

update

parent f195e92c
...@@ -433,6 +433,121 @@ async function getZdfxList(req, res, next) { ...@@ -433,6 +433,121 @@ async function getZdfxList(req, res, next) {
next(error); next(error);
} }
} }
async function createJsqtzhs(req, res, next) {
try {
if (!req.body.projectId) {
return res.sendError(errorMessage.paramsError);
}
//处理财务指标
let flattenArr = [];
let jsqtzhss = req.body.jsqtzhss || [[]]; //二维数组 多次上报
delete req.body.jsqtzhss;
for (let index = 0; index < jsqtzhss.length; index++) {
const element = jsqtzhss[index];
for (let i = 0; i < element.length; i++) {
let ei = element[i];
ei.groupBy = index;
ei.projectId = req.body.projectId;
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);
}
}
async function getJsqtzhsInfo(req, res, next) {
try {
let search = {};
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);
}
let tzhs = await DB.TzJsqtzhs.findOne({ where: search, raw: true });
if (!(tzhs && tzhs.id && tzhs.projectId)) {
return res.sendError(errorMessage.resourceNotFound);
}
let jsqtzhss = await DB.TzJsqtzhszb.findAll({ where: { projectId: tzhs.projectId }, raw: true });
tzhs.jsqtzhss = _.values(_.groupBy(jsqtzhss, 'groupBy')) || [[]]
return res.sendData(tzhs);
} catch (error) {
next(error);
}
}
async function updateJsqtzhs(req, res, next) {
try {
if (!req.body.projectId) {
return res.sendError(errorMessage.paramsError);
}
let jsqtzhss = req.body.jsqtzhss || [[]]; //二维数组 多次上报
let ids3 = [], infos3 = [], newtjsqtzhss = [];
for (let index = 0; index < jsqtzhss.length; index++) {
const element = jsqtzhss[index];
for (let i = 0; i < element.length; i++) {
let ei = element[i];
ei.groupBy = index;
ei.projectId = req.body.projectId;
if (!ei.id) {
if (!_.isEmpty(ei)) {
newtjsqtzhss.push(ei);
}
} else {
ids3.push(ei.id); infos3.push(ei);
}
}
}
await DB.TzJsqtzhszb.destroy({ where: { projectId: req.body.projectId, 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;
await DB.TzJsqtzhs.update(req.body, { where: { id: req.body.id } });
return res.sendData({});
} catch (error) {
next(error);
}
}
async function getJsqtzhsList(req, res, next) {
try {
let page = req.body.page || 1;
let limit = req.body.pagesize || req.body.pageSize || 10;
let offset = (page - 1) * limit;
let search = {};
search.order = [['createdAt', 'DESC']];
search.limit = limit;
search.offset = offset;
let where = { del: 0 };
if (req.body.projectName) {
where = {
[Op.or]: [
{ projectName: { [Op.like]: `%${req.body.projectName}%` } },
],
del: 0
}
}
search.where = where;
if (req.body.attributes && req.body.attributes.length) {
search.attributes = req.body.attributes;
}
let ret = await DB.TzJsqtzhs.findAndCountAll(search);
return res.sendData(ret);
} catch (error) {
next(error);
}
}
...@@ -449,4 +564,8 @@ module.exports = { ...@@ -449,4 +564,8 @@ module.exports = {
updateZdfx, updateZdfx,
getZdfxList, getZdfxList,
getZdfxInfo, getZdfxInfo,
createJsqtzhs,
updateJsqtzhs,
getJsqtzhsList,
getJsqtzhsInfo,
} }
\ No newline at end of file
const { DataTypes } = require('sequelize');
const sequelize = require('../index');
const moment = require('moment');
/**
* 投中管理- 建设期投资回收
*/
const TzJsqtzhs = sequelize.define('TzJsqtzhs', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
projectName: {
type: DataTypes.STRING,
comment: "项目名称",
},
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_jsqtzhs', // 指定表名(如果与模型名不同)
timestamps: true, // 是否自动添加 createdAt 和 updatedAt 字段(覆盖全局设置)
});
// 同步模型到数据库(创建表)
TzJsqtzhs.sync({
// force: false,
// force: true ,//会删除已存在表并重新创建
alter: true
})
.then(() => {
console.log('TzJsqtzhs 表同步成功');
});
module.exports = TzJsqtzhs;
\ No newline at end of file
const { DataTypes } = require('sequelize');
const sequelize = require('../index');
const moment = require('moment');
/**
* 投中管理- 建设期投资回收关联表
*/
const TzJsqtzhszb = sequelize.define('TzJsqtzhszb', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
year: {
type: DataTypes.DATE,
comment: "年份",
},
month: {
type: DataTypes.INTEGER,
comment: "月份",
},
xh: {
type: DataTypes.STRING,
comment: "序号",
},
ndtzhsmb: {
type: DataTypes.DECIMAL(20, 2),
comment: "年度投资回收目标"
},
dyhs: {
type: DataTypes.DECIMAL(20, 2),
comment: "当月回收"
},
dyljhs: {
type: DataTypes.DECIMAL(20, 2),
comment: "当月累计回收"
},
ndjhwcl: {
type: DataTypes.DECIMAL(5, 2),
comment: "年度计划完成率 %"
},
bz: {
type: DataTypes.TEXT,
comment: "备注",
},
groupBy: {
type: DataTypes.INTEGER,
comment: "分组"
},
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_jsqtzhs', // 指定表名(如果与模型名不同)
timestamps: true, // 是否自动添加 createdAt 和 updatedAt 字段(覆盖全局设置)
});
// 同步模型到数据库(创建表)
TzJsqtzhszb.sync({
// force: false,
// force: true ,//会删除已存在表并重新创建
alter: true
})
.then(() => {
console.log('TzJsqtzhszb 表同步成功');
});
module.exports = TzJsqtzhszb;
\ No newline at end of file
...@@ -67,7 +67,11 @@ router.post('/updateZdfx', projectTzController.updateZdfx); ...@@ -67,7 +67,11 @@ router.post('/updateZdfx', projectTzController.updateZdfx);
router.post('/getZdfxList', projectTzController.getZdfxList); router.post('/getZdfxList', projectTzController.getZdfxList);
router.post('/getZdfxInfo', projectTzController.getZdfxInfo); router.post('/getZdfxInfo', projectTzController.getZdfxInfo);
//建设期投资回收
router.post('/createJsqtzhs', projectTzController.createJsqtzhs);
router.post('/updateJsqtzhs', projectTzController.updateJsqtzhs);
router.post('/getJsqtzhsList', projectTzController.getJsqtzhsList);
router.post('/getJsqtzhsInfo', projectTzController.getJsqtzhsInfo);
module.exports = router; module.exports = router;
\ No newline at end of file
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