<?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.OpEnergyStrategyTemplateMapper">
    
    <resultMap type="com.ruoyi.ems.domain.OpEnergyStrategyTemplate" id="OpEnergyStrategyTemplateResult">
        <result property="id"    column="id"    />
        <result property="templateCode"    column="template_code"    />
        <result property="templateName"    column="template_name"    />
        <result property="sceneType"    column="scene_type"    />
        <result property="description"    column="description"    />
        <result property="templateData"    column="template_data"    />
        <result property="icon"    column="icon"    />
        <result property="coverImage"    column="cover_image"    />
        <result property="tags"    column="tags"    />
        <result property="applicableDevices"    column="applicable_devices"    />
        <result property="sortOrder"    column="sort_order"    />
        <result property="useCount"    column="use_count"    />
        <result property="isSystem"    column="is_system"    />
        <result property="isPublic"    column="is_public"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectTemplateVo">
        select id, template_code, template_name, scene_type, description, template_data, icon, cover_image, tags, applicable_devices, sort_order, use_count, is_system, is_public, status, create_by, create_time, update_by, update_time from adm_op_energy_strategy_template
    </sql>

    <select id="selectTemplateList" parameterType="com.ruoyi.ems.domain.OpEnergyStrategyTemplate" resultMap="OpEnergyStrategyTemplateResult">
        <include refid="selectTemplateVo"/>
        <where>  
            <if test="templateCode != null  and templateCode != ''"> and template_code = #{templateCode}</if>
            <if test="templateName != null  and templateName != ''"> and template_name like concat('%', #{templateName}, '%')</if>
            <if test="sceneType != null  and sceneType != ''"> and scene_type = #{sceneType}</if>
            <if test="status != null"> and `status` = #{status}</if>
        </where>
    </select>
    
    <select id="selectTemplateById" parameterType="Long" resultMap="OpEnergyStrategyTemplateResult">
        <include refid="selectTemplateVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTemplate" parameterType="com.ruoyi.ems.domain.OpEnergyStrategyTemplate" useGeneratedKeys="true" keyProperty="id">
        insert into adm_op_energy_strategy_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="templateCode != null and templateCode != ''">template_code,</if>
            <if test="templateName != null and templateName != ''">template_name,</if>
            <if test="sceneType != null and sceneType != ''">scene_type,</if>
            <if test="description != null">`description`,</if>
            <if test="templateData != null">template_data,</if>
            <if test="icon != null">icon,</if>
            <if test="coverImage != null">cover_image,</if>
            <if test="tags != null">tags,</if>
            <if test="applicableDevices != null">applicable_devices,</if>
            <if test="sortOrder != null">sort_order,</if>
            <if test="useCount != null">use_count,</if>
            <if test="isSystem != null">is_system,</if>
            <if test="isPublic != null">is_public,</if>
            <if test="status != null">`status`,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="templateCode != null and templateCode != ''">#{templateCode},</if>
            <if test="templateName != null and templateName != ''">#{templateName},</if>
            <if test="sceneType != null and sceneType != ''">#{sceneType},</if>
            <if test="description != null">#{description},</if>
            <if test="templateData != null">#{templateData},</if>
            <if test="icon != null">#{icon},</if>
            <if test="coverImage != null">#{coverImage},</if>
            <if test="tags != null">#{tags},</if>
            <if test="applicableDevices != null">#{applicableDevices},</if>
            <if test="sortOrder != null">#{sortOrder},</if>
            <if test="useCount != null">#{useCount},</if>
            <if test="isSystem != null">#{isSystem},</if>
            <if test="isPublic != null">#{isPublic},</if>
            <if test="status != null">#{status},</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>
         </trim>
    </insert>

    <update id="updateTemplate" parameterType="com.ruoyi.ems.domain.OpEnergyStrategyTemplate">
        update adm_op_energy_strategy_template
        <trim prefix="SET" suffixOverrides=",">
            <if test="templateCode != null and templateCode != ''">template_code = #{templateCode},</if>
            <if test="templateName != null and templateName != ''">template_name = #{templateName},</if>
            <if test="sceneType != null and sceneType != ''">scene_type = #{sceneType},</if>
            <if test="description != null">`description` = #{description},</if>
            <if test="templateData != null">template_data = #{templateData},</if>
            <if test="icon != null">icon = #{icon},</if>
            <if test="coverImage != null">cover_image = #{coverImage},</if>
            <if test="tags != null">tags = #{tags},</if>
            <if test="applicableDevices != null">applicable_devices = #{applicableDevices},</if>
            <if test="sortOrder != null">sort_order = #{sortOrder},</if>
            <if test="useCount != null">use_count = #{useCount},</if>
            <if test="isSystem != null">is_system = #{isSystem},</if>
            <if test="isPublic != null">is_public = #{isPublic},</if>
            <if test="status != null">`status` = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTemplateById" parameterType="Long">
        delete from adm_op_energy_strategy_template where id = #{id}
    </delete>

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