<?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.ElecLoadIndexMapper">
    
    <resultMap type="com.ruoyi.ems.domain.ElecLoadIndex" id="indexResult">
        <result property="id"    column="id"    />
        <result property="areaCode"    column="area_code"    />
        <result property="objType"    column="obj_type"    />
        <result property="objCode"    column="obj_code"    />
        <result property="recordTime"    column="record_time"    />
        <result property="date"    column="date"    />
        <result property="time"    column="time"    />
        <result property="timeIndex"    column="time_index"    />
        <result property="ua"    column="ua"    />
        <result property="ub"    column="ub"    />
        <result property="uc"    column="uc"    />
        <result property="la"    column="la"    />
        <result property="lb"    column="lb"    />
        <result property="lc"    column="lc"    />
        <result property="p"    column="p"    />
        <result property="pa"    column="pa"    />
        <result property="pb"    column="pb"    />
        <result property="pc"    column="pc"    />
        <result property="q"    column="q"    />
        <result property="qa"    column="qa"    />
        <result property="qb"    column="qb"    />
        <result property="qc"    column="qc"    />
        <result property="pf"    column="pf"    />
    </resultMap>

    <sql id="selectIndexVo">
        select id, area_code, obj_type, obj_code, record_time, `date`, `time`, time_index, ua, ub, uc, la, lb, lc, p, pa, pb, pc, q, qa, qb, qc, pf from adm_ems_elec_load_index
    </sql>

    <select id="selectIndexList" parameterType="com.ruoyi.ems.domain.ElecLoadIndex" resultMap="indexResult">
        <include refid="selectIndexVo"/>
        <where>  
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
            <if test="objType != null "> and obj_type = #{objType}</if>
            <if test="objCode != null  and objCode != ''"> and obj_code = #{objCode}</if>
            <if test="recordTime != null "> and record_time = #{recordTime}</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>
        </where>
    </select>

    <select id="selectByTime" parameterType="com.ruoyi.ems.domain.vo.QueryIndex" resultMap="indexResult">
        <include refid="selectIndexVo"/>
        <where>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
            <if test="objType != null "> and obj_type = #{objType}</if>
            <if test="objCode != null  and objCode != ''"> and obj_code = #{objCode}</if>
            <if test="startTime != null  and startTime != ''"> and record_time >= #{startTime}</if>
            <if test="endTime != null  and endTime != ''"> and record_time = #{endTime}</if>
        </where>
    </select>
    
    <select id="selectIndexById" parameterType="Long" resultMap="indexResult">
        <include refid="selectIndexVo"/>
        where id = #{id}
    </select>

    <select id="selectNewIndex" resultMap="indexResult">
        <include refid="selectIndexVo"/>
        where area_code = #{areaCode} and obj_type = #{objType} and obj_code = #{objCode}
        order by record_time
        desc limit 1
    </select>
        
    <insert id="insertIndex" parameterType="com.ruoyi.ems.domain.ElecLoadIndex" 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="objType != null">obj_type,</if>
            <if test="objCode != null and objCode != ''">obj_code,</if>
            <if test="recordTime != null">record_time,</if>
            <if test="date != null">`date`,</if>
            <if test="time != null">`time`,</if>
            <if test="timeIndex != null">time_index,</if>
            <if test="ua != null">ua,</if>
            <if test="ub != null">ub,</if>
            <if test="uc != null">uc,</if>
            <if test="la != null">la,</if>
            <if test="lb != null">lb,</if>
            <if test="lc != null">lc,</if>
            <if test="p != null">p,</if>
            <if test="pa != null">pa,</if>
            <if test="pb != null">pb,</if>
            <if test="pc != null">pc,</if>
            <if test="q != null">q,</if>
            <if test="qa != null">qa,</if>
            <if test="qb != null">qb,</if>
            <if test="qc != null">qc,</if>
            <if test="pf != null">pf,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">#{areaCode},</if>
            <if test="objType != null">#{objType},</if>
            <if test="objCode != null and objCode != ''">#{objCode},</if>
            <if test="recordTime != null">#{recordTime},</if>
            <if test="date != null">#{date},</if>
            <if test="time != null">#{time},</if>
            <if test="timeIndex != null">#{timeIndex},</if>
            <if test="ua != null">#{ua},</if>
            <if test="ub != null">#{ub},</if>
            <if test="uc != null">#{uc},</if>
            <if test="la != null">#{la},</if>
            <if test="lb != null">#{lb},</if>
            <if test="lc != null">#{lc},</if>
            <if test="p != null">#{p},</if>
            <if test="pa != null">#{pa},</if>
            <if test="pb != null">#{pb},</if>
            <if test="pc != null">#{pc},</if>
            <if test="q != null">#{q},</if>
            <if test="qa != null">#{qa},</if>
            <if test="qb != null">#{qb},</if>
            <if test="qc != null">#{qc},</if>
            <if test="pf != null">#{pf},</if>
         </trim>
    </insert>

    <update id="updateIndex" parameterType="com.ruoyi.ems.domain.ElecLoadIndex">
        update adm_ems_elec_load_index
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">area_code = #{areaCode},</if>
            <if test="objType != null">obj_type = #{objType},</if>
            <if test="objCode != null and objCode != ''">obj_code = #{objCode},</if>
            <if test="recordTime != null">record_time = #{recordTime},</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="ua != null">ua = #{ua},</if>
            <if test="ub != null">ub = #{ub},</if>
            <if test="uc != null">uc = #{uc},</if>
            <if test="la != null">la = #{la},</if>
            <if test="lb != null">lb = #{lb},</if>
            <if test="lc != null">lc = #{lc},</if>
            <if test="p != null">p = #{p},</if>
            <if test="pa != null">pa = #{pa},</if>
            <if test="pb != null">pb = #{pb},</if>
            <if test="pc != null">pc = #{pc},</if>
            <if test="q != null">q = #{q},</if>
            <if test="qa != null">qa = #{qa},</if>
            <if test="qb != null">qb = #{qb},</if>
            <if test="qc != null">qc = #{qc},</if>
            <if test="pf != null">pf = #{pf},</if>
        </trim>
        where id = #{id}
    </update>

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

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