rationTree.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Created by Syusuke on 2017/3/20.
  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 rationTreeSchema = mongoose.Schema({//章节树 //生成唯一id改为sectionID 改成string
  9. sectionId:Number,
  10. parentId:Number,
  11. nextSiblingId:Number,
  12. name:String
  13. });
  14. var rationTreeDAO = function(){};
  15. rationTreeDAO.prototype.getRationTrees = function(Libname,callback){
  16. var db = dbm.getCfgConnection(Libname)
  17. var rationTreeModel = db.model("rationtrees",rationTreeSchema)
  18. rationTreeModel.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. rationTreeDAO.prototype.tempRationTreeInsert = function(Libname,rationTempTree,callback){
  25. var db = dbm.getCfgConnection(Libname)
  26. var rationTreeModel = db.model("rationtrees",rationTreeSchema)
  27. rationTreeModel.collection.insert(rationTempTree,function(err,data){
  28. if(err) callback("插入定额模板错误",false)
  29. else callback(false,"ok")
  30. })
  31. }
  32. rationTreeDAO.prototype.sectionUpsert = function(Libname,section,callback){
  33. var db = dbm.getCfgConnection(Libname);
  34. var rationTreeModel = db.model("rationtrees",rationTreeSchema);
  35. rationTreeModel.find({"sectionId": section.sectionId},function(err,data){
  36. if(data.length){
  37. rationTreeModel.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 rationTreeModel(section).save(function(err){
  45. if(err){
  46. callback(" ",false);
  47. }else
  48. callback(false,"success!");
  49. })
  50. }
  51. })
  52. }
  53. //待 ration模块完成
  54. rationTreeDAO.prototype.deleteSection= function(Libname,sectionId,callback){
  55. var db = dbm.getCfgConnection(Libname);
  56. var rationTreeModel = db.model("rationItems",rationTreeSchema);
  57. rationTreeModel.find({"sectionId": sectionId},[],function(err,data){
  58. })
  59. }
  60. module.exports = new rationTreeDAO()