Przeglądaj źródła

补充人材机库逻辑更改,优化获取人材机速度

zhongzewei 6 lat temu
rodzic
commit
069ee0427e

+ 13 - 6
modules/complementary_glj_lib/controllers/gljController.js

@@ -101,12 +101,19 @@ class GljController extends BaseController{
     }
     getGljItems(req, res) {
         let data = JSON.parse(req.body.data);
-        let stdGljLibId = data.stdGljLibId,
-            userId = data.userId,
-            compilationId = data.compilationId
-            gljDao.getGljItems(stdGljLibId, req.session.sessionUser.id, req.session.sessionCompilation._id, function(err, data){
-                callback(req,res,err,'Get Items',data)
-            });
+        let stdGljLibId = data.stdGljLibId;
+        let projection = data.projection;
+        gljDao.getGljItems(stdGljLibId, req.session.sessionUser.id, req.session.sessionCompilation._id, projection, function(err, data){
+            callback(req,res,err,'Get Items',data)
+        });
+    }
+    getStdItems(req, res) {
+        let data = JSON.parse(req.body.data),
+            stdGljLibId = data.stdGljLibId,
+            projection = data.projection;
+        gljDao.getStdItems(stdGljLibId, projection, function (err, data) {
+            callback(req, res, err, '获取人材机数据失败', data);
+        });
     }
 
     updateComponent(req, res){

+ 12 - 48
modules/complementary_glj_lib/models/gljModel.js

@@ -41,59 +41,14 @@ class GljDao {
         }
     }
     //获得用户的补充工料机和用户当前所在编办的标准工料机
-    async getGljItems (stdGljLibId, userId, compilationId, callback){
+    async getGljItems (stdGljLibId, userId, compilationId, projection, 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([
            async function (cb) {
                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}}).lean().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}}).lean().sort({ID: 1}).limit(500);
-                           if(tempStdGlj.length > 0){
-                               flag = tempStdGlj[tempStdGlj.length - 1].ID;
-                           }
-                       }
-                       if(tempStdGlj){
-                           stdGljs = stdGljs.concat(tempStdGlj);
-                       }
-                   }
+                   let stdGljs = await stdGljModel.find({repositoryId: stdGljLibId}, projection).lean();
                    me.sortToNumber(stdGljs);
                    rst.stdGljs = stdGljs;
                    cb(null);
@@ -124,7 +79,16 @@ class GljDao {
             }
         })
 
