project.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Created by jimiz on 2017/4/16.
  3. */
  4. var billsData = require('./bills');
  5. var rationData = require('./ration');
  6. var GLJData = require('./GLJ');
  7. var consts = require('./projectConsts');
  8. var moduleMap = {};
  9. moduleMap[consts.BILLS] = billsData;
  10. moduleMap[consts.RATION] = rationData;
  11. moduleMap[consts.GLJ] = GLJData;
  12. var Project = function (){};
  13. Project.prototype.datas = [];
  14. Project.prototype.prepare = function(data, callback){
  15. data.updateData.forEach(function(item){
  16. this.datas.push(item);
  17. /*
  18. to do
  19. moduleMap[item.moduleName].prepare(item.data, jobCallback);
  20. */
  21. });
  22. };
  23. Project.prototype.save = function(data, callback){
  24. var job, savePoint;
  25. var errDatas = [];
  26. this.prepare(data, function(job, savePoint){});
  27. var saveCallback = function(err, moduleName, data){
  28. if (err != 0){
  29. var errData = {moduleName: moduleName, err: err, data: data};
  30. errDatas.push(errData);
  31. }
  32. };
  33. this.datas.forEach(function(item){
  34. moduleMap[item.moduleName].save(item.data, saveCallback);
  35. });
  36. this.datas = [];
  37. if (errDatas.length > 0){
  38. callback(1, 'error', errDatas)
  39. }
  40. else{
  41. callback(0, '', null)
  42. }
  43. };
  44. module.exports = new Project();