<?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.zhongzheng.modules.order.mapper.CouponMapper">

    <resultMap type="com.zhongzheng.modules.order.domain.Coupon" id="CouponResult">
        <result property="couponId" column="coupon_id"/>
        <result property="price" column="price"/>
        <result property="endTime" column="end_time"/>
        <result property="userId" column="user_id"/>
        <result property="userStatus" column="user_status"/>
        <result property="configurationId" column="configuration_id"/>
        <result property="couponType" column="coupon_type"/>
    </resultMap>

    <select id="selectCountCon" parameterType="Long" resultType="integer">
        SELECT
        COUNT(a.id)
        FROM
        activity_configuration a
        LEFT JOIN activity_configuration_course t ON a.id = t.configuration_id
        WHERE
        1 = 1
        <if test="couponId != null and couponId != ''" >
            AND a.id = #{couponId}
        </if>
        <if test="goodsId != null and goodsId != ''" >
            AND t.course_id =#{goodsId}
        </if>
    </select>

    <select id="queryIssueListCoupon" parameterType="com.zhongzheng.modules.order.bo.CouponQueryBo" resultMap="CouponResult">
        SELECT
            *
        FROM
            coupon c
                LEFT JOIN activity_configuration a ON c.configuration_id = a.id
                LEFT JOIN activity_configuration_course t ON a.id = t.configuration_id
        WHERE
            1 = 1
          and user_status =0
        <if test="userId != null and userId != ''" >
          AND c.user_id = #{userId}
        </if>
        <if test="courseId != null and courseId != ''" >
          AND t.course_id = #{courseId}
        </if>
        <if test="couponType != null and couponType != ''" >
            AND c.coupon_type = #{couponType}
        </if>
        <if test="userStatus != null and userStatus != ''" >
            AND c.user_status = #{userStatus}
        </if>
    </select>
</mapper>