import_controller.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * Created by zhang on 2019/12/3.
  3. */
  4. /**
  5. * Created by jimiz on 2017/4/9.
  6. */
  7. let logger = require("../../../logs/log_helper").logger;
  8. const Project = require('../../main/models/project');
  9. let pm_facade = require('../../pm/facade/pm_facade');
  10. let controller = {
  11. importProject:async function (req){
  12. let data = req.body;
  13. return await pm_facade.downLoadProjectFile(data);
  14. },
  15. copyConstructionProject:async function(req){
  16. let data = req.body;
  17. return await pm_facade.copyConstructionProject(data);
  18. },
  19. prepareInitialData: async function(req) {
  20. const data = req.body;
  21. return await pm_facade.prepareInitialData(data.userID, data.compilationID, data.example);
  22. },
  23. exportProject:async function(req){
  24. let result={
  25. error:0
  26. };
  27. let data = JSON.parse(req.body.dataString);
  28. result.data = await pm_facade.exportProject(req.body.userID, data);
  29. return result
  30. },
  31. copyProject:async function(req){
  32. let result={
  33. error:0
  34. };
  35. let data = JSON.parse(req.body.dataString);
  36. result.data = await pm_facade.accessToCopyProject(req.body.userID,req.body.compilationID,data);
  37. return result
  38. },
  39. async getDataForInterface (req) {
  40. const result = {
  41. error: 0
  42. };
  43. result.data = await Project.getDataSync(req.body.project_id);
  44. return result;
  45. },
  46. };
  47. module.exports = {
  48. action:async function(req,res){//自动跳转到URL对应的controller方法
  49. let result={
  50. error:0
  51. };
  52. try {
  53. let functionName = req.url.replace(/\//g,"");
  54. result = controller[functionName]?await controller[functionName](req):"";
  55. }catch (err){
  56. logger.err(err);
  57. if(typeof err == "string"){
  58. result.error=2;
  59. result.msg = err;
  60. }else {
  61. result.error=1;
  62. result.msg = "导入失败请检查文件!"
  63. }
  64. }
  65. res.json(result);
  66. }
  67. };