package com.persagy.server.services.rel

import com.persagy.server.services.base.RService
import com.persagy.server.datacenter.models.entities.dict.SpaceInfoDic
import com.persagy.server.datacenter.models.entities.objects.ZoneSpace
import com.persagy.server.datacenter.models.entities.rel.RSh2Sp
import com.persagy.server.datacenter.models.entities.rel.RShContainSpBase
import com.persagy.server.datacenter.models.entities.rel.RShContainSpBaseList
import com.persagy.server.services.objects.EquipmentService
import com.persagy.base.extensions.toJson
import com.persagy.database.SFilter
import com.persagy.mybatis.SMybatisDao
import com.persagy.service.SBaseService
import com.persagy.service.SPageContext
import com.persagy.service.models.enums.SResponseType
import com.persagy.service.models.requests.SCreateRequest
import com.persagy.service.models.requests.SQueryRequest
import com.persagy.service.models.responses.SBaseResponse
import com.persagy.service.models.responses.SCreateResponse
import com.persagy.service.models.responses.SQueryResponse

/**
 * 竖井下的业务空间关系服务 目前只支持 默认空间同步
 *
 * @author 付国宝
 */
object RShContainSpBaseService: SBaseService<RShContainSpBase>(SMybatisDao(RShContainSpBase::class.java)) {

    val rSh2SpService = RService(SMybatisDao(RSh2Sp::class.java))

    /**
     * 创建竖井下业务空间关系
     *
     * @param    rShContainSpBaseList    竖井和业务空间的关系对象
     */
    fun create(rShContainSpBaseList: SCreateRequest<RShContainSpBase>): SCreateResponse<RShContainSpBase> {
        return try {

            val projectId = SPageContext.getHeader("ProjectId")
            for (rShContainSpBase in rShContainSpBaseList.content){
                val rSh2Sp = RSh2Sp()
                rSh2Sp.id2 = rShContainSpBase.spaceId
                rSh2Sp.id1 = rShContainSpBase.shaftId
                rSh2Sp.projectId = projectId
                rSh2Sp.sign = 1
                rSh2Sp.zoneType = rShContainSpBase.objectType
                rSh2Sp.type = "sh2sp"
                val isInsert = rSh2SpService.insert(rSh2Sp)
//                if (isInsert){
//                    SCreateResponse(SResponseType.success)
//                }else{
//                    SCreateResponse(SResponseType.failure)
//                }
            }

//            for (rShContainSpBase in rShContainSpBaseList.content){
//                if (rShContainSpBase.objectType == "HeatingZone"){
//                    RShContainSpZoneHeatingService.create(rShContainSpBase)
//                }else if (rShContainSpBase.objectType == "CleanZone"){
//                    RShContainSpZoneCleanService.create(rShContainSpBase)
//                }else if (rShContainSpBase.objectType == "DomesticWaterSupplyZone"){
//                    RShContainSpZoneDomesticWaterSupplyService.create(rShContainSpBase)
//                }else if (rShContainSpBase.objectType == "NetworkZone" ){
//                    RShContainSpZoneNetworkService.create(rShContainSpBase)
//                }else if (rShContainSpBase.objectType == "TenantZone"){
//                    RShContainSpZoneTenantService.create(rShContainSpBase)
//                }else if (rShContainSpBase.objectType == "AirConditioningZone"){
//                    RShContainSpZoneAirConditioningService.create(rShContainSpBase)
//                }else if (rShContainSpBase.objectType == "FunctionZone"){
//                    RShContainSpZoneFunctionService.create(rShContainSpBase)
//                }else if (rShContainSpBase.objectType == "FireZone"){
//                    RShContainSpZoneFireService.create(rShContainSpBase)
//                }else if (rShContainSpBase.objectType == "SecurityZone"){
//                    RShContainSpZoneSecurityService.create(rShContainSpBase)
//                }else if (rShContainSpBase.objectType == "GeneralZone"){
//                    RShContainSpZoneGeneralService.create(rShContainSpBase)
//                }else if (rShContainSpBase.objectType == "PowerSupplyZone"){
//                    RShContainSpZonePowerSupplyService.create(rShContainSpBase)
//                }else if (rShContainSpBase.objectType == "LightingZone"){
//                    RShContainSpZoneLightingService.create(rShContainSpBase)
//                }else{
//                    val sCreateResponse = SCreateResponse<RShContainSpBase>(SResponseType.failure)
//                    sCreateResponse.message = "空间分区类型不存在：" + rShContainSpBase.objectType
//                    sCreateResponse
//                }
//            }
            val sCreateResponse = SCreateResponse<RShContainSpBase>(SResponseType.success)
            sCreateResponse
        } catch (e: Exception) {
            e.printStackTrace()
            SCreateResponse(SResponseType.failure,e.message.toString())
        }
    } // Function create()

