|
@@ -0,0 +1,492 @@
|
|
|
|
+var mongoose = require("mongoose");
|
|
|
|
+var Schemas = require("./Schemas");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+var callback = function(req,res,err,data){
|
|
|
|
+ if(data){
|
|
|
|
+ res.status(200)
|
|
|
|
+ res.json({success:true,data:data});
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ if(err){
|
|
|
|
+ res.status(500)
|
|
|
|
+ res.json({success:false,error:"e"});
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ res.status(204);
|
|
|
|
+ res.json({success:true});
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+var inserts = {};
|
|
|
|
+var searchs = {};
|
|
|
|
+var updates = {}
|
|
|
|
+var removes = {}
|
|
|
|
+inserts.RationLibInsert = function(req,res){
|
|
|
|
+ var str = req.body.rationDisPlayName;
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ var lib = new LibMapModel({"DisplayName":str, "DBName":str}).save(function(err){
|
|
|
|
+ if(err) callback(req,res,err,false)
|
|
|
|
+ else
|
|
|
|
+ callback(req,res,false," ");
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+inserts.MainContentInsert = function(){};
|
|
|
|
+inserts.RationSectionInsert = function(req,res){//find and updata;
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ var rationSection = JSON.parse(req.body.rationSection);
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length) {
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost", realRationName);
|
|
|
|
+ var RationTreeModel = db.model("rationtrees", Schemas.RationTreeSchema);
|
|
|
|
+ RationTreeModel.find({"SectionID":rationSection.SectionID},function(err,data){
|
|
|
|
+ if(data.length){
|
|
|
|
+ RationTreeModel.update({'SectionID':rationSection.SectionID},{$set:{'Name':rationSection.Name}},function(err,data){
|
|
|
|
+ if(err){
|
|
|
|
+ callback(req,res,"some error occured when save RationTempTree!",false);
|
|
|
|
+ }else
|
|
|
|
+ callback(req,res,false,"save RationTempTree success!");
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ }else{
|
|
|
|
+ var N = new RationTreeModel(rationSection).save(function(err){
|
|
|
|
+ if(err){
|
|
|
|
+ callback(req,res,"some error occured when save RationTempTree!",false);
|
|
|
|
+ }else
|
|
|
|
+ callback(req,res,false,"save RationTempTree success!");
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+};
|
|
|
|
+inserts.SectionTextInsert = function(req,res){};
|
|
|
|
+inserts.RationItemsInsert = function(req,res){
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ var rationItem = JSON.parse(req.body.rationItem);
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length){
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost",realRationName);
|
|
|
|
+ var GLJListModel =db.model("rationitems",Schemas.RationItemsSchema);
|
|
|
|
+ new GLJListModel(rationItem).save(function(err){
|
|
|
|
+ if(err){
|
|
|
|
+ callback(req,res,"",false);
|
|
|
|
+ }else{
|
|
|
|
+ callback(req,res,false,"");
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+};
|
|
|
|
+inserts.RationContentInsert = function(){};
|
|
|
|
+inserts.GLJListInsert = function(req,res){
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ var glj = JSON.parse(req.body.gljItem);
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length){
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost",realRationName);
|
|
|
|
+ var GLJListModel =db.model("gljlists",Schemas.GLJListSchema);
|
|
|
|
+ new GLJListModel(glj).save(function(err){
|
|
|
|
+ if(err){
|
|
|
|
+ callback(req,res,"",false);
|
|
|
|
+ }else{
|
|
|
|
+ callback(req,res,false,"");
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+};
|
|
|
|
+inserts.RationGLJInsert = function(req,res){
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ var rationGLJ = JSON.parse(req.body.rationGLJ);
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length){
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost",realRationName);
|
|
|
|
+ var GLJListModel =db.model("rationgljs",Schemas.RationGLJSchema);
|
|
|
|
+ new GLJListModel(rationGLJ).save(function(err){
|
|
|
|
+ if(err){
|
|
|
|
+ callback(req,res,"",false);
|
|
|
|
+ }else{
|
|
|
|
+ callback(req,res,false,data);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+};
|
|
|
|
+inserts.GLJTypeTreeInsert = function(){};
|
|
|
|
+inserts.MinorRationInsert = function(){};
|
|
|
|
+inserts.CoeListInsert = function(){};
|
|
|
|
+inserts.RationCoeInsert = function(){};
|
|
|
|
+inserts.TempRationTreeInsert = function(req,res){
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ var rationTempTree = JSON.parse(req.body.rationTempTree);
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length){
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost",realRationName);
|
|
|
|
+ var RationTreeModel =db.model("rationtrees",Schemas.RationTreeSchema);
|
|
|
|
+ for(i=0;i<rationTempTree.length;i++){
|
|
|
|
+ var node ={}
|
|
|
|
+ node.SectionID = rationTempTree[i].id;
|
|
|
|
+ node.ParentID = rationTempTree[i].pId;
|
|
|
|
+
|
|
|
|
+ node.NextSiblingID = rationTempTree[i].nId;
|
|
|
|
+ node.Name =rationTempTree[i].name;
|
|
|
|
+ var N = new RationTreeModel(node).save(function(err){
|
|
|
|
+ if(err) console.log("wocao")
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if (i>=rationTempTree.length)
|
|
|
|
+ callback(req,res,false,"save RationTempTree success!");
|
|
|
|
+ else
|
|
|
|
+ callback(req,res,"some error occured when save RationTempTree!",false);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+searchs.getRationTree = function(req,res){
|
|
|
|
+ //打开连接相映定额库
|
|
|
|
+ //返回树结构到前段ztree处理
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length){
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost",realRationName);
|
|
|
|
+ var RationTreeModel =db.model("rationtrees",Schemas.RationTreeSchema);
|
|
|
|
+ RationTreeModel.find({},function(err,data){
|
|
|
|
+ if(data.length)
|
|
|
|
+ {
|
|
|
|
+ callback(req,res,false,data);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ callback(req,res,"查询定额错误!",false)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+searchs.getRationLibs = function(req,res){
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({},{"DisplayName":1},function(err,data){
|
|
|
|
+ if(data){
|
|
|
|
+ callback(req,res,false,data);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ callback(req,res,"没有定额库",false);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+searchs.getGLJList = function(req,res){
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length){
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost",realRationName);
|
|
|
|
+ var GLJListModel =db.model("gljlists",Schemas.GLJListSchema);
|
|
|
|
+ GLJListModel.find({},function(err,data){
|
|
|
|
+ if(data.length)
|
|
|
|
+ {
|
|
|
|
+ callback(req,res,false,data);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ if(err)
|
|
|
|
+ {
|
|
|
|
+ callback(req,res,"err",false)
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ callback(req,res,false,false)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+searchs.getGLJByCode = function(req,res){
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ var gljCode =req.body.gljCode ;
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length){
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost",realRationName);
|
|
|
|
+ var GLJListModel =db.model("gljlists",Schemas.GLJListSchema);
|
|
|
|
+ GLJListModel.find({"GLJCode":gljCode},function(err,data){
|
|
|
|
+ if(data.length)
|
|
|
|
+ {
|
|
|
|
+ callback(req,res,false,data);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ callback(req,res,"",false)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+searchs.getRationGLJItems = function(req,res){
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ var rationCode = req.body.rationCode;
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length){
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ var db = mongoose.createConnection("localhost",realRationName);
|
|
|
|
+ var RationGLJModel =db.model("rationgljs",Schemas.RationGLJSchema);
|
|
|
|
+ RationGLJModel.find({"RationCode":rationCode},function(err,rationglj){
|
|
|
|
+ if(rationglj.length) callback(req,res,false,rationglj);
|
|
|
|
+ else if(err)callback(req,res,"err",false);
|
|
|
|
+ else callback(req,res,false,false);
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+searchs.getGLJ = function(req,res){
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ var GLJCode = req.body.GLJCode ;
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length){
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost",realRationName);
|
|
|
|
+ var GLJListModel =db.model("gljlists",Schemas.GLJListSchema);
|
|
|
|
+ GLJListModel.find({"GLJCode":GLJCode},function(err,data){
|
|
|
|
+ if(data.length)
|
|
|
|
+ {
|
|
|
|
+ callback(req,res,false,data);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ callback(req,res,"",false)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+searchs.getRationsBySectionID = function(req,res){
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ var sectionID = Number(req.body.sectionID) ;
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length){
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost",realRationName);
|
|
|
|
+ var GLJListModel =db.model("rationitems",Schemas.RationItemsSchema);
|
|
|
|
+ GLJListModel.find({"SectionID":sectionID},function(err,data){
|
|
|
|
+ if(data.length)
|
|
|
|
+ {
|
|
|
|
+ callback(req,res,false,data);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ callback(req,res,"",false)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+removes.deleteRationLibs = function(req,res){//只删除了映射表内容 级联操作待完成
|
|
|
|
+ var rationName = req.body.rationName;
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.remove({"DisplayName":rationName},function(err){
|
|
|
|
+ if(err) callback(req,res,"删除错误",false);
|
|
|
|
+ else callback(req,res,false,"已删除");
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+removes.deleteRationSection =function(req,res){
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ var sectionID = req.body.rationSection;
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length) {
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost", realRationName);
|
|
|
|
+ var RationTreeModel = db.model("rationtrees", Schemas.RationTreeSchema);
|
|
|
|
+ RationTreeModel.remove({"SectionID":sectionID},function(err){
|
|
|
|
+ if(err){callback(req,res,"删除错误",false);}
|
|
|
|
+ else{callback(req,res,false,"已删除");}
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+removes.deleteGLJItem = function(req,res){
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ var gljItem = req.body.GLJCode;
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length) {
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost", realRationName);
|
|
|
|
+ var gljListModel = db.model("gljlists", Schemas.GLJListSchema);
|
|
|
|
+ gljListModel.remove({"GLJCode":gljItem},function(err){
|
|
|
|
+ if(err){callback(req,res,"删除错误",false);}
|
|
|
|
+ else{callback(req,res,false,"已删除");}
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+removes.deleteRation = function(req,res){
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ var deltype = req.body.type;
|
|
|
|
+ var delvalue = req.body.value;
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length) {
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost", realRationName);
|
|
|
|
+ var rationModel = db.model("rationitems",Schemas.RationItemsSchema);
|
|
|
|
+ rationModel.remove({"RationCode":delvalue},function(err){
|
|
|
|
+ if(err) callback(req,res,"err",false)
|
|
|
|
+ else {
|
|
|
|
+ var rationGLJModel = db.model("rationgljs",Schemas.RationGLJSchema);
|
|
|
|
+ rationGLJModel.remove({"RationCode":delvalue},function(err){
|
|
|
|
+ if(err) callback(req,res,"err",false)
|
|
|
|
+ else callback(req,res,false,"ok")
|
|
|
|
+ })
|
|
|
|
+ };
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+removes.deleteRationGLJ = function(req,res){
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ var delvalue = req.body.value;
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length) {
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost", realRationName);
|
|
|
|
+ var rationModel = db.model("rationgljs",Schemas.RationGLJSchema);
|
|
|
|
+ rationModel.remove({"GLJCode":delvalue},function(err){
|
|
|
|
+ if(err)
|
|
|
|
+ callback(req,res,"err",false)
|
|
|
|
+ else
|
|
|
|
+ callback(req,res,false,"ok")
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+updates.updateRationLib = function(req,res){
|
|
|
|
+ var str = req.body.rationName;
|
|
|
|
+ var newName = req.body.newName;
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.update({"DisplayName":str},{$set:{"DisplayName":newName}},function(err){
|
|
|
|
+ if(err) callback(req,res,"err",false)
|
|
|
|
+ else callback(req,res,false,"ok");
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+updates.updateGLJItem = function(req,res){
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ var GLJCode = req.body.GLJCode;
|
|
|
|
+ var glj =JSON.parse(req.body.newGLJ);
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length){
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost",realRationName);
|
|
|
|
+
|
|
|
|
+ var GLJListModel =db.model("gljlists",Schemas.GLJListSchema);
|
|
|
|
+ GLJListModel.update({"GLJCode":GLJCode},glj,function(err){
|
|
|
|
+ if(err) callback(req,res,"err",false)
|
|
|
|
+ else callback(req,res,false,"ok");
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+updates.updateRationItem = function(req,res){
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ var rationCode = req.body.RationCode;
|
|
|
|
+ var rationItem =JSON.parse(req.body.newRation);
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length){
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost",realRationName);
|
|
|
|
+ var RationModel =db.model("rationitems",Schemas.RationItemsSchema);
|
|
|
|
+ RationModel.update({"RationCode":rationCode},rationItem,function(err){
|
|
|
|
+ if(err) callback(req,res,"err",false)
|
|
|
|
+ else callback(req,res,false,"ok");
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+updates.updateRGLJAmount = function(req,res){
|
|
|
|
+ var DBName = req.body.rationName;
|
|
|
|
+ var gljCode = req.body.GLJCode;
|
|
|
|
+ var amount =JSON.parse(req.body.Amount);
|
|
|
|
+ Schemas.connectMap(function(db){
|
|
|
|
+ var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
|
|
|
|
+ LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
|
+ if(data.length){
|
|
|
|
+ var realRationName = data[0].DBName;
|
|
|
|
+ db = mongoose.createConnection("localhost",realRationName);
|
|
|
|
+ var RationModel =db.model("rationgljs",Schemas.RationGLJSchema);
|
|
|
|
+ RationModel.update({"GLJCode":gljCode},{$set:{"Amount":amount}},function(err){
|
|
|
|
+ if(err) callback(req,res,"err",false)
|
|
|
|
+ else callback(req,res,false,"ok");
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+var interfaces = {
|
|
|
|
+ "insert":inserts,
|
|
|
|
+ "remove":removes,
|
|
|
|
+ "search":searchs,
|
|
|
|
+ "update":updates
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+module.exports =interfaces;
|