import { Http,Util } from '@/utils';
import EntityService from '../entity-service';
import NextActionLogic from '@/service/ibizbook/next-action-logic';
import PreActionLogic from '@/service/ibizbook/pre-action-logic';
import FinishLogic from '@/service/ibizbook/finish-logic';
import InitDataLogic from '@/service/ibizbook/init-data-logic';
import PrintLogic from '@/service/ibizbook/print-logic';





/**
 * 图书服务对象基类
 * 基于 APP/src/service/%DE_PKGPATH%/%DE_PKGPATH%-service-base.ts.ftl 生成
 * @export
 * @class IBIZBOOKServiceBase
 * @extends {EntityServie}
 */
export default class IBIZBOOKServiceBase extends EntityService {

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

    /**
     * 初始化基础数据
     *
     * @memberof IBIZBOOKServiceBase
     */
    public initBasicData(){
        this.APPLYDEKEY ='ibizbook';
        this.APPDEKEY = 'ibizbookid';
        this.APPDENAME = 'ibizbooks';
        this.APPDETEXT = 'ibizbookname';
        this.APPNAME = 'web';
        this.SYSTEMNAME = 'demosys';
    }

// 实体接口

    /**
     * CheckKey接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof IBIZBOOKServiceBase
     */
    public async CheckKey(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
            let res:any = Http.getInstance().post(`/demosys/demoapi
/ibizbooks/${context.ibizbook}/checkkey`,data,isloading);
            return res;
    }

    /**
     * Create接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof IBIZBOOKServiceBase
     */
    public async Create(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        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(`/demosys/demoapi
/ibizbooks`,data,isloading);
        
        return res;
    }

    /**
     * Finish接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof IBIZBOOKServiceBase
     */
    public async Finish(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        let appLogic:FinishLogic = new FinishLogic({context:JSON.parse(JSON.stringify(context)),data:JSON.parse(JSON.stringify(data))});
        data = await appLogic.onExecute(context,data,isloading?true:false);
        let res:any ={status:200,data:data};
        return res;
    }

    /**
     * Get接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof IBIZBOOKServiceBase
     */
    public async Get(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
            let res:any = await Http.getInstance().get(`/demosys/demoapi
/ibizbooks/${context.ibizbook}`,isloading);
            
            return res;
    }

    /**
     * GetDraft接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof IBIZBOOKServiceBase
     */
    public async GetDraft(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        let res:any = await  Http.getInstance().get(`/demosys/demoapi
/ibizbooks/getdraft`,isloading);
        res.data.ibizbook = data.ibizbook;
        
        return res;
    }

    /**
     * Init接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof IBIZBOOKServiceBase
     */
    public async Init(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        let appLogic:InitDataLogic = new InitDataLogic({context:JSON.parse(JSON.stringify(context)),data:JSON.parse(JSON.stringify(data))});
        data = await appLogic.onExecute(context,data,isloading?true:false);
        let res:any ={status:200,data:data};
        return res;
    }

    /**
     * NextAction接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof IBIZBOOKServiceBase
     */
    public async NextAction(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        let appLogic:NextActionLogic = new NextActionLogic({context:JSON.parse(JSON.stringify(context)),data:JSON.parse(JSON.stringify(data))});
        data = await appLogic.onExecute(context,data,isloading?true:false);
        let res:any ={status:200,data:data};
        return res;
    }

    /**
     * PreAction接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof IBIZBOOKServiceBase
     */
    public async PreAction(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        let appLogic:PreActionLogic = new PreActionLogic({context:JSON.parse(JSON.stringify(context)),data:JSON.parse(JSON.stringify(data))});
        data = await appLogic.onExecute(context,data,isloading?true:false);
        let res:any ={status:200,data:data};
        return res;
    }

    /**
     * Remove接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof IBIZBOOKServiceBase
     */
    public async Remove(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
            let res:any = Http.getInstance().delete(`/demosys/demoapi
/ibizbooks/${context.ibizbook}`,isloading);
            return res;
    }

    /**
     * Save接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof IBIZBOOKServiceBase
     */
    public async Save(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        let masterData:any = {};
        Object.assign(data,masterData);
            let res:any = await  Http.getInstance().post(`/demosys/demoapi
/ibizbooks/${context.ibizbook}/save`,data,isloading);
            
            return res;
    }

    /**
     * Update接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof IBIZBOOKServiceBase
     */
    public async Update(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        let masterData:any = {};
        Object.assign(data,masterData);
            let res:any = await  Http.getInstance().put(`/demosys/demoapi
/ibizbooks/${context.ibizbook}`,data,isloading);
            
            return res;
    }
        public async UpdatePress(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
			let tempData:any = JSON.parse(JSON.stringify(data));
        if(Object.is(tempData.type,"武侠") || Object.is(tempData.type,"仙侠") ){
            tempData.press = "科幻文学出版社";
        }
        if(Object.is(tempData.type,"玄幻") || Object.is(tempData.type,"都市") ){
            tempData.press = "人民出版社";
        }
        return {"status":200,"data":tempData};
}

    /**
     * FetchDefault接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof IBIZBOOKServiceBase
     */
    public async FetchDefault(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        let tempData:any = JSON.parse(JSON.stringify(data));
        let res:any = Http.getInstance().get(`/demosys/demoapi
/ibizbooks/fetchdefault`,tempData,isloading);
        return res;
    }

    /**
     * searchDefault接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof IBIZBOOKServiceBase
     */
    public async searchDefault(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        let tempData:any = JSON.parse(JSON.stringify(data));
        return await Http.getInstance().post(`/demosys/demoapi
/ibizbooks/searchdefault`,tempData,isloading);
    }

    /**
     * Select接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof IBIZBOOKServiceBase
     */
    public async Select(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
            let res:any = Http.getInstance().get(`/demosys/demoapi
/ibizbooks/${context.ibizbook}/select`,isloading);
            
            return res;
    }
}