<?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.flossom.common.core.mapper.WxScriptTemplateMapper">

    <resultMap type="WxScriptTemplate" id="WxScriptTemplateResult">
        <result property="id"    column="id"    />
        <result property="tagNames"    column="tag_names"    />
        <result property="tagIds"    column="tag_ids"    />
        <result property="scriptName"    column="script_name"    />
        <result property="titile"    column="titile"    />
        <result property="content"    column="content"    />
        <result property="level"    column="level"    />
        <result property="tagType"    column="tag_type"    />
        <result property="type"    column="type"    />
        <result property="link"    column="link"    />
        <result property="linkParams"    column="link_params"    />
        <result property="redirectAppid"    column="redirect_appid"    />
        <result property="redirectUrl"    column="redirect_url"    />
        <result property="videoNo"    column="video_no"    />
        <result property="feedId"    column="feed_id"    />
        <result property="parentId"    column="parent_id"    />
        <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"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectWxScriptTemplateVo">
        select id,tag_ids,tag_names,script_name, titile, content, level, tag_type, type, link, link_params, redirect_appid, redirect_url, video_no, feed_id, parent_id, status, create_by, create_time, update_by, update_time, remark from wx_script_template
    </sql>

    <select id="selectWxScriptTemplateList" parameterType="WxScriptTemplate" resultMap="WxScriptTemplateResult">
        <include refid="selectWxScriptTemplateVo"/>
        <where>
            <if test="scriptName != null  and scriptName != ''"> and script_name = #{scriptName}</if>
            <if test="titile != null  and titile != ''"> and titile = #{titile}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="level != null "> and level = #{level}</if>
            <if test="tagType != null "> and tag_type = #{tagType}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="link != null  and link != ''"> and link = #{link}</if>
            <if test="linkParams != null  and linkParams != ''"> and link_params = #{linkParams}</if>
            <if test="redirectAppid != null  and redirectAppid != ''"> and redirect_appid = #{redirectAppid}</if>
            <if test="redirectUrl != null  and redirectUrl != ''"> and redirect_url = #{redirectUrl}</if>
            <if test="videoNo != null "> and video_no = #{videoNo}</if>
            <if test="feedId != null "> and feed_id = #{feedId}</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>

    <select id="selectWxScriptTemplateById" parameterType="Long" resultMap="WxScriptTemplateResult">
        <include refid="selectWxScriptTemplateVo"/>
        where id = #{id}
    </select>

    <select id="hasChildByScriptId" parameterType="Long" resultType="int">
        select count(1) from wx_script_template
        where  parent_id = #{id} limit 1
    </select>

    <insert id="insertWxScriptTemplate" parameterType="WxScriptTemplate" useGeneratedKeys="true" keyProperty="id">
        insert into wx_script_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tagNames != null">tag_names,</if>
            <if test="tagIds != null">tag_ids,</if>
            <if test="scriptName != null">script_name,</if>
            <if test="titile != null">titile,</if>
            <if test="content != null">content,</if>
            <if test="level != null">level,</if>
            <if test="tagType != null">tag_type,</if>
            <if test="type != null">type,</if>
            <if test="link != null">link,</if>
            <if test="linkParams != null">link_params,</if>
            <if test="redirectAppid != null">redirect_appid,</if>
            <if test="redirectUrl != null">redirect_url,</if>
            <if test="videoNo != null">video_no,</if>
            <if test="feedId != null">feed_id,</if>
            <if test="parentId != null">parent_id,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tagNames != null">#{tagNames},</if>
            <if test="tagIds != null">#{tagIds},</if>
            <if test="scriptName != null">#{scriptName},</if>
            <if test="titile != null">#{titile},</if>
            <if test="content != null">#{content},</if>
            <if test="level != null">#{level},</if>
            <if test="tagType != null">#{tagType},</if>
            <if test="type != null">#{type},</if>
            <if test="link != null">#{link},</if>
            <if test="linkParams != null">#{linkParams},</if>
            <if test="redirectAppid != null">#{redirectAppid},</if>
            <if test="redirectUrl != null">#{redirectUrl},</if>
            <if test="videoNo != null">#{videoNo},</if>
            <if test="feedId != null">#{feedId},</if>
            <if test="parentId != null">#{parentId},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateWxScriptTemplate" parameterType="WxScriptTemplate">
        update wx_script_template
        <trim prefix="SET" suffixOverrides=",">
            <if test="tagNames != null">tag_names = #{tagNames},</if>
            <if test="tagIds != null">tag_ids = #{tagIds},</if>
            <if test="scriptName != null">script_name = #{scriptName},</if>
            <if test="titile != null">titile = #{titile},</if>
            <if test="content != null">content = #{content},</if>
            <if test="level != null">level = #{level},</if>
            <if test="tagType != null">tag_type = #{tagType},</if>
            <if test="type != null">type = #{type},</if>
            <if test="link != null">link = #{link},</if>
            <if test="linkParams != null">link_params = #{linkParams},</if>
            <if test="redirectAppid != null">redirect_appid = #{redirectAppid},</if>
            <if test="redirectUrl != null">redirect_url = #{redirectUrl},</if>
            <if test="videoNo != null">video_no = #{videoNo},</if>
            <if test="feedId != null">feed_id = #{feedId},</if>
            <if test="parentId != null">parent_id = #{parentId},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWxScriptTemplateById" parameterType="Long">
        delete from wx_script_template where id = #{id}
    </delete>


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