installation.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * Created by Zhong on 2018/1/24.
  3. */
  4. import {rationItemModel, installFeeItemModel, installSectionModel} from '../models/schemas';
  5. class InstallationDao{
  6. async getInstallation(rationRepId, callback){
  7. try {
  8. let feeItems = await installFeeItemModel.find({rationRepId: rationRepId, $or: [{deleted: false}, {deleted: null}]});
  9. for(let feeItem of feeItems){
  10. let sids = [];
  11. for(let sec of feeItem.section){
  12. sids.push(sec.ID);
  13. }
  14. if(sids.length > 0){
  15. let sections = await installSectionModel.find({ID: {$in: sids}, $or: [{deleted: false}, {deleted: null}]});
  16. feeItem._doc.section = sections;
  17. }
  18. }
  19. callback(0, feeItems);
  20. }
  21. catch(err){
  22. callback(err, null);
  23. }
  24. }
  25. async updateSection(updateData, callback){
  26. try{
  27. for(let data of updateData){
  28. if(data.updateType === 'new'){
  29. await installSectionModel.create(data.updateData);
  30. }
  31. else if(data.updateType === 'update'){
  32. await installSectionModel.update({ID: data.updateData.ID}, data.updateData);
  33. }
  34. }
  35. callback(0, null);
  36. }
  37. catch(err){
  38. callback(err, null);
  39. }
  40. }
  41. async updateFeeItem(updateData, callback){
  42. try{
  43. for(let data of updateData){
  44. if(data.updateType === 'new'){
  45. await installFeeItemModel.create(data.updateData);
  46. }
  47. else if(data.updateType === 'update'){
  48. await installFeeItemModel.update({ID: data.updateData.ID}, data.updateData);
  49. }
  50. }
  51. callback(0, null);
  52. }
  53. catch(err){
  54. callback(err, null);
  55. }
  56. }
  57. async batchUpdateInst(rationSection, inst, callback){
  58. try{
  59. for(let sectionId of rationSection){
  60. await rationItemModel.update({sectionId: sectionId, $or: [{isDeleted: null}, {isDeleted: false}]},
  61. {$addToSet: {rationInstList: {feeItemId: inst.feeItemId, sectionId: inst.sectionId}}}, {multi: true});
  62. }
  63. callback(0, null);
  64. }
  65. catch(err){
  66. callback(err, null);
  67. }
  68. }
  69. }
  70. export default InstallationDao;