Bladeren bron

项目工料机容错处理

zhangweicheng 4 jaren geleden
bovenliggende
commit
af10876872
1 gewijzigde bestanden met toevoegingen van 49 en 6 verwijderingen
  1. 49 6
      modules/main/facade/ration_facade.js

+ 49 - 6
modules/main/facade/ration_facade.js

@@ -727,13 +727,13 @@ async function getProjectGLJinfo(projectID,t_newRationGLJList,gljKeyMap,gljCodes
     let rkey = getIndex(ration_glj);
     let pglj = projectGLJMap[rkey];
     let subList = [];
-    setUnitPrice(pglj,unitPriceMap);
+    await setUnitPrice(pglj,unitPriceMap,ration_glj);
     if(existMixRatioMap[rkey]){//如果有组成物
       for(let m of existMixRatioMap[rkey]){
          let mpglj = projectGLJMap[getIndex(m)]
          if(mpglj){
           let cglj = _.clone(mpglj); 
-          setUnitPrice(cglj,unitPriceMap);
+          await setUnitPrice(cglj,unitPriceMap);
           cglj.ratio_data = m;
           subList.push(cglj);
          }else{
@@ -752,13 +752,54 @@ async function getProjectGLJinfo(projectID,t_newRationGLJList,gljKeyMap,gljCodes
 
 
 
-  function setUnitPrice(p,unitPriceMap){
-    p.unit_price = unitPriceMap[getIndex(p)];
+  async function setUnitPrice(p,unitPriceMap,ration_glj){
+    let unitPrice =  unitPriceMap[getIndex(p)];
+    if(unitPrice){
+      p.unit_price = unitPrice;
+    }else{
+      unitPrice = newPriceDataFromPGlj(p,unitPriceFileId);
+      if(ration_glj){
+        unitPrice.base_price = ration_glj.basePrice;
+        unitPrice.market_price = ration_glj.marketPrice;
+      }
+      await unitPriceModel.insertMany([unitPrice]);
+      p.unit_price =unitPrice
+    }
+   
   }
 
 }
 
 
+function newPriceDataFromPGlj(np,unitPriceFileId){
+    let insertData = {
+        code: np.code,
+        base_price: np.base_price,
+        market_price: np.market_price,
+        unit_price_file_id: unitPriceFileId,
+        name: np.name,
+        specs:np.specs?np.specs:'',
+        original_code:np.original_code,
+        unit:np.unit?np.unit:'',
+        type: np.type,
+        short_name: np.shortName !== undefined ? np.shortName : '',
+        glj_id: np.glj_id,
+        is_add:0,
+        grossWeightCoe:np.grossWeightCoe,
+        purchaseStorageRate:np.purchaseStorageRate,
+        offSiteTransportLossRate:np.offSiteTransportLossRate,
+        handlingLossRate:np.handlingLossRate
+      };
+      if(np.code == '80CCS'){//车船税默认价格为1
+          insertData.base_price = '1';
+          insertData.market_price = '1';
+      }
+      if(np.from=='cpt') insertData.is_add=1;//如果是来自补充工料机,则都添加新增标记
+      if(insertData.code != insertData.original_code) insertData.is_add=1;//添加的时候如果是复制整块来的,可能在源项目中是新增的工料机,这里也要添上(暂时可能还用不到)
+    return insertData;
+  }
+  
+
 //找到并返回单价文件信息,如果没有自动插入
 async function getUnitPriceData(newProjectGLJList,gljCodes,unitPriceFileId){
   let unitPriceMap = {};
@@ -771,7 +812,9 @@ async function getUnitPriceData(newProjectGLJList,gljCodes,unitPriceFileId){
   for(let np of newProjectGLJList){
     let pkey = getIndex(np);
     if(unitPriceMap[pkey]) continue;
-    let insertData = {
+    let insertData = newPriceDataFromPGlj(np,unitPriceFileId);
+    
+    /* {
       code: np.code,
       base_price: np.base_price,
       market_price: np.market_price,
@@ -794,7 +837,7 @@ async function getUnitPriceData(newProjectGLJList,gljCodes,unitPriceFileId){
         insertData.market_price = '1';
     }
     if(np.from=='cpt') insertData.is_add=1;//如果是来自补充工料机,则都添加新增标记
-    if(insertData.code != insertData.original_code) insertData.is_add=1;//添加的时候如果是复制整块来的,可能在源项目中是新增的工料机,这里也要添上(暂时可能还用不到)
+    if(insertData.code != insertData.original_code) insertData.is_add=1;//添加的时候如果是复制整块来的,可能在源项目中是新增的工料机,这里也要添上(暂时可能还用不到) */
     newUnitPriceList.push(insertData);
     unitPriceMap[pkey] = insertData;
   }