/*
 * *********************************************************************************************************************
 *
 *          !!
 *        .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.Insert
import org.apache.ibatis.annotations.Mapper
import org.apache.ibatis.annotations.SelectProvider
import org.apache.ibatis.annotations.Update
import org.springframework.stereotype.Repository

/**
 * 导入关系excel
 *
 * @author  庞利祥 <sybotan@126.com>
 */
@Mapper
@Repository
interface IRelationExcelImportMapper {
    @SelectProvider(type = RelationProvider::class, method = "findObjectId")
    fun findObjectId(projectId: String, table: String, code: String, codeValue: String): ArrayList<String>

    /**
     * 建筑与设备关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             建筑ID
     * @param   id2             设备ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO relationship.r_eq2bd(project_id, eq_id, bd_id, type, sign) VALUES(#{projectId}, #{id2}, #{id1}, #{type}, 1)")
    fun eq2bd(projectId: String, type: String, id1: String, id2: String)

    /**
     * 建筑下的设备
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             建筑ID
     * @param   id2             设备ID
     * @return  excel需要的记录
     */
    @Update("UPDATE public.equipment SET building_id = #{id1} WHERE project_id = #{projectId} AND id = #{id2}")
    fun Eq2BdIn(projectId: String, type: String, id1: String, id2: String,graphCode: String)

    /**
     * 设备与设备关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             设备1
     * @param   id2             设备2
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO relationship.r_eq2eq(project_id, id1, id2, type, sign) VALUES(#{projectId}, #{id1}, #{id2}, #{type}, 1)")
    fun eq2eq(projectId: String, type: String, id1: String, id2: String)

    /**
     * 楼层下的设备
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             楼层ID
     * @param   id2             设备ID
     * @return  excel需要的记录
     */
    @Update("UPDATE public.equipment SET floor_id = #{id1} WHERE project_id = #{projectId} AND id = #{id2}")
    fun Eq2FlIn(projectId: String, type: String, id1: String, id2: String,graphCode: String)

    /**
     * 建筑下空间
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             建筑ID
     * @param   id2             空间ID
     * @return  excel需要的记录
     */
    @Update("UPDATE public.zone_space_base SET building_id = #{id1} WHERE project_id = #{projectId} AND id = #{id2}")
    fun Bd2Sp(projectId: String, type: String, id1: String, id2: String,graphCode: String)

    /**
     * 楼层下空间
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             楼层ID
     * @param   id2             空间ID
     * @return  excel需要的记录
     */
    @Update("UPDATE public.equipment SET floor_id = #{id1} WHERE project_id = #{projectId} AND id = #{id2}")
    fun Fl2Sp(projectId: String, type: String, id1: String, id2: String,graphCode: String)

    /**
     * 楼层与设备关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             楼层ID
     * @param   id2             设备ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO public.r_eq_for_fl(equip_id,floor_id,project_id, sign) VALUES(#{id2}, #{id1},#{projectId}, 1)")
    fun eq2fl(projectId: String, type: String, id1: String, id2: String)

    /**
     * 设备与空间关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             设备ID
     * @param   id2             竖井ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO relationship.r_eq2sh(project_id, eq_id, sh_id, type, sign) VALUES(#{projectId}, #{id1}, #{id2}, #{type}, 1)")
    fun eq2sh(projectId: String, type: String, id1: String, id2: String)

    /**
     * 设备与空间关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             设备ID
     * @param   id2             空间ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO relationship.r_eq2sp(project_id, eq_id, sp_id, type, sign, graph_code,zone_type) VALUES(#{projectId}, #{id1}, #{id2}, #{type}, 1, #{graphCode},#{zoneType})")
    fun Eq2Sp(projectId: String, type: String, id1: String, id2: String,zoneType: String, graphCode: String)

    /**
     * 系统与设备关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             设备ID
     * @param   id2             系统ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO relationship.r_sy2eq(project_id, sy_id, eq_id, type, sign, graph_code) VALUES(#{projectId}, #{id1}, #{id2}, #{type}, 1, #{graphCode})")
    fun Sy2Eq(projectId: String, type: String, id1: String, id2: String, graphCode: String)

    /**
     * 楼层与楼层关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             楼层1
     * @param   id2             楼层2
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO relationship.r_fl2fl(project_id, id1, id2, type, sign) VALUES(#{projectId}, #{id1}, #{id2}, #{type}, 1)")
    fun fl2fl(projectId: String, type: String, id1: String, id2: String)

    /**
     * 建筑下的资产
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             建筑ID
     * @param   id2             资产ID
     * @return  excel需要的记录
     */
    @Update("UPDATE public.property SET building_id = #{id1} WHERE project_id = #{projectId} AND id = #{id2}")
    fun pe2bdIn(projectId: String, type: String, id1: String, id2: String)

//    /**
//     * 建筑与资产关系
//     *
//     * @param   projectId       项目ID
//     * @param   type            关系类型
//     * @param   id1             楼层ID
//     * @param   id2             设备ID
//     * @return  excel需要的记录
//     */
//    @Insert("INSERT INTO relationship.r_pe2bd(project_id, pe_id, bd_id, type, sign) VALUES(#{projectId}, #{id2}, #{id1}, #{type}, 1)")
//    fun pe2bd(projectId: String, type: String, id1: String, id2: String)