    /**
     * 根据对象删除
     *
     * @param    rShContainSpBase    关系对象实例
     * @return
     */
    fun deletes(type: String, rShContainSpBaseList: ArrayList<RShContainSpBase>): SBaseResponse {
        return try {

            val projectId = SPageContext.getHeader("ProjectId")
            for (rShContainSpBase in rShContainSpBaseList){
                val rSh2Sp = RSh2Sp()
                rSh2Sp.id2 = rShContainSpBase.spaceId
                rSh2Sp.id1 = rShContainSpBase.shaftId
                rSh2Sp.projectId = projectId
                rSh2Sp.zoneType = type
                rSh2Sp.type = "sh2sp"
                val isDelete = rSh2SpService.delete(rSh2Sp)
                if (isDelete) {

                } else {

                }
            }
            val sBaseResponse = SBaseResponse(SResponseType.success)
            sBaseResponse


//            if (type == "HeatingZone"){
//                RShContainSpZoneHeatingService.deletes(rShContainSpBaseList)
//            }else if (type == "CleanZone"){
//                RShContainSpZoneCleanService.deletes(rShContainSpBaseList)
//            }else if (type == "DomesticWaterSupplyZone"){
//                RShContainSpZoneDomesticWaterSupplyService.deletes(rShContainSpBaseList)
//            }else if (type == "NetworkZone" ){
//                RShContainSpZoneNetworkService.deletes(rShContainSpBaseList)
//            }else if (type == "TenantZone"){
//                RShContainSpZoneTenantService.deletes(rShContainSpBaseList)
//            }else if (type == "AirConditioningZone"){
//                RShContainSpZoneAirConditioningService.deletes(rShContainSpBaseList)
//            }else if (type == "FunctionZone"){
//                RShContainSpZoneFunctionService.deletes(rShContainSpBaseList)
//            }else if (type == "FireZone"){
//                RShContainSpZoneFireService.deletes(rShContainSpBaseList)
//            }else if (type == "SecurityZone"){
//                RShContainSpZoneSecurityService.deletes(rShContainSpBaseList)
//            }else if (type == "GeneralZone"){
//                RShContainSpZoneGeneralService.deletes(rShContainSpBaseList)
//            }else if (type == "PowerSupplyZone"){
//                RShContainSpZonePowerSupplyService.deletes(rShContainSpBaseList)
//            }else if (type == "LightingZone"){
//                RShContainSpZoneLightingService.deletes(rShContainSpBaseList)
//            }else{
//                val sCreateResponse = SCreateResponse<RShContainSpBase>(SResponseType.failure)
//                sCreateResponse.message = "空间分区类型不存在：$type"
//                sCreateResponse
//            }
        } catch (e: Exception) {
            e.printStackTrace()
            return SBaseResponse(SResponseType.failure, e.message!!)
        }
    } // Function deletes()

    /**
     * 创建竖井下业务空间关系
     *
     * @param    rShContainSpBaseList    竖井和业务空间的关系对象列表
     */
    fun createSh(rShContainSpBaseList: RShContainSpBaseList): SCreateResponse<RShContainSpBase> {
        return try {
            /** 成功集合 */
            val successList = ArrayList<Any>()
            /** 失败集合 */
            val failureList = ArrayList<Any>()
            rSh2SpService.delete("Id1 = '${rShContainSpBaseList.shaftId}'")
            val projectId = SPageContext.getHeader("ProjectId")
            for (spaceId in rShContainSpBaseList.spaceIdList!!){
                val rSh2Sp = RSh2Sp()
                rSh2Sp.id1 = rShContainSpBaseList.shaftId
                rSh2Sp.id2 = spaceId
                rSh2Sp.projectId = projectId
                rSh2Sp.zoneType = rShContainSpBaseList.zoneType
                rSh2Sp.sign = 1
                rSh2Sp.type = "sh2sp"
                val replace = rSh2SpService.replace(rSh2Sp)
                if (replace){
                    successList.add(rSh2Sp)
                }else{
                    failureList.add(rSh2Sp)
                }
            }
            if (successList.size>0){
                val sCreateResponse = SCreateResponse<RShContainSpBase>(SResponseType.success)
                if (failureList.size>0){
                    sCreateResponse.message ="失败对象："+failureList.toJson()
                }
                sCreateResponse
            }else{
                SCreateResponse(SResponseType.failure)
            }
        } catch (e: Exception) {
            e.printStackTrace()
            SCreateResponse(SResponseType.failure,e.message.toString())
        }
    } // Function createSh()

