|
|
@@ -6,37 +6,56 @@ const stdgljutil = require("../../../public/cache/std_glj_type_util");
|
|
|
const GljDao = require("../models/gljModel");
|
|
|
const EngineeringLibModel = require("../../users/models/engineering_lib_model");
|
|
|
const config = require("../../../config/config.js");
|
|
|
-
|
|
|
+const pmFacade = require('../../pm/facade/pm_facade');
|
|
|
+const { ShareLibType } = require('../../../public/common_constants');
|
|
|
let gljDao = new GljDao();
|
|
|
let callback = function(req, res, err, message, data){
|
|
|
res.json({error: err, message: message, data: data});
|
|
|
};
|
|
|
|
|
|
+async function getGljLibId(sessionCompilation) {
|
|
|
+ let gljLibId = null,
|
|
|
+ rationValuation = sessionCompilation.ration_valuation,
|
|
|
+ billValuation = sessionCompilation.bill_valuation,
|
|
|
+ engineeringLibModel = new EngineeringLibModel(),
|
|
|
+ valuationIDs = [] ;
|
|
|
+ for(let r of rationValuation){//{ "glj_lib.0": {$exists:1} }
|
|
|
+ if(r.id){
|
|
|
+ valuationIDs.push(r.id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(let b of billValuation){
|
|
|
+ if(b.id){
|
|
|
+ valuationIDs.push(b.id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(valuationIDs.length > 0){
|
|
|
+ let engineeringInfo = await engineeringLibModel.findDataByCondition({'valuationID': {"$in": valuationIDs},"glj_lib.0": {$exists:1}});//数组大于0
|
|
|
+ gljLibId = engineeringInfo.glj_lib.length > 0 && typeof engineeringInfo.glj_lib !== 'undefined' ? engineeringInfo.glj_lib[0].id : null;
|
|
|
+ }
|
|
|
+ return gljLibId;
|
|
|
+}
|
|
|
+
|
|
|
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(),
|
|
|
- valuationIDs = [] ;
|
|
|
- for(let r of rationValuation){//{ "glj_lib.0": {$exists:1} }
|
|
|
- if(r.id){
|
|
|
- valuationIDs.push(r.id);
|
|
|
+ const { userID } = req.params;
|
|
|
+ const sessionUserID = req.session.sessionUser.id;
|
|
|
+ const compilationID = req.session.sessionCompilation._id;
|
|
|
+ if (userID !== sessionUserID) {
|
|
|
+ const receiveList = await pmFacade.getReceiveLibList(sessionUserID, compilationID, ShareLibType.GLJ_LIB);
|
|
|
+ const isValid = !!receiveList.find(user => String(user._id) === userID);
|
|
|
+ if (!isValid) {
|
|
|
+ return res.redirect(`/complementaryGlj/${sessionUserID}`);
|
|
|
}
|
|
|
}
|
|
|
- for(let b of billValuation){
|
|
|
- if(b.id){
|
|
|
- valuationIDs.push(b.id);
|
|
|
- }
|
|
|
- }
|
|
|
- if(valuationIDs.length > 0){
|
|
|
- let engineeringInfo = await engineeringLibModel.findDataByCondition({'valuationID': {"$in": valuationIDs},"glj_lib.0": {$exists:1}});//数组大于0
|
|
|
- gljLibId = engineeringInfo.glj_lib.length > 0 && typeof engineeringInfo.glj_lib !== 'undefined' ? engineeringInfo.glj_lib[0].id : null;
|
|
|
- }
|
|
|
- let overWriteUrl = req.session.sessionCompilation && req.session.sessionCompilation.overWriteUrl &&
|
|
|
- req.session.sessionCompilation._id !== '5b4d581023a924000b760f2d' ? req.session.sessionCompilation.overWriteUrl : null;
|
|
|
+ const sessionCompilation = req.session.sessionCompilation;
|
|
|
+ const gljLibId = await getGljLibId(sessionCompilation);
|
|
|
+ let overWriteUrl = sessionCompilation && req.session.sessionCompilation.overWriteUrl &&
|
|
|
+ compilationID !== '5b4d581023a924000b760f2d' ? req.session.sessionCompilation.overWriteUrl : null;
|
|
|
+ const isReadOnly = userID !== sessionUserID;
|
|
|
res.render('building_saas/complementary_glj_lib/html/tools-gongliaoji.html',{
|
|
|
- userID: req.session.sessionUser.id,
|
|
|
+ isReadOnly,
|
|
|
+ userID: sessionUserID,
|
|
|
gljLibId: gljLibId,
|
|
|
compilationId: sessionCompilation._id,
|
|
|
compilationName: sessionCompilation.name,
|
|
|
@@ -46,6 +65,21 @@ class GljController extends BaseController{
|
|
|
title:config[process.env.NODE_ENV].title?config[process.env.NODE_ENV].title:"纵横公路养护云造价"
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ async prepareInitData(req, res) {
|
|
|
+ try {
|
|
|
+ const { userID, projection } = JSON.parse(req.body.data);
|
|
|
+ const sessionUserID = req.session.sessionUser.id;
|
|
|
+ const gljLibID = await getGljLibId(req.session.sessionCompilation);
|
|
|
+ const compilationID = req.session.sessionCompilation._id;
|
|
|
+ const initData = await gljDao.prepareInitData(gljLibID, userID, sessionUserID, compilationID, projection);
|
|
|
+ res.json({error: 0, message: 'success', data: initData});
|
|
|
+ } catch (err) {
|
|
|
+ console.log(err);
|
|
|
+ res.json({error: 1, message: 'fail', data: null});
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
getGljDistType (req, res) {
|
|
|
let gljDistTypeCache = stdgljutil.getStdGljTypeCacheObj().toArray();
|
|
|
if(gljDistTypeCache.length >0 ){
|