123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- /**
- * Created by Tony on 2017/4/21.
- */
- var mongoose = require("mongoose");
- var dbm = require("../../../config/db/db_manager");
- var chapterTreeDb = dbm.getCfgConnection("scConstruct");
- var async = require("async");
- var Schema = mongoose.Schema;
- var rationChapterTreeSchema = new Schema({//章节树 //生成唯一id改为sectionID 改成string
- rationRepId: Number,
- ID:Number,
- ParentID:Number,
- NextSiblingID:Number,
- name: String,
- explanation: String,//说明
- ruleText: String,//计算规则,
- jobContentSituation: String,//工作内容适用情况,ALL适用本项全部定额,PARTIAL适用本项部分定额
- isDeleted: Boolean
- });
- var rationChapterTreeModel = chapterTreeDb.model("std_ration_lib_ration_chapter_trees", rationChapterTreeSchema, "std_ration_lib_ration_chapter_trees");
- var counter = require('../../../public/counter/counter');
- var rationChapterTreeDAO = function(){};
- rationChapterTreeDAO.prototype.getRationChapterTree = function(rationLibId,callback){
- rationChapterTreeModel.find({"rationRepId": rationLibId, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){
- if(data.length) callback(false,data);
- else if(err) callback("获取定额树错误!",false)
- else callback(false,false);
- })
- }
- rationChapterTreeDAO.prototype.getRationChapterTreeByRepId = function(repId,callback){
- rationChapterTreeModel.find({"rationRepId": repId, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){
- if(data.length) callback(false,data);
- else if(err) callback("获取定额树错误!",false)
- else callback(false,false);
- })
- }
- rationChapterTreeDAO.prototype.createNewNode = function(libId, lastNodeId, nodeData,callback){
- counter.counterDAO.getIDAfterCount(counter.moduleName.rationTree, 1, function(err, result){
- nodeData.rationRepId = libId;
- nodeData.ID = result.value.sequence_value;
- var node = new rationChapterTreeModel(nodeData);
- node.save(function (err, result) {
- if (err) {
- callback("章节树ID错误!", false);
- } else {
- if (lastNodeId > 0) {
- rationChapterTreeModel.update({ID: lastNodeId}, {"NextSiblingID": nodeData.ID}, function(err, rst){
- if (err) {
- callback("章节树ID错误!", false);
- } else {
- callback(false, result);
- }
- });
- } else callback(false, result);
- }
- });
- });
- },
- rationChapterTreeDAO.prototype.removeNodes = function(nodeIds, preNodeId, preNodeNextId, callback){
- var functions = [];
- if (preNodeId != -1) {
- functions.push((function(nodeId, nextId) {
- return function(cb) {
- rationChapterTreeModel.update({ID: nodeId}, {"NextSiblingID": nextId}, cb);
- };
- })(preNodeId, preNodeNextId));
- }
- for (var i=0; i < nodeIds.length; i++) {
- functions.push((function(nodeId) {
- return function(cb) {
- rationChapterTreeModel.update({ID: nodeId}, {"isDeleted": true}, cb);
- };
- })(nodeIds[i]));
- }
- async.parallel(functions, function(err, results) {
- callback(err, results);
- });
- }
- rationChapterTreeDAO.prototype.updateNodes = function(nodes,callback){
- var functions = [];
- for (var i=0; i < nodes.length; i++) {
- //var md = new rationChapterTreeModel(nodes[i]);
- //md.isNew = false;
- functions.push((function(doc) {
- return function(cb) {
- rationChapterTreeModel.update({ID: doc.ID}, doc, cb);
- };
- })(nodes[i]));
- }
- async.parallel(functions, function(err, results) {
- callback(err, results);
- });
- };
- module.exports = new rationChapterTreeDAO()
|