project_facade.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /**
  2. * Created by zhang on 2018/1/26.
  3. */
  4. module.exports = {
  5. markUpdateProject:markUpdateProject,
  6. removeProjectMark:removeProjectMark,
  7. updateNodes:updateNodes,
  8. calcInstallationFee:calcInstallationFee,
  9. calcOverHeightFee: calcOverHeightFee,
  10. saveProperty: saveProperty,
  11. getDefaultColSetting: getDefaultColSetting,
  12. markProjectsToChange:markProjectsToChange,
  13. getSEIProjects:getSEIProjects,
  14. loadSEIProjectData:loadSEIProjectData,
  15. setSEILibData:setSEILibData,
  16. getIndexReportData:getIndexReportData,
  17. setDefaultItemIncrease:setDefaultItemIncrease
  18. };
  19. let mongoose = require('mongoose');
  20. let logger = require("../../../logs/log_helper").logger;
  21. let projectsModel = mongoose.model('projects');
  22. let async_n = require("async");
  23. let _ = require('lodash');
  24. let ration_model = require('../models/ration');
  25. let bill_model = require('../models/bills');
  26. let consts = require('../models/project_consts');
  27. let projectConsts = consts.projectConst;
  28. let ration_glj_model = mongoose.model('ration_glj');
  29. let rationTemplateModel = mongoose.model('ration_template');
  30. let project_glj_model = mongoose.model('glj_list');
  31. let ration_glj_facade = require("../../ration_glj/facade/ration_glj_facade");
  32. let glj_calculate_facade = require("../../ration_glj/facade/glj_calculate_facade");
  33. const uuidV1 = require('uuid/v1');
  34. const gljUtil = require('../../../public/gljUtil');
  35. let stdColSettingModel = mongoose.model('std_main_col_lib');
  36. import GLJListModel from "../../glj/models/glj_list_model";
  37. let economicLib = mongoose.model('std_economic_lib');
  38. let engineerFeatureLib = mongoose.model('std_engineer_feature_lib');
  39. let engineerInfoLib = mongoose.model('std_engineer_info_lib');
  40. let mainQuantityLib = mongoose.model('std_main_quantity_lib');
  41. let materialLib = mongoose.model('std_material_lib');
  42. import fixedFlag from '../../common/const/bills_fixed';
  43. const scMathUtil = require('../../../public/scMathUtil').getUtil();
  44. const billsLibDao = require("../../bills_lib/models/bills_lib_interfaces");
  45. async function calcInstallationFee(data) {
  46. let result={};
  47. let billTasks = generateTasks(data.bills,data.useID);
  48. let rationTasks = generateTasks(data.ration,data.useID);
  49. if(billTasks.length>0){
  50. await bill_model.model.bulkWrite(billTasks);
  51. }
  52. if(rationTasks.length>0){
  53. await ration_model.model.bulkWrite(rationTasks);
  54. }
  55. //如果删除定额,需要删除对应的工料机
  56. if(data.ration.delete.length>0){
  57. let rationIDS = _.map(data.ration.delete,'ID');
  58. await ration_glj_model.deleteMany({projectID: data.ration.delete[0].projectID, rationID: {"$in": rationIDS}});//删除定额工料机
  59. }
  60. let rationGLJTasks = [];
  61. let updateList = [];
  62. if(data.ration.update.length>0){//如果有需要更新的定额工料机
  63. for(let ur of data.ration.update){
  64. for(let g of ur.glj){
  65. let gTasks = {
  66. updateOne:{
  67. filter:{
  68. ID:g.ID,
  69. projectID:g.projectID
  70. },
  71. update :{
  72. quantity:g.quantity,
  73. rationItemQuantity:g.rationItemQuantity
  74. }
  75. }
  76. };
  77. rationGLJTasks.push(gTasks);
  78. updateList.push(g);
  79. }
  80. }
  81. }
  82. if(rationGLJTasks.length>0){
  83. await ration_glj_model.bulkWrite(rationGLJTasks);
  84. }
  85. let newGljList = [];
  86. if(data.ration.add.length>0){//新增的安装子目要增加对应的工料机
  87. for(let nr of data.ration.add){
  88. for(let tkey in nr.glj){
  89. let [newRecode,projectGLJ] = await createRationGLJData(nr.glj[tkey])
  90. newGljList.push(newRecode);
  91. }
  92. }
  93. }
  94. if(newGljList.length>0){
  95. await ration_glj_model.insertMany(newGljList);
  96. }
  97. result.update = updateList;
  98. result.add = newGljList;
  99. return result;
  100. }
  101. async function createRationGLJData(glj) {
  102. glj.ID = uuidV1();
  103. let [info,projectGLJ ] = await ration_glj_facade.getInfoFromProjectGLJ(glj);
  104. let newRecode = ration_glj_facade.createNewRecord(info);
  105. return [newRecode,projectGLJ];
  106. }
  107. function generateTasks(data,userID) {
  108. let tasks=[];
  109. let deleteInfo={deleted: true, deleteDateTime: new Date(), deleteBy: userID};
  110. if(data.delete && data.delete.length > 0){
  111. for(let bd of data.delete){
  112. //原先是假删除,现在改成真删除
  113. let task = {
  114. deleteOne:{
  115. filter:{
  116. ID:bd.ID,
  117. projectID:bd.projectID
  118. }
  119. }
  120. };
  121. /* let task={
  122. updateOne:{
  123. filter:{
  124. ID:bd.ID,
  125. projectID:bd.projectID
  126. },
  127. update :{
  128. deleteInfo:deleteInfo
  129. }
  130. }
  131. };*/
  132. tasks.push(task);
  133. }
  134. }
  135. if(data.add && data.add.length > 0){
  136. for(let n_data of data.add){
  137. let task = {
  138. insertOne :{
  139. document:n_data
  140. }
  141. };
  142. tasks.push(task);
  143. }
  144. }
  145. return tasks;
  146. }
  147. /**
  148. * 计取超高降效费,可能包含更新清单、更新定额、新增清单、新增定额及其子数据、删除定额及其子数据
  149. * @param {Object} data - {updateData: {ration: [],..}, addData: {ration: [],...}, deleteData: {ration: [],...}}
  150. * @return {Object} - {bills: Array, rationGLJ: Array}
  151. */
  152. async function calcOverHeightFee(data) {
  153. // 更新数据
  154. async function update({ project, bills, ration }) {
  155. const tasks = [];
  156. // 更新项目
  157. if (project && project.ID) {
  158. const projectTask = projectsModel.update({ ID: project.ID },
  159. { 'property.overHeightOption': project.overHeightOption, 'property.overHeightSpecificID': project.overHeightSpecificID });
  160. tasks.push(projectTask);
  161. }
  162. // 更新清单和定额的超高降效列
  163. const models = [];
  164. if (bills.length) {
  165. models.push({ model: bill_model.model, items: bills });
  166. }
  167. if (ration.length) {
  168. models.push({ model: ration_model.model, items: ration });
  169. }
  170. models.forEach(modelData => {
  171. const bulkTask = modelData.items.map(item => (
  172. {
  173. updateOne: {
  174. filter: { ID: item.ID },
  175. update: { overHeight: item.overHeight }
  176. }
  177. }));
  178. const task = modelData.model.bulkWrite(bulkTask);
  179. tasks.push(task);;
  180. });
  181. if (!tasks.length) {
  182. return;
  183. }
  184. await Promise.all(tasks);
  185. }
  186. // 插入数据
  187. async function add({ bills, ration, rationGLJ}) {
  188. const tasks = [];
  189. // 匹配标准清单,加上工作内容等数据
  190. for (const billsItem of bills) {
  191. let stdBills = await billsLibDao.getStdBillsByCode(billsItem);
  192. stdBills = stdBills ? stdBills._doc : null;
  193. if (stdBills) {
  194. // 获取项目清单所需要的数据
  195. const projectBillsData = billsLibDao.getDataToProjectBills(stdBills);
  196. Object.assign(billsItem, projectBillsData);
  197. } else {
  198. delete billsItem.billsLibId;
  199. }
  200. billsItem.code += '001';
  201. }
  202. // 新增清单
  203. if (bills.length) {
  204. tasks.push(bill_model.model.insertMany(bills));
  205. }
  206. // 新增定额
  207. if (ration.length) {
  208. tasks.push(ration_model.model.insertMany(ration));
  209. }
  210. // 完整的定额人材机数据
  211. const completeRationGLJList = [];
  212. // 完整的项目人材机数据
  213. const completeProjectGLJList = [];
  214. // createRationGLJData方法不能并行,涉及到项目人材机的新增,如果并行可能会重复插入数据
  215. for (const rGLJ of rationGLJ) {
  216. const [completeRGLJ, completePGLJ] = await createRationGLJData(rGLJ);
  217. completeRationGLJList.push(completeRGLJ);
  218. completeProjectGLJList.push(completePGLJ);
  219. }
  220. if (completeRationGLJList.length) {
  221. tasks.push(ration_glj_model.insertMany(completeRationGLJList))
  222. }
  223. // 返回新的清单、定额人材机、项目人材机数据数据
  224. const rst = {
  225. bills,
  226. rationGLJ: completeRationGLJList,
  227. projectGLJ: completeProjectGLJList,
  228. }
  229. if (!tasks.length) {
  230. return rst;
  231. }
  232. await Promise.all(tasks);
  233. return rst;
  234. }
  235. // 删除数据
  236. async function del({ ration }) {
  237. const tasks = [];
  238. const rationIDList = ration.map(item => item.ID);
  239. if (!rationIDList.length) {
  240. return;
  241. }
  242. // 删除定额数据
  243. const rationTask = ration_model.model.deleteMany({ ID: {$in: rationIDList} });
  244. tasks.push(rationTask);
  245. // 删除定额人材机数据
  246. const rationGLJTask = ration_glj_model.deleteMany({ rationID: {$in: rationIDList} });
  247. tasks.push(rationGLJTask);
  248. await Promise.all(tasks);
  249. }
  250. // 处理任务
  251. const { updateData, addData, deleteData } = data;
  252. const updateTask = update(updateData);
  253. const addTask = add(addData);
  254. const delTask = del(deleteData);
  255. const [updateRst, addRst, delRst] = await Promise.all([updateTask, addTask, delTask]);
  256. return addRst;
  257. }
  258. async function updateNodes(datas){
  259. let nodeGroups = _.groupBy(datas,'type');
  260. let asyncTasks = [];
  261. let deleteRationIDs=[];
  262. let taskMap = {};
  263. taskMap[projectConsts.BILLS] = {tasks:[],model:bill_model.model};
  264. taskMap[projectConsts.RATION] = {tasks:[],model:ration_model.model};
  265. taskMap[projectConsts.RATION_GLJ] = {tasks:[],model:ration_glj_model};
  266. taskMap[projectConsts.PROJECTGLJ] = {tasks:[],model:project_glj_model};
  267. taskMap[projectConsts.PROJECT] = {tasks:[],model:projectsModel};
  268. taskMap[projectConsts.RATION_TEMPLATE] = {tasks:[],model:rationTemplateModel};
  269. for(let type in nodeGroups){
  270. for(let node of nodeGroups[type]){
  271. if(taskMap[type]){
  272. if(type == projectConsts.RATION){
  273. //处理面积增加费的数据
  274. if(node.data.hasOwnProperty("areaIncreaseFee")){
  275. let areaSetting = null;
  276. if(nodeGroups[projectConsts.PROJECT]){
  277. for(let pn of nodeGroups[projectConsts.PROJECT]){
  278. if(pn.data['property.areaSetting']) areaSetting = pn.data['property.areaSetting'];
  279. }
  280. }
  281. let t = await glj_calculate_facade.calculateQuantity({rationID:node.data.ID},true,false,node.data.areaIncreaseFee,areaSetting);
  282. node.data.adjustState = t.adjustState;
  283. }
  284. if(node.action == "delete") deleteRationIDs.push(node.data.ID);
  285. }
  286. if(type == projectConsts.RATION_GLJ){
  287. if(node.action == "add"){//添加定額工料机的時候,要先走项目工料机的逻辑
  288. let [newRecode,projectGLJ] = await createRationGLJData(node.data);
  289. node.data =newRecode;
  290. node.projectGLJ = projectGLJ;
  291. }
  292. }
  293. taskMap[type].tasks.push(getTask(node));
  294. }
  295. }
  296. }
  297. for(let key in taskMap){
  298. if(taskMap[key].tasks.length> 0) asyncTasks.push(taskMap[key].model.bulkWrite(taskMap[key].tasks))
  299. }
  300. if(asyncTasks.length>0) await Promise.all(asyncTasks);
  301. if(deleteRationIDs.length > 0) await ration_glj_model.deleteMany({rationID: {$in: deleteRationIDs}});
  302. return datas;
  303. function getTask(node,idFiled = 'ID') {
  304. let task={};
  305. if(node.action == "add"){
  306. task.insertOne ={
  307. document:node.data
  308. }
  309. }else if(node.action =="delete"){
  310. task.deleteOne ={
  311. filter:{}
  312. };
  313. task.deleteOne.filter[idFiled] = node.data[idFiled];
  314. }else {
  315. task.updateOne = {
  316. filter:{},
  317. update :_.cloneDeep(node.data)
  318. };
  319. task.updateOne.filter[idFiled] = node.data[idFiled];//现在复制项目也重新生成一个新的ID了,所以ID是唯一的
  320. delete task.updateOne.update[idFiled];//防止误操作
  321. }
  322. return task;
  323. }
  324. }
  325. /*function updateNodes(datas,callback) {
  326. let tasks = [];
  327. for(let node of datas){
  328. tasks.push(updateOne(node))
  329. }
  330. async_n.parallel(tasks, function(err, results) {
  331. if (!err){
  332. callback(0, '', results);
  333. }
  334. else{
  335. console.log(err);
  336. callback(1, 'save project failed'+err.message, null);
  337. }
  338. });
  339. function updateOne(node) {
  340. if(node.type == projectConsts.BILLS){
  341. return function (asCallback) {
  342. bill_model.model.findOneAndUpdate({projectID: node.data.projectID, ID: node.data.ID,deleteInfo: null}, node.data,{new: true}, asCallback);
  343. }
  344. }else if(node.type ==projectConsts.RATION){
  345. return function (asCallback) {
  346. ration_model.model.findOneAndUpdate({projectID: node.data.projectID, ID: node.data.ID,deleteInfo: null}, node.data,{new: true}, asCallback);
  347. }
  348. }
  349. }
  350. }*/
  351. //data = {feeRateID:111111,projectID:1245}; type = feeRate
  352. async function markUpdateProject(data,type) {
  353. let query = {deleteInfo:null};
  354. if(type=="feeRate"){//更改了费率
  355. query['property.feeFile.id'] = data.feeRateID;
  356. }
  357. if(type=="unitFile"){//更改了单价文件
  358. query['property.unitPriceFile.id'] = data.unitFileID;//unitPriceFile
  359. }
  360. let projects = await projectsModel.find(query);
  361. return await markProjectsToChange(projects,type,data.projectID);
  362. }
  363. async function markProjectsToChange(projects,type,extProjectID){
  364. let tasks=[];
  365. for(let p of projects){
  366. if(extProjectID && p.ID===extProjectID) continue;//排除当前项目
  367. tasks.push(generateMarkTask(type,p.ID));
  368. }
  369. return tasks.length>0 ? await projectsModel.bulkWrite(tasks):null;
  370. }
  371. async function removeProjectMark(projectID) {
  372. return await projectsModel.findOneAndUpdate({ID:projectID},{"$unset":{"changeMark":1}});
  373. }
  374. function generateMarkTask(value,projectID) {
  375. let task = {
  376. updateOne:{
  377. filter:{
  378. ID:projectID
  379. },
  380. update:{
  381. changeMark:value
  382. }
  383. }
  384. };
  385. return task
  386. }
  387. // {projectID: 5, propertyName: 'aaa', propertyValue: 1}
  388. function saveProperty(data, callback){
  389. let obj = {};
  390. let pn = 'property.' + data.propertyName;
  391. obj[pn] = data.propertyValue;
  392. projectsModel.update({"ID": data.projectID}, obj, function (err) {
  393. if (err) {
  394. logger.err(pn + ' save error: ' + err);
  395. callback(err, null)
  396. } else {
  397. // logger.info(pn + ' saved.');
  398. callback('', null);
  399. }}
  400. );
  401. }
  402. async function getDefaultColSetting(libID){
  403. return await stdColSettingModel.findOne({ID: libID, deleted: false}, '-_id main_tree_col');
  404. }
  405. function sortChildren(lists) {
  406. let IDMap ={},nextMap = {}, firstNode = null,newList=[];
  407. for(let l of lists){
  408. if(l.children&&l.children.length > 0) l.children = sortChildren(l.children);//递规排序
  409. IDMap[l.ID] = l;
  410. if(l.NextSiblingID!=-1) nextMap[l.NextSiblingID] = l;
  411. }
  412. for(let t of lists){
  413. if(!nextMap[t.ID]){ //如果在下一节点映射没找到,则是第一个节点
  414. firstNode = t;
  415. break;
  416. }
  417. }
  418. if(firstNode){
  419. newList.push(firstNode);
  420. delete IDMap[firstNode.ID];
  421. setNext(firstNode,newList);
  422. }
  423. //容错处理,如果链断了的情况,直接添加到后面
  424. for(let key in IDMap){
  425. if(IDMap[key]) newList.push(IDMap[key])
  426. }
  427. return newList;
  428. function setNext(node,array) {
  429. if(node.NextSiblingID != -1){
  430. let next = IDMap[node.NextSiblingID];
  431. if(next){
  432. array.push(next);
  433. delete IDMap[next.ID];
  434. setNext(next,array);
  435. }
  436. }
  437. }
  438. }
  439. async function getSEIProjects(projectID) {
  440. let project = await projectsModel.findOne({ID:projectID});
  441. if(!project) throw new Error(`找不到建设项目:${projectID}`);
  442. let tem_e = await projectsModel.find({ParentID:project.ID});
  443. let engineers = [];
  444. for(let e of tem_e){
  445. if(!e.deleteInfo || !e.deleteInfo.deleted){
  446. let tenders = await projectsModel.find({ParentID:e.ID});
  447. let children = [];
  448. for(let t of tenders){
  449. if(!t.deleteInfo || !t.deleteInfo.deleted){
  450. children.push(t);
  451. }
  452. }
  453. e._doc.children = children;
  454. engineers.push(e);
  455. }
  456. }
  457. engineers = sortChildren(engineers);
  458. project._doc.children = engineers;
  459. return project;
  460. }
  461. async function loadSEIProjectData(projectID) {
  462. let gljListModel = new GLJListModel();
  463. let [gljList, mixRatioConnectData,mixRatioMap,unitPriceMap] = await gljListModel.getListByProjectId(projectID);
  464. let rations = await ration_model.getDataSync(projectID);
  465. let bills = await bill_model.getDataSync(projectID);
  466. let ration_gljs = await ration_glj_model.find({projectID:projectID});
  467. let projectGLJs = {
  468. gljList : gljList,
  469. mixRatioConnectData:mixRatioConnectData,
  470. mixRatioMap:mixRatioMap,
  471. unitPriceMap:unitPriceMap
  472. };
  473. return{bills:bills,rations:rations,ration_gljs:ration_gljs,projectGLJs:projectGLJs}
  474. }
  475. //从建设项目中取工程信息默认值
  476. async function setDefaultInfo(rootProjectID,engineerInfos){
  477. let rootProject = await projectsModel.findOne({ID:rootProjectID}).lean();
  478. if(rootProject){
  479. let baseInfo = _.find(rootProject.property.basicInformation,{key:"basicInfo"});
  480. if(!baseInfo) return;
  481. let baseMap = {};
  482. let attrs = ["工程地点","开工日期","竣工日期","编制日期"];
  483. for(let item of baseInfo.items){
  484. baseMap[item.dispName] = item;
  485. }
  486. for(let en of engineerInfos){
  487. if(attrs.indexOf(en.dispName) != -1){
  488. let key = en.dispName;
  489. if(key == "工程地点") key = "工程所在地";
  490. en.value = baseMap[key].value;
  491. }
  492. }
  493. }
  494. }
  495. async function setSEILibData(property){
  496. if(property.engineerInfoLibID){//工程信息指标
  497. let engineerInfo = await engineerInfoLib.findOne({'ID':property.engineerInfoLibID}).lean();
  498. if(engineerInfo){
  499. property.engineerInfos = engineerInfo.info;
  500. await setDefaultInfo(property.rootProjectID,property.engineerInfos);
  501. }
  502. }
  503. if(property.engineerFeatureLibID){//工程特征指标
  504. let engineerFeature = await engineerFeatureLib.findOne({'ID':property.engineerFeatureLibID});
  505. if(engineerFeature) property.engineerFeatures = engineerFeature.features;
  506. }
  507. if(property.materialLibID){//主要工料指标
  508. let material = await materialLib.findOne({'ID':property.materialLibID});
  509. if(material) property.materials = material.materials;
  510. }
  511. if(property.mainQuantityLibID){//主要工程量指标
  512. let mainQuantity = await mainQuantityLib.findOne({'ID':property.mainQuantityLibID});
  513. if(mainQuantity) property.mainQuantities = mainQuantity.index;
  514. }
  515. if(property.economicLibID){//主要工程量指标
  516. let economic = await economicLib.findOne({'ID':property.economicLibID});
  517. if(economic) property.economics = economic.index;
  518. }
  519. }
  520. function setDefaultItemIncrease(property) {
  521. property.itemIncreaseSetting = {
  522. isCalc : false,
  523. setting:[
  524. {"name":"在生产车间边生产边施工","base":"人工费","coe":10,"scope":{}},
  525. {"name":"在有害身体健康的场所内施工","base":"人工费","coe":10,"scope":{}},
  526. {"name":"在洞内、地下室内、库内或暗室内进行施工","base":"人工费","coe":40,"scope":{}},
  527. {"name":"在洞内、地下室内、库内或暗室内进行施工(模板拆除)","base":"人工费","coe":10,"scope":{}}
  528. ]
  529. }
  530. }
  531. async function getIndexReportData(projectID,keyArr) {
  532. let project = await projectsModel.findOne({ID:projectID});
  533. let bills = await bill_model.getDataSync(projectID);
  534. let result = {};
  535. for(let key of keyArr){
  536. switch (key) {
  537. case 'ProjectCostFields':
  538. result[key] =getEngineerCostData(project.property,bills);
  539. break;
  540. case 'ProjectEcoFields':
  541. result[key] = getEconomicDatas(project.property,bills);
  542. break;
  543. case 'ProjectLabMaterialFields':
  544. result[key] = await getMainMaterialDatas(projectID,project.property);
  545. break;
  546. case 'ProjectQtyFields':
  547. result[key] = await getQuantityDatas(project.property,bills);
  548. break;
  549. case 'ProjectInfoFields':
  550. result[key] = getEngineerInfoData(project.property.engineerInfos);
  551. break;
  552. case 'ProjectFeatureFields':
  553. result[key] = getEngineerFeaturesDatas(project.property.engineerFeatures);
  554. break;
  555. }
  556. }
  557. return result
  558. }
  559. function getEngineerInfoData(engineerInfos) {
  560. let datas = [];
  561. for(let info of engineerInfos){
  562. let d = {
  563. name:info.dispName,
  564. value:info.value
  565. };
  566. datas.push(d);
  567. }
  568. return datas;
  569. }
  570. function getEngineerFeaturesDatas(engineerFeatures) {
  571. let datas = [];
  572. if (engineerFeatures !== null && engineerFeatures !== undefined) {
  573. for(let f of engineerFeatures){
  574. let tem = {
  575. ID:f.ID,
  576. name:f.name,
  577. value:f.value,
  578. ParentID:f.ParentID
  579. }
  580. datas.push(tem);
  581. }
  582. }
  583. return datas;
  584. }
  585. function getQuantityDatas(property,bills) {
  586. return gljUtil.getQuantityDatas(property.engineerFeatures,property.mainQuantities,bills,fixedFlag,_,scMathUtil,property.decimal)
  587. }
  588. function getEconomicDatas(property,bills) {
  589. return gljUtil.getEconomicDatas(property.engineerFeatures,property.economics,bills,fixedFlag,_,scMathUtil,property.decimal)
  590. }
  591. function getEngineerCostData(property,bills){
  592. let datas = [];
  593. let priceIndex = gljUtil.getEngineerCostData(property,bills,fixedFlag,scMathUtil);
  594. for(let c of priceIndex.children){
  595. let tem = {
  596. name:c.name,
  597. cost:parseFloat(c.attrs[0].value),
  598. unitCost:parseFloat(c.attrs[1].value),
  599. per:parseFloat(c.attrs[2].value)
  600. };
  601. datas.push(tem);
  602. }
  603. return datas;
  604. }
  605. async function getMainMaterialDatas(projectID,property) {
  606. let gljListModel = new GLJListModel();
  607. let [gljList, mixRatioConnectData,mixRatioMap,unitPriceMap] = await gljListModel.getListByProjectId(projectID, property.unitPriceFile?property.unitPriceFile.id:null);
  608. gljList = JSON.parse(JSON.stringify(gljList));
  609. await calcProjectGLJQuantity(projectID,{gljList:gljList,mixRatioMap:mixRatioMap},property);
  610. return gljUtil.getMainMaterialDatas(property.engineerFeatures,property.materials,{gljList:gljList},property.calcOptions,property.decimal,false,_,scMathUtil)
  611. }
  612. async function calcProjectGLJQuantity(projectID,projectGLJDatas,property){
  613. let q_decimal = property.decimal.glj.quantity;
  614. let rationGLJDatas = await ration_glj_model.find({'projectID':projectID});
  615. let rationDatas = await ration_model.model.find({'projectID':projectID});
  616. gljUtil.calcProjectGLJQuantity(projectGLJDatas,rationGLJDatas,rationDatas,[],q_decimal)
  617. }