<?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.ElecPriceStrategyHourMapper">
    
    <resultMap type="com.ruoyi.ems.domain.ElecPriceStrategyHour" id="ElecPriceStrategyHourResult">
        <result property="id"    column="id"    />
        <result property="strategyCode"    column="strategy_code"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="type"    column="type"    />
    </resultMap>

    <sql id="selectElecPriceStrategyHourVo">
        select `id`, `strategy_code`, `start_time`, `end_time`, `type` from adm_elecprice_strategy_hour
    </sql>

    <select id="selectList" parameterType="com.ruoyi.ems.domain.ElecPriceStrategyHour" resultMap="ElecPriceStrategyHourResult">
        <include refid="selectElecPriceStrategyHourVo"/>
        <where>  
            <if test="strategyCode != null  and strategyCode != ''"> and `strategy_code` = #{strategyCode}</if>
            <if test="startTime != null "> and `start_time` = #{startTime}</if>
            <if test="endTime != null "> and `end_time` = #{endTime}</if>
            <if test="type != null "> and `type` = #{type}</if>
        </where>
    </select>

    <select id="selectByStrategyCode" parameterType="String" resultMap="ElecPriceStrategyHourResult">
        <include refid="selectElecPriceStrategyHourVo"/>
        where `strategy_code` = #{strategyCode}
    </select>
    
    <select id="selectById" parameterType="Long" resultMap="ElecPriceStrategyHourResult">
        <include refid="selectElecPriceStrategyHourVo"/>
        where id = #{id}
    </select>
        
    <insert id="insert" parameterType="com.ruoyi.ems.domain.ElecPriceStrategyHour" useGeneratedKeys="true" keyProperty="id">
        insert into adm_elecprice_strategy_hour
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="strategyCode != null and strategyCode != ''">strategy_code,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="type != null">type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="strategyCode != null and strategyCode != ''">#{strategyCode},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="type != null">#{type},</if>
         </trim>
    </insert>

    <insert id="insertBatch" parameterType="java.util.List">
        insert into adm_elecprice_strategy_hour (strategy_code, start_time, end_time, type)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.strategyCode}, #{item.startTime}, #{item.endTime}, #{item.type})
        </foreach>
    </insert>

    <update id="update" parameterType="com.ruoyi.ems.domain.ElecPriceStrategyHour">
        update adm_elecprice_strategy_hour
        <trim prefix="SET" suffixOverrides=",">
            <if test="strategyCode != null and strategyCode != ''">strategy_code = #{strategyCode},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="type != null">type = #{type},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteById" parameterType="Long">
        delete from adm_elecprice_strategy_hour where id = #{id}
    </delete>

    <delete id="deleteByStrategyCode" parameterType="String">
        delete from adm_elecprice_strategy_hour where strategy_code = #{strategyCode}
    </delete>

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