1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- /**
- * 编办业务逻辑
- *
- * @author CaiAoLin
- * @date 2017/8/16
- * @version
- */
- const BaseModel = require('../../common/base/base_model');
- const mongoose = require('mongoose');
- class CompilationModel extends BaseModel {
- /**
- * 构造函数
- *
- * @return {void}
- */
- constructor() {
- let parent = super();
- parent.model = mongoose.model('compilation');
- parent.init();
- }
- /**
- * 获取编办列表
- *
- * @return {Promise}
- */
- async getCompilationList(fields = null) {
- // 筛选字段
- 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,
- "bill_valuation.id": 1, "bill_valuation.name": 1, "bill_valuation.enable": 1}:fields;
- let compilationData = await this.findDataByCondition({name: {$ne: ''}}, field, false);
- return compilationData === null ? [] : compilationData;
- }
- /**
- * 获取编办列表
- *
- * @return {Promise}
- */
- async getList() {
- // 筛选字段
- let field = {_id: 1, name: 1, is_release: 1, description: 1, categoryID: 1};
- let compilationData = await this.findDataByCondition({name: {$ne: ''}, is_release: true}, field, false);
- return compilationData === null ? [] : compilationData;
- }
- /**
- * 根据id获取可用的编办数据
- *
- * @param {String} id
- * @return {Promise}
- */
- async getCompilationById(id) {
- let condition = {_id: id, is_release: true};
- let compilationData = await this.findDataByCondition(condition);
- if (!compilationData || compilationData.bill_valuation === undefined) {
- return compilationData;
- }
- if (compilationData.bill_valuation.length > 0) {
- let enableValuation = [];
- for (let index in compilationData.bill_valuation) {
- if (compilationData.bill_valuation[index].enable) {
- enableValuation.push(compilationData.bill_valuation[index]);
- }
- }
- compilationData.bill_valuation = enableValuation;
- }
- if (compilationData.ration_valuation.length > 0) {
- let enableValuation = [];
- for (let index in compilationData.ration_valuation) {
- if (compilationData.ration_valuation[index].enable) {
- enableValuation.push(compilationData.bill_valuation[index]);
- }
- }
- compilationData.ration_valuation = enableValuation;
- }
- return compilationData;
- }
- }
- module.exports = CompilationModel;
|