/*
 * *********************************************************************************************************************
 *
 *          !!
 *        .F88X
 *        X8888Y
 *      .}888888N;
 *        i888888N;        .:!              .I$WI:
 *          R888888I      .'N88~            i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
 *          .R888888I    .;N8888~          .X8'  "8I.!,/8"  !%NY8`"8I8~~8>,88I
 *            +888888N;  .8888888Y                                  "&&8Y.}8,
 *            ./888888N;  .R888888Y        .'}~    .>}'.`+>  i}!    "i'  +/'  .'i~  !11,.:">,  .~]!  .i}i
 *              ~888888%:  .I888888l      .]88~`1/iY88Ii+1'.R$8$8]"888888888>  Y8$  W8E  X8E  W8888'188Il}Y88$*
 *              18888888    E8888881    .]W%8$`R8X'&8%++N8i,8N%N8+l8%`  .}8N:.R$RE%N88N%N$K$R  188,FE$8%~Y88I
 *            .E888888I  .i8888888'      .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
 *            8888888I  .,N888888~        ~88i"8W,!N8*.I88.}888%F,i$88"F88"  888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
 *          i888888N'      I888Y          ]88;/EX*IFKFK88X  K8R  .l8W  88Y  ~88}'88E&%8W.X8N``]88!.$8K  .:W8I
 *        .i888888N;        I8Y          .&8$  .X88!  i881.:%888>I88  ;88]  +88+.';;;;:.Y88X  18N.,88l  .+88/
 *      .:R888888I
 *      .&888888I                                          Copyright (c) 2009-2020.  博锐尚格科技股份有限公司
 *        ~8888'
 *        .!88~                                                                     All rights reserved.
 *
 * *********************************************************************************************************************
 */

package com.persagy.server.syn

import com.alibaba.fastjson.JSONArray
import com.alibaba.fastjson.JSONObject
import com.persagy.service.utils.SSpringContextUtil
import org.slf4j.LoggerFactory
import org.springframework.web.client.RestTemplate

/**
 * 配置文件
 *
 * @author wx  <zhangweixin@sagacloud.com>
 * @date  2020/11/1 21:45
 */
object Configure {
    /** 日志 */
    private val logger = LoggerFactory.getLogger(Configure::class.java)

    /** 配置实例 */
     val opts: Opts by lazy {
        SSpringContextUtil.getBean(Opts::class.java) as Opts
    }
    /** 获取配置文件的服务名 */
     val serviceNameConfig by lazy {
        SSpringContextUtil.getBean(ServiceNameConfig::class.java) as ServiceNameConfig
    }
    /** 获取配置自定义属性 */
     val customProperties by lazy {
        SSpringContextUtil.getBean(CustomProperties::class.java) as CustomProperties
    }
    /** Rest服务 */
     val restTemplate by lazy {
        SSpringContextUtil.getBean(RestTemplate::class.java) as RestTemplate
    }

    /** 标记 */
    var flag: Boolean = true
    var messageTypeDataCerten = 1
    /** 数据中台消息之创建 */
    const val RWDCREATE = "instanceObjectCreate"
    /** 数据中台消息之修改 */
    const val RWDUPDATE = "instanceObjectUpdate"
    /** 数据中台消息之删除 */
    const val RWDDELETE = "instanceObjectDelete"
    /** 数据中台创建关系 */
    const val RELATIONCREATE = "instanceRelationCreate"
    /** 数据中台删除关系 */
    const val RELATIONDELETE = "instanceRelationDelete"

    /** 对象类型 - 项目 */
    const val PROJECT = "project"
    /** 对象类型 - 建筑 */
    const val BUILDING = "building"
    /** 对象类型 - 楼层 */
    const val FLOOR = "floor"
    /** 对象类型 - 设备 */
    const val EQUIPMENT = "equipment"
    /** 对象类型 - 空间 */
    const val SPACE = "space"
    /** 对象类型 - 竖井 */
    const val SHAFT = "shaft"
    /** 对象类型 - 系统 */
    const val SYSTEM = "system"
    /** 对象类型 - 部件 */
    const val COMPONENT = "component"
    /** 租户 */
    const val VOTN = "VOTn"

    /** 创建 */
    const val CREATE = "create"
    /** 修改 */
    const val UPDATE = "update"
    /** 删除 */
    const val DELETE = "delete"


