|  | @@ -9,6 +9,7 @@ let ration_glj = mongoose.model('ration_glj');
 | 
	
		
			
				|  |  |  let ration = mongoose.model('ration');
 | 
	
		
			
				|  |  |  let ration_coe = mongoose.model('ration_coe');
 | 
	
		
			
				|  |  |  let std_ration_lib_ration_items = mongoose.model('std_ration_lib_ration_items');
 | 
	
		
			
				|  |  | +let std_glj_lib_gljList_model = mongoose.model('std_glj_lib_gljList');
 | 
	
		
			
				|  |  |  let glj_type_util = require('../../../public/cache/std_glj_type_util');
 | 
	
		
			
				|  |  |  const scMathUtil = require('../../../public/scMathUtil').getUtil();
 | 
	
		
			
				|  |  |  let decimal_facade = require('../../main/facade/decimal_facade');
 | 
	
	
		
			
				|  | @@ -26,7 +27,7 @@ let stateSeq ={
 | 
	
		
			
				|  |  |      cusQuantity:5,
 | 
	
		
			
				|  |  |      cusCoe:6,
 | 
	
		
			
				|  |  |      adjMak:7
 | 
	
		
			
				|  |  | -}
 | 
	
		
			
				|  |  | +};
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  async function calculateQuantity(query,noNeedCal){
 | 
	
	
		
			
				|  | @@ -49,7 +50,7 @@ async function calculateQuantity(query,noNeedCal){
 | 
	
		
			
				|  |  |                   let times = calculateTimes(impactRation.rationAssList[i]);
 | 
	
		
			
				|  |  |                   if(times!=0){
 | 
	
		
			
				|  |  |                       assRation = await  std_ration_lib_ration_items.findOne({rationRepId:impactRation.libID,code:impactRation.rationAssList[i].assistCode});
 | 
	
		
			
				|  |  | -                     assList.push({times:times,assRation:assRation})
 | 
	
		
			
				|  |  | +                     assList.push({times:times,assRation:assRation});
 | 
	
		
			
				|  |  |                       adjustState.push({index:stateSeq.ass,content:impactRation.rationAssList[i].name+" "+impactRation.rationAssList[i].actualValue+" : +"+impactRation.rationAssList[i].assistCode+"x"+times});
 | 
	
		
			
				|  |  |                   }
 | 
	
		
			
				|  |  |               }
 | 
	
	
		
			
				|  | @@ -106,7 +107,7 @@ async function calculateQuantityPerGLJ(glj,index,coeList,assList,adjustState,noN
 | 
	
		
			
				|  |  |          if(noNeedCal==null){
 | 
	
		
			
				|  |  |              if(!glj._doc.hasOwnProperty('customQuantity')||glj.customQuantity==null||glj.customQuantity==""){
 | 
	
		
			
				|  |  |                  quantity =scMathUtil.roundTo(parseFloat(glj.rationItemQuantity),-decimal);
 | 
	
		
			
				|  |  | -                quantity =scMathUtil.roundTo(calculateAss(quantity,assList,glj),-decimal);
 | 
	
		
			
				|  |  | +                quantity =scMathUtil.roundTo(await calculateAss(quantity,assList,glj),-decimal);
 | 
	
		
			
				|  |  |                  quantity = calculateQuantityByCoes(quantity,coeList,glj);
 | 
	
		
			
				|  |  |              }else {
 | 
	
		
			
				|  |  |                  quantity = glj.customQuantity;
 | 
	
	
		
			
				|  | @@ -126,12 +127,22 @@ async function calculateQuantityPerGLJ(glj,index,coeList,assList,adjustState,noN
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -function calculateAss(quantity,assList,glj) {
 | 
	
		
			
				|  |  | +async function calculateAss(quantity,assList,glj) {
 | 
	
		
			
				|  |  |      for(let i=0;i<assList.length;i++){
 | 
	
		
			
				|  |  |          if(assList[i].assRation){
 | 
	
		
			
				|  |  | -            let assglj = _.find(assList[i].assRation.rationGljList,function (aglj) {
 | 
	
		
			
				|  |  | -                return aglj.gljId == glj.GLJID
 | 
	
		
			
				|  |  | -            })
 | 
	
		
			
				|  |  | +            let assglj = null;
 | 
	
		
			
				|  |  | +            for(let aglj of assList[i].assRation.rationGljList){
 | 
	
		
			
				|  |  | +                if(glj.createType == 'replace'){//如果工料机是替换过的,要用原始的编码来匹配
 | 
	
		
			
				|  |  | +                    let std_glj = await std_glj_lib_gljList_model.findOne({'ID':aglj.gljId});
 | 
	
		
			
				|  |  | +                    if(glj.rcode == std_glj.code){
 | 
	
		
			
				|  |  | +                        assglj = aglj;
 | 
	
		
			
				|  |  | +                        break;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }else if(aglj.gljId == glj.GLJID){
 | 
	
		
			
				|  |  | +                    assglj = aglj;
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |              if(assglj){
 | 
	
		
			
				|  |  |                  let calQuantity = assglj.consumeAmt*assList[i].times;
 | 
	
		
			
				|  |  |                  quantity += calQuantity
 | 
	
	
		
			
				|  | @@ -155,9 +166,9 @@ function generateAdjustState(glj,coeList,adjustState,index,quantity) {
 | 
	
		
			
				|  |  |          for(let i=0;i<coeList.length;i++){
 | 
	
		
			
				|  |  |              if(coeList[i].isAdjust==1){
 | 
	
		
			
				|  |  |                  if(i==coeList.length-1){
 | 
	
		
			
				|  |  | -                    adjustState.push({index:stateSeq.cusCoe,content:coeList[i].content});
 | 
	
		
			
				|  |  | +                    adjustState.push({index:stateSeq.cusCoe,content:getContent(coeList[i].coes)});//自定义乘系数要去掉倍数为1的
 | 
	
		
			
				|  |  |                  }else {
 | 
	
		
			
				|  |  | -                    adjustState.push({index:stateSeq.coe,content:"调 : "+coeList[i].content});
 | 
	
		
			
				|  |  | +                    adjustState.push({index:stateSeq.coe,content:"调 : "+coeList[i].content});//coeList[i].content
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -178,6 +189,20 @@ function generateAdjustState(glj,coeList,adjustState,index,quantity) {
 | 
	
		
			
				|  |  |      return adjustState;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +function getContent(coes) {
 | 
	
		
			
				|  |  | +    let stringList=[];
 | 
	
		
			
				|  |  | +    for(let c of coes){
 | 
	
		
			
				|  |  | +        if( c.amount&&c.amount!=1){
 | 
	
		
			
				|  |  | +            let operator = c.operator;
 | 
	
		
			
				|  |  | +            if(c.operator =="*"){
 | 
	
		
			
				|  |  | +                operator = "X";
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            stringList.push(c.coeType+operator+c.amount);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    return stringList.join(",");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  function calculateTimes(ass){
 | 
	
		
			
				|  |  |      let times =(ass.actualValue-ass.stdValue)/ass.stepValue;
 | 
	
	
		
			
				|  | @@ -211,7 +236,7 @@ function everyCoe(quantity,coe,glj) {
 | 
	
		
			
				|  |  |      let coeQuantity = quantity;
 | 
	
		
			
				|  |  |      if(coe.isAdjust==1){
 | 
	
		
			
				|  |  |          for(let i=0;i<coe.coes.length;i++){
 | 
	
		
			
				|  |  | -            if(coe.coes[i].coeType=='单个'&&coe.coes[i].gljCode==glj.code){
 | 
	
		
			
				|  |  | +            if(coe.coes[i].gljCode==glj.code){//if(coe.coes[i].coeType=='单个工料机'&&coe.coes[i].gljCode==glj.code)
 | 
	
		
			
				|  |  |                  coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]);
 | 
	
		
			
				|  |  |              } else if(coe.coes[i].coeType=='定额'){
 | 
	
		
			
				|  |  |                  coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]);
 |