/*
 * *********************************************************************************************************************
 *
 *          !!
 *        .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-2021.  博锐尚格科技股份有限公司
 *        ~8888'
 *        .!88~                                                                     All rights reserved.
 *
 * *********************************************************************************************************************
 */

package com.persagy.server.services.relation_calc

import com.persagy.base.extensions.toJson
import com.persagy.database.SFilter
import com.persagy.mybatis.SMybatisDao
import com.persagy.server.datacenter.models.entities.dictnew.DefClass
import com.persagy.server.datacenter.models.entities.graphtype.RelationTypeProject
import com.persagy.server.datacenter.models.entities.graphtype.block.RelationAddRequest
import com.persagy.server.datacenter.models.entities.graphtype.rel.*
import com.persagy.server.datacenter.models.entities.rel.*
import com.persagy.server.datacenter.models.entities.rel.archforarch.*
import com.persagy.server.datacenter.models.entities.rel.archforarch.RSh2Bd
import com.persagy.server.datacenter.models.entities.rel.archforarch.RSh2Sp
import com.persagy.server.datacenter.models.response.ManualRelationCalcSCreateResponse
import com.persagy.server.jms.RabbitMqService
import com.persagy.server.services.objects.*
import com.persagy.server.services.rel.*
import com.persagy.service.SObjectService
import com.persagy.service.SPageContext
import com.persagy.service.models.enums.SResponseType
import com.persagy.service.utils.SSpringContextUtil
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
import java.text.SimpleDateFormat
import java.util.*

/**
 * 添加
 *
 * @author wx  <zhangweixin@sagacloud.com>
 * @date  2021/3/3 13:50
 */
@Service
class ManualRelationAddService {

    companion object {
        /** 日志 */
        private val logger = LoggerFactory.getLogger(ManualRelationCalcService::class.java)
        /** RabbitMQ消息对象 */
        val rabbitMqService by lazy {
            SSpringContextUtil.getBean(RabbitMqService::class.java) as RabbitMqService
        }
    }

    /** 区域服务-建筑和建筑 */
    private val rBd2BdService = SObjectService(SMybatisDao(RBd2Bd::class.java))
    /** 建筑和楼层 */
    private val rBd2FlService = SObjectService(SMybatisDao(RBd2Fl::class.java))
    /** 建筑和竖井 */
    private val rBd2ShService = SObjectService(SMybatisDao(RBd2Sh::class.java))
    /** 建筑和空间 */
    private val rBd2SpService = SObjectService(SMybatisDao(RBd2Sp::class.java))
    /** 区域服务-楼层和建筑 */
    private val rFl2BdService = SObjectService(SMybatisDao(RFl2Bd::class.java))
    /** 楼层和楼层 */
    private val rFl2FlService = SObjectService(SMybatisDao(RFl2Fl::class.java))
    /** 楼层和竖井 */
    private val rFl2ShService = SObjectService(SMybatisDao(RFl2Sh::class.java))
    /** 楼层和空间 */
    private val rFl2SpService = SObjectService(SMybatisDao(RFl2Sp::class.java))
    /** 区域服务-竖井和建筑 */
    private val rSh2BdService = SObjectService(SMybatisDao(RSh2Bd::class.java))
    /** 竖井和楼层 */
    private val rSh2FlService = SObjectService(SMybatisDao(RSh2Fl::class.java))
    /** 竖井和竖井 */
    private val rSh2ShService = SObjectService(SMybatisDao(RSh2Sh::class.java))
    /** 竖井和空间 */
    private val rSh2SpService = SObjectService(SMybatisDao(RSh2Sp::class.java))

    /** 区域服务-空间和建筑 */
    private val rSp2BdService = SObjectService(SMybatisDao(RSp2Bd::class.java))
    /** 空间和楼层 */
    private val rSp2FlService = SObjectService(SMybatisDao(RSp2Fl::class.java))
    /** 空间和竖井 */
    private val rSp2ShService = SObjectService(SMybatisDao(RSp2Sh::class.java))


    /** 资产服务 */
    private val relPropertyService = SObjectService(SMybatisDao(RelProperty::class.java))
    /** 资产所在的空间 *******************************************************/
    private val rPeInSpBaseService = SObjectService(SMybatisDao(RPe2Sp::class.java))
    /** 设备服务于竖井 */
    private val rEq2ShService = SObjectService(SMybatisDao(REq2Sh::class.java))
    /** 设备服务于楼层 */
    private val rEq2FlService = SObjectService(SMybatisDao(REq2Fl::class.java))
    /** 系统和空间关系 */
    private val rSy2SpService = SObjectService(SMybatisDao(RSy2Sp::class.java))
    /** 系统和竖井关系 */
    private val rSy2ShService = SObjectService(SMybatisDao(RSy2Sh::class.java))
    /** 系统和楼层关系 */
    private val rSy2FlService = SObjectService(SMybatisDao(RSy2Fl::class.java))
    /** 系统和建筑关系 */
    private val rSy2BdService = SObjectService(SMybatisDao(RSy2Bd::class.java))
    /** 空间和空间的关系 */
    private val rSp2SpService = SObjectService(SMybatisDao(RSp2Sp::class.java))
    /** 设备和设备关系 */
    private val rEq2EqService = SObjectService(SMybatisDao(REq2Eq::class.java))
    /** 设备和系统关系 */
    private val rEq2SyService = SObjectService(SMybatisDao(REq2Sy::class.java))
    /** 设备和空间关系 */
    private val rEq2SpService = SObjectService(SMybatisDao(REq2Sp::class.java))

    /** 空间 */
    private val relZoneSpaceService = SObjectService(SMybatisDao(RelZoneSpace::class.java))
    /** 类型查询 */
    private val dClassDefService = SObjectService(SMybatisDao(DefClass::class.java))
    /** 资产所在的竖井 */
    private val rPeInShService = SObjectService(SMybatisDao(RPeInSh::class.java))
    /** 资产和竖井的资产实例 */
    private val relPropertyShaftService = SObjectService(SMybatisDao(RelPropertyShaft::class.java))
    /** 竖井 */
    private val relShaftService = SObjectService(SMybatisDao(RelShaft::class.java))
    /** 设备和竖井的设备 */
    private val relEquipmentShaftService = SObjectService(SMybatisDao(RelEquipmentShaft::class.java))
    /** 设备和楼层的设备 */
    private val  relEquipmentFloorService = SObjectService(SMybatisDao(RelEquipmentFloor::class.java))
    /** 设备服务于建筑 设备 */
    private val relEquipmentBuildingService = SObjectService(SMybatisDao(RelEquipmentBuilding::class.java))
    /** 系统服务于业务空间 */
    private val relGeneralSystemService = SObjectService(SMybatisDao(RelGeneralSystem::class.java))
    /** 系统服务于竖井 */
    private val relGeneralSystemShaftService = SObjectService(SMybatisDao(RelGeneralSystemShaft::class.java))
    /** 系统服务于楼层 */
    private val relGeneralSystemFloorService = SObjectService(SMybatisDao(RelGeneralSystemFloor::class.java))
    /** 系统服务于建筑 */
    private val relGeneralSystemBuildingService = SObjectService(SMybatisDao(RelGeneralSystemBuilding::class.java))


