Преглед на файлове

变更工料机定额价优化

zhongzewei преди 7 години
родител
ревизия
af13d5b150

+ 33 - 12
modules/ration_repository/models/glj_repository.js

@@ -74,23 +74,44 @@ gljItemDAO.prototype.getGljItems = function(gljIds, callback){
     })
 };
 
-gljItemDAO.prototype.getStdCompleGljItems = async function (rationGljList, callback) {
+/*gljItemDAO.prototype.getStdCompleGljItems = async function (rationGljList, callback) {
     try{
         let rst = [];
-        for(let i = 0, len = rationGljList.length; i < len; i++){
-            if(rationGljList[i].type !== undefined && rationGljList[i].type === 'complementary'){
-                let compleGlj = await compleGljModel.find({ID: rationGljList[i].gljId, deleteInfo: null});
-                if(compleGlj.length > 0){
-                    rst.push(compleGlj[0]);
-                }
+        let stdIds = [], compleIds = []
+        for(let glj of rationGljList){
+            if(glj.type !== undefined && glj.type === 'complementary'){
+                compleIds.push(glj.gljId);
             }
-            else {
-                let stdGlj = await gljModel.find({ID: rationGljList[i].gljId, $or: [{deleted: null}, {deleted: false}]});
-                if(stdGlj.length > 0){
-                    rst.push(stdGlj[0]);
-                }
+            else{
+                stdIds.push(glj.gljId);
             }
         }
+        if(compleIds.length > 0){
+            let compleGlj = await compleGljModel.find({ID: {$in: compleIds}, deleteInfo: null}, {ID: 1, gljType: 1, basePrice: 1});
+            rst = rst.concat(compleGlj);
+        }
+        if(stdIds.length > 0){
+            let stdGlj = await gljModel.find({ID: {$in: stdIds}, $or: [{deleted: null}, {deleted: false}]}, {ID: 1, gljType: 1, basePrice: 1});
+            rst = rst.concat(stdGlj);
+        }
+        callback(0, rst);
+    }
+    catch(err){
+        callback(err, null);
+    }
+};*/
+
+gljItemDAO.prototype.getStdCompleGljItems = async function (compleGljIds, stdGljIds, callback) {
+    try{
+        let rst = [];
+        if(compleGljIds.length > 0){
+            let compleGlj = await compleGljModel.find({ID: {$in: compleGljIds}, deleteInfo: null}, {ID: 1, gljType: 1, basePrice: 1});
+            rst = rst.concat(compleGlj);
+        }
+        if(stdGljIds.length > 0){
+            let stdGlj = await gljModel.find({ID: {$in: stdGljIds}, $or: [{deleted: null}, {deleted: false}]}, {ID: 1, gljType: 1, basePrice: 1});
+            rst = rst.concat(stdGlj);
+        }
         callback(0, rst);
     }
     catch(err){

+ 84 - 57
modules/ration_repository/models/ration_item.js

@@ -211,7 +211,6 @@ function round(v,e){
 
 
 rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
-
     async.each(basePrcArr, function (basePrcObj, finalCb) {
         let adjGljId = basePrcObj.gljId, adjBasePrice = basePrcObj.basePrice, adjGljType = basePrcObj.gljType;
         async.waterfall([
@@ -253,12 +252,12 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                     });
                 }
                 else{
-                    rationItemModel.find({'rationGljList.gljId': adjGljId}, function (err, result) {
+                    rationItemModel.find({'rationGljList.gljId': adjGljId}, {ID: 1, rationGljList: 1}, function (err, result) {
                         if(err){
                             cb(err);
                         }
                         else{
-                            compleRationModel.find({'rationGljList.gljId': adjGljId}, function (err, compleRst) {
+                            compleRationModel.find({'rationGljList.gljId': adjGljId}, {ID: 1, rationGljList: 1}, function (err, compleRst) {
                                 if(err){
                                     cb(err);
                                 }
@@ -274,34 +273,53 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                 }
             },
             function (result, cb) {
-                async.each(result, function (rationItem, ecb) {
-                    let rationGljList = rationItem.rationGljList,
-                        gljIds = [];
-                    gljDao.getStdCompleGljItems(rationGljList, function(err, gljItems){
-                        if(err){
-                            ecb(err);
+                let compleRTasks = [], stdRTasks = [];
+                //重算时需要用到的所有工料机,一次性取
+                let compleGljIds = [], stdGljIds = [];
+                for(let ration of result){
+                    for(let glj of ration.rationGljList){
+                        if(glj.type !== undefined && glj.type === 'complementary'){
+                            compleGljIds.push(glj.gljId);
                         }
-                        else{
+                        else {
+                            stdGljIds.push(glj.gljId);
+                        }
+                    }
+                }
+                gljDao.getStdCompleGljItems(compleGljIds, stdGljIds, function (err, allGljs) {
+                    if(err){
+                        cb(err);
+                    }
+                    else {
+                        let gljIndex = {};
+                        for(let glj of allGljs){
+                            gljIndex[glj.ID] = glj;
+                        }
+                        async.each(result, function (rationItem, ecb) {
+                            let rationGljList = rationItem.rationGljList;
                             let gljArr = [];
-                            for(let i=0; i<gljItems.length; i++){
-                                let gljParentType = -1;
-                                if(gljItems[i].ID === adjGljId){
-                                    gljItems[i].gljType = adjGljType;
-                                }
-                                if(gljItems[i].gljType <= 3){
-                                    gljParentType = gljItems[i].gljType;
-                                }
-                                if(gljItems[i].gljType > 200 && gljItems[i].gljType < 300){
-                                    gljParentType = 2;
-                                }
-                                if(gljItems[i].gljType > 300 && gljItems[i].gljType < 400){
-                                    gljParentType = 3;
-                                }
-                                if(gljItems[i].ID === adjGljId){
-                                    gljArr.push({gljId: gljItems[i].ID, basePrice: adjBasePrice, gljParentType: gljParentType});
-                                }
-                                else {
-                                    gljArr.push({gljId: gljItems[i].ID, basePrice: parseFloat(gljItems[i].basePrice), gljParentType: gljParentType});
+                            for(let i=0; i<rationGljList.length; i++){
+                                let theGlj = gljIndex[rationGljList[i].gljId];
+                                if(theGlj !== undefined && theGlj){
+                                    let gljParentType = -1;
+                                    if(theGlj.ID === adjGljId){
+                                        theGlj.gljType = adjGljType;
+                                    }
+                                    if(theGlj.gljType <= 3){
+                                        gljParentType = theGlj.gljType;
+                                    }
+                                    if(theGlj.gljType > 200 && theGlj.gljType < 300){
+                                        gljParentType = 2;
+                                    }
+                                    if(theGlj.gljType > 300 && theGlj.gljType < 400){
+                                        gljParentType = 3;
+                                    }
+                                    if(theGlj.ID === adjGljId){
+                                        gljArr.push({gljId: theGlj.ID, basePrice: adjBasePrice, gljParentType: gljParentType});
+                                    }
+                                    else {
+                                        gljArr.push({gljId: theGlj.ID, basePrice: parseFloat(theGlj.basePrice), gljParentType: gljParentType});
+                                    }
                                 }
                             }
                             gljArr.forEach(function (gljItem) {
@@ -349,39 +367,48 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                                 updatePrc.machinePrice = scMathUtil.roundTo(sumMaP, -2);
                             }
                             updatePrc.basePrice = scMathUtil.roundTo(updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice, -2);
+                            let task = {
+                                updateOne: {
+                                    filter: {
+                                        ID: rationItem.ID
+                                    },
+                                    update: {
+                                        labourPrice: updatePrc.labourPrice.toString(),
+                                        materialPrice: updatePrc.materialPrice.toString(),
+                                        machinePrice: updatePrc.machinePrice.toString(),
+                                        basePrice: updatePrc.basePrice.toString()
+                                    }
+                                }
+                            };
                             //updateDataBase
                             if(rationItem._doc.type !== undefined && rationItem._doc.type === 'complementary'){
-                                compleRationModel.update({ID: rationItem.ID}, {$set: {labourPrice: updatePrc.labourPrice.toString(), materialPrice: updatePrc.materialPrice.toString(),
-                                        machinePrice: updatePrc.machinePrice.toString(), basePrice: updatePrc.basePrice.toString()}},
-                                    function (err, result) {
-                                        if(err){
-                                            ecb(err);
-                                        }
-                                        else {
-                                            ecb(null);
-                                        }
-                                    });
+                                compleRTasks.push(task);
+                                ecb(null);
                             }
                             else {
-                                rationItemModel.update({ID: rationItem.ID}, {$set: {labourPrice: updatePrc.labourPrice.toString(), materialPrice: updatePrc.materialPrice.toString(),
-                                        machinePrice: updatePrc.machinePrice.toString(), basePrice: updatePrc.basePrice.toString()}},
-                                    function (err, result) {
-                                        if(err){
-                                            ecb(err);
-                                        }
-                                        else {
-                                            ecb(null);
-                                        }
-                                    });
+                                stdRTasks.push(task);
+                                ecb(null);
                             }
-                        }
-                    });
-                }, function(err){
-                    if(err){
-                        cb(err);
-                    }
-                    else {
-                        cb(null);
+                        }, async function(err){
+                            if(err){
+                                cb(err);
+                            }
+                            else {
+                                //do sth
+                                try{
+                                    if(compleRTasks.length > 0){
+                                        await compleRationModel.bulkWrite(compleRTasks);
+                                    }
+                                    if(stdRTasks.length > 0){
+                                        await rationItemModel.bulkWrite(stdRTasks);
+                                    }
+                                }
+                                catch(e){
+                                    cb(err);
+                                }
+                                cb(null);
+                            }
+                        });
                     }
                 });
             },

Файловите разлики са ограничени, защото са твърде много
+ 81 - 0
public/web/PerfectLoad.js


+ 10 - 4
web/maintain/ration_repository/js/section_tree.js

@@ -312,6 +312,7 @@ let sectionTreeObj = {
                     me.refreshBtn(me.tree.selected);
                     //fresh tools
                     me.initTools(me.tree.selected);
+                    me.workBook.focus();
                 });
             }
         });
@@ -350,6 +351,7 @@ let sectionTreeObj = {
                 me.controller.delete();
                 me.refreshBtn(me.tree.selected);
                 me.initTools(me.tree.selected);
+                me.workBook.focus();
             });
         }
     },
@@ -387,6 +389,7 @@ let sectionTreeObj = {
             me.sectionTreeAjax(postData, function (rstData) {
                 me.controller.upLevel();
                 me.refreshBtn(me.tree.selected);
+                me.workBook.focus();
             });
         }
 
@@ -414,6 +417,7 @@ let sectionTreeObj = {
             me.sectionTreeAjax(postData, function (rstData) {
                 me.controller.downLevel();
                 me.refreshBtn(me.tree.selected);
+                me.workBook.focus();
             });
         }
     },
@@ -440,6 +444,7 @@ let sectionTreeObj = {
             me.sectionTreeAjax(postData, function (rstData) {
                 me.controller.upMove();
                 me.refreshBtn(me.tree.selected);
+                me.workBook.focus();
             });
         }
     },
@@ -466,6 +471,7 @@ let sectionTreeObj = {
             me.sectionTreeAjax(postData, function (rstData) {
                 me.controller.downMove();
                 me.refreshBtn(me.tree.selected);
+                me.workBook.focus();
             });
         }
     },
@@ -535,12 +541,12 @@ let sectionTreeObj = {
             annotationOprObj.setRadiosDisabled(true, annotationOprObj.radios);
             annotationOprObj.hideTable($('#fzTableAll'), $('#fzTablePartial'));
             sheetCommonObj.cleanSheet(rationOprObj.workBook.getSheet(0), rationOprObj.setting, -1);
-            sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
-            sheetCommonObj.cleanSheet(rationAssistOprObj.sheet, rationAssistOprObj.setting, -1);
-            sheetCommonObj.cleanSheet(rationCoeOprObj.sheet, rationCoeOprObj.setting, -1);
-            sheetCommonObj.cleanSheet(rationInstObj.sheet, rationInstObj.setting, -1);
             rationGLJOprObj.sheet.getParent().focus(false);
         }
+        sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
+        sheetCommonObj.cleanSheet(rationAssistOprObj.sheet, rationAssistOprObj.setting, -1);
+        sheetCommonObj.cleanSheet(rationCoeOprObj.sheet, rationCoeOprObj.setting, -1);
+        sheetCommonObj.cleanSheet(rationInstObj.sheet, rationInstObj.setting, -1);
         me.workBook.focus(true);
     }
 };

+ 5 - 0
web/maintain/std_glj_lib/html/gongliao.html

@@ -146,6 +146,7 @@
     <script src="/lib/jquery-contextmenu/jquery.ui.position.js"></script>
     <script src="/lib/tether/tether.min.js"></script>
     <script src="/lib/bootstrap/bootstrap.min.js"></script>
+    <script src="/public/web/PerfectLoad.js"></script>
     <script src="/web/maintain/std_glj_lib/js/global.js"></script>
     <!-- zTree -->
     <script src = "/lib/spreadjs/sheets/gc.spread.sheets.all.10.0.1.min.js"></script>
@@ -246,6 +247,10 @@
             }
         };
         $(document).ready(function(){
+            //test
+            console.log(scMathUtil.roundTo(parseFloat(25*1.277), -2));
+            console.log(25*1.277);
+            //test
             //解决spreadjs sheet初始化没高度宽度
             $('#modalCon').width($(window).width()*0.5);
             $('#componentTreeDiv').height($(window).height() - 300);

+ 14 - 6
web/maintain/std_glj_lib/js/glj.js

@@ -393,6 +393,10 @@ let repositoryGljObj = {
     onCellEditStart: function(sender, args) {
         let me = repositoryGljObj;
         let rObj = sheetsOprObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row);
+        if(me.prevent){
+            args.cancel = true;
+            return;
+        }
         me.currentEditingGlj = rObj;
         me.orgCode = me.workBook.getSheet(0).getValue(args.row, 0);
         if(args.row < me.currentCache.length){
@@ -535,7 +539,6 @@ let repositoryGljObj = {
                         rObj.basePrice = 0;
                     }
                     rObj.basePrice = !isNaN(parseFloat(rObj.basePrice)) && (rObj.basePrice && typeof rObj.basePrice !== 'undefined') ? scMathUtil.roundTo(parseFloat(rObj.basePrice), -2) : 0;
-                    console.log(rObj.basePrice);
                     addArr.push(rObj);
                 }
             }
@@ -818,7 +821,7 @@ let repositoryGljObj = {
                 for(let i = 0, len = info.cellRange.rowCount; i < len; i++){
                     let row = i + info.cellRange.row;
                     if(row < me.currentCache.length){
-                        if(me.allowComponent.indexOf(me.currentCache[row].gljType) !== -1){
+                        if(me.allowComponent.indexOf(me.currentCache[row].gljType) !== -1 && me.currentCache[row].component.length > 0){
                             rst = false;
                         }
                     }
@@ -852,9 +855,9 @@ let repositoryGljObj = {
                 if(updateObj && typeof updateObj.updateGlj !== 'undefined' && updateObj.updateGlj.length > 0){
                     //updateArr = updateObj.updateGlj;
                     updateArr = updateArr.concat(updateObj.updateGlj);
-                    if(typeof updateObj.updateBasePrc !== 'undefined'){
+                    if(typeof updateObj.updateBasePrcArr !== 'undefined'){
                         //updateBasePrcArr = updateObj.updateBasePrc;
-                        updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrc);
+                        updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrcArr);
                     }
                 }
                 else{
@@ -868,8 +871,8 @@ let repositoryGljObj = {
                 let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
                 if(updateObj && typeof updateObj.updateGlj !== 'undefined'){
                     updateArr = updateArr.concat(updateObj.updateGlj);
-                    if(typeof updateObj.updateBasePrc !== 'undefined'){
-                        updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrc);
+                    if(typeof updateObj.updateBasePrcArr !== 'undefined'){
+                        updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrcArr);
                     }
                 }
                 else{
@@ -951,6 +954,9 @@ let repositoryGljObj = {
         }
     },
     updateRationBasePrcRq: function (basePrcArr) {
+        let me = this;
+        me.prevent = true;
+        $.bootstrapLoading.start();
         $.ajax({
             type: 'post',
             url: 'api/updateRationBasePrc',
@@ -960,6 +966,8 @@ let repositoryGljObj = {
                 if(result.error){
                     alert("计算定额基价失败");
                 }
+                $.bootstrapLoading.end();
+                me.prevent = false;
             }
         });
     },

+ 2 - 0
web/maintain/std_glj_lib/js/gljComponent.js

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