<?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.SalesActivitiesMapper">
    <resultMap  id="BaseResultMap" type="SalesActivities" >
        <result    column="sales_activities_id"    property="salesActivitiesId" />
        <result    column="sales_activities_name"    property="salesActivitiesName" />
        <result    column="sales_activities_type"    property="salesActivitiesType" />
        <result    column="sales_activities_full"    property="salesActivitiesFull" />
        <result    column="sales_activities_reduction"    property="salesActivitiesReduction" />
        <result    column="sales_activities_status"    property="salesActivitiesStatus" />
        <result    column="sales_activities_scenes"    property="salesActivitiesScenes" />
        <result    column="sales_activities_begin_time"    property="salesActivitiesBeginTime" />
        <result    column="sales_activities_end_time"    property="salesActivitiesEndTime" />
        <result    column="sales_activities_create_time"    property="salesActivitiesCreateTime" />
        <result    column="sales_activities_update_time"    property="salesActivitiesUpdateTime" />
    </resultMap>
    <sql    id="Base_List" >
        t.sales_activities_id,
        t.sales_activities_name,
        t.sales_activities_type,
        t.sales_activities_full,
        t.sales_activities_reduction,
        t.sales_activities_status,
        t.sales_activities_scenes,
        t.sales_activities_begin_time,
        t.sales_activities_end_time,
        t.sales_activities_create_time,
        t.sales_activities_update_time
    </sql>

    <select id="getSalesActivitiesList" resultMap="BaseResultMap" parameterType="SalesActivities" >
        select
        <include refid="Base_List" />
        from tb_iamberry_sales_activities t
        <where>
            <if test="salesActivitiesId != null ">
                AND t.sales_activities_id = #{salesActivitiesId}
            </if >
            <if test="salesActivitiesName != null and salesActivitiesName != ''">
                AND t.sales_activities_name  like  CONCAT ('%',#{salesActivitiesName},'%')
            </if >
            <if test="salesActivitiesType != null ">
                AND t.sales_activities_type = #{salesActivitiesType}
            </if >
            <if test="salesActivitiesFull != null ">
                AND t.sales_activities_full = #{salesActivitiesFull}
            </if >
            <if test="salesActivitiesReduction != null ">
                AND t.sales_activities_reduction = #{salesActivitiesReduction}
            </if >
            <if test="salesActivitiesStatus != null ">
                AND t.sales_activities_status = #{salesActivitiesStatus}
            </if >
            <if test="salesActivitiesScenes != null ">
                AND t.sales_activities_scenes = #{salesActivitiesScenes}
            </if >
        </where>
        ORDER BY  t.sales_activities_full DESC
    </select>

    <select id="getSalesActivitiesById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_sales_activities t
        where t.sales_activities_id= #{salesActivitiesId}
    </select>

    <insert id="save" parameterType="SalesActivities" >
        insert into
        tb_iamberry_sales_activities
        (
        sales_activities_name,
        sales_activities_type,
        sales_activities_full,
        sales_activities_reduction,
        sales_activities_status,
        sales_activities_scenes,
        sales_activities_begin_time,
        sales_activities_end_time
        )
        values
        (
        #{salesActivitiesName},
        #{salesActivitiesType},
        #{salesActivitiesFull},
        #{salesActivitiesReduction},
        #{salesActivitiesStatus},
        #{salesActivitiesScenes},
        #{salesActivitiesBeginTime},
        #{salesActivitiesEndTime}
        )
    </insert>
    <update id="update" parameterType="SalesActivities" >
        update
        tb_iamberry_sales_activities
        <set >
            <if test="salesActivitiesName != null and salesActivitiesName != ''">
                sales_activities_name = #{salesActivitiesName},
            </if >
            <if test="salesActivitiesType != null ">
                sales_activities_type = #{salesActivitiesType},
            </if >
            <if test="salesActivitiesFull != null ">
                sales_activities_full = #{salesActivitiesFull},
            </if >
            <if test="salesActivitiesReduction != null ">
                sales_activities_reduction = #{salesActivitiesReduction},
            </if >
            <if test="salesActivitiesStatus != null ">
                sales_activities_status = #{salesActivitiesStatus},
            </if >
            <if test="salesActivitiesScenes != null ">
                sales_activities_scenes = #{salesActivitiesScenes},
            </if >
            <if test="salesActivitiesBeginTime != null and salesActivitiesBeginTime != ''">
                sales_activities_begin_time = #{salesActivitiesBeginTime},
            </if >
            <if test="salesActivitiesEndTime != null and salesActivitiesEndTime != ''">
                sales_activities_end_time = #{salesActivitiesEndTime},
            </if >
        </set >
        where sales_activities_id= #{salesActivitiesId}
    </update>
    <delete id="delete" parameterType="Integer" >
        delete FROM
        tb_iamberry_sales_activities
        where sales_activities_id=#{salesActivitiesId}
    </delete>
</mapper>