ration_repository_controller.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. import gljMapModel from "../../std_glj_lib/models/schemas";
  8. import async from "async";
  9. var callback = function(req, res, err, message, data){
  10. res.json({error: err, message: message, data: data});
  11. };
  12. class RationRepositoryController extends baseController{
  13. async getCompilationList(req, res){
  14. try{
  15. let compilationModel = new CompilationModel(), rst = [];
  16. let compilationList = await compilationModel.getCompilationList();
  17. if(compilationList.length <= 0){
  18. throw '没有数据';
  19. }
  20. else{
  21. compilationList.forEach(function (compilation) {
  22. rst.push({_id: compilation._id, name: compilation.name});
  23. });
  24. //获得相关编办下的工料机库
  25. let parallelFucs = [];
  26. for(let i = 0; i < rst.length; i++){
  27. parallelFucs.push((function (obj) {
  28. return function (cb) {
  29. gljMapModel.find({compilationId: obj._id, deleted: false}, function (err, result) {
  30. if(err){
  31. cb(err);
  32. }
  33. else{
  34. cb(null, result);
  35. }
  36. })
  37. }
  38. })(rst[i]));
  39. }
  40. async.parallel(parallelFucs, function (err, result) {
  41. if(err){
  42. callback(req, res, err, '没有数据', null);
  43. }
  44. else{
  45. let gljLibsRst = [];
  46. for(let i = 0; i < result.length; i++){
  47. for(let j = 0; j < result[i].length; j++){
  48. gljLibsRst.push(result[i][j]);
  49. }
  50. }
  51. callback(req, res, false, '', {compilation: rst, gljLibs: gljLibsRst});
  52. }
  53. })
  54. }
  55. }
  56. catch(err) {
  57. callback(req, res, err, '没有数据', null);
  58. }
  59. }
  60. addRationRepository(req,res){
  61. var rationObj = JSON.parse(req.body.rationRepObj);
  62. rationRepository.addRationRepository(rationObj,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. getRationLib(req, res){
  71. let data = JSON.parse(req.body.data);
  72. let libId = data.libId;
  73. rationRepository.getRationLib(libId, function(err, data){
  74. if (data) {
  75. callback(req, res, err, "has data",data);
  76. } else {
  77. callback(req, res, err, "no data", null);
  78. }
  79. });
  80. }
  81. getDisPlayRationLibs(req, res){
  82. rationRepository.getDisplayRationLibs(function(err, data){
  83. if (data) {
  84. callback(req, res, err, "has data",data);
  85. } else {
  86. callback(req, res, err, "no data", null);
  87. }
  88. });
  89. }
  90. getRealLibName(req,res){
  91. var libName = req.body.rationName;
  92. rationRepository.getRealLibName(libName,function(err,data){
  93. if (data) {
  94. callback(req, res, err, "has data", data);
  95. } else {
  96. callback(req, res, err, "no data", null);
  97. }
  98. })
  99. }
  100. getLibIDByName(req,res){
  101. rationRepository.getLibIDByName(req.body.libName, function(err,data){
  102. if (data) {
  103. callback(req, res, err, "has ID", data);
  104. } else {
  105. callback(req, res, err, "no ID", null);
  106. }
  107. })
  108. }
  109. deleteRationLib(req,res){
  110. let oprtor = req.body.oprtor,
  111. libId = req.body.libId;
  112. rationRepository.deleteRationLib(oprtor, libId, function (err, message) {
  113. callback(req, res, err, message, null);
  114. });
  115. }
  116. updateRationRepositoryName(req, res) {
  117. let oprtor = req.body.oprtor,
  118. renameObj = JSON.parse(req.body.renameObj);
  119. rationRepository.updateName(oprtor, renameObj, function (err, message) {
  120. callback(req, res, err, message, null);
  121. })
  122. }
  123. }
  124. export default RationRepositoryController;
  125. /*
  126. module.exports = {
  127. addRationRepository:function(req,res){
  128. var rationObj = JSON.parse(req.body.rationRepObj);
  129. rationRepository.addRationRepository(rationObj,function(err,data){
  130. if (data) {
  131. callback(req, res, err, "has data", data);
  132. } else {
  133. callback(req, res, err, "no data", null);
  134. }
  135. })
  136. },
  137. getDisPlayRationLibs: function(req, res){
  138. rationRepository.getDisplayRationLibs(function(err, data){
  139. if (data) {
  140. callback(req, res, err, "has data",data);
  141. } else {
  142. callback(req, res, err, "no data", null);
  143. }
  144. });
  145. },
  146. getRealLibName:function(req,res){
  147. var libName = req.body.rationName;
  148. rationRepository.getRealLibName(libName,function(err,data){
  149. if (data) {
  150. callback(req, res, err, "has data", data);
  151. } else {
  152. callback(req, res, err, "no data", null);
  153. }
  154. })
  155. },
  156. getLibIDByName:function(req,res){
  157. rationRepository.getLibIDByName(req.body.libName, function(err,data){
  158. if (data) {
  159. callback(req, res, err, "has ID", data);
  160. } else {
  161. callback(req, res, err, "no ID", null);
  162. }
  163. })
  164. },
  165. deleteRationLib:function(req,res){
  166. var rationName = req.body.rationName;
  167. rationRepository.deleteRationLib(rationName,function(err,data){
  168. if (data) {
  169. callback(req, res, err, "has data", data);
  170. } else {
  171. callback(req, res, err, "no data", null);
  172. }
  173. })
  174. },
  175. updateRationRepositoryName: function(req, res) {
  176. var orgName = req.body.rationName;
  177. var newName = req.body.newName;
  178. rationRepository.updateName(orgName, newName, function(err, data){
  179. if (data) {
  180. callback(req, res, err, "has data", data);
  181. } else {
  182. callback(req, res, err, "no data", null);
  183. }
  184. });
  185. }
  186. }*/