<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.huatek.busi.mapper.BusiEquipmentRelationshipMapper">

    <select id="selectByEquipmentId" resultType="com.huatek.busi.entity.BusiEquipmentRelationship">
        SELECT
        transformer_id as transformerId,
        equipment_id as equipmentId
        FROM busi_equipment_relationship t
        WHERE t.equipment_id = #{equipmentId}
    </select>

    <select id="selectCurrentTransformerInfo" resultType="com.huatek.busi.vo.TransformerTmpVo">
        SELECT
        s.transformer_id AS transformerId,
        b.transformer_name AS transformerName,
        b.equipment_model AS equipmentModel,
        b.manufacturer AS manufacturer
        FROM
        busi_equipment_relationship s
        LEFT JOIN busi_offline_transformer_brand b ON s.transformer_id = b.main_equipment_id
        WHERE
        s.equipment_id = #{equipmentId};
    </select>

    <select id="selectCurrentTransformerInfo2" resultType="com.huatek.busi.vo.TransformerTmpVo">
        SELECT
        s.transformer_id AS transformerId,
        b.transformer_name AS transformerName,
        b.equipment_model AS equipmentModel,
        b.manufacturer AS manufacturer
        FROM
        busi_equipment_relationship s
        LEFT JOIN busi_offline_transformer_brand b ON s.transformer_id = b.main_equipment_id
        WHERE
        s.transformer_id = #{equipmentId};
    </select>

    <insert id="insertRelationship" parameterType="com.huatek.busi.entity.BusiEquipmentRelationship">
        <!-- insert into busi_equipment_relationship
        <trim prefix="(" suffix=")" suffixOverrides=",">
        <if test="transformerId != null">
            transformer_id,
        </if>
        <if test="equipmentId != null">
            equipment_id,
        </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
        <if test="transformerId != null">
            #{transformerId},
        </if>
        <if test="equipmentId != null">
               #{equipmentId},
        </if>
        </trim> -->


        insert into busi_equipment_relationship (transformer_id,equipment_id)
        values (#{transformerId},#{equipmentId})

    </insert>

    <update id="updateRelationship" parameterType="com.huatek.busi.entity.BusiEquipmentRelationship">
        update busi_equipment_relationship set
        transformer_id = #{transformerId}
        where equipment_id = #{equipmentId}
    </update>

    <delete id="cancelRelationship" parameterType="com.huatek.busi.entity.BusiEquipmentRelationship">
        DELETE
        FROM
        busi_equipment_relationship
        WHERE transformer_id = #{transformerId} and equipment_id = #{equipmentId}
    </delete>
</mapper>