明树Git Lab

Commit e1eb1f3a authored by zfp1's avatar zfp1

update

parent 685b25be
......@@ -107,4 +107,14 @@ const transformed = {
// console.log(reverseTransform(transformed));
// console.log(thvc(a));
\ No newline at end of file
// console.log(thvc(a));
// {
// xh: String,
// sjx: String,
// }
// {
// year: []
// }
\ No newline at end of file
{
"tokenEx": 86400,
"dbURI": "mongodb://root:letian2024.@119.29.111.186:27017/letian?authSource=admin",
"tokenEx": 86400000000,
"userDefaultPassword": "GZB123JT.",
"file": {
"storagePath": "/mnt/vdb1/uploadfiles"
"storagePath": "/uploadfiles"
},
"cron": {
"excel": true
},
"mysql": {
"host": "10.40.8.8",
"port": 3306,
"username": "root",
"password": "gzbjt@2025",
"database": "gzbjt",
"logging": true
},
"redis": {
"host": "localhost",
"port": 6379,
"password": "gzbjt@2025",
"db": 0
}
}
\ No newline at end of file
......@@ -64,6 +64,79 @@ async function getExcelTemplate(req, res, next) {
right: { style: 'thin', color: { argb: 'FF000000' } }
};
// 遍历所有单元格添加边框
worksheet.eachRow((row, rowNumber) => {
row.eachCell((cell, colNumber) => {
if (rowNumber >= 4 && rowNumber <= 8 && colNumber >= 4 && colNumber <= (3 + columns.length)) {
cell.numFmt = '#,##0.00'; //数字格式
}
cell.alignment = {
horizontal: 'center',
vertical: 'middle', //垂直居中
wrapText: true
};
cell.border = BLACK_BORDER; //边框
});
});
// 3. 将处理后的文件发送给前端
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
res.setHeader('Content-Disposition', 'attachment; filename=' + encodeURIComponent('项目投资资金流量表.xlsx'));
const buffer = await workbook.xlsx.writeBuffer();
// 发送文件并结束响应
res.end(buffer);
} else if(tampName === 'tjjh'){ // 投决计划模板{
if (!startYear || !endYear) {
errorMessage.paramsError.message = "当前模板开始年份和结束年份不能为空";
return res.sendError(errorMessage.paramsError);
}
// 1. 读取空模板文件
const inputFilePath = path.join(__dirname, '../public/templates/投决计划.xlsx');
// 2. 处理excel 文件,动态生成表格
await workbook.xlsx.readFile(inputFilePath);
const worksheet = await workbook.getWorksheet(1);
// 2.1 处理表头
let count = endYear - startYear;
let columns = [];
for (let index = 0; index <= count; index++) {
columns.push({ name: Number(startYear + index) });
}
// 2.2 处理数据
let rows = Array(42).fill([]); // 5 是模板有5行
if (!projectId) {
let tzzjlls = await ProjectTzzjll.findAll({
where: { projectId: projectId, del: 0 },
raw: true,
});
tzzjlls = _.sortBy(tzzjlls, 'year');
rows = thvc(tzzjlls);
}
console.log(rows, "=============")
// 使用addTable创建表格
worksheet.addTable({
name: 'FinancialData',
ref: 'D3',
headerRow: true,
totalsRow: false,
style: {
theme: null,
showRowStripes: false,
showColumnStripes: false,
},
columns: columns,
rows: rows
});
worksheet.mergeCells(2, 3, 2, (3 + columns.length))
worksheet.mergeCells(1, 1, 1, (3 + columns.length))
const BLACK_BORDER = {
top: { style: 'thin', color: { argb: 'FF000000' } },
left: { style: 'thin', color: { argb: 'FF000000' } },
bottom: { style: 'thin', color: { argb: 'FF000000' } },
right: { style: 'thin', color: { argb: 'FF000000' } }
};
// 遍历所有单元格添加边框
worksheet.eachRow((row, rowNumber) => {
row.eachCell((cell, colNumber) => {
......@@ -122,6 +195,47 @@ async function importExcelTempData(req, res, next) {
await workbook.xlsx.load(req.file.buffer);
const worksheet = await workbook.getWorksheet(1);
let years = [], data = [];
worksheet.eachRow((row, rowIndex) => {
if (rowIndex === 3) {
years = row.values.slice(4);
}
if (rowIndex > 3) {
data.push(row.values.slice(4));
}
});
const fieldMap = {
1: 'xjlr', // 现金流入
2: 'xjlc', // 现金流出
3: 'sdsqjxjll', // 所得税前净现金流量
4: 'tzsds', // 调整所得税
5: 'sdshjxjll' // 所得税后净现金流量
};
let retData = [];
years.map((year, yearIndex) => {
const yearData = { year };
for (let rowIndex = 1; rowIndex <= data.length; rowIndex++) {
const fieldKey = fieldMap[rowIndex];
if (fieldKey) {
const value = data[rowIndex - 1][yearIndex];
yearData[fieldKey] = parseFloat(value) || 0;
}
}
retData.push(yearData);
});
await ProjectTzzjll.destroy({
where: { projectId: projectId },
});
await ProjectTzzjll.bulkCreate(retData);
} else if(tampName === 'tjjh') {
if (!projectId) {
errorMessage.paramsError.message = "项目ID不能为空";
return res.sendError(errorMessage.paramsError);
}
const workbook = new ExcelJS.Workbook();
await workbook.xlsx.load(req.file.buffer);
const worksheet = await workbook.getWorksheet(1);
let years = [], data = [];
worksheet.eachRow((row, rowIndex) => {
if (rowIndex === 3) {
......
const { DataTypes } = require('sequelize');
const sequelize = require('../index');
//投决计划---决策信息--财务评价--投决计划
const ProjectTjjh = sequelize.define('ProjectTjjh', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
xh: { type: DataTypes.STRING, allowNull: true, comment: "序号" },
sjx: { type: DataTypes.STRING, allowNull: true, comment: "数据项" },
hj: { type: DataTypes.DECIMAL(20, 4), allowNull: true, comment: "数据项" },
sz: { type: DataTypes.JSON, allowNull: true, comment: "数值" },
rawNum: {type: DataTypes.INTEGER}, //行数
projectId: {
type: DataTypes.INTEGER,
comment: "所属项目ID",
},
del: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: "0 正常 1 删除"
},
}, {
tableName: 'jt_project_tzzjll', // 指定表名(如果与模型名不同)
timestamps: true, // 是否自动添加 createdAt 和 updatedAt 字段(覆盖全局设置)
});
// 同步模型到数据库(创建表)
ProjectTjjh.sync({
force: false,
// force: true ,//会删除已存在表并重新创建
// alter: true
})
.then(() => {
console.log('ProjectTjjh 表同步成功');
});
module.exports = ProjectTjjh;
\ 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