明树Git Lab

Commit 0d8a2f3a authored by zengfanpei's avatar zengfanpei

设备种类

parent 197ccad1
......@@ -18,7 +18,14 @@
"getAllDevice": "http://open.sennor.net:1881/getAllDevice",
"getInsectNewCollectionResult": "http://open.sennor.net:1881/getInsectNewCollectionResult",
"uploadCameraPhoto": "http://open.sennor.net:1881/uploadCameraPhoto",
"getPreventionToInsectName": "http://open.sennor.net:1881/getPreventionToInsectName"
"getPreventionToInsectName": "http://open.sennor.net:1881/getPreventionToInsectName",
"typeName": {
"1": "采集点",
"2": "气象站",
"3": "全景相机",
"4": "细节相机"
}
},
"cron": {
"getDeviceList": false,
......
const moment = require('moment');
const _ = require('lodash');
/**
* 获取墒情 时间段内变化趋势
......@@ -13,8 +14,8 @@ async function getSMCChangeTrend(req, res, next) {
let search = {
};
if((req.body.startTime && req.body.endTime)) {
search.time = {$gte: new Date(req.body.startTime), $lte: new Date(req.body.endTime)}
if ((req.body.startTime && req.body.endTime)) {
search.time = { $gte: new Date(req.body.startTime), $lte: new Date(req.body.endTime) }
}
let aggr = [
{
......@@ -51,8 +52,8 @@ async function getWSChangeTrend(req, res, next) {
let search = {
};
if((req.body.startTime && req.body.endTime)) {
search.time = {$gte: new Date(req.body.startTime), $lte: new Date(req.body.endTime)}
if ((req.body.startTime && req.body.endTime)) {
search.time = { $gte: new Date(req.body.startTime), $lte: new Date(req.body.endTime) }
}
let aggr = [
{
......@@ -87,8 +88,8 @@ async function getIPSChangeTrend(req, res, next) {
let search = {
};
if((req.body.startTime && req.body.endTime)) {
search.time = {$gte: new Date(req.body.startTime), $lte: new Date(req.body.endTime)}
if ((req.body.startTime && req.body.endTime)) {
search.time = { $gte: new Date(req.body.startTime), $lte: new Date(req.body.endTime) }
}
let aggr = [
{
......@@ -98,14 +99,14 @@ async function getIPSChangeTrend(req, res, next) {
},
{
$project: {
fTime: {$dateToString: { format: "%Y-%m-%d", date: "$time" }},
fTime: { $dateToString: { format: "%Y-%m-%d", date: "$time" } },
name: 1,
count: 1
}
},
{
$group: {
_id: {time: "$fTime", name: "$name"}, // 将时间戳转换为日期字符串
_id: { time: "$fTime", name: "$name" }, // 将时间戳转换为日期字符串
count: { $sum: "$count" }, // 累计每日虫子总数量
// typeCount: { $sum: 1 }, // 有几条 就是有几种虫子
}
......@@ -121,10 +122,11 @@ async function getIPSChangeTrend(req, res, next) {
{
$group: {
_id: '$time',
count: {$sum: '$count'},
typeCount: {$sum: 1}
}
count: { $sum: '$count' },
typeCount: { $sum: 1 }
}
},
{ $sort: { _id: 1 } }
];
let ret = await DB.CollectIPSResult.aggregate(aggr);
res.sendData(ret);
......@@ -136,7 +138,29 @@ async function getIPSChangeTrend(req, res, next) {
async function getDeviceCount(req, res, next) {
try {
let ret = await DB.Device.aggregate([
{
$group: {
_id: '$deviceDPType',
count: { $sum: 1 }
}
}
]);
let devMap = sysConfig.device.typeName; // { 1: "采集点", 2: "气象站", 3: "全景相机", 4: "细节相机" };
let retMap = {};
for (let i = 0; i < ret.length; i++) {
const element = ret[i];
retMap[element._id] = element.count || 0;
}
let datas = [];
for (const key in devMap) {
datas.push({
typeName: devMap[key],
_id: key,
count: retMap[key] || 0
});
}
res.sendData(datas);
} catch (error) {
next(error)
}
......
......@@ -93,15 +93,15 @@ const deviceSchema = new Schema({
deviceHQState: {
type: Number,
default: 1,
comment: "通过http接口获取到的设备状态, 默认有效:1,某次获取若设备消失,则状态置为失效:0",
comment: "通过http接口获取到的设备状态, 默认有效: 1,某次获取若设备消失,则状态置为失效: 0",
},
deviceHQType: {
type: Number,
comment: "获取的设备类型 1.土壤温湿度、土壤氮磷钾, 2土壤ph、土壤电导率, 3 气象站, 4虫情",
comment: "用来获取数据的设备类型-(接口文档): 1.土壤温湿度、土壤氮磷钾, 2土壤ph、土壤电导率, 3 气象站, 4虫情",
},
deviceType: {
deviceDPType: {
type: Number,
comment: "1 采集设备 2 气象站 3 全景相机 4 细节相机"
comment: "用来大屏展示的数据类型-(大屏图): 1 采集点 2 气象站 3 全景相机 4 细节相机"
},
......@@ -118,7 +118,7 @@ const deviceSchema = new Schema({
del: {
type: Number,
default: 0,
comment: '默认0 , 1:表示删除,若有其他隐藏业务 不要混用此字段。'
comment: '默认0 , 1: 表示删除,若有其他隐藏业务 不要混用此字段。'
}
}, {
toJSON: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment