<?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.ElecPriceStrategyMapper">
    
    <resultMap type="com.ruoyi.ems.domain.ElecPriceStrategy" id="ElecpriceStrategyResult">
        <result property="id"    column="id"    />
        <result property="strategyCode"    column="strategy_code"    />
        <result property="strategyName"    column="strategy_name"    />
        <result property="repeatType"    column="repeat_type"    />
        <result property="repeatParam"    column="repeat_param"    />
        <result property="priority"    column="priority"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectElecPriceStrategyVo">
        select id, strategy_code, strategy_name, repeat_type, repeat_param, priority, create_time, update_time from adm_elecprice_strategy
    </sql>

    <select id="selectList" parameterType="com.ruoyi.ems.domain.ElecPriceStrategy" resultMap="ElecpriceStrategyResult">
        <include refid="selectElecPriceStrategyVo"/>
        <where>  
            <if test="strategyCode != null  and strategyCode != ''"> and strategy_code = #{strategyCode}</if>
            <if test="strategyName != null  and strategyName != ''"> and strategy_name like concat('%', #{strategyName}, '%')</if>
            <if test="repeatType != null  and repeatType != ''"> and repeat_type = #{repeatType}</if>
            <if test="priority != null "> and priority = #{priority}</if>
        </where>
    </select>
    
    <select id="selectById" parameterType="Long" resultMap="ElecpriceStrategyResult">
        <include refid="selectElecPriceStrategyVo"/>
        where id = #{id}
    </select>
        
    <insert id="insert" parameterType="com.ruoyi.ems.domain.ElecPriceStrategy" useGeneratedKeys="true" keyProperty="id">
        insert into adm_elecprice_strategy
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="strategyCode != null and strategyCode != ''">strategy_code,</if>
            <if test="strategyName != null and strategyName != ''">strategy_name,</if>
            <if test="repeatType != null">repeat_type,</if>
            <if test="repeatParam != null">repeat_param,</if>
            <if test="priority != null">priority,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="strategyCode != null and strategyCode != ''">#{strategyCode},</if>
            <if test="strategyName != null and strategyName != ''">#{strategyName},</if>
            <if test="repeatType != null">#{repeatType},</if>
            <if test="repeatParam != null">#{repeatParam},</if>
            <if test="priority != null">#{priority},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="update" parameterType="com.ruoyi.ems.domain.ElecPriceStrategy">
        update adm_elecprice_strategy
        <trim prefix="SET" suffixOverrides=",">
            <if test="strategyCode != null and strategyCode != ''">strategy_code = #{strategyCode},</if>
            <if test="strategyName != null and strategyName != ''">strategy_name = #{strategyName},</if>
            <if test="repeatType != null">repeat_type = #{repeatType},</if>
            <if test="repeatParam != null">repeat_param = #{repeatParam},</if>
            <if test="priority != null">priority = #{priority},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

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

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