/*
 * *********************************************************************************************************************
 *
 *          !!
 *        .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.controllers.relation_calc

import com.persagy.server.services.relation_calc.RelationCalcService
import com.persagy.service.SPageContext
import com.persagy.service.models.responses.SBaseResponse
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
 * 关系计算
 *
 * @author  庞利祥 <sybotan@126.com>
 */
@Tag(name = "015、关系计算")
@RestController
@RequestMapping("/relation-calc")
class RelationCalcController {
    companion object {
        /** 日志 */
        private val logger = LoggerFactory.getLogger(RelationCalcController::class.java)
    } // Companion object
    @Autowired
    lateinit var service: RelationCalcService

    /**
     * 建筑下的业务空间
     *
     * @param  objectTypes  参与计算的业务空间(为空表示所有业务空间类型)，以英文逗号隔开
     */
    @Operation(summary = "建筑下的业务空间", description = "objectTypes 参与计算的业务空间(为空表示所有业务空间类型)，以英文逗号隔开 HeatingZone,CleanZone,DomesticWaterSupplyZone,NetworkZone,TenantZone,AirConditioningZone,FunctionZone,FireZone,SecurityZone,GeneralZone,PowerSupplyZone,LightingZone")
    @PostMapping(value = ["/bd2sp"])
    fun calcBd2Sp(objectTypes: String?): SBaseResponse {
        logger.debug("calcBd2Sp --------------")
        val projectId = SPageContext.getHeader("projectId").toString()
        return service.calcBd2Sp(objectTypes,projectId)
    } // Function calcBd2Sp()

    /**
     * 设备所在建筑
     */
    @Operation(summary = "设备所在建筑", description = "")
    @PostMapping(value = ["/eq2bd"])
    fun calcEq2Bd(relationType: String?): SBaseResponse {
        logger.debug("calcEq2Bd --------------")
        val projectId = SPageContext.getHeader("projectId").toString()
        return service.calcEq2Bd(projectId)
    } // Function calcEq2Bd()

    /**
     * 设备所在楼层
     */
    @Operation(summary = "设备所在楼层", description = "")
    @PostMapping(value = ["/eq2fl"])
    fun calcEq2Fl(): SBaseResponse{
        logger.debug("calcEq2Fl --------------")
        val projectId = SPageContext.getHeader("projectId").toString()
        return service.calcEq2Fl(projectId)
    } // Function calcEq2Fl()


    /**
     * 设备所在竖井
     */
    @Operation(summary = "设备所在竖井", description = "")
    @PostMapping(value = ["/eq2sh"])
    fun calcEq2Sh(): SBaseResponse {
        logger.debug("calcEq2Sh --------------")
        val projectId = SPageContext.getHeader("projectId").toString()
        return service.calcEq2Sh(projectId)
    } // Function calcEq2Sh()

