<?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.qs.mp.user.mapper.UserCouponMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qs.mp.user.domain.UserCoupon">
        <id column="id" property="id" />
        <result column="user_id" property="userId" />
        <result column="verify_code" property="verifyCode" />
        <result column="coupon_id" property="couponId" />
        <result column="valid_start" property="validStart" />
        <result column="valid_end" property="validEnd" />
        <result column="use_area_desc" property="useAreaDesc" />
        <result column="order_id" property="orderId" />
        <result column="verify_time" property="verifyTime" />
        <result column="status" property="status" />
        <result column="created_time" property="createdTime" />
        <result column="updated_time" property="updatedTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, user_id, verify_code, coupon_id, valid_start, valid_end, use_area_desc, order_id, verify_time, status, created_time, updated_time
    </sql>

    <select id="listUserCouponVO" resultType="com.qs.mp.user.domain.vo.UserCouponVO">
        select t1.*, t2.coupon_id, t2.title, t2.type, t2.pic_url, t2.description, t2.discount_type, t2.discount, t2.min_order_amt, t2.use_area, t2.distribute_type, t2.composite_use
        from mp_user_coupon t1
        left join mp_coupon t2 on t1.coupon_id = t2.coupon_id
            ${ew.customSqlSegment}
    </select>

    <select id="sumDiscountByQueryWrapper" resultType="java.lang.Integer">
        select  IFNULL(sum(t2.discount) ,0)
        from mp_user_coupon t1
        left join mp_coupon t2 on t1.coupon_id = t2.coupon_id
        ${ew.customSqlSegment}
    </select>
</mapper>
