rationChapterTree.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. ID:Number,
  12. ParentID:Number,
  13. NextSiblingID:Number,
  14. dispName: String
  15. });
  16. var rationChapterTreeModel = chapterTreeDb.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees")
  17. var repositoryMap = require('./repositoryMap');
  18. var counter = require('../../../public/counter/counter');
  19. var rationChapterTreeDAO = function(){};
  20. rationChapterTreeDAO.prototype.getRationChapterTrees = function(repositoryName,callback){
  21. repositoryMap.getRealLibName(repositoryName, function(err, rst){
  22. rationChapterTreeModel.find({"rationRepId": rst[0].ID},function(err,data){
  23. if(data.length) callback(false,data);
  24. else if(err) callback("获取定额树错误!",false)
  25. else callback(false,false);
  26. })
  27. })
  28. }
  29. rationChapterTreeDAO.prototype.createNewNode = function(repositoryName,nodeData,callback){
  30. repositoryMap.getRealLibName(repositoryName, function(err, rst){
  31. //
  32. })
  33. },
  34. rationChapterTreeDAO.prototype.tempRationChapterTreeInsert = function(repositoryName,rationTempTree,callback){
  35. var db = dbm.getCfgConnection(repositoryName)
  36. var rationChapterTreeModel = db.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees")
  37. rationChapterTreeModel.collection.insert(rationTempTree,function(err,data){
  38. if(err) callback("插入定额模板错误",false)
  39. else callback(false,"ok")
  40. })
  41. }
  42. rationChapterTreeDAO.prototype.sectionUpsert = function(repositoryName,section,callback){
  43. var db = dbm.getCfgConnection(repositoryName);
  44. var rationChapterTreeModel = db.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees");
  45. rationChapterTreeModel.find({"sectionId": section.sectionId},function(err,data){
  46. if(data.length){
  47. rationChapterTreeModel.update({'sectionId':section.sectionId},section,function(err,data){
  48. if(err){
  49. callback(" ",false);
  50. }else
  51. callback(false,"ok");
  52. });
  53. }else{
  54. var N = new rationChapterTreeModel(section).save(function(err){
  55. if(err){
  56. callback(" ",false);
  57. }else
  58. callback(false,"success!");
  59. })
  60. }
  61. })
  62. }
  63. //待 ration模块完成
  64. rationChapterTreeDAO.prototype.deleteSection= function(repositoryName,sectionId,callback){
  65. var db = dbm.getCfgConnection(repositoryName);
  66. var rationChapterTreeModel = db.model("rationItems",rationChapterTreeSchema);
  67. rationChapterTreeModel.find({"sectionId": sectionId},[],function(err,data){
  68. })
  69. }
  70. module.exports = new rationChapterTreeDAO()