pm_controller.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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, 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. /* copyProjects: function (req, res) {
  152. let data = JSON.parse(req.body.data);
  153. ProjectsData.copyUserProjects(req.session.sessionUser.id, req.session.sessionCompilation._id, data.updateData, function (err, message, data) {
  154. if (err === 0) {
  155. callback(req, res, err, message, data);
  156. } else {
  157. callback(req, res, err, message, null);
  158. }
  159. });
  160. },*/
  161. rename: function (req, res) {
  162. let data = JSON.parse(req.body.data);
  163. ProjectsData.rename(req.session.sessionUser.id, req.session.sessionCompilation._id, data, function (err, message) {
  164. callback(req, res, err, message, null);
  165. });
  166. },
  167. getProject: function(req, res){
  168. let data = JSON.parse(req.body.data);
  169. let projectID = data.proj_id;
  170. ProjectsData.getUserProject(req.session.sessionUser.id, data.proj_id, async function(err, message, data){
  171. if (err === 0) {
  172. let engineeringLibModel = new EngineeringLibModel();
  173. let engineeringInfo = data !== null && data.property.engineering_id !== undefined ?
  174. await engineeringLibModel.getEngineering(data.property.engineering_id) : null;
  175. let strData = JSON.stringify(data);
  176. let projInfo = JSON.parse(strData);
  177. if (engineeringInfo !== null) {
  178. if(engineeringInfo.billsGuidance_lib){
  179. for(let billsGuidanceLib of engineeringInfo.billsGuidance_lib){
  180. let stdBillsGuidanceLib = await stdBillsGuidanceLibModel.findOne({ID: billsGuidanceLib.id});
  181. if(stdBillsGuidanceLib){
  182. billsGuidanceLib.type = stdBillsGuidanceLib.type ? stdBillsGuidanceLib.type : 1;
  183. }
  184. }
  185. }
  186. projInfo.engineeringInfo = engineeringInfo;
  187. }
  188. //读取建设项目的基本信息
  189. let basicInfo = await ProjectsData.getBasicInfo(projectID);
  190. if(basicInfo !== null){
  191. projInfo.property.basicInformation = basicInfo;
  192. }
  193. //获取单位工程完整目录结构
  194. let fullPath = await pm_facade.getFullPath(projectID);
  195. projInfo.fullPath = fullPath;
  196. callback(req, res, err, message, projInfo);
  197. } else {
  198. callback(req, res, err, message, null);
  199. }
  200. });
  201. },
  202. beforeOpenProject: function (req, res) {
  203. let data = JSON.parse(req.body.data);
  204. ProjectsData.beforeOpenProject(req.session.sessionUser.id, data.proj_id, data.updateData, function (err, message, data) {
  205. callback(req, res, err, message, data);
  206. });
  207. },
  208. getNewProjectID: function (req, res) {
  209. let data = JSON.parse(req.body.data);
  210. ProjectsData.getNewProjectID(data.count, function (err, message, data) {
  211. callback(req, res, err, message, data);
  212. });
  213. },
  214. // 项目管理首页
  215. index: async function(request, response) {
  216. // 获取编办信息
  217. let sessionCompilation = request.session.sessionCompilation;
  218. if (sessionCompilation === undefined ||sessionCompilation ===null) {
  219. return response.redirect('/logout');
  220. }
  221. let compilationModel = new CompilationModel();
  222. //更新编办信息
  223. let compilationData = await compilationModel.getCompilationById(sessionCompilation._id);
  224. request.session.sessionCompilation = compilationData;
  225. sessionCompilation = request.session.sessionCompilation;
  226. // 清单计价
  227. let billValuation = sessionCompilation.bill_valuation !== undefined ?
  228. sessionCompilation.bill_valuation : [];
  229. // 获取标准库数据
  230. let engineeringLibModel = new EngineeringLibModel();
  231. billValuation = await engineeringLibModel.getLib(billValuation);
  232. // 定额计价
  233. let rationValuation = sessionCompilation.ration_valuation !== undefined ?
  234. sessionCompilation.ration_valuation : [];
  235. rationValuation = await engineeringLibModel.getLib(rationValuation);
  236. let renderData = {
  237. userAccount: request.session.userAccount,
  238. userID: request.session.sessionUser.id,
  239. compilationData: JSON.stringify(sessionCompilation),
  240. billValuation: JSON.stringify(billValuation),
  241. rationValuation: JSON.stringify(rationValuation),
  242. engineeringList: JSON.stringify(engineering.List),
  243. versionName: sessionCompilation.name + request.session.compilationVersion,
  244. LicenseKey:config.getLicenseKey(process.env.NODE_ENV)
  245. };
  246. response.render('building_saas/pm/html/project-management.html', renderData);
  247. },
  248. // 获取单价文件列表
  249. getUnitFileList: async function(request, response) {
  250. let data = request.body.data;
  251. try {
  252. data = JSON.parse(data);
  253. let projectId = data.parentID !== undefined ? data.parentID : 0;
  254. if (isNaN(projectId) && projectId <= 0) {
  255. throw {msg: 'id数据有误!', err: 1};
  256. }
  257. /*// 获取对应建设项目下所有的单位工程id
  258. let idList = await ProjectsData.getTenderByProjectId(projectId);
  259. if (idList.length <= 0) {
  260. throw {msg: '不存在对应单位工程', err: 0};
  261. }*/
  262. // 获取对应的单价文件
  263. let unitPriceFileModel = new UnitPriceFileModel();
  264. let unitPriceFileData = await unitPriceFileModel.getDataByRootProject(projectId);
  265. if (unitPriceFileData === null) {
  266. throw {msg: '不存在对应单价文件', err: 0};
  267. }
  268. // 整理数据
  269. let unitPriceFileList = [];
  270. for (let unitPriceFile of unitPriceFileData) {
  271. let tmp = {
  272. name: unitPriceFile.name,
  273. id: unitPriceFile.id
  274. };
  275. unitPriceFileList.push(tmp);
  276. }
  277. callback(request, response, 0, '', unitPriceFileList);
  278. } catch (error) {
  279. console.log(error);
  280. let responseData = error.err === 1 ? null : [];
  281. callback(request, response, error.err, error.msg, responseData);
  282. }
  283. },
  284. getFeeRateFileList:async function(request, response) {
  285. let data = request.body.data;
  286. try {
  287. data = JSON.parse(data);
  288. let projectId = data.parentID !== undefined ? data.parentID : 0;
  289. if (isNaN(projectId) && projectId <= 0) {
  290. throw {msg: 'id数据有误!', err: 1};
  291. }
  292. // 获取对应建设项目下所有的单位工程id
  293. let feeRateFileList = await fee_rate_facade.getFeeRatesByProject(projectId);
  294. callback(request, response, 0, '',feeRateFileList );
  295. } catch (error) {
  296. console.log(error);
  297. let responseData = error.err === 1 ? null : [];
  298. callback(request, response, error.err, error.msg, responseData);
  299. }
  300. },
  301. getGCDatas: async function(request, response) {
  302. let userID = request.session.sessionUser.id;
  303. let compilatoinId = request.session.sessionCompilation._id;
  304. let rst = [];
  305. let _projs = Object.create(null), _engs = Object.create(null), prefix = 'ID_';
  306. try{
  307. let gc_unitPriceFiles = await ProjectsData.getGCFiles(fileType.unitPriceFile, userID);
  308. let gc_feeRateFiles = await ProjectsData.getGCFiles(fileType.feeRateFile, userID);
  309. let gc_tenderFiles = await ProjectsData.getGCFiles(projType.tender, userID);
  310. for(let i = 0, len = gc_unitPriceFiles.length; i < len; i++){
  311. let gc_uf = gc_unitPriceFiles[i];
  312. let theProj = _projs[prefix + gc_uf.root_project_id] || null;
  313. if(!theProj){
  314. let tempProj = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_uf.root_project_id]);
  315. if(tempProj.length > 0 && tempProj[0].projType !== projType.folder){
  316. theProj = _projs[prefix + gc_uf.root_project_id] = tempProj[0]._doc;
  317. buildProj(theProj);
  318. }
  319. }
  320. if(theProj){
  321. theProj.unitPriceFiles.push(gc_uf);
  322. }
  323. }
  324. for(let i = 0, len = gc_feeRateFiles.length; i < len; i++){
  325. let gc_ff = gc_feeRateFiles[i];
  326. let theProj = _projs[prefix + gc_ff.rootProjectID] || null;
  327. if(!theProj){
  328. let tempProj = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_ff.rootProjectID]);
  329. if(tempProj.length > 0 && tempProj[0].projType !== projType.folder){
  330. theProj = _projs[prefix + gc_ff.rootProjectID] = tempProj[0]._doc;
  331. buildProj(theProj);
  332. }
  333. }
  334. if(theProj) {
  335. theProj.feeRateFiles.push(gc_ff);
  336. }
  337. }
  338. if(gc_tenderFiles.length > 0){
  339. for(let i = 0, len = gc_tenderFiles.length; i < len; i++){
  340. let gc_t = gc_tenderFiles[i];
  341. let theEng = _engs[prefix + gc_t.ParentID] || null;
  342. if(!theEng){
  343. let tempEngs = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_t.ParentID]);
  344. if(tempEngs.length > 0 && tempEngs[0].projType === projType.engineering){
  345. theEng = _engs[prefix + gc_t.ParentID] = tempEngs[0]._doc;
  346. theEng.children = [];
  347. }
  348. }
  349. if(theEng) {
  350. theEng.children.push(gc_t);
  351. let theProj = _projs[prefix + theEng.ParentID] || null;
  352. if(!theProj){
  353. let tempProj = await ProjectsData.getProjectsByIds(userID, compilatoinId, [theEng.ParentID]);
  354. if(tempProj.length > 0 && tempProj[0].projType === projType.project){
  355. theProj = _projs[prefix + theEng.ParentID] = tempProj[0]._doc;
  356. buildProj(theProj);
  357. }
  358. }
  359. if(theProj) {
  360. let isExist = false;
  361. for(let j = 0, jLen = theProj.children.length; j < jLen; j++){
  362. if(theProj.children[j].ID === theEng.ID){
  363. isExist = true;
  364. break;
  365. }
  366. }
  367. if(!isExist){
  368. theProj.children.push(theEng);
  369. }
  370. }
  371. }
  372. }
  373. }
  374. for(let i in _projs){
  375. rst.push(_projs[i]);
  376. }
  377. function buildProj(proj){
  378. proj.children = [];
  379. proj.unitPriceFiles = [];
  380. proj.feeRateFiles = [];
  381. }
  382. callback(request, response, 0, 'success', rst);
  383. }
  384. catch (error){
  385. callback(request, response, true, error, null);
  386. }
  387. },
  388. recGC: function(request, response){
  389. let userID = request.session.sessionUser.id;
  390. let data = JSON.parse(request.body.data);
  391. let nodes = data.nodes;
  392. ProjectsData.recGC(userID, nodes, function (err, msg, data) {
  393. callback(request, response, err, msg, data);
  394. });
  395. },
  396. delGC: async function(request, response){
  397. let data = JSON.parse(request.body.data);
  398. let delDatas = data.delDatas;
  399. let bulkProjs = [], bulkUFs = [], bulkFFs = [];
  400. try{
  401. for(let data of delDatas){
  402. if(data.updateType === 'Project'){
  403. bulkProjs.push({updateOne: {filter: {ID: data.ID}, update: {'deleteInfo.completeDeleted': true}}});
  404. }
  405. else if(data.updateType === fileType.unitPriceFile){
  406. bulkUFs.push({updateOne: {filter: {id: data.ID}, update: {'deleteInfo.completeDeleted': true}}});
  407. }
  408. else{
  409. bulkFFs.push({updateOne: {filter: {ID: data.ID}, update: {'deleteInfo.completeDeleted': true}}});
  410. }
  411. }
  412. if(bulkProjs.length > 0){
  413. await projectModel.bulkWrite(bulkProjs);
  414. }
  415. if(bulkUFs.length > 0){
  416. await unitPriceFileModel.bulkWrite(bulkUFs);
  417. }
  418. if(bulkFFs.length > 0){
  419. await feeRateFileModel.bulkWrite(bulkFFs);
  420. }
  421. callback(request, response, 0, 'success', null);
  422. } catch(err){
  423. callback(request, response, 1, err, null);
  424. }
  425. },
  426. moveProject:async function(req,res){
  427. let result={
  428. error:0
  429. };
  430. try {
  431. let data = req.body.data;
  432. let rdata= await pm_facade.moveProject(data);
  433. result.data= rdata;
  434. }catch (err){
  435. console.log(err);
  436. result.error=1;
  437. result.message = err.message;
  438. }
  439. res.json(result);
  440. },
  441. copyProjects:async function (req, res) {
  442. let result={
  443. error:0
  444. };
  445. try {
  446. let data = JSON.parse(req.body.data);
  447. result.data = await pm_facade.copyProject(req.session.sessionUser.id, req.session.sessionCompilation._id,data);
  448. }catch (err){
  449. console.log(err);
  450. result.error=1;
  451. result.message = err.message;
  452. }
  453. res.json(result);
  454. },
  455. projectShareInfo: async function(req, res){
  456. try{
  457. let data = JSON.parse(req.body.data);
  458. let shareInfo = await projectModel.findOne({ID: data.projectID, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}]}, '-_id shareInfo');
  459. callback(req, res, 0, 'success', shareInfo);
  460. }
  461. catch (err){
  462. callback(req, res, 1, err, null);
  463. }
  464. },
  465. share: async function(req, res){
  466. try{
  467. let data = JSON.parse(req.body.data);
  468. //添加分享
  469. let shareData = {userID: data.userID, allowCopy: data.allowCopy, shareDate: moment(Date.now()).format('YYYY-MM-DD HH:mm:ss')};
  470. if(data.type === 'create'){
  471. await projectModel.update({ID: data.projectID, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}]}, {$addToSet: {shareInfo: shareData}});
  472. }
  473. //取消分享
  474. else {
  475. await projectModel.update({ID: data.projectID, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}]}, {$pull: {shareInfo: {userID: data.userID}}});
  476. }
  477. callback(req, res, 0, 'success', null);
  478. }
  479. catch (err){
  480. callback(req, res, 1, err, null);
  481. }
  482. },
  483. getShareProjects: async function (req, res) {
  484. try {
  485. let userID = req.session.sessionUser.id;
  486. let rst = {receive: [], share: []}//接收的、由我分享的
  487. let shareProjects = await projectModel.find({userID: userID,
  488. $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], compilation: req.session.sessionCompilation._id, 'shareInfo.0': {$exists: true}});
  489. //项目类型为分享给别人
  490. let shareToUserIDs = [];
  491. for(let proj of shareProjects){
  492. proj._doc.shareType = 'shareTo';
  493. for(let shareToUser of proj.shareInfo){
  494. shareToUserIDs.push(shareToUser.userID);
  495. }
  496. }
  497. shareToUserIDs = Array.from(new Set(shareToUserIDs));
  498. let shareToObjIDs = [];
  499. for(let userID of shareToUserIDs){
  500. shareToObjIDs.push(mongoose.Types.ObjectId(userID));
  501. }
  502. let shareToUsers = await userModel.find({_id: {$in: shareToObjIDs}});
  503. for(let shareToUser of shareToUsers){
  504. for(let proj of shareProjects){
  505. for(let user of proj.shareInfo){
  506. if(user.userID === shareToUser._id.toString()){
  507. user._doc.company = shareToUser.company;
  508. user._doc.email = shareToUser.email;
  509. user._doc.name = shareToUser.real_name;
  510. user._doc.mobile = shareToUser.mobile;
  511. }
  512. }
  513. }
  514. }
  515. rst.share = shareProjects;
  516. let receiveProjects = await projectModel.find({
  517. $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], compilation: req.session.sessionCompilation._id, 'shareInfo.userID': userID});
  518. //设置原项目用户信息
  519. if(receiveProjects.length > 0){
  520. let orgUserIDs = [];
  521. for(let proj of receiveProjects){
  522. orgUserIDs.push(proj.userID);
  523. }
  524. orgUserIDs = Array.from(new Set(orgUserIDs));
  525. let userObjIDs = [];
  526. for(let uID of orgUserIDs){
  527. userObjIDs.push(mongoose.Types.ObjectId(uID));
  528. }
  529. let orgUsersInfo = await userModel.find({_id: {$in : userObjIDs}});
  530. for(let proj of receiveProjects){
  531. //设置项目类型为来自别人分享
  532. proj._doc.shareType = 'receive';
  533. for(let userData of orgUsersInfo){
  534. if(proj.userID == userData._id.toString()){
  535. let userInfo = {name: userData.real_name, mobile: userData.mobile, company: userData.company, email: userData.email};
  536. proj._doc.userInfo = userInfo;
  537. }
  538. }
  539. }
  540. }
  541. rst.receive = receiveProjects;
  542. callback(req, res, 0, 'success', rst);
  543. }
  544. catch (err){
  545. callback(req, res, 1, err, null);
  546. }
  547. },
  548. getProjectsByQuery: async function (req, res) {
  549. try{
  550. let data = JSON.parse(req.body.data);
  551. let compilation = req.session.sessionCompilation._id;
  552. let query = data.query;
  553. query.compilation = compilation;
  554. console.log(`compilation===============================`);
  555. console.log(compilation);
  556. console.log(query);
  557. let options = data.options;
  558. let projects = await projectModel.find(query, options);
  559. callback(req, res, 0, 'success', projects);
  560. }
  561. catch (err){
  562. callback(req, res, 1, err, null);
  563. }
  564. },
  565. getSummaryInfo: async function(req, res){
  566. try{
  567. let data = JSON.parse(req.body.data);
  568. let summaryInfo = await pm_facade.getSummaryInfo(data.projectIDs);
  569. callback(req, res, 0, 'success', summaryInfo);
  570. }
  571. catch (err){
  572. callback(req, res, 1, err, null);
  573. }
  574. },
  575. };