<?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.ruoyi.ems.mapper.PowerBoxElecEqptMapper">
    
    <resultMap type="com.ruoyi.ems.domain.PowerBoxElecEqpt" id="boxElecEqptResult">
        <result property="id"           column="id"    />
        <result property="boxCode"      column="box_code"    />
        <result property="eqptCode"     column="eqpt_code"    />
        <result property="eqptName"     column="eqpt_name"    />
        <result property="extEqptCode"  column="ext_eqpt_code"    />
        <result property="eqptType"     column="eqpt_type"    />
        <result property="eqptName"     column="eqpt_name"    />
        <result property="eqptSpec"     column="eqpt_spec"    />
        <result property="ratedVoltage" column="rated_voltage"    />
        <result property="ratedCurrent" column="rated_current"    />
        <result property="parentEqpt"   column="parent_eqpt"    />
        <result property="meterDevice"  column="meter_device"    />
    </resultMap>

    <sql id="selectBoxElecEqptVo">
        select
            bee.id, bee.box_code, bee.eqpt_code, bee.ext_eqpt_code, bee.eqpt_type, bet.type_name as eqpt_name, bee.eqpt_spec, bee.rated_voltage, bee.rated_current, bee.parent_eqpt, bee.meter_device
        from adm_box_elec_eqpt bee
            LEFT JOIN dim_box_eleceqpt_type bet ON bee.eqpt_type = bet.type_code
    </sql>

    <select id="selectBoxElecEqptList" parameterType="com.ruoyi.ems.domain.PowerBoxElecEqpt" resultMap="boxElecEqptResult">
        <include refid="selectBoxElecEqptVo"/>
        <where>  
            <if test="boxCode != null  and boxCode != ''"> and bee.box_code = #{boxCode}</if>
            <if test="eqptCode != null  and eqptCode != ''"> and bee.eqpt_code = #{eqptCode}</if>
            <if test="extEqptCode != null  and extEqptCode != ''"> and bee.ext_eqpt_code = #{extEqptCode}</if>
            <if test="eqptType != null  and eqptType != ''"> and bee.eqpt_type = #{eqptType}</if>
            <if test="eqptSpec != null  and eqptSpec != ''"> and bee.eqpt_spec = #{eqptSpec}</if>
            <if test="ratedVoltage != null "> and bee.rated_voltage = #{ratedVoltage}</if>
            <if test="ratedCurrent != null "> and bee.rated_current = #{ratedCurrent}</if>
            <if test="parentEqpt != null  and parentEqpt != ''"> and bee.parent_eqpt = #{parentEqpt}</if>
            <if test="meterDevice != null  and meterDevice != ''"> and bee.meter_device = #{meterDevice}</if>
        </where>
    </select>

    <select id="selectByBoxCode" parameterType="java.lang.String" resultMap="boxElecEqptResult">
        <include refid="selectBoxElecEqptVo"/>
        where bee.box_code = #{code}
    </select>
    
    <select id="selectBoxElecEqptById" parameterType="Long" resultMap="boxElecEqptResult">
        <include refid="selectBoxElecEqptVo"/>
        where bee.id = #{id}
    </select>
        
    <insert id="insertBoxElecEqpt" parameterType="com.ruoyi.ems.domain.PowerBoxElecEqpt" useGeneratedKeys="true" keyProperty="id">
        insert into adm_box_elec_eqpt
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="boxCode != null and boxCode != ''">box_code,</if>
            <if test="eqptCode != null and eqptCode != ''">eqpt_code,</if>
            <if test="extEqptCode != null">ext_eqpt_code,</if>
            <if test="eqptType != null and eqptType != ''">eqpt_type,</if>
            <if test="eqptSpec != null">eqpt_spec,</if>
            <if test="ratedVoltage != null">rated_voltage,</if>
            <if test="ratedCurrent != null">rated_current,</if>
            <if test="parentEqpt != null">parent_eqpt,</if>
            <if test="meterDevice != null">meter_device,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="boxCode != null and boxCode != ''">#{boxCode},</if>
            <if test="eqptCode != null and eqptCode != ''">#{eqptCode},</if>
            <if test="extEqptCode != null">#{extEqptCode},</if>
            <if test="eqptType != null and eqptType != ''">#{eqptType},</if>
            <if test="eqptSpec != null">#{eqptSpec},</if>
            <if test="ratedVoltage != null">#{ratedVoltage},</if>
            <if test="ratedCurrent != null">#{ratedCurrent},</if>
            <if test="parentEqpt != null">#{parentEqpt},</if>
            <if test="meterDevice != null">#{meterDevice},</if>
         </trim>
    </insert>

    <insert id="insertBatch" parameterType="java.util.List" >
        insert into adm_box_elec_eqpt (box_code, eqpt_code, ext_eqpt_code, eqpt_type, eqpt_spec, rated_voltage, rated_current, parent_eqpt, meter_device)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.boxCode}, #{item.eqptCode}, #{item.extEqptCode}, #{item.eqptType}, #{item.eqptSpec}, #{item.ratedVoltage}, #{item.ratedCurrent}, #{item.parentEqpt}, #{item.meterDevice})
        </foreach>
    </insert>

    <update id="updateBoxElecEqpt" parameterType="com.ruoyi.ems.domain.PowerBoxElecEqpt">
        update adm_box_elec_eqpt
        <trim prefix="SET" suffixOverrides=",">
            <if test="boxCode != null and boxCode != ''">box_code = #{boxCode},</if>
            <if test="eqptCode != null and eqptCode != ''">eqpt_code = #{eqptCode},</if>
            <if test="extEqptCode != null">ext_eqpt_code = #{extEqptCode},</if>
            <if test="eqptType != null and eqptType != ''">eqpt_type = #{eqptType},</if>
            <if test="eqptSpec != null">eqpt_spec = #{eqptSpec},</if>
            <if test="ratedVoltage != null">rated_voltage = #{ratedVoltage},</if>
            <if test="ratedCurrent != null">rated_current = #{ratedCurrent},</if>
            <if test="parentEqpt != null">parent_eqpt = #{parentEqpt},</if>
            <if test="meterDevice != null">meter_device = #{meterDevice},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBoxElecEqptById" parameterType="Long">
        delete from adm_box_elec_eqpt where id = #{id}
    </delete>

    <delete id="deleteByBoxCode" parameterType="String">
        delete from adm_box_elec_eqpt where box_code = #{code}
    </delete>

    <delete id="deleteBoxElecEqptByIds" parameterType="String">
        delete from adm_box_elec_eqpt where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>