import_controller.js 2.3 KB

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