import_controller.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. let pm_facade = require('../../pm/facade/pm_facade');
  9. let controller = {
  10. importProject:async function (req){
  11. let data = req.body;
  12. return await pm_facade.downLoadProjectFile(data);
  13. },
  14. copyConstructionProject:async function(req){
  15. let data = req.body;
  16. return await pm_facade.copyConstructionProject(data);
  17. },
  18. prepareInitialData: async function(req) {
  19. const data = req.body;
  20. return await pm_facade.prepareInitialData(data.userID, data.compilationID, data.example);
  21. },
  22. exportProject:async function(req){
  23. let result={
  24. error:0
  25. };
  26. let data = JSON.parse(req.body.dataString);
  27. result.data = await pm_facade.exportProject(req.body.userID, data);
  28. return result
  29. },
  30. copyProject:async function(req){
  31. let result={
  32. error:0
  33. };
  34. let data = JSON.parse(req.body.dataString);
  35. result.data = await pm_facade.accessToCopyProject(req.body.userID,req.body.compilationID,data);
  36. return result
  37. }
  38. };
  39. module.exports = {
  40. action:async function(req,res){//自动跳转到URL对应的controller方法
  41. let result={
  42. error:0
  43. };
  44. try {
  45. let functionName = req.url.replace(/\//g,"");
  46. result = controller[functionName]?await controller[functionName](req):"";
  47. }catch (err){
  48. logger.err(err);
  49. if(typeof err == "string"){
  50. result.error=2;
  51. result.msg = err;
  52. }else {
  53. result.error=1;
  54. result.msg = "导入失败请检查文件!"
  55. }
  56. }
  57. res.json(result);
  58. }
  59. };