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