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