compilation_model.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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: {$nin: ['']}}, field, false);
  31. return compilationData === null ? [] : compilationData;
  32. }
  33. /**
  34. * 获取编办列表
  35. *
  36. * @return {Promise}
  37. */
  38. async getList(host, name_filter = true) {
  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. compilationData === null ? [] : compilationData;
  43. // 川高养护特殊处理费用定额
  44. const cgCompilationNames = ['四川养护(2013)', '部颁2018计价标准'];
  45. let flag = true;
  46. if (host) {
  47. if (/cgyh.smartcost.com.cn/.test(host)) {
  48. compilationData = compilationData.filter(item => cgCompilationNames.includes(item.name));
  49. flag = false;
  50. } else if (/yhyun.smartcost.com.cn/.test(host)) {
  51. compilationData = compilationData.filter(item => !cgCompilationNames.includes(item.name));
  52. flag = false;
  53. }
  54. }
  55. if (name_filter && flag) {
  56. compilationData = compilationData.filter(function (item) {
  57. return cgCompilationNames.indexOf(item.name) === -1;
  58. });
  59. }
  60. return compilationData;
  61. }
  62. /**
  63. * 根据id获取可用的编办数据
  64. *
  65. * @param {String} id
  66. * @return {Promise}
  67. */
  68. async getCompilationById(id) {
  69. let condition = {_id: id, is_release: true};
  70. let compilationData = await this.findDataByCondition(condition);
  71. compilationData = compilationData._doc ? compilationData._doc : compilationData;
  72. if (!compilationData || compilationData.bill_valuation === undefined) {
  73. return compilationData;
  74. }
  75. const fields = ['suggestion', 'feasibility', 'rough', 'bill', 'ration', 'estimation'];
  76. fields.forEach(field => {
  77. const valField = `${field}_valuation`;
  78. if (compilationData[valField] && compilationData[valField].length > 0) {
  79. compilationData[valField] = compilationData[valField].filter(item => item.enable);
  80. }
  81. });
  82. /* if (compilationData.bill_valuation.length > 0) {
  83. let enableValuation = [];
  84. for (let index in compilationData.bill_valuation) {
  85. if (compilationData.bill_valuation[index].enable) {
  86. enableValuation.push(compilationData.bill_valuation[index]);
  87. }
  88. }
  89. compilationData.bill_valuation = enableValuation;
  90. }
  91. if (compilationData.ration_valuation.length > 0) {
  92. let enableValuation = [];
  93. for (let index in compilationData.ration_valuation) {
  94. if (compilationData.ration_valuation[index].enable) {
  95. enableValuation.push(compilationData.ration_valuation[index]);
  96. }
  97. }
  98. compilationData.ration_valuation = enableValuation;
  99. } */
  100. return compilationData;
  101. }
  102. }
  103. module.exports = CompilationModel;