import_controller.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. const Project = require('../../main/models/project');
  10. const project_facade = require('../../main/facade/project_facade.js');
  11. let controller = {
  12. importProject:async function (req){
  13. let data = req.body;
  14. return await pm_facade.downLoadProjectFile(data);
  15. },
  16. exportProject:async function(req){
  17. let result={
  18. error:0
  19. };
  20. let data = JSON.parse(req.body.dataString);
  21. result.data = await pm_facade.exportProject(req.body.userID, data);
  22. return result
  23. },
  24. copyProject:async function(req){
  25. let result={
  26. error:0
  27. };
  28. let data = JSON.parse(req.body.dataString);
  29. result.data = await pm_facade.copyProject(req.body.userID,req.body.compilationID,data);
  30. return result
  31. },
  32. async importInterface (req) {
  33. const result = {
  34. error: 0
  35. };
  36. result.data = await pm_facade.importInterface(req.body.key, req.body.session.sessionUser.id, req.body.session.sessionCompilation._id);
  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. async loadSEIProjectData (req) {
  47. const result = {
  48. error: 0
  49. };
  50. result.data = await project_facade.loadSEIProjectData(req.body.projectID);
  51. return result;
  52. }
  53. };
  54. module.exports = {
  55. action:async function(req,res){//自动跳转到URL对应的controller方法
  56. let result={
  57. error:0
  58. };
  59. try {
  60. let functionName = req.url.replace(/\//g,"");
  61. result = controller[functionName]?await controller[functionName](req):"";
  62. }catch (err){
  63. logger.err(err);
  64. if(typeof err == "string"){
  65. result.error=2;
  66. result.msg = err;
  67. }else {
  68. result.error=1;
  69. result.msg = "导入失败请检查文件!"
  70. }
  71. }
  72. res.json(result);
  73. }
  74. };