    /**
     * 创建关系列表
     *
     * @param graphCode     图类型编码
     * @param relCode       边类型编码
     * @param objFrom       主对象 id
     * @param objTo         从对象 id
     */
    fun toJsonObjArray(graphCode: String, relCode: String, objFrom: String, objTo: String,relValue: String? = null): JSONArray {
        /** 列表 */
        val jsonArray = JSONArray()
        /** 对象 */
        val jsonObject = JSONObject()
        /** 图类型编码 */
        jsonObject["graphCode"] = graphCode
        /** 边类型编码 */
        jsonObject["relCode"] = relCode
        /** 主对象 id */
        jsonObject["objFrom"] = objFrom
        /** 从对象 id */
        jsonObject["objTo"] = objTo
        if (!relValue.isNullOrEmpty()) {
            /** 边类型属性， */
            jsonObject["relValue"] = objTo
        }
        /** 添加到列表 */
        jsonArray.add(jsonObject)
        return jsonArray
    }

    /**
     * 关系列表
     *
     * @param graphCode     图类型编码
     * @param relCode       边类型编码
     * @param objFrom       主对象 id
     * @param objTo         从对象 id
     */
    fun toJsonObjList(graphCode: String, relCode: String, objFrom: String, objTos: ArrayList<String>,type: String? = null): JSONArray {
        /** 列表 */
        val jsonArray = JSONArray()
        for (id in objTos){
            /** 对象 */
            val jsonObject = JSONObject()
            /** 图类型编码 */
            jsonObject["graphCode"] = graphCode
            /** 边类型编码 */
            jsonObject["relCode"] = relCode
            /** 主对象 id */
            jsonObject["objFrom"] = objFrom
            /** 从对象 id */
            jsonObject["objTo"] = id
            if (!type.isNullOrEmpty()) {
                jsonObject["relValue"] = type
            }
            /** 添加到列表 */
            jsonArray.add(jsonObject)
        }
        return jsonArray
    }

    /**
     * 关系列表
     *
     * @param graphCode     图类型编码
     * @param relCode       边类型编码
     * @param objFroms      主对象列表 id
     * @param objTo         从对象 id
     */
    fun toJsonObjFromList(graphCode: String, relCode: String, objFroms: ArrayList<String>, objTo: String,type: String? = null): JSONArray {

        /** 列表 */
        val jsonArray = JSONArray()
        for (id in objFroms){
            /** 对象 */
            val jsonObject = JSONObject()
            /** 图类型编码 */
            jsonObject["graphCode"] = graphCode
            /** 边类型编码 */
            jsonObject["relCode"] = relCode
            /** 主对象 id */
            jsonObject["objFrom"] = id
            /** 从对象 id */
            jsonObject["objTo"] = objTo
            if (!type.isNullOrEmpty()) {
                jsonObject["relValue"] = type
            }

            /** 添加到列表 */
            jsonArray.add(jsonObject)
        }
        return jsonArray
    }

    /**
     * 创建关系列表
     *
     * @param graphCode     图类型编码
     * @param relCode       边类型编码
     * @param objFrom       主对象 id
     * @param objTo         从对象 id
     */
    fun toJsonObj(graphCode: String, relCode: String, objFrom: String?, objTo: String?): JSONObject {
        /** 对象 */
        val jsonObject1 = JSONObject()
        /** 对象 */
        val jsonObject = JSONObject()
        /** 图类型编码 */
        jsonObject["graphCode"] = graphCode
        /** 边类型编码 */
        jsonObject["relCode"] = relCode
        if (!objFrom.isNullOrEmpty()){
            /** 主对象 id */
            jsonObject["objFrom"] = objFrom
        }
        if (!objTo.isNullOrEmpty()){
            /** 从对象 id */
            jsonObject["objTo"] = objTo
        }
        /** 添加到对象 */
        jsonObject1["criteria"] = jsonObject
        return jsonObject1
    }

    /**
     * 关系对照
     */
    fun relContrast(graphCode: String,type: String): String {
        if (graphCode == "SpaceNeighborhood"&&type == "None") {
                return "sp2sp_SpaceNeighborhood_1"
        } else if (graphCode == "SpaceNeighborhood"&&type == "Door") {
            return "sp2sp_SpaceNeighborhood_2"
        } else if (graphCode == "SpaceNeighborhood"&&type == "Window") {
                return "sp2sp_SpaceNeighborhood_3"
        } else if (graphCode == "SpaceNeighborhood"&&type == "DoorWindow") {
            return "sp2sp_SpaceNeighborhood_4"
        } else if (graphCode == "SpaceNeighborhood"&&type == "Connect") {
            return "sp2sp_SpaceNeighborhood_5"
        } else if (graphCode == "TrafficNetwork"&&type == "Normal"){
            return "sp2sp_TrafficNetwork_1"
        }else if (graphCode == "TrafficNetwork"&&type == "FFOpen"){
            return "sp2sp_TrafficNetwork_2"
        } else if (graphCode == "TrafficNetwork"&&type == "FFClose"){
            return "sp2sp_TrafficNetwork_3"
         } else if (graphCode == "ConvectionNetwork"&&type == "Natural"){
            return "sp2sp_ConvectionNetwork_1"
        } else if (graphCode == "ConvectionNetwork"&&type == "OnewayMech"){
            return "sp2sp_ConvectionNetwork_2"
        } else if (graphCode == "ConvectionNetwork"&&type == "MixMech"){
            return "sp2sp_ConvectionNetwork_3"
        } else if (graphCode == "RadiationNetwork"&&type == "Connect"){
            return "sp2sp_RadiationNetwork_1"
        } else if (graphCode == "RadiationNetwork"&&type == "Transparent"){
            return "sp2sp_RadiationNetwork_2"
         }else {
            return ""
        }
    }

