repository_map.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. let async = require("async");
  8. //var stringUtil = require('../../../public/stringUtil');
  9. var rationLibdb = dbm.getCfgConnection("scConstruct");
  10. var Schema = mongoose.Schema;
  11. var RepositoryMapSchema = new Schema({
  12. "ID": Number,
  13. "dispName" : String,
  14. "appType" : String, //如:"建筑" / "公路"
  15. "localeType": Number, //如 各个省份 / 部颁
  16. "descr" : String,
  17. "creator": String,
  18. "createDate": Date,
  19. "lastOperator": String,
  20. "lastOperateDate": Date,
  21. "deleted": Boolean
  22. });
  23. var counter = require('../../../public/counter/counter');
  24. var rationRepository = rationLibdb.model("std_ration_lib_map", RepositoryMapSchema, "std_ration_lib_map");
  25. function createNewLibModel(rationLibObj){
  26. var rst = {};
  27. rst.dispName = rationLibObj.dispName;
  28. rst.appType = rationLibObj.appType?rationLibObj.appType:'construct';
  29. rst.localeType = rationLibObj.localeType?rationLibObj.localeType:'';
  30. rst.descr = rationLibObj.descr;
  31. rst.creator = rationLibObj.creator;
  32. rst.lastOperator = rationLibObj.lastOperator;
  33. rst.createDate = Date.now();
  34. rst.lastOperateDate = Date.now();
  35. rst.deleted = false;
  36. return rst;
  37. }
  38. var rationRepositoryDao = function(){};
  39. rationRepositoryDao.prototype.getRealLibName = function(dispName,callback){
  40. if (callback) {
  41. rationRepository.find({"dispName": dispName}, function(err,data){
  42. if (err) {
  43. callback('Error', null);
  44. } else {
  45. callback(false, data);
  46. }
  47. });
  48. } else {
  49. var rst = rationRepository.find({"dispName": dispName}).exec();
  50. return rst;
  51. }
  52. };
  53. rationRepositoryDao.prototype.getLibIDByName = function(dispName, callback){
  54. rationRepository.findOne({"dispName": dispName}, function(err,data){
  55. if (err) {
  56. callback('Error', null);
  57. } else {
  58. callback(false, data.ID);
  59. }
  60. });
  61. };
  62. rationRepositoryDao.prototype.getRepositoryById = function(repId,callback){
  63. if (callback) {
  64. rationRepository.find({"ID": repId}, function(err,data){
  65. if (err) {
  66. callback('Error', null);
  67. } else {
  68. callback(false, data);
  69. }
  70. });
  71. } else {
  72. var rst = rationRepository.find({"ID": repId}).exec();
  73. return rst;
  74. }
  75. };
  76. rationRepositoryDao.prototype.addRationRepository = function( rationLibObj,callback){
  77. counter.counterDAO.getIDAfterCount(counter.moduleName.rationMap, 1, function(err, result){
  78. var rMap = createNewLibModel(rationLibObj);
  79. rMap.ID = result.value.sequence_value;
  80. new rationRepository(rMap).save(function(err, result) {
  81. if (err) callback("Error", null)
  82. else
  83. callback(false, result);
  84. });
  85. });
  86. };
  87. rationRepositoryDao.prototype.getDisplayRationLibs = function(callback) {
  88. rationRepository.find({"deleted": false}, function(err, data){
  89. if (err) {
  90. callback( 'Error', null);
  91. } else {
  92. callback( false, data);
  93. }
  94. });
  95. };
  96. rationRepositoryDao.prototype.updateName = function(orgName,newName,callback){
  97. rationRepository.find({"dispName":newName, "deleted": false}, function(err, data){
  98. if (data.length == 0) {
  99. rationRepository.update({dispName:orgName},{$set:{dispName:newName}},function(err){
  100. if(err) callback("err",false);
  101. else callback(false,"ok")
  102. })
  103. } else
  104. callback("不可重名!",false);
  105. });
  106. }
  107. rationRepositoryDao.prototype.deleteRationLib = function(rationName, needSet, callback){
  108. rationRepository.find({"dispName":rationName, "deleted": false}, function(err, data){
  109. if (data.length == 1) {
  110. rationRepository.update({dispName:rationName, deleted: false},{$set: needSet},function(err){
  111. if(err) callback("err",false);
  112. else callback(false,"ok")
  113. })
  114. } else
  115. callback("删除失败!",false);
  116. });
  117. }
  118. module.exports = new rationRepositoryDao();