ration_repository_controller.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * Created by Tony on 2017/4/20.
  3. */
  4. var rationRepository = require("../models/repository_map");
  5. import baseController from "../../common/base/base_controller";
  6. import CompilationModel from "../../users/models/compilation_model";
  7. var callback = function(req, res, err, message, data){
  8. res.json({error: err, message: message, data: data});
  9. };
  10. class RationRepositoryController extends baseController{
  11. async getCompilationList(req, res){
  12. try{
  13. let compilationModel = new CompilationModel(), rst = [];
  14. let compilationList = await compilationModel.getCompilationList();
  15. if(compilationList.length <= 0){
  16. throw '没有数据';
  17. }
  18. else{
  19. compilationList.forEach(function (compilation) {
  20. rst.push({_id: compilation._id, name: compilation.name});
  21. })
  22. callback(req, res, false, '', rst);
  23. }
  24. }
  25. catch(err) {
  26. callback(req, res, err, '没有数据', null);
  27. }
  28. }
  29. addRationRepository(req,res){
  30. var rationObj = JSON.parse(req.body.rationRepObj);
  31. rationRepository.addRationRepository(rationObj,function(err,data){
  32. if (data) {
  33. callback(req, res, err, "has data", data);
  34. } else {
  35. callback(req, res, err, "no data", null);
  36. }
  37. })
  38. }
  39. getDisPlayRationLibs(req, res){
  40. rationRepository.getDisplayRationLibs(function(err, data){
  41. if (data) {
  42. callback(req, res, err, "has data",data);
  43. } else {
  44. callback(req, res, err, "no data", null);
  45. }
  46. });
  47. }
  48. getRealLibName(req,res){
  49. var libName = req.body.rationName;
  50. rationRepository.getRealLibName(libName,function(err,data){
  51. if (data) {
  52. callback(req, res, err, "has data", data);
  53. } else {
  54. callback(req, res, err, "no data", null);
  55. }
  56. })
  57. }
  58. getLibIDByName(req,res){
  59. rationRepository.getLibIDByName(req.body.libName, function(err,data){
  60. if (data) {
  61. callback(req, res, err, "has ID", data);
  62. } else {
  63. callback(req, res, err, "no ID", null);
  64. }
  65. })
  66. }
  67. deleteRationLib(req,res){
  68. var rationName = req.body.rationName, lastOperator = req.body.lastOperator;
  69. rationRepository.deleteRationLib(rationName, lastOperator, function(err,data){
  70. if (data) {
  71. callback(req, res, err, "has data", data);
  72. } else {
  73. callback(req, res, err, "no data", null);
  74. }
  75. })
  76. }
  77. updateRationRepositoryName(req, res) {
  78. var orgName = req.body.rationName;
  79. var newName = req.body.newName;
  80. var lastOperator = req.body.lastOperator;
  81. rationRepository.updateName(orgName, newName, lastOperator, function(err, data){
  82. if (data) {
  83. callback(req, res, err, "has data", data);
  84. } else {
  85. callback(req, res, err, "no data", null);
  86. }
  87. });
  88. }
  89. }
  90. export default RationRepositoryController;
  91. /*
  92. module.exports = {
  93. addRationRepository:function(req,res){
  94. var rationObj = JSON.parse(req.body.rationRepObj);
  95. rationRepository.addRationRepository(rationObj,function(err,data){
  96. if (data) {
  97. callback(req, res, err, "has data", data);
  98. } else {
  99. callback(req, res, err, "no data", null);
  100. }
  101. })
  102. },
  103. getDisPlayRationLibs: function(req, res){
  104. rationRepository.getDisplayRationLibs(function(err, data){
  105. if (data) {
  106. callback(req, res, err, "has data",data);
  107. } else {
  108. callback(req, res, err, "no data", null);
  109. }
  110. });
  111. },
  112. getRealLibName:function(req,res){
  113. var libName = req.body.rationName;
  114. rationRepository.getRealLibName(libName,function(err,data){
  115. if (data) {
  116. callback(req, res, err, "has data", data);
  117. } else {
  118. callback(req, res, err, "no data", null);
  119. }
  120. })
  121. },
  122. getLibIDByName:function(req,res){
  123. rationRepository.getLibIDByName(req.body.libName, function(err,data){
  124. if (data) {
  125. callback(req, res, err, "has ID", data);
  126. } else {
  127. callback(req, res, err, "no ID", null);
  128. }
  129. })
  130. },
  131. deleteRationLib:function(req,res){
  132. var rationName = req.body.rationName;
  133. rationRepository.deleteRationLib(rationName,function(err,data){
  134. if (data) {
  135. callback(req, res, err, "has data", data);
  136. } else {
  137. callback(req, res, err, "no data", null);
  138. }
  139. })
  140. },
  141. updateRationRepositoryName: function(req, res) {
  142. var orgName = req.body.rationName;
  143. var newName = req.body.newName;
  144. rationRepository.updateName(orgName, newName, function(err, data){
  145. if (data) {
  146. callback(req, res, err, "has data", data);
  147. } else {
  148. callback(req, res, err, "no data", null);
  149. }
  150. });
  151. }
  152. }*/