/** * Created by Tony on 2017/4/21. */ var mongoose = require("mongoose"); var dbm = require("../../../config/db/db_manager"); var async = require("async"); var Schema = mongoose.Schema; var rationChapterTreeSchema = mongoose.Schema({//章节树 //生成唯一id改为sectionID 改成string sectionId:Number, parentId:Number, nextSiblingId:Number, name:String }); var rationChapterTreeDAO = function(){}; rationChapterTreeDAO.prototype.getRationChapterTrees = function(repositoryDbName,callback){ var db = dbm.getCfgConnection(repositoryDbName) var rationChapterTreeModel = db.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees") rationChapterTreeModel.find({},function(err,data){ if(data.length) callback(false,data); else if(err) callback("获取定额树错误!",false) else callback(false,false); }) } rationChapterTreeDAO.prototype.tempRationChapterTreeInsert = function(repositoryDbName,rationTempTree,callback){ var db = dbm.getCfgConnection(repositoryDbName) var rationChapterTreeModel = db.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees") rationChapterTreeModel.collection.insert(rationTempTree,function(err,data){ if(err) callback("插入定额模板错误",false) else callback(false,"ok") }) } rationChapterTreeDAO.prototype.sectionUpsert = function(repositoryDbName,section,callback){ var db = dbm.getCfgConnection(repositoryDbName); var rationChapterTreeModel = db.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees"); rationChapterTreeModel.find({"sectionId": section.sectionId},function(err,data){ if(data.length){ rationChapterTreeModel.update({'sectionId':section.sectionId},section,function(err,data){ if(err){ callback(" ",false); }else callback(false,"ok"); }); }else{ var N = new rationChapterTreeModel(section).save(function(err){ if(err){ callback(" ",false); }else callback(false,"success!"); }) } }) } //待 ration模块完成 rationChapterTreeDAO.prototype.deleteSection= function(repositoryDbName,sectionId,callback){ var db = dbm.getCfgConnection(repositoryDbName); var rationChapterTreeModel = db.model("rationItems",rationChapterTreeSchema); rationChapterTreeModel.find({"sectionId": sectionId},[],function(err,data){ }) } module.exports = new rationChapterTreeDAO()