import_controller.js 2.7 KB

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