12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- /**
- * 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()
|