compilation_model.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. const fields = ['suggestion', 'feasibility', 'rough', 'bill', 'ration'];
  57. fields.forEach(field => {
  58. const valField = `${field}_valuation`;
  59. if (compilationData[valField] && compilationData[valField].length > 0) {
  60. compilationData[valField] = compilationData[valField].filter(item => item.enable);
  61. }
  62. });
  63. /* if (compilationData.bill_valuation.length > 0) {
  64. let enableValuation = [];
  65. for (let index in compilationData.bill_valuation) {
  66. if (compilationData.bill_valuation[index].enable) {
  67. enableValuation.push(compilationData.bill_valuation[index]);
  68. }
  69. }
  70. compilationData.bill_valuation = enableValuation;
  71. }
  72. if (compilationData.ration_valuation.length > 0) {
  73. let enableValuation = [];
  74. for (let index in compilationData.ration_valuation) {
  75. if (compilationData.ration_valuation[index].enable) {
  76. enableValuation.push(compilationData.ration_valuation[index]);
  77. }
  78. }
  79. compilationData.ration_valuation = enableValuation;
  80. } */
  81. return compilationData;
  82. }
  83. }
  84. module.exports = CompilationModel;