<?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.OpEnergyStrategyStepMapper">
    
    <resultMap type="com.ruoyi.ems.domain.OpEnergyStrategyStep" id="opEnergyStrategyStepResult">
        <result property="id"    column="id"    />
        <result property="strategyCode"    column="strategy_code"    />
        <result property="stepCode"    column="step_code"    />
        <result property="stepName"    column="step_name"    />
        <result property="stepIndex"    column="step_index"    />
        <result property="stepHandler"    column="step_handler"    />
        <result property="stepParam"    column="step_param"    />
        <result property="targetFacs"    column="target_facs"    />
        <result property="targetDevice"    column="target_device"    />
    </resultMap>

    <sql id="selectStepVo">
        select id, strategy_code, step_code, step_name, step_index, step_handler, step_param, target_facs, target_device from adm_op_energy_strategy_step
    </sql>

    <select id="selectStepByStrategyCode" parameterType="java.lang.String" resultMap="opEnergyStrategyStepResult">
        <include refid="selectStepVo"/>
        where strategy_code = #{strategyCode}
    </select>
        
    <insert id="insertStep" parameterType="com.ruoyi.ems.domain.OpEnergyStrategyStep" useGeneratedKeys="true" keyProperty="id">
        insert into adm_op_energy_strategy_step
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="strategyCode != null and strategyCode != ''">strategy_code,</if>
            <if test="stepCode != null and stepCode != ''">step_code,</if>
            <if test="stepName != null and stepName != ''">step_name,</if>
            <if test="stepIndex != null">step_index,</if>
            <if test="stepHandler != null and stepHandler != ''">step_handler,</if>
            <if test="stepParam != null">step_param,</if>
            <if test="targetFacs != null">target_facs,</if>
            <if test="targetDevice != null">target_device,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="strategyCode != null and strategyCode != ''">#{strategyCode},</if>
            <if test="stepCode != null and stepCode != ''">#{stepCode},</if>
            <if test="stepName != null and stepName != ''">#{stepName},</if>
            <if test="stepIndex != null">#{stepIndex},</if>
            <if test="stepHandler != null and stepHandler != ''">#{stepHandler},</if>
            <if test="stepParam != null">#{stepParam},</if>
            <if test="targetFacs != null">#{targetFacs},</if>
            <if test="targetDevice != null">#{targetDevice},</if>
         </trim>
    </insert>

    <insert id="insertStepBatch" parameterType="java.util.List">
        insert into adm_op_energy_strategy_step (strategy_code, step_code, step_name, step_index, step_handler, step_param, target_facs, target_device)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.strategyCode}, #{item.stepCode}, #{item.stepName}, #{item.stepIndex}, #{item.stepHandler}, #{item.stepParam}, #{item.targetFacs}, #{item.targetDevice})
        </foreach>
    </insert>


    <update id="updateStep" parameterType="com.ruoyi.ems.domain.OpEnergyStrategyStep">
        update adm_op_energy_strategy_step
        <trim prefix="SET" suffixOverrides=",">
            <if test="strategyCode != null and strategyCode != ''">strategy_code = #{strategyCode},</if>
            <if test="stepCode != null and stepCode != ''">step_code = #{stepCode},</if>
            <if test="stepName != null and stepName != ''">step_name = #{stepName},</if>
            <if test="stepIndex != null">step_index = #{stepIndex},</if>
            <if test="stepHandler != null and stepHandler != ''">step_handler = #{stepHandler},</if>
            <if test="stepParam != null">step_param = #{stepParam},</if>
            <if test="targetFacs != null">target_facs = #{targetFacs},</if>
            <if test="targetDevice != null">target_device = #{targetDevice},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteStepByStrategyCode" parameterType="java.lang.String">
        delete from adm_op_energy_strategy_step where strategy_code = #{strategyCode}
    </delete>
</mapper>