明树Git Lab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
L
letian_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
letian_backend
Commits
b542490c
Commit
b542490c
authored
Oct 17, 2024
by
zengfanpei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
c04ba571
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
10 deletions
+63
-10
local.json
config/local.json
+1
-1
agrInputRecordController.js
controller/agrInputRecordController.js
+39
-2
fileController.js
controller/fileController.js
+3
-3
letianAgrInputRecord.js
db/models/letianAgrInputRecord.js
+6
-0
systemFile.js
db/models/systemFile.js
+1
-1
agrRouter.js
router/agrRouter.js
+0
-1
fileRouter.js
router/fileRouter.js
+13
-2
No files found.
config/local.json
View file @
b542490c
...
...
@@ -36,6 +36,6 @@
"cron"
:
{
"getDeviceList"
:
false
,
"getAllDevice"
:
false
,
"collectDeviceInfo"
:
tru
e
"collectDeviceInfo"
:
fals
e
}
}
\ No newline at end of file
controller/agrInputRecordController.js
View file @
b542490c
...
...
@@ -2,6 +2,8 @@
const
ExcelJS
=
require
(
'exceljs'
);
const
_
=
require
(
'lodash'
);
...
...
@@ -14,7 +16,7 @@ async function list(req, res, next) {
let
skip
=
(
page
-
1
)
*
pageSize
;
let
count
=
await
DB
.
AgrInputRecord
.
countDocuments
(
search
)
let
list
=
await
DB
.
AgrInputRecord
.
find
(
search
).
skip
(
skip
).
limit
(
pageSize
).
lean
().
exec
();
res
.
sendData
({
count
,
list
});
res
.
sendData
({
count
,
list
});
}
catch
(
error
)
{
next
(
error
)
}
...
...
@@ -31,6 +33,40 @@ async function create(req, res, next) {
}
async
function
importExcel
(
req
,
res
,
next
)
{
try
{
let
workbook
=
new
ExcelJS
.
Workbook
();
console
.
log
(
req
.
file
)
await
workbook
.
xlsx
.
readFile
(
req
.
file
.
path
);
let
worksheet
=
workbook
.
getWorksheet
(
1
);
console
.
log
(
worksheet
.
actualRowCount
);
let
arr
=
[];
for
(
let
index
=
2
;
index
<
worksheet
.
actualRowCount
;
index
++
)
{
let
values
=
worksheet
.
getRow
(
index
).
values
;
let
obj
=
{
creator
:
req
.
user
.
_id
,
time
:
values
[
1
],
agrProName
:
values
[
2
],
name
:
values
[
3
],
type
:
values
[
4
],
total
:
values
[
5
],
unit
:
values
[
6
],
land
:
values
[
7
],
area
:
values
[
8
],
dosage
:
values
[
9
],
}
arr
.
push
(
obj
)
}
if
(
arr
.
length
)
{
await
DB
.
AgrInputRecord
.
insertMany
(
arr
);
}
res
.
sendData
(
arr
);
}
catch
(
error
)
{
next
(
error
)
}
}
...
...
@@ -45,5 +81,6 @@ async function create(req, res, next) {
module
.
exports
=
{
list
,
create
create
,
importExcel
}
\ No newline at end of file
controller/fileController.js
View file @
b542490c
...
...
@@ -6,13 +6,13 @@ const _ = require('lodash');
async
function
upload
(
req
,
res
,
next
)
{
try
{
// console.log(req.file, req.body);
let
path
=
_
.
last
(
String
(
req
.
file
.
path
).
split
(
'/mnt/vdb1'
));
let
nginx
path
=
_
.
last
(
String
(
req
.
file
.
path
).
split
(
'/mnt/vdb1'
));
let
ret
=
await
DB
.
File
.
create
({
originalname
:
req
.
file
.
originalname
,
mimetype
:
req
.
file
.
mimetype
,
filename
:
req
.
file
.
filename
,
path
,
originalpath
:
req
.
file
.
path
,
path
:
req
.
file
.
path
,
nginx
path
,
size
:
req
.
file
.
size
,
});
res
.
sendData
(
ret
);
...
...
db/models/letianAgrInputRecord.js
View file @
b542490c
...
...
@@ -48,6 +48,12 @@ const letianAgrInputRecordSchema = new Schema({
creator
:
{
type
:
mongoose
.
Types
.
ObjectId
,
ref
:
'User'
,
comment
:
"创建人"
},
createdAt
:
{
type
:
Date
,
default
:
Date
.
now
,
...
...
db/models/systemFile.js
View file @
b542490c
...
...
@@ -26,7 +26,7 @@ const fileSchema = new Schema({
path
:
{
type
:
String
,
},
original
path
:
{
nginx
path
:
{
type
:
String
,
},
...
...
router/agrRouter.js
View file @
b542490c
...
...
@@ -6,7 +6,6 @@ const agrInputRecordController = require('../controller/agrInputRecordController
const
agrMatController
=
require
(
'../controller/agrMatController'
);
router
.
post
(
'/input/list'
,
agrInputRecordController
.
list
);
// router.post('/create', agrInputRecordController.create);
// router.post('/update', fileController.update);
// router.post('/upload', fileController.list);
...
...
router/fileRouter.js
View file @
b542490c
...
...
@@ -5,6 +5,7 @@ const router = express.Router();
const
multer
=
require
(
'multer'
);
const
path
=
require
(
'path'
);
const
fs
=
require
(
'fs'
);
const
_
=
require
(
'lodash'
);
const
moment
=
require
(
'moment'
);
const
mongoose
=
require
(
'mongoose'
);
...
...
@@ -38,9 +39,19 @@ router.post('/batch/upload', upload.array('files'), fileController.batchUpload);
// 文件访问: 起nginx用以处理文件服务器。
/**
* excel导
出
* excel导
入
*/
router
.
post
(
'/:modelName/importExcel'
,
upload
.
single
(
'file'
),
fileController
.
importExcel
);
router
.
post
(
'/:modelName/importExcel'
,
upload
.
single
(
'file'
),
async
(
req
,
res
,
next
)
=>
{
let
modelName
=
req
.
params
.
modelName
;
let
controller
=
require
(
`../controller/
${
modelName
}
Controller`
);
console
.
log
(
modelName
,)
await
controller
.
importExcel
(
req
,
res
,
next
);
});
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