| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 | /** * Created by Tony on 2017/3/21. */var mongoose = require('mongoose');var dbm = require("../../config/db/db_manager");var projectdb = dbm.getCfgConnection("scConstruct");var Schema = mongoose.Schema;var counterSchema = new Schema({    _id: String,    sequence_value: Number});counterSchema.statics.findAndModify = function (query, sort, doc, options, callback) {    return this.collection.findAndModify(query, sort, doc, options, callback);};var counterModel = projectdb.model("counters", counterSchema);// All counter Must predefine in DBconst COUNTER_MODULE_NAME = {    project: 'projects',    user: 'users',    bills: 'bills',    rations: 'rations',    GLJ: 'glj',    rationMap: 'rationMaps',    rationTree: 'rationChapterTrees',    report: 'rptTemplates',    fee: 'fees',    unitPriceFile: 'unitPriceFile',    unitPriceGLJ: 'unitPriceGLJ',    template_bills: 'temp_bills',    stdGljLib: 'stdGljLib',    billsLib: 'billsLib',    billsLib_jobs: 'billsLib_jobs',    billsLib_items: 'billsLib_items',    coeList: 'coeList'}/*const PROJECT_COUNTER = 'projects', USER_COUNTER = 'users', BILL_COUNTER = 'bills', RATION_COUNTER = 'rations',    REPORT_COUNTER = 'rptTemplates', FEE_COUNTER = 'fees'*/var counterDAO = function(){};/* * callback = function (err, result) { *     result.value.sequence_value Ϊ�ĺ��id * } */counterDAO.prototype.getIDAfterCount = function(moduleName, stepCount, callback) {    var sc = stepCount;    if (isNaN(stepCount) || (stepCount < 0)) {        sc = 1;    } else if (!(/^-?\d+$/.test(stepCount))) {        sc = Math.round(stepCount + 0.5);    }    counterModel.findAndModify({_id: moduleName}, [], { $inc: { sequence_value: sc } }, {'new':true}, callback);}counterDAO.prototype.getCurrentID = function(moduleName, callback) {    if (callback) {        counterModel.findOne({_id: moduleName}).exec()        .then(function(result, err) {            if (callback) {                callback(result, err);            }        }        );        return null;    } else {        var rst = counterModel.findOne({_id: moduleName}).exec() ;        return rst;    }}module.exports = {    counterDAO: new counterDAO(),    moduleName: COUNTER_MODULE_NAME};
 |