<?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.fs.store.mapper.FsStoreCouponMapper">

    <resultMap type="FsStoreCoupon" id="FsStoreCouponResult">
        <result property="couponId"    column="coupon_id"    />
        <result property="title"    column="title"    />
        <result property="integral"    column="integral"    />
        <result property="couponPrice"    column="coupon_price"    />
        <result property="useMinPrice"    column="use_min_price"    />
        <result property="couponTime"    column="coupon_time"    />
        <result property="sort"    column="sort"    />
        <result property="status"    column="status"    />
        <result property="productIds"    column="product_ids"    />
        <result property="packageCateIds"    column="package_cate_ids"    />
        <result property="type"    column="type"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectFsStoreCouponVo">
        select coupon_id, title, integral, coupon_price, use_min_price, coupon_time, sort, status, product_ids,package_cate_ids, type, create_time, update_time, is_del from fs_store_coupon
    </sql>

    <select id="selectFsStoreCouponList" parameterType="FsStoreCoupon" resultMap="FsStoreCouponResult">
        <include refid="selectFsStoreCouponVo"/>
        <where>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="integral != null "> and integral = #{integral}</if>
            <if test="couponPrice != null "> and coupon_price = #{couponPrice}</if>
            <if test="useMinPrice != null "> and use_min_price = #{useMinPrice}</if>
            <if test="couponTime != null "> and coupon_time = #{couponTime}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="productIds != null  and productIds != ''"> and product_ids = #{productIds}</if>
            <if test="packageCateIds != null  and packageCateIds != ''"> and package_cate_ids = #{packageCateIds}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="beginTime != null and beginTime != ''">
            and date_format(create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d') </if>
            <if test="endTime != null and endTime != ''">
            and date_format(create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d') </if>
        </where>
        order by coupon_price
    </select>

    <select id="selectFsStoreCouponById" parameterType="Long" resultMap="FsStoreCouponResult">
        <include refid="selectFsStoreCouponVo"/>
        where coupon_id = #{couponId}
    </select>

    <insert id="insertFsStoreCoupon" parameterType="FsStoreCoupon" useGeneratedKeys="true" keyProperty="couponId">
        insert into fs_store_coupon
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">title,</if>
            <if test="integral != null">integral,</if>
            <if test="couponPrice != null">coupon_price,</if>
            <if test="useMinPrice != null">use_min_price,</if>
            <if test="couponTime != null">coupon_time,</if>
            <if test="sort != null">sort,</if>
            <if test="status != null">status,</if>
            <if test="productIds != null">product_ids,</if>
            <if test="packageCateIds != null">package_cate_ids,</if>
            <if test="type != null">type,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">#{title},</if>
            <if test="integral != null">#{integral},</if>
            <if test="couponPrice != null">#{couponPrice},</if>
            <if test="useMinPrice != null">#{useMinPrice},</if>
            <if test="couponTime != null">#{couponTime},</if>
            <if test="sort != null">#{sort},</if>
            <if test="status != null">#{status},</if>
            <if test="productIds != null">#{productIds},</if>
            <if test="packageCateIds != null">#{packageCateIds},</if>
            <if test="type != null">#{type},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateFsStoreCoupon" parameterType="FsStoreCoupon">
        update fs_store_coupon
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="integral != null">integral = #{integral},</if>
            <if test="couponPrice != null">coupon_price = #{couponPrice},</if>
            <if test="useMinPrice != null">use_min_price = #{useMinPrice},</if>
            <if test="couponTime != null">coupon_time = #{couponTime},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="status != null">status = #{status},</if>
            <if test="productIds != null">product_ids = #{productIds},</if>
            <if test="packageCateIds != null">package_cate_ids = #{packageCateIds},</if>
            <if test="type != null">type = #{type},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where coupon_id = #{couponId}
    </update>

    <delete id="deleteFsStoreCouponById" parameterType="Long">
        delete from fs_store_coupon where coupon_id = #{couponId}
    </delete>

    <delete id="deleteFsStoreCouponByIds" parameterType="String">
        delete from fs_store_coupon where coupon_id in
        <foreach item="couponId" collection="array" open="(" separator="," close=")">
            #{couponId}
        </foreach>
    </delete>


</mapper>
