ration_facade.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. /**
  2. * Created by zhang on 2018/2/9.
  3. */
  4. let mongoose = require('mongoose');
  5. import SearchDao from '../../complementary_ration_lib/models/searchModel';
  6. const scMathUtil = require('../../../public/scMathUtil').getUtil();
  7. let ration_glj_facade = require("../../ration_glj/facade/ration_glj_facade");
  8. let quantity_detail = require("../facade/quantity_detail_facade");
  9. let ration_glj = mongoose.model('ration_glj');
  10. let ration_coe = mongoose.model('ration_coe');
  11. let ration_model = require('../models/ration');
  12. let bill_model = require('../models/bills');
  13. let decimal_facade = require('./decimal_facade');
  14. let installationFeeModel = mongoose.model("installation_fee");
  15. let rationInstallationModel = mongoose.model('ration_installation');
  16. const uuidV1 = require('uuid/v1');
  17. let std_glj_lib_gljList_model = mongoose.model('std_glj_lib_gljList');
  18. let complementary_glj_model = mongoose.model('complementary_glj_lib');
  19. let rationItemModel = mongoose.model("std_ration_lib_ration_items");
  20. let complementaryRationModel = mongoose.model('complementary_ration_items');
  21. let coeMolde = mongoose.model('std_ration_lib_coe_list');
  22. let compleCoeModel = mongoose.model('complementary_ration_coe_list');
  23. let _= require('lodash');
  24. const projectDao = require('../../pm/models/project_model').project;
  25. let projectModel = mongoose.model('projects');
  26. const fs = require('fs');
  27. module.exports = {
  28. replaceRations: replaceRations,
  29. addNewRation:addNewRation,
  30. addMultiRation: addMultiRation,
  31. getSameSectionRations:getSameSectionRations,
  32. getExtendData:getExtendData,
  33. getDefaultProgramID:getDefaultProgramID
  34. };
  35. async function addNewRation(data,compilation) {
  36. let query = data.itemQuery;
  37. let stdRation = null;
  38. let startTime = +new Date();
  39. if(query){
  40. let searchDao = new SearchDao();
  41. stdRation = await searchDao.getRationItem(query.userID, compilation._id, [query.rationRepId],query.code, query.ID);
  42. //data.newData.code = query.code;
  43. }
  44. let stdRationTime = +new Date();
  45. console.log("取std定额时间-------------------------------"+(stdRationTime - startTime));
  46. if(data.brUpdate.length>0){
  47. await updateSerialNo(data.brUpdate);
  48. }
  49. let newRation =await insertNewRation(data.newData,data.defaultLibID,stdRation,data.calQuantity);
  50. let addRationGLJTime = +new Date();
  51. console.log("插入新定额时间-------------------------------"+(addRationGLJTime - stdRationTime));
  52. if(stdRation){
  53. return await addRationSubList(stdRation,newRation,data.needInstall,compilation);
  54. }else {
  55. return {ration:newRation};
  56. }
  57. }
  58. async function addMultiRation(datas,compilation) {
  59. let rst = [];
  60. for(let data of datas){
  61. let r = await addNewRation(data,compilation);
  62. rst.push(r);
  63. }
  64. return rst;
  65. }
  66. async function getSameSectionRations(data,userId,compilationId){
  67. //let userId
  68. //要先根据定额获取所属章节的ID
  69. let from = data.from; //定额类型,是标准的还是用户定义的
  70. let code = data.code;
  71. let libID = data.libID;
  72. let sectionId,rations=[];
  73. if(from == 'std'){
  74. let ration = await rationItemModel.findOne({rationRepId:libID,code:code},['sectionId']);
  75. sectionId = ration? ration.sectionId:null;
  76. }else {
  77. let ration = await complementaryRationModel.findOne({userId:userId,compilationId: compilationId,code:code},['sectionId']);
  78. sectionId = ration?ration.sectionId:null;
  79. }
  80. if(sectionId){
  81. if (from == 'std') {
  82. rations = await rationItemModel.find({sectionId: sectionId});
  83. } else {
  84. rations = await complementaryRationModel.find({userId: userId, sectionId: sectionId});
  85. }
  86. rations = _.sortBy(rations,'code');
  87. }
  88. return rations
  89. }
  90. async function updateSerialNo(serialNoUpdate){
  91. let tasks=[];
  92. for(let data of serialNoUpdate){
  93. let task={
  94. updateOne:{
  95. filter:{
  96. ID:data.ID,
  97. projectID:data.projectID
  98. },
  99. update :{
  100. serialNo:data.serialNo
  101. }
  102. }
  103. };
  104. tasks.push(task);
  105. }
  106. await ration_model.model.bulkWrite(tasks);
  107. }
  108. async function insertNewRation(newData,defaultLibID,std,calQuantity) {//插入新的定额
  109. let startTime = +new Date();
  110. if(std){
  111. newData.code = std.code;
  112. newData.name = std.name;
  113. newData.caption = std.caption;
  114. newData.unit = std.unit;
  115. newData.libID = std.rationRepId;
  116. newData.content = std.jobContent;
  117. newData.annotation = std.annotation;
  118. if (std.chapter) {
  119. newData.comments = std.chapter.explanation;
  120. newData.ruleText = std.chapter.ruleText;
  121. }
  122. newData.prefix = '';
  123. newData.from = std.type === 'complementary' ? 'cpt' : 'std';
  124. if(defaultLibID !== std.rationRepId){//借
  125. newData.prefix = '借';
  126. }
  127. else if(std.rationRepId === defaultLibID && newData.from === 'cpt') {
  128. newData.prefix = '补';
  129. }
  130. if(std.feeType == undefined || std.feeType == null || std.feeType ==''){//定额取费专业为空的情况下,取项目属性中的定额取费专业ID
  131. newData.programID = await getProgramForProject(newData.projectID);
  132. }else {
  133. newData.programID = std.feeType;
  134. }
  135. newData.rationAssList = createRationAss(std);
  136. // calculate ration Quantity
  137. }
  138. if(calQuantity){
  139. await CalculateQuantity(newData,newData.billsItemID,newData.projectID);
  140. }
  141. let addRationGLJTime = +new Date();
  142. console.log("计算消耗量时间-------------------------------"+(addRationGLJTime - startTime));
  143. let newRation = await ration_model.model.create(newData);
  144. return newRation;
  145. /*ration_model.model.create(newData);
  146. return newData;*/
  147. }
  148. async function replaceRations(userID,data,compilation) {
  149. let searchDao = new SearchDao();
  150. let recodes = [];
  151. for(let recode of data.nodeInfo){
  152. let stdRation = await searchDao.getRationItem(userID,compilation._id,data.libIDs,recode.newCode, null);
  153. let newRecode = await replaceRation(recode,stdRation,data.defaultLibID,data.projectID,data.calQuantity,compilation);
  154. if(newRecode){
  155. recodes.push(newRecode);
  156. }else {
  157. break;
  158. }
  159. }
  160. return recodes;
  161. }
  162. async function getDefaultProgramID(data) {
  163. let searchDao = new SearchDao();
  164. let programID;
  165. let std = await searchDao.getRationItem(data.userID,data.compilationId,[data.libID],data.code, null);
  166. if(std == null||std ==undefined || std.feeType == undefined || std.feeType == null || std.feeType ==''){//定额取费专业为空的情况下,取项目属性中的定额取费专业ID
  167. programID = await getProgramForProject(data.projectID);
  168. }else {
  169. programID = std.feeType;
  170. }
  171. return programID;
  172. }
  173. async function replaceRation(nodeInfo,stdRation,defaultLibID,projectID,calQuantity,compilation) {
  174. if(nodeInfo.newCode == null||nodeInfo.newCode ==""){//说明是删除编号,则要变成一条空定额
  175. await deleRationSubRecode(projectID,nodeInfo.ID);//删除定额下挂的各种数据,如定额工料机等
  176. return await setEmptyRation(projectID,nodeInfo.ID);
  177. }else if(stdRation){
  178. await deleRationSubRecode(projectID,nodeInfo.ID);//删除定额下挂的各种数据,如定额工料机等
  179. let newRation = await updateRation(stdRation,defaultLibID,nodeInfo.ID,nodeInfo.billsItemID,projectID,calQuantity);//生成并插入新的定额
  180. return await addRationSubList(stdRation,newRation,nodeInfo.needInstall,compilation);
  181. }else {
  182. return null;
  183. }
  184. }
  185. async function addRationSubList(stdRation,newRation,needInstall,compilation) {
  186. let startTime = +new Date();
  187. let ration_gljs = await addRationGLJ(stdRation,newRation,compilation);
  188. let addRationGLJTime = +new Date();
  189. console.log("添加定额工料机时间-----"+(addRationGLJTime - startTime));
  190. let ration_coes = await addRationCoe(stdRation,newRation,compilation);
  191. let addRationCoeTime = +new Date();
  192. console.log("添加定额coe时间-----"+(addRationCoeTime - addRationGLJTime));
  193. let ration_installs = [];
  194. if(needInstall && stdRation.type == 'std'){//只有标准的定额才有安装增加费,补充的定额没有安装增加费
  195. ration_installs = await addRationInstallFee(stdRation,newRation);
  196. }
  197. let addRationInstallFeeTime = +new Date();
  198. console.log("添加定额install时间-----"+(addRationInstallFeeTime - addRationCoeTime));
  199. return {ration:newRation,ration_gljs:ration_gljs,ration_coes:ration_coes,ration_installs:ration_installs};
  200. }
  201. async function addRationInstallFee(std,newRation) {
  202. let install_fee_list = [];
  203. if(std.hasOwnProperty('rationInstList') && std.rationInstList.length > 0){
  204. let installFee = await installationFeeModel.findOne({'projectID': newRation.projectID});
  205. if(!installFee) return;//如果没有找到项目对应的安装增加费,则不添加
  206. for(let ri of std.rationInstList){
  207. let feeItem = _.find(installFee.installFeeItem,{'ID':ri.feeItemId});
  208. let section = _.find(installFee.installSection,{'ID':ri.sectionId});
  209. if(feeItem&&section){
  210. let tem_r_i = {
  211. libID:installFee.libID,
  212. projectID:newRation.projectID,
  213. rationID:newRation.ID,
  214. feeItemId:feeItem.ID,
  215. sectionId:section.ID,
  216. itemName:feeItem.feeItem,
  217. feeType:feeItem.feeType,
  218. sectionName:section.name,
  219. unifiedSetting:1,
  220. ruleId:''
  221. };
  222. if(feeItem.isCal==1&&section.feeRuleId&&section.feeRuleId!=''){//勾选记取时并且有规则ID时才读取
  223. let feeRule = _.find(installFee.feeRule,{'ID':section.feeRuleId});
  224. if(feeRule){
  225. tem_r_i.ruleId = feeRule.ID;
  226. }
  227. }
  228. tem_r_i.ID = uuidV1();
  229. install_fee_list.push(tem_r_i);
  230. }
  231. }
  232. if(install_fee_list.length>0){
  233. await rationInstallationModel.insertMany(install_fee_list);
  234. }
  235. }
  236. return install_fee_list;
  237. }
  238. async function addRationCoe(std,newRation,compilation) {
  239. let ration_coe_list = [];
  240. let seq = 0;
  241. if(std.hasOwnProperty('rationCoeList')&&std.rationCoeList.length>0){//添加标准库的工料机
  242. for(let sub of std.rationCoeList){
  243. let libCoe;
  244. if (std.type === 'std') {
  245. libCoe = await coeMolde.findOne({'libID':std.rationRepId,'ID':sub.ID,"$or": [{"isDeleted": null}, {"isDeleted": false}]});//std.rationRepId;
  246. } else {
  247. libCoe = await compleCoeModel.findOne({ID: sub.ID, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}]});
  248. }
  249. if(libCoe){
  250. let newCoe = {};
  251. newCoe.ID = uuidV1();
  252. newCoe.coeID = sub.ID;
  253. newCoe.seq = seq;
  254. newCoe.name = libCoe.name;
  255. newCoe.content = libCoe.content;
  256. newCoe.isAdjust=0;
  257. newCoe.coes = libCoe.coes;
  258. newCoe.rationID = newRation.ID;
  259. newCoe.projectID = newRation.projectID;
  260. seq++;
  261. ration_coe_list.push(newCoe);
  262. }
  263. }
  264. }
  265. let lastCoe = await getCustomerCoe(newRation.projectID,newRation.ID,seq,compilation);
  266. ration_coe_list.push(lastCoe);
  267. await ration_coe.insertMany(ration_coe_list);
  268. return ration_coe_list;
  269. }
  270. function getCustomerCoeData() {
  271. var coeList = [
  272. {amount:1, operator:'*', gljCode:null, coeType:'定额'},
  273. { amount:1, operator:'*', gljCode:null, coeType:'人工'},
  274. { amount:1, operator:'*', gljCode:null, coeType:'材料'},
  275. { amount:1, operator:'*', gljCode:null, coeType:'机械'},
  276. { amount:1, operator:'*', gljCode:null, coeType:'主材'},
  277. { amount:1, operator:'*', gljCode:null, coeType:'设备'}
  278. ];
  279. return coeList;
  280. };
  281. async function getCustomerCoe(projectID,rationID,seq,compilation){//取自定义乘系数,根据编办不同,内容可能不同
  282. //生成默认的自定义乘系数
  283. let lastCoe ={
  284. coeID:-1,
  285. name : '自定义系数',
  286. content:'人工×1,材料×1,机械×1,主材×1,设备×1',
  287. isAdjust:0,
  288. seq:seq,
  289. rationID : rationID,
  290. projectID : projectID
  291. };
  292. lastCoe.ID = uuidV1();
  293. lastCoe.coes = getCustomerCoeData();
  294. try {
  295. //查看编办中有没有重写路径
  296. if(compilation.overWriteUrl && compilation.overWriteUrl!=""){
  297. let overWrite = require("../../.."+compilation.overWriteUrl);
  298. if(overWrite.getCusCoeContent) lastCoe.content = overWrite.getCusCoeContent();
  299. if(overWrite.getCustomerCoeData) lastCoe.coes = overWrite.getCustomerCoeData();
  300. }
  301. return lastCoe
  302. }catch (err){
  303. console.log("读取自定义系数重写文件失败");
  304. console.log(err.message);
  305. return lastCoe
  306. }
  307. }
  308. //对于多单价,多组成物消耗量的编办,通过这个方法获取单价、组成物消耗量的字段,
  309. function getExtendData(property,compilation) {
  310. return projectDao.getExtendData(property,compilation);
  311. }
  312. async function addRationGLJ(std,newRation,compilation) {
  313. let newRationGLJList = [];
  314. let rationGLJShowList = [];
  315. let unitPriceFileId = 0;
  316. let property = await projectDao.getProjectProperty(newRation.projectID);
  317. if(property){
  318. unitPriceFileId = property.unitPriceFile !== undefined ? property.unitPriceFile.id : 0;
  319. }
  320. let ext = getExtendData(property,compilation);
  321. let first = +new Date();
  322. if(std.hasOwnProperty('rationGljList') && std.rationGljList.length > 0){
  323. let stdGLJID =[];//标准工料机ID数组
  324. let cptGLJID=[];//补充工料机ID数组
  325. //let stdGLJID = _.map(std.rationGljList,'gljId');
  326. for(let tem_g of std.rationGljList){
  327. if(tem_g.type == 'complementary'){
  328. cptGLJID.push(tem_g.gljId);
  329. }else {
  330. stdGLJID.push(tem_g.gljId);
  331. }
  332. }
  333. let stdGLJList = stdGLJID.length > 0 ? await std_glj_lib_gljList_model.find({'ID':{'$in':stdGLJID}}):[];//速度优化-------先一次性取出所有的工料机列表
  334. let stdGLJMap = _.indexBy(stdGLJList, 'ID');
  335. let cptGLJList = cptGLJID.length > 0 ? await complementary_glj_model.find({'userId':std.userId,'ID':{'$in':cptGLJID}}):[];
  336. let cptGLJMap = _.indexBy(cptGLJList, 'ID');
  337. let stdGLJMapTime = +new Date();
  338. console.log("找到工料机映射表时间-------------------------------"+(stdGLJMapTime - first));
  339. for(let sub of std.rationGljList){
  340. let newGLJ = {};
  341. newGLJ.ID = uuidV1();
  342. newGLJ.projectID = newRation.projectID;
  343. newGLJ.GLJID = sub.gljId;
  344. newGLJ.rationID = newRation.ID;
  345. newGLJ.billsItemID = newRation.billsItemID;
  346. newGLJ.rationItemQuantity = sub.consumeAmt;
  347. newGLJ.quantity = sub.consumeAmt;
  348. newGLJ.glj_repository_id = std.rationRepId;
  349. let std_glj = null;
  350. if(sub.type == 'complementary'){//有可能来自标准工料机库或补充工料机库
  351. std_glj = cptGLJMap[sub.gljId];
  352. newGLJ.from = 'cpt';
  353. }else {
  354. std_glj = stdGLJMap[sub.gljId];
  355. newGLJ.from = 'std';
  356. //多单价情况处理
  357. if(ext && ext.priceField && std_glj && std_glj.priceProperty){
  358. std_glj.basePrice = std_glj.priceProperty[ext.priceField];
  359. }
  360. }
  361. console.log("================================get std glj=============================================");
  362. console.log(std_glj);
  363. let std_gljTime = +new Date();
  364. if(std_glj){
  365. newGLJ.name = std_glj.name;
  366. newGLJ.code = std_glj.code;
  367. newGLJ.original_code = std_glj.code;
  368. newGLJ.unit = std_glj.unit;
  369. newGLJ.specs = std_glj.specs;
  370. newGLJ.model = std_glj.model;
  371. newGLJ.basePrice = std_glj.basePrice;
  372. newGLJ.marketPrice = std_glj.basePrice;
  373. newGLJ.shortName = std_glj.shortName;
  374. newGLJ.type = std_glj.gljType;
  375. newGLJ.repositoryId = std_glj.repositoryId;
  376. newGLJ.adjCoe = std_glj.adjCoe;
  377. newGLJ.materialType = std_glj.materialType;
  378. newGLJ.materialCoe = std_glj.materialCoe;
  379. newGLJ.createType = 'normal';
  380. let info = await ration_glj_facade.getInfoFromProjectGLJ(newGLJ,unitPriceFileId,ext);
  381. newGLJ = ration_glj_facade.createNewRecord(info);
  382. newRationGLJList.push(newGLJ);
  383. rationGLJShowList.push(info);
  384. }
  385. let InfoFromProjectGLJ = +new Date();
  386. console.log("找到项目工料机时间-------------------------------"+(InfoFromProjectGLJ - std_gljTime));
  387. }
  388. }
  389. let before = +new Date();
  390. console.log("总查询时间为-------------------------------"+(before-first));
  391. if(newRationGLJList.length>0){
  392. await ration_glj.insertMany(newRationGLJList);
  393. }
  394. let after = +new Date();
  395. console.log("实际插入时间为-------------------------------"+(after-before));
  396. console.log("总操作时间为-------------------------------"+(after-first));
  397. return rationGLJShowList;
  398. }
  399. async function deleRationSubRecode(projectID,rationID) {//删除挂在定额下的数据,如工程量明细,定额工料机等
  400. let delete_query={projectID: projectID, rationID: rationID};
  401. //删除工程量明细
  402. await quantity_detail.deleteByQuery(delete_query) ;
  403. await ration_coe.deleteMany(delete_query);//删除附注条件
  404. await ration_glj.deleteMany(delete_query);//删除定额工料机
  405. await rationInstallationModel.deleteMany(delete_query);//删除安装增加费
  406. }
  407. async function updateRation(std,defaultLibID,rationID,billsItemID,projectID,calQuantity) {
  408. // insertNewRation
  409. let ration ={};
  410. ration.code = std.code;
  411. ration.name = std.name;
  412. ration.caption = std.caption;
  413. ration.unit = std.unit;
  414. if (std.type === 'std') {
  415. ration.libID = std.rationRepId;
  416. }
  417. ration.content = std.jobContent;
  418. ration.adjustState = '';
  419. ration.isFromDetail=0;
  420. ration.isSubcontract=false;
  421. ration.fees=[];
  422. if (std.chapter) {
  423. ration.comments = std.chapter.explanation;
  424. ration.ruleText = std.chapter.ruleText;
  425. }
  426. ration.from = std.type === 'complementary' ? 'cpt' : 'std';
  427. //定额前缀 none:0, complementary:1, borrow: 2
  428. ration.prefix = '';
  429. //借用优先级比补充高
  430. if(std.rationRepId !== parseInt(defaultLibID)){//借用
  431. ration.prefix = '借';
  432. }
  433. else if(std.rationRepId === defaultLibID && ration.from === 'cpt') {
  434. ration.prefix = '补';
  435. }
  436. if(std.feeType == undefined || std.feeType == null || std.feeType ==''){//定额取费专业为空的情况下,取项目属性中的定额取费专业ID
  437. ration.programID = await getProgramForProject(projectID);
  438. }else {
  439. ration.programID = std.feeType;
  440. }
  441. ration.rationAssList = createRationAss(std);//生成辅助定额
  442. if(calQuantity){
  443. await CalculateQuantity(ration,billsItemID,projectID);
  444. }
  445. let unsetObject = {
  446. "marketUnitFee":1,
  447. 'marketTotalFee':1,
  448. "maskName":1
  449. }
  450. let newRation = await ration_model.model.findOneAndUpdate({ID:rationID,projectID:projectID},{"$set":ration,"$unset":unsetObject},{new: true});//;
  451. return newRation;
  452. }
  453. async function setEmptyRation(projectID,rationID){
  454. let ration ={};
  455. ration.code = "";
  456. ration.name = "";
  457. ration.caption = "";
  458. ration.unit = "";
  459. ration.libID = null;
  460. ration.content = "";
  461. ration.adjustState = '';
  462. ration.isFromDetail=0;
  463. ration.isSubcontract=false;
  464. ration.fees=[];
  465. ration.comments = "";
  466. ration.ruleText = "";
  467. ration.quantity="";
  468. ration.contain="";
  469. ration.quantityEXP="";
  470. ration.from = 'std';
  471. //定额前缀 none:0, complementary:1, borrow: 2
  472. ration.prefix = '';
  473. ration.rationAssList = [];
  474. ration.marketUnitFee ="";
  475. ration.marketTotalFee ="";
  476. ration.maskName = "";
  477. ration.targetTotalFee ='';
  478. ration.targetUnitFee = "";
  479. ration.deleteInfo = null;
  480. ration.quantityCoe = {};
  481. ration.rationQuantityCoe="";
  482. ration.tenderQuantity = "";
  483. ration.programID = null;
  484. let newRation = await ration_model.model.findOneAndUpdate({ID:rationID,projectID:projectID},{"$set":ration},{new: true});//;
  485. return {ration:newRation,ration_gljs:[],ration_coes:[],ration_installs:[]};
  486. }
  487. function createRationAss(std) {
  488. let rationAssList = [];//生成辅助定额
  489. if(std.hasOwnProperty('rationAssList')&&std.rationAssList.length>0){
  490. for(let i=0;i<std.rationAssList.length;i++){
  491. let ass = std.rationAssList[i];
  492. ass._doc.actualValue = ass.stdValue;
  493. rationAssList.push(ass);
  494. }
  495. }
  496. return rationAssList;
  497. }
  498. async function CalculateQuantity (ration,billsItemID,projectID) {
  499. // calculate ration Quantity
  500. let project = await projectModel.findOne({ID:projectID});
  501. let decimalObject =await decimal_facade.getProjectDecimal(projectID,project);
  502. let quantity_decimal = (decimalObject&&decimalObject.ration&&decimalObject.ration.quantity)?decimalObject.ration.quantity:3;
  503. let pbill = await bill_model.model.findOne({projectID:projectID,ID:billsItemID});
  504. let t_unit = ration.unit?ration.unit.replace(/^\d+/,""):"";
  505. if(t_unit!=pbill.unit){//如果定额工程量的单位去除前面的数字后不等于清单单位,定额工程量保持不变
  506. return ;
  507. }
  508. let billsQuantity = pbill.quantity ? pbill.quantity : 0;
  509. let bill_decimal = await decimal_facade.getBillsQuantityDecimal(projectID,pbill.unit,project);
  510. billsQuantity=scMathUtil.roundForObj(billsQuantity,bill_decimal);
  511. ration.quantityEXP="QDL";
  512. ration.quantity = scMathUtil.roundForObj(billsQuantity / FilterNumberFromUnit(ration.unit),quantity_decimal);//不管是否打勾都做转换
  513. ration.contain = scMathUtil.roundForObj(ration.quantity/billsQuantity,6);
  514. };
  515. async function getProgramForProject(projectID){
  516. let project = await projectModel.findOne({ID:projectID});
  517. return project.property.engineering;
  518. }
  519. function FilterNumberFromUnit (unit) {
  520. let reg = new RegExp('^[0-9]+');
  521. if (reg.test(unit)) {
  522. return parseInt(unit.match(reg)[0]);
  523. } else {
  524. return 1;
  525. }
  526. };