package com.persagy.server.syn.models.api.obj

import com.alibaba.fastjson.JSONObject
import com.persagy.base.utils.SHttpUtil
import com.persagy.server.syn.Opts
import com.persagy.server.syn.models.obj.MiddleGroundDataRespose
import com.persagy.service.utils.SSpringContextUtil

/**
 * 楼层 API - 中台
 *
 * @author wx  <zhangweixin@sagacloud.com>
 * @date  2020/10/20 10:18
 */
object FloorApi {
    /** 配置实例 */
    private val opts: Opts by lazy {
        SSpringContextUtil.getBean(Opts::class.java) as Opts
    } // opts

    /**
     * 获取楼层和建筑的关系
     *
     * @param projectId     项目 id
     * @param equipId       设备 id
     * @return 返回结果
     */
    fun floorInBuilding(projectId: String,floorId: String): ArrayList<HashMap<String, Any?>> {
        val url = "${opts.dataPlatform}/instance/relation/query?projectId=${projectId}"
        val jsonObject = JSONObject()
        val jsonObject2 =  JSONObject()
        jsonObject2["graphCode"] = "ArchSubset"
        jsonObject2["relCode"] = "Bd2Fl"
        jsonObject2["objFrom"] = floorId
        jsonObject["criteria"] = jsonObject2
        val postObject = SHttpUtil.postObject<MiddleGroundDataRespose>(url, jsonObject)
        if (postObject.result == "success"&&!postObject.data.isNullOrEmpty()) {
            return postObject.data!!
        }
        return ArrayList<HashMap<String, Any?>>()
    }
}