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

package com.persagy.server.datacenter.services.relation_calc.tools

import com.persagy.mybatis.SMybatisDao
import com.persagy.server.datacenter.models.entities.graphtype.rel.RelShaft
import com.persagy.server.datacenter.datacenter.models.entities.graphtype.rel.RelZoneSpace
import com.persagy.server.datacenter.models.entities.rel.RPe2Sp
import com.persagy.server.datacenter.models.entities.rel.RPeInSh
import com.persagy.service.SObjectService
import org.springframework.stereotype.Service
import java.text.SimpleDateFormat
import java.util.*

/**
 * 关系工具类
 *
 * @author wx  <zhangweixin@sagacloud.com>
 * @date  2020/11/7 16:05
 */
@Service
class ManualRelationTools {

    /**
     * 单独处理
     *
     * 机电类服务区域关系
     * 资产所在区域关系
     * **********************************************************
     * 设备对设备
     *
     * 低压配电网络
     * 高压变配电网络
     * 设备供电关系
     * 空调冷冻水环路
     * 空调冷却水环路
     * 空调冷凝水网络
     * 采暖水环路
     * 空调风管网
     * 新风管网
     * 通风管网
     * 多联机系统
     * 给水网络
     * 排水网络
     * 中水系统
     * 直饮水网络
     * 生活热水网络
     * 燃气系统
     * 消防供水网络
     * 消防排烟网络
     * 传感器通信网络
     * 设备控制关系
     * 传感器关系
     * 阀门关系
     * 控制设备网络
     ***************************************************
     * 空间对空间
     *
     * 空间邻接关系
     * 建筑交通网络
     * 空气流通网络
     * 光照辐射网络
     *
     */

    /** 资产所在的空间 *******************************************************/
    private val rPeInSpBaseService = SObjectService(SMybatisDao(RPe2Sp::class.java))
    /** 资产所在的竖井 */
    private val rPeInShService = SObjectService(SMybatisDao(RPeInSh::class.java))


    /** 资产服务 */
//    private val relPropertyService = SObjectService(SMybatisDao(RelProperty::class.java))
    /** 竖井 */
    private val relShaftService = SObjectService(SMybatisDao(RelShaft::class.java))
    /** 空间 */
    private val relZoneSpaceService = SObjectService(SMybatisDao(RelZoneSpace::class.java))



    /**
     * 添加关系
     */
//    fun  addRel(relationAddRequest: RelationAddRequest): ManualRelationCalcSCreateResponse{
//        val sCreateResponse = ManualRelationCalcSCreateResponse()
//        when (relationAddRequest.graphicCode) {
//
//            Opt.PropertyInArch -> {
//                /** 资产所在区域关系 */
//               return pe2ShOr2Sp(relationAddRequest)
//            }
//            Opt.MechForArch -> {
//                /** 机电类服务区域关系 */
//            }
//            Opt.SpaceNeighborhood,Opt.TrafficNetwork,Opt.ConvectionNetwork,Opt.RadiationNetwork -> {
//                /** 空间邻接关系,建筑交通网络,空气流通网络,光照辐射网络 */
//            }
//            else ->{
//                /** 设备与与设备 */
//            }
//        }
//
//        return sCreateResponse
//    }

