Просмотр исходного кода

Merge branch 'beta' of https://git.cocorobo.cn/CocoRoboLabs/CocoRoboDesktop into beta

lsc 1 год назад
Родитель
Сommit
905cb9567b
4 измененных файлов с 120 добавлено и 112 удалено
  1. 47 58
      js/Office/Poll.js
  2. 34 27
      node/message.js
  3. 4 18
      node/mysql.js
  4. 35 9
      node/test.js

+ 47 - 58
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,64 +30,58 @@ 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) {
-            text = xhr.responseText;
-            var istrue = true;
-            while (start < text.length && istrue) {
-                end = text.indexOf(delimiter, start);//获取数据的是否已经结束
-                if (end) {
-                    data += text.substring(start, end);
-                    start = end + delimiter.length;
-                    try {
-                        U.MD.O.P.pollingAsyn({ value: JSON.parse(data) })
+    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 = "";
+        xhr.open("POST", US.SCOKET, true);
+        xhr.onreadystatechange = function () {
+            //获取数据
+            if (xhr.readyState == 3 && xhr.status == 200) {
+                text = xhr.responseText;
+                var istrue = true;
+                while (start < text.length && istrue) {
+                    end = text.indexOf(delimiter, start);//获取数据的是否已经结束
+                    if (end > -1) {
+                        data += text.substring(start, end);
+                        start = end + delimiter.length;
+                        try {
+                            U.MD.O.P.pollingAsyn({ value: JSON.parse(data) })
+                        }
+                        catch (e) {
+                            console.log(e);
+                        }
+                        data = "";
                     }
-                    catch (e) {
-                        console.log(e);
+                    else {
+                        istrue = false;
                     }
-                    data = "";
-                }
-                else {
-                    istrue = false;
                 }
             }
-            //clearTimeout(time);
-
-            //只有抓取到数据结束后才执行,防止网络太卡或者数据太大的不完整的获取导致后续无法执行
-
+            //结束重连
+            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函数
-    // }
 }
 
 

+ 34 - 27
node/message.js

@@ -401,6 +401,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])
@@ -537,13 +538,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 +592,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,7 +629,6 @@ 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], //用户连接池,获取制定用户连接的数量,
@@ -637,25 +636,33 @@ us.polling = function (requset, response, userid, pageid, type) {
             ;
         //获取当前连接的用户,如果获取成功那么直接修改用户的连接
         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");
                 _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); //初始化用户离线消息记录
     }
 }
 
@@ -834,24 +841,22 @@ 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);
                     }
@@ -859,6 +864,7 @@ us.updatecscl = function (messageInfo, classId, ty) {
                     break;
                 }
             }
+            //修改包含了添加和修改,如果没有修改说明是添加的功能
             if (_is && ty == "update") {
                 _obj.edges.push(messageInfo.edges[j])
             }
@@ -867,9 +873,11 @@ us.updatecscl = function (messageInfo, classId, ty) {
             _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);
                     }
@@ -877,6 +885,7 @@ us.updatecscl = function (messageInfo, classId, ty) {
                     break;
                 }
             }
+            //修改包含了添加和修改,如果没有修改说明是添加的功能
             if (_is && ty == "update") {
                 _obj.nodes.push(messageInfo.nodes[j])
             }
@@ -1637,8 +1646,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) {
@@ -2172,14 +2180,11 @@ us.getcscl = function (response, calssid, pageid, userid) {
                 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 +2206,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("")
 });
 
 // 启动服务器