<?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.yiqi.crm.mapper.WxMenuMapper">

    <resultMap type="com.yiqi.crm.domain.WxMenu" id="WxMenuResult">
        <result property="wxMenuId" column="wx_menu_id"/>
        <result property="wxMenuName" column="wx_menu_name"/>
        <result property="wxMenuType" column="wx_menu_type"/>
        <result property="parentId" column="parent_id"/>
        <result property="keyWords" column="key_words"/>
        <result property="sort" column="sort"/>
        <result property="status" column="status"/>
        <result property="extendMenu" column="extend_menu"/>
        <result property="picTextUrl" column="pic_text_url"/>
        <result property="createTime" column="create_time"/>
    </resultMap>

    <sql id="selectWxMenuVo">
        select wx_menu_id, wx_menu_name, wx_menu_type, parent_id, key_words, sort, status, extend_menu, pic_text_url, create_time
        from wx_menu
    </sql>

    <select id="selectWxMenuList" resultMap="WxMenuResult">
        <include refid="selectWxMenuVo"/>
        <where>
            <if test="wxMenuName != null  and wxMenuName != ''">
                and wx_menu_name = #{wxMenuName}
            </if>
            <if test="wxMenuType != null  and wxMenuType != ''">
                and wx_menu_type = #{wxMenuType}
            </if>
            <if test="parentId != null ">
                and parent_id = #{parentId}
            </if>
            <if test="keyWords != null  and keyWords != ''">
                and key_words = #{keyWords}
            </if>
            <if test="sort != null  and sort != ''">
                and sort = #{sort}
            </if>
            <if test="status != null  and status != ''">
                and status = #{status}
            </if>
            <if test="extendMenu != null  and extendMenu != ''">
                and extend_menu = #{extendMenu}
            </if>
            <if test="picTextUrl != null  and picTextUrl != ''">
                and pic_text_url = #{picTextUrl}
            </if>
        </where>
    </select>

    <select id="selectWxMenuByWxMenuId" parameterType="Long"
            resultMap="WxMenuResult">
        <include refid="selectWxMenuVo"/>
        where wx_menu_id = #{wxMenuId}
    </select>
    <select id="getMenuTypeList" resultMap="WxMenuResult">
        <include refid="selectWxMenuVo"/>
        where status = "0"
    </select>

    <insert id="insertWxMenu"  useGeneratedKeys="true"
            keyProperty="wxMenuId">
        insert into wx_menu
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="wxMenuName != null">wx_menu_name,
            </if>
            <if test="wxMenuType != null">wx_menu_type,
            </if>
            <if test="parentId != null">parent_id,
            </if>
            <if test="keyWords != null">key_words,
            </if>
            <if test="sort != null">sort,
            </if>
            <if test="status != null">status,
            </if>
            <if test="extendMenu != null">extend_menu,
            </if>
            <if test="picTextUrl != null">pic_text_url,
            </if>
            <if test="createTime != null">create_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="wxMenuName != null">#{wxMenuName},
            </if>
            <if test="wxMenuType != null">#{wxMenuType},
            </if>
            <if test="parentId != null">#{parentId},
            </if>
            <if test="keyWords != null">#{keyWords},
            </if>
            <if test="sort != null">#{sort},
            </if>
            <if test="status != null">#{status},
            </if>
            <if test="extendMenu != null">#{extendMenu},
            </if>
            <if test="picTextUrl != null">#{picTextUrl},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
        </trim>
    </insert>

    <update id="updateWxMenu" >
        update wx_menu
        <trim prefix="SET" suffixOverrides=",">
            <if test="wxMenuName != null">wx_menu_name =
                #{wxMenuName},
            </if>
            <if test="wxMenuType != null">wx_menu_type =
                #{wxMenuType},
            </if>
            <if test="parentId != null">parent_id =
                #{parentId},
            </if>
            <if test="keyWords != null">key_words =
                #{keyWords},
            </if>
            <if test="sort != null">sort =
                #{sort},
            </if>
            <if test="status != null">status =
                #{status},
            </if>
            <if test="extendMenu != null">extend_menu =
                #{extendMenu},
            </if>
            <if test="picTextUrl != null">pic_text_url =
                #{picTextUrl},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
        </trim>
        where wx_menu_id = #{wxMenuId}
    </update>

    <delete id="deleteWxMenuByWxMenuId" parameterType="Long">
        delete from wx_menu where wx_menu_id = #{wxMenuId}
    </delete>

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