From 8125c4dd55965689a3da0f5016260794523bb935 Mon Sep 17 00:00:00 2001
From: 沈斌 <bluelazysb@hotmail.com>
Date: Fri, 30 Dec 2016 23:14:21 +0800
Subject: [PATCH] 环境数服务端后台PM2.5阙值的动态取得
---
method.js | 62 ++++++++++++++++---------------
1 files changed, 32 insertions(+), 30 deletions(-)
diff --git a/method.js b/method.js
index 9f24d43..ded9b19 100644
--- a/method.js
+++ b/method.js
@@ -180,6 +180,9 @@
tel: "15950198162",���
email: "it01@moral.org.cn",���
open_id: "o-RTuwvMHWotyirPHLmdSB_dKoQU"
+ },
+ options: {
+ 1: [500, 700, 900]
}
};
configs[mac] = _config;
@@ -199,6 +202,7 @@
x5: x10, //������
x6: x14 //������������
},
+ options: _config.options,
time: current.valueOf()
};
queue.pushToMQ('ex_data_screen', sensor_data);
@@ -253,11 +257,12 @@
}, function(err, doc) {
if (err) return;
- if(x1 > 500) {
+ var opt1 = _config['options'][1];
+ if(x1 > opt1[0]) {
var level = 1;
- if(x1 > 900) {
+ if(x1 > opt1[2]) {
level = 3;
- } else if(x1 > 700) {
+ } else if(x1 > opt1[1]) {
level = 2;
}
sensor_data._id = doc.insertedId;
@@ -345,34 +350,31 @@
db.collection("devices").find().toArray(function(err, docs) {
docs.forEach(function(doc) {
var mac = doc.mac;
- if(mac != null) {
- var address = doc.address || "";
- var location = doc.location || {};
- var notice = doc.notice;
- if(notice == null || notice == {}) {
- var userID = doc.userID;
- db.collection("users").find({"_id": userID}).limit(1).next(function(err, user){
- if(user) {
- global.configs[mac] = {
- mac: mac,
- address: address,
- location: location,
- notice: {
- tel: user.username,
- email: user.email,
- open_id: user.open_id
- }
- }
- }
- });
- } else {
- global.configs[mac] = {
- mac: mac,
- address: address,
- location: location,
- notice: notice
+ var address = doc.address || "";
+ var location = doc.location || {};
+ var notice = doc.notice;
+ var options = doc.options;
+ var config = {
+ mac: mac,
+ address: address,
+ location: location,
+ notice: notice,
+ options: options
+ };
+ if(notice == null || notice == {}) {
+ var userID = doc.userID;
+ db.collection("users").find({"_id": userID}).limit(1).next(function(err, user){
+ if(user) {
+ config[notice] = {
+ tel: user.username,
+ email: user.email,
+ open_id: user.open_id
+ };
+ global.configs[mac] = config;
}
- }
+ });
+ } else {
+ global.configs[mac] = config;
}
});
});
--
Gitblit v1.8.0