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

    <select id="selectMultiForCouponFilterDto" parameterType="com.liquidnet.service.candy.dto.admin.CandyCouponListParam"
            resultType="com.liquidnet.service.candy.dto.admin.CandyCouponFilterDto">
        SELECT DISTINCT cc.coupon_id  couponId,
                        cc.title,
                        cc.notice,
                        cc.cou_type   couType,
                        cc.busi_type  busiType,
                        cc.bind_type  bindType,
                        cc.val_face   valFace,
                        cc.val_over   valOver,
                        cc.val_minus  valMinus,
                        cc.discount,
                        ccr.busi_name busiName
        FROM candy_coupon cc
                 LEFT JOIN candy_coupon_rule ccr ON cc.coupon_id = ccr.coupon_id
        <where>
            cc.state = 1 AND ccr.state = 1
            <if test="couType != null">
                AND cc.cou_type=#{couType,jdbcType=SMALLINT}
            </if>
            <if test="bindType != null">
                AND cc.bind_type in (${bindType})
            </if>
            <if test="busiType != null">
                AND cc.busi_type = #{busiType,jdbcType=SMALLINT}
            </if>
            <if test="keyword != null and keyword != ''">
                AND INSTR(CONCAT(cc.title, cc.notice, ccr.busi_name), #{keyword,jdbcType=VARCHAR})
            </if>
        </where>
    </select>


</mapper>
