rationChapterTree.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. name: 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. var promise = repositoryMap.getRealLibName(repositoryName), libId;
  31. if (promise) {
  32. promise.then(function(rst){
  33. libId = rst[0].ID;
  34. return counter.counterDAO.getIDAfterCount(counter.moduleName.rationTree, 1, function(err, result){
  35. nodeData.rationRepId = libId;
  36. nodeData.ID = result.value.sequence_value;
  37. var node = new rationChapterTreeModel(nodeData);
  38. node.save(function (err, result) {
  39. if (err) {
  40. callback("章节树ID错误!", false);
  41. } else {
  42. callback(false, result);
  43. }
  44. });
  45. });
  46. });
  47. } else {
  48. callback("定额库选择错误!", false);
  49. }
  50. },
  51. rationChapterTreeDAO.prototype.tempRationChapterTreeInsert = function(repositoryName,rationTempTree,callback){
  52. var db = dbm.getCfgConnection(repositoryName)
  53. var rationChapterTreeModel = db.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees")
  54. rationChapterTreeModel.collection.insert(rationTempTree,function(err,data){
  55. if(err) callback("插入定额模板错误",false)
  56. else callback(false,"ok")
  57. })
  58. }
  59. rationChapterTreeDAO.prototype.sectionUpsert = function(repositoryName,section,callback){
  60. var db = dbm.getCfgConnection(repositoryName);
  61. var rationChapterTreeModel = db.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees");
  62. rationChapterTreeModel.find({"sectionId": section.sectionId},function(err,data){
  63. if(data.length){
  64. rationChapterTreeModel.update({'sectionId':section.sectionId},section,function(err,data){
  65. if(err){
  66. callback(" ",false);
  67. }else
  68. callback(false,"ok");
  69. });
  70. }else{
  71. var N = new rationChapterTreeModel(section).save(function(err){
  72. if(err){
  73. callback(" ",false);
  74. }else
  75. callback(false,"success!");
  76. })
  77. }
  78. })
  79. }
  80. //待 ration模块完成
  81. rationChapterTreeDAO.prototype.deleteSection= function(repositoryName,sectionId,callback){
  82. var db = dbm.getCfgConnection(repositoryName);
  83. var rationChapterTreeModel = db.model("rationItems",rationChapterTreeSchema);
  84. rationChapterTreeModel.find({"sectionId": sectionId},[],function(err,data){
  85. })
  86. }
  87. module.exports = new rationChapterTreeDAO()