    /**
     * 设备所在业务空间
     * @param   objectTypes tables 参与计算的业务空间(为空表示所有业务空间类型)，以英文逗号隔开 HeatingZone,CleanZone,DomesticWaterSupplyZone,NetworkZone,TenantZone,AirConditioningZone FunctionZone,FireZone,SecurityZone,GeneralZone,PowerSupplyZone,LightingZone
     * @param   sign        是否要删除手动维护的关系（不填默认为false）, boolean型, 值为true或false (true表示删除自动和手动维护的关系, false表示只删除自动计算的的关系)
     */
    @Operation(summary = "设备所在业务空间", description = "objectTypes 参与计算的业务空间(为空表示所有业务空间类型)，以英文逗号隔开 HeatingZone,CleanZone,DomesticWaterSupplyZone,NetworkZone,TenantZone,AirConditioningZone,  " +
            "FunctionZone,FireZone,SecurityZone,GeneralZone,PowerSupplyZone,LightingZone\n " +
            "sign 是否要删除手动维护的关系（不填默认为false）, boolean型, 值为true或false (true表示删除自动和手动维护的关系, false表示只删除自动计算的的关系)")
    @PostMapping(value = ["/eq2sp_in"])
    fun calcEq2Sp(objectTypes: String?): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        logger.debug("calcEq2Sp --------------  $projectId")
        return service.calcEq2Sp(objectTypes,projectId, false)
    } // Function calcEq2Sp()

    /**
     * 楼层贯通关系
     *
     * @param   sign1   表示r_fl_through_fl表中要被删除的sign值
     * @param   sign2   同上 与sign1是逻辑或的关系
     */
    @Operation(summary = "楼层贯通关系", description = "")
    @PostMapping(value = ["/fl2fl"])
    fun calcFl2Fl(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        logger.debug("calcFl2Fl --------------$projectId")
        return service.calcFl2Fl(projectId)
    } // Function calcFl2Fl()

    /**
     * 楼层下的业务空间
     *
     * @param  objectTypes  参与计算的业务空间(为空表示所有业务空间类型)，以英文逗号隔开
     */
    @Operation(summary = "楼层下的业务空间", description = "objectTypes 参与计算的业务空间(为空表示所有业务空间类型)，以英文逗号隔开 HeatingZone,CleanZone,DomesticWaterSupplyZone,NetworkZone,TenantZone,AirConditioningZone,FunctionZone,FireZone,SecurityZone,GeneralZone,PowerSupplyZone,LightingZone")
    @PostMapping(value = ["/fl2sp"])
    fun calcFl2Sp(objectTypes: String?): SBaseResponse {
        logger.debug("calcFl2Sp --------------")
        val projectId = SPageContext.getHeader("projectId").toString()
        return service.calcFl2Sp(objectTypes,projectId)
    } // Function calcFl2Sp()

    /**
     * 资产所在建筑
     */
    @Operation(summary = "资产所在建筑", description = "")
    @PostMapping(value = ["/pe2bd"])
    fun calcPe2Bd(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        logger.debug("calcPe2Bd --------------$projectId")
        return service.calcPe2Bd(projectId)
    } // Function calcPe2Bd()

    /**
     * 资产所在楼层
     */
    @Operation(summary = "资产所在楼层", description = "")
    @PostMapping(value = ["/pe2fl"])
    fun calcPe2Fl(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        logger.debug("calcPe2Fl --------------$projectId")
        return service.calcPe2Fl(projectId)
    } // Function calcPe2Fl()

    /**
     * 资产所在竖井
     */
    @Operation(summary = "资产所在竖井", description = "")
    @PostMapping(value = ["/pe2sh"])
    fun calcPe2Sh(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        logger.debug("calcPe2Sh --------------$projectId")
        return service.calcPe2Sh(projectId)
    } // Function property2Shaft()

    /**
     * 资产所在业务空间
     */
    @Operation(summary = "资产所在业务空间", description = "")
    @PostMapping(value = ["/pe2sp"])
    fun calcPe2Sp(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        logger.debug("calcPe2Sp --------------$projectId")
        return service.calcPe2Sp(projectId)
    } // Function calcPe2Sp()

    /**
     * 建筑下的竖井
     */
    @Operation(summary = "建筑下的竖井", description = "************************************************************")
    @PostMapping(value = ["/sh2bd"])
    fun calcSh2Bd(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        logger.debug("calcSh2Bd --------------$projectId")
        return service.calcSh2Bd(projectId)
    } // Function calcSh2Bd()

    /**
     * 竖井贯通
     */
    @Operation(summary = "竖井贯通", description = "")
    @PostMapping(value = ["/sh2sh"])
    fun calcSh2Sh(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        logger.debug("calcSh2Sh --------------$projectId")
        return service.calcSh2Sh(projectId)
    } // Function calcSh2Sh()

    /**
     * 建筑下的系统设备部件
     */
    @Operation(summary = "建筑下的系统设备部件", description = "")
    @PostMapping(value = ["/syeq2bd"])
    fun calcSyEq2Bd(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        logger.debug("calcSyEq2Bd --------------$projectId")
        return service.calcSyEq2Bd(projectId)
    } // Function calcSyEq2Bd()

    /**
     * 系统所在建筑
     */
    @Operation(summary = "系统所在建筑", description = "")
    @PostMapping(value = ["/sy2bd"])
    fun calcSy2Bd(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        logger.debug("calcSy2Bd --------------$projectId")
        return service.calcSy2Bd(projectId)
    } // Function calcSy2Bd()

    /**
     * 系统所在楼层
     */
    @Operation(summary = "系统所在楼层", description = "")
    @PostMapping(value = ["/sy2fl"])
    fun calcSy2Fl(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        logger.debug("calcSy2Fl --------------$projectId")
        return service.calcSy2Fl(projectId)
    } // Function calcSy2Fl()

    /**
     * 系统所在竖井
     */
    @Operation(summary = "系统所在竖井", description = "")
    @PostMapping(value = ["/sy2sh"])
    fun calcSy2Sh(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        logger.debug("calcSy2Sh --------------$projectId")
        return service.calcSy2Sh(projectId)
    } // Function calcSy2Sh()

    /**
     * 系统所在业务空间
     */
    @Operation(summary = "系统所在业务空间", description = "")
    @PostMapping(value = ["/sy2sp"])
    fun calcSy2Sp(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        logger.debug("calcSy2Sp --------------$projectId")
        return service.calcSy2Sp(projectId)
    } // Function calcSy2Sp()

    /**
     * 空间普通交通
     */
    @Operation(summary = "空间普通交通", description = "")
    @PostMapping(value = ["/sp2sp_TrafficNetwork_1"])
    fun sp2spTrafficNetwork1(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        return service.sp2spTransport(projectId)
    } // Function sp2sp_TrafficNetwork_1()

    /**
     * 光照连通
     */
    @Operation(summary = "光照连通", description = "")
    @PostMapping(value = ["/sp2sp_RadiationNetwork_1"])
    fun sp2spRadiationNetwork1(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        logger.debug("calcSy2Sp --------------$projectId")
        return service.sp2spLight(projectId)
    } // Function sp2spRadiationNetwork1()

    /**
    * 空气自然对流
    */
    @Operation(summary = "空气自然对流", description = "")
    @PostMapping(value = ["/sp2sp_ConvectionNetwork_1"])
    fun sp2spConvectionNetwork1(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        return service.sp2spConvection(projectId)
    } // Fun

    /**
     * 空间连通
     */
    @Operation(summary = "空间连通", description = "")
    @PostMapping(value = ["/sp2sp_SpaceNeighborhood_5"])
    fun sp2spV2(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        return service.sp2spV2(projectId)
    } // Fun


    /**
     * 关系变化时标记需要处理的计算
     */
    @Operation(summary = "标记需要计算关系", description = "")
    @PostMapping(value = ["/sign"])
    fun setMark(): SBaseResponse {
        val projectId = SPageContext.getHeader("projectId").toString()
        logger.debug("calcSy2Sp --------------$projectId")
        return service.setMarks(projectId)
    } // Function calcSy2Sp()

} // Class RelationCalcController