明树Git Lab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
J
jt_backend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zengfanpei
jt_backend
Commits
b1f9ac9d
Commit
b1f9ac9d
authored
Nov 25, 2025
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
549e15fa
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
229 additions
and
18 deletions
+229
-18
a.js
a.js
+109
-0
fileController.js
controller/fileController.js
+46
-2
projectController.js
controller/projectController.js
+9
-0
index.js
db/index.js
+1
-11
projectTzzjll.js
db/model/jt/projectTzzjll.js
+42
-0
request.js
middleware/request.js
+19
-5
fileRouter.js
router/fileRouter.js
+1
-0
projectRouter.js
router/projectRouter.js
+2
-0
No files found.
a.js
0 → 100644
View file @
b1f9ac9d
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
controller/fileController.js
View file @
b1f9ac9d
const
ExcelJS
=
require
(
'exceljs'
);
const
ExcelJS
=
require
(
'exceljs'
);
const
_
=
require
(
'lodash'
);
const
_
=
require
(
'lodash'
);
const
errorMessage
=
require
(
'../utils/errorMessage'
);
const
Path
=
require
(
'path'
);
const
fs
=
require
(
'fs'
);
async
function
upload
(
req
,
res
,
next
)
{
async
function
upload
(
req
,
res
,
next
)
{
try
{
try
{
...
@@ -42,6 +44,47 @@ async function batchUpload(req, res, next) {
...
@@ -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) {
...
@@ -53,5 +96,6 @@ async function batchUpload(req, res, next) {
module
.
exports
=
{
module
.
exports
=
{
upload
,
upload
,
batchUpload
batchUpload
,
downloadFileById
,
}
}
\ No newline at end of file
controller/projectController.js
View file @
b1f9ac9d
...
@@ -379,6 +379,14 @@ async function exportExcel(req, res, next) {
...
@@ -379,6 +379,14 @@ async function exportExcel(req, res, next) {
}
}
}
}
async
function
getExcelTemplate
(
req
,
res
,
next
)
{
try
{
//
}
catch
(
error
)
{
next
(
error
);
}
}
module
.
exports
=
{
module
.
exports
=
{
getProjectFields
,
getProjectFields
,
createProject
,
createProject
,
...
@@ -387,4 +395,5 @@ module.exports = {
...
@@ -387,4 +395,5 @@ module.exports = {
deleteProject
,
deleteProject
,
updateProject
,
updateProject
,
exportExcel
,
exportExcel
,
getExcelTemplate
,
}
}
\ No newline at end of file
db/index.js
View file @
b1f9ac9d
...
@@ -16,12 +16,10 @@ const Project = require("./model/jt/project");
...
@@ -16,12 +16,10 @@ const Project = require("./model/jt/project");
const
Resources
=
require
(
"./model/jt/resources"
);
const
Resources
=
require
(
"./model/jt/resources"
);
const
ResourcesInfo
=
require
(
"./model/jt/resourcesInfo"
);
const
ResourcesInfo
=
require
(
"./model/jt/resourcesInfo"
);
const
ProjectBjtj
=
require
(
"./model/jt/projectBjtj"
);
const
ProjectBjtj
=
require
(
"./model/jt/projectBjtj"
);
const
ProjectCwpjzb
=
require
(
"./model/jt/projectCwpjzb"
);
const
ProjectFile
=
require
(
"./model/jt/projectFile"
);
const
ProjectFile
=
require
(
"./model/jt/projectFile"
);
const
ProjectGdxx
=
require
(
"./model/jt/projectGdxx"
);
const
ProjectGdxx
=
require
(
"./model/jt/projectGdxx"
);
const
ProjectJsgm
=
require
(
"./model/jt/projectJsgm"
);
const
ProjectJsgm
=
require
(
"./model/jt/projectJsgm"
);
const
ProjectSpyj
=
require
(
"./model/jt/projectSpyj"
);
const
ProjectSpyj
=
require
(
"./model/jt/projectSpyj"
);
const
ProjectXmtzze
=
require
(
"./model/jt/projectXmtzze"
);
/**
/**
...
@@ -45,12 +43,10 @@ global.DB = {
...
@@ -45,12 +43,10 @@ global.DB = {
Resources
,
Resources
,
ResourcesInfo
,
ResourcesInfo
,
ProjectBjtj
,
ProjectBjtj
,
ProjectCwpjzb
,
ProjectFile
,
ProjectFile
,
ProjectGdxx
,
ProjectGdxx
,
ProjectJsgm
,
ProjectJsgm
,
ProjectSpyj
,
ProjectSpyj
,
ProjectXmtzze
,
}
}
...
@@ -127,9 +123,6 @@ ResourcesInfo.belongsTo(Resources, { foreignKey: 'resourceId' });
...
@@ -127,9 +123,6 @@ ResourcesInfo.belongsTo(Resources, { foreignKey: 'resourceId' });
/**项目-核心边界条件 1:n */
/**项目-核心边界条件 1:n */
Project
.
hasMany
(
ProjectBjtj
,
{
foreignKey
:
'projectId'
,
as
:
'projectBjtjs'
});
Project
.
hasMany
(
ProjectBjtj
,
{
foreignKey
:
'projectId'
,
as
:
'projectBjtjs'
});
ProjectBjtj
.
belongsTo
(
Project
,
{
foreignKey
:
'projectId'
});
ProjectBjtj
.
belongsTo
(
Project
,
{
foreignKey
:
'projectId'
});
/**项目-财务评价指标 1:n */
// Project.hasMany(ProjectCwpjzb, { foreignKey: 'projectId', as: 'projectCwpjzbs' });
// ProjectCwpjzb.belongsTo(Project, { foreignKey: 'projectId' });
/**项目-项目附件 1:n */
/**项目-项目附件 1:n */
Project
.
belongsToMany
(
File
,
{
through
:
'jt_project_file'
,
foreignKey
:
'projectId'
,
as
:
'files'
,
otherKey
:
'fileId'
});
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'
});
File
.
belongsToMany
(
Project
,
{
through
:
'jt_project_file'
,
foreignKey
:
'fileId'
,
otherKey
:
'projectId'
,
as
:
'pros'
});
...
@@ -141,7 +134,4 @@ Project.hasMany(ProjectJsgm, { foreignKey: 'projectId', as: 'projectJsgms' });
...
@@ -141,7 +134,4 @@ Project.hasMany(ProjectJsgm, { foreignKey: 'projectId', as: 'projectJsgms' });
ProjectJsgm
.
belongsTo
(
Project
,
{
foreignKey
:
'projectId'
});
ProjectJsgm
.
belongsTo
(
Project
,
{
foreignKey
:
'projectId'
});
/**项目-审批意见 1:n */
/**项目-审批意见 1:n */
Project
.
hasMany
(
ProjectSpyj
,
{
foreignKey
:
'projectId'
,
as
:
'projectSpyjs'
});
Project
.
hasMany
(
ProjectSpyj
,
{
foreignKey
:
'projectId'
,
as
:
'projectSpyjs'
});
ProjectSpyj
.
belongsTo
(
Project
,
{
foreignKey
:
'projectId'
});
ProjectSpyj
.
belongsTo
(
Project
,
{
foreignKey
:
'projectId'
});
/**项目-项目投资总额 1:n */
\ No newline at end of file
Project
.
hasMany
(
ProjectXmtzze
,
{
foreignKey
:
'projectId'
,
as
:
'projectXmtzzes'
});
ProjectXmtzze
.
belongsTo
(
Project
,
{
foreignKey
:
'projectId'
});
\ No newline at end of file
db/model/jt/projectTzzjll.js
0 → 100644
View file @
b1f9ac9d
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
middleware/request.js
View file @
b1f9ac9d
...
@@ -46,10 +46,24 @@ module.exports = async (req, res, next) => {
...
@@ -46,10 +46,24 @@ module.exports = async (req, res, next) => {
next
();
next
();
}
}
// function checkPath(path) {
// console.log(path, "===============")
// if (['/user/login', '/user/regist',].includes(path)) {
// return true;
// } else {
// return false;
// }
// }
function
checkPath
(
path
)
{
function
checkPath
(
path
)
{
if
([
'/user/login'
,
'/user/regist'
,].
includes
(
path
))
{
console
.
log
(
path
,
"==============="
);
return
true
;
}
else
{
// 允许的路径模式数组
return
false
;
const
allowedPatterns
=
[
}
/^
\/
user
\/
login$/
,
/^
\/
user
\/
regist$/
,
/^
\/
file
\/
download
\/\d
+$/
,
];
return
allowedPatterns
.
some
(
pattern
=>
pattern
.
test
(
path
));
}
}
\ No newline at end of file
router/fileRouter.js
View file @
b1f9ac9d
...
@@ -35,5 +35,6 @@ router.post('/upload', upload.single('file'), fileController.upload);
...
@@ -35,5 +35,6 @@ router.post('/upload', upload.single('file'), fileController.upload);
router
.
post
(
'/batch/upload'
,
upload
.
array
(
'files'
),
fileController
.
batchUpload
);
router
.
post
(
'/batch/upload'
,
upload
.
array
(
'files'
),
fileController
.
batchUpload
);
router
.
get
(
'/download/:fileId'
,
fileController
.
downloadFileById
);
module
.
exports
=
router
;
module
.
exports
=
router
;
\ No newline at end of file
router/projectRouter.js
View file @
b1f9ac9d
...
@@ -17,4 +17,6 @@ router.post('/getProjectFields', projectController.getProjectFields);
...
@@ -17,4 +17,6 @@ router.post('/getProjectFields', projectController.getProjectFields);
router
.
post
(
'/exportExcel'
,
projectController
.
exportExcel
);
router
.
post
(
'/exportExcel'
,
projectController
.
exportExcel
);
router
.
post
(
'/getExcelTemplate'
,
projectController
.
getExcelTemplate
);
module
.
exports
=
router
;
module
.
exports
=
router
;
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment