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

    <resultMap id="Rst_CouponRuleDto" type="com.liquidnet.service.candy.dto.CandyCouponRuleDto">
        <result column="crule_id" jdbcType="VARCHAR" property="cruleId"/>
        <result column="coupon_id" jdbcType="VARCHAR" property="couponId"/>
        <result column="use_scope" jdbcType="SMALLINT" property="useScope"/>
        <result column="busi_name" jdbcType="VARCHAR" property="busiName"/>
        <result column="busi_id" jdbcType="VARCHAR" property="busiId"/>
        <!--        <result column="state" jdbcType="TINYINT" property="state" />-->
        <!--        <result column="comment" jdbcType="VARCHAR" property="comment" />-->
    </resultMap>

    <select id="selectForCouponRuleDto" resultMap="Rst_CouponRuleDto">
        SELECT crule_id, coupon_id, use_scope, busi_name, busi_id
        FROM candy_coupon_rule
        WHERE state = 1
        <if test="couponId != null and couponId != ''">
            AND coupon_id = #{couponId,jdbcType=VARCHAR}
        </if>
        ORDER BY coupon_id
    </select>

    <select id="selectListForCouponRuleDto" resultMap="Rst_CouponRuleDto">
        SELECT crule_id, coupon_id, use_scope, busi_name, busi_id
        FROM candy_coupon_rule
        WHERE state = 1
        <if test="couponIdList != null and couponIdList.size() > 0">
            <foreach collection="couponIdList" item="couponId" open="AND coupon_id IN (" separator="," close=")">
                ${couponId}
            </foreach>
        </if>
        ORDER BY coupon_id
    </select>
</mapper>
