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



/**
 * 工单服务对象基类
 *
 * @export
 * @class EAMWorkOrderServiceBase
 * @extends {EntityServie}
 */
export default class EAMWorkOrderServiceBase extends EntityService {

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

    /**
     * 初始化基础数据
     *
     * @memberof EAMWorkOrderServiceBase
     */
    public initBasicData(){
        this.APPLYDEKEY ='eamworkorder';
        this.APPDEKEY = 'workorderid';
        this.APPDENAME = 'eamworkorders';
        this.APPDETEXT = 'workordername';
        this.APPNAME = 'assetmanagement';
        this.SYSTEMNAME = 'ibizassetmanagement';
    }

// 实体接口

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

    /**
     * Create接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof EAMWorkOrderServiceBase
     */
    public async Create(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.eamapply && 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(`/eamapplies/${context.eamapply}/eamworkorders`,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(`/eamworkorders`,data,isloading);
        
        return res;
    }

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

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

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

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

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

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

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