Chenshilong 8 years ago
parent
commit
1bdf9717cf

+ 4 - 64
modules/rationRepository/controllers/coeListController.js

@@ -13,70 +13,10 @@ module.exports ={
             callback(req, res, err, 'Get coes', data);
         });
     },
-    createNewGljTypeNode: function(req, res) {
-        var repId = req.body.repositoryId;
-        var lastNodeId = req.body.lastNodeId;
-        var nodeData = JSON.parse(req.body.rawNodeData);
-        gljRepository.createNewNode(repId, lastNodeId, nodeData, function(err, msg, data){
-            callback(req,res,err,msg, data)
-        });
-    },
-    updateGljNodes: function(req, res) {
-        var nodes = JSON.parse(req.body.nodes);
-        gljRepository.updateNodes(nodes, function(err,results){
-            callback(req,res, err, results)
-        });
-    },
-    deleteGljNodes: function(req, res) {
-        var nodes = JSON.parse(req.body.nodes);
-        var preNodeId = req.body.preNodeId;
-        var preNodeNextId = req.body.preNodeNextId;
-        gljRepository.removeNodes(nodes, preNodeId, preNodeNextId, function(err,results){
-            callback(req,res, err, results)
-        });
-    },
-    getGljItems: function(req, res) {
-        var repId = req.body.repositoryId,
-            gljType = req.body.type,
-            gljCode = req.body.code;
-        if (gljCode) {
-            gljRepository.getGljItem(repId, gljCode, function(err, data){
-                callback(req,res,err,'Get Items', data)
-            });
-        } else if (gljType) {
-            gljRepository.getGljItemByType(repId, gljType, function(err, data){
-                callback(req,res,err,'Get Types', data)
-            });
-        } else {
-            gljRepository.getGljItemsByRep(repId, function(err, data){
-                callback(req,res,err,'Get Items',data)
-            });
-        }
-    },
-    getGljItemsByIds: function(req, res) {
-        var gljIds = JSON.parse(req.body.gljIds);
-        gljRepository.getGljItems(gljIds, function(err, data){
-            callback(req,res,err,'Get Items',data)
-        });
-    },
-    getGljItemsByCodes: function(req, res) {
-        var gljCodes = JSON.parse(req.body.gljCodes),
-            repId = req.body.repId;
-        gljRepository.getGljItemsByCode(repId, gljCodes, function(err, data){
-            callback(req,res,err,'Get Items',data)
-        });
-    },
-    mixUpdateGljItems: function(req, res){
-        var repId = req.body.repositoryId,
-            updateItems = JSON.parse(req.body.updateItems),
-            addItems = JSON.parse(req.body.addItems),
-            removeIds = JSON.parse(req.body.removeIds);
-        gljRepository.mixUpdateGljItems(repId, updateItems, addItems, removeIds, function(err, message, rst){
-            if (err) {
-                callback(req, res, err, message, null);
-            } else {
-                callback(req, res, err, message, rst);
-            }
+
+    saveCoeList: function(req, res) {
+        coeList.saveToCoeList(req.body.data, function(err, info){
+            callback(req, res, err, info, null);
         });
     }
 

+ 57 - 4
modules/rationRepository/models/coeList.js

@@ -5,13 +5,12 @@
 
 var mongoose = require("mongoose");
 var dbm = require("../../../config/db/db_manager");
-var db = dbm.getCfgConnection("rationRepository")
+var db = dbm.getCfgConnection("rationRepository");
+var counter = require('../../../public/counter/counter');
 
 var coeSchema = mongoose.Schema({
     coeType: String,                // 系数类型,指作用范围:
-                                    // 0 针对单个工料机。如:111量0.001
-                                    // 1 人工类。 2 材料类。 3 机械类。
-                                    // 9 针对本定额所有工料机。如:定额×0.925 (可以用123代替,但9的好处是前端不用做多余的过滤判断,提高效率)
+                                    // 单个(如:111量0.001)、人工类、材料类、机械类、全部(如:定额×0.925)。
     gljID: Number,                  // 要调整的工料机ID(当coeType=0时有效)
     operator: String,               // 运算符(*、+、-、=)
     amount: String,                 // 调整的量
@@ -50,4 +49,58 @@ coeListDAO.prototype.getCoesByLibID = function (libID, callback) {
         })
 };
 
+coeListDAO.prototype.saveToCoeList = function(data, callback) {
+    var me = this;
+    if (data.addArr.length > 0) {
+        me.addItems(data.addArr, callback);
+    };
+
+    //if (data.deleteArr.length > 0) {
+    //    me.deleteItems(data.deleteArr, callback);
+    //};
+
+    if (data.updateArr.length > 0) {
+        me.updateItems(data.updateArr, callback);
+    };
+};
+
+coeListDAO.prototype.addItems = function(addArr, callback) {
+    if (addArr && addArr.length > 0) {
+        counter.counterDAO.getIDAfterCount(counter.moduleName.coeList, addArr.length, function(err, result){
+            var maxId = result.value.sequence_value;
+            for (var i = 0; i < addArr.length; i++) {
+                var obj = new coeListModel(addArr[i]);
+                obj.ID = (maxId - (addArr.length - 1) + i);
+                coeListModel.create(obj, function(err) {
+                    if (err) {
+                        callback(true, err);
+                    } else {
+                        callback(false, null);
+                    };
+                });
+            };
+
+        });
+    } else {
+        callback(true, "No source");
+    };
+};
+
+coeListDAO.prototype.updateItems = function(updateArr, callback) {
+    if (updateArr && updateArr.length > 0) {
+            for (var i = 0; i < updateArr.length; i++) {
+                var obj = updateArr[i];
+                coeListModel.update({"libID": obj.libID, "ID": obj.ID}, updateArr[i], function(err) {
+                    if (err) {
+                        callback(true, "update Fail");
+                    } else {
+                        callback(false, "update success");
+                    };
+                });
+            };
+    } else {
+        callback(true, "No source");
+    };
+};
+
 module.exports = new coeListDAO();

+ 1 - 0
modules/rationRepository/routes/rationRepRoutes.js

@@ -36,6 +36,7 @@ apiRouter.post("/getGljItemsByIds",repositoryGljController.getGljItemsByIds);
 apiRouter.post("/getGljItemsByCodes",repositoryGljController.getGljItemsByCodes);
 
 apiRouter.post("/getCoeList",coeListController.getCoeList);
+apiRouter.post("/saveCoeList",coeListController.saveCoeList);
 
 
 module.exports = apiRouter;

+ 2 - 1
public/counter/counter.js

@@ -27,7 +27,8 @@ const COUNTER_MODULE_NAME = {
     report: 'rptTemplates',
     fee: 'fees',
     template_bills: 'temp_bills',
-    billsLib: 'billsLib'
+    billsLib: 'billsLib',
+    coeList: 'coeList'
 }
 /*const PROJECT_COUNTER = 'projects', USER_COUNTER = 'users', BILL_COUNTER = 'bills', RATION_COUNTER = 'rations',
     REPORT_COUNTER = 'rptTemplates', FEE_COUNTER = 'fees'*/

+ 27 - 0
web/rationRepository/js/coeList.js

@@ -117,6 +117,8 @@ var coeList = {
         //alert('onDetailCellChanged');
         var me = coeList;
         var row = args.sheet.getActiveRowIndex();
+        var mainRow = me.mainSpread.getSheet(0).getActiveRowIndex();
+        //alert(mainRow + ':' + row);
         var curType = args.sheet.getValue(row,0);
         if (!(curType == '单个')){
             me.detailSpread.suspendEvent();
@@ -127,6 +129,31 @@ var coeList = {
         else{
             //args.sheet.getCell(row, 1).backColor("Blue");
         };
+        var obj = me.datas[mainRow];
+        //debug.d(obj);
+        me.save([],[],[obj]);
+    },
+
+    save: function(addArr, deleteArr, updateArr) {
+        var me = repositoryGljObj;
+        $.ajax({
+            type:"POST",
+            url:"api/saveCoeList",
+            data: {data: {"addArr": addArr, "deleteArr": deleteArr, "updateArr": updateArr}},
+            dataType:"json",
+            cache:false,
+            timeout:5000,
+            success:function(result){
+                if (result.error) {
+                    alert(result.message);
+                } else {
+                    // 成功。
+                }
+            },
+            error:function(err){
+                alert("内部程序错误!");
+            }
+        })
     }
 };