pm_controller.js 50 KB

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