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 |   66 +++++++++++++++++----------------
 1 files changed, 34 insertions(+), 32 deletions(-)

diff --git a/method.js b/method.js
index efb3934..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,16 +257,17 @@
     }, function(err, doc) {
         if (err) return;
 
-        if(x1 > 250) {
+        var opt1 = _config['options'][1];
+        if(x1 > opt1[0]) {
             var level = 1;
-            if(x1 > 750) {
+            if(x1 > opt1[2]) {
                 level = 3;
-            } else if(x1 > 500) {
+            } else if(x1 > opt1[1]) {
                 level = 2;
             }
-            sensor_data.id = doc._id;
+            sensor_data._id = doc.insertedId;
             sensor_data.level = level;
-            sensor_data.nitice = _config.notice;
+            sensor_data.notice = _config.notice;
             sensor_data.address = _config.address;
             queue.pushToMQ('ex_data_alarm', sensor_data);
         }
@@ -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