<?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.AdmEmsPvSupplyHMapper">
    <resultMap type="com.ruoyi.ems.domain.AdmEmsPvSupplyH" id="AdmEmsPvSupplyHResult">
        <result property="id"    column="id"    />
        <result property="areaCode"    column="area_code"    />
        <result property="facsCode"    column="facs_code"    />
        <result property="date"    column="date"  jdbcType="DATE"  />
        <result property="time"    column="time"    />
        <result property="timeIndex"    column="time_index"    />
        <result property="meterType"    column="meter_type"    />
        <result property="meterUnitPrice"    column="meter_unit_price"    />
        <result property="elecReading"    column="elec_reading"    />
        <result property="elecQuantity"    column="elec_quantity"    />
        <result property="elecEarn"    column="elec_earn"    />
    </resultMap>

    <sql id="selectAdmEmsPvSupplyHVo">
        select id, area_code, facs_code, date, time, time_index, meter_type, meter_unit_price, elec_reading, elec_quantity, elec_earn from adm_ems_pv_supply_h
    </sql>

    <select id="selectAdmEmsPvSupplyHList" parameterType="com.ruoyi.ems.domain.AdmEmsPvSupplyH" resultMap="AdmEmsPvSupplyHResult">
        <include refid="selectAdmEmsPvSupplyHVo"/>
        <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="time != null "> and time = #{time}</if>
            <if test="timeIndex != null "> and time_index = #{timeIndex}</if>
            <if test="meterType != null "> and meter_type = #{meterType}</if>
            <if test="meterUnitPrice != null "> and meter_unit_price = #{meterUnitPrice}</if>
            <if test="elecReading != null "> and elec_reading = #{elecReading}</if>
            <if test="elecQuantity != null "> and elec_quantity = #{elecQuantity}</if>
            <if test="elecEarn != null "> and elec_earn = #{elecEarn}</if>
        </where>
    </select>
    <select id="selectAreaSupplyH" parameterType="com.ruoyi.ems.domain.AdmEmsPvSupplyH" resultMap="AdmEmsPvSupplyHResult">
        SELECT area_code, DATE, time_index, SUM( elec_quantity ) elec_quantity
        FROM
            adm_ems_pv_supply_h
        WHERE
            area_code = #{areaCode}
          AND DATE = #{date,jdbcType=DATE}
        GROUP BY
            area_code,
            time_index
        ORDER BY
            time_index ASC
    </select>

    <select id="selectAdmEmsPvSupplyHById" parameterType="Long" resultMap="AdmEmsPvSupplyHResult">
        <include refid="selectAdmEmsPvSupplyHVo"/>
        where id = #{id}
    </select>

    <insert id="insertAdmEmsPvSupplyH" parameterType="com.ruoyi.ems.domain.AdmEmsPvSupplyH" useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_pv_supply_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="meterType != null">meter_type,</if>
            <if test="meterUnitPrice != null">meter_unit_price,</if>
            <if test="elecReading != null">elec_reading,</if>
            <if test="elecQuantity != null">elec_quantity,</if>
            <if test="elecEarn != null">elec_earn,</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="meterType != null">#{meterType},</if>
            <if test="meterUnitPrice != null">#{meterUnitPrice},</if>
            <if test="elecReading != null">#{elecReading},</if>
            <if test="elecQuantity != null">#{elecQuantity},</if>
            <if test="elecEarn != null">#{elecEarn},</if>
         </trim>
    </insert>

    <update id="updateAdmEmsPvSupplyH" parameterType="com.ruoyi.ems.domain.AdmEmsPvSupplyH">
        update adm_ems_pv_supply_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="meterType != null">meter_type = #{meterType},</if>
            <if test="meterUnitPrice != null">meter_unit_price = #{meterUnitPrice},</if>
            <if test="elecReading != null">elec_reading = #{elecReading},</if>
            <if test="elecQuantity != null">elec_quantity = #{elecQuantity},</if>
            <if test="elecEarn != null">elec_earn = #{elecEarn},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAdmEmsPvSupplyHById" parameterType="Long">
        delete from adm_ems_pv_supply_h where id = #{id}
    </delete>

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