<?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.iamberry.wechat.service.mapper.MothMovableMapper">
    <resultMap  id="BaseResultMap" type="MothMovable" >
        <result    column="moth_mova_id"    property="mothMovaId" />
        <result    column="moth_mova_open_id"    property="mothMovaOpenId" />
        <result    column="moth_mova_head"    property="mothMovaHead" />
        <result    column="moth_mova_name"    property="mothMovaName" />
        <result    column="moth_mova_text"    property="mothMovaText" />
        <result    column="moth_mova_share_url"    property="mothMovaShareUrl" />
        <result    column="moth_mova_back_type"    property="mothMovaBackType" />
        <result    column="moth_mova_img_url"    property="mothMovaImgUrl" />
        <result    column="coupon_item_id"    property="couponItemId" />
        <result    column="moth_mova_create_time"    property="mothMovaCreateTime" />
    </resultMap>
    <sql    id="Base_List" >
        t.moth_mova_id,
        t.moth_mova_open_id,
        t.moth_mova_head,
        t.moth_mova_name,
        t.moth_mova_text,
        t.moth_mova_share_url,
        t.moth_mova_back_type,
        t.moth_mova_img_url,
        t.coupon_item_id,
        t.moth_mova_create_time
    </sql>
    <select id="getMothMovableList" resultMap="BaseResultMap" parameterType="MothMovable" >
        select
        <include refid="Base_List" />
        from tb_iamberry_mother_movable t
        <where>
            <if test="mothMovaId != null ">
                AND t.moth_mova_id = #{mothMovaId}
            </if >
            <if test="mothMovaOpenId != null and mothMovaOpenId != ''">
                AND t.moth_mova_open_id = #{mothMovaOpenId}
            </if >
            <if test="mothMovaBackType != null and mothMovaBackType != ''">
                AND t.moth_mova_back_type = #{mothMovaBackType}
            </if >
            <if test="couponItemId != null and couponItemId != ''">
                AND t.coupon_item_id = #{couponItemId}
            </if >
        </where>
    </select>

    <select id="getNum" resultType="Integer" parameterType="MothMovable" >
        select
	    COUNT(t.moth_mova_id)
        from tb_iamberry_mother_movable t
    </select>

    <select id="getMothMovableById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_mother_movable t
        where t.moth_mova_id= #{mothMovaId}
    </select>
    <insert id="save" parameterType="MothMovable"  keyProperty="mothMovaId" useGeneratedKeys="true" >
        insert into
        tb_iamberry_mother_movable
        (
        moth_mova_id,
        moth_mova_open_id,
        moth_mova_head,
        moth_mova_name,
        moth_mova_text,
        moth_mova_share_url,
        moth_mova_back_type,
        moth_mova_img_url,
        coupon_item_id
        )
        values
        (
        #{mothMovaId},
        #{mothMovaOpenId},
        #{mothMovaHead},
        #{mothMovaName},
        #{mothMovaText},
        #{mothMovaShareUrl},
        #{mothMovaBackType},
        #{mothMovaImgUrl},
        #{couponItemId}
        )
    </insert>
    <update id="update" parameterType="MothMovable" >
        update
        tb_iamberry_mother_movable
        <set >
            <if test="mothMovaOpenId != null ">
                moth_mova_open_id = #{mothMovaOpenId},
            </if >
            <if test="mothMovaHead != null and mothMovaHead != ''">
                moth_mova_head = #{mothMovaHead},
            </if >
            <if test="mothMovaText != null and mothMovaText != ''">
                moth_mova_text = #{mothMovaText},
            </if >
            <if test="mothMovaShareUrl != null and mothMovaShareUrl != ''">
                moth_mova_share_url = #{mothMovaShareUrl},
            </if >
            <if test="mothMovaBackType != null and mothMovaBackType != ''">
                moth_mova_back_type = #{mothMovaBackType},
            </if >
            <if test="mothMovaImgUrl != null and mothMovaImgUrl != ''">
                moth_mova_img_url = #{mothMovaImgUrl},
            </if >
            <if test="couponItemId != null and couponItemId != ''">
                coupon_item_id = #{couponItemId},
            </if >
        </set >
        where moth_mova_id= #{mothMovaId}
    </update>
    <delete id="delete" parameterType="Integer" >
        delete FROM
        tb_iamberry_mother_movable
        where moth_mova_id=#{mothMovaId}
    </delete>
</mapper>