<?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.xzzn.ems.mapper.EmsStrategyRuntimeConfigMapper">

    <resultMap type="EmsStrategyRuntimeConfig" id="EmsStrategyRuntimeConfigResult">
        <result property="id" column="id"/>
        <result property="siteId" column="site_id"/>
        <result property="socDown" column="soc_down"/>
        <result property="socUp" column="soc_up"/>
        <result property="antiReverseThreshold" column="anti_reverse_threshold"/>
        <result property="antiReverseRangePercent" column="anti_reverse_range_percent"/>
        <result property="antiReverseUp" column="anti_reverse_up"/>
        <result property="antiReversePowerDownPercent" column="anti_reverse_power_down_percent"/>
        <result property="antiReverseHardStopThreshold" column="anti_reverse_hard_stop_threshold"/>
        <result property="powerSetMultiplier" column="power_set_multiplier"/>
        <result property="protectInterveneEnable" column="protect_intervene_enable"/>
        <result property="protectL1DeratePercent" column="protect_l1_derate_percent"/>
        <result property="protectRecoveryStableSeconds" column="protect_recovery_stable_seconds"/>
        <result property="protectL3LatchEnable" column="protect_l3_latch_enable"/>
        <result property="protectConflictPolicy" column="protect_conflict_policy"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectVo">
        select id,
               site_id,
               soc_down,
               soc_up,
               anti_reverse_threshold,
               anti_reverse_range_percent,
               anti_reverse_up,
               anti_reverse_power_down_percent,
               anti_reverse_hard_stop_threshold,
               power_set_multiplier,
               protect_intervene_enable,
               protect_l1_derate_percent,
               protect_recovery_stable_seconds,
               protect_l3_latch_enable,
               protect_conflict_policy,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from ems_strategy_runtime_config
    </sql>

    <select id="selectBySiteId" parameterType="String" resultMap="EmsStrategyRuntimeConfigResult">
        <include refid="selectVo"/>
        where site_id = #{siteId}
        limit 1
    </select>

    <insert id="insert" parameterType="EmsStrategyRuntimeConfig" useGeneratedKeys="true" keyProperty="id">
        insert into ems_strategy_runtime_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="siteId != null and siteId != ''">site_id,</if>
            <if test="socDown != null">soc_down,</if>
            <if test="socUp != null">soc_up,</if>
            <if test="antiReverseThreshold != null">anti_reverse_threshold,</if>
            <if test="antiReverseRangePercent != null">anti_reverse_range_percent,</if>
            <if test="antiReverseUp != null">anti_reverse_up,</if>
            <if test="antiReversePowerDownPercent != null">anti_reverse_power_down_percent,</if>
            <if test="antiReverseHardStopThreshold != null">anti_reverse_hard_stop_threshold,</if>
            <if test="powerSetMultiplier != null">power_set_multiplier,</if>
            <if test="protectInterveneEnable != null">protect_intervene_enable,</if>
            <if test="protectL1DeratePercent != null">protect_l1_derate_percent,</if>
            <if test="protectRecoveryStableSeconds != null">protect_recovery_stable_seconds,</if>
            <if test="protectL3LatchEnable != null">protect_l3_latch_enable,</if>
            <if test="protectConflictPolicy != null and protectConflictPolicy != ''">protect_conflict_policy,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="siteId != null and siteId != ''">#{siteId},</if>
            <if test="socDown != null">#{socDown},</if>
            <if test="socUp != null">#{socUp},</if>
            <if test="antiReverseThreshold != null">#{antiReverseThreshold},</if>
            <if test="antiReverseRangePercent != null">#{antiReverseRangePercent},</if>
            <if test="antiReverseUp != null">#{antiReverseUp},</if>
            <if test="antiReversePowerDownPercent != null">#{antiReversePowerDownPercent},</if>
            <if test="antiReverseHardStopThreshold != null">#{antiReverseHardStopThreshold},</if>
            <if test="powerSetMultiplier != null">#{powerSetMultiplier},</if>
            <if test="protectInterveneEnable != null">#{protectInterveneEnable},</if>
            <if test="protectL1DeratePercent != null">#{protectL1DeratePercent},</if>
            <if test="protectRecoveryStableSeconds != null">#{protectRecoveryStableSeconds},</if>
            <if test="protectL3LatchEnable != null">#{protectL3LatchEnable},</if>
            <if test="protectConflictPolicy != null and protectConflictPolicy != ''">#{protectConflictPolicy},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateBySiteId" parameterType="EmsStrategyRuntimeConfig">
        update ems_strategy_runtime_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="socDown != null">soc_down = #{socDown},</if>
            <if test="socUp != null">soc_up = #{socUp},</if>
            <if test="antiReverseThreshold != null">anti_reverse_threshold = #{antiReverseThreshold},</if>
            <if test="antiReverseRangePercent != null">anti_reverse_range_percent = #{antiReverseRangePercent},</if>
            <if test="antiReverseUp != null">anti_reverse_up = #{antiReverseUp},</if>
            <if test="antiReversePowerDownPercent != null">anti_reverse_power_down_percent = #{antiReversePowerDownPercent},</if>
            <if test="antiReverseHardStopThreshold != null">anti_reverse_hard_stop_threshold = #{antiReverseHardStopThreshold},</if>
            <if test="powerSetMultiplier != null">power_set_multiplier = #{powerSetMultiplier},</if>
            <if test="protectInterveneEnable != null">protect_intervene_enable = #{protectInterveneEnable},</if>
            <if test="protectL1DeratePercent != null">protect_l1_derate_percent = #{protectL1DeratePercent},</if>
            <if test="protectRecoveryStableSeconds != null">protect_recovery_stable_seconds = #{protectRecoveryStableSeconds},</if>
            <if test="protectL3LatchEnable != null">protect_l3_latch_enable = #{protectL3LatchEnable},</if>
            <if test="protectConflictPolicy != null and protectConflictPolicy != ''">protect_conflict_policy = #{protectConflictPolicy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where site_id = #{siteId}
    </update>
</mapper>
