明树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
0e8c4ccc
Commit
0e8c4ccc
authored
Nov 29, 2025
by
zfp1
Browse files
Options
Browse Files
Download
Plain Diff
update
parents
2d2692f7
e1eb1f3a
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
170 additions
and
4 deletions
+170
-4
a.js
a.js
+11
-1
local.json
config/local.json
+3
-3
templateController.js
controller/templateController.js
+114
-0
projectTjjh.js
db/model/jt/projectTjjh.js
+42
-0
投决计划.xlsx
public/template/投决计划.xlsx
+0
-0
项目投资资金流量表.xlsx
public/template/项目投资资金流量表.xlsx
+0
-0
No files found.
a.js
View file @
0e8c4ccc
...
...
@@ -108,3 +108,13 @@ const transformed = {
// console.log(reverseTransform(transformed));
// console.log(thvc(a));
// {
// xh: String,
// sjx: String,
// }
// {
// year: []
// }
\ No newline at end of file
config/local.json
View file @
0e8c4ccc
{
"tokenEx"
:
86400
,
"
dbURI"
:
"mongodb://root:letian2024.@119.29.111.186:27017/letian?authSource=admin
"
,
"tokenEx"
:
86400
000000
,
"
userDefaultPassword"
:
"GZB123JT.
"
,
"file"
:
{
"storagePath"
:
"/
mnt/vdb1/
uploadfiles"
"storagePath"
:
"/uploadfiles"
},
"cron"
:
{
},
...
...
controller/templateController.js
View file @
0e8c4ccc
...
...
@@ -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
)
{
...
...
db/model/jt/projectTjjh.js
0 → 100644
View file @
0e8c4ccc
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
public/template/投决计划.xlsx
View file @
0e8c4ccc
No preview for this file type
public/template/项目投资资金流量表.xlsx
View file @
0e8c4ccc
No preview for this file type
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