|  | @@ -9,7 +9,7 @@ import mongoose from "mongoose";
 | 
	
		
			
				|  |  |  import BaseModel from "../../common/base/base_model";
 | 
	
		
			
				|  |  |  import CompilationModel from "./compilation_model";
 | 
	
		
			
				|  |  |  let stdRationLibModel = mongoose.model("std_ration_lib_map");
 | 
	
		
			
				|  |  | -import {default as EngineeringConst, List as EngineeringList} from "../../common/const/engineering";
 | 
	
		
			
				|  |  | +import { default as EngineeringConst, List as EngineeringList } from "../../common/const/engineering";
 | 
	
		
			
				|  |  |  const billsGuidanceLibModel = mongoose.model('std_billsGuidance_lib');
 | 
	
		
			
				|  |  |  const billsLibListsModel = mongoose.model('std_bills_lib_lists');
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -38,7 +38,7 @@ class EngineeringLibModel extends BaseModel {
 | 
	
		
			
				|  |  |              return result;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          let id = '';
 | 
	
		
			
				|  |  | -        for(let tmp of data) {
 | 
	
		
			
				|  |  | +        for (let tmp of data) {
 | 
	
		
			
				|  |  |              if (tmp.engineering === engineering) {
 | 
	
		
			
				|  |  |                  id = tmp.engineering_id;
 | 
	
		
			
				|  |  |                  break;
 | 
	
	
		
			
				|  | @@ -47,16 +47,16 @@ class EngineeringLibModel extends BaseModel {
 | 
	
		
			
				|  |  |          if (id === '') {
 | 
	
		
			
				|  |  |              return result;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        let condition = {_id: id};
 | 
	
		
			
				|  |  | +        let condition = { _id: id };
 | 
	
		
			
				|  |  |          return this.findDataByCondition(condition);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    async getLibsByValuationID(valuationID){
 | 
	
		
			
				|  |  | -        return this.findDataByCondition({valuationID:valuationID},null,false);
 | 
	
		
			
				|  |  | +    async getLibsByValuationID(valuationID) {
 | 
	
		
			
				|  |  | +        return this.findDataByCondition({ valuationID: valuationID }, null, false);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    async deleteByValuationID(valuationID){
 | 
	
		
			
				|  |  | -        return await this.db.delete({valuationID:valuationID});
 | 
	
		
			
				|  |  | +    async deleteByValuationID(valuationID) {
 | 
	
		
			
				|  |  | +        return await this.db.delete({ valuationID: valuationID });
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -65,14 +65,14 @@ class EngineeringLibModel extends BaseModel {
 | 
	
		
			
				|  |  |       * @param valuationID
 | 
	
		
			
				|  |  |       * @returns {Promise.<*>}
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    async addStdLib(valuationID){
 | 
	
		
			
				|  |  | +    async addStdLib(valuationID) {
 | 
	
		
			
				|  |  |          let stdLibs = [];
 | 
	
		
			
				|  |  | -        for(let eng of EngineeringList){
 | 
	
		
			
				|  |  | +        for (let eng of EngineeringList) {
 | 
	
		
			
				|  |  |              let tem = {
 | 
	
		
			
				|  |  | -                glj_col:{showAdjustPrice:false},
 | 
	
		
			
				|  |  | -                valuationID:valuationID,
 | 
	
		
			
				|  |  | -                name:eng.name,
 | 
	
		
			
				|  |  | -                engineering:eng.value
 | 
	
		
			
				|  |  | +                glj_col: { showAdjustPrice: false },
 | 
	
		
			
				|  |  | +                valuationID: valuationID,
 | 
	
		
			
				|  |  | +                name: eng.name,
 | 
	
		
			
				|  |  | +                engineering: eng.value
 | 
	
		
			
				|  |  |              };
 | 
	
		
			
				|  |  |              stdLibs.push(tem);
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -80,18 +80,18 @@ class EngineeringLibModel extends BaseModel {
 | 
	
		
			
				|  |  |          return result;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    async addEngineer(data){
 | 
	
		
			
				|  |  | -        data.glj_col = {showAdjustPrice:false};
 | 
	
		
			
				|  |  | -        if(data.compilationId && data.compilationId!=""){
 | 
	
		
			
				|  |  | +    async addEngineer(data) {
 | 
	
		
			
				|  |  | +        data.glj_col = { showAdjustPrice: false };
 | 
	
		
			
				|  |  | +        if (data.compilationId && data.compilationId != "") {
 | 
	
		
			
				|  |  |              data.ration_lib = [];
 | 
	
		
			
				|  |  | -            let rationList = await stdRationLibModel.find({compilationId:data.compilationId},['ID','dispName']);
 | 
	
		
			
				|  |  | -            for(let i =0;i< rationList.length;i++){
 | 
	
		
			
				|  |  | +            let rationList = await stdRationLibModel.find({ compilationId: data.compilationId }, ['ID', 'dispName']);
 | 
	
		
			
				|  |  | +            for (let i = 0; i < rationList.length; i++) {
 | 
	
		
			
				|  |  |                  let tem = {
 | 
	
		
			
				|  |  | -                    id:rationList[i].ID,
 | 
	
		
			
				|  |  | -                    name:rationList[i].dispName,
 | 
	
		
			
				|  |  | -                    isDefault:false
 | 
	
		
			
				|  |  | +                    id: rationList[i].ID,
 | 
	
		
			
				|  |  | +                    name: rationList[i].dispName,
 | 
	
		
			
				|  |  | +                    isDefault: false
 | 
	
		
			
				|  |  |                  };
 | 
	
		
			
				|  |  | -                if(i == 0) tem.isDefault = true;
 | 
	
		
			
				|  |  | +                if (i == 0) tem.isDefault = true;
 | 
	
		
			
				|  |  |                  data.ration_lib.push(tem);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -99,6 +99,15 @@ class EngineeringLibModel extends BaseModel {
 | 
	
		
			
				|  |  |          return result;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    // 拷贝工程专业
 | 
	
		
			
				|  |  | +    async copyEngineer(sourceID) {
 | 
	
		
			
				|  |  | +        const engineering = await this.db.findOne({ _id: sourceID });
 | 
	
		
			
				|  |  | +        const newEngineering = engineering._doc;
 | 
	
		
			
				|  |  | +        delete newEngineering._id;
 | 
	
		
			
				|  |  | +        newEngineering.visible = false;
 | 
	
		
			
				|  |  | +        await this.db.create(newEngineering);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 新增标准库
 | 
	
		
			
				|  |  |       *
 | 
	
	
		
			
				|  | @@ -107,12 +116,12 @@ class EngineeringLibModel extends BaseModel {
 | 
	
		
			
				|  |  |       * @return {Promise}
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      async addLib(engineerId, data) {
 | 
	
		
			
				|  |  | -        if(data.glj_col){
 | 
	
		
			
				|  |  | -            data.glj_col =  JSON.parse(data.glj_col);
 | 
	
		
			
				|  |  | +        if (data.glj_col) {
 | 
	
		
			
				|  |  | +            data.glj_col = JSON.parse(data.glj_col);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        data.isInstall == 'true'?data.isInstall=true:data.isInstall=false;
 | 
	
		
			
				|  |  | -        data.isItemIncrease == 'true'?data.isItemIncrease=true:data.isItemIncrease=false;
 | 
	
		
			
				|  |  | -        data.isAreaIncrease == 'true'?data.isAreaIncrease=true:data.isAreaIncrease=false;
 | 
	
		
			
				|  |  | +        data.isInstall == 'true' ? data.isInstall = true : data.isInstall = false;
 | 
	
		
			
				|  |  | +        data.isItemIncrease == 'true' ? data.isItemIncrease = true : data.isItemIncrease = false;
 | 
	
		
			
				|  |  | +        data.isAreaIncrease == 'true' ? data.isAreaIncrease = true : data.isAreaIncrease = false;
 | 
	
		
			
				|  |  |          let result = false;
 | 
	
		
			
				|  |  |          data = this.filterLibData(data);
 | 
	
		
			
				|  |  |          try {
 | 
	
	
		
			
				|  | @@ -136,16 +145,16 @@ class EngineeringLibModel extends BaseModel {
 | 
	
		
			
				|  |  |                      lib.libType = libTypeMap[lib.id] || '1';
 | 
	
		
			
				|  |  |                  });
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            let engineeringLib = await this.findDataByCondition({_id:engineerId});
 | 
	
		
			
				|  |  | -            if(engineeringLib){
 | 
	
		
			
				|  |  | +            let engineeringLib = await this.findDataByCondition({ _id: engineerId });
 | 
	
		
			
				|  |  | +            if (engineeringLib) {
 | 
	
		
			
				|  |  |                  // 存在则直接更新
 | 
	
		
			
				|  |  |                  delete data.id;
 | 
	
		
			
				|  |  |                  delete data.section;
 | 
	
		
			
				|  |  | -                let condition = {_id: engineerId};
 | 
	
		
			
				|  |  | +                let condition = { _id: engineerId };
 | 
	
		
			
				|  |  |                  result = await this.db.update(condition, data);
 | 
	
		
			
				|  |  |                  result = result.ok === 1;
 | 
	
		
			
				|  |  | -            }else {
 | 
	
		
			
				|  |  | -                throw  new Error("找不到对应的工程专业");
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                throw new Error("找不到对应的工程专业");
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          } catch (error) {
 | 
	
	
		
			
				|  | @@ -170,16 +179,16 @@ class EngineeringLibModel extends BaseModel {
 | 
	
		
			
				|  |  |          data.engineering = parseInt(data.engineering);
 | 
	
		
			
				|  |  |          //需求修改,工程专业可以随便输入了
 | 
	
		
			
				|  |  |          //检测专业工程是否合法
 | 
	
		
			
				|  |  | -   /*     let match = false;
 | 
	
		
			
				|  |  | -        for(let index in EngineeringConst) {
 | 
	
		
			
				|  |  | -            if (EngineeringConst[index] === data.engineering) {
 | 
	
		
			
				|  |  | -                match = true;
 | 
	
		
			
				|  |  | -                break;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if (!match) {
 | 
	
		
			
				|  |  | -            throw '工程专业错误';
 | 
	
		
			
				|  |  | -        }*/
 | 
	
		
			
				|  |  | +        /*     let match = false;
 | 
	
		
			
				|  |  | +             for(let index in EngineeringConst) {
 | 
	
		
			
				|  |  | +                 if (EngineeringConst[index] === data.engineering) {
 | 
	
		
			
				|  |  | +                     match = true;
 | 
	
		
			
				|  |  | +                     break;
 | 
	
		
			
				|  |  | +                 }
 | 
	
		
			
				|  |  | +             }
 | 
	
		
			
				|  |  | +             if (!match) {
 | 
	
		
			
				|  |  | +                 throw '工程专业错误';
 | 
	
		
			
				|  |  | +             }*/
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          // 判断标准清单
 | 
	
		
			
				|  |  |          data.bill_lib = this._validLib(data.bill_lib);
 | 
	
	
		
			
				|  | @@ -243,24 +252,24 @@ class EngineeringLibModel extends BaseModel {
 | 
	
		
			
				|  |  |      _validLib(libData) {
 | 
	
		
			
				|  |  |          let result = [];
 | 
	
		
			
				|  |  |          // 判断标准库
 | 
	
		
			
				|  |  | -        if (libData === undefined || libData ===null ||libData === '') {
 | 
	
		
			
				|  |  | +        if (libData === undefined || libData === null || libData === '') {
 | 
	
		
			
				|  |  |              return result;//throw '标准库不能为空'; 按新需求,标准库等不做非空判断
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          libData = libData instanceof Array ? libData : [libData];
 | 
	
		
			
				|  |  | -        for(let tmp in libData) {
 | 
	
		
			
				|  |  | +        for (let tmp in libData) {
 | 
	
		
			
				|  |  |              result[tmp] = JSON.parse(libData[tmp]);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return result;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      //设置默认定额库
 | 
	
		
			
				|  |  | -    setDefaultRation(data){
 | 
	
		
			
				|  |  | -        if(data.ration_lib && data.ration_lib.length>0){
 | 
	
		
			
				|  |  | -            if(data.ration_isDefault && data.ration_isDefault != ""){
 | 
	
		
			
				|  |  | -                for(let r of data.ration_lib){
 | 
	
		
			
				|  |  | -                    r.id.toString() == data.ration_isDefault?r.isDefault = true:r.isDefault=false;
 | 
	
		
			
				|  |  | +    setDefaultRation(data) {
 | 
	
		
			
				|  |  | +        if (data.ration_lib && data.ration_lib.length > 0) {
 | 
	
		
			
				|  |  | +            if (data.ration_isDefault && data.ration_isDefault != "") {
 | 
	
		
			
				|  |  | +                for (let r of data.ration_lib) {
 | 
	
		
			
				|  |  | +                    r.id.toString() == data.ration_isDefault ? r.isDefault = true : r.isDefault = false;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -            }else {
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  |                  data.ration_lib[0].isDefault = true;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -281,11 +290,11 @@ class EngineeringLibModel extends BaseModel {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          // 整理需要查找的数据
 | 
	
		
			
				|  |  |          let findIdList = [];
 | 
	
		
			
				|  |  | -        for(let engineering of valuationData.engineering_list) {
 | 
	
		
			
				|  |  | +        for (let engineering of valuationData.engineering_list) {
 | 
	
		
			
				|  |  |              findIdList.push(engineering.engineering_id);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        let condition = {_id: {$in: findIdList}};
 | 
	
		
			
				|  |  | +        let condition = { _id: { $in: findIdList } };
 | 
	
		
			
				|  |  |          let libData = await this.findDataByCondition(condition, null, false);
 | 
	
		
			
				|  |  |          if (libData === null) {
 | 
	
		
			
				|  |  |              return result;
 | 
	
	
		
			
				|  | @@ -293,7 +302,7 @@ class EngineeringLibModel extends BaseModel {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          // 整理数据
 | 
	
		
			
				|  |  |          let countData = {};
 | 
	
		
			
				|  |  | -        for(let tmp of libData) {
 | 
	
		
			
				|  |  | +        for (let tmp of libData) {
 | 
	
		
			
				|  |  |              countData[tmp._id] = {
 | 
	
		
			
				|  |  |                  bill_count: tmp.bill_lib.length,
 | 
	
		
			
				|  |  |                  ration_count: tmp.ration_lib.length,
 | 
	
	
		
			
				|  | @@ -305,7 +314,7 @@ class EngineeringLibModel extends BaseModel {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        for(let engineering of valuationData.engineering_list) {
 | 
	
		
			
				|  |  | +        for (let engineering of valuationData.engineering_list) {
 | 
	
		
			
				|  |  |              if (countData[engineering.engineering_id] !== undefined) {
 | 
	
		
			
				|  |  |                  result[engineering.engineering] = countData[engineering.engineering_id];
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -316,7 +325,7 @@ class EngineeringLibModel extends BaseModel {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      async copyRationLibsToOthers(valuationID, engineeringID) {
 | 
	
		
			
				|  |  |          const compilationModel = new CompilationModel();
 | 
	
		
			
				|  |  | -        const compilation = await compilationModel.model.findOne({ $or: [{ 'bill_valuation.id': valuationID }, { 'ration_valuation.id': valuationID }]});
 | 
	
		
			
				|  |  | +        const compilation = await compilationModel.model.findOne({ $or: [{ 'bill_valuation.id': valuationID }, { 'ration_valuation.id': valuationID }] });
 | 
	
		
			
				|  |  |          if (!compilation) {
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -329,7 +338,7 @@ class EngineeringLibModel extends BaseModel {
 | 
	
		
			
				|  |  |          if (!engineering) {
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        await this.model.updateMany({ valuationID: { $in: valuationIDList } }, {$set: { ration_lib: engineering.ration_lib }});
 | 
	
		
			
				|  |  | +        await this.model.updateMany({ valuationID: { $in: valuationIDList } }, { $set: { ration_lib: engineering.ration_lib } });
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  }
 |