package com.ys.bdtp.cad.http

import com.ys.bdtp.cad.types.FloorData
import com.sybotan.base.utils.SHttpUtil
import com.sybotan.base.utils.SJsonUtil

/**
 * 下载数据
 *
 * @author 张维新
 */
object DownloadData {

    /**
     *  获取底图压缩文件
     *
     *  @param  url         请求数据文件路径
     *  @param  isGzip      是否为压缩格式
     */
    fun loadUrlFile(url: String, isGzip: Boolean = true): FloorData? {
        //Log.e("数据源","url = $url")
        var floorData: FloorData? = null
       return try {
            val json = if (isGzip) {
                SHttpUtil.getZipRequest(url)
            } else {
                SHttpUtil.getRequest(url)
            }
//            SJsonUtil.propertyNamingStrategy = PropertyNamingStrategy.PascalCase
            val d = SJsonUtil.fromJson<FloorData>(json)
            //Log.e("数据源", "json = ${d?.toJson()}")
           floorData = SJsonUtil.fromJson(json, FloorData::class.java)
           floorData
        } catch (e: Exception) {
            e.printStackTrace()
           floorData
        }
    } // Function loadUrlFile()

} // Object DownloadData