|  | @@ -35,7 +35,10 @@ module.exports = {
 | 
	
		
			
				|  |  |      getQuantityByProjectGLJ: getQuantityByProjectGLJ,
 | 
	
		
			
				|  |  |      getLibInfo: getLibInfo,
 | 
	
		
			
				|  |  |      getGLJData: getGLJData,
 | 
	
		
			
				|  |  | +    getGLJDataByCodes:getGLJDataByCodes,
 | 
	
		
			
				|  |  |      addGLJ: addGLJ,
 | 
	
		
			
				|  |  | +    deleteGLJ:deleteGLJ,
 | 
	
		
			
				|  |  | +    insertAddTypeGLJ:insertAddTypeGLJ,
 | 
	
		
			
				|  |  |      replaceGLJ: replaceGLJ,
 | 
	
		
			
				|  |  |      mReplaceGLJ: mReplaceGLJ,
 | 
	
		
			
				|  |  |      updateRationGLJByEdit: updateRationGLJByEdit,
 | 
	
	
		
			
				|  | @@ -45,7 +48,8 @@ module.exports = {
 | 
	
		
			
				|  |  |      getInfoFromProjectGLJ:getInfoFromProjectGLJ,
 | 
	
		
			
				|  |  |      createNewRecord:createNewRecord,
 | 
	
		
			
				|  |  |      getGLJSearchInfo:getGLJSearchInfo,
 | 
	
		
			
				|  |  | -    updateRationGLJFromDoc:updateRationGLJFromDoc
 | 
	
		
			
				|  |  | +    updateRationGLJFromDoc:updateRationGLJFromDoc,
 | 
	
		
			
				|  |  | +    getGLJLibByEngineerID:getGLJLibByEngineerID
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  let operationMap = {
 | 
	
	
		
			
				|  | @@ -383,6 +387,9 @@ function deleteByID(datas, callback) {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      })
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  | +async function deleteGLJ(IDs) {
 | 
	
		
			
				|  |  | +    await ration_glj.deleteMany({'ID': {$in: IDs}});
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  async function deleteAndUpdateState(datas) {
 | 
	
		
			
				|  |  |      let result = {
 | 
	
	
		
			
				|  | @@ -506,12 +513,10 @@ function save(user_id, datas, callback) {
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  async function getLibInfo(req) {
 | 
	
		
			
				|  |  | -    let gljLibId = null, engineerID, sessionCompilation = req.session.sessionCompilation,
 | 
	
		
			
				|  |  | -        engineeringLibModel = new EngineeringLibModel() ;
 | 
	
		
			
				|  |  | +    let gljLibId = null, engineerID, sessionCompilation = req.session.sessionCompilation;
 | 
	
		
			
				|  |  |      engineerID = req.params.engineerID;
 | 
	
		
			
				|  |  |      if(engineerID){
 | 
	
		
			
				|  |  | -        let engineeringInfo = await engineeringLibModel.findDataByCondition({'_id': engineerID});
 | 
	
		
			
				|  |  | -        gljLibId = engineeringInfo.glj_lib.length > 0 && typeof engineeringInfo.glj_lib !== 'undefined' ? engineeringInfo.glj_lib[0].id : null;
 | 
	
		
			
				|  |  | +        gljLibId = await getGLJLibByEngineerID(engineerID);
 | 
	
		
			
				|  |  |      }else {
 | 
	
		
			
				|  |  |          throw new Error("工程专业ID为空!");
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -524,6 +529,14 @@ async function getLibInfo(req) {
 | 
	
		
			
				|  |  |      return data;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +async function getGLJLibByEngineerID  (engineerID) {
 | 
	
		
			
				|  |  | +    let engineeringLibModel = new EngineeringLibModel() ;
 | 
	
		
			
				|  |  | +    let engineeringInfo = await engineeringLibModel.findDataByCondition({'_id': engineerID});
 | 
	
		
			
				|  |  | +    let gljLibId = engineeringInfo.glj_lib.length > 0 && typeof engineeringInfo.glj_lib !== 'undefined' ? engineeringInfo.glj_lib[0].id : null;
 | 
	
		
			
				|  |  | +    return gljLibId
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  function getGLJData(info, callback) {
 | 
	
		
			
				|  |  |      let gljDao = new GljDao();
 | 
	
		
			
				|  |  |      let datas = {};
 | 
	
	
		
			
				|  | @@ -603,8 +616,22 @@ async function prepareExtData(projectID,compilation) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  async function addGLJ(rgList,compilation) {
 | 
	
		
			
				|  |  | -    let newRecodes = [];
 | 
	
		
			
				|  |  |      if (rgList.length <= 0) return {};
 | 
	
		
			
				|  |  | +    let newRecodes = await insertAddTypeGLJ(rgList,compilation);
 | 
	
		
			
				|  |  | +    let stateResult = await glj_calculate_facade.calculateQuantity({
 | 
	
		
			
				|  |  | +        projectID: rgList[0].projectID,
 | 
	
		
			
				|  |  | +        rationID: rgList[0].rationID
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  | +    let result = {
 | 
	
		
			
				|  |  | +        newRecodes: newRecodes,
 | 
	
		
			
				|  |  | +        showData: rgList,
 | 
	
		
			
				|  |  | +        adjustState: stateResult.adjustState
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  | +    return result;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +async function insertAddTypeGLJ(rgList,compilation) {
 | 
	
		
			
				|  |  | +    let newRecodes = [];
 | 
	
		
			
				|  |  |      let [unitFileId,ext] = await  prepareExtData(rgList[0].projectID,compilation);
 | 
	
		
			
				|  |  |      for (let g of rgList) {
 | 
	
		
			
				|  |  |          let projectGljModel = new GLJListModel();
 | 
	
	
		
			
				|  | @@ -625,19 +652,10 @@ async function addGLJ(rgList,compilation) {
 | 
	
		
			
				|  |  |          newRecodes.push(createNewRecord(g));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      await ration_glj.insertMany(newRecodes);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    let stateResult = await glj_calculate_facade.calculateQuantity({
 | 
	
		
			
				|  |  | -        projectID: rgList[0].projectID,
 | 
	
		
			
				|  |  | -        rationID: rgList[0].rationID
 | 
	
		
			
				|  |  | -    });
 | 
	
		
			
				|  |  | -    let result = {
 | 
	
		
			
				|  |  | -        newRecodes: newRecodes,
 | 
	
		
			
				|  |  | -        showData: rgList,
 | 
	
		
			
				|  |  | -        adjustState: stateResult.adjustState
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -    return result;
 | 
	
		
			
				|  |  | +    return newRecodes;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  async function replaceGLJ(data,compilation) {
 | 
	
		
			
				|  |  |      let rdata = {};
 | 
	
		
			
				|  |  |      let projectGljModel = new GLJListModel();
 | 
	
	
		
			
				|  | @@ -835,6 +853,28 @@ async function changAdjustState(data, rationList) {
 | 
	
		
			
				|  |  |      return stateList;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +async function getGLJDataByCodes(data,compilation) {
 | 
	
		
			
				|  |  | +  let  gljLibId = await getGLJLibByEngineerID(data.engineerID);
 | 
	
		
			
				|  |  | +  let gljDatas = [];
 | 
	
		
			
				|  |  | +  if(gljLibId){
 | 
	
		
			
				|  |  | +     let stdList =   await  std_glj_lib_gljList_model.find({'repositoryId':gljLibId,code:{'$in':data.codes}});
 | 
	
		
			
				|  |  | +     if(stdList.length > 0){
 | 
	
		
			
				|  |  | +         let property = await projectDao.getProjectProperty(data.projectID);
 | 
	
		
			
				|  |  | +         let ext = projectDao.getExtendData(property,compilation);//多单价处理
 | 
	
		
			
				|  |  | +         for(let s of stdList){
 | 
	
		
			
				|  |  | +             let tem = JSON.parse(JSON.stringify(s));
 | 
	
		
			
				|  |  | +             if(ext && ext.priceField && tem && tem.priceProperty){
 | 
	
		
			
				|  |  | +                 tem.basePrice =  tem.priceProperty[ext.priceField];
 | 
	
		
			
				|  |  | +             }
 | 
	
		
			
				|  |  | +             gljDatas.push(tem);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +         }
 | 
	
		
			
				|  |  | +     }
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +    return gljDatas
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  async function testError() {
 | 
	
		
			
				|  |  |      throw  new Error('test Error');
 | 
	
		
			
				|  |  |  }
 |