pm_controller.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. /**
  2. * Created by Mai on 2017/1/18.
  3. */
  4. import UnitPriceFileModel from "../../glj/models/unit_price_file_model";
  5. import moment from 'moment';
  6. import CompilationModel from "../../users/models/compilation_model";
  7. let mongoose = require('mongoose');
  8. let ProjectsData = require('../models/project_model').project;
  9. let labourCoe = require('../../main/facade/labour_coe_facade');
  10. let projType = require('../models/project_model').projType;
  11. let fileType = require('../models/project_model').fileType;
  12. const engineering = require("../../common/const/engineering");
  13. let EngineeringLibModel = require("../../users/models/engineering_lib_model");
  14. let fee_rate_facade = require("../../fee_rates/facade/fee_rates_facade");
  15. let billsModel = require('../../main/models/bills').model;
  16. let rationsModel = require('../../main/models/ration').model;
  17. let projectModel = mongoose.model('projects');
  18. let unitPriceFileModel = mongoose.model('unit_price_file');
  19. let feeRateFileModel = mongoose.model('fee_rate_file');
  20. let asyncTool = require('async');
  21. let pm_facade = require('../facade/pm_facade');
  22. const userModel = mongoose.model('user');
  23. let config = require("../../../config/config.js");
  24. const optionModel = mongoose.model('options');
  25. const stdBillsGuidanceLibModel = mongoose.model('std_billsGuidance_lib');
  26. const fs = require('fs');
  27. const _ = require('lodash');
  28. import SectionTreeDao from '../../complementary_ration_lib/models/sectionTreeModel';
  29. let sectionTreeDao = new SectionTreeDao();
  30. //统一回调函数
  31. let callback = function(req, res, err, message, data){
  32. res.json({error: err, message: message, data: data});
  33. };
  34. module.exports = {
  35. checkRight: function (req, res) {
  36. if(typeof req.body.data === 'object'){
  37. req.body.data = JSON.stringify(req.body.data);
  38. }
  39. let data = JSON.parse(req.body.data);
  40. if (data.user_id) {
  41. return data.user_id === req.session.sessionUser.id;
  42. } else {
  43. return false;
  44. }
  45. },
  46. checkProjectRight: function (userId, projectId, callback) {
  47. ProjectsData.getProject(projectId).then(async function (result) {
  48. /**
  49. * result._doc.userID(Number): MongoDB
  50. * userId(String): Session.userID
  51. */
  52. let isShare = false;
  53. //判断是否是打开分享的项目
  54. if(userId !== result.userID){
  55. isShare = await pm_facade.isShare(userId, result);
  56. }
  57. if ((userId === result.userID || isShare) && result._doc.projType === projType.tender) {
  58. callback(true);
  59. } else {
  60. callback(false);
  61. }
  62. }).catch(function (err) {
  63. callback(false);
  64. });
  65. },
  66. getProjects: async function(req, res){
  67. await ProjectsData.getUserProjects(req.session.sessionUser.id, req.session.sessionCompilation._id, function(err, message, projects){
  68. if (projects) {
  69. callback(req, res, err, message, projects);
  70. } else {
  71. callback(req, res, err, message, null);
  72. }
  73. });
  74. },
  75. updateProjects: async function (req, res) {
  76. let data = JSON.parse(req.body.data);
  77. await ProjectsData.updateUserProjects(req.session.sessionUser.id, req.session.sessionCompilation._id, req.session.sessionCompilation.name, data.updateData, function (err, message, data) {
  78. if (err === 0) {
  79. callback(req, res, err, message, data);
  80. } else {
  81. callback(req, res, err, message, null);
  82. }
  83. });
  84. },
  85. // CSL, 2017-12-14 该方法用于项目属性:提交保存混合型数据,这些数据来自不同的表,包括projects.property、ration、bills、labour_coes.
  86. updateMixDatas: async function(req, res){
  87. let datas = JSON.parse(req.body.data).mixDataArr;
  88. let functions = [];
  89. function updateFunc(model, cod, doc) {
  90. return function (cb) {
  91. model.update(cod, doc, cb);
  92. }
  93. };
  94. function updateLC(){
  95. return function (cb) {
  96. datas.labourCoes.updateData.projectID = datas.projectID;
  97. labourCoe.save(datas.labourCoes.updateData, cb);
  98. }
  99. };
  100. // 项目属性
  101. if (Object.keys(datas.properties).length > 0){
  102. //基本信息特殊处理,更新建设项目
  103. if(datas.properties['property.basicInformation']){
  104. let constructionProject = await pm_facade.getConstructionProject(datas.projectID);
  105. if(constructionProject){
  106. functions.push(updateFunc(projectModel, {ID: constructionProject.ID}, {'property.basicInformation': datas.properties['property.basicInformation']}));
  107. }
  108. delete datas.properties['property.basicInformation'];
  109. }
  110. functions.push(updateFunc(projectModel, {ID: datas.projectID}, datas.properties));
  111. };
  112. //选项
  113. if(datas.options && datas.options.updateData){
  114. functions.push(updateFunc(optionModel, {user_id: req.session.sessionUser.id, compilation_id: req.session.sessionCompilation._id}, {'options.GENERALOPTS': datas.options.updateData}));
  115. }
  116. // 人工系数
  117. if (datas.labourCoes&&datas.labourCoes.updateData){
  118. functions.push(updateLC());
  119. };
  120. // 清单:每文档doc只存储一条清单,每条清单都必须定位一次文档,无法合并处理
  121. if (datas.bills.length > 0){
  122. for (let bill of datas.bills){
  123. functions.push(updateFunc(billsModel, {projectID: datas.projectID, ID: bill.ID, deleteInfo: null}, bill));
  124. };
  125. };
  126. // 定额:每文档doc只存储一条定额,每条定额都必须定位一次文档,无法合并处理
  127. if (datas.rations.length > 0){
  128. for (let ration of datas.rations){
  129. functions.push(updateFunc(rationsModel, {projectID: datas.projectID, ID: ration.ID, deleteInfo: null}, ration));
  130. };
  131. };
  132. asyncTool.parallel(functions, function(err, result){
  133. {
  134. if (!err) {
  135. res.json({error: 0, message: err, data: result});
  136. } else {
  137. res.json({error: 1, message: err, data: null});
  138. }
  139. }
  140. });
  141. },
  142. updateFiles: async function(req, res){
  143. let data = JSON.parse(req.body.data);
  144. let updateDatas = data.updateDatas;
  145. await ProjectsData.udpateUserFiles(req.session.sessionUser.id, updateDatas, function (err, message, data) {
  146. callback(req, res, err, message, data);
  147. });
  148. },
  149. defaultSettings: async function(req, res){
  150. try{
  151. let data = JSON.parse(req.body.data);
  152. let projectID = data.projectID;
  153. let defaultSettingSc = await ProjectsData.defaultSettings(req.session.sessionUser.id, req.session.sessionCompilation._id, projectID);
  154. if(!defaultSettingSc){
  155. throw '恢复失败';
  156. }
  157. res.json({error: 0, message: '恢复成功', data: null});
  158. }
  159. catch(error){
  160. console.log(error);
  161. res.json({error: 1, message: error, data: null});
  162. }
  163. },
  164. /* copyProjects: function (req, res) {
  165. let data = JSON.parse(req.body.data);
  166. ProjectsData.copyUserProjects(req.session.sessionUser.id, req.session.sessionCompilation._id, data.updateData, function (err, message, data) {
  167. if (err === 0) {
  168. callback(req, res, err, message, data);
  169. } else {
  170. callback(req, res, err, message, null);
  171. }
  172. });
  173. },*/
  174. rename: function (req, res) {
  175. let data = JSON.parse(req.body.data);
  176. ProjectsData.rename(req.session.sessionUser.id, req.session.sessionCompilation._id, data, function (err, message) {
  177. callback(req, res, err, message, null);
  178. });
  179. },
  180. getProject: function(req, res){
  181. let data = JSON.parse(req.body.data);
  182. let projectID = data.proj_id;
  183. ProjectsData.getUserProject(req.session.sessionUser.id, data.proj_id, async function(err, message, data){
  184. if (err === 0) {
  185. let engineeringLibModel = new EngineeringLibModel();
  186. let engineeringInfo = data !== null && data.property.engineering_id !== undefined ?
  187. await engineeringLibModel.getEngineering(data.property.engineering_id) : null;
  188. let strData = JSON.stringify(data);
  189. let projInfo = JSON.parse(strData);
  190. if (engineeringInfo !== null) {
  191. if(engineeringInfo.billsGuidance_lib){
  192. for(let billsGuidanceLib of engineeringInfo.billsGuidance_lib){
  193. let stdBillsGuidanceLib = await stdBillsGuidanceLibModel.findOne({ID: billsGuidanceLib.id});
  194. if(stdBillsGuidanceLib){
  195. billsGuidanceLib.type = stdBillsGuidanceLib.type ? stdBillsGuidanceLib.type : 1;
  196. }
  197. }
  198. }
  199. projInfo.engineeringInfo = engineeringInfo;
  200. }
  201. //读取建设项目的基本信息
  202. let basicInfo = await ProjectsData.getBasicInfo(projectID);
  203. if(basicInfo !== null){
  204. projInfo.property.basicInformation = basicInfo;
  205. }
  206. //获取单位工程完整目录结构
  207. let fullPath = await pm_facade.getFullPath(projectID);
  208. projInfo.fullPath = fullPath;
  209. callback(req, res, err, message, projInfo);
  210. } else {
  211. callback(req, res, err, message, null);
  212. }
  213. });
  214. },
  215. beforeOpenProject: function (req, res) {
  216. let data = JSON.parse(req.body.data);
  217. ProjectsData.beforeOpenProject(req.session.sessionUser.id, data.proj_id, data.updateData, function (err, message, data) {
  218. callback(req, res, err, message, data);
  219. });
  220. },
  221. getNewProjectID: function (req, res) {
  222. let data = JSON.parse(req.body.data);
  223. ProjectsData.getNewProjectID(data.count, function (err, message, data) {
  224. callback(req, res, err, message, data);
  225. });
  226. },
  227. // 项目管理首页
  228. index: async function(request, response) {
  229. // 获取编办信息
  230. let sessionCompilation = request.session.sessionCompilation;
  231. if (sessionCompilation === undefined ||sessionCompilation ===null) {
  232. return response.redirect('/logout');
  233. }
  234. let compilationModel = new CompilationModel();
  235. //更新编办信息
  236. let compilationData = await compilationModel.getCompilationById(sessionCompilation._id);
  237. request.session.sessionCompilation = compilationData;
  238. sessionCompilation = request.session.sessionCompilation;
  239. //更新用户的使用过的费用定额列表
  240. let userData = await userModel.findOne({_id: mongoose.Types.ObjectId(request.session.sessionUser.id)}, '-_id used_list');
  241. if (userData) {
  242. let usedCompilation = _.find(userData.used_list, function (o) {
  243. return o.compilationId === compilationData._id.toString();
  244. });
  245. //第一次使用该费用定额
  246. if (!usedCompilation) {
  247. await userModel.update({_id: mongoose.Types.ObjectId(request.session.sessionUser.id)}, {$push: {used_list: {compilationId: compilationData._id}}});
  248. //拷贝补充定额模板数据
  249. await sectionTreeDao.copyDataFromTemplate(request.session.sessionUser.id, compilationData._id);
  250. //拷贝例题数据
  251. }
  252. }
  253. // 清单计价
  254. let billValuation = sessionCompilation.bill_valuation !== undefined ?
  255. sessionCompilation.bill_valuation : [];
  256. // 获取标准库数据
  257. let engineeringLibModel = new EngineeringLibModel();
  258. billValuation = await engineeringLibModel.getLib(billValuation);
  259. // 定额计价
  260. let rationValuation = sessionCompilation.ration_valuation !== undefined ?
  261. sessionCompilation.ration_valuation : [];
  262. rationValuation = await engineeringLibModel.getLib(rationValuation);
  263. let absoluteUrl = compilationData.overWriteUrl ? request.app.locals.rootDir + compilationData.overWriteUrl : request.app.locals.rootDir;
  264. let overWriteUrl = fs.existsSync(absoluteUrl) && fs.statSync(absoluteUrl).isFile()? compilationData.overWriteUrl : null;
  265. let renderData = {
  266. userAccount: request.session.userAccount,
  267. userID: request.session.sessionUser.id,
  268. compilationData: JSON.stringify(sessionCompilation),
  269. overWriteUrl: overWriteUrl,
  270. billValuation: JSON.stringify(billValuation),
  271. rationValuation: JSON.stringify(rationValuation),
  272. engineeringList: JSON.stringify(engineering.List),
  273. compilationName: sessionCompilation.name,
  274. versionName: `纵横云计价(${request.session.compilationVersion})`,
  275. LicenseKey:config.getLicenseKey(process.env.NODE_ENV)
  276. };
  277. response.render('building_saas/pm/html/project-management.html', renderData);
  278. },
  279. // 获取单价文件列表
  280. getUnitFileList: async function(request, response) {
  281. let data = request.body.data;
  282. try {
  283. data = JSON.parse(data);
  284. let projectId = data.parentID !== undefined ? data.parentID : 0;
  285. if (isNaN(projectId) && projectId <= 0) {
  286. throw {msg: 'id数据有误!', err: 1};
  287. }
  288. /*// 获取对应建设项目下所有的单位工程id
  289. let idList = await ProjectsData.getTenderByProjectId(projectId);
  290. if (idList.length <= 0) {
  291. throw {msg: '不存在对应单位工程', err: 0};
  292. }*/
  293. // 获取对应的单价文件
  294. let unitPriceFileModel = new UnitPriceFileModel();
  295. let unitPriceFileData = await unitPriceFileModel.getDataByRootProject(projectId);
  296. if (unitPriceFileData === null) {
  297. throw {msg: '不存在对应单价文件', err: 0};
  298. }
  299. // 整理数据
  300. let unitPriceFileList = [];
  301. for (let unitPriceFile of unitPriceFileData) {
  302. let tmp = {
  303. name: unitPriceFile.name,
  304. id: unitPriceFile.id
  305. };
  306. unitPriceFileList.push(tmp);
  307. }
  308. callback(request, response, 0, '', unitPriceFileList);
  309. } catch (error) {
  310. console.log(error);
  311. let responseData = error.err === 1 ? null : [];
  312. callback(request, response, error.err, error.msg, responseData);
  313. }
  314. },
  315. getFeeRateFileList:async function(request, response) {
  316. let data = request.body.data;
  317. try {
  318. data = JSON.parse(data);
  319. let projectId = data.parentID !== undefined ? data.parentID : 0;
  320. if (isNaN(projectId) && projectId <= 0) {
  321. throw {msg: 'id数据有误!', err: 1};
  322. }
  323. // 获取对应建设项目下所有的单位工程id
  324. let feeRateFileList = await fee_rate_facade.getFeeRatesByProject(projectId);
  325. callback(request, response, 0, '',feeRateFileList );
  326. } catch (error) {
  327. console.log(error);
  328. let responseData = error.err === 1 ? null : [];
  329. callback(request, response, error.err, error.msg, responseData);
  330. }
  331. },
  332. getGCDatas: async function(request, response) {
  333. let userID = request.session.sessionUser.id;
  334. let compilatoinId = request.session.sessionCompilation._id;
  335. let rst = [];
  336. let _projs = Object.create(null), _engs = Object.create(null), prefix = 'ID_';
  337. try{
  338. let gc_unitPriceFiles = await ProjectsData.getGCFiles(fileType.unitPriceFile, userID);
  339. let gc_feeRateFiles = await ProjectsData.getGCFiles(fileType.feeRateFile, userID);
  340. let gc_tenderFiles = await ProjectsData.getGCFiles(projType.tender, userID);
  341. for(let i = 0, len = gc_unitPriceFiles.length; i < len; i++){
  342. let gc_uf = gc_unitPriceFiles[i];
  343. let theProj = _projs[prefix + gc_uf.root_project_id] || null;
  344. if(!theProj){
  345. let tempProj = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_uf.root_project_id]);
  346. if(tempProj.length > 0 && tempProj[0].projType !== projType.folder){
  347. theProj = _projs[prefix + gc_uf.root_project_id] = tempProj[0]._doc;
  348. buildProj(theProj);
  349. }
  350. }
  351. if(theProj){
  352. theProj.unitPriceFiles.push(gc_uf);
  353. }
  354. }
  355. for(let i = 0, len = gc_feeRateFiles.length; i < len; i++){
  356. let gc_ff = gc_feeRateFiles[i];
  357. let theProj = _projs[prefix + gc_ff.rootProjectID] || null;
  358. if(!theProj){
  359. let tempProj = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_ff.rootProjectID]);
  360. if(tempProj.length > 0 && tempProj[0].projType !== projType.folder){
  361. theProj = _projs[prefix + gc_ff.rootProjectID] = tempProj[0]._doc;
  362. buildProj(theProj);
  363. }
  364. }
  365. if(theProj) {
  366. theProj.feeRateFiles.push(gc_ff);
  367. }
  368. }
  369. if(gc_tenderFiles.length > 0){
  370. for(let i = 0, len = gc_tenderFiles.length; i < len; i++){
  371. let gc_t = gc_tenderFiles[i];
  372. let theEng = _engs[prefix + gc_t.ParentID] || null;
  373. if(!theEng){
  374. let tempEngs = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_t.ParentID]);
  375. if(tempEngs.length > 0 && tempEngs[0].projType === projType.engineering){
  376. theEng = _engs[prefix + gc_t.ParentID] = tempEngs[0]._doc;
  377. theEng.children = [];
  378. }
  379. }
  380. if(theEng) {
  381. theEng.children.push(gc_t);
  382. let theProj = _projs[prefix + theEng.ParentID] || null;
  383. if(!theProj){
  384. let tempProj = await ProjectsData.getProjectsByIds(userID, compilatoinId, [theEng.ParentID]);
  385. if(tempProj.length > 0 && tempProj[0].projType === projType.project){
  386. theProj = _projs[prefix + theEng.ParentID] = tempProj[0]._doc;
  387. buildProj(theProj);
  388. }
  389. }
  390. if(theProj) {
  391. let isExist = false;
  392. for(let j = 0, jLen = theProj.children.length; j < jLen; j++){
  393. if(theProj.children[j].ID === theEng.ID){
  394. isExist = true;
  395. break;
  396. }
  397. }
  398. if(!isExist){
  399. theProj.children.push(theEng);
  400. }
  401. }
  402. }
  403. }
  404. }
  405. for(let i in _projs){
  406. rst.push(_projs[i]);
  407. }
  408. function buildProj(proj){
  409. proj.children = [];
  410. proj.unitPriceFiles = [];
  411. proj.feeRateFiles = [];
  412. }
  413. callback(request, response, 0, 'success', rst);
  414. }
  415. catch (error){
  416. callback(request, response, true, error, null);
  417. }
  418. },
  419. recGC: function(request, response){
  420. let userID = request.session.sessionUser.id;
  421. let data = JSON.parse(request.body.data);
  422. let nodes = data.nodes;
  423. ProjectsData.recGC(userID, nodes, function (err, msg, data) {
  424. callback(request, response, err, msg, data);
  425. });
  426. },
  427. delGC: async function(request, response){
  428. let data = JSON.parse(request.body.data);
  429. let delDatas = data.delDatas;
  430. let bulkProjs = [], bulkUFs = [], bulkFFs = [];
  431. try{
  432. for(let data of delDatas){
  433. if(data.updateType === 'Project'){
  434. bulkProjs.push({updateOne: {filter: {ID: data.ID}, update: {'deleteInfo.completeDeleted': true}}});
  435. }
  436. else if(data.updateType === fileType.unitPriceFile){
  437. bulkUFs.push({updateOne: {filter: {id: data.ID}, update: {'deleteInfo.completeDeleted': true}}});
  438. }
  439. else{
  440. bulkFFs.push({updateOne: {filter: {ID: data.ID}, update: {'deleteInfo.completeDeleted': true}}});
  441. }
  442. }
  443. if(bulkProjs.length > 0){
  444. await projectModel.bulkWrite(bulkProjs);
  445. }
  446. if(bulkUFs.length > 0){
  447. await unitPriceFileModel.bulkWrite(bulkUFs);
  448. }
  449. if(bulkFFs.length > 0){
  450. await feeRateFileModel.bulkWrite(bulkFFs);
  451. }
  452. callback(request, response, 0, 'success', null);
  453. } catch(err){
  454. callback(request, response, 1, err, null);
  455. }
  456. },
  457. moveProject:async function(req,res){
  458. let result={
  459. error:0
  460. };
  461. try {
  462. let data = req.body.data;
  463. let rdata= await pm_facade.moveProject(data);
  464. result.data= rdata;
  465. }catch (err){
  466. console.log(err);
  467. result.error=1;
  468. result.message = err.message;
  469. }
  470. res.json(result);
  471. },
  472. copyProjects:async function (req, res) {
  473. let result={
  474. error:0
  475. };
  476. try {
  477. let data = JSON.parse(req.body.data);
  478. result.data = await pm_facade.copyProject(req.session.sessionUser.id, req.session.sessionCompilation._id,data);
  479. }catch (err){
  480. console.log(err);
  481. result.error=1;
  482. result.message = err.message;
  483. }
  484. res.json(result);
  485. },
  486. projectShareInfo: async function(req, res){
  487. try{
  488. let data = JSON.parse(req.body.data);
  489. let shareInfo = await projectModel.findOne({ID: data.projectID, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}]}, '-_id shareInfo');
  490. callback(req, res, 0, 'success', shareInfo);
  491. }
  492. catch (err){
  493. callback(req, res, 1, err, null);
  494. }
  495. },
  496. share: async function(req, res){
  497. try{
  498. let data = JSON.parse(req.body.data);
  499. let shareDate = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'),
  500. shareUserIDs = [];
  501. for (let data of data.shareData) {
  502. shareUserIDs.push(data.userID);
  503. data.shareDate = shareDate;
  504. }
  505. //添加分享
  506. if(data.type === 'create'){
  507. //新增
  508. for (let sData of data.shareData) {
  509. await projectModel.update({ID: data.projectID, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}]}, {$addToSet: {shareInfo: sData}});
  510. }
  511. }
  512. //取消分享
  513. else {
  514. await projectModel.update({ID: data.projectID, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}]}, {$pull: {shareInfo: {userID: {$in: shareUserIDs}}}});
  515. }
  516. callback(req, res, 0, 'success', null);
  517. }
  518. catch (err){
  519. callback(req, res, 1, err, null);
  520. }
  521. },
  522. receiveProjects: async function(req, res) {
  523. try {
  524. let rst = {grouped: [], ungrouped: []};
  525. let userID = req.session.sessionUser.id;
  526. let receiveProjects = await projectModel.find({
  527. $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], compilation: req.session.sessionCompilation._id, 'shareInfo.userID': userID}, '-_id -property');
  528. //设置原项目用户信息
  529. if(receiveProjects.length > 0){
  530. let orgUserIDs = [];
  531. for(let proj of receiveProjects){
  532. orgUserIDs.push(proj.userID);
  533. }
  534. orgUserIDs = Array.from(new Set(orgUserIDs));
  535. let userObjIDs = [];
  536. for(let uID of orgUserIDs){
  537. userObjIDs.push(mongoose.Types.ObjectId(uID));
  538. }
  539. let orgUsersInfo = await userModel.find({_id: {$in : userObjIDs}});
  540. for(let proj of receiveProjects){
  541. //获取分享项目子项
  542. if (proj.projType !== projType.tender) {
  543. proj._doc.children = await pm_facade.getPosterityProjects([proj.ID]);
  544. }
  545. //设置分组,单位工程及单项工程分到未分组那
  546. if (proj.projType === projType.tender || proj.projType === projType.engineering) {
  547. rst.ungrouped.push(proj);
  548. } else {
  549. rst.grouped.push(proj);
  550. }
  551. //设置项目类型为来自别人分享
  552. proj._doc.shareType = 'receive';
  553. for(let userData of orgUsersInfo){
  554. if(proj.userID == userData._id.toString()){
  555. let userInfo = {name: userData.real_name, mobile: userData.mobile, company: userData.company, email: userData.email};
  556. proj._doc.userInfo = userInfo;
  557. }
  558. }
  559. }
  560. }
  561. callback(req, res, 0, 'success', rst);
  562. }
  563. catch (err){
  564. callback(req, res, 1, err, null);
  565. }
  566. },
  567. getProjectsByQuery: async function (req, res) {
  568. try{
  569. let data = JSON.parse(req.body.data);
  570. let compilation = req.session.sessionCompilation._id;
  571. let query = data.query;
  572. query.compilation = compilation;
  573. console.log(`compilation===============================`);
  574. console.log(compilation);
  575. console.log(query);
  576. let options = data.options;
  577. let projects = await projectModel.find(query, options);
  578. callback(req, res, 0, 'success', projects);
  579. }
  580. catch (err){
  581. callback(req, res, 1, err, null);
  582. }
  583. },
  584. getSummaryInfo: async function(req, res){
  585. try{
  586. let data = JSON.parse(req.body.data);
  587. let summaryInfo = await pm_facade.getSummaryInfo(data.projectIDs);
  588. callback(req, res, 0, 'success', summaryInfo);
  589. }
  590. catch (err){
  591. callback(req, res, 1, err, null);
  592. }
  593. },
  594. };