compilation_model.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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, from) {
  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. if (host) {
  46. if (/cgyh.smartcost.com.cn/.test(host)) {
  47. compilationData = compilationData.filter(item => cgCompilationNames.includes(item.name));
  48. } else if (/yhyun.smartcost.com.cn/.test(host)) {
  49. compilationData = compilationData.filter(item => !cgCompilationNames.includes(item.name));
  50. }
  51. }
  52. if (from === 'zplus') {
  53. compilationData = compilationData.filter(item => !cgCompilationNames.includes(item.name));
  54. }
  55. return compilationData;
  56. }
  57. /**
  58. * 根据id获取可用的编办数据
  59. *
  60. * @param {String} id
  61. * @return {Promise}
  62. */
  63. async getCompilationById(id) {
  64. let condition = {_id: id, is_release: true};
  65. let compilationData = await this.findDataByCondition(condition);
  66. compilationData = compilationData._doc ? compilationData._doc : compilationData;
  67. if (!compilationData || compilationData.bill_valuation === undefined) {
  68. return compilationData;
  69. }
  70. const fields = ['suggestion', 'feasibility', 'rough', 'bill', 'ration', 'estimation'];
  71. fields.forEach(field => {
  72. const valField = `${field}_valuation`;
  73. if (compilationData[valField] && compilationData[valField].length > 0) {
  74. compilationData[valField] = compilationData[valField].filter(item => item.enable);
  75. }
  76. });
  77. /* if (compilationData.bill_valuation.length > 0) {
  78. let enableValuation = [];
  79. for (let index in compilationData.bill_valuation) {
  80. if (compilationData.bill_valuation[index].enable) {
  81. enableValuation.push(compilationData.bill_valuation[index]);
  82. }
  83. }
  84. compilationData.bill_valuation = enableValuation;
  85. }
  86. if (compilationData.ration_valuation.length > 0) {
  87. let enableValuation = [];
  88. for (let index in compilationData.ration_valuation) {
  89. if (compilationData.ration_valuation[index].enable) {
  90. enableValuation.push(compilationData.ration_valuation[index]);
  91. }
  92. }
  93. compilationData.ration_valuation = enableValuation;
  94. } */
  95. return compilationData;
  96. }
  97. }
  98. module.exports = CompilationModel;