明树Git Lab

Commit b1f9ac9d authored by zfp1's avatar zfp1

update

parent 549e15fa
const _ = require('lodash');
let a = [
{
xjlr: 100,
xjlc: 200,
sdsqjxjll: 300,
tzsds: 400,
sdshjxjll: 500,
year: "合计",
},
{
xjlr: 100,
xjlc: 200,
sdsqjxjll: 300,
tzsds: 400,
sdshjxjll: 500,
year: 2022,
},
{
xjlr: 101,
xjlc: 201,
sdsqjxjll: 301,
tzsds: 401,
sdshjxjll: 501,
year: 2023,
},
{
xjlr: 1003,
xjlc: 2003,
sdsqjxjll: 3003,
tzsds: 4003,
sdshjxjll: 5003,
year: "2024",
},
{
xjlr: 1004,
xjlc: 2004,
sdsqjxjll: 3004,
tzsds: 4004,
sdshjxjll: 5004,
year: "2025",
}
]
const b = _.sortBy(a, 'year');
console.log(b);
function thvc(a) {
let xjlr = [], xjlc = [], sdsqjxjll = [], tzsds = [], sdshjxjll =[];
let retArr = [];
for (let index = 0; index < a.length; index++) {
const element = a[index];
xjlr.push(element.xjlr);
xjlc.push(element.xjlc);
sdsqjxjll.push(element.sdsqjxjll);
tzsds.push(element.tzsds);
sdshjxjll.push(element.sdshjxjll);
year.push(element.year);
}
return {xjlr, xjlc, sdsqjxjll, tzsds, sdshjxjll};
}
function cvht(obj) {
for (const key in obj) {
const element = obj[key];
}
}
function reverseTransform(transformedData) {
// 获取第一个字段的数组长度作为对象数量
const field = Object.keys(transformedData)[0];
const itemCount = transformedData[field].length;
const result = [];
// 遍历每个索引位置构建对象
for (let i = 0; i < itemCount; i++) {
const item = {};
// 为每个字段赋值
for (const key in transformedData) {
if (transformedData.hasOwnProperty(key)) {
item[key] = transformedData[key][i];
}
}
result.push(item);
}
return result;
}
// 使用示例
const transformed = {
xjlr: [100, 100, 101, 1003, 1004],
xjlc: [200, 200, 201, 2003, 2004],
sdsqjxjll: [300, 300, 301, 3003, 3004],
tzsds: [400, 400, 401, 4003, 4004],
sdshjxjll: [500, 500, 501, 5003, 5004]
};
console.log(reverseTransform(transformed));
// console.log(thvc(a));
\ No newline at end of file
const ExcelJS = require('exceljs');
const _ = require('lodash');
const errorMessage = require('../utils/errorMessage');
const Path = require('path');
const fs = require('fs');
async function upload(req, res, next) {
try {
......@@ -42,6 +44,47 @@ async function batchUpload(req, res, next) {
}
}
/**
*
*/
async function downloadFileById(req, res, next) {
try {
let fileId = req.params.fileId;
let fileinfo = await DB.File.findOne({ where: {id: fileId}, raw: true });
if (!(fileinfo && fileinfo.id)) {
return res.sendError(errorMessage.resourceNotFound)
}
let {
originalname,
filename,
size,
mimetype,
url,
path,
nginxpath,
} = fileinfo;
//TODO:path处理
const filePath = Path.join(__dirname, '../../../', path);
if (!fs.existsSync(filePath)) {
return res.sendError(errorMessage.resourceNotFound)
}
// 3. 设置强制下载响应头
res.setHeader('Content-Type', 'application/octet-stream');
res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(originalname)}"`);
// 4. 创建文件流并传输
const fileStream = fs.createReadStream(filePath);
fileStream.pipe(res);
// 错误处理
fileStream.on('error', (err) => {
console.error(`File stream error: ${err}`);
if (!res.headersSent) res.status(500).send('File streaming error');
});
} catch (error) {
next(error);
}
}
......@@ -53,5 +96,6 @@ async function batchUpload(req, res, next) {
module.exports = {
upload,
batchUpload
batchUpload,
downloadFileById,
}
\ No newline at end of file
......@@ -379,6 +379,14 @@ async function exportExcel(req, res, next) {
}
}
async function getExcelTemplate(req, res, next) {
try {
//
} catch (error) {
next(error);
}
}
module.exports = {
getProjectFields,
createProject,
......@@ -387,4 +395,5 @@ module.exports = {
deleteProject,
updateProject,
exportExcel,
getExcelTemplate,
}
\ No newline at end of file
......@@ -16,12 +16,10 @@ const Project = require("./model/jt/project");
const Resources = require("./model/jt/resources");
const ResourcesInfo = require("./model/jt/resourcesInfo");
const ProjectBjtj = require("./model/jt/projectBjtj");
const ProjectCwpjzb = require("./model/jt/projectCwpjzb");
const ProjectFile = require("./model/jt/projectFile");
const ProjectGdxx = require("./model/jt/projectGdxx");
const ProjectJsgm = require("./model/jt/projectJsgm");
const ProjectSpyj = require("./model/jt/projectSpyj");
const ProjectXmtzze = require("./model/jt/projectXmtzze");
/**
......@@ -45,12 +43,10 @@ global.DB = {
Resources,
ResourcesInfo,
ProjectBjtj,
ProjectCwpjzb,
ProjectFile,
ProjectGdxx,
ProjectJsgm,
ProjectSpyj,
ProjectXmtzze,
}
......@@ -127,9 +123,6 @@ ResourcesInfo.belongsTo(Resources, { foreignKey: 'resourceId' });
/**项目-核心边界条件 1:n */
Project.hasMany(ProjectBjtj, { foreignKey: 'projectId', as: 'projectBjtjs' });
ProjectBjtj.belongsTo(Project, { foreignKey: 'projectId' });
/**项目-财务评价指标 1:n */
// Project.hasMany(ProjectCwpjzb, { foreignKey: 'projectId', as: 'projectCwpjzbs' });
// ProjectCwpjzb.belongsTo(Project, { foreignKey: 'projectId' });
/**项目-项目附件 1:n */
Project.belongsToMany(File, { through: 'jt_project_file', foreignKey: 'projectId', as: 'files', otherKey: 'fileId' });
File.belongsToMany(Project, { through: 'jt_project_file', foreignKey: 'fileId', otherKey: 'projectId', as: 'pros' });
......@@ -142,6 +135,3 @@ ProjectJsgm.belongsTo(Project, { foreignKey: 'projectId' });
/**项目-审批意见 1:n */
Project.hasMany(ProjectSpyj, { foreignKey: 'projectId', as: 'projectSpyjs' });
ProjectSpyj.belongsTo(Project, { foreignKey: 'projectId' });
\ No newline at end of file
/**项目-项目投资总额 1:n */
Project.hasMany(ProjectXmtzze, { foreignKey: 'projectId', as: 'projectXmtzzes' });
ProjectXmtzze.belongsTo(Project, { foreignKey: 'projectId' });
\ No newline at end of file
const { DataTypes } = require('sequelize');
const sequelize = require('../index');
//项目投资资金流量表-excel
const ProjectTzzjll = sequelize.define('ProjectTzzjll', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
xjlr: { type: DataTypes.DECIMAL(19, 8), allowNull: true, comment: "现金流入" },
xjlc: { type: DataTypes.DECIMAL(19, 8), allowNull: true, comment: "现金流出" },
sdsqjxjll: { type: DataTypes.DECIMAL(19, 8), allowNull: true, comment: "所得税前净现金流量" },
tzsds: { type: DataTypes.DECIMAL(19, 8), allowNull: true, comment: "调整所得税" },
sdshjxjll: { type: DataTypes.DECIMAL(19, 8), allowNull: true, comment: "所得税后净现金流量" },
year: { type: DataTypes.STRING, allowNull: true, comment: "所得税后净现金流量"},
projectId: {
type: DataTypes.INTEGER,
comment: "所属项目ID",
},
del: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: "0 正常 1 删除"
},
}, {
tableName: 'jt_project_tzzjll', // 指定表名(如果与模型名不同)
timestamps: true, // 是否自动添加 createdAt 和 updatedAt 字段(覆盖全局设置)
});
// 同步模型到数据库(创建表)
ProjectTzzjll.sync({
force: false,
// force: true ,//会删除已存在表并重新创建
// alter: true
})
.then(() => {
console.log('ProjectTzzjll 表同步成功');
});
module.exports = ProjectTzzjll;
\ No newline at end of file
......@@ -46,10 +46,24 @@ module.exports = async (req, res, next) => {
next();
}
// function checkPath(path) {
// console.log(path, "===============")
// if (['/user/login', '/user/regist',].includes(path)) {
// return true;
// } else {
// return false;
// }
// }
function checkPath(path) {
if (['/user/login', '/user/regist',].includes(path)) {
return true;
} else {
return false;
}
console.log(path, "===============");
// 允许的路径模式数组
const allowedPatterns = [
/^\/user\/login$/,
/^\/user\/regist$/,
/^\/file\/download\/\d+$/,
];
return allowedPatterns.some(pattern => pattern.test(path));
}
\ No newline at end of file
......@@ -35,5 +35,6 @@ router.post('/upload', upload.single('file'), fileController.upload);
router.post('/batch/upload', upload.array('files'), fileController.batchUpload);
router.get('/download/:fileId', fileController.downloadFileById);
module.exports = router;
\ No newline at end of file
......@@ -17,4 +17,6 @@ router.post('/getProjectFields', projectController.getProjectFields);
router.post('/exportExcel', projectController.exportExcel);
router.post('/getExcelTemplate', projectController.getExcelTemplate);
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