123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- /**
- * 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,
- ID:Number,
- ParentID:Number,
- NextSiblingID:Number,
- name: String
- });
- var rationChapterTreeModel = chapterTreeDb.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees")
- var repositoryMap = require('./repositoryMap');
- var counter = require('../../../public/counter/counter');
- 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.createNewNode = function(repositoryName,nodeData,callback){
- var promise = repositoryMap.getRealLibName(repositoryName), libId;
- if (promise) {
- promise.then(function(rst){
- libId = rst[0].ID;
- return counter.counterDAO.getIDAfterCount(counter.moduleName.rationTree, 1, function(err, result){
- nodeData.rationRepId = libId;
- nodeData.ID = result.value.sequence_value;
- var node = new rationChapterTreeModel(nodeData);
- node.save(function (err, result) {
- if (err) {
- callback("章节树ID错误!", false);
- } else {
- callback(false, result);
- }
- });
- });
- });
- } else {
- callback("定额库选择错误!", 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()
|