明树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
d46bc0ae
Commit
d46bc0ae
authored
Sep 09, 2024
by
zengfanpei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:排序
parent
343da57f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
27 deletions
+32
-27
statisticsController.js
controller/statisticsController.js
+31
-26
collectWS.js
db/models/collectWS.js
+1
-1
No files found.
controller/statisticsController.js
View file @
d46bc0ae
...
@@ -35,7 +35,9 @@ async function getSMCChangeTrend(req, res, next) {
...
@@ -35,7 +35,9 @@ async function getSMCChangeTrend(req, res, next) {
potassium
:
{
$avg
:
"$potassium"
},
potassium
:
{
$avg
:
"$potassium"
},
soilPH
:
{
$avg
:
"$soilPH"
},
soilPH
:
{
$avg
:
"$soilPH"
},
}
}
}
},
{
$sort
:
{
_id
:
1
}
}
];
];
let
ret
=
await
DB
.
CollectSMC
.
aggregate
(
aggr
);
let
ret
=
await
DB
.
CollectSMC
.
aggregate
(
aggr
);
res
.
sendData
(
ret
);
res
.
sendData
(
ret
);
...
@@ -70,7 +72,8 @@ async function getWSChangeTrend(req, res, next) {
...
@@ -70,7 +72,8 @@ async function getWSChangeTrend(req, res, next) {
windDirection
:
{
$avg
:
"$windDirection"
},
windDirection
:
{
$avg
:
"$windDirection"
},
rainfall
:
{
$avg
:
"$rainfall"
},
rainfall
:
{
$avg
:
"$rainfall"
},
}
}
}
},
{
$sort
:
{
_id
:
1
}
}
];
];
let
ret
=
await
DB
.
CollectWS
.
aggregate
(
aggr
);
let
ret
=
await
DB
.
CollectWS
.
aggregate
(
aggr
);
res
.
sendData
(
ret
);
res
.
sendData
(
ret
);
...
@@ -174,41 +177,43 @@ async function getDeviceCount(req, res, next) {
...
@@ -174,41 +177,43 @@ async function getDeviceCount(req, res, next) {
async
function
getAreaDistribution
(
req
,
res
,
next
)
{
async
function
getAreaDistribution
(
req
,
res
,
next
)
{
try
{
try
{
// 跟前端约定 传递对应区域名称
// 跟前端约定 传递对应区域名称
let
zonePre
=
await
DB
.
Zone
.
findOne
({
name
:
req
.
body
.
name
,
del
:
0
});
let
zonePre
=
await
DB
.
Zone
.
findOne
({
name
:
req
.
body
.
name
,
del
:
0
});
if
(
!
zonePre
)
{
if
(
!
zonePre
)
{
res
.
sendError
(
errorMessage
.
resourceNotFound
);
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
}
//往下取一层
//往下取一层
let
len
=
zonePre
.
parentIds
&&
zonePre
.
parentIds
.
length
||
0
;
let
len
=
zonePre
.
parentIds
&&
zonePre
.
parentIds
.
length
||
0
;
let
zones
=
await
DB
.
Zone
.
find
({
"parentIds"
:
{
$size
:
len
+
1
,
$elemMatch
:
{
$eq
:
zonePre
.
_id
}}
}).
lean
().
exec
();
//查找所有子区域
let
zones
=
await
DB
.
Zone
.
find
({
"parentIds"
:
{
$size
:
len
+
1
,
$elemMatch
:
{
$eq
:
zonePre
.
_id
}
}
}).
lean
().
exec
();
//查找所有子区域
let
zoneIds
=
zones
.
map
(
o
=>
{
return
o
.
_id
});
let
zoneIds
=
zones
.
map
(
o
=>
{
return
o
.
_id
});
zoneIds
.
push
(
zonePre
.
_id
);
zoneIds
.
push
(
zonePre
.
_id
);
let
lands
=
await
DB
.
Land
.
aggregate
([
let
lands
=
await
DB
.
Land
.
aggregate
([
{
$match
:
{
zone
:
{
$in
:
zoneIds
}}},
{
$match
:
{
zone
:
{
$in
:
zoneIds
}
}
},
{
$group
:
{
{
_id
:
"$varieties"
,
$group
:
{
area
:
{
$sum
:
"$area"
},
_id
:
"$varieties"
,
latestYield
:
{
$sum
:
"$latestYield"
},
area
:
{
$sum
:
"$area"
},
latestYieldValue
:
{
$sum
:
"$latestYieldValue"
},
latestYield
:
{
$sum
:
"$latestYield"
},
}}
latestYieldValue
:
{
$sum
:
"$latestYieldValue"
},
}
}
]);
]);
let
totalArea
=
_
.
sumBy
(
lands
,
'area'
);
let
totalArea
=
_
.
sumBy
(
lands
,
'area'
);
let
totalYield
=
_
.
sumBy
(
lands
,
'latestYield'
);
let
totalYield
=
_
.
sumBy
(
lands
,
'latestYield'
);
let
totalYieldValue
=
_
.
sumBy
(
lands
,
'latestYieldValue'
);
let
totalYieldValue
=
_
.
sumBy
(
lands
,
'latestYieldValue'
);
let
data
=
[];
let
data
=
[];
for
(
let
index
=
0
;
index
<
lands
.
length
;
index
++
)
{
for
(
let
index
=
0
;
index
<
lands
.
length
;
index
++
)
{
const
element
=
lands
[
index
];
const
element
=
lands
[
index
];
if
(
totalArea
!=
0
)
{
if
(
totalArea
!=
0
)
{
element
.
areaPercentage
=
_
.
multiply
(
_
.
divide
(
element
.
area
,
totalArea
),
100
).
toFixed
(
0
)
+
'%'
;
element
.
areaPercentage
=
_
.
multiply
(
_
.
divide
(
element
.
area
,
totalArea
),
100
).
toFixed
(
0
)
+
'%'
;
}
else
{
}
else
{
element
.
areaPercentage
=
"0%"
element
.
areaPercentage
=
"0%"
}
}
if
(
totalYield
!=
0
)
{
if
(
totalYield
!=
0
)
{
element
.
yieldPercentage
=
_
.
multiply
(
_
.
divide
(
element
.
latestYield
,
totalYield
),
100
).
toFixed
(
0
)
+
'%'
;
element
.
yieldPercentage
=
_
.
multiply
(
_
.
divide
(
element
.
latestYield
,
totalYield
),
100
).
toFixed
(
0
)
+
'%'
;
}
else
{
}
else
{
element
.
yieldPercentage
=
"0%"
element
.
yieldPercentage
=
"0%"
}
}
if
(
totalYieldValue
!=
0
)
{
if
(
totalYieldValue
!=
0
)
{
element
.
yieldValuePercentage
=
_
.
multiply
(
_
.
divide
(
element
.
latestYieldValue
,
totalYieldValue
),
100
).
toFixed
(
0
)
+
'%'
;
element
.
yieldValuePercentage
=
_
.
multiply
(
_
.
divide
(
element
.
latestYieldValue
,
totalYieldValue
),
100
).
toFixed
(
0
)
+
'%'
;
}
else
{
}
else
{
element
.
yieldValuePercentage
=
"0%"
element
.
yieldValuePercentage
=
"0%"
...
@@ -232,17 +237,17 @@ async function getAreaDistribution2(req, res, next) {
...
@@ -232,17 +237,17 @@ async function getAreaDistribution2(req, res, next) {
year
:
moment
().
format
(
"YYYY"
)
year
:
moment
().
format
(
"YYYY"
)
}
}
// 跟前端约定 传递对应区域名称
// 跟前端约定 传递对应区域名称
if
(
req
.
body
.
name
==
"雷州半岛"
)
{
if
(
req
.
body
.
name
==
"雷州半岛"
)
{
search
.
county
=
"雷州市"
;
search
.
county
=
"雷州市"
;
}
else
}
else
if
(
req
.
body
.
name
==
"乐田农业"
)
{
if
(
req
.
body
.
name
==
"乐田农业"
)
{
search
.
$or
=
[
search
.
$or
=
[
{
county
:
{
$regex
:
"乐田"
}
},
{
county
:
{
$regex
:
"乐田"
}
},
{
zone
:
{
$regex
:
"乐田"
}
}
{
zone
:
{
$regex
:
"乐田"
}
}
];
];
}
else
{
}
else
{
search
.
plantArea
=
req
.
body
.
name
;
search
.
plantArea
=
req
.
body
.
name
;
}
}
let
areaReds
=
await
DB
.
AreaRecord
.
find
(
search
);
let
areaReds
=
await
DB
.
AreaRecord
.
find
(
search
);
res
.
sendData
(
areaReds
);
res
.
sendData
(
areaReds
);
}
catch
(
error
)
{
}
catch
(
error
)
{
...
...
db/models/collectWS.js
View file @
d46bc0ae
...
@@ -45,7 +45,7 @@ const collectWeatherStationSchema = new Schema({
...
@@ -45,7 +45,7 @@ const collectWeatherStationSchema = new Schema({
},
},
windDirection
:
{
windDirection
:
{
type
:
Number
,
type
:
String
,
comment
:
"风向"
,
comment
:
"风向"
,
},
},
windDirectionUnit
:
{
windDirectionUnit
:
{
...
...
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