ration_repository_controller.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. var callback = function(req, res, err, message, data){
  7. res.json({error: err, message: message, data: data});
  8. };
  9. class RationRepositoryController extends baseController{
  10. addRationRepository(req,res){
  11. var rationObj = JSON.parse(req.body.rationRepObj);
  12. rationRepository.addRationRepository(rationObj,function(err,data){
  13. if (data) {
  14. callback(req, res, err, "has data", data);
  15. } else {
  16. callback(req, res, err, "no data", null);
  17. }
  18. })
  19. }
  20. getDisPlayRationLibs(req, res){
  21. rationRepository.getDisplayRationLibs(function(err, data){
  22. if (data) {
  23. callback(req, res, err, "has data",data);
  24. } else {
  25. callback(req, res, err, "no data", null);
  26. }
  27. });
  28. }
  29. getRealLibName(req,res){
  30. var libName = req.body.rationName;
  31. rationRepository.getRealLibName(libName,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. getLibIDByName(req,res){
  40. rationRepository.getLibIDByName(req.body.libName, function(err,data){
  41. if (data) {
  42. callback(req, res, err, "has ID", data);
  43. } else {
  44. callback(req, res, err, "no ID", null);
  45. }
  46. })
  47. }
  48. deleteRationLib(req,res){
  49. var rationName = req.body.rationName, lastOperator = req.body.lastOperator;
  50. rationRepository.deleteRationLib(rationName, lastOperator, 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. updateRationRepositoryName(req, res) {
  59. var orgName = req.body.rationName;
  60. var newName = req.body.newName;
  61. var lastOperator = req.body.lastOperator;
  62. rationRepository.updateName(orgName, newName, lastOperator, function(err, data){
  63. if (data) {
  64. callback(req, res, err, "has data", data);
  65. } else {
  66. callback(req, res, err, "no data", null);
  67. }
  68. });
  69. }
  70. }
  71. export default RationRepositoryController;
  72. /*
  73. module.exports = {
  74. addRationRepository:function(req,res){
  75. var rationObj = JSON.parse(req.body.rationRepObj);
  76. rationRepository.addRationRepository(rationObj,function(err,data){
  77. if (data) {
  78. callback(req, res, err, "has data", data);
  79. } else {
  80. callback(req, res, err, "no data", null);
  81. }
  82. })
  83. },
  84. getDisPlayRationLibs: function(req, res){
  85. rationRepository.getDisplayRationLibs(function(err, data){
  86. if (data) {
  87. callback(req, res, err, "has data",data);
  88. } else {
  89. callback(req, res, err, "no data", null);
  90. }
  91. });
  92. },
  93. getRealLibName:function(req,res){
  94. var libName = req.body.rationName;
  95. rationRepository.getRealLibName(libName,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. getLibIDByName:function(req,res){
  104. rationRepository.getLibIDByName(req.body.libName, function(err,data){
  105. if (data) {
  106. callback(req, res, err, "has ID", data);
  107. } else {
  108. callback(req, res, err, "no ID", null);
  109. }
  110. })
  111. },
  112. deleteRationLib:function(req,res){
  113. var rationName = req.body.rationName;
  114. rationRepository.deleteRationLib(rationName,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. updateRationRepositoryName: function(req, res) {
  123. var orgName = req.body.rationName;
  124. var newName = req.body.newName;
  125. rationRepository.updateName(orgName, newName, function(err, data){
  126. if (data) {
  127. callback(req, res, err, "has data", data);
  128. } else {
  129. callback(req, res, err, "no data", null);
  130. }
  131. });
  132. }
  133. }*/