Bläddra i källkod

清单库sectionInfo debug

zhongzewei 7 år sedan
förälder
incheckning
88a9c2772f

+ 6 - 0
modules/bills_lib/controllers/bills_lib_controllers.js

@@ -96,6 +96,12 @@ module.exports = {
             callback(req, res, err, message, null);
         });
     },
+    updateSectionInfo: function (req, res) {
+        let data = JSON.parse(req.body.data);
+        billsLibDao.updateSectionInfo(data, function(err, message){
+            callback(req, res, err, message, null);
+        });
+    },
     updateBills: function(req, res){
         let data = JSON.parse(req.body.data);
         billsLibDao.updateBills(data, function(err, message){

+ 3 - 0
modules/bills_lib/controllers/bills_permissionController.js

@@ -32,6 +32,9 @@ class billsPermContr extends baseController{
     updateBills(req, res){
         billsController.updateBills(req, res);
     }
+    updateSectionInfo(req, res){
+        billsController.updateSectionInfo(req, res);
+    }
     updateBillsArr(req, res){
         billsController.updateBillsArr(req, res);
     }

+ 32 - 4
modules/bills_lib/models/bills_lib_interfaces.js

@@ -482,7 +482,7 @@ billsLibDao.prototype.upLevel = function(data, callback){
         },
         oprNode: function (data) {
             return function (cb){
-                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {ParentID: data.ParentID, NextSiblingID: data.NextSiblingID, sectionInfo: data.sectionInfo}}, function(err){
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {ParentID: data.ParentID, NextSiblingID: data.NextSiblingID, sectionInfo: data.sectionInfo?data.sectionInfo:null}}, function(err){
                     if(err){
                         cb(err);
                     }
@@ -538,7 +538,7 @@ billsLibDao.prototype.upLevel = function(data, callback){
         }
         else if(updateDatas[i].type === 'nextSiblingNode'){
             updateDatas[i].ID.forEach(function (id) {
-                let obj = {ID: id, ParentID: updateDatas[i].ParentID, sectionInfo: updateDatas[i].sectionInfo};
+                let obj = {ID: id, ParentID: updateDatas[i].ParentID, sectionInfo: updateDatas[i].sectionInfo ? updateDatas[i].sectionInfo : null };
                 functions.push(parallelFucs.nextSiblingNode(obj));
             });
         }
@@ -598,7 +598,7 @@ billsLibDao.prototype.downLevel = function (data, callback) {
         },
         oprNode: function (data) {
             return function (cb) {
-                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {ParentID: data.ParentID, NextSiblingID: data.NextSiblingID, sectionInfo: data.sectionInfo}}, function (err) {
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {ParentID: data.ParentID, NextSiblingID: data.NextSiblingID, sectionInfo: data.sectionInfo?data.sectionInfo:null}}, function (err) {
                     if(err){
                         cb(err);
                     }
@@ -622,7 +622,7 @@ billsLibDao.prototype.downLevel = function (data, callback) {
         },
         oprChildren: function (data) {
             return function (cb) {
-                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {sectionInfo: data.sectionInfo}}, function (err) {
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {sectionInfo: data.sectionInfo?data.sectionInfo:null}}, function (err) {
                     if(err){
                         cb(err);
                     }
@@ -719,6 +719,34 @@ billsLibDao.prototype.updatePNId= function(upData, callback){
         });
 }
 
+billsLibDao.prototype.updateSectionInfo = function (data, callback) {
+    let functions = [];
+    let updateData = data.updateData;
+    for(let ud of updateData){
+        functions.push((function(udData){
+            return function(cb){
+                Bills.update({ID: udData.ID}, {$set: udData}, function(err){
+                    if(err){
+                        cb(err);
+                    }
+                    else{
+                        cb(null);
+                    }
+                });
+            };
+        })(ud));
+    }
+    async.parallel(functions, function(err, results) {
+        let errCode = 0,
+            errMsg = '';
+        if(err){
+            errCode = 1;
+            errMsg = 'Error'
+        }
+        callback(errCode, errMsg);
+    });
+};
+
 billsLibDao.prototype.updateBills = function(ubillsData, callback){
     let billsLibId = ubillsData.billsLibId;
     let updateId = ubillsData.updateId;

+ 1 - 0
modules/bills_lib/routes/bills_lib_routes.js

@@ -39,6 +39,7 @@ module.exports =function (app) {
      billsRouter.post("/upLevel", billsContr.auth, billsContr.init, billsContr.upLevel);
      billsRouter.post("/downLevel", billsContr.auth, billsContr.init, billsContr.downLevel);
      billsRouter.post("/updateBills", billsContr.auth, billsContr.init, billsContr.updateBills);
+     billsRouter.post("/updateSectionInfo", billsContr.auth, billsContr.init, billsContr.updateSectionInfo);
      billsRouter.post("/updateBillsArr", billsContr.auth, billsContr.init, billsContr.updateBillsArr);
      billsRouter.post("/removeTotal", billsContr.auth, billsContr.init, billsContr.removeTotal);
      billsRouter.post("/updateSerialNo", billsContr.auth, billsContr.init, billsContr.updateSerialNo);

+ 13 - 0
web/maintain/bills_lib/scripts/bills_lib_ajax.js

@@ -292,6 +292,19 @@ var billsAjax = {
             }
         });
     },
+    updateSectionInfo: function(data, callback){
+        $.ajax({
+            type: 'post',
+            url: 'stdBillsEditor/updateSectionInfo',
+            data: {data: JSON.stringify({updateData: data})},
+            dataType: 'json',
+            success: function(result){
+                if(!result.error && callback){
+                    callback();
+                }
+            }
+        });
+    },
     removeTotal: function (lastOperator, billsLibId, billsIds, delIds, field) {
         $.ajax({
             type: 'post',

+ 65 - 95
web/maintain/bills_lib/scripts/db_controller.js

@@ -68,6 +68,7 @@ var dbController = {
         var updateData = [];
         let selNodes = tools.getSameDepthNodes(controller);
         let nextSiblings = [];
+        let toUpSectionNodes = [];
         let getNextSibling = function(node){
             if(node.nextSibling){
                 nextSiblingIds.push(node.getNextSiblingID());
@@ -105,40 +106,10 @@ var dbController = {
                     updateData.push({
                         ID: nextSiblingIds,
                         ParentID: lastSelNode.getID(),
-                        sectionInfo: nextSectionInfo,
+                        //sectionInfo: nextSectionInfo,
                         type: 'nextSiblingNode'
                     });
                     //nextSibling children
-                    for(let nextSibling of nextSiblings){
-                        let nextChildSectionInfo = {first: nextSectionInfo.first, second: nextSectionInfo.second, third: nextSectionInfo.third};
-                        let nextCFlag = false;
-                        let nullNextCInfo = tools.sectionInfoNull(nextChildSectionInfo);
-                        if(nullNextCInfo){
-                            nextChildSectionInfo[nullNextCInfo] = nextSibling.getID();
-                            nextCFlag = true;
-                        }
-                        if(nextCFlag){
-                            let nextCIds = [];
-                            for(let nextChild of nextSibling.children){
-                                nextCIds.push(nextChild.getID());
-                                //nextSibling grandChildren
-                                let nextGChildSectionInfo = {first: nextChildSectionInfo.first, second: nextChildSectionInfo.second, third: nextChildSectionInfo.third};
-                                let nextGCFlag = false;
-                                if(!tools.isDef(nextChildSectionInfo.third)){
-                                    nextGChildSectionInfo.third = nextChild.getID();
-                                    nextGCFlag = true;
-                                }
-                                if(nextGCFlag){
-                                    let nextGCIds = [];
-                                    for(let nextGChild of nextChild.children){
-                                        nextGCIds.push(nextGChild.getID());
-                                    }
-                                    updateData.push({ID: nextGCIds, ParentID: nextChild.getID(), sectionInfo: nextGChildSectionInfo, type: 'nextSiblingNode'});
-                                }
-                            }
-                            updateData.push({ID: nextCIds, ParentID: nextSibling.getID(), sectionInfo: nextChildSectionInfo, type: 'nextSiblingNode'});
-                        }
-                    }
                 }
                 //更新选中节点
                 console.log(selNodes);
@@ -153,49 +124,43 @@ var dbController = {
                         type: 'oprNode'
                     });
                     //update node children and grandchildren sectionInfo
-                    let nullOprSectionInfo = tools.sectionInfoNull(oprSectionInfo);
-                    if(nullOprSectionInfo){
-                        let oprChildSectionInfo = {first: oprSectionInfo.first, second: oprSectionInfo.second, third: oprSectionInfo.third};
-                        oprChildSectionInfo[nullOprSectionInfo] = selNode.getID();
-                        let oprChildIds = [];
-                        for(let oprChild of selNode.children){
-                            oprChildIds.push(oprChild.getID());
-                            let nullOprCSectionInfo = tools.sectionInfoNull(oprChildSectionInfo);
-                            if(nullOprCSectionInfo){
-                                let oprGCSectionInfo = {first: oprChildSectionInfo.first, second: oprChildSectionInfo.second, third: oprChildSectionInfo.third};
-                                oprGCSectionInfo[nullOprCSectionInfo] = oprChild.getID();
-                                let oprGCIds = [];
-                                for(let oprGChild of oprChild.children){
-                                    oprGCIds.push(oprGChild.getID());
-                                }
-                                if(oprGCIds.length > 0){
-                                    updateData.push({ID: oprGCIds, ParentID: oprChild.getID(), sectionInfo: oprGCSectionInfo, type: 'nextSiblingNode'});
-                                }
-                            }
-                        }
-                        if(oprChildIds.length > 0){
-                            updateData.push({ID: oprChildIds, ParentID: selNode.getID(), sectionInfo: oprChildSectionInfo, type: 'nextSiblingNode'});
-                        }
-                    }
                 }
+                //get updateSectionInfo nodes
+                toUpSectionNodes = toUpSectionNodes.concat(selNodes);//选中的节点
+                //选中节点的所有子节点
+                toUpSectionNodes = toUpSectionNodes.concat(tools.getChildrenNodes(selNodes));
+                //后兄弟节点
+                toUpSectionNodes = toUpSectionNodes.concat(nextSiblings);
+                //所有后兄弟节点的所有子节点
+                toUpSectionNodes = toUpSectionNodes.concat(tools.getChildrenNodes(nextSiblings));
+
                 billsAjax.upLevel(userAccount, billsLibId, updateData, function(){
-                    tools.btnAction(btn);
-                    btn.attr('doing', 'false');
+                    //tools.btnAction(btn);
+                    //btn.attr('doing', 'false');
                     for(let upLevelNode of selNodes){
                         controller.setTreeSelected(upLevelNode);
                         controller.upLevel();
                     }
                     sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
                     controller.sheet.getParent().focus(true);
+                    //updateSectionInfo
+                    if(toUpSectionNodes.length > 0){
+                        billsAjax.updateSectionInfo(tools.getUpdateSectionData(toUpSectionNodes), function () {
+                            tools.btnAction(btn);
+                            btn.attr('doing', 'false');
+                        });
+                    }
                 });
             }
         }
     },
+
     downLevel: function(controller, btn){
         tools.btnClose(btn);
         btn.attr('doing', 'true');
         var updateData = [];
         let selNodes = tools.getSameDepthNodes(controller);
+        let toUpSectionNodes = [];
         if(selNodes.length > 0){
             //选中的第一个节点有前节点,则可降级
             let firstPreSibling = selNodes[0].preSibling;
@@ -215,57 +180,36 @@ var dbController = {
                 }
                 for(let i = 0; i < selNodes.length; i++){
                     let selNode = selNodes[i];
-                    //更新选中的节点(第一层)
-                    let oprSectionInfo = tools.getSectionInfo(firstPreSibling);
-                    let nullOprSectionInfo = tools.sectionInfoNull(oprSectionInfo);
-                    if(nullOprSectionInfo){
-                        oprSectionInfo[nullOprSectionInfo] = firstPreSibling.getID();
-                    }
+                    //更新选中的节点
                     updateData.push({
                         ID: selNode.getID(),
                         ParentID: firstPreSibling.getID(),
                         NextSiblingID: i === selNodes.length - 1 ? -1 : selNode.getNextSiblingID(),
-                        sectionInfo: oprSectionInfo,
                         type: 'oprNode'});
-                    //更新选中节点的子节点(第二层)
-                    let childSectionInfo = {first: oprSectionInfo.first, second: oprSectionInfo.second, third: oprSectionInfo.third};
-                    let updateChildFlag = false;
-                    let nullChildSection = tools.sectionInfoNull(childSectionInfo);
-                    if(nullChildSection){
-                        childSectionInfo[nullChildSection] = selNode.getID();
-                        updateChildFlag = true;
-                    }
-                    if(updateChildFlag){
-                        for(let child of selNode.children){
-                            updateData.push({
-                                ID: child.getID(),
-                                sectionInfo: childSectionInfo,
-                                type: 'oprChildren'
-                            });
-                            //更新选中节点的孙子节点(第三层)
-                            let gChildSectionInfo = {first: childSectionInfo.first, second: childSectionInfo.second, third: childSectionInfo.third};
-                            let updateGChildFlag = false;
-                            if(!tools.isDef(gChildSectionInfo.third)){
-                                gChildSectionInfo.third = child.getID();
-                                updateGChildFlag = true;
-                            }
-                            if(updateGChildFlag){
-                                for(let grandChild of child.children){
-                                    updateData.push({ID: grandChild.getID(), sectionInfo: gChildSectionInfo, type: 'oprChildren'});
-                                }
-                            }
-                        }
-                    }
                 }
+
+                //get updateSectionInfo nodes
+                //选中的节点
+                toUpSectionNodes = toUpSectionNodes.concat(selNodes);
+                //选中节点的所有子节点
+                toUpSectionNodes = toUpSectionNodes.concat(tools.getChildrenNodes(selNodes));
+
                 billsAjax.downLevel(userAccount, billsLibId, updateData, function(){
-                    tools.btnAction(btn);
-                    btn.attr('doing', 'false');
+                    //tools.btnAction(btn);
+                    //btn.attr('doing', 'false');
                     for(let downNode of selNodes){
                         controller.setTreeSelected(downNode);
                         controller.downLevel();
                     }
                     sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
                     controller.sheet.getParent().focus(true);
+                    //update sectionInfo
+                    if(toUpSectionNodes.length > 0){
+                        billsAjax.updateSectionInfo(tools.getUpdateSectionData(toUpSectionNodes), function () {
+                            tools.btnAction(btn);
+                            btn.attr('doing', 'false');
+                        });
+                    }
                 });
             }
         }
@@ -1543,6 +1487,32 @@ var tools = {
             }
         }
     },
+
+    getUpdateSectionData: function (nodes) {
+        let rst = [];
+        for(let node of nodes){
+            rst.push({ID: node.getID(), sectionInfo: tools.getSectionInfo(node)});
+        }
+        return rst;
+    },
+
+    //获取节点底下所有子节点
+    getChildrenNodes: function (nodes) {
+        let rst = [];
+        for(let node of nodes){
+            getChild(node.children);
+        }
+        function getChild(ns){
+            rst = rst.concat(ns);
+            for(let n of ns){
+                if(n.children.length > 0){
+                    getChild(n.children);
+                }
+            }
+        }
+        return rst;
+    },
+
     getSameDepthNodes: function(controller){
         const items = controller.tree.items;
         let rst = [];