zhongzewei hace 7 años
padre
commit
648a5a7778

+ 25 - 1
modules/ration_repository/models/glj_repository.js

@@ -35,7 +35,7 @@ var gljItemModel = db.model("std_ration_lib_glj_list",gljSchema, "std_ration_lib
 var repositoryMap = require('./repository_map');
 var counter = require('../../../public/counter/counter');
 let moment = require('moment');
-import {gljModel, gljClassModel} from "../../std_glj_lib/models/schemas";
+import {gljModel, gljClassModel, compleGljModel} from "../../std_glj_lib/models/schemas";
 
 var gljItemDAO = function(){};
 gljItemDAO.prototype.getGljTypes = function(gljLibID, callback){
@@ -74,6 +74,30 @@ gljItemDAO.prototype.getGljItems = function(gljIds, callback){
     })
 };
 
+gljItemDAO.prototype.getStdCompleGljItems = async function (rationGljList, callback) {
+    try{
+        let rst = [];
+        for(let i = 0, len = rationGljList.length; i < len; i++){
+            if(rationGljList[i].type !== undefined && rationGljList[i].type === 'complementary'){
+                let compleGlj = await compleGljModel.find({ID: rationGljList[i].gljId, deleteInfo: null});
+                if(compleGlj.length > 0){
+                    rst.push(compleGlj[0]);
+                }
+            }
+            else {
+                let stdGlj = await gljModel.find({ID: rationGljList[i].gljId, $or: [{deleted: null}, {deleted: false}]});
+                if(stdGlj.length > 0){
+                    rst.push(stdGlj[0]);
+                }
+            }
+        }
+        callback(0, rst);
+    }
+    catch(err){
+        callback(err, null);
+    }
+};
+
 gljItemDAO.prototype.getGljItemsByCode = function(repositoryId, codes, callback){
     gljModel.find({"repositoryId": repositoryId,"code": {"$in": codes}},function(err,data){
         if(err) callback(true, "")

+ 57 - 30
modules/ration_repository/models/ration_item.js

@@ -8,7 +8,7 @@ let counter = require('../../../public/counter/counter');
 let gljDao = require('./glj_repository');
 let rationRepositoryDao = require('./repository_map');
 const scMathUtil = require('../../../public/scMathUtil').getUtil();
-import {rationItemModel} from './schemas';
+import {rationItemModel, compleRationModel} from './schemas';
 
 var rationItemDAO = function(){};
 
@@ -208,12 +208,8 @@ function round(v,e){
     return Math.round(v*t)/t;
 }
 
+
 rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
-   // let basePrcArr = data.basePrcArr;
-       // adjGljId = data.gljId, adjBasePrice = data.basePrice, adjGljType = data.gljType,
-      //  repId = data.repId, lastOpr = data.lastOpr;
-    //
-   // let updateArr;
     async.each(basePrcArr, function (basePrcObj, finalCb) {
         let adjGljId = basePrcObj.gljId, adjBasePrice = basePrcObj.basePrice, adjGljType = basePrcObj.gljType;
         async.waterfall([
@@ -230,7 +226,25 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                                     cb(err);
                                 }
                                 else{
-                                    cb(null, result);
+                                    //补充定额
+                                    compleRationModel.find({'rationGljList.gljId': adjGljId},{ID: 1, rationGljList: 1}, function (err, compleRst) {
+                                        if(err){
+                                            cb(err);
+                                        }
+                                        else {
+                                            compleRationModel.update({'rationGljList.gljId': adjGljId}, {$pull: {rationGljList: {gljId: adjGljId}}}, {multi: true}, function (err) {
+                                                if(err){
+                                                    cb(err);
+                                                }
+                                                else {
+                                                    for(let i = 0, len = compleRst.length; i < len; i++){
+                                                        compleRst[i]._doc.type = 'complementary';
+                                                    }
+                                                    cb(null, result.concat(compleRst));
+                                                }
+                                            });
+                                        }
+                                    });
                                 }
                             });
                         }
@@ -242,27 +256,26 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                             cb(err);
                         }
                         else{
-                            cb(null, result);
+                            compleRationModel.find({'rationGljList.gljId': adjGljId}, function (err, compleRst) {
+                                if(err){
+                                    cb(err);
+                                }
+                                else {
+                                    for(let i = 0, len = compleRst.length; i < len; i++){
+                                        compleRst[i]._doc.type = 'complementary';
+                                    }
+                                    cb(null, result.concat(compleRst));
+                                }
+                            });
                         }
                     });
                 }
