package com.persagy.server.services

import cn.hutool.core.collection.CollUtil
import com.alibaba.fastjson.JSONObject
import com.persagy.dmp.basic.utils.JsonNodeUtils
import com.persagy.dmp.digital.entity.ObjectDigital
import com.persagy.server.Opts
import com.persagy.server.client.DmpDicClient
import com.persagy.server.datacenter.models.entities.dict.EquipCategory
import com.persagy.server.datacenter.models.entities.task.EquipCategoryDic
import com.persagy.server.entities.request.InstanceUrlParam
import com.persagy.server.util.AdmEntityTransferUtil
import com.persagy.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<EquipCategoryDic>? {
        //封装基础查询参数
        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<EquipCategoryDic>()
        }
        return AdmEntityTransferUtil.toAdmMultiEntity(dmpResult.data, null, EquipCategoryDic::class.java)
    }

    /**
     * 查询设备类型
     */
    fun getEquipCategory(classCode:String): List<EquipCategory>? {
        //查询中台类型数据，2021.10.25日中心中台整合调整
        val param = JSONObject()
        val criteria = JSONObject()
        criteria["code"] = classCode!!
        param["criteria"] = criteria
        val dictTypes = queryDictType(param)
        return AdmEntityTransferUtil.toAdmMultiEntity(dictTypes, null, EquipCategory::class.java)

    }




}