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



/**
 * 组织地址服务对象基类
 *
 * @export
 * @class HROrgAddressServiceBase
 * @extends {EntityServie}
 */
export default class HROrgAddressServiceBase extends EntityService {

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

    /**
     * 初始化基础数据
     *
     * @memberof HROrgAddressServiceBase
     */
    public initBasicData(){
        this.APPLYDEKEY ='hrorgaddress';
        this.APPDEKEY = 'hrorgaddressid';
        this.APPDENAME = 'hrorgaddresses';
        this.APPDETEXT = 'hrorgaddressname';
        this.APPNAME = 'pim';
        this.SYSTEMNAME = 'ibizhumanresources';
    }

// 实体接口

    /**
     * Select接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof HROrgAddressServiceBase
     */
    public async Select(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.hroperationunit && context.hrorgaddress){
            let res:any = Http.getInstance().get(`/hroperationunits/${context.hroperationunit}/hrorgaddresses/${context.hrorgaddress}/select`,isloading);
            
            return res;
        }
        if(context.hrlegal && context.hrorgaddress){
            let res:any = Http.getInstance().get(`/hrlegals/${context.hrlegal}/hrorgaddresses/${context.hrorgaddress}/select`,isloading);
            
            return res;
        }
            let res:any = Http.getInstance().get(`/hrorgaddresses/${context.hrorgaddress}/select`,isloading);
            
            return res;
    }

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

    /**
     * Update接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof HROrgAddressServiceBase
     */
    public async Update(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.hroperationunit && context.hrorgaddress){
            let masterData:any = {};
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().put(`/hroperationunits/${context.hroperationunit}/hrorgaddresses/${context.hrorgaddress}`,data,isloading);
            
            return res;
        }
        if(context.hrlegal && context.hrorgaddress){
            let masterData:any = {};
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().put(`/hrlegals/${context.hrlegal}/hrorgaddresses/${context.hrorgaddress}`,data,isloading);
            
            return res;
        }
        let masterData:any = {};
        Object.assign(data,masterData);
            let res:any = await  Http.getInstance().put(`/hrorgaddresses/${context.hrorgaddress}`,data,isloading);
            
            return res;
    }

    /**
     * Remove接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof HROrgAddressServiceBase
     */
    public async Remove(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.hroperationunit && context.hrorgaddress){
            let res:any = Http.getInstance().delete(`/hroperationunits/${context.hroperationunit}/hrorgaddresses/${context.hrorgaddress}`,isloading);
            return res;
        }
        if(context.hrlegal && context.hrorgaddress){
            let res:any = Http.getInstance().delete(`/hrlegals/${context.hrlegal}/hrorgaddresses/${context.hrorgaddress}`,isloading);
            return res;
        }
            let res:any = Http.getInstance().delete(`/hrorgaddresses/${context.hrorgaddress}`,isloading);
            return res;
    }

    /**
     * Get接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof HROrgAddressServiceBase
     */
    public async Get(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.hroperationunit && context.hrorgaddress){
            let res:any = await Http.getInstance().get(`/hroperationunits/${context.hroperationunit}/hrorgaddresses/${context.hrorgaddress}`,isloading);
            
            return res;
        }
        if(context.hrlegal && context.hrorgaddress){
            let res:any = await Http.getInstance().get(`/hrlegals/${context.hrlegal}/hrorgaddresses/${context.hrorgaddress}`,isloading);
            
            return res;
        }
            let res:any = await Http.getInstance().get(`/hrorgaddresses/${context.hrorgaddress}`,isloading);
            
            return res;
    }

    /**
     * GetDraft接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof HROrgAddressServiceBase
     */
    public async GetDraft(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.hroperationunit && true){
            let res:any = await Http.getInstance().get(`/hroperationunits/${context.hroperationunit}/hrorgaddresses/getdraft`,isloading);
            res.data.hrorgaddress = data.hrorgaddress;
            
            return res;
        }
        if(context.hrlegal && true){
            let res:any = await Http.getInstance().get(`/hrlegals/${context.hrlegal}/hrorgaddresses/getdraft`,isloading);
            res.data.hrorgaddress = data.hrorgaddress;
            
            return res;
        }
        let res:any = await  Http.getInstance().get(`/hrorgaddresses/getdraft`,isloading);
        res.data.hrorgaddress = data.hrorgaddress;
        
        return res;
    }

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

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

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