<?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.liquidnet.service.candy.mapper.CandyUserCouponMapper">

    <resultMap id="Rst_UserCouponBasicDto" type="com.liquidnet.service.candy.dto.CandyUserCouponBasicDto">
        <result column="coupon_id" jdbcType="VARCHAR" property="couponId"/>
        <!--        <result column="state" jdbcType="TINYINT" property="state"/>-->
        <result column="title" jdbcType="VARCHAR" property="title"/>
        <result column="label" jdbcType="VARCHAR" property="label"/>
        <result column="notice" jdbcType="VARCHAR" property="notice"/>
        <result column="exclusive" jdbcType="SMALLINT" property="exclusive"/>
        <result column="busi_type" jdbcType="SMALLINT" property="busiType"/>
        <result column="cou_type" jdbcType="SMALLINT" property="couType"/>
        <result column="bind_type" jdbcType="SMALLINT" property="bindType"/>
        <result column="discount" jdbcType="DECIMAL" property="discount"/>
        <result column="val_face" jdbcType="DECIMAL" property="valFace"/>
        <result column="val_over" jdbcType="DECIMAL" property="valOver"/>
        <result column="val_minus" jdbcType="DECIMAL" property="valMinus"/>
        <result column="overlay" jdbcType="TINYINT" property="overlay"/>
        <result column="overlay_level" jdbcType="TINYINT" property="overlayLevel"/>
        <result column="validity" jdbcType="INTEGER" property="validity"/>
        <result column="redeem_validity" jdbcType="INTEGER" property="redeemValidity"/>
        <result column="redeem_start" jdbcType="TIMESTAMP" property="redeemStart"/>
        <result column="redeem_stop" jdbcType="TIMESTAMP" property="redeemStop"/>
        <!--        <result column="effect_at" jdbcType="TIMESTAMP" property="effectAt"/>-->
        <!--        <result column="expire_at" jdbcType="TIMESTAMP" property="expireAt"/>-->
        <!--        <result column="operator" jdbcType="VARCHAR" property="operator" />-->
        <!--        <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />-->
        <!--        <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />-->
        <!--        <result column="comment" jdbcType="VARCHAR" property="comment" />-->

        <result column="ucoupon_id" jdbcType="VARCHAR" property="ucouponId"/>
        <!--        <result column="mcoupon_id" jdbcType="VARCHAR" property="mcouponId" />-->
        <result column="uid" jdbcType="VARCHAR" property="uid"/>
        <!--        <result column="coupon_id" jdbcType="VARCHAR" property="couponId" />-->
        <result column="state" jdbcType="TINYINT" property="state"/>
        <result column="ccode" jdbcType="VARCHAR" property="ccode"/>
        <result column="bind_at" jdbcType="TIMESTAMP" property="bindAt"/>
        <result column="dued_at" jdbcType="TIMESTAMP" property="duedAt"/>
        <result column="used_at" jdbcType="TIMESTAMP" property="usedAt"/>
        <result column="used_for" jdbcType="VARCHAR" property="usedFor"/>
        <!--        <result column="comment" jdbcType="VARCHAR" property="comment" />-->
    </resultMap>

    <sql id="Rst_UserCouponBasicDto_Column_List">
        cc.coupon_id, cc.title, cc.`label`, cc.notice, cc.`exclusive`, cc.busi_type, cc.cou_type, cc.bind_type,
        cc.discount, cc.val_face, cc.val_over, cc.val_minus, cc.`overlay`, cc.overlay_level,
        cc.validity, cc.redeem_validity, cc.redeem_start, cc.redeem_stop,

        cuc.ucoupon_id, cuc.mcoupon_id, cuc.`uid`, cuc.`state`, cuc.ccode, cuc.bind_at, cuc.dued_at, cuc.used_at, cuc.used_for
    </sql>

    <select id="selectMultiForUserCouponBasicDto" resultMap="Rst_UserCouponBasicDto">
        SELECT
        <include refid="Rst_UserCouponBasicDto_Column_List"/>
        FROM candy_user_coupon cuc
        LEFT JOIN candy_coupon cc ON cuc.coupon_id = cc.coupon_id
        WHERE cuc.state <![CDATA[<>]]> 2
        AND cuc.uid = #{uid,jdbcType=VARCHAR}
    </select>
</mapper>
