<?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.OpEnergyStrategyMapper">

    <resultMap type="com.ruoyi.ems.domain.OpEnergyStrategy" id="StrategyResult">
        <result property="id"    column="id"    />
        <result property="areaCode"        column="area_code"    />
        <result property="strategyCode"    column="strategy_code"    />
        <result property="strategyName"    column="strategy_name"    />
        <result property="strategyDesc"    column="strategy_desc"    />
        <result property="strategyType"    column="strategy_type"    />
        <result property="strategyState"   column="strategy_state"    />
        <result property="execMode"        column="exec_mode"    />
        <result property="execRule"        column="exec_rule"    />
    </resultMap>

    <sql id="selectStrategyVo">
        select s.id, s.area_code, s.strategy_code, s.strategy_name, s.strategy_desc, s.strategy_type, s.strategy_state, s.exec_mode, s.exec_rule from adm_op_energy_strategy s
    </sql>

    <select id="selectStrategyList" parameterType="com.ruoyi.ems.domain.OpEnergyStrategy" resultMap="StrategyResult">
        <include refid="selectStrategyVo"/>
        <where>
            <if test="areaCode != null and areaCode != '' and areaCode != '-1'"> and area_code = #{areaCode}</if>
            <if test="strategyCode != null and strategyCode != ''"> and strategy_code = #{strategyCode}</if>
            <if test="strategyType != null "> and strategy_type = #{strategyType}</if>
            <if test="execMode != null "> and exec_mode = #{execMode}</if>
            <if test="strategyName != null  and strategyName != ''"> and strategy_name like concat('%', #{strategyName}, '%')</if>
        </where>
    </select>

    <select id="selectStrategyById" parameterType="Long" resultMap="StrategyResult">
        <include refid="selectStrategyVo"/>
        where id = #{id}
    </select>

    <insert id="insertStrategy" parameterType="com.ruoyi.ems.domain.OpEnergyStrategy" useGeneratedKeys="true" keyProperty="id">
        insert into adm_op_energy_strategy
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">area_code,</if>
            <if test="strategyCode != null and strategyCode != ''">strategy_code,</if>
            <if test="strategyName != null and strategyName != ''">strategy_name,</if>
            <if test="strategyDesc != null">strategy_desc,</if>
            <if test="strategyType != null">strategy_type,</if>
            <if test="strategyState != null">strategy_state,</if>
            <if test="execMode != null">exec_mode,</if>
            <if test="execRule != null">exec_rule,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">#{areaCode},</if>
            <if test="strategyCode != null and strategyCode != ''">#{strategyCode},</if>
            <if test="strategyName != null and strategyName != ''">#{strategyName},</if>
            <if test="strategyDesc != null">#{strategyDesc},</if>
            <if test="strategyType != null">#{strategyType},</if>
            <if test="strategyState != null">#{strategyState},</if>
            <if test="execMode != null">#{execMode},</if>
            <if test="execRule != null">#{execRule},</if>
         </trim>
    </insert>

    <update id="updateStrategy" parameterType="com.ruoyi.ems.domain.OpEnergyStrategy">
        update adm_op_energy_strategy
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">area_code = #{areaCode},</if>
            <if test="strategyCode != null and strategyCode != ''">strategy_code = #{strategyCode},</if>
            <if test="strategyCode != null and strategyCode != ''">strategy_code = #{strategyCode},</if>
            <if test="strategyName != null and strategyName != ''">strategy_name = #{strategyName},</if>
            <if test="strategyDesc != null">strategy_desc = #{strategyDesc},</if>
            <if test="strategyType != null">strategy_type = #{strategyType},</if>
            <if test="strategyState != null">strategy_state = #{strategyState},</if>
            <if test="execMode != null">exec_mode = #{execMode},</if>
            <if test="execRule != null">exec_rule = #{execRule},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteStrategyById" parameterType="Long">
        delete from adm_op_energy_strategy where id = #{id}
    </delete>

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