明树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
33924f9f
Commit
33924f9f
authored
Dec 05, 2025
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
b6fa09d9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
74 deletions
+84
-74
projectController.js
controller/projectController.js
+1
-0
templateController.js
controller/templateController.js
+83
-74
No files found.
controller/projectController.js
View file @
33924f9f
...
@@ -837,6 +837,7 @@ async function listProject(req, res, next) {
...
@@ -837,6 +837,7 @@ async function listProject(req, res, next) {
if
(
req
.
body
.
menuType
)
{
if
(
req
.
body
.
menuType
)
{
where
.
projectLzType
=
{[
Op
.
in
]:
projectLzTypes
}
where
.
projectLzType
=
{[
Op
.
in
]:
projectLzTypes
}
}
}
search
.
where
=
where
;
search
.
limit
=
limit
;
search
.
limit
=
limit
;
search
.
offset
=
offset
;
search
.
offset
=
offset
;
if
(
req
.
body
.
attributes
&&
req
.
body
.
attributes
.
length
)
{
if
(
req
.
body
.
attributes
&&
req
.
body
.
attributes
.
length
)
{
...
...
controller/templateController.js
View file @
33924f9f
...
@@ -8,15 +8,9 @@ const ExcelJS = require('exceljs');
...
@@ -8,15 +8,9 @@ const ExcelJS = require('exceljs');
const
path
=
require
(
'path'
);
const
path
=
require
(
'path'
);
const
errorMessage
=
require
(
"../utils/errorMessage"
);
const
errorMessage
=
require
(
"../utils/errorMessage"
);
async
function
getExcelTemplate
(
req
,
res
,
next
)
{
try
{
async
function
getXmtzzjllTem
({
startYear
,
endYear
,
tampName
,
projectId
})
{
let
{
tampName
,
projectId
,
startYear
,
endYear
}
=
req
.
query
;
const
workbook
=
new
ExcelJS
.
Workbook
();
const
workbook
=
new
ExcelJS
.
Workbook
();
if
(
tampName
===
'xmtzzjll'
)
{
// 项目投资资金流量表
if
(
!
startYear
||
!
endYear
)
{
errorMessage
.
paramsError
.
message
=
"当前模板开始年份和结束年份不能为空"
;
return
res
.
sendError
(
errorMessage
.
paramsError
);
}
// 1. 读取空模板文件
// 1. 读取空模板文件
const
inputFilePath
=
path
.
join
(
__dirname
,
'../public/template/项目投资资金流量表.xlsx'
);
const
inputFilePath
=
path
.
join
(
__dirname
,
'../public/template/项目投资资金流量表.xlsx'
);
// 2. 处理excel 文件,动态生成表格
// 2. 处理excel 文件,动态生成表格
...
@@ -79,12 +73,22 @@ async function getExcelTemplate(req, res, next) {
...
@@ -79,12 +73,22 @@ async function getExcelTemplate(req, res, next) {
cell
.
border
=
BLACK_BORDER
;
//边框
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
();
const
buffer
=
await
workbook
.
xlsx
.
writeBuffer
();
// 发送文件并结束响应
return
buffer
;
res
.
end
(
buffer
);
}
async
function
getExcelTemplate
(
req
,
res
,
next
)
{
try
{
let
{
tampName
,
projectId
,
startYear
,
endYear
}
=
req
.
query
;
startYear
=
startYear
||
new
Date
().
getFullYear
();
endYear
=
endYear
||
Number
(
startYear
+
33
);
let
keyName
=
{
xmtzzjll
:
"项目投资资金流量表"
}
const
workbook
=
new
ExcelJS
.
Workbook
();
let
buffer
;
if
(
tampName
===
'xmtzzjll'
)
{
// 项目投资资金流量表
buffer
=
await
getXmtzzjllTem
({
startYear
,
endYear
,
tampName
,
projectId
});
}
else
if
(
tampName
===
'tjjh'
)
{
// 投决计划模板{
}
else
if
(
tampName
===
'tjjh'
)
{
// 投决计划模板{
if
(
!
startYear
||
!
endYear
)
{
if
(
!
startYear
||
!
endYear
)
{
errorMessage
.
paramsError
.
message
=
"当前模板开始年份和结束年份不能为空"
;
errorMessage
.
paramsError
.
message
=
"当前模板开始年份和结束年份不能为空"
;
...
@@ -163,6 +167,11 @@ async function getExcelTemplate(req, res, next) {
...
@@ -163,6 +167,11 @@ async function getExcelTemplate(req, res, next) {
else
{
else
{
res
.
status
(
400
).
json
({
message
:
'未知的模板名称'
});
res
.
status
(
400
).
json
({
message
:
'未知的模板名称'
});
}
}
// 3. 将处理后的文件发送给前端
res
.
setHeader
(
'Content-Type'
,
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
);
res
.
setHeader
(
'Content-Disposition'
,
'attachment; filename='
+
encodeURIComponent
(
`
${
keyName
[
tampName
]}
.xlsx`
));
// 发送文件并结束响应
res
.
end
(
buffer
);
}
catch
(
error
)
{
}
catch
(
error
)
{
next
(
error
);
next
(
error
);
}
}
...
@@ -194,7 +203,7 @@ async function importExcelTempData(req, res, next) {
...
@@ -194,7 +203,7 @@ async function importExcelTempData(req, res, next) {
const
workbook
=
new
ExcelJS
.
Workbook
();
const
workbook
=
new
ExcelJS
.
Workbook
();
workbook
.
calcProperties
.
fullCalcOnLoad
=
true
;
workbook
.
calcProperties
.
fullCalcOnLoad
=
true
;
await
workbook
.
xlsx
.
load
(
req
.
file
.
buffer
,
{
await
workbook
.
xlsx
.
load
(
req
.
file
.
buffer
,
{
ignoreNodes
:[
'relationships'
,
'styles'
,
'calcChain'
,
'drawings'
,
'core'
]
ignoreNodes
:
[
'relationships'
,
'styles'
,
'calcChain'
,
'drawings'
,
'core'
]
});
});
const
worksheet
=
await
workbook
.
getWorksheet
(
1
);
const
worksheet
=
await
workbook
.
getWorksheet
(
1
);
...
@@ -202,7 +211,7 @@ async function importExcelTempData(req, res, next) {
...
@@ -202,7 +211,7 @@ async function importExcelTempData(req, res, next) {
worksheet
.
eachRow
((
row
,
rowIndex
)
=>
{
worksheet
.
eachRow
((
row
,
rowIndex
)
=>
{
let
colText
=
[];
let
colText
=
[];
row
.
eachCell
((
col
,
colIndex
)
=>
{
row
.
eachCell
((
col
,
colIndex
)
=>
{
console
.
log
(
col
.
result
,
col
.
value
,
"--"
,
col
.
text
,
"-"
,
col
.
toString
());
console
.
log
(
col
.
result
,
col
.
value
,
"--"
,
col
.
text
,
"-"
,
col
.
toString
());
if
(
rowIndex
==
3
&&
colIndex
>
3
)
{
if
(
rowIndex
==
3
&&
colIndex
>
3
)
{
console
.
log
(
col
);
console
.
log
(
col
);
headers
.
push
(
col
.
text
);
headers
.
push
(
col
.
text
);
...
...
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