    /**
     * 楼层下的资产
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             楼层ID
     * @param   id2             资产ID
     * @return  excel需要的记录
     */
    @Update("UPDATE public.property SET floor_id = #{id1} WHERE project_id = #{projectId} AND id = #{id2}")
    fun pe2flIn(projectId: String, type: String, id1: String, id2: String)

//    /**
//     * 楼层与设备关系
//     *
//     * @param   projectId       项目ID
//     * @param   type            关系类型
//     * @param   id1             楼层ID
//     * @param   id2             设备ID
//     * @return  excel需要的记录
//     */
//    @Insert("INSERT INTO relationship.r_pe2fl(project_id, pe_id, fl_id, type, sign) VALUES(#{projectId}, #{id2}, #{id1}, #{type}, 1)")
//    fun pe2fl(projectId: String, type: String, id1: String, id2: String)

    /**
     * 资产与竖井关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             资产ID
     * @param   id2             竖井ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO public.r_pe_in_sh(project_id, equip_id, shaft_id, sign) VALUES(#{projectId}, #{id1}, #{id2}, 1)")
    fun pe2sh(projectId: String, type: String, id1: String, id2: String)

    /**
     * 资产与空间关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             资产ID
     * @param   id2             空间ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO relationship.r_pe2sp(project_id, pe_id, sp_id, type, sign) VALUES(#{projectId}, #{id1}, #{id2}, #{type}, 1)")
    fun pe2sp(projectId: String, type: String, id1: String, id2: String)

    /**
     * 建筑与竖井关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             竖井ID
     * @param   id2             建筑ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO public.r_sh_in_bd(project_id, shaft_id, building_id,  sign) VALUES(#{projectId}, #{id1}, #{id2},  1)")
    fun sh2bd(projectId: String, type: String, id1: String, id2: String)

    /**
     * 楼层与竖井关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             竖井ID
     * @param   id2             楼层ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO public.r_sh_in_fl(project_id, shaft_id, floor_id, sign) VALUES(#{projectId}, #{id1}, #{id2},  1)")
    fun sh2fl(projectId: String, type: String, id1: String, id2: String)

    /**
     * 竖井与竖井关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             竖井ID
     * @param   id2             竖井ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO public.r_sh_through_sh(project_id, shaft_id, shaft_other_id,  sign) VALUES(#{projectId}, #{id1}, #{id2}, 1)")
    fun sh2sh(projectId: String, type: String, id1: String, id2: String)

    /**
     * 竖井与空间关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             竖井ID
     * @param   id2             空间ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO relationship.r_sh2sp(project_id, sh_id, sp_id, type, sign) VALUES(#{projectId}, #{id1}, #{id2}, #{type}, 1)")
    fun sh2sp(projectId: String, type: String, id1: String, id2: String)

    /**
     * 建筑与空间关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             建筑ID
     * @param   id2             空间ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO relationship.r_sp2bd(project_id, sp_id, bd_id, type, sign) VALUES(#{projectId}, #{id2}, #{id1}, #{type}, 1)")
    fun sp2bd(projectId: String, type: String, id1: String, id2: String)

    /**
     * 楼层与空间关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             楼层ID
     * @param   id2             空间ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO relationship.r_sp2fl(project_id, sp_id, fl_id, type, sign) VALUES(#{projectId}, #{id2}, #{id1}, #{type}, 1)")
    fun sp2fl(projectId: String, type: String, id1: String, id2: String)

    /**
     * 空间与空间关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             空间ID
     * @param   id2             空间ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO relationship.r_sp2sp(project_id, id1, id2, type, sign, graph_code,zone_type) VALUES(#{projectId}, #{id1}, #{id2}, #{type}, 1, #{graphCode}, #{zoneType})")
    fun Sp2Sp(projectId: String, type: String, id1: String, id2: String,graphCode: String,zoneType: String)

    /**
     * 建筑与竖井关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             系统ID
     * @param   id2             建筑ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO public.r_sy_in_bd(project_id, sys_id, building_id,  sign) VALUES(#{projectId}, #{id1}, #{id2},  1)")
    fun sy2bd(projectId: String, type: String, id1: String, id2: String)

    /**
     * 建筑与竖井关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             系统ID
     * @param   id2             楼层ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO public.r_sy_in_fl(project_id, sys_id, floor_id,  sign) VALUES(#{projectId}, #{id1}, #{id2},  1)")
    fun sy2fl(projectId: String, type: String, id1: String, id2: String)

    /**
     * 系统与竖井关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             系统ID
     * @param   id2             竖井ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO public.r_sy_in_sh(project_id, sys_id, shaft_id,  sign) VALUES(#{projectId}, #{id1}, #{id2},  1)")
    fun sy2sh(projectId: String, type: String, id1: String, id2: String)

    /**
     * 系统与空间关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             系统ID
     * @param   id2             空间ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO relationship.r_sy2sp(project_id, sy_id, sp_id, type, sign) VALUES(#{projectId}, #{id1}, #{id2}, #{type}, 1)")
    fun sy2sp(projectId: String, type: String, id1: String, id2: String)

    /**
     * 租户与空间关系
     *
     * @param   projectId       项目ID
     * @param   type            关系类型
     * @param   id1             租户ID
     * @param   id2             空间ID
     * @return  excel需要的记录
     */
    @Insert("INSERT INTO relationship.r_tn2sp(project_id, tn_id, sp_id, type, sign) VALUES(#{projectId}, #{id1}, #{id2}, #{type}, 1)")
    fun tn2sp(projectId: String, type: String, id1: String, id2: String)
} // Interface IRelationExcelImportMapper