root 1 year ago
parent
commit
70857707f7
2 changed files with 11 additions and 29 deletions
  1. 7 11
      node/message.js
  2. 4 18
      node/mysql.js

+ 7 - 11
node/message.js

@@ -841,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);
                     }
@@ -866,6 +864,7 @@ us.updatecscl = function (messageInfo, classId, ty) {
                     break;
                 }
             }
+            //修改包含了添加和修改,如果没有修改说明是添加的功能
             if (_is && ty == "update") {
                 _obj.edges.push(messageInfo.edges[j])
             }
@@ -874,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);
                     }
@@ -884,6 +885,7 @@ us.updatecscl = function (messageInfo, classId, ty) {
                     break;
                 }
             }
+            //修改包含了添加和修改,如果没有修改说明是添加的功能
             if (_is && ty == "update") {
                 _obj.nodes.push(messageInfo.nodes[j])
             }
@@ -2178,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 {
@@ -2207,15 +2206,12 @@ 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; //这里是项目当前所有用户
                     try {
                         us.cscl[calssid].content = JSON.parse(ret[0][0].data); //把思维网格的内容转化成数组
                     }
                     catch (e) {
                         us.cscl[calssid].content = ret[0][0].data;
-                        //us.cscl[calssid].content = {};
                     }
                     response.end(JSON.stringify(ret)); //返回文档内容
                 }

+ 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);
                     }
                 });