<?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.live.mapper.LiveCouponIssueMapper">

    <resultMap type="LiveCouponIssue" id="LiveCouponIssueResult">
        <result property="id"    column="id"    />
        <result property="couponName"    column="coupon_name"    />
        <result property="couponId"    column="coupon_id"    />
        <result property="couponType"    column="coupon_type"    />
        <result property="startTime"    column="start_time"    />
        <result property="limitTime"    column="limit_time"    />
        <result property="totalCount"    column="total_count"    />
        <result property="remainCount"    column="remain_count"    />
        <result property="isPermanent"    column="is_permanent"    />
        <result property="status"    column="status"    />
        <result property="isDel"    column="is_del"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="couponPrice"    column="coupon_price"    />
        <result property="useMinPrice"    column="use_min_price"    />
        <result property="couponTime"    column="coupon_time"    />
    </resultMap>

    <sql id="selectLiveCouponIssueVo">
        select id, coupon_name, coupon_id, coupon_type, start_time, limit_time, total_count, remain_count, is_permanent, status, is_del, create_time, update_time from live_coupon_issue
    </sql>

    <select id="selectLiveCouponIssueList" parameterType="LiveCouponIssue" resultMap="LiveCouponIssueResult">
        select lci.id, lci.coupon_name, lci.coupon_id, lci.coupon_type, lci.start_time, lci.limit_time, lci.total_count,
        lci.remain_count, lci.is_permanent, lci.status, lci.is_del, lci.create_time, lci.update_time,lc.coupon_price,lc.use_min_price,lc.coupon_time from live_coupon_issue lci
        left join live_coupon lc on lci.coupon_id = lc.coupon_id
        <where>
            <if test="couponName != null  and couponName != ''"> and lci.coupon_name like concat('%', #{couponName}, '%')</if>
            <if test="couponId != null "> and lci.coupon_id = #{couponId}</if>
            <if test="couponType != null "> and lci.coupon_type = #{couponType}</if>
            <if test="startTime != null "> and lci.start_time = #{startTime}</if>
            <if test="limitTime != null "> and lci.limit_time = #{limitTime}</if>
            <if test="totalCount != null "> and lci.total_count = #{totalCount}</if>
            <if test="remainCount != null "> and lci.remain_count = #{remainCount}</if>
            <if test="isPermanent != null "> and lci.is_permanent = #{isPermanent}</if>
            <if test="status != null "> and lci.status = #{status}</if>
            <if test="isDel != null "> and lci.is_del = #{isDel}</if>
        </where>
    </select>

    <select id="selectLiveCouponIssueById" parameterType="Long" resultMap="LiveCouponIssueResult">
        <include refid="selectLiveCouponIssueVo"/>
        where id = #{id}
    </select>

    <insert id="insertLiveCouponIssue" parameterType="LiveCouponIssue" useGeneratedKeys="true" keyProperty="id">
        insert into live_coupon_issue
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="couponName != null">coupon_name,</if>
            <if test="couponId != null">coupon_id,</if>
            <if test="couponType != null">coupon_type,</if>
            <if test="startTime != null">start_time,</if>
            <if test="limitTime != null">limit_time,</if>
            <if test="totalCount != null">total_count,</if>
            <if test="remainCount != null">remain_count,</if>
            <if test="isPermanent != null">is_permanent,</if>
            <if test="status != null">status,</if>
            <if test="isDel != null">is_del,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="couponName != null">#{couponName},</if>
            <if test="couponId != null">#{couponId},</if>
            <if test="couponType != null">#{couponType},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="limitTime != null">#{limitTime},</if>
            <if test="totalCount != null">#{totalCount},</if>
            <if test="remainCount != null">#{remainCount},</if>
            <if test="isPermanent != null">#{isPermanent},</if>
            <if test="status != null">#{status},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateLiveCouponIssue" parameterType="LiveCouponIssue">
        update live_coupon_issue
        <trim prefix="SET" suffixOverrides=",">
            <if test="couponName != null">coupon_name = #{couponName},</if>
            <if test="couponId != null">coupon_id = #{couponId},</if>
            <if test="couponType != null">coupon_type = #{couponType},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="limitTime != null">limit_time = #{limitTime},</if>
            <if test="totalCount != null">total_count = #{totalCount},</if>
            <if test="remainCount != null">remain_count = #{remainCount},</if>
            <if test="isPermanent != null">is_permanent = #{isPermanent},</if>
            <if test="status != null">status = #{status},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLiveCouponIssueById" parameterType="Long">
        delete from live_coupon_issue where id = #{id}
    </delete>

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

</mapper>
