<?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.CandyMgtCouponMapper">

    <resultMap id="Rst_MgtCouponInfoDto" type="com.liquidnet.service.candy.dto.admin.CandyMgtCouponInfoDto">
        <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="VARCHAR" property="redeemStart"/>
        <result column="redeem_stop" jdbcType="VARCHAR" property="redeemStop"/>
        <result column="effect_at" jdbcType="VARCHAR" property="effectAt"/>
        <result column="expire_at" jdbcType="VARCHAR" 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="mcoupon_id" jdbcType="VARCHAR" property="mcouponId"/>
        <!--        <result column="coupon_id" jdbcType="VARCHAR" property="couponId" />-->
        <result column="state" jdbcType="TINYINT" property="state"/>
<!--        <result column="bind_type" jdbcType="SMALLINT" property="bindType"/>-->
        <result column="event_amt" jdbcType="INTEGER" property="eventAmt"/>
        <result column="event_type" jdbcType="TINYINT" property="eventType"/>
        <result column="event_limit" jdbcType="VARCHAR" property="eventLimit"/>
        <result column="event_at" jdbcType="VARCHAR" property="eventAt"/>
        <result column="operator" jdbcType="VARCHAR" property="operator"/>
        <result column="created_at" jdbcType="VARCHAR" property="createdAt"/>
        <result column="updated_at" jdbcType="VARCHAR" property="updatedAt"/>
        <!--        <result column="comment" jdbcType="VARCHAR" property="comment" />-->
    </resultMap>

    <resultMap id="Rst_MgtCouponMemberDto" type="com.liquidnet.service.candy.dto.admin.CandyMgtCouponMemberDto">
        <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="mcoupon_id" jdbcType="VARCHAR" property="mcouponId"/>
        <!--        <result column="coupon_id" jdbcType="VARCHAR" property="couponId" />-->
        <!--        <result column="state" jdbcType="TINYINT" property="state"/>-->
        <!--        <result column="bind_type" jdbcType="SMALLINT" property="bindType"/>-->
        <result column="event_amt" jdbcType="INTEGER" property="eventAmt"/>
        <!--        <result column="event_type" jdbcType="TINYINT" property="eventType"/>-->
        <!--        <result column="event_limit" jdbcType="VARCHAR" property="eventLimit"/>-->
        <!--        <result column="event_at" jdbcType="TIMESTAMP" property="eventAt"/>-->
        <!--        <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" />-->
    </resultMap>

    <select id="selectMultiForMgtCouponInfoDto" parameterType="com.liquidnet.service.candy.dto.admin.CandyMgtCouponListParam" resultMap="Rst_MgtCouponInfoDto">
        SELECT cc.coupon_id,
               cc.title,
               cc.`label`,
               cc.notice,
               cc.`exclusive`,
               cc.busi_type,
               cc.cou_type,
               cc.bind_type,
               ifnull(cc.discount, 0)*10 as 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,
               cc.effect_at,
               cc.expire_at,

               cmc.mcoupon_id,
#                cmc.coupon_id,
               cmc.`state`,
               cmc.event_amt,
               cmc.event_type,
               cmc.event_limit,
               cmc.event_at,
               cmc.`operator`,
               cmc.created_at created_at,
               cmc.updated_at
        FROM candy_mgt_coupon cmc
        LEFT JOIN candy_coupon cc ON cmc.coupon_id = cc.coupon_id
        WHERE cmc.state <![CDATA[<>]]> 2
          AND cmc.event_driven=1
        <if test="mcouponId != null and mcouponId != ''">
            AND cmc.mcoupon_id = #{mcouponId,jdbcType=VARCHAR}
        </if>
        <if test="couType != null">
            AND cc.cou_type = #{couType,jdbcType=SMALLINT}
        </if>
        <if test="keyword != null and keyword != ''">
            AND INSTR(CONCAT(cc.title, cc.notice), #{keyword,jdbcType=VARCHAR})
        </if>
        <if test="bindType != null">
            AND cc.bind_type = #{bindType,jdbcType=SMALLINT}
        </if>
        <if test="busiType != null">
            AND cc.busi_type = #{busiType,jdbcType=SMALLINT}
        </if>
    </select>
    <select id="selectMultiForMgtCouponMemberDto" resultMap="Rst_MgtCouponMemberDto">
        select cc.coupon_id,
               cc.title,
               cc.busi_type,
               cc.cou_type,
               cc.val_face,
               cc.val_over,
               cc.val_minus,
               cc.overlay,
               cmc.mcoupon_id,
               cmc.event_amt
        from candy_mgt_coupon cmc
                 left join candy_coupon cc on cmc.coupon_id = cc.coupon_id
        where cmc.mcoupon_id in
        <foreach collection="mrightsIdList" item="item" index="idx" open="(" close=")" separator=",">
            ${item}
        </foreach>
          and cmc.state = 10
          and cc.state = 1
    </select>
</mapper>