ration_repository_controller.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 libId = req.body.libId;
  72. rationRepository.getRationLib(libId, function(err, data){
  73. if (data) {
  74. callback(req, res, err, "has data",data);
  75. } else {
  76. callback(req, res, err, "no data", null);
  77. }
  78. });
  79. }
  80. getDisPlayRationLibs(req, res){
  81. rationRepository.getDisplayRationLibs(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. getRealLibName(req,res){
  90. var libName = req.body.rationName;
  91. rationRepository.getRealLibName(libName,function(err,data){
  92. if (data) {
  93. callback(req, res, err, "has data", data);
  94. } else {
  95. callback(req, res, err, "no data", null);
  96. }
  97. })
  98. }
  99. getLibIDByName(req,res){
  100. rationRepository.getLibIDByName(req.body.libName, function(err,data){
  101. if (data) {
  102. callback(req, res, err, "has ID", data);
  103. } else {
  104. callback(req, res, err, "no ID", null);
  105. }
  106. })
  107. }
  108. deleteRationLib(req,res){
  109. let oprtor = req.body.oprtor,
  110. libId = req.body.libId;
  111. rationRepository.deleteRationLib(oprtor, libId, function (err, message) {
  112. callback(req, res, err, message, null);
  113. });
  114. }
  115. updateRationRepositoryName(req, res) {
  116. let oprtor = req.body.oprtor,
  117. renameObj = JSON.parse(req.body.renameObj);
  118. rationRepository.updateName(oprtor, renameObj, function (err, message) {
  119. callback(req, res, err, message, null);
  120. })
  121. }
  122. }
  123. export default RationRepositoryController;
  124. /*
  125. module.exports = {
  126. addRationRepository:function(req,res){
  127. var rationObj = JSON.parse(req.body.rationRepObj);
  128. rationRepository.addRationRepository(rationObj,function(err,data){
  129. if (data) {
  130. callback(req, res, err, "has data", data);
  131. } else {
  132. callback(req, res, err, "no data", null);
  133. }
  134. })
  135. },
  136. getDisPlayRationLibs: function(req, res){
  137. rationRepository.getDisplayRationLibs(function(err, data){
  138. if (data) {
  139. callback(req, res, err, "has data",data);
  140. } else {
  141. callback(req, res, err, "no data", null);
  142. }
  143. });
  144. },
  145. getRealLibName:function(req,res){
  146. var libName = req.body.rationName;
  147. rationRepository.getRealLibName(libName,function(err,data){
  148. if (data) {
  149. callback(req, res, err, "has data", data);
  150. } else {
  151. callback(req, res, err, "no data", null);
  152. }
  153. })
  154. },
  155. getLibIDByName:function(req,res){
  156. rationRepository.getLibIDByName(req.body.libName, function(err,data){
  157. if (data) {
  158. callback(req, res, err, "has ID", data);
  159. } else {
  160. callback(req, res, err, "no ID", null);
  161. }
  162. })
  163. },
  164. deleteRationLib:function(req,res){
  165. var rationName = req.body.rationName;
  166. rationRepository.deleteRationLib(rationName,function(err,data){
  167. if (data) {
  168. callback(req, res, err, "has data", data);
  169. } else {
  170. callback(req, res, err, "no data", null);
  171. }
  172. })
  173. },
  174. updateRationRepositoryName: function(req, res) {
  175. var orgName = req.body.rationName;
  176. var newName = req.body.newName;
  177. rationRepository.updateName(orgName, newName, function(err, data){
  178. if (data) {
  179. callback(req, res, err, "has data", data);
  180. } else {
  181. callback(req, res, err, "no data", null);
  182. }
  183. });
  184. }
  185. }*/