|  | @@ -200,7 +200,7 @@ module.exports = {
 | 
												
													
														
															|  |                  if (sheet[0] === undefined || sheet[0].data === undefined) {
 |  |                  if (sheet[0] === undefined || sheet[0].data === undefined) {
 | 
												
													
														
															|  |                      throw 'excel没有对应数据';
 |  |                      throw 'excel没有对应数据';
 | 
												
													
														
															|  |                  }
 |  |                  }
 | 
												
													
														
															|  | -                //导入的数据是否含有固定行(分部分项、施工技术措施项目、施工组织措施项目)
 |  | 
 | 
												
													
														
															|  | 
 |  | +                //导入的数据是否含有固定行(分部分项、施工技术措施项目、施工组织措施项目,通过文件名判断)
 | 
												
													
														
															|  |                  let flag = getImportFlag(file.originalFilename);
 |  |                  let flag = getImportFlag(file.originalFilename);
 | 
												
													
														
															|  |                  if(!flag){
 |  |                  if(!flag){
 | 
												
													
														
															|  |                      throw 'excel数据错误';
 |  |                      throw 'excel数据错误';
 | 
												
											
												
													
														
															|  | @@ -232,6 +232,8 @@ module.exports = {
 | 
												
													
														
															|  |                      await billsData.model.create(insertFixedBill);
 |  |                      await billsData.model.create(insertFixedBill);
 | 
												
													
														
															|  |                      fixedBill = insertFixedBill;
 |  |                      fixedBill = insertFixedBill;
 | 
												
													
														
															|  |                  }
 |  |                  }
 | 
												
													
														
															|  | 
 |  | +                console.log(`fixedBill--------------`);
 | 
												
													
														
															|  | 
 |  | +                console.log(fixedBill);
 | 
												
													
														
															|  |                  //匹配的清单库
 |  |                  //匹配的清单库
 | 
												
													
														
															|  |                  const billsLibId = fields.billsLibId !== undefined && fields.billsLibId.length > 0 && fields.billsLibId[0]? parseInt(fields.billsLibId[0]) : null;
 |  |                  const billsLibId = fields.billsLibId !== undefined && fields.billsLibId.length > 0 && fields.billsLibId[0]? parseInt(fields.billsLibId[0]) : null;
 | 
												
													
														
															|  |                  let stdBills = [], stdJobs = [], stdCharacters = [];
 |  |                  let stdBills = [], stdJobs = [], stdCharacters = [];
 | 
												
											
												
													
														
															|  | @@ -241,7 +243,7 @@ module.exports = {
 | 
												
													
														
															|  |                      stdCharacters = await stdBillCharacterModel.find({billsLibId: billsLibId, deleted: false});
 |  |                      stdCharacters = await stdBillCharacterModel.find({billsLibId: billsLibId, deleted: false});
 | 
												
													
														
															|  |                  }
 |  |                  }
 | 
												
													
														
															|  |                  //将excel数据转换成清单树结构数据
 |  |                  //将excel数据转换成清单树结构数据
 | 
												
													
														
															|  | -                let insertDatas = parseToBillData(getValidImportData(sheet[0].data), getColMapping(sheet[0].data), fixedBill, projectID, {stdBills: stdBills, stdJobs: stdJobs, stdCharacters: stdCharacters});
 |  | 
 | 
												
													
														
															|  | 
 |  | +                let insertDatas = parseToBillData(getValidImportData(sheet[0].data, fixedBill), getColMapping(sheet[0].data), fixedBill, projectID, {stdBills: stdBills, stdJobs: stdJobs, stdCharacters: stdCharacters});
 | 
												
													
														
															|  |                  //删除相关数据
 |  |                  //删除相关数据
 | 
												
													
														
															|  |                  let deleteDatas = await billsData.deepDeleteBill([fixedBill], req.session.sessionUser.id);
 |  |                  let deleteDatas = await billsData.deepDeleteBill([fixedBill], req.session.sessionUser.id);
 | 
												
													
														
															|  |                  //新增清单数据
 |  |                  //新增清单数据
 | 
												
											
												
													
														
															|  | @@ -305,8 +307,10 @@ function rowExistData(rowData){
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
													
														
															|  |      return false;
 |  |      return false;
 | 
												
													
														
															|  |  }
 |  |  }
 | 
												
													
														
															|  | -//提取excel表数据中的有效数据(去表头表尾,提取其中的excel数据)
 |  | 
 | 
												
													
														
															|  | -function getValidImportData(sheetData){
 |  | 
 | 
												
													
														
															|  | 
 |  | +//提取excel表数据中的有效数据(去表头表尾,提取其中的excel数据)(根据fixedBill获取栏头占行数)
 | 
												
													
														
															|  | 
 |  | +function getValidImportData(sheetData, fixedBill){
 | 
												
													
														
															|  | 
 |  | +    console.log(`sheetData`);
 | 
												
													
														
															|  | 
 |  | +    console.log(sheetData);
 | 
												
													
														
															|  |      let withingD = false;
 |  |      let withingD = false;
 | 
												
													
														
															|  |      let validData = [];
 |  |      let validData = [];
 | 
												
													
														
															|  |      for(let r = 0; r < sheetData.length; r++){
 |  |      for(let r = 0; r < sheetData.length; r++){
 | 
												
											
												
													
														
															|  | @@ -317,7 +321,9 @@ function getValidImportData(sheetData){
 | 
												
													
														
															|  |              //表头
 |  |              //表头
 | 
												
													
														
															|  |              if(rData[0] === '序号'){
 |  |              if(rData[0] === '序号'){
 | 
												
													
														
															|  |                  withingD = true;
 |  |                  withingD = true;
 | 
												
													
														
															|  | -                r++;
 |  | 
 | 
												
													
														
															|  | 
 |  | +                if(fixedBill.name !== '施工组织措施项目'){
 | 
												
													
														
															|  | 
 |  | +                    r++;
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  |                  continue;
 |  |                  continue;
 | 
												
													
														
															|  |              }
 |  |              }
 | 
												
													
														
															|  |              //表尾
 |  |              //表尾
 | 
												
											
												
													
														
															|  | @@ -325,10 +331,16 @@ function getValidImportData(sheetData){
 | 
												
													
														
															|  |                  withingD = false;
 |  |                  withingD = false;
 | 
												
													
														
															|  |              }
 |  |              }
 | 
												
													
														
															|  |          }
 |  |          }
 | 
												
													
														
															|  | 
 |  | +        /*console.log(`rData`);
 | 
												
													
														
															|  | 
 |  | +        console.log(rData);
 | 
												
													
														
															|  | 
 |  | +        console.log(withingD);
 | 
												
													
														
															|  | 
 |  | +        console.log(rowExistData(rData));*/
 | 
												
													
														
															|  |          if(withingD && rowExistData(rData)){
 |  |          if(withingD && rowExistData(rData)){
 | 
												
													
														
															|  |              validData.push(rData);
 |  |              validData.push(rData);
 | 
												
													
														
															|  |          }
 |  |          }
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
													
														
															|  | 
 |  | +    /*console.log(`validData`);
 | 
												
													
														
															|  | 
 |  | +    console.log(validData);*/
 | 
												
													
														
															|  |      return validData;
 |  |      return validData;
 | 
												
													
														
															|  |  }
 |  |  }
 | 
												
													
														
															|  |  
 |  |  
 | 
												
											
												
													
														
															|  | @@ -358,7 +370,7 @@ function parseToBillData(validData, colMapping, fixedBill, projectID, stdData){
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
													
														
															|  |      //续数据,上一行数据是有效节点且无序号
 |  |      //续数据,上一行数据是有效节点且无序号
 | 
												
													
														
															|  |      function isExtend(preData, rData){
 |  |      function isExtend(preData, rData){
 | 
												
													
														
															|  | -        return preData && (isRoot(preData) || isLeaf(preData)) && (rData[colMapping.serialNo] === undefined || rData[colMapping.serialNo] === '');
 |  | 
 | 
												
													
														
															|  | 
 |  | +        return preData && (isRoot(preData) || isLeaf(preData)) &&  !isRoot(rData) && (rData[colMapping.serialNo] === undefined || rData[colMapping.serialNo] === '');
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
													
														
															|  |      function getBillType(rData, flag){
 |  |      function getBillType(rData, flag){
 | 
												
													
														
															|  |          if(flag === fixedFlag.CONSTRUCTION_TECH || flag === fixedFlag.CONSTRUCTION_ORGANIZATION){
 |  |          if(flag === fixedFlag.CONSTRUCTION_TECH || flag === fixedFlag.CONSTRUCTION_ORGANIZATION){
 | 
												
											
												
													
														
															|  | @@ -371,12 +383,14 @@ function parseToBillData(validData, colMapping, fixedBill, projectID, stdData){
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
													
														
															|  |      //excel数据与标准库数据匹配,根据清单前九位编码匹配,匹配成功则获取标准清单对应的工程专业、特征及内容
 |  |      //excel数据与标准库数据匹配,根据清单前九位编码匹配,匹配成功则获取标准清单对应的工程专业、特征及内容
 | 
												
													
														
															|  |      function matchStdBill(excelBill, stdData){
 |  |      function matchStdBill(excelBill, stdData){
 | 
												
													
														
															|  | 
 |  | +        let isMatch = false;
 | 
												
													
														
															|  |          let regExp = /^\d{12}$/g;
 |  |          let regExp = /^\d{12}$/g;
 | 
												
													
														
															|  |          if(regExp.test(excelBill.code)){
 |  |          if(regExp.test(excelBill.code)){
 | 
												
													
														
															|  |              let nineCode = excelBill.code.substr(0, 9);
 |  |              let nineCode = excelBill.code.substr(0, 9);
 | 
												
													
														
															|  |              for(let stdBill of stdData.stdBills){
 |  |              for(let stdBill of stdData.stdBills){
 | 
												
													
														
															|  |                  //set programID
 |  |                  //set programID
 | 
												
													
														
															|  |                  if(nineCode == stdBill.code){
 |  |                  if(nineCode == stdBill.code){
 | 
												
													
														
															|  | 
 |  | +                    isMatch = true;
 | 
												
													
														
															|  |                      excelBill.programID = stdBill.engineering ? stdBill.engineering : null;
 |  |                      excelBill.programID = stdBill.engineering ? stdBill.engineering : null;
 | 
												
													
														
															|  |                      //set jobContent and itemCharacter
 |  |                      //set jobContent and itemCharacter
 | 
												
													
														
															|  |                      let tempJob = [], tempCharacter = [];
 |  |                      let tempJob = [], tempCharacter = [];
 | 
												
											
												
													
														
															|  | @@ -403,6 +417,9 @@ function parseToBillData(validData, colMapping, fixedBill, projectID, stdData){
 | 
												
													
														
															|  |                  }
 |  |                  }
 | 
												
													
														
															|  |              }
 |  |              }
 | 
												
													
														
															|  |          }
 |  |          }
 | 
												
													
														
															|  | 
 |  | +        if(!isMatch && excelBill.type === billType.FX){//分项在标准清单中不匹配,则识别为补项
 | 
												
													
														
															|  | 
 |  | +                excelBill.type = billType.BX;
 | 
												
													
														
															|  | 
 |  | +        }
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
													
														
															|  |      for(let r = 0; r < validData.length; r++){
 |  |      for(let r = 0; r < validData.length; r++){
 | 
												
													
														
															|  |          let preData = validData[r-1],
 |  |          let preData = validData[r-1],
 | 
												
											
												
													
														
															|  | @@ -450,8 +467,9 @@ function parseToBillData(validData, colMapping, fixedBill, projectID, stdData){
 | 
												
													
														
															|  |                  programID: null,
 |  |                  programID: null,
 | 
												
													
														
															|  |                  unit: rData[colMapping.unit] ? rData[colMapping.unit] : '',
 |  |                  unit: rData[colMapping.unit] ? rData[colMapping.unit] : '',
 | 
												
													
														
															|  |                  quantity: rData[colMapping.quantity] ? rData[colMapping.quantity] : '',
 |  |                  quantity: rData[colMapping.quantity] ? rData[colMapping.quantity] : '',
 | 
												
													
														
															|  | -                flags: fixedBill.flags[0].flag === fixedFlag.CONSTRUCTION_ORGANIZATION && rData[colMapping.name] === '安全文明施工专项费用' ?
 |  | 
 | 
												
													
														
															|  | -                    [{fieldName: 'fixed', flag: fixedBill.flags[0].flag}] : [],
 |  | 
 | 
												
													
														
															|  | 
 |  | +                //安全文明
 | 
												
													
														
															|  | 
 |  | +                flags: fixedBill.flags[0].flag === fixedFlag.CONSTRUCTION_ORGANIZATION && (rData[colMapping.name] === '安全文明施工专项费用' || rData[colMapping.name] === '安全文明施工费') ?
 | 
												
													
														
															|  | 
 |  | +                    [{fieldName: 'fixed', flag: fixedFlag.SAFETY_CONSTRUCTION}] : [],
 | 
												
													
														
															|  |                  fees: [],
 |  |                  fees: [],
 | 
												
													
														
															|  |                  projectID: projectID,
 |  |                  projectID: projectID,
 | 
												
													
														
															|  |                  type: getBillType(rData, fixedBill.flags[0].flag)};
 |  |                  type: getBillType(rData, fixedBill.flags[0].flag)};
 | 
												
											
												
													
														
															|  | @@ -470,6 +488,8 @@ function parseToBillData(validData, colMapping, fixedBill, projectID, stdData){
 | 
												
													
														
															|  |      for(let i in billIdx){
 |  |      for(let i in billIdx){
 | 
												
													
														
															|  |          rst.push(billIdx[i]);
 |  |          rst.push(billIdx[i]);
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
													
														
															|  | 
 |  | +    console.log('rst');
 | 
												
													
														
															|  | 
 |  | +    console.log(rst);
 | 
												
													
														
															|  |      return rst;
 |  |      return rst;
 | 
												
													
														
															|  |  }
 |  |  }
 | 
												
													
														
															|  |  
 |  |  
 |