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

    <resultMap type="com.ruoyi.ems.domain.AdmEmsElecStoreH" id="AdmEmsElecStoreHResult">
        <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="timeIndex"    column="time_index"    />
        <result property="chargeElecQuantity"    column="charge_elec_quantity"    />
        <result property="dischargeElecQuantity"    column="discharge_elec_quantity"    />
    </resultMap>

    <sql id="selectAdmEmsElecStoreHVo">
        SELECT
            store.id,
            store.area_code,
            area.area_name,
            facs.facs_name,
            store.facs_code,
            DATE,
            TIME,
            time_index,
            charge_elec_quantity,
            discharge_elec_quantity
        FROM
            adm_ems_elec_store_h store
            INNER JOIN adm_ems_facs facs ON store.facs_code = facs.facs_code
            INNER JOIN adm_service_area area ON store.area_code = area.area_code
    </sql>

    <select id="selectAdmEmsElecStoreHList" parameterType="com.ruoyi.ems.domain.AdmEmsElecStoreH" resultType="com.ruoyi.ems.domain.AdmEmsElecStoreH">
        <include refid="selectAdmEmsElecStoreHVo"/>
        <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="chargeElecQuantity != null "> and charge_elec_quantity = #{chargeElecQuantity}</if>
            <if test="dischargeElecQuantity != null "> and discharge_elec_quantity = #{dischargeElecQuantity}</if>
        </where>
    </select>

    <select id="selectAdmEmsElecStoreHById" parameterType="Long" resultType="com.ruoyi.ems.domain.AdmEmsElecStoreH">
        <include refid="selectAdmEmsElecStoreHVo"/>
        where id = #{id}
    </select>

    <insert id="insertAdmEmsElecStoreH" parameterType="com.ruoyi.ems.domain.AdmEmsElecStoreH" useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_elec_store_h
        <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="timeIndex != null">time_index,</if>
            <if test="chargeElecQuantity != null">charge_elec_quantity,</if>
            <if test="dischargeElecQuantity != null">discharge_elec_quantity,</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="timeIndex != null">#{timeIndex},</if>
            <if test="chargeElecQuantity != null">#{chargeElecQuantity},</if>
            <if test="dischargeElecQuantity != null">#{dischargeElecQuantity},</if>
         </trim>
    </insert>

    <update id="updateAdmEmsElecStoreH" parameterType="com.ruoyi.ems.domain.AdmEmsElecStoreH">
        update adm_ems_elec_store_h
        <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="timeIndex != null">time_index = #{timeIndex},</if>
            <if test="chargeElecQuantity != null">charge_elec_quantity = #{chargeElecQuantity},</if>
            <if test="dischargeElecQuantity != null">discharge_elec_quantity = #{dischargeElecQuantity},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAdmEmsElecStoreHById" parameterType="Long">
        delete from adm_ems_elec_store_h where id = #{id}
    </delete>

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