root 1 year ago
parent
commit
0c2259fb44
2 changed files with 140 additions and 81 deletions
  1. 134 76
      node/message.js
  2. 6 5
      uform.js

+ 134 - 76
node/message.js

@@ -5,6 +5,11 @@ us.qs = require("querystring"); //引用文件解析包
 us.http = require("http"); //引用http server服务
 us.mysql = require("./mysql.js"); //引用执行存储过程包
 
+/**
+* 保持知识建构的时间变量
+**/
+us.savecscltime = null;
+
 /**
 * 用户的链接池集合,以用户id作为搜索键
 **/
@@ -235,6 +240,9 @@ us.server = us.http.createServer(function (requset, response) {
                 case 'quitOffice':
                     us.quitOffice(response, _param[0]);
                     break;
+                case 'quitcscl':
+                    us.quitcscl(response, _param[0]);
+                    break;
                 case 'newWordSave':
                     us.newWordSave(response, _param[0], _param[1], _param[2], _param[3], _param[4]);
                     break;
@@ -523,46 +531,44 @@ us.login = function (requset, response, userid, pageid, username, type) {
 * 用户下线,清理用户的数据
 */
 us.deluser = function (userid, pageid) {
-
-    var i, j, z; //定义循环变量
-    var _userid, _fileid, _message, _docinfo, _messageinfo,
-        _csclids = us.offLineMessage[pageid].cscl;
-    //其他应用的数据
-    // _wordids = us.offLineMessage[pageid].word, //得到加入的所有word
-    // _excelids = us.offLineMessage[pageid].excel; //得到加入的所有excel
-
-    console.log(pageid)
-    console.log(us.offLineMessage[pageid])
-    //删除用户离校消息记录
-    delete us.offLineMessage[pageid];
-    console.log("1111111111111")
-    console.log(_csclids)
-    //知识架构的下线的处理
-    for (i = 0; i < _csclids.length; i++) { //循环处理每一个文档
-        _docinfo = us.cscl[_csclids[i]]; //记录文档信息
-        if (_docinfo) { //如果存在文档信息
-            _fileid = _csclids[i];
-            _userid = us.quitUserList(_docinfo, userid, pageid); //将用户在协同列表中删除
+    if (pageid && us.offLineMessage[pageid]) {
+        var i, j, z; //定义循环变量
+        var _userid, _fileid, _message, _docinfo, _messageinfo,
+            _csclids = us.offLineMessage[pageid].cscl;
+        //其他应用的数据
+        // _wordids = us.offLineMessage[pageid].word, //得到加入的所有word
+        // _excelids = us.offLineMessage[pageid].excel; //得到加入的所有excel
+
+        console.log(pageid)
+        console.log(us.offLineMessage[pageid])
+        //删除用户离校消息记录
+        delete us.offLineMessage[pageid];
+        console.log("1111111111111")
+        console.log(_csclids)
+        //知识架构的下线的处理
+        for (i = 0; i < _csclids.length; i++) { //循环处理每一个文档
+            _docinfo = us.cscl[_csclids[i]]; //记录文档信息
+            if (_docinfo) { //如果存在文档信息
+                _fileid = _csclids[i];
+                _userid = us.quitUserList(_docinfo, userid, pageid); //将用户在协同列表中删除
+            }
+        }
+        console.log(_userid)
+        //下线后通知所有的用户
+        if (_userid) {
+            _message = {};
+            var _messageinfo = us.message(userid, 'us.cscl', {
+                id: us.createGuid(),
+                type: "delUser",
+                userinfo: us.user[_userid],
+                docId: _fileid
+            });
+            _message[_fileid] = [_messageinfo];
+            console.log(_message)
+            us.broadcast(_message, pageid, "cscl");
         }
     }
-    console.log(_userid)
-    //下线后通知所有的用户
-    if (_userid) {
-        _message = {};
-        var _messageinfo = us.message(userid, 'us.cscl', {
-            id: us.createGuid(),
-            type: "delUser",
-            userinfo: us.user[_userid],
-            docId: _fileid
-        });
-        _message[_fileid] = [_messageinfo];
-        console.log(_message)
-        us.broadcast(_message, pageid, "cscl");
-    }
-
-
     //其他应用的处理
-
     // //word的下线的处理
     // for (i = 0; i < _wordids.length; i++) { //循环处理每一个文档
     //     _docinfo = us.word[_wordids[i]]; //记录文档信息
@@ -571,7 +577,6 @@ us.deluser = function (userid, pageid) {
     //         us.insertHistory(_docinfo, 'word'); //插入历史
     //     }
     // }
-
     // //excel的下线的处理
     // for (j = 0; i < _excelids.length; j++) {
     //     _docinfo = us.excel[_excelids[j]]; //记录文档信息
@@ -580,7 +585,6 @@ us.deluser = function (userid, pageid) {
     //         us.insertHistory(_docinfo, 'excel'); //插入历史
     //     }
     // }
-
 }
 
 /**
@@ -878,21 +882,17 @@ us.updatecscl = function (messageInfo, classId, ty) {
                 _obj.nodes.push(messageInfo.nodes[j])
             }
         }
-        //console.log(_obj);
         //如果不存在则去数据库查找
-        us.mysql.usselect(['172.16.12.5', 'pbl', 'updateRoomData', JSON.stringify(_obj), classId],
-            function (ret) {
-            });
-
-
-        //"nodes":[{"id":"9f6d7459-d376-4c0c-944b-a6b140085903","type":"icon-start","x":625,"y":145,"properties":{},"zIndex":1002,"text":{"x":625,"y":145,"value":"起始"}},{"id":"16e18308-7517-4162-8b32-a877b7cf42a0","type":"icon-card","x":325,"y":445,"properties":{},"zIndex":1002},{"id":"5c492b0d-092d-4d84-bd70-4d5734de9266","type":"icon-select","x":970,"y":510,"properties":{},"zIndex":1002}],
-        //"edges":[],
-        //"backgroundUrl":"img/bg.ccee1c62.png"
-
+        try {
+            clearTimeout(us.savecscltime);
+        }
+        catch (e) {
 
-        // if (_obj) {
-        //     _obj[messageInfo.id] = messageInfo.content;
-        // }
+        }
+        //每次修改每隔五秒保存一次数据,防止数据操作频繁导致数据库太卡
+        us.savecscltime = setTimeout(function () {
+            us.mysql.usselect(['172.16.12.5', 'pbl', 'updateRoomData', JSON.stringify(_obj), classId], function (ret) { });
+        }, 5000)
     }
 }
 
@@ -1545,7 +1545,8 @@ us.broadcast = function (messageinfo, pageid, type) {
                         if (_userconnect[j] && _userconnect[j][_recievedpageid]) {
                             console.log(_recievedpageid);
                             _issend = _userconnect[j][_recievedpageid].response.write(JSON.stringify(_messageinfo)); //发送消息
-                            if (!_issend) { //如果用户下线了,那么发送消息就会失败
+                            //用户在轮询切换的时候的中间,会产生数据无法接受,这里是存储数据
+                            if (!_issend) {
                                 us.offLineMessage[_recievedpageid].message.push(_messageinfo); //将消息加入用户离线消息中
                             }
                         }
@@ -1600,7 +1601,7 @@ us.addWord = function (response, wordinfo) {
 * @param  {string} wordinfo 文档信息
 **/
 us.quitOffice = function (response, wordinfo) {
-    //获取用户参数  
+    //获取用户参数
     wordinfo = JSON.parse(wordinfo);
     var _docid = wordinfo.docId,
         _userid = wordinfo.userId,
@@ -1624,9 +1625,53 @@ us.quitOffice = function (response, wordinfo) {
     response.end('quitOffice'); //响应退出请求
 }
 
+/**
+* 退出知识建构
+*
+* @param  {object} response 用户相应对象
+* @param  {string} wordinfo 文档信息
+**/
+us.quitcscl = function (response, info) {
+    //获取用户参数
+    info = JSON.parse(info);
+    var _docid = info.docId,
+        _userid = info.userId,
+        _pageid = info.pageId,
+        _type = info.type,
+        _messagetype = 'us.cscl';
+    var _docinfo = us[_type][_docid]; //获取文档信息
+    //判断是否存在文档信息
+    if (_docinfo) {
+        _userid = us.quitUserList(_docinfo, _userid, _pageid); //将用户在协同列表中删除
+        console.log(_userid)
+        //下线后通知所有的用户
+        if (_userid) {
+            _message = {};
+            var _messageinfo = us.message(userid, 'us.cscl', {
+                id: us.createGuid(),
+                type: "delUser",
+                userinfo: us.user[_userid],
+                docId: _docid
+            });
+            _message[_docid] = [_messageinfo];
+            console.log(_message)
+            us.broadcast(_message, _pageid, "cscl");
+        }
+
+        // var _j, //创建循环变量
+        //     _message = us.offLineMessage[_pageid] ? us.offLineMessage[_pageid].message : []; //获取该用户的离线消息
+        // for (_j = _message.length - 1; _j > -1; _j--) { //循环移除该文档的离线消息
+        //     if (_message[_j].type == _messagetype && _message[_j].messageInfo.docId == _docid) { //判断是否为word文档
+        //         _message.splice(_j, 1); //删除记录
+        //     }
+        // }
+    }
+    response.end('quitOffice'); //响应退出请求
+}
+
 /**
 * 将用户在协同列表中删除
-* 
+*
 * @param {object} docinfo 文档信息
 * @param {string} userid 用户ID
 * @param {string} pageid 用户页面唯一识别ID
@@ -1692,31 +1737,44 @@ us.insertHistory = function (docinfo, docid, type) {
 * @param {string} pageid 用户页面唯一识别ID
 */
 us.logout = function (response, userid, pageid) {
-    var i, j, _docinfo,
-        _wordids = us.offLineMessage[pageid].word, //得到加入的所有word
-        _excelids = us.offLineMessage[pageid].excel; //得到加入的所有excel
+    var j, istrue = true;
+    var _user = us.connect[userid];
+    //循环目前所有的连接用户
+    us.deluser(userid, pageid); //删除用户的数据
+    delete _user[pageid]
+    for (j in _user) { istrue = false; break }
+    //这个用户下所有的连接用户都不在了
+    if (istrue) {
+        //用户登录数据清理,用于已经下线
+        delete us.user[userid];
+        delete us.connect[userid];
+    }
+    response.end('logout'); //响应退出请求
 
-    us.connect[userid][pageid].offLineTime = new Date();
+    // var i, j, _docinfo,
+    //     _wordids = us.offLineMessage[pageid].word, //得到加入的所有word
+    //     _excelids = us.offLineMessage[pageid].excel; //得到加入的所有excel
 
-    for (i = 0; i < _wordids.length; i++) { //循环处理每一个文档
-        _docinfo = us.word[_wordids[i]]; //记录文档信息
-        if (_docinfo) { //如果存在文档信息
-            us.quitUserList(_docinfo, userid, pageid); //将用户在协同列表中删除
-            delete us.offLineMessage[pageid]; //删除用户离线消息记录
-            us.insertHistory(_docinfo, 'word'); //插入历史
-        }
-    }
+    // us.connect[userid][pageid].offLineTime = new Date();
 
-    for (j = 0; i < _excelids.length; j++) {
-        _docinfo = us.excel[_excelids[j]]; //记录文档信息
-        if (_docinfo) { //如果存在文档信息
-            us.quitUserList(_docinfo, userid, pageid); //将用户在协同列表中删除
-            delete us.offLineMessage[pageid]; //删除用户离线消息记录
-            us.insertHistory(_docinfo, 'excel'); //插入历史
-        }
-    }
+    // for (i = 0; i < _wordids.length; i++) { //循环处理每一个文档
+    //     _docinfo = us.word[_wordids[i]]; //记录文档信息
+    //     if (_docinfo) { //如果存在文档信息
+    //         us.quitUserList(_docinfo, userid, pageid); //将用户在协同列表中删除
+    //         delete us.offLineMessage[pageid]; //删除用户离线消息记录
+    //         us.insertHistory(_docinfo, 'word'); //插入历史
+    //     }
+    // }
+
+    // for (j = 0; i < _excelids.length; j++) {
+    //     _docinfo = us.excel[_excelids[j]]; //记录文档信息
+    //     if (_docinfo) { //如果存在文档信息
+    //         us.quitUserList(_docinfo, userid, pageid); //将用户在协同列表中删除
+    //         delete us.offLineMessage[pageid]; //删除用户离线消息记录
+    //         us.insertHistory(_docinfo, 'excel'); //插入历史
+    //     }
+    // }
 
-    response.end('logout'); //响应退出请求
 }
 
 

+ 6 - 5
uform.js

@@ -11690,7 +11690,7 @@ U.MD.U.L.defaultCallBack = function (r, iscookie) {
                     U.UF.CI.getUserLocation(U.MD.U.L.addUserAccess); //客户端信息加载,好像只加载了新浪ip地址?
                 }
                 _userinfo = U.MD.U.L.setUserInfo(r); //设置用户基本信息,包括用户信息,好友信息
-                U.MD.U.L.getLoginUserInfo(_username || US.userInfo.username); //去获取用户详细信息
+                U.MD.U.L.getLoginUserInfo(_username || US.userInfo.UserName); //去获取用户详细信息
                 if ($("#U_MD_D_BDI")[0] && U.selectEl('#U_MD_D_BG')[0]) {
                     //登录有用户的信息展示到页面中,包括背景图片、用户头像等
                     U.MD.U.L.printUserInfo(); //用户头部头像个人信息
@@ -11897,7 +11897,7 @@ U.MD.U.L.initUserLogin = function () {
 U.MD.U.L.addUserAccess = function () {
     //如果用户的城市信息不存在,则添加用户用户城市信息,应该不只是单单判断地址,此处逻辑还需要整理!
     if (US.city.userAllLocation) {
-        U.A.Request(US.USER, ["RecordUserClientInfo", US.userInfo.username, "", "", US.city.userAllLocation, ""],
+        U.A.Request(US.USER, ["RecordUserClientInfo", US.userInfo.UserName, "", "", US.city.userAllLocation, ""],
             function () { }); //异步添加地址信息
     }
 }
@@ -11960,10 +11960,11 @@ U.MD.U.LO.logoutSystem = function (callback) {
     if (US.userInfo.userid) {
         //弹出退出登录的提示
         U.UF.UI.confirm("是否退出" + US.userInfo.username + "账号", function () {
-            // U.MD.U.LO.logout(callback);
             U.A.Request(US.Config.server + "logout", [], function (res) {
-                U.alert("退出成功!")
-                window.location.reload();
+                U.A.Request(US.SCOKET, ["logout", US.userInfo.userid, US.pageId], function () {
+                    U.alert("退出成功!")
+                    window.location.reload();
+                }, [], { "type": "POST", "withCredentials": true }); //在状态服务退出
             }, [], { "type": "POST", "withCredentials": true });
         });
     }