/*
 * *********************************************************************************************************************
 *
 *          !!
 *        .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.datacenter.syn.services.jms.rel

import com.persagy.database.SFilter
import com.persagy.mybatis.SMybatisDao
import com.persagy.server.datacenter.models.entities.dictnew.DictProject
import com.persagy.server.datacenter.models.entities.rel.*
import com.persagy.server.datacenter.models.jms.SynchronousMessageRel
import com.persagy.server.datacenter.wanda.rel.REq2Eq
import com.persagy.server.datacenter.wanda.rel.REq2Sp
import com.persagy.server.datacenter.wanda.rel.RSp2Sp
import com.persagy.server.datacenter.wanda.rel.RSy2Sp
import com.persagy.server.syn.Configure
import com.persagy.server.syn.models.api.obj.EquipApi
import com.persagy.service.SObjectService
import org.springframework.stereotype.Service

/**
 * 自动计算
 *
 * @author wx  <zhangweixin@sagacloud.com>
 * @date  2020/12/17 9:11
 */
@Service
class AutomaticCalculationSync {

    /** 设备设施服务于建筑服务 */
    private val rEqForBdService = SObjectService(SMybatisDao(REqForBd::class.java))
    /** 设备设施所在竖井 */
    private val rEqInShService = SObjectService(SMybatisDao(REqInSh::class.java))
    /** 设备所在业务空间 */
    var rEq2SpService = SObjectService(SMybatisDao( REq2Sp::class.java))
    /** 楼层贯通关系 */
    var  rFlThroughFlService = SObjectService(SMybatisDao( RFlThroughFl::class.java))
    /** 楼层下的业务空间 */
    var  rSpinFlService = SObjectService(SMybatisDao( RSpinFl::class.java))
    /** 数据中心建筑下的竖井关系 */
    val rShInBdService = SObjectService(SMybatisDao(RShInBd::class.java))
    /** 竖井贯通 */
    val rShaftThroughShaftService = SObjectService(SMybatisDao(RShaftThroughShaft::class.java))
    /** 系统所在楼层 */
    val rSyInFlService = SObjectService(SMybatisDao(RSyInFl::class.java))
    /** 系统所在竖井 */
    val rSyInShService = SObjectService(SMybatisDao(RSyInSh::class.java))
    /** 系统所在业务空间 */
    val rSy2SpService = SObjectService(SMybatisDao(RSy2Sp::class.java))
    /** 空间和空间关系 */
    val rSp2SpService = SObjectService(SMybatisDao(RSp2Sp::class.java))
    /** 设备和设备关系 */
    val rEq2EqService = SObjectService(SMybatisDao(REq2Eq::class.java))

    /** 缓存对象数据服务 - 数据中心到数据中台  */
    var synchronousMessageRelService = SObjectService(SMybatisDao(SynchronousMessageRel::class.java))

    /** 项目所属的集团 */
    private val dictProjectService = SObjectService(SMybatisDao(DictProject::class.java))

