import { Http,Util } from '@/utils';
import EntityService from '../entity-service';



/**
 * 指标服务对象基类
 *
 * @export
 * @class DAMetricServiceBase
 * @extends {EntityServie}
 */
export default class DAMetricServiceBase extends EntityService {

    /**
     * Creates an instance of  DAMetricServiceBase.
     * 
     * @param {*} [opts={}]
     * @memberof  DAMetricServiceBase
     */
    constructor(opts: any = {}) {
        super(opts);
    }

    /**
     * 初始化基础数据
     *
     * @memberof DAMetricServiceBase
     */
    public initBasicData(){
        this.APPLYDEKEY ='dametric';
        this.APPDEKEY = 'metric_id';
        this.APPDENAME = 'dametrics';
        this.APPDETEXT = 'metric_name';
        this.APPNAME = 'web';
        this.SYSTEMNAME = 'ibzdst';
    }

// 实体接口

    /**
     * Select接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof DAMetricServiceBase
     */
    public async Select(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.dabuild && context.dametric){
            let res:any = Http.getInstance().get(`/dabuilds/${context.dabuild}/dametrics/${context.dametric}/select`,isloading);
            
            return res;
        }
            let res:any = Http.getInstance().get(`/dametrics/${context.dametric}/select`,isloading);
            
            return res;
    }

    /**
     * Create接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof DAMetricServiceBase
     */
    public async Create(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.dabuild && true){
            let masterData:any = {};
            Object.assign(data,masterData);
            if(!data.srffrontuf || data.srffrontuf !== "1"){
                data[this.APPDEKEY] = null;
            }
            if(data.srffrontuf){
                delete data.srffrontuf;
            }
            let tempContext:any = JSON.parse(JSON.stringify(context));
            let res:any = await Http.getInstance().post(`/dabuilds/${context.dabuild}/dametrics`,data,isloading);
            
            return res;
        }
        let masterData:any = {};
        Object.assign(data,masterData);
        if(!data.srffrontuf || data.srffrontuf !== "1"){
            data[this.APPDEKEY] = null;
        }
        if(data.srffrontuf){
            delete data.srffrontuf;
        }
        let tempContext:any = JSON.parse(JSON.stringify(context));
        let res:any = await Http.getInstance().post(`/dametrics`,data,isloading);
        
        return res;
    }

    /**
     * Update接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof DAMetricServiceBase
     */
    public async Update(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.dabuild && context.dametric){
            let masterData:any = {};
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().put(`/dabuilds/${context.dabuild}/dametrics/${context.dametric}`,data,isloading);
            
            return res;
        }
        let masterData:any = {};
        Object.assign(data,masterData);
            let res:any = await  Http.getInstance().put(`/dametrics/${context.dametric}`,data,isloading);
            
            return res;
    }

    /**
     * Remove接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof DAMetricServiceBase
     */
    public async Remove(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.dabuild && context.dametric){
            let res:any = Http.getInstance().delete(`/dabuilds/${context.dabuild}/dametrics/${context.dametric}`,isloading);
            return res;
        }
            let res:any = Http.getInstance().delete(`/dametrics/${context.dametric}`,isloading);
            return res;
    }

    /**
     * Get接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof DAMetricServiceBase
     */
    public async Get(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.dabuild && context.dametric){
            let res:any = await Http.getInstance().get(`/dabuilds/${context.dabuild}/dametrics/${context.dametric}`,isloading);
            
            return res;
        }
            let res:any = await Http.getInstance().get(`/dametrics/${context.dametric}`,isloading);
            
            return res;
    }

    /**
     * GetDraft接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof DAMetricServiceBase
     */
    public async GetDraft(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.dabuild && true){
            let res:any = await Http.getInstance().get(`/dabuilds/${context.dabuild}/dametrics/getdraft`,isloading);
            res.data.dametric = data.dametric;
            
            return res;
        }
        let res:any = await  Http.getInstance().get(`/dametrics/getdraft`,isloading);
        res.data.dametric = data.dametric;
        
        return res;
    }

    /**
     * CheckKey接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof DAMetricServiceBase
     */
    public async CheckKey(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.dabuild && context.dametric){
            let masterData:any = {};
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().post(`/dabuilds/${context.dabuild}/dametrics/${context.dametric}/checkkey`,data,isloading);
            
            return res;
        }
            let res:any = Http.getInstance().post(`/dametrics/${context.dametric}/checkkey`,data,isloading);
            return res;
    }

    /**
     * Save接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof DAMetricServiceBase
     */
    public async Save(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.dabuild && context.dametric){
            let masterData:any = {};
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().post(`/dabuilds/${context.dabuild}/dametrics/${context.dametric}/save`,data,isloading);
            
            return res;
        }
        let masterData:any = {};
        Object.assign(data,masterData);
            let res:any = await  Http.getInstance().post(`/dametrics/${context.dametric}/save`,data,isloading);
            
            return res;
    }

    /**
     * SyncRule接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof DAMetricServiceBase
     */
    public async SyncRule(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.dabuild && context.dametric){
            let masterData:any = {};
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().post(`/dabuilds/${context.dabuild}/dametrics/${context.dametric}/syncrule`,data,isloading);
            
            return res;
        }
            let res:any = Http.getInstance().post(`/dametrics/${context.dametric}/syncrule`,data,isloading);
            return res;
    }

    /**
     * SyncRuleBatch接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof DAMetricServiceBase
     */
    public async SyncRuleBatch(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.dabuild && true){
            let tempData:any = JSON.parse(JSON.stringify(data));
            return await Http.getInstance().post(`/dabuilds/${context.dabuild}/dametrics/syncrulebatch`,tempData,isloading);
        }
        let tempData:any = JSON.parse(JSON.stringify(data));
        return await Http.getInstance().post(`/dametrics/syncrulebatch`,tempData,isloading);
    }

    /**
     * FetchDefault接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof DAMetricServiceBase
     */
    public async FetchDefault(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.dabuild && true){
            let tempData:any = JSON.parse(JSON.stringify(data));
            let res:any = Http.getInstance().get(`/dabuilds/${context.dabuild}/dametrics/fetchdefault`,tempData,isloading);
            return res;
        }
        let tempData:any = JSON.parse(JSON.stringify(data));
        let res:any = Http.getInstance().get(`/dametrics/fetchdefault`,tempData,isloading);
        return res;
    }

    /**
     * searchDefault接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof DAMetricServiceBase
     */
    public async searchDefault(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.dabuild && true){
            let tempData:any = JSON.parse(JSON.stringify(data));
            return await Http.getInstance().post(`/dabuilds/${context.dabuild}/dametrics/searchdefault`,tempData,isloading);
        }
        let tempData:any = JSON.parse(JSON.stringify(data));
        return await Http.getInstance().post(`/dametrics/searchdefault`,tempData,isloading);
    }
}