ration_repository_controller.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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, needSet = {deleted: true, lastOperator: req.body.lastOperator, lastOperateDate: Date.now()}
  50. rationRepository.deleteRationLib(rationName, needSet, 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. rationRepository.updateName(orgName, newName, function(err, data){
  62. if (data) {
  63. callback(req, res, err, "has data", data);
  64. } else {
  65. callback(req, res, err, "no data", null);
  66. }
  67. });
  68. }
  69. }
  70. export default RationRepositoryController;
  71. /*
  72. module.exports = {
  73. addRationRepository:function(req,res){
  74. var rationObj = JSON.parse(req.body.rationRepObj);
  75. rationRepository.addRationRepository(rationObj,function(err,data){
  76. if (data) {
  77. callback(req, res, err, "has data", data);
  78. } else {
  79. callback(req, res, err, "no data", null);
  80. }
  81. })
  82. },
  83. getDisPlayRationLibs: function(req, res){
  84. rationRepository.getDisplayRationLibs(function(err, data){
  85. if (data) {
  86. callback(req, res, err, "has data",data);
  87. } else {
  88. callback(req, res, err, "no data", null);
  89. }
  90. });
  91. },
  92. getRealLibName:function(req,res){
  93. var libName = req.body.rationName;
  94. rationRepository.getRealLibName(libName,function(err,data){
  95. if (data) {
  96. callback(req, res, err, "has data", data);
  97. } else {
  98. callback(req, res, err, "no data", null);
  99. }
  100. })
  101. },
  102. getLibIDByName:function(req,res){
  103. rationRepository.getLibIDByName(req.body.libName, function(err,data){
  104. if (data) {
  105. callback(req, res, err, "has ID", data);
  106. } else {
  107. callback(req, res, err, "no ID", null);
  108. }
  109. })
  110. },
  111. deleteRationLib:function(req,res){
  112. var rationName = req.body.rationName;
  113. rationRepository.deleteRationLib(rationName,function(err,data){
  114. if (data) {
  115. callback(req, res, err, "has data", data);
  116. } else {
  117. callback(req, res, err, "no data", null);
  118. }
  119. })
  120. },
  121. updateRationRepositoryName: function(req, res) {
  122. var orgName = req.body.rationName;
  123. var newName = req.body.newName;
  124. rationRepository.updateName(orgName, newName, function(err, data){
  125. if (data) {
  126. callback(req, res, err, "has data", data);
  127. } else {
  128. callback(req, res, err, "no data", null);
  129. }
  130. });
  131. }
  132. }*/