Browse Source

getGLjItems优化

zhongzewei 7 years ago
parent
commit
e453b94213

+ 67 - 4
modules/complementary_glj_lib/models/gljModel.js

@@ -58,12 +58,34 @@ class GljDao {
         }
     }
     //获得用户的补充工料机和用户当前所在编办的标准工料机
-    getGljItems (stdGljLibId, userId, compilationId, callback){
+    async getGljItems (stdGljLibId, userId, compilationId, callback){
         let me = this;
         let rst = {stdGljs: [], complementaryGljs: []};
+        //批量获取异步
+       /* let functions = [];
+        let count = await stdGljModel.find({repositoryId: stdGljLibId, $or: [{deleted: null}, {deleted: false}]}).count();
+        let findCount = Math.ceil(count/500);
+        for(let i = 0, len = findCount; i < len; i++){
+            functions.push((function(flag) {
+                return function (cb) {
+                    stdGljModel.find({repositoryId: stdGljLibId, deleted: null}, cb).skip(flag).sort({ID: 1}).limit(500);
+                }
+            })(i*500));
+        }
+        async.parallel(functions,  function (err, results) {
+            if(err){
+                callback(err, null);
+            }
+            else{
+                for(let stdGljs of results){
+                    rst.stdGljs = rst.stdGljs.concat(stdGljs);
+                }
+                callback(0, rst);
+            }
+        });*/
         async.parallel([
-            function (cb) {
-                stdGljModel.find({repositoryId: stdGljLibId}, function (err, stdGljs) {
+           async function (cb) {
+               /* stdGljModel.find({repositoryId: stdGljLibId}, function (err, stdGljs) {
                     if(err){
                         cb(err);
                     }
@@ -72,7 +94,48 @@ class GljDao {
                         rst.stdGljs = stdGljs;
                         cb(null);
                     }
-                });
+                });*/
+               try{
+                   let stdGljs = [];
+                   let first = await stdGljModel.find({repositoryId: stdGljLibId}).sort({ID: 1}).limit(1);
+                   let count = await stdGljModel.find({repositoryId: stdGljLibId, $or: [{deleted: null}, {deleted: false}]}).count();
+                   let findCount = Math.ceil(count/500);
+                   let flag = first[0].ID;
+                   //let flag = 0;
+                   //批量获取,非skip
+                   for(let i = 0, len = findCount; i < len; i++){
+                       let tempStdGlj;
+                       if(i === 0){
+                           tempStdGlj = await stdGljModel.find({repositoryId: stdGljLibId, deleted: null, ID: {$gte: flag}}).sort({ID: 1}).limit(500);
+                           if(tempStdGlj.length > 0){
+                               flag = tempStdGlj[tempStdGlj.length - 1].ID;
+                           }
+                       }
+                       else {
+                           tempStdGlj = await stdGljModel.find({repositoryId: stdGljLibId, deleted: null, ID: {$gt: flag}}).sort({ID: 1}).limit(500);
+                           if(tempStdGlj.length > 0){
+                               flag = tempStdGlj[tempStdGlj.length - 1].ID;
+                           }
+                       }
+                       if(tempStdGlj){
+                           stdGljs = stdGljs.concat(tempStdGlj);
+                       }
+                   }
+               /*    for(let i = 0, len = findCount; i < len; i++){
+                       let tempStdGlj = await stdGljModel.find({repositoryId: stdGljLibId, deleted: null}).skip(flag).sort({ID: 1}).limit(500);
+                       if(tempStdGlj.length > 0){
+                           flag = flag + 500;
+                           stdGljs = stdGljs.concat(tempStdGlj);
+                       }
+                   }*/
+                   me.sortToNumber(stdGljs);
+                   rst.stdGljs = stdGljs;
+                   cb(null);
+               }
+               catch (err){
+                   cb(err);
+               }
+
             },
             function (cb) {
                 complementaryGljModel.find({userId: userId, compilationId: compilationId}, function (err, complementaryGljs) {

+ 1 - 0
modules/complementary_ration_lib/models/searchModel.js

@@ -57,6 +57,7 @@ class SearchDao{
             for(let i = 0, len = stdRations.length; i < len; i++){
                 stdRations[i]._doc.type = 'std';
             }
+            filter.userId = userId;
             let compleRations = await compleRationModel.find(filter);
             for(let i = 0, len = compleRations.length; i <len; i++){
                 compleRations[i]._doc.type = 'complementary';

+ 1 - 1
web/building_saas/complementary_glj_lib/js/gljComponent.js

@@ -498,7 +498,7 @@ let gljComponentOprObj = {
         let me = gljComponentOprObj, gljBasePrc = 0;
         for(let i = 0; i < component.length; i++){
             let roundBasePrc = scMathUtil.roundTo(parseFloat(component[i].basePrice), -2);
-            gljBasePrc += scMathUtil.roundTo(roundBasePrc * parseFloat(component[i].consumeAmt), -2);
+            gljBasePrc = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * parseFloat(component[i].consumeAmt), -2) + gljBasePrc, -2);
         }
         return gljBasePrc;
     }

+ 5 - 0
web/building_saas/main/js/views/glj_view_contextMenu.js

@@ -197,7 +197,10 @@ var gljContextMenu = {
 
 function getGLJData(actionType) {
     $('#actionType').val(actionType);
+    $.bootstrapLoading.start();
+    console.log(+new Date());
     projectObj.project.ration_glj.getGLJData(function (result) {
+        console.log(+new Date());
         zTreeHelper.createTree(result.datas.treeData, gljOprObj.gljTreeSetting, "gljTree", gljOprObj);
         gljOprObj.stdGLJ=result.datas.stdGLJ;
         gljOprObj.complementaryGLJs=result.datas.complementaryGLJs;
@@ -205,6 +208,8 @@ function getGLJData(actionType) {
         gljOprObj.distTypeTree=gljOprObj.getComboData(result.datas.distTypeTree);
         $('#modalCon').width($(window).width()*0.5);
         $("input[name='glj']").get(0).checked=true;
+        $.bootstrapLoading.end();
+        console.log(+new Date());
         $("#glj_tree_div").modal({show:true});
     })
 }