/** * Created by Syusuke on 2017/3/20. */ var mongoose = require("mongoose"); var dbm = require("../../../config/db/db_manager"); var async = require("async"); var Schema = mongoose.Schema; var RationTreeSchema = mongoose.Schema({//章节树 //生成唯一id改为sectionid 改成string SectionID:Number, ParentID:Number, NextSiblingID:Number, Name:String }); var RationTreeDAO = function(){}; RationTreeDAO.prototype.getRationTrees = function(LibName,callback){ var db = dbm.getCfgConnection(LibName) var RationTreeModel = db.model("rationtrees",RationTreeSchema) RationTreeModel.find({},function(err,data){ if(data.length) callback(false,data); else if(err) callback("获取定额树错误!",false) else callback(false,false); }) } RationTreeDAO.prototype.tempRationTreeInsert = function(LibName,rationTempTree,callback){ var db = dbm.getCfgConnection(LibName) var RationTreeModel = db.model("rationtrees",RationTreeSchema) RationTreeModel.collection.insert(rationTempTree,function(err,data){ if(err) callback("插入定额模板错误",false) else callback(false,"ok") }) } RationTreeDAO.prototype.sectionUpsert = function(LibName,section,callback){ var db = dbm.getCfgConnection(LibName); var RationTreeModel = db.model("rationtrees",RationTreeSchema); RationTreeModel.find({"SectionID": section.SectionID},function(err,data){ if(data.length){ RationTreeModel.update({'SectionID':section.SectionID},section,function(err,data){ if(err){ callback(" ",false); }else callback(false,"ok"); }); }else{ var N = new RationTreeModel(section).save(function(err){ if(err){ callback(" ",false); }else callback(false,"success!"); }) } }) } //待 ration模块完成 RationTreeDAO.prototype.deleteSection= function(LibName,sectionID,callback){ var db = dbm.getCfgConnection(LibName); var RationTreeModel = db.model("rationItems",RationTreeSchema); RationTreeModel.find({"SectionID": sectionID},[],function(err,data){ }) } module.exports = new RationTreeDAO()