ration_section_tree.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. annotationSituation: String,//附注适用情况,ALL适用本项全部定额,PARTIAL适用本项部分定额
  19. isDeleted: Boolean
  20. });
  21. var rationChapterTreeModel = chapterTreeDb.model("std_ration_lib_ration_chapter_trees", rationChapterTreeSchema, "std_ration_lib_ration_chapter_trees");
  22. var counter = require('../../../public/counter/counter');
  23. var rationChapterTreeDAO = function(){};
  24. rationChapterTreeDAO.prototype.getRationChapterTree = function(rationLibId,callback){
  25. rationChapterTreeModel.find({"rationRepId": rationLibId, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){
  26. if(data.length) callback(false,data);
  27. else if(err) callback("获取定额树错误!",false)
  28. else callback(false,false);
  29. })
  30. }
  31. rationChapterTreeDAO.prototype.getRationChapterTreeByRepId = function(repId,callback){
  32. rationChapterTreeModel.find({"rationRepId": repId, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){
  33. if(data.length) callback(false,data);
  34. else if(err) callback("获取定额树错误!",false)
  35. else callback(false,false);
  36. })
  37. }
  38. rationChapterTreeDAO.prototype.createNewNode = function(libId, lastNodeId, nodeData,callback){
  39. counter.counterDAO.getIDAfterCount(counter.moduleName.rationTree, 1, function(err, result){
  40. nodeData.rationRepId = libId;
  41. nodeData.ID = result.value.sequence_value;
  42. var node = new rationChapterTreeModel(nodeData);
  43. node.save(function (err, result) {
  44. if (err) {
  45. callback("章节树ID错误!", false);
  46. } else {
  47. if (lastNodeId > 0) {
  48. rationChapterTreeModel.update({ID: lastNodeId}, {"NextSiblingID": nodeData.ID}, function(err, rst){
  49. if (err) {
  50. callback("章节树ID错误!", false);
  51. } else {
  52. callback(false, result);
  53. }
  54. });
  55. } else callback(false, result);
  56. }
  57. });
  58. });
  59. },
  60. rationChapterTreeDAO.prototype.removeNodes = function(nodeIds, preNodeId, preNodeNextId, callback){
  61. var functions = [];
  62. if (preNodeId != -1) {
  63. functions.push((function(nodeId, nextId) {
  64. return function(cb) {
  65. rationChapterTreeModel.update({ID: nodeId}, {"NextSiblingID": nextId}, cb);
  66. };
  67. })(preNodeId, preNodeNextId));
  68. }
  69. for (var i=0; i < nodeIds.length; i++) {
  70. functions.push((function(nodeId) {
  71. return function(cb) {
  72. rationChapterTreeModel.update({ID: nodeId}, {"isDeleted": true}, cb);
  73. };
  74. })(nodeIds[i]));
  75. }
  76. async.parallel(functions, function(err, results) {
  77. callback(err, results);
  78. });
  79. }
  80. rationChapterTreeDAO.prototype.updateNodes = function(nodes,callback){
  81. var functions = [];
  82. for (var i=0; i < nodes.length; i++) {
  83. //var md = new rationChapterTreeModel(nodes[i]);
  84. //md.isNew = false;
  85. functions.push((function(doc) {
  86. return function(cb) {
  87. rationChapterTreeModel.update({ID: doc.ID}, doc, cb);
  88. };
  89. })(nodes[i]));
  90. }
  91. async.parallel(functions, function(err, results) {
  92. callback(err, results);
  93. });
  94. };
  95. rationChapterTreeDAO.prototype.getRationChapter = function (repId, chapterID, callback) {
  96. if (callback) {
  97. rationChapterTreeModel.findOne({rationRepId: repId, ID: chapterID}, '-_id').exec()
  98. .then(function (result, err) {
  99. if (err) {
  100. callback(1, '找不到定额章节' , null);
  101. } else {
  102. callback(0, '', result);
  103. }
  104. });
  105. return null;
  106. } else {
  107. return rationChapterTreeModel.findOne({rationRepId: repId, ID: chapterID}, '-_id').exec();
  108. }
  109. }
  110. module.exports = new rationChapterTreeDAO()