pm_controller.js 26 KB

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