    /**
     * 设备设施服务于建筑
     */
    fun eq2BdFor(message: SynchronousMessageRel) {
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rEqForBdList = rEqForBdService.select(SFilter.eq("projectId", message.projectId!!)).exec()
            message.sign = 0
            if (rEqForBdList.size>0) {
                for (rEqForBd in rEqForBdList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("MechForArch", "Eq2Bd", rEqForBd.equipId!!, rEqForBd.buildingId!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("MechForArch", "Eq2Bd", rEqForBd.equipId!!, rEqForBd.buildingId!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel){
                            message.sign = 2
                            message.count = message.count +1
                           break
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)

        }
    }

    /**
     * 设备设施所在竖井
     */
    fun eq2ShIn(message: SynchronousMessageRel){
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rEqInShList = rEqInShService.select(SFilter.eq("projectId", message.projectId!!)).exec()
            message.sign = 0
            if (rEqInShList.size>0) {
                for (rEqInSh in rEqInShList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("MechInArch", "Eq2Sh", rEqInSh.equipId!!, rEqInSh.shaftId!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("MechInArch", "Eq2Sh",rEqInSh.equipId!!, rEqInSh.shaftId!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel){
                            message.sign = 2
                            message.count = message.count +1
                            break
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)
        }
    }

    /**
     * 设备设施所在空间
     */
    fun eq2SpIn(message: SynchronousMessageRel) {
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rEq2SpList = rEq2SpService.select(SFilter.eq("projectId", message.projectId!!),SFilter.eq("type", "eq2sp_in"),SFilter.eq("zoneType", message.fromId!!)).exec()
            message.sign = 0
            if (rEq2SpList.size>0) {
                for (rEq2Sp in rEq2SpList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("MechInArch", "Eq2Sp", rEq2Sp.id1!!, rEq2Sp.id2!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("MechInArch", "Eq2Sp", rEq2Sp.id1!!, rEq2Sp.id2!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel){
                            message.sign = 2
                            message.count = message.count +1
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)
        }
    }

    /**
     * 楼层贯通关系
     */
    fun fl2FlThrough(message: SynchronousMessageRel){
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rFlThroughFlList = rFlThroughFlService.select(SFilter.eq("projectId", message.projectId!!)).exec()
            message.sign = 0
            if (rFlThroughFlList.size>0) {
                for (rFlThroughFl in rFlThroughFlList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("ThroughRelationship", "Fl2Fl", rFlThroughFl.floorId!!, rFlThroughFl.floorOtherId!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("ThroughRelationship", "Fl2Fl", rFlThroughFl.floorId!!, rFlThroughFl.floorOtherId!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel) {
                            message.sign = 2
                            message.count = message.count +1
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)
        }
    }

    /**
     * 楼层下的业务空间
     */
    fun fl2SpIn(message: SynchronousMessageRel) {
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rSpinFlList = rSpinFlService.select(SFilter.eq("projectId", message.projectId!!)).exec()
            message.sign = 0
            if (rSpinFlList.size>0) {
                for (rSpinFl in rSpinFlList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("ArchSubset", "Fl2Sp", rSpinFl.floorId!!, rSpinFl.spaceId!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("ArchSubset", "Fl2Sp", rSpinFl.floorId!!, rSpinFl.spaceId!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel){
                            message.sign = 2
                            message.count = message.count +1
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)

        }
    }

    /**
     * 建筑下的竖井
     */
    fun bd2ShIn(message: SynchronousMessageRel){
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rShInBdList = rShInBdService.select(SFilter.eq("projectId", message.projectId!!)).exec()
            message.sign = 0
            if (rShInBdList.size>0) {
                for (rShInBd in rShInBdList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("ArchSubset", "Bd2Sh", rShInBd.buildingId!!, rShInBd.shaftId!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("ArchSubset", "Bd2Sh", rShInBd.buildingId!!, rShInBd.shaftId!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel) {
                            message.sign = 2
                            message.count = message.count +1
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)
        }
    }

    /**
     * 竖井贯通
     */
    fun sh2ShThrough(message: SynchronousMessageRel){
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rShaftThroughShaftList = rShaftThroughShaftService.select(SFilter.eq("projectId", message.projectId!!)).exec()
            message.sign = 0
            if (rShaftThroughShaftList.size>0) {
                for (rShaftThroughShaft in rShaftThroughShaftList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("ThroughRelationship", "Sh2Sh", rShaftThroughShaft.shaftId!!, rShaftThroughShaft.shaftOtherId!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("ThroughRelationship", "Sh2Sh", rShaftThroughShaft.shaftId!!, rShaftThroughShaft.shaftOtherId!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel){
                            message.sign = 2
                            message.count = message.count +1
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)
        }
    }

    /**
     * 建筑下的系统设备部件
     */
    fun syeq2bd(message: SynchronousMessageRel){

    }

    /**
     * 系统所在楼层
     */
    fun sy2FlIn(message: SynchronousMessageRel){
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rSyInFlList = rSyInFlService.select(SFilter.eq("projectId", message.projectId!!)).exec()
            message.sign = 0
            if (rSyInFlList.size>0) {
                for (rSyInFl in rSyInFlList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("MechInArch", "Sy2Fl", rSyInFl.sysId!!, rSyInFl.floorId!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("MechInArch", "Sy2Fl", rSyInFl.sysId!!, rSyInFl.floorId!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel){
                            message.sign = 2
                            message.count = message.count +1
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)
        }
    }

    /**
     * 系统所在竖井
     */
    fun sy2ShIn(message: SynchronousMessageRel){
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rSyInShList = rSyInShService.select(SFilter.eq("projectId", message.projectId!!)).exec()
            if (rSyInShList.size>0) {
                for (rSyInSh in rSyInShList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("MechInArch", "Sy2Sh", rSyInSh.sysId!!, rSyInSh.shaftId!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("MechInArch", "Sy2Sh", rSyInSh.sysId!!, rSyInSh.shaftId!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel){
                            message.sign = 2
                            message.count = message.count +1
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }

                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)
        }
    }

    /**
     * 系统所在业务空间
     */
    fun sy2SpIn(message: SynchronousMessageRel){
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rSy2SpList = rSy2SpService.select(SFilter.eq("projectId", message.projectId!!)).exec()
            message.sign = 0
            if (rSy2SpList.size>0) {
                for (rSy2Sp in rSy2SpList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("MechInArch", "Sy2Sp", rSy2Sp.id1!!, rSy2Sp.id2!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("MechInArch", "Sy2Sp", rSy2Sp.id1!!, rSy2Sp.id2!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel){
                            message.sign = 2
                            message.count = message.count +1
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)
        }
    }

    /**
     * 风口（空调风口、通风风口） 服务
     */
    fun fengkouFor(message: SynchronousMessageRel){
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rEq2SpList = rEq2SpService.select(SFilter.eq("projectId", message.projectId!!),SFilter.eq("type", "eq2sp_for"),SFilter.inList("zoneType",
                arrayListOf("GeneralZone","AirConditioningZone"))).exec()
            message.sign = 0
            if (rEq2SpList.size>0) {
                for (rEq2Sp in rEq2SpList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("MechForArch", "Eq2Sp", rEq2Sp.id1!!, rEq2Sp.id2!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("MechForArch", "Eq2Sp", rEq2Sp.id1!!, rEq2Sp.id2!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel){
                            message.sign = 2
                            message.count = message.count +1
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)
        }
    }

    /**
     * 空气自然对流
     */
    fun sp2SpConvectionNetwork01(message: SynchronousMessageRel){
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rSp2SpList = rSp2SpService.select(SFilter.eq("projectId", message.projectId!!),SFilter.eq("type", "sp2sp_ConvectionNetwork_1")).exec()
            message.sign = 0
            if (rSp2SpList.size>0) {
                for (rSp2Sp in rSp2SpList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("ConvectionNetwork", "Natural", rSp2Sp.id1!!, rSp2Sp.id2!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("ConvectionNetwork", "Natural", rSp2Sp.id1!!, rSp2Sp.id2!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel){
                            message.sign = 2
                            message.count = message.count +1
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)
        }
    }

    /**
     * 空间连通
     */
    fun sp2SpSpaceNeighborhood5(message: SynchronousMessageRel){
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rSp2SpList = rSp2SpService.select(SFilter.eq("projectId", message.projectId!!),SFilter.eq("type", "sp2sp_SpaceNeighborhood_5")).exec()
            message.sign = 0
            if (rSp2SpList.size>0) {
                for (rSp2Sp in rSp2SpList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("ThroughRelationship", "Connect", rSp2Sp.id1!!, rSp2Sp.id2!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("ThroughRelationship", "Connect", rSp2Sp.id1!!, rSp2Sp.id2!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel){
                            message.sign = 2
                            message.count = message.count +1
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)
        }
    }

    /**
     * 空间光照连通
     */
    fun sp2SpRadiationNetwork1(message: SynchronousMessageRel){
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rSp2SpList = rSp2SpService.select(SFilter.eq("projectId", message.projectId!!),SFilter.eq("type", "sp2sp_RadiationNetwork_1")).exec()
            message.sign = 0
            if (rSp2SpList.size>0) {
                for (rSp2Sp in rSp2SpList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("RadiationNetwork", "Connect", rSp2Sp.id1!!, rSp2Sp.id2!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("RadiationNetwork", "Connect", rSp2Sp.id1!!, rSp2Sp.id2!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel){
                            message.sign = 2
                            message.count = message.count +1
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)
        }
    }

    /**
     * 普通交通
     */
    fun sp2SpTrafficNetwork1(message: SynchronousMessageRel){
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rSp2SpList = rSp2SpService.select(SFilter.eq("projectId", message.projectId!!),SFilter.eq("type", "sp2sp_TrafficNetwork_1")).exec()
            message.sign = 0
            if (rSp2SpList.size>0) {
                for (rSp2Sp in rSp2SpList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("TrafficNetwork", "Normal", rSp2Sp.id1!!, rSp2Sp.id2!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("TrafficNetwork", "Normal", rSp2Sp.id1!!, rSp2Sp.id2!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel){
                            message.sign = 2
                            message.count = message.count +1
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)
        }
    }

    /**
     * 传感器测量设备关系
     */
    fun eq2EqSensorRelationshipSs2eq(message: SynchronousMessageRel){
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rSp2SpList = rEq2EqService.select(SFilter.eq("projectId", message.projectId!!),SFilter.eq("type", "eq2eq_SensorRelationship_ss2eq")).exec()
            message.sign = 0
            if (rSp2SpList.size>0) {
                for (rSp2Sp in rSp2SpList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("TrafficNetwork", "Normal", rSp2Sp.id1!!, rSp2Sp.id2!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("TrafficNetwork", "Normal", rSp2Sp.id1!!, rSp2Sp.id2!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel){
                            message.sign = 2
                            message.count = message.count +1
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)
        }
    }
    /**
     * 传感器测量空间关系
     */
    fun eq2SpSensorRelationshipSs2sp(message: SynchronousMessageRel){
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rEq2SpList = rEq2SpService.select(SFilter.eq("projectId", message.projectId!!),SFilter.eq("type", "eq2sp_SensorRelationship_ss2sp")).exec()
            message.sign = 0
            if (rEq2SpList.size>0) {
                for (rEq2Sp in rEq2SpList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("SensorRelationship", "Ss2Sp", rEq2Sp.id1!!, rEq2Sp.id2!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("SensorRelationship", "Ss2Sp", rEq2Sp.id1!!, rEq2Sp.id2!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel){
                            message.sign = 2
                            message.count = message.count +1
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)
        }
    }

    /**
     * 设备控制关系
     */
    fun eq2eqControlRelation1(message: SynchronousMessageRel){
        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
        if (dictProject!=null) {
            val rEq2SpList = rEq2EqService.select(SFilter.eq("projectId", message.projectId!!),SFilter.eq("type", "eq2eq_ControlRelation_1")).exec()
            message.sign = 0
            if (rEq2SpList.size>0) {
                for (rEq2Sp in rEq2SpList) {
                    try {
                        /** 先执行删除 */
                        val toJsonObj = Configure.toJsonObj("MechCtrl", "EqCtrl", rEq2Sp.id1!!, rEq2Sp.id2!!)
                        val delRel = EquipApi.delRel(dictProject.groupCode!!, message.projectId!!, toJsonObj)
                        /** 关系列表 */
                        val toJsonObjArray =
                            Configure.toJsonObjArray("MechCtrl", "EqCtrl", rEq2Sp.id1!!, rEq2Sp.id2!!)
                        val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                        if (!createRel){
                            message.sign = 2
                            message.count = message.count +1
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                        message.sign = 2
                        message.count = message.count +1
                    }
                }
            }
            /** 更改标记 */
            synchronousMessageRelService.update(message)
        }
    }

}