    /**
     * 资产和竖井的关系，或资产和空间的关系
     *
     * @param relationAddRequest        入参对象
     * @return 返回结果
     */
//    fun pe2ShOr2Sp(relationAddRequest: RelationAddRequest): ManualRelationCalcSCreateResponse {
//        val sCreateResponse = ManualRelationCalcSCreateResponse()
//        if (relationAddRequest.type == "cadId"){
//            sCreateResponse.result = SResponseType.failure
//            sCreateResponse.message = "从对象不存在CADID编码"
//            sCreateResponse.errorType = "2"
//            return sCreateResponse
//        }
//        /** 查询资产 */
//        val relPropertyList = relPropertyService.select(SFilter.eq("projectId", Opt.projectId!!), SFilter.eq(relationAddRequest.type!!, relationAddRequest.mainContent!!)).exec()
//        if (relPropertyList.size == 0) {
//            /** 数据不存在 */
//            sCreateResponse.result = SResponseType.failure
//            sCreateResponse.message = relationAddRequest.mainContent+":编码不存在"
//            sCreateResponse.errorType = "1"
//            return sCreateResponse
//        }else if (relPropertyList.size > 1) {
//            /** 主对象编码识别到多个实例 */
//            sCreateResponse.result = SResponseType.failure
//            sCreateResponse.message = relationAddRequest.mainContent+":编码存在多个实例"
//            sCreateResponse.errorType = "1"
//            return sCreateResponse
//        }
//
//        if (relationAddRequest.relType == Opt.Pe2Sh){
//            /** 资产所在竖井 */
//            for (fromContent in relationAddRequest.fromContent!!){
//                val relZoneSpaceList = relZoneSpaceService.select(SFilter.eq("projectId", Opt.projectId!!), SFilter.eq(relationAddRequest.type!!, fromContent!!)).exec()
//                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 relShaftList = relShaftService.select(SFilter.eq("projectId", Opt.projectId!!), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
//            /**  遍历从对象列表 */
//            for (relShaft in relShaftList){
//                val rPe2Sh = RPeInSh(relPropertyList[0].id,relShaft.id,relationAddRequest.relType!!,Opt.projectId,relationAddRequest.graphicCode)
//                rPeInShService.replace(rPe2Sh)
//            }
//
//        } else if (relationAddRequest.relType == Opt.Pe2Sp) {
//            /** 资产所在业务空间 */
//
//            for (fromContent in relationAddRequest.fromContent!!){
//                val relZoneSpaceList = relShaftService.select(SFilter.eq("projectId", Opt.projectId!!), SFilter.eq(relationAddRequest.type!!, fromContent)).exec()
//                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", Opt.projectId!!), SFilter.inList(relationAddRequest.type!!, setCode.toList())).exec()
//            /** 遍历空间列表 */
//            for (relZoneSpace in relZoneSpaceList){
//                val rPe2Sp = RPe2Sp(relPropertyList[0].id,relZoneSpace.id,relationAddRequest.relType!!,Opt.projectId,relationAddRequest.graphicCode,relZoneSpace.objectType)
//
//                rPeInSpBaseService.replace(rPe2Sp)
//            }
//        }
//        sCreateResponse.result = SResponseType.success
//        sCreateResponse.message = "添加成功"
//        return sCreateResponse
//    }


//    fun mechForArch(relationAddRequest: RelationAddRequest): ManualRelationCalcSCreateResponse {
//
//        val sCreateResponse = ManualRelationCalcSCreateResponse()
//        if (relationAddRequest.relType == Opt.Sy2Bd){
//            /** 系统服务的建筑 */
//        }else if (relationAddRequest.relType == Opt.Sy2Fl) {
//            /** 系统服务的楼层 */
//        }else if (relationAddRequest.relType == Opt.Sy2Sh) {
//            /** 系统服务的竖井 */
//        }else if (relationAddRequest.relType == Opt.Sy2Sp) {
//            /** 系统服务的空间 */
//        }else if (relationAddRequest.relType == Opt.Eq2Bd) {
//            /** 设备服务的建筑 */
//        }else if (relationAddRequest.relType == Opt.Eq2Fl) {
//            /** 设备服务的楼层 */
//        }else if (relationAddRequest.relType == Opt.Eq2Sh) {
//            /** 设备服务的竖井 */
//            /** 设备服务于竖井 */
//            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", Opt.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", Opt.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
//                }
//            }
//
//        }else if (relationAddRequest.relType == Opt.Eq2Sp) {
//            /** 设备服务的空间 */
//        }
//        sCreateResponse.result = SResponseType.success
//        sCreateResponse.message = "添加成功"
//        return sCreateResponse
//    }



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

}