    /**
     * 添加关系
     */
    fun addRel(relationAddRequest: RelationAddRequest): ManualRelationCalcSCreateResponse {
        /** 项目id */
        val projectId = SPageContext.getHeader("projectId")

        val sCreateResponse = ManualRelationCalcSCreateResponse()

        if (relationAddRequest.relType.isNullOrEmpty()){
            /** 关系类型不能为空 */
            sCreateResponse.result = SResponseType.failure
            sCreateResponse.message = "关系类型不能为空"
            return sCreateResponse
        }
        if (relationAddRequest.type.isNullOrEmpty()){
            /** 编码类型不能为空 */
            sCreateResponse.result = SResponseType.failure
            sCreateResponse.message = "识别不能为空"
            return sCreateResponse
        }
        if (relationAddRequest.mainContent.isNullOrEmpty()){
            /** 主对象内容不能为空 */
            sCreateResponse.result = SResponseType.failure
            sCreateResponse.message = "主对象不能为空"
            sCreateResponse.errorType = "1"
            return sCreateResponse
        }
        if (relationAddRequest.fromContent.isNullOrEmpty()){
            /** 从对象内容不能为空 */
            sCreateResponse.result = SResponseType.failure
            sCreateResponse.message = "从对象不能为空"
            sCreateResponse.errorType = "2"
            return sCreateResponse
        }
        if (!relationAddRequest.fromContent.isNullOrEmpty()&&relationAddRequest.fromContent!!.size<1){
            /** 从对象内容不能为空 */
            sCreateResponse.result = SResponseType.failure
            sCreateResponse.message = "从对象不能为空"
            sCreateResponse.errorType = "2"
            return sCreateResponse
        }

        try {
            val relationTypeProjectService = SObjectService(SMybatisDao(RelationTypeProject::class.java))
            val relationType = relationTypeProjectService.select(
                SFilter.eq("projectId", projectId!!),
                SFilter.eq("relationType", relationAddRequest.relType!!)).entity()
            if (relationType!=null){
                relationType.computingTime = time()
                relationTypeProjectService.update(relationType)
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }

        if (relationAddRequest.relType == "pe2sp"){
            if (!relationAddRequest.type.isNullOrEmpty()&&relationAddRequest.type == "cadId"){
                /** 从对象不存在cadId编码 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = "从对象不存在CADID编码"
                sCreateResponse.errorType = "2"
                return sCreateResponse
            }

            /** 查询资产 */
            val relPropertyList = relPropertyService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()

            if (relPropertyList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (relPropertyList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }

            for (fromContent in relationAddRequest.fromContent!!){
                val relZoneSpaceList = relZoneSpaceService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                if (relZoneSpaceList.size<1){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (relZoneSpaceList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }
            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }
            /** 查询空间 */
            val relZoneSpaceList = relZoneSpaceService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
            /** 资产 */
            val relProperty = relPropertyList[0]

            for (relZoneSpace in relZoneSpaceList){
                val rPe2Sp = RPe2Sp()
                rPe2Sp.id2 = relZoneSpace.id
                rPe2Sp.type = "pe2sp"
                rPe2Sp.projectId = projectId
                rPe2Sp.zoneType = relZoneSpace.objectType
                rPe2Sp.id1 = relProperty.id
                rPe2Sp.sign = 1
                rPeInSpBaseService.replace(rPe2Sp)
            }
            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse

        }else if(relationAddRequest.relType == "pe2sh") {
            if (!relationAddRequest.type.isNullOrEmpty()&&relationAddRequest.type == "cadId"){
                /** 从对象不存在cadId编码 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = "从对象不存在CADID编码"
                sCreateResponse.errorType = "2"
                return sCreateResponse
            }

            /** 查询资产 */
            val relPropertyList = relPropertyService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()

            if (relPropertyList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (relPropertyList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }

            for (fromContent in relationAddRequest.fromContent!!){
                val relZoneSpaceList = relShaftService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                if (relZoneSpaceList.size<1){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (relZoneSpaceList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }
            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }
            /** 查询竖井 */
            val relZoneSpaceList = relShaftService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
            /** 资产 */
            val relProperty = relPropertyList[0]

            for (relZoneSpace in relZoneSpaceList){
                val rPe2Sh = RPeInSh()
                rPe2Sh.shaftId = relZoneSpace.id
                rPe2Sh.projectId = projectId
                rPe2Sh.equipId = relProperty.id
//                rPe2Sh.type = "pe2sh"
                rPe2Sh.sign = 1
                rPeInShService.replace(rPe2Sh)
            }
            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse
        }else if (relationAddRequest.relType == "eq2sh_for"){
            /** 设备服务于竖井 */
            if (!relationAddRequest.type.isNullOrEmpty()&&relationAddRequest.type == "cadId"){
                /** 从对象不存在cadId编码 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = "从对象不存在CADID编码"
                sCreateResponse.errorType = "2"
                return sCreateResponse
            }

            /** 查询资产 */
            val relPropertyList = relEquipmentShaftService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()

            if (relPropertyList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (relPropertyList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }

            for (fromContent in relationAddRequest.fromContent!!){
                val relZoneSpaceList = relShaftService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                if (relZoneSpaceList.size<1){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (relZoneSpaceList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }
            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }
            /** 查询竖井 */
            val relZoneSpaceList = relShaftService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
            /** 资产 */
            val relProperty = relPropertyList[0]

            for (relZoneSpace in relZoneSpaceList){
                val rEq2Sh = REqForSh()
                rEq2Sh.shaftId = relZoneSpace.id
                rEq2Sh.projectId = projectId
                rEq2Sh.equipId = relProperty.id
                rEq2Sh.sign = 1
                REqForShService.replace(rEq2Sh)
            }
            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse

        }else if(relationAddRequest.relType == "eq2fl_for"){
            /** 设备服务于楼层 */
            if (!relationAddRequest.type.isNullOrEmpty()&&relationAddRequest.type == "cadId"){
                /** 从对象不存在cadId编码 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = "从对象不存在CADID编码"
                return sCreateResponse
            }

            /** 查询设备 */
            val relPropertyList = relEquipmentShaftService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()

            if (relPropertyList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (relPropertyList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }

            for (fromContent in relationAddRequest.fromContent!!){
                val relZoneSpaceList = FloorService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                if (relZoneSpaceList.size<1){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (relZoneSpaceList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }

            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }

            val floorList = FloorService.select(SFilter.eq("projectId", projectId!!), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
            val relEquipment = relPropertyList[0]

            for (relZoneSpace in floorList){
                val rEq2Fl = REqForFl()
                rEq2Fl.floorId = relZoneSpace.id
                rEq2Fl.projectId = projectId
                rEq2Fl.equipId = relEquipment.id
//                rEq2Fl.type = "eq2fl_for"
                rEq2Fl.sign = 1
                REqForFlService.replace(rEq2Fl)
            }
            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse

        }else if (relationAddRequest.relType == "eq2bd_for"){
            /** 设备服务于建筑 */
            if (!relationAddRequest.type.isNullOrEmpty()&&relationAddRequest.type == "cadId"){
                /** 从对象不存在cadId编码 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = "从对象不存在CADID编码"
                sCreateResponse.errorType = "2"
                return sCreateResponse
            }
            /** 查询设备 */
            val relPropertyList = EquipmentService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()

            if (relPropertyList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (relPropertyList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }

            for (fromContent in relationAddRequest.fromContent!!){
                val relZoneSpaceList = BuildingService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                if (relZoneSpaceList.size<1){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (relZoneSpaceList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }

            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }

            val buildingList = BuildingService.select(SFilter.eq("projectId", projectId!!), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
            val relEquipment = relPropertyList[0]

            for (relZoneSpace in buildingList){
                val rEq2Bd = REqForBd()
                rEq2Bd.buildingId = relZoneSpace.id
                rEq2Bd.projectId = projectId
                rEq2Bd.equipId = relEquipment.id
//                rEq2Bd.type = "eq2bd_for"
                rEq2Bd.sign = 1
                REqForBdService.replace(rEq2Bd)
            }
            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse
        }else if ( relationAddRequest.relType == "sy2sp_for"){
            if (!relationAddRequest.type.isNullOrEmpty()&&relationAddRequest.type == "cadId"){
                /** 从对象不存在cadId编码 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = "主从对象不存在CADID编码"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }

            val generalSystemList = GeneralSystemService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
            if (generalSystemList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (generalSystemList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }

            for (fromContent in relationAddRequest.fromContent!!){
                val relZoneSpaceList = relZoneSpaceService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                if (relZoneSpaceList.size<1){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (relZoneSpaceList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }
            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }
            /** 查询空间 */
            val relZoneSpaceList = relZoneSpaceService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
            /** 系统 */
            val relProperty = generalSystemList[0]

            for (relZoneSpace in relZoneSpaceList){
                val rSy2Sp = RSy2Sp()
                rSy2Sp.id2 = relZoneSpace.id
                rSy2Sp.zoneType = relZoneSpace.objectType
                rSy2Sp.projectId = projectId
                rSy2Sp.id1 = relProperty.id
                rSy2Sp.type = "sy2sp_for"
                rSy2Sp.sign = 1
                rSy2SpService.replace(rSy2Sp)
            }
            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse
        }else if (relationAddRequest.relType == "sy2sh_for"){

            if (!relationAddRequest.type.isNullOrEmpty()&&relationAddRequest.type == "cadId"){
                /** 从对象不存在cadId编码 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = "主从对象不存在CADID编码"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }

            val generalSystemList = GeneralSystemService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
            if (generalSystemList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (generalSystemList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            for (fromContent in relationAddRequest.fromContent!!){
                val relZoneSpaceList = relShaftService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                if (relZoneSpaceList.size<1){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (relZoneSpaceList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }
            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }
            /** 查询竖井 */
            val relZoneSpaceList = relShaftService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
            /** 资产 */
            val relProperty = generalSystemList[0]

            for (relZoneSpace in relZoneSpaceList){
                val rSy2Sh = RSyForSh()
                rSy2Sh.shaftId = relZoneSpace.id
                rSy2Sh.projectId = projectId
                rSy2Sh.sysId = relProperty.id
//                rSy2Sh.type = "sy2sh_for"
                rSy2Sh.sign = 1
                RSyForShService.replace(rSy2Sh)
            }
            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse
        }else if (relationAddRequest.relType == "sy2fl_for"){
            /** 系统服务于楼层 */
            if (!relationAddRequest.type.isNullOrEmpty()&&relationAddRequest.type == "cadId"){
                /** 从对象不存在cadId编码 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = "主从对象不存在CADID编码"
                return sCreateResponse
            }

            val generalSystemList = GeneralSystemService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
            if (generalSystemList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (generalSystemList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }

            for (fromContent in relationAddRequest.fromContent!!){
                val relZoneSpaceList = FloorService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                if (relZoneSpaceList.size<1){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (relZoneSpaceList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }

            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }

            val floorList = FloorService.select(SFilter.eq("projectId", projectId!!), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
            val relEquipment = generalSystemList[0]

            for (relZoneSpace in floorList){
                val rSy2Fl = RSyForFl()
                rSy2Fl.floorId = relZoneSpace.id
//                rSy2Fl.buildingId = relZoneSpace.buildId
                rSy2Fl.projectId = projectId
                rSy2Fl.sysId = relEquipment.id
//                rSy2Fl.type = "sy2fl_for"
                rSy2Fl.sign = 1
                RSyForFlService.replace(rSy2Fl)
            }
            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse

        }else if (relationAddRequest.relType == "sy2bd_for"){
            /** 系统服务于楼层 */
            if (!relationAddRequest.type.isNullOrEmpty()&&relationAddRequest.type == "cadId"){
                /** 从对象不存在cadId编码 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = "主从对象不存在CADID编码"
                return sCreateResponse
            }

            val generalSystemList = GeneralSystemService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
            if (generalSystemList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (generalSystemList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }

            for (fromContent in relationAddRequest.fromContent!!){
                val relZoneSpaceList = BuildingService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                if (relZoneSpaceList.size<1){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (relZoneSpaceList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }
            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }
            val buildingList = BuildingService.select(SFilter.eq("projectId", projectId!!), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
            val relEquipment = generalSystemList[0]

            for (relZoneSpace in buildingList){
                val rSy2Bd = RSyForBd()
                rSy2Bd.buildingId = relZoneSpace.id
                rSy2Bd.projectId = projectId
                rSy2Bd.sysId = relEquipment.id
                rSy2Bd.sign = 1
                RSyForBdService.replace(rSy2Bd)
            }
            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse
        }else if (relationAddRequest.relType == "sp2sp_ConvectionNetwork_1"||relationAddRequest.relType == "sp2sp_ConvectionNetwork_2"||relationAddRequest.relType == "sp2sp_ConvectionNetwork_3"
            ||relationAddRequest.relType == "sp2sp_SpaceNeighborhood_5"||relationAddRequest.relType == "sp2sp_SpaceNeighborhood_2"||relationAddRequest.relType == "sp2sp_SpaceNeighborhood_4"
            ||relationAddRequest.relType == "sp2sp_TrafficNetwork_3"||relationAddRequest.relType == "sp2sp_TrafficNetwork_2"||relationAddRequest.relType == "sp2sp_RadiationNetwork_1"
            ||relationAddRequest.relType == "sp2sp_RadiationNetwork_2"||relationAddRequest.relType == "sp2sp_SpaceNeighborhood_1"||relationAddRequest.relType == "sp2sp_TrafficNetwork_1"
            ||relationAddRequest.relType == "sp2sp_SpaceNeighborhood_3"
        ){

            if (!relationAddRequest.type.isNullOrEmpty()&&relationAddRequest.type == "cadId"){
                /** 从对象不存在cadId编码 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = "主从对象不存在CADID编码"
                return sCreateResponse
            }
            /**
             * 空间 空气自然对流       spairconvection                              sp2sp_ConvectionNetwork_1
             * 空间空气混合机械通风    spairmixing                                   sp2sp_ConvectionNetwork_2
             * 空气单向机械通风        spairunidirectional                           sp2sp_ConvectionNetwork_3
             * 空间连通关系           spconnectedsp                                   sp2sp_SpaceNeighborhood_5
             * 空间隔断有门           spdoors                                          sp2sp_SpaceNeighborhood_2
             * 空间隔断有门窗          spdoorswind                                     sp2sp_SpaceNeighborhood_4
             * 空间消防常关交通         spfireclose                                     sp2sp_TrafficNetwork_3
             * 空间消防常开交通         spfireopen                                      sp2sp_TrafficNetwork_2
             * 空间光照连通            splightconnection                               sp2sp_RadiationNetwork_1
             * 空间光照透明隔断         splighttrans                                    sp2sp_RadiationNetwork_2
             * 空间隔断无门窗          spnotdoorswind                                   sp2sp_SpaceNeighborhood_1
             * 空间普通交通           spordinary                                         sp2sp_TrafficNetwork_1
             * 空间隔断有窗           spwind                                            sp2sp_SpaceNeighborhood_3
             */
            val relZoneSpaceList = relZoneSpaceService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
            if (relZoneSpaceList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (relZoneSpaceList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            logger.debug("空间类型 = ${relZoneSpaceList.toJson()}")
            val relZoneSpace = relZoneSpaceList[0]
            for (fromContent in relationAddRequest.fromContent!!){
                /** 去除主对象空间id */
                val relZoneToSpaceList = relZoneSpaceService.select(
                    SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!),
                    SFilter.not(SFilter.eq("id",relZoneSpace.id!!)), SFilter.eq("objectType",relZoneSpace.objectType!!)).exec()
                if (relZoneToSpaceList.size == 0){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (relZoneToSpaceList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }
            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }
            /** 查询空间 */
            val relZoneToSpaceList = relZoneSpaceService.select(
                SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList()),
                SFilter.not(SFilter.eq("id",relZoneSpace.id!!)), SFilter.eq("objectType",relZoneSpace.objectType!!)).exec()

            if (relationAddRequest.relType == "sp2sp_ConvectionNetwork_1"){
                for (relZoneTo in relZoneToSpaceList){
                    val rSp2Sp = RSp2Sp()
                    rSp2Sp.id1 = relZoneSpace.id
                    rSp2Sp.projectId = projectId
                    rSp2Sp.sign = 1
                    rSp2Sp.id2 = relZoneTo.id
                    rSp2Sp.type = "sp2sp_ConvectionNetwork_1"
                    rSp2Sp.zoneType = relZoneSpace.objectType
                    rSp2SpService.replace(rSp2Sp)
                }
            }else if (relationAddRequest.relType == "sp2sp_ConvectionNetwork_2"){
                for (relZoneTo in relZoneToSpaceList) {
                    val rSp2Sp = RSp2Sp()
                    rSp2Sp.id1 = relZoneSpace.id
                    rSp2Sp.projectId = projectId
                    rSp2Sp.sign = 1
                    rSp2Sp.id2 = relZoneTo.id
                    rSp2Sp.type = "sp2sp_ConvectionNetwork_2"
                    rSp2Sp.zoneType = relZoneSpace.objectType
                    rSp2SpService.replace(rSp2Sp)
                }
            }else if (relationAddRequest.relType == "sp2sp_ConvectionNetwork_3"){
                for (relZoneTo in relZoneToSpaceList) {
                    val rSp2Sp = RSp2Sp()
                    rSp2Sp.id1 = relZoneSpace.id
                    rSp2Sp.projectId = projectId
                    rSp2Sp.sign = 1
                    rSp2Sp.id2 = relZoneTo.id
                    rSp2Sp.type = "sp2sp_ConvectionNetwork_3"
                    rSp2Sp.zoneType = relZoneSpace.objectType
                    rSp2SpService.replace(rSp2Sp)
                }
            }else if (relationAddRequest.relType == "sp2sp_SpaceNeighborhood_5"){
                for (relZoneTo in relZoneToSpaceList) {
                    val rSp2Sp = RSp2Sp()
                    rSp2Sp.id1 = relZoneSpace.id
                    rSp2Sp.projectId = projectId
                    rSp2Sp.sign = 1
                    rSp2Sp.id2 = relZoneTo.id
                    rSp2Sp.type = "sp2sp_SpaceNeighborhood_5"
                    rSp2Sp.zoneType = relZoneSpace.objectType
                    rSp2SpService.replace(rSp2Sp)
                }
            }else if (relationAddRequest.relType == "sp2sp_SpaceNeighborhood_2"){
                for (relZoneTo in relZoneToSpaceList) {
                    val rSp2Sp = RSp2Sp()
                    rSp2Sp.id1 = relZoneSpace.id
                    rSp2Sp.projectId = projectId
                    rSp2Sp.sign = 1
                    rSp2Sp.id2 = relZoneTo.id
                    rSp2Sp.type = "sp2sp_SpaceNeighborhood_2"
                    rSp2Sp.zoneType = relZoneSpace.objectType
                    rSp2SpService.replace(rSp2Sp)
                }
            }else if (relationAddRequest.relType == "sp2sp_SpaceNeighborhood_4"){
                for (relZoneTo in relZoneToSpaceList) {
                    val rSp2Sp = RSp2Sp()
                    rSp2Sp.id1 = relZoneSpace.id
                    rSp2Sp.projectId = projectId
                    rSp2Sp.sign = 1
                    rSp2Sp.id2 = relZoneTo.id
                    rSp2Sp.type = "sp2sp_SpaceNeighborhood_4"
                    rSp2Sp.zoneType = relZoneSpace.objectType
                    rSp2SpService.replace(rSp2Sp)
                }
            }else if (relationAddRequest.relType == "sp2sp_TrafficNetwork_3"){
                for (relZoneTo in relZoneToSpaceList) {
                    val rSp2Sp = RSp2Sp()
                    rSp2Sp.id1 = relZoneSpace.id
                    rSp2Sp.projectId = projectId
                    rSp2Sp.sign = 1
                    rSp2Sp.id2 = relZoneTo.id
                    rSp2Sp.type = "sp2sp_TrafficNetwork_3"
                    rSp2Sp.zoneType = relZoneSpace.objectType
                    rSp2SpService.replace(rSp2Sp)
                }
            }else if (relationAddRequest.relType == "sp2sp_TrafficNetwork_2"){
                for (relZoneTo in relZoneToSpaceList) {
                    val rSp2Sp = RSp2Sp()
                    rSp2Sp.id1 = relZoneSpace.id
                    rSp2Sp.projectId = projectId
                    rSp2Sp.sign = 1
                    rSp2Sp.id2 = relZoneTo.id
                    rSp2Sp.type = "sp2sp_TrafficNetwork_2"
                    rSp2Sp.zoneType = relZoneSpace.objectType
                    rSp2SpService.replace(rSp2Sp)
                }
            }else if (relationAddRequest.relType == "sp2sp_RadiationNetwork_1"){
                for (relZoneTo in relZoneToSpaceList) {
                    val rSp2Sp = RSp2Sp()
                    rSp2Sp.id1 = relZoneSpace.id
                    rSp2Sp.projectId = projectId
                    rSp2Sp.sign = 1
                    rSp2Sp.id2 = relZoneTo.id
                    rSp2Sp.type = "sp2sp_RadiationNetwork_1"
                    rSp2Sp.zoneType = relZoneSpace.objectType
                    rSp2SpService.replace(rSp2Sp)
                }
            }else if (relationAddRequest.relType == "sp2sp_RadiationNetwork_2"){
                for (relZoneTo in relZoneToSpaceList) {
                    val rSp2Sp = RSp2Sp()
                    rSp2Sp.id1 = relZoneSpace.id
                    rSp2Sp.projectId = projectId
                    rSp2Sp.sign = 1
                    rSp2Sp.id2 = relZoneTo.id
                    rSp2Sp.type = "sp2sp_RadiationNetwork_2"
                    rSp2Sp.zoneType = relZoneSpace.objectType
                    rSp2SpService.replace(rSp2Sp)
                }
            }else if (relationAddRequest.relType == "sp2sp_SpaceNeighborhood_1"){
                for (relZoneTo in relZoneToSpaceList) {
                    val rSp2Sp = RSp2Sp()
                    rSp2Sp.id1 = relZoneSpace.id
                    rSp2Sp.projectId = projectId
                    rSp2Sp.sign = 1
                    rSp2Sp.id2 = relZoneTo.id
                    rSp2Sp.type = "sp2sp_SpaceNeighborhood_1"
                    rSp2Sp.zoneType = relZoneSpace.objectType
                    rSp2SpService.replace(rSp2Sp)
                }
            }else if (relationAddRequest.relType == "sp2sp_TrafficNetwork_1"){
                for (relZoneTo in relZoneToSpaceList) {
                    val rSp2Sp = RSp2Sp()
                    rSp2Sp.id1 = relZoneSpace.id
                    rSp2Sp.projectId = projectId
                    rSp2Sp.sign = 1
                    rSp2Sp.id2 = relZoneTo.id
                    rSp2Sp.type = "sp2sp_TrafficNetwork_1"
                    rSp2Sp.zoneType = relZoneSpace.objectType
                    rSp2SpService.replace(rSp2Sp)
                }
            }else if (relationAddRequest.relType == "sp2sp_SpaceNeighborhood_3"){
                for (relZoneTo in relZoneToSpaceList) {
                    val rSp2Sp = RSp2Sp()
                    rSp2Sp.id1 = relZoneSpace.id
                    rSp2Sp.projectId = projectId
                    rSp2Sp.sign = 1
                    rSp2Sp.id2 = relZoneTo.id
                    rSp2Sp.type = "sp2sp_SpaceNeighborhood_3"
                    rSp2Sp.zoneType = relZoneSpace.objectType
                    rSp2SpService.replace(rSp2Sp)
                }
            }
            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse
        }else if (relationAddRequest.relType == "eq2eq_LUDistribution_1"||relationAddRequest.relType == "eq2eq_LUDistribution_2"||relationAddRequest.relType == "eq2eq_HUDistribution_1"
            ||relationAddRequest.relType == "eq2eq_HUDistribution_2"||relationAddRequest.relType == "eq2eq_EquipPower_1"||relationAddRequest.relType == "eq2eq_EquipPower_2"
            ||relationAddRequest.relType == "eq2eq_EquipPower_3"||relationAddRequest.relType == "eq2eq_EquipPower_4"){

            /** 强电类 */
            val equipmentList = EquipmentService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
            if (equipmentList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在或不符合主对象条件限制"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (equipmentList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (relationAddRequest.relType =="eq2eq_EquipPower_1"||relationAddRequest.relType =="eq2eq_EquipPower_2"||
                    relationAddRequest.relType =="eq2eq_EquipPower_3"||relationAddRequest.relType =="eq2eq_EquipPower_4"){
                if (equipmentList[0].classCode!! == "SETDLS"||equipmentList[0].classCode!! == "SETDHS") {
                    /** 符合条件不做操作 */
                }else {
                    /** 不符合主对象条件限制 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = relationAddRequest.mainContent+":不符合主对象条件限制"
                    sCreateResponse.errorType = "1"
                    return sCreateResponse
                }
            }



            val equipment = equipmentList[0]
            for (fromContent in relationAddRequest.fromContent!!){
                /** 去除主对象空间id */
                val equipmentToList = EquipmentService.select(
                    SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!),
                    SFilter.not(SFilter.eq("id",equipment.id!!))).exec()
                if (equipmentToList.size<1){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (equipmentToList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }
            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }
            /** 查询空间 */
            val equipmentToList = EquipmentService.select(
                SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList()),
                SFilter.not(SFilter.eq("id",equipment.id!!))).exec()
            if (relationAddRequest.relType == "eq2eq_HUDistribution_1"){ /** 高压变配电普通连接 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.type = "eq2eq_HUDistribution_1"
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_HUDistribution_2"){/** 高压变配电互备连接 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.type = "eq2eq_HUDistribution_2"
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_LUDistribution_1"){/** 低压配电普通连接 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.type = "eq2eq_LUDistribution_1"
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_LUDistribution_2"){/** 低压配电互备连接 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.type = "eq2eq_LUDistribution_2"
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_EquipPower_1"){/** 设备常规电源 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.type = "eq2eq_EquipPower_1"
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_EquipPower_2"){/** 设备备用电源 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.type = "eq2eq_EquipPower_2"
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_EquipPower_3"){/** 系统常规电源 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.type = "eq2eq_EquipPower_3"
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_EquipPower_4"){/** 系统备用电源 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.type = "eq2eq_EquipPower_4"
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2EqService.replace(rEq2Eq)
                }
            }
            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse
        }else if (relationAddRequest.relType == "eq2eq_ACAirNetwork_1"||relationAddRequest.relType == "eq2eq_ACAirNetwork_3"||relationAddRequest.relType == "eq2eq_ACAirNetwork_2"
            ||relationAddRequest.relType == "eq2eq_ChillWaterLoop_4"|| relationAddRequest.relType == "eq2eq_ChillWaterLoop_1"||relationAddRequest.relType == "eq2eq_ChillWaterLoop_3"
            || relationAddRequest.relType == "eq2eq_ChillWaterLoop_2"||relationAddRequest.relType == "eq2eq_CondWaterNetwork_1"||relationAddRequest.relType == "eq2eq_CoolingWaterLoop_4"
            ||relationAddRequest.relType == "eq2eq_CoolingWaterLoop_1"||relationAddRequest.relType == "eq2eq_CoolingWaterLoop_3"||relationAddRequest.relType == "eq2eq_CoolingWaterLoop_2"
            ||relationAddRequest.relType == "eq2eqFreshAirNetwork_1"||relationAddRequest.relType == "eq2eq_HeatWaterLoop_4"||relationAddRequest.relType == "eq2eq_HeatWaterLoop_1"
            ||relationAddRequest.relType == "eq2eq_HeatWaterLoop_3"||relationAddRequest.relType == "eq2eq_HeatWaterLoop_2"||relationAddRequest.relType == "eq2eq_VentNetwork_1"
            ||relationAddRequest.relType == "eq2eq_VentNetwork_3"||relationAddRequest.relType == "eq2eq_VentNetwork_2"||relationAddRequest.relType == "eq2eq_VRFNetwork_1"){
            /** 暖通空调类 */
            val equipmentList = EquipmentService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
            if (equipmentList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (equipmentList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            val equipment = equipmentList[0]
            for (fromContent in relationAddRequest.fromContent!!){
                /** 去除主对象空间id */
                val equipmentToList = EquipmentService.select(
                    SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!),
                    SFilter.not(SFilter.eq("id",equipment.id!!))).exec()
                if (equipmentToList.size<1){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (equipmentToList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }
            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }
            /** 查询空间 */
            val equipmentToList = EquipmentService.select(
                SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList()),
                SFilter.not(SFilter.eq("id",equipment.id!!))).exec()
            if (relationAddRequest.relType == "eq2eq_ACAirNetwork_1"){ /** 空调送风 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_ACAirNetwork_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_ACAirNetwork_3"){/** 空调排风 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_ACAirNetwork_3"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_ACAirNetwork_2"){/** 空调回风 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_ACAirNetwork_2"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_ChillWaterLoop_4"){/** 空调冷冻水补水 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_ChillWaterLoop_4"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_ChillWaterLoop_1"){/** 空调冷冻水供水 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_ChillWaterLoop_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_ChillWaterLoop_3"){/** 空调冷冻水旁通 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_ChillWaterLoop_3"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_ChillWaterLoop_2"){/**  空调冷冻水回水*/
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_ChillWaterLoop_2"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_CondWaterNetwork_1"){/** 空调冷凝水网络 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_CondWaterNetwork_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_CoolingWaterLoop_4"){/** 空调冷却水补水 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_CoolingWaterLoop_4"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_CoolingWaterLoop_1"){/** 空调冷却水供水 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_CoolingWaterLoop_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_CoolingWaterLoop_3"){/** 空调冷却水旁通 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_CoolingWaterLoop_2"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_CoolingWaterLoop_2"){/** 空调冷却水回水 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_CoolingWaterLoop_2"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eqFreshAirNetwork_1"){/** 新风管网 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eqFreshAirNetwork_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_HeatWaterLoop_4"){/** 采暖水回水 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_HeatWaterLoop_4"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_HeatWaterLoop_1"){/** 采暖水供水 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_HeatWaterLoop_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_HeatWaterLoop_3"){/** 采暖水旁通 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_HeatWaterLoop_3"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_HeatWaterLoop_2"){/** 采暖水回水 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_HeatWaterLoop_2"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_VentNetwork_1"){/** 通风送风 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_VentNetwork_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_VentNetwork_3"){/** 通风不确定 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_VentNetwork_3"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_VentNetwork_2"){/** 通风排风 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_VentNetwork_2"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_VRFNetwork_1"){/** 多联机供回制冷剂 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_VRFNetwork_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }

            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse
        }else if (relationAddRequest.relType == "eq2eq_SupplyWaterNetwork_1"||relationAddRequest.relType == "eq2eq_SupplyWaterNetwork_2"||relationAddRequest.relType == "eq2eq_DrainingWaterNetwork_1"||relationAddRequest.relType == "eq2eq_DrainingWaterNetwork_2"
            ||relationAddRequest.relType == "eq2eq_DrinkingWaterNetwork_1"||relationAddRequest.relType == "eq2eq_DrinkingWaterNetwork_2"||relationAddRequest.relType == "eq2eq_DHWNetwork_1"||relationAddRequest.relType == "eq2eq_DHWNetwork_2"
            ||relationAddRequest.relType == "eq2eq_GasNetwork_1"||relationAddRequest.relType == "eq2eq_GasNetwork_2"||relationAddRequest.relType == "eq2eq_FireWaterNetwork_1"||relationAddRequest.relType == "eq2eq_FireWaterNetwork_2"
            ||relationAddRequest.relType == "eq2eq_FireVentNetwork_1"||relationAddRequest.relType == "eq2eq_RecycleWaterNetwork_1" ||relationAddRequest.relType == "eq2eq_RecycleWaterNetwork_2"){
            /** 给排水类 和 消防类 */
            val equipmentList = EquipmentService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
            if (equipmentList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (equipmentList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }

            val equipment = equipmentList[0]
            for (fromContent in relationAddRequest.fromContent!!){
                /** 去除主对象空间id */
                val equipmentToList = EquipmentService.select(
                    SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!),
                    SFilter.not(SFilter.eq("id",equipment.id!!))).exec()
                if (equipmentToList.size<1){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (equipmentToList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }
            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }
            /** 查询空间 */
            val equipmentToList = EquipmentService.select(
                SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList()),
                SFilter.not(SFilter.eq("id",equipment.id!!))).exec()

            if (relationAddRequest.relType == "eq2eq_SupplyWaterNetwork_1"){ /** 生活给水供水 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_SupplyWaterNetwork_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_SupplyWaterNetwork_2"){/** 生活给水旁通 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_SupplyWaterNetwork_2"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_DrainingWaterNetwork_1"){/** 污水排水 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_DrainingWaterNetwork_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_DrainingWaterNetwork_2"){/** 污水旁通 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_DrainingWaterNetwork_2"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_DrinkingWaterNetwork_1"){/** 直饮水供水 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_DrinkingWaterNetwork_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_DrinkingWaterNetwork_2"){/** 直饮水旁通 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_DrinkingWaterNetwork_2"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_DHWNetwork_1"){/** 生活热水供水 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_DHWNetwork_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_DHWNetwork_2"){/** 生活热水旁通 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_DHWNetwork_2"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_GasNetwork_1"){/** 燃气供气 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_GasNetwork_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_GasNetwork_2"){/** 燃气旁通 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_GasNetwork_2"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_FireWaterNetwork_1"){/** 消防供水网络 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_FireWaterNetwork_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_FireWaterNetwork_2"){/** 消防给水旁通 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_FireWaterNetwork_2"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_FireVentNetwork_1"){/** 消防排烟 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_FireVentNetwork_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_RecycleWaterNetwork_1"){/** 中水供水 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_RecycleWaterNetwork_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_RecycleWaterNetwork_2"){/** 中水旁通 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_RecycleWaterNetwork_2"
                    rEq2EqService.replace(rEq2Eq)
                }
            }

            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse
        }else if (relationAddRequest.relType == "eq2eq_SensorNetwork_1"||relationAddRequest.relType == "eq2eq_ControlRelation_1"
            ||relationAddRequest.relType == "eq2eq_SensorRelationship_ss2eq"||relationAddRequest.relType == "eq2eq_ValveRelationship_vv2eq"||relationAddRequest.relType =="eq2eq_ControlEquipNetwork"){
            /** 测控类 */
            /** 给排水类 和 消防类 */
            val equipmentList = EquipmentService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
            if (equipmentList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (equipmentList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }

            val equipment = equipmentList[0]
            for (fromContent in relationAddRequest.fromContent!!){
                /** 去除主对象空间id */
                val equipmentToList = EquipmentService.select(
                    SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!),
                    SFilter.not(SFilter.eq("id",equipment.id!!))).exec()
                if (equipmentToList.size<1){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (equipmentToList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }
            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }
            /** 查询空间 */
            val equipmentToList = EquipmentService.select(
                SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList()),
                SFilter.not(SFilter.eq("id",equipment.id!!))).exec()
            /** 控制网络 */
            if (relationAddRequest.relType =="eq2eq_ControlEquipNetwork"){
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_ControlEquipNetwork"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_SensorNetwork_1"){ /** 通信连接 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_SensorNetwork_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_ControlRelation_1"){/** 设备控制关系 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_ControlRelation_1"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_SensorRelationship_ss2eq"){/** 传感器测量设备关系 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_SensorRelationship_ss2eq"
                    rEq2EqService.replace(rEq2Eq)
                }
            }else if (relationAddRequest.relType == "eq2eq_ValveRelationship_vv2eq"){/** 阀门限制设备关系 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Eq = REq2Eq()
                    rEq2Eq.id1 = equipment.id
                    rEq2Eq.projectId = projectId
                    rEq2Eq.sign = 1
                    rEq2Eq.id2 = equipmentTo.id
                    rEq2Eq.type = "eq2eq_ValveRelationship_vv2eq"
                    rEq2EqService.replace(rEq2Eq)
                }
            }
            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse
        }else if (relationAddRequest.relType == "eq2sy_ControlRelation_2"||relationAddRequest.relType == "eq2sy_SensorRelationship_ss2sy"||relationAddRequest.relType == "eq2sy_ValveRelationship_vv2sy"){

            if (!relationAddRequest.type.isNullOrEmpty()&&relationAddRequest.type == "cadId"){
                /** 从对象不存在cadId编码 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = "从对象不存在CADID编码"
                sCreateResponse.errorType = "2"
                return sCreateResponse
            }
            /** 给排水类 和 消防类 */
            val equipmentList = EquipmentService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
            if (equipmentList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (equipmentList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }

            val equipment = equipmentList[0]
            for (fromContent in relationAddRequest.fromContent!!){
                /** 去除主对象空间id */
                val equipmentToList = GeneralSystemService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                if (equipmentToList.size<1){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (equipmentToList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }
            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }
            /** 查询空间 */
            val equipmentToList = GeneralSystemService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
            if (relationAddRequest.relType == "eq2sy_ControlRelation_2"){ /** 系统控制关系 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Sy = REq2Sy()
                    rEq2Sy.id1 = equipment.id
                    rEq2Sy.projectId = projectId
                    rEq2Sy.sign = 1
                    rEq2Sy.id2 = equipmentTo.id
                    rEq2Sy.type = "eq2sy_ControlRelation_2"
                    rEq2SyService.replace(rEq2Sy)
                }
            }else if (relationAddRequest.relType == "eq2sy_SensorRelationship_ss2sy"){ /** 传感器测量系统关系 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Sy = REq2Sy()
                    rEq2Sy.id1 = equipment.id
                    rEq2Sy.projectId = projectId
                    rEq2Sy.sign = 1
                    rEq2Sy.id2 = equipmentTo.id
                    rEq2Sy.type = "eq2sy_SensorRelationship_ss2sy"
                    rEq2SyService.replace(rEq2Sy)
                }
            }else if (relationAddRequest.relType == "eq2sy_ValveRelationship_vv2sy"){ /** 阀门限制系统关系 */
                for (equipmentTo in equipmentToList) {
                    val rEq2Sy = REq2Sy()
                    rEq2Sy.id1 = equipment.id
                    rEq2Sy.projectId = projectId
                    rEq2Sy.sign = 1
                    rEq2Sy.id2 = equipmentTo.id
                    rEq2Sy.type = "eq2sy_ValveRelationship_vv2sy"
                    rEq2SyService.replace(rEq2Sy)
                }
            }

            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse
        }else if (relationAddRequest.relType == "eq2sp_SensorRelationship_ss2sp"){
            if (!relationAddRequest.type.isNullOrEmpty()&&relationAddRequest.type == "cadId"){
                /** 从对象不存在cadId编码 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = "从对象不存在CADID编码"
                sCreateResponse.errorType = "2"
                return sCreateResponse
            }
            /** 给排水类 和 消防类 */
            val equipmentList = EquipmentService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
            if (equipmentList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (equipmentList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }

            val equipment = equipmentList[0]

            for (fromContent in relationAddRequest.fromContent!!){
                /** 去除主对象空间id */
                val equipmentToList = ZoneSpaceBaseService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                if (equipmentToList.size<1){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (equipmentToList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }
            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }
            /** 查询空间 */
            val equipmentToList = ZoneSpaceBaseService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()

            for (equipmentTo in equipmentToList) {
                val rEq2Sp = REq2Sp()
                rEq2Sp.id1 = equipment.id
                rEq2Sp.projectId = projectId
                rEq2Sp.sign = 1
                rEq2Sp.id2 = equipmentTo.id
                rEq2Sp.zoneType = equipmentTo.classCode
                rEq2Sp.type = "eq2sp_SensorRelationship_ss2sp"
                rEq2SpService.replace(rEq2Sp)
            }
            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse
        }else if (relationAddRequest.relType == "eq2sp_x"){
            if (!relationAddRequest.type.isNullOrEmpty()&&relationAddRequest.type == "cadId"){
                /** 从对象不存在cadId编码 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = "从对象不存在CADID编码"
                sCreateResponse.errorType = "2"
                return sCreateResponse
            }
            /** 给排水类 和 消防类 */
            val equipmentList = EquipmentService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
            if (equipmentList.size<1){
                /** 主对象不存在 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (equipmentList.size>1){
                /** 主对象编码识别到多个实例 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }

            val equipment = equipmentList[0]

            for (fromContent in relationAddRequest.fromContent!!){
                /** 去除主对象空间id */
                val equipmentToList = ZoneSpaceBaseService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                if (equipmentToList.size<1){
                    /** 从对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":不存在"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
                if (equipmentToList.size>1){
                    /** 从对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = fromContent+":存在多个实例"
                    sCreateResponse.errorType = "2"
                    return sCreateResponse
                }
            }
            /** 处理关系 */
            val setCode = HashSet<String>()
            for (fromContent in relationAddRequest.fromContent!!){
                setCode.add(fromContent)
            }
            /** 查询空间 */
            val equipmentToList = ZoneSpaceBaseService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()

            for (equipmentTo in equipmentToList) {
                val rEq2Sp = REq2Sp()
                rEq2Sp.id1 = equipment.id
                rEq2Sp.projectId = projectId
                rEq2Sp.sign = 1
                rEq2Sp.id2 = equipmentTo.id
                rEq2Sp.zoneType = equipmentTo.classCode
                rEq2Sp.type = "eq2sp_x"
                rEq2SpService.replace(rEq2Sp)
            }
            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
            return sCreateResponse

        }else if (relationAddRequest.relType == "bd2bd_ArchForArch"||relationAddRequest.relType == "bd2fl_ArchForArch"||relationAddRequest.relType == "bd2sh_ArchForArch"
            ||relationAddRequest.relType == "bd2sp_ArchForArch"||relationAddRequest.relType == "fl2bd_ArchForArch"||relationAddRequest.relType == "fl2fl_ArchForArch"
            ||relationAddRequest.relType == "fl2sh_ArchForArch"||relationAddRequest.relType == "fl2sp_ArchForArch"||relationAddRequest.relType == "sh2bd_ArchForArch"
                || relationAddRequest.relType == "sh2fl_ArchForArch"||relationAddRequest.relType == "sh2sh_ArchForArch"||relationAddRequest.relType == "sh2sp_ArchForArch"
                || relationAddRequest.relType == "sp2bd_ArchForArch" ||relationAddRequest.relType == "sp2fl_ArchForArch"||relationAddRequest.relType == "sp2sh_ArchForArch"
                ||relationAddRequest.relType == "sp2sp_ArchForArch"){
//            val sReplaceBuilder = SReplaceBuilder<RBd2Bd>(SMybatisDao(RBd2Bd::class.java))

            if (!relationAddRequest.type.isNullOrEmpty()&&relationAddRequest.type == "cadId"){
                /** 从对象不存在cadId编码 */
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = "主对象不存在CADID编码"
                sCreateResponse.errorType = "1"
                return sCreateResponse
            }
            if (relationAddRequest.relType == "bd2bd_ArchForArch"||relationAddRequest.relType == "bd2fl_ArchForArch"
                    ||relationAddRequest.relType == "bd2sh_ArchForArch" ||relationAddRequest.relType == "bd2sp_ArchForArch"){
                /** 建筑服务于建筑 */
                val buildingList = BuildingService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
                if (buildingList.size<1){
                    /** 主对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                    sCreateResponse.errorType = "1"
                    return sCreateResponse
                }
                if (buildingList.size>1){
                    /** 主对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                    sCreateResponse.errorType = "1"
                    return sCreateResponse
                }

                val building = buildingList[0]
                if (relationAddRequest.relType == "bd2bd_ArchForArch") {

                for (fromContent in relationAddRequest.fromContent!!){
                    /** 去除主对象空间id */
                    val buildingToList = BuildingService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                    if (buildingToList.size<1){
                        /** 从对象不存在 */
                        sCreateResponse.result = SResponseType.failure
                        sCreateResponse.message = fromContent+":不存在"
                        sCreateResponse.errorType = "2"
                        return sCreateResponse
                    }
                    if (buildingToList.size>1){
                        /** 从对象编码识别到多个实例 */
                        sCreateResponse.result = SResponseType.failure
                        sCreateResponse.message = fromContent+":存在多个实例"
                        sCreateResponse.errorType = "2"
                        return sCreateResponse
                    }
                }

                /** 处理关系 */
                val setCode = HashSet<String>()
                for (fromContent in relationAddRequest.fromContent!!){
                    setCode.add(fromContent)
                }
                /** 查询空间 */
                val buildingToList = BuildingService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
                for (buildingTo in buildingToList) {
                    val rBd2Bd = RBd2Bd()
                    rBd2Bd.id1 = building.id
                    rBd2Bd.id2 = buildingTo.id
                    rBd2Bd.projectId = projectId
                    rBd2Bd.type = relationAddRequest.relType
                    rBd2Bd.sign = 1
                    rBd2BdService.replace(rBd2Bd)
                }
                }else if (relationAddRequest.relType == "bd2fl_ArchForArch") {
                    for (fromContent in relationAddRequest.fromContent!!){
                        /** 去除主对象空间id */
                        val floorToList = FloorService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                        if (floorToList.size<1){
                            /** 从对象不存在 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":不存在"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                        if (floorToList.size>1){
                            /** 从对象编码识别到多个实例 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":存在多个实例"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                    }

                    /** 处理关系 */
                    val setCode = HashSet<String>()
                    for (fromContent in relationAddRequest.fromContent!!){
                        setCode.add(fromContent)
                    }
                    /** 查询空间 */
                    val floorToList = FloorService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
                    for (floorTo in floorToList) {
                        val rBd2Fl = RBd2Fl()
                        rBd2Fl.id1 = building.id
                        rBd2Fl.id2 = floorTo.id
                        rBd2Fl.projectId = projectId
                        rBd2Fl.type = relationAddRequest.relType
                        rBd2Fl.sign = 1
//                        sReplaceBuilder.tableName = "relationship.r_bd2bd"
                        rBd2FlService.replace(rBd2Fl)
                    }

                }else if (relationAddRequest.relType =="bd2sh_ArchForArch") {
                    for (fromContent in relationAddRequest.fromContent!!){
                        /** 去除主对象空间id */
                        val shaftToList = ShaftService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                        if (shaftToList.size<1){
                            /** 从对象不存在 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":不存在"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                        if (shaftToList.size>1){
                            /** 从对象编码识别到多个实例 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":存在多个实例"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                    }

                    /** 处理关系 */
                    val setCode = HashSet<String>()
                    for (fromContent in relationAddRequest.fromContent!!){
                        setCode.add(fromContent)
                    }
                    /** 查询空间 */
                    val shaftToList = ShaftService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
                    for (shaftTo in shaftToList) {
                        val rBd2Sh = RBd2Sh()
                        rBd2Sh.id1 = building.id
                        rBd2Sh.id2 = shaftTo.id
                        rBd2Sh.projectId = projectId
                        rBd2Sh.type = relationAddRequest.relType
                        rBd2Sh.sign = 1
//                        sReplaceBuilder.tableName = "relationship.r_bd2sh"
//                        rRBd2BdService.replace(rBd2Bd,sReplaceBuilder)
                        rBd2ShService.replace(rBd2Sh)
                    }
                }else if (relationAddRequest.relType =="bd2sp_ArchForArch") {
                    for (fromContent in relationAddRequest.fromContent!!){
                        /** 去除主对象空间id */
                        val spaceToList = relZoneSpaceService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                        if (spaceToList.size<1){
                            /** 从对象不存在 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":不存在"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                        if (spaceToList.size>1){
                            /** 从对象编码识别到多个实例 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":存在多个实例"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                    }

                    /** 处理关系 */
                    val setCode = HashSet<String>()
                    for (fromContent in relationAddRequest.fromContent!!){
                        setCode.add(fromContent)
                    }
                    /** 查询空间 */
                    val spaceToList = relZoneSpaceService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
                    for (spaceTo in spaceToList) {
                        val rBd2Sp = RBd2Sp()
                        rBd2Sp.id1 = building.id
                        rBd2Sp.id2 = spaceTo.id
                        rBd2Sp.projectId = projectId
                        rBd2Sp.type = relationAddRequest.relType
                        rBd2Sp.sign = 1
                        rBd2Sp.zoneType = spaceTo.classCode
//                        sReplaceBuilder.tableName = "relationship.r_bd2sh"
//                        rRBd2BdService.replace(rBd2Bd,sReplaceBuilder)
                        rBd2SpService.replace(rBd2Sp)
                    }
                }
            }else if (relationAddRequest.relType == "fl2bd_ArchForArch"||relationAddRequest.relType == "fl2fl_ArchForArch"
                ||relationAddRequest.relType == "fl2sh_ArchForArch"||relationAddRequest.relType == "fl2sp_ArchForArch") {
                /** 楼层服务 */
                val floorList = FloorService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
                if (floorList.size<1){
                    /** 主对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                    sCreateResponse.errorType = "1"
                    return sCreateResponse
                }
                if (floorList.size>1){
                    /** 主对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                    sCreateResponse.errorType = "1"
                    return sCreateResponse
                }

                if (relationAddRequest.relType == "fl2bd_ArchForArch") {
                    for (fromContent in relationAddRequest.fromContent!!){
                        /** 去除主对象空间id */
                        val buildingToList = BuildingService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                        if (buildingToList.size<1){
                            /** 从对象不存在 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":不存在"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                        if (buildingToList.size>1){
                            /** 从对象编码识别到多个实例 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":存在多个实例"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                    }

                    /** 处理关系 */
                    val setCode = HashSet<String>()
                    for (fromContent in relationAddRequest.fromContent!!){
                        setCode.add(fromContent)
                    }
                    /** 查询空间 */
                    val buildingToList = BuildingService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
                    for (buildingTo in buildingToList) {
                        val rFl2Bd = RFl2Bd()
                        rFl2Bd.id1 = floorList[0].id
                        rFl2Bd.id2 = buildingTo.id
                        rFl2Bd.projectId = projectId
                        rFl2Bd.type = relationAddRequest.relType
                        rFl2Bd.sign = 1
                        rFl2BdService.replace(rFl2Bd)
                    }
                } else if (relationAddRequest.relType == "fl2fl_ArchForArch") {
                    for (fromContent in relationAddRequest.fromContent!!){
                        /** 去除主对象空间id */
                        val floorToList = FloorService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                        if (floorToList.size<1){
                            /** 从对象不存在 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":不存在"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                        if (floorToList.size>1){
                            /** 从对象编码识别到多个实例 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":存在多个实例"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                    }

                    /** 处理关系 */
                    val setCode = HashSet<String>()
                    for (fromContent in relationAddRequest.fromContent!!){
                        setCode.add(fromContent)
                    }
                    /** 查询空间 */
                    val floorToList = FloorService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
                    for (floorTo in floorToList) {
                        val rFl2Fl = RFl2Fl()
                        rFl2Fl.id1 = floorList[0].id
                        rFl2Fl.id2 = floorTo.id
                        rFl2Fl.projectId = projectId
                        rFl2Fl.type = relationAddRequest.relType
                        rFl2Fl.sign = 1
                        rFl2FlService.replace(rFl2Fl)
                    }
                } else if (relationAddRequest.relType == "fl2sh_ArchForArch") {
                    for (fromContent in relationAddRequest.fromContent!!){
                        /** 去除主对象空间id */
                        val shaftToList = ShaftService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
                        if (shaftToList.size<1){
                            /** 从对象不存在 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":不存在"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                        if (shaftToList.size>1){
                            /** 从对象编码识别到多个实例 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":存在多个实例"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                    }

                    /** 处理关系 */
                    val setCode = HashSet<String>()
                    for (fromContent in relationAddRequest.fromContent!!){
                        setCode.add(fromContent)
                    }
                    /** 查询空间 */
                    val shaftToList = ShaftService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
                    for (shaftTo in shaftToList) {
                        val rFl2Sh = RFl2Sh()
                        rFl2Sh.id1 = floorList[0].id
                        rFl2Sh.id2 = shaftTo.id
                        rFl2Sh.projectId = projectId
                        rFl2Sh.type = relationAddRequest.relType
                        rFl2Sh.sign = 1
                        rFl2Sh.graphCode = relationAddRequest.graphicType
                        rFl2ShService.replace(rFl2Sh)
                    }
                }else if (relationAddRequest.relType == "fl2sp_ArchForArch") {
                    for (fromContent in relationAddRequest.fromContent!!){
                        /** 去除主对象空间id */
                        val spaceToList = relZoneSpaceService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent)).exec()
                        if (spaceToList.size<1){
                            /** 从对象不存在 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":不存在"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                        if (spaceToList.size>1){
                            /** 从对象编码识别到多个实例 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":存在多个实例"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                    }

                    /** 处理关系 */
                    val setCode = HashSet<String>()
                    for (fromContent in relationAddRequest.fromContent!!){
                        setCode.add(fromContent)
                    }
                    /** 查询空间 */
                    val spaceToList = relZoneSpaceService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
                    for (spaceTo in spaceToList) {
                        val rFl2Sp = RFl2Sp()
                        rFl2Sp.id1 = floorList[0].id
                        rFl2Sp.id2 = spaceTo.id
                        rFl2Sp.projectId = projectId
                        rFl2Sp.type = relationAddRequest.relType
                        rFl2Sp.sign = 1
                        rFl2Sp.graphCode = relationAddRequest.graphicType
                        rFl2Sp.zoneType = spaceTo.classCode
                        rFl2SpService.replace(rFl2Sp)
                    }
                }

            }else if (relationAddRequest.relType == "sh2bd_ArchForArch"|| relationAddRequest.relType == "sh2fl_ArchForArch"||
                relationAddRequest.relType == "sh2sh_ArchForArch"||relationAddRequest.relType == "sh2sp_ArchForArch") {
                /** 楼层服务 */
                val shaftList = ShaftService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
                if (shaftList.size<1){
                    /** 主对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                    sCreateResponse.errorType = "1"
                    return sCreateResponse
                }
                if (shaftList.size>1){
                    /** 主对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                    sCreateResponse.errorType = "1"
                    return sCreateResponse
                }
                if (relationAddRequest.relType == "sh2bd_ArchForArch"){
                    for (fromContent in relationAddRequest.fromContent!!){
                        /** 去除主对象空间id */
                        val buildingToList = BuildingService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent)).exec()
                        if (buildingToList.size<1){
                            /** 从对象不存在 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":不存在"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                        if (buildingToList.size>1){
                            /** 从对象编码识别到多个实例 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":存在多个实例"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                    }

                    /** 处理关系 */
                    val setCode = HashSet<String>()
                    for (fromContent in relationAddRequest.fromContent!!){
                        setCode.add(fromContent)
                    }
                    /** 查询空间 */
                    val buildingToList = BuildingService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
                    for (buildingTo in buildingToList) {
                        val rSh2Bd = RSh2Bd()
                        rSh2Bd.id1 = shaftList[0].id
                        rSh2Bd.id2 = buildingTo.id
                        rSh2Bd.projectId = projectId
                        rSh2Bd.type = relationAddRequest.relType
                        rSh2Bd.sign = 1
                        rSh2BdService.replace(rSh2Bd)
                    }
                }else if (relationAddRequest.relType == "sh2fl_ArchForArch"){
                    for (fromContent in relationAddRequest.fromContent!!){
                        /** 去除主对象空间id */
                        val floorToList = FloorService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent)).exec()
                        if (floorToList.size<1){
                            /** 从对象不存在 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":不存在"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                        if (floorToList.size>1){
                            /** 从对象编码识别到多个实例 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":存在多个实例"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                    }

                    /** 处理关系 */
                    val setCode = HashSet<String>()
                    for (fromContent in relationAddRequest.fromContent!!){
                        setCode.add(fromContent)
                    }
                    /** 查询空间 */
                    val floorToList = FloorService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
                    for (floorTo in floorToList) {
                        val rSh2Fl = RSh2Fl()
                        rSh2Fl.id1 = shaftList[0].id
                        rSh2Fl.id2 = floorTo.id
                        rSh2Fl.projectId = projectId
                        rSh2Fl.type = relationAddRequest.relType
                        rSh2Fl.sign = 1
                        rSh2FlService.replace(rSh2Fl)
                    }
                }else if (relationAddRequest.relType == "sh2sh_ArchForArch"){
                    for (fromContent in relationAddRequest.fromContent!!){
                        /** 去除主对象空间id */
                        val shaftToList = ShaftService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent)).exec()
                        if (shaftToList.size<1){
                            /** 从对象不存在 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":不存在"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                        if (shaftToList.size>1){
                            /** 从对象编码识别到多个实例 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":存在多个实例"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                    }

                    /** 处理关系 */
                    val setCode = HashSet<String>()
                    for (fromContent in relationAddRequest.fromContent!!){
                        setCode.add(fromContent)
                    }
                    /** 查询空间 */
                    val shaftToList = ShaftService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
                    for (shaftTo in shaftToList) {
                        val rSh2Sh = RSh2Sh()
                        rSh2Sh.id1 = shaftList[0].id
                        rSh2Sh.id2 = shaftTo.id
                        rSh2Sh.projectId = projectId
                        rSh2Sh.type = relationAddRequest.relType
                        rSh2Sh.sign = 1
                        rSh2Sh.graphCode = relationAddRequest.graphicType
                        rSh2ShService.replace(rSh2Sh)
                    }
                }else if (relationAddRequest.relType == "sh2sp_ArchForArch"){
                    for (fromContent in relationAddRequest.fromContent!!){
                        /** 去除主对象空间id */
                        val spaceToList = relZoneSpaceService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent)).exec()
                        if (spaceToList.size<1){
                            /** 从对象不存在 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":不存在"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                        if (spaceToList.size>1){
                            /** 从对象编码识别到多个实例 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":存在多个实例"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                    }

                    /** 处理关系 */
                    val setCode = HashSet<String>()
                    for (fromContent in relationAddRequest.fromContent!!){
                        setCode.add(fromContent)
                    }
                    /** 查询空间 */
                    val spaceToList = relZoneSpaceService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
                    for (spaceTo in spaceToList) {
                        val rSh2Sp = RSh2Sp()
                        rSh2Sp.id1 = shaftList[0].id
                        rSh2Sp.id2 = spaceTo.id
                        rSh2Sp.projectId = projectId
                        rSh2Sp.type = relationAddRequest.relType
                        rSh2Sp.sign = 1
                        rSh2Sp.graphCode = relationAddRequest.graphicType
                        rSh2Sp.zoneType = spaceTo.classCode
                        rSh2SpService.replace(rSh2Sp)
                    }

                }
            }else if(relationAddRequest.relType == "sp2bd_ArchForArch" ||relationAddRequest.relType == "sp2fl_ArchForArch"
                    ||relationAddRequest.relType == "sp2sh_ArchForArch"||relationAddRequest.relType == "sp2sp_ArchForArch") {

                /** 楼层服务 */
                val zoneSpaceList = relZoneSpaceService.select(SFilter.eq("projectId", projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
                if (zoneSpaceList.size<1){
                    /** 主对象不存在 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = relationAddRequest.mainContent+":不存在"
                    sCreateResponse.errorType = "1"
                    return sCreateResponse
                }
                if (zoneSpaceList.size>1){
                    /** 主对象编码识别到多个实例 */
                    sCreateResponse.result = SResponseType.failure
                    sCreateResponse.message = relationAddRequest.mainContent+":存在多个实例"
                    sCreateResponse.errorType = "1"
                    return sCreateResponse
                }
                if (relationAddRequest.relType == "sp2sp_ArchForArch") {
                    for (fromContent in relationAddRequest.fromContent!!){
                        /** 去除主对象空间id */
                        val spaceToList = relZoneSpaceService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent)).exec()
                        if (spaceToList.size<1){
                            /** 从对象不存在 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":不存在"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                        if (spaceToList.size>1){
                            /** 从对象编码识别到多个实例 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":存在多个实例"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                    }

                    /** 处理关系 */
                    val setCode = HashSet<String>()
                    for (fromContent in relationAddRequest.fromContent!!){
                        setCode.add(fromContent)
                    }
                    /** 查询空间 */
                    val spaceToList = relZoneSpaceService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
                    for (spaceTo in spaceToList) {
                        val rSp2Sp = RSp2Sp()
                        rSp2Sp.id1 = zoneSpaceList[0].id
                        rSp2Sp.id2 = spaceTo.id
                        rSp2Sp.projectId = projectId
                        rSp2Sp.type = relationAddRequest.relType
                        rSp2Sp.sign = 1
                        rSp2Sp.zoneType = zoneSpaceList[0].classCode
                        rSp2SpService.replace(rSp2Sp)
                    }

                }else if (relationAddRequest.relType == "sp2bd_ArchForArch") {
                    for (fromContent in relationAddRequest.fromContent!!){
                        /** 去除主对象空间id */
                        val buildingToList = BuildingService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent)).exec()
                        if (buildingToList.size<1){
                            /** 从对象不存在 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":不存在"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                        if (buildingToList.size>1){
                            /** 从对象编码识别到多个实例 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":存在多个实例"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                    }

                    /** 处理关系 */
                    val setCode = HashSet<String>()
                    for (fromContent in relationAddRequest.fromContent!!){
                        setCode.add(fromContent)
                    }
                    /** 查询空间 */
                    val buildingToList = BuildingService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
                    for (buildingTo in buildingToList) {
                        val rSp2Bd = RSp2Bd()
                        rSp2Bd.id1 = zoneSpaceList[0].id
                        rSp2Bd.id2 = buildingTo.id
                        rSp2Bd.projectId = projectId
                        rSp2Bd.type = relationAddRequest.relType
                        rSp2Bd.sign = 1
                        rSp2Bd.zoneType = zoneSpaceList[0].classCode
                        rSp2BdService.replace(rSp2Bd)
                    }
                }else if (relationAddRequest.relType == "sp2fl_ArchForArch") {
                    for (fromContent in relationAddRequest.fromContent!!){
                        /** 去除主对象空间id */
                        val floorToList = FloorService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent)).exec()
                        if (floorToList.size<1){
                            /** 从对象不存在 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":不存在"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                        if (floorToList.size>1){
                            /** 从对象编码识别到多个实例 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":存在多个实例"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                    }

                    /** 处理关系 */
                    val setCode = HashSet<String>()
                    for (fromContent in relationAddRequest.fromContent!!){
                        setCode.add(fromContent)
                    }
                    /** 查询空间 */
                    val floorToList = FloorService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
                    for (floorTo in floorToList) {
                        val rSp2Fl = RSp2Fl()
                        rSp2Fl.id1 = zoneSpaceList[0].id
                        rSp2Fl.id2 = floorTo.id
                        rSp2Fl.projectId = projectId
                        rSp2Fl.type = relationAddRequest.relType
                        rSp2Fl.sign = 1
                        rSp2Fl.zoneType = zoneSpaceList[0].classCode
                        rSp2FlService.replace(rSp2Fl)
                    }
                }else if (relationAddRequest.relType == "sp2sh_ArchForArch") {
                    for (fromContent in relationAddRequest.fromContent!!){
                        /** 去除主对象空间id */
                        val shaftToList = ShaftService.select(SFilter.eq("projectId", projectId), SFilter.eq(relationAddRequest.type!!, fromContent)).exec()
                        if (shaftToList.size<1){
                            /** 从对象不存在 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":不存在"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                        if (shaftToList.size>1){
                            /** 从对象编码识别到多个实例 */
                            sCreateResponse.result = SResponseType.failure
                            sCreateResponse.message = fromContent+":存在多个实例"
                            sCreateResponse.errorType = "2"
                            return sCreateResponse
                        }
                    }
                    /** 处理关系 */
                    val setCode = HashSet<String>()
                    for (fromContent in relationAddRequest.fromContent!!){
                        setCode.add(fromContent)
                    }
                    /** 查询空间 */
                    val shaftToList = ShaftService.select(SFilter.eq("projectId", projectId), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
                    for (shaftTo in shaftToList) {
                        val rSp2Sh = RSp2Sh()
                        rSp2Sh.id1 = zoneSpaceList[0].id
                        rSp2Sh.id2 = shaftTo.id
                        rSp2Sh.projectId = projectId
                        rSp2Sh.type = relationAddRequest.relType
                        rSp2Sh.sign = 1
                        rSp2Sh.zoneType = zoneSpaceList[0].classCode
                        rSp2ShService.replace(rSp2Sh)
                    }
                }
            }

        }
            sCreateResponse.result = SResponseType.success
            sCreateResponse.message = "添加成功"
        return sCreateResponse
    } // Fun


    fun time():String {
        val df = SimpleDateFormat("yyyy-MM-dd HH:mm:ss") //设置日期格式
        println(df.format(Date())) // new Date()为获取当前系统时间
        return df.format(Date())
    } // Fun

}