|
@@ -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);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
},
|