compilation_model.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * 编办业务逻辑
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/8/16
  6. * @version
  7. */
  8. const BaseModel = require('../../common/base/base_model');
  9. const mongoose = require('mongoose');
  10. class CompilationModel extends BaseModel {
  11. /**
  12. * 构造函数
  13. *
  14. * @return {void}
  15. */
  16. constructor() {
  17. let parent = super();
  18. parent.model = mongoose.model('compilation');
  19. parent.init();
  20. }
  21. /**
  22. * 获取编办列表
  23. *
  24. * @return {Promise}
  25. */
  26. async getCompilationList(fields = null) {
  27. // 筛选字段
  28. let field = fields == null ?{_id: 1, name: 1, is_release: 1, categoryID: 1, description: 1,overWriteUrl: 1,example: 1, "ration_valuation.id": 1, "ration_valuation.name": 1, "ration_valuation.enable": 1,
  29. "bill_valuation.id": 1, "bill_valuation.name": 1, "bill_valuation.enable": 1}:fields;
  30. let compilationData = await this.findDataByCondition({name: {$ne: ''}}, field, false);
  31. return compilationData === null ? [] : compilationData;
  32. }
  33. /**
  34. * 获取编办列表
  35. *
  36. * @return {Promise}
  37. */
  38. async getList() {
  39. // 筛选字段
  40. let field = {_id: 1, name: 1, is_release: 1, description: 1, categoryID: 1};
  41. let compilationData = await this.findDataByCondition({name: {$ne: ''}, is_release: true}, field, false);
  42. return compilationData === null ? [] : compilationData;
  43. }
  44. /**
  45. * 根据id获取可用的编办数据
  46. *
  47. * @param {String} id
  48. * @return {Promise}
  49. */
  50. async getCompilationById(id) {
  51. let condition = {_id: id, is_release: true};
  52. let compilationData = await this.findDataByCondition(condition);
  53. if (!compilationData || compilationData.bill_valuation === undefined) {
  54. return compilationData;
  55. }
  56. if (compilationData.bill_valuation.length > 0) {
  57. let enableValuation = [];
  58. for (let index in compilationData.bill_valuation) {
  59. if (compilationData.bill_valuation[index].enable) {
  60. enableValuation.push(compilationData.bill_valuation[index]);
  61. }
  62. }
  63. compilationData.bill_valuation = enableValuation;
  64. }
  65. if (compilationData.ration_valuation.length > 0) {
  66. let enableValuation = [];
  67. for (let index in compilationData.ration_valuation) {
  68. if (compilationData.ration_valuation[index].enable) {
  69. enableValuation.push(compilationData.bill_valuation[index]);
  70. }
  71. }
  72. compilationData.ration_valuation = enableValuation;
  73. }
  74. return compilationData;
  75. }
  76. }
  77. module.exports = CompilationModel;