// import {request} from "@/utils"
import request from "@/utils/request"
import qs from "qs"
import config from "@/commons"

const {api:{metaRepo}} =config

declare global {
    interface Navigator {
        msSaveBlob?: (blob: any, defaultName?: string) => boolean
    }
}

class sessionService{

    async getSystemDatabase(payload={},autotip=false){
        let result = await request({ url: `${metaRepo}/rest/tag/getDatabaseBySystemCode`, method: "get", data: payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaByParentId(payload={},autotip=false){
        let result = await request({ url: `${metaRepo}/rest/metadata/getChild`, method: "get", data: payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async searchMetaByPageWithOrder(param={params:{},data:[]},autotip=false){
        let result = await request({ url: `${metaRepo}/rest/query/findPage?${qs.stringify(param.params)}`, method: "post", data: param.data },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaByIds(param:any,autotip=false){
        const {data,params} = param
        let result = await request({ url: `${metaRepo}/rest/metadata/getByIdList`, method: "post", data: data,params },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }


    async getMetaCN(payload={},autotip=false){
        let result = await request({ url: `${metaRepo}/rest/model/getAttributes/${payload}`, method: "get", data: null },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaByModel(payload={},autotip=false){
        let result = await request({ url: `${metaRepo}/rest/query/findPageByModel`, method: "post", data: qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaByModelNew(payload={},autotip=false,hashrequest=false){
        let result = await request({ url: `${metaRepo}/rest/query/findByModel`, method: "post", data: qs.stringify(payload),hashrequest },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaByModelByAdmin(payload={},autotip=false,hashrequest=false){
        let result = await request({ url: `${metaRepo}/rest/admin/findByModel`, method: "post", data: qs.stringify(payload),hashrequest },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaByModelByUser(payload={},autotip=false,hashrequest=false){
        let result = await request({ url: `${metaRepo}/rest/user/findByModel`, method: "post", data: qs.stringify(payload),hashrequest },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaDisc(payload={},autotip=false){
        let result = await request({ url: `${metaRepo}/rest/query/findDic`, method: "post", data: qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaDiscNew(payload={},autotip=false,hashrequest=false){
        let result = await request({ url: `${metaRepo}/rest/query/searchDic`, method: "post", data: qs.stringify(payload),hashrequest },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getSearchType(payload={},autotip=false){
        let result = await request({ url: `${metaRepo}/rest/model/getQueryModelPath`, method: "get", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getModelTree(payload={},autotip=false){
        let result = await request({ url: `${metaRepo}/rest/model/tree`, method: "get", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getOtherSearchItems(payload={},autotip=false){
        let result = await request({ url: `${metaRepo}/rest/model/getParentBelowCatalog`, method: "get", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaChildren(payload={},autotip=false){
        let result = await request({ url: `${metaRepo}/rest/query/getSelection`, method: "get", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaSearhList(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/query/findPage`, method: "post", data:qs.stringify(payload.params) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getShowItems(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/model/getItemsByModel`, method: "get", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getModelAttrs(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/model/getAttributes/${payload}`, method: "get" },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaById(payload:any,params={},autotip=false){
        let result = await request({ url: `${metaRepo}/rest/metadata/get/${payload}`, method: "get",data:params },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaByIdAndDisplay(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/metadata/display/${payload}`, method: "get" },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getChildByParentIdAndModel(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/metadata/getChild`, method: "post",params:payload.params, data:payload.data },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async updateMeta(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/metadata/updateById`, method: "post",params:{...payload.params,isHttp:true}, data:payload.data },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async deleteMeta(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/metadata/delete/${payload.id}`, method: "post", },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async banchDeleteMeta(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/metadata/batchToDelete/${payload.id}`, method: "post", data:qs.stringify(payload.data)},autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async setParam(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/metadataAnalysis/setParam`, method: "post",params:payload.params, data:payload.data },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getDDL(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/download/generateDDL`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async downloadFile(payload:any,autotip=false){
        const {keys,params,data,type,name}=payload
        if(keys.length){
            await request({ url: `${metaRepo}/rest/download/exportList`, method: "postdownload", data:qs.stringify(data),responseType:'blob' },autotip).then((data:any)=>{
                let types = data.data.type
                var blob = new Blob([data.data], {type: types});
                let fileName:any = name
                let contentDisposition = data.headers['content-disposition'];
                if (contentDisposition) {
                    fileName = window.decodeURI(data.headers['content-disposition'].split('=')[1]);
                }
                console.log(typeof window.navigator?.msSaveBlob)
                if (typeof window.navigator?.msSaveBlob !== 'undefined') {
                    window.navigator.msSaveBlob(blob, fileName);
                }
                else {
                    var csvURL = window.URL.createObjectURL(blob);
                    console.log(csvURL)
                    var tempLink = document.createElement('a');
                    tempLink.href = csvURL;
                    tempLink.setAttribute('download', fileName);
                    tempLink.setAttribute('target', '_blank');
                    document.body.appendChild(tempLink);
                    tempLink.click();
                    document.body.removeChild(tempLink);
                }
            }).catch(error=>{
                console.log(error)
            })
        }else{
            window.open(`${metaRepo}/rest/download/export?${qs.stringify(params)}`)
        }
    }

    async downloadFileByUser(payload:any,autotip=false){
        const {keys,params,data,type,name}=payload
        if(keys.length){
            await request({ url: `${metaRepo}/rest/user/exportList`, method: "postdownload", data:qs.stringify(data),responseType:'blob' },autotip).then((data:any)=>{
                let types = data.data.type
                var blob = new Blob([data.data], {type: types});
                let fileName:any = name
                let contentDisposition = data.headers['content-disposition'];
                if (contentDisposition) {
                    fileName = window.decodeURI(data.headers['content-disposition'].split('=')[1]);
                }
                console.log(typeof window.navigator?.msSaveBlob)
                if (typeof window.navigator?.msSaveBlob !== 'undefined') {
                    window.navigator.msSaveBlob(blob, fileName);
                }
                else {
                    var csvURL = window.URL.createObjectURL(blob);
                    console.log(csvURL)
                    var tempLink = document.createElement('a');
                    tempLink.href = csvURL;
                    tempLink.setAttribute('download', fileName);
                    tempLink.setAttribute('target', '_blank');
                    document.body.appendChild(tempLink);
                    tempLink.click();
                    document.body.removeChild(tempLink);
                }
            }).catch(error=>{
                console.log(error)
            })
        }else{
            window.open(`${metaRepo}/rest/download/export?${qs.stringify(params)}`)
        }
    }

    async downloadFileByAdmin(payload:any,autotip=false){
        const {keys,params,data,type,name}=payload
        if(keys.length){
            await request({ url: `${metaRepo}/rest/admin/exportList`, method: "postdownload", data:qs.stringify(data),responseType:'blob' },autotip).then((data:any)=>{
                let types = data.data.type
                var blob = new Blob([data.data], {type: types});
                let fileName:any = name
                let contentDisposition = data.headers['content-disposition'];
                if (contentDisposition) {
                    fileName = window.decodeURI(data.headers['content-disposition'].split('=')[1]);
                }
                console.log(typeof window.navigator?.msSaveBlob)
                if (typeof window.navigator?.msSaveBlob !== 'undefined') {
                    window.navigator.msSaveBlob(blob, fileName);
                }
                else {
                    var csvURL = window.URL.createObjectURL(blob);
                    console.log(csvURL)
                    var tempLink = document.createElement('a');
                    tempLink.href = csvURL;
                    tempLink.setAttribute('download', fileName);
                    tempLink.setAttribute('target', '_blank');
                    document.body.appendChild(tempLink);
                    tempLink.click();
                    document.body.removeChild(tempLink);
                }
            }).catch(error=>{
                console.log(error)
            })
        }else{
            window.open(`${metaRepo}/rest/download/export?${qs.stringify(params)}`)
        }
    }

    async downloadDDL(payload:any,autotip=false){
        const {data,name}=payload
        request({ url: `${metaRepo}/rest/download/exportTxt`, method: "postdownload", data:qs.stringify(data),responseType:'blob' },autotip).then((data:any)=>{
            let types = data.data.type
            var blob = new Blob([data.data], {type: types});
            let fileName:any = name
            let contentDisposition = data.headers['content-disposition'];
            if (contentDisposition) {
                fileName = window.decodeURI(data.headers['content-disposition'].split('=')[1]);
            }
            if (typeof window.navigator.msSaveBlob !== 'undefined') {
                window.navigator.msSaveBlob(blob, fileName);
            }
            else {
                var csvURL = window.URL.createObjectURL(blob);
                var tempLink = document.createElement('a');
                tempLink.href = csvURL;
                tempLink.setAttribute('download', fileName);
                tempLink.setAttribute('target', '_blank');
                document.body.appendChild(tempLink);
                tempLink.click();
                document.body.removeChild(tempLink);
            }
        })
    }

    async getSystemChildren(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/metadata/getChildBySysAndPath`, method: "post",params:payload.params, data:payload.data },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getSystemChildrenByPage(payload:any,autotip=false,hashrequest=false){
        let result = await request({ url: `${metaRepo}/rest/metadata/getPageChildBySysAndPath`, method: "post",params:payload.params, data:payload.data,hashrequest },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }
    
    async getChildrenModel(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/model/getSubModels`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getChildByIdAndSys(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/query/getChildBySys`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getChildByIdAndSysByPage(payload:any,autotip=false,hashrequest=false){
        let result = await request({ url: `${metaRepo}/rest/metadata/getPageChild`, method: "post",params:payload.params,data:payload.data,hashrequest },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getSearchTop50(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/metadata/searchByModelAndName`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getSearchTop50ByAdmin(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/admin/searchByModelAndName`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getSearchTop50ByUser(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/user/searchByModelAndName`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async metaCompare(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/analysis/comparison`, method: "post",data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaOffset(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/query/getMetadataLocation`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaImportList(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/import/log`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaRelationList(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/import/listRelationLog`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async metaImportFile(payload:any,autotip=false){
        const {file,catalog,ignoreTechnical}=payload
        const data = new FormData();
        data.append('file',file);
        data.append('catalog',catalog);
        data.append('ignoreTechnical',ignoreTechnical);
        let result = await request({ url: `${metaRepo}/rest/import/add`, method: "post",data:data },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async metaRelationFile(payload:any,autotip=false){
        const {file,catalog}=payload
        const data = new FormData();
        data.append('file',file);
        data.append('catalog',catalog);
        let result = await request({ url: `${metaRepo}/rest/import/importRelation`, method: "post",data:data },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    // async downloadMetaRelation(payload:any,autotip=false){
    //     request({ url: `${metaRepo}/rest/download/exportRelation`, method: "postdownload", data:qs.stringify(payload),responseType:'blob' },autotip).then((data:any)=>{
    //         let types = data.data.type
    //         var blob = new Blob([data.data], {type: types});
    //         let fileName:any = name
    //         let contentDisposition = data.headers['content-disposition'];
    //         if (contentDisposition) {
    //             fileName = window.decodeURI(data.headers['content-disposition'].split('=')[1]);
    //         }
    //         if (typeof window.navigator.msSaveBlob !== 'undefined') {
    //             window.navigator.msSaveBlob(blob, fileName);
    //         }
    //         else {
    //             var csvURL = window.URL.createObjectURL(blob);
    //             var tempLink = document.createElement('a');
    //             tempLink.href = csvURL;
    //             tempLink.setAttribute('download', fileName);
    //             tempLink.setAttribute('target', '_blank');
    //             document.body.appendChild(tempLink);
    //             tempLink.click();
    //             document.body.removeChild(tempLink);
    //         }
    //     })
    // }

    async downloadMetaRelation(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/download/exportRelation`, method: "post", data:qs.stringify(payload),responseType:'blob' },autotip).then((data:any)=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaImportLogById(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/import/getLog`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getRelationImportLogById(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/import/getRelationLog`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getModelsCnName(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/model/getModelCnName`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaByIdsWithoutCatalog(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/metadata/getByIds`, method: "post",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getStringDiff(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/version/getHighLightDifferent`, method: "post",data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async setUpAndDown(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/metadata/seq`, method: "post",data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getSubModel(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/model/getSubModel`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async createMeta(payload:any,autotip=false){
        const {parentId,model,data} = payload
        let result = await request({ url: `${metaRepo}/rest/metadata/add/${parentId}/${model}`, method: "post",data:data,params:{isHttp:true} },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async countTotal(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/statistics/groupByClass`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async systemTotal(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/statistics/countBySys`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async countRule(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/rule/count`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async ruletop10(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/match/top10`, method: "post",data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getDataSourceCount(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/statistics/heatMap`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async countSystem(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/statistics/treeSystemCount`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async countMetaNode(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/statistics/treeNodeCount`, method: "post",data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async countMetaDatabaseNode(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/statistics/treeSchemaCount`, method: "post",data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async countModelNode(payload:any,autotip=false){
        const {data,params} = payload
        let result = await request({ url: `${metaRepo}/rest/statistics/treeNodeCountByModels`, method: "post",data,params },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async checkMetaSso(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/metadata/readable/${payload}`, method: "get" },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getSystemChild(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/query/getSysChild`, method: "get",data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getAdminModalTitle(payload={},autotip=false){
        let result = await request({ url: `${metaRepo}/rest/admin/getDisplayTitle`, method: "get", data: payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async saveAdminModalTitle(payload:any,autotip=false){
        const {params,data} = payload
        let result = await request({ url: `${metaRepo}/rest/admin/setDisplayTitle`, method: "post", data,params },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getUserModalTitle(payload={},autotip=false){
        let result = await request({ url: `${metaRepo}/rest/user/getDisplayTitle`, method: "get", data: payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async saveUserModalTitle(payload:any,autotip=false){
        const {params,data} = payload
        let result = await request({ url: `${metaRepo}/rest/user/setDisplayTitle`, method: "post", data,params },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getCompareMeta(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/user/modelComparison`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getModelColumnByKeyword(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/model/getAttributesByKeyword`, method: "get", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async saveModelColumnInfo(payload:any,autotip=false){
        const {params,data} = payload
        let result = await request({ url: `${metaRepo}/rest/model/saveAttribute`, method: "post", data,params },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaChangeTotal(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/changeStatistics`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async downloadMetaChange(payload:any,autotip=false){
        await request({ url: `${metaRepo}/rest/version/export`, method: "postdownload", data:qs.stringify(payload),responseType:'blob' },autotip).then((data:any)=>{
            let types = data.data.type
            var blob = new Blob([data.data], {type: types});
            let fileName:any = ''
            let contentDisposition = data.headers['content-disposition'];
            if (contentDisposition) {
                fileName = window.decodeURI(data.headers['content-disposition'].split('=')[1]);
            }
            if (typeof window.navigator.msSaveBlob !== 'undefined') {
                window.navigator.msSaveBlob(blob, fileName);
            }
            else {
                var csvURL = window.URL.createObjectURL(blob);
                var tempLink = document.createElement('a');
                tempLink.href = csvURL;
                tempLink.setAttribute('download', fileName);
                tempLink.setAttribute('target', '_blank');
                document.body.appendChild(tempLink);
                tempLink.click();
                document.body.removeChild(tempLink);
            }
        })
    }

    async getMetaIslandTotal(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/islandAnalysis`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getIslandInfoSearch(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/islandAnalysisSearch`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async downloadMetaIsland(payload:any,autotip=false){
        await request({ url: `${metaRepo}/rest/operate/exportIslandAnalysis`, method: "postdownload", data:qs.stringify(payload),responseType:'blob' },autotip).then((data:any)=>{
            let types = data.data.type
            var blob = new Blob([data.data], {type: types});
            let fileName:any = ''
            let contentDisposition = data.headers['content-disposition'];
            if (contentDisposition) {
                fileName = window.decodeURI(data.headers['content-disposition'].split('=')[1]);
            }
            if (typeof window.navigator.msSaveBlob !== 'undefined') {
                window.navigator.msSaveBlob(blob, fileName);
            }
            else {
                var csvURL = window.URL.createObjectURL(blob);
                var tempLink = document.createElement('a');
                tempLink.href = csvURL;
                tempLink.setAttribute('download', fileName);
                tempLink.setAttribute('target', '_blank');
                document.body.appendChild(tempLink);
                tempLink.click();
                document.body.removeChild(tempLink);
            }
        })
    }

    async getModelChangeInfo(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/model/getChangeRecord`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getDayChange(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/get30DaySum`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getDayChangeBySize(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/getDataSize30DaySum`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getYearChange(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/get1YearSum`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getYearChangeBySize(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/getDataSize1YearSum`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMonthChange(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/getByMonthSum`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMonthChangeBySize(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/getDataSizeByMonthSum`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getDataChangeInfoTable(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/dataRowSearch`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getDataChangeInfoTableBySize(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/dataSizeSearch`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getDayChangeById(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/get30DaySumByType`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getDayChangeByIdBySize(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/getDataSize30DaySumByType`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getYearChangeById(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/get1YearSumByType`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getYearChangeByIdBySize(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/getDataSize1YearSumByType`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMonthChangeById(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/getByMonthSumByType`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMonthChangeByIdBySize(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/getDataSizeByMonthSumByType`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getModelHistory(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/model/getHistoryByModel`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async downloadMetaIslandModelChange(payload:any,autotip=false){
        await request({ url: `${metaRepo}/rest/model/exportMetaModelChangeRecord`, method: "postdownload", data:payload,responseType:'blob' },autotip).then((data:any)=>{
            let types = data.data.type
            var blob = new Blob([data.data], {type: types});
            let fileName:any = ''
            let contentDisposition = data.headers['content-disposition'];
            if (contentDisposition) {
                fileName = window.decodeURI(data.headers['content-disposition'].split('=')[1]);
            }
            if (typeof window.navigator.msSaveBlob !== 'undefined') {
                window.navigator.msSaveBlob(blob, fileName);
            }
            else {
                var csvURL = window.URL.createObjectURL(blob);
                var tempLink = document.createElement('a');
                tempLink.href = csvURL;
                tempLink.setAttribute('download', fileName);
                tempLink.setAttribute('target', '_blank');
                document.body.appendChild(tempLink);
                tempLink.click();
                document.body.removeChild(tempLink);
            }
        })
    }

    async downloadMetaDataChange(payload:any,autotip=false){
        await request({ url: `${metaRepo}/rest/operate/exportDataRowSearch`, method: "postdownload", data:qs.stringify(payload),responseType:'blob' },autotip).then((data:any)=>{
            let types = data.data.type
            var blob = new Blob([data.data], {type: types});
            let fileName:any = ''
            let contentDisposition = data.headers['content-disposition'];
            if (contentDisposition) {
                fileName = window.decodeURI(data.headers['content-disposition'].split('=')[1]);
            }
            if (typeof window.navigator.msSaveBlob !== 'undefined') {
                window.navigator.msSaveBlob(blob, fileName);
            }
            else {
                var csvURL = window.URL.createObjectURL(blob);
                var tempLink = document.createElement('a');
                tempLink.href = csvURL;
                tempLink.setAttribute('download', fileName);
                tempLink.setAttribute('target', '_blank');
                document.body.appendChild(tempLink);
                tempLink.click();
                document.body.removeChild(tempLink);
            }
        })
    }

    async downloadMetaDataChangeBySize(payload:any,autotip=false){
        await request({ url: `${metaRepo}/rest/operate/exportDataSizeSearch`, method: "postdownload", data:qs.stringify(payload),responseType:'blob' },autotip).then((data:any)=>{
            let types = data.data.type
            var blob = new Blob([data.data], {type: types});
            let fileName:any = ''
            let contentDisposition = data.headers['content-disposition'];
            if (contentDisposition) {
                fileName = window.decodeURI(data.headers['content-disposition'].split('=')[1]);
            }
            if (typeof window.navigator.msSaveBlob !== 'undefined') {
                window.navigator.msSaveBlob(blob, fileName);
            }
            else {
                var csvURL = window.URL.createObjectURL(blob);
                var tempLink = document.createElement('a');
                tempLink.href = csvURL;
                tempLink.setAttribute('download', fileName);
                tempLink.setAttribute('target', '_blank');
                document.body.appendChild(tempLink);
                tempLink.click();
                document.body.removeChild(tempLink);
            }
        })
    }

    async createSystem(payload:any,autotip=false){
        const {params,data} = payload
        let result = await request({ url: `${metaRepo}/rest/system/add`, method: "post", data,params:{...params,isHttp:true} },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getBtnAdmit(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/auth/getAllowButtons`, method: "get", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getModelColumnByAuth(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/model/getAttributeAuth`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async saveModelColumnByAuth(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/model/saveAttributeAuth`, method: "post", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getAuthBySystem(payload:any,autotip=false){
        const {params,data} = payload
        let result = await request({ url: `${metaRepo}/rest/auth/getMateDataAuthSys`, method: "post", data,params },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getAuthByParentId(payload:any,autotip=false){
        const {params,data} = payload
        let result = await request({ url: `${metaRepo}/rest/auth/getMateDataAuthChild`, method: "post", data,params },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async saveMetaAdmitTable(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/auth/saveMateDataAuth`, method: "post", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaMatchStandard(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/standardStatistics`, method: "get", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaMatchStandardInfoSearch(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/operate/standardStatistics`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaByPath(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/metadata/getByPath`, method: "get", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async downloadMetaMetch(payload:any,autotip=false){
        await request({ url: `${metaRepo}/rest/operate/exportStandard`, method: "postdownload", data:qs.stringify(payload),responseType:'blob' },autotip).then((data:any)=>{
            let types = data.data.type
            var blob = new Blob([data.data], {type: types});
            let fileName:any = ''
            let contentDisposition = data.headers['content-disposition'];
            if (contentDisposition) {
                fileName = window.decodeURI(data.headers['content-disposition'].split('=')[1]);
            }
            if (typeof window.navigator.msSaveBlob !== 'undefined') {
                window.navigator.msSaveBlob(blob, fileName);
            }
            else {
                var csvURL = window.URL.createObjectURL(blob);
                var tempLink = document.createElement('a');
                tempLink.href = csvURL;
                tempLink.setAttribute('download', fileName);
                tempLink.setAttribute('target', '_blank');
                document.body.appendChild(tempLink);
                tempLink.click();
                document.body.removeChild(tempLink);
            }
        })
    }

    async getCatalogInfoById(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/query/getCatalog`, method: "get", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async checkChildTypeByType(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/model/getSubModels`, method: "get", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }
}

export default new sessionService();