pm_controller.js 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096
  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 } = 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.estimationValuation !== undefined ?
  337. sessionCompilation.estimationValuation : [];
  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. compilationName: sessionCompilation.name,
  374. versionName: request.session.compilationVersion,
  375. socketPort:config[process.env.NODE_ENV].socketPort?config[process.env.NODE_ENV].socketPort:5500,
  376. LicenseKey:config.getLicenseKey(process.env.NODE_ENV),
  377. title:config[process.env.NODE_ENV].title?config[process.env.NODE_ENV].title:"纵横公路养护云造价"
  378. };
  379. response.render('building_saas/pm/html/project-management.html', renderData);
  380. },
  381. //第一次进入该费用定额时准备的初始数据
  382. prepareInitialData: async function (request, response) {
  383. try {
  384. const data = {
  385. userID: request.session.sessionUser.id,
  386. compilationID: request.session.sessionCompilation._id,
  387. example: request.session.sessionCompilation.example
  388. };
  389. await redirectToImportServer(data, 'prepareInitialData', request);
  390. callback(request, response, 0, 'success', null);
  391. } catch (err) {
  392. console.log(err);
  393. callback(request, response, 1, err.toString(), null);
  394. }
  395. },
  396. // 获取单价文件列表
  397. getUnitFileList: async function (request, response) {
  398. let data = request.body.data;
  399. try {
  400. data = JSON.parse(data);
  401. let projectId = data.parentID !== undefined ? data.parentID : 0;
  402. if (isNaN(projectId) && projectId <= 0) {
  403. throw { msg: 'id数据有误!', err: 1 };
  404. }
  405. /*// 获取对应建设项目下所有的单位工程id
  406. let idList = await ProjectsData.getTenderByProjectId(projectId);
  407. if (idList.length <= 0) {
  408. throw {msg: '不存在对应单位工程', err: 0};
  409. }*/
  410. // 获取对应的单价文件
  411. let unitPriceFileModel = new UnitPriceFileModel();
  412. let unitPriceFileData = await unitPriceFileModel.getDataByRootProject(projectId);
  413. if (unitPriceFileData === null) {
  414. throw { msg: '不存在对应单价文件', err: 0 };
  415. }
  416. // 整理数据
  417. let unitPriceFileList = [];
  418. for (let unitPriceFile of unitPriceFileData) {
  419. let tmp = {
  420. name: unitPriceFile.name,
  421. id: unitPriceFile.id
  422. };
  423. unitPriceFileList.push(tmp);
  424. }
  425. callback(request, response, 0, '', unitPriceFileList);
  426. } catch (error) {
  427. console.log(error);
  428. let responseData = error.err === 1 ? null : [];
  429. callback(request, response, error.err, error.msg, responseData);
  430. }
  431. },
  432. getFeeRateFileList: async function (request, response) {
  433. let data = request.body.data;
  434. try {
  435. data = JSON.parse(data);
  436. let projectId = data.parentID !== undefined ? data.parentID : 0;
  437. if (isNaN(projectId) && projectId <= 0) {
  438. throw { msg: 'id数据有误!', err: 1 };
  439. }
  440. // 获取对应建设项目下所有的单位工程id
  441. let feeRateFileList = await fee_rate_facade.getFeeRatesByProject(projectId);
  442. callback(request, response, 0, '', feeRateFileList);
  443. } catch (error) {
  444. console.log(error);
  445. let responseData = error.err === 1 ? null : [];
  446. callback(request, response, error.err, error.msg, responseData);
  447. }
  448. },
  449. getGC: async function(req, res) {
  450. const userID = req.session.sessionUser.id;
  451. const compilationId = req.session.sessionCompilation._id;
  452. try {
  453. const rst = [];
  454. const priceFilesTask = ProjectsData.getGCFiles(fileType.unitPriceFile, userID);
  455. const feeRateFilesTask = ProjectsData.getGCFiles(fileType.feeRateFile, userID);
  456. const tendersTask = ProjectsData.getGCFiles(projType.tender, userID);
  457. const [priceFiles, rateFiles, tenders] = await Promise.all([priceFilesTask, feeRateFilesTask, tendersTask]);
  458. // 建设项目
  459. let projectIDs = tenders.reduce((acc, cur) => {
  460. acc.push(cur.ParentID);
  461. return acc;
  462. }, []);
  463. projectIDs = [...new Set(projectIDs)];
  464. const projects = await ProjectsData.getProjectsByIds(userID, compilationId, projectIDs);
  465. projects.forEach(project => {
  466. const projectDoc = project._doc;
  467. const relTenders = tenders.filter(tender => tender.ParentID === projectDoc.ID);
  468. const unitPriceFiles = priceFiles.filter(file => relTenders.find(tender => tender.property.unitPriceFile.id === file.id));
  469. const feeRateFiles = rateFiles.filter(file => relTenders.find(tender => tender.property.feeFile.id === file.ID));
  470. projectDoc.children = relTenders;
  471. projectDoc.unitPriceFiles = unitPriceFiles;
  472. projectDoc.feeRateFiles = feeRateFiles;
  473. rst.push(projectDoc);
  474. });
  475. callback(req, res, 0, 'success', rst);
  476. } catch (err) {
  477. console.log(err);
  478. callback(req, res, true, err.message, null);
  479. }
  480. },
  481. getGCDatas: async function (request, response) {
  482. let userID = request.session.sessionUser.id;
  483. let compilatoinId = request.session.sessionCompilation._id;
  484. let rst = [];
  485. let _projs = Object.create(null), _engs = Object.create(null), prefix = 'ID_';
  486. try {
  487. let gc_unitPriceFiles = await ProjectsData.getGCFiles(fileType.unitPriceFile, userID);
  488. let gc_feeRateFiles = await ProjectsData.getGCFiles(fileType.feeRateFile, userID);
  489. let gc_tenderFiles = await ProjectsData.getGCFiles(projType.tender, userID);
  490. for (let i = 0, len = gc_unitPriceFiles.length; i < len; i++) {
  491. let gc_uf = gc_unitPriceFiles[i];
  492. let theProj = _projs[prefix + gc_uf.root_project_id] || null;
  493. if (!theProj) {
  494. let tempProj = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_uf.root_project_id]);
  495. if (tempProj.length > 0 && tempProj[0].projType !== projType.folder) {
  496. theProj = _projs[prefix + gc_uf.root_project_id] = tempProj[0]._doc;
  497. buildProj(theProj);
  498. }
  499. }
  500. if (theProj) {
  501. theProj.unitPriceFiles.push(gc_uf);
  502. }
  503. }
  504. for (let i = 0, len = gc_feeRateFiles.length; i < len; i++) {
  505. let gc_ff = gc_feeRateFiles[i];
  506. let theProj = _projs[prefix + gc_ff.rootProjectID] || null;
  507. if (!theProj) {
  508. let tempProj = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_ff.rootProjectID]);
  509. if (tempProj.length > 0 && tempProj[0].projType !== projType.folder) {
  510. theProj = _projs[prefix + gc_ff.rootProjectID] = tempProj[0]._doc;
  511. buildProj(theProj);
  512. }
  513. }
  514. if (theProj) {
  515. theProj.feeRateFiles.push(gc_ff);
  516. }
  517. }
  518. if (gc_tenderFiles.length > 0) {
  519. for (let i = 0, len = gc_tenderFiles.length; i < len; i++) {
  520. let gc_t = gc_tenderFiles[i];
  521. let theProj = _projs[prefix + gc_t.ParentID] || null;
  522. if(!theProj){
  523. let tempProjs = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_t.ParentID]);
  524. if(tempProjs.length > 0 && tempProjs[0].projType === projType.project){
  525. theProj = _projs[prefix + gc_t.ParentID] = tempProjs[0]._doc;
  526. buildProj(theProj);
  527. }
  528. }
  529. if(theProj) {
  530. theProj.children.push(gc_t);
  531. }
  532. }
  533. }
  534. for (let i in _projs) {
  535. rst.push(_projs[i]);
  536. }
  537. function buildProj(proj) {
  538. proj.children = [];
  539. proj.unitPriceFiles = [];
  540. proj.feeRateFiles = [];
  541. }
  542. callback(request, response, 0, 'success', rst);
  543. }
  544. catch (error) {
  545. callback(request, response, true, error, null);
  546. }
  547. },
  548. recGC: function (request, response) {
  549. let userID = request.session.sessionUser.id,
  550. compilationId = request.session.sessionCompilation._id;
  551. let data = JSON.parse(request.body.data);
  552. let nodes = data.nodes;
  553. ProjectsData.recGC(userID, compilationId, nodes, function (err, msg, data) {
  554. callback(request, response, err, msg, data);
  555. });
  556. },
  557. delGC: async function (request, response) {
  558. let data = JSON.parse(request.body.data);
  559. let delDatas = data.delDatas;
  560. let bulkProjs = [], bulkUFs = [], bulkFFs = [];
  561. try {
  562. for (let data of delDatas) {
  563. if (data.updateType === 'Project') {
  564. bulkProjs.push({ updateOne: { filter: { ID: data.ID }, update: { 'deleteInfo.completeDeleted': true } } });
  565. }
  566. else if (data.updateType === fileType.unitPriceFile) {
  567. bulkUFs.push({ updateOne: { filter: { id: data.ID }, update: { 'deleteInfo.completeDeleted': true } } });
  568. }
  569. else {
  570. bulkFFs.push({ updateOne: { filter: { ID: data.ID }, update: { 'deleteInfo.completeDeleted': true } } });
  571. }
  572. }
  573. if (bulkProjs.length > 0) {
  574. await projectModel.bulkWrite(bulkProjs);
  575. }
  576. if (bulkUFs.length > 0) {
  577. await unitPriceFileModel.bulkWrite(bulkUFs);
  578. }
  579. if (bulkFFs.length > 0) {
  580. await feeRateFileModel.bulkWrite(bulkFFs);
  581. }
  582. callback(request, response, 0, 'success', null);
  583. } catch (err) {
  584. callback(request, response, 1, err, null);
  585. }
  586. },
  587. moveProject: async function (req, res) {
  588. let result = {
  589. error: 0
  590. };
  591. try {
  592. let data = req.body.data;
  593. let rdata = await pm_facade.moveProject(data);
  594. result.data = rdata;
  595. } catch (err) {
  596. console.log(err);
  597. result.error = 1;
  598. result.message = err.message;
  599. }
  600. res.json(result);
  601. },
  602. copyProjects: async function (req, res) {
  603. let result = {
  604. error: 0
  605. };
  606. try {
  607. let data = { dataString: req.body.data, userID: req.session.sessionUser.id, compilationID: req.session.sessionCompilation._id };
  608. result = await redirectToImportServer(data, "copyProject", req);
  609. } catch (err) {
  610. console.log(err);
  611. result.error = 1;
  612. result.message = err.message;
  613. }
  614. res.json(result);
  615. },
  616. projectShareInfo: async function (req, res) {
  617. try {
  618. const data = JSON.parse(req.body.data);
  619. const shareList = await pm_facade.getShareList({ projectID: data.projectID });
  620. const shareInfoMap = await pm_facade.getShareInfoMap(null, shareList);
  621. const shareInfo = shareInfoMap[data.projectID] || [];
  622. callback(req, res, 0, 'success', shareInfo);
  623. }
  624. catch (err) {
  625. callback(req, res, 1, err, null);
  626. }
  627. },
  628. getRecentShareInfo: async function (req, res) {
  629. try {
  630. const { count } = JSON.parse(req.body.data);
  631. const userID = req.session.sessionUser.id;
  632. const recentUsers = await pm_facade.getRecentShareList(userID, count);
  633. const contacts = await userModelObj.getContacts(userID);
  634. callback(req, res, 0, 'success', { recentUsers, contacts });
  635. } catch (err) {
  636. console.log(err);
  637. callback(req, res, 1, err.message, null);
  638. }
  639. },
  640. getInitialShareData: async function (req, res) {
  641. try {
  642. const { count, projectID } = JSON.parse(req.body.data);
  643. // 分享建设项目,仅提供给专业版用户
  644. /* const proShareProjType = [projType.folder, projType.project];
  645. const project = await projectModel.findOne({ ID: projectID }, 'projType');
  646. if (project && proShareProjType.indexOf(project.projType) >= 0) {
  647. const isFree = userModelObj.isFreeFromSession(req.session.compilationVersion);
  648. if (isFree) {
  649. callback(req, res, 0, 'success', { isFree });
  650. return;
  651. }
  652. } */
  653. const userID = req.session.sessionUser.id;
  654. // 最近分享
  655. const recentUsers = await pm_facade.getRecentShareList(userID, count);
  656. // 联系人
  657. const contacts = await userModelObj.getContacts(userID);
  658. // 分享过的人
  659. const sharedUsers = await pm_facade.getProjectShareList(projectID);
  660. callback(req, res, 0, 'success', { recentUsers, contacts, sharedUsers });
  661. } catch (err) {
  662. console.log(err);
  663. callback(req, res, 1, err.message, null);
  664. }
  665. },
  666. getReceiveLibList: async function (req, res) {
  667. try {
  668. const { libType } = JSON.parse(req.body.data);
  669. const userID = req.session.sessionUser.id;
  670. const compilationID = req.session.sessionCompilation._id;
  671. const list = await pm_facade.getReceiveLibList(userID, compilationID, libType);
  672. callback(req, res, 0, 'success', list);
  673. } catch (err) {
  674. callback(req, res, 1, err.message, null);
  675. }
  676. },
  677. getInitialShareLibData: async function (req, res) {
  678. try {
  679. const { libType, count } = JSON.parse(req.body.data);
  680. const userID = req.session.sessionUser.id;
  681. const compilationID = req.session.sessionCompilation._id;
  682. // 最近分享
  683. const recentUsers = await pm_facade.getRecentShareList(userID, count);
  684. // 联系人
  685. const contacts = await userModelObj.getContacts(userID);
  686. // 分享过的人
  687. const sharedUsers = await pm_facade.getLibShareList(userID, compilationID, libType, count);
  688. callback(req, res, 0, 'success', { recentUsers, contacts, sharedUsers });
  689. } catch (err) {
  690. console.log(err);
  691. callback(req, res, 1, err.message, null);
  692. }
  693. },
  694. shareLib: async function (req, res) {
  695. try {
  696. const { type, libType, shareData, count } = JSON.parse(req.body.data);
  697. const owner = req.session.sessionUser.id;
  698. const compilationID = req.session.sessionCompilation._id;
  699. const shareDate = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
  700. shareData.forEach(item => item.shareDate = shareDate);
  701. const task = [];
  702. // 是否只是单纯的更新分享选项,如果不是,需要重新获取最近分享和联系人
  703. let isSimpleUpdate = true;
  704. if (type === 'create') {
  705. isSimpleUpdate = false;
  706. // 生成分享记录
  707. const docs = shareData.map(item => ({
  708. compilationID,
  709. owner,
  710. libType,
  711. ID: uuidV1(),
  712. receiver: item.receiver,
  713. allowCooperate: false,
  714. shareDate: item.shareDate,
  715. updateDate: item.shareDate
  716. }));
  717. task.push(pm_facade.addShareList(docs, true));
  718. // 分享即互相添加为联系人
  719. task.push(userModelObj.addContact(docs[0].owner, docs[0].receiver));
  720. } else if (type === 'cancel') { // 取消分享
  721. const cancelReceivers = shareData.map(item => item.receiver);
  722. task.push(pm_facade.deleteShareList({ owner, libType, compilationID, receiver: { $in: cancelReceivers } }, true));
  723. }
  724. await Promise.all(task);
  725. const rst = {};
  726. if (!isSimpleUpdate) {
  727. const rstTask = [
  728. pm_facade.getRecentShareList(owner, count),
  729. userModelObj.getContacts(owner)
  730. ];
  731. const [recentUsers, contacts] = await Promise.all(rstTask);
  732. Object.assign(rst, { recentUsers, contacts });
  733. }
  734. callback(req, res, 0, 'success', rst);
  735. } catch (err) {
  736. console.log(err);
  737. logger.info(err);
  738. callback(req, res, 1, err, null);
  739. }
  740. },
  741. share: async function (req, res) {
  742. try {
  743. const data = JSON.parse(req.body.data);
  744. const { type, permissionType, shareData, projectID, count } = data;
  745. const userID = req.session.sessionUser.id;
  746. const shareDate = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
  747. shareData.forEach(item => item.shareDate = shareDate);
  748. const task = [];
  749. // 是否只是单纯的更新分享选项,如果不是,需要重新获取最近分享和联系人
  750. let isSimpleUpdate = true;
  751. if (type === 'create') {
  752. isSimpleUpdate = false;
  753. // 生成分享记录
  754. const docs = shareData.map(item => ({
  755. ID: uuidV1(),
  756. projectID,
  757. owner: userID,
  758. receiver: item.userID,
  759. allowCooperate: item.allowCooperate,
  760. allowCopy: item.allowCopy,
  761. shareDate: item.shareDate,
  762. updateDate: item.shareDate
  763. }));
  764. task.push(pm_facade.addShareList(docs));
  765. // 分享即互相添加为联系人
  766. task.push(userModelObj.addContact(docs[0].owner, docs[0].receiver));
  767. } else if (type === 'update') {
  768. // 取消分享(以前项目管理界面可一次进行更新和取消)
  769. const cancelReceivers = shareData
  770. .filter(item => item.isCancel)
  771. .map(item => item.userID);
  772. if (cancelReceivers.length) {
  773. isSimpleUpdate = false;
  774. task.push(pm_facade.deleteShareList({ projectID, receiver: { $in: cancelReceivers } }));
  775. }
  776. // 更新分享选项
  777. const updateData = shareData
  778. .filter(item => !item.isCancel)
  779. .map(item => {
  780. const update = { updateDate: shareDate };
  781. if (commonUtil.isDef(item.allowCopy)) {
  782. update.allowCopy = item.allowCopy;
  783. }
  784. if (commonUtil.isDef(item.allowCooperate)) {
  785. update.allowCooperate = item.allowCooperate;
  786. }
  787. return {
  788. query: {
  789. projectID,
  790. receiver: item.userID
  791. },
  792. update
  793. };
  794. });
  795. if (updateData.length) {
  796. task.push(pm_facade.updateShareList(updateData))
  797. }
  798. } else { // 取消分享
  799. const cancelReceivers = shareData.map(item => item.userID);
  800. task.push(pm_facade.deleteShareList({ projectID, receiver: { $in: cancelReceivers } }));
  801. }
  802. await Promise.all(task);
  803. // 获取需要广播推送的单位工程
  804. // shareData数组的形式是以前需求需要,现在的需求下,shareData数组必定只有一个元素
  805. const emitTenders = await pm_facade.getShareInfoAfterChangePermission(permissionType, shareData[0].userID, projectID);
  806. let rst = { emitTenders };
  807. if (!isSimpleUpdate) {
  808. const rstTask = [
  809. pm_facade.getRecentShareList(userID, count),
  810. userModelObj.getContacts(userID)
  811. ];
  812. const [recentUsers, contacts] = await Promise.all(rstTask);
  813. Object.assign(rst, { recentUsers, contacts });
  814. }
  815. callback(req, res, 0, 'success', rst);
  816. }
  817. catch (err) {
  818. console.log(err);
  819. callback(req, res, 1, String(err), null);
  820. }
  821. },
  822. receiveProjects: async function (req, res) {
  823. try {
  824. let rst = { grouped: [], ungrouped: [], summaryInfo: null };
  825. let userID = req.session.sessionUser.id;
  826. const shareList = await pm_facade.getShareList({ receiver: userID });
  827. const receiveProjectIDs = shareList.map(item => item.projectID);
  828. const compilation = req.session.sessionCompilation._id;
  829. const notDeleted = [{ deleteInfo: null }, { 'deleteInfo.deleted': false }];
  830. const receiveProjects = await projectModel.find({ ID: { $in: receiveProjectIDs }, compilation, $or: notDeleted }, '-_id').lean();
  831. //设置原项目用户信息
  832. const shareInfoMap = await pm_facade.getShareInfoMap(null, shareList);
  833. if (receiveProjects.length > 0) {
  834. let orgUserIDs = [];
  835. for (let proj of receiveProjects) {
  836. orgUserIDs.push(proj.userID);
  837. if (proj.projType === projType.tender) {
  838. // 设置项目类别
  839. proj.valuationType = ValuationText[proj.property.valuationType] || '';
  840. proj._valuationType = proj.property.valuationType;
  841. //设置工程专业
  842. proj.feeStandardName = proj.property.feeStandardName || '';
  843. //设置计税方法
  844. proj.taxType = proj.property.taxType;
  845. }
  846. delete proj.property;
  847. }
  848. orgUserIDs = Array.from(new Set(orgUserIDs));
  849. let userObjIDs = [];
  850. for (let uID of orgUserIDs) {
  851. userObjIDs.push(mongoose.Types.ObjectId(uID));
  852. }
  853. let orgUsersInfo = await userModel.find({ _id: { $in: userObjIDs } });
  854. //建设项目
  855. let consProjIDs = [],
  856. ungroupedTenders = [];
  857. for (let proj of receiveProjects) {
  858. // 设置分享信息
  859. proj.shareInfo = shareInfoMap[proj.ID] || [];
  860. if (proj.projType === projType.project) {
  861. consProjIDs.push(proj.ID);
  862. }
  863. //获取分享项目子项
  864. if (proj.projType !== projType.tender) {
  865. proj.children = await pm_facade.getPosterityProjects([proj.ID]);
  866. for (let projC of proj.children) {
  867. // 设置分享信息
  868. projC.shareInfo = shareInfoMap[projC.ID] || [];
  869. if (projC.projType === projType.project) {
  870. consProjIDs.push(projC.ID);
  871. } else if (projC.projType === projType.tender) {
  872. // 设置项目类别
  873. projC.valuationType = ValuationText[projC.property.valuationType] || '';
  874. projC._valuationType = projC.property.valuationType;
  875. //设置工程专业
  876. projC.feeStandardName = projC.property.feeStandardName || '';
  877. }
  878. delete projC.property;
  879. }
  880. } else {//未分类的单位工程不进行汇总,只取价格信息
  881. ungroupedTenders.push(proj);
  882. }
  883. //设置分组,单位工程及单项工程分到未分组那
  884. if (proj.projType === projType.tender || proj.projType === projType.engineering) {
  885. rst.ungrouped.push(proj);
  886. } else {
  887. rst.grouped.push(proj);
  888. }
  889. //设置项目类型为来自别人分享
  890. proj.shareType = 'receive';
  891. for (let userData of orgUsersInfo) {
  892. if (proj.userID == userData._id.toString()) {
  893. let userInfo = { name: userData.real_name, mobile: userData.mobile, company: userData.company, email: userData.email };
  894. proj.userInfo = userInfo;
  895. }
  896. }
  897. }
  898. consProjIDs = Array.from(new Set(consProjIDs));
  899. let summaryInfo = await pm_facade.getSummaryInfo(consProjIDs);
  900. let tendersFeeInfo = await pm_facade.getTendersFeeInfo(ungroupedTenders);
  901. rst.summaryInfo = { grouped: summaryInfo, ungrouped: tendersFeeInfo };
  902. }
  903. callback(req, res, 0, 'success', rst);
  904. }
  905. catch (err) {
  906. console.log(err);
  907. callback(req, res, 1, err, null);
  908. }
  909. },
  910. getProjectsByQuery: async function (req, res) {
  911. try {
  912. let data = JSON.parse(req.body.data);
  913. let compilation = req.session.sessionCompilation._id;
  914. let query = data.query;
  915. query.compilation = compilation;
  916. let options = data.options;
  917. let projects = await projectModel.find(query, options);
  918. callback(req, res, 0, 'success', projects);
  919. }
  920. catch (err) {
  921. callback(req, res, 1, err, null);
  922. }
  923. },
  924. getSummaryInfo: async function (req, res) {
  925. try {
  926. let data = JSON.parse(req.body.data);
  927. let summaryInfo = await pm_facade.getSummaryInfo(data.projectIDs);
  928. callback(req, res, 0, 'success', summaryInfo);
  929. }
  930. catch (err) {
  931. callback(req, res, 1, err, null);
  932. }
  933. },
  934. changeFile: async function (req, res) {
  935. try {
  936. let data = JSON.parse(req.body.data);
  937. console.log(data);
  938. await pm_facade.changeFile(data.projects, data.user_id, data.fileID, data.name, data.from, data.type);
  939. callback(req, res, 0, 'success', []);
  940. }
  941. catch (err) {
  942. console.log(err);
  943. callback(req, res, 1, err, null);
  944. }
  945. },
  946. exportProject: async function (req, res) {
  947. let result = {
  948. error: 0
  949. };
  950. try {
  951. let data = { dataString: req.body.data, userID: req.session.sessionUser.id };
  952. result = await redirectToImportServer(data, "exportProject", req);
  953. } catch (err) {
  954. console.log(err);
  955. result.error = 1;
  956. result.message = err.message;
  957. }
  958. res.json(result);
  959. },
  960. importProject: async function (req, res) {
  961. let data = JSON.parse(req.body.data);
  962. let result = {
  963. error: 0
  964. };
  965. try {
  966. data.session = req.session;
  967. result = await redirectToImportServer(data,"importProject",req);
  968. } catch (err) {
  969. console.log(err);
  970. result.error = 1;
  971. result.message = err.message;
  972. }
  973. res.json(result);
  974. },
  975. copyConstructionProject: async function (req, res) {
  976. let data = JSON.parse(req.body.data);
  977. let result = {
  978. error: 0
  979. };
  980. try {
  981. data.session = req.session;
  982. result.data = await redirectToImportServer(data, "copyConstructionProject", req);
  983. } catch (err) {
  984. console.log(err);
  985. result.error = 1;
  986. result.message = err.message;
  987. }
  988. res.json(result);
  989. },
  990. importProcessChecking: async function (req, res) {
  991. let result = {
  992. error: 0
  993. };
  994. try {
  995. let data = JSON.parse(req.body.data);
  996. data.userID = req.session.sessionUser.id;
  997. data.compilationID = req.session.sessionCompilation._id;
  998. result.data = await pm_facade.importProcessChecking(data);
  999. } catch (err) {
  1000. console.log(err);
  1001. result.error = 1;
  1002. result.message = err.message;
  1003. }
  1004. res.json(result);
  1005. },
  1006. getUploadToken: function (req, res) {
  1007. let result = {
  1008. error: 0
  1009. };
  1010. try {
  1011. result = pm_facade.uploadToken();
  1012. } catch (err) {
  1013. console.log(err);
  1014. result.error = 1;
  1015. result.message = err.message;
  1016. }
  1017. res.json(result);
  1018. },
  1019. getProjectByGranularity: async function (req, res) {
  1020. try {
  1021. const data = JSON.parse(req.body.data);
  1022. const userID = req.session.sessionUser.id;
  1023. const version = req.session.compilationVersion;
  1024. const projData = await pm_facade.getProjectByGranularity(data.tenderID, data.granularity, data.requestForSummaryInfo, userID, version);
  1025. callback(req, res, 0, 'success', projData);
  1026. } catch (err) {
  1027. callback(req, res, 1, err, null);
  1028. }
  1029. },
  1030. getImportTemplateData: async function (req, res) {
  1031. try {
  1032. const data = JSON.parse(req.body.data);
  1033. const templateData = await pm_facade.getImportTemplateData(req.session.sessionCompilation._id, data.valuationID, data.engineeringID, data.projectCount);
  1034. callback(req, res, 0, 'success', templateData);
  1035. } catch (err) {
  1036. callback(req, res, 1, err, null);
  1037. }
  1038. },
  1039. importInterface: async function (req, res) {
  1040. const data = JSON.parse(req.body.data);
  1041. let result = {
  1042. error: 0
  1043. };
  1044. try {
  1045. data.session = req.session;
  1046. result = await redirectToImportServer(data, "importInterface", req);
  1047. } catch (err) {
  1048. console.log(err);
  1049. result.error = 1;
  1050. result.message = err.message;
  1051. }
  1052. res.json(result);
  1053. },
  1054. };
  1055. async function redirectToImportServer(data, action, req) {
  1056. let importURL = config.getImportURL(process.env.NODE_ENV, req.headers.origin);
  1057. let options = {
  1058. method: 'POST',
  1059. uri: `http://${importURL}/import/${action}`,
  1060. body: data,
  1061. timeout: 220000,
  1062. json: true
  1063. };
  1064. console.log("post import data to:" + options.uri);
  1065. return await rp.post(options);
  1066. }