-               /* rationItemModel.find({'rationGljList.gljId': adjGljId}, function (err, result) {
-                    if(err){
-                        cb(err);
-                    }
-                    else{
-                        cb(null, result);
-                    }
-                });*/
             },
             function (result, cb) {
                 async.each(result, function (rationItem, ecb) {
                     let rationGljList = rationItem.rationGljList,
                         gljIds = [];
-                    rationGljList.forEach(function (rationGlj) {
-                        gljIds.push(rationGlj.gljId);
-                    });
-                    gljDao.getGljItems(gljIds, function(err, gljItems){
+                    gljDao.getStdCompleGljItems(rationGljList, function(err, gljItems){
                         if(err){
                             ecb(err);
                         }
@@ -335,16 +348,30 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                             }
                             updatePrc.basePrice = scMathUtil.roundTo(updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice, -2);
                             //updateDataBase
-                            rationItemModel.update({ID: rationItem.ID}, {$set: {labourPrice: updatePrc.labourPrice.toString(), materialPrice: updatePrc.materialPrice.toString(),
-                                    machinePrice: updatePrc.machinePrice.toString(), basePrice: updatePrc.basePrice.toString()}},
-                                function (err, result) {
-                                    if(err){
-                                        ecb(err);
-                                    }
-                                    else {
-                                        ecb(null);
-                                    }
-                                });
+                            if(rationItem._doc.type !== undefined && rationItem._doc.type === 'complementary'){
+                                compleRationModel.update({ID: rationItem.ID}, {$set: {labourPrice: updatePrc.labourPrice.toString(), materialPrice: updatePrc.materialPrice.toString(),
+                                        machinePrice: updatePrc.machinePrice.toString(), basePrice: updatePrc.basePrice.toString()}},
+                                    function (err, result) {
+                                        if(err){
+                                            ecb(err);
+                                        }
+                                        else {
+                                            ecb(null);
+                                        }
+                                    });
+                            }
+                            else {
+                                rationItemModel.update({ID: rationItem.ID}, {$set: {labourPrice: updatePrc.labourPrice.toString(), materialPrice: updatePrc.materialPrice.toString(),
+                                        machinePrice: updatePrc.machinePrice.toString(), basePrice: updatePrc.basePrice.toString()}},
+                                    function (err, result) {
+                                        if(err){
+                                            ecb(err);
+                                        }
+                                        else {
+                                            ecb(null);
+                                        }
+                                    });
+                            }
                         }
                     });
                 }, function(err){

+ 27 - 1
modules/ration_repository/models/schemas.js

@@ -104,9 +104,35 @@ var rationItemSchema = new Schema({
     isDeleted: Boolean
 });
 
+//补充定额
+let compleRationSchema = new Schema({
+    userId: Number,
+    compilationId: String,
+    rationRepId: Number,
+    ID:Number,
+    code: String,
+    name: String,
+    unit: String,
+    labourPrice: String,
+    materialPrice: String,
+    machinePrice: String,
+    basePrice: String,
+    sectionId: Number,
+    caption: String,
+    feeType: Number,
+    jobContent: String,
+    annotation: String,
+    rationGljList: Array,
+    rationCoeList: Array,
+    rationAssList: Array,
+    deleteInfo: Schema.Types.Mixed
+}, {versionKey: false});
+
 let coeListModel = db.model("std_ration_lib_coe_list",coeListSchema, "std_ration_lib_coe_list")
 let rationRepository = db.model("std_ration_lib_map", RepositoryMapSchema, "std_ration_lib_map");
 let rationChapterTreeModel = db.model("std_ration_lib_ration_chapter_trees", rationChapterTreeSchema, "std_ration_lib_ration_chapter_trees");
 let rationItemModel = db.model("std_ration_lib_ration_items",rationItemSchema, "std_ration_lib_ration_items");
+//补充定额
+let compleRationModel = db.model('complementary_ration_items', compleRationSchema, 'complementary_ration_items');
 
-export{coeListModel, rationRepository, rationChapterTreeModel, rationItemModel};
+export{coeListModel, rationRepository, rationChapterTreeModel, rationItemModel, compleRationModel};

+ 17 - 1
modules/std_glj_lib/models/schemas.js

@@ -77,10 +77,26 @@ let gljClassTemplate = mongoose.Schema({
     deleted: Boolean
 }, {versionKey: false});
 
+//补充工料机跟用户和编办绑定
+let complementaryGljSchema = new Schema({
+    userId: Number,
+    compilationId: String,
+    ID: Number,
+    code: String,
+    name: String,
+    specs: String,
+    unit: String,
+    basePrice: String,
+    gljClass: Number,
+    gljType: Number,
+    shortName: String,
+    component: Array
+}, {versionKey: false});
 
 let gljMapModel = mongoose.model('std_glj_lib_map', gljMapSchema, 'std_glj_lib_map');
 let gljModel = mongoose.model('std_glj_lib_gljList', gljSchema, 'std_glj_lib_gljList');
 let gljClassModel = mongoose.model('std_glj_lib_gljClass', gljClassSchema, 'std_glj_lib_gljClass');
 let gljClassTemplateModel = mongoose.model('std_glj_lib_gljClassTemplate', gljClassTemplate, 'std_glj_lib_gljClassTemplate');
+let compleGljModel = mongoose.model('complementary_glj_lib', complementaryGljSchema, 'complementary_glj_lib');
 
-export {gljMapModel as default, gljModel, gljClassModel, gljClassTemplateModel};
+export {gljMapModel as default, gljModel, gljClassModel, gljClassTemplateModel, compleGljModel};

+ 2 - 1
web/maintain/ration_repository/js/ration_assist.js

@@ -23,7 +23,8 @@ var rationAssistOprObj = {
     buildSheet: function(sheet) {
         var me = this;
         me.sheet = sheet;
-        me.libID = storageUtil.getSessionCache("RationGrp","repositoryID"); // 不可靠,有时取不到
+        //me.libID = storageUtil.getSessionCache("RationGrp","repositoryID"); // 不可靠,有时取不到
+        me.libID = pageOprObj.rationLibId; // 不可靠,有时取不到
         if (me.libID == undefined){me.libID = getQueryString('repository')};
 
         sheetCommonObj.initSheet(me.sheet, me.setting, 30);

+ 2 - 1
web/maintain/ration_repository/js/ration_coe.js

@@ -23,7 +23,8 @@ var rationCoeOprObj = {
     buildSheet: function(sheet) {
         var me = this;
         me.sheet = sheet;
-        me.libID = storageUtil.getSessionCache("RationGrp","repositoryID"); // 不可靠,有时取不到
+        //me.libID = storageUtil.getSessionCache("RationGrp","repositoryID"); // 不可靠,有时取不到
+        me.libID = pageOprObj.rationLibId; // 不可靠,有时取不到
         if (me.libID == undefined){me.libID = getQueryString('repository')};
         sheetCommonObj.initSheet(me.sheet, me.setting, 30);
         me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);

+ 4 - 6
web/maintain/ration_repository/js/ration_glj.js

@@ -143,10 +143,10 @@ var rationGLJOprObj = {
         }
     },
     onClipboardPasted: function(e, info) {
-        var me = rationGLJOprObj, repId = storageUtil.getSessionCache("RationGrp","repositoryID");
+        var me = rationGLJOprObj, repId = pageOprObj.rationLibId;
         me.tempCacheArr = [];
         if (repId) {
-            let gljLibId = storageUtil.getSessionCache("gljLib", "repositoryID_" + repId);
+            let gljLibId = pageOprObj.gljLibId;
             if(gljLibId){
                 if (info.cellRange.col == 0) {
                     let cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
@@ -257,15 +257,13 @@ var rationGLJOprObj = {
                         if (args.row < cacheArr.length && args.editingText !== cacheArr[args.row].code) {//更新
                             me.tempCacheArr.push({org: cacheArr[args.row], newCode: args.editingText.toString().trim()});
                             cacheArr.splice(args.row, 1);
-                            let rationRepId = storageUtil.getSessionCache("RationGrp", "repositoryID");
-                            let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
+                            let gljLibID = pageOprObj.gljLibId;
                             let codes = [];
                             codes.push(args.editingText.toString().trim());
                             me.addGljItems(codes, gljLibID, args);
                         }
                         else if (args.row >= cacheArr.length) {//新增
-                            let rationRepId = storageUtil.getSessionCache("RationGrp", "repositoryID");
-                            let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
+                            let gljLibID = pageOprObj.gljLibId;
                             if (gljLibID) {
                                 var codes = [];
                                 codes.push(args.editingText.toString().trim());