123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- /**
- * Created by Tony on 2017/4/21.
- */
- var mongoose = require("mongoose");
- var dbm = require("../../../config/db/db_manager");
- var chapterTreeDb = dbm.getCfgConnection("rationRepository")
- var async = require("async");
- var Schema = mongoose.Schema;
- var rationChapterTreeSchema = mongoose.Schema({//章节树 //生成唯一id改为sectionID 改成string
- rationRepId: Number,
- sectionId:Number,
- parentId:Number,
- nextSiblingId:Number,
- name:String
- });
- var rationChapterTreeModel = chapterTreeDb.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees")
- var repositoryMap = require('./repositoryMap');
- var rationChapterTreeDAO = function(){};
- rationChapterTreeDAO.prototype.getRationChapterTrees = function(repositoryName,callback){
- repositoryMap.getRealLibName(repositoryName, function(err, rst){
- rationChapterTreeModel.find({"rationRepId": rst[0].ID},function(err,data){
- if(data.length) callback(false,data);
- else if(err) callback("获取定额树错误!",false)
- else callback(false,false);
- })
- })
- }
- rationChapterTreeDAO.prototype.tempRationChapterTreeInsert = function(repositoryName,rationTempTree,callback){
- var db = dbm.getCfgConnection(repositoryName)
- 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(repositoryName,section,callback){
- var db = dbm.getCfgConnection(repositoryName);
- 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(repositoryName,sectionId,callback){
- var db = dbm.getCfgConnection(repositoryName);
- var rationChapterTreeModel = db.model("rationItems",rationChapterTreeSchema);
- rationChapterTreeModel.find({"sectionId": sectionId},[],function(err,data){
- })
- }
- module.exports = new rationChapterTreeDAO()
|