ration_facade.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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.stdID = std.ID;
  117. newData.content = std.jobContent;
  118. newData.annotation = std.annotation;
  119. if (std.chapter) {
  120. newData.comments = std.chapter.explanation;
  121. newData.ruleText = std.chapter.ruleText;
  122. }
  123. newData.prefix = '';
  124. newData.from = std.type === 'complementary' ? 'cpt' : 'std';
  125. if(defaultLibID !== std.rationRepId){//借
  126. newData.prefix = '借';
  127. }
  128. else if(std.rationRepId === defaultLibID && newData.from === 'cpt') {
  129. newData.prefix = '补';
  130. }
  131. if(std.feeType == undefined || std.feeType == null || std.feeType ==''){//定额取费专业为空的情况下,取项目属性中的定额取费专业ID
  132. newData.programID = await getProgramForProject(newData.projectID);
  133. }else {
  134. newData.programID = std.feeType;
  135. }
  136. newData.rationAssList = createRationAss(std);
  137. // calculate ration Quantity
  138. }
  139. if(calQuantity){
  140. await CalculateQuantity(newData,newData.billsItemID,newData.projectID);
  141. }
  142. let addRationGLJTime = +new Date();
  143. console.log("计算消耗量时间-------------------------------"+(addRationGLJTime - startTime));
  144. let newRation = await ration_model.model.create(newData);
  145. return newRation;
  146. /*ration_model.model.create(newData);
  147. return newData;*/
  148. }
  149. async function replaceRations(userID,data,compilation) {
  150. let searchDao = new SearchDao();
  151. let recodes = [];
  152. for(let recode of data.nodeInfo){
  153. let stdRation = await searchDao.getRationItem(userID,compilation._id,data.libIDs,recode.newCode, null);
  154. let newRecode = await replaceRation(recode,stdRation,data.defaultLibID,data.projectID,data.calQuantity,compilation);
  155. if(newRecode){
  156. recodes.push(newRecode);
  157. }else {
  158. break;
  159. }
  160. }
  161. return recodes;
  162. }
  163. async function getDefaultProgramID(data) {
  164. let searchDao = new SearchDao();
  165. let programID;
  166. let std = await searchDao.getRationItem(data.userID,data.compilationId,[data.libID],data.code, null);
  167. if(std == null||std ==undefined || std.feeType == undefined || std.feeType == null || std.feeType ==''){//定额取费专业为空的情况下,取项目属性中的定额取费专业ID
  168. programID = await getProgramForProject(data.projectID);
  169. }else {
  170. programID = std.feeType;
  171. }
  172. return programID;
  173. }
  174. async function replaceRation(nodeInfo,stdRation,defaultLibID,projectID,calQuantity,compilation) {
  175. if(nodeInfo.newCode == null||nodeInfo.newCode ==""){//说明是删除编号,则要变成一条空定额
  176. await deleRationSubRecode(projectID,nodeInfo.ID);//删除定额下挂的各种数据,如定额工料机等
  177. return await setEmptyRation(projectID,nodeInfo.ID);
  178. }else if(stdRation){
  179. await deleRationSubRecode(projectID,nodeInfo.ID);//删除定额下挂的各种数据,如定额工料机等
  180. let newRation = await updateRation(stdRation,defaultLibID,nodeInfo.ID,nodeInfo.billsItemID,projectID,calQuantity);//生成并插入新的定额
  181. return await addRationSubList(stdRation,newRation,nodeInfo.needInstall,compilation);
  182. }else {
  183. return null;
  184. }
  185. }
  186. async function addRationSubList(stdRation,newRation,needInstall,compilation) {
  187. let startTime = +new Date();
  188. let ration_gljs = await addRationGLJ(stdRation,newRation,compilation);
  189. let addRationGLJTime = +new Date();
  190. console.log("添加定额工料机时间-----"+(addRationGLJTime - startTime));
  191. let ration_coes = await addRationCoe(stdRation,newRation,compilation);
  192. let addRationCoeTime = +new Date();
  193. console.log("添加定额coe时间-----"+(addRationCoeTime - addRationGLJTime));
  194. let ration_installs = [];
  195. if(needInstall && stdRation.type == 'std'){//只有标准的定额才有安装增加费,补充的定额没有安装增加费
  196. ration_installs = await addRationInstallFee(stdRation,newRation);
  197. }
  198. let addRationInstallFeeTime = +new Date();
  199. console.log("添加定额install时间-----"+(addRationInstallFeeTime - addRationCoeTime));
  200. return {ration:newRation,ration_gljs:ration_gljs,ration_coes:ration_coes,ration_installs:ration_installs};
  201. }
  202. async function addRationInstallFee(std,newRation) {
  203. let install_fee_list = [];
  204. if(std.hasOwnProperty('rationInstList') && std.rationInstList.length > 0){
  205. let installFee = await installationFeeModel.findOne({'projectID': newRation.projectID});
  206. if(!installFee) return;//如果没有找到项目对应的安装增加费,则不添加
  207. for(let ri of std.rationInstList){
  208. let feeItem = _.find(installFee.installFeeItem,{'ID':ri.feeItemId});
  209. let section = _.find(installFee.installSection,{'ID':ri.sectionId});
  210. if(feeItem&&section){
  211. let tem_r_i = {
  212. libID:installFee.libID,
  213. projectID:newRation.projectID,
  214. rationID:newRation.ID,
  215. feeItemId:feeItem.ID,
  216. sectionId:section.ID,
  217. itemName:feeItem.feeItem,
  218. feeType:feeItem.feeType,
  219. sectionName:section.name,
  220. unifiedSetting:1,
  221. ruleId:''
  222. };
  223. if(feeItem.isCal==1&&section.feeRuleId&&section.feeRuleId!=''){//勾选记取时并且有规则ID时才读取
  224. let feeRule = _.find(installFee.feeRule,{'ID':section.feeRuleId});
  225. if(feeRule){
  226. tem_r_i.ruleId = feeRule.ID;
  227. }
  228. }
  229. tem_r_i.ID = uuidV1();
  230. install_fee_list.push(tem_r_i);
  231. }
  232. }
  233. if(install_fee_list.length>0){
  234. await rationInstallationModel.insertMany(install_fee_list);
  235. }
  236. }
  237. return install_fee_list;
  238. }
  239. async function addRationCoe(std,newRation,compilation) {
  240. let ration_coe_list = [];
  241. let seq = 0;
  242. if(std.hasOwnProperty('rationCoeList')&&std.rationCoeList.length>0){//添加标准库的工料机
  243. for(let sub of std.rationCoeList){
  244. let libCoe;
  245. if (std.type === 'std') {
  246. libCoe = await coeMolde.findOne({'libID':std.rationRepId,'ID':sub.ID,"$or": [{"isDeleted": null}, {"isDeleted": false}]});//std.rationRepId;
  247. } else {
  248. libCoe = await compleCoeModel.findOne({ID: sub.ID, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}]});
  249. }
  250. if(libCoe){
  251. let newCoe = {};
  252. newCoe.ID = uuidV1();
  253. newCoe.coeID = sub.ID;
  254. newCoe.seq = seq;
  255. newCoe.name = libCoe.name;
  256. newCoe.content = libCoe.content;
  257. newCoe.isAdjust=0;
  258. newCoe.coes = libCoe.coes;
  259. newCoe.rationID = newRation.ID;
  260. newCoe.projectID = newRation.projectID;
  261. seq++;
  262. ration_coe_list.push(newCoe);
  263. }
  264. }
  265. }
  266. let lastCoe = await getCustomerCoe(newRation.projectID,newRation.ID,seq,compilation);
  267. ration_coe_list.push(lastCoe);
  268. await ration_coe.insertMany(ration_coe_list);
  269. return ration_coe_list;
  270. }
  271. function getCustomerCoeData() {
  272. var coeList = [
  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. { amount:1, operator:'*', gljCode:null, coeType:'设备'}
  279. ];
  280. return coeList;
  281. };
  282. async function getCustomerCoe(projectID,rationID,seq,compilation){//取自定义乘系数,根据编办不同,内容可能不同
  283. //生成默认的自定义乘系数
  284. let lastCoe ={
  285. coeID:-1,
  286. name : '自定义系数',
  287. content:'人工×1,材料×1,机械×1,主材×1,设备×1',
  288. isAdjust:0,
  289. seq:seq,
  290. rationID : rationID,
  291. projectID : projectID
  292. };
  293. lastCoe.ID = uuidV1();
  294. lastCoe.coes = getCustomerCoeData();
  295. try {
  296. //查看编办中有没有重写路径
  297. if(compilation.overWriteUrl && compilation.overWriteUrl!=""){
  298. let overWrite = require("../../.."+compilation.overWriteUrl);
  299. if(overWrite.getCusCoeContent) lastCoe.content = overWrite.getCusCoeContent();
  300. if(overWrite.getCustomerCoeData) lastCoe.coes = overWrite.getCustomerCoeData();
  301. }
  302. return lastCoe
  303. }catch (err){
  304. console.log("读取自定义系数重写文件失败");
  305. console.log(err.message);
  306. return lastCoe
  307. }
  308. }
  309. //对于多单价,多组成物消耗量的编办,通过这个方法获取单价、组成物消耗量的字段,
  310. function getExtendData(property,compilation) {
  311. return projectDao.getExtendData(property,compilation);
  312. }
  313. async function addRationGLJ(std,newRation,compilation) {
  314. let newRationGLJList = [];
  315. let rationGLJShowList = [];
  316. let unitPriceFileId = 0;
  317. let property = await projectDao.getProjectProperty(newRation.projectID);
  318. if(property){
  319. unitPriceFileId = property.unitPriceFile !== undefined ? property.unitPriceFile.id : 0;
  320. }
  321. let ext = getExtendData(property,compilation);
  322. let first = +new Date();
  323. if(std.hasOwnProperty('rationGljList') && std.rationGljList.length > 0){
  324. let stdGLJID =[];//标准工料机ID数组
  325. let cptGLJID=[];//补充工料机ID数组
  326. //let stdGLJID = _.map(std.rationGljList,'gljId');
  327. for(let tem_g of std.rationGljList){
  328. if(tem_g.type == 'complementary'){
  329. cptGLJID.push(tem_g.gljId);
  330. }else {
  331. stdGLJID.push(tem_g.gljId);
  332. }
  333. }
  334. let stdGLJList = stdGLJID.length > 0 ? await std_glj_lib_gljList_model.find({'ID':{'$in':stdGLJID}}):[];//速度优化-------先一次性取出所有的工料机列表
  335. let stdGLJMap = _.indexBy(stdGLJList, 'ID');
  336. let cptGLJList = cptGLJID.length > 0 ? await complementary_glj_model.find({'userId':std.userId,'ID':{'$in':cptGLJID}}):[];
  337. let cptGLJMap = _.indexBy(cptGLJList, 'ID');
  338. let stdGLJMapTime = +new Date();
  339. console.log("找到工料机映射表时间-------------------------------"+(stdGLJMapTime - first));
  340. for(let sub of std.rationGljList){
  341. let newGLJ = {};
  342. newGLJ.ID = uuidV1();
  343. newGLJ.projectID = newRation.projectID;
  344. newGLJ.GLJID = sub.gljId;
  345. newGLJ.rationID = newRation.ID;
  346. newGLJ.billsItemID = newRation.billsItemID;
  347. newGLJ.rationItemQuantity = sub.consumeAmt;
  348. newGLJ.quantity = sub.consumeAmt;
  349. newGLJ.glj_repository_id = std.rationRepId;
  350. let std_glj = null;
  351. if(sub.type == 'complementary'){//有可能来自标准工料机库或补充工料机库
  352. std_glj = cptGLJMap[sub.gljId];
  353. newGLJ.from = 'cpt';
  354. }else {
  355. std_glj = stdGLJMap[sub.gljId];
  356. newGLJ.from = 'std';
  357. //多单价情况处理
  358. if(ext && ext.priceField && std_glj && std_glj.priceProperty){
  359. std_glj.basePrice = std_glj.priceProperty[ext.priceField];
  360. }
  361. }
  362. console.log("================================get std glj=============================================");
  363. console.log(std_glj);
  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. ration.stdID = std.ID;
  418. }
  419. ration.content = std.jobContent;
  420. ration.adjustState = '';
  421. ration.isFromDetail=0;
  422. ration.isSubcontract=false;
  423. ration.fees=[];
  424. if (std.chapter) {
  425. ration.comments = std.chapter.explanation;
  426. ration.ruleText = std.chapter.ruleText;
  427. }
  428. ration.from = std.type === 'complementary' ? 'cpt' : 'std';
  429. //定额前缀 none:0, complementary:1, borrow: 2
  430. ration.prefix = '';
  431. //借用优先级比补充高
  432. if(std.rationRepId !== parseInt(defaultLibID)){//借用
  433. ration.prefix = '借';
  434. }
  435. else if(std.rationRepId === defaultLibID && ration.from === 'cpt') {
  436. ration.prefix = '补';
  437. }
  438. if(std.feeType == undefined || std.feeType == null || std.feeType ==''){//定额取费专业为空的情况下,取项目属性中的定额取费专业ID
  439. ration.programID = await getProgramForProject(projectID);
  440. }else {
  441. ration.programID = std.feeType;
  442. }
  443. ration.rationAssList = createRationAss(std);//生成辅助定额
  444. if(calQuantity){
  445. await CalculateQuantity(ration,billsItemID,projectID);
  446. }
  447. let unsetObject = {
  448. "marketUnitFee":1,
  449. 'marketTotalFee':1,
  450. "maskName":1
  451. }
  452. let newRation = await ration_model.model.findOneAndUpdate({ID:rationID,projectID:projectID},{"$set":ration,"$unset":unsetObject},{new: true});//;
  453. return newRation;
  454. }
  455. async function setEmptyRation(projectID,rationID){
  456. let ration ={};
  457. ration.code = "";
  458. ration.name = "";
  459. ration.caption = "";
  460. ration.unit = "";
  461. ration.libID = null;
  462. ration.content = "";
  463. ration.adjustState = '';
  464. ration.isFromDetail=0;
  465. ration.isSubcontract=false;
  466. ration.fees=[];
  467. ration.comments = "";
  468. ration.ruleText = "";
  469. ration.quantity="";
  470. ration.contain="";
  471. ration.quantityEXP="";
  472. ration.from = 'std';
  473. //定额前缀 none:0, complementary:1, borrow: 2
  474. ration.prefix = '';
  475. ration.rationAssList = [];
  476. ration.marketUnitFee ="";
  477. ration.marketTotalFee ="";
  478. ration.maskName = "";
  479. ration.targetTotalFee ='';
  480. ration.targetUnitFee = "";
  481. ration.deleteInfo = null;
  482. ration.quantityCoe = {};
  483. ration.rationQuantityCoe="";
  484. ration.tenderQuantity = "";
  485. ration.programID = null;
  486. let newRation = await ration_model.model.findOneAndUpdate({ID:rationID,projectID:projectID},{"$set":ration},{new: true});//;
  487. return {ration:newRation,ration_gljs:[],ration_coes:[],ration_installs:[]};
  488. }
  489. function createRationAss(std) {
  490. let rationAssList = [];//生成辅助定额
  491. if(std.hasOwnProperty('rationAssList')&&std.rationAssList.length>0){
  492. for(let i=0;i<std.rationAssList.length;i++){
  493. let ass = std.rationAssList[i];
  494. ass._doc.actualValue = ass.stdValue;
  495. rationAssList.push(ass);
  496. }
  497. }
  498. return rationAssList;
  499. }
  500. async function CalculateQuantity (ration,billsItemID,projectID) {
  501. // calculate ration Quantity
  502. let project = await projectModel.findOne({ID:projectID});
  503. let decimalObject =await decimal_facade.getProjectDecimal(projectID,project);
  504. let quantity_decimal = (decimalObject&&decimalObject.ration&&decimalObject.ration.quantity)?decimalObject.ration.quantity:3;
  505. let pbill = await bill_model.model.findOne({projectID:projectID,ID:billsItemID});
  506. let t_unit = ration.unit?ration.unit.replace(/^\d+/,""):"";
  507. if(t_unit!=pbill.unit){//如果定额工程量的单位去除前面的数字后不等于清单单位,定额工程量保持不变
  508. return ;
  509. }
  510. let billsQuantity = pbill.quantity ? pbill.quantity : 0;
  511. let bill_decimal = await decimal_facade.getBillsQuantityDecimal(projectID,pbill.unit,project);
  512. billsQuantity=scMathUtil.roundForObj(billsQuantity,bill_decimal);
  513. ration.quantityEXP="QDL";
  514. ration.quantity = scMathUtil.roundForObj(billsQuantity / FilterNumberFromUnit(ration.unit),quantity_decimal);//不管是否打勾都做转换
  515. ration.contain = scMathUtil.roundForObj(ration.quantity/billsQuantity,6);
  516. };
  517. async function getProgramForProject(projectID){
  518. let project = await projectModel.findOne({ID:projectID});
  519. return project.property.engineering;
  520. }
  521. function FilterNumberFromUnit (unit) {
  522. let reg = new RegExp('^[0-9]+');
  523. if (reg.test(unit)) {
  524. return parseInt(unit.match(reg)[0]);
  525. } else {
  526. return 1;
  527. }
  528. };