明树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
e3d6bb73
Commit
e3d6bb73
authored
Mar 18, 2025
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
ac87d65c
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
354 additions
and
57 deletions
+354
-57
statisticsController.js
controller/statisticsController.js
+88
-55
suppFactController.js
controller/suppFactController.js
+174
-0
index.js
db/index.js
+5
-0
letianSuppFact.js
db/models/letianSuppFact.js
+64
-0
fileRouter.js
router/fileRouter.js
+2
-0
index.js
router/index.js
+5
-2
nutrRouter.js
router/nutrRouter.js
+16
-0
No files found.
controller/statisticsController.js
View file @
e3d6bb73
...
...
@@ -25,13 +25,13 @@ async function getSMCChangeTrend(req, res, next) {
startTime
.
setHours
(
0
);
startTime
.
setMinutes
(
0
);
startTime
.
setSeconds
(
0
);
search
.
time
=
{
$gt
:
startTime
,
$lte
:
endTime
}
search
.
time
=
{
$gt
:
startTime
,
$lte
:
endTime
}
}
if
(
req
.
body
.
land
)
{
let
devs
=
await
DB
.
Device
.
find
({
land
:
req
.
body
.
land
}).
lean
().
exec
();
if
(
devs
&&
devs
.
length
)
{
let
devNums
=
devs
.
map
(
o
=>
{
return
o
.
deviceNumber
});
search
.
deviceNumber
=
{
$in
:
devNums
}
if
(
req
.
body
.
land
)
{
let
devs
=
await
DB
.
Device
.
find
({
land
:
req
.
body
.
land
}).
lean
().
exec
();
if
(
devs
&&
devs
.
length
)
{
let
devNums
=
devs
.
map
(
o
=>
{
return
o
.
deviceNumber
});
search
.
deviceNumber
=
{
$in
:
devNums
}
}
}
console
.
log
(
JSON
.
stringify
(
search
))
...
...
@@ -54,13 +54,15 @@ async function getSMCChangeTrend(req, res, next) {
// soilPH: { $avg: "$soilPH" },
}
},
{
$project
:
{
soilTemperature
:
{
$round
:
[
"$soilTemperature"
,
2
]},
soilMoisture
:
{
$round
:
[
"$soilMoisture"
,
2
]},
nitrogen
:
{
$round
:
[
"$nitrogen"
,
2
]},
phosphorus
:
{
$round
:
[
"$phosphorus"
,
2
]},
potassium
:
{
$round
:
[
"$potassium"
,
2
]},
}},
{
$project
:
{
soilTemperature
:
{
$round
:
[
"$soilTemperature"
,
2
]
},
soilMoisture
:
{
$round
:
[
"$soilMoisture"
,
2
]
},
nitrogen
:
{
$round
:
[
"$nitrogen"
,
2
]
},
phosphorus
:
{
$round
:
[
"$phosphorus"
,
2
]
},
potassium
:
{
$round
:
[
"$potassium"
,
2
]
},
}
},
{
$sort
:
{
_id
:
1
}
}
];
...
...
@@ -86,10 +88,12 @@ async function getSMCChangeTrend(req, res, next) {
soilConductivity
:
{
$avg
:
"$soilConductivity"
},
}
},
{
$project
:
{
soilPH
:
{
$round
:
[
"$soilPH"
,
2
]},
soilConductivity
:
{
$round
:
[
"$soilConductivity"
,
2
]},
}},
{
$project
:
{
soilPH
:
{
$round
:
[
"$soilPH"
,
2
]
},
soilConductivity
:
{
$round
:
[
"$soilConductivity"
,
2
]
},
}
},
{
$sort
:
{
_id
:
1
}
}
];
...
...
@@ -105,7 +109,7 @@ async function getSMCChangeTrend(req, res, next) {
let
returnData
=
[];
for
(
let
index
=
0
;
index
<
ret
.
length
;
index
++
)
{
let
element
=
ret
[
index
];
if
(
phMap
[
element
.
_id
])
{
if
(
phMap
[
element
.
_id
])
{
element
=
{
...
element
,
...
phMap
[
element
.
_id
]
...
...
@@ -139,7 +143,7 @@ async function getWSChangeTrend(req, res, next) {
startTime
.
setHours
(
0
);
startTime
.
setMinutes
(
0
);
startTime
.
setSeconds
(
0
);
search
.
time
=
{
$gt
:
startTime
,
$lte
:
endTime
}
search
.
time
=
{
$gt
:
startTime
,
$lte
:
endTime
}
}
let
aggr
=
[
{
...
...
@@ -155,11 +159,13 @@ async function getWSChangeTrend(req, res, next) {
rainfall
:
{
$avg
:
"$rainfall"
},
}
},
{
$project
:
{
wsTemperature
:
{
$round
:
[
"$wsTemperature"
,
2
]},
wsMoisture
:
{
$round
:
[
"$wsMoisture"
,
2
]},
rainfall
:
{
$round
:
[
"$rainfall"
,
2
]},
}},
{
$project
:
{
wsTemperature
:
{
$round
:
[
"$wsTemperature"
,
2
]
},
wsMoisture
:
{
$round
:
[
"$wsMoisture"
,
2
]
},
rainfall
:
{
$round
:
[
"$rainfall"
,
2
]
},
}
},
{
$sort
:
{
_id
:
1
}
}
];
let
ret
=
await
DB
.
CollectWS
.
aggregate
(
aggr
);
...
...
@@ -189,7 +195,7 @@ async function getIPSChangeTrend(req, res, next) {
startTime
.
setHours
(
0
);
startTime
.
setMinutes
(
0
);
startTime
.
setSeconds
(
0
);
search
.
time
=
{
$gt
:
startTime
,
$lte
:
endTime
}
search
.
time
=
{
$gt
:
startTime
,
$lte
:
endTime
}
}
let
aggr
=
[
{
...
...
@@ -293,11 +299,13 @@ async function getAreaDistribution(req, res, next) {
latestYieldValue
:
{
$sum
:
"$latestYieldValue"
},
}
},
{
$project
:
{
area
:
{
$round
:
[
"$area"
,
2
]},
latestYield
:
{
$round
:
[
"$latestYield"
,
2
]},
latestYieldValue
:
{
$round
:
[
"$latestYieldValue"
,
2
]},
}},
{
$project
:
{
area
:
{
$round
:
[
"$area"
,
2
]
},
latestYield
:
{
$round
:
[
"$latestYield"
,
2
]
},
latestYieldValue
:
{
$round
:
[
"$latestYieldValue"
,
2
]
},
}
},
]);
let
totalArea
=
_
.
sumBy
(
lands
,
'area'
);
let
totalYield
=
_
.
sumBy
(
lands
,
'latestYield'
);
...
...
@@ -385,7 +393,7 @@ async function getEnvironmentalTrend(req, res, next) {
startTime
.
setHours
(
0
);
startTime
.
setMinutes
(
0
);
startTime
.
setSeconds
(
0
);
search
.
time
=
{
$gt
:
startTime
,
$lte
:
endTime
}
search
.
time
=
{
$gt
:
startTime
,
$lte
:
endTime
}
}
let
aggr
=
[
{
...
...
@@ -401,11 +409,13 @@ async function getEnvironmentalTrend(req, res, next) {
chemicalPollutant
:
{
$avg
:
"$chemicalPollutant"
},
}
},
{
$project
:
{
miCcrobialCount
:
{
$round
:
[
"$miCcrobialCount"
,
2
]},
particleConcentration
:
{
$round
:
[
"$particleConcentration"
,
2
]},
chemicalPollutant
:
{
$round
:
[
"$chemicalPollutant"
,
2
]},
}},
{
$project
:
{
miCcrobialCount
:
{
$round
:
[
"$miCcrobialCount"
,
2
]
},
particleConcentration
:
{
$round
:
[
"$particleConcentration"
,
2
]
},
chemicalPollutant
:
{
$round
:
[
"$chemicalPollutant"
,
2
]
},
}
},
{
$sort
:
{
_id
:
1
}
}
];
let
ret
=
await
DB
.
CollectIET
.
aggregate
(
aggr
);
...
...
@@ -419,7 +429,7 @@ async function getEnvironmentalTrend(req, res, next) {
async
function
getQualityInfoTrend
(
req
,
res
,
next
)
{
try
{
let
search
=
{
time
:
{
$exists
:
true
}
};
if
((
req
.
body
.
startTime
&&
req
.
body
.
endTime
))
{
let
endTime
=
new
Date
(
req
.
body
.
endTime
);
...
...
@@ -430,30 +440,53 @@ async function getQualityInfoTrend(req, res, next) {
startTime
.
setHours
(
0
);
startTime
.
setMinutes
(
0
);
startTime
.
setSeconds
(
0
);
search
.
time
=
{
$gt
:
startTime
,
$lte
:
endTime
}
search
.
time
=
{
$gt
:
startTime
,
$lte
:
endTime
}
}
let
aggr
=
[
{
$match
:
search
},
{
$match
:
{
...
search
$group
:
{
_id
:
{
$dateToString
:
{
format
:
"%Y-%m-%d"
,
date
:
"$time"
}
},
total
:
{
$sum
:
1
},
// 每天总量
weightPassCount
:
{
$sum
:
{
$cond
:
[{
$eq
:
[
"$proWeightStatus"
,
"合格"
]
},
1
,
0
]
}
},
metalPassCount
:
{
$sum
:
{
$cond
:
[{
$eq
:
[
"$proHaveMetal"
,
false
]
},
1
,
0
]
}
}
}
},
{
$group
:
{
_id
:
{
$dateToString
:
{
format
:
"%Y-%m-%d"
,
date
:
"$time"
,
timezone
:
"+08:00"
}
},
// 将时间戳转换为日期字符串
water
:
{
$avg
:
"$water"
},
heavyMetal
:
{
$avg
:
"$heavyMetal"
},
impurity
:
{
$avg
:
"$impurity"
},
$project
:
{
time
:
"$_id"
,
total
:
1
,
weightPassRate
:
{
$round
:
[
{
$divide
:
[
"$weightPassCount"
,
"$total"
]
},
2
]
},
metalPassRate
:
{
$round
:
[
{
$divide
:
[
"$metalPassCount"
,
"$total"
]
},
2
]
},
_id
:
0
}
},
{
$project
:
{
water
:
{
$round
:
[
"$water"
,
2
]},
heavyMetal
:
{
$round
:
[
"$heavyMetal"
,
2
]},
impurity
:
{
$round
:
[
"$impurity"
,
2
]},
}},
{
$sort
:
{
_id
:
1
}
}
{
$sort
:
{
date
:
1
}
}
// 按日期排序
];
let
ret
=
await
DB
.
CollectIQI
.
aggregate
(
aggr
);
let
ret
=
await
DB
.
HeavyMetal
.
aggregate
(
aggr
);
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
...
...
controller/suppFactController.js
0 → 100644
View file @
e3d6bb73
const
ExcelJS
=
require
(
'exceljs'
);
const
_
=
require
(
'lodash'
);
const
fs
=
require
(
'fs'
);
async
function
list
(
req
,
res
,
next
)
{
try
{
let
search
=
{
del
:
0
};
let
page
=
req
.
body
.
page
||
1
;
let
pageSize
=
req
.
body
.
pageSize
||
10
;
let
skip
=
(
page
-
1
)
*
pageSize
;
if
(
req
.
body
.
name
)
{
search
.
name
=
req
.
body
.
name
;
}
let
count
=
await
DB
.
SuppFact
.
countDocuments
(
search
)
let
list
=
await
DB
.
SuppFact
.
find
(
search
).
skip
(
skip
).
limit
(
pageSize
).
sort
({
_id
:
-
1
}).
lean
().
exec
();
res
.
sendData
({
count
,
list
});
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
lunbo
(
req
,
res
,
next
)
{
try
{
let
search
=
{
del
:
0
,
name
:
{
$exists
:
true
}
};
let
ret
=
await
DB
.
SuppFact
.
aggregate
([
{
$match
:
search
},
{
$group
:
{
_id
:
"$name"
,
}
}
]);
ret
=
ret
.
map
(
o
=>
{
return
o
.
_id
})
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
create
(
req
,
res
,
next
)
{
try
{
let
ret
=
await
DB
.
SuppFact
.
create
(
req
.
body
)
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
updateOne
(
req
,
res
,
next
)
{
try
{
let
updateInfo
=
{
...
req
.
body
,
}
let
ret
=
await
DB
.
SuppFact
.
findOneAndUpdate
({
_id
:
req
.
body
.
_id
},
updateInfo
);
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
deleteOne
(
req
,
res
,
next
)
{
try
{
let
ret
=
await
DB
.
SuppFact
.
findOneAndUpdate
({
_id
:
req
.
body
.
_id
},
{
del
:
1
});
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
deleteMany
(
req
,
res
,
next
)
{
try
{
let
_ids
=
req
.
body
.
_ids
;
if
(
_
.
isArray
(
_ids
)
&&
_ids
.
length
>
0
)
{
let
ret
=
await
DB
.
SuppFact
.
updateMany
({
_id
:
{
$in
:
_ids
}
},
{
del
:
1
});
res
.
sendData
(
ret
);
}
else
{
res
.
sendData
();
}
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
importExcel
(
req
,
res
,
next
)
{
try
{
let
workbook
=
new
ExcelJS
.
Workbook
();
await
workbook
.
xlsx
.
readFile
(
req
.
file
.
path
);
let
worksheet
=
workbook
.
getWorksheet
(
1
);
let
arr
=
[];
for
(
let
index
=
2
;
index
<=
worksheet
.
actualRowCount
;
index
++
)
{
let
values
=
worksheet
.
getRow
(
index
).
values
;
let
obj
=
{
creator
:
req
.
user
.
_id
,
name
:
values
[
1
],
testItem
:
values
[
2
],
result
:
values
[
3
],
unit
:
values
[
4
],
nutrientReferenceValue
:
values
[
5
],
}
if
(
typeof
obj
.
indate
==
'number'
)
{
obj
.
indate
=
new
Date
(
1900
,
0
,
obj
.
indate
-
1
,
0
,
0
,
0
);
}
arr
.
push
(
obj
)
}
if
(
arr
.
length
)
{
await
DB
.
SuppFact
.
insertMany
(
arr
);
}
res
.
sendData
(
arr
);
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
exportExcel
(
req
,
res
,
next
)
{
try
{
let
search
=
{
del
:
0
};
if
(
req
.
body
.
name
)
{
search
.
name
=
{
$regex
:
req
.
body
.
name
};
}
if
(
req
.
body
.
startTime
)
{
search
.
indate
=
search
.
indate
||
{};
search
.
indate
.
$gte
=
req
.
body
.
startTime
;
}
if
(
req
.
body
.
endTime
)
{
search
.
indate
=
search
.
indate
||
{};
search
.
indate
.
$lte
=
req
.
body
.
endTime
}
let
ret
=
await
DB
.
ExcelRecord
.
create
({
creator
:
req
.
user
.
_id
,
type
:
2
,
modleName
:
'SuppFact'
,
search
,
})
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
}
module
.
exports
=
{
list
,
create
,
importExcel
,
deleteOne
,
updateOne
,
exportExcel
,
deleteMany
,
lunbo
,
}
\ No newline at end of file
db/index.js
View file @
e3d6bb73
...
...
@@ -83,6 +83,9 @@ const RawMatReqList = require("./models/letianRawMatReqList");
const
PackMatInList
=
require
(
"./models/letianPackMatInList"
);
const
PackMatOutList
=
require
(
"./models/letianPackMatOutList"
);
//营养成分表
const
SuppFact
=
require
(
"./models/letianSuppFact"
);
global
.
DB
=
{
File
,
...
...
@@ -136,6 +139,8 @@ global.DB = {
RawMatReqList
,
PackMatInList
,
PackMatOutList
,
SuppFact
,
}
...
...
db/models/letianSuppFact.js
0 → 100644
View file @
e3d6bb73
const
mongoose
=
require
(
'mongoose'
);
const
Schema
=
mongoose
.
Schema
;
const
moment
=
require
(
'moment'
);
// const autoIncrement = require('mongoose-auto-increment');
// autoIncrement.initialize(mongoose.connection);
/**
* //营养成分表
*/
const
letianSuppFactSchema
=
new
Schema
({
name
:
{
type
:
String
,
comment
:
"名称"
,
},
testItem
:
{
type
:
String
,
comment
:
"检测项目"
,
},
result
:
{
type
:
String
,
comment
:
"结果"
,
},
unit
:
{
type
:
String
,
comment
:
"单位"
,
},
nutrientReferenceValue
:
{
type
:
String
,
comment
:
"营养素参考值%"
,
},
creator
:
{
type
:
mongoose
.
Types
.
ObjectId
,
ref
:
'User'
,
comment1
:
"创建人"
},
createdAt
:
{
type
:
Date
,
default
:
Date
.
now
,
get
:
v
=>
moment
(
v
).
format
(
"YYYY-MM-DD HH:mm:ss"
),
},
updatedAt
:
{
type
:
Date
,
default
:
Date
.
now
,
get
:
v
=>
moment
(
v
).
format
(
"YYYY-MM-DD HH:mm:ss"
),
},
del
:
{
type
:
Number
,
default
:
0
,
comment1
:
'默认0 , 1:表示删除, 若有其他隐藏业务 不要混用此字段。'
}
},
{
toJSON
:
{
getters
:
true
}
});
const
SuppFact
=
mongoose
.
model
(
'SuppFact'
,
letianSuppFactSchema
,
'letianSuppFact'
);
module
.
exports
=
SuppFact
;
\ No newline at end of file
router/fileRouter.js
View file @
e3d6bb73
...
...
@@ -63,6 +63,7 @@ router.post('/:modelName/importExcel', upload.single('file'), async (req, res, n
'rawMatReq'
:
'rawMatReqlistController'
,
//原材料出库(领用)明细表
'packMatIn'
:
'packMatInListController'
,
//包装材料入库(采购)明细表
'packMatOut'
:
'packMatOutListController'
,
//包装材料出库(领用)明细表
'suppFact'
:
'suppFactController'
,
}
let
controller
=
require
(
`../controller/
${
modelMap
[
modelName
]}
`
);
await
controller
.
importExcel
(
req
,
res
,
next
);
...
...
@@ -85,6 +86,7 @@ router.post('/:modelName/exportExcel', async (req, res, next) => {
'rawMatReq'
:
'rawMatReqlistController'
,
//原材料出库(领用)明细表
'packMatIn'
:
'packMatInListController'
,
//包装材料入库(采购)明细表
'packMatOut'
:
'packMatOutListController'
,
//包装材料出库(领用)明细表
'suppFact'
:
'suppFactController'
,
}
console
.
log
(
modelMap
[
modelName
]);
let
controller
=
require
(
`../controller/
${
modelMap
[
modelName
]}
`
);
...
...
router/index.js
View file @
e3d6bb73
...
...
@@ -24,6 +24,7 @@ const inductryRouter = require('./inductryRouter');
const
heavyMetalRouter
=
require
(
'./externalRouter'
);
const
compInfoRouter
=
require
(
'./compInfoRouter'
);
const
rawmatRouter
=
require
(
'./rawmatRouter'
);
const
nutrRouter
=
require
(
'./nutrRouter'
);
router
.
use
(
'/user'
,
userRouter
);
// 用户 角色
...
...
@@ -53,9 +54,11 @@ router.use('/excelrecord', excelrecordRouter);
// 工业
router
.
use
(
'/ind'
,
inductryRouter
);
router
.
use
(
'/company'
,
compInfoRouter
);
router
.
use
(
'/company'
,
compInfoRouter
);
//公司信息
router
.
use
(
'/mat'
,
rawmatRouter
);
router
.
use
(
'/mat'
,
rawmatRouter
);
//原材料 包材
router
.
use
(
'/nutrients'
,
nutrRouter
);
...
...
router/nutrRouter.js
0 → 100644
View file @
e3d6bb73
const
express
=
require
(
'express'
);
const
router
=
express
.
Router
();
const
suppFactController
=
require
(
'../controller/suppFactController'
);
router
.
post
(
'/suppFact/create'
,
suppFactController
.
create
);
router
.
post
(
'/suppFact/update'
,
suppFactController
.
updateOne
);
router
.
post
(
'/suppFact/delete'
,
suppFactController
.
deleteOne
);
router
.
post
(
'/suppFact/batchDelete'
,
suppFactController
.
deleteMany
);
router
.
post
(
'/suppFact/list'
,
suppFactController
.
list
);
router
.
post
(
'/suppFact/lunbo'
,
suppFactController
.
lunbo
);
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