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

import org.apache.ibatis.annotations.Mapper
import org.apache.ibatis.annotations.Select
import org.springframework.stereotype.Repository

/**
 * 自动关系计算
 *
 * @author  庞利祥 <sybotan@126.com>
 */
@Mapper
@Repository
interface IRelationCalcMapper {
    /**
     * 建筑下的业务空间
     *
     * @param    projectId  项目id
     * @param   tables      参与计算的表的全名称, 带schema名, 以英文逗号隔开
     */
    //@Select(" SELECT * from public.f_rel_bd2sp(#{tables},#{projectId}) ")
    @Select("select public.f_rel_calc('rel_bd2sp', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcBd2Sp(tables: String, projectId: String): Int?

    /**
     * 设备所在建筑
     */
    //@Select(" SELECT * from public.f_rel_eq2bd(#{projectId}) ")
    @Select("select public.f_rel_calc('rel_eq2bd', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcEq2Bd(projectId: String): Int?

    /**
     * 设备所在楼层
     */
    // @Select(" SELECT * from public.f_rel_eq2fl(#{projectId}) ")
    @Select("select public.f_rel_calc('rel_eq2fl', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcEq2Fl(projectId: String): Int?

    /**
     * 设备所在竖井
     */
    // @Select(" SELECT * from public.f_rel_eq2sh(#{projectId}) ")
    @Select("select public.f_rel_calc('rel_eq2sh', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcEq2Sh(projectId: String): Int?

    /**
     * 设备所在业务空间
     *
     *@param projectId 项目id
     */
    // @Select(" SELECT * from public.f_rel_eq2sp(#{tables},#{outTables},#{projectId},#{sign1},#{sign2}) ")
    @Select("select public.f_rel_calc('rel_eq2sp', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcEq2Sp(tables: String, outTables: String, projectId: String, sign1: Int, sign2: Int): Int?

    /**
     * 楼层贯通关系
     *
     * @param   projectId   项目id
     * @param   sign1       表示r_fl_through_fl表中要被删除的sign值
     * @param   sign2       同上 与sign1是逻辑或的关系
     */
    // @Select(" SELECT * from public.f_rel_fl2fl(#{projectId},#{sign1},#{sign2}) ")
    @Select("select public.f_rel_calc('rel_fl2fl', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcFl2Fl(projectId: String, sign1: Int, sign2: Int): Int?

    /**
     * 楼层下的业务空间
     *
     * @param    projectId  项目id
     * @param    tables      参与计算的表的全名称, 带schema名, 以英文逗号隔开
     */
    // @Select(" SELECT * from public.f_rel_bd2sp(#{tables},#{projectId}) ")
    @Select("select public.f_rel_calc('rel_sp2fl', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcFl2Sp(tables: String, projectId: String): Int?

    /**
     * 资产所在建筑
     */
//    @Select(" SELECT * from public.f_rel_pe2bd(#{projectId}) ")
    @Select("select public.f_rel_calc('rel_pe2bd', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcPe2Bd(projectId: String): Int?

    /**
     * 资产所在楼层
     */
//    @Select(" SELECT * from public.f_rel_pe2fl(#{projectId}) ")
    @Select("select public.f_rel_calc('rel_pe2fl', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcPe2Fl(projectId: String): Int?

    /**
     * 资产所在竖井
     */
//    @Select(" SELECT * from public.f_rel_pe2sh(#{projectId}) ")
    @Select("select public.f_rel_calc('rel_pe2sh', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcPe2Sh(projectId: String): Int?

    /**
     * 资产所在业务空间
     */
//    @Select(" SELECT * from public.f_rel_pe2sp(#{projectId}) ")
    @Select("select public.f_rel_calc('rel_pe2sp', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcPe2Sp(projectId: String): Int?

    /**
     * 建筑下的竖井
     */
//    @Select(" SELECT * from public.f_rel_sh2bd(#{projectId}) ")
    @Select("select public.f_rel_calc('rel_sh2bd', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcSh2Bd(projectId: String): Int?

    /**
     * 竖井贯通
     */
//    @Select(" SELECT * from public.f_rel_sh2sh(#{projectId}) ")
    @Select("select public.f_rel_calc('rel_sh2sh', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcSh2Sh(projectId: String): Int?

    /**
     * 建筑下的系统设备部件
     */
//    @Select(" SELECT * from public.f_rel_syeq2bd(#{projectId}) ")
    @Select("select public.f_rel_calc('rel_syeq2bd', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcSyEq2Bd(projectId: String): Int?

    /**
     * 系统所在建筑
     */
//    @Select(" SELECT * from public.f_rel_sy2bd(#{projectId}) ")
    @Select("select public.f_rel_calc('rel_sy2bd', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcSy2Bd(projectId: String): Int?

    /**
     * 系统所在楼层
     */
//    @Select(" SELECT * from public.f_rel_sy2fl(#{projectId}) ")
    @Select("select public.f_rel_calc('rel_sy2fl', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcSy2Fl(projectId: String): Int?

    /**
     * 系统所在竖井
     */
//    @Select(" SELECT * from public.f_rel_sy2sh(#{projectId}) ")
    @Select("select public.f_rel_calc('rel_sy2sh', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcSy2Sh(projectId: String): Int?

    /**
     * 系统所在业务空间
     */
//    @Select(" SELECT * from public.f_rel_sy2sp(#{projectId}) ")
    @Select("select public.f_rel_calc('rel_sy2sp', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcSy2Sp(projectId: String): Int?

    /**
     * 空间普通交通
     */
    @Select("select public.f_rel_calc('rel_sp2sp_transport', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcsp2spTransport(projectId: String): Int?

    /**
     * 光照连通
     */
    @Select("select public.f_rel_calc('rel_sp2sp_light', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcsp2spLight(projectId: String): Int?

    /**
     * 光照连通
     */
    @Select("select public.f_rel_calc('rel_sp2sp_convection', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcsp2spConvection(projectId: String): Int?

    /**
     * 空间连通
     */
    @Select("select public.f_rel_calc('rel_sp2sp_v2', #{projectId}, 'zone_space_base','relationship.r_eq2sp', 2, 2)")
    fun calcsp2spV2(projectId: String): Int?

} // Interface IRelationCalcMapper