    /**
     * 创建竖井下业务空间关系
     *
     * @param    rShContainSpBaseList    竖井和业务空间的关系对象列表
     */
    fun createsSp(rShContainSpBaseList: RSpContainShBaseList): SCreateResponse<RShContainSpBase> {
        return try {
            /** 成功集合 */
            val successList = ArrayList<Any>()
            /** 失败集合 */
            val failureList = ArrayList<Any>()
            rSh2SpService.delete("id2 = '${rShContainSpBaseList.spaceId}'")
            val projectId = SPageContext.getHeader("ProjectId")
            for (shaftId in rShContainSpBaseList.shaftIdList!!){
                val rSh2Sp = RSh2Sp()
                rSh2Sp.id2 = rShContainSpBaseList.spaceId
                rSh2Sp.id1 = shaftId
                rSh2Sp.projectId = projectId
                rSh2Sp.zoneType = rShContainSpBaseList.zoneType
                rSh2Sp.sign = 1
                rSh2Sp.type = "sh2sp"
                val replace = rSh2SpService.replace(rSh2Sp)
                if (replace){
                    successList.add(rSh2Sp)
                }else{
                    failureList.add(rSh2Sp)
                }
            }
            if (successList.size>0){
                if (failureList.size>0){
                    val sCreateResponse = SCreateResponse<RShContainSpBase>(SResponseType.success)
                    sCreateResponse.message ="失败对象："+failureList.toJson()
                    sCreateResponse
                }else{
                    val sCreateResponse = SCreateResponse<RShContainSpBase>(SResponseType.success)
                    sCreateResponse
                }
            }else{
                SCreateResponse(SResponseType.failure)
            }
        } catch (e:Exception){
            e.printStackTrace()
            SCreateResponse(SResponseType.failure,e.message.toString())
        }
    } // Function createsSp()

