package com.hai.dao;

import com.hai.model.HighOrderPreModel;
import com.hai.model.HighUserDiscountUnicomModel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * mapper扩展类
 */
public interface HighDiscountUserRelMapperExt {


    @Select({"<script>" +
            " SELECT" +
            " hdur.id id , " +
            " hd.using_range usingAttribution , " +
            " hdur.use_time useTime , " +
            " hdur.use_end_time useEndTime , " +
            " hdur.status status , " +
            " hdur.create_time createTime , " +
            " hd.discount_name discountName , " +
            " hd.discount_img discountImg , " +
            " hd.discount_condition discountCondition , " +
            " hd.discount_price discountPrice , " +
            " hd.discount_type discountType " +
            " FROM" +
            " high_discount_user_rel hdur join high_discount hd on hdur.discount_id = hd.id " +
            " WHERE" +
            " 1=1" +
            " <if test='map.useScope != null'> and hd.use_scope = #{map.useScope} </if> " +
            " <if test='map.userId != null'> and hdur.user_id = #{map.userId} </if>",
            " <if test='map.status != null'> and hdur.status = #{map.status} </if>",
            " <if test='map.createTimeS != null'> <![CDATA[ and hdur.create_time >= #{map.createTimeS} ]]> </if>",
            " <if test='map.createTimeE != null'> <![CDATA[ and hdur.create_time <= #{map.createTimeE} ]]> </if>",
            " ORDER BY hdur.create_time desc" +
                    "</script>"})
    List<HighUserDiscountUnicomModel> getUserCouponsList(@Param("map") Map<String,Object> map);


    @Select({"<script> select count(1) count from high_discount_user_rel where user_id = #{userId} and discount_id = #{discountId} and `status` <![CDATA[ <> 100 ]]> </script>"})
    Integer receiveDiscountCount(@Param("userId") Long userId, @Param("discountId") Long discountId);
}
