package cn.ysk.cashier.mybatis.mapper;

import cn.ysk.cashier.dto.QueryReceiveDto;
import cn.ysk.cashier.pojo.shop.TbFullShopId;
import cn.ysk.cashier.vo.QueryReceiveVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.ysk.cashier.mybatis.entity.TbShopCoupon;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 优惠券(TbShopCoupon)表数据库访问层
 *
 * @author ww
 * @since 2024-10-22 15:43:25
 */
public interface TbShopCouponMapper extends BaseMapper<TbShopCoupon> {

    @Select("<script>" +
            " SELECT" +
            "   record.id, " +
            "   vip.id as userId ," +
            "   vip.`name`," +
            "   vip.telephone as phone," +
            "   record.create_time as receiveTime," +
            "   record.update_time as useTime, " +
            "   record.num ," +
            "   record.over_num as overNum," +
            "   record.source as source" +
            " FROM" +
            " tb_activate_in_record record" +
            " LEFT JOIN tb_shop_user vip " +
            " ON record.vip_user_id = vip.id AND vip.shop_id = #{param.shopId} " +
            " WHERE" +
            "       record.coupon_id = #{param.couponId}  " +
            "            and record.shop_id = #{param.shopId}  " +
            "        <if test=\"param.value != null and param.value != '' \">" +
            "            and (vip.name like concat('%', #{param.value}, '%') or vip.telephone like concat('%', #{param.value}, '%')) " +
            "        </if>" +
            "        <if test=\"param.status != null and param.status == 1\">" +
            "            and record.over_num != record.num  " +
            "        </if>" +
            "        <if test=\"param.status != null and param.status == 0\">" +
            "            and record.over_num = record.num  " +
            "        </if>" +
            "        <if test=\"param.startTime != null \">" +
            "            and record.create_time &gt; #{param.startTime} " +
            "        </if>" +
            "        <if test=\"param.endTime != null \">" +
            "            and record.create_time &lt; #{param.endTime} " +
            "        </if>" +
            " order by record.create_time desc" +
            "</script>")
    Page<QueryReceiveVo> queryReceive(QueryReceiveDto param ,Page<QueryReceiveVo> page);
}