    /**
     * 创建竖井下业务空间关系
     *
     * @param    rShContainSpBaseList    竖井和业务空间的关系对象列表
     */
    fun createShSps(type: String?,rShContainSpBaseList: RShContainSpBaseList): SCreateResponse<RShContainSpBaseList> {
        return try {

            /** 成功集合 */
            val successList = ArrayList<Any>()
            /** 失败集合 */
            val failureList = ArrayList<Any>()
            val projectId = SPageContext.getHeader("ProjectId")
            if (!rShContainSpBaseList.spaceIdList.isNullOrEmpty()&&!type.isNullOrEmpty()){
                for (spaceId in rShContainSpBaseList.spaceIdList!!){
                    val rSh2Sp = RSh2Sp()
                    rSh2Sp.id1 = rShContainSpBaseList.shaftId
                    rSh2Sp.id2 = spaceId
                    rSh2Sp.projectId = projectId
                    rSh2Sp.zoneType = type
                    rSh2Sp.sign = 1
                    rSh2Sp.type = "sh2sp"
                    val replace = rSh2SpService.replace(rSh2Sp)
                    if (replace){
                        successList.add(rSh2Sp)
                    }else{
                        failureList.add(rSh2Sp)
                    }
                }
                if (successList.size>0){
                    try {
                        /** 处理关系标记 */
                        val listType = ArrayList<String>()
                        listType.add("sh2bd")
                        listType.add("eq2sh")
                        for (type in listType){
                            val entity = EquipmentService.relationTypeProjectservice.select(SFilter.eq("projectId", projectId!!), SFilter.eq("relationType", type)).entity()
                            if (entity!=null){
                                entity.computationalState = 2
                                EquipmentService.relationTypeProjectservice.update(entity)
                            }
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                    }
                    val sCreateResponse = SCreateResponse<RShContainSpBaseList>(SResponseType.success)
                    if (failureList.size>0){
                        sCreateResponse.message ="失败对象："+failureList.toJson()
                    }
                    sCreateResponse
                }else{
                    SCreateResponse(SResponseType.failure)
                }
            }else{
                val sCreateResponse = SCreateResponse<RShContainSpBaseList>(SResponseType.success)
                sCreateResponse.message = "空间类型和空间列表不能为空"
                sCreateResponse
            }


//            if (type == "HeatingZone"){
//                RShContainSpZoneHeatingService.createShSps(rShContainSpBaseList)
//            }else if (type == "CleanZone"){
//                RShContainSpZoneCleanService.createShSps(rShContainSpBaseList)
//            }else if (type == "DomesticWaterSupplyZone"){
//                RShContainSpZoneDomesticWaterSupplyService.createShSps(rShContainSpBaseList)
//            }else if (type == "NetworkZone" ){
//                RShContainSpZoneNetworkService.createShSps(rShContainSpBaseList)
//            }else if (type == "TenantZone"){
//                RShContainSpZoneTenantService.createShSps(rShContainSpBaseList)
//            }else if (type == "AirConditioningZone"){
//                RShContainSpZoneAirConditioningService.createShSps(rShContainSpBaseList)
//            }else if (type == "FunctionZone"){
//                RShContainSpZoneFunctionService.createShSps(rShContainSpBaseList)
//            }else if (type == "FireZone"){
//                RShContainSpZoneFireService.createShSps(rShContainSpBaseList)
//            }else if (type == "SecurityZone"){
//                RShContainSpZoneSecurityService.createShSps(rShContainSpBaseList)
//            }else if (type == "GeneralZone"){
//                RShContainSpZoneGeneralService.createShSps(rShContainSpBaseList)
//            }else if (type == "PowerSupplyZone"){
//                RShContainSpZonePowerSupplyService.createShSps(rShContainSpBaseList)
//            }else if (type == "LightingZone"){
//                RShContainSpZoneLightingService.createShSps(rShContainSpBaseList)
//            }else{
//                val sCreateResponse = SCreateResponse<RShContainSpBaseList>(SResponseType.failure)
//                sCreateResponse.message = "空间分区类型不存在：$type"
//                sCreateResponse
//            }
        } catch (e: Exception) {
            e.printStackTrace()
            SCreateResponse(SResponseType.failure,e.message.toString())
        }
    }


    /**
     * 创建竖井下业务空间关系
     *
     * @param    rSpContainShBaseList    竖井和业务空间的关系对象列表
     */
    fun createSpShs(type: String,rSpContainShBaseList: RSpContainShBaseList): SCreateResponse<RSpContainShBaseList> {
        return try {
            /** 成功集合 */
            val successList = ArrayList<Any>()
            /** 失败集合 */
            val failureList = ArrayList<Any>()
            val projectId = SPageContext.getHeader("ProjectId")

            if (!rSpContainShBaseList.shaftIdList.isNullOrEmpty()){
                for (shaftId in rSpContainShBaseList.shaftIdList!!){
                    val rSh2Sp = RSh2Sp()
                    rSh2Sp.id2 = rSpContainShBaseList.spaceId
                    rSh2Sp.id1 = shaftId
                    rSh2Sp.projectId = projectId
                    rSh2Sp.zoneType = type
                    rSh2Sp.sign = 1
                    rSh2Sp.type = "sh2sp"
                    val replace = rSh2SpService.replace(rSh2Sp)
                    if (replace){
                        successList.add(rSh2Sp)
                    }else{
                        failureList.add(rSh2Sp)
                    }
                }
                if (successList.size>0){
                    if (failureList.size>0){
                        val sCreateResponse = SCreateResponse<RSpContainShBaseList>(SResponseType.success)
                        sCreateResponse.message ="失败对象："+failureList.toJson()
                        sCreateResponse
                    }else{
                        val sCreateResponse = SCreateResponse<RSpContainShBaseList>(SResponseType.success)
                        sCreateResponse
                    }
                }else{
                    SCreateResponse(SResponseType.failure)
                }
            }else{
                SCreateResponse(SResponseType.success)
            }

//            if (type == "HeatingZone"){
//                RShContainSpZoneHeatingService.createSpShs(rSpContainShBaseList)
//            }else if (type == "CleanZone"){
//                RShContainSpZoneCleanService.createSpShs(rSpContainShBaseList)
//            }else if (type == "DomesticWaterSupplyZone"){
//                RShContainSpZoneDomesticWaterSupplyService.createSpShs(rSpContainShBaseList)
//            }else if (type == "NetworkZone" ){
//                RShContainSpZoneNetworkService.createSpShs(rSpContainShBaseList)
//            }else if (type == "TenantZone"){
//                RShContainSpZoneTenantService.createSpShs(rSpContainShBaseList)
//            }else if (type == "AirConditioningZone"){
//                RShContainSpZoneAirConditioningService.createSpShs(rSpContainShBaseList)
//            }else if (type == "FunctionZone"){
//                RShContainSpZoneFunctionService.createSpShs(rSpContainShBaseList)
//            }else if (type == "FireZone"){
//                RShContainSpZoneFireService.createSpShs(rSpContainShBaseList)
//            }else if (type == "SecurityZone"){
//                RShContainSpZoneSecurityService.createSpShs(rSpContainShBaseList)
//            }else if (type == "GeneralZone"){
//                RShContainSpZoneGeneralService.createSpShs(rSpContainShBaseList)
//            }else if (type == "PowerSupplyZone"){
//                RShContainSpZonePowerSupplyService.createSpShs(rSpContainShBaseList)
//            }else if (type == "LightingZone"){
//                RShContainSpZoneLightingService.createSpShs(rSpContainShBaseList)
//            }else{
//                val sCreateResponse = SCreateResponse<RSpContainShBaseList>(SResponseType.failure)
//                sCreateResponse.message = "空间分区类型不存在：$type"
//                sCreateResponse
//            }
        } catch (e: Exception) {
            e.printStackTrace()
            SCreateResponse(SResponseType.failure,e.message.toString())
        }
    }

    /**
     * 创建竖井下业务空间关系
     *
     * @param    rShContainSpBaseList    竖井和业务空间的关系对象列表
     */
    fun createShSpsReplace(type: String,buildingId: String,floorId: String,rShContainSpBaseList: RShContainSpBaseList): SCreateResponse<RShContainSpBaseList> {
        return try {
            val projectId = SPageContext.getHeader("ProjectId")
            val allSpaceIdList = ArrayList<String>()//和竖井关联的并且为当前空间类型的业务空间id列表
            val spaceIdList = ArrayList<String>()//和竖井关联且为当前空间类型、所在建筑楼层为当前建筑楼层的的业务空间id列表
            val allSpaceIdFilterList = ArrayList<SFilter>()
            val zoneSpaceBaseTableService = SBaseService(SMybatisDao(ZoneSpace::class.java))


            //查出和当前竖井关联并为当前空间类型的的业务空间id
            val list1 =  rSh2SpService.select(SFilter.eq("projectId",projectId!!),SFilter.eq("Id1",rShContainSpBaseList.shaftId!!),SFilter.eq("zoneType",type)).projection("id2").distinct().exec()
            for(rShContainSpBase in list1){
                allSpaceIdList.add(rShContainSpBase.id2!!)
            }
            allSpaceIdFilterList.add(SFilter.eq("projectId",projectId!!))
            allSpaceIdFilterList.add(SFilter.eq("objectType",type))
            allSpaceIdFilterList.add(SFilter.eq("buildingId",buildingId))
            allSpaceIdFilterList.add(SFilter.eq("floorId",floorId))
            if (allSpaceIdList.size>0){
                allSpaceIdFilterList.add(SFilter.inList("id",allSpaceIdList))
            }
            var spaceList = zoneSpaceBaseTableService.select(allSpaceIdFilterList).projection("id").exec()
            for(zoneSpaceBaseTable in spaceList){
                spaceIdList.add(zoneSpaceBaseTable.id!!)
            }


            /** 成功集合 */
            val successList = ArrayList<Any>()
            /** 失败集合 */
            val failureList = ArrayList<Any>()
            if (spaceIdList.size>0){
                for(oldSpaceId in spaceIdList){
                    rSh2SpService.delete("Id1 = '${rShContainSpBaseList.shaftId}' and Id2 = '${oldSpaceId}' and type = 'sh2sp'")
                }
            }
            if (!rShContainSpBaseList.spaceIdList.isNullOrEmpty()){
                for (spaceId in rShContainSpBaseList.spaceIdList!!){
                    val rSh2Sp = RSh2Sp()
                    rSh2Sp.id1 = rShContainSpBaseList.shaftId
                    rSh2Sp.id2 = spaceId
                    rSh2Sp.projectId = projectId
                    rSh2Sp.sign = 1
                    rSh2Sp.zoneType = type
                    rSh2Sp.type = "sh2sp"
                    val replace = rSh2SpService.replace(rSh2Sp)
                    if (replace){
                        successList.add(rSh2Sp)
                    }else{
                        failureList.add(rSh2Sp)
                    }
                }
                if (successList.size>0){
                    try {
                        /** 处理关系标记 */
                        val listType = ArrayList<String>()
                        listType.add("sh2bd")
                        listType.add("eq2sh")
                        for (type in listType){
                            val entity = EquipmentService.relationTypeProjectservice.select(SFilter.eq("projectId", projectId!!), SFilter.eq("relationType", type)).entity()
                            if (entity!=null){
                                entity.computationalState = 2
                                EquipmentService.relationTypeProjectservice.update(entity)
                            }
                        }
                    } catch (e: Exception) {
                        e.printStackTrace()
                    }
                    val sCreateResponse = SCreateResponse<RShContainSpBaseList>(SResponseType.success)
                    if (failureList.size>0){
                        sCreateResponse.message ="失败对象："+failureList.toJson()
                    }
                    sCreateResponse
                }else{
                    SCreateResponse(SResponseType.failure)
                }
            }else{
                SCreateResponse(SResponseType.success)
            }

//            if (type == "HeatingZone"){
//                RShContainSpZoneHeatingService.createShSpsReplace(spaceIdList,rShContainSpBaseList)
//            }else if (type == "CleanZone"){
//                RShContainSpZoneCleanService.createShSpsReplace(spaceIdList,rShContainSpBaseList)
//            }else if (type == "DomesticWaterSupplyZone"){
//                RShContainSpZoneDomesticWaterSupplyService.createShSpsReplace(spaceIdList,rShContainSpBaseList)
//            }else if (type == "NetworkZone" ){
//                RShContainSpZoneNetworkService.createShSpsReplace(spaceIdList,rShContainSpBaseList)
//            }else if (type == "TenantZone"){
//                RShContainSpZoneTenantService.createShSpsReplace(spaceIdList,rShContainSpBaseList)
//            }else if (type == "AirConditioningZone"){
//                RShContainSpZoneAirConditioningService.createShSpsReplace(spaceIdList,rShContainSpBaseList)
//            }else if (type == "FunctionZone"){
//                RShContainSpZoneFunctionService.createShSpsReplace(spaceIdList,rShContainSpBaseList)
//            }else if (type == "FireZone"){
//                RShContainSpZoneFireService.createShSpsReplace(spaceIdList,rShContainSpBaseList)
//            }else if (type == "SecurityZone"){
//                RShContainSpZoneSecurityService.createShSpsReplace(spaceIdList,rShContainSpBaseList)
//            }else if (type == "GeneralZone"){
//                RShContainSpZoneGeneralService.createShSpsReplace(spaceIdList,rShContainSpBaseList)
//            }else if (type == "PowerSupplyZone"){
//                RShContainSpZonePowerSupplyService.createShSpsReplace(spaceIdList,rShContainSpBaseList)
//            }else if (type == "LightingZone"){
//                RShContainSpZoneLightingService.createShSpsReplace(spaceIdList,rShContainSpBaseList)
//            }else{
//                val sCreateResponse = SCreateResponse<RShContainSpBaseList>(SResponseType.failure)
//                sCreateResponse.message = "空间分区类型不存在：$type"
//                sCreateResponse
//            }
        } catch (e: Exception) {
            e.printStackTrace()
            SCreateResponse(SResponseType.failure,e.message.toString())
        }
    }

    /**
     * 查询空间类型和名称
     */
    fun spaceTypeQuery(projectId: String, shaftId: String): SQueryResponse<SpaceInfoDic> {
        return try {
            var request = SQueryRequest()
            val service = SBaseService(SMybatisDao(SpaceInfoDic::class.java))
            val queryBuilder = service.select(request.filters)
            queryBuilder.tableName = "public.f_get_sh_space_type('$projectId','$shaftId')"
            val pageQuery = queryBuilder.pageQuery(1, 1000)
            SQueryResponse(pageQuery)
        } catch (e: Exception) {
            e.printStackTrace()
            SQueryResponse(SResponseType.failure, e.message!!)
        }
    } //  Fun spaceTypeQuery


} // Object RShContainSpBaseService