明树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
Hide 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,83 +8,87 @@ const ExcelJS = require('exceljs');
...
@@ -8,83 +8,87 @@ 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
{
let
{
tampName
,
projectId
,
startYear
,
endYear
}
=
req
.
query
;
const
workbook
=
new
ExcelJS
.
Workbook
();
if
(
tampName
===
'xmtzzjll'
)
{
// 项目投资资金流量表
if
(
!
startYear
||
!
endYear
)
{
errorMessage
.
paramsError
.
message
=
"当前模板开始年份和结束年份不能为空"
;
return
res
.
sendError
(
errorMessage
.
paramsError
);
}
// 1. 读取空模板文件
const
inputFilePath
=
path
.
join
(
__dirname
,
'../public/template/项目投资资金流量表.xlsx'
);
// 2. 处理excel 文件,动态生成表格
await
workbook
.
xlsx
.
readFile
(
inputFilePath
);
const
worksheet
=
await
workbook
.
getWorksheet
(
1
);
// 2.1 处理表头
let
count
=
Number
(
endYear
)
-
Number
(
startYear
);
let
columns
=
[];
for
(
let
index
=
0
;
index
<=
count
;
index
++
)
{
columns
.
push
({
name
:
Number
(
Number
(
startYear
)
+
index
)
});
}
// 2.2 处理数据
async
function
getXmtzzjllTem
({
startYear
,
endYear
,
tampName
,
projectId
})
{
let
rows
=
Array
(
5
).
fill
(
Array
(
columns
.
length
).
fill
(
0
));
// 5 是模板有5行
const
workbook
=
new
ExcelJS
.
Workbook
();
if
(
projectId
)
{
// 1. 读取空模板文件
let
tzzjlls
=
await
DB
.
ProjectTzzjll
.
findAll
({
const
inputFilePath
=
path
.
join
(
__dirname
,
'../public/template/项目投资资金流量表.xlsx'
);
where
:
{
projectId
:
projectId
,
del
:
0
},
// 2. 处理excel 文件,动态生成表格
raw
:
true
,
await
workbook
.
xlsx
.
readFile
(
inputFilePath
);
});
const
worksheet
=
await
workbook
.
getWorksheet
(
1
);
tzzjlls
=
_
.
sortBy
(
tzzjlls
,
'year'
);
// 2.1 处理表头
rows
=
thvc
(
tzzjlls
);
let
count
=
Number
(
endYear
)
-
Number
(
startYear
);
}
let
columns
=
[];
console
.
log
(
rows
,
"============="
)
for
(
let
index
=
0
;
index
<=
count
;
index
++
)
{
columns
.
push
({
name
:
Number
(
Number
(
startYear
)
+
index
)
});
}
// 使用addTable创建表格
// 2.2 处理数据
worksheet
.
addTable
({
let
rows
=
Array
(
5
).
fill
(
Array
(
columns
.
length
).
fill
(
0
));
// 5 是模板有5行
name
:
'FinancialData'
,
if
(
projectId
)
{
ref
:
'D3'
,
let
tzzjlls
=
await
DB
.
ProjectTzzjll
.
findAll
({
headerRow
:
true
,
where
:
{
projectId
:
projectId
,
del
:
0
},
totalsRow
:
false
,
raw
:
true
,
style
:
{
});
theme
:
null
,
tzzjlls
=
_
.
sortBy
(
tzzjlls
,
'year'
);
showRowStripes
:
false
,
rows
=
thvc
(
tzzjlls
);
showColumnStripes
:
false
,
}
},
console
.
log
(
rows
,
"============="
)
columns
:
columns
,
rows
:
rows
});
worksheet
.
mergeCells
(
2
,
3
,
2
,
(
3
+
columns
.
length
))
// 使用addTable创建表格
worksheet
.
mergeCells
(
1
,
1
,
1
,
(
3
+
columns
.
length
))
worksheet
.
addTable
({
const
BLACK_BORDER
=
{
name
:
'FinancialData'
,
top
:
{
style
:
'thin'
,
color
:
{
argb
:
'FF000000'
}
},
ref
:
'D3'
,
left
:
{
style
:
'thin'
,
color
:
{
argb
:
'FF000000'
}
},
headerRow
:
true
,
bottom
:
{
style
:
'thin'
,
color
:
{
argb
:
'FF000000'
}
},
totalsRow
:
false
,
right
:
{
style
:
'thin'
,
color
:
{
argb
:
'FF000000'
}
}
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
)
=>
{
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
;
//边框
});
});
const
buffer
=
await
workbook
.
xlsx
.
writeBuffer
();
return
buffer
;
}
// 遍历所有单元格添加边框
async
function
getExcelTemplate
(
req
,
res
,
next
)
{
worksheet
.
eachRow
((
row
,
rowNumber
)
=>
{
try
{
row
.
eachCell
((
cell
,
colNumber
)
=>
{
let
{
tampName
,
projectId
,
startYear
,
endYear
}
=
req
.
query
;
if
(
rowNumber
>=
4
&&
rowNumber
<=
8
&&
colNumber
>=
4
&&
colNumber
<=
(
3
+
columns
.
length
))
{
startYear
=
startYear
||
new
Date
().
getFullYear
();
cell
.
numFmt
=
'#,##0.00'
;
//数字格式
endYear
=
endYear
||
Number
(
startYear
+
33
);
}
let
keyName
=
{
cell
.
alignment
=
{
xmtzzjll
:
"项目投资资金流量表"
horizontal
:
'center'
,
}
vertical
:
'middle'
,
//垂直居中
const
workbook
=
new
ExcelJS
.
Workbook
();
wrapText
:
true
let
buffer
;
};
if
(
tampName
===
'xmtzzjll'
)
{
// 项目投资资金流量表
cell
.
border
=
BLACK_BORDER
;
//边框
buffer
=
await
getXmtzzjllTem
({
startYear
,
endYear
,
tampName
,
projectId
});
});
});
// 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'
)
{
// 投决计划模板{
}
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