ration_facade.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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.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. let ext = {};
  311. let region = property.region;
  312. let taxType = property.taxType;
  313. if(compilation.priceProperties && compilation.priceProperties.length > 0){//如果是具有多单价的编办,取单价对应的字段
  314. let priceProperty = _.find(compilation.priceProperties,{region:region,taxModel:parseInt(taxType)});
  315. if(priceProperty){
  316. ext['priceField'] = priceProperty.price.dataCode;
  317. }
  318. }
  319. if(compilation.consumeAmtProperties && compilation.consumeAmtProperties.length > 0){
  320. let consumeAmt = _.find(compilation.consumeAmtProperties,{region:region,taxModel:parseInt(taxType)});
  321. if(consumeAmt){
  322. ext['quantityField'] = consumeAmt.consumeAmt.dataCode;
  323. }
  324. }
  325. return _.isEmpty(ext)?null:ext;
  326. }
  327. async function addRationGLJ(std,newRation,compilation) {
  328. let newRationGLJList = [];
  329. let rationGLJShowList = [];
  330. let unitPriceFileId = 0;
  331. let property = await projectDao.getProjectProperty(newRation.projectID);
  332. if(property){
  333. unitPriceFileId = property.unitPriceFile !== undefined ? property.unitPriceFile.id : 0;
  334. }
  335. let ext = getExtendData(property,compilation);
  336. let first = +new Date();
  337. if(std.hasOwnProperty('rationGljList') && std.rationGljList.length > 0){
  338. let stdGLJID =[];//标准工料机ID数组
  339. let cptGLJID=[];//补充工料机ID数组
  340. //let stdGLJID = _.map(std.rationGljList,'gljId');
  341. for(let tem_g of std.rationGljList){
  342. if(tem_g.type == 'complementary'){
  343. cptGLJID.push(tem_g.gljId);
  344. }else {
  345. stdGLJID.push(tem_g.gljId);
  346. }
  347. }
  348. let stdGLJList = stdGLJID.length > 0 ? await std_glj_lib_gljList_model.find({'ID':{'$in':stdGLJID}}):[];//速度优化-------先一次性取出所有的工料机列表
  349. let stdGLJMap = _.indexBy(stdGLJList, 'ID');
  350. let cptGLJList = cptGLJID.length > 0 ? await complementary_glj_model.find({'userId':std.userId,'ID':{'$in':cptGLJID}}):[];
  351. let cptGLJMap = _.indexBy(cptGLJList, 'ID');
  352. let stdGLJMapTime = +new Date();
  353. console.log("找到工料机映射表时间-------------------------------"+(stdGLJMapTime - first));
  354. for(let sub of std.rationGljList){
  355. let newGLJ = {};
  356. newGLJ.ID = uuidV1();
  357. newGLJ.projectID = newRation.projectID;
  358. newGLJ.GLJID = sub.gljId;
  359. newGLJ.rationID = newRation.ID;
  360. newGLJ.billsItemID = newRation.billsItemID;
  361. newGLJ.rationItemQuantity = sub.consumeAmt;
  362. newGLJ.quantity = sub.consumeAmt;
  363. newGLJ.glj_repository_id = std.rationRepId;
  364. let std_glj = null;
  365. if(sub.type == 'complementary'){//有可能来自标准工料机库或补充工料机库
  366. std_glj = cptGLJMap[sub.gljId];
  367. newGLJ.from = 'cpt';
  368. }else {
  369. std_glj = stdGLJMap[sub.gljId];
  370. newGLJ.from = 'std';
  371. //多单价情况处理
  372. if(ext && ext.priceField && std_glj && std_glj.priceProperty){
  373. std_glj.basePrice = std_glj.priceProperty[ext.priceField];
  374. }
  375. }
  376. console.log("================================get std glj=============================================");
  377. console.log(std_glj);
  378. let std_gljTime = +new Date();
  379. if(std_glj){
  380. newGLJ.name = std_glj.name;
  381. newGLJ.code = std_glj.code;
  382. newGLJ.original_code = std_glj.code;
  383. newGLJ.unit = std_glj.unit;
  384. newGLJ.specs = std_glj.specs;
  385. newGLJ.model = std_glj.model;
  386. newGLJ.basePrice = std_glj.basePrice;
  387. newGLJ.marketPrice = std_glj.basePrice;
  388. newGLJ.shortName = std_glj.shortName;
  389. newGLJ.type = std_glj.gljType;
  390. newGLJ.repositoryId = std_glj.repositoryId;
  391. newGLJ.adjCoe = std_glj.adjCoe;
  392. newGLJ.materialType = std_glj.materialType;
  393. newGLJ.materialCoe = std_glj.materialCoe;
  394. newGLJ.createType = 'normal';
  395. let info = await ration_glj_facade.getInfoFromProjectGLJ(newGLJ,unitPriceFileId,ext);
  396. newGLJ = ration_glj_facade.createNewRecord(info);
  397. newRationGLJList.push(newGLJ);
  398. rationGLJShowList.push(info);
  399. }
  400. let InfoFromProjectGLJ = +new Date();
  401. console.log("找到项目工料机时间-------------------------------"+(InfoFromProjectGLJ - std_gljTime));
  402. }
  403. }
  404. let before = +new Date();
  405. console.log("总查询时间为-------------------------------"+(before-first));
  406. if(newRationGLJList.length>0){
  407. await ration_glj.insertMany(newRationGLJList);
  408. }
  409. let after = +new Date();
  410. console.log("实际插入时间为-------------------------------"+(after-before));
  411. console.log("总操作时间为-------------------------------"+(after-first));
  412. return rationGLJShowList;
  413. }
  414. async function deleRationSubRecode(projectID,rationID) {//删除挂在定额下的数据,如工程量明细,定额工料机等
  415. let delete_query={projectID: projectID, rationID: rationID};
  416. //删除工程量明细
  417. await quantity_detail.deleteByQuery(delete_query) ;
  418. await ration_coe.deleteMany(delete_query);//删除附注条件
  419. await ration_glj.deleteMany(delete_query);//删除定额工料机
  420. await rationInstallationModel.deleteMany(delete_query);//删除安装增加费
  421. }
  422. async function updateRation(std,defaultLibID,rationID,billsItemID,projectID,calQuantity) {
  423. // insertNewRation
  424. let ration ={};
  425. ration.code = std.code;
  426. ration.name = std.name;
  427. ration.caption = std.caption;
  428. ration.unit = std.unit;
  429. if (std.type === 'std') {
  430. ration.libID = std.rationRepId;
  431. }
  432. ration.content = std.jobContent;
  433. ration.adjustState = '';
  434. ration.isFromDetail=0;
  435. ration.isSubcontract=false;
  436. ration.fees=[];
  437. if (std.chapter) {
  438. ration.comments = std.chapter.explanation;
  439. ration.ruleText = std.chapter.ruleText;
  440. }
  441. ration.from = std.type === 'complementary' ? 'cpt' : 'std';
  442. //定额前缀 none:0, complementary:1, borrow: 2
  443. ration.prefix = '';
  444. //借用优先级比补充高
  445. if(std.rationRepId !== parseInt(defaultLibID)){//借用
  446. ration.prefix = '借';
  447. }
  448. else if(std.rationRepId === defaultLibID && ration.from === 'cpt') {
  449. ration.prefix = '补';
  450. }
  451. if(std.feeType == undefined || std.feeType == null || std.feeType ==''){//定额取费专业为空的情况下,取项目属性中的定额取费专业ID
  452. ration.programID = await getProgramForProject(projectID);
  453. }else {
  454. ration.programID = std.feeType;
  455. }
  456. ration.rationAssList = createRationAss(std);//生成辅助定额
  457. if(calQuantity){
  458. await CalculateQuantity(ration,billsItemID,projectID);
  459. }
  460. let unsetObject = {
  461. "marketUnitFee":1,
  462. 'marketTotalFee':1,
  463. "maskName":1
  464. }
  465. let newRation = await ration_model.model.findOneAndUpdate({ID:rationID,projectID:projectID},{"$set":ration,"$unset":unsetObject},{new: true});//;
  466. return newRation;
  467. }
  468. async function setEmptyRation(projectID,rationID){
  469. let ration ={};
  470. ration.code = "";
  471. ration.name = "";
  472. ration.caption = "";
  473. ration.unit = "";
  474. ration.libID = null;
  475. ration.content = "";
  476. ration.adjustState = '';
  477. ration.isFromDetail=0;
  478. ration.isSubcontract=false;
  479. ration.fees=[];
  480. ration.comments = "";
  481. ration.ruleText = "";
  482. ration.quantity="";
  483. ration.contain="";
  484. ration.quantityEXP="";
  485. ration.from = 'std';
  486. //定额前缀 none:0, complementary:1, borrow: 2
  487. ration.prefix = '';
  488. ration.rationAssList = [];
  489. ration.marketUnitFee ="";
  490. ration.marketTotalFee ="";
  491. ration.maskName = "";
  492. ration.targetTotalFee ='';
  493. ration.targetUnitFee = "";
  494. ration.deleteInfo = null;
  495. ration.quantityCoe = {};
  496. ration.rationQuantityCoe="";
  497. ration.tenderQuantity = "";
  498. ration.programID = null;
  499. let newRation = await ration_model.model.findOneAndUpdate({ID:rationID,projectID:projectID},{"$set":ration},{new: true});//;
  500. return {ration:newRation,ration_gljs:[],ration_coes:[],ration_installs:[]};
  501. }
  502. function createRationAss(std) {
  503. let rationAssList = [];//生成辅助定额
  504. if(std.hasOwnProperty('rationAssList')&&std.rationAssList.length>0){
  505. for(let i=0;i<std.rationAssList.length;i++){
  506. let ass = std.rationAssList[i];
  507. ass.actualValue = ass.stdValue;
  508. rationAssList.push(ass);
  509. }
  510. }
  511. return rationAssList;
  512. }
  513. async function CalculateQuantity (ration,billsItemID,projectID) {
  514. // calculate ration Quantity
  515. let project = await projectModel.findOne({ID:projectID});
  516. let decimalObject =await decimal_facade.getProjectDecimal(projectID,project);
  517. let quantity_decimal = (decimalObject&&decimalObject.ration&&decimalObject.ration.quantity)?decimalObject.ration.quantity:3;
  518. let pbill = await bill_model.model.findOne({projectID:projectID,ID:billsItemID});
  519. let t_unit = ration.unit?ration.unit.replace(/^\d+/,""):"";
  520. if(t_unit!=pbill.unit){//如果定额工程量的单位去除前面的数字后不等于清单单位,定额工程量保持不变
  521. return ;
  522. }
  523. let billsQuantity = pbill.quantity ? pbill.quantity : 0;
  524. let bill_decimal = await decimal_facade.getBillsQuantityDecimal(projectID,pbill.unit,project);
  525. billsQuantity=scMathUtil.roundForObj(billsQuantity,bill_decimal);
  526. ration.quantityEXP="QDL";
  527. ration.quantity = scMathUtil.roundForObj(billsQuantity / FilterNumberFromUnit(ration.unit),quantity_decimal);//不管是否打勾都做转换
  528. ration.contain = scMathUtil.roundForObj(ration.quantity/billsQuantity,6);
  529. };
  530. async function getProgramForProject(projectID){
  531. let project = await projectModel.findOne({ID:projectID});
  532. return project.property.engineering;
  533. }
  534. function FilterNumberFromUnit (unit) {
  535. let reg = new RegExp('^[0-9]+');
  536. if (reg.test(unit)) {
  537. return parseInt(unit.match(reg)[0]);
  538. } else {
  539. return 1;
  540. }
  541. };