-    };
+    }
+
+    async getStdItems (stdGljLibId, projection, callback) {
+        try {
+            let stdItems = await stdGljModel.find({repositoryId: stdGljLibId}, projection).lean();
+            callback(0, stdItems);
+        } catch (err) {
+            callback(1, null);
+        }
+    }
 
     getGljItemsByCode (repositoryId, codes, callback){
         gljModel.find({"repositoryId": repositoryId,"code": {"$in": codes}},function(err,data){

+ 1 - 0
modules/complementary_glj_lib/routes/routes.js

@@ -21,6 +21,7 @@ module.exports = function (app) {
     router.post("/getGljDistType", gljController.init, gljController.getGljDistType);
     router.post("/getGljTree", gljController.init, gljController.getGljTree);
     router.post("/getGljItems", gljController.init, gljController.getGljItems);
+    router.post('/getStdItems', gljController.init, gljController.getStdItems);
     router.post("/updateComponent", gljController.init, gljController.updateComponent);
     router.post("/mixUpdateGljItems", gljController.init, gljController.mixUpdateGljItems);
     router.post("/updateRationBasePrc",compleRationController.init, compleRationController.updateRationBasePrc);//更新定额单价

+ 1 - 1
modules/ration_glj/facade/ration_glj_facade.js

@@ -561,7 +561,7 @@ function getGLJData(info, callback) {
             }
         },
         function (cb) {
-            gljDao.getGljItems(info.gljLibId, info.userID, info.compilationId, function (err, data) {
+            gljDao.getGljItems(info.gljLibId, info.userID, info.compilationId, {_id: 0}, function (err, data) {
                 if (err) {
                     cb(err);
                 } else {

+ 2 - 8
web/building_saas/complementary_glj_lib/js/components.js

@@ -87,9 +87,7 @@ let componentOprObj = {
                         }
                     }
                     if(!isExist){
-                        if(clearChecked){
-                            gljList[i].isChecked = false;
-                        }
+                        gljList[i].isChecked = false;
                     }
                     else {
                         gljList[i].isChecked = true;
@@ -223,7 +221,6 @@ let componentOprObj = {
                     cacheSection.push(data[i]);
                 }
             }
-            sheetOpr.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
             sheetOpr.showData(me.workBook.getSheet(0), me.setting, cacheSection, re.distTypeTree);
             me.workBook.getSheet(0).setRowCount(cacheSection.length);
             cacheSection = null;
@@ -236,7 +233,6 @@ let componentOprObj = {
             //添加选择添加的组成物
             let updateArr = [];
             let newComponent = [];
-            //re.currentGlj.component = [];
             for(let i = 0, len = me.selectedList.length; i < len; i++){
                 let isExist = false;
                 for(let j = 0, jLen = re.currentGlj.component.length; j < jLen; j++){
@@ -250,14 +246,12 @@ let componentOprObj = {
                 if(!isExist){
                     newComponent.push({isStd: typeof me.selectedList[i].isStd !== 'undefined' ? me.selectedList[i].isStd : false, ID: me.selectedList[i].ID, consumeAmt: 0});
                 }
-                //re.currentGlj.component.push({ID: me.selectedList[i].ID, consumeAmt: 0});
             }
             re.currentGlj.component = newComponent;
             let gljBasePrc = that.reCalGljBasePrc(re.getCurrentComponent(re.currentGlj.component));
             if(gljBasePrc !== re.currentGlj.basePrice){
                 re.currentGlj.basePrice = gljBasePrc;
                 re.reshowGljBasePrc(re.currentGlj);
-                //updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
             }
             updateArr.push(re.currentGlj);
             that.updateComponent(updateArr);
@@ -282,7 +276,7 @@ let componentTypeTreeOprObj = {
     }
 }
 $(document).ready(function () {
-    $('#gljSearchKeyword').change(function () {
+    $('#gljSearchKeyword').bind('keyup', function () {
         componentOprObj.filterDatasAndShow();
     });
     $('#gljSearchKeyword').bind('keypress', function (e) {

+ 70 - 32
web/building_saas/complementary_glj_lib/js/glj.js

@@ -60,8 +60,10 @@ let pageOprObj = {
         //repositoryGljObj.getRationGljIds(gljLibId);
         repositoryGljObj.getGljDistType(function () {
             repositoryGljObj.currentRepositoryId = me.stdGljLibId;
-            repositoryGljObj.getGljItems(me.stdGljLibId, function () {
-                gljClassTreeObj.getGljClassTree(stdGljLibId);
+            gljClassTreeObj.getGljClassTree(stdGljLibId, function () {
+                repositoryGljObj.getGljItems(me.stdGljLibId, function () {
+                    gljClassTreeObj.initSelection(gljClassTreeObj.tree.selected);
+                });
             });
         });
     }
@@ -70,6 +72,10 @@ let pageOprObj = {
 let repositoryGljObj = {
     treeObj : null,
     workBook: null,
+    // 是否获取了完整的人材机数据
+    // 第一次打开页面只加载补充人材机和标准人材机的编码
+    // 第一次打开选择组成物的窗口才加载标准人材机剩余数据
+    pullCompleteData: false,
     gljCurTypeId: -1,
     currentRepositoryId: -1,
     currentCache: null,
@@ -179,8 +185,19 @@ let repositoryGljObj = {
         });
     },
     getGljItems: function(stdGljLibId, callback) {
-        let me = this;
-        CommonAjax.post('complementartGlj/api/getGljItems', {stdGljLibId: stdGljLibId}, function (rstData) {
+        let me = this,
+            // 一开始获取的标准人材机只包含code,提升打开页面速度
+            projection = {
+                _id: 0,
+                ID: 1,
+                code: 1,
+                unit: 1,
+                name: 1,
+                priceProperty: 1,
+                basePrice: 1
+            };
+        $.bootstrapLoading.start();
+        CommonAjax.post('/complementartGlj/api/getGljItems', {stdGljLibId, projection}, function (rstData) {
             me.stdGljList = rstData.stdGljs;
             //兼容多单价情况
             for(let sGlj of me.stdGljList){
@@ -188,14 +205,44 @@ let repositoryGljObj = {
                     sGlj.basePrice = sGlj.priceProperty.price1;
                 }
             }
-            me.complementaryGljList = rstData.complementaryGljs;
-            me.workBook.getSheet(0).setRowCount(me.stdGljList.length);
             me.sortGlj(me.stdGljList);
             me.setProp('isStd', true, me.stdGljList);
+            me.complementaryGljList = rstData.complementaryGljs;
             me.sortGlj(me.complementaryGljList);
             if(callback){
                 callback();
             }
+            $.bootstrapLoading.end();
+        }, function () {
+            $.bootstrapLoading.end();
+        });
+    },
+    // 获取标准人材机数据
+    getStdItems: function (stdGljLibId, callback) {
+        $.bootstrapLoading.start();
+        let me = this;
+        let projection = {
+            _id: 0,
+            ID: 1,
+            specs: 1,
+            gljType: 1,
+            shortName: 1,
+            gljClass: 1
+        };
+        CommonAjax.post('/complementartGlj/api/getStdItems', {stdGljLibId, projection}, function (data) {
+            me.pullCompleteData = true;
+            // 更新标准人材机数据
+            let IDMapping = {};
+            for (let glj of data) {
+                IDMapping[glj.ID] = glj;
+            }
+            for (let glj of me.stdGljList) {
+                Object.assign(glj, IDMapping[glj.ID]);
+            }
+            callback();
+            $.bootstrapLoading.end();
+        }, function () {
+            $.bootstrapLoading.end();
         });
     },
     showGljItems: function(data, type) {
@@ -283,32 +330,23 @@ let repositoryGljObj = {
     },
 
     getCurrentComponent: function (gljComponent) {
-        let me = repositoryGljObj, rst = [];
-        for(let i = 0; i < gljComponent.length; i++){
-            let obj = {};
-            for(let j = 0; j < me.complementaryGljList.length; j++){
-                if(gljComponent[i].ID == me.complementaryGljList[j].ID){
-                    obj.isStd = false;
-                    obj.ID = me.complementaryGljList[j].ID;
-                    obj.code = me.complementaryGljList[j].code;
-                    obj.name = me.complementaryGljList[j].name;
-                    obj.unit = me.complementaryGljList[j].unit;
-                    obj.basePrice = me.complementaryGljList[j].basePrice;
-                    obj.consumeAmt = gljComponent[i].consumeAmt;
-                    rst.push(obj);
-                }
-            }
-            for(let j = 0; j < me.stdGljList.length; j++){
-                if(gljComponent[i].ID == me.stdGljList[j].ID){
-                    obj.isStd = true;
-                    obj.ID = me.stdGljList[j].ID;
-                    obj.code = me.stdGljList[j].code;
-                    obj.name = me.stdGljList[j].name;
-                    obj.unit = me.stdGljList[j].unit;
-                    obj.basePrice = me.stdGljList[j].basePrice;
-                    obj.consumeAmt = gljComponent[i].consumeAmt;
-                    rst.push(obj);
-                }
+        let me = repositoryGljObj,
+            rst = [];
+        for(let thisGlj of gljComponent){
+            let toFindGljList = thisGlj.isStd
+                ? me.stdGljList
+                : me.complementaryGljList;
+            let matchGlj = toFindGljList.find(glj => glj.ID === thisGlj.ID);
+            if (matchGlj) {
+                rst.push({
+                    isStd: thisGlj.isStd ? true : false,
+                    ID: matchGlj.ID,
+                    code: matchGlj.code,
+                    name: matchGlj.name,
+                    unit: matchGlj.unit,
+                    basePrice: matchGlj.basePrice,
+                    consumeAmt: thisGlj.consumeAmt
+                });
             }
         }
         rst.sort(function (a, b) {

+ 1 - 15
web/building_saas/complementary_glj_lib/js/gljClassTree.js

@@ -111,7 +111,6 @@ let gljClassTreeObj = {
     },
 
     getGljClassTree: function (gljLibId, callback) {
-        console.log('enter1');
         let me = gljClassTreeObj;
         let re = repositoryGljObj;
         let url = '/complementartGlj/api/getMixedTree';
@@ -119,11 +118,6 @@ let gljClassTreeObj = {
         let sucFunc = function (rstData) {
             me.treeData = rstData;
             let compleTreeData = me.treeData.comple;
-            /*zTreeHelper.createTree(rstData.std, componentSetting, "componentTree", componentOprObj);
-            let rootNode = componentOprObj.treeObj.getNodes()[0];
-            if(rootNode && rootNode.isParent && rootNode.isFirstNode){
-                componentOprObj.rootNode = rootNode;
-            }*/
             if (compleTreeData && compleTreeData.length > 0) {
                 me.gljCurTypeId = compleTreeData[0].ID;
             }
@@ -135,15 +129,11 @@ let gljClassTreeObj = {
             me.initController(me.tree, me.sheet, me.setting.sheet);
             me.controller.showTreeData();
             me.sheet.setFormatter(-1, 0, '@');
-            me.initSelection(me.tree.selected);
             if(callback){
                 callback();
             }
         };
-        let errFunc = function () {
-
-        };
-        CommonAjax.post(url, postData, sucFunc, errFunc);
+        CommonAjax.post(url, postData, sucFunc);
     },
 
     initTree: function (datas) {
@@ -155,10 +145,6 @@ let gljClassTreeObj = {
     initController: function (tree, sheet, setting) {
         this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting);
     },
-
-    gljClassTreeAjax: function (postData, scFunc, errFunc) {
-        CommonAjax.post('api/updateNodes', {updateData: postData, lastOpr: userAccount}, scFunc, errFunc);
-    },
     //模仿默认点击
     initSelection: function (node) {
         let me = this,

+ 14 - 7
web/building_saas/complementary_glj_lib/js/gljComponent.js

@@ -92,13 +92,20 @@ let gljComponentOprObj = {
                         callback: function(){},
                         items: {
                             "insert": {name: "插入", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
-                                //默认radio所有工料机
-                                co.initRadio();
-                                co.gljCurTypeId = null;
-                                //默认点击树根节点
-                                co.initClassTree('std', gljClassTreeObj.treeData.std);
-                                //弹出窗口
-                                $('#component').modal('show');
+                                let oprFunc = function () {
+                                    //默认radio所有工料机
+                                    co.initRadio();
+                                    co.gljCurTypeId = null;
+                                    //默认点击树根节点
+                                    co.initClassTree('std', gljClassTreeObj.treeData.std);
+                                    //弹出窗口
+                                    $('#component').modal('show');
+                                };
+                                if (repositoryGljObj.pullCompleteData) {
+                                    oprFunc();
+                                } else {
+                                    repositoryGljObj.getStdItems(pageOprObj.stdGljLibId, oprFunc);
+                                }
                             }},
                             "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
                                 //删除

+ 1 - 0
web/building_saas/complementary_glj_lib/js/sheetOpr.js

@@ -43,6 +43,7 @@ let sheetOpr = {
         spreadBook.options.allowCopyPasteExcelStyle = false;
         spreadBook.options.allowExtendPasteRange = true;
         spreadBook.options.allowUserDragDrop = false;
+        spreadBook.options.allowUserDragFill = false;
         spreadBook.options.allowContextMenu = false;
         var spreadNS = GC.Spread.Sheets;
         var sheet = spreadBook.getSheet(0);

+ 4 - 0
web/building_saas/css/custom.css

@@ -319,4 +319,8 @@ input.text-right{
     display: none;
     color: #43CD80;
     margin-left: 8px
+}
+/*占位底色*/
+.occupied {
+    background: #f1f1f1;
 }

+ 1 - 1
web/building_saas/main/html/main.html

@@ -454,7 +454,7 @@
                               </div>
 
                               <!--清单指引-->
-                              <div class="tab-pane" id="zy">
+                              <div class="tab-pane occupied" id="zy">
                                   <div class="sidebar-tools-bar container-fluid tools-bar-height-z">
                                       <div class="p-1 row">
                                           <div class="col p-0">

+ 1 - 1
web/building_saas/main/js/views/std_billsGuidance_lib.js

@@ -971,8 +971,8 @@ const billsGuidance = (function () {
                 elfItem.workBook = null;
             }
             initViews();
+            initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, rstData.bills);
             let callback = function () {
-                initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, rstData.bills);
                 if(doAfterLoadGuidance){
                     doAfterLoadGuidance();
                 }