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

    <resultMap type="com.ruoyi.ems.domain.AdmOpEnergyStrategy" id="AdmOpEnergyStrategyResult">
        <result property="id"    column="id"    />
        <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="execMode"    column="exec_mode"    />
        <result property="execRule"    column="exec_rule"    />
        <result property="allowModify"    column="allow_modify"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectAdmOpEnergyStrategyVo">
        select id, strategy_code, strategy_name, strategy_desc, strategy_type, exec_mode, exec_rule, allow_modify, create_time, update_time from adm_op_energy_strategy
    </sql>

    <select id="selectAdmOpEnergyStrategyList" parameterType="com.ruoyi.ems.domain.AdmOpEnergyStrategy" resultMap="AdmOpEnergyStrategyResult">
        <include refid="selectAdmOpEnergyStrategyVo"/>
        <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="strategyDesc != null  and strategyDesc != ''"> and strategy_desc = #{strategyDesc}</if>
            <if test="strategyType != null "> and strategy_type = #{strategyType}</if>
            <if test="execMode != null "> and exec_mode = #{execMode}</if>
            <if test="execRule != null  and execRule != ''"> and exec_rule = #{execRule}</if>
            <if test="allowModify != null "> and allow_modify = #{allowModify}</if>
        </where>
    </select>

    <select id="selectAdmOpEnergyStrategyById" parameterType="Long" resultMap="AdmOpEnergyStrategyResult">
        <include refid="selectAdmOpEnergyStrategyVo"/>
        where id = #{id}
    </select>

    <insert id="insertAdmOpEnergyStrategy" parameterType="com.ruoyi.ems.domain.AdmOpEnergyStrategy" useGeneratedKeys="true" keyProperty="id">
        insert into adm_op_energy_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="strategyDesc != null">strategy_desc,</if>
            <if test="strategyType != null">strategy_type,</if>
            <if test="execMode != null">exec_mode,</if>
            <if test="execRule != null">exec_rule,</if>
            <if test="allowModify != null">allow_modify,</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="strategyDesc != null">#{strategyDesc},</if>
            <if test="strategyType != null">#{strategyType},</if>
            <if test="execMode != null">#{execMode},</if>
            <if test="execRule != null">#{execRule},</if>
            <if test="allowModify != null">#{allowModify},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateAdmOpEnergyStrategy" parameterType="com.ruoyi.ems.domain.AdmOpEnergyStrategy">
        update adm_op_energy_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="strategyDesc != null">strategy_desc = #{strategyDesc},</if>
            <if test="strategyType != null">strategy_type = #{strategyType},</if>
            <if test="execMode != null">exec_mode = #{execMode},</if>
            <if test="execRule != null">exec_rule = #{execRule},</if>
            <if test="allowModify != null">allow_modify = #{allowModify},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

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

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