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

/**
 * 数据中台至数据中心
 *
 * @author wx  <zhangweixin@sagacloud.com>
 * @date  2020/10/18 10:15
 */
object ProjectApi {

    /** 配置实例 */
    private val opts: Opts by lazy {
        SSpringContextUtil.getBean(Opts::class.java) as Opts
    }

    /**
     * 根据集团查询集团下所有的项目
     *
     * @param projectId     集团编码
     * @return
     */
    fun projectQueryGroup(id: String): ArrayList<HashMap<String, Any?>> {
        val url = "${opts.dataPlatform}/rwd/instance/object/query?groupCode=${id}"
        val jsonObject = JSONObject()
        val jsonObject2 = JSONObject()
        jsonObject2["classCode"] = "project"
        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?>>()
    }

    /**
     * 根据集团查询集团下所有的项目
     *
     * @param projectId     集团编码
     * @return
     */
    fun projectQuery(projectId: String): ArrayList<HashMap<String, Any?>> {
        val url = "${opts.dataPlatform}/rwd/instance/object/query?projectId=${projectId}"
        val jsonObject = JSONObject()
        val jsonObject2 = JSONObject()
        jsonObject2["classCode"] = "project"
        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?>>()
    }


}