|
@@ -35,7 +35,7 @@ var gljTypeModel = db.model("std_ration_lib_glj_type",gljClassSchema, "std_ratio
|
|
|
var gljItemModel = db.model("std_ration_lib_glj_list",gljSchema, "std_ration_lib_glj_list");
|
|
|
var repositoryMap = require('./repository_map');
|
|
|
var counter = require('../../../public/counter/counter');
|
|
|
-let rationItemDao = require('./ration_item');
|
|
|
+let moment = require('moment');
|
|
|
|
|
|
var gljItemDAO = function(){};
|
|
|
gljItemDAO.prototype.getGljTypes = function(rationLibId, callback){
|
|
@@ -81,18 +81,18 @@ gljItemDAO.prototype.getGljItemsByCode = function(repositoryId, codes, callback)
|
|
|
})
|
|
|
};
|
|
|
|
|
|
-gljItemDAO.prototype.mixUpdateGljItems = function(repId, updateItems, addItems, rIds, callback) {
|
|
|
+gljItemDAO.prototype.mixUpdateGljItems = function(repId, lastOpr, updateItems, addItems, rIds, callback) {
|
|
|
var me = this;
|
|
|
if (updateItems.length == 0 && rIds.length == 0) {
|
|
|
- me.addGljItems(repId, addItems, callback);
|
|
|
+ me.addGljItems(repId, lastOpr, addItems, callback);
|
|
|
} else {
|
|
|
- me.removeGljItems(rIds, function(err, message, docs) {
|
|
|
- me.updateGljItems(repId, updateItems, function(err, results){
|
|
|
+ me.removeGljItems(repId, lastOpr, rIds, function(err, message, docs) {
|
|
|
+ me.updateGljItems(repId, lastOpr, updateItems, function(err, results){
|
|
|
if (err) {
|
|
|
callback(true, "Fail to update", false);
|
|
|
} else {
|
|
|
if (addItems && addItems.length > 0) {
|
|
|
- me.addGljItems(repId, addItems, callback);
|
|
|
+ me.addGljItems(repId, lastOpr, addItems, callback);
|
|
|
} else {
|
|
|
callback(false, "Save successfully", results);
|
|
|
}
|
|
@@ -102,13 +102,20 @@ gljItemDAO.prototype.mixUpdateGljItems = function(repId, updateItems, addItems,
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-gljItemDAO.prototype.removeGljItems = function(rIds, callback) {
|
|
|
+gljItemDAO.prototype.removeGljItems = function(repId, lastOpr, rIds, callback) {
|
|
|
if (rIds && rIds.length > 0) {
|
|
|
gljItemModel.collection.remove({ID: {$in: rIds}}, null, function(err, docs){
|
|
|
if (err) {
|
|
|
callback(true, "Fail to remove", false);
|
|
|
} else {
|
|
|
- callback(false, "Remove successfully", docs);
|
|
|
+ repositoryMap.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
+ if(err){
|
|
|
+ callback(true, "Fail to update operator", false);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ callback(false, "Remove successfully", docs);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
@@ -116,7 +123,7 @@ gljItemDAO.prototype.removeGljItems = function(rIds, callback) {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-gljItemDAO.prototype.addGljItems = function(repId, items, callback) {
|
|
|
+gljItemDAO.prototype.addGljItems = function(repId, lastOpr, items, callback) {
|
|
|
if (items && items.length > 0) {
|
|
|
counter.counterDAO.getIDAfterCount(counter.moduleName.GLJ, items.length, function(err, result){
|
|
|
var maxId = result.value.sequence_value;
|
|
@@ -131,7 +138,14 @@ gljItemDAO.prototype.addGljItems = function(repId, items, callback) {
|
|
|
if (err) {
|
|
|
callback(true, "Fail to add", false);
|
|
|
} else {
|
|
|
- callback(false, "Add successfully", docs);
|
|
|
+ repositoryMap.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
+ if(err){
|
|
|
+ callback(true, "Fail to update Operator", false);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ callback(false, "Add successfully", docs);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
})
|
|
|
});
|
|
@@ -140,7 +154,7 @@ gljItemDAO.prototype.addGljItems = function(repId, items, callback) {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-gljItemDAO.prototype.updateGljItems = function(repId, items, callback) {
|
|
|
+gljItemDAO.prototype.updateGljItems = function(repId, lastOpr, items, callback) {
|
|
|
var functions = [];
|
|
|
for (var i=0; i < items.length; i++) {
|
|
|
functions.push((function(doc) {
|
|
@@ -156,12 +170,24 @@ gljItemDAO.prototype.updateGljItems = function(repId, items, callback) {
|
|
|
};
|
|
|
})(items[i]));
|
|
|
}
|
|
|
+ functions.push((function () {
|
|
|
+ return function (cb) {
|
|
|
+ repositoryMap.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
+ if(err){
|
|
|
+ cb(err);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ cb(null);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })());
|
|
|
async.parallel(functions, function(err, results) {
|
|
|
callback(err, results);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
-gljItemDAO.prototype.updateNodes = function(nodes, callback) {
|
|
|
+gljItemDAO.prototype.updateNodes = function(repId, lastOpr, nodes, callback) {
|
|
|
var functions = [];
|
|
|
for (var i=0; i < nodes.length; i++) {
|
|
|
functions.push((function(doc) {
|
|
@@ -170,11 +196,23 @@ gljItemDAO.prototype.updateNodes = function(nodes, callback) {
|
|
|
};
|
|
|
})(nodes[i]));
|
|
|
}
|
|
|
+ functions.push((function () {
|
|
|
+ return function (cb) {
|
|
|
+ repositoryMap.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
+ if(err){
|
|
|
+ cb(err);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ cb(null);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })());
|
|
|
async.parallel(functions, function(err, results) {
|
|
|
callback(err, results);
|
|
|
});
|
|
|
};
|
|
|
-gljItemDAO.prototype.removeNodes = function(nodeIds, preNodeId, preNodeNextId, callback){
|
|
|
+gljItemDAO.prototype.removeNodes = function(repId, lastOpr, nodeIds, preNodeId, preNodeNextId, callback){
|
|
|
var functions = [];
|
|
|
if (preNodeId != -1) {
|
|
|
functions.push((function(nodeId, nextId) {
|
|
@@ -190,31 +228,64 @@ gljItemDAO.prototype.removeNodes = function(nodeIds, preNodeId, preNodeNextId,
|
|
|
};
|
|
|
})(nodeIds[i]));
|
|
|
}
|
|
|
+ functions.push((function () {
|
|
|
+ return function (cb) {
|
|
|
+ repositoryMap.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
+ if(err){
|
|
|
+ cb(err);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ cb(null);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })());
|
|
|
async.parallel(functions, function(err, results) {
|
|
|
callback(err, results);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
-gljItemDAO.prototype.createNewNode = function(repId, lastNodeId, nodeData, callback) {
|
|
|
+gljItemDAO.prototype.createNewNode = function(repId, lastOpr, lastNodeId, nodeData, callback) {
|
|
|
return counter.counterDAO.getIDAfterCount(counter.moduleName.GLJ, 1, function(err, result){
|
|
|
nodeData.repositoryId = repId;
|
|
|
nodeData.ID = result.value.sequence_value;
|
|
|
var node = new gljTypeModel(nodeData);
|
|
|
- node.save(function (err, result) {
|
|
|
- if (err) {
|
|
|
- callback(true, "章节树ID错误!", false);
|
|
|
- } else {
|
|
|
- if (lastNodeId > 0) {
|
|
|
- gljTypeModel.update({ID: lastNodeId}, {"NextSiblingID": nodeData.ID}, function(err, rst){
|
|
|
- if (err) {
|
|
|
- callback(true, "章节树ID错误!", false);
|
|
|
- } else {
|
|
|
- callback(false, '', result);
|
|
|
- }
|
|
|
- });
|
|
|
- } else callback(false, '', result);
|
|
|
+ async.parallel([
|
|
|
+ function (cb) {
|
|
|
+ node.save(function (err, result) {
|
|
|
+ if (err) {
|
|
|
+ cb("章节树ID错误!", false);
|
|
|
+ } else {
|
|
|
+ if (lastNodeId > 0) {
|
|
|
+ gljTypeModel.update({ID: lastNodeId}, {"NextSiblingID": nodeData.ID}, function(err, rst){
|
|
|
+ if (err) {
|
|
|
+ cb("章节树ID错误!", false);
|
|
|
+ } else {
|
|
|
+ cb(false, result);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else cb(false, result);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ function (cb) {
|
|
|
+ repositoryMap.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
|
|
|
+ if(err){
|
|
|
+ cb(err);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ cb(null);
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
- });
|
|
|
+ ], function (err, result) {
|
|
|
+ if(err){
|
|
|
+ callback(true, "章节树错误!", false);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ callback(false, '', result[0]);
|
|
|
+ }
|
|
|
+ })
|
|
|
});
|
|
|
};
|
|
|
|