From 565c4f00094c6894911b47fae031c4777539b616 Mon Sep 17 00:00:00 2001
From: 沈斌 <bluelazysb@hotmail.com>
Date: Mon, 26 Dec 2016 15:48:25 +0800
Subject: [PATCH] 服务端代码优化与测试

---
 method.js |   46 ++++++++++++++++++++++++++--------------------
 1 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/method.js b/method.js
index a215c48..48aea6b 100644
--- a/method.js
+++ b/method.js
@@ -170,6 +170,7 @@
     var _config = global.configs[mac];
     if(_config == null) {
         _config = {
+            mac: mac,
             address: "���������������������������������",
             location: {���
                 lat:31.430616,
@@ -180,6 +181,7 @@
                 email: "it01@moral.org.cn",���
                 open_id: "o-RTuwvMHWotyirPHLmdSB_dKoQU"
             }
+            configs[mac] = _config;
         }
     }
 
@@ -353,29 +355,33 @@
     db.collection("devices").find().toArray(function(err, docs) {
         docs.forEach(function(doc) {
             var mac = doc.mac;
-            var address = doc.address;
-            var location = doc.location;
-            var notice = doc.notice;
-            if(notice == null) {
-                var userID = doc.userID;
-                db.collection("users").find({"_id": userID}).limit(1).next(function(err, user){
-                    if(user) {
-                        global.configs[mac] = {
-                            address: address,
-                            location: location,
-                            notice: {
-                                tel: user.username,
-                                email: user.email,
-                                open_id: user.open_id
+            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
                     }
-                });
-            } else {
-                global.configs[mac] = {
-                    address: address,
-                    location: location,
-                    notice: notice
                 }
             }
         });

--
Gitblit v1.8.0