123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- /**
- * Created by Zhong on 2017/8/22.
- */
- import BaseController from "../../common/base/base_controller";
- import stdgljutil from "../../../public/cache/std_glj_type_util";
- import GljDao from "../models/gljModel";
- import EngineeringLibModel from "../../users/models/engineering_lib_model";
- let gljDao = new GljDao();
- let callback = function(req, res, err, message, data){
- res.json({error: err, message: message, data: data});
- };
- class GljController extends BaseController{
- async redirectGlj(req, res){
- let gljLibId = null, engineeringId, sessionCompilation = req.session.sessionCompilation,
- rationValuation = sessionCompilation.ration_valuation,
- billValuation = sessionCompilation.bill_valuation,
- engineeringLibModel = new EngineeringLibModel();
- if(rationValuation[0]){
- let engineeringList = rationValuation[0].engineering_list;
- engineeringId = engineeringList.length > 0 ? engineeringList[0].engineering_id : null;
- let engineeringInfo = await engineeringLibModel.getEngineering(engineeringId);
- gljLibId = engineeringInfo.glj_lib.length > 0 && typeof engineeringInfo.glj_lib !== 'undefined' ? engineeringInfo.glj_lib[0].id : null;
- }
- else if(billValuation[0]){
- let engineeringList = billValuation[0].engineering_list;
- engineeringId = engineeringList.length > 0 ? engineeringList[0].engineering_id : null;
- let engineeringInfo = await engineeringLibModel.getEngineering(engineeringId);
- gljLibId = engineeringInfo.glj_lib.length > 0 && typeof engineeringInfo.glj_lib !== 'undefined' ? engineeringInfo.glj_lib[0].id : null;
- }
- res.render('building_saas/complementary_glj_lib/html/tools-gongliaoji.html',{
- userID: req.session.sessionUser.id,
- gljLibId: gljLibId,
- compilationId: sessionCompilation._id
- });
- }
- getGljDistType (req, res) {
- let gljDistTypeCache = stdgljutil.getStdGljTypeCacheObj().toArray();
- if(gljDistTypeCache.length >0 ){
- callback(req, res, 0, '', gljDistTypeCache);
- }
- else {
- callback(req, res, 1, 'Error', null);
- }
- }
- getGljTree(req,res){
- let data = JSON.parse(req.body.data);
- let gljLibId = data.gljLibId;
- gljDao.getGljTypes(gljLibId,function(err,data){
- callback(req,res,err, 'Get Tree', data)
- });
- }
- createNewGljTypeNode(req, res) {
- let repId = req.body.repositoryId;
- let lastNodeId = req.body.lastNodeId;
- let lastOpr = req.body.lastOpr;
- let nodeData = JSON.parse(req.body.rawNodeData);
- gljDao.createNewNode(repId, lastOpr, lastNodeId, nodeData, function(err, msg, data){
- callback(req,res,err,msg, data)
- });
- }
- updateGljNodes(req, res) {
- let nodes = JSON.parse(req.body.nodes);
- let repId = req.body.repId,
- lastOpr = req.body.lastOpr;
- gljDao.updateNodes(repId, lastOpr, nodes, function(err,results){
- callback(req,res, err, results)
- });
- }
- deleteGljNodes(req, res) {
- let nodes = JSON.parse(req.body.nodes);
- let preNodeId = req.body.preNodeId;
- let preNodeNextId = req.body.preNodeNextId;
- let repId = req.body.repId, lastOpr = req.body.lastOpr;
- gljDao.removeNodes(repId, lastOpr, nodes, preNodeId, preNodeNextId, function(err,results){
- callback(req,res, err, results)
- });
- }
- getGljItems(req, res) {
- let data = JSON.parse(req.body.data);
- let stdGljLibId = data.stdGljLibId,
- userId = data.userId,
- compilationId = data.compilationId
- gljDao.getGljItems(stdGljLibId, req.session.sessionUser.id, req.session.sessionCompilation._id, function(err, data){
- callback(req,res,err,'Get Items',data)
- });
- }
- updateComponent(req, res){
- let userId = req.body.userId;
- let updateArr = JSON.parse(req.body.updateArr);
- gljDao.updateComponent(userId, updateArr, function (err, message, rst) {
- callback(req, res, err, message, rst);
- })
- }
- mixUpdateGljItems(req, res){
- let user_id = req.session.sessionUser.id,
- compilation_id = req.session.sessionCompilation._id;
- let data = JSON.parse(req.body.data);
- let updateItems = data.updateItems,
- addItems = data.addItems,
- removeIds = data.removeIds;
- gljDao.mixUpdateGljItems(user_id, compilation_id, updateItems, addItems, removeIds, function(err, message, rst){
- if (err) {
- callback(req, res, err, message, null);
- } else {
- callback(req, res, 0, message, rst);
- }
- });
- }
- }
- export default GljController;
|