明树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
813abdf1
Commit
813abdf1
authored
Nov 29, 2025
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
879382cf
Pipeline
#103859
passed with stage
in 4 seconds
Changes
6
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
183 additions
and
72 deletions
+183
-72
resourceController.js
controller/resourceController.js
+81
-59
templateController.js
controller/templateController.js
+95
-12
request.js
middleware/request.js
+1
-0
package.json
package.json
+2
-1
resourceRouter.js
router/resourceRouter.js
+3
-0
tempRouter.js
router/tempRouter.js
+1
-0
No files found.
controller/resourceController.js
View file @
813abdf1
const
{
buildTree
}
=
require
(
"../utils"
);
const
errorMessage
=
require
(
"../utils/errorMessage"
);
const
{
Op
,
where
}
=
require
(
'sequelize'
);
const
{
Op
}
=
require
(
'sequelize'
);
/**
...
...
@@ -9,30 +9,30 @@ const { Op, where } = require('sequelize');
async
function
createResource
(
req
,
res
,
next
)
{
try
{
const
body
=
req
.
body
;
// await DB.Resources.bulkCreate(
// [
// { "key": "k1a92f", "name": "公交车" },
// { "key": "u3b81x", "name": "地铁" },
// { "key": "p9c44m", "name": "高铁" },
// { "key": "n7d22t", "name": "出租车" },
// { "key": "q4e93z", "name": "轻轨" },
// { "key": "t6f81k", "name": "磁悬浮列车" },
// { "key": "r8g55w", "name": "轮渡" },
// { "key": "s2h19p", "name": "共享单车" },
// { "key": "w9j73v", "name": "电动车" },
// { "key": "a5k33q", "name": "自驾车" },
// { "key": "y1l87u", "name": "长途客车" },
// { "key": "d3m41b", "name": "飞机" },
// { "key": "f8n22h", "name": "直升机" },
// { "key": "c4p66r", "name": "城际铁路" },
// { "key": "m2q99s", "name": "轨道交通" },
// { "key": "j7r55d", "name": "大巴车" },
// { "key": "z3s13e", "name": "顺风车" },
// { "key": "e9t80y", "name": "三轮车" },
// { "key": "h5u28i", "name": "地面有轨电车" },
// { "key": "b6v71o", "name": "高速公路客运" }
// ]
// )
// await DB.Resources.bulkCreate(
// [
// { "key": "k1a92f", "name": "公交车" },
// { "key": "u3b81x", "name": "地铁" },
// { "key": "p9c44m", "name": "高铁" },
// { "key": "n7d22t", "name": "出租车" },
// { "key": "q4e93z", "name": "轻轨" },
// { "key": "t6f81k", "name": "磁悬浮列车" },
// { "key": "r8g55w", "name": "轮渡" },
// { "key": "s2h19p", "name": "共享单车" },
// { "key": "w9j73v", "name": "电动车" },
// { "key": "a5k33q", "name": "自驾车" },
// { "key": "y1l87u", "name": "长途客车" },
// { "key": "d3m41b", "name": "飞机" },
// { "key": "f8n22h", "name": "直升机" },
// { "key": "c4p66r", "name": "城际铁路" },
// { "key": "m2q99s", "name": "轨道交通" },
// { "key": "j7r55d", "name": "大巴车" },
// { "key": "z3s13e", "name": "顺风车" },
// { "key": "e9t80y", "name": "三轮车" },
// { "key": "h5u28i", "name": "地面有轨电车" },
// { "key": "b6v71o", "name": "高速公路客运" }
// ]
// )
const
ret
=
await
DB
.
Resources
.
create
(
body
);
return
res
.
sendData
(
ret
);
}
catch
(
error
)
{
...
...
@@ -270,6 +270,27 @@ async function saveAllResourceInfo(req, res, next) {
}
}
async
function
listResourceAll
(
req
,
res
,
next
)
{
try
{
let
datas
=
await
DB
.
Resources
.
findAll
(
{
where
:
{
del
:
0
},
include
:
[
{
model
:
DB
.
ResourcesInfo
,
as
:
'resourcesInfos'
,
attributes
:
[
'key'
,
'value'
]
}
]
}
)
return
res
.
sendData
(
datas
)
}
catch
(
error
)
{
next
(
error
);
}
}
module
.
exports
=
{
createResource
,
updateResource
,
...
...
@@ -282,5 +303,6 @@ module.exports = {
deleteResourceInfo
,
listResourceInfo
,
saveAllResourceInfo
saveAllResourceInfo
,
listResourceAll
,
}
\ No newline at end of file
controller/templateController.js
View file @
813abdf1
...
...
@@ -4,12 +4,13 @@
* 2. 上传文件导入数据 解析数据并存入数据库
* 3.
*/
const
ExcelJS
=
require
(
'exceljs'
);
const
path
=
require
(
'path'
);
const
errorMessage
=
require
(
"../utils/errorMessage"
);
async
function
getExcelTemplate
(
req
,
res
,
next
)
{
try
{
let
{
tampName
,
projectId
,
startYear
,
endYear
}
=
req
.
bod
y
;
let
{
tampName
,
projectId
,
startYear
,
endYear
}
=
req
.
quer
y
;
const
workbook
=
new
ExcelJS
.
Workbook
();
if
(
tampName
===
'xmtzzjll'
)
{
// 项目投资资金流量表
if
(
!
startYear
||
!
endYear
)
{
...
...
@@ -17,21 +18,21 @@ async function getExcelTemplate(req, res, next) {
return
res
.
sendError
(
errorMessage
.
paramsError
);
}
// 1. 读取空模板文件
const
inputFilePath
=
path
.
join
(
__dirname
,
'../public/template
s
/项目投资资金流量表.xlsx'
);
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
=
endYear
-
startYear
;
let
count
=
Number
(
endYear
)
-
Number
(
startYear
)
;
let
columns
=
[];
for
(
let
index
=
0
;
index
<=
count
;
index
++
)
{
columns
.
push
({
name
:
Number
(
startYear
+
index
)
});
columns
.
push
({
name
:
Number
(
Number
(
startYear
)
+
index
)
});
}
// 2.2 处理数据
let
rows
=
Array
(
5
).
fill
(
[]
);
// 5 是模板有5行
if
(
!
projectId
)
{
let
tzzjlls
=
await
ProjectTzzjll
.
findAll
({
let
rows
=
Array
(
5
).
fill
(
Array
(
columns
.
length
).
fill
(
0
)
);
// 5 是模板有5行
if
(
projectId
)
{
let
tzzjlls
=
await
DB
.
ProjectTzzjll
.
findAll
({
where
:
{
projectId
:
projectId
,
del
:
0
},
raw
:
true
,
});
...
...
@@ -84,7 +85,7 @@ async function getExcelTemplate(req, res, next) {
const
buffer
=
await
workbook
.
xlsx
.
writeBuffer
();
// 发送文件并结束响应
res
.
end
(
buffer
);
}
else
if
(
tampName
===
'tjjh'
)
{
// 投决计划模板{
}
else
if
(
tampName
===
'tjjh'
)
{
// 投决计划模板{
if
(
!
startYear
||
!
endYear
)
{
errorMessage
.
paramsError
.
message
=
"当前模板开始年份和结束年份不能为空"
;
return
res
.
sendError
(
errorMessage
.
paramsError
);
...
...
@@ -182,8 +183,90 @@ function thvc(a) {
return
[
xjlr
,
xjlc
,
sdsqjxjll
,
tzsds
,
sdshjxjll
];
}
async
function
importExcelTempData
(
req
,
res
,
next
)
{
try
{
let
{
tampName
,
projectId
}
=
req
.
body
;
if
(
tampName
==
'xmtzzjll'
)
{
// if (!projectId) {
// errorMessage.paramsError.message = "项目ID不能为空";
// return res.sendError(errorMessage.paramsError);
// }
const
workbook
=
new
ExcelJS
.
Workbook
();
workbook
.
calcProperties
.
fullCalcOnLoad
=
true
;
await
workbook
.
xlsx
.
load
(
req
.
file
.
buffer
,
{
ignoreNodes
:[
'relationships'
,
'styles'
,
'calcChain'
,
'drawings'
,
'core'
]
});
const
worksheet
=
await
workbook
.
getWorksheet
(
1
);
let
headers
=
[],
data
=
[];
worksheet
.
eachRow
((
row
,
rowIndex
)
=>
{
let
colText
=
[];
row
.
eachCell
((
col
,
colIndex
)
=>
{
console
.
log
(
col
.
result
,
col
.
value
,
"--"
,
col
.
text
,
"-"
,
col
.
toString
());
if
(
rowIndex
==
3
&&
colIndex
>
3
)
{
console
.
log
(
col
);
headers
.
push
(
col
.
text
);
}
if
(
rowIndex
>
3
)
{
colText
.
push
(
col
.
value
);
}
});
if
(
rowIndex
>
3
)
{
data
.
push
(
colText
);
}
});
return
res
.
sendData
({
headers
,
data
});
}
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
)
{
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
);
}
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
importExcelTempData2
(
req
,
res
,
next
)
{
try
{
let
{
tampName
,
projectId
}
=
req
.
body
;
if
(
tampName
==
'xmtzzjll'
)
{
...
...
@@ -227,7 +310,7 @@ async function importExcelTempData(req, res, next) {
where
:
{
projectId
:
projectId
},
});
await
ProjectTzzjll
.
bulkCreate
(
retData
);
}
else
if
(
tampName
===
'tjjh'
)
{
}
else
if
(
tampName
===
'tjjh'
)
{
if
(
!
projectId
)
{
errorMessage
.
paramsError
.
message
=
"项目ID不能为空"
;
return
res
.
sendError
(
errorMessage
.
paramsError
);
...
...
middleware/request.js
View file @
813abdf1
...
...
@@ -62,6 +62,7 @@ function checkPath(path) {
const
allowedPatterns
=
[
/^
\/
user
\/
login$/
,
/^
\/
user
\/
regist$/
,
/^
\/
template
\/
getExcelTemplate$/
,
/^
\/
file
\/
download
\/\d
+$/
,
/^
\/
file
\/
show
\/\d
+$/
,
];
...
...
package.json
View file @
813abdf1
...
...
@@ -32,7 +32,8 @@
"
multer
"
:
"
1.4.5-lts.1
"
,
"
mysql2
"
:
"
^3.15.3
"
,
"
node-cron
"
:
"
3.0.3
"
,
"
sequelize
"
:
"
^6.37.7
"
"
sequelize
"
:
"
^6.37.7
"
,
"
xlsx
"
:
"
^0.18.5
"
},
"devDependencies"
:
{
"
cross-env
"
:
"
^7.0.3
"
,
...
...
router/resourceRouter.js
View file @
813abdf1
...
...
@@ -22,5 +22,8 @@ router.post('/listResourceInfo', resourceController.listResourceInfo);
router
.
post
(
'/saveAllResourceInfo'
,
resourceController
.
saveAllResourceInfo
);
router
.
post
(
'/listResourceAll'
,
resourceController
.
listResourceAll
);
module
.
exports
=
router
;
\ No newline at end of file
router/tempRouter.js
View file @
813abdf1
...
...
@@ -13,6 +13,7 @@ const templateController = require('../controller/templateController');
* 获取项目相关excel 模板下载
*/
router
.
post
(
'/getExcelTemplate'
,
templateController
.
getExcelTemplate
);
router
.
get
(
'/getExcelTemplate'
,
templateController
.
getExcelTemplate
);
...
...
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