明树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
0ebe4021
Commit
0ebe4021
authored
Oct 21, 2024
by
zengfanpei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
41325eb9
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
362 additions
and
154 deletions
+362
-154
local.json
config/local.json
+3
-1
production.json
config/production.json
+3
-1
collectIPSController.js
controller/collectIPSController.js
+7
-1
collectSMCController.js
controller/collectSMCController.js
+42
-2
collectWSController.js
controller/collectWSController.js
+40
-0
excelController.js
controller/excelController.js
+0
-27
fileController.js
controller/fileController.js
+1
-1
excelCron.js
cron/excelCron.js
+104
-0
index.js
cron/index.js
+14
-2
ipsCron.js
cron/ipsCron.js
+60
-60
smcCron.js
cron/smcCron.js
+1
-1
wsCron.js
cron/wsCron.js
+1
-0
index.js
db/index.js
+2
-0
collectIPS.js
db/models/collectIPS.js
+27
-23
collectSMC.js
db/models/collectSMC.js
+17
-15
collectWS.js
db/models/collectWS.js
+10
-8
letianExcelRecord.js
db/models/letianExcelRecord.js
+6
-5
systemFile.js
db/models/systemFile.js
+11
-2
systemNotice.js
db/models/systemNotice.js
+1
-0
collectIPSModule.js
module/collectIPSModule.js
+1
-3
fileRouter.js
router/fileRouter.js
+11
-2
No files found.
config/local.json
View file @
0ebe4021
...
@@ -36,6 +36,8 @@
...
@@ -36,6 +36,8 @@
"cron"
:
{
"cron"
:
{
"getDeviceList"
:
false
,
"getDeviceList"
:
false
,
"getAllDevice"
:
false
,
"getAllDevice"
:
false
,
"collectDeviceInfo"
:
false
"collectDeviceInfo"
:
false
,
"collectDeviceInfo4"
:
true
,
"excel"
:
true
}
}
}
}
\ No newline at end of file
config/production.json
View file @
0ebe4021
...
@@ -36,6 +36,8 @@
...
@@ -36,6 +36,8 @@
"cron"
:
{
"cron"
:
{
"getDeviceList"
:
false
,
"getDeviceList"
:
false
,
"getAllDevice"
:
false
,
"getAllDevice"
:
false
,
"collectDeviceInfo"
:
true
"collectDeviceInfo"
:
true
,
"excel"
:
true
}
}
}
}
\ No newline at end of file
controller/collectIPSController.js
View file @
0ebe4021
...
@@ -124,7 +124,13 @@ async function exportExcel(req, res, next) {
...
@@ -124,7 +124,13 @@ async function exportExcel(req, res, next) {
$gte
:
req
.
body
.
time
[
0
]
$gte
:
req
.
body
.
time
[
0
]
}
}
}
}
let
ret
=
await
DB
.
ExcelRecord
.
create
({
creator
:
req
.
user
.
_id
,
type
:
2
,
modleName
:
'CollectIPS'
,
search
,
})
res
.
sendData
(
ret
);
}
catch
(
error
)
{
}
catch
(
error
)
{
next
(
error
);
next
(
error
);
}
}
...
...
controller/collectSMCController.js
View file @
0ebe4021
...
@@ -39,13 +39,13 @@ async function list(req, res, next) {
...
@@ -39,13 +39,13 @@ async function list(req, res, next) {
search
.
deviceNumber
=
{
$in
:
devNums
}
search
.
deviceNumber
=
{
$in
:
devNums
}
}
}
}
}
search
.
deviceHQType
=
req
.
body
.
deviceHQType
||
1
;
search
.
deviceHQType
=
req
.
body
.
deviceHQType
;
let
page
=
req
.
body
.
page
||
1
;
let
page
=
req
.
body
.
page
||
1
;
let
pageSize
=
req
.
body
.
pageSize
||
10
;
let
pageSize
=
req
.
body
.
pageSize
||
10
;
let
skip
=
(
page
-
1
)
*
pageSize
;
let
skip
=
(
page
-
1
)
*
pageSize
;
let
count
=
await
collectSMCModule
.
count
(
search
);
let
count
=
await
collectSMCModule
.
count
(
search
);
let
data
=
await
collectSMCModule
.
findList
(
search
,
{
skip
,
limit
:
pageSize
});
let
data
=
await
collectSMCModule
.
findList
(
search
,
{
skip
,
limit
:
pageSize
});
if
(
search
.
deviceHQType
==
1
)
{
// 这段是为了大屏 把 ph电导率 和 温湿度氮磷钾 合并起来
if
(
!
search
.
deviceHQType
)
{
// 这段是为了大屏 把 ph电导率 和 温湿度氮磷钾 合并起来
search
.
deviceHQType
=
2
;
search
.
deviceHQType
=
2
;
delete
search
.
deviceNumber
;
delete
search
.
deviceNumber
;
let
phData
=
await
collectSMCModule
.
findList
(
search
,
{
skip
,
limit
:
pageSize
});
let
phData
=
await
collectSMCModule
.
findList
(
search
,
{
skip
,
limit
:
pageSize
});
...
@@ -68,6 +68,46 @@ async function list(req, res, next) {
...
@@ -68,6 +68,46 @@ async function list(req, res, next) {
}
}
}
}
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
.
time
=
search
.
time
||
{};
search
.
time
.
$gte
=
req
.
body
.
startTime
;
}
if
(
req
.
body
.
endTime
)
{
search
.
time
=
search
.
time
||
{};
search
.
time
.
$lte
=
req
.
body
.
endTime
}
if
(
_
.
isArray
(
req
.
body
.
time
)
&&
req
.
body
.
time
.
length
==
2
)
{
search
.
time
=
{
$lte
:
req
.
body
.
time
[
1
],
$gte
:
req
.
body
.
time
[
0
]
}
}
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
}
}
}
search
.
deviceHQType
=
req
.
body
.
deviceHQType
||
1
;
let
ret
=
await
DB
.
ExcelRecord
.
create
({
creator
:
req
.
user
.
_id
,
type
:
2
,
modleName
:
'CollectSMC'
,
search
,
})
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
}
/**
/**
...
...
controller/collectWSController.js
View file @
0ebe4021
...
@@ -50,6 +50,45 @@ async function list(req, res, next) {
...
@@ -50,6 +50,45 @@ async function list(req, res, next) {
}
}
}
}
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
.
time
=
search
.
time
||
{};
search
.
time
.
$gte
=
req
.
body
.
startTime
;
}
if
(
req
.
body
.
endTime
)
{
search
.
time
=
search
.
time
||
{};
search
.
time
.
$lte
=
req
.
body
.
endTime
}
if
(
_
.
isArray
(
req
.
body
.
time
)
&&
req
.
body
.
time
.
length
==
2
)
{
search
.
time
=
{
$lte
:
req
.
body
.
time
[
1
],
$gte
:
req
.
body
.
time
[
0
]
}
}
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
}
}
}
let
ret
=
await
DB
.
ExcelRecord
.
create
({
creator
:
req
.
user
.
_id
,
type
:
2
,
modleName
:
'CollectWS'
,
search
,
})
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
}
/**
/**
...
@@ -123,4 +162,5 @@ module.exports = {
...
@@ -123,4 +162,5 @@ module.exports = {
queryInfo
,
queryInfo
,
updateInfo
,
updateInfo
,
delInfo
,
delInfo
,
exportExcel
,
}
}
\ No newline at end of file
controller/excelController.js
deleted
100644 → 0
View file @
41325eb9
const
path
=
require
(
'path'
);
const
fs
=
require
(
'fs'
);
const
_
=
require
(
'lodash'
);
const
moment
=
require
(
'moment'
);
async
function
exportExcel
(
req
,
res
,
next
)
{
let
modelName
=
req
.
params
.
modelName
;
let
modelMap
=
{
'IPS'
:
"CollectIPS"
,
'SMC'
:
"CollectSMC"
,
'WS'
:
"CollectWS"
,
}
}
module
.
exports
=
{
exportExcel
}
\ No newline at end of file
controller/fileController.js
View file @
0ebe4021
...
@@ -5,7 +5,7 @@ const _ = require('lodash');
...
@@ -5,7 +5,7 @@ const _ = require('lodash');
async
function
upload
(
req
,
res
,
next
)
{
async
function
upload
(
req
,
res
,
next
)
{
try
{
try
{
//
console.log(req.file, req.body);
console
.
log
(
req
.
file
,
req
.
body
);
let
nginxpath
=
_
.
last
(
String
(
req
.
file
.
path
).
split
(
'/mnt/vdb1'
));
let
nginxpath
=
_
.
last
(
String
(
req
.
file
.
path
).
split
(
'/mnt/vdb1'
));
let
ret
=
await
DB
.
File
.
create
({
let
ret
=
await
DB
.
File
.
create
({
originalname
:
req
.
file
.
originalname
,
originalname
:
req
.
file
.
originalname
,
...
...
cron/excelCron.js
0 → 100644
View file @
0ebe4021
// 气象
const
httpRequest
=
require
(
'../utils/httpRequest'
);
const
deviceModule
=
require
(
'../module/deviceModule'
);
const
collectIPSModule
=
require
(
'../module/collectIPSModule'
);
const
_
=
require
(
'lodash'
);
const
moment
=
require
(
'moment'
);
const
ExcelJS
=
require
(
'exceljs'
);
const
fs
=
require
(
'fs'
);
exportExcel
()
async
function
exportExcel
()
{
let
info
=
await
DB
.
ExcelRecord
.
findOne
({
type
:
2
,
status
:
1
});
console
.
log
(
info
);
if
(
info
&&
info
.
_id
&&
info
.
modleName
)
{
let
workbook
=
new
ExcelJS
.
Workbook
();
let
name
=
`Excel导出
${
new
Date
(
info
.
createdAt
).
getTime
()}
_
${
info
.
_id
}
`
let
worksheet
=
workbook
.
addWorksheet
(
name
);
let
columns
=
[];
if
(
!
_
.
isEmpty
(
DB
[
info
.
modleName
]
&&
DB
[
info
.
modleName
].
schema
&&
DB
[
info
.
modleName
].
schema
.
obj
))
{
for
(
const
key
in
DB
[
info
.
modleName
].
schema
.
obj
)
{
const
element
=
DB
[
info
.
modleName
].
schema
.
obj
[
key
];
if
(
element
&&
element
.
comment
)
{
// 有comment的导出,其他需要标注 不需要导出的用comment1
columns
.
push
({
header
:
element
.
comment
,
key
});
}
}
}
console
.
log
(
columns
.
length
,
"-=-=-"
);
if
(
columns
.
length
>
0
)
{
// TODO: 可以优化根据count翻页 暂时
worksheet
.
columns
=
columns
;
let
list
=
await
DB
[
info
.
modleName
].
find
(
info
.
search
||
{
del
:
0
});
for
(
let
index
=
0
;
index
<
list
.
length
;
index
++
)
{
const
element
=
list
[
index
];
worksheet
.
addRow
(
element
);
}
if
(
list
.
length
>
0
)
{
let
path
=
sysConfig
.
file
.
storagePath
+
'/'
+
moment
().
format
(
'YYYYMMDD'
);
if
(
!
fs
.
existsSync
(
path
))
{
fs
.
mkdirSync
(
path
,
{
recursive
:
true
});
}
let
excelUrl
=
path
+
'/'
+
name
+
'.xlsx'
// 1. 写入数据到存储位置
await
workbook
.
xlsx
.
writeFile
(
excelUrl
);
// 2. 创建文件信息
let
fileInfo
=
await
DB
.
File
.
create
({
originalname
:
name
+
'.xlsx'
,
mimetype
:
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
,
filename
:
name
+
'.xlsx'
,
path
:
excelUrl
,
// size: req.file.size,
type
:
2
,
});
// 3. 更新任务结果
await
DB
.
ExcelRecord
.
findOneAndUpdate
({
_id
:
info
.
_id
},
{
status
:
2
,
excelUrl
:
fileInfo
.
_id
})
}
}
}
// let workbook = new Excel.Workbook();
// // 添加一个工作表
// let worksheet = workbook.addWorksheet('我的工作表');
// // 添加表头
// worksheet.columns = [
// { header: '姓名', key: 'name' },
// { header: '年龄', key: 'age' },
// { header: '职业', key: 'occupation' }
// ];
// // 添加数据行
// worksheet.addRow({ name: '张三', age: 30, occupation: '软件工程师' });
// worksheet.addRow({ name: '李四', age: 25, occupation: '产品经理' });
// // 写入文件到磁盘
// await workbook.xlsx.writeFile('我的Excel.xlsx');
}
module
.
exports
=
{
exportExcel
,
}
cron/index.js
View file @
0ebe4021
...
@@ -8,6 +8,8 @@ const smcCron = require('./smcCron');
...
@@ -8,6 +8,8 @@ const smcCron = require('./smcCron');
const
wsCron
=
require
(
'./wsCron'
);
const
wsCron
=
require
(
'./wsCron'
);
// 虫情
// 虫情
const
ipsCron
=
require
(
'./ipsCron'
);
const
ipsCron
=
require
(
'./ipsCron'
);
// excel
const
excelCron
=
require
(
'./excelCron'
);
/**
/**
根据config cron 配置 定时处理
根据config cron 配置 定时处理
...
@@ -75,14 +77,24 @@ const cron = () => {
...
@@ -75,14 +77,24 @@ const cron = () => {
// 获取设备上述设备 4 采集信息
// 获取设备上述设备 4 采集信息
if
(
sysConfig
&&
sysConfig
.
cron
&&
sysConfig
.
cron
.
collectDeviceInfo
)
{
if
(
sysConfig
&&
sysConfig
.
cron
&&
sysConfig
.
cron
.
collectDeviceInfo
4
)
{
console
.
log
(
"collectDeviceInfo4:"
,
new
Date
());
console
.
log
(
"collectDeviceInfo4:"
,
new
Date
());
new
nodeCron
.
schedule
(
'1 */
3
* * * *'
,
async
()
=>
{
new
nodeCron
.
schedule
(
'1 */
1
* * * *'
,
async
()
=>
{
await
ipsCron
.
collectDeviceInfo4
({
deviceHQType
:
4
});
await
ipsCron
.
collectDeviceInfo4
({
deviceHQType
:
4
});
},
{
timezone
:
"Asia/Shanghai"
});
},
{
timezone
:
"Asia/Shanghai"
});
}
}
if
(
sysConfig
&&
sysConfig
.
cron
&&
sysConfig
.
cron
.
excel
)
{
console
.
log
(
"excel:"
,
new
Date
());
// new nodeCron.schedule('1 */1 * * * *', async () => {
// console.log(new Date().getTime())
// await excelCron.exportExcel();
// }, { timezone: "Asia/Shanghai" });
}
}
}
module
.
exports
=
cron
;
module
.
exports
=
cron
;
\ No newline at end of file
cron/ipsCron.js
View file @
0ebe4021
...
@@ -21,72 +21,72 @@ const _ = require('lodash');
...
@@ -21,72 +21,72 @@ const _ = require('lodash');
* 采集上述设备 4 的信息
* 采集上述设备 4 的信息
*/
*/
async
function
collectDeviceInfo4
({
deviceHQType
})
{
async
function
collectDeviceInfo4
({
deviceHQType
})
{
const
url
=
sysConfig
.
device
.
getInsectNewCollectionResult
;
const
token
=
sysConfig
.
device
.
token
;
const
userName
=
sysConfig
.
device
.
userName
;
const
password
=
sysConfig
.
device
.
password
;
// 查询有效状态、类型的设备信息
const
devices
=
await
deviceModule
.
findAll
({
deviceHQType
:
'4'
},
[
'deviceNumber'
,
'deviceHQType'
,
'name'
]);
// console.log(devices.length)
for
(
let
index
=
0
;
index
<
devices
.
length
;
index
++
)
{
const
dev
=
devices
[
index
];
// console.log(dev);
const
result
=
await
httpRequest
({
url
,
method
:
"POST"
,
params
:
{
token
,
userName
,
deviceNumber
:
dev
.
deviceNumber
}
});
console
.
log
(
result
);
if
(
result
&&
result
.
data
&&
result
.
status
&&
result
.
data
.
state
==
"success"
)
{
let
obj
=
result
.
data
.
data
||
{};
obj
.
name
=
dev
.
name
||
obj
.
name
;
console
.
log
(
obj
);
await
collectIPSModule
.
insertHQData
(
obj
);
// 3. 处理虫情每日种类数量记录
// 4. 处理设备在线状态
handleDeviceOnLine
({
deviceNumber
:
obj
.
deviceNumber
,
online
:
obj
.
online
});
//onLineState 1在线0离线
}
else
{
handleDeviceOnLine
({
deviceNumber
:
obj
.
deviceNumber
,
online
:
0
});
//onLineState 1在线0离线
}
}
// /**
// * 按硬件方要求 获取虫子的种类 和 数量 均调用设备列表接口
// */
// const url = sysConfig.device.getAllDevice;
// const url = sysConfig.device.getAllDevice;
// const token = sysConfig.device.token;
// const token = sysConfig.device.token;
// const userName = sysConfig.device.userName;
// const userName = sysConfig.device.userName;
// const password = sysConfig.device.password;
// const password = sysConfig.device.password;
// // 查询有效状态、类型的设备信息
// const devices = await deviceModule.findAll({ deviceHQType: '4'}, ['deviceNumber', 'deviceHQType']);
// console.log(devices.length)
// for (let index = 0; index < devices.length; index++) {
// const dev = devices[index];
// // console.log(dev);
// const result = await httpRequest({
// url,
// method: "POST",
// params: { token, userName, deviceNumber: dev.deviceNumber }
// });
// // console.log(result);
// if(result && result.data && result.data.state == "success") {
// let obj = result.data.data || {};
// obj.name = obj.name || dev.name;
// await collectIPSModule.insertHQData(obj);
// console.log(obj);
// // 3. 处理虫情每日种类数量记录
// // 4. 处理设备在线状态
// handleDeviceOnLine({deviceNumber: obj.deviceNumber, online: obj.online}); //onLineState 1在线0离线
// } else {
// handleDeviceOnLine({deviceNumber: obj.deviceNumber, online: 0}); //onLineState 1在线0离线
// let result = await httpRequest({
// url,
// method: "POST",
// params: { token, userName, password },
// });
// if (result && result.data && result.data.state == "success") {
// let devArr = result.data.data || [];
// for (let index = 0; index < devArr.length; index++) {
// const element = devArr[index];
// console.log(element, "虫情");
// let obj = {
// downloadUrl: element.imgUrl,
// downloadUrlCompress: element.imgUrl,
// newTime: element.latestCollectionTime,
// results: element.results || "",
// typeCount: element.typeCount || 0,
// newCount: element.newCount || 0,
// online: element.online,
// deviceNumber: element.deviceNumber,
// }
// await collectIPSModule.insertHQData(obj); // 处理虫子种类入库 数量入库
// handleDeviceOnLine({ deviceNumber: obj.deviceNumber, online: obj.online }); //onLineState 1在线0离线
// }
// }
// }
// }
/**
* 按硬件方要求 获取虫子的种类 和 数量 均调用设备列表接口
*/
const
url
=
sysConfig
.
device
.
getAllDevice
;
const
token
=
sysConfig
.
device
.
token
;
const
userName
=
sysConfig
.
device
.
userName
;
const
password
=
sysConfig
.
device
.
password
;
let
result
=
await
httpRequest
({
url
,
method
:
"POST"
,
params
:
{
token
,
userName
,
password
},
});
if
(
result
&&
result
.
data
&&
result
.
data
.
state
==
"success"
)
{
let
devArr
=
result
.
data
.
data
||
[];
for
(
let
index
=
0
;
index
<
devArr
.
length
;
index
++
)
{
const
element
=
devArr
[
index
];
console
.
log
(
element
,
"虫情"
);
let
obj
=
{
downloadUrl
:
element
.
imgUrl
,
downloadUrlCompress
:
element
.
imgUrl
,
newTime
:
element
.
latestCollectionTime
,
results
:
element
.
results
||
""
,
typeCount
:
element
.
typeCount
||
0
,
newCount
:
element
.
newCount
||
0
,
online
:
element
.
online
,
deviceNumber
:
element
.
deviceNumber
,
}
await
collectIPSModule
.
insertHQData
(
obj
);
// 处理虫子种类入库 数量入库
handleDeviceOnLine
({
deviceNumber
:
obj
.
deviceNumber
,
online
:
obj
.
online
});
//onLineState 1在线0离线
}
}
}
}
...
...
cron/smcCron.js
View file @
0ebe4021
...
@@ -150,7 +150,7 @@ async function handleDeviceThreshold(obj) {
...
@@ -150,7 +150,7 @@ async function handleDeviceThreshold(obj) {
sendUser
:
"66d6c4099f8480c6db53ce13"
,
sendUser
:
"66d6c4099f8480c6db53ce13"
,
receiveUser
:
"66d6c4099f8480c6db53ce13"
,
receiveUser
:
"66d6c4099f8480c6db53ce13"
,
content
:
exceeds
.
join
(
"
\
\n
"
),
content
:
exceeds
.
join
(
"
\
\n
"
),
title
:
"土壤采集数据预警通知"
});
});
}
}
}
}
...
...
cron/wsCron.js
View file @
0ebe4021
...
@@ -134,6 +134,7 @@ async function handleDeviceThreshold(obj) {
...
@@ -134,6 +134,7 @@ async function handleDeviceThreshold(obj) {
sendUser
:
"66d6c4099f8480c6db53ce13"
,
sendUser
:
"66d6c4099f8480c6db53ce13"
,
receiveUser
:
"66d6c4099f8480c6db53ce13"
,
receiveUser
:
"66d6c4099f8480c6db53ce13"
,
content
:
exceeds
.
join
(
"
\
\n
"
),
content
:
exceeds
.
join
(
"
\
\n
"
),
title
:
"气象站采集数据预警通知"
});
});
}
}
...
...
db/index.js
View file @
0ebe4021
...
@@ -47,6 +47,7 @@ const AgrMatApproval = require('./models/letianAgrMatApproval');
...
@@ -47,6 +47,7 @@ const AgrMatApproval = require('./models/letianAgrMatApproval');
const
AgrMatInOut
=
require
(
'./models/letianAgrMatInOut'
);
const
AgrMatInOut
=
require
(
'./models/letianAgrMatInOut'
);
const
FileTemplate
=
require
(
'./models/letianFIleTemplate'
);
const
FileTemplate
=
require
(
'./models/letianFIleTemplate'
);
const
ExcelRecord
=
require
(
'./models/letianExcelRecord'
);
...
@@ -85,6 +86,7 @@ global.DB = {
...
@@ -85,6 +86,7 @@ global.DB = {
AgrMatApproval
,
AgrMatApproval
,
AgrMatInOut
,
AgrMatInOut
,
FileTemplate
,
FileTemplate
,
ExcelRecord
,
CollectThreshold
,
CollectThreshold
,
CollectSMC
,
CollectSMC
,
...
...
db/models/collectIPS.js
View file @
0ebe4021
...
@@ -4,17 +4,19 @@ const moment = require('moment');
...
@@ -4,17 +4,19 @@ const moment = require('moment');
/**
/**
* 虫情 采集信息
* 虫情 采集信息
*
* 1. 下面schema结构会在导出excel时候用到,comment即为会导出的字段,comment1则不会导出
*/
*/
const
collectInsectPestSituationSchema
=
new
Schema
({
const
collectInsectPestSituationSchema
=
new
Schema
({
// name: {
name
:
{
// type: String,
type
:
String
,
// required: true,
comment
:
"设备名称"
// comment: "设备名称"
},
// },
deviceNumber
:
{
deviceNumber
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
index
:
true
index
:
true
,
comment
:
"设备编号"
},
},
time
:
{
time
:
{
...
@@ -25,70 +27,72 @@ const collectInsectPestSituationSchema = new Schema({
...
@@ -25,70 +27,72 @@ const collectInsectPestSituationSchema = new Schema({
downloadUrl
:
{
downloadUrl
:
{
type
:
String
,
type
:
String
,
comment
:
"摄像头采集原图下载URL"
,
comment
:
"图像"
,
comment1
:
"摄像头采集原图下载URL"
,
get
:
v
=>
sysConfig
.
device
.
fileBaseUrl
+
v
,
get
:
v
=>
sysConfig
.
device
.
fileBaseUrl
+
v
,
},
},
downloadUrlCompress
:
{
downloadUrlCompress
:
{
type
:
String
,
type
:
String
,
comment
:
"摄像头采集原图下载URL(压缩后)"
,
comment
1
:
"摄像头采集原图下载URL(压缩后)"
,
get
:
v
=>
sysConfig
.
device
.
fileBaseUrl
+
v
,
get
:
v
=>
sysConfig
.
device
.
fileBaseUrl
+
v
,
},
},
newTime
:
{
newTime
:
{
type
:
Date
,
type
:
Date
,
get
:
v
=>
moment
(
v
).
format
(
"YYYY-MM-DD HH:mm:ss"
),
get
:
v
=>
moment
(
v
).
format
(
"YYYY-MM-DD HH:mm:ss"
),
comment
:
"最新一次识别时间"
,
comment
1
:
"最新一次识别时间"
,
},
},
results
:
{
results
:
{
type
:
String
,
type
:
String
,
comment
:
"
最新一次
识别结果"
,
comment
:
"识别结果"
,
},
},
newCount
:
{
newCount
:
{
type
:
Number
,
type
:
Number
,
comment
:
"
最新一次
识别数量"
,
comment
:
"识别数量"
,
},
},
typeCount
:
{
typeCount
:
{
type
:
Number
,
type
:
Number
,
comment
:
"
最新一次识别的
种类数量"
,
comment
:
"种类数量"
,
},
},
oldCount
:
{
oldCount
:
{
type
:
Number
,
type
:
Number
,
comment
:
"上一次识别数量"
,
comment
1
:
"上一次识别数量"
,
},
},
oldTime
:
{
oldTime
:
{
type
:
Date
,
type
:
Date
,
comment
:
"上一次识别时间"
,
comment
1
:
"上一次识别时间"
,
},
},
oldResults
:
{
oldResults
:
{
type
:
String
,
type
:
String
,
comment
:
"上一次识别结果"
,
comment
1
:
"上一次识别结果"
,
},
},
oldTypeCount
:
{
oldTypeCount
:
{
type
:
Number
,
type
:
Number
,
comment
:
"上一次识别种类数量"
,
comment
1
:
"上一次识别种类数量"
,
},
},
oldDownloadUrl
:
{
oldDownloadUrl
:
{
type
:
String
,
type
:
String
,
comment
:
"上一次摄像头采集原图下载URL"
,
comment
1
:
"上一次摄像头采集原图下载URL"
,
},
},
oldDownloadUrlCompress
:
{
oldDownloadUrlCompress
:
{
type
:
String
,
type
:
String
,
comment
:
"上一次摄像头采集原图下载URL(压缩后)"
,
comment
1
:
"上一次摄像头采集原图下载URL(压缩后)"
,
},
},
taggingImgUrl
:
{
taggingImgUrl
:
{
type
:
String
,
type
:
String
,
comment
:
"标注后的图片"
,
comment
1
:
"标注后的图片"
,
},
},
taggingImgUrlCompress
:
{
taggingImgUrlCompress
:
{
type
:
String
,
type
:
String
,
comment
:
"标注后图片(压缩后)"
,
comment
1
:
"标注后图片(压缩后)"
,
},
},
oldDownloadUrl
:
{
oldDownloadUrl
:
{
type
:
String
,
type
:
String
,
comment
:
"上一次标注后的图片"
,
comment
1
:
"上一次标注后的图片"
,
},
},
oldDownloadUrlCompress
:
{
oldDownloadUrlCompress
:
{
type
:
String
,
type
:
String
,
comment
:
"上一次标注后的图片(压缩后)"
,
comment
1
:
"上一次标注后的图片(压缩后)"
,
},
},
/* 识别结果 不管哪一种形式,只要结果确认有效则写入,为空则表示此条数据无效,后续需要根据业务定期处理这类数据 */
/* 识别结果 不管哪一种形式,只要结果确认有效则写入,为空则表示此条数据无效,后续需要根据业务定期处理这类数据 */
...
@@ -112,7 +116,7 @@ const collectInsectPestSituationSchema = new Schema({
...
@@ -112,7 +116,7 @@ const collectInsectPestSituationSchema = new Schema({
del
:
{
del
:
{
type
:
Number
,
type
:
Number
,
default
:
0
,
default
:
0
,
comment
:
'默认0 , 1:表示删除,若有其他隐藏业务 不要混用此字段。'
comment
1
:
'默认0 , 1:表示删除,若有其他隐藏业务 不要混用此字段。'
}
}
},
{
},
{
toJSON
:
{
toJSON
:
{
...
...
db/models/collectSMC.js
View file @
0ebe4021
...
@@ -18,7 +18,9 @@ const soilMoistureContentSchema = new Schema({
...
@@ -18,7 +18,9 @@ const soilMoistureContentSchema = new Schema({
deviceNumber
:
{
deviceNumber
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
index
:
true
index
:
true
,
comment
:
"设备编号"
},
},
/* 接口返回的数据原始存储 */
/* 接口返回的数据原始存储 */
...
@@ -42,7 +44,7 @@ const soilMoistureContentSchema = new Schema({
...
@@ -42,7 +44,7 @@ const soilMoistureContentSchema = new Schema({
},
},
soilTemperatureUnit
:
{
soilTemperatureUnit
:
{
type
:
String
,
type
:
String
,
comment
:
"土壤温度单位"
,
comment
1
:
"土壤温度单位"
,
},
},
soilMoisture
:
{
soilMoisture
:
{
type
:
Number
,
type
:
Number
,
...
@@ -50,7 +52,7 @@ const soilMoistureContentSchema = new Schema({
...
@@ -50,7 +52,7 @@ const soilMoistureContentSchema = new Schema({
},
},
soilMoistureUnit
:
{
soilMoistureUnit
:
{
type
:
String
,
type
:
String
,
comment
:
"土壤湿度 单位"
,
comment
1
:
"土壤湿度 单位"
,
},
},
nitrogen
:
{
nitrogen
:
{
type
:
Number
,
type
:
Number
,
...
@@ -58,7 +60,7 @@ const soilMoistureContentSchema = new Schema({
...
@@ -58,7 +60,7 @@ const soilMoistureContentSchema = new Schema({
},
},
nitrogenUnit
:
{
nitrogenUnit
:
{
type
:
String
,
type
:
String
,
comment
:
"氮 单位"
,
comment
1
:
"氮 单位"
,
},
},
phosphorus
:
{
phosphorus
:
{
type
:
Number
,
type
:
Number
,
...
@@ -66,7 +68,7 @@ const soilMoistureContentSchema = new Schema({
...
@@ -66,7 +68,7 @@ const soilMoistureContentSchema = new Schema({
},
},
phosphorusUnit
:
{
phosphorusUnit
:
{
type
:
String
,
type
:
String
,
comment
:
"磷 单位"
,
comment
1
:
"磷 单位"
,
},
},
potassium
:
{
potassium
:
{
type
:
Number
,
type
:
Number
,
...
@@ -74,7 +76,7 @@ const soilMoistureContentSchema = new Schema({
...
@@ -74,7 +76,7 @@ const soilMoistureContentSchema = new Schema({
},
},
potassiumUnit
:
{
potassiumUnit
:
{
type
:
String
,
type
:
String
,
comment
:
"钾 单位"
,
comment
1
:
"钾 单位"
,
},
},
soilPH
:
{
soilPH
:
{
type
:
Number
,
type
:
Number
,
...
@@ -82,7 +84,7 @@ const soilMoistureContentSchema = new Schema({
...
@@ -82,7 +84,7 @@ const soilMoistureContentSchema = new Schema({
},
},
soilPHUnit
:
{
soilPHUnit
:
{
type
:
String
,
type
:
String
,
comment
:
"土壤PH 单位"
,
comment
1
:
"土壤PH 单位"
,
},
},
soilConductivity
:
{
soilConductivity
:
{
type
:
Number
,
type
:
Number
,
...
@@ -90,29 +92,29 @@ const soilMoistureContentSchema = new Schema({
...
@@ -90,29 +92,29 @@ const soilMoistureContentSchema = new Schema({
},
},
soilConductivityUnit
:
{
soilConductivityUnit
:
{
type
:
String
,
type
:
String
,
comment
:
"土壤电导率 单位"
,
comment
1
:
"土壤电导率 单位"
,
},
},
signalSterngth
:
{
signalSterngth
:
{
type
:
Number
,
type
:
Number
,
comment
:
"信号强度"
,
comment
1
:
"信号强度"
,
},
},
soilConductivityUnit
:
{
soilConductivityUnit
:
{
type
:
String
,
type
:
String
,
comment
:
"信号强度 单位"
,
comment
1
:
"信号强度 单位"
,
},
},
errorCode
:
{
errorCode
:
{
type
:
String
,
type
:
String
,
comment
:
"错误码"
,
comment
1
:
"错误码"
,
},
},
version
:
{
version
:
{
type
:
String
,
type
:
String
,
comment
:
"版本号"
,
comment
1
:
"版本号"
,
},
},
deviceHQType
:
{
deviceHQType
:
{
type
:
Number
,
type
:
Number
,
comment
:
"用来获取数据的设备类型-(接口文档): 1.土壤温湿度氮磷钾, 2土壤ph电导率, 3 气象站, 4虫情"
,
comment
1
:
"用来获取数据的设备类型-(接口文档): 1.土壤温湿度氮磷钾, 2土壤ph电导率, 3 气象站, 4虫情"
,
},
},
...
@@ -125,7 +127,7 @@ const soilMoistureContentSchema = new Schema({
...
@@ -125,7 +127,7 @@ const soilMoistureContentSchema = new Schema({
},
},
onLineState
:
{
onLineState
:
{
type
:
String
,
type
:
String
,
comment
:
"在线状态,该字段不记录到db,后期采集数据时将状态更新到redis里面即可"
comment
1
:
"在线状态,该字段不记录到db,后期采集数据时将状态更新到redis里面即可"
},
},
...
@@ -143,7 +145,7 @@ const soilMoistureContentSchema = new Schema({
...
@@ -143,7 +145,7 @@ const soilMoistureContentSchema = new Schema({
del
:
{
del
:
{
type
:
Number
,
type
:
Number
,
default
:
0
,
default
:
0
,
comment
:
'默认0 , 1:表示删除,若有其他隐藏业务 不要混用此字段。'
comment
1
:
'默认0 , 1:表示删除,若有其他隐藏业务 不要混用此字段。'
}
}
},
{
},
{
toJSON
:
{
toJSON
:
{
...
...
db/models/collectWS.js
View file @
0ebe4021
...
@@ -18,7 +18,9 @@ const collectWeatherStationSchema = new Schema({
...
@@ -18,7 +18,9 @@ const collectWeatherStationSchema = new Schema({
deviceNumber
:
{
deviceNumber
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
index
:
true
index
:
true
,
comment
:
"设备编号"
},
},
/* 接口返回的数据原始存储 */
/* 接口返回的数据原始存储 */
type
:
{
type
:
{
...
@@ -41,7 +43,7 @@ const collectWeatherStationSchema = new Schema({
...
@@ -41,7 +43,7 @@ const collectWeatherStationSchema = new Schema({
},
},
windSpeedUnit
:
{
windSpeedUnit
:
{
type
:
String
,
type
:
String
,
comment
:
"风速单位"
,
comment
1
:
"风速单位"
,
},
},
windDirection
:
{
windDirection
:
{
...
@@ -50,7 +52,7 @@ const collectWeatherStationSchema = new Schema({
...
@@ -50,7 +52,7 @@ const collectWeatherStationSchema = new Schema({
},
},
windDirectionUnit
:
{
windDirectionUnit
:
{
type
:
String
,
type
:
String
,
comment
:
"风向单位"
,
comment
1
:
"风向单位"
,
},
},
rainfall
:
{
rainfall
:
{
...
@@ -59,7 +61,7 @@ const collectWeatherStationSchema = new Schema({
...
@@ -59,7 +61,7 @@ const collectWeatherStationSchema = new Schema({
},
},
rainfallUnit
:
{
rainfallUnit
:
{
type
:
String
,
type
:
String
,
comment
:
"雨量单位"
,
comment
1
:
"雨量单位"
,
},
},
wsTemperature
:
{
wsTemperature
:
{
...
@@ -68,7 +70,7 @@ const collectWeatherStationSchema = new Schema({
...
@@ -68,7 +70,7 @@ const collectWeatherStationSchema = new Schema({
},
},
wsTemperatureUnit
:
{
wsTemperatureUnit
:
{
type
:
String
,
type
:
String
,
comment
:
"温度单位"
,
comment
1
:
"温度单位"
,
},
},
wsMoisture
:
{
wsMoisture
:
{
type
:
Number
,
type
:
Number
,
...
@@ -76,7 +78,7 @@ const collectWeatherStationSchema = new Schema({
...
@@ -76,7 +78,7 @@ const collectWeatherStationSchema = new Schema({
},
},
wsMoistureUnit
:
{
wsMoistureUnit
:
{
type
:
String
,
type
:
String
,
comment
:
"湿度单位"
,
comment
1
:
"湿度单位"
,
},
},
wsIllumination
:
{
wsIllumination
:
{
type
:
Number
,
type
:
Number
,
...
@@ -84,7 +86,7 @@ const collectWeatherStationSchema = new Schema({
...
@@ -84,7 +86,7 @@ const collectWeatherStationSchema = new Schema({
},
},
wsIlluminationUnit
:
{
wsIlluminationUnit
:
{
type
:
String
,
type
:
String
,
comment
:
"光照单位"
,
comment
1
:
"光照单位"
,
},
},
...
@@ -101,7 +103,7 @@ const collectWeatherStationSchema = new Schema({
...
@@ -101,7 +103,7 @@ const collectWeatherStationSchema = new Schema({
del
:
{
del
:
{
type
:
Number
,
type
:
Number
,
default
:
0
,
default
:
0
,
comment
:
'默认0 , 1:表示删除,若有其他隐藏业务 不要混用此字段。'
comment
1
:
'默认0 , 1:表示删除,若有其他隐藏业务 不要混用此字段。'
}
}
},
{
},
{
toJSON
:
{
toJSON
:
{
...
...
db/models/letianExcel.js
→
db/models/letianExcel
Record
.js
View file @
0ebe4021
...
@@ -7,10 +7,11 @@ const moment = require('moment');
...
@@ -7,10 +7,11 @@ const moment = require('moment');
*/
*/
const
ExcelSchema
=
new
Schema
({
const
ExcelSchema
=
new
Schema
({
creator
:
{
type
:
mongoose
.
Types
.
ObjectId
,
ref
:
'User'
},
creator
:
{
type
:
mongoose
.
Types
.
ObjectId
,
ref
:
'User'
},
type
:
{
type
:
Number
,
comment
:
"1. 导入 2, 导出"
},
type
:
{
type
:
Number
,
comment
:
"1. 导入 2, 导出"
},
excelUrl
:
{
type
:
mongoose
.
Types
.
ObjectId
,
ref
:
'File'
},
excelUrl
:
{
type
:
mongoose
.
Types
.
ObjectId
,
ref
:
'File'
},
modleName
:
String
,
modleName
:
String
,
search
:
{
type
:
Object
},
search
:
{
type
:
Object
},
status
:
{
type
:
Number
,
default
:
1
,
comment
:
"1, 未完成, 2 已完成。"
},
createdAt
:
{
createdAt
:
{
type
:
Date
,
type
:
Date
,
...
@@ -35,5 +36,5 @@ const ExcelSchema = new Schema({
...
@@ -35,5 +36,5 @@ const ExcelSchema = new Schema({
});
});
const
letianExcel
=
mongoose
.
model
(
'letianExcel'
,
ExcelSchema
,
'letianExcel'
);
const
letianExcelRecord
=
mongoose
.
model
(
'letianExcelRecord'
,
ExcelSchema
,
'letianExcelRecord'
);
module
.
exports
=
letianExcel
;
module
.
exports
=
letianExcelRecord
;
\ No newline at end of file
\ No newline at end of file
db/models/systemFile.js
View file @
0ebe4021
const
mongoose
=
require
(
'mongoose'
);
const
mongoose
=
require
(
'mongoose'
);
const
Schema
=
mongoose
.
Schema
;
const
Schema
=
mongoose
.
Schema
;
const
moment
=
require
(
'moment'
);
const
moment
=
require
(
'moment'
);
const
_
=
require
(
'lodash'
);
/**
/**
* 用户
* 用户
...
@@ -17,7 +18,7 @@ const fileSchema = new Schema({
...
@@ -17,7 +18,7 @@ const fileSchema = new Schema({
size
:
{
size
:
{
type
:
Number
,
type
:
Number
,
},
},
mim
i
etype
:
{
mimetype
:
{
type
:
String
type
:
String
},
},
url
:
{
url
:
{
...
@@ -28,9 +29,10 @@ const fileSchema = new Schema({
...
@@ -28,9 +29,10 @@ const fileSchema = new Schema({
},
},
nginxpath
:
{
nginxpath
:
{
type
:
String
,
type
:
String
,
set
:
setNginxPathByPath
,
},
},
type
:
{
type
:
Number
,
default
:
1
,
comment
:
"1上传 2导出excel"
},
createdAt
:
{
createdAt
:
{
type
:
Date
,
type
:
Date
,
...
@@ -54,6 +56,13 @@ const fileSchema = new Schema({
...
@@ -54,6 +56,13 @@ const fileSchema = new Schema({
}
}
});
});
function
setNginxPathByPath
()
{
console
.
log
(
this
,
"--this--"
,
this
.
path
);
let
nginxpath
=
_
.
last
(
String
(
this
.
path
).
split
(
'/mnt/vdb1'
));
console
.
log
(
nginxpath
,
"==nginxpath=="
)
return
nginxpath
}
const
File
=
mongoose
.
model
(
'File'
,
fileSchema
,
'systemFile'
);
const
File
=
mongoose
.
model
(
'File'
,
fileSchema
,
'systemFile'
);
module
.
exports
=
File
;
module
.
exports
=
File
;
\ No newline at end of file
db/models/systemNotice.js
View file @
0ebe4021
...
@@ -14,6 +14,7 @@ const Noticechema = new Schema({
...
@@ -14,6 +14,7 @@ const Noticechema = new Schema({
type
:
mongoose
.
Types
.
ObjectId
,
type
:
mongoose
.
Types
.
ObjectId
,
ref
:
"User"
ref
:
"User"
},
},
title
:
String
,
content
:
String
,
content
:
String
,
sendTime
:
{
sendTime
:
{
type
:
Date
,
type
:
Date
,
...
...
module/collectIPSModule.js
View file @
0ebe4021
...
@@ -29,13 +29,11 @@ async function count(search) {
...
@@ -29,13 +29,11 @@ async function count(search) {
async
function
insertHQData
(
data
)
{
async
function
insertHQData
(
data
)
{
if
(
!
(
data
.
deviceNumber
&&
data
.
newTime
))
{
return
;
}
data
.
time
=
data
.
newTime
;
// 为跟其他采集一致 ,都用time
data
.
time
=
data
.
newTime
;
// 为跟其他采集一致 ,都用time
let
check
=
await
DB
.
CollectIPS
.
findOne
({
newTime
:
data
.
newTime
});
let
check
=
await
DB
.
CollectIPS
.
findOne
({
newTime
:
data
.
newTime
});
if
(
!
check
)
{
if
(
!
check
)
{
let
ret
=
await
DB
.
CollectIPS
.
create
(
data
);
let
ret
=
await
DB
.
CollectIPS
.
create
(
data
);
console
.
log
(
"ret,:::"
,
ret
)
handleIPSResult
(
ret
);
handleIPSResult
(
ret
);
}
}
}
}
...
...
router/fileRouter.js
View file @
0ebe4021
...
@@ -10,7 +10,6 @@ const moment = require('moment');
...
@@ -10,7 +10,6 @@ const moment = require('moment');
const
mongoose
=
require
(
'mongoose'
);
const
mongoose
=
require
(
'mongoose'
);
const
fileController
=
require
(
'../controller/fileController'
);
const
fileController
=
require
(
'../controller/fileController'
);
const
excelController
=
require
(
'../controller/excelController'
);
const
storage
=
multer
.
diskStorage
({
const
storage
=
multer
.
diskStorage
({
...
@@ -54,6 +53,16 @@ router.post('/:modelName/importExcel', upload.single('file'), async (req, res, n
...
@@ -54,6 +53,16 @@ router.post('/:modelName/importExcel', upload.single('file'), async (req, res, n
await
controller
.
importExcel
(
req
,
res
,
next
);
await
controller
.
importExcel
(
req
,
res
,
next
);
});
});
router
.
post
(
'/:modelName/exportExcel'
,
excelController
.
exportExcel
);
router
.
post
(
'/:modelName/exportExcel'
,
async
(
req
,
res
,
next
)
=>
{
let
modelName
=
req
.
params
.
modelName
;
let
modelMap
=
{
'IPS'
:
"collectIPSController"
,
'SMC'
:
"collectSMCController"
,
'WS'
:
"collectWSController"
,
}
console
.
log
(
modelMap
[
modelName
]);
let
controller
=
require
(
`../controller/
${
modelMap
[
modelName
]}
`
);
await
controller
.
exportExcel
(
req
,
res
,
next
);
});
module
.
exports
=
router
;
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