import_controller.js 1.5 KB

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