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. const Project = require('../../main/models/project');
  9. let pm_facade = require('../../pm/facade/pm_facade');
  10. let controller = {
  11. importProject:async function (req){
  12. let data = req.body;
  13. return await pm_facade.downLoadProjectFile(data);
  14. },
  15. copyConstructionProject:async function(req){
  16. let data = req.body;
  17. return await pm_facade.copyConstructionProject(data);
  18. },
  19. prepareInitialData: async function(req) {
  20. const data = req.body;
  21. return await pm_facade.prepareInitialData(data.userID, data.compilationID, data.example);
  22. },
  23. exportProject:async function(req){
  24. let result={
  25. error:0
  26. };
  27. let data = JSON.parse(req.body.dataString);
  28. result.data = await pm_facade.exportProject(req.body.userID, data);
  29. return result
  30. },
  31. copyProject:async function(req){
  32. let result={
  33. error:0
  34. };
  35. let data = JSON.parse(req.body.dataString);
  36. result.data = await pm_facade.accessToCopyProject(req.body.userID,req.body.compilationID,data);
  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 importInterface (req) {
  47. const result = {
  48. error: 0
  49. };
  50. result.data = await pm_facade.importInterface(req.body.key, req.body.session);
  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. };