<?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.PromotionsMapper">
    <resultMap  id="BaseResultMap" type="Promotions" >
        <result    column="promotions_id"    property="promotionsId" />
        <result    column="promotions_name"    property="promotionsName" />
        <result    column="promotions_type"    property="promotionsType" />
        <result    column="promotions_status"    property="promotionsStatus" />
        <result    column="promotions_begin_time"    property="promotionsBeginTime" />
        <result    column="promotions_end_time"    property="promotionsEndTime" />
        <result    column="promotions_desc"    property="promotionsDesc" />
        <result    column="promotions_create_time"    property="promotionsCreateTime" />
    </resultMap>
    <sql    id="Base_List" >
        t.promotions_id,
        t.promotions_name,
        t.promotions_type,
        t.promotions_status,
        t.promotions_begin_time,
        t.promotions_end_time,
        t.promotions_desc,
        t.promotions_create_time
    </sql>
    <select id="getPromotionsList" resultMap="BaseResultMap" parameterType="Promotions" >
        select
        <include refid="Base_List" />
        from tb_iamberry_eo_promotions t
        <where>
            <if test="promotionsId != null ">
                AND t.promotions_id = #{promotionsId}
            </if >
            <if test="promotionsName != null and promotionsName != ''">
                AND t.promotions_name  like  CONCAT ('%',#{promotionsName},'%')
            </if >
            <if test="promotionsType != null ">
                AND t.promotions_type = #{promotionsType}
            </if >
            <if test="promotionsStatus != null ">
                AND t.promotions_status = #{promotionsStatus}
            </if >
            <if test="promotionsDesc != null and promotionsDesc != ''">
                AND t.promotions_desc  like  CONCAT ('%',#{promotionsDesc},'%')
            </if >
        </where>
    </select>
    <select id="getPromotionsListByTime" resultMap="BaseResultMap" parameterType="Promotions" >
        select
        <include refid="Base_List" />
        from tb_iamberry_eo_promotions t
        <where>
            AND t.promotions_status = 1
            AND t.promotions_begin_time <![CDATA[ <= ]]> NOW()
            AND t.promotions_end_time <![CDATA[ >= ]]> NOW()
            <if test="promotionsType != null ">
                AND t.promotions_type = #{promotionsType}
            </if >
        </where>
    </select>
    <select id="getPromotionsById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_eo_promotions t
        where t.promotions_id= #{promotionsId}
    </select>
</mapper>