pm_controller.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  1. /**
  2. * Created by Mai on 2017/1/18.
  3. */
  4. const UnitPriceFileModel = require("../../glj/models/unit_price_file_model");
  5. const moment = require('moment');
  6. const CompilationModel = require("../../users/models/compilation_model");
  7. const UserModel = require("../../users/models/user_model");
  8. const userModelObj = new UserModel();
  9. let mongoose = require('mongoose');
  10. let ProjectsData = require('../models/project_model').project;
  11. let labourCoe = require('../../main/facade/labour_coe_facade');
  12. let projType = require('../models/project_model').projType;
  13. let fileType = require('../models/project_model').fileType;
  14. const engineering = require("../../common/const/engineering");
  15. let EngineeringLibModel = require("../../users/models/engineering_lib_model");
  16. const engineeringModel = mongoose.model('engineering_lib');
  17. let fee_rate_facade = require("../../fee_rates/facade/fee_rates_facade");
  18. let billsModel = require('../../main/models/bills').model;
  19. let rationsModel = require('../../main/models/ration').model;
  20. let projectModel = mongoose.model('projects');
  21. let unitPriceFileModel = mongoose.model('unit_price_file');
  22. let feeRateFileModel = mongoose.model('fee_rate_file');
  23. let asyncTool = require('async');
  24. let pm_facade = require('../facade/pm_facade');
  25. const userModel = mongoose.model('user');
  26. let config = require("../../../config/config.js");
  27. const optionModel = mongoose.model('options');
  28. const stdBillsGuidanceLibModel = mongoose.model('std_billsGuidance_lib');
  29. const fs = require('fs');
  30. const _ = require('lodash');
  31. const SectionTreeDao = require('../../complementary_ration_lib/models/sectionTreeModel');
  32. const uuidV1 = require('uuid/v1');
  33. let sectionTreeDao = new SectionTreeDao();
  34. let consts = require('../../main/models/project_consts');
  35. let rp = require('request-promise');
  36. const commonUtil = require('../../../public/common_util');
  37. const { ValuationText, AdminLevelType } = require('../../../public/common_constants');
  38. const { getTitle } = require("../../../public/titleUtil");
  39. //统一回调函数
  40. let callback = function (req, res, err, message, data) {
  41. res.json({ error: err, message: message, data: data });
  42. };
  43. module.exports = {
  44. redirectToImportServer,
  45. checkRight: function (req, res) {
  46. if (typeof req.body.data === 'object') {
  47. req.body.data = JSON.stringify(req.body.data);
  48. }
  49. let data = JSON.parse(req.body.data);
  50. if (data.user_id) {
  51. return data.user_id === req.session.sessionUser.id;
  52. } else {
  53. return false;
  54. }
  55. },
  56. checkProjectRight: function (userId, projectId, callback) {
  57. ProjectsData.getProject(projectId).then(async function (result) {
  58. /**
  59. * result._doc.userID(Number): MongoDB
  60. * userId(String): Session.userID
  61. */
  62. let shareInfo = null;
  63. let isOpenShareProject = false;
  64. //判断是否是打开分享的项目,分享项目shareInfo不为null
  65. if (userId !== result.userID) {
  66. shareInfo = await pm_facade.getShareInfo(userId, result.ID);
  67. isOpenShareProject = true;
  68. }
  69. if ((userId === result.userID || shareInfo) && result._doc.projType === projType.tender) {
  70. const allowCooperate = (shareInfo || {}).allowCooperate;
  71. callback(true, result, isOpenShareProject, allowCooperate);
  72. } else {
  73. callback(false);
  74. }
  75. }).catch(function (err) {
  76. callback(false);
  77. });
  78. },
  79. getProjects: async function (req, res) {
  80. await ProjectsData.getUserProjects(req.session.sessionUser.id, req.session.sessionCompilation._id, function(err, message, projects){
  81. if (projects) {
  82. callback(req, res, err, message, projects);
  83. } else {
  84. callback(req, res, err, message, null);
  85. }
  86. });
  87. },
  88. getAllUnitProjects: async function (req, res) {
  89. const rootProjectID = JSON.parse(req.body.data).rootProjectID;
  90. await ProjectsData.getAllUnitProjects(req.session.sessionUser.id, req.session.sessionCompilation._id, rootProjectID, function (err, message, data) {
  91. console.log(err);
  92. callback(req, res, err, message, data);
  93. });
  94. },
  95. updateProjects: async function (req, res) {
  96. let data = JSON.parse(req.body.data);
  97. try {
  98. await ProjectsData.updateUserProjects(req.session.sessionUser.id, req.session.sessionCompilation._id, req.session.sessionCompilation, data.updateData, function (err, message, data) {
  99. if (err === 0) {
  100. callback(req, res, err, message, data);
  101. } else {
  102. callback(req, res, err, message, null);
  103. }
  104. });
  105. } catch (err) {
  106. console.log(err);
  107. callback(req, res, 1, String(err), null);
  108. }
  109. },
  110. // CSL, 2017-12-14 该方法用于项目属性:提交保存混合型数据,这些数据来自不同的表,包括projects.property、ration、bills、labour_coes.
  111. updateMixDatas: async function (req, res) {
  112. let datas = JSON.parse(req.body.data).mixDataArr;
  113. let functions = [];
  114. let specialResult = {};
  115. function updateFunc(model, cod, doc) {
  116. return function (cb) {
  117. model.update(cod, doc, cb);
  118. }
  119. };
  120. function updateLC() {
  121. return function (cb) {
  122. datas.labourCoes.updateData.projectID = datas.projectID;
  123. labourCoe.save(datas.labourCoes.updateData, cb);
  124. }
  125. };
  126. // 项目属性
  127. if (Object.keys(datas.properties).length > 0) {
  128. //基本信息特殊处理,更新建设项目
  129. if (datas.properties['property.basicInformation']) {
  130. let constructionProject = await pm_facade.getConstructionProject(datas.projectID);
  131. if (constructionProject) {
  132. functions.push(updateFunc(projectModel, { ID: constructionProject.ID }, { 'property.basicInformation': datas.properties['property.basicInformation'] }));
  133. }
  134. delete datas.properties['property.basicInformation'];
  135. }
  136. // 工程特征特殊处理
  137. if (datas.properties['property.projectFeature']) {
  138. const engineeringItem = _.find(datas.properties['property.projectFeature'], { key: 'engineering' });
  139. const feeStandardItem = _.find(datas.properties['property.projectFeature'], { key: 'feeStandard' });
  140. if (engineeringItem && engineeringItem.value && feeStandardItem && feeStandardItem.value) {
  141. const project = await projectModel.findOne({ ID: datas.projectID }, { 'property.valuation': 1, 'property.engineering_id': 1 }).lean();
  142. if (project) {
  143. const orgEngineeringID = project.property.engineering_id;
  144. const engineering = await engineeringModel.findOne({ valuationID: project.property.valuation, name: engineeringItem.value, feeName: feeStandardItem.value }, { _id: 1, tax_group: 1, bill_lib: 1 }).lean();
  145. if (engineering && orgEngineeringID !== engineering._id.toString()) {
  146. datas.properties['property.engineeringName'] = engineeringItem.value;
  147. datas.properties['property.feeStandardName'] = feeStandardItem.value;
  148. datas.properties['property.engineering_id'] = engineering._id.toString();
  149. if (engineering.tax_group && engineering.tax_group[0] && engineering.tax_group[0].fee_lib) {
  150. // 工程专业变更,需要更改费率
  151. specialResult.newFeeLibID = engineering.tax_group[0].fee_lib.id;
  152. }
  153. specialResult.billLibs = engineering.bill_lib;
  154. }
  155. }
  156. }
  157. }
  158. functions.push(updateFunc(projectModel, { ID: datas.projectID }, datas.properties));
  159. };
  160. //选项
  161. if (datas.options && datas.options.updateData) {
  162. functions.push(updateFunc(optionModel, { user_id: req.session.sessionUser.id, compilation_id: req.session.sessionCompilation._id }, { 'options.GENERALOPTS': datas.options.updateData }));
  163. }
  164. // 人工系数
  165. if (datas.labourCoes && datas.labourCoes.updateData) {
  166. functions.push(updateLC());
  167. };
  168. // 清单:每文档doc只存储一条清单,每条清单都必须定位一次文档,无法合并处理
  169. if (datas.bills && datas.bills.length > 0) {
  170. for (let bill of datas.bills) {
  171. functions.push(updateFunc(billsModel, { projectID: datas.projectID, ID: bill.ID, deleteInfo: null }, bill));
  172. };
  173. };
  174. // 定额:每文档doc只存储一条定额,每条定额都必须定位一次文档,无法合并处理
  175. if (datas.rations && datas.rations.length > 0) {
  176. for (let ration of datas.rations) {
  177. functions.push(updateFunc(rationsModel, { projectID: datas.projectID, ID: ration.ID, deleteInfo: null }, ration));
  178. };
  179. };
  180. asyncTool.parallel(functions, function (err, result) {
  181. {
  182. if (!err) {
  183. res.json({ error: 0, message: err, data: specialResult});
  184. } else {
  185. res.json({ error: 1, message: err, data: null });
  186. }
  187. }
  188. });
  189. },
  190. updateFiles: async function (req, res) {
  191. let data = JSON.parse(req.body.data);
  192. let updateDatas = data.updateDatas;
  193. await ProjectsData.udpateUserFiles(req.session.sessionUser.id, updateDatas, function (err, message, data) {
  194. callback(req, res, err, message, data);
  195. });
  196. },
  197. defaultSettings: async function (req, res) {
  198. try {
  199. let data = JSON.parse(req.body.data);
  200. let projectID = data.projectID;
  201. let defaultSettingSc = await ProjectsData.defaultSettings(req.session.sessionUser.id, req.session.sessionCompilation, projectID);
  202. if (!defaultSettingSc) {
  203. throw '恢复失败';
  204. }
  205. res.json({ error: 0, message: '恢复成功', data: null });
  206. }
  207. catch (error) {
  208. console.log(error);
  209. res.json({ error: 1, message: error, data: null });
  210. }
  211. },
  212. /* copyProjects: function (req, res) {
  213. let data = JSON.parse(req.body.data);
  214. ProjectsData.copyUserProjects(req.session.sessionUser.id, req.session.sessionCompilation._id, data.updateData, function (err, message, data) {
  215. if (err === 0) {
  216. callback(req, res, err, message, data);
  217. } else {
  218. callback(req, res, err, message, null);
  219. }
  220. });
  221. },*/
  222. rename: function (req, res) {
  223. let data = JSON.parse(req.body.data);
  224. ProjectsData.rename(req.session.sessionUser.id, req.session.sessionCompilation._id, data, function (err, message) {
  225. callback(req, res, err, message, null);
  226. });
  227. },
  228. //project getData接口
  229. getData: function (projectID, callback, isReport, userID) {
  230. projectModel.findOne({ $or: [{ deleteInfo: null }, { 'deleteInfo.deleted': false }], ID: projectID }, '-_id').then(async function (project) {
  231. if (!project) {
  232. callback('', consts.projectConst.PROJECT_INFO, {});
  233. }
  234. let engineeringLibModel = new EngineeringLibModel();
  235. let engineeringInfo = project !== null && project.property.engineering_id !== undefined ?
  236. await engineeringLibModel.getEngineering(project.property.engineering_id) : null;
  237. let projInfo = project._doc;
  238. if (engineeringInfo !== null) {
  239. if (engineeringInfo.billsGuidance_lib) {
  240. for (let billsGuidanceLib of engineeringInfo.billsGuidance_lib) {
  241. let stdBillsGuidanceLib = await stdBillsGuidanceLibModel.findOne({ ID: billsGuidanceLib.id });
  242. if (stdBillsGuidanceLib) {
  243. billsGuidanceLib.type = stdBillsGuidanceLib.type ? stdBillsGuidanceLib.type : 1;
  244. }
  245. }
  246. }
  247. projInfo.engineeringInfo = engineeringInfo;
  248. }
  249. // 获取建设项目相关信息
  250. const constructionProject = await pm_facade.getConstructionProject(projectID);
  251. if (constructionProject) {
  252. projInfo.property.basicInformation = constructionProject.property && constructionProject.property.basicInformation || null;
  253. projInfo.property.projectValuationType = constructionProject.property && constructionProject.property.valuationType || null;
  254. }
  255. //获取单位工程完整目录结构
  256. let fullPath = await pm_facade.getFullPath(projectID);
  257. projInfo.fullPath = fullPath;
  258. // 获取分享的tip
  259. projInfo.shareTip = await pm_facade.getShareTip(projectID, 2);
  260. // 获取分享状态
  261. if (typeof userID === 'string') {
  262. projInfo.shareState = await pm_facade.getShareState(projectID, userID);
  263. }
  264. // 获取项目所属用户
  265. projInfo.owner = await userModel.findOne({_id: mongoose.Types.ObjectId(project.userID)}, 'real_name mobile').lean();
  266. projInfo.opener = await userModel.findOne({_id: mongoose.Types.ObjectId(userID)}, 'real_name mobile').lean();
  267. callback('', consts.projectConst.PROJECT_INFO, project);
  268. }, function (err) {
  269. callback(err, consts.projectConst.PROJECT_INFO, {});
  270. });
  271. },
  272. getProject: function (req, res) {
  273. let data = JSON.parse(req.body.data);
  274. let projectID = data.proj_id;
  275. ProjectsData.getUserProject(req.session.sessionUser.id, data.proj_id, async function (err, message, data) {
  276. if (err === 0) {
  277. let engineeringLibModel = new EngineeringLibModel();
  278. let engineeringInfo = data !== null && data.property.engineering_id !== undefined ?
  279. await engineeringLibModel.getEngineering(data.property.engineering_id) : null;
  280. let strData = JSON.stringify(data);
  281. let projInfo = JSON.parse(strData);
  282. if (engineeringInfo !== null) {
  283. if (engineeringInfo.billsGuidance_lib) {
  284. for (let billsGuidanceLib of engineeringInfo.billsGuidance_lib) {
  285. let stdBillsGuidanceLib = await stdBillsGuidanceLibModel.findOne({ ID: billsGuidanceLib.id });
  286. if (stdBillsGuidanceLib) {
  287. billsGuidanceLib.type = stdBillsGuidanceLib.type ? stdBillsGuidanceLib.type : 1;
  288. }
  289. }
  290. }
  291. projInfo.engineeringInfo = engineeringInfo;
  292. }
  293. //读取建设项目的基本信息
  294. let basicInfo = await ProjectsData.getBasicInfo(projectID);
  295. if(basicInfo !== null){
  296. projInfo.property.basicInformation = basicInfo;
  297. }
  298. //获取单位工程完整目录结构
  299. let fullPath = await pm_facade.getFullPath(projectID);
  300. projInfo.fullPath = fullPath;
  301. callback(req, res, err, message, projInfo);
  302. } else {
  303. callback(req, res, err, message, null);
  304. }
  305. });
  306. },
  307. beforeOpenProject: function (req, res) {
  308. let data = JSON.parse(req.body.data);
  309. ProjectsData.beforeOpenProject(req.session.sessionUser.id, data.proj_id, data.updateData, function (err, message, data) {
  310. callback(req, res, err, message, data);
  311. });
  312. },
  313. getNewProjectID: function (req, res) {
  314. let data = JSON.parse(req.body.data);
  315. ProjectsData.getNewProjectID(data.count, function (err, message, data) {
  316. callback(req, res, err, message, data);
  317. });
  318. },
  319. // 项目管理首页
  320. index: async function (request, response) {
  321. //await pm_facade.prepareShareList();
  322. // 获取编办信息
  323. let sessionCompilation = request.session.sessionCompilation;
  324. if (sessionCompilation === undefined || sessionCompilation === null) {
  325. return response.redirect('/logout');
  326. }
  327. let compilationModel = new CompilationModel();
  328. //更新编办信息
  329. let compilationData = await compilationModel.getCompilationById(sessionCompilation._id);
  330. request.session.sessionCompilation = compilationData;
  331. sessionCompilation = request.session.sessionCompilation;
  332. //更新用户的使用过的费用定额列表
  333. let isFirst = await pm_facade.isFirst(request.session.sessionUser.id, compilationData._id.toString());
  334. let engineeringLibModel = new EngineeringLibModel();
  335. // 建议估算
  336. let suggestionValuation = sessionCompilation.suggestion_valuation !== undefined ?
  337. sessionCompilation.suggestion_valuation : [];
  338. suggestionValuation = await engineeringLibModel.getLib(suggestionValuation);
  339. // 可行性估算
  340. let feasibilityValuation = sessionCompilation.feasibility_valuation !== undefined ?
  341. sessionCompilation.feasibility_valuation : [];
  342. feasibilityValuation = await engineeringLibModel.getLib(feasibilityValuation);
  343. // 估算
  344. let estimationValuation = sessionCompilation.estimation_valuation !== undefined ?
  345. sessionCompilation.estimation_valuation : [];
  346. estimationValuation = await engineeringLibModel.getLib(estimationValuation);
  347. // 概算
  348. let roughValuation = sessionCompilation.rough_valuation !== undefined ?
  349. sessionCompilation.rough_valuation : [];
  350. roughValuation = await engineeringLibModel.getLib(roughValuation);
  351. // 清单计价
  352. let billValuation = sessionCompilation.bill_valuation !== undefined ?
  353. sessionCompilation.bill_valuation : [];
  354. billValuation = await engineeringLibModel.getLib(billValuation);
  355. // 定额计价
  356. let rationValuation = sessionCompilation.ration_valuation !== undefined ?
  357. sessionCompilation.ration_valuation : [];
  358. rationValuation = await engineeringLibModel.getLib(rationValuation);
  359. if (sessionCompilation.name === '四川养护(2013)') {
  360. billValuation = rationValuation;
  361. }
  362. let absoluteUrl = compilationData.overWriteUrl ? request.app.locals.rootDir + compilationData.overWriteUrl : request.app.locals.rootDir;
  363. let overWriteUrl = fs.existsSync(absoluteUrl) && fs.statSync(absoluteUrl).isFile() ? compilationData.overWriteUrl : null;
  364. //欢迎页显示控制
  365. let [isShow,context,showTime] = await pm_facade.getWelcomeInfo(sessionCompilation._id,request.session.sessionUser,request.session.compilationVersion.includes('学习'));
  366. const unreadShareList = await pm_facade.getUnreadShareListByCompilation(request.session.sessionUser.id, sessionCompilation._id);
  367. let renderData = {
  368. unreadShareList: JSON.stringify(unreadShareList),
  369. isFirst: isFirst,
  370. isShow:isShow,
  371. context:context,
  372. showTime:showTime,
  373. userAccount: request.session.userAccount,
  374. userID: request.session.sessionUser.id,
  375. compilationData: JSON.stringify(sessionCompilation),
  376. overWriteUrl: overWriteUrl,
  377. suggestionValuation: JSON.stringify(suggestionValuation),
  378. feasibilityValuation: JSON.stringify(feasibilityValuation),
  379. estimationValuation: JSON.stringify(estimationValuation),
  380. roughValuation: JSON.stringify(roughValuation),
  381. billValuation: JSON.stringify(billValuation),
  382. rationValuation: JSON.stringify(rationValuation),
  383. engineeringList: JSON.stringify(engineering.List),
  384. adminLevelType: JSON.stringify(AdminLevelType),
  385. compilationName: sessionCompilation.name,
  386. versionName: request.session.compilationVersion,
  387. socketPort:config[process.env.NODE_ENV].socketPort?config[process.env.NODE_ENV].socketPort:5500,
  388. LicenseKey:config.getLicenseKey(process.env.NODE_ENV),
  389. title:getTitle(request.headers.host)
  390. };
  391. response.render('building_saas/pm/html/project-management.html', renderData);
  392. },
  393. //第一次进入该费用定额时准备的初始数据
  394. prepareInitialData: async function (request, response) {
  395. try {
  396. const data = {
  397. userID: request.session.sessionUser.id,
  398. compilationID: request.session.sessionCompilation._id,
  399. example: request.session.sessionCompilation.example
  400. };
  401. await redirectToImportServer(data, 'prepareInitialData', request);
  402. callback(request, response, 0, 'success', null);
  403. } catch (err) {
  404. console.log(err);
  405. callback(request, response, 1, err.toString(), null);
  406. }
  407. },
  408. // 获取单价文件列表
  409. getUnitFileList: async function (request, response) {
  410. let data = request.body.data;
  411. try {
  412. data = JSON.parse(data);
  413. let projectId = data.parentID !== undefined ? data.parentID : 0;
  414. if (isNaN(projectId) && projectId <= 0) {
  415. throw { msg: 'id数据有误!', err: 1 };
  416. }
  417. /*// 获取对应建设项目下所有的单位工程id
  418. let idList = await ProjectsData.getTenderByProjectId(projectId);
  419. if (idList.length <= 0) {
  420. throw {msg: '不存在对应单位工程', err: 0};
  421. }*/
  422. // 获取对应的单价文件
  423. let unitPriceFileModel = new UnitPriceFileModel();
  424. let unitPriceFileData = await unitPriceFileModel.getDataByRootProject(projectId);
  425. if (unitPriceFileData === null) {
  426. throw { msg: '不存在对应单价文件', err: 0 };
  427. }
  428. // 整理数据
  429. let unitPriceFileList = [];
  430. for (let unitPriceFile of unitPriceFileData) {
  431. let tmp = {
  432. name: unitPriceFile.name,
  433. id: unitPriceFile.id
  434. };
  435. unitPriceFileList.push(tmp);
  436. }
  437. callback(request, response, 0, '', unitPriceFileList);
  438. } catch (error) {
  439. console.log(error);
  440. let responseData = error.err === 1 ? null : [];
  441. callback(request, response, error.err, error.msg, responseData);
  442. }
  443. },
  444. getFeeRateFileList: async function (request, response) {
  445. let data = request.body.data;
  446. try {
  447. data = JSON.parse(data);
  448. let projectId = data.parentID !== undefined ? data.parentID : 0;
  449. if (isNaN(projectId) && projectId <= 0) {
  450. throw { msg: 'id数据有误!', err: 1 };
  451. }
  452. // 获取对应建设项目下所有的单位工程id
  453. let feeRateFileList = await fee_rate_facade.getFeeRatesByProject(projectId);
  454. callback(request, response, 0, '', feeRateFileList);
  455. } catch (error) {
  456. console.log(error);
  457. let responseData = error.err === 1 ? null : [];
  458. callback(request, response, error.err, error.msg, responseData);
  459. }
  460. },
  461. getGC: async function(req, res) {
  462. const userID = req.session.sessionUser.id;
  463. const compilationId = req.session.sessionCompilation._id;
  464. try {
  465. const rst = [];
  466. const priceFilesTask = ProjectsData.getGCFiles(fileType.unitPriceFile, userID);
  467. const feeRateFilesTask = ProjectsData.getGCFiles(fileType.feeRateFile, userID);
  468. const tendersTask = ProjectsData.getGCFiles(projType.tender, userID);
  469. const [priceFiles, rateFiles, tenders] = await Promise.all([priceFilesTask, feeRateFilesTask, tendersTask]);
  470. // 建设项目
  471. let projectIDs = tenders.reduce((acc, cur) => {
  472. acc.push(cur.ParentID);
  473. return acc;
  474. }, []);
  475. projectIDs = [...new Set(projectIDs)];
  476. const projects = await ProjectsData.getProjectsByIds(userID, compilationId, projectIDs);
  477. projects.forEach(project => {
  478. const projectDoc = project._doc;
  479. const relTenders = tenders.filter(tender => tender.ParentID === projectDoc.ID);
  480. const unitPriceFiles = priceFiles.filter(file => relTenders.find(tender => tender.property.unitPriceFile.id === file.id));
  481. const feeRateFiles = rateFiles.filter(file => relTenders.find(tender => tender.property.feeFile.id === file.ID));
  482. projectDoc.children = relTenders;
  483. projectDoc.unitPriceFiles = unitPriceFiles;
  484. projectDoc.feeRateFiles = feeRateFiles;
  485. rst.push(projectDoc);
  486. });
  487. callback(req, res, 0, 'success', rst);
  488. } catch (err) {
  489. console.log(err);
  490. callback(req, res, true, err.message, null);
  491. }
  492. },
  493. getGCDatas: async function (request, response) {
  494. let userID = request.session.sessionUser.id;
  495. let compilatoinId = request.session.sessionCompilation._id;
  496. let rst = [];
  497. let _projs = Object.create(null), _engs = Object.create(null), prefix = 'ID_';
  498. try {
  499. let gc_unitPriceFiles = await ProjectsData.getGCFiles(fileType.unitPriceFile, userID);
  500. let gc_feeRateFiles = await ProjectsData.getGCFiles(fileType.feeRateFile, userID);
  501. let gc_tenderFiles = await ProjectsData.getGCFiles(projType.tender, userID);
  502. for (let i = 0, len = gc_unitPriceFiles.length; i < len; i++) {
  503. let gc_uf = gc_unitPriceFiles[i];
  504. let theProj = _projs[prefix + gc_uf.root_project_id] || null;
  505. if (!theProj) {
  506. let tempProj = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_uf.root_project_id]);
  507. if (tempProj.length > 0 && tempProj[0].projType !== projType.folder) {
  508. theProj = _projs[prefix + gc_uf.root_project_id] = tempProj[0]._doc;
  509. buildProj(theProj);
  510. }
  511. }
  512. if (theProj) {
  513. theProj.unitPriceFiles.push(gc_uf);
  514. }
  515. }
  516. for (let i = 0, len = gc_feeRateFiles.length; i < len; i++) {
  517. let gc_ff = gc_feeRateFiles[i];
  518. let theProj = _projs[prefix + gc_ff.rootProjectID] || null;
  519. if (!theProj) {
  520. let tempProj = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_ff.rootProjectID]);
  521. if (tempProj.length > 0 && tempProj[0].projType !== projType.folder) {
  522. theProj = _projs[prefix + gc_ff.rootProjectID] = tempProj[0]._doc;
  523. buildProj(theProj);
  524. }
  525. }
  526. if (theProj) {
  527. theProj.feeRateFiles.push(gc_ff);
  528. }
  529. }
  530. if (gc_tenderFiles.length > 0) {
  531. for (let i = 0, len = gc_tenderFiles.length; i < len; i++) {
  532. let gc_t = gc_tenderFiles[i];
  533. let theProj = _projs[prefix + gc_t.ParentID] || null;
  534. if(!theProj){
  535. let tempProjs = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_t.ParentID]);
  536. if(tempProjs.length > 0 && tempProjs[0].projType === projType.project){
  537. theProj = _projs[prefix + gc_t.ParentID] = tempProjs[0]._doc;
  538. buildProj(theProj);
  539. }
  540. }
  541. if(theProj) {
  542. theProj.children.push(gc_t);
  543. }
  544. }
  545. }
  546. for (let i in _projs) {
  547. rst.push(_projs[i]);
  548. }
  549. function buildProj(proj) {
  550. proj.children = [];
  551. proj.unitPriceFiles = [];
  552. proj.feeRateFiles = [];
  553. }
  554. callback(request, response, 0, 'success', rst);
  555. }
  556. catch (error) {
  557. callback(request, response, true, error, null);
  558. }
  559. },
  560. recGC: function (request, response) {
  561. let userID = request.session.sessionUser.id,
  562. compilationId = request.session.sessionCompilation._id;
  563. let data = JSON.parse(request.body.data);
  564. let nodes = data.nodes;
  565. ProjectsData.recGC(userID, compilationId, nodes, function (err, msg, data) {
  566. callback(request, response, err, msg, data);
  567. });
  568. },
  569. delGC: async function (request, response) {
  570. let data = JSON.parse(request.body.data);
  571. let delDatas = data.delDatas;
  572. let bulkProjs = [], bulkUFs = [], bulkFFs = [];
  573. try {
  574. for (let data of delDatas) {
  575. if (data.updateType === 'Project') {
  576. bulkProjs.push({ updateOne: { filter: { ID: data.ID }, update: { 'deleteInfo.completeDeleted': true } } });
  577. }
  578. else if (data.updateType === fileType.unitPriceFile) {
  579. bulkUFs.push({ updateOne: { filter: { id: data.ID }, update: { 'deleteInfo.completeDeleted': true } } });
  580. }
  581. else {
  582. bulkFFs.push({ updateOne: { filter: { ID: data.ID }, update: { 'deleteInfo.completeDeleted': true } } });
  583. }
  584. }
  585. if (bulkProjs.length > 0) {
  586. await projectModel.bulkWrite(bulkProjs);
  587. }
  588. if (bulkUFs.length > 0) {
  589. await unitPriceFileModel.bulkWrite(bulkUFs);
  590. }
  591. if (bulkFFs.length > 0) {
  592. await feeRateFileModel.bulkWrite(bulkFFs);
  593. }
  594. callback(request, response, 0, 'success', null);
  595. } catch (err) {
  596. callback(request, response, 1, err, null);
  597. }
  598. },
  599. moveProject: async function (req, res) {
  600. let result = {
  601. error: 0
  602. };
  603. try {
  604. let data = req.body.data;
  605. let rdata = await pm_facade.moveProject(data);
  606. result.data = rdata;
  607. } catch (err) {
  608. console.log(err);
  609. result.error = 1;
  610. result.message = err.message;
  611. }
  612. res.json(result);
  613. },
  614. copyProjects: async function (req, res) {
  615. let result = {
  616. error: 0
  617. };
  618. try {
  619. let data = { dataString: req.body.data, userID: req.session.sessionUser.id, compilationID: req.session.sessionCompilation._id };
  620. result = await redirectToImportServer(data, "copyProject", req);
  621. } catch (err) {
  622. console.log(err);
  623. result.error = 1;
  624. result.message = err.message;
  625. }
  626. res.json(result);
  627. },
  628. projectShareInfo: async function (req, res) {
  629. try {
  630. const data = JSON.parse(req.body.data);
  631. const shareList = await pm_facade.getShareList({ projectID: data.projectID });
  632. const shareInfoMap = await pm_facade.getShareInfoMap(null, shareList);
  633. const shareInfo = shareInfoMap[data.projectID] || [];
  634. callback(req, res, 0, 'success', shareInfo);
  635. }
  636. catch (err) {
  637. callback(req, res, 1, err, null);
  638. }
  639. },
  640. getRecentShareInfo: async function (req, res) {
  641. try {
  642. const { count } = JSON.parse(req.body.data);
  643. const userID = req.session.sessionUser.id;
  644. const recentUsers = await pm_facade.getRecentShareList(userID, count);
  645. const contacts = await userModelObj.getContacts(userID);
  646. callback(req, res, 0, 'success', { recentUsers, contacts });
  647. } catch (err) {
  648. console.log(err);
  649. callback(req, res, 1, err.message, null);
  650. }
  651. },
  652. getInitialShareData: async function (req, res) {
  653. try {
  654. const { count, projectID } = JSON.parse(req.body.data);
  655. // 分享建设项目,仅提供给专业版用户
  656. /* const proShareProjType = [projType.folder, projType.project];
  657. const project = await projectModel.findOne({ ID: projectID }, 'projType');
  658. if (project && proShareProjType.indexOf(project.projType) >= 0) {
  659. const isFree = userModelObj.isFreeFromSession(req.session.compilationVersion);
  660. if (isFree) {
  661. callback(req, res, 0, 'success', { isFree });
  662. return;
  663. }
  664. } */
  665. const userID = req.session.sessionUser.id;
  666. // 最近分享
  667. const recentUsers = await pm_facade.getRecentShareList(userID, count);
  668. // 联系人
  669. const contacts = await userModelObj.getContacts(userID);
  670. // 分享过的人
  671. const sharedUsers = await pm_facade.getProjectShareList(projectID);
  672. callback(req, res, 0, 'success', { recentUsers, contacts, sharedUsers });
  673. } catch (err) {
  674. console.log(err);
  675. callback(req, res, 1, err.message, null);
  676. }
  677. },
  678. getReceiveLibList: async function (req, res) {
  679. try {
  680. const { libType } = JSON.parse(req.body.data);
  681. const userID = req.session.sessionUser.id;
  682. const compilationID = req.session.sessionCompilation._id;
  683. const list = await pm_facade.getReceiveLibList(userID, compilationID, libType);
  684. callback(req, res, 0, 'success', list);
  685. } catch (err) {
  686. callback(req, res, 1, err.message, null);
  687. }
  688. },
  689. getInitialShareLibData: async function (req, res) {
  690. try {
  691. const { libType, count } = JSON.parse(req.body.data);
  692. const userID = req.session.sessionUser.id;
  693. const compilationID = req.session.sessionCompilation._id;
  694. // 最近分享
  695. const recentUsers = await pm_facade.getRecentShareList(userID, count);
  696. // 联系人
  697. const contacts = await userModelObj.getContacts(userID);
  698. // 分享过的人
  699. const sharedUsers = await pm_facade.getLibShareList(userID, compilationID, libType, count);
  700. callback(req, res, 0, 'success', { recentUsers, contacts, sharedUsers });
  701. } catch (err) {
  702. console.log(err);
  703. callback(req, res, 1, err.message, null);
  704. }
  705. },
  706. shareLib: async function (req, res) {
  707. try {
  708. const { type, libType, shareData, count } = JSON.parse(req.body.data);
  709. const owner = req.session.sessionUser.id;
  710. const compilationID = req.session.sessionCompilation._id;
  711. const shareDate = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
  712. shareData.forEach(item => item.shareDate = shareDate);
  713. const task = [];
  714. // 是否只是单纯的更新分享选项,如果不是,需要重新获取最近分享和联系人
  715. let isSimpleUpdate = true;
  716. if (type === 'create') {
  717. isSimpleUpdate = false;
  718. // 生成分享记录
  719. const docs = shareData.map(item => ({
  720. compilationID,
  721. owner,
  722. libType,
  723. ID: uuidV1(),
  724. receiver: item.receiver,
  725. allowCooperate: false,
  726. shareDate: item.shareDate,
  727. updateDate: item.shareDate
  728. }));
  729. task.push(pm_facade.addShareList(docs, true));
  730. // 分享即互相添加为联系人
  731. task.push(userModelObj.addContact(docs[0].owner, docs[0].receiver));
  732. } else if (type === 'cancel') { // 取消分享
  733. const cancelReceivers = shareData.map(item => item.receiver);
  734. task.push(pm_facade.deleteShareList({ owner, libType, compilationID, receiver: { $in: cancelReceivers } }, true));
  735. }
  736. await Promise.all(task);
  737. const rst = {};
  738. if (!isSimpleUpdate) {
  739. const rstTask = [
  740. pm_facade.getRecentShareList(owner, count),
  741. userModelObj.getContacts(owner)
  742. ];
  743. const [recentUsers, contacts] = await Promise.all(rstTask);
  744. Object.assign(rst, { recentUsers, contacts });
  745. }
  746. callback(req, res, 0, 'success', rst);
  747. } catch (err) {
  748. console.log(err);
  749. logger.info(err);
  750. callback(req, res, 1, err, null);
  751. }
  752. },
  753. share: async function (req, res) {
  754. try {
  755. const data = JSON.parse(req.body.data);
  756. const { type, permissionType, shareData, projectID, count } = data;
  757. const userID = req.session.sessionUser.id;
  758. const shareDate = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
  759. shareData.forEach(item => item.shareDate = shareDate);
  760. const task = [];
  761. // 是否只是单纯的更新分享选项,如果不是,需要重新获取最近分享和联系人
  762. let isSimpleUpdate = true;
  763. if (type === 'create') {
  764. isSimpleUpdate = false;
  765. // 生成分享记录
  766. const docs = shareData.map(item => ({
  767. ID: uuidV1(),
  768. projectID,
  769. owner: userID,
  770. receiver: item.userID,
  771. allowCooperate: item.allowCooperate,
  772. allowCopy: item.allowCopy,
  773. shareDate: item.shareDate,
  774. updateDate: item.shareDate
  775. }));
  776. task.push(pm_facade.addShareList(docs));
  777. // 分享即互相添加为联系人
  778. task.push(userModelObj.addContact(docs[0].owner, docs[0].receiver));
  779. } else if (type === 'update') {
  780. // 取消分享(以前项目管理界面可一次进行更新和取消)
  781. const cancelReceivers = shareData
  782. .filter(item => item.isCancel)
  783. .map(item => item.userID);
  784. if (cancelReceivers.length) {
  785. isSimpleUpdate = false;
  786. task.push(pm_facade.deleteShareList({ projectID, receiver: { $in: cancelReceivers } }));
  787. }
  788. // 更新分享选项
  789. const updateData = shareData
  790. .filter(item => !item.isCancel)
  791. .map(item => {
  792. const update = { updateDate: shareDate };
  793. if (commonUtil.isDef(item.allowCopy)) {
  794. update.allowCopy = item.allowCopy;
  795. }
  796. if (commonUtil.isDef(item.allowCooperate)) {
  797. update.allowCooperate = item.allowCooperate;
  798. }
  799. return {
  800. query: {
  801. projectID,
  802. receiver: item.userID
  803. },
  804. update
  805. };
  806. });
  807. if (updateData.length) {
  808. task.push(pm_facade.updateShareList(updateData))
  809. }
  810. } else { // 取消分享
  811. const cancelReceivers = shareData.map(item => item.userID);
  812. task.push(pm_facade.deleteShareList({ projectID, receiver: { $in: cancelReceivers } }));
  813. }
  814. await Promise.all(task);
  815. // 获取需要广播推送的单位工程
  816. // shareData数组的形式是以前需求需要,现在的需求下,shareData数组必定只有一个元素
  817. const emitTenders = await pm_facade.getShareInfoAfterChangePermission(permissionType, shareData[0].userID, projectID);
  818. let rst = { emitTenders };
  819. if (!isSimpleUpdate) {
  820. const rstTask = [
  821. pm_facade.getRecentShareList(userID, count),
  822. userModelObj.getContacts(userID)
  823. ];
  824. const [recentUsers, contacts] = await Promise.all(rstTask);
  825. Object.assign(rst, { recentUsers, contacts });
  826. }
  827. callback(req, res, 0, 'success', rst);
  828. }
  829. catch (err) {
  830. console.log(err);
  831. callback(req, res, 1, String(err), null);
  832. }
  833. },
  834. receiveProjects: async function (req, res) {
  835. try {
  836. let rst = { grouped: [], ungrouped: [], summaryInfo: null };
  837. let userID = req.session.sessionUser.id;
  838. const shareList = await pm_facade.getShareList({ receiver: userID });
  839. const receiveProjectIDs = shareList.map(item => item.projectID);
  840. const compilation = req.session.sessionCompilation._id;
  841. const notDeleted = [{ deleteInfo: null }, { 'deleteInfo.deleted': false }];
  842. const receiveProjects = await projectModel.find({ ID: { $in: receiveProjectIDs }, compilation, $or: notDeleted }, '-_id').lean();
  843. //设置原项目用户信息
  844. const shareInfoMap = await pm_facade.getShareInfoMap(null, shareList);
  845. if (receiveProjects.length > 0) {
  846. let orgUserIDs = [];
  847. for (let proj of receiveProjects) {
  848. orgUserIDs.push(proj.userID);
  849. if (proj.projType === projType.tender) {
  850. // 设置项目类别
  851. proj.valuationType = ValuationText[proj.property.valuationType] || '';
  852. proj._valuationType = proj.property.valuationType;
  853. //设置工程专业
  854. proj.feeStandardName = proj.property.feeStandardName || '';
  855. //设置计税方法
  856. proj.taxType = proj.property.taxType;
  857. }
  858. delete proj.property;
  859. }
  860. orgUserIDs = Array.from(new Set(orgUserIDs));
  861. let userObjIDs = [];
  862. for (let uID of orgUserIDs) {
  863. userObjIDs.push(mongoose.Types.ObjectId(uID));
  864. }
  865. let orgUsersInfo = await userModel.find({ _id: { $in: userObjIDs } });
  866. //建设项目
  867. let consProjIDs = [],
  868. ungroupedTenders = [];
  869. for (let proj of receiveProjects) {
  870. // 设置分享信息
  871. proj.shareInfo = shareInfoMap[proj.ID] || [];
  872. if (proj.projType === projType.project) {
  873. consProjIDs.push(proj.ID);
  874. }
  875. //获取分享项目子项
  876. if (proj.projType !== projType.tender) {
  877. proj.children = await pm_facade.getPosterityProjects([proj.ID]);
  878. for (let projC of proj.children) {
  879. // 设置分享信息
  880. projC.shareInfo = shareInfoMap[projC.ID] || [];
  881. if (projC.projType === projType.project) {
  882. consProjIDs.push(projC.ID);
  883. } else if (projC.projType === projType.tender) {
  884. // 设置项目类别
  885. projC.valuationType = ValuationText[projC.property.valuationType] || '';
  886. projC._valuationType = projC.property.valuationType;
  887. //设置工程专业
  888. projC.feeStandardName = projC.property.feeStandardName || '';
  889. }
  890. delete projC.property;
  891. }
  892. } else {//未分类的单位工程不进行汇总,只取价格信息
  893. ungroupedTenders.push(proj);
  894. }
  895. //设置分组,单位工程及单项工程分到未分组那
  896. if (proj.projType === projType.tender || proj.projType === projType.engineering) {
  897. rst.ungrouped.push(proj);
  898. } else {
  899. rst.grouped.push(proj);
  900. }
  901. //设置项目类型为来自别人分享
  902. proj.shareType = 'receive';
  903. for (let userData of orgUsersInfo) {
  904. if (proj.userID == userData._id.toString()) {
  905. let userInfo = { name: userData.real_name, mobile: userData.mobile, company: userData.company, email: userData.email };
  906. proj.userInfo = userInfo;
  907. }
  908. }
  909. }
  910. consProjIDs = Array.from(new Set(consProjIDs));
  911. let summaryInfo = await pm_facade.getSummaryInfo(consProjIDs);
  912. let tendersFeeInfo = await pm_facade.getTendersFeeInfo(ungroupedTenders);
  913. rst.summaryInfo = { grouped: summaryInfo, ungrouped: tendersFeeInfo };
  914. }
  915. callback(req, res, 0, 'success', rst);
  916. }
  917. catch (err) {
  918. console.log(err);
  919. callback(req, res, 1, err, null);
  920. }
  921. },
  922. getProjectsByQuery: async function (req, res) {
  923. try {
  924. let data = JSON.parse(req.body.data);
  925. let compilation = req.session.sessionCompilation._id;
  926. let query = data.query;
  927. query.compilation = compilation;
  928. let options = data.options;
  929. let projects = await projectModel.find(query, options);
  930. callback(req, res, 0, 'success', projects);
  931. }
  932. catch (err) {
  933. callback(req, res, 1, err, null);
  934. }
  935. },
  936. getSummaryInfo: async function (req, res) {
  937. try {
  938. let data = JSON.parse(req.body.data);
  939. let summaryInfo = await pm_facade.getSummaryInfo(data.projectIDs);
  940. callback(req, res, 0, 'success', summaryInfo);
  941. }
  942. catch (err) {
  943. callback(req, res, 1, err, null);
  944. }
  945. },
  946. changeFile: async function (req, res) {
  947. try {
  948. let data = JSON.parse(req.body.data);
  949. console.log(data);
  950. await pm_facade.changeFile(data.projects, data.user_id, data.fileID, data.name, data.from, data.type);
  951. callback(req, res, 0, 'success', []);
  952. }
  953. catch (err) {
  954. console.log(err);
  955. callback(req, res, 1, err, null);
  956. }
  957. },
  958. exportProject: async function (req, res) {
  959. let result = {
  960. error: 0
  961. };
  962. try {
  963. let data = { dataString: req.body.data, userID: req.session.sessionUser.id };
  964. result = await redirectToImportServer(data, "exportProject", req);
  965. } catch (err) {
  966. console.log(err);
  967. result.error = 1;
  968. result.message = err.message;
  969. }
  970. res.json(result);
  971. },
  972. importProject: async function (req, res) {
  973. let data = JSON.parse(req.body.data);
  974. let result = {
  975. error: 0
  976. };
  977. try {
  978. data.session = req.session;
  979. result = await redirectToImportServer(data,"importProject",req);
  980. } catch (err) {
  981. console.log(err);
  982. result.error = 1;
  983. result.message = err.message;
  984. }
  985. res.json(result);
  986. },
  987. copyConstructionProject: async function (req, res) {
  988. let data = JSON.parse(req.body.data);
  989. let result = {
  990. error: 0
  991. };
  992. try {
  993. data.session = req.session;
  994. result.data = await redirectToImportServer(data, "copyConstructionProject", req);
  995. } catch (err) {
  996. console.log(err);
  997. result.error = 1;
  998. result.message = err.message;
  999. }
  1000. res.json(result);
  1001. },
  1002. importProcessChecking: async function (req, res) {
  1003. let result = {
  1004. error: 0
  1005. };
  1006. try {
  1007. let data = JSON.parse(req.body.data);
  1008. data.userID = req.session.sessionUser.id;
  1009. data.compilationID = req.session.sessionCompilation._id;
  1010. result.data = await pm_facade.importProcessChecking(data);
  1011. } catch (err) {
  1012. console.log(err);
  1013. result.error = 1;
  1014. result.message = err.message;
  1015. }
  1016. res.json(result);
  1017. },
  1018. getUploadToken: function (req, res) {
  1019. let result = {
  1020. error: 0
  1021. };
  1022. try {
  1023. result = pm_facade.uploadToken();
  1024. } catch (err) {
  1025. console.log(err);
  1026. result.error = 1;
  1027. result.message = err.message;
  1028. }
  1029. res.json(result);
  1030. },
  1031. getProjectByGranularity: async function (req, res) {
  1032. try {
  1033. const data = JSON.parse(req.body.data);
  1034. const userID = req.session.sessionUser.id;
  1035. const version = req.session.compilationVersion;
  1036. const projData = await pm_facade.getProjectByGranularity(data.tenderID, data.granularity, data.requestForSummaryInfo, userID, version);
  1037. callback(req, res, 0, 'success', projData);
  1038. } catch (err) {
  1039. callback(req, res, 1, err, null);
  1040. }
  1041. },
  1042. getImportTemplateData: async function (req, res) {
  1043. try {
  1044. const data = JSON.parse(req.body.data);
  1045. const templateData = await pm_facade.getImportTemplateData(req.session.sessionCompilation._id, data.valuationID, data.engineeringID, data.projectCount);
  1046. callback(req, res, 0, 'success', templateData);
  1047. } catch (err) {
  1048. callback(req, res, 1, err, null);
  1049. }
  1050. },
  1051. importInterface: async function (req, res) {
  1052. const data = JSON.parse(req.body.data);
  1053. let result = {
  1054. error: 0
  1055. };
  1056. try {
  1057. data.session = req.session;
  1058. result = await redirectToImportServer(data, "importInterface", req);
  1059. } catch (err) {
  1060. console.log(err);
  1061. result.error = 1;
  1062. result.message = err.message;
  1063. }
  1064. res.json(result);
  1065. },
  1066. };
  1067. async function redirectToImportServer(data, action, req) {
  1068. let importURL = config.getImportURL(process.env.NODE_ENV, req.headers.origin);
  1069. let options = {
  1070. method: 'POST',
  1071. uri: `http://${importURL}/import/${action}`,
  1072. body: data,
  1073. timeout: 220000,
  1074. json: true
  1075. };
  1076. console.log("post import data to:" + options.uri);
  1077. return await rp.post(options);
  1078. }