Browse Source

Merge branch 'beta' into HK

lsc 2 years ago
parent
commit
98ec6973dd
5 changed files with 271 additions and 152 deletions
  1. 69 14
      js/Desktop/DeskTop.js
  2. 40 46
      js/Office/Poll.js
  3. 123 65
      node/message.js
  4. 4 18
      node/mysql.js
  5. 35 9
      node/test.js

+ 69 - 14
js/Desktop/DeskTop.js

@@ -202,7 +202,7 @@ U.MD.D.I.orgStemDeskIcon = [
     { "Name": "教學資源", "Url": "source", "style": { "cssText": "background-image:url(/img/icon/source.png)" } },
     { "Name": "AI共創", "Url": "AIChat", "style": { "cssText": "background-image:url(/img/icon/AIChat.png)" } },
     { "Name": "AI協同", "Url": "ainew", "style": { "cssText": "background-image:url(/img/icon/AIChat.png)" } },
-    { "Name": "知識建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
+    { "Name": "協同建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
     { "Name": "數據看板", "Url": "dataBoard", "style": { "cssText": "background-image:url(/img/icon/dataBoard.png)" } },
     // { "Name": "jupyter", "Url": "jupyter", "style": { "cssText": "background-image:url(/img/icon/jupyter.png)" } },
 ];
@@ -560,6 +560,7 @@ U.MD.D.I.lotechTeacherDeskIcon = [
     { "Name": "學習分析", "Url": "learnAna", "style": { "cssText": "background-image:url(/img/icon/learnAna.png)" } },
     { "Name": "AI共創", "Url": "AIChat", "style": { "cssText": "background-image:url(/img/icon/AIChat.png)" } },
     { "Name": "AI協同", "Url": "ainew", "style": { "cssText": "background-image:url(/img/icon/AIChat.png)" } },
+    { "Name": "協同建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
 ];
 
 //龍華中心小學教師桌面圖標的全局變量
@@ -784,7 +785,7 @@ U.MD.D.I.dseiTeacherDeskIcon = [
     { "Name": "學習分析", "Url": "learnAna", "style": { "cssText": "background-image:url(/img/icon/learnAna.png)" } },
     { "Name": "AI共創", "Url": "AIChat", "style": { "cssText": "background-image:url(/img/icon/AIChat.png)" } },
     { "Name": "AI協同", "Url": "ainew", "style": { "cssText": "background-image:url(/img/icon/AIChat.png)" } },
-    { "Name": "知識建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
+    { "Name": "協同建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
     { "Name": "數據看板", "Url": "dataBoard", "style": { "cssText": "background-image:url(/img/icon/dataBoard.png)" } },
 ];
 
@@ -829,7 +830,7 @@ U.MD.D.I.dseiAdminDeskIcon = [
     { "Name": "學習分析", "Url": "learnAna", "style": { "cssText": "background-image:url(/img/icon/learnAna.png)" } },
     { "Name": "AI共創", "Url": "AIChat", "style": { "cssText": "background-image:url(/img/icon/AIChat.png)" } },
     { "Name": "AI協同", "Url": "ainew", "style": { "cssText": "background-image:url(/img/icon/AIChat.png)" } },
-    { "Name": "知識建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
+    { "Name": "協同建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
     { "Name": "數據看板", "Url": "dataBoard", "style": { "cssText": "background-image:url(/img/icon/dataBoard.png)" } },
 ];
 
@@ -858,7 +859,7 @@ U.MD.D.I.szjkyTeacherDeskIcon = [
     { "Name": "課程進展", "Url": "case", "style": { "cssText": "background-image:url(/img/icon/case.png)" } },
     { "Name": "AI共創", "Url": "AIChat", "style": { "cssText": "background-image:url(/img/icon/AIChat.png)" } },
     { "Name": "AI協同", "Url": "ainew", "style": { "cssText": "background-image:url(/img/icon/AIChat.png)" } },
-    { "Name": "知識建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
+    { "Name": "協同建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
     { "Name": "數據看板", "Url": "dataBoard", "style": { "cssText": "background-image:url(/img/icon/dataBoard.png)" } },
 ];
 
@@ -877,7 +878,7 @@ U.MD.D.I.szjkyAdminDeskIcon = [
     { "Name": "課程進展", "Url": "case", "style": { "cssText": "background-image:url(/img/icon/case.png)" } },
     { "Name": "AI共創", "Url": "AIChat", "style": { "cssText": "background-image:url(/img/icon/AIChat.png)" } },
     { "Name": "AI協同", "Url": "ainew", "style": { "cssText": "background-image:url(/img/icon/AIChat.png)" } },
-    { "Name": "知識建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
+    { "Name": "協同建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
     { "Name": "數據看板", "Url": "dataBoard", "style": { "cssText": "background-image:url(/img/icon/dataBoard.png)" } },
 ];
 
@@ -1092,22 +1093,28 @@ U.MD.D.I.initDesktopIcons = function(el, type) {
             { "Name": "AI協同", "Url": "ainew", "style": { "cssText": "background-image:url(/img/icon/AIChat.png)" } }, 
             { "Name": "工作管理", "Url": "studioCourse", "style": { "cssText": "background-image:url(/img/icon/studioCourse.png)" } }, 
             { "Name": "工作中心", "Url": "studioIndex", "style": { "cssText": "background-image:url(/img/icon/studioIndex.png)" } },
-            { "Name": "知識建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
+            { "Name": "協同建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
             { "Name": "數據看板", "Url": "dataBoard", "style": { "cssText": "background-image:url(/img/icon/dataBoard.png)" } },
         )
     }
 
     if (_org == 'c95e0a56-c205-11ed-8d51-005056b86db5') {
         _teacherDesktopIconInfo.push(
-            { "Name": "知識建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
+            { "Name": "協同建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
             { "Name": "數據看板", "Url": "dataBoard", "style": { "cssText": "background-image:url(/img/icon/dataBoard.png)" } },
         )
         _studentDesktopIconInfo.push(
-            { "Name": "知識建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
+            { "Name": "協同建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
         )
         
     }
 
+    if (_oid == 'cf8841e8-c7c0-11ed-9546-005056b86db5') {
+        _teacherDesktopIconInfo.push(
+            { "Name": "協同建構", "Url": "futureClass", "style": { "cssText": "background-image:url(/img/icon/futureClass.png)" } },
+        )   
+    }
+
     if (_oid == '1c3b9def-8fbe-11ed-b13d-005056b86db5') {
         _studentDesktopIconInfo3 = _studentDesktopIconInfo3.filter((el) => {
             if (el.Name == '項目管理') {
@@ -2474,8 +2481,13 @@ window.addEventListener('message', function(e) { // 監聽 message 事件
             classid:e.data.classid || '',
         }
         U.MD.D.I.openInApplication("dataClass", _data)
+    } else if (e.data.tools && e.data.tools == "opencCscl") {
+        let _data = {
+            cid:e.data.cid || '',
+            gid:e.data.gid || '',
+        }
+        U.MD.D.I.openInApplication("opencCscl", _data)
     }
-
 });
 
 U.MD.D.I.selectUser = function() {
@@ -2642,7 +2654,7 @@ U.MD.D.I.openInApplication = function(str, data, screenType, tType) {
                     _taskbar = { "id": str + _formdiv.id, "style": { "backgroundImage": "url(/img/icon/studentCourse.png)" }, "name": "課程中心", "forms": _formdiv, "click": function() { U.MD.D.I.openApplication(str, obj, info); } }
                     break;
                 }
-            case "dataClass":
+        case "dataClass":
                     if (!_userinfo || Object.keys(_userinfo).length === 0) {
                         setTimeout(() => {
                             U.MD.U.L.login();
@@ -2660,8 +2672,25 @@ U.MD.D.I.openInApplication = function(str, data, screenType, tType) {
                         _taskbar = { "id": str + _formdiv.id, "style": { "backgroundImage": "url(/img/icon/evaluation.png)" }, "name": "數據報告", "forms": _formdiv, "click": function() { U.MD.D.I.openApplication(str, obj, info); } }
                         break;
                     }
+        case "opencCscl":
+                        if (!_userinfo || Object.keys(_userinfo).length === 0) {
+                            setTimeout(() => {
+                                U.MD.U.L.login();
+                            }, 2000);
+                        } else {
+                            _formdiv = new U.UF.UI.form(
+                                "協同建構",
+                                $$("iframe", { "allow": "camera *; microphone *;display-capture;midi;encrypted-media;", "webkitallowfullscreen": "", "mozallowfullscreen": "", "allowfullscreen": "", "frameborder": "no", "border": "0", "scrolling ": "no", "style": { "cssText": "border:0;width:100%;height:100%" }, "src": "https://cscl.cocorobo.cn?cid="+  data.cid + "&gid=" + data.gid }), {
+                                    "id": "futureClass",
+                                    "style": { "width": "90%", "height": "90%", "overflow": 'hidden' },
+                                    "onresize": function() {}
+                                }, {
+                                    closecallback: function() {}
+                                }, { "style": { "height": "36px" } }).form; //創建窗體
+                            _taskbar = { "id": str + _formdiv.id, "style": { "backgroundImage": "url(/img/icon/futureClass.png)" }, "name": "協同建構", "forms": _formdiv, "click": function() { U.MD.D.I.openApplication(str, obj, info); } }
+                            break;
+                        }
     }
-
 }
 U.MD.D.I.openApplication = function(str, obj, info) {
     obj = obj || {};
@@ -3104,7 +3133,7 @@ U.MD.D.I.openApplication = function(str, obj, info) {
 
                 _formdiv = new U.UF.UI.form(
                     "學生管理",
-                    $$("iframe", { "frameborder": "no", "border": "0", "scrolling ": "no", "style": { "cssText": "border:0;width:100%;height:100%" }, "src": US.Config.bpbl + "/pbl-teacher-table/dist/#/student?userid=" + _userid + "&oid=" + _oid + "&cid=" + _classId + "&org=" + _org }), {
+                    $$("iframe", { "frameborder": "no", "border": "0", "scrolling ": "no", "style": { "cssText": "border:0;width:100%;height:100%" }, "src": US.Config.bpbl + "/pbl-teacher-table/dist/#/student?userid=" + _userid + "&oid=" + _oid + "&cid=" + _classId + "&org=" + _org + "&role=" + _role }), {
                         "id": "student",
                         "style": { "width": "90%", "height": "90%", "overflow": 'hidden' },
                         "onresize": function() {}
@@ -3133,7 +3162,7 @@ U.MD.D.I.openApplication = function(str, obj, info) {
                     "目標管理",
                     $$("iframe", { "frameborder": "no", "border": "0", "scrolling ": "no", "style": { "cssText": "border:0;width:100%;height:100%" }, "src": US.Config.bpbl + "/pbl-teacher-table/dist/#/evaluation?userid=" + _userid + "&oid=" + _oid + "&org=" + _org }), {
                         "id": "sys",
-                        "style": { "width": "90%", "height": "90%", "overflow": 'hidden' },
+                        "style": { "width": "100%", "height": "100%", "overflow": 'hidden' },
                         "onresize": function() {}
                     }, {
                         closecallback: function() {}
@@ -3558,7 +3587,7 @@ U.MD.D.I.openApplication = function(str, obj, info) {
                     "目標管理",
                     $$("iframe", { "frameborder": "no", "border": "0", "scrolling ": "no", "style": { "cssText": "border:0;width:100%;height:100%" }, "src": US.Config.bpbl + "/pbl-teacher-table/dist/#/evaluation?userid=" + _userid + "&oid=" + _oid + "&org=" + _org }), {
                         "id": "sys",
-                        "style": { "width": "90%", "height": "90%", "overflow": 'hidden' },
+                        "style": { "width": "100%", "height": "100%", "overflow": 'hidden' },
                         "onresize": function() {}
                     }, {
                         closecallback: function() {}
@@ -4252,6 +4281,32 @@ U.MD.D.I.openApplication = function(str, obj, info) {
             }, { "style": { "height": "36px" } }).form; //創建窗體
             _taskbar = { "id": str + _formdiv.id, "style": { "backgroundImage": "url(/img/icon/AIChat.png)" }, "name": "AI協同", "forms": _formdiv, "click": function () { U.MD.D.I.openApplication(str, obj, info); } }
 
+            break;
+        case "futureClass": //AI共創
+            _formdiv = new U.UF.UI.form(
+                "協同建構",
+                $$("iframe", { "frameborder": "no", "border": "0", "scrolling ": "no", "webkitallowfullscreen": "", "mozallowfullscreen": "", "allowfullscreen": "", "style": { "cssText": "border:0;width:100%;height:100%" }, "src": US.Config.bpbl + "/pbl-teacher-table/dist/#/synergyCourse?userid=" + _userid + "&oid=" + _oid + "&org=" + _org + "&role=" + _role }), {//https://cscl.cocorobo.cn
+                    "id": "synergyCourse",
+                    "style": { "width": "100%", "height": "100%", "overflow": 'hidden' },
+                    "onresize": function() {}
+                }, {
+                    closecallback: function() {}
+                }, { "style": { "height": "36px" } }).form; //創建窗體
+            _taskbar = { "id": str + _formdiv.id, "style": { "backgroundImage": "url(/img/icon/futureClass.png)" }, "name": "協同建構", "forms": _formdiv, "click": function() { U.MD.D.I.openApplication(str, obj, info); } }
+
+            break;
+        case "dataBoard": //數據看板
+            _formdiv = new U.UF.UI.form(
+                "數據看板",
+                $$("iframe", { "frameborder": "no", "border": "0", "scrolling ": "no", "webkitallowfullscreen": "", "mozallowfullscreen": "", "allowfullscreen": "", "style": { "cssText": "border:0;width:100%;height:100%" }, "src": US.Config.bpbl + "/pbl-teacher-table/dist/#/dataBoard?userid=" + _userid + "&oid=" + _oid + "&org=" + _org + "&role=" + _role }), {
+                    "id": "dataBoard",
+                    "style": { "width": "100%", "height": "100%", "overflow": 'hidden' },
+                    "onresize": function() {}
+                }, {
+                    closecallback: function() {}
+                }, { "style": { "height": "36px" } }).form; //創建窗體
+            _taskbar = { "id": str + _formdiv.id, "style": { "backgroundImage": "url(/img/icon/dataBoard.png)" }, "name": "數據看板", "forms": _formdiv, "click": function() { U.MD.D.I.openApplication(str, obj, info); } }
+
             break;
         case "AIAnalyse": //AI共創
             _formdiv = new U.UF.UI.form(

+ 40 - 46
js/Office/Poll.js

@@ -1,6 +1,8 @@
 //轮训处理
 Namespace.register("U.MD.O.P");
 
+//设置是否允许连接
+U.MD.O.P.isconnect = true;
 /*
 * 链接后台,并发送请求
 */
@@ -12,13 +14,6 @@ U.MD.O.P.connect = function () {
             userName: US.userInfo.username,
             type: US.systemId
         })]);
-
-        // U.A.Request(US.SCOKET, ["login", JSON.stringify({     //发送登录请求
-        //     pageId: US.pageId,
-        //     userId: US.userInfo.userid,
-        //     userName: US.userInfo.username,
-        //     type: US.systemId
-        // })], U.MD.O.P.pollingAsyn);       //回调进   U.MD.O.P.pollingAsyn 函数
     }
 };
 
@@ -35,22 +30,24 @@ U.MD.O.P.dataAsyn = function () {
 * 发送请求进入轮训
 */
 U.MD.O.P.polling = function (params) {
-    params = params || ["polling", US.userInfo.userid, US.pageId, US.systemId]
-    var start = 0;
-    var delimiter = "\r\n"
-    var end = 0;
-    var text = "";
-    var xhr = new XMLHttpRequest();
-    var data = "";
-    xhr.open("POST", US.SCOKET, true);
-    xhr.onreadystatechange = function () {
-        //获取数据
-        if (xhr.readyState == 3 && xhr.status == 200) {
+    if (U.MD.O.P.isconnect) {
+        U.MD.O.P.isconnect = false;
+        params = params || ["polling", US.userInfo.userid, US.pageId, US.systemId]
+        var start = 0;
+        var delimiter = "\r\n"
+        var end = 0;
+        var text = "";
+        var xhr = new XMLHttpRequest();
+        var data = "";
+        //var time = null;
+        //
+        var fun = function () {
+            //clearTimeout(time)
             text = xhr.responseText;
             var istrue = true;
             while (start < text.length && istrue) {
                 end = text.indexOf(delimiter, start);//获取数据的是否已经结束
-                if (end) {
+                if (end > -1) {
                     data += text.substring(start, end);
                     start = end + delimiter.length;
                     try {
@@ -63,40 +60,37 @@ U.MD.O.P.polling = function (params) {
                 }
                 else {
                     istrue = false;
+                    //time = setTimeout(fun, 500);//
                 }
             }
-            //clearTimeout(time);
-
-            //只有抓取到数据结束后才执行,防止网络太卡或者数据太大的不完整的获取导致后续无法执行
-
+        };
+        xhr.open("POST", US.SCOKET, true);
+        xhr.onreadystatechange = function () {
+            //获取数据
+            if (xhr.readyState == 3 && xhr.status == 200) {
+                fun();
+            }
+            //结束重连
+            else if (xhr.readyState == 4) {
+                console.log(xhr);
+                U.MD.O.P.isconnect = true;
+                U.MD.O.P.connect();
+            }
+        };
+        //超时重新连接
+        xhr.onerror = function (err) {
+            console.log(err);
+        };
+        try {
+            //发送请求
+            xhr.send(U.A.Request.toAjaxFormat(params));
         }
-        //结束重连
-        else if (xhr.readyState == 4) {
-            console.log(xhr);
-            U.MD.O.P.polling();
+        catch (e) {
+            console.log(e);
         }
-    };
-    //超时重新连接
-    xhr.onerror = function (err) {
-        console.log(err);
-        //U.MD.O.P.polling();
-    };
-    try {
-        //发送请求
-        xhr.send(U.A.Request.toAjaxFormat(params));
     }
-    catch (e) {
-        console.log(e);
-        //U.MD.O.P.polling();
-    }
-
-    // U.A.Request(US.SCOKET, ["polling", US.userInfo.userid, US.pageId, US.systemId], U.MD.O.P.pollingAsyn);
-    //     //发送轮循  回调进  U.MD.O.P.pollingAsyn函数
-    // }
 }
 
-
-
 /* 
 * 处理从后台返回的数据
 *

+ 123 - 65
node/message.js

@@ -89,6 +89,21 @@ us.nav = {
     //}  //导航文档数据结构
 }
 
+//知识建构的数据结构
+us.cscldata = function () {
+    return {
+        id: "",
+        userid: "",
+        name: "",
+        num: "",
+        data: "",
+        isClose: "",
+        create_at: "",
+        createuser: "",
+        smailheadportrait: ""
+    };
+}
+
 /**
 * 用户链接类
 *
@@ -401,6 +416,7 @@ us.addUser = function (response, type, fileid, userids, userid, pageid) {
 **/
 us.getuserbytype = function (userids) {
     var _userinfo = [];
+    //console.log(us.user);
     for (var i in userids) {
         if (us.user[i]) {
             _userinfo.push(us.user[i])
@@ -482,7 +498,7 @@ us.unifyDispose = function (req, res, cb) {
     });
 
     //设置30秒后超时
-    res.setTimeout(30000, function () {
+    res.setTimeout(60000, function () {
         try {
             //console.log("响应超时.");
             res.end(""); //返回值
@@ -537,13 +553,12 @@ us.deluser = function (userid, pageid) {
         //其他应用的数据
         // _wordids = us.offLineMessage[pageid].word, //得到加入的所有word
         // _excelids = us.offLineMessage[pageid].excel; //得到加入的所有excel
-
+        console.log("1111111111111")
+        console.log(_csclids)
         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]]; //记录文档信息
@@ -592,15 +607,15 @@ us.deluser = function (userid, pageid) {
 us.offLine = function () {
     var i, j, istrue = true;
     var _user, _connect = us.connect;
-    console.log(_connect)
     //循环目前所有的连接用户
     for (i in _connect) {
         _user = _connect[i];
         for (j in _user) {
-            console.log(j)
-            //console.log(_user[j].response.connection)
             //判断用户已下线
             if (_user[j].response.connection == null || _user[j].response.connection.destroyed) {
+                console.log("================2===============");
+                console.log(i);
+                console.log(j);
                 us.deluser(i, j); //删除用户的数据
                 delete _user[j]
             }
@@ -629,33 +644,47 @@ us.polling = function (requset, response, userid, pageid, type) {
     //     console.log("--------" + userid + "-------------" + pageid);
     //     //us.offLine(response, userid, pageid)
     // });
-
     //判断轮询的用户是否在连接池中
     if (us.connect[userid]) {
-        var _userarray = us.connect[userid], //用户连接池,获取制定用户连接的数量,
+        var _data,
+            _userarray = us.connect[userid], //用户连接池,获取制定用户连接的数量,
             _messagearray = us.offLineMessage[pageid] //用户离线信息
             ;
+        const chunkSize = 100;
         //获取当前连接的用户,如果获取成功那么直接修改用户的连接
         if (_userarray[pageid]) {
+            //防止重复多连
+            try {
+                _userarray[pageid].response.end("");
+            }
+            catch (e) {
+
+            }
             _userarray[pageid].response = response;
             if (_messagearray && _messagearray.message.length > 0) {
-                response.write(JSON.stringify(_messagearray.message) + "\r\n");
+                _data = JSON.stringify(_messagearray.message);
+                for (let i = 0; i < _data.length; i += chunkSize) {
+                    const chunk = _data.slice(i, i + chunkSize);
+                    response.write(chunk);
+                }
+                response.write("\r\n");
                 _messagearray.message = [];
             }
             else {
-                us.offLineMessage[pageid] = us.userOffLineMessage(type); //初始化用户离线消息记录
+                us.offLineMessage[pageid] = us.offLineMessage[pageid] || us.userOffLineMessage(type); //初始化用户离线消息记录
             }
-            return;
         }
-        //如果用户连接不存在
-        _userarray[pageid] = us.userConnect(pageid, response); //那么直接添加用户连接 添加到用户连接数组里
-        us.offLineMessage[pageid] = us.userOffLineMessage(type); //初始化用户离线消息记录
+        else {
+            //如果用户连接不存在
+            _userarray[pageid] = us.userConnect(pageid, response); //那么直接添加用户连接 添加到用户连接数组里
+            us.offLineMessage[pageid] = us.userOffLineMessage(type); //初始化用户离线消息记录
+        }
     }
     else {
         var _userconect = us.userConnect(pageid, response); //创建用户连接对象
         us.connect[userid] = {}; //添加用户连接对象
         us.connect[userid][pageid] = _userconect;
-        us.offLineMessage[pageid] = us.userOffLineMessage(type); //初始化用户离线消息记录
+        us.offLineMessage[pageid] = us.offLineMessage[pageid] || us.userOffLineMessage(type); //初始化用户离线消息记录
     }
 }
 
@@ -697,9 +726,23 @@ us.send = function (response, messageinfo) {
                 break;
             //未来课堂交互
             case "us.cscl":
+
                 _messagearr = _messageobj[i]; //获取未来消息
-                //得到word所有的用户
+                //得到未来课堂所有的用户
                 for (j = 0; j < _messagearr.length; j++) {
+                    // //如果存在则直接返回内层的文档
+                    // if (!us.cscl[calssid].user[userid]) {
+                    //     us.cscl[calssid].user[userid] = [pageid];
+                    // }
+                    // else if (us.cscl[calssid].user[userid].indexOf(pageid) == -1) {
+                    //     us.cscl[calssid].user[userid].push(pageid);
+                    // }
+                    // try {
+                    //     us.offLineMessage[pageid].cscl.indexOf(calssid) == -1 && us.offLineMessage[pageid].cscl.push(calssid); //添加到用户离线消息的连接wrod记录中
+                    // }
+                    // catch (e) {
+
+                    // }
                     _messagearr[j].messageInfo.type = _messagearr[j].type;
                     //生成发送的消息结构体
                     _message = us.message(_messagearr[j].sendId, "us.cscl", _messagearr[j].messageInfo);
@@ -834,51 +877,58 @@ us.updatemindNetwork = function (messageInfo) {
 * @param {object} message 消息信息
 */
 us.updatecscl = function (messageInfo, classId, ty) {
-    //messageInfo = messageInfo;
     if (us.cscl[classId]) {
         var i, j, _is;
         var _obj = us.cscl[classId].content;
-        _obj.backgroundUrl = messageInfo.backgroundUrl;
-        _obj.edges = _obj.edges || [];
-        _obj.nodes = _obj.nodes || [];
-        // console.log("------------s------------");
-        // console.log(messageInfo);
-        // console.log(_obj);
-        // console.log(ty);
-        for (j = 0; j < messageInfo.edges.length; j++) {
-            _is = true;
-            for (i = 0; i < _obj.edges.length; i++) {
-                if (_obj.edges[i].id == messageInfo.edges[j].id) {
-                    if (ty == "update") {
-                        _obj.edges[i] = messageInfo.edges[j];
-                    }
-                    else {
-                        _obj.edges.splice(i, 1);
+        if (ty == "clean") {
+            _obj = us.cscl[classId].content = {};
+        }
+        else {
+            _obj.backgroundUrl = messageInfo.backgroundUrl;
+            _obj.edges = _obj.edges || [];
+            _obj.nodes = _obj.nodes || [];
+            //循环线的处理
+            for (j = 0; j < messageInfo.edges.length; j++) {
+                _is = true;
+                for (i = 0; i < _obj.edges.length; i++) {
+                    if (_obj.edges[i].id == messageInfo.edges[j].id) {
+                        //如果是修改线同时先又存在那就直接修改
+                        if (ty == "update") {
+                            _obj.edges[i] = messageInfo.edges[j];
+                        }
+                        //如果是删除线的操作
+                        else {
+                            _obj.edges.splice(i, 1);
+                        }
+                        _is = false;
+                        break;
                     }
-                    _is = false;
-                    break;
+                }
+                //修改包含了添加和修改,如果没有修改说明是添加的功能
+                if (_is && ty == "update") {
+                    _obj.edges.push(messageInfo.edges[j])
                 }
             }
-            if (_is && ty == "update") {
-                _obj.edges.push(messageInfo.edges[j])
-            }
-        }
-        for (j = 0; j < messageInfo.nodes.length; j++) {
-            _is = true;
-            for (i = 0; i < _obj.nodes.length; i++) {
-                if (_obj.nodes[i].id == messageInfo.nodes[j].id) {
-                    if (ty == "update") {
-                        _obj.nodes[i] = messageInfo.nodes[j];
-                    }
-                    else {
-                        _obj.nodes.splice(i, 1);
+            for (j = 0; j < messageInfo.nodes.length; j++) {
+                _is = true;
+                for (i = 0; i < _obj.nodes.length; i++) {
+                    if (_obj.nodes[i].id == messageInfo.nodes[j].id) {
+                        //如果是修改节点
+                        if (ty == "update") {
+                            _obj.nodes[i] = messageInfo.nodes[j];
+                        }
+                        //如果是删除节点
+                        else {
+                            _obj.nodes.splice(i, 1);
+                        }
+                        _is = false;
+                        break;
                     }
-                    _is = false;
-                    break;
                 }
-            }
-            if (_is && ty == "update") {
-                _obj.nodes.push(messageInfo.nodes[j])
+                //修改包含了添加和修改,如果没有修改说明是添加的功能
+                if (_is && ty == "update") {
+                    _obj.nodes.push(messageInfo.nodes[j])
+                }
             }
         }
         //如果不存在则去数据库查找
@@ -1526,12 +1576,14 @@ us.senduser = function (userid, messageinfo) {
 **/
 us.broadcast = function (messageinfo, pageid, type) {
     var i, j, o, //循环变量
+        _data,
         _messageinfo, //消息信息
         _users, //用户ID集合
         _pageids, //用户页面唯一识别集合
         _recievedpageid, //接收用户的页面唯一识别ID
         _issend, // 是否发送
         _userconnect = us.connect; //用户连接池
+    const chunkSize = 100;
     for (i in messageinfo) {
         _messageinfo = messageinfo[i]; //记录消息消息b
         _users = us[type][i] ? us[type][i].user : {}; //记录用户集合
@@ -1543,11 +1595,19 @@ us.broadcast = function (messageinfo, pageid, type) {
                     try {
                         if (_userconnect[j] && _userconnect[j][_recievedpageid]) {
                             console.log(_recievedpageid);
-                            _issend = _userconnect[j][_recievedpageid].response.write(JSON.stringify(_messageinfo) + "\r\n"); //发送消息
+                            _data = JSON.stringify(_messageinfo);
+                            _issend = _userconnect[j][_recievedpageid].response.write(""); //发送消息
                             //用户在轮询切换的时候的中间,会产生数据无法接受,这里是存储数据
                             if (!_issend) {
                                 us.offLineMessage[_recievedpageid].message.push(_messageinfo); //将消息加入用户离线消息中
                             }
+                            else {
+                                for (let i = 0; i < _data.length; i += chunkSize) {
+                                    const chunk = _data.slice(i, i + chunkSize);
+                                    _userconnect[j][_recievedpageid].response.write(chunk);
+                                }
+                                _userconnect[j][_recievedpageid].response.write("\r\n");
+                            }
                         }
                     }
                     catch (e) {
@@ -1637,8 +1697,7 @@ us.quitcscl = function (response, info) {
     var _docid = info.docId,
         _userid = info.userId,
         _pageid = info.pageId,
-        _type = info.type,
-        _messagetype = 'us.cscl';
+        _type = info.type;
     var _docinfo = us[_type][_docid]; //获取文档信息
     //判断是否存在文档信息
     if (_docinfo) {
@@ -2166,20 +2225,17 @@ us.getcscl = function (response, calssid, pageid, userid) {
         catch (e) {
 
         }
-        //如果不存在则去数据库查找
+        //后续优化到redis获取
         us.mysql.usselect(['172.16.12.5', 'pbl', 'select_room', calssid],
             function (ret) {
                 var _user = us.getuserbytype(us.cscl[calssid].user); //获取当前项目下所有的用户信息
                 var _data = us.cscl[calssid].content; //保存在内存的知识建构数据
                 if (ret) {
-                    //console.log("eeee");
-                    //console.log(us.offLineMessage[pageid]);
                     ret[0][0].user = _user; //这里是项目当前所有用户
                     ret[0][0].data = _data; //把思维网格的内容转化成数组
                     if (userid && us.user[userid]) {
                         us.sendUser(us.user[userid], "cscl", pageid, calssid); //加入知识建构项目后通知所有的用户
                     }
-                    //console.log(ret[0][0].user)
                     response.end(JSON.stringify(ret)); //返回文档内容
                 }
                 else {
@@ -2201,11 +2257,13 @@ us.getcscl = function (response, calssid, pageid, userid) {
             function (ret) {
                 var _user = us.getuserbytype(us.cscl[calssid].user);
                 if (ret) {
-                    //console.log("bbbbbbbbbbbbbbb");
-                    //console.log(us.offLineMessage[pageid]);
                     ret[0][0].user = _user; //这里是项目当前所有用户
-                    us.cscl[calssid].content = JSON.parse(ret[0][0].data); //把思维网格的内容转化成数组
-                    //us.sendUser(us.user[userid], "cscl", pageid, calssid); //加入知识建构项目后通知所有的用户
+                    try {
+                        us.cscl[calssid].content = JSON.parse(ret[0][0].data); //把思维网格的内容转化成数组
+                    }
+                    catch (e) {
+                        us.cscl[calssid].content = ret[0][0].data;
+                    }
                     response.end(JSON.stringify(ret)); //返回文档内容
                 }
                 else {

+ 4 - 18
node/mysql.js

@@ -30,19 +30,13 @@ exports.usselect = function (param, callback) {
         console.log(param);
         _mysqlconnection.getConnection(function (error, connection) { //获取连接
             if (error) { //连接错误
-                console.log("连接失败:", error);
+                console.error("连接失败:", error);
             } else { //连接成功
-                for (i = 0; i < param.length; i++) {
-                    param[i] = decodeURIComponent(param[i]);
-
-                } //格式化处理参数
-                var i, _sql = "CALL ";
+                var _sql = "CALL ";
                 var _param = new Array();
                 if (param.length > 3) { //带有参数的sql语句  如:'call test(?, ?, ?);'
                     _param = param.slice(3) //截取有效参数
-                    _sql += (param[2] || "") + "(?"; //拼接存储过程名称 
-                    //_s += (p[2] || "") + "('" + p.slice(3).join("','") + "');";
-                    //, + ? 拼接参数 该方法拼接后比数组长度少一因此上一句代码中默认拼接了第一个参数
+                    _sql += (param[2] || "") + "(?"; //拼接存储过程名称
                     _sql += Array(_param.length).join(",?");
                     _sql += ");"; //拼接结果语句
                 } else { //不带参数的sql语句 如:'call test();'
@@ -51,18 +45,10 @@ exports.usselect = function (param, callback) {
                 console.log("拼凑的MySQl语句为:", _sql);
                 connection.query(_sql, _param, function (error, results, fields) { //执行sql语句 
                     if (results) {
-                        // if (results.pop) {
-                        //     results.pop();
-                        // }
-                        //console.log(JSON.stringify(results)); 输出结果集
-                        //执行回调函数
-                        //results.affectedRows != null 如果受影响行不等于null(空) 则返回受影响行数
-                        //results.affectedRows != null 如果受影响行不等于null(空) 则返回受影响行数
-                        //results.length > 1 ? results : results[0] 如果结果集为单行则直接返回Object对象 否则返回数组对象
                         callback(results.affectedRows != null ? results.affectedRows : results.length > 1 ? results : results[0]);
                     }
                     else { //执行错误
-                        console.log("sql执行失败", error || "");
+                        console.error("sql执行失败", error || "");
                         callback(error);
                     }
                 });

+ 35 - 9
node/test.js

@@ -4,8 +4,10 @@ us = {};
 
 // 引入Express模块
 const express = require('express');
+const qs = require('qs');
 const path = require('path');
 us.http = require("http"); //引用http server服务
+const http = require('http');
 // 创建Express应用
 const app = express();
 
@@ -13,23 +15,47 @@ const app = express();
 app.use(express.static(path.join(__dirname, '/')));
 
 
-us.server = us.http.createServer(function (req, res) {
+us.server = us.http.createServer(function (reqo, reso) {
     // 定义路由
     // app.all('/', (req, res) => {
     //设置跨域
-    res.writeHead(200, {
+    reso.writeHead(200, {
         "Content-Type": "application/json",
         'Access-Control-Allow-Origin': '*',
         "Connection": "keep-alive",
         'Access-Control-Allow-Headers': 'Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With'
     });
-    var data = [{ "name": "John", "age": 30 }];
-    for (var i = 0; i < 100; i++) {
-        data.push(data[0]);
-    }
-    setInterval(function () {
-        res.write(JSON.stringify(data));
-    }, 2000);
+
+    //  http://apis.ssti.net.cn:80/taskcenterapp/sys/taskCenter/taskReceive/pushTask.do
+
+    const options = {
+        hostname: 'apis.ssti.net.cn',
+        port: 80,
+        path: '/taskcenterapp/sys/taskCenter/taskReceive/pushTask.do',
+        method: 'POST',
+        headers: {
+            'Content-Type': 'application/x-www-form-urlencoded',
+            'appId': '36dd21cde3b2f30a',
+            'accessToken': '463e95bdad1a9506bd1b271194f89383'
+        }
+    };
+
+    const req = http.request(options, (res) => {
+        console.log(`statusCode: ${res.statusCode}`);
+
+        res.on('data', (data) => {
+            console.log(data.toString());
+        });
+    });
+
+    req.on('error', (error) => {
+        console.error(error);
+    });
+
+    const bodyData = qs.stringify({ appId: "36dd21cde3b2f30a", taskInfo: '{"inserttasks":[{"app_id":"test11","assignments":[{"assign_dept":"图书部门","assign_id":"ampadmin","assign_name":"ampadmin"}],"biz_domain":"测试部门","biz_key":"bizkey_1000112","created_by_depts":"图书部门","created_by_ids":"ampadmin","created_by_names":"ampadmin","created_on":"2018-01-16 15:06:18","form_url":"https://baidu.com","form_url_view":"https://baidu.com","node_id":"1000112","node_name":"人事审核","priority":0,"process_delete_flag":0,"process_id":"leave_1233211932","process_instance_form_view":"https://taobao.com","process_instance_id":"1233211932","process_instance_image_url":"https://baidu.com","process_instance_initiator":"ampadmin","process_instance_initiator_dp":"图书部门","process_instance_initiator_id":"ampadmin","process_instance_start_date":"2018-01-16 15:06:18","process_instance_status":"RUNNING","process_instance_subject":"请假流程:ampadmin","process_name":"请假流程","process_version":"1.0","status":"ACTIVE","subject":"test_发起请假流程-tstsysys","task_delete_flag":0,"task_id":"1000112"}],"updatetasks":[]}' });
+    req.write(bodyData);
+    req.end();
+    reso.end("")
 });
 
 // 启动服务器