明树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
7c84ebf9
Commit
7c84ebf9
authored
Sep 09, 2024
by
zengfanpei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
0e4ba127
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
34 deletions
+62
-34
fileController.js
controller/fileController.js
+15
-19
statisticsController.js
controller/statisticsController.js
+2
-2
collectWS.js
db/models/collectWS.js
+26
-0
letianAgrInRecord.js
db/models/letianAgrInRecord.js
+19
-13
No files found.
controller/fileController.js
View file @
7c84ebf9
...
...
@@ -30,30 +30,26 @@ async function importExcel(req, res, next) {
try
{
console
.
log
(
DB
.
AreaRecord
.
schema
.
obj
);
let
workbook
=
new
ExcelJS
.
Workbook
();
console
.
log
(
req
.
file
)
await
workbook
.
xlsx
.
readFile
(
req
.
file
.
path
);
let
worksheet
=
workbook
.
getWorksheet
(
1
);
console
.
log
(
work
sheet
.
actualRowCount
);
let
worksheet
=
workbook
.
getWorksheet
(
4
);
console
.
log
(
work
book
.
_worksheets
.
length
);
let
values
=
worksheet
.
getRow
(
1
).
values
;
// 示例:读取第一行
// for (let index = 1; index < worksheet.actualRowCount; index++) {
// let values = worksheet.getRow(index + 1).values;
// await DB.AreaRecord.create({
// province: values[1],
// city: values[2],
// county: values[3],
// town: values[4],
// zone: values[5],
// plantArea: values[6],
// varieties: values[7],
// area: Number( values[8]),
// yield: Number(values[9]),
// yieldValue:Number(values[10]),
// year: values[11]
// })
// }
for
(
let
index
=
1
;
index
<
worksheet
.
actualRowCount
;
index
++
)
{
let
values
=
worksheet
.
getRow
(
index
+
1
).
values
;
await
DB
.
AgrInRecord
.
create
({
time
:
values
[
1
],
name
:
values
[
2
],
type
:
values
[
3
],
total
:
values
[
4
],
unit
:
values
[
5
],
})
}
//1. 先通过参数获取对应的表字段对应关系
//2. 找到对应的表 写入
res
.
send
(
DB
.
AreaRecord
.
schema
.
obj
);
res
.
send
(
values
);
// res.send(DB.AreaRecord.schema.obj);
}
catch
(
error
)
{
next
(
error
);
}
...
...
controller/statisticsController.js
View file @
7c84ebf9
...
...
@@ -76,8 +76,8 @@ async function getWSChangeTrend(req, res, next) {
{
$group
:
{
_id
:
{
$dateToString
:
{
format
:
"%Y-%m-%d"
,
date
:
"$time"
}
},
// 将时间戳转换为日期字符串
w
indSpeed
:
{
$avg
:
"$windSpeed
"
},
w
indDirection
:
{
$avg
:
"$windDirection
"
},
w
sTemperature
:
{
$avg
:
"$wsTemperature
"
},
w
sMoisture
:
{
$avg
:
"$wsMoisture
"
},
rainfall
:
{
$avg
:
"$rainfall"
},
}
},
...
...
db/models/collectWS.js
View file @
7c84ebf9
...
...
@@ -62,6 +62,32 @@ const collectWeatherStationSchema = new Schema({
comment
:
"雨量单位"
,
},
wsTemperature
:
{
type
:
Number
,
comment
:
"温度"
,
},
wsTemperatureUnit
:
{
type
:
String
,
comment
:
"温度单位"
,
},
wsMoisture
:
{
type
:
Number
,
comment
:
"湿度"
,
},
wsMoistureUnit
:
{
type
:
String
,
comment
:
"湿度单位"
,
},
wsIllumination
:
{
type
:
Number
,
comment
:
"光照"
,
},
wsIlluminationUnit
:
{
type
:
String
,
comment
:
"光照单位"
,
},
createdAt
:
{
type
:
Date
,
default
:
Date
.
now
,
...
...
db/models/letianAgrInRecord.js
View file @
7c84ebf9
...
...
@@ -3,28 +3,34 @@ const Schema = mongoose.Schema;
const
moment
=
require
(
'moment'
);
/**
* 乐田 农业投入品 出入库记录表
* 乐田 农业投入品 出入库记录表
时间 生产投入品名称 投入品类别 总投入品使用数量 单位
*/
const
letianAgrInRecordSchema
=
new
Schema
({
time
:
{
type
:
Date
,
get
:
v
=>
moment
(
v
).
format
(
"YYYY-MM-DD HH:mm:ss"
),
comment
:
"时间"
,
},
agrProName
:
{
type
:
String
,
commnet
:
"农产品名称"
,
},
name
:
{
type
:
String
,
required
:
true
,
commnet
:
"品名"
,
commnet
:
"生产投入品名称"
,
},
t
otal
:
{
type
:
Number
,
comm
ent
:
"库存总量"
t
ype
:
{
type
:
String
,
comm
net
:
"投入品类别"
,
},
inNum
:
{
total
:
{
type
:
Number
,
default
:
0
,
comment
:
"入库"
comment
:
"总投入品使用数量"
},
outNum
:
{
type
:
Number
,
default
:
0
,
comment
:
"出库"
unit
:
{
type
:
String
,
commnet
:
"单位"
,
},
...
...
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