package com.persagy.revit.controllers.modelFile

import com.persagy.base.extensions.toJson
import com.persagy.revit.models.config.MyProperties
import com.persagy.revit.models.jsonAnalyzer.AllComponents
import com.persagy.revit.models.jsonAnalyzer.BaseObj
import com.persagy.revit.services.CommonService
import com.persagy.revit.services.http.HttpService
import com.persagy.revit.services.json.JSONAnalyzerService
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
 * @author Cainga
 * @date 2020/12/8 9:35
 */
@Tag(name = "测试接口")
@RestController
@RequestMapping("/test")
open class TestController {

    @Autowired
    private val prop: MyProperties? = null

    @Autowired
    lateinit var jsonAnalyzerService : JSONAnalyzerService

    @Autowired
    lateinit var myProperties : MyProperties

    /**
     * 测试
     */
    @Operation(summary = "模型文件json数据导入", description =  "")
    @GetMapping(value = ["/test"])
    fun test11(){


        "a67ac1ec8fef11ea9dfea9a679dda25a"
        val id = "03e4dbc2192011ebb7c2517abf7cc6d61"
        var jsonData : BaseObj<AllComponents>?
        var size = 0L
        try {
            val url = CommonService.getExportJSONDownloadUrl(id, myProperties)
            println(url)
//            size = CommonService.getRemoteHttpFileSize(url)
            val fileStream = HttpService.getInputStream(url)
            //解析json
            jsonData = jsonAnalyzerService.analyzeJsonzFile(fileStream)

//            jsonData = JSONObject.parseObject(josn,BaseObj<AllComponents>().javaClass)

            val importResult = jsonAnalyzerService.importModelData(jsonData!!, "")
            println(importResult.toJson())
        }catch (e : Exception){
            println(e.message)
        }

    }
}