repositoryMap.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Created by Tony on 2017/4/24.
  3. * 重新构造,不适宜生成多个定额库db,还是得统一在一个表
  4. */
  5. var mongoose = require('mongoose');
  6. var dbm = require("../../../config/db/db_manager");
  7. //var stringUtil = require('../../../public/stringUtil');
  8. var rationLibdb = dbm.getCfgConnection("rationRepository");
  9. var Schema = mongoose.Schema;
  10. var RepositoryMapSchema = new Schema({
  11. "ID": Number,
  12. "dispName" : String,
  13. "appType" : String, //如:"建筑" / "公路"
  14. "localeType": String, //如 各个省份 / 部颁
  15. "descr" : String,
  16. "deleted": Boolean
  17. });
  18. var counter = require('../../../public/counter/counter');
  19. var rationRepository = rationLibdb.model("repositoryMap", RepositoryMapSchema, "repositoryMap");
  20. function createNewLibModel(rationLibObj){
  21. var rst = {};
  22. rst.dispName = rationLibObj.dispName;
  23. rst.appType = rationLibObj.appType?rationLibObj.appType:'construct';
  24. rst.localeType = rationLibObj.localeType?rationLibObj.localeType:'';
  25. rst.descr = rationLibObj.descr;
  26. rst.deleted = false;
  27. return rst;
  28. }
  29. rationRepositoryDao = function(){};
  30. rationRepositoryDao.prototype.getRealLibName = function(dispName,callback){
  31. if (callback) {
  32. rationRepository.find({"dispName": dispName}, function(err,data){
  33. if (err) {
  34. callback('Error', null);
  35. } else {
  36. callback(0, data);
  37. }
  38. });
  39. } else {
  40. var rst = rationRepository.find({"dispName": dispName}).exec();
  41. return rst;
  42. }
  43. };
  44. rationRepositoryDao.prototype.addRationRepository = function( rationLibObj,callback){
  45. counter.counterDAO.getIDAfterCount(counter.moduleName.rationMap, 1, function(err, result){
  46. var rMap = createNewLibModel(rationLibObj);
  47. rMap.ID = result.value.sequence_value;
  48. new rationRepository(rMap).save(function(err) {
  49. if (err) callback("Error", null)
  50. else
  51. callback(false, "ok");
  52. });
  53. });
  54. };
  55. rationRepositoryDao.prototype.getDisplayRationLibs = function(callback) {
  56. rationRepository.find({"deleted": false}, function(err, data){
  57. if (err) {
  58. callback( 'Error', null);
  59. } else {
  60. callback( false, data);
  61. }
  62. });
  63. };
  64. rationRepositoryDao.prototype.updateName = function(orgName,newName,callback){
  65. rationRepository.find({"dispName":newName, "deleted": false}, function(err, data){
  66. if (data.length == 0) {
  67. rationRepository.update({dispName:orgName},{$set:{dispName:newName}},function(err){
  68. if(err) callback("err",false);
  69. else callback(false,"ok")
  70. })
  71. } else
  72. callback("不可重名!",false);
  73. });
  74. }
  75. rationRepositoryDao.prototype.deleteRationLib = function(rationName,callback){
  76. rationRepository.find({"dispName":rationName, "deleted": false}, function(err, data){
  77. if (data.length == 1) {
  78. rationRepository.update({dispName:rationName},{$set:{deleted: true}},function(err){
  79. if(err) callback("err",false);
  80. else callback(false,"ok")
  81. })
  82. } else
  83. callback("删除失败!",false);
  84. });
  85. }
  86. module.exports = new rationRepositoryDao();