repositoryMap.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. rationRepository.find({"dispName": dispName}, function(err,data){
  32. if (err) {
  33. callback('Error', null);
  34. } else {
  35. callback(0, data);
  36. }
  37. });
  38. };
  39. rationRepositoryDao.prototype.addRationRepository = function( rationLibObj,callback){
  40. counter.counterDAO.getIDAfterCount(counter.moduleName.rationMap, 1, function(err, result){
  41. var rMap = createNewLibModel(rationLibObj);
  42. rMap.ID = result.value.sequence_value;
  43. new rationRepository(rMap).save(function(err) {
  44. if (err) callback("Error", null)
  45. else
  46. callback(false, "ok");
  47. });
  48. });
  49. };
  50. rationRepositoryDao.prototype.getDisplayRationLibs = function(callback) {
  51. rationRepository.find({"deleted": false}, function(err, data){
  52. if (err) {
  53. callback( 'Error', null);
  54. } else {
  55. callback( false, data);
  56. }
  57. });
  58. };
  59. rationRepositoryDao.prototype.updateName = function(orgName,newName,callback){
  60. rationRepository.find({"dispName":newName, "deleted": false}, function(err, data){
  61. if (data.length == 0) {
  62. rationRepository.update({dispName:orgName},{$set:{dispName:newName}},function(err){
  63. if(err) callback("err",false);
  64. else callback(false,"ok")
  65. })
  66. } else
  67. callback("不可重名!",false);
  68. });
  69. }
  70. rationRepositoryDao.prototype.deleteRationLib = function(rationName,callback){
  71. rationRepository.find({"dispName":rationName, "deleted": false}, function(err, data){
  72. if (data.length == 1) {
  73. rationRepository.update({dispName:rationName},{$set:{deleted: true}},function(err){
  74. if(err) callback("err",false);
  75. else callback(false,"ok")
  76. })
  77. } else
  78. callback("删除失败!",false);
  79. });
  80. }
  81. module.exports = new rationRepositoryDao();