compilation_model.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * 编办业务逻辑
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/8/16
  6. * @version
  7. */
  8. import BaseModel from "../../common/base/base_model";
  9. import mongoose from "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 getList() {
  27. // 筛选字段
  28. let field = {_id: 1, name: 1, is_release: 1, description: 1, categoryID: 1};
  29. let compilationData = await this.findDataByCondition({name: {$ne: ''}, is_release: true}, field, false);
  30. return compilationData === null ? [] : compilationData;
  31. }
  32. /**
  33. * 根据id获取可用的编办数据
  34. *
  35. * @param {String} id
  36. * @return {Promise}
  37. */
  38. async getCompilationById(id) {
  39. let condition = {_id: id, is_release: true};
  40. let compilationData = await this.findDataByCondition(condition);
  41. if (!compilationData || compilationData.bill_valuation === undefined) {
  42. return compilationData;
  43. }
  44. if (compilationData.bill_valuation.length > 0) {
  45. let enableValuation = [];
  46. for (let index in compilationData.bill_valuation) {
  47. if (compilationData.bill_valuation[index].enable) {
  48. enableValuation.push(compilationData.bill_valuation[index]);
  49. }
  50. }
  51. compilationData.bill_valuation = enableValuation;
  52. }
  53. if (compilationData.ration_valuation.length > 0) {
  54. let enableValuation = [];
  55. for (let index in compilationData.ration_valuation) {
  56. if (compilationData.ration_valuation[index].enable) {
  57. enableValuation.push(compilationData.bill_valuation[index]);
  58. }
  59. }
  60. compilationData.ration_valuation = enableValuation;
  61. }
  62. return compilationData;
  63. }
  64. }
  65. export default CompilationModel;