Explorar el Código

优化应用到所有清单功能

zhongzewei hace 6 años
padre
commit
7a0354180b

+ 10 - 0
modules/main/controllers/bills_controller.js

@@ -78,6 +78,16 @@ module.exports = {
             callback(req, res, err, message, null);
         });
     },
+    updateBills: async function (req, res) {
+        try{
+            let data = JSON.parse(req.body.data);
+            await billsData.updateBills(data.updateDatas);
+            callback(req, res, 0, 'success', null);
+        }
+        catch (err){
+            callback(req, res, 1, err, null);
+        }
+    },
     updateBill: async function(request, response) {
         const data = JSON.parse(request.body.data);
         const findSet = data.findSet;

+ 7 - 0
modules/main/models/bills.js

@@ -118,6 +118,13 @@ class billsModel extends baseModel {
            }
        });
     };
+    async updateBills(updateDatas){
+        let bulk = [];
+        for(let updateData of updateDatas){
+            bulk.push({updateOne: {filter: updateData.findSet, update: {$set: updateData.updateData}}});
+        }
+        await bills.bulkWrite(bulk);
+    };
     async updateBill(findSet, updateData) {
         let update = {};
         if (!updateData instanceof Array) {

+ 1 - 0
modules/main/routes/bills_route.js

@@ -11,6 +11,7 @@ module.exports = function (app) {
     billsRouter.post('/allocIDs', billsController.allocIDs);
     billsRouter.post('/updateCharacterContent', billsController.updateCharacterContent);//特征及内容更新 zhong 2017-9-1
     // 批量更新bill数据
+    billsRouter.post('/updateBills', billsController.updateBills);
     billsRouter.post('/updateBill', billsController.updateBill);
     //删除单个清单,不删除子项
     billsRouter.post('/singleDelete',billsController.singleDelete);

+ 46 - 0
web/building_saas/main/js/views/character_content_view.js

@@ -1114,6 +1114,52 @@ let pageCCOprObj = {
         }
         projectObj.mainSpread.getActiveSheet().autoFitRow(row);
     },
+    bulkSetCharacterBySetting: function(nodes, setting) {
+        $.bootstrapLoading.start();
+        let me = this;
+        let updateDatas = [];
+        let updateNodes = [];
+        let updateMapping = {};
+        for(let node of nodes){
+            if(!node || node.sourceType !== projectObj.project.Bills.getSourceType()){
+                continue;
+            }
+            let findSet = {ID: node.data.ID, projectID: node.data.projectID};
+            let updateData = this.getCharacterUpdateData(setting, node);
+            updateData.jobContent = node.data.jobContent;
+            updateData.itemCharacter = node.data.itemCharacter;
+            let orgName = isDef(node.data.name) ? node.data.name : '';
+            let orgItemCharacterText = isDef(node.data.itemCharacterText) ? node.data.itemCharacterText : '';
+            let orgJobContentText = isDef(node.data.jobContentText) ? node.data.jobContentText : '';
+            if(orgName == updateData.name && orgItemCharacterText == updateData.itemCharacterText && orgJobContentText == updateData.jobContentText){
+                continue;
+            }
+            updateMapping[node.data.ID] = updateData;
+            updateNodes.push(node);
+            updateDatas.push({findSet: findSet, updateData: updateData});
+        }
+        if(updateDatas.length > 0){
+            CommonAjax.post('/bills/updateBills', {updateDatas: updateDatas}, function (rstData) {
+                for(let node of updateNodes){
+                    let mainSheet = projectObj.mainSpread.getActiveSheet();
+                    mainSheet.suspendPaint();
+                    mainSheet.suspendEvent();
+                    me.refreshView(node, updateMapping[node.data.ID]);
+                    node.data.name = updateMapping[node.data.ID]['name'];
+                    node.data.itemCharacterText = updateMapping[node.data.ID]['itemCharacterText'];
+                    node.data.jobContentText = updateMapping[node.data.ID]['jobContentText'];
+                    mainSheet.resumePaint();
+                    mainSheet.resumeEvent();
+                }
+                $.bootstrapLoading.end();
+            }, function () {
+                $.bootstrapLoading.end();
+            });
+        }
+        else {
+            $.bootstrapLoading.end();
+        }
+    },
     /**
      * 根据配置设置清单项目特征
      *

+ 2 - 13
web/building_saas/main/js/views/sub_view.js

@@ -221,9 +221,7 @@ $("#use-to-current").click(function() {
 });
 //todo: 优化成批量
 function addRuleUseToBills(setting, nodes) {
-    for(let node of nodes){
-        pageCCOprObj.setCharacterBySetting(node, setting, null, null, true);
-    }
+    pageCCOprObj.bulkSetCharacterBySetting(nodes, setting);
 }
 // 应用到所有的清单
 $("#use-to-all").click(function() {
@@ -241,20 +239,11 @@ $("#use-to-all").click(function() {
     }
     // 处理
     addRuleUseToBills(setting, treeNode.items);
-   /* for (const item of treeNode.items) {
-        if(setting.addContent !== '5'){
-            if (item.data.jobContent === undefined || item.data.jobContent.length <= 0 ||
-                item.data.itemCharacter === undefined || item.data.itemCharacter.length <= 0 || item.data.code === undefined) {
-                continue;
-            }
-        }
-        pageCCOprObj.setCharacterBySetting(item, setting);
-    }*/
 });
 
 function saveAddRule(){
     let setting = getAddRuleSetting();
-    let toUpdate = false;//
+    let toUpdate = false;
     if(!projectObj.project.property.addRule){
         toUpdate = true;
     }