package com.persagy.server.services

import cn.hutool.core.collection.CollUtil
import com.alibaba.fastjson.JSONObject
import com.persagy.legend.models.entities.DefClass
import com.persagy.legend.models.request.InstanceUrlParam
import com.persagy.server.Opts
import com.persagy.server.client.DmpDicClient
import com.persagy.server.util.AdmEntityTransferUtil
import com.sybotan.service.utils.SSpringContextUtil
import org.springframework.stereotype.Service

/**
 * 物理世界对象查询
 * @author:linhuili
 * @date:2021/10/19
 */
@Service
class DmpBaseService {

    /** 自定义 sql */
    private val rwdClient by lazy {
        SSpringContextUtil.getBean(DmpDicClient::class.java) as DmpDicClient
    }

    /**
     * 查询字典类型
     * @param params
     * @return
     */
    fun queryDictType(params: JSONObject?): List<DefClass>? {
        //封装基础查询参数
        val instanceUrlParam = InstanceUrlParam()
        instanceUrlParam.groupCode = Opts.groupCode
        instanceUrlParam.projectId = Opts.projectId
        //查询对象信息
        val dmpResult = rwdClient!!.queryDictObjectType(instanceUrlParam, params) ?: return ArrayList()
        if(CollUtil.isEmpty(dmpResult.data)){
            return ArrayList<DefClass>()
        }
        return AdmEntityTransferUtil.toAdmMultiEntity(dmpResult.data, null, DefClass::class.java)
    }




}