<?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.kym.mapper.miniapp.UserCouponMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.kym.entity.miniapp.UserCoupon">
        <result column="id" property="id" />
        <result column="company_id" property="companyId" />
        <result column="coupon_id" property="couponId" />
        <result column="coupon_name" property="couponName" />
        <result column="activity_id" property="activityId" />
        <result column="activity_name" property="activityName" />
        <result column="user_id" property="userId" />
        <result column="start_time" property="startTime" />
        <result column="end_time" property="endTime" />
        <result column="validity" property="validity" />
        <result column="receive_type" property="receiveType" />
        <result column="coupon_type" property="couponType" />
        <result column="discount" property="discount" />
        <result column="min_service_money" property="minServiceMoney" />
        <result column="allow_stacke" property="allowStacke" />
        <result column="status" property="status" />
        <result column="usage_status" property="usageStatus" />
        <result column="remark" property="remark" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,company_id,coupon_id, activity_id, user_id, start_time, end_time, validity,receive_type,coupon_type, discount, min_service_money, allow_stacke, status, usage_status,remark,create_time,update_time
    </sql>

    <select id="listStationAvailableCoupons" resultMap="BaseResultMap" parameterType="java.util.Map" >
        SELECT
            t1.*
        FROM
            car_wash.`t_user_coupon` t1
                LEFT JOIN charge_admin.`t_activity_station` t2
                          ON t1.`activity_id` = t2.`activity_id`
        WHERE t1.`user_id` = #{params.userId}
          AND t1.`status` = 1
          AND t1.`usage_status` = 0
          AND t2.`station_id` = #{params.stationId}
        ORDER BY  t1.`end_time` ASC
    </select>

</mapper>
