/**
 * 费率文件标准库业务逻辑
 *
 * @author CaiAoLin
 * @date 2017/8/30
 * @version
 */
import BaseModel from "../base/base_model";
import mongoose from "mongoose";

class STDFeeRateLibsModel extends BaseModel {

    /**
     * 构造函数
     *
     * @return {void}
     */
    constructor() {
        let parent = super();
        parent.model = mongoose.model("std_fee_rate_libs");
        parent.init();
    }

    /**
     * 获取费率列表
     *
     * @return {Promise}
     */
    async getFeeRateList(compilationId) {
        let result = [];
        let field = {ID: 1, libName: 1};
        let feeRateList = await this.findDataByCondition({compilationId:compilationId,ID: {$ne: ''}}, field, false);

        if (feeRateList === null) {
            return result;
        }
        // 整理数据
        for(let feeRate of feeRateList) {
            let tmpData = {
                id: feeRate.ID,
                name: feeRate.libName
            };
            result.push(tmpData);
        }
        return result;
    }

}

export default STDFeeRateLibsModel;
