|
@@ -30,14 +30,14 @@ let stateSeq ={
|
|
|
};
|
|
|
|
|
|
|
|
|
-async function calculateQuantity(query,noNeedCal){
|
|
|
+async function calculateQuantity(query,noNeedCal,refreshRationName = false){
|
|
|
try {
|
|
|
let result ={
|
|
|
glj_result:[],
|
|
|
rationID:query.rationID
|
|
|
};
|
|
|
let impactRation = await ration.findOne({projectID:query.projectID,ID:query.rationID,deleteInfo:null});
|
|
|
- let gljList = await ration_glj.find(query)//{projectID:query.projectID,rationID:query.rationID}
|
|
|
+ let gljList = await ration_glj.find(query);//{projectID:query.projectID,rationID:query.rationID}
|
|
|
let coeList = await ration_coe.find({projectID:query.projectID,rationID:query.rationID}).sort('seq').exec();
|
|
|
let assList=[];
|
|
|
let assRation = null;
|
|
@@ -55,19 +55,25 @@ async function calculateQuantity(query,noNeedCal){
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- gljList = sortRationGLJ(gljList);
|
|
|
+ gljList = sortRationGLJ(gljList);
|
|
|
for(let i =0;i<gljList.length;i++ ){
|
|
|
let r = await calculateQuantityPerGLJ(gljList[i],i,coeList,assList,adjustState,noNeedCal);
|
|
|
result.glj_result.push(r);
|
|
|
}
|
|
|
|
|
|
- if(noNeedCal==null){
|
|
|
+ if(noNeedCal==null){
|
|
|
await ration_glj.bulkWrite(generateUpdateTasks(result.glj_result));
|
|
|
- }
|
|
|
+ }
|
|
|
adjustState= _.sortByOrder(adjustState, ['index'], ['asc']);
|
|
|
adjustState=_.map(adjustState, _.property('content'));
|
|
|
let adjustStateString = adjustState.join(';');
|
|
|
- await ration.update({projectID:query.projectID,ID:query.rationID,deleteInfo: null},{adjustState:adjustStateString});
|
|
|
+ let setData = {adjustState:adjustStateString};
|
|
|
+ if(refreshRationName == true){//需要更新定额名称
|
|
|
+ let newName = generateRationName(impactRation,gljList);
|
|
|
+ setData.name = newName;
|
|
|
+ result.rationName = newName;
|
|
|
+ }
|
|
|
+ await ration.update({projectID:query.projectID,ID:query.rationID,deleteInfo: null},setData);
|
|
|
result.adjustState=adjustStateString;
|
|
|
return result;
|
|
|
}catch (err){
|
|
@@ -76,6 +82,25 @@ async function calculateQuantity(query,noNeedCal){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+function generateRationName(ration,gljList) {
|
|
|
+ let caption = ration.caption ? ration.caption:ration.name;
|
|
|
+ if(ration.rationAssList && ration.rationAssList.length > 0){
|
|
|
+ let ass = ration.rationAssList[0];
|
|
|
+ if(ass.actualValue != null && ass.actualValue != undefined ){
|
|
|
+ caption = caption.replace('%s',ass.actualValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for(let g of gljList){
|
|
|
+ //glj._doc.createType=='replace'&&glj.rcode!=glj.code
|
|
|
+ if(g.createType=='replace'&&g.rcode!=g.code){ //是替换工料机
|
|
|
+ caption = caption + ' '+g.name;
|
|
|
+ if(!_.isEmpty(g.specs)) caption = caption + ' '+g.specs
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return caption;
|
|
|
+}
|
|
|
+
|
|
|
function generateUpdateTasks(result) {
|
|
|
let tasks = [];
|
|
|
for(let i =0;i<result.length;i++){
|