    /**
     * 设备和设备的关系
     */
    fun relContrastEq(graphCode: String,type: String): String{
        if (graphCode == "LUDistribution"&&type == "Normal") {
            /** 低压配电普通连接 */
            return "eq2eq_LUDistribution_1"
        } else if (graphCode == "LUDistribution"&&type == "Backup") {
            /** 低压配电互备连接 */
            return "eq2eq_LUDistribution_2"
        } else if (graphCode == "HUDistribution"&&type == "Normal") {
            /** 高压变配电普通连接 */
            return  "eq2eq_HUDistribution_1"
        } else if (graphCode == "HUDistribution"&&type == "Backup") {
            /** 高压变配电互备连接 */
            return "eq2eq_HUDistribution_2"
        } else if (graphCode == "ChillWaterLoop"&&type == "Supply") {
            /** 空调冷冻水供水 */
            return "eq2eq_ChillWaterLoop_1"
        } else if (graphCode == "ChillWaterLoop"&&type == "Return") {
            /** 空调冷冻水回水 */
            return "eq2eq_ChillWaterLoop_2"
        } else if (graphCode == "ChillWaterLoop"&&type == "Bypass") {
            /** 空调冷冻水旁通 */
            return "eq2eq_ChillWaterLoop_3"
        } else if (graphCode == "ChillWaterLoop"&&type == "Fill") {
            /** 空调冷冻水补水 */
            return "eq2eq_ChillWaterLoop_4"
        } else if (graphCode == "CoolingWaterLoop"&&type == "Supply") {
            /** 空调冷却水供水 */
            return "eq2eq_CoolingWaterLoop_1"
        } else if (graphCode == "CoolingWaterLoop"&&type == "Return") {
            /** 空调冷却水回水 */
            return "eq2eq_CoolingWaterLoop_2"
        } else if (graphCode == "CoolingWaterLoop"&&type == "Bypass") {
            /** 空调冷却水旁通 */
            return "eq2eq_CoolingWaterLoop_3"
        } else if (graphCode == "CoolingWaterLoop"&&type == "Fill") {
            /** 空调冷冻水补水 */
            return "eq2eq_ChillWaterLoop_4"
        } else if (graphCode == "HeatWaterLoop"&&type == "Supply") {
            /** 采暖水供水 */
            return "eq2eq_HeatWaterLoop_1"
        } else if (graphCode == "HeatWaterLoop"&&type == "Return") {
            /** 采暖水回水 */
            return "eq2eq_HeatWaterLoop_2"
        } else if (graphCode == "HeatWaterLoop"&&type == "Bypass") {
            /** 采暖水旁通 */
            return "eq2eq_HeatWaterLoop_3"
        } else if (graphCode == "HeatWaterLoop"&&type == "Fill") {
            /** 采暖水补水 */
            return "eq2eq_HeatWaterLoop_4"
        } else if (graphCode == "CondWaterNetwork"&&type == "Discharge") {
            /** 空调冷凝水排水 */
            return "eq2eq_CondWaterNetwork_1"
        } else if (graphCode == "ACAirNetwork"&&type == "Supply") {
            /** 空调送风 */
            return "eq2eq_ACAirNetwork_1"
        } else if (graphCode == "ACAirNetwork"&&type == "Return") {
            /** 空调回风 */
            return "eq2eq_ACAirNetwork_2"
        } else if (graphCode == "ACAirNetwork"&&type == "Discharge") {
            /** 空调排风 */
            return "eq2eq_ACAirNetwork_3"
        } else if (graphCode == "FreshAirNetwork"&&type == "Fresh") {
            /** 新风送风 */
            return "eq2eqFreshAirNetwork_1"
        } else if (graphCode == "VentNetwork"&&type == "Supply") {
            /** 通风送风 */
            return "eq2eq_VentNetwork_1"
        } else if (graphCode == "VentNetwork"&&type == "Discharge") {
            /** 通风排风 */
            return "eq2eq_VentNetwork_2"
        } else if (graphCode == "VentNetwork"&&type == "Uncertain") {
            /** 通风不确定 */
            return "eq2eq_VentNetwork_3"
        } else if (graphCode == "VRFNetwork"&&type == "SupplyReturn") {
            /** 多联机供回制冷剂 */
            return "eq2eq_VRFNetwork_1"
        } else if (graphCode == "DomesticWaterNetwork"&&type == "Supply") {
            /** 生活给水供水 */
            return "eq2eq_SupplyWaterNetwork_1"
        } else if (graphCode == "DomesticWaterNetwork"&&type == "Bypass") {
            /** 生活给水旁通 */
            return "eq2eq_SupplyWaterNetwork_2"
        } else if (graphCode == "DrainingWaterNetwork"&&type == "Discharge") {
            /** 污水排水 */
            return "eq2eq_DrainingWaterNetwork_1"
        } else if (graphCode == "DrainingWaterNetwork"&&type == "Bypass") {
            /** 污水旁通 */
            return "eq2eq_DrainingWaterNetwork_2"
        } else if (graphCode == "RecycleWaterNetwork"&&type == "Supply") {
            /** 中水供水 */
            return "eq2eq_RecycleWaterNetwork_1"
        } else if (graphCode == "RecycleWaterNetwork"&&type == "Bypass") {
            /** 中水旁通 */
            return "eq2eq_RecycleWaterNetwork_2"
        } else if (graphCode == "DrinkingWaterNetwork"&&type == "Supply") {
            /** 直饮水供水 */
            return "eq2eq_DrinkingWaterNetwork_1"
        } else if (graphCode == "DrinkingWaterNetwork"&&type == "Bypass") {
            /** 直饮水旁通 */
            return "eq2eq_DrinkingWaterNetwork_2"
        } else if (graphCode == "DHWNetwork"&&type == "Supply") {
            /** 生活热水供水 */
            return "eq2eq_DHWNetwork_1"
        } else if (graphCode == "DHWNetwork"&&type == "Bypass") {
            /** 生活热水旁通 */
            return "eq2eq_DHWNetwork_2"
        } else if (graphCode == "GasNetwork"&&type == "Supply") {
            /** 燃气供气 */
            return "eq2eq_GasNetwork_1"
        } else if (graphCode == "GasNetwork"&&type == "Bypass") {
            /** 燃气旁通 */
            return "eq2eq_GasNetwork_2"
        } else if (graphCode == "FireWaterNetwork"&&type == "Supply") {
            /** 消防给水供水 */
            return "eq2eq_FireWaterNetwork_1"
        } else if (graphCode == "FireWaterNetwork"&&type == "Bypass") {
            /** 消防给水旁通 */
            return "eq2eq_FireWaterNetwork_2"
        } else if (graphCode == "FireVentNetwork"&&type == "Discharge") {
            /** 消防排烟 */
            return "eq2eq_FireVentNetwork_1"
        } else if (graphCode == "WENetwork"&&type == "Normal") {
            /** 通信连接 */
            return "eq2eq_SensorNetwork_1"
        } else if (graphCode == "MechCtrl"&&type == "SyCtrl") {
            /** 系统控制关系 */
            return "eq2eq_ControlRelation_1"
        } else if (graphCode == "MechCtrl"&&type == "EqCtrl") {
            /** 设备控制关系 */
            return "eq2eq_ControlRelation_1"
        } else if (graphCode == "MechPower"&&type == "SyNormal") {
            /** 系统常规电源 */
            return "eq2eq_EquipPower_3"
        } else if (graphCode == "MechPower"&&type == "SyBackup") {
            /** 系统备用电源 */
            return "eq2eq_EquipPower_4"
        } else if (graphCode == "MechPower"&&type == "EqNormal") {
            /** 设备常规电源 */
            return "eq2eq_EquipPower_1"
        } else if (graphCode == "MechPower"&&type == "EqBackup") {
            /** 设备备用电源 */
            return "eq2eq_EquipPower_2"
        } else if (graphCode == "SensorRelationship"&&type == "Ss2Eq") {
            /** 传感器测量设备关系 */
            return "eq2eq_SensorRelationship_ss2eq"
        } else if (graphCode == "SensorRelationship"&&type == "Ss2Sy") {
            /** 传感器测量系统关系 */
            return "eq2sy_SensorRelationship_ss2sy"
        } else if (graphCode == "SensorRelationship"&&type == "Ss2Sp") {
            /** 传感器测量空间关系 */
            return "eq2sp_SensorRelationship_ss2sp"
        } else if (graphCode == "ValveRelationship"&&type == "Vv2Eq") {
            /** 阀门限制设备关系 */
            return "eq2eq_ValveRelationship_vv2eq"
        } else if (graphCode == "ValveRelationship"&&type == "Vv2Sy") {
            /** 阀门限制系统关系 */
            return "eq2sy_ValveRelationship_vv2sy"
        } else {
            return ""
        }
    }








}