<?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.AdmEmsElecLoadIndexMapper">

    <resultMap type="com.ruoyi.ems.domain.AdmEmsElecLoadIndex" id="AdmEmsElecLoadIndexResult">
        <result property="id"    column="id"    />
        <result property="areaCode"    column="area_code"    />
        <result property="facsCode"    column="facs_code"    />
        <result property="date"    column="date"    />
        <result property="time"    column="time"    />
        <result property="voltage"    column="voltage"    />
        <result property="amperage"    column="amperage"    />
        <result property="power"    column="power"    />
    </resultMap>

    <sql id="selectAdmEmsElecLoadIndexVo">
        SELECT
            loadIndex.id,
            loadIndex.area_code,
            loadIndex.facs_code,
            area.area_name,
            facs.facs_name,
            DATE,
            TIME,
            voltage,
            amperage,
            power
        FROM
            adm_ems_elec_load_index loadIndex
            INNER JOIN adm_ems_facs facs ON loadIndex.facs_code = facs.facs_code
            INNER JOIN adm_service_area area ON loadIndex.area_code = area.area_code
    </sql>

    <select id="selectAdmEmsElecLoadIndexList" parameterType="com.ruoyi.ems.domain.AdmEmsElecLoadIndex" resultType="com.ruoyi.ems.domain.AdmEmsElecLoadIndex">
        <include refid="selectAdmEmsElecLoadIndexVo"/>
        <where>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
            <if test="facsCode != null  and facsCode != ''"> and facs_code = #{facsCode}</if>
            <if test="date != null "> and date = #{date}</if>
            <if test="voltage != null "> and voltage = #{voltage}</if>
            <if test="amperage != null "> and amperage = #{amperage}</if>
            <if test="power != null "> and power = #{power}</if>
        </where>
    </select>

    <select id="selectAdmEmsElecLoadIndexById" parameterType="Long" resultMap="AdmEmsElecLoadIndexResult">
        <include refid="selectAdmEmsElecLoadIndexVo"/>
        where id = #{id}
    </select>

    <insert id="insertAdmEmsElecLoadIndex" parameterType="com.ruoyi.ems.domain.AdmEmsElecLoadIndex" useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_elec_load_index
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">area_code,</if>
            <if test="facsCode != null and facsCode != ''">facs_code,</if>
            <if test="date != null">date,</if>
            <if test="time != null">time,</if>
            <if test="voltage != null">voltage,</if>
            <if test="amperage != null">amperage,</if>
            <if test="power != null">power,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">#{areaCode},</if>
            <if test="facsCode != null and facsCode != ''">#{facsCode},</if>
            <if test="date != null">#{date},</if>
            <if test="time != null">#{time},</if>
            <if test="voltage != null">#{voltage},</if>
            <if test="amperage != null">#{amperage},</if>
            <if test="power != null">#{power},</if>
         </trim>
    </insert>

    <update id="updateAdmEmsElecLoadIndex" parameterType="com.ruoyi.ems.domain.AdmEmsElecLoadIndex">
        update adm_ems_elec_load_index
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">area_code = #{areaCode},</if>
            <if test="facsCode != null and facsCode != ''">facs_code = #{facsCode},</if>
            <if test="date != null">date = #{date},</if>
            <if test="time != null">time = #{time},</if>
            <if test="voltage != null">voltage = #{voltage},</if>
            <if test="amperage != null">amperage = #{amperage},</if>
            <if test="power != null">power = #{power},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAdmEmsElecLoadIndexById" parameterType="Long">
        delete from adm_ems_elec_load_index where id = #{id}
    </delete>

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