/**
 * Created by Tony on 2016/12/23.
 */
var mongoose = require('mongoose');
var dbm = require("../../../config/db/db_manager");
var smartcostdb = dbm.getCfgConnection("Reports");
var Schema = mongoose.Schema;
var RptTemplateSchema = new Schema({
    "GROUP_KEY": String,
    "ID_KEY": String,
    "主信息": Schema.Types.Mixed,
    "指标_数据_映射": Schema.Types.Mixed,
    "布局框_集合": Array,
    "流水式表_信息": Schema.Types.Mixed,
    "交叉表_信息": Schema.Types.Mixed,
    "无映射离散指标_集合": Schema.Types.Mixed,
    "离散参数_集合": Schema.Types.Mixed,
    "计算式_集合": Array
});

var Template = smartcostdb.model("rpt_templates", RptTemplateSchema, "rpt_templates");

var RplTplDAO = function(){};

RplTplDAO.prototype.get = function(grpId, id, callback){
    Template.find({GROUP_KEY: grpId, ID_KEY: id}, '-_id', function(err, templates){
        if(templates.length){
            callback(false, templates[0]);
        }
        else{
            callback('查找不到报表模板！');
        }
    })
};

RplTplDAO.prototype.getPromise = function(grpId, id){
    var rst = Template.findOne({GROUP_KEY: grpId, ID_KEY: id}, '-_id').exec() ;
    return rst;
}

module.exports = new RplTplDAO();
