1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- /**
- * Created by Tony on 2017/4/24.
- * 重新构造,不适宜生成多个定额库db,还是得统一在一个表
- */
- var mongoose = require('mongoose');
- var dbm = require("../../../config/db/db_manager");
- //var stringUtil = require('../../../public/stringUtil');
- var rationLibdb = dbm.getCfgConnection("rationRepository");
- var Schema = mongoose.Schema;
- var RepositoryMapSchema = new Schema({
- "ID": Number,
- "dispName" : String,
- "appType" : String, //如:"建筑" / "公路"
- "localeType": String, //如 各个省份 / 部颁
- "descr" : String,
- "deleted": Boolean
- });
- var counter = require('../../../public/counter/counter');
- var rationRepository = rationLibdb.model("repositoryMap", RepositoryMapSchema, "repositoryMap");
- function createNewLibModel(rationLibObj){
- var rst = {};
- rst.dispName = rationLibObj.dispName;
- rst.appType = rationLibObj.appType?rationLibObj.appType:'construct';
- rst.localeType = rationLibObj.localeType?rationLibObj.localeType:'';
- rst.descr = rationLibObj.descr;
- rst.deleted = false;
- return rst;
- }
- rationRepositoryDao = function(){};
- rationRepositoryDao.prototype.getRealLibName = function(dispName,callback){
- if (callback) {
- rationRepository.find({"dispName": dispName}, function(err,data){
- if (err) {
- callback('Error', null);
- } else {
- callback(0, data);
- }
- });
- } else {
- var rst = rationRepository.find({"dispName": dispName}).exec();
- return rst;
- }
- };
- rationRepositoryDao.prototype.addRationRepository = function( rationLibObj,callback){
- counter.counterDAO.getIDAfterCount(counter.moduleName.rationMap, 1, function(err, result){
- var rMap = createNewLibModel(rationLibObj);
- rMap.ID = result.value.sequence_value;
- new rationRepository(rMap).save(function(err) {
- if (err) callback("Error", null)
- else
- callback(false, "ok");
- });
- });
- };
- rationRepositoryDao.prototype.getDisplayRationLibs = function(callback) {
- rationRepository.find({"deleted": false}, function(err, data){
- if (err) {
- callback( 'Error', null);
- } else {
- callback( false, data);
- }
- });
- };
- rationRepositoryDao.prototype.updateName = function(orgName,newName,callback){
- rationRepository.find({"dispName":newName, "deleted": false}, function(err, data){
- if (data.length == 0) {
- rationRepository.update({dispName:orgName},{$set:{dispName:newName}},function(err){
- if(err) callback("err",false);
- else callback(false,"ok")
- })
- } else
- callback("不可重名!",false);
- });
- }
- rationRepositoryDao.prototype.deleteRationLib = function(rationName,callback){
- rationRepository.find({"dispName":rationName, "deleted": false}, function(err, data){
- if (data.length == 1) {
- rationRepository.update({dispName:rationName},{$set:{deleted: true}},function(err){
- if(err) callback("err",false);
- else callback(false,"ok")
- })
- } else
- callback("删除失败!",false);
- });
- }
- module.exports = new rationRepositoryDao();
|