import_controller.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. importChongqingProject:async function(req){
  17. let data = req.body;
  18. return await pm_facade.importChongqingProject(data);
  19. },
  20. prepareInitialData: async function(req) {
  21. const data = req.body;
  22. return await pm_facade.prepareInitialData(data.userID, data.compilationID, data.example);
  23. },
  24. exportProject:async function(req){
  25. let result={
  26. error:0
  27. };
  28. let data = JSON.parse(req.body.dataString);
  29. result.data = await pm_facade.exportProject(req.body.userID, data);
  30. return result
  31. },
  32. copyProject:async function(req){
  33. let result={
  34. error:0
  35. };
  36. let data = JSON.parse(req.body.dataString);
  37. result.data = await pm_facade.accessToCopyProject(req.body.userID,req.body.compilationID,data);
  38. return result
  39. },
  40. async importInterface (req) {
  41. const result = {
  42. error: 0
  43. };
  44. result.data = await pm_facade.importInterface(req.body.key, req.body.session);
  45. return result;
  46. },
  47. async getDataForInterface (req) {
  48. const result = {
  49. error: 0
  50. };
  51. result.data = await Project.getDataSync(req.body.project_id);
  52. return result;
  53. },
  54. async loadSEIProjectData (req) {
  55. const result = {
  56. error: 0
  57. };
  58. result.data = await project_facade.loadSEIProjectData(req.body.projectID);
  59. return result;
  60. }
  61. };
  62. module.exports = {
  63. action:async function(req,res){//自动跳转到URL对应的controller方法
  64. let result={
  65. error:0
  66. };
  67. try {
  68. let functionName = req.url.replace(/\//g,"");
  69. result = controller[functionName]?await controller[functionName](req):"";
  70. }catch (err){
  71. logger.err(err);
  72. if(typeof err == "string"){
  73. result.error=2;
  74. result.msg = err;
  75. }else {
  76. result.error=1;
  77. result.msg = "导入失败请检查文件!"
  78. }
  79. }
  80. res.json(result);
  81. }
  82. };