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/21 19:29
 */
object SystemApi {
    /** 配置实例 */
    private val opts: Opts by lazy {
        SSpringContextUtil.getBean(Opts::class.java) as Opts
    }

    /**
     * 系统API
     *
     * @param projectId     项目id
     * @return 返回结果
     */
    fun systemQuery(projectId: String): ArrayList<HashMap<String, Any?>> {
        val url = "${opts.dataPlatform}/instance/object/query?projectId=${projectId}"
        val jsonObject = JSONObject()
        val jsonObject2 = JSONObject()
        jsonObject2["classCode"] = "system"
        jsonObject2["valid"] = 1
        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?>>()
    }


}