gljController.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. });
  35. }
  36. getGljDistType (req, res) {
  37. let gljDistTypeCache = stdgljutil.getStdGljTypeCacheObj().toArray();
  38. if(gljDistTypeCache.length >0 ){
  39. callback(req, res, 0, '', gljDistTypeCache);
  40. }
  41. else {
  42. callback(req, res, 1, 'Error', null);
  43. }
  44. }
  45. getGljTree(req,res){
  46. let data = JSON.parse(req.body.data);
  47. let gljLibId = data.gljLibId;
  48. gljDao.getGljTypes(gljLibId,function(err,data){
  49. callback(req,res,err, 'Get Tree', data)
  50. });
  51. }
  52. createNewGljTypeNode(req, res) {
  53. let repId = req.body.repositoryId;
  54. let lastNodeId = req.body.lastNodeId;
  55. let lastOpr = req.body.lastOpr;
  56. let nodeData = JSON.parse(req.body.rawNodeData);
  57. gljDao.createNewNode(repId, lastOpr, lastNodeId, nodeData, function(err, msg, data){
  58. callback(req,res,err,msg, data)
  59. });
  60. }
  61. updateGljNodes(req, res) {
  62. let nodes = JSON.parse(req.body.nodes);
  63. let repId = req.body.repId,
  64. lastOpr = req.body.lastOpr;
  65. gljDao.updateNodes(repId, lastOpr, nodes, function(err,results){
  66. callback(req,res, err, results)
  67. });
  68. }
  69. deleteGljNodes(req, res) {
  70. let nodes = JSON.parse(req.body.nodes);
  71. let preNodeId = req.body.preNodeId;
  72. let preNodeNextId = req.body.preNodeNextId;
  73. let repId = req.body.repId, lastOpr = req.body.lastOpr;
  74. gljDao.removeNodes(repId, lastOpr, nodes, preNodeId, preNodeNextId, function(err,results){
  75. callback(req,res, err, results)
  76. });
  77. }
  78. getGljItems(req, res) {
  79. let data = JSON.parse(req.body.data);
  80. let stdGljLibId = data.stdGljLibId,
  81. userId = data.userId,
  82. compilationId = data.compilationId
  83. gljDao.getGljItems(stdGljLibId, req.session.sessionUser.id, req.session.sessionCompilation._id, function(err, data){
  84. callback(req,res,err,'Get Items',data)
  85. });
  86. }
  87. updateComponent(req, res){
  88. let userId = req.body.userId;
  89. let updateArr = JSON.parse(req.body.updateArr);
  90. gljDao.updateComponent(userId, updateArr, function (err, message, rst) {
  91. callback(req, res, err, message, rst);
  92. })
  93. }
  94. mixUpdateGljItems(req, res){
  95. let user_id = req.session.sessionUser.id,
  96. compilation_id = req.session.sessionCompilation._id;
  97. let data = JSON.parse(req.body.data);
  98. let updateItems = data.updateItems,
  99. addItems = data.addItems,
  100. removeIds = data.removeIds;
  101. gljDao.mixUpdateGljItems(user_id, compilation_id, updateItems, addItems, removeIds, function(err, message, rst){
  102. if (err) {
  103. callback(req, res, err, message, null);
  104. } else {
  105. callback(req, res, 0, message, rst);
  106. }
  107. });
  108. }
  109. }
  110. export default GljController;