|
@@ -10,7 +10,7 @@ var callback = function(req,res,err,data){
|
|
|
else
|
|
|
if(err){
|
|
|
res.status(500)
|
|
|
- res.json({success:false,error:"e"});
|
|
|
+ res.json({success:false,error:err});
|
|
|
}
|
|
|
else{
|
|
|
res.status(204);
|
|
@@ -42,7 +42,7 @@ inserts.RationSectionInsert = function(req,res){//find and updata;
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length) {
|
|
|
var realRationName = data[0].DBName;
|
|
|
- db = mongoose.createConnection("localhost", realRationName);
|
|
|
+ db = mongoose.createConnection("192.168.1.184", realRationName,60666);
|
|
|
var RationTreeModel = db.model("rationtrees", Schemas.RationTreeSchema);
|
|
|
RationTreeModel.find({"SectionID":rationSection.SectionID},function(err,data){
|
|
|
if(data.length){
|
|
@@ -75,15 +75,23 @@ inserts.RationItemsInsert = function(req,res){
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length){
|
|
|
var realRationName = data[0].DBName;
|
|
|
- db = mongoose.createConnection("localhost",realRationName);
|
|
|
+ db = mongoose.createConnection("192.168.1.184",realRationName,60666);
|
|
|
var GLJListModel =db.model("rationitems",Schemas.RationItemsSchema);
|
|
|
- new GLJListModel(rationItem).save(function(err){
|
|
|
- if(err){
|
|
|
- callback(req,res,"",false);
|
|
|
- }else{
|
|
|
- callback(req,res,false,"");
|
|
|
- }
|
|
|
+ //加控制语句
|
|
|
+ GLJListModel.find({"RationCode":rationItem.RationCode},function(err,data){
|
|
|
+ if(data.length)
|
|
|
+ callback(req,res,"定额号重复!",false)
|
|
|
+ else
|
|
|
+ new GLJListModel(rationItem).save(function(err){
|
|
|
+ if(err){
|
|
|
+ callback(req,res,"",false);
|
|
|
+ }else{
|
|
|
+ callback(req,res,false,"");
|
|
|
+ }
|
|
|
+ })
|
|
|
})
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
})
|
|
|
})
|
|
@@ -97,15 +105,20 @@ inserts.GLJListInsert = function(req,res){
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length){
|
|
|
var realRationName = data[0].DBName;
|
|
|
- db = mongoose.createConnection("localhost",realRationName);
|
|
|
+ db = mongoose.createConnection("192.168.1.184",realRationName,60666);
|
|
|
var GLJListModel =db.model("gljlists",Schemas.GLJListSchema);
|
|
|
- new GLJListModel(glj).save(function(err){
|
|
|
- if(err){
|
|
|
- callback(req,res,"",false);
|
|
|
- }else{
|
|
|
- callback(req,res,false,"");
|
|
|
- }
|
|
|
+ GLJListModel.find({"GLJCode":glj.GLJCode},function(err,data){
|
|
|
+ if(data.length) callback(req,res,"工料机号重复!",false)
|
|
|
+ else
|
|
|
+ new GLJListModel(glj).save(function(err){
|
|
|
+ if(err){
|
|
|
+ callback(req,res,"新增工料机错误!",false);
|
|
|
+ }else{
|
|
|
+ callback(req,res,false,"");
|
|
|
+ }
|
|
|
+ })
|
|
|
})
|
|
|
+
|
|
|
}
|
|
|
})
|
|
|
})
|
|
@@ -118,15 +131,20 @@ inserts.RationGLJInsert = function(req,res){
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length){
|
|
|
var realRationName = data[0].DBName;
|
|
|
- db = mongoose.createConnection("localhost",realRationName);
|
|
|
+ db = mongoose.createConnection("192.168.1.184",realRationName,60666);
|
|
|
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);
|
|
|
- }
|
|
|
+ GLJListModel.find({"RationCode":rationGLJ.RationCode,"GLJCode":rationGLJ.GLJCode},function(err,data){
|
|
|
+ if(data.length) callback(req,res,"不可在一条定额下套用相同定额多次",false)
|
|
|
+ else
|
|
|
+ new GLJListModel(rationGLJ).save(function(err){
|
|
|
+ if(err){
|
|
|
+ callback(req,res,"",false);
|
|
|
+ }else{
|
|
|
+ callback(req,res,false,data);
|
|
|
+ }
|
|
|
+ })
|
|
|
})
|
|
|
+
|
|
|
}
|
|
|
})
|
|
|
})
|
|
@@ -143,7 +161,7 @@ inserts.TempRationTreeInsert = function(req,res){
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length){
|
|
|
var realRationName = data[0].DBName;
|
|
|
- db = mongoose.createConnection("localhost",realRationName);
|
|
|
+ db = mongoose.createConnection("192.168.1.184",realRationName,60666);
|
|
|
var RationTreeModel =db.model("rationtrees",Schemas.RationTreeSchema);
|
|
|
for(i=0;i<rationTempTree.length;i++){
|
|
|
var node ={}
|
|
@@ -173,7 +191,7 @@ searchs.getRationTree = function(req,res){
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length){
|
|
|
var realRationName = data[0].DBName;
|
|
|
- db = mongoose.createConnection("localhost",realRationName);
|
|
|
+ db = mongoose.createConnection("192.168.1.184",realRationName,60666);
|
|
|
var RationTreeModel =db.model("rationtrees",Schemas.RationTreeSchema);
|
|
|
RationTreeModel.find({},function(err,data){
|
|
|
if(data.length)
|
|
@@ -209,7 +227,7 @@ searchs.getGLJList = function(req,res){
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length){
|
|
|
var realRationName = data[0].DBName;
|
|
|
- db = mongoose.createConnection("localhost",realRationName);
|
|
|
+ db = mongoose.createConnection("192.168.1.184",realRationName,60666);
|
|
|
var GLJListModel =db.model("gljlists",Schemas.GLJListSchema);
|
|
|
GLJListModel.find({},function(err,data){
|
|
|
if(data.length)
|
|
@@ -237,17 +255,13 @@ searchs.getGLJByCode = function(req,res){
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length){
|
|
|
var realRationName = data[0].DBName;
|
|
|
- db = mongoose.createConnection("localhost",realRationName);
|
|
|
+ db = mongoose.createConnection("192.168.1.184",realRationName,60666);
|
|
|
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)
|
|
|
- }
|
|
|
+ callback(req,res,"无此工料机",false)
|
|
|
})
|
|
|
}
|
|
|
})
|
|
@@ -261,7 +275,7 @@ searchs.getRationGLJItems = function(req,res){
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length){
|
|
|
var realRationName = data[0].DBName;
|
|
|
- var db = mongoose.createConnection("localhost",realRationName);
|
|
|
+ var db = mongoose.createConnection("192.168.1.184",realRationName,60666);
|
|
|
var RationGLJModel =db.model("rationgljs",Schemas.RationGLJSchema);
|
|
|
RationGLJModel.find({"RationCode":rationCode},function(err,rationglj){
|
|
|
if(rationglj.length) callback(req,res,false,rationglj);
|
|
@@ -280,7 +294,7 @@ searchs.getGLJ = function(req,res){
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length){
|
|
|
var realRationName = data[0].DBName;
|
|
|
- db = mongoose.createConnection("localhost",realRationName);
|
|
|
+ db = mongoose.createConnection("192.168.1.184",realRationName,60666);
|
|
|
var GLJListModel =db.model("gljlists",Schemas.GLJListSchema);
|
|
|
GLJListModel.find({"GLJCode":GLJCode},function(err,data){
|
|
|
if(data.length)
|
|
@@ -304,7 +318,7 @@ searchs.getRationsBySectionID = function(req,res){
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length){
|
|
|
var realRationName = data[0].DBName;
|
|
|
- db = mongoose.createConnection("localhost",realRationName);
|
|
|
+ db = mongoose.createConnection("192.168.1.184",realRationName,60666);
|
|
|
var GLJListModel =db.model("rationitems",Schemas.RationItemsSchema);
|
|
|
GLJListModel.find({"SectionID":sectionID},function(err,data){
|
|
|
if(data.length)
|
|
@@ -320,6 +334,30 @@ searchs.getRationsBySectionID = function(req,res){
|
|
|
})
|
|
|
});
|
|
|
}
|
|
|
+searchs.getRationByCode = 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;
|
|
|
+ db = mongoose.createConnection("192.168.1.184",realRationName,60666);
|
|
|
+ var RationModel =db.model("rationitems",Schemas.RationItemsSchema);
|
|
|
+ RationModel.find({"RationCode":rationCode},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){
|
|
@@ -338,7 +376,7 @@ removes.deleteRationSection =function(req,res){
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length) {
|
|
|
var realRationName = data[0].DBName;
|
|
|
- db = mongoose.createConnection("localhost", realRationName);
|
|
|
+ db = mongoose.createConnection("192.168.1.184", realRationName,60666);
|
|
|
var RationTreeModel = db.model("rationtrees", Schemas.RationTreeSchema);
|
|
|
RationTreeModel.remove({"SectionID":sectionID},function(err){
|
|
|
if(err){callback(req,res,"删除错误",false);}
|
|
@@ -356,7 +394,7 @@ removes.deleteGLJItem = function(req,res){
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length) {
|
|
|
var realRationName = data[0].DBName;
|
|
|
- db = mongoose.createConnection("localhost", realRationName);
|
|
|
+ db = mongoose.createConnection("192.168.1.184", realRationName,60666);
|
|
|
var gljListModel = db.model("gljlists", Schemas.GLJListSchema);
|
|
|
gljListModel.remove({"GLJCode":gljItem},function(err){
|
|
|
if(err){callback(req,res,"删除错误",false);}
|
|
@@ -375,7 +413,7 @@ removes.deleteRation = function(req,res){
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length) {
|
|
|
var realRationName = data[0].DBName;
|
|
|
- db = mongoose.createConnection("localhost", realRationName);
|
|
|
+ db = mongoose.createConnection("192.168.1.184", realRationName,60666);
|
|
|
var rationModel = db.model("rationitems",Schemas.RationItemsSchema);
|
|
|
rationModel.remove({"RationCode":delvalue},function(err){
|
|
|
if(err) callback(req,res,"err",false)
|
|
@@ -399,7 +437,7 @@ removes.deleteRationGLJ = function(req,res){
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length) {
|
|
|
var realRationName = data[0].DBName;
|
|
|
- db = mongoose.createConnection("localhost", realRationName);
|
|
|
+ db = mongoose.createConnection("192.168.1.184", realRationName,60666);
|
|
|
var rationModel = db.model("rationgljs",Schemas.RationGLJSchema);
|
|
|
rationModel.remove({"GLJCode":delvalue},function(err){
|
|
|
if(err)
|
|
@@ -433,7 +471,7 @@ updates.updateGLJItem = function(req,res){
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length){
|
|
|
var realRationName = data[0].DBName;
|
|
|
- db = mongoose.createConnection("localhost",realRationName);
|
|
|
+ db = mongoose.createConnection("192.168.1.184",realRationName,60666);
|
|
|
|
|
|
var GLJListModel =db.model("gljlists",Schemas.GLJListSchema);
|
|
|
GLJListModel.update({"GLJCode":GLJCode},glj,function(err){
|
|
@@ -453,7 +491,7 @@ updates.updateRationItem = function(req,res){
|
|
|
LibMapModel.find({"DisplayName":DBName},function(err,data){
|
|
|
if(data.length){
|
|
|
var realRationName = data[0].DBName;
|
|
|
- db = mongoose.createConnection("localhost",realRationName);
|
|
|
+ db = mongoose.createConnection("192.168.1.184",realRationName,60666);
|
|
|
var RationModel =db.model("rationitems",Schemas.RationItemsSchema);
|
|
|
RationModel.update({"RationCode":rationCode},rationItem,function(err){
|
|
|
if(err) callback(req,res,"err",false)
|
|
@@ -465,18 +503,39 @@ updates.updateRationItem = function(req,res){
|
|
|
}
|
|
|
updates.updateRGLJAmount = function(req,res){
|
|
|
var DBName = req.body.rationName;
|
|
|
- var gljCode = req.body.GLJCode;
|
|
|
- var amount =JSON.parse(req.body.Amount);
|
|
|
+ var rationCode = req.body.RationCode;
|
|
|
+ var gljCdoe = req.body.GLJCode
|
|
|
+ var Amount = 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);
|
|
|
+ db = mongoose.createConnection("192.168.1.184",realRationName,60666);
|
|
|
var RationModel =db.model("rationgljs",Schemas.RationGLJSchema);
|
|
|
- RationModel.update({"GLJCode":gljCode},{$set:{"Amount":amount}},function(err){
|
|
|
+ RationModel.update({"RationCode":rationCode,"GLJCode":gljCdoe},{$set:{'Amount':Amount}},function(err){
|
|
|
+ if(err) callback(req,res,"err",false)
|
|
|
+ else callback(req,res,false,"ok");
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|
|
|
+updates.setRationBasePrice = function(req,res){
|
|
|
+ var DBName = req.body.rationName;
|
|
|
+ var rationCode = req.body.rationCode;
|
|
|
+ var basePrice = req.body.BasePrice;
|
|
|
+ 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("192.168.1.184",realRationName,60666);
|
|
|
+ var RationModel =db.model("rationitems",Schemas.RationItemsSchema);
|
|
|
+ RationModel.update({"RationCode":rationCode},{$set:{'BasePrice':basePrice}},function(err){
|
|
|
if(err) callback(req,res,"err",false)
|
|
|
else callback(req,res,false,"ok");
|
|
|
+
|
|
|
})
|
|
|
}
|
|
|
})
|