gljController.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Created by Zhong on 2017/8/22.
  3. */
  4. import BaseController from "../../common/base/base_controller";
  5. import stdgljutil from "../../../public/cache/std_glj_type_util";
  6. import GljDao from "../models/gljModel";
  7. import EngineeringLibModel from "../../users/models/engineering_lib_model";
  8. let gljDao = new GljDao();
  9. let callback = function(req, res, err, message, data){
  10. res.json({error: err, message: message, data: data});
  11. };
  12. class GljController extends BaseController{
  13. async redirectGlj(req, res){
  14. let gljLibId = null, engineeringId, sessionCompilation = req.session.sessionCompilation,
  15. rationValuation = sessionCompilation.ration_valuation,
  16. billValuation = sessionCompilation.bill_valuation,
  17. engineeringLibModel = new EngineeringLibModel();
  18. if(rationValuation[0]){
  19. let engineeringList = rationValuation[0].engineering_list;
  20. engineeringId = engineeringList.length > 0 ? engineeringList[0].engineering_id : null;
  21. let engineeringInfo = await engineeringLibModel.getEngineering(engineeringId);
  22. gljLibId = engineeringInfo.glj_lib.length > 0 && typeof engineeringInfo.glj_lib !== 'undefined' ? engineeringInfo.glj_lib[0].id : null;
  23. }
  24. else if(billValuation[0]){
  25. let engineeringList = billValuation[0].engineering_list;
  26. engineeringId = engineeringList.length > 0 ? engineeringList[0].engineering_id : null;
  27. let engineeringInfo = await engineeringLibModel.getEngineering(engineeringId);
  28. gljLibId = engineeringInfo.glj_lib.length > 0 && typeof engineeringInfo.glj_lib !== 'undefined' ? engineeringInfo.glj_lib[0].id : null;
  29. }
  30. res.render('building_saas/complementary_glj_lib/html/tools-gongliaoji.html',{
  31. userID: req.session.sessionUser.id,
  32. gljLibId: gljLibId,
  33. compilationId: sessionCompilation._id,
  34. versionName: req.session.sessionCompilation.name + '免费版'
  35. });
  36. }
  37. getGljDistType (req, res) {
  38. let gljDistTypeCache = stdgljutil.getStdGljTypeCacheObj().toArray();
  39. if(gljDistTypeCache.length >0 ){
  40. callback(req, res, 0, '', gljDistTypeCache);
  41. }
  42. else {
  43. callback(req, res, 1, 'Error', null);
  44. }
  45. }
  46. getGljTree(req,res){
  47. let data = JSON.parse(req.body.data);
  48. let gljLibId = data.gljLibId;
  49. gljDao.getGljTypes(gljLibId,function(err,data){
  50. callback(req,res,err, 'Get Tree', data)
  51. });
  52. }
  53. createNewGljTypeNode(req, res) {
  54. let repId = req.body.repositoryId;
  55. let lastNodeId = req.body.lastNodeId;
  56. let lastOpr = req.body.lastOpr;
  57. let nodeData = JSON.parse(req.body.rawNodeData);
  58. gljDao.createNewNode(repId, lastOpr, lastNodeId, nodeData, function(err, msg, data){
  59. callback(req,res,err,msg, data)
  60. });
  61. }
  62. updateGljNodes(req, res) {
  63. let nodes = JSON.parse(req.body.nodes);
  64. let repId = req.body.repId,
  65. lastOpr = req.body.lastOpr;
  66. gljDao.updateNodes(repId, lastOpr, nodes, function(err,results){
  67. callback(req,res, err, results)
  68. });
  69. }
  70. deleteGljNodes(req, res) {
  71. let nodes = JSON.parse(req.body.nodes);
  72. let preNodeId = req.body.preNodeId;
  73. let preNodeNextId = req.body.preNodeNextId;
  74. let repId = req.body.repId, lastOpr = req.body.lastOpr;
  75. gljDao.removeNodes(repId, lastOpr, nodes, preNodeId, preNodeNextId, function(err,results){
  76. callback(req,res, err, results)
  77. });
  78. }
  79. getGljItems(req, res) {
  80. let data = JSON.parse(req.body.data);
  81. let stdGljLibId = data.stdGljLibId,
  82. userId = data.userId,
  83. compilationId = data.compilationId
  84. gljDao.getGljItems(stdGljLibId, req.session.sessionUser.id, req.session.sessionCompilation._id, function(err, data){
  85. callback(req,res,err,'Get Items',data)
  86. });
  87. }
  88. updateComponent(req, res){
  89. let userId = req.body.userId;
  90. let updateArr = JSON.parse(req.body.updateArr);
  91. gljDao.updateComponent(userId, updateArr, function (err, message, rst) {
  92. callback(req, res, err, message, rst);
  93. })
  94. }
  95. mixUpdateGljItems(req, res){
  96. let user_id = req.session.sessionUser.id,
  97. compilation_id = req.session.sessionCompilation._id;
  98. let data = JSON.parse(req.body.data);
  99. let updateItems = data.updateItems,
  100. addItems = data.addItems,
  101. removeIds = data.removeIds;
  102. gljDao.mixUpdateGljItems(user_id, compilation_id, updateItems, addItems, removeIds, function(err, message, rst){
  103. if (err) {
  104. callback(req, res, err, message, null);
  105. } else {
  106. callback(req, res, 0, message, rst);
  107. }
  108. });
  109. }
  110. }
  111. export default GljController;