rationChapterTree.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Created by Tony on 2017/4/21.
  3. */
  4. var mongoose = require("mongoose");
  5. var dbm = require("../../../config/db/db_manager");
  6. var async = require("async");
  7. var Schema = mongoose.Schema;
  8. var rationChapterTreeSchema = mongoose.Schema({//章节树 //生成唯一id改为sectionID 改成string
  9. sectionId:Number,
  10. parentId:Number,
  11. nextSiblingId:Number,
  12. name:String
  13. });
  14. var rationChapterTreeDAO = function(){};
  15. rationChapterTreeDAO.prototype.getRationChapterTrees = function(repositoryDbName,callback){
  16. var db = dbm.getCfgConnection(repositoryDbName)
  17. var rationChapterTreeModel = db.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees")
  18. rationChapterTreeModel.find({},function(err,data){
  19. if(data.length) callback(false,data);
  20. else if(err) callback("获取定额树错误!",false)
  21. else callback(false,false);
  22. })
  23. }
  24. rationChapterTreeDAO.prototype.tempRationChapterTreeInsert = function(repositoryDbName,rationTempTree,callback){
  25. var db = dbm.getCfgConnection(repositoryDbName)
  26. var rationChapterTreeModel = db.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees")
  27. rationChapterTreeModel.collection.insert(rationTempTree,function(err,data){
  28. if(err) callback("插入定额模板错误",false)
  29. else callback(false,"ok")
  30. })
  31. }
  32. rationChapterTreeDAO.prototype.sectionUpsert = function(repositoryDbName,section,callback){
  33. var db = dbm.getCfgConnection(repositoryDbName);
  34. var rationChapterTreeModel = db.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees");
  35. rationChapterTreeModel.find({"sectionId": section.sectionId},function(err,data){
  36. if(data.length){
  37. rationChapterTreeModel.update({'sectionId':section.sectionId},section,function(err,data){
  38. if(err){
  39. callback(" ",false);
  40. }else
  41. callback(false,"ok");
  42. });
  43. }else{
  44. var N = new rationChapterTreeModel(section).save(function(err){
  45. if(err){
  46. callback(" ",false);
  47. }else
  48. callback(false,"success!");
  49. })
  50. }
  51. })
  52. }
  53. //待 ration模块完成
  54. rationChapterTreeDAO.prototype.deleteSection= function(repositoryDbName,sectionId,callback){
  55. var db = dbm.getCfgConnection(repositoryDbName);
  56. var rationChapterTreeModel = db.model("rationItems",rationChapterTreeSchema);
  57. rationChapterTreeModel.find({"sectionId": sectionId},[],function(err,data){
  58. })
  59. }
  60. module.exports = new rationChapterTreeDAO()