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