<?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.ElecUseHMapper">
    
    <resultMap type="com.ruoyi.ems.domain.ElecUseH" id="elecUseHResult">
        <result property="id"    column="id"    />
        <result property="areaCode"    column="area_code"    />
        <result property="areaName"    column="area_name"    />
        <result property="areaShortName"    column="area_short_name"    />
        <result property="facsCode"    column="facs_code"    />
        <result property="facsName"    column="facs_name"    />
        <result property="date"    column="date"    />
        <result property="time"    column="time"    />
        <result property="timeIndex"    column="time_index"    />
        <result property="elecQuantity"    column="elec_quantity"    />
    </resultMap>

    <sql id="selectElecUseHVo">
        select
            u.id, u.area_code, a.area_name, a.short_name as area_short_name, u.facs_code, f.facs_name, f.facs_type, f.facs_subtype, u.`date`, u.`time`, u.time_index, u.elec_quantity
        from adm_ems_facs_use_h u
            LEFT JOIN adm_service_area a ON u.`area_code` = a.`area_code`
            LEFT JOIN adm_ems_facs f ON u.`facs_code` = f.`facs_code`
    </sql>

    <select id="selectElecUseHList" parameterType="com.ruoyi.ems.domain.ElecUseH" resultMap="elecUseHResult">
        <include refid="selectElecUseHVo"/>
        <where>  
            <if test="areaCode != null  and areaCode != ''"> and u.area_code = #{areaCode}</if>
            <if test="facsCode != null  and facsCode != ''"> and u.facs_code = #{facsCode}</if>
            <if test="facsType != null  and facsType != ''"> and f.facs_type = #{facsType}</if>
            <if test="facsSubtype != null  and facsSubtype != ''"> and f.facs_subtype = #{facsSubtype}</if>
            <if test="date != null "> and u.`date` = #{date}</if>
            <if test="time != null "> and u.`time` = #{time}</if>
            <if test="timeIndex != null "> and u.time_index = #{timeIndex}</if>
            <if test="elecQuantity != null "> and u.elec_quantity = #{elecQuantity}</if>
        </where>
    </select>
    
    <select id="selectElecUseHById" parameterType="Long" resultMap="elecUseHResult">
        <include refid="selectElecUseHVo"/>
        where u.`id` = #{id}
    </select>
        
    <insert id="insertElecUseH" parameterType="com.ruoyi.ems.domain.ElecUseH" useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_facs_use_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="elecQuantity != null">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="elecQuantity != null">#{elecQuantity},</if>
         </trim>
    </insert>

    <update id="updateElecUseH" parameterType="com.ruoyi.ems.domain.ElecUseH">
        update adm_ems_facs_use_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="elecQuantity != null">elec_quantity = #{elecQuantity},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteElecUseHById" parameterType="Long">
        delete from adm_ems_facs_use_h where id = #{id}
    </delete>

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