rationChapterTree.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 chapterTreeDb = dbm.getCfgConnection("rationRepository")
  7. var async = require("async");
  8. var Schema = mongoose.Schema;
  9. var rationChapterTreeSchema = mongoose.Schema({//章节树 //生成唯一id改为sectionID 改成string
  10. rationRepId: Number,
  11. sectionId:Number,
  12. parentId:Number,
  13. nextSiblingId:Number,
  14. name:String
  15. });
  16. var rationChapterTreeModel = chapterTreeDb.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees")
  17. var repositoryMap = require('./repositoryMap');
  18. var rationChapterTreeDAO = function(){};
  19. rationChapterTreeDAO.prototype.getRationChapterTrees = function(repositoryName,callback){
  20. repositoryMap.getRealLibName(repositoryName, function(err, rst){
  21. rationChapterTreeModel.find({"rationRepId": rst[0].ID},function(err,data){
  22. if(data.length) callback(false,data);
  23. else if(err) callback("获取定额树错误!",false)
  24. else callback(false,false);
  25. })
  26. })
  27. }
  28. rationChapterTreeDAO.prototype.tempRationChapterTreeInsert = function(repositoryName,rationTempTree,callback){
  29. var db = dbm.getCfgConnection(repositoryName)
  30. var rationChapterTreeModel = db.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees")
  31. rationChapterTreeModel.collection.insert(rationTempTree,function(err,data){
  32. if(err) callback("插入定额模板错误",false)
  33. else callback(false,"ok")
  34. })
  35. }
  36. rationChapterTreeDAO.prototype.sectionUpsert = function(repositoryName,section,callback){
  37. var db = dbm.getCfgConnection(repositoryName);
  38. var rationChapterTreeModel = db.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees");
  39. rationChapterTreeModel.find({"sectionId": section.sectionId},function(err,data){
  40. if(data.length){
  41. rationChapterTreeModel.update({'sectionId':section.sectionId},section,function(err,data){
  42. if(err){
  43. callback(" ",false);
  44. }else
  45. callback(false,"ok");
  46. });
  47. }else{
  48. var N = new rationChapterTreeModel(section).save(function(err){
  49. if(err){
  50. callback(" ",false);
  51. }else
  52. callback(false,"success!");
  53. })
  54. }
  55. })
  56. }
  57. //待 ration模块完成
  58. rationChapterTreeDAO.prototype.deleteSection= function(repositoryName,sectionId,callback){
  59. var db = dbm.getCfgConnection(repositoryName);
  60. var rationChapterTreeModel = db.model("rationItems",rationChapterTreeSchema);
  61. rationChapterTreeModel.find({"sectionId": sectionId},[],function(err,data){
  62. })
  63. }
  64. module.exports = new rationChapterTreeDAO()