ration_section_tree.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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("scConstruct");
  7. var async = require("async");
  8. var Schema = mongoose.Schema;
  9. var rationChapterTreeSchema = new Schema({//章节树 //生成唯一id改为sectionID 改成string
  10. rationRepId: Number,
  11. ID:Number,
  12. ParentID:Number,
  13. NextSiblingID:Number,
  14. name: String,
  15. explanation: String,//说明
  16. ruleText: String,//计算规则,
  17. jobContentSituation: String,//工作内容适用情况,ALL适用本项全部定额,PARTIAL适用本项部分定额
  18. isDeleted: Boolean
  19. });
  20. var rationChapterTreeModel = chapterTreeDb.model("std_ration_lib_ration_chapter_trees", rationChapterTreeSchema, "std_ration_lib_ration_chapter_trees");
  21. var counter = require('../../../public/counter/counter');
  22. var rationChapterTreeDAO = function(){};
  23. rationChapterTreeDAO.prototype.getRationChapterTree = function(rationLibId,callback){
  24. rationChapterTreeModel.find({"rationRepId": rationLibId, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){
  25. if(data.length) callback(false,data);
  26. else if(err) callback("获取定额树错误!",false)
  27. else callback(false,false);
  28. })
  29. }
  30. rationChapterTreeDAO.prototype.getRationChapterTreeByRepId = function(repId,callback){
  31. rationChapterTreeModel.find({"rationRepId": repId, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){
  32. if(data.length) callback(false,data);
  33. else if(err) callback("获取定额树错误!",false)
  34. else callback(false,false);
  35. })
  36. }
  37. rationChapterTreeDAO.prototype.createNewNode = function(libId, lastNodeId, nodeData,callback){
  38. counter.counterDAO.getIDAfterCount(counter.moduleName.rationTree, 1, function(err, result){
  39. nodeData.rationRepId = libId;
  40. nodeData.ID = result.value.sequence_value;
  41. var node = new rationChapterTreeModel(nodeData);
  42. node.save(function (err, result) {
  43. if (err) {
  44. callback("章节树ID错误!", false);
  45. } else {
  46. if (lastNodeId > 0) {
  47. rationChapterTreeModel.update({ID: lastNodeId}, {"NextSiblingID": nodeData.ID}, function(err, rst){
  48. if (err) {
  49. callback("章节树ID错误!", false);
  50. } else {
  51. callback(false, result);
  52. }
  53. });
  54. } else callback(false, result);
  55. }
  56. });
  57. });
  58. },
  59. rationChapterTreeDAO.prototype.removeNodes = function(nodeIds, preNodeId, preNodeNextId, callback){
  60. var functions = [];
  61. if (preNodeId != -1) {
  62. functions.push((function(nodeId, nextId) {
  63. return function(cb) {
  64. rationChapterTreeModel.update({ID: nodeId}, {"NextSiblingID": nextId}, cb);
  65. };
  66. })(preNodeId, preNodeNextId));
  67. }
  68. for (var i=0; i < nodeIds.length; i++) {
  69. functions.push((function(nodeId) {
  70. return function(cb) {
  71. rationChapterTreeModel.update({ID: nodeId}, {"isDeleted": true}, cb);
  72. };
  73. })(nodeIds[i]));
  74. }
  75. async.parallel(functions, function(err, results) {
  76. callback(err, results);
  77. });
  78. }
  79. rationChapterTreeDAO.prototype.updateNodes = function(nodes,callback){
  80. var functions = [];
  81. for (var i=0; i < nodes.length; i++) {
  82. //var md = new rationChapterTreeModel(nodes[i]);
  83. //md.isNew = false;
  84. functions.push((function(doc) {
  85. return function(cb) {
  86. rationChapterTreeModel.update({ID: doc.ID}, doc, cb);
  87. };
  88. })(nodes[i]));
  89. }
  90. async.parallel(functions, function(err, results) {
  91. callback(err, results);
  92. });
  93. };
  94. module.exports = new rationChapterTreeDAO()